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

Side by Side Diff: chrome/browser/ui/toolbar/media_router_action.h

Issue 2155293002: Show the Cast toolbar icon ephemerally when Cast is in use (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_TOOLBAR_MEDIA_ROUTER_ACTION_H_ 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ 6 #define CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/scoped_observer.h" 9 #include "base/scoped_observer.h"
10 #include "chrome/browser/media/router/issues_observer.h" 10 #include "chrome/browser/media/router/issues_observer.h"
11 #include "chrome/browser/media/router/media_routes_observer.h" 11 #include "chrome/browser/media/router/media_routes_observer.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/media_router_contextual_menu.h" 13 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h"
14 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 14 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
15 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" 15 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_observer.h"
16 #include "ui/gfx/vector_icons_public.h" 17 #include "ui/gfx/vector_icons_public.h"
17 18
18 class Browser; 19 class Browser;
19 class MediaRouterActionPlatformDelegate; 20 class MediaRouterActionPlatformDelegate;
20 class TabStripModel; 21 class TabStripModel;
21 22
22 namespace media_router { 23 namespace media_router {
23 class MediaRouterDialogControllerImpl; 24 class MediaRouterDialogControllerImpl;
24 } // namespace media_router 25 } // namespace media_router
25 26
26 // The class for the Media Router component action that will be shown in 27 // The class for the Media Router component action that will be shown in
27 // the toolbar. 28 // the toolbar.
28 class MediaRouterAction : public ToolbarActionViewController, 29 class MediaRouterAction : public ToolbarActionViewController,
29 public media_router::IssuesObserver, 30 public media_router::IssuesObserver,
30 public media_router::MediaRoutesObserver, 31 public media_router::MediaRoutesObserver,
31 public TabStripModelObserver { 32 public TabStripModelObserver,
33 public ToolbarActionsBarObserver {
32 public: 34 public:
33 MediaRouterAction(Browser* browser, ToolbarActionsBar* toolbar_actions_bar); 35 MediaRouterAction(Browser* browser, ToolbarActionsBar* toolbar_actions_bar);
34 ~MediaRouterAction() override; 36 ~MediaRouterAction() override;
35 37
36 // ToolbarActionViewController implementation. 38 // ToolbarActionViewController implementation.
37 std::string GetId() const override; 39 std::string GetId() const override;
38 void SetDelegate(ToolbarActionViewDelegate* delegate) override; 40 void SetDelegate(ToolbarActionViewDelegate* delegate) override;
39 gfx::Image GetIcon(content::WebContents* web_contents, 41 gfx::Image GetIcon(content::WebContents* web_contents,
40 const gfx::Size& size) override; 42 const gfx::Size& size) override;
41 base::string16 GetActionName() const override; 43 base::string16 GetActionName() const override;
(...skipping 18 matching lines...) Expand all
60 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes, 62 void OnRoutesUpdated(const std::vector<media_router::MediaRoute>& routes,
61 const std::vector<media_router::MediaRoute::Id>& 63 const std::vector<media_router::MediaRoute::Id>&
62 joinable_route_ids) override; 64 joinable_route_ids) override;
63 65
64 // ToolbarStripModelObserver: 66 // ToolbarStripModelObserver:
65 void ActiveTabChanged(content::WebContents* old_contents, 67 void ActiveTabChanged(content::WebContents* old_contents,
66 content::WebContents* new_contents, 68 content::WebContents* new_contents,
67 int index, 69 int index,
68 int reason) override; 70 int reason) override;
69 71
72 // ToolbarActionsBarObserver:
73 void OnToolbarActionsBarAnimationEnded() override;
74
70 void OnPopupHidden(); 75 void OnPopupHidden();
71 void OnPopupShown(); 76 void OnPopupShown();
72 77
78 // Toggle the "Always show icon" option.
79 void ToggleVisibilityPreference();
80
81 protected:
82 // For accessing from tests.
83 base::WeakPtr<MediaRouterAction> GetWeakPtr();
84
73 private: 85 private:
74 // Called when a new browser window is opened, the user switches tabs in the 86 // Called when a new browser window is opened, the user switches tabs in the
75 // browser window, or when |delegate_| is swapped out to be non-null and has 87 // browser window, or when |delegate_| is swapped out to be non-null and has
76 // a valid WebContents. 88 // a valid WebContents.
77 // This updates the pressed/unpressed state of the icon, which is different 89 // This updates the pressed/unpressed state of the icon, which is different
78 // on a per-tab basis. 90 // on a per-tab basis.
79 void UpdatePopupState(); 91 void UpdatePopupState();
80 92
81 // Returns a reference to the MediaRouterDialogControllerImpl associated with 93 // Returns a reference to the MediaRouterDialogControllerImpl associated with
82 // |delegate_|'s current WebContents. Guaranteed to be non-null. 94 // |delegate_|'s current WebContents. Guaranteed to be non-null.
83 // |delegate_| and its current WebContents must not be null. 95 // |delegate_| and its current WebContents must not be null.
84 // Marked virtual for tests. 96 // Marked virtual for tests.
85 virtual media_router::MediaRouterDialogControllerImpl* 97 virtual media_router::MediaRouterDialogControllerImpl*
86 GetMediaRouterDialogController(); 98 GetMediaRouterDialogController();
87 99
88 // Overridden by tests. 100 // Overridden by tests.
89 virtual MediaRouterActionPlatformDelegate* GetPlatformDelegate(); 101 virtual MediaRouterActionPlatformDelegate* GetPlatformDelegate();
90 102
91 // Checks if the current icon of MediaRouterAction has changed. If so, 103 // Checks if the current icon of MediaRouterAction has changed. If so,
92 // updates |current_icon_|. 104 // updates |current_icon_|.
93 void MaybeUpdateIcon(); 105 void MaybeUpdateIcon();
94 106
107 void MaybeRemoveAction();
108
109 // Returns whether the "Always show icon" option is checked.
110 bool ShouldAlwaysShowIcon();
111
95 gfx::VectorIconId GetCurrentIcon() const; 112 gfx::VectorIconId GetCurrentIcon() const;
96 113
97 // The current icon to show. This is updated based on the current issues and 114 // The current icon to show. This is updated based on the current issues and
98 // routes since |this| is an IssueObserver and MediaRoutesObserver. 115 // routes since |this| is an IssueObserver and MediaRoutesObserver.
99 gfx::VectorIconId current_icon_; 116 gfx::VectorIconId current_icon_;
100 117
101 // The current issue shown in the Media Router WebUI. Can be null. It is set 118 // The current issue shown in the Media Router WebUI. Can be null. It is set
102 // in OnIssueUpdated(), which is called by the IssueManager. 119 // in OnIssueUpdated(), which is called by the IssueManager.
103 std::unique_ptr<media_router::Issue> issue_; 120 std::unique_ptr<media_router::Issue> issue_;
104 121
105 // Whether a local displayable active route exists. 122 // Whether a local displayable active route exists.
106 bool has_local_display_route_; 123 bool has_local_display_route_;
107 124
108 ToolbarActionViewDelegate* delegate_; 125 ToolbarActionViewDelegate* delegate_;
109 126
110 Browser* const browser_; 127 Browser* const browser_;
111 ToolbarActionsBar* const toolbar_actions_bar_; 128 ToolbarActionsBar* const toolbar_actions_bar_;
112 129
113 // The delegate to handle platform-specific implementations. 130 // The delegate to handle platform-specific implementations.
114 std::unique_ptr<MediaRouterActionPlatformDelegate> platform_delegate_; 131 std::unique_ptr<MediaRouterActionPlatformDelegate> platform_delegate_;
115 132
116 MediaRouterContextualMenu contextual_menu_; 133 MediaRouterContextualMenu contextual_menu_;
117 134
118 ScopedObserver<TabStripModel, TabStripModelObserver> 135 ScopedObserver<TabStripModel, TabStripModelObserver>
119 tab_strip_model_observer_; 136 tab_strip_model_observer_;
137 ScopedObserver<ToolbarActionsBar, ToolbarActionsBarObserver>
138 toolbar_actions_bar_observer_;
120 139
121 base::WeakPtrFactory<MediaRouterAction> weak_ptr_factory_; 140 base::WeakPtrFactory<MediaRouterAction> weak_ptr_factory_;
122 141
123 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction); 142 DISALLOW_COPY_AND_ASSIGN(MediaRouterAction);
124 }; 143 };
125 144
126 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_ 145 #endif // CHROME_BROWSER_UI_TOOLBAR_MEDIA_ROUTER_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698