Changeset 129121 in webkit


Ignore:
Timestamp:
Sep 20, 2012 5:09:08 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[EFL][WK2] Implemented color picker API
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):

Location:
trunk/Source/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r129116 r129121  
     12012-09-20  KwangYong Choi  <ky0.choi@samsung.com>
     2
     3        [EFL][WK2] Implemented color picker API
     4        https://bugs.webkit.org/show_bug.cgi?id=91832
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Add support for color picker API for EFL port in WebKit2.
     9
     10        The external application can implement input picker by overriding
     11        smart class function.
     12
     13        * UIProcess/API/efl/ewk_view.cpp:
     14        (_Ewk_View_Private_Data):
     15        (_Ewk_View_Private_Data::_Ewk_View_Private_Data):
     16        (ewk_view_color_picker_request):
     17        (ewk_view_color_picker_dismiss):
     18        (ewk_view_color_picker_color_set):
     19        * UIProcess/API/efl/ewk_view.h:
     20        * UIProcess/API/efl/ewk_view_private.h:
     21        * UIProcess/API/efl/ewk_view_ui_client.cpp:
     22        (showColorPicker):
     23        (hideColorPicker):
     24        (ewk_view_ui_client_attach):
     25        * UIProcess/API/efl/tests/test_ewk2_view.cpp:
     26        (onColorPickerDone):
     27        (setColorPickerColor):
     28        (showColorPicker):
     29        (hideColorPicker):
     30        (TEST_F):
     31
    1322012-09-20  Balazs Kelemen  <kbalazs@webkit.org>
    233
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp

    r129101 r129121  
    2727#include "PageClientImpl.h"
    2828#include "WKAPICast.h"
     29#include "WKColorPickerResultListener.h"
    2930#include "WKEinaSharedString.h"
    3031#include "WKFindOptions.h"
     
    99100    OwnPtr<Ewk_Settings> settings;
    100101    bool areMouseEventsEnabled;
     102    WKColorPickerResultListenerRef colorPickerResultListener;
    101103
    102104    WebPopupMenuProxyEfl* popupMenuProxy;
     
    117119        , backForwardList(0)
    118120        , areMouseEventsEnabled(false)
     121        , colorPickerResultListener(0)
    119122        , popupMenuProxy(0)
    120123        , popupMenuItems(0)
     
    16981701    return WKEinaSharedString::adopt(smartData->api->run_javascript_prompt(smartData, message, defaultValue));
    16991702}
     1703
     1704#if ENABLE(INPUT_TYPE_COLOR)
     1705/**
     1706 * @internal
     1707 * Reqeusts to show external color picker.
     1708 */
     1709void ewk_view_color_picker_request(Evas_Object* ewkView, int r, int g, int b, int a, WKColorPickerResultListenerRef listener)
     1710{
     1711    EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
     1712    EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
     1713    EINA_SAFETY_ON_NULL_RETURN(smartData->api->input_picker_color_request);
     1714
     1715    priv->colorPickerResultListener = listener;
     1716
     1717    smartData->api->input_picker_color_request(smartData, r, g, b, a);
     1718}
     1719
     1720/**
     1721 * @internal
     1722 * Reqeusts to hide external color picker.
     1723 */
     1724void ewk_view_color_picker_dismiss(Evas_Object* ewkView)
     1725{
     1726    EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData);
     1727    EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv);
     1728    EINA_SAFETY_ON_NULL_RETURN(smartData->api->input_picker_color_dismiss);
     1729
     1730    priv->colorPickerResultListener = 0;
     1731
     1732    smartData->api->input_picker_color_dismiss(smartData);
     1733}
     1734#endif
     1735
     1736Eina_Bool ewk_view_color_picker_color_set(Evas_Object* ewkView, int r, int g, int b, int a)
     1737{
     1738#if ENABLE(INPUT_TYPE_COLOR)
     1739    EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false);
     1740    EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false);
     1741    EINA_SAFETY_ON_NULL_RETURN_VAL(priv->colorPickerResultListener, false);
     1742
     1743    WebCore::Color color = WebCore::Color(r, g, b, a);
     1744    const WKStringRef colorString = WKStringCreateWithUTF8CString(color.serialized().utf8().data());
     1745    WKColorPickerResultListenerSetColor(priv->colorPickerResultListener, colorString);
     1746    priv->colorPickerResultListener = 0;
     1747
     1748    return true;
     1749#else
     1750    return false;
     1751#endif
     1752}
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h

    r128967 r129121  
    122122    Eina_Bool (*run_javascript_confirm)(Ewk_View_Smart_Data *sd, const char *message);
    123123    const char *(*run_javascript_prompt)(Ewk_View_Smart_Data *sd, const char *message, const char *default_value); /**< return string should be stringshared. */
     124
     125    // color picker:
     126    //   - Shows and hides color picker.
     127    Eina_Bool (*input_picker_color_request)(Ewk_View_Smart_Data *sd, int r, int g, int b, int a);
     128    Eina_Bool (*input_picker_color_dismiss)(Ewk_View_Smart_Data *sd);
    124129};
    125130
     
    128133 * in the @a Ewk_View_Smart_Class structure.
    129134 */
    130 #define EWK_VIEW_SMART_CLASS_VERSION 4UL
     135#define EWK_VIEW_SMART_CLASS_VERSION 5UL
    131136
    132137/**
     
    140145 * @see EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION
    141146 */
    142 #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}
     147#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}
    143148
    144149/**
     
    662667EAPI Eina_Bool ewk_view_mouse_events_enabled_get(const Evas_Object *o);
    663668
     669/*
     670 * Sets the user chosen color. To be used when implementing a color picker.
     671 *
     672 * The function should only be called when a color has been requested by the document.
     673 * If called when this is not the case or when the input picker has been dismissed, this
     674 * function will fail and return EINA_FALSE.
     675 *
     676 * @param o view object contains color picker
     677 * @param r red channel value to be set
     678 * @param g green channel value to be set
     679 * @param b blue channel value to be set
     680 * @param a alpha channel value to be set
     681 *
     682 * @return @c EINA_TRUE on success @c EINA_FALSE otherwise
     683 */
     684EAPI Eina_Bool ewk_view_color_picker_color_set(Evas_Object *o, int r, int g, int b, int a);
     685
    664686#ifdef __cplusplus
    665687}
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h

    r129099 r129121  
    110110WKEinaSharedString ewk_view_run_javascript_prompt(Evas_Object* ewkView, const WKEinaSharedString& message, const WKEinaSharedString& defaultValue);
    111111
     112#if ENABLE(INPUT_TYPE_COLOR)
     113void ewk_view_color_picker_request(Evas_Object* ewkView, int r, int g, int b, int a, WKColorPickerResultListenerRef listener);
     114void ewk_view_color_picker_dismiss(Evas_Object* ewkView);
     115#endif
     116
    112117#endif // ewk_view_private_h
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp

    r128967 r129121  
    6161}
    6262
     63#if ENABLE(INPUT_TYPE_COLOR)
     64static void showColorPicker(WKPageRef, WKStringRef initialColor, WKColorPickerResultListenerRef listener, const void* clientInfo)
     65{
     66    WebCore::Color color = WebCore::Color(WebKit::toWTFString(initialColor));
     67    ewk_view_color_picker_request(toEwkView(clientInfo), color.red(), color.green(), color.blue(), color.alpha(), listener);
     68}
     69
     70static void hideColorPicker(WKPageRef, const void* clientInfo)
     71{
     72    ewk_view_color_picker_dismiss(toEwkView(clientInfo));
     73}
     74#endif
     75
    6376void ewk_view_ui_client_attach(WKPageRef pageRef, Evas_Object* ewkView)
    6477{
     
    7285    uiClient.runJavaScriptConfirm = runJavaScriptConfirm;
    7386    uiClient.runJavaScriptPrompt = runJavaScriptPrompt;
     87
     88#if ENABLE(INPUT_TYPE_COLOR)
     89    uiClient.showColorPicker = showColorPicker;
     90    uiClient.hideColorPicker = hideColorPicker;
     91#endif
     92
    7493    WKPageSetPageUIClient(pageRef, &uiClient);
    7594}
  • trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp

    r129111 r129121  
    625625    EXPECT_EQ(promptCallbackData.called, false);
    626626}
     627
     628#if ENABLE(INPUT_TYPE_COLOR)
     629static const int initialRed = 0x12;
     630static const int initialGreen = 0x34;
     631static const int initialBlue = 0x56;
     632static const int initialAlpha = 0xff;
     633static const int changedRed = 0x98;
     634static const int changedGreen = 0x76;
     635static const int changedBlue = 0x54;
     636static const int changedAlpha = 0xff;
     637
     638static bool isColorPickerShown = false;
     639
     640static void onColorPickerDone(void* userData, Evas_Object*, void*)
     641{
     642    bool* handled = static_cast<bool*>(userData);
     643
     644    *handled = true;
     645}
     646
     647static unsigned char setColorPickerColor(void* data)
     648{
     649    Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data);
     650
     651    // 3. Change color to changed color.
     652    EXPECT_TRUE(ewk_view_color_picker_color_set(smartData->self, changedRed, changedGreen, changedBlue, changedAlpha));
     653
     654    evas_object_smart_callback_call(smartData->self, "input,type,color,request", 0);
     655
     656    return 0;
     657}
     658
     659static Eina_Bool showColorPicker(Ewk_View_Smart_Data* smartData, int r, int g, int b, int a)
     660{
     661    static bool isFirstRun = true;
     662
     663    isColorPickerShown = true;
     664
     665    if (isFirstRun) {
     666        // 1. Check initial value from html file.
     667        EXPECT_EQ(r, initialRed);
     668        EXPECT_EQ(g, initialGreen);
     669        EXPECT_EQ(b, initialBlue);
     670        EXPECT_EQ(a, initialAlpha);
     671
     672        isFirstRun = false;
     673    } else {
     674        // 4. Input values should be same as changed color.
     675        EXPECT_EQ(r, changedRed);
     676        EXPECT_EQ(g, changedGreen);
     677        EXPECT_EQ(b, changedBlue);
     678        EXPECT_EQ(a, changedAlpha);
     679    }
     680
     681    // 2. Return after making a color picker.
     682    ecore_timer_add(0.0, setColorPickerColor, smartData);
     683    return true;
     684}
     685
     686static Eina_Bool hideColorPicker(Ewk_View_Smart_Data*)
     687{
     688    // Test color picker is shown.
     689    EXPECT_TRUE(isColorPickerShown);
     690    isColorPickerShown = false;
     691}
     692
     693TEST_F(EWK2UnitTestBase, ewk_view_color_picker_color_set)
     694{
     695    Ewk_View_Smart_Class* api = ewkViewClass();
     696    api->input_picker_color_request = showColorPicker;
     697    api->input_picker_color_dismiss = hideColorPicker;
     698
     699    loadUrlSync("data:text/html,<input type='color' value='#123456'>");
     700
     701    // Click input element.
     702    mouseClick(30, 20);
     703
     704    bool handled = false;
     705    evas_object_smart_callback_add(webView(), "input,type,color,request", onColorPickerDone, &handled);
     706    while (!handled)
     707        ecore_main_loop_iterate();
     708
     709    // Click input element again.
     710    mouseClick(30, 20);
     711
     712    handled = false;
     713    while (!handled)
     714        ecore_main_loop_iterate();
     715    evas_object_smart_callback_del(webView(), "input,type,color,request", onColorPickerDone);
     716}
     717#endif // ENABLE(INPUT_TYPE_COLOR)
Note: See TracChangeset for help on using the changeset viewer.