Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(753)

Side by Side Diff: chrome/browser/ui/views/toolbar/app_menu_button.h

Issue 2789203003: [Views] App Menu Animated Icon (Closed)
Patch Set: Cleaned up Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/toolbar/app_menu_icon_controller.h" 13 #include "chrome/browser/ui/toolbar/app_menu_icon_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/view.h" 16 #include "ui/views/view.h"
16 17
17 class AppMenu; 18 class AppMenu;
18 class AppMenuModel; 19 class AppMenuModel;
19 20
20 namespace views { 21 namespace views {
21 class LabelButtonBorder; 22 class LabelButtonBorder;
22 class MenuListener; 23 class MenuListener;
23 } 24 }
24 25
26 class AppMenuAnimation;
25 class ToolbarView; 27 class ToolbarView;
26 28
27 class AppMenuButton : public views::MenuButton { 29 class AppMenuButton : public views::MenuButton, public TabStripModelObserver {
28 public: 30 public:
29 explicit AppMenuButton(ToolbarView* toolbar_view); 31 explicit AppMenuButton(ToolbarView* toolbar_view);
30 ~AppMenuButton() override; 32 ~AppMenuButton() override;
31 33
32 void SetSeverity(AppMenuIconController::IconType type, 34 void SetSeverity(AppMenuIconController::IconType type,
33 AppMenuIconController::Severity severity, 35 AppMenuIconController::Severity severity,
34 bool animate); 36 bool animate);
35 37
36 // 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
37 // drag-and-drop operation. 39 // drag-and-drop operation.
38 void ShowMenu(bool for_drop); 40 void ShowMenu(bool for_drop);
39 41
40 // Closes the app menu, if it's open. 42 // Closes the app menu, if it's open.
41 void CloseMenu(); 43 void CloseMenu();
42 44
43 AppMenu* app_menu_for_testing() { return menu_.get(); } 45 AppMenu* app_menu_for_testing() { return menu_.get(); }
44 46
45 // Whether the app/hotdogs menu is currently showing. 47 // Whether the app/hotdogs menu is currently showing.
46 bool IsMenuShowing() const; 48 bool IsMenuShowing() const;
47 49
48 // Adds a listener to receive a callback when the menu opens. 50 // Adds a listener to receive a callback when the menu opens.
49 void AddMenuListener(views::MenuListener* listener); 51 void AddMenuListener(views::MenuListener* listener);
50 52
51 // Removes a menu listener. 53 // Removes a menu listener.
52 void RemoveMenuListener(views::MenuListener* listener); 54 void RemoveMenuListener(views::MenuListener* listener);
53 55
54 // views::MenuButton: 56 // views::MenuButton:
55 gfx::Size GetPreferredSize() const override; 57 gfx::Size GetPreferredSize() const override;
58 void Layout() override;
59 void OnPaint(gfx::Canvas* canvas) override;
60
61 // TabStripObserver:
62 void TabInsertedAt(TabStripModel* tab_strip_model,
63 content::WebContents* contents,
64 int index,
65 bool foreground) override;
56 66
57 // Updates the presentation according to |severity_| and the theme provider. 67 // Updates the presentation according to |severity_| and the theme provider.
58 void UpdateIcon(); 68 void UpdateIcon(bool should_animate);
msw 2017/04/11 17:34:14 nit: describe |should_animate| in the comment abov
spqchan 2017/04/12 19:42:10 Done.
59 69
60 // Sets |margin_trailing_| when the browser is maximized and updates layout 70 // Sets |margin_trailing_| when the browser is maximized and updates layout
61 // to make the focus rectangle centered. 71 // to make the focus rectangle centered.
62 void SetTrailingMargin(int margin); 72 void SetTrailingMargin(int margin);
63 73
64 // Opens the app menu immediately during a drag-and-drop operation. 74 // Opens the app menu immediately during a drag-and-drop operation.
65 // Used only in testing. 75 // Used only in testing.
66 static bool g_open_app_immediately_for_testing; 76 static bool g_open_app_immediately_for_testing;
67 77
68 private: 78 private:
(...skipping 20 matching lines...) Expand all
89 99
90 // Listeners to call when the menu opens. 100 // Listeners to call when the menu opens.
91 base::ObserverList<views::MenuListener> menu_listeners_; 101 base::ObserverList<views::MenuListener> menu_listeners_;
92 102
93 // App model and menu. 103 // App model and menu.
94 // Note that the menu should be destroyed before the model it uses, so the 104 // Note that the menu should be destroyed before the model it uses, so the
95 // menu should be listed later. 105 // menu should be listed later.
96 std::unique_ptr<AppMenuModel> menu_model_; 106 std::unique_ptr<AppMenuModel> menu_model_;
97 std::unique_ptr<AppMenu> menu_; 107 std::unique_ptr<AppMenu> menu_;
98 108
109 // Used for animating and drawing the app menu icon.
110 std::unique_ptr<AppMenuAnimation> animation_;
111
99 // Any trailing margin to be applied. Used when the browser is in 112 // Any trailing margin to be applied. Used when the browser is in
100 // a maximized state to extend to the full window width. 113 // a maximized state to extend to the full window width.
101 int margin_trailing_; 114 int margin_trailing_;
102 115
103 // Used to spawn weak pointers for delayed tasks to open the overflow menu. 116 // Used to spawn weak pointers for delayed tasks to open the overflow menu.
104 base::WeakPtrFactory<AppMenuButton> weak_factory_; 117 base::WeakPtrFactory<AppMenuButton> weak_factory_;
105 118
106 DISALLOW_COPY_AND_ASSIGN(AppMenuButton); 119 DISALLOW_COPY_AND_ASSIGN(AppMenuButton);
107 }; 120 };
108 121
109 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ 122 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698