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

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: Clean up layout (and rebased) 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
« no previous file with comments | « chrome/browser/ui/views/profiles/profile_chooser_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
87 const int kButtonHeight = 32; 86 const int kButtonHeight = 32;
88 const int kPasswordCombinedFixedGaiaViewWidth = 360; 87 const int kPasswordCombinedFixedGaiaViewWidth = 360;
89 const int kFixedGaiaViewWidth = 448; 88 const int kFixedGaiaViewWidth = 448;
90 const int kFixedAccountRemovalViewWidth = 280; 89 const int kFixedAccountRemovalViewWidth = 280;
91 const int kFixedSwitchUserViewWidth = 320; 90 const int kFixedSwitchUserViewWidth = 320;
92 const int kLargeImageSide = 88; 91 const int kLargeImageSide = 88;
92 const int kMediumImageSide = 40;
Evan Stade 2016/06/20 17:51:11 if this is going to be the only image size, I'd na
Jane 2016/06/20 18:53:26 Done.
93
94 // Vertical spacing between the edge of the material design user menu and the
95 // top or bottom of the menu items.
96 const int kMaterialMenuVerticalEdgeMargin = 16;
97 // Horizontal spacing between the edge of the material design user menu and the
98 // left or right of the menu items.
99 const int kMaterialMenuHorizontalEdgeMargin = 16;
Evan Stade 2016/06/20 17:51:11 nit: I'd combine these constants
Jane 2016/06/20 18:53:26 Done.
93 100
94 const int kVerticalSpacing = 16; 101 const int kVerticalSpacing = 16;
95 102
96 const int kTitleViewNativeWidgetOffset = 8; 103 const int kTitleViewNativeWidgetOffset = 8;
97 104
98 bool IsProfileChooser(profiles::BubbleViewMode mode) { 105 bool IsProfileChooser(profiles::BubbleViewMode mode) {
99 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || 106 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ||
100 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; 107 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
101 } 108 }
102 109
110 int GetProfileBadgeSize() {
111 return switches::IsMaterialDesignUserMenu() ? 24 : 30;
112 }
113
114 // DEPRECATED: New user menu components should use views::BoxLayout instead.
103 // Creates a GridLayout with a single column. This ensures that all the child 115 // Creates a GridLayout with a single column. This ensures that all the child
104 // views added get auto-expanded to fill the full width of the bubble. 116 // views added get auto-expanded to fill the full width of the bubble.
105 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { 117 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) {
106 views::GridLayout* layout = new views::GridLayout(view); 118 views::GridLayout* layout = new views::GridLayout(view);
107 view->SetLayoutManager(layout); 119 view->SetLayoutManager(layout);
108 120
109 views::ColumnSet* columns = layout->AddColumnSet(0); 121 views::ColumnSet* columns = layout->AddColumnSet(0);
110 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, 122 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
111 views::GridLayout::FIXED, width, width); 123 views::GridLayout::FIXED, width, width);
112 return layout; 124 return layout;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 gfx::Rect bounds(title_view_->GetPreferredSize()); 268 gfx::Rect bounds(title_view_->GetPreferredSize());
257 title_view_->SetBoundsRect(bounds); 269 title_view_->SetBoundsRect(bounds);
258 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset); 270 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset);
259 title_widget_->SetBounds(bounds); 271 title_widget_->SetBounds(bounds);
260 } 272 }
261 273
262 } // namespace 274 } // namespace
263 275
264 // RightAlignedIconLabelButton ------------------------------------------------- 276 // RightAlignedIconLabelButton -------------------------------------------------
265 277
266 // A custom LabelButton that has a centered text and right aligned icon. 278 // A custom LabelButton that has a left-aligned text and right aligned icon.
279 // For non-material-design user menu, it has centered text instead.
267 class RightAlignedIconLabelButton : public views::LabelButton { 280 class RightAlignedIconLabelButton : public views::LabelButton {
268 public: 281 public:
269 RightAlignedIconLabelButton(views::ButtonListener* listener, 282 RightAlignedIconLabelButton(views::ButtonListener* listener,
270 const base::string16& text) 283 const base::string16& text)
271 : views::LabelButton(listener, text) { 284 : views::LabelButton(listener, text) {
272 SetHorizontalAlignment(gfx::ALIGN_RIGHT); 285 SetHorizontalAlignment(gfx::ALIGN_RIGHT);
273 label()->SetHorizontalAlignment(gfx::ALIGN_CENTER); 286 label()->SetHorizontalAlignment(switches::IsMaterialDesignUserMenu()
287 ? gfx::ALIGN_LEFT
288 : gfx::ALIGN_CENTER);
274 } 289 }
275 290
276 protected: 291 protected:
277 void Layout() override { 292 void Layout() override {
278 views::LabelButton::Layout(); 293 views::LabelButton::Layout();
279 294
280 // Keep the text centered and the icon right-aligned by stretching the label 295 // 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. 296 // to take up more of the content area and centering its contents.
282 gfx::Rect content_bounds = GetContentsBounds(); 297 gfx::Rect content_bounds = GetContentsBounds();
283 gfx::Rect label_bounds = label()->bounds(); 298 gfx::Rect label_bounds = label()->bounds();
(...skipping 13 matching lines...) Expand all
297 DISALLOW_COPY_AND_ASSIGN(RightAlignedIconLabelButton); 312 DISALLOW_COPY_AND_ASSIGN(RightAlignedIconLabelButton);
298 }; 313 };
299 314
300 // EditableProfilePhoto ------------------------------------------------- 315 // EditableProfilePhoto -------------------------------------------------
301 316
302 // A custom Image control that shows a "change" button when moused over. 317 // A custom Image control that shows a "change" button when moused over.
303 class EditableProfilePhoto : public views::LabelButton { 318 class EditableProfilePhoto : public views::LabelButton {
304 public: 319 public:
305 EditableProfilePhoto(views::ButtonListener* listener, 320 EditableProfilePhoto(views::ButtonListener* listener,
306 const gfx::Image& icon, 321 const gfx::Image& icon,
307 bool is_editing_allowed, 322 bool is_editing_allowed)
308 const gfx::Rect& bounds) 323 : views::LabelButton(listener, base::string16()), photo_overlay_(NULL) {
Evan Stade 2016/06/20 17:51:11 s/NULL/nullptr
Jane 2016/06/20 18:53:26 Done.
309 : views::LabelButton(listener, base::string16()), 324 const int icon_image_side = switches::IsMaterialDesignUserMenu()
310 photo_overlay_(NULL) { 325 ? kMediumImageSide
311 gfx::Image image = profiles::GetSizedAvatarIcon( 326 : kLargeImageSide;
312 icon, true, kLargeImageSide, kLargeImageSide); 327 gfx::Image image = profiles::GetSizedAvatarIcon(icon, true, icon_image_side,
328 icon_image_side);
313 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); 329 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia());
314 SetBorder(views::Border::NullBorder()); 330 SetBorder(views::Border::NullBorder());
315 SetBoundsRect(bounds); 331 SetSize(GetPreferredSize());
316 332
317 // Calculate the circular mask that will be used to display the photo. 333 // Calculate the circular mask that will be used to display the photo.
318 circular_mask_.addCircle(SkIntToScalar(bounds.width() / 2), 334 circular_mask_.addCircle(SkIntToScalar(icon_image_side / 2),
319 SkIntToScalar(bounds.height() / 2), 335 SkIntToScalar(icon_image_side / 2),
320 SkIntToScalar(bounds.width() / 2)); 336 SkIntToScalar(icon_image_side / 2));
321 337
322 if (!is_editing_allowed) { 338 if (!is_editing_allowed) {
323 SetEnabled(false); 339 SetEnabled(false);
324 return; 340 return;
325 } 341 }
326 342
327 set_notify_enter_exit_on_child(true); 343 set_notify_enter_exit_on_child(true);
328 344
329 // Photo overlay that appears when hovering over the button. 345 // Photo overlay that appears when hovering over the button.
330 photo_overlay_ = new views::ImageView(); 346 photo_overlay_ = new views::ImageView();
331 347
332 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); 348 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255);
333 photo_overlay_->set_background( 349 photo_overlay_->set_background(
334 views::Background::CreateSolidBackground(kBackgroundColor)); 350 views::Background::CreateSolidBackground(kBackgroundColor));
335 photo_overlay_->SetImage(gfx::CreateVectorIcon( 351 photo_overlay_->SetImage(
336 gfx::VectorIconId::PHOTO_CAMERA, 48u, SkColorSetRGB(0x33, 0x33, 0x33))); 352 gfx::CreateVectorIcon(gfx::VectorIconId::PHOTO_CAMERA,
353 switches::IsMaterialDesignUserMenu() ? 22u : 48u,
354 SkColorSetRGB(0x33, 0x33, 0x33)));
337 355
338 photo_overlay_->SetSize(bounds.size()); 356 photo_overlay_->SetSize(gfx::Size(icon_image_side, icon_image_side));
339 photo_overlay_->SetVisible(false); 357 photo_overlay_->SetVisible(false);
340 AddChildView(photo_overlay_); 358 AddChildView(photo_overlay_);
341 } 359 }
342 360
343 void OnPaint(gfx::Canvas* canvas) override { 361 void OnPaint(gfx::Canvas* canvas) override {
344 // Display the profile picture as a circle. 362 // Display the profile picture as a circle.
345 canvas->ClipPath(circular_mask_, true); 363 canvas->ClipPath(circular_mask_, true);
346 views::LabelButton::OnPaint(canvas); 364 views::LabelButton::OnPaint(canvas);
Evan Stade 2016/06/21 21:55:16 canvas->Save(); // current fn body canvas->Restore
Jane 2016/06/22 15:38:33 Thanks, I see what you are getting at. I'm not sur
Evan Stade 2016/06/22 17:15:43 children are painted after |this| so you'll have t
Jane 2016/06/22 22:02:32 Thanks! I think I implemented what you suggested i
Evan Stade 2016/06/24 18:25:26 yes, views are clipped to their bounds. You have t
Jane 2016/06/27 18:08:56 Not sure if I'm following, but my question is more
347 } 365 }
348 366
349 void PaintChildren(const ui::PaintContext& context) override { 367 void PaintChildren(const ui::PaintContext& context) override {
350 // Display any children (the "change photo" overlay) as a circle. 368 // Display any children (the "change photo" overlay) as a circle.
351 ui::ClipRecorder clip_recorder(context); 369 ui::ClipRecorder clip_recorder(context);
352 clip_recorder.ClipPathWithAntiAliasing(circular_mask_); 370 clip_recorder.ClipPathWithAntiAliasing(circular_mask_);
353 View::PaintChildren(context); 371 View::PaintChildren(context);
354 } 372 }
355 373
356 private: 374 private:
(...skipping 29 matching lines...) Expand all
386 404
387 // EditableProfileName ------------------------------------------------- 405 // EditableProfileName -------------------------------------------------
388 406
389 // A custom text control that turns into a textfield for editing when clicked. 407 // A custom text control that turns into a textfield for editing when clicked.
390 class EditableProfileName : public views::View, 408 class EditableProfileName : public views::View,
391 public views::ButtonListener { 409 public views::ButtonListener {
392 public: 410 public:
393 EditableProfileName(views::TextfieldController* controller, 411 EditableProfileName(views::TextfieldController* controller,
394 const base::string16& text, 412 const base::string16& text,
395 bool is_editing_allowed) 413 bool is_editing_allowed)
396 : button_(nullptr), label_(nullptr), profile_name_textfield_(nullptr) { 414 : button_(nullptr), profile_name_textfield_(nullptr) {
397 SetLayoutManager( 415 SetLayoutManager(
398 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 416 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
399 417
400 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 418 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
401 const gfx::FontList& medium_font_list = 419 const gfx::FontList& medium_font_list =
402 rb->GetFontList(ui::ResourceBundle::MediumFont); 420 rb->GetFontList(ui::ResourceBundle::MediumFont);
403 421
404 if (!is_editing_allowed) { 422 if (!is_editing_allowed) {
405 label_ = new views::Label(text); 423 views::Label* name_label = new views::Label(text);
406 label_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); 424 name_label->SetBorder(
407 label_->SetFontList(medium_font_list); 425 views::Border::CreateEmptyBorder(border_width, 0, border_width, 0));
408 AddChildView(label_); 426 name_label->SetFontList(medium_font_list);
427 if (switches::IsMaterialDesignUserMenu())
428 name_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
429 AddChildView(name_label);
409 return; 430 return;
410 } 431 }
411 432
433 profile_name_textfield_ = new views::Textfield();
434 // Textfield that overlaps the button.
435 profile_name_textfield_->set_controller(controller);
436 profile_name_textfield_->SetFontList(medium_font_list);
437 profile_name_textfield_->SetHorizontalAlignment(
438 switches::IsMaterialDesignUserMenu() ? gfx::ALIGN_LEFT
439 : gfx::ALIGN_CENTER);
440 profile_name_textfield_->SetVisible(false);
441 AddChildView(profile_name_textfield_);
442
412 button_ = new RightAlignedIconLabelButton(this, text); 443 button_ = new RightAlignedIconLabelButton(this, text);
413 button_->SetFontList(medium_font_list); 444 button_->SetFontList(medium_font_list);
414 // Show an "edit" pencil icon when hovering over. In the default state, 445 // 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 446 // 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. 447 // the text doesn't jump around when the hovered icon appears.
417 // TODO(estade): revisit colors and press effect. 448 // TODO(estade): revisit colors and press effect.
418 const int kIconSize = 16; 449 const int kIconSize = 16;
419 button_->SetImage(views::LabelButton::STATE_NORMAL, 450 button_->SetImage(views::LabelButton::STATE_NORMAL,
420 CreateSquarePlaceholderImage(kIconSize)); 451 CreateSquarePlaceholderImage(kIconSize));
421 button_->SetImage(views::LabelButton::STATE_HOVERED, 452 button_->SetImage(views::LabelButton::STATE_HOVERED,
422 gfx::CreateVectorIcon( 453 gfx::CreateVectorIcon(
423 gfx::VectorIconId::MODE_EDIT, kIconSize, 454 gfx::VectorIconId::MODE_EDIT, kIconSize,
424 SkColorSetRGB(0x33, 0x33, 0x33))); 455 SkColorSetRGB(0x33, 0x33, 0x33)));
425 button_->SetImage(views::LabelButton::STATE_PRESSED, 456 button_->SetImage(views::LabelButton::STATE_PRESSED,
426 gfx::CreateVectorIcon( 457 gfx::CreateVectorIcon(
427 gfx::VectorIconId::MODE_EDIT, kIconSize, 458 gfx::VectorIconId::MODE_EDIT, kIconSize,
428 SkColorSetRGB(0x20, 0x20, 0x20))); 459 SkColorSetRGB(0x20, 0x20, 0x20)));
429 // To center the text, we need to offest it by the width of the icon we 460 // 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 461 // to the text to account for the textfield's border.
431 // padding to account for the textfield's border. 462 if (switches::IsMaterialDesignUserMenu()) {
432 const int kIconTextLabelButtonSpacing = 5; 463 button_->SetBorder(views::Border::CreateEmptyBorder(
433 button_->SetBorder(views::Border::CreateEmptyBorder( 464 border_width, profile_name_textfield_->GetInsets().left(),
434 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); 465 border_width, 0));
466 } else {
467 const int kIconTextLabelButtonSpacing = 5;
468 button_->SetBorder(views::Border::CreateEmptyBorder(
469 border_width, kIconSize + kIconTextLabelButtonSpacing, border_width,
470 0));
471 }
435 AddChildView(button_); 472 AddChildView(button_);
436
437 profile_name_textfield_ = new views::Textfield();
438 // Textfield that overlaps the button.
439 profile_name_textfield_->set_controller(controller);
440 profile_name_textfield_->SetFontList(medium_font_list);
441 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
442 profile_name_textfield_->SetVisible(false);
443 AddChildView(profile_name_textfield_);
444 } 473 }
445 474
446 views::Textfield* profile_name_textfield() { 475 views::Textfield* profile_name_textfield() {
447 return profile_name_textfield_; 476 return profile_name_textfield_;
448 } 477 }
449 478
450 // Hide the editable textfield to show the profile name button instead. 479 // Hide the editable textfield to show the profile name button instead.
451 void ShowReadOnlyView() { 480 void ShowReadOnlyView() {
452 button_->SetVisible(true); 481 button_->SetVisible(true);
453 profile_name_textfield_->SetVisible(false); 482 profile_name_textfield_->SetVisible(false);
454 } 483 }
455 484
485 static const int border_width = 2;
Evan Stade 2016/06/20 17:51:11 If you explained this already, I forgot (sorry): l
Jane 2016/06/20 18:53:26 Don't think we went over this, but it's because it
Evan Stade 2016/06/21 21:55:16 Not really, isn't the border 1px rather than 2? If
Jane 2016/06/22 15:38:33 Done. I thought the original code had a purpose...
486
456 private: 487 private:
457 // views::ButtonListener: 488 // views::ButtonListener:
458 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 489 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
459 button_->SetVisible(false); 490 button_->SetVisible(false);
460 profile_name_textfield_->SetVisible(true); 491 profile_name_textfield_->SetVisible(true);
461 profile_name_textfield_->SetText(button_->GetText()); 492 profile_name_textfield_->SetText(button_->GetText());
462 profile_name_textfield_->SelectAll(false); 493 profile_name_textfield_->SelectAll(false);
463 profile_name_textfield_->RequestFocus(); 494 profile_name_textfield_->RequestFocus();
464 // Re-layouts the view after swaping the controls. 495 // Re-layouts the view after swaping the controls.
465 Layout(); 496 Layout();
466 } 497 }
467 498
468 // views::LabelButton: 499 // views::LabelButton:
469 bool OnKeyReleased(const ui::KeyEvent& event) override { 500 bool OnKeyReleased(const ui::KeyEvent& event) override {
470 // Override CustomButton's implementation, which presses the button when 501 // Override CustomButton's implementation, which presses the button when
471 // you press space and clicks it when you release space, as the space can be 502 // you press space and clicks it when you release space, as the space can be
472 // part of the new profile name typed in the textfield. 503 // part of the new profile name typed in the textfield.
473 return false; 504 return false;
474 } 505 }
475 506
476 // The label button which shows the profile name, and can handle the event to 507 // The label button which shows the profile name, and can handle the event to
477 // make it editable. Can be NULL if the profile name isn't allowed to be 508 // make it editable. Can be NULL if the profile name isn't allowed to be
478 // edited. 509 // edited.
479 RightAlignedIconLabelButton* button_; 510 RightAlignedIconLabelButton* button_;
480 511
481 // The label which shows when the profile name cannot be edited (e.g. for
482 // supervised user). Can be NULL if the profile name is allowed to be edited.
483 views::Label* label_;
484
485 // Textfield that is shown when editing the profile name. Can be NULL if 512 // Textfield that is shown when editing the profile name. Can be NULL if
486 // the profile name isn't allowed to be edited (e.g. for guest profiles). 513 // the profile name isn't allowed to be edited (e.g. for guest profiles).
487 views::Textfield* profile_name_textfield_; 514 views::Textfield* profile_name_textfield_;
488 515
489 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); 516 DISALLOW_COPY_AND_ASSIGN(EditableProfileName);
490 }; 517 };
491 518
492 // A title card with one back button right aligned and one label center aligned. 519 // A title card with one back button right aligned and one label center aligned.
493 class TitleCard : public views::View { 520 class TitleCard : public views::View {
494 public: 521 public:
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 } 584 }
558 585
559 views::ImageButton* back_button_; 586 views::ImageButton* back_button_;
560 views::Label* title_label_; 587 views::Label* title_label_;
561 588
562 DISALLOW_COPY_AND_ASSIGN(TitleCard); 589 DISALLOW_COPY_AND_ASSIGN(TitleCard);
563 }; 590 };
564 591
565 // ProfileBadge -------------------------------------------------------- 592 // ProfileBadge --------------------------------------------------------
566 593
567 const size_t kProfileBadgeSize = 30;
568 const size_t kProfileBadgeWhitePadding = 2; 594 const size_t kProfileBadgeWhitePadding = 2;
569 595
570 // Draws a white circle, then a light blue circle, then a dark blue icon. 596 // Draws a white circle, then a light blue circle, then a dark blue icon.
571 class ProfileBadge : public gfx::CanvasImageSource { 597 class ProfileBadge : public gfx::CanvasImageSource {
572 public: 598 public:
573 ProfileBadge(gfx::VectorIconId id, size_t icon_size) 599 ProfileBadge(gfx::VectorIconId id, size_t icon_size)
574 : CanvasImageSource(gfx::Size(kProfileBadgeSize, kProfileBadgeSize), 600 : CanvasImageSource(
575 false), 601 gfx::Size(GetProfileBadgeSize(), GetProfileBadgeSize()),
602 false),
576 id_(id), 603 id_(id),
577 icon_size_(icon_size) {} 604 icon_size_(icon_size) {}
578 605
579 ~ProfileBadge() override {} 606 ~ProfileBadge() override {}
580 607
581 // CanvasImageSource: 608 // CanvasImageSource:
582 void Draw(gfx::Canvas* canvas) override { 609 void Draw(gfx::Canvas* canvas) override {
583 const SkISize size = canvas->sk_canvas()->getBaseLayerSize(); 610 const SkISize size = canvas->sk_canvas()->getBaseLayerSize();
584 gfx::Rect bounds(0, 0, size.width(), size.height()); 611 gfx::Rect bounds(0, 0, size.width(), size.height());
585 612
586 SkPaint paint; 613 SkPaint paint;
587 paint.setAntiAlias(true); 614 paint.setAntiAlias(true);
588 paint.setColor(SK_ColorWHITE); 615 paint.setColor(SK_ColorWHITE);
589 canvas->DrawCircle(bounds.CenterPoint(), size.width() / 2, paint); 616 canvas->DrawCircle(bounds.CenterPoint(), size.width() / 2, paint);
590 617
591 paint.setColor(SkColorSetRGB(0xAF, 0xD9, 0xFC)); 618 paint.setColor(SkColorSetRGB(0xAF, 0xD9, 0xFC));
592 canvas->DrawCircle(bounds.CenterPoint(), 619 canvas->DrawCircle(bounds.CenterPoint(),
593 size.width() / 2 - kProfileBadgeWhitePadding, paint); 620 size.width() / 2 - kProfileBadgeWhitePadding, paint);
594 621
595 int offset = (kProfileBadgeSize - icon_size_) / 2; 622 int offset = (GetProfileBadgeSize() - icon_size_) / 2;
596 canvas->Translate(gfx::Vector2d(offset, offset)); 623 canvas->Translate(gfx::Vector2d(offset, offset));
597 gfx::PaintVectorIcon(canvas, id_, icon_size_, SkColorSetRGB(0, 0x66, 0xff)); 624 gfx::PaintVectorIcon(canvas, id_, icon_size_, SkColorSetRGB(0, 0x66, 0xff));
598 } 625 }
599 626
600 private: 627 private:
601 const gfx::VectorIconId id_; 628 const gfx::VectorIconId id_;
602 const size_t icon_size_; 629 const size_t icon_size_;
603 630
604 DISALLOW_COPY_AND_ASSIGN(ProfileBadge); 631 DISALLOW_COPY_AND_ASSIGN(ProfileBadge);
605 }; 632 };
606 633
607 gfx::ImageSkia CreateBadgeForProfile(Profile* profile) { 634 gfx::ImageSkia CreateBadgeForProfile(Profile* profile) {
608 ProfileBadge* badge = 635 ProfileBadge* badge =
609 profile->IsChild() 636 profile->IsChild()
610 ? new ProfileBadge(gfx::VectorIconId::ACCOUNT_CHILD_INVERT, 26) 637 ? new ProfileBadge(gfx::VectorIconId::ACCOUNT_CHILD_INVERT,
611 : new ProfileBadge(gfx::VectorIconId::SUPERVISOR_ACCOUNT, 20); 638 switches::IsMaterialDesignUserMenu() ? 21 : 26)
612 639 : new ProfileBadge(gfx::VectorIconId::SUPERVISOR_ACCOUNT,
640 switches::IsMaterialDesignUserMenu() ? 16 : 20);
613 return gfx::ImageSkia(badge, badge->size()); 641 return gfx::ImageSkia(badge, badge->size());
614 } 642 }
615 643
616 // ProfileChooserView --------------------------------------------------------- 644 // ProfileChooserView ---------------------------------------------------------
617 645
618 // static 646 // static
619 ProfileChooserView* ProfileChooserView::profile_bubble_ = nullptr; 647 ProfileChooserView* ProfileChooserView::profile_bubble_ = nullptr;
620 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; 648 bool ProfileChooserView::close_on_deactivate_for_testing_ = true;
621 649
622 // static 650 // static
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 bool ProfileChooserView::IsShowing() { 685 bool ProfileChooserView::IsShowing() {
658 return profile_bubble_ != NULL; 686 return profile_bubble_ != NULL;
659 } 687 }
660 688
661 // static 689 // static
662 void ProfileChooserView::Hide() { 690 void ProfileChooserView::Hide() {
663 if (IsShowing()) 691 if (IsShowing())
664 profile_bubble_->GetWidget()->Close(); 692 profile_bubble_->GetWidget()->Close();
665 } 693 }
666 694
695 // static
696 int ProfileChooserView::GetFixedMenuWidth() {
697 return switches::IsMaterialDesignUserMenu() ? 240 : 250;
698 }
699
667 ProfileChooserView::ProfileChooserView(views::View* anchor_view, 700 ProfileChooserView::ProfileChooserView(views::View* anchor_view,
668 Browser* browser, 701 Browser* browser,
669 profiles::BubbleViewMode view_mode, 702 profiles::BubbleViewMode view_mode,
670 profiles::TutorialMode tutorial_mode, 703 profiles::TutorialMode tutorial_mode,
671 signin::GAIAServiceType service_type, 704 signin::GAIAServiceType service_type,
672 signin_metrics::AccessPoint access_point) 705 signin_metrics::AccessPoint access_point)
673 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 706 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
674 browser_(browser), 707 browser_(browser),
675 view_mode_(view_mode), 708 view_mode_(view_mode),
676 tutorial_mode_(tutorial_mode), 709 tutorial_mode_(tutorial_mode),
(...skipping 10 matching lines...) Expand all
687 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); 720 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile());
688 if (oauth2_token_service) 721 if (oauth2_token_service)
689 oauth2_token_service->RemoveObserver(this); 722 oauth2_token_service->RemoveObserver(this);
690 } 723 }
691 724
692 void ProfileChooserView::ResetView() { 725 void ProfileChooserView::ResetView() {
693 open_other_profile_indexes_map_.clear(); 726 open_other_profile_indexes_map_.clear();
694 delete_account_button_map_.clear(); 727 delete_account_button_map_.clear();
695 reauth_account_button_map_.clear(); 728 reauth_account_button_map_.clear();
696 manage_accounts_link_ = NULL; 729 manage_accounts_link_ = NULL;
697 signin_current_profile_link_ = NULL; 730 signin_current_profile_button_ = NULL;
698 auth_error_email_button_ = NULL; 731 auth_error_email_button_ = NULL;
699 current_profile_photo_ = NULL; 732 current_profile_photo_ = NULL;
700 current_profile_name_ = NULL; 733 current_profile_name_ = NULL;
701 users_button_ = NULL; 734 users_button_ = NULL;
702 go_incognito_button_ = NULL; 735 go_incognito_button_ = NULL;
703 lock_button_ = NULL; 736 lock_button_ = NULL;
704 add_account_link_ = NULL; 737 add_account_link_ = NULL;
705 gaia_signin_cancel_button_ = NULL; 738 gaia_signin_cancel_button_ = NULL;
706 remove_account_button_ = NULL; 739 remove_account_button_ = NULL;
707 account_removal_cancel_button_ = NULL; 740 account_removal_cancel_button_ = NULL;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 break; 865 break;
833 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: 866 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER:
834 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); 867 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth);
835 sub_view = CreateSwitchUserView(); 868 sub_view = CreateSwitchUserView();
836 ProfileMetrics::LogProfileNewAvatarMenuNotYou( 869 ProfileMetrics::LogProfileNewAvatarMenuNotYou(
837 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW); 870 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW);
838 break; 871 break;
839 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: 872 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT:
840 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER: 873 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER:
841 case profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER: 874 case profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER:
842 layout = CreateSingleColumnLayout(this, kFixedMenuWidth); 875 layout = CreateSingleColumnLayout(this, GetFixedMenuWidth());
843 sub_view = CreateProfileChooserView(avatar_menu); 876 sub_view = CreateProfileChooserView(avatar_menu);
844 break; 877 break;
845 } 878 }
846 // Clears tutorial mode for all non-profile-chooser views. 879 // Clears tutorial mode for all non-profile-chooser views.
847 if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) 880 if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER)
848 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; 881 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE;
849 882
850 layout->StartRow(1, 0); 883 layout->StartRow(1, 0);
851 layout->AddView(sub_view); 884 layout->AddView(sub_view);
852 Layout(); 885 Layout();
(...skipping 26 matching lines...) Expand all
879 if (accelerator.key_code() != ui::VKEY_DOWN && 912 if (accelerator.key_code() != ui::VKEY_DOWN &&
880 accelerator.key_code() != ui::VKEY_UP) 913 accelerator.key_code() != ui::VKEY_UP)
881 return BubbleDialogDelegateView::AcceleratorPressed(accelerator); 914 return BubbleDialogDelegateView::AcceleratorPressed(accelerator);
882 915
883 // Move the focus up or down. 916 // Move the focus up or down.
884 GetFocusManager()->AdvanceFocus(accelerator.key_code() != ui::VKEY_DOWN); 917 GetFocusManager()->AdvanceFocus(accelerator.key_code() != ui::VKEY_DOWN);
885 return true; 918 return true;
886 } 919 }
887 920
888 views::View* ProfileChooserView::GetInitiallyFocusedView() { 921 views::View* ProfileChooserView::GetInitiallyFocusedView() {
889 return signin_current_profile_link_; 922 return signin_current_profile_button_;
890 } 923 }
891 924
892 int ProfileChooserView::GetDialogButtons() const { 925 int ProfileChooserView::GetDialogButtons() const {
893 return ui::DIALOG_BUTTON_NONE; 926 return ui::DIALOG_BUTTON_NONE;
894 } 927 }
895 928
896 bool ProfileChooserView::HandleContextMenu( 929 bool ProfileChooserView::HandleContextMenu(
897 const content::ContextMenuParams& params) { 930 const content::ContextMenuParams& params) {
898 // Suppresses the context menu because some features, such as inspecting 931 // Suppresses the context menu because some features, such as inspecting
899 // elements, are not appropriate in a bubble. 932 // elements, are not appropriate in a bubble.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 bool account_management_available = 981 bool account_management_available =
949 SigninManagerFactory::GetForProfile(browser_->profile())-> 982 SigninManagerFactory::GetForProfile(browser_->profile())->
950 IsAuthenticated() && 983 IsAuthenticated() &&
951 switches::IsEnableAccountConsistency(); 984 switches::IsEnableAccountConsistency();
952 ShowViewFromMode(account_management_available ? 985 ShowViewFromMode(account_management_available ?
953 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : 986 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT :
954 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); 987 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER);
955 } else if (sender == current_profile_photo_) { 988 } else if (sender == current_profile_photo_) {
956 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); 989 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex());
957 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); 990 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE);
958 } else if (sender == signin_current_profile_link_) { 991 } else if (sender == signin_current_profile_button_) {
959 ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN); 992 ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN);
960 } else if (sender == add_person_button_) { 993 } else if (sender == add_person_button_) {
961 ProfileMetrics::LogProfileNewAvatarMenuNotYou( 994 ProfileMetrics::LogProfileNewAvatarMenuNotYou(
962 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON); 995 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON);
963 UserManager::Show(base::FilePath(), 996 UserManager::Show(base::FilePath(),
964 profiles::USER_MANAGER_NO_TUTORIAL, 997 profiles::USER_MANAGER_NO_TUTORIAL,
965 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 998 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
966 } else if (sender == disconnect_button_) { 999 } else if (sender == disconnect_button_) {
967 ProfileMetrics::LogProfileNewAvatarMenuNotYou( 1000 ProfileMetrics::LogProfileNewAvatarMenuNotYou(
968 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT); 1001 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 Indexes other_profiles; 1118 Indexes other_profiles;
1086 views::View* tutorial_view = NULL; 1119 views::View* tutorial_view = NULL;
1087 views::View* current_profile_view = NULL; 1120 views::View* current_profile_view = NULL;
1088 views::View* current_profile_accounts = NULL; 1121 views::View* current_profile_accounts = NULL;
1089 views::View* option_buttons_view = NULL; 1122 views::View* option_buttons_view = NULL;
1090 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { 1123 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
1091 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); 1124 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
1092 if (item.active) { 1125 if (item.active) {
1093 option_buttons_view = CreateOptionsView( 1126 option_buttons_view = CreateOptionsView(
1094 item.signed_in && profiles::IsLockAvailable(browser_->profile())); 1127 item.signed_in && profiles::IsLockAvailable(browser_->profile()));
1095 current_profile_view = CreateCurrentProfileView(item, false); 1128 current_profile_view =
1129 switches::IsMaterialDesignUserMenu()
1130 ? CreateMaterialDesignCurrentProfileView(item, false)
1131 : CreateCurrentProfileView(item, false);
1096 if (IsProfileChooser(view_mode_)) { 1132 if (IsProfileChooser(view_mode_)) {
1097 tutorial_view = CreateTutorialViewIfNeeded(item); 1133 tutorial_view = CreateTutorialViewIfNeeded(item);
1098 } else { 1134 } else {
1099 current_profile_accounts = CreateCurrentProfileAccountsView(item); 1135 current_profile_accounts = CreateCurrentProfileAccountsView(item);
1100 } 1136 }
1101 } else { 1137 } else {
1102 other_profiles.push_back(i); 1138 other_profiles.push_back(i);
1103 } 1139 }
1104 } 1140 }
1105 1141
(...skipping 16 matching lines...) Expand all
1122 1158
1123 if (!IsProfileChooser(view_mode_)) { 1159 if (!IsProfileChooser(view_mode_)) {
1124 DCHECK(current_profile_accounts); 1160 DCHECK(current_profile_accounts);
1125 layout->StartRow(0, 0); 1161 layout->StartRow(0, 0);
1126 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1162 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1127 layout->StartRow(1, 0); 1163 layout->StartRow(1, 0);
1128 layout->AddView(current_profile_accounts); 1164 layout->AddView(current_profile_accounts);
1129 } 1165 }
1130 1166
1131 if (browser_->profile()->IsSupervised()) { 1167 if (browser_->profile()->IsSupervised()) {
1132 layout->StartRow(0, 0); 1168 if (!switches::IsMaterialDesignUserMenu()) {
1133 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1169 layout->StartRow(0, 0);
1170 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1171 }
1134 layout->StartRow(1, 0); 1172 layout->StartRow(1, 0);
1135 layout->AddView(CreateSupervisedUserDisclaimerView()); 1173 layout->AddView(CreateSupervisedUserDisclaimerView());
1136 } 1174 }
1137 1175
1138 layout->StartRow(0, 0); 1176 layout->StartRow(0, 0);
1139 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1177 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1140 1178
1141 if (option_buttons_view) { 1179 if (option_buttons_view) {
1142 layout->StartRow(0, 0); 1180 layout->StartRow(0, 0);
1143 layout->AddView(option_buttons_view); 1181 layout->AddView(option_buttons_view);
(...skipping 11 matching lines...) Expand all
1155 } 1193 }
1156 } 1194 }
1157 1195
1158 layout->StartRow(1, 0); 1196 layout->StartRow(1, 0);
1159 layout->AddView(CreateOtherProfilesView(other_profiles)); 1197 layout->AddView(CreateOtherProfilesView(other_profiles));
1160 } 1198 }
1161 1199
1162 views::View* ProfileChooserView::CreateProfileChooserView( 1200 views::View* ProfileChooserView::CreateProfileChooserView(
1163 AvatarMenu* avatar_menu) { 1201 AvatarMenu* avatar_menu) {
1164 views::View* view = new views::View(); 1202 views::View* view = new views::View();
1165 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 1203 views::GridLayout* layout =
1204 CreateSingleColumnLayout(view, GetFixedMenuWidth());
1166 1205
1167 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) { 1206 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) {
1168 PopulateMinimalProfileChooserView(layout, avatar_menu); 1207 PopulateMinimalProfileChooserView(layout, avatar_menu);
1169 // The user is using right-click switching, no need to tell them about it. 1208 // The user is using right-click switching, no need to tell them about it.
1170 PrefService* local_state = g_browser_process->local_state(); 1209 PrefService* local_state = g_browser_process->local_state();
1171 local_state->SetBoolean( 1210 local_state->SetBoolean(
1172 prefs::kProfileAvatarRightClickTutorialDismissed, true); 1211 prefs::kProfileAvatarRightClickTutorialDismissed, true);
1173 } else { 1212 } else {
1174 PopulateCompleteProfileChooserView(layout, avatar_menu); 1213 PopulateCompleteProfileChooserView(layout, avatar_menu);
1175 } 1214 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 const base::string16& button_text, 1269 const base::string16& button_text,
1231 bool stack_button, 1270 bool stack_button,
1232 views::Link** link, 1271 views::Link** link,
1233 views::LabelButton** button, 1272 views::LabelButton** button,
1234 views::ImageButton** close_button) { 1273 views::ImageButton** close_button) {
1235 tutorial_mode_ = tutorial_mode; 1274 tutorial_mode_ = tutorial_mode;
1236 1275
1237 views::View* view = new views::View(); 1276 views::View* view = new views::View();
1238 view->set_background(views::Background::CreateSolidBackground( 1277 view->set_background(views::Background::CreateSolidBackground(
1239 profiles::kAvatarTutorialBackgroundColor)); 1278 profiles::kAvatarTutorialBackgroundColor));
1240 views::GridLayout* layout = CreateSingleColumnLayout(view, 1279 views::GridLayout* layout = CreateSingleColumnLayout(
1241 kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); 1280 view, GetFixedMenuWidth() - 2 * views::kButtonHEdgeMarginNew);
1242 // Creates a second column set for buttons and links. 1281 // Creates a second column set for buttons and links.
1243 views::ColumnSet* button_columns = layout->AddColumnSet(1); 1282 views::ColumnSet* button_columns = layout->AddColumnSet(1);
1244 button_columns->AddColumn(views::GridLayout::LEADING, 1283 button_columns->AddColumn(views::GridLayout::LEADING,
1245 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); 1284 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0);
1246 button_columns->AddPaddingColumn( 1285 button_columns->AddPaddingColumn(
1247 1, views::kUnrelatedControlHorizontalSpacing); 1286 1, views::kUnrelatedControlHorizontalSpacing);
1248 button_columns->AddColumn(views::GridLayout::TRAILING, 1287 button_columns->AddColumn(views::GridLayout::TRAILING,
1249 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); 1288 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0);
1250 layout->SetInsets(views::kButtonVEdgeMarginNew, 1289 layout->SetInsets(views::kButtonVEdgeMarginNew,
1251 views::kButtonHEdgeMarginNew, 1290 views::kButtonHEdgeMarginNew,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 layout->SkipColumns(1); 1372 layout->SkipColumns(1);
1334 } 1373 }
1335 1374
1336 return view; 1375 return view;
1337 } 1376 }
1338 1377
1339 views::View* ProfileChooserView::CreateCurrentProfileView( 1378 views::View* ProfileChooserView::CreateCurrentProfileView(
1340 const AvatarMenu::Item& avatar_item, 1379 const AvatarMenu::Item& avatar_item,
1341 bool is_guest) { 1380 bool is_guest) {
1342 views::View* view = new views::View(); 1381 views::View* view = new views::View();
1343 int column_width = kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew; 1382 int column_width = GetFixedMenuWidth() - 2 * views::kButtonHEdgeMarginNew;
1344 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); 1383 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width);
1345 layout->SetInsets(views::kButtonVEdgeMarginNew, 1384 layout->SetInsets(views::kButtonVEdgeMarginNew,
1346 views::kButtonHEdgeMarginNew, 1385 views::kButtonHEdgeMarginNew,
1347 views::kUnrelatedControlVerticalSpacing, 1386 views::kUnrelatedControlVerticalSpacing,
1348 views::kButtonHEdgeMarginNew); 1387 views::kButtonHEdgeMarginNew);
1349 1388
1350 // Profile icon, centered. 1389 // Profile icon, centered.
1351 int x_offset = (column_width - kLargeImageSide) / 2; 1390 int x_offset = (column_width - kLargeImageSide) / 2;
1352 current_profile_photo_ = new EditableProfilePhoto( 1391 current_profile_photo_ =
1353 this, avatar_item.icon, !is_guest, 1392 new EditableProfilePhoto(this, avatar_item.icon, !is_guest);
1354 gfx::Rect(x_offset, 0, kLargeImageSide, kLargeImageSide)); 1393 current_profile_photo_->SetX(x_offset);
1355 SizedContainer* profile_icon_container = 1394 SizedContainer* profile_icon_container =
1356 new SizedContainer(gfx::Size(column_width, kLargeImageSide)); 1395 new SizedContainer(gfx::Size(column_width, kLargeImageSide));
1357 profile_icon_container->AddChildView(current_profile_photo_); 1396 profile_icon_container->AddChildView(current_profile_photo_);
1358 1397
1359 if (browser_->profile()->IsSupervised()) { 1398 if (browser_->profile()->IsSupervised()) {
1360 views::ImageView* supervised_icon = new views::ImageView(); 1399 views::ImageView* supervised_icon = new views::ImageView();
1361 supervised_icon->SetImage(CreateBadgeForProfile(browser_->profile())); 1400 supervised_icon->SetImage(CreateBadgeForProfile(browser_->profile()));
1362 gfx::Size preferred_size = supervised_icon->GetPreferredSize(); 1401 gfx::Size preferred_size = supervised_icon->GetPreferredSize();
1363 gfx::Rect parent_bounds = current_profile_photo_->bounds(); 1402 gfx::Rect parent_bounds = current_profile_photo_->bounds();
1364 supervised_icon->SetBounds( 1403 supervised_icon->SetBounds(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 if (signin_manager->IsSigninAllowed()) { 1470 if (signin_manager->IsSigninAllowed()) {
1432 views::Label* promo = new views::Label( 1471 views::Label* promo = new views::Label(
1433 l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); 1472 l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO));
1434 promo->SetMultiLine(true); 1473 promo->SetMultiLine(true);
1435 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1474 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1436 layout->StartRowWithPadding(1, 0, 0, 1475 layout->StartRowWithPadding(1, 0, 0,
1437 views::kRelatedControlSmallVerticalSpacing); 1476 views::kRelatedControlSmallVerticalSpacing);
1438 layout->StartRow(1, 0); 1477 layout->StartRow(1, 0);
1439 layout->AddView(promo); 1478 layout->AddView(promo);
1440 1479
1441 signin_current_profile_link_ = new views::BlueButton( 1480 signin_current_profile_button_ = new views::BlueButton(
1442 this, l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL, 1481 this, l10n_util::GetStringFUTF16(
1443 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); 1482 IDS_SYNC_START_SYNC_BUTTON_LABEL,
1483 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
1444 layout->StartRowWithPadding(1, 0, 0, 1484 layout->StartRowWithPadding(1, 0, 0,
1445 views::kRelatedControlVerticalSpacing); 1485 views::kRelatedControlVerticalSpacing);
1446 layout->StartRow(1, 0); 1486 layout->StartRow(1, 0);
1447 layout->AddView(signin_current_profile_link_); 1487 layout->AddView(signin_current_profile_button_);
1448 content::RecordAction( 1488 content::RecordAction(
1449 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); 1489 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin"));
1450 } 1490 }
1451 } 1491 }
1452 1492
1453 return view; 1493 return view;
1454 } 1494 }
1455 1495
1496 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView(
1497 const AvatarMenu::Item& avatar_item,
1498 bool is_guest) {
1499 views::View* view = new views::View();
1500 view->SetLayoutManager(new views::BoxLayout(
1501 views::BoxLayout::kVertical, kMaterialMenuHorizontalEdgeMargin,
1502 views::kRelatedControlVerticalSpacing,
1503 views::kRelatedControlVerticalSpacing));
1504
1505 // Profile container for the profile photo and avatar/user name.
1506 views::View* profile_container = new views::View();
1507
1508 // Profile picture, left-aligned.
1509 current_profile_photo_ =
1510 new EditableProfilePhoto(this, avatar_item.icon, !is_guest);
1511 current_profile_photo_->SetY(views::kRelatedControlSmallVerticalSpacing);
1512 gfx::Rect photo_bounds = current_profile_photo_->bounds();
1513 const int badge_spacing = 4;
1514 SizedContainer* profile_photo_container = new SizedContainer(
1515 gfx::Size(current_profile_photo_->width() + badge_spacing,
1516 current_profile_photo_->height() +
1517 2 * views::kRelatedControlSmallVerticalSpacing));
1518 profile_photo_container->AddChildView(current_profile_photo_);
1519
1520 // Add supervised badge for supervised profile.
1521 if (browser_->profile()->IsSupervised()) {
1522 views::ImageView* supervised_icon = new views::ImageView();
1523 supervised_icon->SetImage(CreateBadgeForProfile(browser_->profile()));
1524 gfx::Size preferred_size = supervised_icon->GetPreferredSize();
1525 supervised_icon->SetBounds(
Evan Stade 2016/06/20 17:51:11 seems like supervised_icon should be a child of cu
Jane 2016/06/20 18:53:26 That's a good logical point. However, the current
Evan Stade 2016/06/21 21:55:16 where does it say in the mocks it shouldn't be cli
Jane 2016/06/22 15:38:33 Sorry, let me be more clear about "clickable": I w
1526 photo_bounds.right() - preferred_size.width() + badge_spacing,
1527 photo_bounds.bottom() - preferred_size.height() + badge_spacing,
1528 preferred_size.width(), preferred_size.height());
1529 profile_photo_container->AddChildView(supervised_icon);
1530 }
1531
1532 // Profile name, left-aligned to the right of profile icon.
1533 bool editing_allowed =
1534 !is_guest && !browser_->profile()->IsLegacySupervised();
1535 current_profile_name_ = new EditableProfileName(
1536 this, profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()),
1537 editing_allowed);
1538 views::View* profile_name_container = new views::View();
1539 int name_container_v_spacing = views::kRelatedControlSmallVerticalSpacing;
1540 if (!avatar_item.signed_in) {
1541 name_container_v_spacing += views::kRelatedControlVerticalSpacing;
Evan Stade 2016/06/20 17:51:11 nit: no curly braces
Jane 2016/06/20 18:53:25 Done.
1542 }
1543 profile_name_container->SetLayoutManager(new views::BoxLayout(
1544 views::BoxLayout::kVertical, 0, name_container_v_spacing, 0));
1545 profile_name_container->AddChildView(current_profile_name_);
1546
1547 const int between_child_spacing =
1548 kMaterialMenuHorizontalEdgeMargin - badge_spacing;
1549 profile_container->SetLayoutManager(new views::BoxLayout(
1550 views::BoxLayout::kHorizontal, 0,
1551 views::kRelatedControlSmallVerticalSpacing, between_child_spacing));
1552 profile_container->AddChildView(profile_photo_container);
1553 profile_container->AddChildView(profile_name_container);
1554 view->AddChildView(profile_container);
1555
1556 if (is_guest)
1557 return view;
1558
1559 // The available links depend on the type of profile that is active.
1560 if (avatar_item.signed_in) {
1561 if (switches::IsEnableAccountConsistency()) {
1562 base::string16 link_title = l10n_util::GetStringUTF16(
1563 IsProfileChooser(view_mode_)
1564 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON
1565 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
1566 manage_accounts_link_ = CreateLink(link_title, this);
1567 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1568 profile_name_container->AddChildView(manage_accounts_link_);
1569 } else {
1570 views::Label* email_label = new views::Label(avatar_item.username);
1571 email_label->SetElideBehavior(gfx::ELIDE_EMAIL);
1572 email_label->SetEnabled(false);
1573 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1574 profile_name_container->AddChildView(email_label);
1575 }
1576 return view;
1577 }
1578
1579 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile(
1580 browser_->profile()->GetOriginalProfile());
1581 if (signin_manager->IsSigninAllowed()) {
1582 views::Label* promo =
1583 new views::Label(l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO));
1584 promo->SetMultiLine(true);
1585 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1586 view->AddChildView(promo);
1587
1588 signin_current_profile_button_ =
1589 views::MdTextButton::CreateSecondaryUiBlueButton(
1590 this, l10n_util::GetStringFUTF16(
1591 IDS_SYNC_START_SYNC_BUTTON_LABEL,
1592 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
1593 view->AddChildView(signin_current_profile_button_);
1594 content::RecordAction(
1595 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin"));
1596 view->SetBorder(views::Border::CreateEmptyBorder(
1597 0, 0, views::kRelatedControlVerticalSpacing, 0));
1598 }
1599
1600 return view;
1601 }
1602
1456 views::View* ProfileChooserView::CreateGuestProfileView() { 1603 views::View* ProfileChooserView::CreateGuestProfileView() {
1457 gfx::Image guest_icon = 1604 gfx::Image guest_icon =
1458 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 1605 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
1459 profiles::GetPlaceholderAvatarIconResourceID()); 1606 profiles::GetPlaceholderAvatarIconResourceID());
1460 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); 1607 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon);
1461 guest_avatar_item.active = true; 1608 guest_avatar_item.active = true;
1462 guest_avatar_item.name = l10n_util::GetStringUTF16( 1609 guest_avatar_item.name = l10n_util::GetStringUTF16(
1463 IDS_PROFILES_GUEST_PROFILE_NAME); 1610 IDS_PROFILES_GUEST_PROFILE_NAME);
1464 guest_avatar_item.signed_in = false; 1611 guest_avatar_item.signed_in = false;
1465 1612
1466 return CreateCurrentProfileView(guest_avatar_item, true); 1613 return switches::IsMaterialDesignUserMenu()
1614 ? CreateMaterialDesignCurrentProfileView(guest_avatar_item, true)
1615 : CreateCurrentProfileView(guest_avatar_item, true);
1467 } 1616 }
1468 1617
1469 views::View* ProfileChooserView::CreateOtherProfilesView( 1618 views::View* ProfileChooserView::CreateOtherProfilesView(
1470 const Indexes& avatars_to_show) { 1619 const Indexes& avatars_to_show) {
1471 views::View* view = new views::View(); 1620 views::View* view = new views::View();
1472 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 1621 views::GridLayout* layout =
1622 CreateSingleColumnLayout(view, GetFixedMenuWidth());
1473 1623
1474 for (size_t index : avatars_to_show) { 1624 for (size_t index : avatars_to_show) {
1475 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index); 1625 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index);
1476 const int kSmallImageSide = 32; 1626 const int kSmallImageSide = 32;
1477 1627
1478 // Use the low-res, small default avatars in the fast user switcher, like 1628 // Use the low-res, small default avatars in the fast user switcher, like
1479 // we do in the menu bar. 1629 // we do in the menu bar.
1480 gfx::Image item_icon; 1630 gfx::Image item_icon;
1481 AvatarMenu::GetImageForMenuButton(item.profile_path, &item_icon); 1631 AvatarMenu::GetImageForMenuButton(item.profile_path, &item_icon);
1482 1632
(...skipping 10 matching lines...) Expand all
1493 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1643 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1494 layout->StartRow(1, 0); 1644 layout->StartRow(1, 0);
1495 layout->AddView(button); 1645 layout->AddView(button);
1496 } 1646 }
1497 1647
1498 return view; 1648 return view;
1499 } 1649 }
1500 1650
1501 views::View* ProfileChooserView::CreateOptionsView(bool display_lock) { 1651 views::View* ProfileChooserView::CreateOptionsView(bool display_lock) {
1502 views::View* view = new views::View(); 1652 views::View* view = new views::View();
1503 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 1653 views::GridLayout* layout =
1654 CreateSingleColumnLayout(view, GetFixedMenuWidth());
1504 1655
1505 base::string16 text = browser_->profile()->IsGuestSession() ? 1656 base::string16 text = browser_->profile()->IsGuestSession() ?
1506 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) : 1657 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) :
1507 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON); 1658 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON);
1508 if (!browser_->profile()->IsGuestSession() 1659 if (!browser_->profile()->IsGuestSession()
1509 && switches::IsMaterialDesignUserMenu()) { 1660 && switches::IsMaterialDesignUserMenu()) {
1510 text = l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON); 1661 text = l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON);
1511 } 1662 }
1512 const int kIconSize = 16; 1663 const int kIconSize = 16;
1513 1664
(...skipping 29 matching lines...) Expand all
1543 gfx::kChromeIconGrey)); 1694 gfx::kChromeIconGrey));
1544 layout->StartRow(1, 0); 1695 layout->StartRow(1, 0);
1545 layout->AddView(lock_button_); 1696 layout->AddView(lock_button_);
1546 } 1697 }
1547 return view; 1698 return view;
1548 } 1699 }
1549 1700
1550 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() { 1701 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() {
1551 views::View* view = new views::View(); 1702 views::View* view = new views::View();
1552 views::GridLayout* layout = CreateSingleColumnLayout( 1703 views::GridLayout* layout = CreateSingleColumnLayout(
1553 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); 1704 view, GetFixedMenuWidth() - 2 * views::kButtonHEdgeMarginNew);
1554 layout->SetInsets(views::kRelatedControlVerticalSpacing, 1705 if (switches::IsMaterialDesignUserMenu()) {
1555 views::kButtonHEdgeMarginNew, 1706 layout->SetInsets(0, kMaterialMenuHorizontalEdgeMargin,
1556 views::kRelatedControlVerticalSpacing, 1707 kMaterialMenuVerticalEdgeMargin,
1557 views::kButtonHEdgeMarginNew); 1708 kMaterialMenuHorizontalEdgeMargin);
1709 } else {
1710 layout->SetInsets(
1711 views::kRelatedControlVerticalSpacing, views::kButtonHEdgeMarginNew,
1712 views::kRelatedControlVerticalSpacing, views::kButtonHEdgeMarginNew);
1713 }
1714
1558 views::Label* disclaimer = new views::Label( 1715 views::Label* disclaimer = new views::Label(
1559 avatar_menu_->GetSupervisedUserInformation()); 1716 avatar_menu_->GetSupervisedUserInformation());
1560 disclaimer->SetMultiLine(true); 1717 disclaimer->SetMultiLine(true);
1561 disclaimer->SetAllowCharacterBreak(true); 1718 disclaimer->SetAllowCharacterBreak(true);
1562 disclaimer->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1719 disclaimer->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1563 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1720 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1564 disclaimer->SetFontList(rb->GetFontList(ui::ResourceBundle::SmallFont)); 1721 disclaimer->SetFontList(rb->GetFontList(ui::ResourceBundle::SmallFont));
1565 layout->StartRow(1, 0); 1722 layout->StartRow(1, 0);
1566 layout->AddView(disclaimer); 1723 layout->AddView(disclaimer);
1567 1724
1568 return view; 1725 return view;
1569 } 1726 }
1570 1727
1571 views::View* ProfileChooserView::CreateCurrentProfileAccountsView( 1728 views::View* ProfileChooserView::CreateCurrentProfileAccountsView(
1572 const AvatarMenu::Item& avatar_item) { 1729 const AvatarMenu::Item& avatar_item) {
1573 DCHECK(avatar_item.signed_in); 1730 DCHECK(avatar_item.signed_in);
1574 views::View* view = new views::View(); 1731 views::View* view = new views::View();
1575 view->set_background(views::Background::CreateSolidBackground( 1732 view->set_background(views::Background::CreateSolidBackground(
1576 profiles::kAvatarBubbleAccountsBackgroundColor)); 1733 profiles::kAvatarBubbleAccountsBackgroundColor));
1577 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 1734 views::GridLayout* layout =
1735 CreateSingleColumnLayout(view, GetFixedMenuWidth());
1578 1736
1579 Profile* profile = browser_->profile(); 1737 Profile* profile = browser_->profile();
1580 std::string primary_account = 1738 std::string primary_account =
1581 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); 1739 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
1582 DCHECK(!primary_account.empty()); 1740 DCHECK(!primary_account.empty());
1583 std::vector<std::string>accounts = 1741 std::vector<std::string>accounts =
1584 profiles::GetSecondaryAccountsForProfile(profile, primary_account); 1742 profiles::GetSecondaryAccountsForProfile(profile, primary_account);
1585 1743
1586 // Get state of authentication error, if any. 1744 // Get state of authentication error, if any.
1587 std::string error_account_id = GetAuthErrorAccountId(profile); 1745 std::string error_account_id = GetAuthErrorAccountId(profile);
1588 1746
1589 // The primary account should always be listed first. 1747 // The primary account should always be listed first.
1590 // TODO(rogerta): we still need to further differentiate the primary account 1748 // TODO(rogerta): we still need to further differentiate the primary account
1591 // from the others in the UI, so more work is likely required here: 1749 // from the others in the UI, so more work is likely required here:
1592 // crbug.com/311124. 1750 // crbug.com/311124.
1593 CreateAccountButton(layout, primary_account, true, 1751 CreateAccountButton(layout, primary_account, true,
1594 error_account_id == primary_account, kFixedMenuWidth); 1752 error_account_id == primary_account, GetFixedMenuWidth());
1595 for (size_t i = 0; i < accounts.size(); ++i) 1753 for (size_t i = 0; i < accounts.size(); ++i)
1596 CreateAccountButton(layout, accounts[i], false, 1754 CreateAccountButton(layout, accounts[i], false,
1597 error_account_id == accounts[i], kFixedMenuWidth); 1755 error_account_id == accounts[i], GetFixedMenuWidth());
1598 1756
1599 if (!profile->IsSupervised()) { 1757 if (!profile->IsSupervised()) {
1600 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 1758 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
1601 1759
1602 add_account_link_ = CreateLink(l10n_util::GetStringFUTF16( 1760 add_account_link_ = CreateLink(l10n_util::GetStringFUTF16(
1603 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this); 1761 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this);
1604 add_account_link_->SetBorder(views::Border::CreateEmptyBorder( 1762 add_account_link_->SetBorder(views::Border::CreateEmptyBorder(
1605 0, views::kButtonVEdgeMarginNew, 1763 0, views::kButtonVEdgeMarginNew,
1606 views::kRelatedControlVerticalSpacing, 0)); 1764 views::kRelatedControlVerticalSpacing, 0));
1607 layout->StartRow(1, 0); 1765 layout->StartRow(1, 0);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2055 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1898 IncognitoModePrefs::DISABLED; 2056 IncognitoModePrefs::DISABLED;
1899 return incognito_available && !browser_->profile()->IsGuestSession(); 2057 return incognito_available && !browser_->profile()->IsGuestSession();
1900 } 2058 }
1901 2059
1902 void ProfileChooserView::PostActionPerformed( 2060 void ProfileChooserView::PostActionPerformed(
1903 ProfileMetrics::ProfileDesktopMenu action_performed) { 2061 ProfileMetrics::ProfileDesktopMenu action_performed) {
1904 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 2062 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1905 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 2063 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1906 } 2064 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/profiles/profile_chooser_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698