| 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 "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate_views.h" | 9 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate_views.h" |
| 10 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
| 11 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
| 12 #include "ui/views/animation/ink_drop_host.h" |
| 12 #include "ui/views/context_menu_controller.h" | 13 #include "ui/views/context_menu_controller.h" |
| 13 #include "ui/views/controls/button/menu_button.h" | 14 #include "ui/views/controls/button/menu_button.h" |
| 14 #include "ui/views/controls/button/menu_button_listener.h" | 15 #include "ui/views/controls/button/menu_button_listener.h" |
| 15 #include "ui/views/drag_controller.h" | 16 #include "ui/views/drag_controller.h" |
| 16 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
| 17 | 18 |
| 18 class ExtensionAction; | 19 class ExtensionAction; |
| 19 class Profile; | 20 class Profile; |
| 20 | 21 |
| 21 namespace extensions { | 22 namespace extensions { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 } | 33 } |
| 33 | 34 |
| 34 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
| 35 // ToolbarActionView | 36 // ToolbarActionView |
| 36 // A wrapper around a ToolbarActionViewController to display a toolbar action | 37 // A wrapper around a ToolbarActionViewController to display a toolbar action |
| 37 // action in the BrowserActionsContainer. | 38 // action in the BrowserActionsContainer. |
| 38 class ToolbarActionView : public views::MenuButton, | 39 class ToolbarActionView : public views::MenuButton, |
| 39 public ToolbarActionViewDelegateViews, | 40 public ToolbarActionViewDelegateViews, |
| 40 public views::MenuButtonListener, | 41 public views::MenuButtonListener, |
| 41 public views::ContextMenuController, | 42 public views::ContextMenuController, |
| 42 public content::NotificationObserver { | 43 public content::NotificationObserver, |
| 44 public views::InkDropHost { |
| 43 public: | 45 public: |
| 44 // Need DragController here because ToolbarActionView could be | 46 // Need DragController here because ToolbarActionView could be |
| 45 // dragged/dropped. | 47 // dragged/dropped. |
| 46 class Delegate : public views::DragController { | 48 class Delegate : public views::DragController { |
| 47 public: | 49 public: |
| 48 // Returns the current web contents. | 50 // Returns the current web contents. |
| 49 virtual content::WebContents* GetCurrentWebContents() = 0; | 51 virtual content::WebContents* GetCurrentWebContents() = 0; |
| 50 | 52 |
| 51 // Whether the container for this button is shown inside a menu. | 53 // Whether the container for this button is shown inside a menu. |
| 52 virtual bool ShownInsideMenu() const = 0; | 54 virtual bool ShownInsideMenu() const = 0; |
| 53 | 55 |
| 54 // Notifies that a drag completed. | 56 // Notifies that a drag completed. |
| 55 virtual void OnToolbarActionViewDragDone() = 0; | 57 virtual void OnToolbarActionViewDragDone() = 0; |
| 56 | 58 |
| 57 // Returns the view of the toolbar actions overflow menu to use as a | 59 // Returns the view of the toolbar actions overflow menu to use as a |
| 58 // reference point for a popup when this view isn't visible. | 60 // reference point for a popup when this view isn't visible. |
| 59 virtual views::MenuButton* GetOverflowReferenceView() = 0; | 61 virtual views::MenuButton* GetOverflowReferenceView() = 0; |
| 60 | 62 |
| 61 // Notifies the delegate that the mouse entered the view. | 63 // Notifies the delegate that the mouse entered the view. |
| 62 virtual void OnMouseEnteredToolbarActionView() = 0; | 64 virtual void OnMouseEnteredToolbarActionView() = 0; |
| 63 | 65 |
| 64 protected: | 66 protected: |
| 65 ~Delegate() override {} | 67 ~Delegate() override {} |
| 66 }; | 68 }; |
| 67 | 69 |
| 70 // Callback type used for testing. |
| 71 using ContextMenuCallback = base::Callback<void(ToolbarActionView*)>; |
| 72 |
| 68 ToolbarActionView(ToolbarActionViewController* view_controller, | 73 ToolbarActionView(ToolbarActionViewController* view_controller, |
| 69 Profile* profile, | 74 Profile* profile, |
| 70 Delegate* delegate); | 75 Delegate* delegate); |
| 71 ~ToolbarActionView() override; | 76 ~ToolbarActionView() override; |
| 72 | 77 |
| 73 // views::MenuButton: | 78 // views::MenuButton: |
| 74 void GetAccessibleState(ui::AXViewState* state) override; | 79 void GetAccessibleState(ui::AXViewState* state) override; |
| 80 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; |
| 81 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 82 bool ShouldEnterPushedState(const ui::Event& event) override; |
| 83 |
| 84 // ToolbarActionViewDelegateViews: |
| 85 content::WebContents* GetCurrentWebContents() const override; |
| 86 void UpdateState() override; |
| 75 | 87 |
| 76 // views::MenuButtonListener: | 88 // views::MenuButtonListener: |
| 77 void OnMenuButtonClicked(views::View* sender, | 89 void OnMenuButtonClicked(views::View* sender, |
| 78 const gfx::Point& point) override; | 90 const gfx::Point& point) override; |
| 79 | 91 |
| 80 // content::NotificationObserver: | 92 // content::NotificationObserver: |
| 81 void Observe(int type, | 93 void Observe(int type, |
| 82 const content::NotificationSource& source, | 94 const content::NotificationSource& source, |
| 83 const content::NotificationDetails& details) override; | 95 const content::NotificationDetails& details) override; |
| 84 | 96 |
| 85 // views::MenuButton: | 97 // views::InkDropHost: |
| 86 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; | 98 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 87 void OnMouseEntered(const ui::MouseEvent& event) override; | 99 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 88 bool ShouldEnterPushedState(const ui::Event& event) override; | |
| 89 | |
| 90 // ToolbarActionViewDelegate: (public because called by others). | |
| 91 void UpdateState() override; | |
| 92 content::WebContents* GetCurrentWebContents() const override; | |
| 93 | 100 |
| 94 ToolbarActionViewController* view_controller() { | 101 ToolbarActionViewController* view_controller() { |
| 95 return view_controller_; | 102 return view_controller_; |
| 96 } | 103 } |
| 97 | 104 |
| 98 // Returns button icon so it can be accessed during tests. | 105 // Returns button icon so it can be accessed during tests. |
| 99 gfx::ImageSkia GetIconForTest(); | 106 gfx::ImageSkia GetIconForTest(); |
| 100 | 107 |
| 101 bool wants_to_run_for_testing() const { return wants_to_run_; } | 108 bool wants_to_run_for_testing() const { return wants_to_run_; } |
| 102 | 109 |
| 103 using ContextMenuCallback = base::Callback<void(ToolbarActionView*)>; | |
| 104 // Set a callback to be called directly before the context menu is shown. | 110 // Set a callback to be called directly before the context menu is shown. |
| 105 // The toolbar action opening the menu will be passed in. | 111 // The toolbar action opening the menu will be passed in. |
| 106 static void set_context_menu_callback_for_testing( | 112 static void set_context_menu_callback_for_testing( |
| 107 ContextMenuCallback* callback); | 113 ContextMenuCallback* callback); |
| 108 | 114 |
| 109 views::MenuItemView* menu_for_testing() { return menu_; } | 115 views::MenuItemView* menu_for_testing() { return menu_; } |
| 110 | 116 |
| 111 private: | 117 private: |
| 112 // views::MenuButton: | 118 // views::MenuButton: |
| 113 gfx::Size GetPreferredSize() const override; | 119 gfx::Size GetPreferredSize() const override; |
| 120 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 121 void OnGestureEvent(ui::GestureEvent* event) override; |
| 114 void OnDragDone() override; | 122 void OnDragDone() override; |
| 115 void ViewHierarchyChanged( | 123 void ViewHierarchyChanged( |
| 116 const ViewHierarchyChangedDetails& details) override; | 124 const ViewHierarchyChangedDetails& details) override; |
| 117 | 125 |
| 118 // ToolbarActionViewDelegateViews: | 126 // ToolbarActionViewDelegateViews: |
| 119 views::View* GetAsView() override; | 127 views::View* GetAsView() override; |
| 120 views::FocusManager* GetFocusManagerForAccelerator() override; | 128 views::FocusManager* GetFocusManagerForAccelerator() override; |
| 121 views::View* GetReferenceViewForPopup() override; | 129 views::View* GetReferenceViewForPopup() override; |
| 122 bool IsMenuRunning() const override; | 130 bool IsMenuRunning() const override; |
| 123 void OnPopupShown(bool by_user) override; | 131 void OnPopupShown(bool by_user) override; |
| 124 void OnPopupClosed() override; | 132 void OnPopupClosed() override; |
| 125 | 133 |
| 126 // views::ContextMenuController: | 134 // views::ContextMenuController: |
| 127 void ShowContextMenuForView(views::View* source, | 135 void ShowContextMenuForView(views::View* source, |
| 128 const gfx::Point& point, | 136 const gfx::Point& point, |
| 129 ui::MenuSourceType source_type) override; | 137 ui::MenuSourceType source_type) override; |
| 130 | 138 |
| 139 // views::InkDropHost: |
| 140 gfx::Point CalculateInkDropCenter() const override; |
| 141 |
| 131 // Shows the context menu (if one exists) for the toolbar action. | 142 // Shows the context menu (if one exists) for the toolbar action. |
| 132 void DoShowContextMenu(ui::MenuSourceType source_type); | 143 void DoShowContextMenu(ui::MenuSourceType source_type); |
| 133 | 144 |
| 134 // Closes the currently-active menu, if needed. This is the case when there | 145 // Closes the currently-active menu, if needed. This is the case when there |
| 135 // is an active menu that wouldn't close automatically when a new one is | 146 // is an active menu that wouldn't close automatically when a new one is |
| 136 // opened. | 147 // opened. |
| 137 // Returns true if a menu was closed, false otherwise. | 148 // Returns true if a menu was closed, false otherwise. |
| 138 bool CloseActiveMenuIfNeeded(); | 149 bool CloseActiveMenuIfNeeded(); |
| 139 | 150 |
| 140 // A lock to keep the MenuButton pressed when a menu or popup is visible. | 151 // A lock to keep the MenuButton pressed when a menu or popup is visible. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 171 base::TimeTicks popup_closed_time_; | 182 base::TimeTicks popup_closed_time_; |
| 172 | 183 |
| 173 content::NotificationRegistrar registrar_; | 184 content::NotificationRegistrar registrar_; |
| 174 | 185 |
| 175 base::WeakPtrFactory<ToolbarActionView> weak_factory_; | 186 base::WeakPtrFactory<ToolbarActionView> weak_factory_; |
| 176 | 187 |
| 177 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); | 188 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); |
| 178 }; | 189 }; |
| 179 | 190 |
| 180 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ | 191 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
| OLD | NEW |