Title: [171182] trunk/Source/WebKit2
Revision
171182
Author
[email protected]
Date
2014-07-17 03:55:57 -0700 (Thu, 17 Jul 2014)

Log Message

[EFL][WK2] Add a "focus,notfound" signal.
https://bugs.webkit.org/show_bug.cgi?id=134674

Patch by Sanghyup Lee <[email protected]> on 2014-07-17
Reviewed by Gyuyoung Kim.

Add a "focus,notfound" signal to handover focus control to application
because there are no elements of webview to focus on the given direction.

Application can decide to move the focus to next widget of ewk_view or something else
by using this signal.

* UIProcess/API/efl/EwkViewCallbacks.h:
* UIProcess/API/efl/ewk_view.h:
* UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp: Added keyDown and keyUp function.
(EWK2UnitTest::EWK2UnitTestBase::waitUntilDirectionChanged):
(EWK2UnitTest::EWK2UnitTestBase::keyDown):
(EWK2UnitTest::EWK2UnitTestBase::keyUp):
* UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h:
* UIProcess/API/efl/tests/test_ewk2_view.cpp:
(EWK2ViewTest::FocusNotFoundCallback):
(TEST_F):
* UIProcess/efl/PageUIClientEfl.cpp: Removed unnecessary calls to evas_object_focus_set().
(WebKit::PageUIClientEfl::takeFocus):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (171181 => 171182)


--- trunk/Source/WebKit2/ChangeLog	2014-07-17 09:29:49 UTC (rev 171181)
+++ trunk/Source/WebKit2/ChangeLog	2014-07-17 10:55:57 UTC (rev 171182)
@@ -1,3 +1,29 @@
+2014-07-17  Sanghyup Lee  <[email protected]>
+
+        [EFL][WK2] Add a "focus,notfound" signal.
+        https://bugs.webkit.org/show_bug.cgi?id=134674
+
+        Reviewed by Gyuyoung Kim.
+
+        Add a "focus,notfound" signal to handover focus control to application
+        because there are no elements of webview to focus on the given direction.
+
+        Application can decide to move the focus to next widget of ewk_view or something else
+        by using this signal.
+
+        * UIProcess/API/efl/EwkViewCallbacks.h:
+        * UIProcess/API/efl/ewk_view.h:
+        * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp: Added keyDown and keyUp function.
+        (EWK2UnitTest::EWK2UnitTestBase::waitUntilDirectionChanged):
+        (EWK2UnitTest::EWK2UnitTestBase::keyDown):
+        (EWK2UnitTest::EWK2UnitTestBase::keyUp):
+        * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h:
+        * UIProcess/API/efl/tests/test_ewk2_view.cpp:
+        (EWK2ViewTest::FocusNotFoundCallback):
+        (TEST_F):
+        * UIProcess/efl/PageUIClientEfl.cpp: Removed unnecessary calls to evas_object_focus_set().
+        (WebKit::PageUIClientEfl::takeFocus):
+
 2014-07-16  Brady Eidson  <[email protected]>
 
         Reintroduce the SPI _websiteDataURLForContainerWithURL: that was removed in r171160

Modified: trunk/Source/WebKit2/UIProcess/API/efl/EwkViewCallbacks.h (171181 => 171182)


--- trunk/Source/WebKit2/UIProcess/API/efl/EwkViewCallbacks.h	2014-07-17 09:29:49 UTC (rev 171181)
+++ trunk/Source/WebKit2/UIProcess/API/efl/EwkViewCallbacks.h	2014-07-17 10:55:57 UTC (rev 171182)
@@ -27,6 +27,7 @@
 #define EwkViewCallbacks_h
 
 #include "WKEinaSharedString.h"
+#include "WKPageUIClient.h"
 #include "ewk_view.h"
 #include <Evas.h>
 #include <WebKit/WKGeometry.h>
@@ -52,6 +53,7 @@
     DownloadJobFinished,
     DownloadJobRequested,
     FileChooserRequest,
+    FocusNotFound,
     NewFormSubmissionRequest,
     LoadError,
     LoadFinished,
@@ -144,6 +146,24 @@
     }
 };
 
