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

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

Issue 2099103002: Give Ash material design tray items the correct size and layout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: split shelf and tray constants Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/system/status_area_widget_delegate.cc ('k') | ash/system/user/user_card_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/common/ash_switches.h" 7 #include "ash/common/ash_switches.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shelf/wm_shelf_util.h" 9 #include "ash/common/shelf/wm_shelf_util.h"
10 #include "ash/common/system/tray/system_tray_delegate.h" 10 #include "ash/common/system/tray/system_tray_delegate.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 (need_label != (label_ != nullptr))) { 152 (need_label != (label_ != nullptr))) {
153 layout_view_->RemoveAllChildViews(true); 153 layout_view_->RemoveAllChildViews(true);
154 if (need_label) { 154 if (need_label) {
155 label_ = new views::Label; 155 label_ = new views::Label;
156 SetupLabelForTray(label_); 156 SetupLabelForTray(label_);
157 layout_view_->AddChildView(label_); 157 layout_view_->AddChildView(label_);
158 } else { 158 } else {
159 label_ = nullptr; 159 label_ = nullptr;
160 } 160 }
161 if (need_avatar) { 161 if (need_avatar) {
162 avatar_ = new tray::RoundedImageView(kTrayAvatarCornerRadius, true); 162 avatar_ = new tray::RoundedImageView(kTrayRoundedBorderRadius, true);
163 layout_view_->AddChildView(avatar_); 163 layout_view_->AddChildView(avatar_);
164 } else { 164 } else {
165 avatar_ = nullptr; 165 avatar_ = nullptr;
166 } 166 }
167 } 167 }
168 168
169 if (delegate->IsUserSupervised()) { 169 if (delegate->IsUserSupervised()) {
170 label_->SetText( 170 label_->SetText(
171 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)); 171 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL));
172 } else if (status == LoginStatus::GUEST) { 172 } else if (status == LoginStatus::GUEST) {
173 label_->SetText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); 173 label_->SetText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL));
174 } 174 }
175 175
176 if (avatar_) { 176 if (avatar_) {
177 avatar_->SetCornerRadii(0, kTrayAvatarCornerRadius, kTrayAvatarCornerRadius, 177 avatar_->SetCornerRadii(0, kTrayRoundedBorderRadius,
178 0); 178 kTrayRoundedBorderRadius, 0);
179 avatar_->SetBorder(views::Border::NullBorder()); 179 avatar_->SetBorder(views::Border::NullBorder());
180 } 180 }
181 UpdateAvatarImage(status); 181 UpdateAvatarImage(status);
182 182
183 // Update layout after setting label_ and avatar_ with new login status. 183 // Update layout after setting label_ and avatar_ with new login status.
184 UpdateLayoutOfItem(); 184 UpdateLayoutOfItem();
185 } 185 }
186 186
187 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 187 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
188 // Inactive users won't have a layout. 188 // Inactive users won't have a layout.
189 if (!layout_view_) 189 if (!layout_view_)
190 return; 190 return;
191 if (IsHorizontalAlignment(alignment)) { 191 if (IsHorizontalAlignment(alignment)) {
192 if (avatar_) { 192 if (avatar_) {
193 avatar_->SetBorder(views::Border::NullBorder()); 193 avatar_->SetBorder(views::Border::NullBorder());
194 avatar_->SetCornerRadii(0, kTrayAvatarCornerRadius, 194 avatar_->SetCornerRadii(0, kTrayRoundedBorderRadius,
195 kTrayAvatarCornerRadius, 0); 195 kTrayRoundedBorderRadius, 0);
196 } 196 }
197 if (label_) { 197 if (label_) {
198 // If label_ hasn't figured out its size yet, do that first. 198 // If label_ hasn't figured out its size yet, do that first.
199 if (label_->GetContentsBounds().height() == 0) 199 if (label_->GetContentsBounds().height() == 0)
200 label_->SizeToPreferredSize(); 200 label_->SizeToPreferredSize();
201 int height = label_->GetContentsBounds().height(); 201 int height = label_->GetContentsBounds().height();
202 int vertical_pad = (kTrayItemSize - height) / 2; 202 int vertical_pad = (kTrayItemSize - height) / 2;
203 int remainder = height % 2; 203 int remainder = height % 2;
204 label_->SetBorder(views::Border::CreateEmptyBorder( 204 label_->SetBorder(views::Border::CreateEmptyBorder(
205 vertical_pad + remainder, 205 vertical_pad + remainder,
206 kTrayLabelItemHorizontalPaddingBottomAlignment, vertical_pad, 206 kTrayLabelItemHorizontalPaddingBottomAlignment, vertical_pad,
207 kTrayLabelItemHorizontalPaddingBottomAlignment)); 207 kTrayLabelItemHorizontalPaddingBottomAlignment));
208 } 208 }
209 layout_view_->SetLayoutManager(new views::BoxLayout( 209 layout_view_->SetLayoutManager(new views::BoxLayout(
210 views::BoxLayout::kHorizontal, 0, 0, kUserLabelToIconPadding)); 210 views::BoxLayout::kHorizontal, 0, 0, kUserLabelToIconPadding));
211 } else { 211 } else {
212 if (avatar_) { 212 if (avatar_) {
213 avatar_->SetBorder(views::Border::NullBorder()); 213 avatar_->SetBorder(views::Border::NullBorder());
214 avatar_->SetCornerRadii(0, 0, kTrayAvatarCornerRadius, 214 avatar_->SetCornerRadii(0, 0, kTrayRoundedBorderRadius,
215 kTrayAvatarCornerRadius); 215 kTrayRoundedBorderRadius);
216 } 216 }
217 if (label_) { 217 if (label_) {
218 label_->SetBorder(views::Border::CreateEmptyBorder( 218 label_->SetBorder(views::Border::CreateEmptyBorder(
219 kTrayLabelItemVerticalPaddingVerticalAlignment, 219 kTrayLabelItemVerticalPaddingVerticalAlignment,
220 kTrayLabelItemHorizontalPaddingBottomAlignment, 220 kTrayLabelItemHorizontalPaddingBottomAlignment,
221 kTrayLabelItemVerticalPaddingVerticalAlignment, 221 kTrayLabelItemVerticalPaddingVerticalAlignment,
222 kTrayLabelItemHorizontalPaddingBottomAlignment)); 222 kTrayLabelItemHorizontalPaddingBottomAlignment));
223 } 223 }
224 layout_view_->SetLayoutManager(new views::BoxLayout( 224 layout_view_->SetLayoutManager(new views::BoxLayout(
225 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding)); 225 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding));
(...skipping 24 matching lines...) Expand all
250 SessionStateDelegate* session_state_delegate = 250 SessionStateDelegate* session_state_delegate =
251 WmShell::Get()->GetSessionStateDelegate(); 251 WmShell::Get()->GetSessionStateDelegate();
252 if (!avatar_ || 252 if (!avatar_ ||
253 user_index_ >= session_state_delegate->NumberOfLoggedInUsers()) 253 user_index_ >= session_state_delegate->NumberOfLoggedInUsers())
254 return; 254 return;
255 255
256 const user_manager::UserInfo* user_info = 256 const user_manager::UserInfo* user_info =
257 session_state_delegate->GetUserInfo(user_index_); 257 session_state_delegate->GetUserInfo(user_index_);
258 CHECK(user_info); 258 CHECK(user_info);
259 avatar_->SetImage(user_info->GetImage(), 259 avatar_->SetImage(user_info->GetImage(),
260 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); 260 gfx::Size(kTrayItemSize, kTrayItemSize));
261 261
262 // Unit tests might come here with no images for some users. 262 // Unit tests might come here with no images for some users.
263 if (avatar_->size().IsEmpty()) 263 if (avatar_->size().IsEmpty())
264 avatar_->SetSize(gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); 264 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize));
265 } 265 }
266 266
267 void TrayUser::UpdateLayoutOfItem() { 267 void TrayUser::UpdateLayoutOfItem() {
268 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); 268 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment());
269 } 269 }
270 270
271 } // namespace ash 271 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/status_area_widget_delegate.cc ('k') | ash/system/user/user_card_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698