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

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

Issue 2708073002: Removing pre-material design menu setting. (Closed)
Patch Set: Replacing functions by variables Created 3 years, 10 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include "ui/views/controls/button/blue_button.h" 73 #include "ui/views/controls/button/blue_button.h"
74 #include "ui/views/controls/button/image_button.h" 74 #include "ui/views/controls/button/image_button.h"
75 #include "ui/views/controls/button/label_button.h" 75 #include "ui/views/controls/button/label_button.h"
76 #include "ui/views/controls/button/label_button_border.h" 76 #include "ui/views/controls/button/label_button_border.h"
77 #include "ui/views/controls/button/md_text_button.h" 77 #include "ui/views/controls/button/md_text_button.h"
78 #include "ui/views/controls/button/menu_button.h" 78 #include "ui/views/controls/button/menu_button.h"
79 #include "ui/views/controls/label.h" 79 #include "ui/views/controls/label.h"
80 #include "ui/views/controls/link.h" 80 #include "ui/views/controls/link.h"
81 #include "ui/views/controls/separator.h" 81 #include "ui/views/controls/separator.h"
82 #include "ui/views/controls/styled_label.h" 82 #include "ui/views/controls/styled_label.h"
83 #include "ui/views/controls/textfield/textfield.h"
84 #include "ui/views/controls/webview/webview.h" 83 #include "ui/views/controls/webview/webview.h"
85 #include "ui/views/layout/box_layout.h" 84 #include "ui/views/layout/box_layout.h"
86 #include "ui/views/layout/fill_layout.h" 85 #include "ui/views/layout/fill_layout.h"
87 #include "ui/views/layout/grid_layout.h" 86 #include "ui/views/layout/grid_layout.h"
88 #include "ui/views/layout/layout_constants.h" 87 #include "ui/views/layout/layout_constants.h"
89 #include "ui/views/widget/widget.h" 88 #include "ui/views/widget/widget.h"
90 89
91 namespace { 90 namespace {
92 91
93 // Helpers -------------------------------------------------------------------- 92 // Helpers --------------------------------------------------------------------
94 93
95 const int kButtonHeight = 32; 94 const int kButtonHeight = 32;
96 const int kPasswordCombinedFixedGaiaViewWidth = 360; 95 const int kPasswordCombinedFixedGaiaViewWidth = 360;
97 const int kFixedGaiaViewWidth = 448; 96 const int kFixedGaiaViewWidth = 448;
98 const int kFixedAccountRemovalViewWidth = 280; 97 const int kFixedAccountRemovalViewWidth = 280;
99 const int kFixedSwitchUserViewWidth = 320; 98 const int kFixedSwitchUserViewWidth = 320;
100 const int kLargeImageSide = 88;
101 const int kMdImageSide = 40; 99 const int kMdImageSide = 40;
100 const int kProfileBadgeSize = 24;
101 const int kFixedMenuWidth = 240;
102 const int kSupervisedIconBadgeSize = 22;
103
104 // The space between the right/bottom edge of the profile badge and the
105 // right/bottom edge of the profile icon.
106 const int kBadgeSpacing = 4;
102 107
103 // Spacing between the edge of the material design user menu and the 108 // Spacing between the edge of the material design user menu and the
104 // top/bottom or left/right of the menu items. 109 // top/bottom or left/right of the menu items.
105 const int kMaterialMenuEdgeMargin = 16; 110 const int kMaterialMenuEdgeMargin = 16;
106 111
107 const int kVerticalSpacing = 16; 112 const int kVerticalSpacing = 16;
108 113
109 const int kTitleViewNativeWidgetOffset = 8; 114 const int kTitleViewNativeWidgetOffset = 8;
110 115
111 bool IsProfileChooser(profiles::BubbleViewMode mode) { 116 bool IsProfileChooser(profiles::BubbleViewMode mode) {
112 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || 117 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ||
113 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; 118 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
114 } 119 }
115 120
116 int GetFixedMenuWidth() {
117 return switches::IsMaterialDesignUserMenu() ? 240 : 250;
118 }
119
120 int GetProfileBadgeSize() {
121 return switches::IsMaterialDesignUserMenu() ? 24 : 30;
122 }
123
124 // DEPRECATED: New user menu components should use views::BoxLayout instead. 121 // DEPRECATED: New user menu components should use views::BoxLayout instead.
125 // Creates a GridLayout with a single column. This ensures that all the child 122 // Creates a GridLayout with a single column. This ensures that all the child
126 // views added get auto-expanded to fill the full width of the bubble. 123 // views added get auto-expanded to fill the full width of the bubble.
127 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { 124 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) {
128 views::GridLayout* layout = new views::GridLayout(view); 125 views::GridLayout* layout = new views::GridLayout(view);
129 view->SetLayoutManager(layout); 126 view->SetLayoutManager(layout);
130 127
131 views::ColumnSet* columns = layout->AddColumnSet(0); 128 views::ColumnSet* columns = layout->AddColumnSet(0);
132 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, 129 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
133 views::GridLayout::FIXED, width, width); 130 views::GridLayout::FIXED, width, width);
134 return layout; 131 return layout;
135 } 132 }
136 133
137 views::Link* CreateLink(const base::string16& link_text, 134 views::Link* CreateLink(const base::string16& link_text,
138 views::LinkListener* listener) { 135 views::LinkListener* listener) {
139 views::Link* link_button = new views::Link(link_text); 136 views::Link* link_button = new views::Link(link_text);
140 link_button->SetHorizontalAlignment(gfx::ALIGN_LEFT); 137 link_button->SetHorizontalAlignment(gfx::ALIGN_LEFT);
141 link_button->SetUnderline(false); 138 link_button->SetUnderline(false);
142 link_button->set_listener(listener); 139 link_button->set_listener(listener);
143 return link_button; 140 return link_button;
144 } 141 }
145 142
146 gfx::ImageSkia CreateSquarePlaceholderImage(int size) {
147 SkBitmap bitmap;
148 bitmap.allocPixels(SkImageInfo::MakeA8(size, size));
149 bitmap.eraseARGB(0, 0, 0, 0);
150 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
151 }
152
153 bool HasAuthError(Profile* profile) { 143 bool HasAuthError(Profile* profile) {
154 const SigninErrorController* error = 144 const SigninErrorController* error =
155 SigninErrorControllerFactory::GetForProfile(profile); 145 SigninErrorControllerFactory::GetForProfile(profile);
156 return error && error->HasError(); 146 return error && error->HasError();
157 } 147 }
158 148
159 std::string GetAuthErrorAccountId(Profile* profile) { 149 std::string GetAuthErrorAccountId(Profile* profile) {
160 const SigninErrorController* error = 150 const SigninErrorController* error =
161 SigninErrorControllerFactory::GetForProfile(profile); 151 SigninErrorControllerFactory::GetForProfile(profile);
162 if (!error) 152 if (!error)
(...skipping 25 matching lines...) Expand all
188 class BackgroundColorHoverButton : public views::LabelButton { 178 class BackgroundColorHoverButton : public views::LabelButton {
189 public: 179 public:
190 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view, 180 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view,
191 const base::string16& text) 181 const base::string16& text)
192 : views::LabelButton(profile_chooser_view, text), 182 : views::LabelButton(profile_chooser_view, text),
193 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 183 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
194 profile_chooser_view_(profile_chooser_view), 184 profile_chooser_view_(profile_chooser_view),
195 #endif 185 #endif
196 title_(nullptr), 186 title_(nullptr),
197 subtitle_(nullptr) { 187 subtitle_(nullptr) {
198 SetImageLabelSpacing(switches::IsMaterialDesignUserMenu() 188 SetImageLabelSpacing(kMaterialMenuEdgeMargin - 2);
199 ? (kMaterialMenuEdgeMargin - 2) 189 SetBorder(views::CreateEmptyBorder(0, kMaterialMenuEdgeMargin, 0,
200 : views::kItemLabelSpacing); 190 kMaterialMenuEdgeMargin));
201 const int button_margin = switches::IsMaterialDesignUserMenu()
202 ? kMaterialMenuEdgeMargin
203 : views::kButtonHEdgeMarginNew;
204 SetBorder(views::CreateEmptyBorder(0, button_margin, 0, button_margin));
205 SetFocusForPlatform(); 191 SetFocusForPlatform();
206 192
207 if (switches::IsMaterialDesignUserMenu()) { 193 label()->SetHandlesTooltips(false);
208 label()->SetHandlesTooltips(false);
209 }
210 } 194 }
211 195
212 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view, 196 BackgroundColorHoverButton(ProfileChooserView* profile_chooser_view,
213 const base::string16& text, 197 const base::string16& text,
214 const gfx::ImageSkia& icon) 198 const gfx::ImageSkia& icon)
215 : BackgroundColorHoverButton(profile_chooser_view, text) { 199 : BackgroundColorHoverButton(profile_chooser_view, text) {
216 SetMinSize(gfx::Size( 200 SetMinSize(gfx::Size(
217 icon.width(), kButtonHeight + views::kRelatedControlVerticalSpacing)); 201 icon.width(), kButtonHeight + views::kRelatedControlVerticalSpacing));
218 SetImage(STATE_NORMAL, icon); 202 SetImage(STATE_NORMAL, icon);
219 } 203 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 title_widget_->SetContentsView(title_view_); 351 title_widget_->SetContentsView(title_view_);
368 352
369 gfx::Rect bounds(title_view_->GetPreferredSize()); 353 gfx::Rect bounds(title_view_->GetPreferredSize());
370 title_view_->SetBoundsRect(bounds); 354 title_view_->SetBoundsRect(bounds);
371 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset); 355 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset);
372 title_widget_->SetBounds(bounds); 356 title_widget_->SetBounds(bounds);
373 } 357 }
374 358
375 } // namespace 359 } // namespace
376 360
377 // RightAlignedIconLabelButton -------------------------------------------------
378
379 // A custom LabelButton that has a center-aligned text and right aligned icon.
380 // Only used in non-material-design user menu.
381 class RightAlignedIconLabelButton : public views::LabelButton {
382 public:
383 RightAlignedIconLabelButton(views::ButtonListener* listener,
384 const base::string16& text)
385 : views::LabelButton(listener, text) {
386 SetHorizontalAlignment(gfx::ALIGN_RIGHT);
387 label()->SetHorizontalAlignment(gfx::ALIGN_CENTER);
388 }
389
390 protected:
391 void Layout() override {
392 views::LabelButton::Layout();
393
394 // Keep the text centered and the icon right-aligned by stretching the label
395 // to take up more of the content area and centering its contents.
396 gfx::Rect content_bounds = GetContentsBounds();
397 gfx::Rect label_bounds = label()->bounds();
398 label_bounds.Inset(content_bounds.x() - label_bounds.x(), 0, 0, 0);
399 label()->SetBoundsRect(label_bounds);
400 }
401
402 private:
403 void OnFocus() override {
404 SetState(STATE_HOVERED);
405 }
406
407 void OnBlur() override {
408 SetState(STATE_NORMAL);
409 }
410
411 DISALLOW_COPY_AND_ASSIGN(RightAlignedIconLabelButton);
412 };
413
414 // EditableProfilePhoto ------------------------------------------------- 361 // EditableProfilePhoto -------------------------------------------------
415 362
416 const size_t kProfileBadgeWhitePadding = 2;
417
418 // A custom Image control that shows a "change" button when moused over. 363 // A custom Image control that shows a "change" button when moused over.
419 class EditableProfilePhoto : public views::LabelButton { 364 class EditableProfilePhoto : public views::LabelButton {
420 public: 365 public:
421 EditableProfilePhoto(views::ButtonListener* listener, 366 EditableProfilePhoto(views::ButtonListener* listener,
422 const gfx::Image& icon, 367 const gfx::Image& icon,
423 bool is_editing_allowed, 368 bool is_editing_allowed,
424 Profile* profile) 369 Profile* profile)
425 : views::LabelButton(listener, base::string16()), 370 : views::LabelButton(listener, base::string16()),
426 interactive_(!switches::IsMaterialDesignUserMenu()),
427 photo_overlay_(nullptr), 371 photo_overlay_(nullptr),
428 profile_(profile) { 372 profile_(profile) {
429 gfx::Image image = profiles::GetSizedAvatarIcon( 373 set_can_process_events_within_subtree(false);
sky 2017/02/23 20:44:52 Why are you adding this?
jlebel 2017/03/06 13:09:29 This is to replace: bool CanProcessEventsWithinSub
430 icon, true, icon_image_side(), icon_image_side()); 374 gfx::Image image =
375 profiles::GetSizedAvatarIcon(icon, true, kMdImageSide, kMdImageSide);
431 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); 376 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia());
432 SetBorder(views::NullBorder()); 377 SetBorder(views::NullBorder());
433 if (switches::IsMaterialDesignUserMenu()) { 378 SetMinSize(gfx::Size(GetPreferredSize().width() + kBadgeSpacing,
434 SetMinSize(gfx::Size(GetPreferredSize().width() + badge_spacing(), 379 GetPreferredSize().height() + kBadgeSpacing +
435 GetPreferredSize().height() + badge_spacing() + 380 views::kRelatedControlSmallVerticalSpacing));
436 views::kRelatedControlSmallVerticalSpacing));
437 } else {
438 SetSize(GetPreferredSize());
439 }
440 381
441 if (switches::IsMaterialDesignUserMenu() || !is_editing_allowed) { 382 SetEnabled(false);
442 SetEnabled(false);
443 return;
444 }
445
446 set_notify_enter_exit_on_child(true);
447
448 // Photo overlay that appears when hovering over the button.
449 photo_overlay_ = new views::ImageView();
450
451 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255);
452 photo_overlay_->set_background(
453 views::Background::CreateSolidBackground(kBackgroundColor));
454 photo_overlay_->SetImage(gfx::CreateVectorIcon(
455 gfx::VectorIconId::PHOTO_CAMERA, 48u, SkColorSetRGB(0x33, 0x33, 0x33)));
456
457 photo_overlay_->SetSize(gfx::Size(icon_image_side(), icon_image_side()));
458 photo_overlay_->SetY(badge_spacing());
459 photo_overlay_->SetVisible(false);
460 AddChildView(photo_overlay_);
461 } 383 }
462 384
463 void PaintChildren(const ui::PaintContext& context) override { 385 void PaintChildren(const ui::PaintContext& context) override {
464 { 386 {
465 // Display any children (the "change photo" overlay) as a circle. 387 // Display any children (the "change photo" overlay) as a circle.
466 ui::ClipRecorder clip_recorder(context); 388 ui::ClipRecorder clip_recorder(context);
467 gfx::Rect clip_bounds = image()->GetMirroredBounds(); 389 gfx::Rect clip_bounds = image()->GetMirroredBounds();
468 gfx::Path clip_mask; 390 gfx::Path clip_mask;
469 clip_mask.addCircle( 391 clip_mask.addCircle(
470 clip_bounds.x() + clip_bounds.width() / 2, 392 clip_bounds.x() + clip_bounds.width() / 2,
471 clip_bounds.y() + clip_bounds.height() / 2, 393 clip_bounds.y() + clip_bounds.height() / 2,
472 clip_bounds.width() / 2); 394 clip_bounds.width() / 2);
473 clip_recorder.ClipPathWithAntiAliasing(clip_mask); 395 clip_recorder.ClipPathWithAntiAliasing(clip_mask);
474 View::PaintChildren(context); 396 View::PaintChildren(context);
475 } 397 }
476 398
477 ui::PaintRecorder paint_recorder( 399 ui::PaintRecorder paint_recorder(
478 context, gfx::Size(GetProfileBadgeSize(), GetProfileBadgeSize())); 400 context, gfx::Size(kProfileBadgeSize, kProfileBadgeSize));
479 gfx::Canvas* canvas = paint_recorder.canvas(); 401 gfx::Canvas* canvas = paint_recorder.canvas();
480 if (profile_->IsSupervised()) { 402 if (profile_->IsSupervised()) {
481 gfx::Rect bounds(0, 0, GetProfileBadgeSize(), GetProfileBadgeSize()); 403 gfx::Rect bounds(0, 0, kProfileBadgeSize, kProfileBadgeSize);
482 int badge_offset = 404 int badge_offset = kMdImageSide + kBadgeSpacing - kProfileBadgeSize;
483 icon_image_side() + badge_spacing() - GetProfileBadgeSize();
484 gfx::Vector2d badge_offset_vector = gfx::Vector2d( 405 gfx::Vector2d badge_offset_vector = gfx::Vector2d(
485 GetMirroredXWithWidthInView(badge_offset, GetProfileBadgeSize()), 406 GetMirroredXWithWidthInView(badge_offset, kProfileBadgeSize),
486 badge_offset + (switches::IsMaterialDesignUserMenu() 407 badge_offset + views::kRelatedControlSmallVerticalSpacing);
487 ? views::kRelatedControlSmallVerticalSpacing
488 : 0));
489 408
490 gfx::Point center_point = bounds.CenterPoint() + badge_offset_vector; 409 gfx::Point center_point = bounds.CenterPoint() + badge_offset_vector;
491 410
492 // Paint the circular background. 411 // Paint the circular background.
493 cc::PaintFlags flags; 412 cc::PaintFlags flags;
494 flags.setAntiAlias(true); 413 flags.setAntiAlias(true);
495 flags.setColor(GetNativeTheme()->GetSystemColor( 414 flags.setColor(GetNativeTheme()->GetSystemColor(
496 ui::NativeTheme::kColorId_BubbleBackground)); 415 ui::NativeTheme::kColorId_BubbleBackground));
497 canvas->DrawCircle(center_point, GetProfileBadgeSize() / 2, flags); 416 canvas->DrawCircle(center_point, kProfileBadgeSize / 2, flags);
498 417
499 gfx::VectorIconId icon_id; 418 gfx::VectorIconId icon_id =
500 int icon_size; 419 profile_->IsChild() ? gfx::VectorIconId::ACCOUNT_CHILD_CIRCLE
501 SkColor icon_color; 420 : gfx::VectorIconId::SUPERVISOR_ACCOUNT_CIRCLE;
502 if (switches::IsMaterialDesignUserMenu()) {
503 icon_id = profile_->IsChild()
504 ? gfx::VectorIconId::ACCOUNT_CHILD_CIRCLE
505 : gfx::VectorIconId::SUPERVISOR_ACCOUNT_CIRCLE;
506 icon_size = 22;
507 icon_color = gfx::kChromeIconGrey;
508 } else {
509 // Paint the light blue circle.
510 flags.setColor(SkColorSetRGB(0xaf, 0xd9, 0xfc));
511 canvas->DrawCircle(
512 center_point, GetProfileBadgeSize() / 2 - kProfileBadgeWhitePadding,
513 flags);
514
515 icon_id = profile_->IsChild()
516 ? gfx::VectorIconId::ACCOUNT_CHILD
517 : gfx::VectorIconId::SUPERVISOR_ACCOUNT;
518 icon_size = profile_->IsChild() ? 26 : 20;
519 icon_color = SkColorSetRGB(0, 0x66, 0xff);
520 }
521 421
522 // Paint the badge icon. 422 // Paint the badge icon.
523 int offset = (GetProfileBadgeSize() - icon_size) / 2; 423 int offset = (kProfileBadgeSize - kSupervisedIconBadgeSize) / 2;
524 canvas->Translate(badge_offset_vector + gfx::Vector2d(offset, offset)); 424 canvas->Translate(badge_offset_vector + gfx::Vector2d(offset, offset));
525 gfx::PaintVectorIcon(canvas, icon_id, icon_size, icon_color); 425 gfx::PaintVectorIcon(canvas, icon_id, kSupervisedIconBadgeSize,
426 gfx::kChromeIconGrey);
526 } 427 }
527 } 428 }
528 429
529 static int icon_image_side() {
530 return switches::IsMaterialDesignUserMenu() ? kMdImageSide
531 : kLargeImageSide;
532 }
533
534 static int badge_spacing() {
535 // The space between the right/bottom edge of the profile badge and the
536 // right/bottom edge of the profile icon.
537 return switches::IsMaterialDesignUserMenu() ? 4 : 0;
538 }
539
540 bool CanProcessEventsWithinSubtree() const override { return interactive_; }
541
542 private: 430 private:
543 // views::CustomButton: 431 // views::CustomButton:
544 void StateChanged(ButtonState old_state) override { 432 void StateChanged(ButtonState old_state) override {
545 if (photo_overlay_) { 433 if (photo_overlay_) {
546 photo_overlay_->SetVisible( 434 photo_overlay_->SetVisible(
547 state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus()); 435 state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus());
548 } 436 }
549 } 437 }
550 438
551 void OnFocus() override { 439 void OnFocus() override {
552 views::LabelButton::OnFocus(); 440 views::LabelButton::OnFocus();
553 if (photo_overlay_) 441 if (photo_overlay_)
554 photo_overlay_->SetVisible(true); 442 photo_overlay_->SetVisible(true);
555 } 443 }
556 444
557 void OnBlur() override { 445 void OnBlur() override {
558 views::LabelButton::OnBlur(); 446 views::LabelButton::OnBlur();
559 // Don't hide the overlay if it's being shown as a result of a mouseover. 447 // Don't hide the overlay if it's being shown as a result of a mouseover.
560 if (photo_overlay_ && state() != STATE_HOVERED) 448 if (photo_overlay_ && state() != STATE_HOVERED)
561 photo_overlay_->SetVisible(false); 449 photo_overlay_->SetVisible(false);
562 } 450 }
563 451
564 bool interactive_;
565
566 // Image that is shown when hovering over the image button. Can be NULL if 452 // Image that is shown when hovering over the image button. Can be NULL if
567 // the photo isn't allowed to be edited (e.g. for guest profiles). 453 // the photo isn't allowed to be edited (e.g. for guest profiles).
568 views::ImageView* photo_overlay_; 454 views::ImageView* photo_overlay_;
569 455
570 Profile* profile_; 456 Profile* profile_;
571 457
572 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); 458 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto);
573 }; 459 };
574 460
575 // EditableProfileName -------------------------------------------------
576
577 // A custom text control that turns into a textfield for editing when clicked.
578 // Only used in non-material-design user menu.
579 class EditableProfileName : public views::View,
580 public views::ButtonListener {
581 public:
582 EditableProfileName(views::TextfieldController* controller,
583 const base::string16& text,
584 bool is_editing_allowed)
585 : button_(nullptr), profile_name_textfield_(nullptr) {
586 SetLayoutManager(
587 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
588
589 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
590 const gfx::FontList& medium_font_list =
591 rb->GetFontList(ui::ResourceBundle::MediumFont);
592 const gfx::Insets textfield_border_insets =
593 views::Textfield().border()->GetInsets();
594
595 if (!is_editing_allowed) {
596 views::Label* name_label = new views::Label(text);
597 name_label->SetBorder(views::CreateEmptyBorder(textfield_border_insets));
598 name_label->SetFontList(medium_font_list);
599 AddChildView(name_label);
600 return;
601 }
602
603 profile_name_textfield_ = new views::Textfield();
604 // Textfield that overlaps the button.
605 profile_name_textfield_->set_controller(controller);
606 profile_name_textfield_->SetFontList(medium_font_list);
607 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
608 profile_name_textfield_->SetVisible(false);
609 AddChildView(profile_name_textfield_);
610
611 button_ = new RightAlignedIconLabelButton(this, text);
612 button_->SetFontListDeprecated(medium_font_list);
613 // Show an "edit" pencil icon when hovering over. In the default state,
614 // we need to create an empty placeholder of the correct size, so that
615 // the text doesn't jump around when the hovered icon appears.
616 // TODO(estade): revisit colors and press effect.
617 const int kIconSize = 16;
618 button_->SetImage(views::LabelButton::STATE_NORMAL,
619 CreateSquarePlaceholderImage(kIconSize));
620 button_->SetImage(views::LabelButton::STATE_HOVERED,
621 gfx::CreateVectorIcon(
622 gfx::VectorIconId::MODE_EDIT, kIconSize,
623 SkColorSetRGB(0x33, 0x33, 0x33)));
624 button_->SetImage(views::LabelButton::STATE_PRESSED,
625 gfx::CreateVectorIcon(
626 gfx::VectorIconId::MODE_EDIT, kIconSize,
627 SkColorSetRGB(0x20, 0x20, 0x20)));
628 // We need to add a left padding as well as a small top/bottom padding
629 // to the text to account for the textfield's border.
630 const int kIconTextLabelButtonSpacing = 5;
631 button_->SetBorder(views::CreateEmptyBorder(
632 textfield_border_insets +
633 gfx::Insets(0, kIconSize + kIconTextLabelButtonSpacing, 0, 0)));
634 AddChildView(button_);
635 }
636
637 views::Textfield* profile_name_textfield() {
638 return profile_name_textfield_;
639 }
640
641 // Hide the editable textfield to show the profile name button instead.
642 void ShowReadOnlyView() {
643 button_->SetVisible(true);
644 profile_name_textfield_->SetVisible(false);
645 }
646
647 private:
648 // views::ButtonListener:
649 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
650 button_->SetVisible(false);
651 profile_name_textfield_->SetVisible(true);
652 profile_name_textfield_->SetText(button_->GetText());
653 profile_name_textfield_->SelectAll(false);
654 profile_name_textfield_->RequestFocus();
655 // Re-layouts the view after swaping the controls.
656 Layout();
657 }
658
659 // views::LabelButton:
660 bool OnKeyReleased(const ui::KeyEvent& event) override {
661 // Override CustomButton's implementation, which presses the button when
662 // you press space and clicks it when you release space, as the space can be
663 // part of the new profile name typed in the textfield.
664 return false;
665 }
666
667 // The label button which shows the profile name, and can handle the event to
668 // make it editable. Can be NULL if the profile name isn't allowed to be
669 // edited.
670 RightAlignedIconLabelButton* button_;
671
672 // Textfield that is shown when editing the profile name. Can be NULL if
673 // the profile name isn't allowed to be edited (e.g. for guest profiles).
674 views::Textfield* profile_name_textfield_;
675
676 DISALLOW_COPY_AND_ASSIGN(EditableProfileName);
677 };
678
679 // A title card with one back button right aligned and one label center aligned. 461 // A title card with one back button right aligned and one label center aligned.
680 class TitleCard : public views::View { 462 class TitleCard : public views::View {
681 public: 463 public:
682 TitleCard(const base::string16& message, views::ButtonListener* listener, 464 TitleCard(const base::string16& message, views::ButtonListener* listener,
683 views::ImageButton** back_button) { 465 views::ImageButton** back_button) {
684 back_button_ = CreateBackButton(listener); 466 back_button_ = CreateBackButton(listener);
685 *back_button = back_button_; 467 *back_button = back_button_;
686 468
687 title_label_ = new views::Label(message); 469 title_label_ = new views::Label(message);
688 title_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 470 title_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 const signin::ManageAccountsParams& manage_accounts_params, 544 const signin::ManageAccountsParams& manage_accounts_params,
763 signin_metrics::AccessPoint access_point, 545 signin_metrics::AccessPoint access_point,
764 views::View* anchor_view, 546 views::View* anchor_view,
765 Browser* browser, 547 Browser* browser,
766 bool is_source_keyboard) { 548 bool is_source_keyboard) {
767 // Don't start creating the view if it would be an empty fast user switcher. 549 // Don't start creating the view if it would be an empty fast user switcher.
768 // It has to happen here to prevent the view system from creating an empty 550 // It has to happen here to prevent the view system from creating an empty
769 // container. 551 // container.
770 // Same for material design user menu since fast profile switcher will be 552 // Same for material design user menu since fast profile switcher will be
771 // migrated to the left-click menu. 553 // migrated to the left-click menu.
772 if (view_mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER && 554 if (view_mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) {
sky 2017/02/23 20:44:52 no {}
jlebel 2017/03/06 13:09:30 Done.
773 (!profiles::HasProfileSwitchTargets(browser->profile()) ||
774 switches::IsMaterialDesignUserMenu())) {
775 return; 555 return;
776 } 556 }
777 557
778 if (IsShowing()) { 558 if (IsShowing()) {
779 if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) { 559 if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) {
780 profile_bubble_->tutorial_mode_ = tutorial_mode; 560 profile_bubble_->tutorial_mode_ = tutorial_mode;
781 profile_bubble_->ShowViewFromMode(view_mode); 561 profile_bubble_->ShowViewFromMode(view_mode);
782 } 562 }
783 return; 563 return;
784 } 564 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 tutorial_learn_more_link_ = nullptr; 623 tutorial_learn_more_link_ = nullptr;
844 sync_error_signin_button_ = nullptr; 624 sync_error_signin_button_ = nullptr;
845 sync_error_passphrase_button_ = nullptr; 625 sync_error_passphrase_button_ = nullptr;
846 sync_error_upgrade_button_ = nullptr; 626 sync_error_upgrade_button_ = nullptr;
847 sync_error_signin_again_button_ = nullptr; 627 sync_error_signin_again_button_ = nullptr;
848 sync_error_signout_button_ = nullptr; 628 sync_error_signout_button_ = nullptr;
849 manage_accounts_link_ = nullptr; 629 manage_accounts_link_ = nullptr;
850 manage_accounts_button_ = nullptr; 630 manage_accounts_button_ = nullptr;
851 signin_current_profile_button_ = nullptr; 631 signin_current_profile_button_ = nullptr;
852 auth_error_email_button_ = nullptr; 632 auth_error_email_button_ = nullptr;
853 current_profile_photo_ = nullptr;
854 current_profile_name_ = nullptr;
855 current_profile_card_ = nullptr; 633 current_profile_card_ = nullptr;
856 first_profile_button_ = nullptr; 634 first_profile_button_ = nullptr;
857 guest_profile_button_ = nullptr; 635 guest_profile_button_ = nullptr;
858 users_button_ = nullptr; 636 users_button_ = nullptr;
859 go_incognito_button_ = nullptr; 637 go_incognito_button_ = nullptr;
860 lock_button_ = nullptr; 638 lock_button_ = nullptr;
861 close_all_windows_button_ = nullptr; 639 close_all_windows_button_ = nullptr;
862 add_account_link_ = nullptr; 640 add_account_link_ = nullptr;
863 gaia_signin_cancel_button_ = nullptr; 641 gaia_signin_cancel_button_ = nullptr;
864 remove_account_button_ = nullptr; 642 remove_account_button_ = nullptr;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 break; 767 break;
990 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: 768 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER:
991 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); 769 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth);
992 sub_view = CreateSwitchUserView(); 770 sub_view = CreateSwitchUserView();
993 ProfileMetrics::LogProfileNewAvatarMenuNotYou( 771 ProfileMetrics::LogProfileNewAvatarMenuNotYou(
994 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW); 772 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW);
995 break; 773 break;
996 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: 774 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT:
997 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER: 775 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER:
998 case profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER: 776 case profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER:
999 layout = CreateSingleColumnLayout(this, GetFixedMenuWidth()); 777 layout = CreateSingleColumnLayout(this, kFixedMenuWidth);
1000 sub_view = CreateProfileChooserView(avatar_menu); 778 sub_view = CreateProfileChooserView(avatar_menu);
1001 break; 779 break;
1002 } 780 }
1003 // Clears tutorial mode for all non-profile-chooser views. 781 // Clears tutorial mode for all non-profile-chooser views.
1004 if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) 782 if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER)
1005 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; 783 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE;
1006 784
1007 layout->StartRow(1, 0); 785 layout->StartRow(1, 0);
1008 layout->AddView(sub_view); 786 layout->AddView(sub_view);
1009 Layout(); 787 Layout();
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 } else if (sender == gaia_signin_cancel_button_) { 911 } else if (sender == gaia_signin_cancel_button_) {
1134 // The account management view is only available with the 912 // The account management view is only available with the
1135 // --enable-account-consistency flag. 913 // --enable-account-consistency flag.
1136 bool account_management_available = 914 bool account_management_available =
1137 SigninManagerFactory::GetForProfile(browser_->profile())-> 915 SigninManagerFactory::GetForProfile(browser_->profile())->
1138 IsAuthenticated() && 916 IsAuthenticated() &&
1139 switches::IsEnableAccountConsistency(); 917 switches::IsEnableAccountConsistency();
1140 ShowViewFromMode(account_management_available ? 918 ShowViewFromMode(account_management_available ?
1141 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : 919 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT :
1142 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); 920 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER);
1143 } else if (sender == current_profile_photo_) {
1144 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex());
1145 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE);
1146 } else if (sender == current_profile_card_) { 921 } else if (sender == current_profile_card_) {
1147 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); 922 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex());
1148 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); 923 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE);
1149 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); 924 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME);
1150 } else if (sender == manage_accounts_button_) { 925 } else if (sender == manage_accounts_button_) {
1151 // This button can either mean show/hide the account management view, 926 // This button can either mean show/hide the account management view,
1152 // depending on which view it is displayed. 927 // depending on which view it is displayed.
1153 ShowViewFromMode(view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT 928 ShowViewFromMode(view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
1154 ? profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER 929 ? profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
1155 : profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT); 930 : profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 signin_ui_util::ShowSigninErrorLearnMorePage(browser_->profile()); 1010 signin_ui_util::ShowSigninErrorLearnMorePage(browser_->profile());
1236 } 1011 }
1237 } 1012 }
1238 1013
1239 void ProfileChooserView::StyledLabelLinkClicked(views::StyledLabel* label, 1014 void ProfileChooserView::StyledLabelLinkClicked(views::StyledLabel* label,
1240 const gfx::Range& range, 1015 const gfx::Range& range,
1241 int event_flags) { 1016 int event_flags) {
1242 chrome::ShowSettings(browser_); 1017 chrome::ShowSettings(browser_);
1243 } 1018 }
1244 1019
1245 bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender,
1246 const ui::KeyEvent& key_event) {
1247 if (key_event.type() != ui::ET_KEY_PRESSED)
1248 return false;
1249
1250 views::Textfield* name_textfield =
1251 current_profile_name_->profile_name_textfield();
1252 DCHECK(sender == name_textfield);
1253
1254 if (key_event.key_code() == ui::VKEY_RETURN ||
1255 key_event.key_code() == ui::VKEY_TAB) {
1256 // Pressing Tab/Enter commits the new profile name, unless it's empty.
1257 base::string16 new_profile_name = name_textfield->text();
1258 base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name);
1259 if (new_profile_name.empty())
1260 return true;
1261
1262 const AvatarMenu::Item& active_item = avatar_menu_->GetItemAt(
1263 avatar_menu_->GetActiveProfileIndex());
1264 Profile* profile = g_browser_process->profile_manager()->GetProfile(
1265 active_item.profile_path);
1266 DCHECK(profile);
1267
1268 if (profile->IsLegacySupervised())
1269 return true;
1270
1271 profiles::UpdateProfileName(profile, new_profile_name);
1272 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME);
1273 current_profile_name_->ShowReadOnlyView();
1274 return true;
1275 }
1276 return false;
1277 }
1278
1279 void ProfileChooserView::PopulateCompleteProfileChooserView( 1020 void ProfileChooserView::PopulateCompleteProfileChooserView(
1280 views::GridLayout* layout, 1021 views::GridLayout* layout,
1281 AvatarMenu* avatar_menu) { 1022 AvatarMenu* avatar_menu) {
1282 // Separate items into active and alternatives. 1023 // Separate items into active and alternatives.
1283 Indexes other_profiles; 1024 Indexes other_profiles;
1284 views::View* tutorial_view = NULL; 1025 views::View* tutorial_view = NULL;
1285 views::View* sync_error_view = NULL; 1026 views::View* sync_error_view = NULL;
1286 views::View* current_profile_view = NULL; 1027 views::View* current_profile_view = NULL;
1287 views::View* current_profile_accounts = NULL; 1028 views::View* current_profile_accounts = NULL;
1288 views::View* option_buttons_view = NULL; 1029 views::View* option_buttons_view = NULL;
1289 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { 1030 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
1290 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); 1031 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
1291 if (item.active) { 1032 if (item.active) {
1292 option_buttons_view = CreateOptionsView( 1033 option_buttons_view = CreateOptionsView(
1293 item.signed_in && profiles::IsLockAvailable(browser_->profile()), 1034 item.signed_in && profiles::IsLockAvailable(browser_->profile()),
1294 avatar_menu); 1035 avatar_menu);
1295 current_profile_view = 1036 current_profile_view =
1296 switches::IsMaterialDesignUserMenu() 1037 CreateMaterialDesignCurrentProfileView(item, false);
sky 2017/02/23 20:44:52 Now that MaterialDesign is the default, can functi
jlebel 2017/03/06 13:09:30 Done.
1297 ? CreateMaterialDesignCurrentProfileView(item, false) 1038 if (!IsProfileChooser(view_mode_)) {
sky 2017/02/23 20:44:52 no {}
jlebel 2017/03/06 13:09:29 Done.
1298 : CreateCurrentProfileView(item, false);
1299 if (IsProfileChooser(view_mode_)) {
1300 if (!switches::IsMaterialDesignUserMenu())
1301 tutorial_view = CreateTutorialViewIfNeeded(item);
1302 } else {
1303 current_profile_accounts = CreateCurrentProfileAccountsView(item); 1039 current_profile_accounts = CreateCurrentProfileAccountsView(item);
1304 } 1040 }
1305 if (switches::IsMaterialDesignUserMenu()) 1041 sync_error_view = CreateSyncErrorViewIfNeeded();
1306 sync_error_view = CreateSyncErrorViewIfNeeded();
1307 } else { 1042 } else {
1308 other_profiles.push_back(i); 1043 other_profiles.push_back(i);
1309 } 1044 }
1310 } 1045 }
1311 1046
1312 if (tutorial_view) { 1047 if (tutorial_view) {
1313 // TODO(mlerman): update UMA stats for the new tutorial. 1048 // TODO(mlerman): update UMA stats for the new tutorial.
1314 layout->StartRow(1, 0); 1049 layout->StartRow(1, 0);
1315 layout->AddView(tutorial_view); 1050 layout->AddView(tutorial_view);
1316 } else { 1051 } else {
(...skipping 18 matching lines...) Expand all
1335 1070
1336 if (!IsProfileChooser(view_mode_)) { 1071 if (!IsProfileChooser(view_mode_)) {
1337 DCHECK(current_profile_accounts); 1072 DCHECK(current_profile_accounts);
1338 layout->StartRow(0, 0); 1073 layout->StartRow(0, 0);
1339 layout->AddView(new views::Separator()); 1074 layout->AddView(new views::Separator());
1340 layout->StartRow(1, 0); 1075 layout->StartRow(1, 0);
1341 layout->AddView(current_profile_accounts); 1076 layout->AddView(current_profile_accounts);
1342 } 1077 }
1343 1078
1344 if (browser_->profile()->IsSupervised()) { 1079 if (browser_->profile()->IsSupervised()) {
1345 if (!switches::IsMaterialDesignUserMenu()) {
1346 layout->StartRow(0, 0);
1347 layout->AddView(new views::Separator());
1348 }
1349 layout->StartRow(1, 0); 1080 layout->StartRow(1, 0);
1350 layout->AddView(CreateSupervisedUserDisclaimerView()); 1081 layout->AddView(CreateSupervisedUserDisclaimerView());
1351 } 1082 }
1352 1083
1353 layout->StartRow(0, 0); 1084 layout->StartRow(0, 0);
1354 layout->AddView(new views::Separator()); 1085 layout->AddView(new views::Separator());
1355 1086
1356 if (option_buttons_view) { 1087 if (option_buttons_view) {
1357 layout->StartRow(0, 0); 1088 layout->StartRow(0, 0);
1358 layout->AddView(option_buttons_view); 1089 layout->AddView(option_buttons_view);
(...skipping 11 matching lines...) Expand all
1370 } 1101 }
1371 } 1102 }
1372 1103
1373 layout->StartRow(1, 0); 1104 layout->StartRow(1, 0);
1374 layout->AddView(CreateOtherProfilesView(other_profiles)); 1105 layout->AddView(CreateOtherProfilesView(other_profiles));
1375 } 1106 }
1376 1107
1377 views::View* ProfileChooserView::CreateProfileChooserView( 1108 views::View* ProfileChooserView::CreateProfileChooserView(
1378 AvatarMenu* avatar_menu) { 1109 AvatarMenu* avatar_menu) {
1379 views::View* view = new views::View(); 1110 views::View* view = new views::View();
1380 views::GridLayout* layout = 1111 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
1381 CreateSingleColumnLayout(view, GetFixedMenuWidth());
1382 1112
1383 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) { 1113 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) {
1384 PopulateMinimalProfileChooserView(layout, avatar_menu); 1114 PopulateMinimalProfileChooserView(layout, avatar_menu);
1385 // The user is using right-click switching, no need to tell them about it. 1115 // The user is using right-click switching, no need to tell them about it.
1386 PrefService* local_state = g_browser_process->local_state(); 1116 PrefService* local_state = g_browser_process->local_state();
1387 local_state->SetBoolean( 1117 local_state->SetBoolean(
1388 prefs::kProfileAvatarRightClickTutorialDismissed, true); 1118 prefs::kProfileAvatarRightClickTutorialDismissed, true);
1389 } else { 1119 } else {
1390 PopulateCompleteProfileChooserView(layout, avatar_menu); 1120 PopulateCompleteProfileChooserView(layout, avatar_menu);
1391 } 1121 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 bool stack_button, 1177 bool stack_button,
1448 views::Link** link, 1178 views::Link** link,
1449 views::LabelButton** button, 1179 views::LabelButton** button,
1450 views::ImageButton** close_button) { 1180 views::ImageButton** close_button) {
1451 tutorial_mode_ = tutorial_mode; 1181 tutorial_mode_ = tutorial_mode;
1452 1182
1453 views::View* view = new views::View(); 1183 views::View* view = new views::View();
1454 view->set_background(views::Background::CreateSolidBackground( 1184 view->set_background(views::Background::CreateSolidBackground(
1455 profiles::kAvatarTutorialBackgroundColor)); 1185 profiles::kAvatarTutorialBackgroundColor));
1456 views::GridLayout* layout = CreateSingleColumnLayout( 1186 views::GridLayout* layout = CreateSingleColumnLayout(
1457 view, GetFixedMenuWidth() - 2 * views::kButtonHEdgeMarginNew); 1187 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew);
1458 // Creates a second column set for buttons and links. 1188 // Creates a second column set for buttons and links.
1459 views::ColumnSet* button_columns = layout->AddColumnSet(1); 1189 views::ColumnSet* button_columns = layout->AddColumnSet(1);
1460 button_columns->AddColumn(views::GridLayout::LEADING, 1190 button_columns->AddColumn(views::GridLayout::LEADING,
1461 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); 1191 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0);
1462 button_columns->AddPaddingColumn( 1192 button_columns->AddPaddingColumn(
1463 1, views::kUnrelatedControlHorizontalSpacing); 1193 1, views::kUnrelatedControlHorizontalSpacing);
1464 button_columns->AddColumn(views::GridLayout::TRAILING, 1194 button_columns->AddColumn(views::GridLayout::TRAILING,
1465 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); 1195 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0);
1466 layout->SetInsets(views::kButtonVEdgeMarginNew, 1196 layout->SetInsets(views::kButtonVEdgeMarginNew,
1467 views::kButtonHEdgeMarginNew, 1197 views::kButtonHEdgeMarginNew,
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 this, l10n_util::GetStringUTF16(button_string_id)); 1365 this, l10n_util::GetStringUTF16(button_string_id));
1636 vertical_view->AddChildView(*button_out); 1366 vertical_view->AddChildView(*button_out);
1637 view->SetBorder(views::CreateEmptyBorder( 1367 view->SetBorder(views::CreateEmptyBorder(
1638 0, 0, views::kRelatedControlSmallVerticalSpacing, 0)); 1368 0, 0, views::kRelatedControlSmallVerticalSpacing, 0));
1639 } 1369 }
1640 1370
1641 view->AddChildView(vertical_view); 1371 view->AddChildView(vertical_view);
1642 return view; 1372 return view;
1643 } 1373 }
1644 1374
1645 views::View* ProfileChooserView::CreateCurrentProfileView(
1646 const AvatarMenu::Item& avatar_item,
1647 bool is_guest) {
1648 views::View* view = new views::View();
1649 int column_width = GetFixedMenuWidth() - 2 * views::kButtonHEdgeMarginNew;
1650 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width);
1651 layout->SetInsets(views::kButtonVEdgeMarginNew,
1652 views::kButtonHEdgeMarginNew,
1653 views::kUnrelatedControlVerticalSpacing,
1654 views::kButtonHEdgeMarginNew);
1655
1656 // Profile icon, centered.
1657 int x_offset = (column_width - kLargeImageSide) / 2;
1658 current_profile_photo_ = new EditableProfilePhoto(
1659 this, avatar_item.icon, !is_guest, browser_->profile());
1660 current_profile_photo_->SetX(x_offset);
1661 SizedContainer* profile_icon_container =
1662 new SizedContainer(gfx::Size(column_width, kLargeImageSide));
1663 profile_icon_container->AddChildView(current_profile_photo_);
1664
1665
1666 layout->StartRow(1, 0);
1667 layout->AddView(profile_icon_container);
1668
1669 // Profile name, centered.
1670 bool editing_allowed = !is_guest &&
1671 !browser_->profile()->IsLegacySupervised();
1672 current_profile_name_ = new EditableProfileName(
1673 this,
1674 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()),
1675 editing_allowed);
1676 layout->StartRowWithPadding(1, 0, 0,
1677 views::kRelatedControlSmallVerticalSpacing);
1678 layout->StartRow(1, 0);
1679 layout->AddView(current_profile_name_);
1680
1681 if (is_guest)
1682 return view;
1683
1684 // The available links depend on the type of profile that is active.
1685 if (avatar_item.signed_in) {
1686 layout->StartRow(1, 0);
1687 if (switches::IsEnableAccountConsistency()) {
1688 base::string16 link_title = l10n_util::GetStringUTF16(
1689 IsProfileChooser(view_mode_) ?
1690 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON :
1691 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
1692 manage_accounts_link_ = CreateLink(link_title, this);
1693 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
1694 layout->AddView(manage_accounts_link_);
1695 } else {
1696 // Badge the email address if there's an authentication error.
1697 if (HasAuthError(browser_->profile())) {
1698 auth_error_email_button_ =
1699 new RightAlignedIconLabelButton(this, avatar_item.username);
1700 auth_error_email_button_->SetElideBehavior(gfx::ELIDE_EMAIL);
1701 auth_error_email_button_->SetImage(
1702 views::LabelButton::STATE_NORMAL,
1703 gfx::CreateVectorIcon(gfx::VectorIconId::WARNING, 18,
1704 gfx::kChromeIconGrey));
1705 auth_error_email_button_->SetFocusForPlatform();
1706 gfx::Insets insets =
1707 views::LabelButtonAssetBorder::GetDefaultInsetsForStyle(
1708 views::Button::STYLE_TEXTBUTTON);
1709 auth_error_email_button_->SetBorder(views::CreateEmptyBorder(
1710 insets.top(), insets.left(), insets.bottom(), insets.right()));
1711 layout->AddView(auth_error_email_button_);
1712 } else {
1713 // Add a small padding between the email button and the profile name.
1714 layout->StartRowWithPadding(1, 0, 0, 2);
1715 views::Label* email_label = new views::Label(avatar_item.username);
1716 email_label->SetElideBehavior(gfx::ELIDE_EMAIL);
1717 email_label->SetEnabled(false);
1718 layout->AddView(email_label);
1719 }
1720 }
1721 } else {
1722 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile(
1723 browser_->profile()->GetOriginalProfile());
1724 if (signin_manager->IsSigninAllowed()) {
1725 views::Label* promo = new views::Label(
1726 l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO));
1727 promo->SetMultiLine(true);
1728 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1729 layout->StartRowWithPadding(1, 0, 0,
1730 views::kRelatedControlSmallVerticalSpacing);
1731 layout->StartRow(1, 0);
1732 layout->AddView(promo);
1733
1734 signin_current_profile_button_ =
1735 views::MdTextButton::CreateSecondaryUiBlueButton(
1736 this, l10n_util::GetStringFUTF16(
1737 IDS_SYNC_START_SYNC_BUTTON_LABEL,
1738 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
1739 layout->StartRowWithPadding(1, 0, 0,
1740 views::kRelatedControlVerticalSpacing);
1741 layout->StartRow(1, 0);
1742 layout->AddView(signin_current_profile_button_);
1743 content::RecordAction(
1744 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin"));
1745 }
1746 }
1747
1748 return view;
1749 }
1750
1751 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( 1375 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView(
1752 const AvatarMenu::Item& avatar_item, 1376 const AvatarMenu::Item& avatar_item,
1753 bool is_guest) { 1377 bool is_guest) {
1754 views::View* view = new views::View(); 1378 views::View* view = new views::View();
1755 view->SetLayoutManager( 1379 view->SetLayoutManager(
1756 new views::BoxLayout(views::BoxLayout::kVertical, 0, 1380 new views::BoxLayout(views::BoxLayout::kVertical, 0,
1757 views::kRelatedControlVerticalSpacing, 0)); 1381 views::kRelatedControlVerticalSpacing, 0));
1758 1382
1759 // Container for the profile photo and avatar/user name. 1383 // Container for the profile photo and avatar/user name.
1760 BackgroundColorHoverButton* current_profile_card = 1384 BackgroundColorHoverButton* current_profile_card =
(...skipping 16 matching lines...) Expand all
1777 NonInteractiveContainer* profile_name_container = 1401 NonInteractiveContainer* profile_name_container =
1778 new NonInteractiveContainer(); 1402 new NonInteractiveContainer();
1779 int name_container_v_spacing = 1403 int name_container_v_spacing =
1780 (current_profile_photo->GetPreferredSize().height() - 1404 (current_profile_photo->GetPreferredSize().height() -
1781 current_profile_name->GetPreferredSize().height()) / 2; 1405 current_profile_name->GetPreferredSize().height()) / 2;
1782 views::BoxLayout* profile_name_layout = new views::BoxLayout( 1406 views::BoxLayout* profile_name_layout = new views::BoxLayout(
1783 views::BoxLayout::kVertical, 0, name_container_v_spacing, 0); 1407 views::BoxLayout::kVertical, 0, name_container_v_spacing, 0);
1784 profile_name_container->SetLayoutManager(profile_name_layout); 1408 profile_name_container->SetLayoutManager(profile_name_layout);
1785 profile_name_container->AddChildView(current_profile_name); 1409 profile_name_container->AddChildView(current_profile_name);
1786 1410
1787 const int between_child_spacing = 1411 const int between_child_spacing = kMaterialMenuEdgeMargin - kBadgeSpacing;
1788 kMaterialMenuEdgeMargin - EditableProfilePhoto::badge_spacing();
1789 current_profile_card_->SetLayoutManager(new views::BoxLayout( 1412 current_profile_card_->SetLayoutManager(new views::BoxLayout(
1790 views::BoxLayout::kHorizontal, 0, 1413 views::BoxLayout::kHorizontal, 0,
1791 views::kRelatedControlSmallVerticalSpacing, between_child_spacing)); 1414 views::kRelatedControlSmallVerticalSpacing, between_child_spacing));
1792 current_profile_card_->AddChildView(current_profile_photo); 1415 current_profile_card_->AddChildView(current_profile_photo);
1793 current_profile_card_->AddChildView(profile_name_container); 1416 current_profile_card_->AddChildView(profile_name_container);
1794 current_profile_card_->SetMinSize(gfx::Size( 1417 current_profile_card_->SetMinSize(
1795 GetFixedMenuWidth(), current_profile_photo->GetPreferredSize().height() + 1418 gfx::Size(kFixedMenuWidth,
1796 2 * views::kRelatedControlSmallVerticalSpacing)); 1419 current_profile_photo->GetPreferredSize().height() +
1420 2 * views::kRelatedControlSmallVerticalSpacing));
1797 view->AddChildView(current_profile_card_); 1421 view->AddChildView(current_profile_card_);
1798 1422
1799 if (is_guest) { 1423 if (is_guest) {
1800 current_profile_card_->SetEnabled(false); 1424 current_profile_card_->SetEnabled(false);
1801 return view; 1425 return view;
1802 } 1426 }
1803 1427
1804 const base::string16 profile_name = 1428 const base::string16 profile_name =
1805 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()); 1429 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath());
1806 1430
1807 // The available links depend on the type of profile that is active. 1431 // The available links depend on the type of profile that is active.
1808 if (avatar_item.signed_in) { 1432 if (avatar_item.signed_in) {
1809 if (switches::IsEnableAccountConsistency()) { 1433 if (switches::IsEnableAccountConsistency()) {
1810 base::string16 button_text = l10n_util::GetStringUTF16( 1434 base::string16 button_text = l10n_util::GetStringUTF16(
1811 IsProfileChooser(view_mode_) 1435 IsProfileChooser(view_mode_)
1812 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON 1436 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON
1813 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); 1437 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
1814 manage_accounts_button_ = 1438 manage_accounts_button_ =
1815 new BackgroundColorHoverButton(this, button_text); 1439 new BackgroundColorHoverButton(this, button_text);
1816 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1440 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1817 manage_accounts_button_->SetMinSize( 1441 manage_accounts_button_->SetMinSize(
1818 gfx::Size(GetFixedMenuWidth(), kButtonHeight)); 1442 gfx::Size(kFixedMenuWidth, kButtonHeight));
1819 view->AddChildView(manage_accounts_button_); 1443 view->AddChildView(manage_accounts_button_);
1820 } else { 1444 } else {
1821 views::Label* email_label = new views::Label(avatar_item.username); 1445 views::Label* email_label = new views::Label(avatar_item.username);
1822 current_profile_card->set_subtitle(email_label); 1446 current_profile_card->set_subtitle(email_label);
1823 email_label->SetAutoColorReadabilityEnabled(false); 1447 email_label->SetAutoColorReadabilityEnabled(false);
1824 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); 1448 email_label->SetElideBehavior(gfx::ELIDE_EMAIL);
1825 email_label->SetEnabled(false); 1449 email_label->SetEnabled(false);
1826 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1450 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
1827 name_container_v_spacing = 1451 name_container_v_spacing =
1828 (current_profile_photo->GetPreferredSize().height() - 1452 (current_profile_photo->GetPreferredSize().height() -
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 views::View* ProfileChooserView::CreateGuestProfileView() { 1503 views::View* ProfileChooserView::CreateGuestProfileView() {
1880 gfx::Image guest_icon = 1504 gfx::Image guest_icon =
1881 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 1505 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
1882 profiles::GetPlaceholderAvatarIconResourceID()); 1506 profiles::GetPlaceholderAvatarIconResourceID());
1883 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); 1507 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon);
1884 guest_avatar_item.active = true; 1508 guest_avatar_item.active = true;
1885 guest_avatar_item.name = l10n_util::GetStringUTF16( 1509 guest_avatar_item.name = l10n_util::GetStringUTF16(
1886 IDS_PROFILES_GUEST_PROFILE_NAME); 1510 IDS_PROFILES_GUEST_PROFILE_NAME);
1887 guest_avatar_item.signed_in = false; 1511 guest_avatar_item.signed_in = false;
1888 1512
1889 return switches::IsMaterialDesignUserMenu() 1513 return CreateMaterialDesignCurrentProfileView(guest_avatar_item, true);
1890 ? CreateMaterialDesignCurrentProfileView(guest_avatar_item, true)
1891 : CreateCurrentProfileView(guest_avatar_item, true);
1892 } 1514 }
1893 1515
1894 views::View* ProfileChooserView::CreateOtherProfilesView( 1516 views::View* ProfileChooserView::CreateOtherProfilesView(
1895 const Indexes& avatars_to_show) { 1517 const Indexes& avatars_to_show) {
1896 views::View* view = new views::View(); 1518 views::View* view = new views::View();
1897 views::GridLayout* layout = 1519 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
1898 CreateSingleColumnLayout(view, GetFixedMenuWidth());
1899 1520
1900 for (size_t index : avatars_to_show) { 1521 for (size_t index : avatars_to_show) {
1901 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index); 1522 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index);
1902 const int kSmallImageSide = 32; 1523 const int kSmallImageSide = 32;
1903 1524
1904 // Use the low-res, small default avatars in the fast user switcher, like 1525 // Use the low-res, small default avatars in the fast user switcher, like
1905 // we do in the menu bar. 1526 // we do in the menu bar.
1906 gfx::Image item_icon; 1527 gfx::Image item_icon;
1907 AvatarMenu::GetImageForMenuButton(item.profile_path, &item_icon); 1528 AvatarMenu::GetImageForMenuButton(item.profile_path, &item_icon);
1908 1529
(...skipping 11 matching lines...) Expand all
1920 layout->StartRow(1, 0); 1541 layout->StartRow(1, 0);
1921 layout->AddView(button); 1542 layout->AddView(button);
1922 } 1543 }
1923 1544
1924 return view; 1545 return view;
1925 } 1546 }
1926 1547
1927 views::View* ProfileChooserView::CreateOptionsView(bool display_lock, 1548 views::View* ProfileChooserView::CreateOptionsView(bool display_lock,
1928 AvatarMenu* avatar_menu) { 1549 AvatarMenu* avatar_menu) {
1929 views::View* view = new views::View(); 1550 views::View* view = new views::View();
1930 views::GridLayout* layout = 1551 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
1931 CreateSingleColumnLayout(view, GetFixedMenuWidth());
1932 1552
1933 const bool is_guest = browser_->profile()->IsGuestSession(); 1553 const bool is_guest = browser_->profile()->IsGuestSession();
1934 const int kIconSize = switches::IsMaterialDesignUserMenu() ? 20 : 16; 1554 const int kIconSize = 20;
1935 if (switches::IsMaterialDesignUserMenu()) { 1555 // Add the user switching buttons
1936 // Add the user switching buttons 1556 const int kProfileIconSize = 18;
1937 const int kProfileIconSize = 18; 1557 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing);
1938 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); 1558 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
1939 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { 1559 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
1940 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); 1560 if (!item.active) {
1941 if (!item.active) { 1561 gfx::Image image = profiles::GetSizedAvatarIcon(
1942 gfx::Image image = profiles::GetSizedAvatarIcon( 1562 item.icon, true, kProfileIconSize, kProfileIconSize,
1943 item.icon, true, kProfileIconSize, kProfileIconSize, 1563 profiles::SHAPE_CIRCLE);
1944 profiles::SHAPE_CIRCLE); 1564 views::LabelButton* button = new BackgroundColorHoverButton(
1945 views::LabelButton* button = new BackgroundColorHoverButton( 1565 this, profiles::GetProfileSwitcherTextForItem(item),
1946 this, profiles::GetProfileSwitcherTextForItem(item), 1566 *image.ToImageSkia());
1947 *image.ToImageSkia()); 1567 button->SetImageLabelSpacing(kMaterialMenuEdgeMargin);
1948 button->SetImageLabelSpacing(kMaterialMenuEdgeMargin); 1568 open_other_profile_indexes_map_[button] = i;
1949 open_other_profile_indexes_map_[button] = i;
1950 1569
1951 if (!first_profile_button_) 1570 if (!first_profile_button_)
1952 first_profile_button_ = button; 1571 first_profile_button_ = button;
1953 layout->StartRow(1, 0); 1572 layout->StartRow(1, 0);
1954 layout->AddView(button); 1573 layout->AddView(button);
1955 }
1956 }
1957
1958 // Add the "Guest" button for browsing as guest
1959 if (!is_guest) {
1960 PrefService* service = g_browser_process->local_state();
1961 DCHECK(service);
1962 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) {
1963 guest_profile_button_ = new BackgroundColorHoverButton(
1964 this, l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME),
1965 gfx::CreateVectorIcon(gfx::VectorIconId::ACCOUNT_CIRCLE, kIconSize,
1966 gfx::kChromeIconGrey));
1967 layout->StartRow(1, 0);
1968 layout->AddView(guest_profile_button_);
1969 }
1970 } 1574 }
1971 } 1575 }
1972 1576
1973 base::string16 text; 1577 // Add the "Guest" button for browsing as guest
1974 gfx::VectorIconId settings_icon; 1578 if (!is_guest) {
1975 if (switches::IsMaterialDesignUserMenu()) { 1579 PrefService* service = g_browser_process->local_state();
1976 text = is_guest 1580 DCHECK(service);
1977 ? l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) 1581 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) {
1582 guest_profile_button_ = new BackgroundColorHoverButton(
1583 this, l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME),
1584 gfx::CreateVectorIcon(gfx::VectorIconId::ACCOUNT_CIRCLE, kIconSize,
1585 gfx::kChromeIconGrey));
1586 layout->StartRow(1, 0);
1587 layout->AddView(guest_profile_button_);
1588 }
1589 }
1590
1591 base::string16 text =
1592 is_guest ? l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST)
1978 : l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON); 1593 : l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON);
1979 settings_icon = 1594 gfx::VectorIconId settings_icon =
1980 is_guest ? gfx::VectorIconId::CLOSE_ALL : gfx::VectorIconId::SETTINGS; 1595 is_guest ? gfx::VectorIconId::CLOSE_ALL : gfx::VectorIconId::SETTINGS;
1981 } else {
1982 text = is_guest
1983 ? l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST)
1984 : l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON);
1985 settings_icon = gfx::VectorIconId::ACCOUNT_BOX;
1986 }
1987 users_button_ = new BackgroundColorHoverButton( 1596 users_button_ = new BackgroundColorHoverButton(
1988 this, text, gfx::CreateVectorIcon(settings_icon, kIconSize, 1597 this, text, gfx::CreateVectorIcon(settings_icon, kIconSize,
1989 gfx::kChromeIconGrey)); 1598 gfx::kChromeIconGrey));
1990 1599
1991 layout->StartRow(1, 0); 1600 layout->StartRow(1, 0);
1992 layout->AddView(users_button_); 1601 layout->AddView(users_button_);
1993 1602
1994 if (!switches::IsMaterialDesignUserMenu() && ShouldShowGoIncognito()) {
1995 layout->StartRow(1, 0);
1996 layout->AddView(new views::Separator());
1997
1998 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1999 go_incognito_button_ = new BackgroundColorHoverButton(
2000 this,
2001 l10n_util::GetStringUTF16(IDS_PROFILES_GO_INCOGNITO_BUTTON),
2002 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_INCOGNITO));
2003 layout->StartRow(1, 0);
2004 layout->AddView(go_incognito_button_);
2005 }
2006
2007 if (display_lock) { 1603 if (display_lock) {
2008 if (!switches::IsMaterialDesignUserMenu()) {
2009 layout->StartRow(1, 0);
2010 layout->AddView(new views::Separator());
2011 }
2012
2013 lock_button_ = new BackgroundColorHoverButton( 1604 lock_button_ = new BackgroundColorHoverButton(
2014 this, l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON), 1605 this, l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON),
2015 gfx::CreateVectorIcon(gfx::VectorIconId::LOCK, kIconSize, 1606 gfx::CreateVectorIcon(gfx::VectorIconId::LOCK, kIconSize,
2016 gfx::kChromeIconGrey)); 1607 gfx::kChromeIconGrey));
2017 layout->StartRow(1, 0); 1608 layout->StartRow(1, 0);
2018 layout->AddView(lock_button_); 1609 layout->AddView(lock_button_);
2019 } else if (switches::IsMaterialDesignUserMenu() && !is_guest) { 1610 } else if (!is_guest) {
2020 int num_browsers = 0; 1611 int num_browsers = 0;
2021 for (auto* browser : *BrowserList::GetInstance()) { 1612 for (auto* browser : *BrowserList::GetInstance()) {
2022 if (browser->profile()->GetOriginalProfile() == 1613 if (browser->profile()->GetOriginalProfile() ==
2023 browser_->profile()->GetOriginalProfile()) 1614 browser_->profile()->GetOriginalProfile())
2024 num_browsers++; 1615 num_browsers++;
2025 } 1616 }
2026 if (num_browsers > 1) { 1617 if (num_browsers > 1) {
2027 close_all_windows_button_ = new BackgroundColorHoverButton( 1618 close_all_windows_button_ = new BackgroundColorHoverButton(
2028 this, 1619 this,
2029 l10n_util::GetStringUTF16(IDS_PROFILES_CLOSE_ALL_WINDOWS_BUTTON), 1620 l10n_util::GetStringUTF16(IDS_PROFILES_CLOSE_ALL_WINDOWS_BUTTON),
2030 gfx::CreateVectorIcon(gfx::VectorIconId::CLOSE_ALL, kIconSize, 1621 gfx::CreateVectorIcon(gfx::VectorIconId::CLOSE_ALL, kIconSize,
2031 gfx::kChromeIconGrey)); 1622 gfx::kChromeIconGrey));
2032 layout->StartRow(1, 0); 1623 layout->StartRow(1, 0);
2033 layout->AddView(close_all_windows_button_); 1624 layout->AddView(close_all_windows_button_);
2034 } 1625 }
2035 } 1626 }
2036 1627
2037 if (switches::IsMaterialDesignUserMenu()) 1628 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing);
2038 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing);
2039 return view; 1629 return view;
2040 } 1630 }
2041 1631
2042 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() { 1632 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() {
2043 views::View* view = new views::View(); 1633 views::View* view = new views::View();
2044 int horizontal_margin = switches::IsMaterialDesignUserMenu() ? 1634 int horizontal_margin = kMaterialMenuEdgeMargin;
2045 kMaterialMenuEdgeMargin : views::kButtonHEdgeMarginNew; 1635 views::GridLayout* layout =
2046 views::GridLayout* layout = CreateSingleColumnLayout( 1636 CreateSingleColumnLayout(view, kFixedMenuWidth - 2 * horizontal_margin);
2047 view, GetFixedMenuWidth() - 2 * horizontal_margin); 1637 layout->SetInsets(0, horizontal_margin, kMaterialMenuEdgeMargin,
2048 if (switches::IsMaterialDesignUserMenu()) { 1638 horizontal_margin);
2049 layout->SetInsets(0, horizontal_margin,
2050 kMaterialMenuEdgeMargin, horizontal_margin);
2051 } else {
2052 layout->SetInsets(
2053 views::kRelatedControlVerticalSpacing, horizontal_margin,
2054 views::kRelatedControlVerticalSpacing, horizontal_margin);
2055 }
2056 1639
2057 views::Label* disclaimer = new views::Label( 1640 views::Label* disclaimer = new views::Label(
2058 avatar_menu_->GetSupervisedUserInformation()); 1641 avatar_menu_->GetSupervisedUserInformation());
2059 disclaimer->SetMultiLine(true); 1642 disclaimer->SetMultiLine(true);
2060 disclaimer->SetAllowCharacterBreak(true); 1643 disclaimer->SetAllowCharacterBreak(true);
2061 disclaimer->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1644 disclaimer->SetHorizontalAlignment(gfx::ALIGN_LEFT);
2062 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1645 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
2063 disclaimer->SetFontList(rb->GetFontList(ui::ResourceBundle::SmallFont)); 1646 disclaimer->SetFontList(rb->GetFontList(ui::ResourceBundle::SmallFont));
2064 layout->StartRow(1, 0); 1647 layout->StartRow(1, 0);
2065 layout->AddView(disclaimer); 1648 layout->AddView(disclaimer);
2066 1649
2067 return view; 1650 return view;
2068 } 1651 }
2069 1652
2070 views::View* ProfileChooserView::CreateCurrentProfileAccountsView( 1653 views::View* ProfileChooserView::CreateCurrentProfileAccountsView(
2071 const AvatarMenu::Item& avatar_item) { 1654 const AvatarMenu::Item& avatar_item) {
2072 DCHECK(avatar_item.signed_in); 1655 DCHECK(avatar_item.signed_in);
2073 views::View* view = new views::View(); 1656 views::View* view = new views::View();
2074 view->set_background(views::Background::CreateSolidBackground( 1657 view->set_background(views::Background::CreateSolidBackground(
2075 profiles::kAvatarBubbleAccountsBackgroundColor)); 1658 profiles::kAvatarBubbleAccountsBackgroundColor));
2076 views::GridLayout* layout = 1659 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
2077 CreateSingleColumnLayout(view, GetFixedMenuWidth());
2078 1660
2079 Profile* profile = browser_->profile(); 1661 Profile* profile = browser_->profile();
2080 std::string primary_account = 1662 std::string primary_account =
2081 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); 1663 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
2082 DCHECK(!primary_account.empty()); 1664 DCHECK(!primary_account.empty());
2083 std::vector<std::string>accounts = 1665 std::vector<std::string>accounts =
2084 profiles::GetSecondaryAccountsForProfile(profile, primary_account); 1666 profiles::GetSecondaryAccountsForProfile(profile, primary_account);
2085 1667
2086 // Get state of authentication error, if any. 1668 // Get state of authentication error, if any.
2087 std::string error_account_id = GetAuthErrorAccountId(profile); 1669 std::string error_account_id = GetAuthErrorAccountId(profile);
2088 1670
2089 // The primary account should always be listed first. 1671 // The primary account should always be listed first.
2090 // TODO(rogerta): we still need to further differentiate the primary account 1672 // TODO(rogerta): we still need to further differentiate the primary account
2091 // from the others in the UI, so more work is likely required here: 1673 // from the others in the UI, so more work is likely required here:
2092 // crbug.com/311124. 1674 // crbug.com/311124.
2093 CreateAccountButton(layout, primary_account, true, 1675 CreateAccountButton(layout, primary_account, true,
2094 error_account_id == primary_account, GetFixedMenuWidth()); 1676 error_account_id == primary_account, kFixedMenuWidth);
2095 for (size_t i = 0; i < accounts.size(); ++i) 1677 for (size_t i = 0; i < accounts.size(); ++i)
2096 CreateAccountButton(layout, accounts[i], false, 1678 CreateAccountButton(layout, accounts[i], false,
2097 error_account_id == accounts[i], GetFixedMenuWidth()); 1679 error_account_id == accounts[i], kFixedMenuWidth);
2098 1680
2099 if (!profile->IsSupervised()) { 1681 if (!profile->IsSupervised()) {
2100 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 1682 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
2101 1683
2102 add_account_link_ = CreateLink(l10n_util::GetStringFUTF16( 1684 add_account_link_ = CreateLink(l10n_util::GetStringFUTF16(
2103 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this); 1685 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this);
2104 add_account_link_->SetBorder( 1686 add_account_link_->SetBorder(
2105 views::CreateEmptyBorder(0, views::kButtonVEdgeMarginNew, 1687 views::CreateEmptyBorder(0, views::kButtonVEdgeMarginNew,
2106 views::kRelatedControlVerticalSpacing, 0)); 1688 views::kRelatedControlVerticalSpacing, 0));
2107 layout->StartRow(1, 0); 1689 layout->StartRow(1, 0);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1979 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2398 IncognitoModePrefs::DISABLED; 1980 IncognitoModePrefs::DISABLED;
2399 return incognito_available && !browser_->profile()->IsGuestSession(); 1981 return incognito_available && !browser_->profile()->IsGuestSession();
2400 } 1982 }
2401 1983
2402 void ProfileChooserView::PostActionPerformed( 1984 void ProfileChooserView::PostActionPerformed(
2403 ProfileMetrics::ProfileDesktopMenu action_performed) { 1985 ProfileMetrics::ProfileDesktopMenu action_performed) {
2404 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1986 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
2405 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1987 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
2406 } 1988 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698