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

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

Issue 2098023002: mash: Migrate remaining tray observers and notify functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. Created 4 years, 6 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/system/user/user_card_view.h" 5 #include "ash/system/user/user_card_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/common/login_status.h" 10 #include "ash/common/login_status.h"
11 #include "ash/common/session/session_state_delegate.h" 11 #include "ash/common/session/session_state_delegate.h"
12 #include "ash/common/system/tray/system_tray_delegate.h" 12 #include "ash/common/system/tray/system_tray_delegate.h"
13 #include "ash/common/system/tray/system_tray_notifier.h"
13 #include "ash/common/system/tray/tray_constants.h" 14 #include "ash/common/system/tray/tray_constants.h"
14 #include "ash/common/system/tray/tray_utils.h" 15 #include "ash/common/system/tray/tray_utils.h"
15 #include "ash/common/system/user/rounded_image_view.h" 16 #include "ash/common/system/user/rounded_image_view.h"
16 #include "ash/common/wm_shell.h" 17 #include "ash/common/wm_shell.h"
17 #include "ash/shell.h" 18 #include "ash/shell.h"
18 #include "ash/system/tray/system_tray_notifier.h"
19 #include "base/i18n/rtl.h" 19 #include "base/i18n/rtl.h"
20 #include "base/memory/scoped_vector.h" 20 #include "base/memory/scoped_vector.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "components/user_manager/user_info.h" 24 #include "components/user_manager/user_info.h"
25 #include "grit/ash_resources.h" 25 #include "grit/ash_resources.h"
26 #include "grit/ash_strings.h" 26 #include "grit/ash_strings.h"
27 #include "ui/accessibility/ax_view_state.h" 27 #include "ui/accessibility/ax_view_state.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/geometry/insets.h" 30 #include "ui/gfx/geometry/insets.h"
31 #include "ui/gfx/geometry/rect.h" 31 #include "ui/gfx/geometry/rect.h"
32 #include "ui/gfx/geometry/size.h" 32 #include "ui/gfx/geometry/size.h"
33 #include "ui/gfx/range/range.h" 33 #include "ui/gfx/range/range.h"
34 #include "ui/gfx/render_text.h" 34 #include "ui/gfx/render_text.h"
35 #include "ui/gfx/text_elider.h" 35 #include "ui/gfx/text_elider.h"
36 #include "ui/gfx/text_utils.h" 36 #include "ui/gfx/text_utils.h"
37 #include "ui/views/border.h" 37 #include "ui/views/border.h"
38 #include "ui/views/controls/link.h" 38 #include "ui/views/controls/link.h"
39 #include "ui/views/controls/link_listener.h" 39 #include "ui/views/controls/link_listener.h"
40 #include "ui/views/layout/box_layout.h" 40 #include "ui/views/layout/box_layout.h"
41 41
42 #if defined(OS_CHROMEOS) 42 #if defined(OS_CHROMEOS)
43 #include "ash/ash_view_ids.h" 43 #include "ash/ash_view_ids.h"
44 #include "ash/common/system/chromeos/media_security/media_capture_observer.h"
44 #include "ash/media_delegate.h" 45 #include "ash/media_delegate.h"
45 #include "ash/system/tray/media_security/media_capture_observer.h"
46 #include "ui/views/controls/image_view.h" 46 #include "ui/views/controls/image_view.h"
47 #include "ui/views/layout/fill_layout.h" 47 #include "ui/views/layout/fill_layout.h"
48 #endif 48 #endif
49 49
50 namespace ash { 50 namespace ash {
51 namespace tray { 51 namespace tray {
52 52
53 namespace { 53 namespace {
54 54
55 const int kUserDetailsVerticalPadding = 5; 55 const int kUserDetailsVerticalPadding = 5;
(...skipping 10 matching lines...) Expand all
66 SetLayoutManager(new views::FillLayout); 66 SetLayoutManager(new views::FillLayout);
67 views::ImageView* icon = new views::ImageView; 67 views::ImageView* icon = new views::ImageView;
68 icon->SetImage(ui::ResourceBundle::GetSharedInstance() 68 icon->SetImage(ui::ResourceBundle::GetSharedInstance()
69 .GetImageNamed(IDR_AURA_UBER_TRAY_RECORDING_RED) 69 .GetImageNamed(IDR_AURA_UBER_TRAY_RECORDING_RED)
70 .ToImageSkia()); 70 .ToImageSkia());
71 AddChildView(icon); 71 AddChildView(icon);
72 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 72 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
73 label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 73 label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
74 ui::ResourceBundle::SmallFont)); 74 ui::ResourceBundle::SmallFont));
75 OnMediaCaptureChanged(); 75 OnMediaCaptureChanged();
76 Shell::GetInstance()->system_tray_notifier()->AddMediaCaptureObserver(this); 76 WmShell::Get()->system_tray_notifier()->AddMediaCaptureObserver(this);
77 set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR); 77 set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR);
78 } 78 }
79 79
80 ~MediaIndicator() override { 80 ~MediaIndicator() override {
81 Shell::GetInstance()->system_tray_notifier()->RemoveMediaCaptureObserver( 81 WmShell::Get()->system_tray_notifier()->RemoveMediaCaptureObserver(this);
82 this);
83 } 82 }
84 83
85 // MediaCaptureObserver: 84 // MediaCaptureObserver:
86 void OnMediaCaptureChanged() override { 85 void OnMediaCaptureChanged() override {
87 MediaCaptureState state = 86 MediaCaptureState state =
88 Shell::GetInstance()->media_delegate()->GetMediaCaptureState(index_); 87 Shell::GetInstance()->media_delegate()->GetMediaCaptureState(index_);
89 int res_id = 0; 88 int res_id = 0;
90 switch (state) { 89 switch (state) {
91 case MEDIA_CAPTURE_AUDIO_VIDEO: 90 case MEDIA_CAPTURE_AUDIO_VIDEO:
92 res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO_VIDEO; 91 res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO_VIDEO;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; 155 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems;
157 const bool rtl = base::i18n::IsRTL(); 156 const bool rtl = base::i18n::IsRTL();
158 SetBorder(views::Border::CreateEmptyBorder(kUserDetailsVerticalPadding, 157 SetBorder(views::Border::CreateEmptyBorder(kUserDetailsVerticalPadding,
159 rtl ? 0 : inner_padding, 158 rtl ? 0 : inner_padding,
160 kUserDetailsVerticalPadding, 159 kUserDetailsVerticalPadding,
161 rtl ? inner_padding : 0)); 160 rtl ? inner_padding : 0));
162 161
163 // Retrieve the user's display name and wrap it with markers. 162 // Retrieve the user's display name and wrap it with markers.
164 // Note that since this is a public account it always has to be the primary 163 // Note that since this is a public account it always has to be the primary
165 // user. 164 // user.
166 base::string16 display_name = Shell::GetInstance() 165 base::string16 display_name = WmShell::Get()
167 ->session_state_delegate() 166 ->GetSessionStateDelegate()
168 ->GetUserInfo(0) 167 ->GetUserInfo(0)
169 ->GetDisplayName(); 168 ->GetDisplayName();
170 base::RemoveChars(display_name, kDisplayNameMark, &display_name); 169 base::RemoveChars(display_name, kDisplayNameMark, &display_name);
171 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; 170 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0];
172 // Retrieve the domain managing the device and wrap it with markers. 171 // Retrieve the domain managing the device and wrap it with markers.
173 base::string16 domain = base::UTF8ToUTF16( 172 base::string16 domain = base::UTF8ToUTF16(
174 WmShell::Get()->system_tray_delegate()->GetEnterpriseDomain()); 173 WmShell::Get()->system_tray_delegate()->GetEnterpriseDomain());
175 base::RemoveChars(domain, kDisplayNameMark, &domain); 174 base::RemoveChars(domain, kDisplayNameMark, &domain);
176 base::i18n::WrapStringWithLTRFormatting(&domain); 175 base::i18n::WrapStringWithLTRFormatting(&domain);
177 // Retrieve the label text, inserting the display name and domain. 176 // Retrieve the label text, inserting the display name and domain.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 AddChildView(icon); 360 AddChildView(icon);
362 int details_max_width = max_width - icon->GetPreferredSize().width() - 361 int details_max_width = max_width - icon->GetPreferredSize().width() -
363 kTrayPopupPaddingBetweenItems; 362 kTrayPopupPaddingBetweenItems;
364 AddChildView(new PublicAccountUserDetails(details_max_width)); 363 AddChildView(new PublicAccountUserDetails(details_max_width));
365 } 364 }
366 365
367 void UserCardView::AddUserContent(LoginStatus login_status, int user_index) { 366 void UserCardView::AddUserContent(LoginStatus login_status, int user_index) {
368 views::View* icon = CreateIcon(login_status, user_index); 367 views::View* icon = CreateIcon(login_status, user_index);
369 AddChildView(icon); 368 AddChildView(icon);
370 views::Label* user_name = NULL; 369 views::Label* user_name = NULL;
371 SessionStateDelegate* delegate = 370 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
372 Shell::GetInstance()->session_state_delegate();
373 if (!user_index) { 371 if (!user_index) {
374 base::string16 user_name_string = 372 base::string16 user_name_string =
375 login_status == LoginStatus::GUEST 373 login_status == LoginStatus::GUEST
376 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL) 374 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)
377 : delegate->GetUserInfo(user_index)->GetDisplayName(); 375 : delegate->GetUserInfo(user_index)->GetDisplayName();
378 if (!user_name_string.empty()) { 376 if (!user_name_string.empty()) {
379 user_name = new views::Label(user_name_string); 377 user_name = new views::Label(user_name_string);
380 user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); 378 user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT);
381 } 379 }
382 } 380 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 views::View* UserCardView::CreateIcon(LoginStatus login_status, 442 views::View* UserCardView::CreateIcon(LoginStatus login_status,
445 int user_index) { 443 int user_index) {
446 RoundedImageView* icon = 444 RoundedImageView* icon =
447 new RoundedImageView(kTrayAvatarCornerRadius, user_index == 0); 445 new RoundedImageView(kTrayAvatarCornerRadius, user_index == 0);
448 if (login_status == LoginStatus::GUEST) { 446 if (login_status == LoginStatus::GUEST) {
449 icon->SetImage(*ui::ResourceBundle::GetSharedInstance() 447 icon->SetImage(*ui::ResourceBundle::GetSharedInstance()
450 .GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON) 448 .GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON)
451 .ToImageSkia(), 449 .ToImageSkia(),
452 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); 450 gfx::Size(kTrayAvatarSize, kTrayAvatarSize));
453 } else { 451 } else {
454 SessionStateDelegate* delegate = 452 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
455 Shell::GetInstance()->session_state_delegate();
456 icon->SetImage(delegate->GetUserInfo(user_index)->GetImage(), 453 icon->SetImage(delegate->GetUserInfo(user_index)->GetImage(),
457 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); 454 gfx::Size(kTrayAvatarSize, kTrayAvatarSize));
458 } 455 }
459 return icon; 456 return icon;
460 } 457 }
461 458
462 } // namespace tray 459 } // namespace tray
463 } // namespace ash 460 } // namespace ash
OLDNEW
« ash/shell.h ('K') | « ash/system/user/tray_user.cc ('k') | ash/test/test_shell_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698