| 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/ash_switches.h" |
| 11 #include "ash/popup_message.h" | 12 #include "ash/popup_message.h" |
| 12 #include "ash/session_state_delegate.h" | 13 #include "ash/session_state_delegate.h" |
| 13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 14 #include "ash/shell_delegate.h" | 15 #include "ash/shell_delegate.h" |
| 15 #include "ash/system/tray/system_tray.h" | 16 #include "ash/system/tray/system_tray.h" |
| 16 #include "ash/system/tray/system_tray_delegate.h" | 17 #include "ash/system/tray/system_tray_delegate.h" |
| 17 #include "ash/system/tray/system_tray_notifier.h" | 18 #include "ash/system/tray/system_tray_notifier.h" |
| 18 #include "ash/system/tray/tray_constants.h" | 19 #include "ash/system/tray/tray_constants.h" |
| 19 #include "ash/system/tray/tray_item_view.h" | 20 #include "ash/system/tray/tray_item_view.h" |
| 20 #include "ash/system/tray/tray_popup_label_button.h" | 21 #include "ash/system/tray/tray_popup_label_button.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 #include "ui/views/view.h" | 63 #include "ui/views/view.h" |
| 63 #include "ui/views/widget/widget.h" | 64 #include "ui/views/widget/widget.h" |
| 64 | 65 |
| 65 namespace { | 66 namespace { |
| 66 | 67 |
| 67 const int kUserDetailsVerticalPadding = 5; | 68 const int kUserDetailsVerticalPadding = 5; |
| 68 const int kUserCardVerticalPadding = 10; | 69 const int kUserCardVerticalPadding = 10; |
| 69 const int kInactiveUserCardVerticalPadding = 4; | 70 const int kInactiveUserCardVerticalPadding = 4; |
| 70 const int kProfileRoundedCornerRadius = 2; | 71 const int kProfileRoundedCornerRadius = 2; |
| 71 const int kUserIconSize = 27; | 72 const int kUserIconSize = 27; |
| 73 const int kUserIconLargeSize = 32; |
| 74 const int kUserIconLargeCornerRadius = 2; |
| 72 const int kUserLabelToIconPadding = 5; | 75 const int kUserLabelToIconPadding = 5; |
| 73 | 76 |
| 74 // When a hover border is used, it is starting this many pixels before the icon | 77 // When a hover border is used, it is starting this many pixels before the icon |
| 75 // position. | 78 // position. |
| 76 const int kTrayUserTileHoverBorderInset = 10; | 79 const int kTrayUserTileHoverBorderInset = 10; |
| 77 | 80 |
| 78 // The border color of the user button. | 81 // The border color of the user button. |
| 79 const SkColor kBorderColor = 0xffdcdcdc; | 82 const SkColor kBorderColor = 0xffdcdcdc; |
| 80 | 83 |
| 81 // The invisible word joiner character, used as a marker to indicate the start | 84 // The invisible word joiner character, used as a marker to indicate the start |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Constructs a new rounded image view with rounded corners of radius | 125 // Constructs a new rounded image view with rounded corners of radius |
| 123 // |corner_radius|. If |active_user| is set, the icon will be drawn in | 126 // |corner_radius|. If |active_user| is set, the icon will be drawn in |
| 124 // full colors - otherwise it will fade into the background. | 127 // full colors - otherwise it will fade into the background. |
| 125 RoundedImageView(int corner_radius, bool active_user); | 128 RoundedImageView(int corner_radius, bool active_user); |
| 126 virtual ~RoundedImageView(); | 129 virtual ~RoundedImageView(); |
| 127 | 130 |
| 128 // Set the image that should be displayed. The image contents is copied to the | 131 // Set the image that should be displayed. The image contents is copied to the |
| 129 // receiver's image. | 132 // receiver's image. |
| 130 void SetImage(const gfx::ImageSkia& img, const gfx::Size& size); | 133 void SetImage(const gfx::ImageSkia& img, const gfx::Size& size); |
| 131 | 134 |
| 135 // Set the radii of the corners independantly. |
| 136 void SetCornerRadii(int top_left, |
| 137 int top_right, |
| 138 int bottom_right, |
| 139 int bottom_left); |
| 140 |
| 132 private: | 141 private: |
| 133 // Overridden from views::View. | 142 // Overridden from views::View. |
| 134 virtual gfx::Size GetPreferredSize() OVERRIDE; | 143 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 135 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 144 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 136 | 145 |
| 137 gfx::ImageSkia image_; | 146 gfx::ImageSkia image_; |
| 138 gfx::ImageSkia resized_; | 147 gfx::ImageSkia resized_; |
| 139 gfx::Size image_size_; | 148 gfx::Size image_size_; |
| 140 int corner_radius_; | 149 int corner_radius_[4]; |
| 141 | 150 |
| 142 // True if the given user is the active user and the icon should get | 151 // True if the given user is the active user and the icon should get |
| 143 // painted as active. | 152 // painted as active. |
| 144 bool active_user_; | 153 bool active_user_; |
| 145 | 154 |
| 146 DISALLOW_COPY_AND_ASSIGN(RoundedImageView); | 155 DISALLOW_COPY_AND_ASSIGN(RoundedImageView); |
| 147 }; | 156 }; |
| 148 | 157 |
| 149 // The user details shown in public account mode. This is essentially a label | 158 // The user details shown in public account mode. This is essentially a label |
| 150 // but with custom painting code as the text is styled with multiple colors and | 159 // but with custom painting code as the text is styled with multiple colors and |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 // This is the owner view of this item. | 336 // This is the owner view of this item. |
| 328 UserCard* owner_; | 337 UserCard* owner_; |
| 329 | 338 |
| 330 // The anchor view for targetted bubble messages. | 339 // The anchor view for targetted bubble messages. |
| 331 views::View* anchor_; | 340 views::View* anchor_; |
| 332 | 341 |
| 333 DISALLOW_COPY_AND_ASSIGN(AddUserView); | 342 DISALLOW_COPY_AND_ASSIGN(AddUserView); |
| 334 }; | 343 }; |
| 335 | 344 |
| 336 RoundedImageView::RoundedImageView(int corner_radius, bool active_user) | 345 RoundedImageView::RoundedImageView(int corner_radius, bool active_user) |
| 337 : corner_radius_(corner_radius), | 346 : active_user_(active_user) { |
| 338 active_user_(active_user) {} | 347 for (int i = 0; i < 4; ++i) |
| 348 corner_radius_[i] = corner_radius; |
| 349 } |
| 339 | 350 |
| 340 RoundedImageView::~RoundedImageView() {} | 351 RoundedImageView::~RoundedImageView() {} |
| 341 | 352 |
| 342 void RoundedImageView::SetImage(const gfx::ImageSkia& img, | 353 void RoundedImageView::SetImage(const gfx::ImageSkia& img, |
| 343 const gfx::Size& size) { | 354 const gfx::Size& size) { |
| 344 image_ = img; | 355 image_ = img; |
| 345 image_size_ = size; | 356 image_size_ = size; |
| 346 | 357 |
| 347 // Try to get the best image quality for the avatar. | 358 // Try to get the best image quality for the avatar. |
| 348 resized_ = gfx::ImageSkiaOperations::CreateResizedImage(image_, | 359 resized_ = gfx::ImageSkiaOperations::CreateResizedImage(image_, |
| 349 skia::ImageOperations::RESIZE_BEST, size); | 360 skia::ImageOperations::RESIZE_BEST, size); |
| 350 if (GetWidget() && visible()) { | 361 if (GetWidget() && visible()) { |
| 351 PreferredSizeChanged(); | 362 PreferredSizeChanged(); |
| 352 SchedulePaint(); | 363 SchedulePaint(); |
| 353 } | 364 } |
| 354 } | 365 } |
| 355 | 366 |
| 367 void RoundedImageView::SetCornerRadii(int top_left, |
| 368 int top_right, |
| 369 int bottom_right, |
| 370 int bottom_left) { |
| 371 corner_radius_[0] = top_left; |
| 372 corner_radius_[1] = top_right; |
| 373 corner_radius_[2] = bottom_right; |
| 374 corner_radius_[3] = bottom_left; |
| 375 } |
| 376 |
| 356 gfx::Size RoundedImageView::GetPreferredSize() { | 377 gfx::Size RoundedImageView::GetPreferredSize() { |
| 357 return gfx::Size(image_size_.width() + GetInsets().width(), | 378 return gfx::Size(image_size_.width() + GetInsets().width(), |
| 358 image_size_.height() + GetInsets().height()); | 379 image_size_.height() + GetInsets().height()); |
| 359 } | 380 } |
| 360 | 381 |
| 361 void RoundedImageView::OnPaint(gfx::Canvas* canvas) { | 382 void RoundedImageView::OnPaint(gfx::Canvas* canvas) { |
| 362 View::OnPaint(canvas); | 383 View::OnPaint(canvas); |
| 363 gfx::Rect image_bounds(size()); | 384 gfx::Rect image_bounds(size()); |
| 364 image_bounds.ClampToCenteredSize(GetPreferredSize()); | 385 image_bounds.ClampToCenteredSize(GetPreferredSize()); |
| 365 image_bounds.Inset(GetInsets()); | 386 image_bounds.Inset(GetInsets()); |
| 366 const SkScalar kRadius = SkIntToScalar(corner_radius_); | 387 const SkScalar kRadius[8] = { |
| 388 SkIntToScalar(corner_radius_[0]), |
| 389 SkIntToScalar(corner_radius_[0]), |
| 390 SkIntToScalar(corner_radius_[1]), |
| 391 SkIntToScalar(corner_radius_[1]), |
| 392 SkIntToScalar(corner_radius_[2]), |
| 393 SkIntToScalar(corner_radius_[2]), |
| 394 SkIntToScalar(corner_radius_[3]), |
| 395 SkIntToScalar(corner_radius_[3]) |
| 396 }; |
| 367 SkPath path; | 397 SkPath path; |
| 368 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius, kRadius); | 398 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius); |
| 369 SkPaint paint; | 399 SkPaint paint; |
| 370 paint.setAntiAlias(true); | 400 paint.setAntiAlias(true); |
| 371 paint.setXfermodeMode(active_user_ ? SkXfermode::kSrcOver_Mode : | 401 paint.setXfermodeMode(active_user_ ? SkXfermode::kSrcOver_Mode : |
| 372 SkXfermode::kLuminosity_Mode); | 402 SkXfermode::kLuminosity_Mode); |
| 373 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(), | 403 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(), |
| 374 path, paint); | 404 path, paint); |
| 375 } | 405 } |
| 376 | 406 |
| 377 PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner, | 407 PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner, |
| 378 int used_width) | 408 int used_width) |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 avatar_ = NULL; | 1195 avatar_ = NULL; |
| 1166 } | 1196 } |
| 1167 } | 1197 } |
| 1168 | 1198 |
| 1169 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 1199 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 1170 if (status == user::LOGGED_IN_LOCALLY_MANAGED) { | 1200 if (status == user::LOGGED_IN_LOCALLY_MANAGED) { |
| 1171 label_->SetText( | 1201 label_->SetText( |
| 1172 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); | 1202 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); |
| 1173 } | 1203 } |
| 1174 | 1204 |
| 1205 int icon_size = kUserIconSize; |
| 1206 if (avatar_ && ash::switches::UseAlternateShelfLayout()) { |
| 1207 icon_size = kUserIconLargeSize; |
| 1208 avatar_->SetCornerRadii(0, |
| 1209 kUserIconLargeCornerRadius, |
| 1210 kUserIconLargeCornerRadius, |
| 1211 0); |
| 1212 avatar_->set_border(NULL); |
| 1213 } |
| 1175 if (avatar_) { | 1214 if (avatar_) { |
| 1176 if (status == user::LOGGED_IN_GUEST) { | 1215 if (status == user::LOGGED_IN_GUEST) { |
| 1177 avatar_->SetImage(*ui::ResourceBundle::GetSharedInstance(). | 1216 int image_name = ash::switches::UseAlternateShelfLayout() ? |
| 1178 GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON).ToImageSkia(), | 1217 IDR_AURA_UBER_TRAY_GUEST_ICON_LARGE : |
| 1179 gfx::Size(kUserIconSize, kUserIconSize)); | 1218 IDR_AURA_UBER_TRAY_GUEST_ICON; |
| 1219 avatar_->SetImage(*ui::ResourceBundle::GetSharedInstance(). |
| 1220 GetImageNamed(image_name).ToImageSkia(), |
| 1221 gfx::Size(icon_size, icon_size)); |
| 1180 } else { | 1222 } else { |
| 1181 avatar_->SetImage( | 1223 avatar_->SetImage( |
| 1182 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( | 1224 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( |
| 1183 multiprofile_index_), | 1225 multiprofile_index_), |
| 1184 gfx::Size(kUserIconSize, kUserIconSize)); | 1226 gfx::Size(icon_size, icon_size)); |
| 1185 } | 1227 } |
| 1186 } | 1228 } |
| 1187 } | 1229 } |
| 1188 | 1230 |
| 1189 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 1231 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 1190 // Inactive users won't have a layout. | 1232 // Inactive users won't have a layout. |
| 1191 if (!layout_view_) | 1233 if (!layout_view_) |
| 1192 return; | 1234 return; |
| 1193 if (alignment == SHELF_ALIGNMENT_BOTTOM || | 1235 if (alignment == SHELF_ALIGNMENT_BOTTOM || |
| 1194 alignment == SHELF_ALIGNMENT_TOP) { | 1236 alignment == SHELF_ALIGNMENT_TOP) { |
| 1195 if (avatar_) { | 1237 if (avatar_) { |
| 1196 avatar_->set_border(views::Border::CreateEmptyBorder( | 1238 if (ash::switches::UseAlternateShelfLayout()) { |
| 1197 0, kTrayImageItemHorizontalPaddingBottomAlignment + 2, | 1239 avatar_->set_border(NULL); |
| 1198 0, kTrayImageItemHorizontalPaddingBottomAlignment)); | 1240 avatar_->SetCornerRadii(0, |
| 1199 | 1241 kUserIconLargeCornerRadius, |
| 1242 kUserIconLargeCornerRadius, |
| 1243 0); |
| 1244 } else { |
| 1245 avatar_->set_border(views::Border::CreateEmptyBorder( |
| 1246 0, kTrayImageItemHorizontalPaddingBottomAlignment + 2, |
| 1247 0, kTrayImageItemHorizontalPaddingBottomAlignment)); |
| 1248 } |
| 1200 } | 1249 } |
| 1201 if (label_) { | 1250 if (label_) { |
| 1202 label_->set_border(views::Border::CreateEmptyBorder( | 1251 label_->set_border(views::Border::CreateEmptyBorder( |
| 1203 0, kTrayLabelItemHorizontalPaddingBottomAlignment, | 1252 0, kTrayLabelItemHorizontalPaddingBottomAlignment, |
| 1204 0, kTrayLabelItemHorizontalPaddingBottomAlignment)); | 1253 0, kTrayLabelItemHorizontalPaddingBottomAlignment)); |
| 1205 } | 1254 } |
| 1206 layout_view_->SetLayoutManager( | 1255 layout_view_->SetLayoutManager( |
| 1207 new views::BoxLayout(views::BoxLayout::kHorizontal, | 1256 new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 1208 0, 0, kUserLabelToIconPadding)); | 1257 0, 0, kUserLabelToIconPadding)); |
| 1209 } else { | 1258 } else { |
| 1210 if (avatar_) | 1259 if (avatar_) { |
| 1211 SetTrayImageItemBorder(avatar_, alignment); | 1260 if (ash::switches::UseAlternateShelfLayout()) { |
| 1261 avatar_->set_border(NULL); |
| 1262 avatar_->SetCornerRadii(0, |
| 1263 0, |
| 1264 kUserIconLargeCornerRadius, |
| 1265 kUserIconLargeCornerRadius); |
| 1266 } else { |
| 1267 SetTrayImageItemBorder(avatar_, alignment); |
| 1268 } |
| 1269 } |
| 1212 if (label_) { | 1270 if (label_) { |
| 1213 label_->set_border(views::Border::CreateEmptyBorder( | 1271 label_->set_border(views::Border::CreateEmptyBorder( |
| 1214 kTrayLabelItemVerticalPaddingVeriticalAlignment, | 1272 kTrayLabelItemVerticalPaddingVeriticalAlignment, |
| 1215 kTrayLabelItemHorizontalPaddingBottomAlignment, | 1273 kTrayLabelItemHorizontalPaddingBottomAlignment, |
| 1216 kTrayLabelItemVerticalPaddingVeriticalAlignment, | 1274 kTrayLabelItemVerticalPaddingVeriticalAlignment, |
| 1217 kTrayLabelItemHorizontalPaddingBottomAlignment)); | 1275 kTrayLabelItemHorizontalPaddingBottomAlignment)); |
| 1218 } | 1276 } |
| 1219 layout_view_->SetLayoutManager( | 1277 layout_view_->SetLayoutManager( |
| 1220 new views::BoxLayout(views::BoxLayout::kVertical, | 1278 new views::BoxLayout(views::BoxLayout::kVertical, |
| 1221 0, 0, kUserLabelToIconPadding)); | 1279 0, 0, kUserLabelToIconPadding)); |
| 1222 } | 1280 } |
| 1223 } | 1281 } |
| 1224 | 1282 |
| 1225 void TrayUser::OnUserUpdate() { | 1283 void TrayUser::OnUserUpdate() { |
| 1226 // Check for null to avoid crbug.com/150944. | 1284 // Check for null to avoid crbug.com/150944. |
| 1227 if (avatar_) { | 1285 if (avatar_) { |
| 1286 int icon_size = ash::switches::UseAlternateShelfLayout() ? |
| 1287 kUserIconLargeSize : kUserIconSize; |
| 1228 avatar_->SetImage( | 1288 avatar_->SetImage( |
| 1229 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( | 1289 ash::Shell::GetInstance()->session_state_delegate()->GetUserImage( |
| 1230 multiprofile_index_), | 1290 multiprofile_index_), |
| 1231 gfx::Size(kUserIconSize, kUserIconSize)); | 1291 gfx::Size(icon_size, icon_size)); |
| 1232 } | 1292 } |
| 1233 } | 1293 } |
| 1234 | 1294 |
| 1235 } // namespace internal | 1295 } // namespace internal |
| 1236 } // namespace ash | 1296 } // namespace ash |
| OLD | NEW |