Changeset 179984 in webkit


Ignore:
Timestamp:
Feb 12, 2015 12:50:00 AM (9 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Add API to allow overriding the default color chooser implementation
https://bugs.webkit.org/show_bug.cgi?id=98935

Reviewed by Gustavo Noronha Silva.

Source/WebKit2:

Add API to allow the user to override the default UI of color
chooser. Similar to the file chooser API, a new run-color-chooser
signal is added to WebKitWebView that passes a WebKitColorChooserRequest
parameter to the signal.

Initial patch by Arnaud Renevier <a.renevier@sisa.samsung.com>.

  • PlatformGTK.cmake: Add new files to compilation.
  • UIProcess/API/gtk/PageClientImpl.cpp:

(WebKit::PageClientImpl::createColorPicker): Create a
WebKitColorChooser is the view widget is a WebKitWebView or a
WebColorPicker otherwise,

  • UIProcess/API/gtk/WebKitColorChooser.cpp: Added.

(WebKit::WebKitColorChooser::create):
(WebKit::WebKitColorChooser::WebKitColorChooser):
(WebKit::WebKitColorChooser::~WebKitColorChooser):
(WebKit::WebKitColorChooser::endPicker): Chain up to parent class
when not having a request, or finish the request if we have one.
(WebKit::WebKitColorChooser::colorChooserRequestFinished):
(WebKit::WebKitColorChooser::colorChooserRequestRGBAChanged):
(WebKit::WebKitColorChooser::showColorPicker): Create a new
WebKitColorChooserRequest and emit WebKitWebView::run-color-chooser.
If the signal is not handled, fallback to the default color
chooser dialog implemented by the parent class.

  • UIProcess/API/gtk/WebKitColorChooser.h: Added.
  • UIProcess/API/gtk/WebKitColorChooserRequest.cpp: Added.

(webkitColorChooserRequestGetProperty):
(webkitColorChooserRequestSetProperty):
(webkit_color_chooser_request_class_init):
(webkit_color_chooser_request_set_rgba):
(webkit_color_chooser_request_get_rgba):
(webkit_color_chooser_request_get_element_rectangle):
(webkit_color_chooser_request_finish):
(webkit_color_chooser_request_cancel):
(webkitColorChooserRequestCreate):

  • UIProcess/API/gtk/WebKitColorChooserRequest.h: Added.
  • UIProcess/API/gtk/WebKitColorChooserRequestPrivate.h: Added.
  • UIProcess/API/gtk/WebKitWebView.cpp:

(webkit_web_view_class_init): Add run-color-chooser signal.
(webkitWebViewEmitRunColorChooser): Emit run-color-chooser signal.

  • UIProcess/API/gtk/WebKitWebView.h:
  • UIProcess/API/gtk/WebKitWebViewPrivate.h:
  • UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols.
  • UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section for WebKitColorChooserRequest.
  • UIProcess/API/gtk/webkit2.h: Include WebKitColorChooserRequest.h

Tools:

Add a color chooser implementation for MiniBrowser using
GtkPopover when the GTK+ version is recent enough.
And a test case to check the new color chooser API.

  • MiniBrowser/gtk/BrowserWindow.c:

(colorChooserRGBAChanged):
(popoverColorClosed):
(colorChooserRequestFinished):
(runColorChooserCallback):
(browserWindowConstructed):

  • TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp:

(testWebViewColorChooserRequest):
(beforeAll):

Location:
trunk
Files:
5 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r179975 r179984  
     12015-02-12  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add API to allow overriding the default color chooser implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=98935
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        Add API to allow the user to override the default UI of color
     9        chooser. Similar to the file chooser API, a new run-color-chooser
     10        signal is added to WebKitWebView that passes a WebKitColorChooserRequest
     11        parameter to the signal.
     12
     13        Initial patch by Arnaud Renevier <a.renevier@sisa.samsung.com>.
     14
     15        * PlatformGTK.cmake: Add new files to compilation.
     16        * UIProcess/API/gtk/PageClientImpl.cpp:
     17        (WebKit::PageClientImpl::createColorPicker): Create a
     18        WebKitColorChooser is the view widget is a WebKitWebView or a
     19        WebColorPicker otherwise,
     20        * UIProcess/API/gtk/WebKitColorChooser.cpp: Added.
     21        (WebKit::WebKitColorChooser::create):
     22        (WebKit::WebKitColorChooser::WebKitColorChooser):
     23        (WebKit::WebKitColorChooser::~WebKitColorChooser):
     24        (WebKit::WebKitColorChooser::endPicker): Chain up to parent class
     25        when not having a request, or finish the request if we have one.
     26        (WebKit::WebKitColorChooser::colorChooserRequestFinished):
     27        (WebKit::WebKitColorChooser::colorChooserRequestRGBAChanged):
     28        (WebKit::WebKitColorChooser::showColorPicker): Create a new
     29        WebKitColorChooserRequest and emit WebKitWebView::run-color-chooser.
     30        If the signal is not handled, fallback to the default color
     31        chooser dialog implemented by the parent class.
     32        * UIProcess/API/gtk/WebKitColorChooser.h: Added.
     33        * UIProcess/API/gtk/WebKitColorChooserRequest.cpp: Added.
     34        (webkitColorChooserRequestGetProperty):
     35        (webkitColorChooserRequestSetProperty):
     36        (webkit_color_chooser_request_class_init):
     37        (webkit_color_chooser_request_set_rgba):
     38        (webkit_color_chooser_request_get_rgba):
     39        (webkit_color_chooser_request_get_element_rectangle):
     40        (webkit_color_chooser_request_finish):
     41        (webkit_color_chooser_request_cancel):
     42        (webkitColorChooserRequestCreate):
     43        * UIProcess/API/gtk/WebKitColorChooserRequest.h: Added.
     44        * UIProcess/API/gtk/WebKitColorChooserRequestPrivate.h: Added.
     45        * UIProcess/API/gtk/WebKitWebView.cpp:
     46        (webkit_web_view_class_init): Add run-color-chooser signal.
     47        (webkitWebViewEmitRunColorChooser): Emit run-color-chooser signal.
     48        * UIProcess/API/gtk/WebKitWebView.h:
     49        * UIProcess/API/gtk/WebKitWebViewPrivate.h:
     50        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols.
     51        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section for WebKitColorChooserRequest.
     52        * UIProcess/API/gtk/webkit2.h: Include WebKitColorChooserRequest.h
     53
    1542015-02-11  Enrica Casucci  <enrica@apple.com>
    255
  • trunk/Source/WebKit2/PlatformGTK.cmake

    r179922 r179984  
    102102    UIProcess/API/gtk/WebKitBackForwardListItem.h
    103103    UIProcess/API/gtk/WebKitBackForwardListPrivate.h
     104    UIProcess/API/gtk/WebKitColorChooser.cpp
     105    UIProcess/API/gtk/WebKitColorChooserRequest.cpp
    104106    UIProcess/API/gtk/WebKitContextMenu.cpp
    105107    UIProcess/API/gtk/WebKitContextMenu.h
     
    348350    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitBackForwardList.h
    349351    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitBackForwardListItem.h
     352    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitColorChooserRequest.h
    350353    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitCredential.h
    351354    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitContextMenu.h
  • trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp

    r179922 r179984  
    3636#include "WebContextMenuProxyGtk.h"
    3737#include "WebEventFactory.h"
     38#include "WebKitColorChooser.h"
     39#include "WebKitWebView.h"
    3840#include "WebKitWebViewBasePrivate.h"
    3941#include "WebPageProxy.h"
     
    227229}
    228230
    229 #if ENABLE(INPUT_TYPE_COLOR)
    230231PassRefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy* page, const WebCore::Color& color, const WebCore::IntRect& rect)
    231232{
     233    if (WEBKIT_IS_WEB_VIEW(m_viewWidget))
     234        return WebKitColorChooser::create(*page, color, rect);
    232235    return WebColorPickerGtk::create(*page, color, rect);
    233236}
    234 #endif
    235237
    236238void PageClientImpl::setTextIndicator(PassRefPtr<WebCore::TextIndicator>, bool /* fadeOut */)
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r179745 r179984  
    133133    SHOW_NOTIFICATION,
    134134
     135    RUN_COLOR_CHOOSER,
     136
    135137    LAST_SIGNAL
    136138};
     
    17151717            G_TYPE_BOOLEAN, 1,
    17161718            WEBKIT_TYPE_NOTIFICATION);
     1719
     1720     /**
     1721      * WebKitWebView::run-color-chooser:
     1722      * @web_view: the #WebKitWebView on which the signal is emitted
     1723      * @request: a #WebKitColorChooserRequest
     1724      *
     1725      * This signal is emitted when the user interacts with a &lt;input
     1726      * type='color' /&gt; HTML element, requesting from WebKit to show
     1727      * a dialog to select a color. To let the application know the details of
     1728      * the color chooser, as well as to allow the client application to either
     1729      * cancel the request or perform an actual color selection, the signal will
     1730      * pass an instance of the #WebKitColorChooserRequest in the @request
     1731      * argument.
     1732      *
     1733      * It is possible to handle this request asynchronously by increasing the
     1734      * reference count of the request.
     1735      *
     1736      * The default signal handler will asynchronously run a regular
     1737      * #GtkColorChooser for the user to interact with.
     1738      *
     1739      * Returns: %TRUE to stop other handlers from being invoked for the event.
     1740      *   %FALSE to propagate the event further.
     1741      *
     1742      * Since: 2.8
     1743      */
     1744    signals[RUN_COLOR_CHOOSER] =
     1745        g_signal_new("run-color-chooser",
     1746            G_TYPE_FROM_CLASS(webViewClass),
     1747            G_SIGNAL_RUN_LAST,
     1748            G_STRUCT_OFFSET(WebKitWebViewClass, run_color_chooser),
     1749            g_signal_accumulator_true_handled, nullptr,
     1750            webkit_marshal_BOOLEAN__OBJECT,
     1751            G_TYPE_BOOLEAN, 1,
     1752            WEBKIT_TYPE_COLOR_CHOOSER_REQUEST);
    17171753}
    17181754
     
    20892125    gboolean handled;
    20902126    g_signal_emit(webView, signals[SHOW_NOTIFICATION], 0, webNotification, &handled);
     2127    return handled;
     2128}
     2129
     2130bool webkitWebViewEmitRunColorChooser(WebKitWebView* webView, WebKitColorChooserRequest* request)
     2131{
     2132    gboolean handled;
     2133    g_signal_emit(webView, signals[RUN_COLOR_CHOOSER], 0, request, &handled);
    20912134    return handled;
    20922135}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

    r179745 r179984  
    3333#include <webkit2/WebKitBackForwardList.h>
    3434#include <webkit2/WebKitDefines.h>
     35#include <webkit2/WebKitColorChooserRequest.h>
    3536#include <webkit2/WebKitFileChooserRequest.h>
    3637#include <webkit2/WebKitFindController.h>
     
    245246    gboolean   (* show_notification)           (WebKitWebView               *web_view,
    246247                                                WebKitNotification          *notification);
     248    gboolean   (* run_color_chooser)           (WebKitWebView               *web_view,
     249                                                WebKitColorChooserRequest   *request);
    247250
    248251    void (*_webkit_reserved0) (void);
     
    250253    void (*_webkit_reserved2) (void);
    251254    void (*_webkit_reserved3) (void);
    252     void (*_webkit_reserved4) (void);
    253255};
    254256
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h

    r179745 r179984  
    6060void webkitWebViewInsecureContentDetected(WebKitWebView*, WebKitInsecureContentEvent);
    6161bool webkitWebViewEmitShowNotification(WebKitWebView*, WebKitNotification*);
     62bool webkitWebViewEmitRunColorChooser(WebKitWebView*, WebKitColorChooserRequest*);
    6263void webkitWebViewWebProcessCrashed(WebKitWebView*);
    6364void webkitWebViewIsPlayingAudioChanged(WebKitWebView*);
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt

    r179745 r179984  
    12481248webkit_web_hit_test_result_get_type
    12491249</SECTION>
     1250
     1251<SECTION>
     1252<FILE>WebKitColorChooserRequest</FILE>
     1253WebKitColorChooserRequest
     1254webkit_color_chooser_request_get_rgba
     1255webkit_color_chooser_request_set_rgba
     1256webkit_color_chooser_request_get_element_rectangle
     1257webkit_color_chooser_request_finish
     1258webkit_color_chooser_request_cancel
     1259
     1260<SUBSECTION Standard>
     1261WebKitColorChooserRequestClass
     1262WEBKIT_TYPE_COLOR_CHOOSER_REQUEST
     1263WEBKIT_COLOR_CHOOSER_REQUEST
     1264WEBKIT_IS_COLOR_CHOOSER_REQUEST
     1265WEBKIT_COLOR_CHOOSER_REQUEST_CLASS
     1266WEBKIT_IS_COLOR_CHOOSER_REQUEST_CLASS
     1267WEBKIT_COLOR_CHOOSER_REQUEST_GET_CLASS
     1268
     1269<SUBSECTION Private>
     1270WebKitColorChooserRequestPrivate
     1271webkit_color_chooser_request_get_type
     1272</SECTION>
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml

    r176952 r179984  
    3434    <xi:include href="xml/WebKitError.xml"/>
    3535    <xi:include href="xml/WebKitFaviconDatabase.xml"/>
     36    <xi:include href="xml/WebKitColorChooserRequest.xml"/>
    3637    <xi:include href="xml/WebKitFileChooserRequest.xml"/>
    3738    <xi:include href="xml/WebKitFindController.xml"/>
  • trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h

    r177073 r179984  
    4242#include <webkit2/WebKitError.h>
    4343#include <webkit2/WebKitFaviconDatabase.h>
     44#include <webkit2/WebKitColorChooserRequest.h>
    4445#include <webkit2/WebKitFileChooserRequest.h>
    4546#include <webkit2/WebKitFindController.h>
  • trunk/Tools/ChangeLog

    r179946 r179984  
     12015-02-12  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add API to allow overriding the default color chooser implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=98935
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        Add a color chooser implementation for MiniBrowser using
     9        GtkPopover when the GTK+ version is recent enough.
     10        And a test case to check the new color chooser API.
     11
     12        * MiniBrowser/gtk/BrowserWindow.c:
     13        (colorChooserRGBAChanged):
     14        (popoverColorClosed):
     15        (colorChooserRequestFinished):
     16        (runColorChooserCallback):
     17        (browserWindowConstructed):
     18        * TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp:
     19        (testWebViewColorChooserRequest):
     20        (beforeAll):
     21
    1222015-02-11  Csaba Osztrogonác  <ossy@webkit.org>
    223
  • trunk/Tools/MiniBrowser/gtk/BrowserWindow.c

    r179474 r179984  
    502502}
    503503
     504#if GTK_CHECK_VERSION(3, 12, 0)
     505static void colorChooserRGBAChanged(GtkColorChooser *colorChooser, GParamSpec *paramSpec, WebKitColorChooserRequest *request)
     506{
     507    GdkRGBA rgba;
     508    gtk_color_chooser_get_rgba(colorChooser, &rgba);
     509    webkit_color_chooser_request_set_rgba(request, &rgba);
     510}
     511
     512static void popoverColorClosed(GtkWidget *popover, WebKitColorChooserRequest *request)
     513{
     514    webkit_color_chooser_request_finish(request);
     515}
     516
     517static void colorChooserRequestFinished(WebKitColorChooserRequest *request, GtkWidget *popover)
     518{
     519    g_object_unref(request);
     520    gtk_widget_destroy(popover);
     521}
     522
     523static gboolean runColorChooserCallback(WebKitWebView *webView, WebKitColorChooserRequest *request, BrowserWindow *window)
     524{
     525    GtkWidget *popover = gtk_popover_new(GTK_WIDGET(webView));
     526
     527    GdkRectangle rectangle;
     528    webkit_color_chooser_request_get_element_rectangle(request, &rectangle);
     529    gtk_popover_set_pointing_to(GTK_POPOVER(popover), &rectangle);
     530
     531    GtkWidget *colorChooser = gtk_color_chooser_widget_new();
     532    GdkRGBA rgba;
     533    webkit_color_chooser_request_get_rgba(request, &rgba);
     534    gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(colorChooser), &rgba);
     535    g_signal_connect(colorChooser, "notify::rgba", G_CALLBACK(colorChooserRGBAChanged), request);
     536    gtk_container_add(GTK_CONTAINER(popover), colorChooser);
     537    gtk_widget_show(colorChooser);
     538
     539    g_object_ref(request);
     540    g_signal_connect_object(popover, "hide", G_CALLBACK(popoverColorClosed), request, 0);
     541    g_signal_connect_object(request, "finished", G_CALLBACK(colorChooserRequestFinished), popover, 0);
     542
     543    gtk_widget_show(popover);
     544
     545    return TRUE;
     546}
     547#endif /* GTK_CHECK_VERSION(3, 12, 0) */
     548
    504549static void browserWindowUpdateZoomActions(BrowserWindow *window)
    505550{
     
    839884    g_signal_connect(window->webView, "notify::is-loading", G_CALLBACK(webViewIsLoadingChanged), window);
    840885    g_signal_connect(window->webView, "scroll-event", G_CALLBACK(scrollEventCallback), window);
     886#if GTK_CHECK_VERSION(3, 12, 0)
     887    g_signal_connect(window->webView, "run-color-chooser", G_CALLBACK(runColorChooserCallback), window);
     888#endif
    841889
    842890    g_signal_connect(webkit_web_view_get_context(window->webView), "download-started", G_CALLBACK(downloadStarted), window);
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp

    r176952 r179984  
    858858}
    859859
     860class ColorChooserTest: public WebViewTest {
     861public:
     862    MAKE_GLIB_TEST_FIXTURE(ColorChooserTest);
     863
     864    static gboolean runColorChooserCallback(WebKitWebView*, WebKitColorChooserRequest* request, ColorChooserTest* test)
     865    {
     866        test->runColorChooser(request);
     867        return TRUE;
     868    }
     869
     870    static void requestFinishedCallback(WebKitColorChooserRequest* request, ColorChooserTest* test)
     871    {
     872        g_assert(test->m_request.get() == request);
     873        test->m_request = nullptr;
     874        if (g_main_loop_is_running(test->m_mainLoop))
     875            g_main_loop_quit(test->m_mainLoop);
     876    }
     877
     878    ColorChooserTest()
     879    {
     880        g_signal_connect(m_webView, "run-color-chooser", G_CALLBACK(runColorChooserCallback), this);
     881    }
     882
     883    void runColorChooser(WebKitColorChooserRequest* request)
     884    {
     885        g_assert(WEBKIT_IS_COLOR_CHOOSER_REQUEST(request));
     886        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request));
     887        m_request = request;
     888        g_signal_connect(request, "finished", G_CALLBACK(requestFinishedCallback), this);
     889        g_main_loop_quit(m_mainLoop);
     890    }
     891
     892    void finishRequest()
     893    {
     894        g_assert(m_request.get());
     895        webkit_color_chooser_request_finish(m_request.get());
     896        g_assert(!m_request);
     897    }
     898
     899    void cancelRequest()
     900    {
     901        g_assert(m_request.get());
     902        webkit_color_chooser_request_cancel(m_request.get());
     903        g_assert(!m_request);
     904    }
     905
     906    WebKitColorChooserRequest* clickMouseButtonAndWaitForColorChooserRequest(int x, int y)
     907    {
     908        clickMouseButton(x, y);
     909        g_main_loop_run(m_mainLoop);
     910        g_assert(m_request.get());
     911        return m_request.get();
     912    }
     913
     914private:
     915    GRefPtr<WebKitColorChooserRequest> m_request;
     916};
     917
     918static void testWebViewColorChooserRequest(ColorChooserTest* test, gconstpointer)
     919{
     920    static const char* colorChooserHTMLFormat = "<html><body><input style='position:absolute;left:1;top:1;margin:0;padding:0;width:45;height:25' type='color' %s/></body></html>";
     921    test->showInWindowAndWaitUntilMapped();
     922
     923    GUniquePtr<char> defaultColorHTML(g_strdup_printf(colorChooserHTMLFormat, ""));
     924    test->loadHtml(defaultColorHTML.get(), nullptr);
     925    test->waitUntilLoadFinished();
     926    WebKitColorChooserRequest* request = test->clickMouseButtonAndWaitForColorChooserRequest(5, 5);
     927
     928    // Default color is black (#000000).
     929    GdkRGBA rgba1;
     930    GdkRGBA rgba2 = { 0., 0., 0., 1. };
     931    webkit_color_chooser_request_get_rgba(request, &rgba1);
     932    g_assert(gdk_rgba_equal(&rgba1, &rgba2));
     933
     934    // Set a different color.
     935    rgba2.green = 1;
     936    webkit_color_chooser_request_set_rgba(request, &rgba2);
     937    webkit_color_chooser_request_get_rgba(request, &rgba1);
     938    g_assert(gdk_rgba_equal(&rgba1, &rgba2));
     939
     940    GdkRectangle rect;
     941    webkit_color_chooser_request_get_element_rectangle(request, &rect);
     942    g_assert_cmpint(rect.x, == , 1);
     943    g_assert_cmpint(rect.y, == , 1);
     944    g_assert_cmpint(rect.width, == , 45);
     945    g_assert_cmpint(rect.height, == , 25);
     946
     947    test->finishRequest();
     948
     949    // Use an initial color.
     950    GUniquePtr<char> initialColorHTML(g_strdup_printf(colorChooserHTMLFormat, "value='#FF00FF'"));
     951    test->loadHtml(initialColorHTML.get(), nullptr);
     952    test->waitUntilLoadFinished();
     953    request = test->clickMouseButtonAndWaitForColorChooserRequest(5, 5);
     954
     955    webkit_color_chooser_request_get_rgba(request, &rgba1);
     956    GdkRGBA rgba3 = { 1., 0., 1., 1. };
     957    g_assert(gdk_rgba_equal(&rgba1, &rgba3));
     958
     959    test->cancelRequest();
     960}
     961
    860962void beforeAll()
    861963{
     
    871973    UIClientTest::add("WebKitWebView", "audio-usermedia-permission-request", testWebViewAudioOnlyUserMediaPermissionRequests);
    872974    FileChooserTest::add("WebKitWebView", "file-chooser-request", testWebViewFileChooserRequest);
     975    ColorChooserTest::add("WebKitWebView", "color-chooser-request", testWebViewColorChooserRequest);
    873976}
    874977
Note: See TracChangeset for help on using the changeset viewer.