Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/gtk/bookmark_menu_controller_gtk.cc

Issue 164183: GTK: Make the bookmark bar folder menus dismiss properly.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: don't leak Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/bookmark_menu_controller_gtk.h" 5 #include "chrome/browser/gtk/bookmark_menu_controller_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 30 matching lines...) Expand all
41 41
42 const BookmarkNode* GetParentNodeFromEmptyMenu(GtkWidget* menu) { 42 const BookmarkNode* GetParentNodeFromEmptyMenu(GtkWidget* menu) {
43 return static_cast<const BookmarkNode*>( 43 return static_cast<const BookmarkNode*>(
44 g_object_get_data(G_OBJECT(menu), "parent-node")); 44 g_object_get_data(G_OBJECT(menu), "parent-node"));
45 } 45 }
46 46
47 void* AsVoid(const BookmarkNode* node) { 47 void* AsVoid(const BookmarkNode* node) {
48 return const_cast<BookmarkNode*>(node); 48 return const_cast<BookmarkNode*>(node);
49 } 49 }
50 50
51 // The context menu has been dismissed, restore the X and application grabs
52 // to whichever menu last had them. (Assuming that menu is still showing.)
53 // The event mask in this function is taken from gtkmenu.c.
54 void OnContextMenuHide(GtkWidget* context_menu, GtkWidget* grab_menu) {
55 guint time = gtk_get_current_event_time();
56
57 if (GTK_WIDGET_VISIBLE(grab_menu)) {
58 if (!gdk_pointer_grab(grab_menu->window, TRUE,
59 GdkEventMask(
60 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
61 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
62 GDK_POINTER_MOTION_MASK), NULL, NULL, time) == 0) {
63 g_object_unref(grab_menu);
64 return;
65 }
66 if (!gdk_keyboard_grab(grab_menu->window, TRUE, time) == 0) {
67 gdk_display_pointer_ungrab(gdk_drawable_get_display(grab_menu->window),
68 time);
69 g_object_unref(grab_menu);
70 return;
71 }
72 gtk_grab_add(grab_menu);
73 }
74
75 // Match the ref we took when connecting this signal.
76 g_object_unref(grab_menu);
77 }
78
51 } // namespace 79 } // namespace
52 80
53 BookmarkMenuController::BookmarkMenuController(Browser* browser, 81 BookmarkMenuController::BookmarkMenuController(Browser* browser,
54 Profile* profile, 82 Profile* profile,
55 PageNavigator* navigator, 83 PageNavigator* navigator,
56 GtkWindow* window, 84 GtkWindow* window,
57 const BookmarkNode* node, 85 const BookmarkNode* node,
58 int start_child_index, 86 int start_child_index,
59 bool show_other_folder) 87 bool show_other_folder)
60 : browser_(browser), 88 : browser_(browser),
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 237
210 // Show the right click menu and stop processing this button event. 238 // Show the right click menu and stop processing this button event.
211 std::vector<const BookmarkNode*> nodes; 239 std::vector<const BookmarkNode*> nodes;
212 if (node) 240 if (node)
213 nodes.push_back(node); 241 nodes.push_back(node);
214 controller->context_menu_.reset( 242 controller->context_menu_.reset(
215 new BookmarkContextMenu( 243 new BookmarkContextMenu(
216 sender, controller->profile_, controller->browser_, 244 sender, controller->profile_, controller->browser_,
217 controller->page_navigator_, parent, nodes, 245 controller->page_navigator_, parent, nodes,
218 BookmarkContextMenu::BOOKMARK_BAR)); 246 BookmarkContextMenu::BOOKMARK_BAR));
247
248 // Our bookmark folder menu loses the grab to the context menu. When the
249 // context menu is hidden, re-assert our grab.
250 GtkWidget* grabbing_menu = gtk_grab_get_current();
251 g_object_ref(grabbing_menu);
252 g_signal_connect(controller->context_menu_->menu(), "hide",
253 G_CALLBACK(OnContextMenuHide), grabbing_menu);
254
219 controller->context_menu_->PopupAsContext(event->time); 255 controller->context_menu_->PopupAsContext(event->time);
220 return TRUE; 256 return TRUE;
221 } 257 }
222 258
223 return FALSE; 259 return FALSE;
224 } 260 }
225 261
226 // static 262 // static
227 gboolean BookmarkMenuController::OnButtonReleased( 263 gboolean BookmarkMenuController::OnButtonReleased(
228 GtkWidget* sender, 264 GtkWidget* sender,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // static 337 // static
302 void BookmarkMenuController::OnMenuItemDragGet( 338 void BookmarkMenuController::OnMenuItemDragGet(
303 GtkWidget* widget, GdkDragContext* context, 339 GtkWidget* widget, GdkDragContext* context,
304 GtkSelectionData* selection_data, 340 GtkSelectionData* selection_data,
305 guint target_type, guint time, 341 guint target_type, guint time,
306 BookmarkMenuController* controller) { 342 BookmarkMenuController* controller) {
307 const BookmarkNode* node = bookmark_utils::BookmarkNodeForWidget(widget); 343 const BookmarkNode* node = bookmark_utils::BookmarkNodeForWidget(widget);
308 bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type, 344 bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type,
309 controller->profile_); 345 controller->profile_);
310 } 346 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698