1a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 2a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// found in the LICENSE file. 4a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 5a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ash/system/user/user_card_view.h" 6a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 7a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include <algorithm> 8a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include <vector> 9a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ash/session/session_state_delegate.h" 11a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ash/shell.h" 12a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ash/system/tray/system_tray_delegate.h" 13010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ash/system/tray/system_tray_notifier.h" 14a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ash/system/tray/tray_constants.h" 15a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ash/system/user/config.h" 16a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ash/system/user/rounded_image_view.h" 17a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/i18n/rtl.h" 18a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/memory/scoped_vector.h" 19a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/strings/string16.h" 20a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/strings/string_util.h" 21a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/strings/utf_string_conversions.h" 22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/user_manager/user_info.h" 23a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "grit/ash_resources.h" 24a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "grit/ash_strings.h" 25a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/base/l10n/l10n_util.h" 26a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/base/resource/resource_bundle.h" 27a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/insets.h" 28a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/range/range.h" 29a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/rect.h" 30a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/render_text.h" 31a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/size.h" 32a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/text_elider.h" 33a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/text_utils.h" 34a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/views/border.h" 35a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/views/controls/link.h" 36a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/views/controls/link_listener.h" 37a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/views/layout/box_layout.h" 38a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 39010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#if defined(OS_CHROMEOS) 40010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ash/ash_view_ids.h" 41010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ash/media_delegate.h" 42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ash/system/tray/media_security/media_capture_observer.h" 43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/views/controls/image_view.h" 44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/views/layout/fill_layout.h" 45010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#endif 46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 47a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace ash { 48a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace tray { 49a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 50a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace { 51a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 52a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochconst int kUserDetailsVerticalPadding = 5; 53a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 54a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// The invisible word joiner character, used as a marker to indicate the start 55a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// and end of the user's display name in the public account user card's text. 56a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochconst base::char16 kDisplayNameMark[] = {0x2060, 0}; 57a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 58010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#if defined(OS_CHROMEOS) 59010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class MediaIndicator : public views::View, public MediaCaptureObserver { 60010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public: 61010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) explicit MediaIndicator(MultiProfileIndex index) 62010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) : index_(index), label_(new views::Label) { 63010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SetLayoutManager(new views::FillLayout); 64010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::ImageView* icon = new views::ImageView; 65010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) icon->SetImage(ui::ResourceBundle::GetSharedInstance() 66010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) .GetImageNamed(IDR_AURA_UBER_TRAY_RECORDING_RED) 67010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) .ToImageSkia()); 68010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) AddChildView(icon); 69010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 70010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 71010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) ui::ResourceBundle::SmallFont)); 72010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) OnMediaCaptureChanged(); 73010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) Shell::GetInstance()->system_tray_notifier()->AddMediaCaptureObserver(this); 74010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR); 75010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 76010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 77010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual ~MediaIndicator() { 78010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) Shell::GetInstance()->system_tray_notifier()->RemoveMediaCaptureObserver( 79010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) this); 80010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 81010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 82010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // MediaCaptureObserver: 83010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void OnMediaCaptureChanged() OVERRIDE { 84010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) Shell* shell = Shell::GetInstance(); 85010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) content::BrowserContext* context = 86010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) shell->session_state_delegate()->GetBrowserContextByIndex(index_); 87010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) MediaCaptureState state = 88010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) Shell::GetInstance()->media_delegate()->GetMediaCaptureState(context); 89010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) int res_id = 0; 90010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) switch (state) { 91010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case MEDIA_CAPTURE_AUDIO_VIDEO: 92010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO_VIDEO; 93010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 94010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case MEDIA_CAPTURE_AUDIO: 95010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO; 96010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 97010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case MEDIA_CAPTURE_VIDEO: 98010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_VIDEO; 99010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 100010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case MEDIA_CAPTURE_NONE: 101010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 102010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 103010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SetMessage(res_id ? l10n_util::GetStringUTF16(res_id) : base::string16()); 104010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 105010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 106010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::View* GetMessageView() { return label_; } 107010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 108010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) void SetMessage(const base::string16& message) { 109010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SetVisible(!message.empty()); 110010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) label_->SetText(message); 111010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) label_->SetVisible(!message.empty()); 112010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 113010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 114010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) private: 115010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) MultiProfileIndex index_; 116010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::Label* label_; 117010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 118010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MediaIndicator); 119010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}; 120010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#endif 121010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 122a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// The user details shown in public account mode. This is essentially a label 123a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// but with custom painting code as the text is styled with multiple colors and 124a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// contains a link. 125a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochclass PublicAccountUserDetails : public views::View, 126a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch public views::LinkListener { 127a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch public: 128a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch PublicAccountUserDetails(int max_width); 129a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch virtual ~PublicAccountUserDetails(); 130a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 131a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch private: 132a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Overridden from views::View. 133a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch virtual void Layout() OVERRIDE; 134cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual gfx::Size GetPreferredSize() const OVERRIDE; 135a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 136a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 137a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Overridden from views::LinkListener. 138a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; 139a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 140a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Calculate a preferred size that ensures the label text and the following 141a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // link do not wrap over more than three lines in total for aesthetic reasons 142a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // if possible. 143a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch void CalculatePreferredSize(int max_allowed_width); 144a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 145a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch base::string16 text_; 146a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::Link* learn_more_; 147a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Size preferred_size_; 148a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ScopedVector<gfx::RenderText> lines_; 149a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 150a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails); 151a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}; 152a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 153a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochPublicAccountUserDetails::PublicAccountUserDetails(int max_width) 154a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch : learn_more_(NULL) { 155a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const int inner_padding = 156a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; 157a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const bool rtl = base::i18n::IsRTL(); 158a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch SetBorder(views::Border::CreateEmptyBorder(kUserDetailsVerticalPadding, 159a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch rtl ? 0 : inner_padding, 160a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch kUserDetailsVerticalPadding, 161a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch rtl ? inner_padding : 0)); 162a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 163a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Retrieve the user's display name and wrap it with markers. 164a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Note that since this is a public account it always has to be the primary 165a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // user. 1665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu base::string16 display_name = Shell::GetInstance() 1675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ->session_state_delegate() 1685c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ->GetUserInfo(0) 1695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ->GetDisplayName(); 170a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch base::RemoveChars(display_name, kDisplayNameMark, &display_name); 171a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; 172a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Retrieve the domain managing the device and wrap it with markers. 173a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch base::string16 domain = base::UTF8ToUTF16( 174a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch Shell::GetInstance()->system_tray_delegate()->GetEnterpriseDomain()); 175a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch base::RemoveChars(domain, kDisplayNameMark, &domain); 176a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch base::i18n::WrapStringWithLTRFormatting(&domain); 177a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Retrieve the label text, inserting the display name and domain. 178a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch text_ = l10n_util::GetStringFUTF16( 179a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch IDS_ASH_STATUS_TRAY_PUBLIC_LABEL, display_name, domain); 180a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 181a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_ASH_LEARN_MORE)); 182a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch learn_more_->SetUnderline(false); 183a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch learn_more_->set_listener(this); 184a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AddChildView(learn_more_); 185a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 186a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch CalculatePreferredSize(max_width); 187a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 188a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 189a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochPublicAccountUserDetails::~PublicAccountUserDetails() {} 190a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 191a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid PublicAccountUserDetails::Layout() { 192a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch lines_.clear(); 193a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const gfx::Rect contents_area = GetContentsBounds(); 194a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (contents_area.IsEmpty()) 195a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return; 196a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 197a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Word-wrap the label text. 198a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const gfx::FontList font_list; 199a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<base::string16> lines; 200a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::ElideRectangleText(text_, 201a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch font_list, 202a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch contents_area.width(), 203a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch contents_area.height(), 204a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::ELIDE_LONG_WORDS, 205a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch &lines); 206a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Loop through the lines, creating a renderer for each. 207a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Point position = contents_area.origin(); 208a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Range display_name(gfx::Range::InvalidRange()); 209a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch for (std::vector<base::string16>::const_iterator it = lines.begin(); 210a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch it != lines.end(); 211a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ++it) { 212a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::RenderText* line = gfx::RenderText::CreateInstance(); 213a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI); 214a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch line->SetText(*it); 215a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const gfx::Size size(contents_area.width(), line->GetStringSize().height()); 216a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch line->SetDisplayRect(gfx::Rect(position, size)); 217a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch position.set_y(position.y() + size.height()); 218a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 219a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Set the default text color for the line. 220a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch line->SetColor(kPublicAccountUserCardTextColor); 221a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 222a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // If a range of the line contains the user's display name, apply a custom 223a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // text color to it. 224a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (display_name.is_empty()) 225a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch display_name.set_start(it->find(kDisplayNameMark)); 226a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (!display_name.is_empty()) { 227a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch display_name.set_end( 228a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch it->find(kDisplayNameMark, display_name.start() + 1)); 229a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Range line_range(0, it->size()); 230a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch line->ApplyColor(kPublicAccountUserCardNameColor, 231a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch display_name.Intersect(line_range)); 232a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Update the range for the next line. 233a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (display_name.end() >= line_range.end()) 234a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch display_name.set_start(0); 235a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch else 236a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch display_name = gfx::Range::InvalidRange(); 237a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 238a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 239a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch lines_.push_back(line); 240a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 241a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 242a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Position the link after the label text, separated by a space. If it does 243a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // not fit onto the last line of the text, wrap the link onto its own line. 244a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const gfx::Size last_line_size = lines_.back()->GetStringSize(); 245a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const int space_width = 246a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::GetStringWidth(base::ASCIIToUTF16(" "), font_list); 247a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const gfx::Size link_size = learn_more_->GetPreferredSize(); 248a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (contents_area.width() - last_line_size.width() >= 249a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch space_width + link_size.width()) { 250a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch position.set_x(position.x() + last_line_size.width() + space_width); 251a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch position.set_y(position.y() - last_line_size.height()); 252a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 253a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch position.set_y(position.y() - learn_more_->GetInsets().top()); 254a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Rect learn_more_bounds(position, link_size); 255a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch learn_more_bounds.Intersect(contents_area); 256a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (base::i18n::IsRTL()) { 257a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const gfx::Insets insets = GetInsets(); 258a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch learn_more_bounds.Offset(insets.right() - insets.left(), 0); 259a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 260a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch learn_more_->SetBoundsRect(learn_more_bounds); 261a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 262a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 263cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)gfx::Size PublicAccountUserDetails::GetPreferredSize() const { 264a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return preferred_size_; 265a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 266a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 267a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid PublicAccountUserDetails::OnPaint(gfx::Canvas* canvas) { 268a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch for (ScopedVector<gfx::RenderText>::const_iterator it = lines_.begin(); 269a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch it != lines_.end(); 270a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ++it) { 271a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch (*it)->Draw(canvas); 272a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 273a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View::OnPaint(canvas); 274a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 275a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 276a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid PublicAccountUserDetails::LinkClicked(views::Link* source, 277a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch int event_flags) { 278a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch DCHECK_EQ(source, learn_more_); 279a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch Shell::GetInstance()->system_tray_delegate()->ShowPublicAccountInfo(); 280a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 281a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 282a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid PublicAccountUserDetails::CalculatePreferredSize(int max_allowed_width) { 283a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const gfx::FontList font_list; 284a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const gfx::Size link_size = learn_more_->GetPreferredSize(); 285a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const int space_width = 286a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::GetStringWidth(base::ASCIIToUTF16(" "), font_list); 287a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const gfx::Insets insets = GetInsets(); 288a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch int min_width = link_size.width(); 289a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch int max_width = std::min( 290a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::GetStringWidth(text_, font_list) + space_width + link_size.width(), 291a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch max_allowed_width - insets.width()); 292a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Do a binary search for the minimum width that ensures no more than three 293a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // lines are needed. The lower bound is the minimum of the current bubble 294a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // width and the width of the link (as no wrapping is permitted inside the 295a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // link). The upper bound is the maximum of the largest allowed bubble width 296a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // and the sum of the label text and link widths when put on a single line. 297a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<base::string16> lines; 298a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch while (min_width < max_width) { 299a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch lines.clear(); 300a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const int width = (min_width + max_width) / 2; 301a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const bool too_narrow = gfx::ElideRectangleText(text_, 302a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch font_list, 303a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch width, 304a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch INT_MAX, 305a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::TRUNCATE_LONG_WORDS, 306a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch &lines) != 0; 307a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch int line_count = lines.size(); 308a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (!too_narrow && line_count == 3 && 309a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch width - gfx::GetStringWidth(lines.back(), font_list) <= 310a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch space_width + link_size.width()) 311a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ++line_count; 312a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (too_narrow || line_count > 3) 313a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch min_width = width + 1; 314a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch else 315a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch max_width = width; 316a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 317a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 318a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Calculate the corresponding height and set the preferred size. 319a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch lines.clear(); 320a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::ElideRectangleText( 321a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch text_, font_list, min_width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines); 322a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch int line_count = lines.size(); 323a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (min_width - gfx::GetStringWidth(lines.back(), font_list) <= 324a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch space_width + link_size.width()) { 325a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ++line_count; 326a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 327a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const int line_height = font_list.GetHeight(); 328a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const int link_extra_height = std::max( 329a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch link_size.height() - learn_more_->GetInsets().top() - line_height, 0); 330a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch preferred_size_ = 331a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Size(min_width + insets.width(), 332a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch line_count * line_height + link_extra_height + insets.height()); 333a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 334a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 335a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} // namespace 336a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 337a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochUserCardView::UserCardView(user::LoginStatus login_status, 338a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch int max_width, 339a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch int multiprofile_index) { 340a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch SetLayoutManager(new views::BoxLayout( 341a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); 342a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch switch (login_status) { 343a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch case user::LOGGED_IN_RETAIL_MODE: 344a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AddRetailModeUserContent(); 345a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch break; 346a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch case user::LOGGED_IN_PUBLIC: 347a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AddPublicModeUserContent(max_width); 348a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch break; 349a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch default: 350a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AddUserContent(login_status, multiprofile_index); 351a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch break; 352a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 353a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 354a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 355a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochUserCardView::~UserCardView() {} 356a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 357a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid UserCardView::AddRetailModeUserContent() { 358a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::Label* details = new views::Label; 359a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch details->SetText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_KIOSK_LABEL)); 360a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch details->SetBorder(views::Border::CreateEmptyBorder(0, 4, 0, 1)); 361a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch details->SetHorizontalAlignment(gfx::ALIGN_LEFT); 362a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AddChildView(details); 363a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 364a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 365a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid UserCardView::AddPublicModeUserContent(int max_width) { 366a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View* icon = CreateIcon(user::LOGGED_IN_PUBLIC, 0); 367a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AddChildView(icon); 368a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch int details_max_width = max_width - icon->GetPreferredSize().width() - 369a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch kTrayPopupPaddingBetweenItems; 370a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AddChildView(new PublicAccountUserDetails(details_max_width)); 371a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 372a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 373a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid UserCardView::AddUserContent(user::LoginStatus login_status, 374a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch int multiprofile_index) { 375a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View* icon = CreateIcon(login_status, multiprofile_index); 376a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AddChildView(icon); 377010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::Label* user_name = NULL; 378a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch SessionStateDelegate* delegate = 379a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch Shell::GetInstance()->session_state_delegate(); 380a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (!multiprofile_index) { 381a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch base::string16 user_name_string = 382a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch login_status == user::LOGGED_IN_GUEST 383a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL) 3845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu : delegate->GetUserInfo(multiprofile_index)->GetDisplayName(); 385a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (user_name_string.empty() && IsMultiAccountSupportedAndUserActive()) 3865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu user_name_string = base::ASCIIToUTF16( 3875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu delegate->GetUserInfo(multiprofile_index)->GetEmail()); 388a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (!user_name_string.empty()) { 389010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) user_name = new views::Label(user_name_string); 390010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); 391a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 392a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 393a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 394010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::Label* user_email = NULL; 395a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (login_status != user::LOGGED_IN_GUEST && 396a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch (multiprofile_index || !IsMultiAccountSupportedAndUserActive())) { 3971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci SystemTrayDelegate* tray_delegate = 3981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Shell::GetInstance()->system_tray_delegate(); 399a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch base::string16 user_email_string = 4001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci tray_delegate->IsUserSupervised() 4015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL) 4025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu : base::UTF8ToUTF16( 4035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu delegate->GetUserInfo(multiprofile_index)->GetEmail()); 404a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (!user_email_string.empty()) { 405010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) user_email = new views::Label(user_email_string); 406010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) user_email->SetFontList( 407a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ui::ResourceBundle::GetSharedInstance().GetFontList( 408a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ui::ResourceBundle::SmallFont)); 409010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) user_email->SetHorizontalAlignment(gfx::ALIGN_LEFT); 410a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 411a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 412a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 413a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Adjust text properties dependent on if it is an active or inactive user. 414a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (multiprofile_index) { 415a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Fade the text of non active users to 50%. 416010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SkColor text_color = user_email->enabled_color(); 417a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2); 418010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (user_email) 419010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) user_email->SetDisabledColor(text_color); 420010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (user_name) 421010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) user_name->SetDisabledColor(text_color); 422a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 423a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 424010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (user_email && user_name) { 425a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View* details = new views::View; 426a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch details->SetLayoutManager(new views::BoxLayout( 427a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0)); 428010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) details->AddChildView(user_name); 429010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) details->AddChildView(user_email); 430a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AddChildView(details); 431a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } else { 432010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (user_name) 433010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) AddChildView(user_name); 434010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (user_email) { 435010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#if defined(OS_CHROMEOS) 436010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Only non active user can have a media indicator. 437010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) MediaIndicator* media_indicator = new MediaIndicator(multiprofile_index); 438010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::View* email_indicator_view = new views::View; 439010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) email_indicator_view->SetLayoutManager(new views::BoxLayout( 440010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); 441010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) email_indicator_view->AddChildView(user_email); 442010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) email_indicator_view->AddChildView(media_indicator); 443010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 444010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::View* details = new views::View; 445010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) details->SetLayoutManager(new views::BoxLayout( 446010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0)); 447010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) details->AddChildView(email_indicator_view); 448010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) details->AddChildView(media_indicator->GetMessageView()); 449010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) AddChildView(details); 450010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#else 451010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) AddChildView(user_email); 452010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#endif 453010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 454a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 455a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 456a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 457a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochviews::View* UserCardView::CreateIcon(user::LoginStatus login_status, 458a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch int multiprofile_index) { 459a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch RoundedImageView* icon = 460a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch new RoundedImageView(kTrayAvatarCornerRadius, multiprofile_index == 0); 461a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (login_status == user::LOGGED_IN_GUEST) { 462a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch icon->SetImage(*ui::ResourceBundle::GetSharedInstance() 463a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch .GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON) 464a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch .ToImageSkia(), 465a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); 466a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } else { 467a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch SessionStateDelegate* delegate = 468a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch Shell::GetInstance()->session_state_delegate(); 469a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch content::BrowserContext* context = 470a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch delegate->GetBrowserContextByIndex(multiprofile_index); 4715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu icon->SetImage(delegate->GetUserInfo(context)->GetImage(), 472a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); 473a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 474a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return icon; 475a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 476a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 477a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} // namespace tray 478a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} // namespace ash 479