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

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 2023093002: Reflow of the profile items in desktop user menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-profile-icon
Patch Set: Consolidated with upstream CL Created 4 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/ui/views/profiles/profile_chooser_view.h" 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/metrics/user_metrics.h" 8 #include "base/metrics/user_metrics.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 #include "ui/views/layout/box_layout.h" 76 #include "ui/views/layout/box_layout.h"
77 #include "ui/views/layout/fill_layout.h" 77 #include "ui/views/layout/fill_layout.h"
78 #include "ui/views/layout/grid_layout.h" 78 #include "ui/views/layout/grid_layout.h"
79 #include "ui/views/layout/layout_constants.h" 79 #include "ui/views/layout/layout_constants.h"
80 #include "ui/views/widget/widget.h" 80 #include "ui/views/widget/widget.h"
81 81
82 namespace { 82 namespace {
83 83
84 // Helpers -------------------------------------------------------------------- 84 // Helpers --------------------------------------------------------------------
85 85
86 const int kFixedMenuWidth = 250; 86 const int kFixedMenuWidth = 240;
Jane 2016/06/06 16:56:46 I couldn't figure out how to make this helper para
Roger Tawa OOO till Jul 10th 2016/06/07 14:20:48 You could write a function like: static int GetFi
Jane 2016/06/07 17:32:44 Done.
87 const int kButtonHeight = 32; 87 const int kButtonHeight = 32;
88 const int kPasswordCombinedFixedGaiaViewWidth = 360; 88 const int kPasswordCombinedFixedGaiaViewWidth = 360;
89 const int kFixedGaiaViewWidth = 448; 89 const int kFixedGaiaViewWidth = 448;
90 const int kFixedAccountRemovalViewWidth = 280; 90 const int kFixedAccountRemovalViewWidth = 280;
91 const int kFixedSwitchUserViewWidth = 320; 91 const int kFixedSwitchUserViewWidth = 320;
92 const int kLargeImageSide = 88; 92 const int kLargeImageSide = 88;
93 const int kMediumImageSide = 40;
93 94
95 const int kTextfieldLabelHorizontalSpacing = 4;
96 const int kProfileHorizontalSpacing = 16;
94 const int kVerticalSpacing = 16; 97 const int kVerticalSpacing = 16;
95 98
96 const int kTitleViewNativeWidgetOffset = 8; 99 const int kTitleViewNativeWidgetOffset = 8;
97 100
98 bool IsProfileChooser(profiles::BubbleViewMode mode) { 101 bool IsProfileChooser(profiles::BubbleViewMode mode) {
99 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || 102 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ||
100 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; 103 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
101 } 104 }
102 105
103 // Creates a GridLayout with a single column. This ensures that all the child 106 // Creates a GridLayout with a single column. This ensures that all the child
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 gfx::Rect bounds(title_view_->GetPreferredSize()); 259 gfx::Rect bounds(title_view_->GetPreferredSize());
257 title_view_->SetBoundsRect(bounds); 260 title_view_->SetBoundsRect(bounds);
258 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset); 261 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset);
259 title_widget_->SetBounds(bounds); 262 title_widget_->SetBounds(bounds);
260 } 263 }
261 264
262 } // namespace 265 } // namespace
263 266
264 // RightAlignedIconLabelButton ------------------------------------------------- 267 // RightAlignedIconLabelButton -------------------------------------------------
265 268
266 // A custom LabelButton that has a centered text and right aligned icon. 269 // A custom LabelButton that has a left-aligned text and right aligned icon.
270 // For non-material-design user menu, it has centered text instead.
267 class RightAlignedIconLabelButton : public views::LabelButton { 271 class RightAlignedIconLabelButton : public views::LabelButton {
268 public: 272 public:
269 RightAlignedIconLabelButton(views::ButtonListener* listener, 273 RightAlignedIconLabelButton(views::ButtonListener* listener,
270 const base::string16& text) 274 const base::string16& text)
271 : views::LabelButton(listener, text) { 275 : views::LabelButton(listener, text) {
272 SetHorizontalAlignment(gfx::ALIGN_RIGHT); 276 SetHorizontalAlignment(gfx::ALIGN_RIGHT);
273 label()->SetHorizontalAlignment(gfx::ALIGN_CENTER); 277 label()->SetHorizontalAlignment(switches::IsMaterialDesignUserMenu()
278 ? gfx::ALIGN_LEFT : gfx::ALIGN_CENTER);
274 } 279 }
275 280
276 protected: 281 protected:
277 void Layout() override { 282 void Layout() override {
278 views::LabelButton::Layout(); 283 views::LabelButton::Layout();
279 284
280 // Keep the text centered and the icon right-aligned by stretching the label 285 // Keep the text centered and the icon right-aligned by stretching the label
281 // to take up more of the content area and centering its contents. 286 // to take up more of the content area and centering its contents.
282 gfx::Rect content_bounds = GetContentsBounds(); 287 gfx::Rect content_bounds = GetContentsBounds();
283 gfx::Rect label_bounds = label()->bounds(); 288 gfx::Rect label_bounds = label()->bounds();
(...skipping 17 matching lines...) Expand all
301 306
302 // A custom Image control that shows a "change" button when moused over. 307 // A custom Image control that shows a "change" button when moused over.
303 class EditableProfilePhoto : public views::LabelButton { 308 class EditableProfilePhoto : public views::LabelButton {
304 public: 309 public:
305 EditableProfilePhoto(views::ButtonListener* listener, 310 EditableProfilePhoto(views::ButtonListener* listener,
306 const gfx::Image& icon, 311 const gfx::Image& icon,
307 bool is_editing_allowed, 312 bool is_editing_allowed,
308 const gfx::Rect& bounds) 313 const gfx::Rect& bounds)
309 : views::LabelButton(listener, base::string16()), 314 : views::LabelButton(listener, base::string16()),
310 photo_overlay_(NULL) { 315 photo_overlay_(NULL) {
316 const int kIconImageSide = switches::IsMaterialDesignUserMenu()
317 ? kMediumImageSide : kLargeImageSide;
311 gfx::Image image = profiles::GetSizedAvatarIcon( 318 gfx::Image image = profiles::GetSizedAvatarIcon(
312 icon, true, kLargeImageSide, kLargeImageSide); 319 icon, true, kIconImageSide, kIconImageSide);
313 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); 320 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia());
314 SetBorder(views::Border::NullBorder()); 321 SetBorder(views::Border::NullBorder());
315 SetBoundsRect(bounds); 322 SetBoundsRect(bounds);
316 323
317 // Calculate the circular mask that will be used to display the photo. 324 // Calculate the circular mask that will be used to display the photo.
318 circular_mask_.addCircle(SkIntToScalar(bounds.width() / 2), 325 circular_mask_.addCircle(SkIntToScalar(bounds.width() / 2),
319 SkIntToScalar(bounds.height() / 2), 326 SkIntToScalar(bounds.height() / 2),
320 SkIntToScalar(bounds.width() / 2)); 327 SkIntToScalar(bounds.width() / 2));
321 328
322 if (!is_editing_allowed) { 329 if (!is_editing_allowed) {
323 SetEnabled(false); 330 SetEnabled(false);
324 return; 331 return;
325 } 332 }
326 333
327 set_notify_enter_exit_on_child(true); 334 set_notify_enter_exit_on_child(true);
328 335
329 // Photo overlay that appears when hovering over the button. 336 // Photo overlay that appears when hovering over the button.
330 photo_overlay_ = new views::ImageView(); 337 photo_overlay_ = new views::ImageView();
331 338
332 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); 339 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255);
333 photo_overlay_->set_background( 340 photo_overlay_->set_background(
334 views::Background::CreateSolidBackground(kBackgroundColor)); 341 views::Background::CreateSolidBackground(kBackgroundColor));
335 photo_overlay_->SetImage(gfx::CreateVectorIcon( 342 photo_overlay_->SetImage(gfx::CreateVectorIcon(
336 gfx::VectorIconId::PHOTO_CAMERA, 48u, SkColorSetRGB(0x33, 0x33, 0x33))); 343 gfx::VectorIconId::PHOTO_CAMERA,
344 switches::IsMaterialDesignUserMenu() ? 22u : 48u,
345 SkColorSetRGB(0x33, 0x33, 0x33)));
337 346
338 photo_overlay_->SetSize(bounds.size()); 347 photo_overlay_->SetSize(bounds.size());
339 photo_overlay_->SetVisible(false); 348 photo_overlay_->SetVisible(false);
340 AddChildView(photo_overlay_); 349 AddChildView(photo_overlay_);
341 } 350 }
342 351
343 void OnPaint(gfx::Canvas* canvas) override { 352 void OnPaint(gfx::Canvas* canvas) override {
344 // Display the profile picture as a circle. 353 // Display the profile picture as a circle.
345 canvas->ClipPath(circular_mask_, true); 354 canvas->ClipPath(circular_mask_, true);
346 views::LabelButton::OnPaint(canvas); 355 views::LabelButton::OnPaint(canvas);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 407 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
399 408
400 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 409 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
401 const gfx::FontList& medium_font_list = 410 const gfx::FontList& medium_font_list =
402 rb->GetFontList(ui::ResourceBundle::MediumFont); 411 rb->GetFontList(ui::ResourceBundle::MediumFont);
403 412
404 if (!is_editing_allowed) { 413 if (!is_editing_allowed) {
405 label_ = new views::Label(text); 414 label_ = new views::Label(text);
406 label_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); 415 label_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0));
407 label_->SetFontList(medium_font_list); 416 label_->SetFontList(medium_font_list);
417 if (switches::IsMaterialDesignUserMenu()) {
418 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
419 }
408 AddChildView(label_); 420 AddChildView(label_);
409 return; 421 return;
410 } 422 }
411 423
412 button_ = new RightAlignedIconLabelButton(this, text); 424 button_ = new RightAlignedIconLabelButton(this, text);
413 button_->SetFontList(medium_font_list); 425 button_->SetFontList(medium_font_list);
414 // Show an "edit" pencil icon when hovering over. In the default state, 426 // Show an "edit" pencil icon when hovering over. In the default state,
415 // we need to create an empty placeholder of the correct size, so that 427 // we need to create an empty placeholder of the correct size, so that
416 // the text doesn't jump around when the hovered icon appears. 428 // the text doesn't jump around when the hovered icon appears.
417 // TODO(estade): revisit colors and press effect. 429 // TODO(estade): revisit colors and press effect.
418 const int kIconSize = 16; 430 const int kIconSize = 16;
419 button_->SetImage(views::LabelButton::STATE_NORMAL, 431 button_->SetImage(views::LabelButton::STATE_NORMAL,
420 CreateSquarePlaceholderImage(kIconSize)); 432 CreateSquarePlaceholderImage(kIconSize));
421 button_->SetImage(views::LabelButton::STATE_HOVERED, 433 button_->SetImage(views::LabelButton::STATE_HOVERED,
422 gfx::CreateVectorIcon( 434 gfx::CreateVectorIcon(
423 gfx::VectorIconId::MODE_EDIT, kIconSize, 435 gfx::VectorIconId::MODE_EDIT, kIconSize,
424 SkColorSetRGB(0x33, 0x33, 0x33))); 436 SkColorSetRGB(0x33, 0x33, 0x33)));
425 button_->SetImage(views::LabelButton::STATE_PRESSED, 437 button_->SetImage(views::LabelButton::STATE_PRESSED,
426 gfx::CreateVectorIcon( 438 gfx::CreateVectorIcon(
427 gfx::VectorIconId::MODE_EDIT, kIconSize, 439 gfx::VectorIconId::MODE_EDIT, kIconSize,
428 SkColorSetRGB(0x20, 0x20, 0x20))); 440 SkColorSetRGB(0x20, 0x20, 0x20)));
429 // To center the text, we need to offest it by the width of the icon we 441 // We need to add a left padding as well as a small top/bottom padding
430 // are adding and its padding. We need to also add a small top/bottom 442 // to the text to account for the textfield's border.
431 // padding to account for the textfield's border. 443 if (switches::IsMaterialDesignUserMenu()) {
432 const int kIconTextLabelButtonSpacing = 5; 444 button_->SetBorder(views::Border::CreateEmptyBorder(
433 button_->SetBorder(views::Border::CreateEmptyBorder( 445 2, kTextfieldLabelHorizontalSpacing, 2, 0));
434 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); 446 } else {
447 const int kIconTextLabelButtonSpacing = 5;
448 button_->SetBorder(views::Border::CreateEmptyBorder(
449 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0));
450 }
435 AddChildView(button_); 451 AddChildView(button_);
436 452
437 profile_name_textfield_ = new views::Textfield(); 453 profile_name_textfield_ = new views::Textfield();
438 // Textfield that overlaps the button. 454 // Textfield that overlaps the button.
439 profile_name_textfield_->set_controller(controller); 455 profile_name_textfield_->set_controller(controller);
440 profile_name_textfield_->SetFontList(medium_font_list); 456 profile_name_textfield_->SetFontList(medium_font_list);
441 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 457 profile_name_textfield_->SetHorizontalAlignment(
458 switches::IsMaterialDesignUserMenu()
459 ? gfx::ALIGN_LEFT : gfx::ALIGN_CENTER);
442 profile_name_textfield_->SetVisible(false); 460 profile_name_textfield_->SetVisible(false);
443 AddChildView(profile_name_textfield_); 461 AddChildView(profile_name_textfield_);
444 } 462 }
445 463
446 views::Textfield* profile_name_textfield() { 464 views::Textfield* profile_name_textfield() {
447 return profile_name_textfield_; 465 return profile_name_textfield_;
448 } 466 }
449 467
450 // Hide the editable textfield to show the profile name button instead. 468 // Hide the editable textfield to show the profile name button instead.
451 void ShowReadOnlyView() { 469 void ShowReadOnlyView() {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 576
559 views::ImageButton* back_button_; 577 views::ImageButton* back_button_;
560 views::Label* title_label_; 578 views::Label* title_label_;
561 579
562 DISALLOW_COPY_AND_ASSIGN(TitleCard); 580 DISALLOW_COPY_AND_ASSIGN(TitleCard);
563 }; 581 };
564 582
565 // ProfileBadge -------------------------------------------------------- 583 // ProfileBadge --------------------------------------------------------
566 584
567 const size_t kProfileBadgeSize = 30; 585 const size_t kProfileBadgeSize = 30;
586 const size_t kSmallProfileBadgeSize = 24;
568 const size_t kProfileBadgeWhitePadding = 2; 587 const size_t kProfileBadgeWhitePadding = 2;
569 588
570 // Draws a white circle, then a light blue circle, then a dark blue icon. 589 // Draws a white circle, then a light blue circle, then a dark blue icon.
571 class ProfileBadge : public gfx::CanvasImageSource { 590 class ProfileBadge : public gfx::CanvasImageSource {
572 public: 591 public:
573 ProfileBadge(gfx::VectorIconId id, size_t icon_size) 592 ProfileBadge(gfx::VectorIconId id, size_t icon_size)
574 : CanvasImageSource(gfx::Size(kProfileBadgeSize, kProfileBadgeSize), 593 : CanvasImageSource(gfx::Size(
575 false), 594 switches::IsMaterialDesignUserMenu()
595 ? kSmallProfileBadgeSize : kProfileBadgeSize,
596 switches::IsMaterialDesignUserMenu()
597 ? kSmallProfileBadgeSize : kProfileBadgeSize),
598 false),
576 id_(id), 599 id_(id),
577 icon_size_(icon_size) {} 600 icon_size_(icon_size) {}
578 601
579 ~ProfileBadge() override {} 602 ~ProfileBadge() override {}
580 603
581 // CanvasImageSource: 604 // CanvasImageSource:
582 void Draw(gfx::Canvas* canvas) override { 605 void Draw(gfx::Canvas* canvas) override {
583 const SkISize size = canvas->sk_canvas()->getBaseLayerSize(); 606 const SkISize size = canvas->sk_canvas()->getBaseLayerSize();
584 gfx::Rect bounds(0, 0, size.width(), size.height()); 607 gfx::Rect bounds(0, 0, size.width(), size.height());
585 608
586 SkPaint paint; 609 SkPaint paint;
587 paint.setAntiAlias(true); 610 paint.setAntiAlias(true);
588 paint.setColor(SK_ColorWHITE); 611 paint.setColor(SK_ColorWHITE);
589 canvas->DrawCircle(bounds.CenterPoint(), size.width() / 2, paint); 612 canvas->DrawCircle(bounds.CenterPoint(), size.width() / 2, paint);
590 613
591 paint.setColor(SkColorSetRGB(0xAF, 0xD9, 0xFC)); 614 paint.setColor(SkColorSetRGB(0xAF, 0xD9, 0xFC));
592 canvas->DrawCircle(bounds.CenterPoint(), 615 canvas->DrawCircle(bounds.CenterPoint(),
593 size.width() / 2 - kProfileBadgeWhitePadding, paint); 616 size.width() / 2 - kProfileBadgeWhitePadding, paint);
594 617
595 int offset = (kProfileBadgeSize - icon_size_) / 2; 618 int offset = ((switches::IsMaterialDesignUserMenu()
619 ? kSmallProfileBadgeSize : kProfileBadgeSize)
620 - icon_size_) / 2;
596 canvas->Translate(gfx::Vector2d(offset, offset)); 621 canvas->Translate(gfx::Vector2d(offset, offset));
597 gfx::PaintVectorIcon(canvas, id_, icon_size_, SkColorSetRGB(0, 0x66, 0xff)); 622 gfx::PaintVectorIcon(canvas, id_, icon_size_, SkColorSetRGB(0, 0x66, 0xff));
598 } 623 }
599 624
600 private: 625 private:
601 const gfx::VectorIconId id_; 626 const gfx::VectorIconId id_;
602 const size_t icon_size_; 627 const size_t icon_size_;
603 628
604 DISALLOW_COPY_AND_ASSIGN(ProfileBadge); 629 DISALLOW_COPY_AND_ASSIGN(ProfileBadge);
605 }; 630 };
606 631
607 gfx::ImageSkia CreateBadgeForProfile(Profile* profile) { 632 gfx::ImageSkia CreateBadgeForProfile(Profile* profile) {
608 ProfileBadge* badge = 633 ProfileBadge* badge = profile->IsChild()
609 profile->IsChild() 634 ? new ProfileBadge(gfx::VectorIconId::ACCOUNT_CHILD_INVERT,
610 ? new ProfileBadge(gfx::VectorIconId::ACCOUNT_CHILD_INVERT, 26) 635 switches::IsMaterialDesignUserMenu() ? 21 : 26)
611 : new ProfileBadge(gfx::VectorIconId::SUPERVISOR_ACCOUNT, 20); 636 : new ProfileBadge(gfx::VectorIconId::SUPERVISOR_ACCOUNT,
612 637 switches::IsMaterialDesignUserMenu() ? 16 : 20);
613 return gfx::ImageSkia(badge, badge->size()); 638 return gfx::ImageSkia(badge, badge->size());
614 } 639 }
615 640
616 // ProfileChooserView --------------------------------------------------------- 641 // ProfileChooserView ---------------------------------------------------------
617 642
618 // static 643 // static
619 ProfileChooserView* ProfileChooserView::profile_bubble_ = nullptr; 644 ProfileChooserView* ProfileChooserView::profile_bubble_ = nullptr;
620 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; 645 bool ProfileChooserView::close_on_deactivate_for_testing_ = true;
621 646
622 // static 647 // static
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 Indexes other_profiles; 1102 Indexes other_profiles;
1078 views::View* tutorial_view = NULL; 1103 views::View* tutorial_view = NULL;
1079 views::View* current_profile_view = NULL; 1104 views::View* current_profile_view = NULL;
1080 views::View* current_profile_accounts = NULL; 1105 views::View* current_profile_accounts = NULL;
1081 views::View* option_buttons_view = NULL; 1106 views::View* option_buttons_view = NULL;
1082 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { 1107 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
1083 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); 1108 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
1084 if (item.active) { 1109 if (item.active) {
1085 option_buttons_view = CreateOptionsView( 1110 option_buttons_view = CreateOptionsView(
1086 item.signed_in && profiles::IsLockAvailable(browser_->profile())); 1111 item.signed_in && profiles::IsLockAvailable(browser_->profile()));
1087 current_profile_view = CreateCurrentProfileView(item, false); 1112 current_profile_view = switches::IsMaterialDesignUserMenu() ?
1113 CreateMaterialDesignCurrentProfileView(item, false) :
1114 CreateCurrentProfileView(item, false);
Roger Tawa OOO till Jul 10th 2016/06/07 14:20:48 I think lines 1113 and 1114 only need to be indent
Jane 2016/06/07 17:32:44 Done.
1088 if (IsProfileChooser(view_mode_)) { 1115 if (IsProfileChooser(view_mode_)) {
1089 tutorial_view = CreateTutorialViewIfNeeded(item); 1116 tutorial_view = CreateTutorialViewIfNeeded(item);
1090 } else { 1117 } else {
1091 current_profile_accounts = CreateCurrentProfileAccountsView(item); 1118 current_profile_accounts = CreateCurrentProfileAccountsView(item);
1092 } 1119 }
1093 } else { 1120 } else {
1094 other_profiles.push_back(i); 1121 other_profiles.push_back(i);
1095 } 1122 }
1096 } 1123 }
1097 1124
(...skipping 16 matching lines...) Expand all
1114 1141
1115 if (!IsProfileChooser(view_mode_)) { 1142 if (!IsProfileChooser(view_mode_)) {
1116 DCHECK(current_profile_accounts); 1143 DCHECK(current_profile_accounts);
1117 layout->StartRow(0, 0); 1144 layout->StartRow(0, 0);
1118 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1145 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1119 layout->StartRow(1, 0); 1146 layout->StartRow(1, 0);
1120 layout->AddView(current_profile_accounts); 1147 layout->AddView(current_profile_accounts);
1121 } 1148 }
1122 1149
1123 if (browser_->profile()->IsSupervised()) { 1150 if (browser_->profile()->IsSupervised()) {
1124 layout->StartRow(0, 0); 1151 if (!switches::IsMaterialDesignUserMenu()) {
1125 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1152 layout->StartRow(0, 0);
1153 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1154 }
1126 layout->StartRow(1, 0); 1155 layout->StartRow(1, 0);
1127 layout->AddView(CreateSupervisedUserDisclaimerView()); 1156 layout->AddView(CreateSupervisedUserDisclaimerView());
1128 } 1157 }
1129 1158
1130 layout->StartRow(0, 0); 1159 layout->StartRow(0, 0);
1131 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1160 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1132 1161
1133 if (option_buttons_view) { 1162 if (option_buttons_view) {
1134 layout->StartRow(0, 0); 1163 layout->StartRow(0, 0);
1135 layout->AddView(option_buttons_view); 1164 layout->AddView(option_buttons_view);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 layout->StartRow(1, 0); 1467 layout->StartRow(1, 0);
1439 layout->AddView(signin_current_profile_link_); 1468 layout->AddView(signin_current_profile_link_);
1440 content::RecordAction( 1469 content::RecordAction(
1441 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); 1470 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin"));
1442 } 1471 }
1443 } 1472 }
1444 1473
1445 return view; 1474 return view;
1446 } 1475 }
1447 1476
1477 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView(
1478 const AvatarMenu::Item& avatar_item,
1479 bool is_guest) {
1480 views::View* view = new views::View();
1481 int column_width = kFixedMenuWidth - 2 * views::kMaterialHorizontalMargin;
1482 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width);
1483 layout->SetInsets(views::kRelatedControlVerticalSpacing,
1484 views::kMaterialHorizontalMargin,
1485 views::kRelatedControlVerticalSpacing,
1486 views::kMaterialHorizontalMargin);
1487
1488 // Profile picture left aligned for material design user menu,
1489 // centered otherwise.
1490 const int kProfileRowHeight = 56;
1491 current_profile_photo_ = new EditableProfilePhoto(
1492 this, avatar_item.icon, !is_guest,
1493 gfx::Rect(0, (kProfileRowHeight - kMediumImageSide) / 2,
1494 kMediumImageSide, kMediumImageSide));
1495 SizedContainer* profile_container =
1496 new SizedContainer(gfx::Size(column_width, kProfileRowHeight));
1497 profile_container->AddChildView(current_profile_photo_);
1498
1499 // Add supervised badge for supervised profile.
1500 if (browser_->profile()->IsSupervised()) {
1501 const int kBadgeSpacing = 4;
1502 views::ImageView* supervised_icon = new views::ImageView();
1503 supervised_icon->SetImage(CreateBadgeForProfile(browser_->profile()));
1504 gfx::Size preferred_size = supervised_icon->GetPreferredSize();
1505 gfx::Rect parent_bounds = current_profile_photo_->bounds();
1506 supervised_icon->SetBounds(
1507 parent_bounds.right() - preferred_size.width() + kBadgeSpacing,
1508 parent_bounds.bottom() - preferred_size.height() + kBadgeSpacing,
1509 preferred_size.width(),
1510 preferred_size.height());
1511 profile_container->AddChildView(supervised_icon);
1512 }
1513
1514 // Profile name, left-aligned to the right of profile icon.
1515 bool editing_allowed = !is_guest &&
1516 !browser_->profile()->IsLegacySupervised();
1517 current_profile_name_ = new EditableProfileName(
1518 this,
1519 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()),
1520 editing_allowed);
1521 gfx::Rect photo_bounds = current_profile_photo_->bounds();
1522 const int kTextfieldLeftMargin =
1523 kProfileHorizontalSpacing - kTextfieldLabelHorizontalSpacing;
1524 current_profile_name_->SetBounds(
1525 photo_bounds.width() + kTextfieldLeftMargin,
1526 views::kRelatedControlVerticalSpacing,
1527 profile_container->GetPreferredSize().width() - photo_bounds.width()
1528 - kTextfieldLeftMargin,
1529 profile_container->GetPreferredSize().height() / 2
1530 - views::kRelatedControlVerticalSpacing);
1531 profile_container->AddChildView(current_profile_name_);
1532
1533 // Center-align the avatar name if the profile is not signed in.
1534 if (is_guest || !avatar_item.signed_in) {
1535 current_profile_name_->SetY(
1536 (profile_container->GetPreferredSize().height()
1537 - current_profile_name_->height()) / 2);
1538 layout->StartRow(1, 0);
1539 layout->AddView(profile_container);
1540 }
1541
1542 if (is_guest)
1543 return view;
1544
1545 // The available links depend on the type of profile that is active.
1546 if (avatar_item.signed_in) {
1547 // Calculate the position and size for links available for signed-in
1548 // profiles.
1549 const int kXCoordinate = photo_bounds.width() + kProfileHorizontalSpacing;
1550 const int kYCoordinate = profile_container->GetPreferredSize().height() / 2;
1551 const int kWidth = profile_container->GetPreferredSize().width()
1552 - photo_bounds.width() - kProfileHorizontalSpacing;
1553 const int kHeight = profile_container->GetPreferredSize().height() / 2
1554 - views::kRelatedControlVerticalSpacing;
1555 layout->StartRow(1, 0);
1556
1557 if (switches::IsEnableAccountConsistency()) {
1558 base::string16 link_title = l10n_util::GetStringUTF16(
1559 IsProfileChooser(view_mode_) ?
1560 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON :
1561 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
1562 manage_accounts_link_ = CreateLink(link_title, this);
1563 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1564 manage_accounts_link_->SetBounds(
1565 kXCoordinate, kYCoordinate, kWidth, kHeight);
1566 profile_container->AddChildView(manage_accounts_link_);
1567 } else {
1568 // Badge the email address if there's an authentication error.
1569 if (HasAuthError(browser_->profile())) {
1570 auth_error_email_button_ =
1571 new RightAlignedIconLabelButton(this, avatar_item.username);
1572 auth_error_email_button_->SetElideBehavior(gfx::ELIDE_EMAIL);
1573 auth_error_email_button_->SetImage(
1574 views::LabelButton::STATE_NORMAL,
1575 gfx::CreateVectorIcon(gfx::VectorIconId::WARNING, 12,
1576 gfx::kChromeIconGrey));
1577 auth_error_email_button_->SetFocusForPlatform();
1578 auth_error_email_button_->set_request_focus_on_press(true);
1579 gfx::Insets insets =
1580 views::LabelButtonAssetBorder::GetDefaultInsetsForStyle(
1581 views::Button::STYLE_TEXTBUTTON);
1582 auth_error_email_button_->SetBorder(views::Border::CreateEmptyBorder(
1583 insets.top(), insets.left(), insets.bottom(), insets.right()));
1584 auth_error_email_button_->SetBounds(
1585 kXCoordinate - insets.left(), kYCoordinate, kWidth, kHeight);
1586 profile_container->AddChildView(auth_error_email_button_);
1587 } else {
1588 views::Label* email_label = new views::Label(avatar_item.username);
1589 email_label->SetElideBehavior(gfx::ELIDE_EMAIL);
1590 email_label->SetEnabled(false);
1591 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1592 email_label->SetBounds(
1593 kXCoordinate, kYCoordinate, kWidth, kHeight);
1594 profile_container->AddChildView(email_label);
1595 }
1596 }
1597 layout->AddView(profile_container);
1598 } else {
1599 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile(
1600 browser_->profile()->GetOriginalProfile());
1601 if (signin_manager->IsSigninAllowed()) {
1602 views::Label* promo = new views::Label(
1603 l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO));
1604 promo->SetMultiLine(true);
1605 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1606 layout->StartRowWithPadding(1, 0, 0,
1607 views::kRelatedControlVerticalSpacing);
1608 layout->StartRow(1, 0);
1609 layout->AddView(promo);
1610
1611 signin_current_profile_link_ = new views::BlueButton(
1612 this, l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL,
1613 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
1614 layout->StartRowWithPadding(1, 0, 0,
1615 views::kRelatedControlVerticalSpacing);
1616 layout->StartRow(1, 0);
1617 layout->AddView(signin_current_profile_link_);
1618 content::RecordAction(
1619 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin"));
1620 layout->StartRowWithPadding(1, 0, 0,
1621 views::kLabelToControlVerticalSpacing);
1622 }
1623 }
1624
1625 return view;
1626 }
1627
1448 views::View* ProfileChooserView::CreateGuestProfileView() { 1628 views::View* ProfileChooserView::CreateGuestProfileView() {
1449 gfx::Image guest_icon = 1629 gfx::Image guest_icon =
1450 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 1630 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
1451 profiles::GetPlaceholderAvatarIconResourceID()); 1631 profiles::GetPlaceholderAvatarIconResourceID());
1452 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); 1632 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon);
1453 guest_avatar_item.active = true; 1633 guest_avatar_item.active = true;
1454 guest_avatar_item.name = l10n_util::GetStringUTF16( 1634 guest_avatar_item.name = l10n_util::GetStringUTF16(
1455 IDS_PROFILES_GUEST_PROFILE_NAME); 1635 IDS_PROFILES_GUEST_PROFILE_NAME);
1456 guest_avatar_item.signed_in = false; 1636 guest_avatar_item.signed_in = false;
1457 1637
1458 return CreateCurrentProfileView(guest_avatar_item, true); 1638 return switches::IsMaterialDesignUserMenu() ?
1639 CreateMaterialDesignCurrentProfileView(guest_avatar_item, true) :
1640 CreateCurrentProfileView(guest_avatar_item, true);
1459 } 1641 }
1460 1642
1461 views::View* ProfileChooserView::CreateOtherProfilesView( 1643 views::View* ProfileChooserView::CreateOtherProfilesView(
1462 const Indexes& avatars_to_show) { 1644 const Indexes& avatars_to_show) {
1463 views::View* view = new views::View(); 1645 views::View* view = new views::View();
1464 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 1646 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
1465 1647
1466 for (size_t index : avatars_to_show) { 1648 for (size_t index : avatars_to_show) {
1467 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index); 1649 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index);
1468 const int kSmallImageSide = 32; 1650 const int kSmallImageSide = 32;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 layout->StartRow(1, 0); 1697 layout->StartRow(1, 0);
1516 layout->AddView(lock_button_); 1698 layout->AddView(lock_button_);
1517 } 1699 }
1518 return view; 1700 return view;
1519 } 1701 }
1520 1702
1521 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() { 1703 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() {
1522 views::View* view = new views::View(); 1704 views::View* view = new views::View();
1523 views::GridLayout* layout = CreateSingleColumnLayout( 1705 views::GridLayout* layout = CreateSingleColumnLayout(
1524 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); 1706 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew);
1525 layout->SetInsets(views::kRelatedControlVerticalSpacing, 1707 if (switches::IsMaterialDesignUserMenu()) {
1526 views::kButtonHEdgeMarginNew, 1708 layout->SetInsets(0, views::kMaterialHorizontalMargin,
Roger Tawa OOO till Jul 10th 2016/06/07 14:20:48 Nit: put views::kMaterialHorizontalMargin on next
Jane 2016/06/07 17:32:44 Done.
1527 views::kRelatedControlVerticalSpacing, 1709 views::kMaterialVerticalMargin,
1528 views::kButtonHEdgeMarginNew); 1710 views::kMaterialHorizontalMargin);
1711 } else {
1712 layout->SetInsets(views::kRelatedControlVerticalSpacing,
1713 views::kButtonHEdgeMarginNew,
1714 views::kRelatedControlVerticalSpacing,
1715 views::kButtonHEdgeMarginNew);
1716 }
1717
1529 views::Label* disclaimer = new views::Label( 1718 views::Label* disclaimer = new views::Label(
1530 avatar_menu_->GetSupervisedUserInformation()); 1719 avatar_menu_->GetSupervisedUserInformation());
1531 disclaimer->SetMultiLine(true); 1720 disclaimer->SetMultiLine(true);
1532 disclaimer->SetAllowCharacterBreak(true); 1721 disclaimer->SetAllowCharacterBreak(true);
1533 disclaimer->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1722 disclaimer->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1534 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1723 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1535 disclaimer->SetFontList(rb->GetFontList(ui::ResourceBundle::SmallFont)); 1724 disclaimer->SetFontList(rb->GetFontList(ui::ResourceBundle::SmallFont));
1536 layout->StartRow(1, 0); 1725 layout->StartRow(1, 0);
1537 layout->AddView(disclaimer); 1726 layout->AddView(disclaimer);
1538 1727
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2057 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1869 IncognitoModePrefs::DISABLED; 2058 IncognitoModePrefs::DISABLED;
1870 return incognito_available && !browser_->profile()->IsGuestSession(); 2059 return incognito_available && !browser_->profile()->IsGuestSession();
1871 } 2060 }
1872 2061
1873 void ProfileChooserView::PostActionPerformed( 2062 void ProfileChooserView::PostActionPerformed(
1874 ProfileMetrics::ProfileDesktopMenu action_performed) { 2063 ProfileMetrics::ProfileDesktopMenu action_performed) {
1875 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 2064 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1876 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 2065 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1877 } 2066 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/profiles/profile_chooser_view.h ('k') | ui/views/layout/layout_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698