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

Side by Side Diff: ash/common/system/chromeos/cast/tray_cast.cc

Issue 2463163002: Update chromeos system menu buttons for MD. (Closed)
Patch Set: boxlayout has some annoying dchecks Created 4 years, 1 month 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 #include "ash/common/system/cast/tray_cast.h" 5 #include "ash/common/system/chromeos/cast/tray_cast.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shelf/wm_shelf_util.h" 9 #include "ash/common/shelf/wm_shelf_util.h"
10 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h" 10 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h"
11 #include "ash/common/system/tray/fixed_sized_image_view.h" 11 #include "ash/common/system/tray/fixed_sized_image_view.h"
12 #include "ash/common/system/tray/fixed_sized_scroll_view.h" 12 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
13 #include "ash/common/system/tray/hover_highlight_view.h" 13 #include "ash/common/system/tray/hover_highlight_view.h"
14 #include "ash/common/system/tray/system_tray.h" 14 #include "ash/common/system/tray/system_tray.h"
15 #include "ash/common/system/tray/system_tray_delegate.h" 15 #include "ash/common/system/tray/system_tray_delegate.h"
16 #include "ash/common/system/tray/throbber_view.h" 16 #include "ash/common/system/tray/throbber_view.h"
17 #include "ash/common/system/tray/tray_constants.h" 17 #include "ash/common/system/tray/tray_constants.h"
18 #include "ash/common/system/tray/tray_details_view.h" 18 #include "ash/common/system/tray/tray_details_view.h"
19 #include "ash/common/system/tray/tray_item_more.h" 19 #include "ash/common/system/tray/tray_item_more.h"
20 #include "ash/common/system/tray/tray_item_view.h" 20 #include "ash/common/system/tray/tray_item_view.h"
21 #include "ash/common/system/tray/tray_popup_label_button.h" 21 #include "ash/common/system/tray/tray_utils.h"
22 #include "ash/common/wm_shell.h" 22 #include "ash/common/wm_shell.h"
23 #include "ash/public/cpp/shelf_types.h" 23 #include "ash/public/cpp/shelf_types.h"
24 #include "ash/resources/vector_icons/vector_icons.h" 24 #include "ash/resources/vector_icons/vector_icons.h"
25 #include "base/bind.h" 25 #include "base/bind.h"
26 #include "grit/ash_resources.h" 26 #include "grit/ash_resources.h"
27 #include "grit/ash_strings.h" 27 #include "grit/ash_strings.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/gfx/image/image.h" 30 #include "ui/gfx/image/image.h"
31 #include "ui/gfx/paint_vector_icon.h" 31 #include "ui/gfx/paint_vector_icon.h"
32 #include "ui/gfx/text_elider.h" 32 #include "ui/gfx/text_elider.h"
33 #include "ui/views/background.h"
34 #include "ui/views/border.h"
33 #include "ui/views/controls/button/button.h" 35 #include "ui/views/controls/button/button.h"
34 #include "ui/views/controls/image_view.h" 36 #include "ui/views/controls/image_view.h"
35 #include "ui/views/controls/label.h" 37 #include "ui/views/controls/label.h"
36 #include "ui/views/layout/box_layout.h" 38 #include "ui/views/layout/box_layout.h"
37 #include "ui/views/layout/fill_layout.h" 39 #include "ui/views/layout/fill_layout.h"
38 40
39 namespace ash { 41 namespace ash {
40 42
41 namespace { 43 namespace {
42 44
43 const size_t kMaximumStatusStringLength = 100; 45 const size_t kMaximumStatusStringLength = 100;
44 const int kStopButtonRightPadding = 18;
45 46
46 // Returns the active CastConfigDelegate instance. 47 // Returns the active CastConfigDelegate instance.
47 CastConfigDelegate* GetCastConfigDelegate() { 48 CastConfigDelegate* GetCastConfigDelegate() {
48 return WmShell::Get()->system_tray_delegate()->GetCastConfigDelegate(); 49 return WmShell::Get()->system_tray_delegate()->GetCastConfigDelegate();
49 } 50 }
50 51
51 // Helper method to elide the given string to the maximum length. If a string is 52 // Helper method to elide the given string to the maximum length. If a string is
52 // contains user-input and is displayed, we should elide it. 53 // contains user-input and is displayed, we should elide it.
53 // TODO(jdufault): This does not properly trim unicode characters. We should 54 // TODO(jdufault): This does not properly trim unicode characters. We should
54 // implement this properly by using views::Label::SetElideBehavior(...). See 55 // implement this properly by using views::Label::SetElideBehavior(...). See
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_DESKTOP); 99 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_DESKTOP);
99 SetLabel(label); 100 SetLabel(label);
100 SetAccessibleName(label); 101 SetAccessibleName(label);
101 } 102 }
102 103
103 CastSelectDefaultView::~CastSelectDefaultView() {} 104 CastSelectDefaultView::~CastSelectDefaultView() {}
104 105
105 // This view is displayed when the screen is actively being casted; it allows 106 // This view is displayed when the screen is actively being casted; it allows
106 // the user to easily stop casting. It fully replaces the 107 // the user to easily stop casting. It fully replaces the
107 // |CastSelectDefaultView| view inside of the |CastDuplexView|. 108 // |CastSelectDefaultView| view inside of the |CastDuplexView|.
108 class CastCastView : public views::View, public views::ButtonListener { 109 class CastCastView : public ScreenStatusView {
109 public: 110 public:
110 CastCastView(); 111 CastCastView();
111 ~CastCastView() override; 112 ~CastCastView() override;
112 113
113 void StopCasting(); 114 void StopCasting();
114 115
115 const std::string& displayed_activity_id() const { 116 const std::string& displayed_activity_id() const {
116 return displayed_activity_id_; 117 return displayed_activity_id_;
117 } 118 }
118 119
119 // Updates the label for the stop view to include information about the 120 // Updates the label for the stop view to include information about the
120 // current device that is being casted. 121 // current device that is being casted.
121 void UpdateLabel( 122 void UpdateLabel(
122 const CastConfigDelegate::ReceiversAndActivities& receivers_activities); 123 const CastConfigDelegate::ReceiversAndActivities& receivers_activities);
123 124
124 private: 125 private:
125 // Overridden from views::View.
126 int GetHeightForWidth(int width) const override;
127 void Layout() override;
128
129 // Overridden from views::ButtonListener. 126 // Overridden from views::ButtonListener.
130 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 127 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
131 128
132 // The cast activity id that we are displaying. If the user stops a cast, we 129 // The cast activity id that we are displaying. If the user stops a cast, we
133 // send this value to the config delegate so that we stop the right cast. 130 // send this value to the config delegate so that we stop the right cast.
134 std::string displayed_activity_id_; 131 std::string displayed_activity_id_;
135 132
136 views::ImageView* icon_;
137 views::Label* label_;
138 TrayPopupLabelButton* stop_button_;
139
140 DISALLOW_COPY_AND_ASSIGN(CastCastView); 133 DISALLOW_COPY_AND_ASSIGN(CastCastView);
141 }; 134 };
142 135
143 CastCastView::CastCastView() { 136 CastCastView::CastCastView()
144 // We will initialize the primary tray view which shows a stop button here. 137 : ScreenStatusView(
145 138 nullptr,
146 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 139 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_CAST_CAST_UNKNOWN),
147 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 140 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_CAST_STOP)) {
148 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
149 kTrayPopupPaddingHorizontal, 0,
150 kTrayPopupPaddingBetweenItems));
151 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
152 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 141 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
153 icon_->SetImage(GetCastIconForSystemMenu(true)); 142 icon()->SetImage(GetCastIconForSystemMenu(true));
154 } else { 143 } else {
155 icon_->SetImage( 144 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
145 icon()->SetImage(
156 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia()); 146 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia());
157 } 147 }
158 AddChildView(icon_);
159
160 // The label which describes both what we are casting (ie, the desktop) and
161 // where we are casting it to.
162 label_ = new views::Label;
163 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
164 label_->SetMultiLine(true);
165 label_->SetText(
166 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_CAST_UNKNOWN));
167 AddChildView(label_);
168
169 // Add the stop bottom on the far-right. We customize how this stop button is
170 // displayed inside of |Layout()|.
171 base::string16 stop_button_text =
172 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
173 IDS_ASH_STATUS_TRAY_CAST_STOP);
174 stop_button_ = new TrayPopupLabelButton(this, stop_button_text);
175 AddChildView(stop_button_);
176 } 148 }
177 149
178 CastCastView::~CastCastView() {} 150 CastCastView::~CastCastView() {}
179 151
180 int CastCastView::GetHeightForWidth(int width) const {
181 // We are reusing the cached label_->bounds() calculation which was
182 // done inside of Layout(). Due to the way this object is initialized,
183 // Layout() will always get initially invoked with the dummy text
184 // (which will compute the proper label width) and then when we know
185 // the cast receiver we will update the label text, which will cause
186 // this method to get invoked.
187 return std::max(views::View::GetHeightForWidth(width),
188 kTrayPopupPaddingBetweenItems * 2 +
189 label_->GetHeightForWidth(label_->bounds().width()));
190 }
191
192 void CastCastView::Layout() {
193 views::View::Layout();
194
195 // Give the stop button the space it requests.
196 gfx::Size stop_size = stop_button_->GetPreferredSize();
197 gfx::Rect stop_bounds(stop_size);
198 stop_bounds.set_x(width() - stop_size.width() - kStopButtonRightPadding);
199 stop_bounds.set_y((height() - stop_size.height()) / 2);
200 stop_button_->SetBoundsRect(stop_bounds);
201
202 // Adjust the label's bounds in case it got cut off by |stop_button_|.
203 if (label_->bounds().Intersects(stop_button_->bounds())) {
204 gfx::Rect label_bounds = label_->bounds();
205 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems -
206 label_->x());
207 label_->SetBoundsRect(label_bounds);
208 }
209 }
210
211 void CastCastView::StopCasting() { 152 void CastCastView::StopCasting() {
212 GetCastConfigDelegate()->StopCasting(displayed_activity_id_); 153 GetCastConfigDelegate()->StopCasting(displayed_activity_id_);
213 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_CAST_STOP_CAST); 154 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_CAST_STOP_CAST);
214 } 155 }
215 156
216 void CastCastView::UpdateLabel( 157 void CastCastView::UpdateLabel(
217 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) { 158 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) {
218 for (auto& i : receivers_activities) { 159 for (auto& i : receivers_activities) {
219 const CastConfigDelegate::Receiver& receiver = i.receiver; 160 const CastConfigDelegate::Receiver& receiver = i.receiver;
220 const CastConfigDelegate::Activity& activity = i.activity; 161 const CastConfigDelegate::Activity& activity = i.activity;
221 162
222 if (!activity.id.empty()) { 163 if (!activity.id.empty()) {
223 displayed_activity_id_ = activity.id; 164 displayed_activity_id_ = activity.id;
224 165
225 // We want to display different labels inside of the title depending on 166 // We want to display different labels inside of the title depending on
226 // what we are actually casting - either the desktop, a tab, or a fallback 167 // what we are actually casting - either the desktop, a tab, or a fallback
227 // that catches everything else (ie, an extension tab). 168 // that catches everything else (ie, an extension tab).
228 if (activity.tab_id == CastConfigDelegate::Activity::TabId::DESKTOP) { 169 if (activity.tab_id == CastConfigDelegate::Activity::TabId::DESKTOP) {
229 label_->SetText(ElideString(l10n_util::GetStringFUTF16( 170 label()->SetText(ElideString(l10n_util::GetStringFUTF16(
230 IDS_ASH_STATUS_TRAY_CAST_CAST_DESKTOP, receiver.name))); 171 IDS_ASH_STATUS_TRAY_CAST_CAST_DESKTOP, receiver.name)));
231 } else if (activity.tab_id >= 0) { 172 } else if (activity.tab_id >= 0) {
232 label_->SetText(ElideString(l10n_util::GetStringFUTF16( 173 label()->SetText(ElideString(l10n_util::GetStringFUTF16(
233 IDS_ASH_STATUS_TRAY_CAST_CAST_TAB, activity.title, receiver.name))); 174 IDS_ASH_STATUS_TRAY_CAST_CAST_TAB, activity.title, receiver.name)));
234 } else { 175 } else {
235 label_->SetText( 176 label()->SetText(
236 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_CAST_CAST_UNKNOWN)); 177 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_CAST_CAST_UNKNOWN));
237 } 178 }
238 179
239 PreferredSizeChanged(); 180 PreferredSizeChanged();
240 Layout(); 181 Layout();
241 182
242 // If this machine is the source of the activity, then we want to display 183 // If this machine is the source of the activity, then we want to display
243 // it over any other activity. There can be multiple activities if other 184 // it over any other activity. There can be multiple activities if other
244 // devices on the network are casting at the same time. 185 // devices on the network are casting at the same time.
245 if (activity.is_local_source) 186 if (activity.is_local_source)
246 break; 187 break;
247 } 188 }
248 } 189 }
249 } 190 }
250 191
251 void CastCastView::ButtonPressed(views::Button* sender, 192 void CastCastView::ButtonPressed(views::Button* sender,
252 const ui::Event& event) { 193 const ui::Event& event) {
253 DCHECK(sender == stop_button_);
254 StopCasting(); 194 StopCasting();
255 } 195 }
256 196
257 // This view by itself does very little. It acts as a front-end for managing 197 // This view by itself does very little. It acts as a front-end for managing
258 // which of the two child views (|CastSelectDefaultView| and |CastCastView|) 198 // which of the two child views (|CastSelectDefaultView| and |CastCastView|)
259 // is active. 199 // is active.
260 class CastDuplexView : public views::View { 200 class CastDuplexView : public views::View {
261 public: 201 public:
262 CastDuplexView( 202 CastDuplexView(
263 SystemTrayItem* owner, 203 SystemTrayItem* owner,
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 tray_->SetVisible(false); 602 tray_->SetVisible(false);
663 } 603 }
664 } 604 }
665 605
666 void TrayCast::OnCastingSessionStartedOrStopped(bool started) { 606 void TrayCast::OnCastingSessionStartedOrStopped(bool started) {
667 is_casting_ = started; 607 is_casting_ = started;
668 UpdatePrimaryView(); 608 UpdatePrimaryView();
669 } 609 }
670 610
671 } // namespace ash 611 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/cast/tray_cast.h ('k') | ash/common/system/chromeos/network/network_state_list_detailed_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698