| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_GTK_GLOBAL_BOOKMARK_MENU_H_ | |
| 6 #define CHROME_BROWSER_UI_GTK_GLOBAL_BOOKMARK_MENU_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/task.h" | |
| 13 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | |
| 14 #include "chrome/browser/ui/gtk/global_menu_owner.h" | |
| 15 #include "content/common/notification_observer.h" | |
| 16 #include "content/common/notification_registrar.h" | |
| 17 #include "ui/base/gtk/gtk_signal.h" | |
| 18 #include "ui/base/gtk/owned_widget_gtk.h" | |
| 19 | |
| 20 class Browser; | |
| 21 class Profile; | |
| 22 | |
| 23 typedef struct _GdkPixbuf GdkPixbuf; | |
| 24 typedef struct _GtkWidget GtkWidget; | |
| 25 | |
| 26 // Manages the global bookmarks menu. | |
| 27 // | |
| 28 // There are a few subtleties here: we can't rely on accurate event | |
| 29 // dispositions being sent back, right click menus on menu items are placed | |
| 30 // relative to the main chrome window instead of the global menu bar, and we | |
| 31 // need to update the menu in the background (instead of building it on showing | |
| 32 // and not updating it if the model changes). I'm not even thinking about | |
| 33 // making these draggable since these items aren't displayed in our process. | |
| 34 class GlobalBookmarkMenu : public GlobalMenuOwner, | |
| 35 public NotificationObserver, | |
| 36 public BookmarkModelObserver { | |
| 37 public: | |
| 38 explicit GlobalBookmarkMenu(Browser* browser); | |
| 39 virtual ~GlobalBookmarkMenu(); | |
| 40 | |
| 41 // Takes the bookmark menu we need to modify based on bookmark state. | |
| 42 virtual void Init(GtkWidget* bookmark_menu, GtkWidget* bookmark_menu_item); | |
| 43 | |
| 44 private: | |
| 45 // Schedules the menu to be rebuilt. The mac version sets a boolean and | |
| 46 // rebuilds the menu during their pre-show callback. We don't have anything | |
| 47 // like that: by the time we get a "show" signal from GTK+, the menu has | |
| 48 // already been displayed and it will take multiple dbus calls to add the | |
| 49 // menu items. | |
| 50 // | |
| 51 // Since the bookmark model works by sending us BookmarkNodeEvent | |
| 52 // notifications one by one, we use a timer to batch up calls. | |
| 53 void RebuildMenuInFuture(); | |
| 54 | |
| 55 // Rebuilds the menu now. Called on initial Load() and from | |
| 56 // RebuildMenuInFuture(). | |
| 57 void RebuildMenu(); | |
| 58 | |
| 59 // Adds |item| to |menu| and marks it as a dynamic item. | |
| 60 void AddBookmarkMenuItem(GtkWidget* menu, GtkWidget* menu_item); | |
| 61 | |
| 62 // Adds an menu item representing |node| to |menu|. | |
| 63 void AddNodeToMenu(const BookmarkNode* node, GtkWidget* menu); | |
| 64 | |
| 65 // This configures a GtkWidget with all the data from a BookmarkNode. This is | |
| 66 // used to update existing menu items, as well as to configure newly created | |
| 67 // ones, like in AddNodeToMenu(). | |
| 68 void ConfigureMenuItem(const BookmarkNode* node, GtkWidget* menu_item); | |
| 69 | |
| 70 // Returns the GtkMenuItem for |node|. | |
| 71 GtkWidget* MenuItemForNode(const BookmarkNode* node); | |
| 72 | |
| 73 // Removes all bookmark entries from the bookmark menu in anticipation that | |
| 74 // we're about to do a rebuild. | |
| 75 void ClearBookmarkMenu(); | |
| 76 | |
| 77 // Callback used in ClearBookmarkMenu(). | |
| 78 static void ClearBookmarkItemCallback(GtkWidget* menu_item, | |
| 79 void* unused); | |
| 80 | |
| 81 // NotificationObserver: | |
| 82 virtual void Observe(int type, | |
| 83 const NotificationSource& source, | |
| 84 const NotificationDetails& details); | |
| 85 | |
| 86 // BookmarkModelObserver: | |
| 87 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; | |
| 88 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; | |
| 89 virtual void BookmarkNodeMoved(BookmarkModel* model, | |
| 90 const BookmarkNode* old_parent, | |
| 91 int old_index, | |
| 92 const BookmarkNode* new_parent, | |
| 93 int new_index) OVERRIDE; | |
| 94 virtual void BookmarkNodeAdded(BookmarkModel* model, | |
| 95 const BookmarkNode* parent, | |
| 96 int index) OVERRIDE; | |
| 97 virtual void BookmarkNodeRemoved(BookmarkModel* model, | |
| 98 const BookmarkNode* parent, | |
| 99 int old_index, | |
| 100 const BookmarkNode* node) OVERRIDE; | |
| 101 virtual void BookmarkNodeChanged(BookmarkModel* model, | |
| 102 const BookmarkNode* node) OVERRIDE; | |
| 103 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, | |
| 104 const BookmarkNode* node) OVERRIDE; | |
| 105 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | |
| 106 const BookmarkNode* node) OVERRIDE; | |
| 107 | |
| 108 CHROMEGTK_CALLBACK_0(GlobalBookmarkMenu, void, OnBookmarkItemActivated); | |
| 109 | |
| 110 Browser* browser_; | |
| 111 Profile* profile_; | |
| 112 | |
| 113 NotificationRegistrar registrar_; | |
| 114 | |
| 115 GdkPixbuf* default_favicon_; | |
| 116 GdkPixbuf* default_folder_; | |
| 117 | |
| 118 ui::OwnedWidgetGtk bookmark_menu_; | |
| 119 | |
| 120 base::WeakPtrFactory<GlobalBookmarkMenu> weak_factory_; | |
| 121 | |
| 122 // In order to appropriately update items in the bookmark menu, without | |
| 123 // forcing a rebuild, map the model's nodes to menu items. | |
| 124 std::map<const BookmarkNode*, GtkWidget*> bookmark_nodes_; | |
| 125 }; | |
| 126 | |
| 127 #endif // CHROME_BROWSER_UI_GTK_GLOBAL_BOOKMARK_MENU_H_ | |
| OLD | NEW |