| 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_APP_MENU_BUTTON_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 13 #include "chrome/browser/ui/toolbar/app_menu_icon_controller.h" | 15 #include "chrome/browser/ui/toolbar/app_menu_icon_controller.h" |
| 14 #include "ui/views/controls/button/menu_button.h" | 16 #include "ui/views/controls/button/menu_button.h" |
| 15 #include "ui/views/controls/button/menu_button_listener.h" | 17 #include "ui/views/controls/button/menu_button_listener.h" |
| 16 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
| 17 | 19 |
| 18 class AppMenu; | 20 class AppMenu; |
| 19 class AppMenuModel; | 21 class AppMenuModel; |
| 20 | 22 |
| 21 namespace views { | 23 namespace views { |
| 22 class LabelButtonBorder; | 24 class LabelButtonBorder; |
| 23 class MenuListener; | 25 class MenuListener; |
| 24 } | 26 } |
| 25 | 27 |
| 26 class AppMenuAnimation; | |
| 27 class ToolbarView; | 28 class ToolbarView; |
| 28 | 29 |
| 30 namespace internal { |
| 31 class VectorIconAnimator; |
| 32 } |
| 33 |
| 29 class AppMenuButton : public views::MenuButton, public TabStripModelObserver { | 34 class AppMenuButton : public views::MenuButton, public TabStripModelObserver { |
| 30 public: | 35 public: |
| 31 explicit AppMenuButton(ToolbarView* toolbar_view); | 36 explicit AppMenuButton(ToolbarView* toolbar_view); |
| 32 ~AppMenuButton() override; | 37 ~AppMenuButton() override; |
| 33 | 38 |
| 34 void SetSeverity(AppMenuIconController::IconType type, | 39 void SetSeverity(AppMenuIconController::IconType type, |
| 35 AppMenuIconController::Severity severity, | 40 AppMenuIconController::Severity severity, |
| 36 bool animate); | 41 bool animate); |
| 37 | 42 |
| 38 // Shows the app menu. |for_drop| indicates whether the menu is opened for a | 43 // Shows the app menu. |for_drop| indicates whether the menu is opened for a |
| (...skipping 27 matching lines...) Expand all Loading... |
| 66 | 71 |
| 67 // Updates the presentation according to |severity_| and the theme provider. | 72 // Updates the presentation according to |severity_| and the theme provider. |
| 68 // If |should_animate| is true, the icon should animate. | 73 // If |should_animate| is true, the icon should animate. |
| 69 void UpdateIcon(bool should_animate); | 74 void UpdateIcon(bool should_animate); |
| 70 | 75 |
| 71 // Sets |margin_trailing_| when the browser is maximized and updates layout | 76 // Sets |margin_trailing_| when the browser is maximized and updates layout |
| 72 // to make the focus rectangle centered. | 77 // to make the focus rectangle centered. |
| 73 void SetTrailingMargin(int margin); | 78 void SetTrailingMargin(int margin); |
| 74 | 79 |
| 75 // Animates the icon if possible. The icon will not animate if the severity | 80 // Animates the icon if possible. The icon will not animate if the severity |
| 76 // level is none, |animation_| is nullptr or |should_use_new_icon_| is false. | 81 // level is none, |animator_| is nullptr or |should_use_new_icon_| is false. |
| 77 void AnimateIconIfPossible(); | 82 void AnimateIconIfPossible(); |
| 78 | 83 |
| 79 // Methods called by AppMenuAnimation when the animation has started/ended. | |
| 80 // The layer is managed inside these methods. | |
| 81 void AppMenuAnimationStarted(); | |
| 82 void AppMenuAnimationEnded(); | |
| 83 | |
| 84 // Opens the app menu immediately during a drag-and-drop operation. | 84 // Opens the app menu immediately during a drag-and-drop operation. |
| 85 // Used only in testing. | 85 // Used only in testing. |
| 86 static bool g_open_app_immediately_for_testing; | 86 static bool g_open_app_immediately_for_testing; |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 // views::MenuButton: | 89 // views::MenuButton: |
| 90 const char* GetClassName() const override; | 90 const char* GetClassName() const override; |
| 91 std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder() | 91 std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder() |
| 92 const override; | 92 const override; |
| 93 gfx::Rect GetThemePaintRect() const override; | 93 gfx::Rect GetThemePaintRect() const override; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 110 // Listeners to call when the menu opens. | 110 // Listeners to call when the menu opens. |
| 111 base::ObserverList<views::MenuListener> menu_listeners_; | 111 base::ObserverList<views::MenuListener> menu_listeners_; |
| 112 | 112 |
| 113 // App model and menu. | 113 // App model and menu. |
| 114 // Note that the menu should be destroyed before the model it uses, so the | 114 // Note that the menu should be destroyed before the model it uses, so the |
| 115 // menu should be listed later. | 115 // menu should be listed later. |
| 116 std::unique_ptr<AppMenuModel> menu_model_; | 116 std::unique_ptr<AppMenuModel> menu_model_; |
| 117 std::unique_ptr<AppMenu> menu_; | 117 std::unique_ptr<AppMenu> menu_; |
| 118 | 118 |
| 119 // Used for animating and drawing the app menu icon. | 119 // Used for animating and drawing the app menu icon. |
| 120 std::unique_ptr<AppMenuAnimation> animation_; | 120 std::unique_ptr<internal::VectorIconAnimator> animator_; |
| 121 | 121 |
| 122 // True if the app menu should use the new animated icon. | 122 // True if the app menu should use the new animated icon. |
| 123 bool should_use_new_icon_; | 123 bool should_use_new_icon_; |
| 124 | 124 |
| 125 // Any trailing margin to be applied. Used when the browser is in | 125 // Any trailing margin to be applied. Used when the browser is in |
| 126 // a maximized state to extend to the full window width. | 126 // a maximized state to extend to the full window width. |
| 127 int margin_trailing_; | 127 int margin_trailing_; |
| 128 | 128 |
| 129 // Used to spawn weak pointers for delayed tasks to open the overflow menu. | 129 // Used to spawn weak pointers for delayed tasks to open the overflow menu. |
| 130 base::WeakPtrFactory<AppMenuButton> weak_factory_; | 130 base::WeakPtrFactory<AppMenuButton> weak_factory_; |
| 131 | 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(AppMenuButton); | 132 DISALLOW_COPY_AND_ASSIGN(AppMenuButton); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ | 135 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ |
| OLD | NEW |