| 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 // The app menu button lives in the top right of the main browser window. It |
| 30 public TabStripModelObserver, | 30 // shows three dots and animates to a hamburger-ish icon when there's a need to |
| 31 public AppMenuAnimationDelegate { | 31 // alert the user. Clicking displays the app menu. |
| 32 class AppMenuButton : public views::MenuButton, public TabStripModelObserver { |
| 32 public: | 33 public: |
| 33 explicit AppMenuButton(ToolbarView* toolbar_view); | 34 explicit AppMenuButton(ToolbarView* toolbar_view); |
| 34 ~AppMenuButton() override; | 35 ~AppMenuButton() override; |
| 35 | 36 |
| 36 void SetSeverity(AppMenuIconController::IconType type, | 37 void SetSeverity(AppMenuIconController::IconType type, |
| 37 AppMenuIconController::Severity severity, | 38 AppMenuIconController::Severity severity, |
| 38 bool animate); | 39 bool animate); |
| 39 | 40 |
| 40 // Shows the app menu. |for_drop| indicates whether the menu is opened for a | 41 // Shows the app menu. |for_drop| indicates whether the menu is opened for a |
| 41 // drag-and-drop operation. | 42 // drag-and-drop operation. |
| 42 void ShowMenu(bool for_drop); | 43 void ShowMenu(bool for_drop); |
| 43 | 44 |
| 44 // Closes the app menu, if it's open. | 45 // Closes the app menu, if it's open. |
| 45 void CloseMenu(); | 46 void CloseMenu(); |
| 46 | 47 |
| 47 AppMenu* app_menu_for_testing() { return menu_.get(); } | 48 AppMenu* app_menu_for_testing() { return menu_.get(); } |
| 48 | 49 |
| 49 // Whether the app/hotdogs menu is currently showing. | 50 // Whether the app/hotdogs menu is currently showing. |
| 50 bool IsMenuShowing() const; | 51 bool IsMenuShowing() const; |
| 51 | 52 |
| 52 // Adds a listener to receive a callback when the menu opens. | 53 // Adds a listener to receive a callback when the menu opens. |
| 53 void AddMenuListener(views::MenuListener* listener); | 54 void AddMenuListener(views::MenuListener* listener); |
| 54 | 55 |
| 55 // Removes a menu listener. | 56 // Removes a menu listener. |
| 56 void RemoveMenuListener(views::MenuListener* listener); | 57 void RemoveMenuListener(views::MenuListener* listener); |
| 57 | 58 |
| 58 // views::MenuButton: | 59 // views::MenuButton: |
| 59 gfx::Size CalculatePreferredSize() const override; | 60 gfx::Size CalculatePreferredSize() const override; |
| 60 void Layout() override; | 61 void Layout() override; |
| 61 void PaintButtonContents(gfx::Canvas* canvas) override; | 62 void OnThemeChanged() override; |
| 62 | 63 |
| 63 // TabStripObserver: | 64 // TabStripObserver: |
| 64 void TabInsertedAt(TabStripModel* tab_strip_model, | 65 void TabInsertedAt(TabStripModel* tab_strip_model, |
| 65 content::WebContents* contents, | 66 content::WebContents* contents, |
| 66 int index, | 67 int index, |
| 67 bool foreground) override; | 68 bool foreground) override; |
| 68 | 69 |
| 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. | 70 // Updates the presentation according to |severity_| and the theme provider. |
| 75 // If |should_animate| is true, the icon should animate. | 71 // If |should_animate| is true, the icon should animate. |
| 76 void UpdateIcon(bool should_animate); | 72 void UpdateIcon(bool should_animate); |
| 77 | 73 |
| 78 // Sets |margin_trailing_| when the browser is maximized and updates layout | 74 // Sets |margin_trailing_| when the browser is maximized and updates layout |
| 79 // to make the focus rectangle centered. | 75 // to make the focus rectangle centered. |
| 80 void SetTrailingMargin(int margin); | 76 void SetTrailingMargin(int margin); |
| 81 | 77 |
| 82 // Animates the icon if possible. The icon will not animate if the severity | 78 // 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. | 79 // level is none, |animation_| is nullptr or |should_use_new_icon_| is false. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 96 bool GetDropFormats( | 92 bool GetDropFormats( |
| 97 int* formats, | 93 int* formats, |
| 98 std::set<ui::Clipboard::FormatType>* format_types) override; | 94 std::set<ui::Clipboard::FormatType>* format_types) override; |
| 99 bool AreDropTypesRequired() override; | 95 bool AreDropTypesRequired() override; |
| 100 bool CanDrop(const ui::OSExchangeData& data) override; | 96 bool CanDrop(const ui::OSExchangeData& data) override; |
| 101 void OnDragEntered(const ui::DropTargetEvent& event) override; | 97 void OnDragEntered(const ui::DropTargetEvent& event) override; |
| 102 int OnDragUpdated(const ui::DropTargetEvent& event) override; | 98 int OnDragUpdated(const ui::DropTargetEvent& event) override; |
| 103 void OnDragExited() override; | 99 void OnDragExited() override; |
| 104 int OnPerformDrop(const ui::DropTargetEvent& event) override; | 100 int OnPerformDrop(const ui::DropTargetEvent& event) override; |
| 105 | 101 |
| 106 AppMenuIconController::Severity severity_; | 102 AppMenuIconController::Severity severity_ = |
| 107 AppMenuIconController::IconType type_; | 103 AppMenuIconController::Severity::NONE; |
| 104 AppMenuIconController::IconType type_ = AppMenuIconController::IconType::NONE; |
| 108 | 105 |
| 109 // Our owning toolbar view. | 106 // Our owning toolbar view. |
| 110 ToolbarView* toolbar_view_; | 107 ToolbarView* toolbar_view_; |
| 111 | 108 |
| 112 // Listeners to call when the menu opens. | 109 // Listeners to call when the menu opens. |
| 113 base::ObserverList<views::MenuListener> menu_listeners_; | 110 base::ObserverList<views::MenuListener> menu_listeners_; |
| 114 | 111 |
| 115 // App model and menu. | 112 // App model and menu. |
| 116 // Note that the menu should be destroyed before the model it uses, so the | 113 // Note that the menu should be destroyed before the model it uses, so the |
| 117 // menu should be listed later. | 114 // menu should be listed later. |
| 118 std::unique_ptr<AppMenuModel> menu_model_; | 115 std::unique_ptr<AppMenuModel> menu_model_; |
| 119 std::unique_ptr<AppMenu> menu_; | 116 std::unique_ptr<AppMenu> menu_; |
| 120 | 117 |
| 121 // Used for animating and drawing the app menu icon. | 118 // The view that depicts and animates the icon. TODO(estade): rename to |
| 122 std::unique_ptr<AppMenuAnimation> animation_; | 119 // |animated_icon_| when |should_use_new_icon_| defaults to true and is |
| 120 // removed. |
| 121 views::AnimatedIconView* new_icon_ = nullptr; |
| 123 | 122 |
| 124 // True if the app menu should use the new animated icon. | 123 // True if the app menu should use the new animated icon. |
| 125 bool should_use_new_icon_; | 124 bool should_use_new_icon_ = false; |
| 126 | 125 |
| 127 // Any trailing margin to be applied. Used when the browser is in | 126 // Any trailing margin to be applied. Used when the browser is in |
| 128 // a maximized state to extend to the full window width. | 127 // a maximized state to extend to the full window width. |
| 129 int margin_trailing_; | 128 int margin_trailing_ = 0; |
| 130 | 129 |
| 131 // Used to spawn weak pointers for delayed tasks to open the overflow menu. | 130 // Used to spawn weak pointers for delayed tasks to open the overflow menu. |
| 132 base::WeakPtrFactory<AppMenuButton> weak_factory_; | 131 base::WeakPtrFactory<AppMenuButton> weak_factory_{this}; |
| 133 | 132 |
| 134 DISALLOW_COPY_AND_ASSIGN(AppMenuButton); | 133 DISALLOW_COPY_AND_ASSIGN(AppMenuButton); |
| 135 }; | 134 }; |
| 136 | 135 |
| 137 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ | 136 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ |
| OLD | NEW |