| Index: chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h
|
| ===================================================================
|
| --- chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h (revision 86142)
|
| +++ chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h (working copy)
|
| @@ -2,8 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
|
| -#define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
|
| +#ifndef CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_
|
| +#define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_
|
| #pragma once
|
|
|
| #include <map>
|
| @@ -14,65 +14,57 @@
|
| #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
|
| #include "ui/gfx/native_widget_types.h"
|
| #include "views/controls/menu/menu_delegate.h"
|
| -#include "views/controls/menu/menu_item_view.h"
|
|
|
| -class BookmarkBarView;
|
| class BookmarkNode;
|
| -class Browser;
|
| class PageNavigator;
|
| class Profile;
|
|
|
| -namespace gfx {
|
| -class Rect;
|
| -} // namespace gfx
|
| -
|
| namespace ui {
|
| class OSExchangeData;
|
| -} // namespace ui
|
| +}
|
|
|
| namespace views {
|
| -class MenuButton;
|
| -} // namespace views
|
| +class MenuItemView;
|
| +}
|
|
|
| -// BookmarkMenuController is responsible for showing a menu of bookmarks,
|
| -// each item in the menu represents a bookmark.
|
| -// BookmarkMenuController deletes itself as necessary, although the menu can
|
| -// be explicitly hidden by way of the Cancel method.
|
| -class BookmarkMenuController : public BaseBookmarkModelObserver,
|
| - public views::MenuDelegate,
|
| - public BookmarkContextMenuObserver {
|
| +// BookmarkMenuDelegate acts as the (informal) views::MenuDelegate for showing
|
| +// bookmarks in a MenuItemView. BookmarkMenuDelegate informally implements
|
| +// MenuDelegate as its assumed another class is going to forward the appropriate
|
| +// methods to this class. Doing so allows this class to be used for both menus
|
| +// on the bookmark bar and the bookmarks in the wrench menu.
|
| +class BookmarkMenuDelegate : public BaseBookmarkModelObserver,
|
| + public BookmarkContextMenuObserver {
|
| public:
|
| - // The observer is notified prior to the menu being deleted.
|
| - class Observer {
|
| - public:
|
| - virtual void BookmarkMenuDeleted(BookmarkMenuController* controller) = 0;
|
| + enum ShowOptions {
|
| + // Indicates a menu should be added containing the 'other' bookmarks folder
|
| + // and all its contents. This only makes sense when showing the contents
|
| + // of the bookmark folder.
|
| + SHOW_OTHER_FOLDER,
|
|
|
| - protected:
|
| - virtual ~Observer() {}
|
| + // Don't show the 'other' bookmarks folder.
|
| + HIDE_OTHER_FOLDER
|
| };
|
|
|
| - // Creates a BookmarkMenuController showing the children of |node| starting
|
| - // at index |start_child_index|.
|
| - BookmarkMenuController(Browser* browser,
|
| - Profile* profile,
|
| - PageNavigator* page_navigator,
|
| - gfx::NativeWindow parent,
|
| - const BookmarkNode* node,
|
| - int start_child_index);
|
| + BookmarkMenuDelegate(Profile* profile,
|
| + PageNavigator* navigator,
|
| + gfx::NativeWindow parent,
|
| + int first_menu_id);
|
| + virtual ~BookmarkMenuDelegate();
|
|
|
| - void RunMenuAt(BookmarkBarView* bookmark_bar, bool for_drop);
|
| + // Creates the menus from the model.
|
| + void Init(views::MenuDelegate* real_delegate,
|
| + views::MenuItemView* parent,
|
| + const BookmarkNode* node,
|
| + int start_child_index,
|
| + ShowOptions show_options);
|
|
|
| - // Shows the menu.
|
| - void RunMenuAt(views::MenuButton* button,
|
| - views::MenuItemView::AnchorPosition position,
|
| - bool for_drop);
|
| + // Returns the id given to the next menu.
|
| + int next_menu_id() const { return next_menu_id_; }
|
|
|
| - // Hides the menu.
|
| - void Cancel();
|
| + // Makes the menu for |node| the active menu. |start_index| is the index of
|
| + // the first child of |node| to show in the menu.
|
| + void SetActiveMenu(const BookmarkNode* node, int start_index);
|
|
|
| - // Returns the node the menu is showing for.
|
| - const BookmarkNode* node() const { return node_; }
|
| -
|
| // Returns the menu.
|
| views::MenuItemView* menu() const { return menu_; }
|
|
|
| @@ -81,42 +73,39 @@
|
| return context_menu_.get() ? context_menu_->menu() : NULL;
|
| }
|
|
|
| - void set_observer(Observer* observer) { observer_ = observer; }
|
| + Profile* profile() { return profile_; }
|
|
|
| - // MenuDelegate methods.
|
| - virtual std::wstring GetTooltipText(int id, const gfx::Point& p);
|
| - virtual bool IsTriggerableEvent(views::MenuItemView* view,
|
| - const views::MouseEvent& e);
|
| - virtual void ExecuteCommand(int id, int mouse_event_flags);
|
| - virtual bool GetDropFormats(
|
| + gfx::NativeWindow parent() { return parent_; }
|
| +
|
| + // Returns true if we're in the process of mutating the model. This happens
|
| + // when the user deletes menu items using the context menu.
|
| + bool is_mutating_model() const { return is_mutating_model_; }
|
| +
|
| + // MenuDelegate like methods (see class description for details).
|
| + std::wstring GetTooltipText(int id, const gfx::Point& p);
|
| + bool IsTriggerableEvent(views::MenuItemView* menu,
|
| + const views::MouseEvent& e);
|
| + void ExecuteCommand(int id, int mouse_event_flags);
|
| + bool GetDropFormats(
|
| views::MenuItemView* menu,
|
| int* formats,
|
| std::set<ui::OSExchangeData::CustomFormat>* custom_formats);
|
| - virtual bool AreDropTypesRequired(views::MenuItemView* menu);
|
| - virtual bool CanDrop(views::MenuItemView* menu,
|
| - const ui::OSExchangeData& data);
|
| - virtual int GetDropOperation(views::MenuItemView* item,
|
| - const views::DropTargetEvent& event,
|
| - DropPosition* position);
|
| - virtual int OnPerformDrop(views::MenuItemView* menu,
|
| - DropPosition position,
|
| - const views::DropTargetEvent& event);
|
| - virtual bool ShowContextMenu(views::MenuItemView* source,
|
| - int id,
|
| - const gfx::Point& p,
|
| - bool is_mouse_gesture);
|
| - virtual void DropMenuClosed(views::MenuItemView* menu);
|
| - virtual bool CanDrag(views::MenuItemView* menu);
|
| - virtual void WriteDragData(views::MenuItemView* sender,
|
| - ui::OSExchangeData* data);
|
| - virtual int GetDragOperations(views::MenuItemView* sender);
|
| - virtual views::MenuItemView* GetSiblingMenu(
|
| - views::MenuItemView* menu,
|
| - const gfx::Point& screen_point,
|
| - views::MenuItemView::AnchorPosition* anchor,
|
| - bool* has_mnemonics,
|
| - views::MenuButton** button);
|
| - virtual int GetMaxWidthForMenu(views::MenuItemView* view);
|
| + bool AreDropTypesRequired(views::MenuItemView* menu);
|
| + bool CanDrop(views::MenuItemView* menu, const ui::OSExchangeData& data);
|
| + int GetDropOperation(views::MenuItemView* item,
|
| + const views::DropTargetEvent& event,
|
| + views::MenuDelegate::DropPosition* position);
|
| + int OnPerformDrop(views::MenuItemView* menu,
|
| + views::MenuDelegate::DropPosition position,
|
| + const views::DropTargetEvent& event);
|
| + bool ShowContextMenu(views::MenuItemView* source,
|
| + int id,
|
| + const gfx::Point& p,
|
| + bool is_mouse_gesture);
|
| + bool CanDrag(views::MenuItemView* menu);
|
| + void WriteDragData(views::MenuItemView* sender, ui::OSExchangeData* data);
|
| + int GetDragOperations(views::MenuItemView* sender);
|
| + int GetMaxWidthForMenu(views::MenuItemView* menu);
|
|
|
| // BookmarkModelObserver methods.
|
| virtual void BookmarkModelChanged();
|
| @@ -130,15 +119,18 @@
|
|
|
| private:
|
| typedef std::map<const BookmarkNode*, int> NodeToMenuIDMap;
|
| + typedef std::map<const BookmarkNode*, views::MenuItemView*> NodeToMenuMap;
|
|
|
| - // BookmarkMenuController deletes itself as necessary.
|
| - virtual ~BookmarkMenuController();
|
| -
|
| // Creates a menu and adds it to node_to_menu_id_map_. This uses
|
| // BuildMenu to recursively populate the menu.
|
| views::MenuItemView* CreateMenu(const BookmarkNode* parent,
|
| - int start_child_index);
|
| + int start_child_index,
|
| + ShowOptions show_options);
|
|
|
| + // Builds the menu for the other bookmarks folder. This is added as the last
|
| + // item to menu_.
|
| + void BuildOtherFolderMenu(views::MenuItemView* menu, int* next_menu_id);
|
| +
|
| // Creates an entry in menu for each child node of |parent| starting at
|
| // |start_child_index|.
|
| void BuildMenu(const BookmarkNode* parent,
|
| @@ -156,8 +148,6 @@
|
| const std::vector<const BookmarkNode*>& bookmarks,
|
| std::set<views::MenuItemView*>* removed_menus);
|
|
|
| - Browser* browser_;
|
| -
|
| Profile* profile_;
|
|
|
| PageNavigator* page_navigator_;
|
| @@ -165,9 +155,6 @@
|
| // Parent of menus.
|
| gfx::NativeWindow parent_;
|
|
|
| - // The node we're showing the contents of.
|
| - const BookmarkNode* node_;
|
| -
|
| // Maps from menu id to BookmarkNode.
|
| std::map<int, const BookmarkNode*> menu_id_to_node_map_;
|
|
|
| @@ -184,23 +171,20 @@
|
| // Used when a context menu is shown.
|
| scoped_ptr<BookmarkContextMenu> context_menu_;
|
|
|
| - // The observer, may be null.
|
| - Observer* observer_;
|
| -
|
| // Is the menu being shown for a drop?
|
| bool for_drop_;
|
|
|
| - // The bookmark bar. This is only non-null if we're showing a menu item
|
| - // for a folder on the bookmark bar and not for drop.
|
| - BookmarkBarView* bookmark_bar_;
|
| -
|
| - typedef std::map<const BookmarkNode*, views::MenuItemView*> NodeToMenuMap;
|
| NodeToMenuMap node_to_menu_map_;
|
|
|
| // ID of the next menu item.
|
| int next_menu_id_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController);
|
| + views::MenuDelegate* real_delegate_;
|
| +
|
| + // Is the model being changed?
|
| + bool is_mutating_model_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(BookmarkMenuDelegate);
|
| };
|
|
|
| -#endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
|
| +#endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_
|
|
|