| 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_TOOLBAR_ACTION_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate_views.h" | 8 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate_views.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" |
| 11 #include "ui/views/animation/ink_drop_host.h" |
| 11 #include "ui/views/context_menu_controller.h" | 12 #include "ui/views/context_menu_controller.h" |
| 12 #include "ui/views/controls/button/menu_button.h" | 13 #include "ui/views/controls/button/menu_button.h" |
| 13 #include "ui/views/controls/button/menu_button_listener.h" | 14 #include "ui/views/controls/button/menu_button_listener.h" |
| 14 #include "ui/views/drag_controller.h" | 15 #include "ui/views/drag_controller.h" |
| 15 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
| 16 | 17 |
| 17 class ExtensionAction; | 18 class ExtensionAction; |
| 18 class Profile; | 19 class Profile; |
| 19 | 20 |
| 20 namespace extensions { | 21 namespace extensions { |
| 21 class Extension; | 22 class Extension; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace gfx { | 25 namespace gfx { |
| 25 class Image; | 26 class Image; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace views { | 29 namespace views { |
| 30 class InkDropAnimationController; |
| 29 class MenuRunner; | 31 class MenuRunner; |
| 30 } | 32 } |
| 31 | 33 |
| 32 //////////////////////////////////////////////////////////////////////////////// | 34 //////////////////////////////////////////////////////////////////////////////// |
| 33 // ToolbarActionView | 35 // ToolbarActionView |
| 34 // A wrapper around a ToolbarActionViewController to display a toolbar action | 36 // A wrapper around a ToolbarActionViewController to display a toolbar action |
| 35 // action in the BrowserActionsContainer. | 37 // action in the BrowserActionsContainer. |
| 36 class ToolbarActionView : public views::MenuButton, | 38 class ToolbarActionView : public views::MenuButton, |
| 37 public ToolbarActionViewDelegateViews, | 39 public ToolbarActionViewDelegateViews, |
| 38 public views::MenuButtonListener, | 40 public views::MenuButtonListener, |
| 39 public views::ContextMenuController, | 41 public views::ContextMenuController, |
| 40 public content::NotificationObserver { | 42 public content::NotificationObserver, |
| 43 public views::InkDropHost { |
| 41 public: | 44 public: |
| 42 // Need DragController here because ToolbarActionView could be | 45 // Need DragController here because ToolbarActionView could be |
| 43 // dragged/dropped. | 46 // dragged/dropped. |
| 44 class Delegate : public views::DragController { | 47 class Delegate : public views::DragController { |
| 45 public: | 48 public: |
| 46 // Returns the current web contents. | 49 // Returns the current web contents. |
| 47 virtual content::WebContents* GetCurrentWebContents() = 0; | 50 virtual content::WebContents* GetCurrentWebContents() = 0; |
| 48 | 51 |
| 49 // Whether the container for this button is shown inside a menu. | 52 // Whether the container for this button is shown inside a menu. |
| 50 virtual bool ShownInsideMenu() const = 0; | 53 virtual bool ShownInsideMenu() const = 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 67 Profile* profile, | 70 Profile* profile, |
| 68 Delegate* delegate); | 71 Delegate* delegate); |
| 69 ~ToolbarActionView() override; | 72 ~ToolbarActionView() override; |
| 70 | 73 |
| 71 // views::MenuButton: | 74 // views::MenuButton: |
| 72 void GetAccessibleState(ui::AXViewState* state) override; | 75 void GetAccessibleState(ui::AXViewState* state) override; |
| 73 | 76 |
| 74 // views::MenuButtonListener: | 77 // views::MenuButtonListener: |
| 75 void OnMenuButtonClicked(views::View* sender, | 78 void OnMenuButtonClicked(views::View* sender, |
| 76 const gfx::Point& point) override; | 79 const gfx::Point& point) override; |
| 80 void OnMenuButtonReleasedWithoutClick(views::View* sender) override; |
| 77 | 81 |
| 78 // content::NotificationObserver: | 82 // content::NotificationObserver: |
| 79 void Observe(int type, | 83 void Observe(int type, |
| 80 const content::NotificationSource& source, | 84 const content::NotificationSource& source, |
| 81 const content::NotificationDetails& details) override; | 85 const content::NotificationDetails& details) override; |
| 82 | 86 |
| 83 // views::MenuButton: | 87 // views::MenuButton: |
| 84 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; | 88 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; |
| 85 void OnMouseEntered(const ui::MouseEvent& event) override; | 89 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 86 bool ShouldEnterPushedState(const ui::Event& event) override; | 90 bool ShouldEnterPushedState(const ui::Event& event) override; |
| 87 | 91 |
| 88 // ToolbarActionViewDelegate: (public because called by others). | 92 // ToolbarActionViewDelegate: (public because called by others). |
| 89 void UpdateState() override; | 93 void UpdateState() override; |
| 90 content::WebContents* GetCurrentWebContents() const override; | 94 content::WebContents* GetCurrentWebContents() const override; |
| 91 | 95 |
| 92 ToolbarActionViewController* view_controller() { | 96 ToolbarActionViewController* view_controller() { |
| 93 return view_controller_; | 97 return view_controller_; |
| 94 } | 98 } |
| 95 | 99 |
| 96 // Returns button icon so it can be accessed during tests. | 100 // Returns button icon so it can be accessed during tests. |
| 97 gfx::ImageSkia GetIconForTest(); | 101 gfx::ImageSkia GetIconForTest(); |
| 98 | 102 |
| 99 bool wants_to_run_for_testing() const { return wants_to_run_; } | 103 bool wants_to_run_for_testing() const { return wants_to_run_; } |
| 100 | 104 |
| 105 // views::InkDropHost: |
| 106 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 107 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 108 |
| 109 protected: |
| 110 // Returns the Point where the ink drop should be centered. |
| 111 virtual gfx::Point CalculateInkDropCenter() const; |
| 112 |
| 113 views::InkDropAnimationController* ink_drop_animation_controller() { |
| 114 return ink_drop_animation_controller_.get(); |
| 115 } |
| 116 |
| 101 private: | 117 private: |
| 102 // views::MenuButton: | 118 // views::MenuButton: |
| 103 gfx::Size GetPreferredSize() const override; | 119 gfx::Size GetPreferredSize() const override; |
| 120 void Layout() override; |
| 121 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 122 void OnGestureEvent(ui::GestureEvent* event) override; |
| 104 void OnDragDone() override; | 123 void OnDragDone() override; |
| 105 void ViewHierarchyChanged( | 124 void ViewHierarchyChanged( |
| 106 const ViewHierarchyChangedDetails& details) override; | 125 const ViewHierarchyChangedDetails& details) override; |
| 107 | 126 |
| 108 // ToolbarActionViewDelegateViews: | 127 // ToolbarActionViewDelegateViews: |
| 109 views::View* GetAsView() override; | 128 views::View* GetAsView() override; |
| 110 views::FocusManager* GetFocusManagerForAccelerator() override; | 129 views::FocusManager* GetFocusManagerForAccelerator() override; |
| 111 views::View* GetReferenceViewForPopup() override; | 130 views::View* GetReferenceViewForPopup() override; |
| 112 bool IsMenuRunning() const override; | 131 bool IsMenuRunning() const override; |
| 113 void OnPopupShown(bool by_user) override; | 132 void OnPopupShown(bool by_user) override; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 139 // Delegate that usually represents a container for ToolbarActionView. | 158 // Delegate that usually represents a container for ToolbarActionView. |
| 140 Delegate* delegate_; | 159 Delegate* delegate_; |
| 141 | 160 |
| 142 // Used to make sure we only register the command once. | 161 // Used to make sure we only register the command once. |
| 143 bool called_register_command_; | 162 bool called_register_command_; |
| 144 | 163 |
| 145 // The cached value of whether or not the action wants to run on the current | 164 // The cached value of whether or not the action wants to run on the current |
| 146 // tab. | 165 // tab. |
| 147 bool wants_to_run_; | 166 bool wants_to_run_; |
| 148 | 167 |
| 168 // Indicates if menu is currently showing. |
| 169 bool menu_showing_; |
| 170 |
| 149 // Responsible for running the menu. | 171 // Responsible for running the menu. |
| 150 scoped_ptr<views::MenuRunner> menu_runner_; | 172 scoped_ptr<views::MenuRunner> menu_runner_; |
| 151 | 173 |
| 152 // If non-null, this is the next toolbar action context menu that wants to run | 174 // If non-null, this is the next toolbar action context menu that wants to run |
| 153 // once the current owner (this one) is done. | 175 // once the current owner (this one) is done. |
| 154 base::Closure followup_context_menu_task_; | 176 base::Closure followup_context_menu_task_; |
| 155 | 177 |
| 156 // The time the popup was last closed. | 178 // The time the popup was last closed. |
| 157 base::TimeTicks popup_closed_time_; | 179 base::TimeTicks popup_closed_time_; |
| 158 | 180 |
| 159 content::NotificationRegistrar registrar_; | 181 content::NotificationRegistrar registrar_; |
| 160 | 182 |
| 183 // Animation controller for the ink drop ripple effect. |
| 184 scoped_ptr<views::InkDropAnimationController> ink_drop_animation_controller_; |
| 185 |
| 161 base::WeakPtrFactory<ToolbarActionView> weak_factory_; | 186 base::WeakPtrFactory<ToolbarActionView> weak_factory_; |
| 162 | 187 |
| 163 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); | 188 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); |
| 164 }; | 189 }; |
| 165 | 190 |
| 166 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ | 191 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
| OLD | NEW |