| 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 "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 13 #include "chrome/browser/ui/toolbar/app_menu_animation.h" |
| 13 #include "chrome/browser/ui/toolbar/app_menu_icon_controller.h" | 14 #include "chrome/browser/ui/toolbar/app_menu_icon_controller.h" |
| 14 #include "ui/views/controls/button/menu_button.h" | 15 #include "ui/views/controls/button/menu_button.h" |
| 15 #include "ui/views/controls/button/menu_button_listener.h" | 16 #include "ui/views/controls/button/menu_button_listener.h" |
| 16 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
| 17 | 18 |
| 18 class AppMenu; | 19 class AppMenu; |
| 19 class AppMenuModel; | 20 class AppMenuModel; |
| 20 | 21 |
| 21 namespace views { | 22 namespace views { |
| 22 class LabelButtonBorder; | 23 class LabelButtonBorder; |
| 23 class MenuListener; | 24 class MenuListener; |
| 24 } | 25 } |
| 25 | 26 |
| 26 class AppMenuAnimation; | |
| 27 class ToolbarView; | 27 class ToolbarView; |
| 28 | 28 |
| 29 class AppMenuButton : public views::MenuButton, public TabStripModelObserver { | 29 class AppMenuButton : public views::MenuButton, |
| 30 public TabStripModelObserver, |
| 31 public AppMenuAnimationDelegate { |
| 30 public: | 32 public: |
| 31 explicit AppMenuButton(ToolbarView* toolbar_view); | 33 explicit AppMenuButton(ToolbarView* toolbar_view); |
| 32 ~AppMenuButton() override; | 34 ~AppMenuButton() override; |
| 33 | 35 |
| 34 void SetSeverity(AppMenuIconController::IconType type, | 36 void SetSeverity(AppMenuIconController::IconType type, |
| 35 AppMenuIconController::Severity severity, | 37 AppMenuIconController::Severity severity, |
| 36 bool animate); | 38 bool animate); |
| 37 | 39 |
| 38 // Shows the app menu. |for_drop| indicates whether the menu is opened for a | 40 // Shows the app menu. |for_drop| indicates whether the menu is opened for a |
| 39 // drag-and-drop operation. | 41 // drag-and-drop operation. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 57 gfx::Size GetPreferredSize() const override; | 59 gfx::Size GetPreferredSize() const override; |
| 58 void Layout() override; | 60 void Layout() override; |
| 59 void OnPaint(gfx::Canvas* canvas) override; | 61 void OnPaint(gfx::Canvas* canvas) override; |
| 60 | 62 |
| 61 // TabStripObserver: | 63 // TabStripObserver: |
| 62 void TabInsertedAt(TabStripModel* tab_strip_model, | 64 void TabInsertedAt(TabStripModel* tab_strip_model, |
| 63 content::WebContents* contents, | 65 content::WebContents* contents, |
| 64 int index, | 66 int index, |
| 65 bool foreground) override; | 67 bool foreground) override; |
| 66 | 68 |
| 69 // AppMenuAnimationDelegate: |
| 70 void AppMenuAnimationStarted() override; |
| 71 void AppMenuAnimationEnded() override; |
| 72 void InvalidateIcon() override; |
| 73 |
| 67 // Updates the presentation according to |severity_| and the theme provider. | 74 // Updates the presentation according to |severity_| and the theme provider. |
| 68 // If |should_animate| is true, the icon should animate. | 75 // If |should_animate| is true, the icon should animate. |
| 69 void UpdateIcon(bool should_animate); | 76 void UpdateIcon(bool should_animate); |
| 70 | 77 |
| 71 // Sets |margin_trailing_| when the browser is maximized and updates layout | 78 // Sets |margin_trailing_| when the browser is maximized and updates layout |
| 72 // to make the focus rectangle centered. | 79 // to make the focus rectangle centered. |
| 73 void SetTrailingMargin(int margin); | 80 void SetTrailingMargin(int margin); |
| 74 | 81 |
| 75 // Animates the icon if possible. The icon will not animate if the severity | 82 // 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. | 83 // level is none, |animation_| is nullptr or |should_use_new_icon_| is false. |
| 77 void AnimateIconIfPossible(); | 84 void AnimateIconIfPossible(); |
| 78 | 85 |
| 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. | 86 // Opens the app menu immediately during a drag-and-drop operation. |
| 85 // Used only in testing. | 87 // Used only in testing. |
| 86 static bool g_open_app_immediately_for_testing; | 88 static bool g_open_app_immediately_for_testing; |
| 87 | 89 |
| 88 private: | 90 private: |
| 89 // views::MenuButton: | 91 // views::MenuButton: |
| 90 const char* GetClassName() const override; | 92 const char* GetClassName() const override; |
| 91 std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder() | 93 std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder() |
| 92 const override; | 94 const override; |
| 93 gfx::Rect GetThemePaintRect() const override; | 95 gfx::Rect GetThemePaintRect() const override; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // a maximized state to extend to the full window width. | 128 // a maximized state to extend to the full window width. |
| 127 int margin_trailing_; | 129 int margin_trailing_; |
| 128 | 130 |
| 129 // Used to spawn weak pointers for delayed tasks to open the overflow menu. | 131 // Used to spawn weak pointers for delayed tasks to open the overflow menu. |
| 130 base::WeakPtrFactory<AppMenuButton> weak_factory_; | 132 base::WeakPtrFactory<AppMenuButton> weak_factory_; |
| 131 | 133 |
| 132 DISALLOW_COPY_AND_ASSIGN(AppMenuButton); | 134 DISALLOW_COPY_AND_ASSIGN(AppMenuButton); |
| 133 }; | 135 }; |
| 134 | 136 |
| 135 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ | 137 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ |
| OLD | NEW |