| Index: chrome/browser/ui/gtk/global_bookmark_menu.h
|
| diff --git a/chrome/browser/ui/gtk/global_bookmark_menu.h b/chrome/browser/ui/gtk/global_bookmark_menu.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..aff940e83650d7d3080da0f0c6718d16b2ded9a2
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/gtk/global_bookmark_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_BOOKMARK_MENU_H_
|
| +#define CHROME_BROWSER_UI_GTK_GLOBAL_BOOKMARK_MENU_H_
|
| +
|
| +#include <map>
|
| +
|
| +#include "base/task.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.
|
| +//
|
| +// There are a few subtleties here: we can't rely on accurate event
|
| +// dispositions being sent back, right click menus on menu items are placed
|
| +// 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
|
| +// and not updating it if the model changes). I'm not even thinking about
|
| +// making these draggable since these items aren't displayed in our process.
|
| +class GlobalBookmarkMenu : public NotificationObserver,
|
| + public BookmarkModelObserver {
|
| + public:
|
| + explicit GlobalBookmarkMenu(Browser* browser);
|
| + virtual ~GlobalBookmarkMenu();
|
| +
|
| + // 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 anything
|
| + // like that: by the time we get a "show" signal from GTK+, the menu has
|
| + // already been displayed and it will take multiple dbus calls to add the
|
| + // menu 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(GlobalBookmarkMenu, void, OnBookmarkItemActivated);
|
| +
|
| + Browser* browser_;
|
| + Profile* profile_;
|
| +
|
| + NotificationRegistrar registrar_;
|
| +
|
| + GdkPixbuf* default_favicon_;
|
| + GdkPixbuf* default_folder_;
|
| +
|
| + GtkWidget* bookmark_menu_;
|
| +
|
| + // We use this factory to create callback tasks for ThreadWatcher object. We
|
| + // use this during ping-pong messaging between WatchDog thread and watched
|
| + // thread.
|
| + ScopedRunnableMethodFactory<GlobalBookmarkMenu> method_factory_;
|
| +
|
| + // 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_BOOKMARK_MENU_H_
|
|
|