[GTK] Add API to allow overriding popup menus
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Jun 2017 09:41:27 +0000 (09:41 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Jun 2017 09:41:27 +0000 (09:41 +0000)
commitd437ecefb40403ac6fa7ed53ffef9b71b27a1f58
treeb358e548902b3e5df0cab08ad316d2e1e872c2e6
parent631bb89e9960657b14006731f344fbddd792673e
[GTK] Add API to allow overriding popup menus
https://bugs.webkit.org/show_bug.cgi?id=172905

Reviewed by Michael Catanzaro.

Source/WebKit2:

The GTK+ API uses GTK+ for the default implementation of several UI elements like the file chooser, print dialog,
color picker, context menu, etc. but in all those cases it allows to override the default implementation. It's
not possible to override the popup menu used for select elements. This patch adds WebKitOptionMenu to represent
a select dropdown menu. It's passed as an argument of the new signal WebKitWebView::show-option-menu, and
contains WebKitOptionMenuItem elements representing the items to be displayed.

* PlatformGTK.cmake:
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::createPopupMenuProxy): Create a WebKitPopupMenu.
* UIProcess/API/gtk/WebKitOptionMenu.cpp: Added.
(webkitOptionMenuCreate):
(webkit_option_menu_get_n_items):
(webkit_option_menu_get_item):
(webkit_option_menu_select_item):
(webkit_option_menu_activate_item):
(webkit_option_menu_close):
* UIProcess/API/gtk/WebKitOptionMenu.h: Added.
* UIProcess/API/gtk/WebKitOptionMenuItem.cpp: Added.
(webkit_option_menu_item_copy):
(webkit_option_menu_item_free):
(webkit_option_menu_item_get_label):
(webkit_option_menu_item_get_tooltip):
(webkit_option_menu_item_is_group_label):
(webkit_option_menu_item_is_group_child):
(webkit_option_menu_item_is_enabled):
(webkit_option_menu_item_is_selected):
* UIProcess/API/gtk/WebKitOptionMenuItem.h: Added.
* UIProcess/API/gtk/WebKitOptionMenuItemPrivate.h: Added.
(_WebKitOptionMenuItem::_WebKitOptionMenuItem):
* UIProcess/API/gtk/WebKitOptionMenuPrivate.h: Added.
* UIProcess/API/gtk/WebKitPopupMenu.cpp: Added.
(WebKit::WebKitPopupMenu::WebKitPopupMenu):
(WebKit::menuCloseCallback):
(WebKit::WebKitPopupMenu::showPopupMenu): Call webkitWebViewShowOptionMenu() falling back to default
implementation if the user didn't handle the signal.
(WebKit::WebKitPopupMenu::hidePopupMenu):
(WebKit::WebKitPopupMenu::cancelTracking):
(WebKit::WebKitPopupMenu::selectItem):
(WebKit::WebKitPopupMenu::activateItem):
* UIProcess/API/gtk/WebKitPopupMenu.h: Added.
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkit_web_view_class_init):
(webkitWebViewShowOptionMenu): Emit WebKitWebView::show-option-menu.
* 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-4.0.types: Add new get_type functions.
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new sections.
* UIProcess/API/gtk/webkit2.h: Add new public headers.
* UIProcess/gtk/WebPopupMenuProxyGtk.cpp:
(WebKit::WebPopupMenuProxyGtk::WebPopupMenuProxyGtk): Do not create the GtkMenu in constructor.
(WebKit::WebPopupMenuProxyGtk::showPopupMenu): Create the GtkMenu and connect to the signals here.
(WebKit::WebPopupMenuProxyGtk::hidePopupMenu): Return early if the Gtk hasn't been shown.
* UIProcess/gtk/WebPopupMenuProxyGtk.h: Make constructor and webview protected.

Tools:

Add a unit test to check the new API.

* TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt:
* TestWebKitAPI/Tests/WebKit2Gtk/TestOptionMenu.cpp: Added.
(OptionMenuTest::OptionMenuTest):
(OptionMenuTest::~OptionMenuTest):
(OptionMenuTest::destroyMenu):
(OptionMenuTest::showOptionMenuCallback):
(OptionMenuTest::menuCloseCallback):
(OptionMenuTest::showOptionMenu):
(OptionMenuTest::clickAtPositionAndWaitUntilOptionMenuShown):
(OptionMenuTest::close):
(OptionMenuTest::activateItem):
(OptionMenuTest::selectItem):
(testOptionMenuSimple):
(testOptionMenuGroups):
(testOptionMenuActivate):
(testOptionMenuSelect):
(beforeAll):
(afterAll):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218325 268f45cc-cd09-0410-ab3c-d52691b4dbfc
23 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitOptionMenu.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitOptionMenu.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitOptionMenuItem.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitOptionMenuItem.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitOptionMenuItemPrivate.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitOptionMenuPrivate.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitPopupMenu.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitPopupMenu.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h
Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0.types
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml
Source/WebKit2/UIProcess/API/gtk/webkit2.h
Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.cpp
Source/WebKit2/UIProcess/gtk/WebPopupMenuProxyGtk.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestOptionMenu.cpp [new file with mode: 0644]