+template <CallbackType callbackType>
+struct CallBack <callbackType, Ewk_Focus_Direction> : public EvasObjectHolder {
+    explicit CallBack(Evas_Object* view)
+        : EvasObjectHolder(view)
+    { }
+
+    void call(Ewk_Focus_Direction direction)
+    {
+        evas_object_smart_callback_call(m_object, CallBackInfo<callbackType>::name(), &direction);
+    }
+
+    void call(const WKFocusDirection arg)
+    {
+        Ewk_Focus_Direction direction = (arg == kWKFocusDirectionForward) ? EWK_FOCUS_DIRECTION_FORWARD : EWK_FOCUS_DIRECTION_BACKWARD;
+        call(direction);
+    }
+};
+
 #define DECLARE_EWK_VIEW_CALLBACK(callbackType, string, type) \
 template <>                                                   \
 struct CallBackInfo<callbackType> {                           \
@@ -161,6 +181,7 @@
 DECLARE_EWK_VIEW_CALLBACK(DownloadJobFinished, "download,finished", Ewk_Download_Job*);
 DECLARE_EWK_VIEW_CALLBACK(DownloadJobRequested, "download,request", Ewk_Download_Job*);
 DECLARE_EWK_VIEW_CALLBACK(FileChooserRequest, "file,chooser,request", Ewk_File_Chooser_Request*);
+DECLARE_EWK_VIEW_CALLBACK(FocusNotFound, "focus,notfound", Ewk_Focus_Direction);
 DECLARE_EWK_VIEW_CALLBACK(NewFormSubmissionRequest, "form,submission,request", Ewk_Form_Submission_Request*);
 DECLARE_EWK_VIEW_CALLBACK(LoadError, "load,error", Ewk_Error*);
 DECLARE_EWK_VIEW_CALLBACK(LoadFinished, "load,finished", void);

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h (171181 => 171182)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h	2014-07-17 09:29:49 UTC (rev 171181)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h	2014-07-17 10:55:57 UTC (rev 171182)
@@ -39,6 +39,8 @@
  * - "file,chooser,request", Ewk_File_Chooser_Request*: reports that a request has been made for the user to choose
  *   a file (or several) on the file system. Call ewk_file_chooser_request_ref() on the request object to process it
  *   asynchronously.
+ * - "focus,notfound", Ewk_Focus_Direction*: reports that there was no element to be focused on the given direction.
+ *   The user can handle next focus behavior using the signal.
  * - "form,submission,request", Ewk_Form_Submission_Request*: Reports that a form request is about to be submitted.
  *   The Ewk_Form_Submission_Request passed contains information about the text fields of the form. This
  *   is typically used to store login information that can be used later to pre-fill the form.
@@ -276,6 +278,14 @@
 } Ewk_Pagination_Mode;
 
 /**
+ * Enum values used to set focus direction.
+ */
+typedef enum Ewk_Focus_Direction {
+    EWK_FOCUS_DIRECTION_FORWARD = 0,
+    EWK_FOCUS_DIRECTION_BACKWARD,
+} Ewk_Focus_Direction;
+
+/**
  * @typedef Ewk_View_Script_Execute_Cb Ewk_View_Script_Execute_Cb
  * @brief Callback type for use with ewk_view_script_execute()
  */

Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp (171181 => 171182)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp	2014-07-17 09:29:49 UTC (rev 171181)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp	2014-07-17 10:55:57 UTC (rev 171182)
@@ -239,6 +239,17 @@
     return !data.didTimeOut();
 }
 
+bool EWK2UnitTestBase::waitUntilDirectionChanged(Ewk_Focus_Direction &direction, double timeoutSeconds)
+{
+    CallbackDataTimer data(timeoutSeconds);
+    Ewk_Focus_Direction initialDirection = direction;
+
+    while (!data.isDone() && direction == initialDirection)
+        ecore_main_loop_iterate();
+
+    return !data.didTimeOut();
+}
+
 Eina_List* EWK2UnitTestBase::waitUntilSpellingLanguagesLoaded(unsigned expectedLanguageCount, double timeoutValue)
 {
     // Keep waiting until all languages has been loaded or leave afqter timeout.
@@ -312,4 +323,24 @@
     evas_event_feed_multi_move(evas_object_evas_get(m_webView), id, x, y, 0, 0, 0, 0, 0, 0, 0, 0, 0);
 }
 
+void EWK2UnitTestBase::keyDown(char* keyname, char* key, char* string, char* modifier)
+{
+    Evas* evas = evas_object_evas_get(m_webView);
+    ASSERT(evas);
+
+    if (modifier) {
+        evas_key_modifier_on(evas, modifier);
+        evas_event_feed_key_down(evas, keyname, key, string, 0, 0, 0);
+        evas_key_modifier_off(evas, modifier);
+        return;
+    }
+
+    evas_event_feed_key_down(evas, keyname, key, string, 0, 0, 0);
+}
+
+void EWK2UnitTestBase::keyUp(char* keyname, char* key, char* string)
+{
+    evas_event_feed_key_up(evas_object_evas_get(m_webView), keyname, key, string, 0, 0, 0);
+}
+
 } // namespace EWK2UnitTest

Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h (171181 => 171182)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h	2014-07-17 09:29:49 UTC (rev 171181)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h	2014-07-17 10:55:57 UTC (rev 171182)
@@ -52,6 +52,7 @@
     bool waitUntilTitleChangedTo(const char* expectedTitle, double timeoutSeconds = defaultTimeoutSeconds);
     bool waitUntilURLChangedTo(const char* expectedURL, double timeoutSeconds = defaultTimeoutSeconds);
     bool waitUntilTrue(bool &flag, double timeoutSeconds = defaultTimeoutSeconds);
