Changeset 88634 in webkit
- Timestamp:
- Jun 13, 2011 2:35:30 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 added
- 9 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r88632 r88634 1 2011-06-13 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [GTK] Add context menu support for Webkit2 6 https://bugs.webkit.org/show_bug.cgi?id=54827 7 8 * platform/ContextMenuItem.h: Add gtkAction(). 9 * platform/gtk/ContextMenuGtk.cpp: 10 (WebCore::ContextMenu::ContextMenu): Implement constructor that 11 receives a platform menu. 12 (WebCore::ContextMenu::setPlatformDescription): Make sure we don't 13 destroy the menu if the new context menu is the current one. 14 (WebCore::contextMenuItemVector): Implement this method to return 15 the list of menu items in the given context menu, required by WebKit2. 16 (WebCore::platformMenuDescription): Implement this method to 17 return a platform menu for the given menu items. 18 * platform/gtk/ContextMenuItemGtk.cpp: 19 (WebCore::createPlatformMenuItemDescription): Helper function to 20 create a platform context menu item. 21 (WebCore::ContextMenuItem::ContextMenuItem): Use 22 createPlatformMenuItemDescription(). 23 (WebCore::ContextMenuItem::title): Convert the title from UTF-8. 24 (WebCore::ContextMenuItem::setTitle): Use gtkAction(). 25 (WebCore::ContextMenuItem::setSubMenu): Implement setSubMenu() 26 that receives a list of items. 27 (WebCore::ContextMenuItem::setChecked): Use gtkAction(). 28 (WebCore::ContextMenuItem::checked): Implement this, required by WebKit2. 29 (WebCore::ContextMenuItem::enabled): Ditto. 30 (WebCore::ContextMenuItem::setEnabled): Use gtkAction(). 31 (WebCore::ContextMenuItem::gtkAction): Return the GtkAction 32 associated to the context menu item. 33 1 34 2011-06-13 Keishi Hattori <keishi@webkit.org> 2 35 -
trunk/Source/WebCore/platform/ContextMenuItem.h
r80344 r88634 44 44 #elif PLATFORM(GTK) 45 45 typedef struct _GtkMenuItem GtkMenuItem; 46 typedef struct _GtkAction GtkAction; 46 47 #elif PLATFORM(QT) 47 48 #include <QAction> … … 249 250 void setSubMenu(ContextMenu*); 250 251 252 #if PLATFORM(GTK) 253 GtkAction* gtkAction() const; 254 #endif 255 251 256 #if USE(CROSS_PLATFORM_CONTEXT_MENUS) 252 257 #if PLATFORM(WIN) -
trunk/Source/WebCore/platform/gtk/ContextMenuGtk.cpp
r75481 r88634 21 21 #include "ContextMenu.h" 22 22 23 #include " NotImplemented.h"23 #include "GOwnPtr.h" 24 24 #include <gtk/gtk.h> 25 25 … … 29 29 { 30 30 m_platformDescription = GTK_MENU(gtk_menu_new()); 31 } 32 33 ContextMenu::ContextMenu(const PlatformMenuDescription menu) 34 : m_platformDescription(menu) 35 { 31 36 } 32 37 … … 50 55 { 51 56 ASSERT(menu); 57 if (m_platformDescription == menu) 58 return; 52 59 if (m_platformDescription) 53 60 gtk_widget_destroy(GTK_WIDGET(m_platformDescription)); … … 69 76 } 70 77 71 Vector<ContextMenuItem> contextMenuItemVector(const PlatformMenuDescription )78 Vector<ContextMenuItem> contextMenuItemVector(const PlatformMenuDescription menu) 72 79 { 73 notImplemented();80 Vector<ContextMenuItem> menuItemVector; 74 81 75 Vector<ContextMenuItem> menuItemVector; 82 GOwnPtr<GList> children(gtk_container_get_children(GTK_CONTAINER(menu))); 83 int itemCount = g_list_length(children.get()); 84 menuItemVector.reserveCapacity(itemCount); 85 86 for (GList* item = children.get(); item; item = g_list_next(item)) { 87 GtkWidget* widget = static_cast<GtkWidget*>(item->data); 88 if (!GTK_IS_MENU_ITEM(widget)) 89 continue; 90 menuItemVector.append(ContextMenuItem(GTK_MENU_ITEM(widget))); 91 } 92 76 93 return menuItemVector; 77 94 } 78 95 96 PlatformMenuDescription platformMenuDescription(Vector<ContextMenuItem>& subMenuItems) 97 { 98 GtkMenu* menu = GTK_MENU(gtk_menu_new()); 99 for (size_t i = 0; i < subMenuItems.size(); i++) { 100 GtkWidget* platformItem = GTK_WIDGET(subMenuItems[i].releasePlatformDescription()); 101 gtk_menu_shell_append(GTK_MENU_SHELL(menu), platformItem); 102 gtk_widget_show(platformItem); 103 } 104 return menu; 79 105 } 106 107 } -
trunk/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp
r80344 r88634 25 25 #include "ContextMenu.h" 26 26 #include "GOwnPtr.h" 27 #include " NotImplemented.h"27 #include "GRefPtr.h" 28 28 #include <gtk/gtk.h> 29 29 #include <wtf/text/CString.h> … … 118 118 } 119 119 120 static PlatformMenuItemDescription createPlatformMenuItemDescription(ContextMenuItemType type, ContextMenuAction action, const String& title, bool enabled, bool checked) 121 { 122 if (type == SeparatorType) 123 return GTK_MENU_ITEM(gtk_separator_menu_item_new()); 124 125 GOwnPtr<char> actionName(g_strdup_printf("context-menu-action-%d", action)); 126 GRefPtr<GtkAction> platformAction; 127 128 if (type == CheckableActionType) { 129 platformAction = adoptGRef(GTK_ACTION(gtk_toggle_action_new(actionName.get(), title.utf8().data(), 0, gtkStockIDFromContextMenuAction(action)))); 130 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(platformAction.get()), checked); 131 } else 132 platformAction = adoptGRef(gtk_action_new(actionName.get(), title.utf8().data(), 0, gtkStockIDFromContextMenuAction(action))); 133 gtk_action_set_sensitive(platformAction.get(), enabled); 134 135 GtkMenuItem* item = GTK_MENU_ITEM(gtk_action_create_menu_item(platformAction.get())); 136 g_object_set_data(G_OBJECT(item), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action)); 137 138 return item; 139 } 140 120 141 // Extract the ActionType from the menu item 121 142 ContextMenuItem::ContextMenuItem(PlatformMenuItemDescription item) … … 124 145 } 125 146 126 ContextMenuItem::ContextMenuItem(ContextMenu*) 127 { 128 notImplemented(); 129 } 130 131 ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu) 132 { 133 if (type == SeparatorType) { 134 m_platformDescription = GTK_MENU_ITEM(gtk_separator_menu_item_new()); 135 return; 136 } 137 138 GOwnPtr<char> actionName(g_strdup_printf("context-menu-action-%d", action)); 139 GtkAction* platformAction = 0; 140 141 if (type == CheckableActionType) 142 platformAction = GTK_ACTION(gtk_toggle_action_new(actionName.get(), title.utf8().data(), 0, gtkStockIDFromContextMenuAction(action))); 143 else 144 platformAction = gtk_action_new(actionName.get(), title.utf8().data(), 0, gtkStockIDFromContextMenuAction(action)); 145 146 m_platformDescription = GTK_MENU_ITEM(gtk_action_create_menu_item(platformAction)); 147 g_object_unref(platformAction); 148 149 g_object_set_data(G_OBJECT(m_platformDescription), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action)); 150 147 ContextMenuItem::ContextMenuItem(ContextMenu* subMenu) 148 { 149 m_platformDescription = GTK_MENU_ITEM(gtk_menu_item_new()); 151 150 if (subMenu) 152 151 setSubMenu(subMenu); 153 152 } 154 153 155 ContextMenuItem::ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool, bool) 156 { 157 // FIXME: Implement with WebKit2 ContextMenu changes. 158 notImplemented(); 159 } 160 161 ContextMenuItem::ContextMenuItem(ContextMenuAction, const String&, bool, bool, Vector<ContextMenuItem>&) 162 { 163 // FIXME: Implement with WebKit2 ContextMenu changes. 164 notImplemented(); 154 ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu) 155 { 156 m_platformDescription = createPlatformMenuItemDescription(type, action, title, true, false); 157 if (subMenu) 158 setSubMenu(subMenu); 159 } 160 161 ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, bool enabled, bool checked) 162 { 163 m_platformDescription = createPlatformMenuItemDescription(type, action, title, enabled, checked); 164 } 165 166 ContextMenuItem::ContextMenuItem(ContextMenuAction action, const String& title, bool enabled, bool checked, Vector<ContextMenuItem>& subMenuItems) 167 { 168 m_platformDescription = createPlatformMenuItemDescription(SubmenuType, action, title, enabled, checked); 169 setSubMenu(subMenuItems); 165 170 } 166 171 … … 205 210 String ContextMenuItem::title() const 206 211 { 207 GtkAction* action = gtk _activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));208 return action ? String (gtk_action_get_label(action)) : String();212 GtkAction* action = gtkAction(); 213 return action ? String::fromUTF8(gtk_action_get_label(action)) : String(); 209 214 } 210 215 211 216 void ContextMenuItem::setTitle(const String& title) 212 217 { 213 GtkAction* action = gtk _activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));218 GtkAction* action = gtkAction(); 214 219 if (action) 215 220 gtk_action_set_label(action, title.utf8().data()); … … 224 229 void ContextMenuItem::setSubMenu(ContextMenu* menu) 225 230 { 226 gtk_menu_item_set_submenu(m_platformDescription, GTK_WIDGET(menu->platformDescription())); 231 gtk_menu_item_set_submenu(m_platformDescription, GTK_WIDGET(menu->releasePlatformDescription())); 232 } 233 234 void ContextMenuItem::setSubMenu(Vector<ContextMenuItem>& subMenuItems) 235 { 236 ContextMenu menu(platformMenuDescription(subMenuItems)); 237 setSubMenu(&menu); 227 238 } 228 239 229 240 void ContextMenuItem::setChecked(bool shouldCheck) 230 241 { 231 GtkAction* action = gtk _activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));242 GtkAction* action = gtkAction(); 232 243 if (action && GTK_IS_TOGGLE_ACTION(action)) 233 244 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), shouldCheck); … … 236 247 bool ContextMenuItem::checked() const 237 248 { 238 // FIXME: Implement with WebKit2 ContextMenu changes. 239 notImplemented(); 249 GtkAction* action = gtkAction(); 250 if (action && GTK_IS_TOGGLE_ACTION(action)) 251 return gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)); 240 252 return false; 241 253 } … … 243 255 bool ContextMenuItem::enabled() const 244 256 { 245 // FIXME: Implement with WebKit2 ContextMenu changes. 246 notImplemented(); 247 return false; 257 GtkAction* action = gtkAction(); 258 return action ? gtk_action_get_sensitive(action) : false; 248 259 } 249 260 250 261 void ContextMenuItem::setEnabled(bool shouldEnable) 251 262 { 252 GtkAction* action = gtk _activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));263 GtkAction* action = gtkAction(); 253 264 if (action) 254 265 gtk_action_set_sensitive(action, shouldEnable); 255 266 } 256 267 257 } 268 GtkAction* ContextMenuItem::gtkAction() const 269 { 270 return gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription)); 271 } 272 273 } -
trunk/Source/WebKit2/ChangeLog
r88631 r88634 1 2011-06-13 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [GTK] Add context menu support for Webkit2 6 https://bugs.webkit.org/show_bug.cgi?id=54827 7 8 * GNUmakefile.am: Add new files to compilation. 9 * UIProcess/API/gtk/PageClientImpl.cpp: 10 (WebKit::PageClientImpl::createContextMenuProxy): Create a context 11 menu proxy. 12 * UIProcess/API/gtk/WebKitWebViewBase.cpp: 13 (globalPointForClientPoint): Function copied from webkit1 to 14 convert a point in widget coordinates to global coordinates. 15 (popupMenuPositionFunction): 16 (webkitWebViewBaseShowContextMenu): Show the given context menu at 17 the given position. 18 * UIProcess/API/gtk/WebKitWebViewBasePrivate.h: 19 * UIProcess/gtk/WebContextMenuProxyGtk.cpp: Added. 20 (WebKit::contextMenuItemActivatedCallback): 21 (WebKit::WebContextMenuProxyGtk::createGtkMenu): 22 (WebKit::WebContextMenuProxyGtk::showContextMenu): 23 (WebKit::WebContextMenuProxyGtk::hideContextMenu): 24 (WebKit::WebContextMenuProxyGtk::WebContextMenuProxyGtk): 25 (WebKit::WebContextMenuProxyGtk::~WebContextMenuProxyGtk): 26 * UIProcess/gtk/WebContextMenuProxyGtk.h: Copied from Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h. 27 (WebKit::WebContextMenuProxyGtk::create): 28 1 29 2011-06-13 Carlos Garcia Campos <cgarcia@igalia.com> 2 30 -
trunk/Source/WebKit2/GNUmakefile.am
r88631 r88634 395 395 Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp \ 396 396 Source/WebKit2/UIProcess/gtk/WebContextGtk.cpp \ 397 Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp \ 398 Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h \ 397 399 Source/WebKit2/UIProcess/gtk/WebFullScreenManagerProxyGtk.cpp \ 398 400 Source/WebKit2/UIProcess/gtk/WebInspectorGtk.cpp \ -
trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp
r87930 r88634 34 34 #include "NotImplemented.h" 35 35 #include "WebContext.h" 36 #include "WebContextMenuProxy .h"36 #include "WebContextMenuProxyGtk.h" 37 37 #include "WebEventFactory.h" 38 38 #include "WebKitWebViewBasePrivate.h" … … 211 211 } 212 212 213 PassRefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy*) 214 { 215 notImplemented(); 216 return 0; 213 PassRefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy* page) 214 { 215 return WebContextMenuProxyGtk::create(m_viewWidget, page); 217 216 } 218 217 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp
r88631 r88634 57 57 GtkClickCounter clickCounter; 58 58 CString tooltipText; 59 IntPoint lastPopupPosition; 59 60 }; 60 61 … … 379 380 #endif 380 381 } 382 383 static IntPoint globalPointForClientPoint(GdkWindow* window, const IntPoint& clientPoint) 384 { 385 int x, y; 386 gdk_window_get_origin(window, &x, &y); 387 return clientPoint + IntSize(x, y); 388 } 389 390 static void popupMenuPositionFunction(GtkMenu* menu, gint* x, gint* y, gboolean* pushIn, gpointer userData) 391 { 392 WebKitWebViewBase* view = WEBKIT_WEB_VIEW_BASE(userData); 393 WebKitWebViewBasePrivate* priv = view->priv; 394 GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(view)); 395 GtkRequisition menuSize; 396 397 #ifdef GTK_API_VERSION_2 398 gtk_widget_size_request(GTK_WIDGET(menu), &menuSize); 399 #else 400 gtk_widget_get_preferred_size(GTK_WIDGET(menu), &menuSize, 0); 401 #endif 402 403 *x = priv->lastPopupPosition.x(); 404 if ((*x + menuSize.width) >= gdk_screen_get_width(screen)) 405 *x -= menuSize.width; 406 407 *y = priv->lastPopupPosition.y(); 408 if ((*y + menuSize.height) >= gdk_screen_get_height(screen)) 409 *y -= menuSize.height; 410 411 *pushIn = FALSE; 412 } 413 414 void webkitWebViewBaseShowContextMenu(WebKitWebViewBase* webViewBase, GtkMenu* menu, const IntPoint& position) 415 { 416 webViewBase->priv->lastPopupPosition = globalPointForClientPoint(gtk_widget_get_window(GTK_WIDGET(webViewBase)), position); 417 418 // Display menu initiated by right click (mouse button pressed = 3). 419 gtk_menu_popup(menu, 0, 0, &popupMenuPositionFunction, webViewBase, 3, gtk_get_current_event_time()); 420 } -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h
r88631 r88634 47 47 void webkitWebViewBaseSetTooltipText(WebKitWebViewBase*, const char*); 48 48 49 void webkitWebViewBaseShowContextMenu(WebKitWebViewBase*, GtkMenu*, const WebCore::IntPoint&); 50 49 51 G_END_DECLS 50 52 -
trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h
r88633 r88634 1 1 /* 2 * Copyright (C) 2010 Apple Inc. All rights reserved.3 * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.4 2 * Copyright (C) 2011 Igalia S.L. 5 3 * … … 13 11 * documentation and/or other materials provided with the distribution. 14 12 * 15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS AS IS'' 16 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 17 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR … … 26 24 */ 27 25 28 #ifndef Web KitWebViewBasePrivate_h29 #define Web KitWebViewBasePrivate_h26 #ifndef WebContextMenuProxyGtk_h 27 #define WebContextMenuProxyGtk_h 30 28 31 #include "WebKitWebViewBase.h" 32 #include "WebPageProxy.h" 33 #include <WebKit2/WebKit2.h> 29 #include "WebContextMenuProxy.h" 34 30 35 using namespace WebKit; 31 namespace WebKit { 36 32 37 G_BEGIN_DECLS 33 class WebContextMenuItemData; 34 class WebPageProxy; 38 35 39 WebKitWebViewBase* webkitWebViewBaseCreate(WebContext*, WebPageGroup*); 36 class WebContextMenuProxyGtk : public WebContextMenuProxy { 37 public: 38 static PassRefPtr<WebContextMenuProxyGtk> create(GtkWidget* webView, WebPageProxy* page) 39 { 40 return adoptRef(new WebContextMenuProxyGtk(webView, page)); 41 } 42 ~WebContextMenuProxyGtk(); 40 43 41 GtkIMContext* webkitWebViewBaseGetIMContext(WebKitWebViewBase*); 44 virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&); 45 virtual void hideContextMenu(); 42 46 43 WebPageProxy* webkitWebViewBaseGetPage(WebKitWebViewBase*); 47 private: 48 WebContextMenuProxyGtk(GtkWidget*, WebPageProxy*); 49 GtkMenu* createGtkMenu(const Vector<WebContextMenuItemData>&); 44 50 45 void webkitWebViewBaseCreateWebPage(WebKitWebViewBase*, WKContextRef, WKPageGroupRef); 51 GtkWidget* m_webView; 52 WebPageProxy* m_page; 53 }; 46 54 47 void webkitWebViewBaseSetTooltipText(WebKitWebViewBase*, const char*);48 55 49 G_END_DECLS 56 } // namespace WebKit 50 57 51 #endif // Web KitWebViewBasePrivate_h58 #endif // WebContextMenuProxyGtk_h
Note: See TracChangeset
for help on using the changeset viewer.