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

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

Issue 2789203003: [Views] App Menu Animated Icon (Closed)
Patch Set: nit 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 // If |should_animate| is true, the icon should animate.
69 void UpdateIcon(bool should_animate);
59 70
60 // Sets |margin_trailing_| when the browser is maximized and updates layout 71 // Sets |margin_trailing_| when the browser is maximized and updates layout
61 // to make the focus rectangle centered. 72 // to make the focus rectangle centered.
62 void SetTrailingMargin(int margin); 73 void SetTrailingMargin(int margin);
63 74
75 // Methods called by AppMenuAnimation when the animation has started/ended.
76 // The layer is managed inside these methods.
77 void AppMenuAnimationStarted();
78 void AppMenuAnimationEnded();
79
64 // Opens the app menu immediately during a drag-and-drop operation. 80 // Opens the app menu immediately during a drag-and-drop operation.
65 // Used only in testing. 81 // Used only in testing.
66 static bool g_open_app_immediately_for_testing; 82 static bool g_open_app_immediately_for_testing;
67 83
68 private: 84 private:
69 // views::MenuButton: 85 // views::MenuButton:
70 const char* GetClassName() const override; 86 const char* GetClassName() const override;
71 std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder() 87 std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder()
72 const override; 88 const override;
73 gfx::Rect GetThemePaintRect() const override; 89 gfx::Rect GetThemePaintRect() const override;
(...skipping 15 matching lines...) Expand all
89 105
90 // Listeners to call when the menu opens. 106 // Listeners to call when the menu opens.
91 base::ObserverList<views::MenuListener> menu_listeners_; 107 base::ObserverList<views::MenuListener> menu_listeners_;
92 108
93 // App model and menu. 109 // App model and menu.
94 // Note that the menu should be destroyed before the model it uses, so the 110 // Note that the menu should be destroyed before the model it uses, so the
95 // menu should be listed later. 111 // menu should be listed later.
96 std::unique_ptr<AppMenuModel> menu_model_; 112 std::unique_ptr<AppMenuModel> menu_model_;
97 std::unique_ptr<AppMenu> menu_; 113 std::unique_ptr<AppMenu> menu_;
98 114
115 // Used for animating and drawing the app menu icon.
116 std::unique_ptr<AppMenuAnimation> animation_;
117
99 // Any trailing margin to be applied. Used when the browser is in 118 // Any trailing margin to be applied. Used when the browser is in
100 // a maximized state to extend to the full window width. 119 // a maximized state to extend to the full window width.
101 int margin_trailing_; 120 int margin_trailing_;
102 121
103 // Used to spawn weak pointers for delayed tasks to open the overflow menu. 122 // Used to spawn weak pointers for delayed tasks to open the overflow menu.
104 base::WeakPtrFactory<AppMenuButton> weak_factory_; 123 base::WeakPtrFactory<AppMenuButton> weak_factory_;
105 124
106 DISALLOW_COPY_AND_ASSIGN(AppMenuButton); 125 DISALLOW_COPY_AND_ASSIGN(AppMenuButton);
107 }; 126 };
108 127
109 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_ 128 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_APP_MENU_BUTTON_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/app_menu_animation.cc ('k') | chrome/browser/ui/views/toolbar/app_menu_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698