| 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" | |
| 14 #include "chrome/browser/ui/toolbar/app_menu_icon_controller.h" | 13 #include "chrome/browser/ui/toolbar/app_menu_icon_controller.h" |
| 14 #include "ui/views/controls/animated_icon_view.h" |
| 15 #include "ui/views/controls/button/menu_button.h" | 15 #include "ui/views/controls/button/menu_button.h" |
| 16 #include "ui/views/controls/button/menu_button_listener.h" | 16 #include "ui/views/controls/button/menu_button_listener.h" |
| 17 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
| 18 | 18 |
| 19 class AppMenu; | 19 class AppMenu; |
| 20 class AppMenuModel; | 20 class AppMenuModel; |
| 21 | 21 |
| 22 namespace views { | 22 namespace views { |
| 23 class LabelButtonBorder; | 23 class LabelButtonBorder; |
| 24 class MenuListener; | 24 class MenuListener; |
| 25 } | 25 } |
| 26 | 26 |
| 27 class ToolbarView; | 27 class ToolbarView; |
| 28 | 28 |
| 29 class AppMenuButton : public views::MenuButton, | 29 class AppMenuButton : public views::MenuButton, public TabStripModelObserver { |
| 30 public TabStripModelObserver, | |
| 31 public AppMenuAnimationDelegate { | |
| 32 public: | 30 public: |
| 33 explicit AppMenuButton(ToolbarView* toolbar_view); | 31 explicit AppMenuButton(ToolbarView* toolbar_view); |
| 34 ~AppMenuButton() override; | 32 ~AppMenuButton() override; |
| 35 | 33 |
| 36 void SetSeverity(AppMenuIconController::IconType type, | 34 void SetSeverity(AppMenuIconController::IconType type, |
| 37 AppMenuIconController::Severity severity, | 35 AppMenuIconController::Severity severity, |
| 38 bool animate); | 36 bool animate); |
| 39 | 37 |
| 40 // Shows the app menu. |for_drop| indicates whether the menu is opened for a | 38 // Shows the app menu. |for_drop| indicates whether the menu is opened for a |
| 41 // drag-and-drop operation. | 39 // drag-and-drop operation. |
| 42 void ShowMenu(bool for_drop); | 40 void ShowMenu(bool for_drop); |
| 43 | 41 |
| 44 // Closes the app menu, if it's open. | 42 // Closes the app menu, if it's open. |
| 45 void CloseMenu(); | 43 void CloseMenu(); |
| 46 | 44 |
| 47 AppMenu* app_menu_for_testing() { return menu_.get(); } | 45 AppMenu* app_menu_for_testing() { return menu_.get(); } |
| 48 | 46 |
| 49 // Whether the app/hotdogs menu is currently showing. | 47 // Whether the app/hotdogs menu is currently showing. |
| 50 bool IsMenuShowing() const; | 48 bool IsMenuShowing() const; |
| 51 | 49 |
| 52 // Adds a listener to receive a callback when the menu opens. | 50 // Adds a listener to receive a callback when the menu opens. |
| 53 void AddMenuListener(views::MenuListener* listener); | 51 void AddMenuListener(views::MenuListener* listener); |
| 54 | 52 |
| 55 // Removes a menu listener. | 53 // Removes a menu listener. |
| 56 void RemoveMenuListener(views::MenuListener* listener); | 54 void RemoveMenuListener(views::MenuListener* listener); |
| 57 | 55 |
| 58 // views::MenuButton: | 56 // views::MenuButton: |
| 59 gfx::Size GetPreferredSize() const override; | 57 gfx::Size GetPreferredSize() const override; |
| 60 void Layout() override; | 58 void Layout() override; |
| 61 void OnPaint(gfx::Canvas* canvas) override; | 59 void OnThemeChanged() override; |
| 62 | 60 |
| 63 // TabStripObserver: | 61 // TabStripObserver: |
| 64 void TabInsertedAt(TabStripModel* tab_strip_model, | 62 void TabInsertedAt(TabStripModel* tab_strip_model, |
| 65 content::WebContents* contents, | 63 content::WebContents* contents, |
| 66 int index, | 64 int index, |
| 67 bool foreground) override; | 65 bool foreground) override; |
| 68 | 66 |
| 69 // AppMenuAnimationDelegate: | |
| 70 void AppMenuAnimationStarted() override; | |
| 71 void AppMenuAnimationEnded() override; | |
| 72 void InvalidateIcon() override; | |
| 73 | |
| 74 // Updates the presentation according to |severity_| and the theme provider. | 67 // Updates the presentation according to |severity_| and the theme provider. |
| 75 // If |should_animate| is true, the icon should animate. | 68 // If |should_animate| is true, the icon should animate. |
| 76 void UpdateIcon(bool should_animate); | 69 void UpdateIcon(bool should_animate); |
| 77 | 70 |
| 78 // Sets |margin_trailing_| when the browser is maximized and updates layout | 71 // Sets |margin_trailing_| when the browser is maximized and updates layout |
| 79 // to make the focus rectangle centered. | 72 // to make the focus rectangle centered. |
| 80 void SetTrailingMargin(int margin); | 73 void SetTrailingMargin(int margin); |
| 81 | 74 |
| 82 // Animates the icon if possible. The icon will not animate if the severity | 75 // Animates the icon if possible. The icon will not animate if the severity |
| 83 // level is none, |animation_| is nullptr or |should_use_new_icon_| is false. | 76 // level is none, |animation_| is nullptr or |should_use_new_icon_| is false. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 111 | 104 |
| 112 // Listeners to call when the menu opens. | 105 // Listeners to call when the menu opens. |
| 113 base::ObserverList<views::MenuListener> menu_listeners_; | 106 base::ObserverList<views::MenuListener> menu_listeners_; |
| 114 | 107 |
| 115 // App model and menu. | 108 // App model and menu. |
| 116 // Note that the menu should be destroyed before the model it uses, so the | 109 // Note that the menu should be destroyed before the model it uses, so the |
| 117 // menu should be listed later. | 110 // menu should be listed later. |
| 118 std::unique_ptr<AppMenuModel> menu_model_; | 111 std::unique_ptr<AppMenuModel> menu_model_; |
| 119 std::unique_ptr<AppMenu> menu_; | 112 std::unique_ptr<AppMenu> menu_; |
| 120 | 113 |
| 121 // Used for animating and drawing the app menu icon. | 114 // The view which displays three dots and animates to a hamburger-ish icon |
| 122 std::unique_ptr<AppMenuAnimation> animation_; | 115 // when there's a need to alert the user. TODO(estade): rename to |
| 116 // |animated_icon_| when |should_use_new_icon_| defaults to true and is |
| 117 // removed. |
| 118 views::AnimatedIconView* new_icon_ = nullptr; |
| 123 | 119 |
| 124 // True if the app menu should use the new animated icon. | 120 // True if the app menu should use the new animated icon. |
| 125 bool should_use_new_icon_; | 121 bool should_use_new_icon_ = false; |
| 126 | 122 |
| 127 // Any trailing margin to be applied. Used when the browser is in | 123 // Any trailing margin to be applied. Used when the browser is in |
| 128 // a maximized state to extend to the full window width. | 124 // a maximized state to extend to the full window width. |
| 129 int margin_trailing_; | 125 int margin_trailing_ = 0; |
| 130 | 126 |
| 131 // Used to spawn weak pointers for delayed tasks to open the overflow menu. | 127 // Used to spawn weak pointers for delayed tasks to open the overflow menu. |
| 132 base::WeakPtrFactory<AppMenuButton> weak_factory_; | 128 base::WeakPtrFactory<AppMenuButton> weak_factory_; |
| 133 | 129 |
| 134 DISALLOW_COPY_AND_ASSIGN(AppMenuButton); | 130 DISALLOW_COPY_AND_ASSIGN(AppMenuButton); |
| 135 }; | 131 }; |
| 136 | 132 |
| 137 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ | 133 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ |
| OLD | NEW |