Chromium Code Reviews| Index: chrome/browser/ui/gtk/global_bookmarks_menu.h |
| diff --git a/chrome/browser/ui/gtk/global_bookmarks_menu.h b/chrome/browser/ui/gtk/global_bookmarks_menu.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8e0c753867681c339856e0452957e365b51df26d |
| --- /dev/null |
| +++ b/chrome/browser/ui/gtk/global_bookmarks_menu.h |
| @@ -0,0 +1,125 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_UI_GTK_GLOBAL_BOOKMARKS_MENU_H_ |
| +#define CHROME_BROWSER_UI_GTK_GLOBAL_BOOKMARKS_MENU_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/time.h" |
| +#include "base/timer.h" |
| +#include "chrome/browser/bookmarks/bookmark_model_observer.h" |
| +#include "content/common/notification_observer.h" |
| +#include "content/common/notification_registrar.h" |
| +#include "ui/base/gtk/gtk_signal.h" |
| + |
| +class Browser; |
| +class Profile; |
| + |
| +typedef struct _GdkPixbuf GdkPixbuf; |
| +typedef struct _GtkWidget GtkWidget; |
| + |
| +// Manages the global Bookmarks menu. |
|
Evan Stade
2011/05/10 17:09:18
odd to capitalize bookmarks here
|
| +// |
| +// There are a few subtilties here: we can't rely on accurate event |
|
Evan Stade
2011/05/10 17:09:18
subtleties
|
| +// dispositions being sent back, right click menus on menu items were placed |
|
Evan Stade
2011/05/10 17:09:18
confusing change of tense here ("were" -- when?)
|
| +// relative to the main chrome window instead of the global menu bar, and we |
| +// need to update the menu in the background (instead of building it on showing |
|
Evan Stade
2011/05/10 17:09:18
can you separate some of these comments into a TOD
Elliot Glaysher
2011/05/10 18:29:28
I put these here to document the limitations. I do
|
| +// and not updating it if the model changes). I'm not even thinking about |
| +// making these dragable since these items aren't displayed in our process. |
|
Evan Stade
2011/05/10 17:09:18
draggable
|
| +class GlobalBookmarksMenu : public NotificationObserver, |
|
Evan Stade
2011/05/10 17:09:18
this should be GlobalBookmarkMenu (the only class
Elliot Glaysher
2011/05/10 18:29:28
The class implements a menu that whose title is th
Evan Stade
2011/05/10 18:50:34
I think consistency with other code is more import
|
| + public BookmarkModelObserver { |
| + public: |
| + explicit GlobalBookmarksMenu(Browser* browser); |
| + virtual ~GlobalBookmarksMenu(); |
| + |
| + // Takes the bookmark menu we need to modify based on bookmark state. |
| + void Init(GtkWidget* bookmark_menu); |
| + |
| + private: |
| + // Schedules the menu to be rebuilt. The mac version sets a boolean and |
| + // rebuilds the menu during their pre-show callback. We don't have that |
|
Evan Stade
2011/05/10 17:09:18
s/that//
|
| + // anything like that: by the time we get a "show" signal from GTK+, the menu |
| + // has already been displayed and its multiple dbus calls to add the menu |
|
Evan Stade
2011/05/10 17:09:18
s/its/it takes/
(?)
|
| + // items. |
| + // |
| + // Since the bookmark model works by sending us BookmarkNodeEvent |
| + // notifications one by one, we use a timer to batch up calls. |
| + void RebuildMenuInFuture(); |
| + |
| + // Rebuilds the menu now. Called on initial Load() and from |
| + // RebuildMenuInFuture(). |
| + void RebuildMenu(); |
| + |
| + // Adds |item| to |menu| and marks it as a dynamic item. |
| + void AddBookmarkMenuItem(GtkWidget* menu, GtkWidget* menu_item); |
| + |
| + // Adds an menu item representing |node| to |menu|. |
| + void AddNodeToMenu(const BookmarkNode* node, GtkWidget* menu); |
| + |
| + // This configures a GtkWidget with all the data from a BookmarkNode. This is |
| + // used to update existing menu items, as well as to configure newly created |
| + // ones, like in AddNodeToMenu(). |
| + void ConfigureMenuItem(const BookmarkNode* node, GtkWidget* menu_item); |
| + |
| + // Returns the GtkMenuItem for |node|. |
| + GtkWidget* MenuItemForNode(const BookmarkNode* node); |
| + |
| + // Removes all bookmark entries from the bookmark menu in anticipation that |
| + // we're about to do a rebuild. |
| + void ClearBookmarkMenu(); |
| + |
| + // Callback used in ClearBookmarkMenu(). |
| + static void ClearBookmarkItemCallback(GtkWidget* menu_item, |
| + void* /*unused*/); |
| + |
| + // NotificationObserver: |
| + virtual void Observe(NotificationType type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details); |
| + |
| + // BookmarkModelObserver: |
| + virtual void Loaded(BookmarkModel* model); |
| + virtual void BookmarkModelBeingDeleted(BookmarkModel* model); |
| + virtual void BookmarkNodeMoved(BookmarkModel* model, |
| + const BookmarkNode* old_parent, |
| + int old_index, |
| + const BookmarkNode* new_parent, |
| + int new_index); |
| + virtual void BookmarkNodeAdded(BookmarkModel* model, |
| + const BookmarkNode* parent, |
| + int index); |
| + virtual void BookmarkNodeRemoved(BookmarkModel* model, |
| + const BookmarkNode* parent, |
| + int old_index, |
| + const BookmarkNode* node); |
| + virtual void BookmarkNodeChanged(BookmarkModel* model, |
| + const BookmarkNode* node); |
| + virtual void BookmarkNodeFaviconLoaded(BookmarkModel* model, |
| + const BookmarkNode* node); |
| + virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, |
| + const BookmarkNode* node); |
| + |
| + CHROMEGTK_CALLBACK_0(GlobalBookmarksMenu, void, OnBookmarkItemActivated); |
| + |
| + Browser* browser_; |
| + Profile* profile_; |
| + |
| + NotificationRegistrar registrar_; |
| + |
| + GdkPixbuf* default_favicon_; |
| + GdkPixbuf* default_folder_; |
| + |
| + GtkWidget* bookmark_menu_; |
| + |
| + // A timer set/reset by RebuildMenuInFuture() to group menu mutating events |
| + // together. |
| + base::OneShotTimer<GlobalBookmarksMenu> menu_build_timer_; |
| + |
| + // In order to appropriately update items in the bookmark menu, without |
| + // forcing a rebuild, map the model's nodes to menu items. |
| + std::map<const BookmarkNode*, GtkWidget*> bookmark_nodes_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_UI_GTK_GLOBAL_BOOKMARKS_MENU_H_ |