| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_VIEWS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ |
| 6 #define CHROME_BROWSER_VIEWS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ | 6 #define CHROME_BROWSER_VIEWS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "app/gfx/native_widget_types.h" | 10 #include "app/gfx/native_widget_types.h" |
| 11 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" | 11 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 12 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
| 13 #include "chrome/browser/views/bookmark_context_menu.h" | 13 #include "chrome/browser/views/bookmark_context_menu.h" |
| 14 #include "views/controls/menu/menu_delegate.h" | 14 #include "views/controls/menu/menu_delegate.h" |
| 15 #include "views/controls/menu/menu_item_view.h" | 15 #include "views/controls/menu/menu_item_view.h" |
| 16 | 16 |
| 17 namespace gfx { | 17 namespace gfx { |
| 18 class Rect; | 18 class Rect; |
| 19 } | 19 } // namespace gfx |
| 20 | 20 |
| 21 namespace views { |
| 22 class MenuButton; |
| 23 } // namespace views |
| 24 |
| 25 class BookmarkBarView; |
| 21 class BookmarkContextMenu; | 26 class BookmarkContextMenu; |
| 22 class BookmarkNode; | 27 class BookmarkNode; |
| 23 class Browser; | 28 class Browser; |
| 24 class OSExchangeData; | 29 class OSExchangeData; |
| 25 class PageNavigator; | 30 class PageNavigator; |
| 26 class Profile; | 31 class Profile; |
| 27 | 32 |
| 28 // BookmarkMenuController is responsible for showing a menu of bookmarks, | 33 // BookmarkMenuController is responsible for showing a menu of bookmarks, |
| 29 // each item in the menu represents a bookmark. | 34 // each item in the menu represents a bookmark. |
| 30 // BookmarkMenuController deletes itself as necessary, although the menu can | 35 // BookmarkMenuController deletes itself as necessary, although the menu can |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 // Creates a BookmarkMenuController showing the children of |node| starting | 46 // Creates a BookmarkMenuController showing the children of |node| starting |
| 42 // at index |start_child_index|. | 47 // at index |start_child_index|. |
| 43 BookmarkMenuController(Browser* browser, | 48 BookmarkMenuController(Browser* browser, |
| 44 Profile* profile, | 49 Profile* profile, |
| 45 PageNavigator* page_navigator, | 50 PageNavigator* page_navigator, |
| 46 gfx::NativeWindow parent, | 51 gfx::NativeWindow parent, |
| 47 const BookmarkNode* node, | 52 const BookmarkNode* node, |
| 48 int start_child_index, | 53 int start_child_index, |
| 49 bool show_other_folder); | 54 bool show_other_folder); |
| 50 | 55 |
| 56 void RunMenuAt(BookmarkBarView* bookmark_bar, bool for_drop); |
| 57 |
| 51 // Shows the menu. | 58 // Shows the menu. |
| 52 void RunMenuAt(const gfx::Rect& bounds, | 59 void RunMenuAt(views::MenuButton* button, |
| 53 views::MenuItemView::AnchorPosition position, | 60 views::MenuItemView::AnchorPosition position, |
| 54 bool for_drop); | 61 bool for_drop); |
| 55 | 62 |
| 56 // Hides the menu. | 63 // Hides the menu. |
| 57 void Cancel(); | 64 void Cancel(); |
| 58 | 65 |
| 59 // Returns the node the menu is showing for. | 66 // Returns the node the menu is showing for. |
| 60 const BookmarkNode* node() const { return node_; } | 67 const BookmarkNode* node() const { return node_; } |
| 61 | 68 |
| 62 // Returns the menu. | 69 // Returns the menu. |
| 63 views::MenuItemView* menu() const { return menu_.get(); } | 70 views::MenuItemView* menu() const { return menu_; } |
| 64 | 71 |
| 65 // Returns the context menu, or NULL if the context menu isn't showing. | 72 // Returns the context menu, or NULL if the context menu isn't showing. |
| 66 views::MenuItemView* context_menu() const { | 73 views::MenuItemView* context_menu() const { |
| 67 return context_menu_.get() ? context_menu_->menu() : NULL; | 74 return context_menu_.get() ? context_menu_->menu() : NULL; |
| 68 } | 75 } |
| 69 | 76 |
| 70 void set_observer(Observer* observer) { observer_ = observer; } | 77 void set_observer(Observer* observer) { observer_ = observer; } |
| 71 | 78 |
| 72 // MenuDelegate methods. | 79 // MenuDelegate methods. |
| 73 virtual bool IsTriggerableEvent(const views::MouseEvent& e); | 80 virtual bool IsTriggerableEvent(const views::MouseEvent& e); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 86 const views::DropTargetEvent& event); | 93 const views::DropTargetEvent& event); |
| 87 virtual bool ShowContextMenu(views::MenuItemView* source, | 94 virtual bool ShowContextMenu(views::MenuItemView* source, |
| 88 int id, | 95 int id, |
| 89 int x, | 96 int x, |
| 90 int y, | 97 int y, |
| 91 bool is_mouse_gesture); | 98 bool is_mouse_gesture); |
| 92 virtual void DropMenuClosed(views::MenuItemView* menu); | 99 virtual void DropMenuClosed(views::MenuItemView* menu); |
| 93 virtual bool CanDrag(views::MenuItemView* menu); | 100 virtual bool CanDrag(views::MenuItemView* menu); |
| 94 virtual void WriteDragData(views::MenuItemView* sender, OSExchangeData* data); | 101 virtual void WriteDragData(views::MenuItemView* sender, OSExchangeData* data); |
| 95 virtual int GetDragOperations(views::MenuItemView* sender); | 102 virtual int GetDragOperations(views::MenuItemView* sender); |
| 103 virtual views::MenuItemView* GetSiblingMenu( |
| 104 views::MenuItemView* menu, |
| 105 const gfx::Point& screen_point, |
| 106 views::MenuItemView::AnchorPosition* anchor, |
| 107 bool* has_mnemonics, |
| 108 views::MenuButton** button); |
| 96 | 109 |
| 110 // BookmarkModelObserver methods. |
| 97 virtual void BookmarkModelChanged(); | 111 virtual void BookmarkModelChanged(); |
| 98 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, | 112 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, |
| 99 const BookmarkNode* node); | 113 const BookmarkNode* node); |
| 100 | 114 |
| 101 private: | 115 private: |
| 102 // BookmarkMenuController deletes itself as necessary. | 116 // BookmarkMenuController deletes itself as necessary. |
| 103 ~BookmarkMenuController(); | 117 ~BookmarkMenuController(); |
| 104 | 118 |
| 119 // Creates a menu and adds it to node_to_menu_id_map_. This uses |
| 120 // BuildMenu to recursively populate the menu. |
| 121 views::MenuItemView* CreateMenu(const BookmarkNode* parent, |
| 122 int start_child_index); |
| 123 |
| 105 // Builds the menu for the other bookmarks folder. This is added as the last | 124 // Builds the menu for the other bookmarks folder. This is added as the last |
| 106 // item to menu_. | 125 // item to menu_. |
| 107 void BuildOtherFolderMenu(int* next_menu_id); | 126 void BuildOtherFolderMenu(views::MenuItemView* menu, int* next_menu_id); |
| 108 | 127 |
| 109 // Creates an entry in menu for each child node of |parent| starting at | 128 // Creates an entry in menu for each child node of |parent| starting at |
| 110 // |start_child_index|. | 129 // |start_child_index|. |
| 111 void BuildMenu(const BookmarkNode* parent, | 130 void BuildMenu(const BookmarkNode* parent, |
| 112 int start_child_index, | 131 int start_child_index, |
| 113 views::MenuItemView* menu, | 132 views::MenuItemView* menu, |
| 114 int* next_menu_id); | 133 int* next_menu_id); |
| 115 | 134 |
| 116 Browser* browser_; | 135 Browser* browser_; |
| 117 | 136 |
| 118 Profile* profile_; | 137 Profile* profile_; |
| 119 | 138 |
| 120 PageNavigator* page_navigator_; | 139 PageNavigator* page_navigator_; |
| 121 | 140 |
| 122 // Parent of menus. | 141 // Parent of menus. |
| 123 gfx::NativeWindow parent_; | 142 gfx::NativeWindow parent_; |
| 124 | 143 |
| 125 // The node we're showing the contents of. | 144 // The node we're showing the contents of. |
| 126 const BookmarkNode* node_; | 145 const BookmarkNode* node_; |
| 127 | 146 |
| 128 // Maps from menu id to BookmarkNode. | 147 // Maps from menu id to BookmarkNode. |
| 129 std::map<int, const BookmarkNode*> menu_id_to_node_map_; | 148 std::map<int, const BookmarkNode*> menu_id_to_node_map_; |
| 130 | 149 |
| 131 // Mapping from node to menu id. This only contains entries for nodes of type | 150 // Mapping from node to menu id. This only contains entries for nodes of type |
| 132 // URL. | 151 // URL. |
| 133 std::map<const BookmarkNode*, int> node_to_menu_id_map_; | 152 std::map<const BookmarkNode*, int> node_to_menu_id_map_; |
| 134 | 153 |
| 135 // The menu. | 154 // Current menu. |
| 136 scoped_ptr<views::MenuItemView> menu_; | 155 views::MenuItemView* menu_; |
| 137 | 156 |
| 138 // Data for the drop. | 157 // Data for the drop. |
| 139 BookmarkDragData drop_data_; | 158 BookmarkDragData drop_data_; |
| 140 | 159 |
| 141 // Used when a context menu is shown. | 160 // Used when a context menu is shown. |
| 142 scoped_ptr<BookmarkContextMenu> context_menu_; | 161 scoped_ptr<BookmarkContextMenu> context_menu_; |
| 143 | 162 |
| 144 // The observer, may be null. | 163 // The observer, may be null. |
| 145 Observer* observer_; | 164 Observer* observer_; |
| 146 | 165 |
| 147 // Is the menu being shown for a drop? | 166 // Is the menu being shown for a drop? |
| 148 bool for_drop_; | 167 bool for_drop_; |
| 149 | 168 |
| 150 // Should the other folder be shown? | 169 // Should the other folder be shown? |
| 151 bool show_other_folder_; | 170 bool show_other_folder_; |
| 152 | 171 |
| 172 // The bookmark bar. This is only non-null if we're showing a menu item |
| 173 // for a folder on the bookmark bar and not for drop. |
| 174 BookmarkBarView* bookmark_bar_; |
| 175 |
| 176 typedef std::map<const BookmarkNode*, views::MenuItemView*> NodeToMenuMap; |
| 177 NodeToMenuMap node_to_menu_map_; |
| 178 |
| 179 // ID of the next menu item. |
| 180 int next_menu_id_; |
| 181 |
| 153 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController); | 182 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController); |
| 154 }; | 183 }; |
| 155 | 184 |
| 156 #endif // CHROME_BROWSER_VIEWS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ | 185 #endif // CHROME_BROWSER_VIEWS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ |
| OLD | NEW |