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

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

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

Powered by Google App Engine
This is Rietveld 408576698