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

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

Issue 253183003: Media indicator for background recording task (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: support apps/exetnsions Created 6 years, 7 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 | Annotate | Revision Log
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/session/session_state_delegate.h" 10 #include "ash/session/session_state_delegate.h"
11 #include "ash/session/user_info.h" 11 #include "ash/session/user_info.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/system/tray/system_tray_delegate.h" 13 #include "ash/system/tray/system_tray_delegate.h"
14 #include "ash/system/tray/system_tray_notifier.h"
14 #include "ash/system/tray/tray_constants.h" 15 #include "ash/system/tray/tray_constants.h"
15 #include "ash/system/user/config.h" 16 #include "ash/system/user/config.h"
16 #include "ash/system/user/rounded_image_view.h" 17 #include "ash/system/user/rounded_image_view.h"
17 #include "base/i18n/rtl.h" 18 #include "base/i18n/rtl.h"
18 #include "base/memory/scoped_vector.h" 19 #include "base/memory/scoped_vector.h"
19 #include "base/strings/string16.h" 20 #include "base/strings/string16.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
22 #include "grit/ash_resources.h" 23 #include "grit/ash_resources.h"
23 #include "grit/ash_strings.h" 24 #include "grit/ash_strings.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/insets.h" 27 #include "ui/gfx/insets.h"
27 #include "ui/gfx/range/range.h" 28 #include "ui/gfx/range/range.h"
28 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
29 #include "ui/gfx/render_text.h" 30 #include "ui/gfx/render_text.h"
30 #include "ui/gfx/size.h" 31 #include "ui/gfx/size.h"
31 #include "ui/gfx/text_elider.h" 32 #include "ui/gfx/text_elider.h"
32 #include "ui/gfx/text_utils.h" 33 #include "ui/gfx/text_utils.h"
33 #include "ui/views/border.h" 34 #include "ui/views/border.h"
34 #include "ui/views/controls/link.h" 35 #include "ui/views/controls/link.h"
35 #include "ui/views/controls/link_listener.h" 36 #include "ui/views/controls/link_listener.h"
36 #include "ui/views/layout/box_layout.h" 37 #include "ui/views/layout/box_layout.h"
37 38
39 #if defined(OS_CHROMEOS)
40 #include "ash/ash_view_ids.h"
41 #include "ash/media_delegate.h"
42 #include "ash/system/tray/media_security/media_capture_observer.h"
43 #include "ui/views/controls/image_view.h"
44 #include "ui/views/layout/fill_layout.h"
45 #endif
46
38 namespace ash { 47 namespace ash {
39 namespace tray { 48 namespace tray {
40 49
41 namespace { 50 namespace {
42 51
43 const int kUserDetailsVerticalPadding = 5; 52 const int kUserDetailsVerticalPadding = 5;
44 53
45 // The invisible word joiner character, used as a marker to indicate the start 54 // The invisible word joiner character, used as a marker to indicate the start
46 // and end of the user's display name in the public account user card's text. 55 // and end of the user's display name in the public account user card's text.
47 const base::char16 kDisplayNameMark[] = {0x2060, 0}; 56 const base::char16 kDisplayNameMark[] = {0x2060, 0};
48 57
58 #if defined(OS_CHROMEOS)
59 class MediaIndicator : public views::View, public MediaCaptureObserver {
60 public:
61 explicit MediaIndicator(MultiProfileIndex index)
62 : index_(index), label_(new views::Label) {
63 SetLayoutManager(new views::FillLayout);
64 views::ImageView* icon = new views::ImageView;
65 icon->SetImage(ui::ResourceBundle::GetSharedInstance()
66 .GetImageNamed(IDR_AURA_UBER_TRAY_RECORDING_RED)
67 .ToImageSkia());
68 AddChildView(icon);
69 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
70 label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
71 ui::ResourceBundle::SmallFont));
72 OnMediaCaptureChanged();
73 Shell::GetInstance()->system_tray_notifier()->AddMediaCaptureObserver(this);
74 set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR);
75 }
76
77 virtual ~MediaIndicator() {
78 Shell::GetInstance()->system_tray_notifier()->RemoveMediaCaptureObserver(
79 this);
80 }
81
82 // MediaCaptureObserver:
83 virtual void OnMediaCaptureChanged() OVERRIDE {
84 Shell* shell = Shell::GetInstance();
85 content::BrowserContext* context =
86 shell->session_state_delegate()->GetBrowserContextByIndex(index_);
87 MediaCaptureState state =
88 Shell::GetInstance()->media_delegate()->GetMediaCaptureState(context);
Mr4D (OOO till 08-26) 2014/05/02 18:07:29 According to GetMediaCaptureState you only check t
oshima 2014/05/02 18:59:05 This indicator is created for each of other users
89 int res_id = 0;
90 switch (state) {
91 case MEDIA_CAPTURE_AUDIO_VIDEO:
92 res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO_VIDEO;
93 break;
94 case MEDIA_CAPTURE_AUDIO:
95 res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO;
96 break;
97 case MEDIA_CAPTURE_VIDEO:
98 res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_VIDEO;
99 break;
100 case MEDIA_CAPTURE_NONE:
101 break;
102 }
103 SetMessage(res_id ? l10n_util::GetStringUTF16(res_id) : base::string16());
104 }
105
106 views::View* GetMessageView() { return label_; }
107
108 void SetMessage(const base::string16& message) {
109 SetVisible(!message.empty());
110 label_->SetText(message);
111 label_->SetVisible(!message.empty());
112 }
113
114 private:
115 MultiProfileIndex index_;
116 views::Label* label_;
117
118 DISALLOW_COPY_AND_ASSIGN(MediaIndicator);
119 };
120 #endif
121
49 // The user details shown in public account mode. This is essentially a label 122 // The user details shown in public account mode. This is essentially a label
50 // but with custom painting code as the text is styled with multiple colors and 123 // but with custom painting code as the text is styled with multiple colors and
51 // contains a link. 124 // contains a link.
52 class PublicAccountUserDetails : public views::View, 125 class PublicAccountUserDetails : public views::View,
53 public views::LinkListener { 126 public views::LinkListener {
54 public: 127 public:
55 PublicAccountUserDetails(int max_width); 128 PublicAccountUserDetails(int max_width);
56 virtual ~PublicAccountUserDetails(); 129 virtual ~PublicAccountUserDetails();
57 130
58 private: 131 private:
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 AddChildView(icon); 367 AddChildView(icon);
295 int details_max_width = max_width - icon->GetPreferredSize().width() - 368 int details_max_width = max_width - icon->GetPreferredSize().width() -
296 kTrayPopupPaddingBetweenItems; 369 kTrayPopupPaddingBetweenItems;
297 AddChildView(new PublicAccountUserDetails(details_max_width)); 370 AddChildView(new PublicAccountUserDetails(details_max_width));
298 } 371 }
299 372
300 void UserCardView::AddUserContent(user::LoginStatus login_status, 373 void UserCardView::AddUserContent(user::LoginStatus login_status,
301 int multiprofile_index) { 374 int multiprofile_index) {
302 views::View* icon = CreateIcon(login_status, multiprofile_index); 375 views::View* icon = CreateIcon(login_status, multiprofile_index);
303 AddChildView(icon); 376 AddChildView(icon);
304 views::Label* username = NULL; 377 views::Label* user_name = NULL;
305 SessionStateDelegate* delegate = 378 SessionStateDelegate* delegate =
306 Shell::GetInstance()->session_state_delegate(); 379 Shell::GetInstance()->session_state_delegate();
307 if (!multiprofile_index) { 380 if (!multiprofile_index) {
308 base::string16 user_name_string = 381 base::string16 user_name_string =
309 login_status == user::LOGGED_IN_GUEST 382 login_status == user::LOGGED_IN_GUEST
310 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL) 383 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)
311 : delegate->GetUserInfo(multiprofile_index)->GetDisplayName(); 384 : delegate->GetUserInfo(multiprofile_index)->GetDisplayName();
312 if (user_name_string.empty() && IsMultiAccountSupportedAndUserActive()) 385 if (user_name_string.empty() && IsMultiAccountSupportedAndUserActive())
313 user_name_string = base::ASCIIToUTF16( 386 user_name_string = base::ASCIIToUTF16(
314 delegate->GetUserInfo(multiprofile_index)->GetEmail()); 387 delegate->GetUserInfo(multiprofile_index)->GetEmail());
315 if (!user_name_string.empty()) { 388 if (!user_name_string.empty()) {
316 username = new views::Label(user_name_string); 389 user_name = new views::Label(user_name_string);
317 username->SetHorizontalAlignment(gfx::ALIGN_LEFT); 390 user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT);
318 } 391 }
319 } 392 }
320 393
321 views::Label* additional = NULL; 394 views::Label* user_email = NULL;
322 if (login_status != user::LOGGED_IN_GUEST && 395 if (login_status != user::LOGGED_IN_GUEST &&
323 (multiprofile_index || !IsMultiAccountSupportedAndUserActive())) { 396 (multiprofile_index || !IsMultiAccountSupportedAndUserActive())) {
324 base::string16 user_email_string = 397 base::string16 user_email_string =
325 login_status == user::LOGGED_IN_LOCALLY_MANAGED 398 login_status == user::LOGGED_IN_LOCALLY_MANAGED
326 ? l10n_util::GetStringUTF16( 399 ? l10n_util::GetStringUTF16(
327 IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL) 400 IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)
328 : base::UTF8ToUTF16( 401 : base::UTF8ToUTF16(
329 delegate->GetUserInfo(multiprofile_index)->GetEmail()); 402 delegate->GetUserInfo(multiprofile_index)->GetEmail());
330 if (!user_email_string.empty()) { 403 if (!user_email_string.empty()) {
331 additional = new views::Label(user_email_string); 404 user_email = new views::Label(user_email_string);
332 additional->SetFontList( 405 user_email->SetFontList(
333 ui::ResourceBundle::GetSharedInstance().GetFontList( 406 ui::ResourceBundle::GetSharedInstance().GetFontList(
334 ui::ResourceBundle::SmallFont)); 407 ui::ResourceBundle::SmallFont));
335 additional->SetHorizontalAlignment(gfx::ALIGN_LEFT); 408 user_email->SetHorizontalAlignment(gfx::ALIGN_LEFT);
336 } 409 }
337 } 410 }
338 411
339 // Adjust text properties dependent on if it is an active or inactive user. 412 // Adjust text properties dependent on if it is an active or inactive user.
340 if (multiprofile_index) { 413 if (multiprofile_index) {
341 // Fade the text of non active users to 50%. 414 // Fade the text of non active users to 50%.
342 SkColor text_color = additional->enabled_color(); 415 SkColor text_color = user_email->enabled_color();
343 text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2); 416 text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2);
344 if (additional) 417 if (user_email)
345 additional->SetDisabledColor(text_color); 418 user_email->SetDisabledColor(text_color);
346 if (username) 419 if (user_name)
347 username->SetDisabledColor(text_color); 420 user_name->SetDisabledColor(text_color);
348 } 421 }
349 422
350 if (additional && username) { 423 if (user_email && user_name) {
351 views::View* details = new views::View; 424 views::View* details = new views::View;
352 details->SetLayoutManager(new views::BoxLayout( 425 details->SetLayoutManager(new views::BoxLayout(
353 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0)); 426 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0));
354 details->AddChildView(username); 427 details->AddChildView(user_name);
355 details->AddChildView(additional); 428 details->AddChildView(user_email);
356 AddChildView(details); 429 AddChildView(details);
357 } else { 430 } else {
358 if (username) 431 if (user_name)
359 AddChildView(username); 432 AddChildView(user_name);
360 if (additional) 433 if (user_email) {
361 AddChildView(additional); 434 #if defined(OS_CHROMEOS)
435 // Only non active user can have a media indicator.
436 MediaIndicator* media_indicator = new MediaIndicator(multiprofile_index);
437 views::View* email_indicator_view = new views::View;
438 email_indicator_view->SetLayoutManager(new views::BoxLayout(
439 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems));
440 email_indicator_view->AddChildView(user_email);
441 email_indicator_view->AddChildView(media_indicator);
442
443 views::View* details = new views::View;
444 details->SetLayoutManager(new views::BoxLayout(
445 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0));
446 details->AddChildView(email_indicator_view);
447 details->AddChildView(media_indicator->GetMessageView());
448 AddChildView(details);
449 #else
450 AddChildView(user_email);
451 #endif
452 }
362 } 453 }
363 } 454 }
364 455
365 views::View* UserCardView::CreateIcon(user::LoginStatus login_status, 456 views::View* UserCardView::CreateIcon(user::LoginStatus login_status,
366 int multiprofile_index) { 457 int multiprofile_index) {
367 RoundedImageView* icon = 458 RoundedImageView* icon =
368 new RoundedImageView(kTrayAvatarCornerRadius, multiprofile_index == 0); 459 new RoundedImageView(kTrayAvatarCornerRadius, multiprofile_index == 0);
369 if (login_status == user::LOGGED_IN_GUEST) { 460 if (login_status == user::LOGGED_IN_GUEST) {
370 icon->SetImage(*ui::ResourceBundle::GetSharedInstance() 461 icon->SetImage(*ui::ResourceBundle::GetSharedInstance()
371 .GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON) 462 .GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON)
372 .ToImageSkia(), 463 .ToImageSkia(),
373 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); 464 gfx::Size(kTrayAvatarSize, kTrayAvatarSize));
374 } else { 465 } else {
375 SessionStateDelegate* delegate = 466 SessionStateDelegate* delegate =
376 Shell::GetInstance()->session_state_delegate(); 467 Shell::GetInstance()->session_state_delegate();
377 content::BrowserContext* context = 468 content::BrowserContext* context =
378 delegate->GetBrowserContextByIndex(multiprofile_index); 469 delegate->GetBrowserContextByIndex(multiprofile_index);
379 icon->SetImage(delegate->GetUserInfo(context)->GetImage(), 470 icon->SetImage(delegate->GetUserInfo(context)->GetImage(),
380 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); 471 gfx::Size(kTrayAvatarSize, kTrayAvatarSize));
381 } 472 }
382 return icon; 473 return icon;
383 } 474 }
384 475
385 } // namespace tray 476 } // namespace tray
386 } // namespace ash 477 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698