Changeset 179984 in webkit
- Timestamp:
- Feb 12, 2015 12:50:00 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r179975 r179984 1 2015-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 1 54 2015-02-11 Enrica Casucci <enrica@apple.com> 2 55 -
trunk/Source/WebKit2/PlatformGTK.cmake
r179922 r179984 102 102 UIProcess/API/gtk/WebKitBackForwardListItem.h 103 103 UIProcess/API/gtk/WebKitBackForwardListPrivate.h 104 UIProcess/API/gtk/WebKitColorChooser.cpp 105 UIProcess/API/gtk/WebKitColorChooserRequest.cpp 104 106 UIProcess/API/gtk/WebKitContextMenu.cpp 105 107 UIProcess/API/gtk/WebKitContextMenu.h … … 348 350 ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitBackForwardList.h 349 351 ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitBackForwardListItem.h 352 ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitColorChooserRequest.h 350 353 ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitCredential.h 351 354 ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitContextMenu.h -
trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp
r179922 r179984 36 36 #include "WebContextMenuProxyGtk.h" 37 37 #include "WebEventFactory.h" 38 #include "WebKitColorChooser.h" 39 #include "WebKitWebView.h" 38 40 #include "WebKitWebViewBasePrivate.h" 39 41 #include "WebPageProxy.h" … … 227 229 } 228 230 229 #if ENABLE(INPUT_TYPE_COLOR)230 231 PassRefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy* page, const WebCore::Color& color, const WebCore::IntRect& rect) 231 232 { 233 if (WEBKIT_IS_WEB_VIEW(m_viewWidget)) 234 return WebKitColorChooser::create(*page, color, rect); 232 235 return WebColorPickerGtk::create(*page, color, rect); 233 236 } 234 #endif235 237 236 238 void PageClientImpl::setTextIndicator(PassRefPtr<WebCore::TextIndicator>, bool /* fadeOut */) -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
r179745 r179984 133 133 SHOW_NOTIFICATION, 134 134 135 RUN_COLOR_CHOOSER, 136 135 137 LAST_SIGNAL 136 138 }; … … 1715 1717 G_TYPE_BOOLEAN, 1, 1716 1718 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 <input 1726 * type='color' /> 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); 1717 1753 } 1718 1754 … … 2089 2125 gboolean handled; 2090 2126 g_signal_emit(webView, signals[SHOW_NOTIFICATION], 0, webNotification, &handled); 2127 return handled; 2128 } 2129 2130 bool webkitWebViewEmitRunColorChooser(WebKitWebView* webView, WebKitColorChooserRequest* request) 2131 { 2132 gboolean handled; 2133 g_signal_emit(webView, signals[RUN_COLOR_CHOOSER], 0, request, &handled); 2091 2134 return handled; 2092 2135 } -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h
r179745 r179984 33 33 #include <webkit2/WebKitBackForwardList.h> 34 34 #include <webkit2/WebKitDefines.h> 35 #include <webkit2/WebKitColorChooserRequest.h> 35 36 #include <webkit2/WebKitFileChooserRequest.h> 36 37 #include <webkit2/WebKitFindController.h> … … 245 246 gboolean (* show_notification) (WebKitWebView *web_view, 246 247 WebKitNotification *notification); 248 gboolean (* run_color_chooser) (WebKitWebView *web_view, 249 WebKitColorChooserRequest *request); 247 250 248 251 void (*_webkit_reserved0) (void); … … 250 253 void (*_webkit_reserved2) (void); 251 254 void (*_webkit_reserved3) (void); 252 void (*_webkit_reserved4) (void);253 255 }; 254 256 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h
r179745 r179984 60 60 void webkitWebViewInsecureContentDetected(WebKitWebView*, WebKitInsecureContentEvent); 61 61 bool webkitWebViewEmitShowNotification(WebKitWebView*, WebKitNotification*); 62 bool webkitWebViewEmitRunColorChooser(WebKitWebView*, WebKitColorChooserRequest*); 62 63 void webkitWebViewWebProcessCrashed(WebKitWebView*); 63 64 void webkitWebViewIsPlayingAudioChanged(WebKitWebView*); -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt
r179745 r179984 1248 1248 webkit_web_hit_test_result_get_type 1249 1249 </SECTION> 1250 1251 <SECTION> 1252 <FILE>WebKitColorChooserRequest</FILE> 1253 WebKitColorChooserRequest 1254 webkit_color_chooser_request_get_rgba 1255 webkit_color_chooser_request_set_rgba 1256 webkit_color_chooser_request_get_element_rectangle 1257 webkit_color_chooser_request_finish 1258 webkit_color_chooser_request_cancel 1259 1260 <SUBSECTION Standard> 1261 WebKitColorChooserRequestClass 1262 WEBKIT_TYPE_COLOR_CHOOSER_REQUEST 1263 WEBKIT_COLOR_CHOOSER_REQUEST 1264 WEBKIT_IS_COLOR_CHOOSER_REQUEST 1265 WEBKIT_COLOR_CHOOSER_REQUEST_CLASS 1266 WEBKIT_IS_COLOR_CHOOSER_REQUEST_CLASS 1267 WEBKIT_COLOR_CHOOSER_REQUEST_GET_CLASS 1268 1269 <SUBSECTION Private> 1270 WebKitColorChooserRequestPrivate 1271 webkit_color_chooser_request_get_type 1272 </SECTION> -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml
r176952 r179984 34 34 <xi:include href="xml/WebKitError.xml"/> 35 35 <xi:include href="xml/WebKitFaviconDatabase.xml"/> 36 <xi:include href="xml/WebKitColorChooserRequest.xml"/> 36 37 <xi:include href="xml/WebKitFileChooserRequest.xml"/> 37 38 <xi:include href="xml/WebKitFindController.xml"/> -
trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h
r177073 r179984 42 42 #include <webkit2/WebKitError.h> 43 43 #include <webkit2/WebKitFaviconDatabase.h> 44 #include <webkit2/WebKitColorChooserRequest.h> 44 45 #include <webkit2/WebKitFileChooserRequest.h> 45 46 #include <webkit2/WebKitFindController.h> -
trunk/Tools/ChangeLog
r179946 r179984 1 2015-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 1 22 2015-02-11 Csaba Osztrogonác <ossy@webkit.org> 2 23 -
trunk/Tools/MiniBrowser/gtk/BrowserWindow.c
r179474 r179984 502 502 } 503 503 504 #if GTK_CHECK_VERSION(3, 12, 0) 505 static 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 512 static void popoverColorClosed(GtkWidget *popover, WebKitColorChooserRequest *request) 513 { 514 webkit_color_chooser_request_finish(request); 515 } 516 517 static void colorChooserRequestFinished(WebKitColorChooserRequest *request, GtkWidget *popover) 518 { 519 g_object_unref(request); 520 gtk_widget_destroy(popover); 521 } 522 523 static 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 504 549 static void browserWindowUpdateZoomActions(BrowserWindow *window) 505 550 { … … 839 884 g_signal_connect(window->webView, "notify::is-loading", G_CALLBACK(webViewIsLoadingChanged), window); 840 885 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 841 889 842 890 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 858 858 } 859 859 860 class ColorChooserTest: public WebViewTest { 861 public: 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 914 private: 915 GRefPtr<WebKitColorChooserRequest> m_request; 916 }; 917 918 static 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 860 962 void beforeAll() 861 963 { … … 871 973 UIClientTest::add("WebKitWebView", "audio-usermedia-permission-request", testWebViewAudioOnlyUserMediaPermissionRequests); 872 974 FileChooserTest::add("WebKitWebView", "file-chooser-request", testWebViewFileChooserRequest); 975 ColorChooserTest::add("WebKitWebView", "color-chooser-request", testWebViewColorChooserRequest); 873 976 } 874 977
Note: See TracChangeset
for help on using the changeset viewer.