diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2012-09-20 16:13:48 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-09-20 16:13:48 +0200 |
commit | 0b3dc81d9701aea106543b49bde511a5697cdd6e (patch) | |
tree | 1382a17542d8ca4d0e054b9b143021d8f471e33b /Source/WebKit2/UIProcess | |
parent | 6dbcd09121fe266c7704a524b5cbd7f2754659c0 (diff) | |
download | qtwebkit-0b3dc81d9701aea106543b49bde511a5697cdd6e.tar.gz |
Imported WebKit commit 6dbad7b03986b50773637200cddddeeeb92745cc (http://svn.webkit.org/repository/webkit/trunk@129129)
Another update that should fix the initial build in the CI system
Diffstat (limited to 'Source/WebKit2/UIProcess')
-rw-r--r-- | Source/WebKit2/UIProcess/API/efl/ewk_view.cpp | 53 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/API/efl/ewk_view.h | 26 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/API/efl/ewk_view_private.h | 5 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp | 19 | ||||
-rw-r--r-- | Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp | 91 |
5 files changed, 192 insertions, 2 deletions
diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp index 98c9c66be..bbbfc18c1 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp @@ -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 +} diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view.h b/Source/WebKit2/UIProcess/API/efl/ewk_view.h index c449514aa..13b8daf0b 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view.h @@ -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 diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h b/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h index 5d6881dcc..4cba22d36 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h @@ -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 diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp index 8ede50dd9..6bbf8956c 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp @@ -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); } diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp index b608c7cb7..25f62fcf8 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp @@ -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) |