Diff
Modified: trunk/Source/WebKit2/ChangeLog (129120 => 129121)
--- trunk/Source/WebKit2/ChangeLog 2012-09-20 12:05:56 UTC (rev 129120)
+++ trunk/Source/WebKit2/ChangeLog 2012-09-20 12:09:08 UTC (rev 129121)
@@ -1,3 +1,34 @@
+2012-09-20 KwangYong Choi <[email protected]>
+
+ [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 <[email protected]>
[CoordinatedGraphics] Don't reset m_shouldSyncFrame in flushPendingLayerChanges
Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp (129120 => 129121)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp 2012-09-20 12:05:56 UTC (rev 129120)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp 2012-09-20 12:09:08 UTC (rev 129121)
@@ -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 @@
Ewk_Back_Forward_List* backForwardList;
OwnPtr<Ewk_Settings> settings;
bool areMouseEventsEnabled;
+ WKColorPickerResultListenerRef colorPickerResultListener;
WebPopupMenuProxyEfl* popupMenuProxy;
Eina_List* popupMenuItems;
@@ -116,6 +118,7 @@
: cursorObject(0)
, backForwardList(0)
, areMouseEventsEnabled(false)
+ , colorPickerResultListener(0)
, popupMenuProxy(0)
, popupMenuItems(0)
#ifdef HAVE_ECORE_X
@@ -1697,3 +1700,53 @@
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
+}
Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h (129120 => 129121)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h 2012-09-20 12:05:56 UTC (rev 129120)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h 2012-09-20 12:09:08 UTC (rev 129121)
@@ -121,13 +121,18 @@
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 @@
* @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_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
Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h (129120 => 129121)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h 2012-09-20 12:05:56 UTC (rev 129120)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h 2012-09-20 12:09:08 UTC (rev 129121)
@@ -109,4 +109,9 @@
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
Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp (129120 => 129121)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp 2012-09-20 12:05:56 UTC (rev 129120)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp 2012-09-20 12:09:08 UTC (rev 129121)
@@ -60,6 +60,19 @@
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 @@
uiClient.runJavaScriptAlert = runJavaScriptAlert;
uiClient.runJavaScriptConfirm = runJavaScriptConfirm;
uiClient.runJavaScriptPrompt = runJavaScriptPrompt;
+
+#if ENABLE(INPUT_TYPE_COLOR)
+ uiClient.showColorPicker = showColorPicker;
+ uiClient.hideColorPicker = hideColorPicker;
+#endif
+
WKPageSetPageUIClient(pageRef, &uiClient);
}
Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp (129120 => 129121)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp 2012-09-20 12:05:56 UTC (rev 129120)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp 2012-09-20 12:09:08 UTC (rev 129121)
@@ -624,3 +624,94 @@
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)