bookmark_menu_controller_views.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
1// Copyright (c) 2012 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_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ 6#define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ 7 8#include <set> 9 10#include "base/compiler_specific.h" 11#include "chrome/browser/bookmarks/base_bookmark_model_observer.h" 12#include "chrome/browser/bookmarks/bookmark_node_data.h" 13#include "ui/views/controls/menu/menu_delegate.h" 14#include "ui/views/controls/menu/menu_item_view.h" 15 16class BookmarkBarView; 17class BookmarkMenuDelegate; 18class BookmarkNode; 19class Browser; 20 21namespace content { 22class PageNavigator; 23} 24 25namespace ui { 26class OSExchangeData; 27} // namespace ui 28 29namespace views { 30class MenuButton; 31class MenuRunner; 32class Widget; 33} // namespace views 34 35// BookmarkMenuController is responsible for showing a menu of bookmarks, 36// each item in the menu represents a bookmark. 37// BookmarkMenuController deletes itself as necessary, although the menu can 38// be explicitly hidden by way of the Cancel method. 39class BookmarkMenuController : public BaseBookmarkModelObserver, 40 public views::MenuDelegate { 41 public: 42 // The observer is notified prior to the menu being deleted. 43 class Observer { 44 public: 45 virtual void BookmarkMenuDeleted(BookmarkMenuController* controller) = 0; 46 47 protected: 48 virtual ~Observer() {} 49 }; 50 51 // Creates a BookmarkMenuController showing the children of |node| starting 52 // at |start_child_index|. 53 BookmarkMenuController(Browser* browser, 54 content::PageNavigator* page_navigator, 55 views::Widget* parent, 56 const BookmarkNode* node, 57 int start_child_index); 58 59 void RunMenuAt(BookmarkBarView* bookmark_bar, bool for_drop); 60 61 // Hides the menu. 62 void Cancel(); 63 64 // Returns the node the menu is showing for. 65 const BookmarkNode* node() const { return node_; } 66 67 // Returns the menu. 68 views::MenuItemView* menu() const; 69 70 // Returns the context menu, or NULL if the context menu isn't showing. 71 views::MenuItemView* context_menu() const; 72 73 // Sets the page navigator. 74 void SetPageNavigator(content::PageNavigator* navigator); 75 76 void set_observer(Observer* observer) { observer_ = observer; } 77 78 // MenuDelegate methods. 79 virtual string16 GetTooltipText(int id, const gfx::Point& p) const OVERRIDE; 80 virtual bool IsTriggerableEvent(views::MenuItemView* view, 81 const ui::Event& e) OVERRIDE; 82 virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE; 83 virtual bool ShouldExecuteCommandWithoutClosingMenu( 84 int id, 85 const ui::Event& e) OVERRIDE; 86 virtual bool GetDropFormats( 87 views::MenuItemView* menu, 88 int* formats, 89 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; 90 virtual bool AreDropTypesRequired(views::MenuItemView* menu) OVERRIDE; 91 virtual bool CanDrop(views::MenuItemView* menu, 92 const ui::OSExchangeData& data) OVERRIDE; 93 virtual int GetDropOperation(views::MenuItemView* item, 94 const ui::DropTargetEvent& event, 95 DropPosition* position) OVERRIDE; 96 virtual int OnPerformDrop(views::MenuItemView* menu, 97 DropPosition position, 98 const ui::DropTargetEvent& event) OVERRIDE; 99 virtual bool ShowContextMenu(views::MenuItemView* source, 100 int id, 101 const gfx::Point& p, 102 ui::MenuSourceType source_type) OVERRIDE; 103 virtual void DropMenuClosed(views::MenuItemView* menu) OVERRIDE; 104 virtual bool CanDrag(views::MenuItemView* menu) OVERRIDE; 105 virtual void WriteDragData(views::MenuItemView* sender, 106 ui::OSExchangeData* data) OVERRIDE; 107 virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE; 108 virtual views::MenuItemView* GetSiblingMenu( 109 views::MenuItemView* menu, 110 const gfx::Point& screen_point, 111 views::MenuItemView::AnchorPosition* anchor, 112 bool* has_mnemonics, 113 views::MenuButton** button) OVERRIDE; 114 virtual int GetMaxWidthForMenu(views::MenuItemView* view) OVERRIDE; 115 116 // BookmarkModelObserver methods. 117 virtual void BookmarkModelChanged() OVERRIDE; 118 119 private: 120 // BookmarkMenuController deletes itself as necessary. 121 virtual ~BookmarkMenuController(); 122 123 scoped_ptr<views::MenuRunner> menu_runner_; 124 125 scoped_ptr<BookmarkMenuDelegate> menu_delegate_; 126 127 // The node we're showing the contents of. 128 const BookmarkNode* node_; 129 130 // Data for the drop. 131 BookmarkNodeData drop_data_; 132 133 // The observer, may be null. 134 Observer* observer_; 135 136 // Is the menu being shown for a drop? 137 bool for_drop_; 138 139 // The bookmark bar. This is only non-null if we're showing a menu item 140 // for a folder on the bookmark bar and not for drop. 141 BookmarkBarView* bookmark_bar_; 142 143 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController); 144}; 145 146#endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ 147