[EFL][WK2] Implemented color picker API
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Sep 2012 12:09:08 +0000 (12:09 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Sep 2012 12:09:08 +0000 (12:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=91832

Patch by KwangYong Choi <ky0.choi@samsung.com> on 2012-09-20
Reviewed by Kenneth Rohde Christiansen.

Add support for color picker API for EFL port in WebKit2.

The external application can implement input picker by overriding
smart class function.

* UIProcess/API/efl/ewk_view.cpp:
(_Ewk_View_Private_Data):
(_Ewk_View_Private_Data::_Ewk_View_Private_Data):
(ewk_view_color_picker_request):
(ewk_view_color_picker_dismiss):
(ewk_view_color_picker_color_set):
* UIProcess/API/efl/ewk_view.h:
* UIProcess/API/efl/ewk_view_private.h:
* UIProcess/API/efl/ewk_view_ui_client.cpp:
(showColorPicker):
(hideColorPicker):
(ewk_view_ui_client_attach):
* UIProcess/API/efl/tests/test_ewk2_view.cpp:
(onColorPickerDone):
(setColorPickerColor):
(showColorPicker):
(hideColorPicker):
(TEST_F):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@129121 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/efl/ewk_view.cpp
Source/WebKit2/UIProcess/API/efl/ewk_view.h
Source/WebKit2/UIProcess/API/efl/ewk_view_private.h
Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp
Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp

index cbb88ad..310e5fe 100644 (file)
@@ -1,3 +1,34 @@
+2012-09-20  KwangYong Choi  <ky0.choi@samsung.com>
+
+        [EFL][WK2] Implemented color picker API
+        https://bugs.webkit.org/show_bug.cgi?id=91832
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Add support for color picker API for EFL port in WebKit2.
+
+        The external application can implement input picker by overriding
+        smart class function.
+
+        * UIProcess/API/efl/ewk_view.cpp:
+        (_Ewk_View_Private_Data):
+        (_Ewk_View_Private_Data::_Ewk_View_Private_Data):
+        (ewk_view_color_picker_request):
+        (ewk_view_color_picker_dismiss):
+        (ewk_view_color_picker_color_set):
+        * UIProcess/API/efl/ewk_view.h:
+        * UIProcess/API/efl/ewk_view_private.h:
+        * UIProcess/API/efl/ewk_view_ui_client.cpp:
+        (showColorPicker):
+        (hideColorPicker):
+        (ewk_view_ui_client_attach):
+        * UIProcess/API/efl/tests/test_ewk2_view.cpp:
+        (onColorPickerDone):
+        (setColorPickerColor):
+        (showColorPicker):
+        (hideColorPicker):
+        (TEST_F):
+
 2012-09-20  Balazs Kelemen  <kbalazs@webkit.org>
 
         [CoordinatedGraphics] Don't reset m_shouldSyncFrame in flushPendingLayerChanges
index 98c9c66..bbbfc18 100644 (file)
@@ -26,6 +26,7 @@
 #include "NativeWebWheelEvent.h"
 #include "PageClientImpl.h"
 #include "WKAPICast.h"
+#include "WKColorPickerResultListener.h"
 #include "WKEinaSharedString.h"
 #include "WKFindOptions.h"
 #include "WKRetainPtr.h"
@@ -98,6 +99,7 @@ struct _Ewk_View_Private_Data {
     Ewk_Back_Forward_List* backForwardList;
     OwnPtr<Ewk_Settings> settings;
     bool areMouseEventsEnabled;
+    WKColorPickerResultListenerRef colorPickerResultListener;
 
     WebPopupMenuProxyEfl* popupMenuProxy;
     Eina_List* popupMenuItems;
@@ -116,6 +118,7 @@ struct _Ewk_View_Private_Data {
         : cursorObject(0)
         , backForwardList(0)
         , areMouseEventsEnabled(false)
+        , colorPickerResultListener(0)
         , popupMenuProxy(0)
         , popupMenuItems(0)
 #ifdef HAVE_ECORE_X
@@ -1697,3 +1700,53 @@ WKEinaSharedString ewk_view_run_javascript_prompt(Evas_Object* ewkView, const WK
 
     return WKEinaSharedString::adopt(smartData->api->run_javascript_prompt(smartData, message, defaultValue));
 }
+
+#if ENABLE(INPUT_TYPE_COLOR)
+/**
+ * @internal
+ * Reqeusts to show external color picker.
+ */
+void ewk_view_color_picker_request(Evas_Object* ewkView, int r, int g, int b, int a, WKColorPickerResultListenerRef listener)
+{
+    EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
+    EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
+    EINA_SAFETY_ON_NULL_RETURN(smartData->api->input_picker_color_request);
+
+    priv->colorPickerResultListener = listener;
+
+    smartData->api->input_picker_color_request(smartData, r, g, b, a);
+}
+
+/**
+ * @internal
+ * Reqeusts to hide external color picker.
+ */
+void ewk_view_color_picker_dismiss(Evas_Object* ewkView)
+{
+    EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
+    EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
+    EINA_SAFETY_ON_NULL_RETURN(smartData->api->input_picker_color_dismiss);
+
+    priv->colorPickerResultListener = 0;
+
+    smartData->api->input_picker_color_dismiss(smartData);
+}
+#endif
+
+Eina_Bool ewk_view_color_picker_color_set(Evas_Object* ewkView, int r, int g, int b, int a)
+{
+#if ENABLE(INPUT_TYPE_COLOR)
+    EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
+    EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
+    EINA_SAFETY_ON_NULL_RETURN_VAL(priv->colorPickerResultListener, false);
+
+    WebCore::Color color = WebCore::Color(r, g, b, a);
+    const WKStringRef colorString = WKStringCreateWithUTF8CString(color.serialized().utf8().data());
+    WKColorPickerResultListenerSetColor(priv->colorPickerResultListener, colorString);
+    priv->colorPickerResultListener = 0;
+
+    return true;
+#else
+    return false;
+#endif
+}
index c449514..13b8daf 100644 (file)
@@ -121,13 +121,18 @@ struct _Ewk_View_Smart_Class {
     void (*run_javascript_alert)(Ewk_View_Smart_Data *sd, const char *message);
     Eina_Bool (*run_javascript_confirm)(Ewk_View_Smart_Data *sd, const char *message);
     const char *(*run_javascript_prompt)(Ewk_View_Smart_Data *sd, const char *message, const char *default_value); /**< return string should be stringshared. */
+
+    // color picker:
+    //   - Shows and hides color picker.
+    Eina_Bool (*input_picker_color_request)(Ewk_View_Smart_Data *sd, int r, int g, int b, int a);
+    Eina_Bool (*input_picker_color_dismiss)(Ewk_View_Smart_Data *sd);
 };
 
 /**
  * The version you have to put into the version field
  * in the @a Ewk_View_Smart_Class structure.
  */
-#define EWK_VIEW_SMART_CLASS_VERSION 4UL
+#define EWK_VIEW_SMART_CLASS_VERSION 5UL
 
 /**
  * Initializer for whole Ewk_View_Smart_Class structure.
@@ -139,7 +144,7 @@ struct _Ewk_View_Smart_Class {
  * @see EWK_VIEW_SMART_CLASS_INIT_VERSION
  * @see EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION
  */
-#define EWK_VIEW_SMART_CLASS_INIT(smart_class_init) {smart_class_init, EWK_VIEW_SMART_CLASS_VERSION, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
+#define EWK_VIEW_SMART_CLASS_INIT(smart_class_init) {smart_class_init, EWK_VIEW_SMART_CLASS_VERSION, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
 
 /**
  * Initializer to zero a whole Ewk_View_Smart_Class structure.
@@ -661,6 +666,23 @@ EAPI Eina_Bool ewk_view_mouse_events_enabled_set(Evas_Object *o, Eina_Bool enabl
  */
 EAPI Eina_Bool ewk_view_mouse_events_enabled_get(const Evas_Object *o);
 
+/*
+ * Sets the user chosen color. To be used when implementing a color picker.
+ *
+ * The function should only be called when a color has been requested by the document.
+ * If called when this is not the case or when the input picker has been dismissed, this
+ * function will fail and return EINA_FALSE.
+ *
+ * @param o view object contains color picker
+ * @param r red channel value to be set
+ * @param g green channel value to be set
+ * @param b blue channel value to be set
+ * @param a alpha channel value to be set
+ *
+ * @return @c EINA_TRUE on success @c EINA_FALSE otherwise
+ */
+EAPI Eina_Bool ewk_view_color_picker_color_set(Evas_Object *o, int r, int g, int b, int a);
+
 #ifdef __cplusplus
 }
 #endif
index 5d6881d..4cba22d 100644 (file)
@@ -109,4 +109,9 @@ void ewk_view_run_javascript_alert(Evas_Object* ewkView, const WKEinaSharedStrin
 bool ewk_view_run_javascript_confirm(Evas_Object* ewkView, const WKEinaSharedString& message);
 WKEinaSharedString ewk_view_run_javascript_prompt(Evas_Object* ewkView, const WKEinaSharedString& message, const WKEinaSharedString& defaultValue);
 
+#if ENABLE(INPUT_TYPE_COLOR)
+void ewk_view_color_picker_request(Evas_Object* ewkView, int r, int g, int b, int a, WKColorPickerResultListenerRef listener);
+void ewk_view_color_picker_dismiss(Evas_Object* ewkView);
+#endif
+
 #endif // ewk_view_private_h
index 8ede50d..6bbf895 100644 (file)
@@ -60,6 +60,19 @@ static WKStringRef runJavaScriptPrompt(WKPageRef, WKStringRef message, WKStringR
     return value ? WKStringCreateWithUTF8CString(value) : 0;
 }
 
+#if ENABLE(INPUT_TYPE_COLOR)
+static void showColorPicker(WKPageRef, WKStringRef initialColor, WKColorPickerResultListenerRef listener, const void* clientInfo)
+{
+    WebCore::Color color = WebCore::Color(WebKit::toWTFString(initialColor));
+    ewk_view_color_picker_request(toEwkView(clientInfo), color.red(), color.green(), color.blue(), color.alpha(), listener);
+}
+
+static void hideColorPicker(WKPageRef, const void* clientInfo)
+{
+    ewk_view_color_picker_dismiss(toEwkView(clientInfo));
+}
+#endif
+
 void ewk_view_ui_client_attach(WKPageRef pageRef, Evas_Object* ewkView)
 {
     WKPageUIClient uiClient;
@@ -71,5 +84,11 @@ void ewk_view_ui_client_attach(WKPageRef pageRef, Evas_Object* ewkView)
     uiClient.runJavaScriptAlert = runJavaScriptAlert;
     uiClient.runJavaScriptConfirm = runJavaScriptConfirm;
     uiClient.runJavaScriptPrompt = runJavaScriptPrompt;
+
+#if ENABLE(INPUT_TYPE_COLOR)
+    uiClient.showColorPicker = showColorPicker;
+    uiClient.hideColorPicker = hideColorPicker;
+#endif
+
     WKPageSetPageUIClient(pageRef, &uiClient);
 }
index b608c7c..25f62fc 100644 (file)
@@ -624,3 +624,94 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_prompt)
     EXPECT_STREQ(ewk_view_title_get(webView()), "null");
     EXPECT_EQ(promptCallbackData.called, false);
 }
+
+#if ENABLE(INPUT_TYPE_COLOR)
+static const int initialRed = 0x12;
+static const int initialGreen = 0x34;
+static const int initialBlue = 0x56;
+static const int initialAlpha = 0xff;
+static const int changedRed = 0x98;
+static const int changedGreen = 0x76;
+static const int changedBlue = 0x54;
+static const int changedAlpha = 0xff;
+
+static bool isColorPickerShown = false;
+
+static void onColorPickerDone(void* userData, Evas_Object*, void*)
+{
+    bool* handled = static_cast<bool*>(userData);
+
+    *handled = true;
+}
+
+static unsigned char setColorPickerColor(void* data)
+{
+    Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
+
+    // 3. Change color to changed color.
+    EXPECT_TRUE(ewk_view_color_picker_color_set(smartData->self, changedRed, changedGreen, changedBlue, changedAlpha));
+
+    evas_object_smart_callback_call(smartData->self, "input,type,color,request", 0);
+
+    return 0;
+}
+
+static Eina_Bool showColorPicker(Ewk_View_Smart_Data* smartData, int r, int g, int b, int a)
+{
+    static bool isFirstRun = true;
+
+    isColorPickerShown = true;
+
+    if (isFirstRun) {
+        // 1. Check initial value from html file.
+        EXPECT_EQ(r, initialRed);
+        EXPECT_EQ(g, initialGreen);
+        EXPECT_EQ(b, initialBlue);
+        EXPECT_EQ(a, initialAlpha);
+
+        isFirstRun = false;
+    } else {
+        // 4. Input values should be same as changed color.
+        EXPECT_EQ(r, changedRed);
+        EXPECT_EQ(g, changedGreen);
+        EXPECT_EQ(b, changedBlue);
+        EXPECT_EQ(a, changedAlpha);
+    }
+
+    // 2. Return after making a color picker.
+    ecore_timer_add(0.0, setColorPickerColor, smartData);
+    return true;
+}
+
+static Eina_Bool hideColorPicker(Ewk_View_Smart_Data*)
+{
+    // Test color picker is shown.
+    EXPECT_TRUE(isColorPickerShown);
+    isColorPickerShown = false;
+}
+
+TEST_F(EWK2UnitTestBase, ewk_view_color_picker_color_set)
+{
+    Ewk_View_Smart_Class* api = ewkViewClass();
+    api->input_picker_color_request = showColorPicker;
+    api->input_picker_color_dismiss = hideColorPicker;
+
+    loadUrlSync("data:text/html,<input type='color' value='#123456'>");
+
+    // Click input element.
+    mouseClick(30, 20);
+
+    bool handled = false;
+    evas_object_smart_callback_add(webView(), "input,type,color,request", onColorPickerDone, &handled);
+    while (!handled)
+        ecore_main_loop_iterate();
+
+    // Click input element again.
+    mouseClick(30, 20);
+
+    handled = false;
+    while (!handled)
+        ecore_main_loop_iterate();
+    evas_object_smart_callback_del(webView(), "input,type,color,request", onColorPickerDone);
+}
+#endif // ENABLE(INPUT_TYPE_COLOR)