+    bool waitUntilDirectionChanged(Ewk_Focus_Direction &direction, double timeoutSeconds = defaultTimeoutSeconds);
     Eina_List* waitUntilSpellingLanguagesLoaded(unsigned expectedLanguageCount, double timeoutValue = defaultTimeoutSeconds);
 
     void mouseClick(int x, int y, int button = 1 /*Left*/);
@@ -62,6 +63,8 @@
     void multiDown(int id, int x, int y);
     void multiUp(int id, int x, int y);
     void multiMove(int id, int x, int y);
+    void keyDown(char* keyname, char* key, char* string, char* modifier);
+    void keyUp(char* keyname, char* key, char* string);
 
 private:
     Evas_Object* m_webView;

Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp (171181 => 171182)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp	2014-07-17 09:29:49 UTC (rev 171181)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp	2014-07-17 10:55:57 UTC (rev 171182)
@@ -238,6 +238,13 @@
 
         obtainedPageContents = true;
     }
+
+    static void FocusNotFoundCallback(void* userData, Evas_Object*, void* eventInfo)
+    {
+        Ewk_Focus_Direction* direction = static_cast<Ewk_Focus_Direction*>(eventInfo);
+        Ewk_Focus_Direction* result = static_cast<Ewk_Focus_Direction*>(userData);
+        *result = *direction;
+    }
 };
 
 TEST_F(EWK2ViewTest, ewk_view_type_check)
@@ -1201,3 +1208,36 @@
     EXPECT_EQ(2000, contentsWidth);
     EXPECT_EQ(3000, contentsHeight);
 }
+
+TEST_F(EWK2ViewTest, ewk_focus_notfound)
+{
+    const char contents[] =
+        "<!DOCTYPE html>"
+        "<body><input type='text' autofocus></body>";
+    ewk_view_html_string_load(webView(), contents, 0, 0);
+    ASSERT_TRUE(waitUntilLoadFinished());
+
+    Ewk_Settings* settings = ewk_page_group_settings_get(ewk_view_page_group_get(webView()));
+    ewk_settings_spatial_navigation_enabled_set(settings, EINA_TRUE);
+
+    Ewk_Focus_Direction direction = EWK_FOCUS_DIRECTION_FORWARD;
+    evas_object_smart_callback_add(webView(), "focus,notfound", FocusNotFoundCallback, &direction);
+
+    keyDown("Tab", "Tab", 0, "Shift");
+    keyUp("Tab", "Tab", 0);
+
+    ASSERT_TRUE(waitUntilDirectionChanged(direction));
+    EXPECT_EQ(EWK_FOCUS_DIRECTION_BACKWARD, direction);
+
+    // Set focus to the input element again.
+    keyDown("Tab", "Tab", 0, 0);
+    keyUp("Tab", "Tab", 0);
+
+    keyDown("Tab", "Tab", 0, 0);
+    keyUp("Tab", "Tab", 0);
+
+    ASSERT_TRUE(waitUntilDirectionChanged(direction));
+    EXPECT_EQ(EWK_FOCUS_DIRECTION_FORWARD, direction);
+
+    evas_object_smart_callback_del(webView(), "focus,notfound", FocusNotFoundCallback);
+}

Modified: trunk/Source/WebKit2/UIProcess/efl/PageUIClientEfl.cpp (171181 => 171182)


--- trunk/Source/WebKit2/UIProcess/efl/PageUIClientEfl.cpp	2014-07-17 09:29:49 UTC (rev 171181)
+++ trunk/Source/WebKit2/UIProcess/efl/PageUIClientEfl.cpp	2014-07-17 10:55:57 UTC (rev 171182)
@@ -98,10 +98,9 @@
     toPageUIClientEfl(clientInfo)->m_view->close();
 }
 
-void PageUIClientEfl::takeFocus(WKPageRef, WKFocusDirection, const void* clientInfo)
+void PageUIClientEfl::takeFocus(WKPageRef, WKFocusDirection direction, const void* clientInfo)
 {
-    // FIXME: this is only a partial implementation.
-    evas_object_focus_set(toPageUIClientEfl(clientInfo)->m_view->evasObject(), false);
+    toPageUIClientEfl(clientInfo)->m_view->smartCallback<FocusNotFound>().call(direction);
 }
 
 void PageUIClientEfl::focus(WKPageRef, const void* clientInfo)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to