| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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_TOOLBAR_BROWSER_ACTION_VIEW_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | |
| 7 | |
| 8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate.h" | |
| 9 #include "content/public/browser/notification_observer.h" | |
| 10 #include "content/public/browser/notification_registrar.h" | |
| 11 #include "ui/views/controls/button/menu_button.h" | |
| 12 #include "ui/views/controls/button/menu_button_listener.h" | |
| 13 #include "ui/views/drag_controller.h" | |
| 14 #include "ui/views/view.h" | |
| 15 | |
| 16 class Browser; | |
| 17 class ExtensionAction; | |
| 18 | |
| 19 namespace extensions { | |
| 20 class Extension; | |
| 21 } | |
| 22 | |
| 23 namespace gfx { | |
| 24 class Image; | |
| 25 } | |
| 26 | |
| 27 //////////////////////////////////////////////////////////////////////////////// | |
| 28 // BrowserActionView | |
| 29 // A wrapper around a ToolbarActionViewController to display a toolbar action | |
| 30 // action in the BrowserActionsContainer. | |
| 31 // Despite its name, this class can handle any type of toolbar action, including | |
| 32 // extension actions (browser and page actions) and component actions. | |
| 33 // TODO(devlin): Rename this and BrowserActionsContainer when more of the | |
| 34 // toolbar redesign is done. | |
| 35 class BrowserActionView : public views::MenuButton, | |
| 36 public ToolbarActionViewDelegate, | |
| 37 public views::ButtonListener, | |
| 38 public content::NotificationObserver { | |
| 39 public: | |
| 40 // Need DragController here because BrowserActionView could be | |
| 41 // dragged/dropped. | |
| 42 class Delegate : public views::DragController { | |
| 43 public: | |
| 44 // Returns the current web contents. | |
| 45 virtual content::WebContents* GetCurrentWebContents() = 0; | |
| 46 | |
| 47 // Whether the container for this button is shown inside a menu. | |
| 48 virtual bool ShownInsideMenu() const = 0; | |
| 49 | |
| 50 // Notifies that a drag completed. Note this will only happen if the view | |
| 51 // wasn't removed during the drag-and-drop process (i.e., not when there | |
| 52 // was a move in the browser actions, since we re-create the views each | |
| 53 // time we re-order the browser actions). | |
| 54 virtual void OnBrowserActionViewDragDone() = 0; | |
| 55 | |
| 56 // Returns the view of the browser actions overflow menu to use as a | |
| 57 // reference point for a popup when this view isn't visible. | |
| 58 virtual views::MenuButton* GetOverflowReferenceView() = 0; | |
| 59 | |
| 60 // Sets the delegate's active popup owner to be |popup_owner|. | |
| 61 virtual void SetPopupOwner(BrowserActionView* popup_owner) = 0; | |
| 62 | |
| 63 // Hides the active popup of the delegate, if one exists. | |
| 64 virtual void HideActivePopup() = 0; | |
| 65 | |
| 66 // Returns the primary BrowserActionView associated with the given | |
| 67 // |extension|. | |
| 68 virtual BrowserActionView* GetMainViewForAction( | |
| 69 BrowserActionView* view) = 0; | |
| 70 | |
| 71 protected: | |
| 72 ~Delegate() override {} | |
| 73 }; | |
| 74 | |
| 75 BrowserActionView(scoped_ptr<ToolbarActionViewController> view_controller, | |
| 76 Browser* browser, | |
| 77 Delegate* delegate); | |
| 78 ~BrowserActionView() override; | |
| 79 | |
| 80 // Called to update the display to match the browser action's state. | |
| 81 void UpdateState(); | |
| 82 | |
| 83 // Overridden from views::View: | |
| 84 void GetAccessibleState(ui::AXViewState* state) override; | |
| 85 | |
| 86 // Overridden from views::ButtonListener: | |
| 87 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 88 | |
| 89 // Overridden from content::NotificationObserver: | |
| 90 void Observe(int type, | |
| 91 const content::NotificationSource& source, | |
| 92 const content::NotificationDetails& details) override; | |
| 93 | |
| 94 // MenuButton behavior overrides. These methods all default to LabelButton | |
| 95 // behavior unless this button is a popup. In that case, it uses MenuButton | |
| 96 // behavior. MenuButton has the notion of a child popup being shown where the | |
| 97 // button will stay in the pushed state until the "menu" (a popup in this | |
| 98 // case) is dismissed. | |
| 99 bool Activate() override; | |
| 100 bool OnMousePressed(const ui::MouseEvent& event) override; | |
| 101 void OnMouseReleased(const ui::MouseEvent& event) override; | |
| 102 void OnMouseExited(const ui::MouseEvent& event) override; | |
| 103 bool OnKeyReleased(const ui::KeyEvent& event) override; | |
| 104 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 105 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; | |
| 106 | |
| 107 // ToolbarActionViewDelegate: (public because called by others). | |
| 108 content::WebContents* GetCurrentWebContents() const override; | |
| 109 | |
| 110 ToolbarActionViewController* view_controller() { | |
| 111 return view_controller_.get(); | |
| 112 } | |
| 113 Browser* browser() { return browser_; } | |
| 114 | |
| 115 // Returns button icon so it can be accessed during tests. | |
| 116 gfx::ImageSkia GetIconForTest(); | |
| 117 | |
| 118 private: | |
| 119 // Overridden from views::View: | |
| 120 void ViewHierarchyChanged( | |
| 121 const ViewHierarchyChangedDetails& details) override; | |
| 122 void OnDragDone() override; | |
| 123 gfx::Size GetPreferredSize() const override; | |
| 124 void PaintChildren(gfx::Canvas* canvas, | |
| 125 const views::CullSet& cull_set) override; | |
| 126 | |
| 127 // ToolbarActionViewDelegate: | |
| 128 views::View* GetAsView() override; | |
| 129 bool IsShownInMenu() override; | |
| 130 views::FocusManager* GetFocusManagerForAccelerator() override; | |
| 131 views::Widget* GetParentForContextMenu() override; | |
| 132 ToolbarActionViewController* GetPreferredPopupViewController() override; | |
| 133 views::View* GetReferenceViewForPopup() override; | |
| 134 views::MenuButton* GetContextMenuButton() override; | |
| 135 void HideActivePopup() override; | |
| 136 void OnIconUpdated() override; | |
| 137 void OnPopupShown(bool grant_tab_permissions) override; | |
| 138 void CleanupPopup() override; | |
| 139 | |
| 140 // A lock to keep the MenuButton pressed when a menu or popup is visible. | |
| 141 // This needs to be destroyed after |view_controller_|, because | |
| 142 // |view_controller_|'s destructor can call CleanupPopup(), which uses this | |
| 143 // object. | |
| 144 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_; | |
| 145 | |
| 146 // The controller for this toolbar action view. | |
| 147 scoped_ptr<ToolbarActionViewController> view_controller_; | |
| 148 | |
| 149 // The associated browser. | |
| 150 Browser* browser_; | |
| 151 | |
| 152 // Delegate that usually represents a container for BrowserActionView. | |
| 153 Delegate* delegate_; | |
| 154 | |
| 155 // Used to make sure we only register the command once. | |
| 156 bool called_register_command_; | |
| 157 | |
| 158 content::NotificationRegistrar registrar_; | |
| 159 | |
| 160 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); | |
| 161 }; | |
| 162 | |
| 163 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | |
| OLD | NEW |