OLD | NEW |
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 ASH_SYSTEM_CAST_TRAY_CAST_H_ | 5 #ifndef ASH_SYSTEM_CAST_TRAY_CAST_H_ |
6 #define ASH_SYSTEM_CAST_TRAY_CAST_H_ | 6 #define ASH_SYSTEM_CAST_TRAY_CAST_H_ |
7 | 7 |
| 8 #include "ash/ash_export.h" |
8 #include "ash/cast_config_delegate.h" | 9 #include "ash/cast_config_delegate.h" |
9 #include "ash/shell_observer.h" | 10 #include "ash/shell_observer.h" |
10 #include "ash/system/tray/system_tray_item.h" | 11 #include "ash/system/tray/system_tray_item.h" |
| 12 #include "ash/system/tray/tray_details_view.h" |
| 13 #include "ash/system/tray/tray_item_more.h" |
| 14 #include "ash/system/tray/tray_popup_label_button.h" |
| 15 #include "ash/system/tray/view_click_listener.h" |
11 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "ui/views/controls/button/button.h" |
| 18 #include "ui/views/view.h" |
12 | 19 |
13 namespace ash { | 20 namespace ash { |
14 namespace tray { | 21 namespace tray { |
15 class CastTrayView; | 22 class CastTrayView; |
16 class CastSelectDefaultView; | 23 class CastSelectDefaultView; |
17 class CastDetailedView; | 24 class CastDetailedView; |
18 class CastDuplexView; | 25 class CastDuplexView; |
19 } // namespace tray | 26 } // namespace tray |
20 | 27 |
21 class TrayCast : public SystemTrayItem, public ShellObserver { | 28 class ASH_EXPORT TrayCast : public SystemTrayItem, public ShellObserver { |
22 public: | 29 public: |
23 explicit TrayCast(SystemTray* system_tray); | 30 explicit TrayCast(SystemTray* system_tray); |
24 ~TrayCast() override; | 31 ~TrayCast() override; |
25 | 32 |
26 private: | 33 private: |
| 34 friend class TrayCastTestAPI; |
| 35 |
27 // Overridden from SystemTrayItem. | 36 // Overridden from SystemTrayItem. |
28 views::View* CreateTrayView(user::LoginStatus status) override; | 37 views::View* CreateTrayView(user::LoginStatus status) override; |
29 views::View* CreateDefaultView(user::LoginStatus status) override; | 38 views::View* CreateDefaultView(user::LoginStatus status) override; |
30 views::View* CreateDetailedView(user::LoginStatus status) override; | 39 views::View* CreateDetailedView(user::LoginStatus status) override; |
31 void DestroyTrayView() override; | 40 void DestroyTrayView() override; |
32 void DestroyDefaultView() override; | 41 void DestroyDefaultView() override; |
33 void DestroyDetailedView() override; | 42 void DestroyDetailedView() override; |
34 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) override; | 43 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) override; |
35 | 44 |
36 // Overridden from ShellObserver. | 45 // Overridden from ShellObserver. |
(...skipping 20 matching lines...) Expand all Loading... |
57 tray::CastDetailedView* detailed_ = nullptr; | 66 tray::CastDetailedView* detailed_ = nullptr; |
58 CastConfigDelegate* cast_config_delegate_; | 67 CastConfigDelegate* cast_config_delegate_; |
59 | 68 |
60 bool has_cast_receivers_ = false; | 69 bool has_cast_receivers_ = false; |
61 bool is_casting_ = false; | 70 bool is_casting_ = false; |
62 base::WeakPtrFactory<TrayCast> weak_ptr_factory_; | 71 base::WeakPtrFactory<TrayCast> weak_ptr_factory_; |
63 | 72 |
64 DISALLOW_COPY_AND_ASSIGN(TrayCast); | 73 DISALLOW_COPY_AND_ASSIGN(TrayCast); |
65 }; | 74 }; |
66 | 75 |
| 76 // The classes below are internal implementation details that are only exposed |
| 77 // inside of this header for testing purposes. |
| 78 namespace tray { |
| 79 |
| 80 // This view is displayed in the system tray when the cast extension is active. |
| 81 // It asks the user if they want to cast the desktop. If they click on the |
| 82 // chevron, then a detail view will replace this view where the user will |
| 83 // actually pick the cast receiver. |
| 84 class CastSelectDefaultView : public TrayItemMore { |
| 85 public: |
| 86 CastSelectDefaultView(SystemTrayItem* owner, |
| 87 CastConfigDelegate* cast_config_delegate, |
| 88 bool show_more); |
| 89 ~CastSelectDefaultView() override; |
| 90 |
| 91 // Updates the label based on the current set of receivers (if there are or |
| 92 // are not any available receivers). |
| 93 void UpdateLabel(); |
| 94 |
| 95 private: |
| 96 void UpdateLabelCallback( |
| 97 const CastConfigDelegate::ReceiversAndActivites& receivers_activities); |
| 98 |
| 99 CastConfigDelegate* cast_config_delegate_; |
| 100 base::WeakPtrFactory<CastSelectDefaultView> weak_ptr_factory_; |
| 101 DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView); |
| 102 }; |
| 103 |
| 104 // This view displays a list of cast receivers that can be clicked on and casted |
| 105 // to. It is activated by clicking on the chevron inside of |
| 106 // |CastSelectDefaultView|. |
| 107 class CastDetailedView : public TrayDetailsView, public ViewClickListener { |
| 108 public: |
| 109 CastDetailedView(SystemTrayItem* owner, |
| 110 CastConfigDelegate* cast_config_delegate, |
| 111 user::LoginStatus login); |
| 112 ~CastDetailedView() override; |
| 113 |
| 114 // Makes the detail view think the view associated with the given receiver_id |
| 115 // was clicked. This will start a cast. |
| 116 void SimulateViewClickedForTest(const std::string& receiver_id); |
| 117 |
| 118 private: |
| 119 void CreateItems(); |
| 120 |
| 121 void UpdateReceiverList(); |
| 122 void UpdateReceiverListCallback( |
| 123 const CastConfigDelegate::ReceiversAndActivites& |
| 124 new_receivers_and_activities); |
| 125 void UpdateReceiverListFromCachedData(); |
| 126 views::View* AddToReceiverList( |
| 127 const CastConfigDelegate::ReceiverAndActivity& receiverActivity); |
| 128 |
| 129 void AppendSettingsEntries(); |
| 130 void AppendHeaderEntry(); |
| 131 |
| 132 // Overridden from ViewClickListener. |
| 133 void OnViewClicked(views::View* sender) override; |
| 134 |
| 135 CastConfigDelegate* cast_config_delegate_; |
| 136 user::LoginStatus login_; |
| 137 views::View* options_ = nullptr; |
| 138 CastConfigDelegate::ReceiversAndActivites receivers_and_activities_; |
| 139 // A mapping from the view pointer to the associated activity id |
| 140 std::map<views::View*, std::string> receiver_activity_map_; |
| 141 base::WeakPtrFactory<CastDetailedView> weak_ptr_factory_; |
| 142 |
| 143 DISALLOW_COPY_AND_ASSIGN(CastDetailedView); |
| 144 }; |
| 145 |
| 146 // This view is displayed when the screen is actively being casted; it allows |
| 147 // the user to easily stop casting. It fully replaces the |
| 148 // |CastSelectDefaultView| view inside of the |CastDuplexView|. |
| 149 class CastCastView : public views::View, public views::ButtonListener { |
| 150 public: |
| 151 explicit CastCastView(CastConfigDelegate* cast_config_delegate); |
| 152 ~CastCastView() override; |
| 153 |
| 154 void StopCasting(); |
| 155 |
| 156 // Updates the label for the stop view to include information about the |
| 157 // current device that is being casted. |
| 158 void UpdateLabel(); |
| 159 |
| 160 private: |
| 161 void UpdateLabelCallback( |
| 162 const CastConfigDelegate::ReceiversAndActivites& receivers_activities); |
| 163 |
| 164 // Overridden from views::View. |
| 165 int GetHeightForWidth(int width) const override; |
| 166 void Layout() override; |
| 167 |
| 168 // Overridden from views::ButtonListener. |
| 169 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 170 |
| 171 CastConfigDelegate* cast_config_delegate_; |
| 172 views::ImageView* icon_; |
| 173 views::Label* label_; |
| 174 TrayPopupLabelButton* stop_button_; |
| 175 base::WeakPtrFactory<CastCastView> weak_ptr_factory_; |
| 176 |
| 177 DISALLOW_COPY_AND_ASSIGN(CastCastView); |
| 178 }; |
| 179 |
| 180 // This view by itself does very little. It acts as a front-end for managing |
| 181 // which of the two child views (|CastSelectDefaultView| and |CastCastView|) |
| 182 // is active. |
| 183 class CastDuplexView : public views::View { |
| 184 public: |
| 185 CastDuplexView(SystemTrayItem* owner, |
| 186 CastConfigDelegate* config_delegate, |
| 187 bool show_more); |
| 188 ~CastDuplexView() override; |
| 189 |
| 190 // Activate either the casting or select view. |
| 191 void ActivateCastView(); |
| 192 void ActivateSelectView(); |
| 193 |
| 194 CastSelectDefaultView* select_view() { return select_view_; } |
| 195 CastCastView* cast_view() { return cast_view_; } |
| 196 |
| 197 // Only one of |select_view_| or |cast_view_| will be displayed at any given |
| 198 // time. This will return the view is being displayed. |
| 199 views::View* ActiveChildView(); |
| 200 |
| 201 private: |
| 202 // Overridden from views::View. |
| 203 void ChildPreferredSizeChanged(views::View* child) override; |
| 204 void Layout() override; |
| 205 |
| 206 CastSelectDefaultView* select_view_; |
| 207 CastCastView* cast_view_; |
| 208 |
| 209 DISALLOW_COPY_AND_ASSIGN(CastDuplexView); |
| 210 }; |
| 211 |
| 212 } // namespace tray |
67 } // namespace ash | 213 } // namespace ash |
68 | 214 |
69 #endif // ASH_SYSTEM_CAST_TRAY_CAST_H_ | 215 #endif // ASH_SYSTEM_CAST_TRAY_CAST_H_ |
OLD | NEW |