| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tray_user.h" | 5 #include "ash/system/user/tray_user.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <climits> | 8 #include <climits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/session_state_delegate.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/shell_delegate.h" | 13 #include "ash/shell_delegate.h" |
| 13 #include "ash/system/tray/system_tray.h" | 14 #include "ash/system/tray/system_tray.h" |
| 14 #include "ash/system/tray/system_tray_delegate.h" | 15 #include "ash/system/tray/system_tray_delegate.h" |
| 15 #include "ash/system/tray/system_tray_notifier.h" | 16 #include "ash/system/tray/system_tray_notifier.h" |
| 16 #include "ash/system/tray/tray_constants.h" | 17 #include "ash/system/tray/tray_constants.h" |
| 17 #include "ash/system/tray/tray_item_view.h" | 18 #include "ash/system/tray/tray_item_view.h" |
| 18 #include "ash/system/tray/tray_popup_label_button.h" | 19 #include "ash/system/tray/tray_popup_label_button.h" |
| 19 #include "ash/system/tray/tray_popup_label_button_border.h" | 20 #include "ash/system/tray/tray_popup_label_button_border.h" |
| 20 #include "ash/system/tray/tray_utils.h" | 21 #include "ash/system/tray/tray_utils.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "ui/views/layout/box_layout.h" | 55 #include "ui/views/layout/box_layout.h" |
| 55 #include "ui/views/layout/fill_layout.h" | 56 #include "ui/views/layout/fill_layout.h" |
| 56 #include "ui/views/painter.h" | 57 #include "ui/views/painter.h" |
| 57 #include "ui/views/view.h" | 58 #include "ui/views/view.h" |
| 58 #include "ui/views/widget/widget.h" | 59 #include "ui/views/widget/widget.h" |
| 59 | 60 |
| 60 namespace { | 61 namespace { |
| 61 | 62 |
| 62 const int kUserDetailsVerticalPadding = 5; | 63 const int kUserDetailsVerticalPadding = 5; |
| 63 const int kUserCardVerticalPadding = 10; | 64 const int kUserCardVerticalPadding = 10; |
| 65 const int kInactiveUserCardVerticalPadding = 4; |
| 64 const int kProfileRoundedCornerRadius = 2; | 66 const int kProfileRoundedCornerRadius = 2; |
| 65 const int kUserIconSize = 27; | 67 const int kUserIconSize = 27; |
| 66 const int kUserLabelToIconPadding = 5; | 68 const int kUserLabelToIconPadding = 5; |
| 67 | 69 |
| 70 // When a hover border is used, it is starting this many pixels before the icon |
| 71 // position. |
| 72 const int kTrayUserTileHoverBorderInset = 10; |
| 73 |
| 74 // The border color of the user button. |
| 75 const SkColor kBorderColor = 0xffdcdcdc; |
| 76 |
| 68 // The invisible word joiner character, used as a marker to indicate the start | 77 // The invisible word joiner character, used as a marker to indicate the start |
| 69 // and end of the user's display name in the public account user card's text. | 78 // and end of the user's display name in the public account user card's text. |
| 70 const char16 kDisplayNameMark[] = { 0x2060, 0 }; | 79 const char16 kDisplayNameMark[] = { 0x2060, 0 }; |
| 71 | 80 |
| 72 const int kPublicAccountLogoutButtonBorderImagesNormal[] = { | 81 const int kPublicAccountLogoutButtonBorderImagesNormal[] = { |
| 73 IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, | 82 IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, |
| 74 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, | 83 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, |
| 75 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, | 84 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, |
| 76 IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, | 85 IDR_AURA_TRAY_POPUP_PUBLIC_ACCOUNT_LOGOUT_BUTTON_BORDER, |
| 77 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, | 86 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 97 | 106 |
| 98 namespace ash { | 107 namespace ash { |
| 99 namespace internal { | 108 namespace internal { |
| 100 | 109 |
| 101 namespace tray { | 110 namespace tray { |
| 102 | 111 |
| 103 // A custom image view with rounded edges. | 112 // A custom image view with rounded edges. |
| 104 class RoundedImageView : public views::View { | 113 class RoundedImageView : public views::View { |
| 105 public: | 114 public: |
| 106 // Constructs a new rounded image view with rounded corners of radius | 115 // Constructs a new rounded image view with rounded corners of radius |
| 107 // |corner_radius|. | 116 // |corner_radius|. If |active_user| is set, the icon will be drawn in |
| 108 explicit RoundedImageView(int corner_radius); | 117 // full colors - otherwise it will fade into the background. |
| 118 RoundedImageView(int corner_radius, bool active_user); |
| 109 virtual ~RoundedImageView(); | 119 virtual ~RoundedImageView(); |
| 110 | 120 |
| 111 // Set the image that should be displayed. The image contents is copied to the | 121 // Set the image that should be displayed. The image contents is copied to the |
| 112 // receiver's image. | 122 // receiver's image. |
| 113 void SetImage(const gfx::ImageSkia& img, const gfx::Size& size); | 123 void SetImage(const gfx::ImageSkia& img, const gfx::Size& size); |
| 114 | 124 |
| 115 private: | 125 private: |
| 116 // Overridden from views::View. | 126 // Overridden from views::View. |
| 117 virtual gfx::Size GetPreferredSize() OVERRIDE; | 127 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 118 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 128 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 119 | 129 |
| 120 gfx::ImageSkia image_; | 130 gfx::ImageSkia image_; |
| 121 gfx::ImageSkia resized_; | 131 gfx::ImageSkia resized_; |
| 122 gfx::Size image_size_; | 132 gfx::Size image_size_; |
| 123 int corner_radius_; | 133 int corner_radius_; |
| 124 | 134 |
| 135 // True if the given user is the active user and the icon should get |
| 136 // painted as active. |
| 137 bool active_user_; |
| 138 |
| 125 DISALLOW_COPY_AND_ASSIGN(RoundedImageView); | 139 DISALLOW_COPY_AND_ASSIGN(RoundedImageView); |
| 126 }; | 140 }; |
| 127 | 141 |
| 128 class ClickableAvatar : public views::CustomButton { | |
| 129 public: | |
| 130 ClickableAvatar(views::ButtonListener* listener, | |
| 131 ash::user::LoginStatus login); | |
| 132 virtual ~ClickableAvatar(); | |
| 133 | |
| 134 private: | |
| 135 DISALLOW_COPY_AND_ASSIGN(ClickableAvatar); | |
| 136 }; | |
| 137 | |
| 138 // The user details shown in public account mode. This is essentially a label | 142 // The user details shown in public account mode. This is essentially a label |
| 139 // but with custom painting code as the text is styled with multiple colors and | 143 // but with custom painting code as the text is styled with multiple colors and |
| 140 // contains a link. | 144 // contains a link. |
| 141 class PublicAccountUserDetails : public views::View, | 145 class PublicAccountUserDetails : public views::View, |
| 142 public views::LinkListener { | 146 public views::LinkListener { |
| 143 public: | 147 public: |
| 144 PublicAccountUserDetails(SystemTrayItem* owner, int used_width); | 148 PublicAccountUserDetails(SystemTrayItem* owner, int used_width); |
| 145 virtual ~PublicAccountUserDetails(); | 149 virtual ~PublicAccountUserDetails(); |
| 146 | 150 |
| 147 private: | 151 private: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 159 void CalculatePreferredSize(SystemTrayItem* owner, int used_width); | 163 void CalculatePreferredSize(SystemTrayItem* owner, int used_width); |
| 160 | 164 |
| 161 base::string16 text_; | 165 base::string16 text_; |
| 162 views::Link* learn_more_; | 166 views::Link* learn_more_; |
| 163 gfx::Size preferred_size_; | 167 gfx::Size preferred_size_; |
| 164 ScopedVector<gfx::RenderText> lines_; | 168 ScopedVector<gfx::RenderText> lines_; |
| 165 | 169 |
| 166 DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails); | 170 DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails); |
| 167 }; | 171 }; |
| 168 | 172 |
| 173 // The button which holds the user card in case of multi profile. |
| 174 class UserCard : public views::CustomButton { |
| 175 public: |
| 176 UserCard(views::ButtonListener* listener, bool active_user); |
| 177 virtual ~UserCard(); |
| 178 |
| 179 // Overridden from views::View |
| 180 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
| 181 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
| 182 |
| 183 private: |
| 184 // Change the hover/active state of the "button". |
| 185 void ShowActive(bool active); |
| 186 |
| 187 // True if this is the active user. |
| 188 bool is_active_user_; |
| 189 DISALLOW_COPY_AND_ASSIGN(UserCard); |
| 190 }; |
| 191 |
| 169 class UserView : public views::View, | 192 class UserView : public views::View, |
| 170 public views::ButtonListener { | 193 public views::ButtonListener { |
| 171 public: | 194 public: |
| 172 explicit UserView(SystemTrayItem* owner, ash::user::LoginStatus login); | 195 UserView(SystemTrayItem* owner, |
| 196 ash::user::LoginStatus login, |
| 197 MultiProfileIndex index); |
| 173 virtual ~UserView(); | 198 virtual ~UserView(); |
| 174 | 199 |
| 175 private: | 200 private: |
| 176 // Overridden from views::View. | 201 // Overridden from views::View. |
| 177 virtual gfx::Size GetPreferredSize() OVERRIDE; | 202 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 178 virtual int GetHeightForWidth(int width) OVERRIDE; | 203 virtual int GetHeightForWidth(int width) OVERRIDE; |
| 179 virtual void Layout() OVERRIDE; | 204 virtual void Layout() OVERRIDE; |
| 180 | 205 |
| 181 // Overridden from views::ButtonListener. | 206 // Overridden from views::ButtonListener. |
| 182 virtual void ButtonPressed(views::Button* sender, | 207 virtual void ButtonPressed(views::Button* sender, |
| 183 const ui::Event& event) OVERRIDE; | 208 const ui::Event& event) OVERRIDE; |
| 184 | 209 |
| 185 void AddLogoutButton(ash::user::LoginStatus login); | 210 void AddLogoutButton(ash::user::LoginStatus login); |
| 186 void AddUserCard(SystemTrayItem* owner, ash::user::LoginStatus login); | 211 void AddUserCard(SystemTrayItem* owner, ash::user::LoginStatus login); |
| 187 | 212 |
| 213 // Create a user icon representation for the user card. |
| 214 views::View* CreateIconForUserCard(ash::user::LoginStatus login); |
| 215 |
| 216 // Create the additional user card content for the retail logged in mode. |
| 217 void AddLoggedInRetailModeUserCardContent(); |
| 218 |
| 219 // Create the additional user card content for the public mode. |
| 220 void AddLoggedInPublicModeUserCardContent(SystemTrayItem* owner); |
| 221 |
| 222 MultiProfileIndex multiprofile_index_; |
| 188 views::View* user_card_; | 223 views::View* user_card_; |
| 189 views::View* logout_button_; | 224 views::View* logout_button_; |
| 190 ClickableAvatar* profile_picture_; | |
| 191 | 225 |
| 192 DISALLOW_COPY_AND_ASSIGN(UserView); | 226 DISALLOW_COPY_AND_ASSIGN(UserView); |
| 193 }; | 227 }; |
| 194 | 228 |
| 195 RoundedImageView::RoundedImageView(int corner_radius) | 229 RoundedImageView::RoundedImageView(int corner_radius, bool active_user) |
| 196 : corner_radius_(corner_radius) {} | 230 : corner_radius_(corner_radius), |
| 231 active_user_(active_user) {} |
| 197 | 232 |
| 198 RoundedImageView::~RoundedImageView() {} | 233 RoundedImageView::~RoundedImageView() {} |
| 199 | 234 |
| 200 void RoundedImageView::SetImage(const gfx::ImageSkia& img, | 235 void RoundedImageView::SetImage(const gfx::ImageSkia& img, |
| 201 const gfx::Size& size) { | 236 const gfx::Size& size) { |
| 202 image_ = img; | 237 image_ = img; |
| 203 image_size_ = size; | 238 image_size_ = size; |
| 204 | 239 |
| 205 // Try to get the best image quality for the avatar. | 240 // Try to get the best image quality for the avatar. |
| 206 resized_ = gfx::ImageSkiaOperations::CreateResizedImage(image_, | 241 resized_ = gfx::ImageSkiaOperations::CreateResizedImage(image_, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 219 void RoundedImageView::OnPaint(gfx::Canvas* canvas) { | 254 void RoundedImageView::OnPaint(gfx::Canvas* canvas) { |
| 220 View::OnPaint(canvas); | 255 View::OnPaint(canvas); |
| 221 gfx::Rect image_bounds(size()); | 256 gfx::Rect image_bounds(size()); |
| 222 image_bounds.ClampToCenteredSize(GetPreferredSize()); | 257 image_bounds.ClampToCenteredSize(GetPreferredSize()); |
| 223 image_bounds.Inset(GetInsets()); | 258 image_bounds.Inset(GetInsets()); |
| 224 const SkScalar kRadius = SkIntToScalar(corner_radius_); | 259 const SkScalar kRadius = SkIntToScalar(corner_radius_); |
| 225 SkPath path; | 260 SkPath path; |
| 226 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius, kRadius); | 261 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius, kRadius); |
| 227 SkPaint paint; | 262 SkPaint paint; |
| 228 paint.setAntiAlias(true); | 263 paint.setAntiAlias(true); |
| 229 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 264 paint.setXfermodeMode(active_user_ ? SkXfermode::kSrcOver_Mode : |
| 265 SkXfermode::kLuminosity_Mode); |
| 230 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(), | 266 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(), |
| 231 path, paint); | 267 path, paint); |
| 232 } | 268 } |
| 233 | 269 |
| 234 ClickableAvatar::ClickableAvatar(views::ButtonListener* listener, | |
| 235 ash::user::LoginStatus login) | |
| 236 : views::CustomButton(listener) { | |
| 237 SetLayoutManager(new views::FillLayout()); | |
| 238 RoundedImageView* user_picture = | |
| 239 new RoundedImageView(kProfileRoundedCornerRadius); | |
| 240 if (login == ash::user::LOGGED_IN_GUEST) { | |
| 241 user_picture->SetImage(*ui::ResourceBundle::GetSharedInstance(). | |
| 242 GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON).ToImageSkia(), | |
| 243 gfx::Size(kUserIconSize, kUserIconSize)); | |
| 244 } else { | |
| 245 user_picture->SetImage( | |
| 246 ash::Shell::GetInstance()->system_tray_delegate()->GetUserImage(), | |
| 247 gfx::Size(kUserIconSize, kUserIconSize)); | |
| 248 } | |
| 249 AddChildView(user_picture); | |
| 250 } | |
| 251 | |
| 252 ClickableAvatar::~ClickableAvatar() {} | |
| 253 | |
| 254 PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner, | 270 PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner, |
| 255 int used_width) | 271 int used_width) |
| 256 : learn_more_(NULL) { | 272 : learn_more_(NULL) { |
| 257 const int inner_padding = | 273 const int inner_padding = |
| 258 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; | 274 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; |
| 259 const bool rtl = base::i18n::IsRTL(); | 275 const bool rtl = base::i18n::IsRTL(); |
| 260 set_border(views::Border::CreateEmptyBorder( | 276 set_border(views::Border::CreateEmptyBorder( |
| 261 kUserDetailsVerticalPadding, rtl ? 0 : inner_padding, | 277 kUserDetailsVerticalPadding, rtl ? 0 : inner_padding, |
| 262 kUserDetailsVerticalPadding, rtl ? inner_padding : 0)); | 278 kUserDetailsVerticalPadding, rtl ? inner_padding : 0)); |
| 263 | 279 |
| 264 ash::SystemTrayDelegate* delegate = | |
| 265 ash::Shell::GetInstance()->system_tray_delegate(); | |
| 266 // Retrieve the user's display name and wrap it with markers. | 280 // Retrieve the user's display name and wrap it with markers. |
| 267 base::string16 display_name = delegate->GetUserDisplayName(); | 281 // Note that since this is a public account it always has to be the primary |
| 282 // user. |
| 283 base::string16 display_name = |
| 284 ash::Shell::GetInstance()->session_state_delegate()-> |
| 285 GetUserDisplayName(0); |
| 268 RemoveChars(display_name, kDisplayNameMark, &display_name); | 286 RemoveChars(display_name, kDisplayNameMark, &display_name); |
| 269 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; | 287 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; |
| 270 // Retrieve the domain managing the device and wrap it with markers. | 288 // Retrieve the domain managing the device and wrap it with markers. |
| 271 base::string16 domain = UTF8ToUTF16(delegate->GetEnterpriseDomain()); | 289 base::string16 domain = UTF8ToUTF16( |
| 290 ash::Shell::GetInstance()->system_tray_delegate()->GetEnterpriseDomain()); |
| 272 RemoveChars(domain, kDisplayNameMark, &domain); | 291 RemoveChars(domain, kDisplayNameMark, &domain); |
| 273 base::i18n::WrapStringWithLTRFormatting(&domain); | 292 base::i18n::WrapStringWithLTRFormatting(&domain); |
| 274 // Retrieve the label text, inserting the display name and domain. | 293 // Retrieve the label text, inserting the display name and domain. |
| 275 text_ = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_PUBLIC_LABEL, | 294 text_ = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_PUBLIC_LABEL, |
| 276 display_name, domain); | 295 display_name, domain); |
| 277 | 296 |
| 278 learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_ASH_LEARN_MORE)); | 297 learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_ASH_LEARN_MORE)); |
| 279 learn_more_->SetUnderline(false); | 298 learn_more_->SetUnderline(false); |
| 280 learn_more_->set_listener(this); | 299 learn_more_->set_listener(this); |
| 281 AddChildView(learn_more_); | 300 AddChildView(learn_more_); |
| 282 | 301 |
| 283 CalculatePreferredSize(owner, used_width); | 302 CalculatePreferredSize(owner, used_width); |
| 284 } | 303 } |
| 285 | 304 |
| 286 PublicAccountUserDetails::~PublicAccountUserDetails() {} | 305 PublicAccountUserDetails::~PublicAccountUserDetails() {} |
| 287 | 306 |
| 288 void PublicAccountUserDetails::Layout() { | 307 void PublicAccountUserDetails::Layout() { |
| 289 lines_.clear(); | 308 lines_.clear(); |
| 290 const gfx::Rect contents_area = GetContentsBounds(); | 309 const gfx::Rect contents_area = GetContentsBounds(); |
| 291 if (contents_area.IsEmpty()) | 310 if (contents_area.IsEmpty()) |
| 292 return; | 311 return; |
| 293 | 312 |
| 294 // Word-wrap the label text. | 313 // Word-wrap the label text. |
| 295 const gfx::Font font; | 314 const gfx::Font font; |
| 296 std::vector<base::string16> lines; | 315 std::vector<base::string16> lines; |
| 297 ui::ElideRectangleText(text_, font, contents_area.width(), | 316 ui::ElideRectangleText(text_, font, contents_area.width(), |
| 298 contents_area.height(), ui::ELIDE_LONG_WORDS, &lines); | 317 contents_area.height(), ui::ELIDE_LONG_WORDS, &lines); |
| 299 // Loop through the lines, creating a renderer for each. | 318 // Loop through the lines, creating a renderer for each. |
| 300 gfx::Point position = contents_area.origin(); | 319 gfx::Point position = contents_area.origin(); |
| 301 ui::Range display_name(ui::Range::InvalidRange()); | 320 ui::Range display_name(ui::Range::InvalidRange()); |
| 302 for (std::vector<base::string16>::const_iterator it = lines.begin(); | 321 for (std::vector<base::string16>::const_iterator it = lines.begin(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 const int line_height = font.GetHeight(); | 437 const int line_height = font.GetHeight(); |
| 419 const int link_extra_height = std::max( | 438 const int link_extra_height = std::max( |
| 420 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); | 439 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); |
| 421 preferred_size_ = gfx::Size( | 440 preferred_size_ = gfx::Size( |
| 422 min_width + insets.width(), | 441 min_width + insets.width(), |
| 423 line_count * line_height + link_extra_height + insets.height()); | 442 line_count * line_height + link_extra_height + insets.height()); |
| 424 | 443 |
| 425 bubble_view->SetWidth(preferred_size_.width() + used_width); | 444 bubble_view->SetWidth(preferred_size_.width() + used_width); |
| 426 } | 445 } |
| 427 | 446 |
| 428 UserView::UserView(SystemTrayItem* owner, ash::user::LoginStatus login) | 447 UserCard::UserCard(views::ButtonListener* listener, bool active_user) |
| 429 : user_card_(NULL), | 448 : CustomButton(listener), |
| 430 logout_button_(NULL), | 449 is_active_user_(active_user) { |
| 431 profile_picture_(NULL) { | 450 if (is_active_user_) { |
| 451 set_background( |
| 452 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 453 ShowActive(false); |
| 454 } |
| 455 } |
| 456 |
| 457 UserCard::~UserCard() {} |
| 458 |
| 459 void UserCard::OnMouseEntered(const ui::MouseEvent& event) { |
| 460 if (is_active_user_) { |
| 461 background()->SetNativeControlColor(kHoverBackgroundColor); |
| 462 ShowActive(true); |
| 463 SchedulePaint(); |
| 464 } |
| 465 } |
| 466 |
| 467 void UserCard::OnMouseExited(const ui::MouseEvent& event) { |
| 468 if (is_active_user_) { |
| 469 background()->SetNativeControlColor(kBackgroundColor); |
| 470 ShowActive(false); |
| 471 SchedulePaint(); |
| 472 } |
| 473 } |
| 474 |
| 475 void UserCard::ShowActive(bool active) { |
| 476 int width = active ? 1 : 0; |
| 477 set_border(views::Border::CreateSolidSidedBorder(width, width, width, 1, |
| 478 kBorderColor)); |
| 479 } |
| 480 |
| 481 UserView::UserView(SystemTrayItem* owner, |
| 482 ash::user::LoginStatus login, |
| 483 MultiProfileIndex index) |
| 484 : multiprofile_index_(index), |
| 485 user_card_(NULL), |
| 486 logout_button_(NULL) { |
| 432 CHECK_NE(ash::user::LOGGED_IN_NONE, login); | 487 CHECK_NE(ash::user::LOGGED_IN_NONE, login); |
| 433 set_background(views::Background::CreateSolidBackground( | 488 if (!index) { |
| 434 login == ash::user::LOGGED_IN_PUBLIC ? kPublicAccountBackgroundColor : | 489 // Only the logged in user will have a background. All other users will have |
| 435 kBackgroundColor)); | 490 // to allow the TrayPopupContainer highlighting the menu line. |
| 491 set_background(views::Background::CreateSolidBackground( |
| 492 login == ash::user::LOGGED_IN_PUBLIC ? kPublicAccountBackgroundColor : |
| 493 kBackgroundColor)); |
| 494 } |
| 436 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | 495 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
| 437 kTrayPopupPaddingBetweenItems)); | 496 kTrayPopupPaddingBetweenItems)); |
| 438 // The logout button must be added before the user card so that the user card | 497 // The logout button must be added before the user card so that the user card |
| 439 // can correctly calculate the remaining available width. | 498 // can correctly calculate the remaining available width. |
| 440 AddLogoutButton(login); | 499 // Note that only the current multiprofile user gets a button. |
| 500 AddLogoutButton(!multiprofile_index_ ? login : ash::user::LOGGED_IN_LOCKED); |
| 441 AddUserCard(owner, login); | 501 AddUserCard(owner, login); |
| 442 } | 502 } |
| 443 | 503 |
| 444 UserView::~UserView() {} | 504 UserView::~UserView() {} |
| 445 | 505 |
| 446 gfx::Size UserView::GetPreferredSize() { | 506 gfx::Size UserView::GetPreferredSize() { |
| 447 gfx::Size size = views::View::GetPreferredSize(); | 507 gfx::Size size = views::View::GetPreferredSize(); |
| 448 // Make sure the default user view item is at least as tall as the other | 508 // Only the active user panel will be forced to a certain height. |
| 449 // items. | 509 if (!multiprofile_index_) { |
| 450 size.set_height(std::max(size.height(), | 510 size.set_height(std::max(size.height(), |
| 451 kTrayPopupItemHeight + GetInsets().height())); | 511 kTrayPopupItemHeight + GetInsets().height())); |
| 512 } |
| 452 return size; | 513 return size; |
| 453 } | 514 } |
| 454 | 515 |
| 455 int UserView::GetHeightForWidth(int width) { | 516 int UserView::GetHeightForWidth(int width) { |
| 456 return GetPreferredSize().height(); | 517 return GetPreferredSize().height(); |
| 457 } | 518 } |
| 458 | 519 |
| 459 void UserView::Layout() { | 520 void UserView::Layout() { |
| 460 gfx::Rect contents_area(GetContentsBounds()); | 521 gfx::Rect contents_area(GetContentsBounds()); |
| 461 if (user_card_ && logout_button_) { | 522 if (user_card_ && logout_button_) { |
| 462 // Give the logout button the space it requests. | 523 // Give the logout button the space it requests. |
| 463 gfx::Rect logout_area = contents_area; | 524 gfx::Rect logout_area = contents_area; |
| 464 logout_area.ClampToCenteredSize(logout_button_->GetPreferredSize()); | 525 logout_area.ClampToCenteredSize(logout_button_->GetPreferredSize()); |
| 465 logout_area.set_x(contents_area.right() - logout_area.width()); | 526 logout_area.set_x(contents_area.right() - logout_area.width()); |
| 466 logout_button_->SetBoundsRect(logout_area); | |
| 467 | 527 |
| 468 // Give the remaining space to the user card. | 528 // Give the remaining space to the user card. |
| 469 gfx::Rect user_card_area = contents_area; | 529 gfx::Rect user_card_area = contents_area; |
| 470 int remaining_width = contents_area.width() - | 530 int remaining_width = contents_area.width() - logout_area.width(); |
| 471 (logout_area.width() + kTrayPopupPaddingBetweenItems); | 531 if (ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) { |
| 472 user_card_area.set_width(std::max(0, remaining_width)); | 532 // In multiprofile case |user_card_| and |logout_button_| have to have the |
| 533 // same height. |
| 534 int y = std::min(user_card_area.y(), logout_area.y()); |
| 535 int height = std::max(user_card_area.height(), logout_area.height()); |
| 536 logout_area.set_y(y); |
| 537 logout_area.set_height(height); |
| 538 user_card_area.set_y(y); |
| 539 user_card_area.set_height(height); |
| 540 |
| 541 // In multiprofile mode we have also to increase the size of the card by |
| 542 // the size of the border to make it overlap with the logout button. |
| 543 user_card_area.set_width(std::max(0, remaining_width + 1)); |
| 544 |
| 545 // To make the logout button symmetrical with the user card we also make |
| 546 // the button longer by the same size the hover area in front of the icon |
| 547 // got inset. |
| 548 logout_area.set_width(logout_area.width() + |
| 549 kTrayUserTileHoverBorderInset); |
| 550 } else { |
| 551 // In all other modes we have to make sure that there is enough spacing |
| 552 // between the two. |
| 553 remaining_width -= kTrayPopupPaddingBetweenItems; |
| 554 } |
| 473 user_card_->SetBoundsRect(user_card_area); | 555 user_card_->SetBoundsRect(user_card_area); |
| 556 logout_button_->SetBoundsRect(logout_area); |
| 474 } else if (user_card_) { | 557 } else if (user_card_) { |
| 475 user_card_->SetBoundsRect(contents_area); | 558 user_card_->SetBoundsRect(contents_area); |
| 476 } else if (logout_button_) { | 559 } else if (logout_button_) { |
| 477 logout_button_->SetBoundsRect(contents_area); | 560 logout_button_->SetBoundsRect(contents_area); |
| 478 } | 561 } |
| 479 } | 562 } |
| 480 | 563 |
| 481 void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { | 564 void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { |
| 482 if (sender == logout_button_) { | 565 if (sender == logout_button_) { |
| 483 ash::Shell::GetInstance()->system_tray_delegate()->SignOut(); | 566 ash::Shell::GetInstance()->system_tray_delegate()->SignOut(); |
| 484 } else if (sender == profile_picture_) { | 567 } else if (sender == user_card_ && |
| 485 if (ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) | 568 ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) { |
| 486 ash::Shell::GetInstance()->system_tray_delegate()->ShowUserLogin(); | 569 if (!multiprofile_index_) { |
| 487 else | 570 // TODO(skuhne): Need to add the images & adding logic here. |
| 488 ash::Shell::GetInstance()->system_tray_delegate()->ChangeProfilePicture(); | 571 // TODO(skuhne): Make sure that we do not offer an add when this mode is |
| 572 // active. |
| 573 // TODO(skuhne): Use IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT as |
| 574 // string. |
| 575 const SessionStateDelegate* session_state_delegate = |
| 576 ash::Shell::GetInstance()->session_state_delegate(); |
| 577 if (session_state_delegate->NumberOfLoggedInUsers() >= |
| 578 session_state_delegate->GetMaximumNumberOfLoggedInUsers()) { |
| 579 // TODO(skuhne): Use IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER and |
| 580 // IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER when showing the error |
| 581 // message that no more users can be added. |
| 582 } else { |
| 583 ash::Shell::GetInstance()->system_tray_delegate()->ShowUserLogin(); |
| 584 } |
| 585 } else { |
| 586 ash::SessionStateDelegate* delegate = |
| 587 ash::Shell::GetInstance()->session_state_delegate(); |
| 588 delegate->SwitchActiveUser(delegate->GetUserEmail(multiprofile_index_)); |
| 589 } |
| 489 } else { | 590 } else { |
| 490 NOTREACHED(); | 591 NOTREACHED(); |
| 491 } | 592 } |
| 492 } | 593 } |
| 493 | 594 |
| 494 void UserView::AddLogoutButton(ash::user::LoginStatus login) { | 595 void UserView::AddLogoutButton(ash::user::LoginStatus login) { |
| 495 // A user should not be able to modify logged-in state when screen is | 596 // A user should not be able to modify logged-in state when screen is |
| 496 // locked. | 597 // locked. |
| 497 if (login == ash::user::LOGGED_IN_LOCKED) | 598 if (login == ash::user::LOGGED_IN_LOCKED) |
| 498 return; | 599 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 514 kPublicAccountLogoutButtonBorderImagesHovered)); | 615 kPublicAccountLogoutButtonBorderImagesHovered)); |
| 515 border->SetPainter(false, views::Button::STATE_PRESSED, | 616 border->SetPainter(false, views::Button::STATE_PRESSED, |
| 516 views::Painter::CreateImageGridPainter( | 617 views::Painter::CreateImageGridPainter( |
| 517 kPublicAccountLogoutButtonBorderImagesHovered)); | 618 kPublicAccountLogoutButtonBorderImagesHovered)); |
| 518 } | 619 } |
| 519 AddChildView(logout_button_); | 620 AddChildView(logout_button_); |
| 520 } | 621 } |
| 521 | 622 |
| 522 void UserView::AddUserCard(SystemTrayItem* owner, | 623 void UserView::AddUserCard(SystemTrayItem* owner, |
| 523 ash::user::LoginStatus login) { | 624 ash::user::LoginStatus login) { |
| 524 set_border(views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, | 625 // Add padding around the panel. |
| 525 0, kTrayPopupPaddingHorizontal)); | 626 set_border(views::Border::CreateEmptyBorder( |
| 627 kUserCardVerticalPadding, kTrayPopupPaddingHorizontal, |
| 628 kUserCardVerticalPadding, kTrayPopupPaddingHorizontal)); |
| 526 | 629 |
| 527 user_card_ = new views::View(); | 630 if (ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled() && |
| 631 login != ash::user::LOGGED_IN_RETAIL_MODE) { |
| 632 user_card_ = new UserCard(this, multiprofile_index_ == 0); |
| 633 } else { |
| 634 user_card_ = new views::View(); |
| 635 } |
| 636 |
| 528 user_card_->SetLayoutManager(new views::BoxLayout( | 637 user_card_->SetLayoutManager(new views::BoxLayout( |
| 529 views::BoxLayout::kHorizontal, 0, kUserCardVerticalPadding, | 638 views::BoxLayout::kHorizontal, 0, 0 , kTrayPopupPaddingBetweenItems)); |
| 530 kTrayPopupPaddingBetweenItems)); | |
| 531 AddChildViewAt(user_card_, 0); | 639 AddChildViewAt(user_card_, 0); |
| 532 | 640 |
| 533 if (login == ash::user::LOGGED_IN_RETAIL_MODE) { | 641 if (login == ash::user::LOGGED_IN_RETAIL_MODE) { |
| 534 views::Label* details = new views::Label; | 642 AddLoggedInRetailModeUserCardContent(); |
| 535 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 536 details->SetText( | |
| 537 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_KIOSK_LABEL)); | |
| 538 details->set_border(views::Border::CreateEmptyBorder(0, 4, 0, 1)); | |
| 539 details->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 540 user_card_->AddChildView(details); | |
| 541 return; | |
| 542 } | |
| 543 profile_picture_ = new ClickableAvatar(this, login); | |
| 544 user_card_->AddChildView(profile_picture_); | |
| 545 | |
| 546 if (login == ash::user::LOGGED_IN_PUBLIC) { | |
| 547 user_card_->AddChildView(new PublicAccountUserDetails( | |
| 548 owner, GetPreferredSize().width() + kTrayPopupPaddingBetweenItems)); | |
| 549 return; | 643 return; |
| 550 } | 644 } |
| 551 | 645 |
| 552 ash::SystemTrayDelegate* delegate = | 646 // The entire user card should trigger hover (the inner items get disabled). |
| 553 ash::Shell::GetInstance()->system_tray_delegate(); | 647 user_card_->SetEnabled(true); |
| 648 |
| 649 if (login == ash::user::LOGGED_IN_PUBLIC) { |
| 650 AddLoggedInPublicModeUserCardContent(owner); |
| 651 return; |
| 652 } |
| 653 |
| 654 views::View* icon = CreateIconForUserCard(login); |
| 655 user_card_->AddChildView(icon); |
| 656 |
| 657 // To allow the border to start before the icon, reduce the size before and |
| 658 // add an inset to the icon to get the spacing. |
| 659 if (multiprofile_index_ == 0 && |
| 660 ash::Shell::GetInstance()->delegate()->IsMultiProfilesEnabled()) { |
| 661 icon->set_border(views::Border::CreateEmptyBorder( |
| 662 0, kTrayUserTileHoverBorderInset, 0, 0)); |
| 663 set_border(views::Border::CreateEmptyBorder( |
| 664 kUserCardVerticalPadding, |
| 665 kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset, |
| 666 kUserCardVerticalPadding, |
| 667 kTrayPopupPaddingHorizontal)); |
| 668 } |
| 669 ash::SessionStateDelegate* delegate = |
| 670 ash::Shell::GetInstance()->session_state_delegate(); |
| 554 views::View* details = new views::View; | 671 views::View* details = new views::View; |
| 672 details->SetEnabled(false); |
| 555 details->SetLayoutManager(new views::BoxLayout( | 673 details->SetLayoutManager(new views::BoxLayout( |
| 556 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0)); | 674 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0)); |
| 675 views::Label* username = NULL; |
| 676 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 677 if (!multiprofile_index_) { |
| 678 views::Label* username = new views::Label( |
| 679 login == ash::user::LOGGED_IN_GUEST ? |
| 680 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL) : |
| 681 delegate->GetUserDisplayName(multiprofile_index_)); |
| 682 username->SetEnabled(false); |
| 683 username->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 684 details->AddChildView(username); |
| 685 } |
| 557 | 686 |
| 558 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 687 views::Label* additional = NULL; |
| 559 views::Label* username = new views::Label( | |
| 560 login == ash::user::LOGGED_IN_GUEST ? | |
| 561 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL) : | |
| 562 delegate->GetUserDisplayName()); | |
| 563 username->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 564 details->AddChildView(username); | |
| 565 | |
| 566 if (login != ash::user::LOGGED_IN_GUEST) { | 688 if (login != ash::user::LOGGED_IN_GUEST) { |
| 567 views::Label* additional = new views::Label(); | 689 additional = new views::Label(); |
| 568 additional->SetText(login == ash::user::LOGGED_IN_LOCALLY_MANAGED ? | 690 additional->SetText(login == ash::user::LOGGED_IN_LOCALLY_MANAGED ? |
| 569 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL) : | 691 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL) : |
| 570 UTF8ToUTF16(delegate->GetUserEmail())); | 692 UTF8ToUTF16(delegate->GetUserEmail(multiprofile_index_))); |
| 571 | 693 |
| 572 additional->SetFont(bundle.GetFont(ui::ResourceBundle::SmallFont)); | 694 additional->SetFont(bundle.GetFont(ui::ResourceBundle::SmallFont)); |
| 573 additional->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 695 additional->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 574 additional->SetEnabled(false); | 696 additional->SetEnabled(false); |
| 575 details->AddChildView(additional); | 697 details->AddChildView(additional); |
| 576 } | 698 } |
| 577 | 699 |
| 700 // Adjust text properties dependent on if it is an active or inactive user. |
| 701 if (multiprofile_index_) { |
| 702 // Fade the text of non active users to 50%. |
| 703 SkColor text_color = additional->enabled_color(); |
| 704 text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2); |
| 705 if (additional) |
| 706 additional->SetDisabledColor(text_color); |
| 707 if (username) |
| 708 username->SetDisabledColor(text_color); |
| 709 } |
| 710 |
| 711 // Use a small font for email address if username exists as well. |
| 712 if (username) |
| 713 additional->SetFont(bundle.GetFont(ui::ResourceBundle::SmallFont)); |
| 714 |
| 578 user_card_->AddChildView(details); | 715 user_card_->AddChildView(details); |
| 579 } | 716 } |
| 580 | 717 |
| 718 views::View* UserView::CreateIconForUserCard(ash::user::LoginStatus login) { |
| 719 RoundedImageView* icon = new RoundedImageView(kProfileRoundedCornerRadius, |
| 720 multiprofile_index_ == 0); |
| 721 icon->SetEnabled(false); |
| 722 if (login == ash::user::LOGGED_IN_GUEST) { |
| 723 icon->SetImage(*ui::ResourceBundle::GetSharedInstance(). |
| 724 GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON).ToImageSkia(), |
| 725 gfx::Size(kUserIconSize, kUserIconSize)); |
| 726 } else { |
| 727 icon->SetImage( |
| 728 ash::Shell::GetInstance()->session_state_delegate()-> |
| 729 GetUserImage(multiprofile_index_), |
| 730 gfx::Size(kUserIconSize, kUserIconSize)); |
| 731 } |
| 732 return icon; |
| 733 } |
| 734 |
| 735 void UserView::AddLoggedInRetailModeUserCardContent() { |
| 736 views::Label* details = new views::Label; |
| 737 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 738 details->SetText( |
| 739 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_KIOSK_LABEL)); |
| 740 details->set_border(views::Border::CreateEmptyBorder(0, 4, 0, 1)); |
| 741 details->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 742 user_card_->AddChildView(details); |
| 743 } |
| 744 |
| 745 void UserView::AddLoggedInPublicModeUserCardContent(SystemTrayItem* owner) { |
| 746 user_card_->AddChildView(CreateIconForUserCard(ash::user::LOGGED_IN_PUBLIC)); |
| 747 user_card_->AddChildView(new PublicAccountUserDetails( |
| 748 owner, GetPreferredSize().width() + kTrayPopupPaddingBetweenItems)); |
| 749 } |
| 750 |
| 581 } // namespace tray | 751 } // namespace tray |
| 582 | 752 |
| 583 TrayUser::TrayUser(SystemTray* system_tray) | 753 TrayUser::TrayUser(SystemTray* system_tray, MultiProfileIndex index) |
| 584 : SystemTrayItem(system_tray), | 754 : SystemTrayItem(system_tray), |
| 755 multiprofile_index_(index), |
| 585 user_(NULL), | 756 user_(NULL), |
| 586 layout_view_(NULL), | 757 layout_view_(NULL), |
| 587 avatar_(NULL), | 758 avatar_(NULL), |
| 588 label_(NULL) { | 759 label_(NULL) { |
| 589 Shell::GetInstance()->system_tray_notifier()->AddUserObserver(this); | 760 Shell::GetInstance()->system_tray_notifier()->AddUserObserver(this); |
| 590 } | 761 } |
| 591 | 762 |
| 592 TrayUser::~TrayUser() { | 763 TrayUser::~TrayUser() { |
| 593 Shell::GetInstance()->system_tray_notifier()->RemoveUserObserver(this); | 764 Shell::GetInstance()->system_tray_notifier()->RemoveUserObserver(this); |
| 594 } | 765 } |
| 595 | 766 |
| 596 views::View* TrayUser::CreateTrayView(user::LoginStatus status) { | 767 views::View* TrayUser::CreateTrayView(user::LoginStatus status) { |
| 597 CHECK(layout_view_ == NULL); | 768 CHECK(layout_view_ == NULL); |
| 769 // Only the current user gets an icon. All other users will only be |
| 770 // represented in the tray menu. |
| 771 if (multiprofile_index_) |
| 772 return NULL; |
| 773 |
| 598 layout_view_ = new views::View(); | 774 layout_view_ = new views::View(); |
| 599 layout_view_->SetLayoutManager( | 775 layout_view_->SetLayoutManager( |
| 600 new views::BoxLayout(views::BoxLayout::kHorizontal, | 776 new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 601 0, 0, kUserLabelToIconPadding)); | 777 0, 0, kUserLabelToIconPadding)); |
| 602 UpdateAfterLoginStatusChange(status); | 778 UpdateAfterLoginStatusChange(status); |
| 603 return layout_view_; | 779 return layout_view_; |
| 604 } | 780 } |
| 605 | 781 |
| 606 views::View* TrayUser::CreateDefaultView(user::LoginStatus status) { | 782 views::View* TrayUser::CreateDefaultView(user::LoginStatus status) { |
| 607 if (status == user::LOGGED_IN_NONE) | 783 if (status == user::LOGGED_IN_NONE) |
| 608 return NULL; | 784 return NULL; |
| 609 | 785 |
| 610 CHECK(user_ == NULL); | 786 CHECK(user_ == NULL); |
| 611 user_ = new tray::UserView(this, status); | 787 |
| 788 const SessionStateDelegate* session_state_delegate = |
| 789 ash::Shell::GetInstance()->session_state_delegate(); |
| 790 int logged_in_users = session_state_delegate->NumberOfLoggedInUsers(); |
| 791 |
| 792 // If there are multiple users logged in, the users will be separated from the |
| 793 // rest of the menu by a separator. |
| 794 if (multiprofile_index_ == |
| 795 session_state_delegate->GetMaximumNumberOfLoggedInUsers() && |
| 796 logged_in_users > 1) { |
| 797 return new views::View(); |
| 798 } |
| 799 |
| 800 // Do not show more UserView's then there are logged in users. |
| 801 if (multiprofile_index_ >= logged_in_users) |
| 802 return NULL;; |
| 803 |
| 804 user_ = new tray::UserView(this, status, multiprofile_index_); |
| 612 return user_; | 805 return user_; |
| 613 } | 806 } |
| 614 | 807 |
| 615 views::View* TrayUser::CreateDetailedView(user::LoginStatus status) { | 808 views::View* TrayUser::CreateDetailedView(user::LoginStatus status) { |
| 616 return NULL; | 809 return NULL; |
| 617 } | 810 } |
| 618 | 811 |
| 619 void TrayUser::DestroyTrayView() { | 812 void TrayUser::DestroyTrayView() { |
| 620 layout_view_ = NULL; | 813 layout_view_ = NULL; |
| 621 avatar_ = NULL; | 814 avatar_ = NULL; |
| 622 label_ = NULL; | 815 label_ = NULL; |
| 623 } | 816 } |
| 624 | 817 |
| 625 void TrayUser::DestroyDefaultView() { | 818 void TrayUser::DestroyDefaultView() { |
| 626 user_ = NULL; | 819 user_ = NULL; |
| 627 } | 820 } |
| 628 | 821 |
| 629 void TrayUser::DestroyDetailedView() { | 822 void TrayUser::DestroyDetailedView() { |
| 630 } | 823 } |
| 631 | 824 |
| 632 void TrayUser::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 825 void TrayUser::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
| 633 CHECK(layout_view_); | 826 // Only the active user is represented in the tray. |
| 827 if (!layout_view_) |
| 828 return; |
| 634 bool need_label = false; | 829 bool need_label = false; |
| 635 bool need_avatar = false; | 830 bool need_avatar = false; |
| 636 switch (status) { | 831 switch (status) { |
| 637 case user::LOGGED_IN_LOCKED: | 832 case user::LOGGED_IN_LOCKED: |
| 638 case user::LOGGED_IN_USER: | 833 case user::LOGGED_IN_USER: |
| 639 case user::LOGGED_IN_OWNER: | 834 case user::LOGGED_IN_OWNER: |
| 640 case user::LOGGED_IN_PUBLIC: | 835 case user::LOGGED_IN_PUBLIC: |
| 641 need_avatar = true; | 836 need_avatar = true; |
| 642 break; | 837 break; |
| 643 case user::LOGGED_IN_LOCALLY_MANAGED: | 838 case user::LOGGED_IN_LOCALLY_MANAGED: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 657 (need_label != (label_ != NULL))) { | 852 (need_label != (label_ != NULL))) { |
| 658 layout_view_->RemoveAllChildViews(true); | 853 layout_view_->RemoveAllChildViews(true); |
| 659 if (need_label) { | 854 if (need_label) { |
| 660 label_ = new views::Label; | 855 label_ = new views::Label; |
| 661 SetupLabelForTray(label_); | 856 SetupLabelForTray(label_); |
| 662 layout_view_->AddChildView(label_); | 857 layout_view_->AddChildView(label_); |
| 663 } else { | 858 } else { |
| 664 label_ = NULL; | 859 label_ = NULL; |
| 665 } | 860 } |
| 666 if (need_avatar) { | 861 if (need_avatar) { |
| 667 avatar_ = new tray::RoundedImageView(kProfileRoundedCornerRadius); | 862 avatar_ = new tray::RoundedImageView(kProfileRoundedCornerRadius, true); |
| 668 layout_view_->AddChildView(avatar_); | 863 layout_view_->AddChildView(avatar_); |
| 669 } else { | 864 } else { |
| 670 avatar_ = NULL; | 865 avatar_ = NULL; |
| 671 } | 866 } |
| 672 } | 867 } |
| 673 | 868 |
| 674 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 869 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 675 if (status == user::LOGGED_IN_LOCALLY_MANAGED) { | 870 if (status == user::LOGGED_IN_LOCALLY_MANAGED) { |
| 676 label_->SetText( | 871 label_->SetText( |
| 677 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); | 872 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); |
| 678 } | 873 } |
| 679 | 874 |
| 680 if (avatar_) { | 875 if (avatar_) { |
| 681 if (status == user::LOGGED_IN_GUEST) { | 876 if (status == user::LOGGED_IN_GUEST) { |
| 682 avatar_->SetImage(*ui::ResourceBundle::GetSharedInstance(). | 877 avatar_->SetImage(*ui::ResourceBundle::GetSharedInstance(). |
| 683 GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON).ToImageSkia(), | 878 GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON).ToImageSkia(), |
| 684 gfx::Size(kUserIconSize, kUserIconSize)); | 879 gfx::Size(kUserIconSize, kUserIconSize)); |
| 685 } else { | 880 } else { |
| 686 avatar_->SetImage( | 881 avatar_->SetImage( |
| 687 ash::Shell::GetInstance()->system_tray_delegate()->GetUserImage(), | 882 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( |
| 883 multiprofile_index_), |
| 688 gfx::Size(kUserIconSize, kUserIconSize)); | 884 gfx::Size(kUserIconSize, kUserIconSize)); |
| 689 } | 885 } |
| 690 } | 886 } |
| 691 } | 887 } |
| 692 | 888 |
| 693 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 889 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 694 CHECK(layout_view_); | 890 // Inactive users won't have a layout. |
| 891 if (!layout_view_) |
| 892 return; |
| 695 if (alignment == SHELF_ALIGNMENT_BOTTOM || | 893 if (alignment == SHELF_ALIGNMENT_BOTTOM || |
| 696 alignment == SHELF_ALIGNMENT_TOP) { | 894 alignment == SHELF_ALIGNMENT_TOP) { |
| 697 if (avatar_) { | 895 if (avatar_) { |
| 698 avatar_->set_border(views::Border::CreateEmptyBorder( | 896 avatar_->set_border(views::Border::CreateEmptyBorder( |
| 699 0, kTrayImageItemHorizontalPaddingBottomAlignment + 2, | 897 0, kTrayImageItemHorizontalPaddingBottomAlignment + 2, |
| 700 0, kTrayImageItemHorizontalPaddingBottomAlignment)); | 898 0, kTrayImageItemHorizontalPaddingBottomAlignment)); |
| 701 | 899 |
| 702 } | 900 } |
| 703 if (label_) { | 901 if (label_) { |
| 704 label_->set_border(views::Border::CreateEmptyBorder( | 902 label_->set_border(views::Border::CreateEmptyBorder( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 721 layout_view_->SetLayoutManager( | 919 layout_view_->SetLayoutManager( |
| 722 new views::BoxLayout(views::BoxLayout::kVertical, | 920 new views::BoxLayout(views::BoxLayout::kVertical, |
| 723 0, 0, kUserLabelToIconPadding)); | 921 0, 0, kUserLabelToIconPadding)); |
| 724 } | 922 } |
| 725 } | 923 } |
| 726 | 924 |
| 727 void TrayUser::OnUserUpdate() { | 925 void TrayUser::OnUserUpdate() { |
| 728 // Check for null to avoid crbug.com/150944. | 926 // Check for null to avoid crbug.com/150944. |
| 729 if (avatar_) { | 927 if (avatar_) { |
| 730 avatar_->SetImage( | 928 avatar_->SetImage( |
| 731 ash::Shell::GetInstance()->system_tray_delegate()->GetUserImage(), | 929 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( |
| 930 multiprofile_index_), |
| 732 gfx::Size(kUserIconSize, kUserIconSize)); | 931 gfx::Size(kUserIconSize, kUserIconSize)); |
| 733 } | 932 } |
| 734 } | 933 } |
| 735 | 934 |
| 736 } // namespace internal | 935 } // namespace internal |
| 737 } // namespace ash | 936 } // namespace ash |
| OLD | NEW |