| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 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_GTK_BOOKMARK_CONTEXT_MENU_H_ | |
| 6 #define CHROME_BROWSER_GTK_BOOKMARK_CONTEXT_MENU_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/gfx/native_widget_types.h" | |
| 12 #include "base/scoped_ptr.h" | |
| 13 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | |
| 14 | |
| 15 // TODO(port): Port this file. | |
| 16 #if defined(TOOLKIT_VIEWS) | |
| 17 #include "views/controls/menu/menu_delegate.h" | |
| 18 #elif defined(OS_LINUX) | |
| 19 #include "chrome/browser/gtk/menu_gtk.h" | |
| 20 #else | |
| 21 #include "chrome/common/temp_scaffolding_stubs.h" | |
| 22 #endif | |
| 23 | |
| 24 class Browser; | |
| 25 class PageNavigator; | |
| 26 class Profile; | |
| 27 | |
| 28 // BookmarkContextMenu manages the context menu shown for the | |
| 29 // bookmark bar, items on the bookmark bar, submenus of the bookmark bar and | |
| 30 // the bookmark manager. | |
| 31 class BookmarkContextMenu : public BookmarkModelObserver, | |
| 32 #if defined(TOOLKIT_VIEWS) | |
| 33 public views::MenuDelegate | |
| 34 #elif defined(OS_LINUX) | |
| 35 public MenuGtk::Delegate | |
| 36 #endif | |
| 37 { | |
| 38 public: | |
| 39 // Used to configure what the context menu shows. | |
| 40 enum ConfigurationType { | |
| 41 BOOKMARK_BAR, | |
| 42 BOOKMARK_MANAGER_TABLE, | |
| 43 // Used when the source is the table in the bookmark manager and the table | |
| 44 // is showing recently bookmarked or searched. | |
| 45 BOOKMARK_MANAGER_TABLE_OTHER, | |
| 46 BOOKMARK_MANAGER_TREE, | |
| 47 BOOKMARK_MANAGER_ORGANIZE_MENU, | |
| 48 // Used when the source is the bookmark manager and the table is showing | |
| 49 // recently bookmarked or searched. | |
| 50 BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER | |
| 51 }; | |
| 52 | |
| 53 class Delegate { | |
| 54 public: | |
| 55 // Called when one of the menu items is selected and executed. | |
| 56 virtual void WillExecuteCommand() = 0; | |
| 57 }; | |
| 58 | |
| 59 // Creates the bookmark context menu. | |
| 60 // |profile| is used for opening urls as well as enabling 'open incognito'. | |
| 61 // |browser| is used to determine the PageNavigator and may be null. | |
| 62 // |navigator| is used if |browser| is null, and is provided for testing. | |
| 63 // |parent| is the parent for newly created nodes if |selection| is empty. | |
| 64 // |selection| is the nodes the context menu operates on and may be empty. | |
| 65 // |configuration| determines which items to show. | |
| 66 BookmarkContextMenu(gfx::NativeView hwnd, | |
| 67 Profile* profile, | |
| 68 Browser* browser, | |
| 69 PageNavigator* navigator, | |
| 70 const BookmarkNode* parent, | |
| 71 const std::vector<const BookmarkNode*>& selection, | |
| 72 ConfigurationType configuration, | |
| 73 Delegate* delegate); | |
| 74 virtual ~BookmarkContextMenu(); | |
| 75 | |
| 76 #if defined(TOOLKIT_VIEWS) | |
| 77 // Shows the menu at the specified place. | |
| 78 void RunMenuAt(int x, int y); | |
| 79 | |
| 80 // Returns the menu. | |
| 81 views::MenuItemView* menu() const { return menu_.get(); } | |
| 82 #elif defined(OS_LINUX) | |
| 83 // Pops up this menu. This call doesn't block. | |
| 84 void PopupAsContext(guint32 event_time); | |
| 85 | |
| 86 // Returns the menu. | |
| 87 GtkWidget* menu() const { return menu_->widget(); } | |
| 88 #endif | |
| 89 | |
| 90 // Should be called by the delegate when it is no longer valid. | |
| 91 void DelegateDestroyed(); | |
| 92 | |
| 93 // Menu::Delegate / MenuGtk::Delegate methods. | |
| 94 virtual void ExecuteCommand(int id); | |
| 95 virtual bool IsItemChecked(int id) const; | |
| 96 virtual bool IsCommandEnabled(int id) const; | |
| 97 | |
| 98 private: | |
| 99 // BookmarkModelObserver method. Any change to the model results in closing | |
| 100 // the menu. | |
| 101 virtual void Loaded(BookmarkModel* model) {} | |
| 102 virtual void BookmarkModelBeingDeleted(BookmarkModel* model); | |
| 103 virtual void BookmarkNodeMoved(BookmarkModel* model, | |
| 104 const BookmarkNode* old_parent, | |
| 105 int old_index, | |
| 106 const BookmarkNode* new_parent, | |
| 107 int new_index); | |
| 108 virtual void BookmarkNodeAdded(BookmarkModel* model, | |
| 109 const BookmarkNode* parent, | |
| 110 int index); | |
| 111 virtual void BookmarkNodeRemoved(BookmarkModel* model, | |
| 112 const BookmarkNode* parent, | |
| 113 int index, | |
| 114 const BookmarkNode* node); | |
| 115 virtual void BookmarkNodeChanged(BookmarkModel* model, | |
| 116 const BookmarkNode* node); | |
| 117 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, | |
| 118 const BookmarkNode* node) {} | |
| 119 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | |
| 120 const BookmarkNode* node); | |
| 121 | |
| 122 // Invoked from the various bookmark model observer methods. Closes the menu. | |
| 123 void ModelChanged(); | |
| 124 | |
| 125 // Builds the platform specific menu object. | |
| 126 void CreateMenuObject(); | |
| 127 | |
| 128 // Adds a IDS_* style command to the menu. | |
| 129 void AppendItem(int id); | |
| 130 // Adds a IDS_* style command to the menu with a different localized string. | |
| 131 void AppendItem(int id, int localization_id); | |
| 132 // Adds a separator to the menu. | |
| 133 void AppendSeparator(); | |
| 134 // Adds a checkable item to the menu. | |
| 135 void AppendCheckboxItem(int id); | |
| 136 | |
| 137 // Removes the observer from the model and NULLs out model_. | |
| 138 BookmarkModel* RemoveModelObserver(); | |
| 139 | |
| 140 // Returns true if selection_ has at least one bookmark of type url. | |
| 141 bool HasURLs() const; | |
| 142 | |
| 143 // Returns the parent for newly created folders/bookmarks. If selection_ | |
| 144 // has one element and it is a folder, selection_[0] is returned, otherwise | |
| 145 // parent_ is returned. | |
| 146 const BookmarkNode* GetParentForNewNodes() const; | |
| 147 | |
| 148 gfx::NativeView wnd_; | |
| 149 Profile* profile_; | |
| 150 Browser* browser_; | |
| 151 PageNavigator* navigator_; | |
| 152 const BookmarkNode* parent_; | |
| 153 std::vector<const BookmarkNode*> selection_; | |
| 154 BookmarkModel* model_; | |
| 155 ConfigurationType configuration_; | |
| 156 Delegate* delegate_; | |
| 157 | |
| 158 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) | |
| 159 scoped_ptr<views::MenuItemView> menu_; | |
| 160 #elif defined(OS_LINUX) | |
| 161 scoped_ptr<MenuGtk> menu_; | |
| 162 #endif | |
| 163 | |
| 164 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenu); | |
| 165 }; | |
| 166 | |
| 167 #endif // CHROME_BROWSER_GTK_BOOKMARK_CONTEXT_MENU_H_ | |
| OLD | NEW |