1 // Copyright (c) 2011 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_CONTEXT_MENU_CONTROLLER_VIEWS_H_ 6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_VIEWS_H_ 7 #pragma once 8 9 #include <vector> 10 11 #include "base/basictypes.h" 12 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" 13 #include "ui/gfx/native_widget_types.h" 14 15 class PageNavigator; 16 class Profile; 17 18 // An interface implemented by an object that performs actions on the actual 19 // menu for the controller. 20 class BookmarkContextMenuControllerViewsDelegate { 21 public: 22 virtual ~BookmarkContextMenuControllerViewsDelegate() {} 23 24 // Closes the bookmark context menu. 25 virtual void CloseMenu() = 0; 26 27 // Methods that add items to the underlying menu. 28 virtual void AddItemWithStringId(int command_id, int string_id) = 0; 29 virtual void AddSeparator() = 0; 30 virtual void AddCheckboxItem(int command_id, int string_id) = 0; 31 32 // Sent before bookmarks are removed. 33 virtual void WillRemoveBookmarks( 34 const std::vector<const BookmarkNode*>& bookmarks) {} 35 36 // Sent after bookmarks have been removed. 37 virtual void DidRemoveBookmarks() {} 38 }; 39 40 // BookmarkContextMenuControllerViews creates and manages state for the context 41 // menu shown for any bookmark item. 42 class BookmarkContextMenuControllerViews : public BaseBookmarkModelObserver { 43 public: 44 // Creates the bookmark context menu. 45 // |parent_window| is the window that this menu should be added to. 46 // |delegate| is described above. 47 // |profile| is used for opening urls as well as enabling 'open incognito'. 48 // |navigator| is used if |browser| is null, and is provided for testing. 49 // |parent| is the parent for newly created nodes if |selection| is empty. 50 // |selection| is the nodes the context menu operates on and may be empty. 51 BookmarkContextMenuControllerViews( 52 gfx::NativeWindow parent_window, 53 BookmarkContextMenuControllerViewsDelegate* delegate, 54 Profile* profile, 55 PageNavigator* navigator, 56 const BookmarkNode* parent, 57 const std::vector<const BookmarkNode*>& selection); 58 virtual ~BookmarkContextMenuControllerViews(); 59 60 void BuildMenu(); 61 62 void ExecuteCommand(int id); 63 bool IsItemChecked(int id) const; 64 bool IsCommandEnabled(int id) const; 65 66 // Accessors: 67 Profile* profile() const { return profile_; } 68 PageNavigator* navigator() const { return navigator_; } 69 70 private: 71 // Overridden from BaseBookmarkModelObserver: 72 // Any change to the model results in closing the menu. 73 virtual void BookmarkModelChanged(); 74 75 // Removes the observer from the model and NULLs out model_. 76 BookmarkModel* RemoveModelObserver(); 77 78 // Returns true if selection_ has at least one bookmark of type url. 79 bool HasURLs() const; 80 81 gfx::NativeWindow parent_window_; 82 BookmarkContextMenuControllerViewsDelegate* delegate_; 83 Profile* profile_; 84 PageNavigator* navigator_; 85 const BookmarkNode* parent_; 86 std::vector<const BookmarkNode*> selection_; 87 BookmarkModel* model_; 88 89 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuControllerViews); 90 }; 91 92 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_VIEWS_H_ 93