| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate.h" | 8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate.h" |
| 9 #include "content/public/browser/notification_observer.h" | 9 #include "content/public/browser/notification_observer.h" |
| 10 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 // Hides the active popup of the delegate, if one exists. | 63 // Hides the active popup of the delegate, if one exists. |
| 64 virtual void HideActivePopup() = 0; | 64 virtual void HideActivePopup() = 0; |
| 65 | 65 |
| 66 // Returns the primary BrowserActionView associated with the given | 66 // Returns the primary BrowserActionView associated with the given |
| 67 // |extension|. | 67 // |extension|. |
| 68 virtual BrowserActionView* GetMainViewForAction( | 68 virtual BrowserActionView* GetMainViewForAction( |
| 69 BrowserActionView* view) = 0; | 69 BrowserActionView* view) = 0; |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 virtual ~Delegate() {} | 72 ~Delegate() override {} |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 BrowserActionView(scoped_ptr<ToolbarActionViewController> view_controller, | 75 BrowserActionView(scoped_ptr<ToolbarActionViewController> view_controller, |
| 76 Browser* browser, | 76 Browser* browser, |
| 77 Delegate* delegate); | 77 Delegate* delegate); |
| 78 virtual ~BrowserActionView(); | 78 ~BrowserActionView() override; |
| 79 | 79 |
| 80 // Called to update the display to match the browser action's state. | 80 // Called to update the display to match the browser action's state. |
| 81 void UpdateState(); | 81 void UpdateState(); |
| 82 | 82 |
| 83 // Overridden from views::View: | 83 // Overridden from views::View: |
| 84 virtual void GetAccessibleState(ui::AXViewState* state) override; | 84 void GetAccessibleState(ui::AXViewState* state) override; |
| 85 | 85 |
| 86 // Overridden from views::ButtonListener: | 86 // Overridden from views::ButtonListener: |
| 87 virtual void ButtonPressed(views::Button* sender, | 87 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 88 const ui::Event& event) override; | |
| 89 | 88 |
| 90 // Overridden from content::NotificationObserver: | 89 // Overridden from content::NotificationObserver: |
| 91 virtual void Observe(int type, | 90 void Observe(int type, |
| 92 const content::NotificationSource& source, | 91 const content::NotificationSource& source, |
| 93 const content::NotificationDetails& details) override; | 92 const content::NotificationDetails& details) override; |
| 94 | 93 |
| 95 // MenuButton behavior overrides. These methods all default to LabelButton | 94 // MenuButton behavior overrides. These methods all default to LabelButton |
| 96 // behavior unless this button is a popup. In that case, it uses MenuButton | 95 // behavior unless this button is a popup. In that case, it uses MenuButton |
| 97 // behavior. MenuButton has the notion of a child popup being shown where the | 96 // behavior. MenuButton has the notion of a child popup being shown where the |
| 98 // button will stay in the pushed state until the "menu" (a popup in this | 97 // button will stay in the pushed state until the "menu" (a popup in this |
| 99 // case) is dismissed. | 98 // case) is dismissed. |
| 100 virtual bool Activate() override; | 99 bool Activate() override; |
| 101 virtual bool OnMousePressed(const ui::MouseEvent& event) override; | 100 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 102 virtual void OnMouseReleased(const ui::MouseEvent& event) override; | 101 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 103 virtual void OnMouseExited(const ui::MouseEvent& event) override; | 102 void OnMouseExited(const ui::MouseEvent& event) override; |
| 104 virtual bool OnKeyReleased(const ui::KeyEvent& event) override; | 103 bool OnKeyReleased(const ui::KeyEvent& event) override; |
| 105 virtual void OnGestureEvent(ui::GestureEvent* event) override; | 104 void OnGestureEvent(ui::GestureEvent* event) override; |
| 106 virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const | 105 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; |
| 107 override; | |
| 108 | 106 |
| 109 // ToolbarActionViewDelegate: (public because called by others). | 107 // ToolbarActionViewDelegate: (public because called by others). |
| 110 virtual content::WebContents* GetCurrentWebContents() const override; | 108 content::WebContents* GetCurrentWebContents() const override; |
| 111 | 109 |
| 112 ToolbarActionViewController* view_controller() { | 110 ToolbarActionViewController* view_controller() { |
| 113 return view_controller_.get(); | 111 return view_controller_.get(); |
| 114 } | 112 } |
| 115 Browser* browser() { return browser_; } | 113 Browser* browser() { return browser_; } |
| 116 | 114 |
| 117 // Returns button icon so it can be accessed during tests. | 115 // Returns button icon so it can be accessed during tests. |
| 118 gfx::ImageSkia GetIconForTest(); | 116 gfx::ImageSkia GetIconForTest(); |
| 119 | 117 |
| 120 private: | 118 private: |
| 121 // Overridden from views::View: | 119 // Overridden from views::View: |
| 122 virtual void ViewHierarchyChanged( | 120 void ViewHierarchyChanged( |
| 123 const ViewHierarchyChangedDetails& details) override; | 121 const ViewHierarchyChangedDetails& details) override; |
| 124 virtual void OnDragDone() override; | 122 void OnDragDone() override; |
| 125 virtual gfx::Size GetPreferredSize() const override; | 123 gfx::Size GetPreferredSize() const override; |
| 126 virtual void PaintChildren(gfx::Canvas* canvas, | 124 void PaintChildren(gfx::Canvas* canvas, |
| 127 const views::CullSet& cull_set) override; | 125 const views::CullSet& cull_set) override; |
| 128 | 126 |
| 129 // ToolbarActionViewDelegate: | 127 // ToolbarActionViewDelegate: |
| 130 virtual views::View* GetAsView() override; | 128 views::View* GetAsView() override; |
| 131 virtual bool IsShownInMenu() override; | 129 bool IsShownInMenu() override; |
| 132 virtual views::FocusManager* GetFocusManagerForAccelerator() override; | 130 views::FocusManager* GetFocusManagerForAccelerator() override; |
| 133 virtual views::Widget* GetParentForContextMenu() override; | 131 views::Widget* GetParentForContextMenu() override; |
| 134 virtual ToolbarActionViewController* GetPreferredPopupViewController() | 132 ToolbarActionViewController* GetPreferredPopupViewController() override; |
| 135 override; | 133 views::View* GetReferenceViewForPopup() override; |
| 136 virtual views::View* GetReferenceViewForPopup() override; | 134 views::MenuButton* GetContextMenuButton() override; |
| 137 virtual views::MenuButton* GetContextMenuButton() override; | 135 void HideActivePopup() override; |
| 138 virtual void HideActivePopup() override; | 136 void OnIconUpdated() override; |
| 139 virtual void OnIconUpdated() override; | 137 void OnPopupShown(bool grant_tab_permissions) override; |
| 140 virtual void OnPopupShown(bool grant_tab_permissions) override; | 138 void CleanupPopup() override; |
| 141 virtual void CleanupPopup() override; | |
| 142 | 139 |
| 143 // A lock to keep the MenuButton pressed when a menu or popup is visible. | 140 // A lock to keep the MenuButton pressed when a menu or popup is visible. |
| 144 // This needs to be destroyed after |view_controller_|, because | 141 // This needs to be destroyed after |view_controller_|, because |
| 145 // |view_controller_|'s destructor can call CleanupPopup(), which uses this | 142 // |view_controller_|'s destructor can call CleanupPopup(), which uses this |
| 146 // object. | 143 // object. |
| 147 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_; | 144 scoped_ptr<views::MenuButton::PressedLock> pressed_lock_; |
| 148 | 145 |
| 149 // The controller for this toolbar action view. | 146 // The controller for this toolbar action view. |
| 150 scoped_ptr<ToolbarActionViewController> view_controller_; | 147 scoped_ptr<ToolbarActionViewController> view_controller_; |
| 151 | 148 |
| 152 // The associated browser. | 149 // The associated browser. |
| 153 Browser* browser_; | 150 Browser* browser_; |
| 154 | 151 |
| 155 // Delegate that usually represents a container for BrowserActionView. | 152 // Delegate that usually represents a container for BrowserActionView. |
| 156 Delegate* delegate_; | 153 Delegate* delegate_; |
| 157 | 154 |
| 158 // Used to make sure we only register the command once. | 155 // Used to make sure we only register the command once. |
| 159 bool called_register_command_; | 156 bool called_register_command_; |
| 160 | 157 |
| 161 content::NotificationRegistrar registrar_; | 158 content::NotificationRegistrar registrar_; |
| 162 | 159 |
| 163 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); | 160 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); |
| 164 }; | 161 }; |
| 165 | 162 |
| 166 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ | 163 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ |
| OLD | NEW |