summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-23 01:14:34 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-23 01:14:34 +0000
commit13cdde22f51438848b28a58de3bb22996e7c6661 (patch)
tree4d6cdf896ffa2db474207182dccaa378adbc91d7 /chrome
parent5c2b9cd062197d60bd0f7f7bf237b6409df393fa (diff)
downloadchromium_src-13cdde22f51438848b28a58de3bb22996e7c6661.zip
chromium_src-13cdde22f51438848b28a58de3bb22996e7c6661.tar.gz
chromium_src-13cdde22f51438848b28a58de3bb22996e7c6661.tar.bz2
GTK: Dismiss the bookmark folder menu(s) when a context menu item is executed.
BUG=22372 Review URL: http://codereview.chromium.org/211056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26890 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.cc5
-rw-r--r--chrome/browser/gtk/bookmark_context_menu.cc13
-rw-r--r--chrome/browser/gtk/bookmark_context_menu.h13
-rw-r--r--chrome/browser/gtk/bookmark_manager_gtk.cc3
-rw-r--r--chrome/browser/gtk/bookmark_menu_controller_gtk.cc9
-rw-r--r--chrome/browser/gtk/bookmark_menu_controller_gtk.h8
6 files changed, 43 insertions, 8 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc
index 1ecf5c9..a6f82b0 100644
--- a/chrome/browser/gtk/bookmark_bar_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bar_gtk.cc
@@ -414,6 +414,9 @@ void BookmarkBarGtk::SetInstructionState() {
}
void BookmarkBarGtk::SetChevronState() {
+ if (!GTK_WIDGET_VISIBLE(bookmark_toolbar_.get()))
+ return;
+
int extra_space = 0;
if (GTK_WIDGET_VISIBLE(overflow_button_))
@@ -647,7 +650,7 @@ void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender,
current_context_menu_.reset(new BookmarkContextMenu(
sender, profile_, browser_, page_navigator_,
parent, nodes,
- BookmarkContextMenu::BOOKMARK_BAR));
+ BookmarkContextMenu::BOOKMARK_BAR, NULL));
current_context_menu_->PopupAsContext(event->time);
}
diff --git a/chrome/browser/gtk/bookmark_context_menu.cc b/chrome/browser/gtk/bookmark_context_menu.cc
index eef3110..c282a5e 100644
--- a/chrome/browser/gtk/bookmark_context_menu.cc
+++ b/chrome/browser/gtk/bookmark_context_menu.cc
@@ -215,7 +215,8 @@ BookmarkContextMenu::BookmarkContextMenu(
PageNavigator* navigator,
const BookmarkNode* parent,
const std::vector<const BookmarkNode*>& selection,
- ConfigurationType configuration)
+ ConfigurationType configuration,
+ Delegate* delegate)
: wnd_(wnd),
profile_(profile),
browser_(browser),
@@ -223,7 +224,8 @@ BookmarkContextMenu::BookmarkContextMenu(
parent_(parent),
selection_(selection),
model_(profile->GetBookmarkModel()),
- configuration_(configuration) {
+ configuration_(configuration),
+ delegate_(delegate) {
DCHECK(profile_);
DCHECK(model_->IsLoaded());
CreateMenuObject();
@@ -294,7 +296,14 @@ BookmarkContextMenu::~BookmarkContextMenu() {
model_->RemoveObserver(this);
}
+void BookmarkContextMenu::DelegateDestroyed() {
+ delegate_ = NULL;
+}
+
void BookmarkContextMenu::ExecuteCommand(int id) {
+ if (delegate_)
+ delegate_->WillExecuteCommand();
+
switch (id) {
case IDS_BOOMARK_BAR_OPEN_ALL:
case IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO:
diff --git a/chrome/browser/gtk/bookmark_context_menu.h b/chrome/browser/gtk/bookmark_context_menu.h
index 755a01c..ca949f6 100644
--- a/chrome/browser/gtk/bookmark_context_menu.h
+++ b/chrome/browser/gtk/bookmark_context_menu.h
@@ -50,6 +50,12 @@ class BookmarkContextMenu : public BookmarkModelObserver,
BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER
};
+ class Delegate {
+ public:
+ // Called when one of the menu items is selected and executed.
+ virtual void WillExecuteCommand() = 0;
+ };
+
// Creates the bookmark context menu.
// |profile| is used for opening urls as well as enabling 'open incognito'.
// |browser| is used to determine the PageNavigator and may be null.
@@ -63,7 +69,8 @@ class BookmarkContextMenu : public BookmarkModelObserver,
PageNavigator* navigator,
const BookmarkNode* parent,
const std::vector<const BookmarkNode*>& selection,
- ConfigurationType configuration);
+ ConfigurationType configuration,
+ Delegate* delegate);
virtual ~BookmarkContextMenu();
#if defined(TOOLKIT_VIEWS)
@@ -80,6 +87,9 @@ class BookmarkContextMenu : public BookmarkModelObserver,
GtkWidget* menu() const { return menu_->widget(); }
#endif
+ // Should be called by the delegate when it is no longer valid.
+ void DelegateDestroyed();
+
// Menu::Delegate / MenuGtk::Delegate methods.
virtual void ExecuteCommand(int id);
virtual bool IsItemChecked(int id) const;
@@ -143,6 +153,7 @@ class BookmarkContextMenu : public BookmarkModelObserver,
std::vector<const BookmarkNode*> selection_;
BookmarkModel* model_;
ConfigurationType configuration_;
+ Delegate* delegate_;
#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
scoped_ptr<views::MenuItemView> menu_;
diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc
index 65167db..aa8f0bc 100644
--- a/chrome/browser/gtk/bookmark_manager_gtk.cc
+++ b/chrome/browser/gtk/bookmark_manager_gtk.cc
@@ -607,7 +607,8 @@ void BookmarkManagerGtk::ResetOrganizeMenu(bool left) {
MessageLoop::current()->DeleteSoon(FROM_HERE, old_menu);
organize_menu_.reset(new BookmarkContextMenu(window_, profile_, NULL, NULL,
- parent, nodes, BookmarkContextMenu::BOOKMARK_MANAGER_ORGANIZE_MENU));
+ parent, nodes, BookmarkContextMenu::BOOKMARK_MANAGER_ORGANIZE_MENU,
+ NULL));
#if defined(TOOLKIT_GTK)
gtk_menu_item_set_submenu(GTK_MENU_ITEM(organize_), organize_menu_->menu());
#else
diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc
index ce2a22ca..7ea7aee 100644
--- a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc
+++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc
@@ -105,6 +105,9 @@ BookmarkMenuController::BookmarkMenuController(Browser* browser,
}
BookmarkMenuController::~BookmarkMenuController() {
+
+ if (context_menu_.get())
+ context_menu_->DelegateDestroyed();
profile_->GetBookmarkModel()->RemoveObserver(this);
gtk_menu_popdown(GTK_MENU(menu_));
}
@@ -133,6 +136,10 @@ void BookmarkMenuController::BookmarkNodeFavIconLoaded(
SetImageMenuItem(it->second, node, model);
}
+void BookmarkMenuController::WillExecuteCommand() {
+ gtk_menu_popdown(GTK_MENU(menu_));
+}
+
void BookmarkMenuController::NavigateToMenuItem(
GtkWidget* menu_item,
WindowOpenDisposition disposition) {
@@ -245,7 +252,7 @@ gboolean BookmarkMenuController::OnButtonPressed(
new BookmarkContextMenu(
GTK_WIDGET(controller->parent_window_), controller->profile_,
controller->browser_, controller->page_navigator_, parent, nodes,
- BookmarkContextMenu::BOOKMARK_BAR));
+ BookmarkContextMenu::BOOKMARK_BAR, controller));
// Our bookmark folder menu loses the grab to the context menu. When the
// context menu is hidden, re-assert our grab.
diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.h b/chrome/browser/gtk/bookmark_menu_controller_gtk.h
index f3182df..f6f0389f 100644
--- a/chrome/browser/gtk/bookmark_menu_controller_gtk.h
+++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.h
@@ -11,10 +11,10 @@
#include "base/scoped_ptr.h"
#include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
+#include "chrome/browser/gtk/bookmark_context_menu.h"
#include "chrome/common/owned_widget_gtk.h"
#include "webkit/glue/window_open_disposition.h"
-class BookmarkContextMenu;
class Browser;
class Profile;
class Profiler;
@@ -22,7 +22,8 @@ class PageNavigator;
class BookmarkModel;
class BookmarkNode;
-class BookmarkMenuController : public BaseBookmarkModelObserver {
+class BookmarkMenuController : public BaseBookmarkModelObserver,
+ public BookmarkContextMenu::Delegate {
public:
// Creates a BookmarkMenuController showing the children of |node| starting
// at index |start_child_index|.
@@ -45,6 +46,9 @@ class BookmarkMenuController : public BaseBookmarkModelObserver {
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
const BookmarkNode* node);
+ // Overridden from BookmarkContextMenu::Delegate:
+ virtual void WillExecuteCommand();
+
private:
// Recursively change the bookmark hierarchy rooted in |parent| into a set of
// gtk menus rooted in |menu|.