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

Side by Side Diff: ash/common/system/user/user_card_view.cc

Issue 2678353005: Remove pre-MD code related to tray/menu user profiles. (Closed)
Patch Set: tdanderson review, a11y Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/user/user_card_view.h" 5 #include "ash/common/system/user/user_card_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/common/ash_view_ids.h" 11 #include "ash/common/ash_view_ids.h"
12 #include "ash/common/login_status.h" 12 #include "ash/common/login_status.h"
13 #include "ash/common/material_design/material_design_controller.h"
14 #include "ash/common/media_controller.h" 13 #include "ash/common/media_controller.h"
15 #include "ash/common/session/session_state_delegate.h" 14 #include "ash/common/session/session_state_delegate.h"
16 #include "ash/common/system/tray/system_tray_controller.h" 15 #include "ash/common/system/tray/system_tray_controller.h"
17 #include "ash/common/system/tray/system_tray_delegate.h" 16 #include "ash/common/system/tray/system_tray_delegate.h"
18 #include "ash/common/system/tray/tray_constants.h" 17 #include "ash/common/system/tray/tray_constants.h"
19 #include "ash/common/system/tray/tray_popup_item_style.h" 18 #include "ash/common/system/tray/tray_popup_item_style.h"
20 #include "ash/common/system/tray/tray_utils.h" 19 #include "ash/common/system/tray/tray_utils.h"
21 #include "ash/common/system/user/rounded_image_view.h" 20 #include "ash/common/system/user/rounded_image_view.h"
22 #include "ash/common/wm_shell.h" 21 #include "ash/common/wm_shell.h"
23 #include "ash/resources/vector_icons/vector_icons.h" 22 #include "ash/resources/vector_icons/vector_icons.h"
24 #include "base/i18n/rtl.h" 23 #include "base/i18n/rtl.h"
25 #include "base/memory/ptr_util.h" 24 #include "base/memory/ptr_util.h"
26 #include "base/strings/string16.h" 25 #include "base/strings/string16.h"
27 #include "base/strings/string_util.h" 26 #include "base/strings/string_util.h"
28 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
29 #include "components/user_manager/user_info.h" 28 #include "components/user_manager/user_info.h"
30 #include "grit/ash_resources.h"
31 #include "grit/ash_strings.h" 29 #include "grit/ash_strings.h"
32 #include "ui/accessibility/ax_node_data.h" 30 #include "ui/accessibility/ax_node_data.h"
33 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/base/resource/resource_bundle.h"
35 #include "ui/compositor/compositing_recorder.h" 32 #include "ui/compositor/compositing_recorder.h"
36 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
37 #include "ui/gfx/color_palette.h" 34 #include "ui/gfx/color_palette.h"
38 #include "ui/gfx/geometry/insets.h" 35 #include "ui/gfx/geometry/insets.h"
39 #include "ui/gfx/geometry/rect.h" 36 #include "ui/gfx/geometry/rect.h"
40 #include "ui/gfx/geometry/size.h" 37 #include "ui/gfx/geometry/size.h"
41 #include "ui/gfx/paint_vector_icon.h" 38 #include "ui/gfx/paint_vector_icon.h"
42 #include "ui/gfx/range/range.h" 39 #include "ui/gfx/range/range.h"
43 #include "ui/gfx/render_text.h" 40 #include "ui/gfx/render_text.h"
44 #include "ui/gfx/text_elider.h" 41 #include "ui/gfx/text_elider.h"
45 #include "ui/gfx/text_utils.h" 42 #include "ui/gfx/text_utils.h"
46 #include "ui/views/border.h" 43 #include "ui/views/border.h"
47 #include "ui/views/controls/image_view.h" 44 #include "ui/views/controls/image_view.h"
48 #include "ui/views/controls/link.h" 45 #include "ui/views/controls/link.h"
49 #include "ui/views/controls/link_listener.h" 46 #include "ui/views/controls/link_listener.h"
50 #include "ui/views/layout/box_layout.h" 47 #include "ui/views/layout/box_layout.h"
51 #include "ui/views/layout/fill_layout.h"
52 48
53 namespace ash { 49 namespace ash {
54 namespace tray { 50 namespace tray {
55 51
56 namespace { 52 namespace {
57 53
58 const int kUserDetailsVerticalPadding = 5; 54 const int kUserDetailsVerticalPadding = 5;
59 55
60 // The invisible word joiner character, used as a marker to indicate the start 56 // The invisible word joiner character, used as a marker to indicate the start
61 // and end of the user's display name in the public account user card's text. 57 // and end of the user's display name in the public account user card's text.
62 const base::char16 kDisplayNameMark[] = {0x2060, 0}; 58 const base::char16 kDisplayNameMark[] = {0x2060, 0};
63 59
64 bool UseMd() {
65 return MaterialDesignController::IsSystemTrayMenuMaterial();
66 }
67
68 views::View* CreateUserAvatarView(LoginStatus login_status, int user_index) { 60 views::View* CreateUserAvatarView(LoginStatus login_status, int user_index) {
69 RoundedImageView* image_view = new RoundedImageView( 61 RoundedImageView* image_view = new RoundedImageView(kTrayItemSize / 2);
70 UseMd() ? kTrayItemSize / 2 : kTrayRoundedBorderRadius, user_index == 0);
71 if (login_status == LoginStatus::GUEST) { 62 if (login_status == LoginStatus::GUEST) {
72 gfx::ImageSkia icon = 63 gfx::ImageSkia icon =
73 UseMd() ? gfx::CreateVectorIcon(kSystemMenuGuestIcon, kMenuIconColor) 64 gfx::CreateVectorIcon(kSystemMenuGuestIcon, kMenuIconColor);
74 : *ui::ResourceBundle::GetSharedInstance()
75 .GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON)
76 .ToImageSkia();
77 image_view->SetImage(icon, icon.size()); 65 image_view->SetImage(icon, icon.size());
78 } else { 66 } else {
79 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); 67 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
80 image_view->SetImage(delegate->GetUserInfo(user_index)->GetImage(), 68 image_view->SetImage(delegate->GetUserInfo(user_index)->GetImage(),
81 gfx::Size(kTrayItemSize, kTrayItemSize)); 69 gfx::Size(kTrayItemSize, kTrayItemSize));
82 } 70 }
83 71
84 if (UseMd()) { 72 image_view->SetBorder(views::CreateEmptyBorder(
85 image_view->SetBorder(views::CreateEmptyBorder(gfx::Insets( 73 gfx::Insets((GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH) -
86 (GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH) - 74 image_view->GetPreferredSize().width()) /
87 image_view->GetPreferredSize().width()) / 75 2)));
88 2)));
89 }
90 return image_view; 76 return image_view;
91 } 77 }
92 78
93 class MediaIndicator : public views::View, public MediaCaptureObserver {
94 public:
95 explicit MediaIndicator(UserIndex index)
96 : index_(index), label_(new views::Label) {
97 DCHECK(!UseMd());
98 SetLayoutManager(new views::FillLayout);
99 views::ImageView* icon = new views::ImageView;
100 icon->SetImage(ui::ResourceBundle::GetSharedInstance()
101 .GetImageNamed(IDR_AURA_UBER_TRAY_RECORDING_RED)
102 .ToImageSkia());
103 AddChildView(icon);
104 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
105 label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
106 ui::ResourceBundle::SmallFont));
107 WmShell::Get()->media_controller()->AddObserver(this);
108 SetVisible(false);
109 WmShell::Get()->media_controller()->RequestCaptureState();
110 set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR);
111 }
112
113 ~MediaIndicator() override {
114 WmShell::Get()->media_controller()->RemoveObserver(this);
115 }
116
117 // MediaCaptureObserver:
118 void OnMediaCaptureChanged(
119 const std::vector<mojom::MediaCaptureState>& capture_states) override {
120 if (static_cast<size_t>(index_) >= capture_states.size()) {
121 NOTREACHED();
122 return;
123 }
124
125 mojom::MediaCaptureState state = capture_states[index_];
126 int res_id = 0;
127 switch (state) {
128 case mojom::MediaCaptureState::AUDIO_VIDEO:
129 res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO_VIDEO;
130 break;
131 case mojom::MediaCaptureState::AUDIO:
132 res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO;
133 break;
134 case mojom::MediaCaptureState::VIDEO:
135 res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_VIDEO;
136 break;
137 case mojom::MediaCaptureState::NONE:
138 break;
139 }
140 SetMessage(res_id ? l10n_util::GetStringUTF16(res_id) : base::string16());
141 }
142
143 views::View* GetMessageView() { return label_; }
144
145 void SetMessage(const base::string16& message) {
146 SetVisible(!message.empty());
147 label_->SetText(message);
148 label_->SetVisible(!message.empty());
149 }
150
151 private:
152 UserIndex index_;
153 views::Label* label_;
154
155 DISALLOW_COPY_AND_ASSIGN(MediaIndicator);
156 };
157
158 // The user details shown in public account mode. This is essentially a label 79 // The user details shown in public account mode. This is essentially a label
159 // but with custom painting code as the text is styled with multiple colors and 80 // but with custom painting code as the text is styled with multiple colors and
160 // contains a link. 81 // contains a link.
161 class PublicAccountUserDetails : public views::View, 82 class PublicAccountUserDetails : public views::View,
162 public views::LinkListener { 83 public views::LinkListener {
163 public: 84 public:
164 PublicAccountUserDetails(int max_width); 85 PublicAccountUserDetails(int max_width);
165 ~PublicAccountUserDetails() override; 86 ~PublicAccountUserDetails() override;
166 87
167 private: 88 private:
168 // Overridden from views::View. 89 // Overridden from views::View.
169 void Layout() override; 90 void Layout() override;
170 gfx::Size GetPreferredSize() const override; 91 gfx::Size GetPreferredSize() const override;
171 void OnPaint(gfx::Canvas* canvas) override; 92 void OnPaint(gfx::Canvas* canvas) override;
93 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
172 94
173 // Overridden from views::LinkListener. 95 // Overridden from views::LinkListener.
174 void LinkClicked(views::Link* source, int event_flags) override; 96 void LinkClicked(views::Link* source, int event_flags) override;
175 97
176 // Calculate a preferred size that ensures the label text and the following 98 // Calculate a preferred size that ensures the label text and the following
177 // link do not wrap over more than three lines in total for aesthetic reasons 99 // link do not wrap over more than three lines in total for aesthetic reasons
178 // if possible. 100 // if possible.
179 void CalculatePreferredSize(int max_allowed_width); 101 void CalculatePreferredSize();
180 102
181 base::string16 text_; 103 base::string16 text_;
182 views::Link* learn_more_; 104 views::Link* learn_more_;
183 gfx::Size preferred_size_; 105 gfx::Size preferred_size_;
184 std::vector<std::unique_ptr<gfx::RenderText>> lines_; 106 std::vector<std::unique_ptr<gfx::RenderText>> lines_;
185 107
186 DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails); 108 DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails);
187 }; 109 };
188 110
189 PublicAccountUserDetails::PublicAccountUserDetails(int max_width) 111 PublicAccountUserDetails::PublicAccountUserDetails(int max_width)
(...skipping 21 matching lines...) Expand all
211 base::i18n::WrapStringWithLTRFormatting(&domain); 133 base::i18n::WrapStringWithLTRFormatting(&domain);
212 // Retrieve the label text, inserting the display name and domain. 134 // Retrieve the label text, inserting the display name and domain.
213 text_ = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_PUBLIC_LABEL, 135 text_ = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_PUBLIC_LABEL,
214 display_name, domain); 136 display_name, domain);
215 137
216 learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_ASH_LEARN_MORE)); 138 learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_ASH_LEARN_MORE));
217 learn_more_->SetUnderline(false); 139 learn_more_->SetUnderline(false);
218 learn_more_->set_listener(this); 140 learn_more_->set_listener(this);
219 AddChildView(learn_more_); 141 AddChildView(learn_more_);
220 142
221 CalculatePreferredSize(max_width); 143 CalculatePreferredSize();
222 } 144 }
223 145
224 PublicAccountUserDetails::~PublicAccountUserDetails() {} 146 PublicAccountUserDetails::~PublicAccountUserDetails() {}
225 147
226 void PublicAccountUserDetails::Layout() { 148 void PublicAccountUserDetails::Layout() {
227 lines_.clear(); 149 lines_.clear();
228 const gfx::Rect contents_area = GetContentsBounds(); 150 const gfx::Rect contents_area = GetContentsBounds();
229 if (contents_area.IsEmpty()) 151 if (contents_area.IsEmpty())
230 return; 152 return;
231 153
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return preferred_size_; 216 return preferred_size_;
295 } 217 }
296 218
297 void PublicAccountUserDetails::OnPaint(gfx::Canvas* canvas) { 219 void PublicAccountUserDetails::OnPaint(gfx::Canvas* canvas) {
298 for (const auto& line : lines_) 220 for (const auto& line : lines_)
299 line->Draw(canvas); 221 line->Draw(canvas);
300 222
301 views::View::OnPaint(canvas); 223 views::View::OnPaint(canvas);
302 } 224 }
303 225
226 void PublicAccountUserDetails::GetAccessibleNodeData(
227 ui::AXNodeData* node_data) {
228 node_data->role = ui::AX_ROLE_STATIC_TEXT;
229 node_data->SetName(text_);
230 }
231
304 void PublicAccountUserDetails::LinkClicked(views::Link* source, 232 void PublicAccountUserDetails::LinkClicked(views::Link* source,
305 int event_flags) { 233 int event_flags) {
306 DCHECK_EQ(source, learn_more_); 234 DCHECK_EQ(source, learn_more_);
307 WmShell::Get()->system_tray_controller()->ShowPublicAccountInfo(); 235 WmShell::Get()->system_tray_controller()->ShowPublicAccountInfo();
308 } 236 }
309 237
310 void PublicAccountUserDetails::CalculatePreferredSize(int max_allowed_width) { 238 void PublicAccountUserDetails::CalculatePreferredSize() {
311 const gfx::FontList font_list; 239 const gfx::FontList font_list;
312 const gfx::Size link_size = learn_more_->GetPreferredSize(); 240 const gfx::Size link_size = learn_more_->GetPreferredSize();
313 const int space_width = 241 const int space_width =
314 gfx::GetStringWidth(base::ASCIIToUTF16(" "), font_list); 242 gfx::GetStringWidth(base::ASCIIToUTF16(" "), font_list);
315 const gfx::Insets insets = GetInsets(); 243 const gfx::Insets insets = GetInsets();
316 int min_width = link_size.width(); 244 int min_width = link_size.width();
317 int max_width = 245 int max_width =
318 gfx::GetStringWidth(text_, font_list) + space_width + link_size.width(); 246 gfx::GetStringWidth(text_, font_list) + space_width + link_size.width();
319 // TODO(estade): |max_allowed_width| isn't used in MD. 247
320 if (UseMd())
321 DCHECK_EQ(-1, max_allowed_width);
322 else
323 max_width = std::min(max_width, max_allowed_width - insets.width());
324 // Do a binary search for the minimum width that ensures no more than three 248 // Do a binary search for the minimum width that ensures no more than three
325 // lines are needed. The lower bound is the minimum of the current bubble 249 // lines are needed. The lower bound is the minimum of the current bubble
326 // width and the width of the link (as no wrapping is permitted inside the 250 // width and the width of the link (as no wrapping is permitted inside the
327 // link). The upper bound is the maximum of the largest allowed bubble width 251 // link). The upper bound is the maximum of the largest allowed bubble width
328 // and the sum of the label text and link widths when put on a single line. 252 // and the sum of the label text and link widths when put on a single line.
329 std::vector<base::string16> lines; 253 std::vector<base::string16> lines;
330 while (min_width < max_width) { 254 while (min_width < max_width) {
331 lines.clear(); 255 lines.clear();
332 const int width = (min_width + max_width) / 2; 256 const int width = (min_width + max_width) / 2;
333 const bool too_narrow = 257 const bool too_narrow =
(...skipping 30 matching lines...) Expand all
364 } // namespace 288 } // namespace
365 289
366 UserCardView::UserCardView(LoginStatus login_status, 290 UserCardView::UserCardView(LoginStatus login_status,
367 int max_width, 291 int max_width,
368 int user_index) 292 int user_index)
369 : user_index_(user_index), 293 : user_index_(user_index),
370 user_name_(nullptr), 294 user_name_(nullptr),
371 media_capture_label_(nullptr), 295 media_capture_label_(nullptr),
372 media_capture_icon_(nullptr) { 296 media_capture_icon_(nullptr) {
373 auto layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 297 auto layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0,
374 UseMd() ? kTrayPopupLabelHorizontalPadding 298 kTrayPopupLabelHorizontalPadding);
375 : kTrayPopupPaddingBetweenItems);
376 SetLayoutManager(layout); 299 SetLayoutManager(layout);
377 if (UseMd()) { 300 layout->set_minimum_cross_axis_size(
378 layout->set_minimum_cross_axis_size( 301 GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT));
379 GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT)); 302 layout->set_cross_axis_alignment(
380 layout->set_cross_axis_alignment( 303 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
381 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 304 // For active users, the left inset is provided by ActiveUserBorder, which
382 // For active users, the left inset is provided by ActiveUserBorder, which 305 // is necessary to make sure the ripple does not cover that part of the row.
383 // is necessary to make sure the ripple does not cover that part of the row. 306 // For inactive users, we set the inset here and this causes the ripple to
384 // For inactive users, we set the inset here and this causes the ripple to 307 // extend all the way to the edges of the menu.
385 // extend all the way to the edges of the menu. 308 if (!is_active_user())
386 if (!is_active_user()) { 309 SetBorder(views::CreateEmptyBorder(0, kMenuExtraMarginFromLeftEdge, 0, 0));
387 SetBorder(
388 views::CreateEmptyBorder(0, kMenuExtraMarginFromLeftEdge, 0, 0));
389 }
390 310
391 WmShell::Get()->media_controller()->AddObserver(this); 311 WmShell::Get()->media_controller()->AddObserver(this);
392 }
393 312
394 if (login_status == LoginStatus::PUBLIC) 313 if (login_status == LoginStatus::PUBLIC)
395 AddPublicModeUserContent(max_width); 314 AddPublicModeUserContent(max_width);
396 else if (UseMd())
397 AddUserContentMd(layout, login_status);
398 else 315 else
399 AddUserContent(login_status); 316 AddUserContent(layout, login_status);
400 } 317 }
401 318
402 UserCardView::~UserCardView() { 319 UserCardView::~UserCardView() {
403 if (UseMd()) 320 WmShell::Get()->media_controller()->RemoveObserver(this);
404 WmShell::Get()->media_controller()->RemoveObserver(this);
405 } 321 }
406 322
407 void UserCardView::PaintChildren(const ui::PaintContext& context) { 323 void UserCardView::PaintChildren(const ui::PaintContext& context) {
408 if (!is_active_user()) { 324 if (!is_active_user()) {
409 ui::CompositingRecorder alpha(context, 0xFF / 2, true); 325 ui::CompositingRecorder alpha(context, 0xFF / 2, true);
410 View::PaintChildren(context); 326 View::PaintChildren(context);
411 } else { 327 } else {
412 View::PaintChildren(context); 328 View::PaintChildren(context);
413 } 329 }
414 } 330 }
415 331
416 void UserCardView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 332 void UserCardView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
417 node_data->role = ui::AX_ROLE_STATIC_TEXT; 333 node_data->role = ui::AX_ROLE_STATIC_TEXT;
418 std::vector<base::string16> labels; 334 std::vector<base::string16> labels;
419 for (int i = 0; i < child_count(); ++i) 335
420 GetAccessibleLabelFromDescendantViews(child_at(i), labels); 336 // Construct the name by concatenating descendants' names.
Evan Stade 2017/02/09 17:45:07 This logic exists because there are many different
337 std::list<views::View*> descendants;
338 descendants.push_back(this);
339 while (!descendants.empty()) {
340 auto view = descendants.front();
341 descendants.pop_front();
342 if (view != this) {
343 ui::AXNodeData descendant_data;
344 view->GetAccessibleNodeData(&descendant_data);
345 base::string16 label =
346 descendant_data.GetString16Attribute(ui::AX_ATTR_NAME);
347 // If we find a non-empty name, use that and don't descend further into
348 // the tree.
349 if (!label.empty()) {
350 labels.push_back(label);
351 continue;
352 }
353 }
354
355 // This view didn't have its own name, so look over its children.
356 for (int i = view->child_count() - 1; i >= 0; --i)
357 descendants.push_front(view->child_at(i));
358 }
421 node_data->SetName(base::JoinString(labels, base::ASCIIToUTF16(" "))); 359 node_data->SetName(base::JoinString(labels, base::ASCIIToUTF16(" ")));
422 } 360 }
423 361
424 void UserCardView::OnMediaCaptureChanged( 362 void UserCardView::OnMediaCaptureChanged(
425 const std::vector<mojom::MediaCaptureState>& capture_states) { 363 const std::vector<mojom::MediaCaptureState>& capture_states) {
426 if (is_active_user()) 364 if (is_active_user())
427 return; 365 return;
428 366
429 mojom::MediaCaptureState state = capture_states[user_index_]; 367 mojom::MediaCaptureState state = capture_states[user_index_];
430 int res_id = 0; 368 int res_id = 0;
(...skipping 19 matching lines...) Expand all
450 } 388 }
451 389
452 void UserCardView::AddPublicModeUserContent(int max_width) { 390 void UserCardView::AddPublicModeUserContent(int max_width) {
453 views::View* avatar = CreateUserAvatarView(LoginStatus::PUBLIC, 0); 391 views::View* avatar = CreateUserAvatarView(LoginStatus::PUBLIC, 0);
454 AddChildView(avatar); 392 AddChildView(avatar);
455 int details_max_width = max_width - avatar->GetPreferredSize().width() - 393 int details_max_width = max_width - avatar->GetPreferredSize().width() -
456 kTrayPopupPaddingBetweenItems; 394 kTrayPopupPaddingBetweenItems;
457 AddChildView(new PublicAccountUserDetails(details_max_width)); 395 AddChildView(new PublicAccountUserDetails(details_max_width));
458 } 396 }
459 397
460 void UserCardView::AddUserContent(LoginStatus login_status) { 398 void UserCardView::AddUserContent(views::BoxLayout* layout,
461 DCHECK(!UseMd()); 399 LoginStatus login_status) {
462 views::View* avatar = CreateUserAvatarView(login_status, user_index_);
463 AddChildView(avatar);
464 views::Label* user_name = NULL;
465 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
466 if (!user_index_) {
467 base::string16 user_name_string =
468 login_status == LoginStatus::GUEST
469 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)
470 : delegate->GetUserInfo(user_index_)->GetDisplayName();
471 if (!user_name_string.empty()) {
472 user_name = new views::Label(user_name_string);
473 user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT);
474 }
475 }
476
477 views::Label* user_email = NULL;
478 if (login_status != LoginStatus::GUEST) {
479 SystemTrayDelegate* tray_delegate = WmShell::Get()->system_tray_delegate();
480 base::string16 user_email_string =
481 tray_delegate->IsUserSupervised()
482 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)
483 : base::UTF8ToUTF16(
484 delegate->GetUserInfo(user_index_)->GetDisplayEmail());
485 if (!user_email_string.empty()) {
486 user_email = new views::Label(user_email_string);
487 user_email->SetFontList(
488 ui::ResourceBundle::GetSharedInstance().GetFontList(
489 ui::ResourceBundle::SmallFont));
490 user_email->SetHorizontalAlignment(gfx::ALIGN_LEFT);
491 }
492 }
493
494 // Adjust text properties dependent on if it is an active or inactive user.
495 if (user_index_) {
496 // Fade the text of non active users to 50%.
497 SkColor text_color = user_email->enabled_color();
498 text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2);
499 if (user_email)
500 user_email->SetDisabledColor(text_color);
501 if (user_name)
502 user_name->SetDisabledColor(text_color);
503 }
504
505 if (user_email && user_name) {
506 views::View* details = new views::View;
507 details->SetLayoutManager(new views::BoxLayout(
508 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0));
509 details->AddChildView(user_name);
510 details->AddChildView(user_email);
511 AddChildView(details);
512 } else {
513 if (user_name)
514 AddChildView(user_name);
515 if (user_email) {
516 // Only non active user can have a media indicator.
517 MediaIndicator* media_indicator = new MediaIndicator(user_index_);
518 views::View* email_indicator_view = new views::View;
519 email_indicator_view->SetLayoutManager(new views::BoxLayout(
520 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems));
521 email_indicator_view->AddChildView(user_email);
522 email_indicator_view->AddChildView(media_indicator);
523
524 views::View* details = new views::View;
525 details->SetLayoutManager(new views::BoxLayout(
526 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0));
527 details->AddChildView(email_indicator_view);
528 details->AddChildView(media_indicator->GetMessageView());
529 AddChildView(details);
530 }
531 }
532 }
533
534 void UserCardView::AddUserContentMd(views::BoxLayout* layout,
535 LoginStatus login_status) {
536 AddChildView(CreateUserAvatarView(login_status, user_index_)); 400 AddChildView(CreateUserAvatarView(login_status, user_index_));
537 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); 401 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
538 base::string16 user_name_string = 402 base::string16 user_name_string =
539 login_status == LoginStatus::GUEST 403 login_status == LoginStatus::GUEST
540 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL) 404 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)
541 : delegate->GetUserInfo(user_index_)->GetDisplayName(); 405 : delegate->GetUserInfo(user_index_)->GetDisplayName();
542 user_name_ = new views::Label(user_name_string); 406 user_name_ = new views::Label(user_name_string);
543 user_name_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 407 user_name_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
544 TrayPopupItemStyle user_name_style( 408 TrayPopupItemStyle user_name_style(
545 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); 409 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 465
602 media_capture_icon_->set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR); 466 media_capture_icon_->set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR);
603 AddChildView(media_capture_icon_); 467 AddChildView(media_capture_icon_);
604 468
605 WmShell::Get()->media_controller()->RequestCaptureState(); 469 WmShell::Get()->media_controller()->RequestCaptureState();
606 } 470 }
607 } 471 }
608 472
609 } // namespace tray 473 } // namespace tray
610 } // namespace ash 474 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698