Chromium Code Reviews| 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/common/system/user/tray_user.h" | 5 #include "ash/common/system/user/tray_user.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 7 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 8 #include "ash/common/shelf/wm_shelf_util.h" | 9 #include "ash/common/shelf/wm_shelf_util.h" |
| 9 #include "ash/common/system/tray/system_tray.h" | 10 #include "ash/common/system/tray/system_tray.h" |
| 10 #include "ash/common/system/tray/system_tray_delegate.h" | 11 #include "ash/common/system/tray/system_tray_delegate.h" |
| 11 #include "ash/common/system/tray/system_tray_notifier.h" | 12 #include "ash/common/system/tray/system_tray_notifier.h" |
| 12 #include "ash/common/system/tray/tray_constants.h" | 13 #include "ash/common/system/tray/tray_constants.h" |
| 13 #include "ash/common/system/tray/tray_item_view.h" | 14 #include "ash/common/system/tray/tray_item_view.h" |
| 14 #include "ash/common/system/tray/tray_utils.h" | 15 #include "ash/common/system/tray/tray_utils.h" |
| 15 #include "ash/common/system/user/rounded_image_view.h" | 16 #include "ash/common/system/user/rounded_image_view.h" |
| 16 #include "ash/common/system/user/user_view.h" | 17 #include "ash/common/system/user/user_view.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 if (delegate->IsUserSupervised()) { | 169 if (delegate->IsUserSupervised()) { |
| 169 label_->SetText( | 170 label_->SetText( |
| 170 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)); | 171 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)); |
| 171 } else if (status == LoginStatus::GUEST) { | 172 } else if (status == LoginStatus::GUEST) { |
| 172 label_->SetText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); | 173 label_->SetText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); |
| 173 } | 174 } |
| 174 | 175 |
| 175 if (avatar_) { | 176 if (avatar_) { |
| 176 avatar_->SetCornerRadii(0, kTrayRoundedBorderRadius, | 177 avatar_->SetCornerRadii(0, kTrayRoundedBorderRadius, |
| 177 kTrayRoundedBorderRadius, 0); | 178 kTrayRoundedBorderRadius, 0); |
| 178 avatar_->SetBorder(views::Border::NullBorder()); | 179 const int distance_to_avatar = |
| 180 MaterialDesignController::IsShelfMaterial() | |
| 181 ? GetTrayConstant(TRAY_IMAGE_ITEM_PADDING) | |
| 182 : 0; | |
| 183 bool is_horizontal = | |
|
tdanderson
2016/10/05 21:34:29
nit: const
yiyix
2016/10/05 22:46:47
Done.
| |
| 184 IsHorizontalAlignment(system_tray()->shelf_alignment()); | |
| 185 avatar_->SetBorder(views::Border::CreateEmptyBorder( | |
| 186 is_horizontal ? 0 : distance_to_avatar, | |
| 187 is_horizontal ? distance_to_avatar : 0, 0, 0)); | |
|
tdanderson
2016/10/05 21:34:29
nice use of ternary
yiyix
2016/10/05 22:46:47
thanks.
| |
| 179 } | 188 } |
| 180 UpdateAvatarImage(status); | 189 UpdateAvatarImage(status); |
| 181 | 190 |
| 182 // Update layout after setting label_ and avatar_ with new login status. | 191 // Update layout after setting label_ and avatar_ with new login status. |
| 183 UpdateLayoutOfItem(); | 192 UpdateLayoutOfItem(); |
| 184 } | 193 } |
| 185 | 194 |
| 186 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 195 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 187 // Inactive users won't have a layout. | 196 // Inactive users won't have a layout. |
| 188 if (!layout_view_) | 197 if (!layout_view_) |
| 189 return; | 198 return; |
| 199 const int distance_to_avatar = MaterialDesignController::IsShelfMaterial() | |
| 200 ? GetTrayConstant(TRAY_IMAGE_ITEM_PADDING) | |
| 201 : 0; | |
| 190 if (IsHorizontalAlignment(alignment)) { | 202 if (IsHorizontalAlignment(alignment)) { |
| 191 if (avatar_) { | 203 if (avatar_) { |
| 192 avatar_->SetBorder(views::Border::NullBorder()); | 204 avatar_->SetBorder( |
| 205 views::Border::CreateEmptyBorder(0, distance_to_avatar, 0, 0)); | |
| 193 avatar_->SetCornerRadii(0, kTrayRoundedBorderRadius, | 206 avatar_->SetCornerRadii(0, kTrayRoundedBorderRadius, |
| 194 kTrayRoundedBorderRadius, 0); | 207 kTrayRoundedBorderRadius, 0); |
| 195 } | 208 } |
| 196 if (label_) { | 209 if (label_) { |
| 197 // If label_ hasn't figured out its size yet, do that first. | 210 // If label_ hasn't figured out its size yet, do that first. |
| 198 if (label_->GetContentsBounds().height() == 0) | 211 if (label_->GetContentsBounds().height() == 0) |
| 199 label_->SizeToPreferredSize(); | 212 label_->SizeToPreferredSize(); |
| 200 int height = label_->GetContentsBounds().height(); | 213 int height = label_->GetContentsBounds().height(); |
| 201 int vertical_pad = (kTrayItemSize - height) / 2; | 214 int vertical_pad = (kTrayItemSize - height) / 2; |
| 202 int remainder = height % 2; | 215 int remainder = height % 2; |
| 203 label_->SetBorder(views::Border::CreateEmptyBorder( | 216 label_->SetBorder(views::Border::CreateEmptyBorder( |
| 204 vertical_pad + remainder, | 217 vertical_pad + remainder, |
| 205 kTrayLabelItemHorizontalPaddingBottomAlignment, vertical_pad, | 218 kTrayLabelItemHorizontalPaddingBottomAlignment, vertical_pad, |
| 206 kTrayLabelItemHorizontalPaddingBottomAlignment)); | 219 kTrayLabelItemHorizontalPaddingBottomAlignment)); |
| 207 } | 220 } |
| 208 layout_view_->SetLayoutManager(new views::BoxLayout( | 221 layout_view_->SetLayoutManager(new views::BoxLayout( |
| 209 views::BoxLayout::kHorizontal, 0, 0, kUserLabelToIconPadding)); | 222 views::BoxLayout::kHorizontal, 0, 0, kUserLabelToIconPadding)); |
| 210 } else { | 223 } else { |
| 211 if (avatar_) { | 224 if (avatar_) { |
| 212 avatar_->SetBorder(views::Border::NullBorder()); | 225 avatar_->SetBorder( |
| 226 views::Border::CreateEmptyBorder(distance_to_avatar, 0, 0, 0)); | |
| 213 avatar_->SetCornerRadii(0, 0, kTrayRoundedBorderRadius, | 227 avatar_->SetCornerRadii(0, 0, kTrayRoundedBorderRadius, |
| 214 kTrayRoundedBorderRadius); | 228 kTrayRoundedBorderRadius); |
| 215 } | 229 } |
| 216 if (label_) { | 230 if (label_) { |
| 217 label_->SetBorder(views::Border::CreateEmptyBorder( | 231 label_->SetBorder(views::Border::CreateEmptyBorder( |
| 218 kTrayLabelItemVerticalPaddingVerticalAlignment, | 232 kTrayLabelItemVerticalPaddingVerticalAlignment, |
| 219 kTrayLabelItemHorizontalPaddingBottomAlignment, | 233 kTrayLabelItemHorizontalPaddingBottomAlignment, |
| 220 kTrayLabelItemVerticalPaddingVerticalAlignment, | 234 kTrayLabelItemVerticalPaddingVerticalAlignment, |
| 221 kTrayLabelItemHorizontalPaddingBottomAlignment)); | 235 kTrayLabelItemHorizontalPaddingBottomAlignment)); |
| 222 } | 236 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 // Unit tests might come here with no images for some users. | 275 // Unit tests might come here with no images for some users. |
| 262 if (avatar_->size().IsEmpty()) | 276 if (avatar_->size().IsEmpty()) |
| 263 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize)); | 277 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize)); |
| 264 } | 278 } |
| 265 | 279 |
| 266 void TrayUser::UpdateLayoutOfItem() { | 280 void TrayUser::UpdateLayoutOfItem() { |
| 267 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); | 281 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); |
| 268 } | 282 } |
| 269 | 283 |
| 270 } // namespace ash | 284 } // namespace ash |
| OLD | NEW |