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

Side by Side Diff: chrome/browser/ui/gtk/global_bookmark_menu.h

Issue 6980011: GTK: Implement the global bookmarks menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 'GlobalBookmarkMenu' Created 9 years, 7 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 | chrome/browser/ui/gtk/global_bookmark_menu.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/task.h"
11 #include "chrome/browser/bookmarks/bookmark_model_observer.h"
12 #include "content/common/notification_observer.h"
13 #include "content/common/notification_registrar.h"
14 #include "ui/base/gtk/gtk_signal.h"
15
16 class Browser;
17 class Profile;
18
19 typedef struct _GdkPixbuf GdkPixbuf;
20 typedef struct _GtkWidget GtkWidget;
21
22 // Manages the global bookmarks menu.
23 //
24 // There are a few subtleties here: we can't rely on accurate event
25 // dispositions being sent back, right click menus on menu items are placed
26 // relative to the main chrome window instead of the global menu bar, and we
27 // need to update the menu in the background (instead of building it on showing
28 // and not updating it if the model changes). I'm not even thinking about
29 // making these draggable since these items aren't displayed in our process.
30 class GlobalBookmarkMenu : public NotificationObserver,
31 public BookmarkModelObserver {
32 public:
33 explicit GlobalBookmarkMenu(Browser* browser);
34 virtual ~GlobalBookmarkMenu();
35
36 // Takes the bookmark menu we need to modify based on bookmark state.
37 void Init(GtkWidget* bookmark_menu);
38
39 private:
40 // Schedules the menu to be rebuilt. The mac version sets a boolean and
41 // rebuilds the menu during their pre-show callback. We don't have anything
42 // like that: by the time we get a "show" signal from GTK+, the menu has
43 // already been displayed and it will take multiple dbus calls to add the
44 // menu items.
45 //
46 // Since the bookmark model works by sending us BookmarkNodeEvent
47 // notifications one by one, we use a timer to batch up calls.
48 void RebuildMenuInFuture();
49
50 // Rebuilds the menu now. Called on initial Load() and from
51 // RebuildMenuInFuture().
52 void RebuildMenu();
53
54 // Adds |item| to |menu| and marks it as a dynamic item.
55 void AddBookmarkMenuItem(GtkWidget* menu, GtkWidget* menu_item);
56
57 // Adds an menu item representing |node| to |menu|.
58 void AddNodeToMenu(const BookmarkNode* node, GtkWidget* menu);
59
60 // This configures a GtkWidget with all the data from a BookmarkNode. This is
61 // used to update existing menu items, as well as to configure newly created
62 // ones, like in AddNodeToMenu().
63 void ConfigureMenuItem(const BookmarkNode* node, GtkWidget* menu_item);
64
65 // Returns the GtkMenuItem for |node|.
66 GtkWidget* MenuItemForNode(const BookmarkNode* node);
67
68 // Removes all bookmark entries from the bookmark menu in anticipation that
69 // we're about to do a rebuild.
70 void ClearBookmarkMenu();
71
72 // Callback used in ClearBookmarkMenu().
73 static void ClearBookmarkItemCallback(GtkWidget* menu_item,
74 void* unused);
75
76 // NotificationObserver:
77 virtual void Observe(NotificationType type,
78 const NotificationSource& source,
79 const NotificationDetails& details);
80
81 // BookmarkModelObserver:
82 virtual void Loaded(BookmarkModel* model);
83 virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
84 virtual void BookmarkNodeMoved(BookmarkModel* model,
85 const BookmarkNode* old_parent,
86 int old_index,
87 const BookmarkNode* new_parent,
88 int new_index);
89 virtual void BookmarkNodeAdded(BookmarkModel* model,
90 const BookmarkNode* parent,
91 int index);
92 virtual void BookmarkNodeRemoved(BookmarkModel* model,
93 const BookmarkNode* parent,
94 int old_index,
95 const BookmarkNode* node);
96 virtual void BookmarkNodeChanged(BookmarkModel* model,
97 const BookmarkNode* node);
98 virtual void BookmarkNodeFaviconLoaded(BookmarkModel* model,
99 const BookmarkNode* node);
100 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
101 const BookmarkNode* node);
102
103 CHROMEGTK_CALLBACK_0(GlobalBookmarkMenu, void, OnBookmarkItemActivated);
104
105 Browser* browser_;
106 Profile* profile_;
107
108 NotificationRegistrar registrar_;
109
110 GdkPixbuf* default_favicon_;
111 GdkPixbuf* default_folder_;
112
113 GtkWidget* bookmark_menu_;
114
115 // We use this factory to create callback tasks for ThreadWatcher object. We
116 // use this during ping-pong messaging between WatchDog thread and watched
117 // thread.
118 ScopedRunnableMethodFactory<GlobalBookmarkMenu> method_factory_;
119
120 // In order to appropriately update items in the bookmark menu, without
121 // forcing a rebuild, map the model's nodes to menu items.
122 std::map<const BookmarkNode*, GtkWidget*> bookmark_nodes_;
123 };
124
125 #endif // CHROME_BROWSER_UI_GTK_GLOBAL_BOOKMARK_MENU_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/global_bookmark_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698