Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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; | |
| 93 | 93 |
| 94 const int kTextfieldLabelHorizontalSpacing = 4; | |
| 95 const int kProfileHorizontalSpacing = 16; | |
| 94 const int kVerticalSpacing = 16; | 96 const int kVerticalSpacing = 16; |
| 95 | 97 |
| 96 const int kTitleViewNativeWidgetOffset = 8; | 98 const int kTitleViewNativeWidgetOffset = 8; |
| 97 | 99 |
| 98 bool IsProfileChooser(profiles::BubbleViewMode mode) { | 100 bool IsProfileChooser(profiles::BubbleViewMode mode) { |
| 99 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || | 101 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || |
| 100 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; | 102 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; |
| 101 } | 103 } |
| 102 | 104 |
| 103 // Creates a GridLayout with a single column. This ensures that all the child | 105 // 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. | 106 // views added get auto-expanded to fill the full width of the bubble. |
| 105 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { | 107 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { |
|
Evan Stade
2016/06/10 17:39:46
I don't understand why this exists instead of usin
Jane
2016/06/10 18:49:16
I wouldn't know why this got created initially eit
Evan Stade
2016/06/10 19:53:34
I'd at least not add another usage of it. Create a
Jane
2016/06/10 21:09:42
That sounds like a reasonable suggestion. However,
Evan Stade
2016/06/13 16:36:02
Are you talking about updates to existing code or
Jane
2016/06/13 20:46:05
I replaced the GridLayout with BoxLayout in the la
| |
| 106 views::GridLayout* layout = new views::GridLayout(view); | 108 views::GridLayout* layout = new views::GridLayout(view); |
| 107 view->SetLayoutManager(layout); | 109 view->SetLayoutManager(layout); |
| 108 | 110 |
| 109 views::ColumnSet* columns = layout->AddColumnSet(0); | 111 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 110 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 112 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 111 views::GridLayout::FIXED, width, width); | 113 views::GridLayout::FIXED, width, width); |
| 112 return layout; | 114 return layout; |
| 113 } | 115 } |
| 114 | 116 |
| 115 views::Link* CreateLink(const base::string16& link_text, | 117 views::Link* CreateLink(const base::string16& link_text, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 gfx::Rect bounds(title_view_->GetPreferredSize()); | 258 gfx::Rect bounds(title_view_->GetPreferredSize()); |
| 257 title_view_->SetBoundsRect(bounds); | 259 title_view_->SetBoundsRect(bounds); |
| 258 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset); | 260 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset); |
| 259 title_widget_->SetBounds(bounds); | 261 title_widget_->SetBounds(bounds); |
| 260 } | 262 } |
| 261 | 263 |
| 262 } // namespace | 264 } // namespace |
| 263 | 265 |
| 264 // RightAlignedIconLabelButton ------------------------------------------------- | 266 // RightAlignedIconLabelButton ------------------------------------------------- |
| 265 | 267 |
| 266 // A custom LabelButton that has a centered text and right aligned icon. | 268 // A custom LabelButton that has a left-aligned text and right aligned icon. |
| 269 // For non-material-design user menu, it has centered text instead. | |
| 267 class RightAlignedIconLabelButton : public views::LabelButton { | 270 class RightAlignedIconLabelButton : public views::LabelButton { |
| 268 public: | 271 public: |
| 269 RightAlignedIconLabelButton(views::ButtonListener* listener, | 272 RightAlignedIconLabelButton(views::ButtonListener* listener, |
| 270 const base::string16& text) | 273 const base::string16& text) |
| 271 : views::LabelButton(listener, text) { | 274 : views::LabelButton(listener, text) { |
| 272 SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 275 SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 273 label()->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 276 label()->SetHorizontalAlignment(switches::IsMaterialDesignUserMenu() |
| 277 ? gfx::ALIGN_LEFT : gfx::ALIGN_CENTER); | |
| 274 } | 278 } |
| 275 | 279 |
| 276 protected: | 280 protected: |
| 277 void Layout() override { | 281 void Layout() override { |
| 278 views::LabelButton::Layout(); | 282 views::LabelButton::Layout(); |
| 279 | 283 |
| 280 // Keep the text centered and the icon right-aligned by stretching the label | 284 // 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. | 285 // to take up more of the content area and centering its contents. |
| 282 gfx::Rect content_bounds = GetContentsBounds(); | 286 gfx::Rect content_bounds = GetContentsBounds(); |
| 283 gfx::Rect label_bounds = label()->bounds(); | 287 gfx::Rect label_bounds = label()->bounds(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 301 | 305 |
| 302 // A custom Image control that shows a "change" button when moused over. | 306 // A custom Image control that shows a "change" button when moused over. |
| 303 class EditableProfilePhoto : public views::LabelButton { | 307 class EditableProfilePhoto : public views::LabelButton { |
| 304 public: | 308 public: |
| 305 EditableProfilePhoto(views::ButtonListener* listener, | 309 EditableProfilePhoto(views::ButtonListener* listener, |
| 306 const gfx::Image& icon, | 310 const gfx::Image& icon, |
| 307 bool is_editing_allowed, | 311 bool is_editing_allowed, |
| 308 const gfx::Rect& bounds) | 312 const gfx::Rect& bounds) |
| 309 : views::LabelButton(listener, base::string16()), | 313 : views::LabelButton(listener, base::string16()), |
| 310 photo_overlay_(NULL) { | 314 photo_overlay_(NULL) { |
| 315 const int icon_image_side = switches::IsMaterialDesignUserMenu() | |
| 316 ? kMediumImageSide : kLargeImageSide; | |
| 311 gfx::Image image = profiles::GetSizedAvatarIcon( | 317 gfx::Image image = profiles::GetSizedAvatarIcon( |
| 312 icon, true, kLargeImageSide, kLargeImageSide); | 318 icon, true, icon_image_side, icon_image_side); |
| 313 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); | 319 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); |
| 314 SetBorder(views::Border::NullBorder()); | 320 SetBorder(views::Border::NullBorder()); |
| 315 SetBoundsRect(bounds); | 321 SetBoundsRect(bounds); |
| 316 | 322 |
| 317 // Calculate the circular mask that will be used to display the photo. | 323 // Calculate the circular mask that will be used to display the photo. |
| 318 circular_mask_.addCircle(SkIntToScalar(bounds.width() / 2), | 324 circular_mask_.addCircle(SkIntToScalar(bounds.width() / 2), |
| 319 SkIntToScalar(bounds.height() / 2), | 325 SkIntToScalar(bounds.height() / 2), |
| 320 SkIntToScalar(bounds.width() / 2)); | 326 SkIntToScalar(bounds.width() / 2)); |
| 321 | 327 |
| 322 if (!is_editing_allowed) { | 328 if (!is_editing_allowed) { |
| 323 SetEnabled(false); | 329 SetEnabled(false); |
| 324 return; | 330 return; |
| 325 } | 331 } |
| 326 | 332 |
| 327 set_notify_enter_exit_on_child(true); | 333 set_notify_enter_exit_on_child(true); |
| 328 | 334 |
| 329 // Photo overlay that appears when hovering over the button. | 335 // Photo overlay that appears when hovering over the button. |
| 330 photo_overlay_ = new views::ImageView(); | 336 photo_overlay_ = new views::ImageView(); |
| 331 | 337 |
| 332 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); | 338 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); |
| 333 photo_overlay_->set_background( | 339 photo_overlay_->set_background( |
| 334 views::Background::CreateSolidBackground(kBackgroundColor)); | 340 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 335 photo_overlay_->SetImage(gfx::CreateVectorIcon( | 341 photo_overlay_->SetImage(gfx::CreateVectorIcon( |
| 336 gfx::VectorIconId::PHOTO_CAMERA, 48u, SkColorSetRGB(0x33, 0x33, 0x33))); | 342 gfx::VectorIconId::PHOTO_CAMERA, |
| 343 switches::IsMaterialDesignUserMenu() ? 22u : 48u, | |
| 344 SkColorSetRGB(0x33, 0x33, 0x33))); | |
| 337 | 345 |
| 338 photo_overlay_->SetSize(bounds.size()); | 346 photo_overlay_->SetSize(bounds.size()); |
| 339 photo_overlay_->SetVisible(false); | 347 photo_overlay_->SetVisible(false); |
| 340 AddChildView(photo_overlay_); | 348 AddChildView(photo_overlay_); |
| 341 } | 349 } |
| 342 | 350 |
| 343 void OnPaint(gfx::Canvas* canvas) override { | 351 void OnPaint(gfx::Canvas* canvas) override { |
| 344 // Display the profile picture as a circle. | 352 // Display the profile picture as a circle. |
| 345 canvas->ClipPath(circular_mask_, true); | 353 canvas->ClipPath(circular_mask_, true); |
| 346 views::LabelButton::OnPaint(canvas); | 354 views::LabelButton::OnPaint(canvas); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 406 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 399 | 407 |
| 400 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 408 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 401 const gfx::FontList& medium_font_list = | 409 const gfx::FontList& medium_font_list = |
| 402 rb->GetFontList(ui::ResourceBundle::MediumFont); | 410 rb->GetFontList(ui::ResourceBundle::MediumFont); |
| 403 | 411 |
| 404 if (!is_editing_allowed) { | 412 if (!is_editing_allowed) { |
| 405 label_ = new views::Label(text); | 413 label_ = new views::Label(text); |
| 406 label_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); | 414 label_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); |
| 407 label_->SetFontList(medium_font_list); | 415 label_->SetFontList(medium_font_list); |
| 416 if (switches::IsMaterialDesignUserMenu()) | |
| 417 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 408 AddChildView(label_); | 418 AddChildView(label_); |
| 409 return; | 419 return; |
| 410 } | 420 } |
| 411 | 421 |
| 412 button_ = new RightAlignedIconLabelButton(this, text); | 422 button_ = new RightAlignedIconLabelButton(this, text); |
| 413 button_->SetFontList(medium_font_list); | 423 button_->SetFontList(medium_font_list); |
| 414 // Show an "edit" pencil icon when hovering over. In the default state, | 424 // 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 | 425 // 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. | 426 // the text doesn't jump around when the hovered icon appears. |
| 417 // TODO(estade): revisit colors and press effect. | 427 // TODO(estade): revisit colors and press effect. |
| 418 const int kIconSize = 16; | 428 const int kIconSize = 16; |
| 419 button_->SetImage(views::LabelButton::STATE_NORMAL, | 429 button_->SetImage(views::LabelButton::STATE_NORMAL, |
| 420 CreateSquarePlaceholderImage(kIconSize)); | 430 CreateSquarePlaceholderImage(kIconSize)); |
| 421 button_->SetImage(views::LabelButton::STATE_HOVERED, | 431 button_->SetImage(views::LabelButton::STATE_HOVERED, |
| 422 gfx::CreateVectorIcon( | 432 gfx::CreateVectorIcon( |
| 423 gfx::VectorIconId::MODE_EDIT, kIconSize, | 433 gfx::VectorIconId::MODE_EDIT, kIconSize, |
| 424 SkColorSetRGB(0x33, 0x33, 0x33))); | 434 SkColorSetRGB(0x33, 0x33, 0x33))); |
| 425 button_->SetImage(views::LabelButton::STATE_PRESSED, | 435 button_->SetImage(views::LabelButton::STATE_PRESSED, |
| 426 gfx::CreateVectorIcon( | 436 gfx::CreateVectorIcon( |
| 427 gfx::VectorIconId::MODE_EDIT, kIconSize, | 437 gfx::VectorIconId::MODE_EDIT, kIconSize, |
| 428 SkColorSetRGB(0x20, 0x20, 0x20))); | 438 SkColorSetRGB(0x20, 0x20, 0x20))); |
| 429 // To center the text, we need to offest it by the width of the icon we | 439 // 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 | 440 // to the text to account for the textfield's border. |
| 431 // padding to account for the textfield's border. | 441 if (switches::IsMaterialDesignUserMenu()) { |
| 432 const int kIconTextLabelButtonSpacing = 5; | 442 button_->SetBorder(views::Border::CreateEmptyBorder( |
| 433 button_->SetBorder(views::Border::CreateEmptyBorder( | 443 2, kTextfieldLabelHorizontalSpacing, 2, 0)); |
| 434 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); | 444 } else { |
| 445 const int kIconTextLabelButtonSpacing = 5; | |
| 446 button_->SetBorder(views::Border::CreateEmptyBorder( | |
| 447 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); | |
| 448 } | |
| 435 AddChildView(button_); | 449 AddChildView(button_); |
| 436 | 450 |
| 437 profile_name_textfield_ = new views::Textfield(); | 451 profile_name_textfield_ = new views::Textfield(); |
| 438 // Textfield that overlaps the button. | 452 // Textfield that overlaps the button. |
| 439 profile_name_textfield_->set_controller(controller); | 453 profile_name_textfield_->set_controller(controller); |
| 440 profile_name_textfield_->SetFontList(medium_font_list); | 454 profile_name_textfield_->SetFontList(medium_font_list); |
| 441 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 455 profile_name_textfield_->SetHorizontalAlignment( |
| 456 switches::IsMaterialDesignUserMenu() | |
| 457 ? gfx::ALIGN_LEFT : gfx::ALIGN_CENTER); | |
| 442 profile_name_textfield_->SetVisible(false); | 458 profile_name_textfield_->SetVisible(false); |
| 443 AddChildView(profile_name_textfield_); | 459 AddChildView(profile_name_textfield_); |
| 444 } | 460 } |
| 445 | 461 |
| 446 views::Textfield* profile_name_textfield() { | 462 views::Textfield* profile_name_textfield() { |
| 447 return profile_name_textfield_; | 463 return profile_name_textfield_; |
| 448 } | 464 } |
| 449 | 465 |
| 450 // Hide the editable textfield to show the profile name button instead. | 466 // Hide the editable textfield to show the profile name button instead. |
| 451 void ShowReadOnlyView() { | 467 void ShowReadOnlyView() { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 | 574 |
| 559 views::ImageButton* back_button_; | 575 views::ImageButton* back_button_; |
| 560 views::Label* title_label_; | 576 views::Label* title_label_; |
| 561 | 577 |
| 562 DISALLOW_COPY_AND_ASSIGN(TitleCard); | 578 DISALLOW_COPY_AND_ASSIGN(TitleCard); |
| 563 }; | 579 }; |
| 564 | 580 |
| 565 // ProfileBadge -------------------------------------------------------- | 581 // ProfileBadge -------------------------------------------------------- |
| 566 | 582 |
| 567 const size_t kProfileBadgeSize = 30; | 583 const size_t kProfileBadgeSize = 30; |
| 584 const size_t kSmallProfileBadgeSize = 24; | |
| 568 const size_t kProfileBadgeWhitePadding = 2; | 585 const size_t kProfileBadgeWhitePadding = 2; |
| 569 | 586 |
| 570 // Draws a white circle, then a light blue circle, then a dark blue icon. | 587 // Draws a white circle, then a light blue circle, then a dark blue icon. |
| 571 class ProfileBadge : public gfx::CanvasImageSource { | 588 class ProfileBadge : public gfx::CanvasImageSource { |
| 572 public: | 589 public: |
| 573 ProfileBadge(gfx::VectorIconId id, size_t icon_size) | 590 ProfileBadge(gfx::VectorIconId id, size_t icon_size) |
| 574 : CanvasImageSource(gfx::Size(kProfileBadgeSize, kProfileBadgeSize), | 591 : CanvasImageSource(gfx::Size( |
| 592 switches::IsMaterialDesignUserMenu() | |
| 593 ? kSmallProfileBadgeSize : kProfileBadgeSize, | |
|
Evan Stade
2016/06/10 17:39:46
is this the output of git cl format?
Jane
2016/06/10 18:49:16
Missed it, now it is.
| |
| 594 switches::IsMaterialDesignUserMenu() | |
| 595 ? kSmallProfileBadgeSize : kProfileBadgeSize), | |
| 575 false), | 596 false), |
| 576 id_(id), | 597 id_(id), |
| 577 icon_size_(icon_size) {} | 598 icon_size_(icon_size) {} |
| 578 | 599 |
| 579 ~ProfileBadge() override {} | 600 ~ProfileBadge() override {} |
| 580 | 601 |
| 581 // CanvasImageSource: | 602 // CanvasImageSource: |
| 582 void Draw(gfx::Canvas* canvas) override { | 603 void Draw(gfx::Canvas* canvas) override { |
| 583 const SkISize size = canvas->sk_canvas()->getBaseLayerSize(); | 604 const SkISize size = canvas->sk_canvas()->getBaseLayerSize(); |
| 584 gfx::Rect bounds(0, 0, size.width(), size.height()); | 605 gfx::Rect bounds(0, 0, size.width(), size.height()); |
| 585 | 606 |
| 586 SkPaint paint; | 607 SkPaint paint; |
| 587 paint.setAntiAlias(true); | 608 paint.setAntiAlias(true); |
| 588 paint.setColor(SK_ColorWHITE); | 609 paint.setColor(SK_ColorWHITE); |
| 589 canvas->DrawCircle(bounds.CenterPoint(), size.width() / 2, paint); | 610 canvas->DrawCircle(bounds.CenterPoint(), size.width() / 2, paint); |
| 590 | 611 |
| 591 paint.setColor(SkColorSetRGB(0xAF, 0xD9, 0xFC)); | 612 paint.setColor(SkColorSetRGB(0xAF, 0xD9, 0xFC)); |
| 592 canvas->DrawCircle(bounds.CenterPoint(), | 613 canvas->DrawCircle(bounds.CenterPoint(), |
| 593 size.width() / 2 - kProfileBadgeWhitePadding, paint); | 614 size.width() / 2 - kProfileBadgeWhitePadding, paint); |
| 594 | 615 |
| 595 int offset = (kProfileBadgeSize - icon_size_) / 2; | 616 int offset = ((switches::IsMaterialDesignUserMenu() |
| 617 ? kSmallProfileBadgeSize : kProfileBadgeSize) | |
| 618 - icon_size_) / 2; | |
| 596 canvas->Translate(gfx::Vector2d(offset, offset)); | 619 canvas->Translate(gfx::Vector2d(offset, offset)); |
| 597 gfx::PaintVectorIcon(canvas, id_, icon_size_, SkColorSetRGB(0, 0x66, 0xff)); | 620 gfx::PaintVectorIcon(canvas, id_, icon_size_, SkColorSetRGB(0, 0x66, 0xff)); |
| 598 } | 621 } |
| 599 | 622 |
| 600 private: | 623 private: |
| 601 const gfx::VectorIconId id_; | 624 const gfx::VectorIconId id_; |
| 602 const size_t icon_size_; | 625 const size_t icon_size_; |
| 603 | 626 |
| 604 DISALLOW_COPY_AND_ASSIGN(ProfileBadge); | 627 DISALLOW_COPY_AND_ASSIGN(ProfileBadge); |
| 605 }; | 628 }; |
| 606 | 629 |
| 607 gfx::ImageSkia CreateBadgeForProfile(Profile* profile) { | 630 gfx::ImageSkia CreateBadgeForProfile(Profile* profile) { |
| 608 ProfileBadge* badge = | 631 ProfileBadge* badge = profile->IsChild() |
| 609 profile->IsChild() | 632 ? new ProfileBadge(gfx::VectorIconId::ACCOUNT_CHILD_INVERT, |
| 610 ? new ProfileBadge(gfx::VectorIconId::ACCOUNT_CHILD_INVERT, 26) | 633 switches::IsMaterialDesignUserMenu() ? 21 : 26) |
| 611 : new ProfileBadge(gfx::VectorIconId::SUPERVISOR_ACCOUNT, 20); | 634 : new ProfileBadge(gfx::VectorIconId::SUPERVISOR_ACCOUNT, |
| 612 | 635 switches::IsMaterialDesignUserMenu() ? 16 : 20); |
| 613 return gfx::ImageSkia(badge, badge->size()); | 636 return gfx::ImageSkia(badge, badge->size()); |
| 614 } | 637 } |
| 615 | 638 |
| 616 // ProfileChooserView --------------------------------------------------------- | 639 // ProfileChooserView --------------------------------------------------------- |
| 617 | 640 |
| 618 // static | 641 // static |
| 619 ProfileChooserView* ProfileChooserView::profile_bubble_ = nullptr; | 642 ProfileChooserView* ProfileChooserView::profile_bubble_ = nullptr; |
| 620 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; | 643 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; |
| 621 | 644 |
| 622 // static | 645 // static |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 bool ProfileChooserView::IsShowing() { | 680 bool ProfileChooserView::IsShowing() { |
| 658 return profile_bubble_ != NULL; | 681 return profile_bubble_ != NULL; |
| 659 } | 682 } |
| 660 | 683 |
| 661 // static | 684 // static |
| 662 void ProfileChooserView::Hide() { | 685 void ProfileChooserView::Hide() { |
| 663 if (IsShowing()) | 686 if (IsShowing()) |
| 664 profile_bubble_->GetWidget()->Close(); | 687 profile_bubble_->GetWidget()->Close(); |
| 665 } | 688 } |
| 666 | 689 |
| 690 // static | |
| 691 int ProfileChooserView::GetFixedMenuWidth() { | |
| 692 return switches::IsMaterialDesignUserMenu() ? 240 : 250; | |
| 693 } | |
| 694 | |
| 667 ProfileChooserView::ProfileChooserView(views::View* anchor_view, | 695 ProfileChooserView::ProfileChooserView(views::View* anchor_view, |
| 668 Browser* browser, | 696 Browser* browser, |
| 669 profiles::BubbleViewMode view_mode, | 697 profiles::BubbleViewMode view_mode, |
| 670 profiles::TutorialMode tutorial_mode, | 698 profiles::TutorialMode tutorial_mode, |
| 671 signin::GAIAServiceType service_type, | 699 signin::GAIAServiceType service_type, |
| 672 signin_metrics::AccessPoint access_point) | 700 signin_metrics::AccessPoint access_point) |
| 673 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 701 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 674 browser_(browser), | 702 browser_(browser), |
| 675 view_mode_(view_mode), | 703 view_mode_(view_mode), |
| 676 tutorial_mode_(tutorial_mode), | 704 tutorial_mode_(tutorial_mode), |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 831 break; | 859 break; |
| 832 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: | 860 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: |
| 833 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); | 861 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); |
| 834 sub_view = CreateSwitchUserView(); | 862 sub_view = CreateSwitchUserView(); |
| 835 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 863 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
| 836 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW); | 864 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW); |
| 837 break; | 865 break; |
| 838 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: | 866 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: |
| 839 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER: | 867 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER: |
| 840 case profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER: | 868 case profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER: |
| 841 layout = CreateSingleColumnLayout(this, kFixedMenuWidth); | 869 layout = CreateSingleColumnLayout(this, GetFixedMenuWidth()); |
| 842 sub_view = CreateProfileChooserView(avatar_menu); | 870 sub_view = CreateProfileChooserView(avatar_menu); |
| 843 break; | 871 break; |
| 844 } | 872 } |
| 845 // Clears tutorial mode for all non-profile-chooser views. | 873 // Clears tutorial mode for all non-profile-chooser views. |
| 846 if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) | 874 if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) |
| 847 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; | 875 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; |
| 848 | 876 |
| 849 layout->StartRow(1, 0); | 877 layout->StartRow(1, 0); |
| 850 layout->AddView(sub_view); | 878 layout->AddView(sub_view); |
| 851 Layout(); | 879 Layout(); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1077 Indexes other_profiles; | 1105 Indexes other_profiles; |
| 1078 views::View* tutorial_view = NULL; | 1106 views::View* tutorial_view = NULL; |
| 1079 views::View* current_profile_view = NULL; | 1107 views::View* current_profile_view = NULL; |
| 1080 views::View* current_profile_accounts = NULL; | 1108 views::View* current_profile_accounts = NULL; |
| 1081 views::View* option_buttons_view = NULL; | 1109 views::View* option_buttons_view = NULL; |
| 1082 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { | 1110 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { |
| 1083 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); | 1111 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); |
| 1084 if (item.active) { | 1112 if (item.active) { |
| 1085 option_buttons_view = CreateOptionsView( | 1113 option_buttons_view = CreateOptionsView( |
| 1086 item.signed_in && profiles::IsLockAvailable(browser_->profile())); | 1114 item.signed_in && profiles::IsLockAvailable(browser_->profile())); |
| 1087 current_profile_view = CreateCurrentProfileView(item, false); | 1115 current_profile_view = switches::IsMaterialDesignUserMenu() ? |
| 1116 CreateMaterialDesignCurrentProfileView(item, false) : | |
| 1117 CreateCurrentProfileView(item, false); | |
| 1088 if (IsProfileChooser(view_mode_)) { | 1118 if (IsProfileChooser(view_mode_)) { |
| 1089 tutorial_view = CreateTutorialViewIfNeeded(item); | 1119 tutorial_view = CreateTutorialViewIfNeeded(item); |
| 1090 } else { | 1120 } else { |
| 1091 current_profile_accounts = CreateCurrentProfileAccountsView(item); | 1121 current_profile_accounts = CreateCurrentProfileAccountsView(item); |
| 1092 } | 1122 } |
| 1093 } else { | 1123 } else { |
| 1094 other_profiles.push_back(i); | 1124 other_profiles.push_back(i); |
| 1095 } | 1125 } |
| 1096 } | 1126 } |
| 1097 | 1127 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1114 | 1144 |
| 1115 if (!IsProfileChooser(view_mode_)) { | 1145 if (!IsProfileChooser(view_mode_)) { |
| 1116 DCHECK(current_profile_accounts); | 1146 DCHECK(current_profile_accounts); |
| 1117 layout->StartRow(0, 0); | 1147 layout->StartRow(0, 0); |
| 1118 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 1148 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 1119 layout->StartRow(1, 0); | 1149 layout->StartRow(1, 0); |
| 1120 layout->AddView(current_profile_accounts); | 1150 layout->AddView(current_profile_accounts); |
| 1121 } | 1151 } |
| 1122 | 1152 |
| 1123 if (browser_->profile()->IsSupervised()) { | 1153 if (browser_->profile()->IsSupervised()) { |
| 1124 layout->StartRow(0, 0); | 1154 if (!switches::IsMaterialDesignUserMenu()) { |
| 1125 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 1155 layout->StartRow(0, 0); |
| 1156 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | |
| 1157 } | |
| 1126 layout->StartRow(1, 0); | 1158 layout->StartRow(1, 0); |
| 1127 layout->AddView(CreateSupervisedUserDisclaimerView()); | 1159 layout->AddView(CreateSupervisedUserDisclaimerView()); |
| 1128 } | 1160 } |
| 1129 | 1161 |
| 1130 layout->StartRow(0, 0); | 1162 layout->StartRow(0, 0); |
| 1131 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 1163 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 1132 | 1164 |
| 1133 if (option_buttons_view) { | 1165 if (option_buttons_view) { |
| 1134 layout->StartRow(0, 0); | 1166 layout->StartRow(0, 0); |
| 1135 layout->AddView(option_buttons_view); | 1167 layout->AddView(option_buttons_view); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1147 } | 1179 } |
| 1148 } | 1180 } |
| 1149 | 1181 |
| 1150 layout->StartRow(1, 0); | 1182 layout->StartRow(1, 0); |
| 1151 layout->AddView(CreateOtherProfilesView(other_profiles)); | 1183 layout->AddView(CreateOtherProfilesView(other_profiles)); |
| 1152 } | 1184 } |
| 1153 | 1185 |
| 1154 views::View* ProfileChooserView::CreateProfileChooserView( | 1186 views::View* ProfileChooserView::CreateProfileChooserView( |
| 1155 AvatarMenu* avatar_menu) { | 1187 AvatarMenu* avatar_menu) { |
| 1156 views::View* view = new views::View(); | 1188 views::View* view = new views::View(); |
| 1157 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | 1189 views::GridLayout* layout = |
| 1190 CreateSingleColumnLayout(view, GetFixedMenuWidth()); | |
| 1158 | 1191 |
| 1159 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) { | 1192 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) { |
| 1160 PopulateMinimalProfileChooserView(layout, avatar_menu); | 1193 PopulateMinimalProfileChooserView(layout, avatar_menu); |
| 1161 // The user is using right-click switching, no need to tell them about it. | 1194 // The user is using right-click switching, no need to tell them about it. |
| 1162 PrefService* local_state = g_browser_process->local_state(); | 1195 PrefService* local_state = g_browser_process->local_state(); |
| 1163 local_state->SetBoolean( | 1196 local_state->SetBoolean( |
| 1164 prefs::kProfileAvatarRightClickTutorialDismissed, true); | 1197 prefs::kProfileAvatarRightClickTutorialDismissed, true); |
| 1165 } else { | 1198 } else { |
| 1166 PopulateCompleteProfileChooserView(layout, avatar_menu); | 1199 PopulateCompleteProfileChooserView(layout, avatar_menu); |
| 1167 } | 1200 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1223 bool stack_button, | 1256 bool stack_button, |
| 1224 views::Link** link, | 1257 views::Link** link, |
| 1225 views::LabelButton** button, | 1258 views::LabelButton** button, |
| 1226 views::ImageButton** close_button) { | 1259 views::ImageButton** close_button) { |
| 1227 tutorial_mode_ = tutorial_mode; | 1260 tutorial_mode_ = tutorial_mode; |
| 1228 | 1261 |
| 1229 views::View* view = new views::View(); | 1262 views::View* view = new views::View(); |
| 1230 view->set_background(views::Background::CreateSolidBackground( | 1263 view->set_background(views::Background::CreateSolidBackground( |
| 1231 profiles::kAvatarTutorialBackgroundColor)); | 1264 profiles::kAvatarTutorialBackgroundColor)); |
| 1232 views::GridLayout* layout = CreateSingleColumnLayout(view, | 1265 views::GridLayout* layout = CreateSingleColumnLayout(view, |
| 1233 kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); | 1266 GetFixedMenuWidth() - 2 * views::kButtonHEdgeMarginNew); |
| 1234 // Creates a second column set for buttons and links. | 1267 // Creates a second column set for buttons and links. |
| 1235 views::ColumnSet* button_columns = layout->AddColumnSet(1); | 1268 views::ColumnSet* button_columns = layout->AddColumnSet(1); |
| 1236 button_columns->AddColumn(views::GridLayout::LEADING, | 1269 button_columns->AddColumn(views::GridLayout::LEADING, |
| 1237 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); | 1270 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); |
| 1238 button_columns->AddPaddingColumn( | 1271 button_columns->AddPaddingColumn( |
| 1239 1, views::kUnrelatedControlHorizontalSpacing); | 1272 1, views::kUnrelatedControlHorizontalSpacing); |
| 1240 button_columns->AddColumn(views::GridLayout::TRAILING, | 1273 button_columns->AddColumn(views::GridLayout::TRAILING, |
| 1241 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); | 1274 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); |
| 1242 layout->SetInsets(views::kButtonVEdgeMarginNew, | 1275 layout->SetInsets(views::kButtonVEdgeMarginNew, |
| 1243 views::kButtonHEdgeMarginNew, | 1276 views::kButtonHEdgeMarginNew, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1325 layout->SkipColumns(1); | 1358 layout->SkipColumns(1); |
| 1326 } | 1359 } |
| 1327 | 1360 |
| 1328 return view; | 1361 return view; |
| 1329 } | 1362 } |
| 1330 | 1363 |
| 1331 views::View* ProfileChooserView::CreateCurrentProfileView( | 1364 views::View* ProfileChooserView::CreateCurrentProfileView( |
| 1332 const AvatarMenu::Item& avatar_item, | 1365 const AvatarMenu::Item& avatar_item, |
| 1333 bool is_guest) { | 1366 bool is_guest) { |
| 1334 views::View* view = new views::View(); | 1367 views::View* view = new views::View(); |
| 1335 int column_width = kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew; | 1368 int column_width = GetFixedMenuWidth() - 2 * views::kButtonHEdgeMarginNew; |
| 1336 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); | 1369 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); |
| 1337 layout->SetInsets(views::kButtonVEdgeMarginNew, | 1370 layout->SetInsets(views::kButtonVEdgeMarginNew, |
| 1338 views::kButtonHEdgeMarginNew, | 1371 views::kButtonHEdgeMarginNew, |
| 1339 views::kUnrelatedControlVerticalSpacing, | 1372 views::kUnrelatedControlVerticalSpacing, |
| 1340 views::kButtonHEdgeMarginNew); | 1373 views::kButtonHEdgeMarginNew); |
| 1341 | 1374 |
| 1342 // Profile icon, centered. | 1375 // Profile icon, centered. |
| 1343 int x_offset = (column_width - kLargeImageSide) / 2; | 1376 int x_offset = (column_width - kLargeImageSide) / 2; |
| 1344 current_profile_photo_ = new EditableProfilePhoto( | 1377 current_profile_photo_ = new EditableProfilePhoto( |
| 1345 this, avatar_item.icon, !is_guest, | 1378 this, avatar_item.icon, !is_guest, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1438 layout->StartRow(1, 0); | 1471 layout->StartRow(1, 0); |
| 1439 layout->AddView(signin_current_profile_link_); | 1472 layout->AddView(signin_current_profile_link_); |
| 1440 content::RecordAction( | 1473 content::RecordAction( |
| 1441 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); | 1474 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); |
| 1442 } | 1475 } |
| 1443 } | 1476 } |
| 1444 | 1477 |
| 1445 return view; | 1478 return view; |
| 1446 } | 1479 } |
| 1447 | 1480 |
| 1481 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( | |
| 1482 const AvatarMenu::Item& avatar_item, | |
| 1483 bool is_guest) { | |
| 1484 views::View* view = new views::View(); | |
| 1485 int column_width = GetFixedMenuWidth() - 2 * views::kMaterialHorizontalMargin; | |
| 1486 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); | |
| 1487 layout->SetInsets(views::kRelatedControlVerticalSpacing, | |
| 1488 views::kMaterialHorizontalMargin, | |
| 1489 views::kRelatedControlVerticalSpacing, | |
| 1490 views::kMaterialHorizontalMargin); | |
| 1491 | |
| 1492 // Profile picture left aligned for material design user menu, | |
| 1493 // centered otherwise. | |
| 1494 const int profile_bar_height = 56; | |
| 1495 current_profile_photo_ = new EditableProfilePhoto( | |
| 1496 this, avatar_item.icon, !is_guest, | |
| 1497 gfx::Rect(0, (profile_bar_height - kMediumImageSide) / 2, | |
| 1498 kMediumImageSide, kMediumImageSide)); | |
| 1499 SizedContainer* profile_container = | |
| 1500 new SizedContainer(gfx::Size(column_width, profile_bar_height)); | |
| 1501 profile_container->AddChildView(current_profile_photo_); | |
| 1502 | |
| 1503 // Add supervised badge for supervised profile. | |
| 1504 if (browser_->profile()->IsSupervised()) { | |
| 1505 const int badge_spacing = 4; | |
| 1506 views::ImageView* supervised_icon = new views::ImageView(); | |
| 1507 supervised_icon->SetImage(CreateBadgeForProfile(browser_->profile())); | |
| 1508 gfx::Size preferred_size = supervised_icon->GetPreferredSize(); | |
| 1509 gfx::Rect parent_bounds = current_profile_photo_->bounds(); | |
| 1510 supervised_icon->SetBounds( | |
| 1511 parent_bounds.right() - preferred_size.width() + badge_spacing, | |
| 1512 parent_bounds.bottom() - preferred_size.height() + badge_spacing, | |
| 1513 preferred_size.width(), | |
| 1514 preferred_size.height()); | |
| 1515 profile_container->AddChildView(supervised_icon); | |
| 1516 } | |
| 1517 | |
| 1518 // Profile name, left-aligned to the right of profile icon. | |
| 1519 bool editing_allowed = !is_guest && | |
| 1520 !browser_->profile()->IsLegacySupervised(); | |
| 1521 current_profile_name_ = new EditableProfileName( | |
| 1522 this, | |
| 1523 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()), | |
| 1524 editing_allowed); | |
| 1525 gfx::Rect photo_bounds = current_profile_photo_->bounds(); | |
| 1526 const int textfield_left_margin = | |
| 1527 kProfileHorizontalSpacing - | |
| 1528 (editing_allowed ? kTextfieldLabelHorizontalSpacing : 0); | |
| 1529 current_profile_name_->SetBounds( | |
| 1530 photo_bounds.width() + textfield_left_margin, | |
| 1531 views::kRelatedControlVerticalSpacing, | |
| 1532 profile_container->GetPreferredSize().width() - photo_bounds.width() | |
| 1533 - textfield_left_margin, | |
| 1534 profile_container->GetPreferredSize().height() / 2 | |
| 1535 - views::kRelatedControlVerticalSpacing); | |
| 1536 profile_container->AddChildView(current_profile_name_); | |
| 1537 | |
| 1538 // Center-align the avatar name if the profile is not signed in. | |
| 1539 if (is_guest || !avatar_item.signed_in) { | |
| 1540 current_profile_name_->SetY( | |
| 1541 (profile_container->GetPreferredSize().height() | |
| 1542 - current_profile_name_->height()) / 2); | |
| 1543 layout->StartRow(1, 0); | |
| 1544 layout->AddView(profile_container); | |
| 1545 } | |
| 1546 | |
| 1547 if (is_guest) | |
| 1548 return view; | |
| 1549 | |
| 1550 // The available links depend on the type of profile that is active. | |
| 1551 if (avatar_item.signed_in) { | |
| 1552 // Calculate the position and size for links available for signed-in | |
| 1553 // profiles. | |
| 1554 const int x_coordinate = photo_bounds.width() + kProfileHorizontalSpacing; | |
| 1555 const int y_coordinate = profile_container->GetPreferredSize().height() / 2; | |
| 1556 const int width = profile_container->GetPreferredSize().width() | |
| 1557 - photo_bounds.width() - kProfileHorizontalSpacing; | |
| 1558 const int height = profile_container->GetPreferredSize().height() / 2 | |
| 1559 - views::kRelatedControlVerticalSpacing; | |
| 1560 layout->StartRow(1, 0); | |
| 1561 | |
| 1562 if (switches::IsEnableAccountConsistency()) { | |
| 1563 base::string16 link_title = l10n_util::GetStringUTF16( | |
| 1564 IsProfileChooser(view_mode_) ? | |
| 1565 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : | |
| 1566 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | |
| 1567 manage_accounts_link_ = CreateLink(link_title, this); | |
| 1568 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 1569 manage_accounts_link_->SetBounds( | |
| 1570 x_coordinate, y_coordinate, width, height); | |
| 1571 profile_container->AddChildView(manage_accounts_link_); | |
| 1572 } else { | |
|
Evan Stade
2016/06/10 17:39:46
combine else with if-else below
Jane
2016/06/10 18:49:16
Done. FYI, these massive logic statements were bas
| |
| 1573 // Badge the email address if there's an authentication error. | |
| 1574 if (HasAuthError(browser_->profile())) { | |
| 1575 auth_error_email_button_ = | |
| 1576 new RightAlignedIconLabelButton(this, avatar_item.username); | |
| 1577 auth_error_email_button_->SetElideBehavior(gfx::ELIDE_EMAIL); | |
| 1578 auth_error_email_button_->SetImage( | |
| 1579 views::LabelButton::STATE_NORMAL, | |
| 1580 gfx::CreateVectorIcon(gfx::VectorIconId::WARNING, 12, | |
| 1581 gfx::kChromeIconGrey)); | |
| 1582 auth_error_email_button_->SetFocusForPlatform(); | |
| 1583 auth_error_email_button_->set_request_focus_on_press(true); | |
| 1584 gfx::Insets insets = | |
| 1585 views::LabelButtonAssetBorder::GetDefaultInsetsForStyle( | |
| 1586 views::Button::STYLE_TEXTBUTTON); | |
| 1587 auth_error_email_button_->SetBorder(views::Border::CreateEmptyBorder( | |
| 1588 insets.top(), insets.left(), insets.bottom(), insets.right())); | |
| 1589 auth_error_email_button_->SetBounds( | |
| 1590 x_coordinate - insets.left(), y_coordinate, width, height); | |
| 1591 profile_container->AddChildView(auth_error_email_button_); | |
| 1592 } else { | |
| 1593 views::Label* email_label = new views::Label(avatar_item.username); | |
| 1594 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); | |
| 1595 email_label->SetEnabled(false); | |
| 1596 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 1597 email_label->SetBounds(x_coordinate, y_coordinate, width, height); | |
| 1598 profile_container->AddChildView(email_label); | |
| 1599 } | |
| 1600 } | |
| 1601 layout->AddView(profile_container); | |
|
Evan Stade
2016/06/10 17:39:46
return view; then get rid of the next else
Jane
2016/06/10 18:49:16
Done. But same as above.
| |
| 1602 } else { | |
| 1603 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( | |
| 1604 browser_->profile()->GetOriginalProfile()); | |
| 1605 if (signin_manager->IsSigninAllowed()) { | |
| 1606 views::Label* promo = new views::Label( | |
| 1607 l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); | |
| 1608 promo->SetMultiLine(true); | |
| 1609 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 1610 layout->StartRowWithPadding(1, 0, 0, | |
| 1611 views::kRelatedControlVerticalSpacing); | |
| 1612 layout->StartRow(1, 0); | |
| 1613 layout->AddView(promo); | |
| 1614 | |
| 1615 signin_current_profile_link_ = new views::BlueButton( | |
|
Evan Stade
2016/06/10 17:39:46
don't use BlueButton for material design. What you
Jane
2016/06/10 18:49:16
Done. Thanks, didn't know that.
| |
| 1616 this, l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL, | |
| 1617 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | |
| 1618 signin_current_profile_link_->SetMinSize(gfx::Size(0, 36)); | |
| 1619 layout->StartRowWithPadding(1, 0, 0, | |
| 1620 views::kRelatedControlVerticalSpacing); | |
| 1621 layout->StartRow(1, 0); | |
| 1622 layout->AddView(signin_current_profile_link_); | |
| 1623 content::RecordAction( | |
| 1624 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); | |
| 1625 layout->StartRowWithPadding(1, 0, 0, | |
| 1626 views::kLabelToControlVerticalSpacing); | |
| 1627 } | |
| 1628 } | |
| 1629 | |
| 1630 return view; | |
| 1631 } | |
| 1632 | |
| 1448 views::View* ProfileChooserView::CreateGuestProfileView() { | 1633 views::View* ProfileChooserView::CreateGuestProfileView() { |
| 1449 gfx::Image guest_icon = | 1634 gfx::Image guest_icon = |
| 1450 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 1635 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 1451 profiles::GetPlaceholderAvatarIconResourceID()); | 1636 profiles::GetPlaceholderAvatarIconResourceID()); |
| 1452 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); | 1637 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); |
| 1453 guest_avatar_item.active = true; | 1638 guest_avatar_item.active = true; |
| 1454 guest_avatar_item.name = l10n_util::GetStringUTF16( | 1639 guest_avatar_item.name = l10n_util::GetStringUTF16( |
| 1455 IDS_PROFILES_GUEST_PROFILE_NAME); | 1640 IDS_PROFILES_GUEST_PROFILE_NAME); |
| 1456 guest_avatar_item.signed_in = false; | 1641 guest_avatar_item.signed_in = false; |
| 1457 | 1642 |
| 1458 return CreateCurrentProfileView(guest_avatar_item, true); | 1643 return switches::IsMaterialDesignUserMenu() ? |
| 1644 CreateMaterialDesignCurrentProfileView(guest_avatar_item, true) : | |
| 1645 CreateCurrentProfileView(guest_avatar_item, true); | |
| 1459 } | 1646 } |
| 1460 | 1647 |
| 1461 views::View* ProfileChooserView::CreateOtherProfilesView( | 1648 views::View* ProfileChooserView::CreateOtherProfilesView( |
| 1462 const Indexes& avatars_to_show) { | 1649 const Indexes& avatars_to_show) { |
| 1463 views::View* view = new views::View(); | 1650 views::View* view = new views::View(); |
| 1464 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | 1651 views::GridLayout* layout = |
| 1652 CreateSingleColumnLayout(view, GetFixedMenuWidth()); | |
| 1465 | 1653 |
| 1466 for (size_t index : avatars_to_show) { | 1654 for (size_t index : avatars_to_show) { |
| 1467 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index); | 1655 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index); |
| 1468 const int kSmallImageSide = 32; | 1656 const int kSmallImageSide = 32; |
| 1469 | 1657 |
| 1470 // Use the low-res, small default avatars in the fast user switcher, like | 1658 // Use the low-res, small default avatars in the fast user switcher, like |
| 1471 // we do in the menu bar. | 1659 // we do in the menu bar. |
| 1472 gfx::Image item_icon; | 1660 gfx::Image item_icon; |
| 1473 AvatarMenu::GetImageForMenuButton(item.profile_path, &item_icon); | 1661 AvatarMenu::GetImageForMenuButton(item.profile_path, &item_icon); |
| 1474 | 1662 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1485 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 1673 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 1486 layout->StartRow(1, 0); | 1674 layout->StartRow(1, 0); |
| 1487 layout->AddView(button); | 1675 layout->AddView(button); |
| 1488 } | 1676 } |
| 1489 | 1677 |
| 1490 return view; | 1678 return view; |
| 1491 } | 1679 } |
| 1492 | 1680 |
| 1493 views::View* ProfileChooserView::CreateOptionsView(bool display_lock) { | 1681 views::View* ProfileChooserView::CreateOptionsView(bool display_lock) { |
| 1494 views::View* view = new views::View(); | 1682 views::View* view = new views::View(); |
| 1495 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | 1683 views::GridLayout* layout = |
| 1684 CreateSingleColumnLayout(view, GetFixedMenuWidth()); | |
| 1496 | 1685 |
| 1497 base::string16 text = browser_->profile()->IsGuestSession() ? | 1686 base::string16 text = browser_->profile()->IsGuestSession() ? |
| 1498 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) : | 1687 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) : |
| 1499 l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON); | 1688 l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON); |
| 1500 const int kIconSize = 16; | 1689 const int kIconSize = 16; |
| 1501 users_button_ = new BackgroundColorHoverButton( | 1690 users_button_ = new BackgroundColorHoverButton( |
| 1502 this, text, gfx::CreateVectorIcon(gfx::VectorIconId::ACCOUNT_BOX, | 1691 this, text, gfx::CreateVectorIcon(gfx::VectorIconId::ACCOUNT_BOX, |
| 1503 kIconSize, gfx::kChromeIconGrey)); | 1692 kIconSize, gfx::kChromeIconGrey)); |
| 1504 layout->StartRow(1, 0); | 1693 layout->StartRow(1, 0); |
| 1505 layout->AddView(users_button_); | 1694 layout->AddView(users_button_); |
| 1506 | 1695 |
| 1507 if (display_lock) { | 1696 if (display_lock) { |
| 1508 layout->StartRow(1, 0); | 1697 layout->StartRow(1, 0); |
| 1509 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 1698 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 1510 | 1699 |
| 1511 lock_button_ = new BackgroundColorHoverButton( | 1700 lock_button_ = new BackgroundColorHoverButton( |
| 1512 this, l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON), | 1701 this, l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON), |
| 1513 gfx::CreateVectorIcon(gfx::VectorIconId::LOCK, kIconSize, | 1702 gfx::CreateVectorIcon(gfx::VectorIconId::LOCK, kIconSize, |
| 1514 gfx::kChromeIconGrey)); | 1703 gfx::kChromeIconGrey)); |
| 1515 layout->StartRow(1, 0); | 1704 layout->StartRow(1, 0); |
| 1516 layout->AddView(lock_button_); | 1705 layout->AddView(lock_button_); |
| 1517 } | 1706 } |
| 1518 return view; | 1707 return view; |
| 1519 } | 1708 } |
| 1520 | 1709 |
| 1521 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() { | 1710 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() { |
| 1522 views::View* view = new views::View(); | 1711 views::View* view = new views::View(); |
| 1523 views::GridLayout* layout = CreateSingleColumnLayout( | 1712 views::GridLayout* layout = CreateSingleColumnLayout( |
| 1524 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); | 1713 view, GetFixedMenuWidth() - 2 * views::kButtonHEdgeMarginNew); |
| 1525 layout->SetInsets(views::kRelatedControlVerticalSpacing, | 1714 if (switches::IsMaterialDesignUserMenu()) { |
| 1526 views::kButtonHEdgeMarginNew, | 1715 layout->SetInsets(0, |
| 1527 views::kRelatedControlVerticalSpacing, | 1716 views::kMaterialHorizontalMargin, |
| 1528 views::kButtonHEdgeMarginNew); | 1717 views::kMaterialVerticalMargin, |
| 1718 views::kMaterialHorizontalMargin); | |
| 1719 } else { | |
| 1720 layout->SetInsets(views::kRelatedControlVerticalSpacing, | |
| 1721 views::kButtonHEdgeMarginNew, | |
| 1722 views::kRelatedControlVerticalSpacing, | |
| 1723 views::kButtonHEdgeMarginNew); | |
| 1724 } | |
| 1725 | |
| 1529 views::Label* disclaimer = new views::Label( | 1726 views::Label* disclaimer = new views::Label( |
| 1530 avatar_menu_->GetSupervisedUserInformation()); | 1727 avatar_menu_->GetSupervisedUserInformation()); |
| 1531 disclaimer->SetMultiLine(true); | 1728 disclaimer->SetMultiLine(true); |
| 1532 disclaimer->SetAllowCharacterBreak(true); | 1729 disclaimer->SetAllowCharacterBreak(true); |
| 1533 disclaimer->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1730 disclaimer->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1534 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1731 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 1535 disclaimer->SetFontList(rb->GetFontList(ui::ResourceBundle::SmallFont)); | 1732 disclaimer->SetFontList(rb->GetFontList(ui::ResourceBundle::SmallFont)); |
| 1536 layout->StartRow(1, 0); | 1733 layout->StartRow(1, 0); |
| 1537 layout->AddView(disclaimer); | 1734 layout->AddView(disclaimer); |
| 1538 | 1735 |
| 1539 return view; | 1736 return view; |
| 1540 } | 1737 } |
| 1541 | 1738 |
| 1542 views::View* ProfileChooserView::CreateCurrentProfileAccountsView( | 1739 views::View* ProfileChooserView::CreateCurrentProfileAccountsView( |
| 1543 const AvatarMenu::Item& avatar_item) { | 1740 const AvatarMenu::Item& avatar_item) { |
| 1544 DCHECK(avatar_item.signed_in); | 1741 DCHECK(avatar_item.signed_in); |
| 1545 views::View* view = new views::View(); | 1742 views::View* view = new views::View(); |
| 1546 view->set_background(views::Background::CreateSolidBackground( | 1743 view->set_background(views::Background::CreateSolidBackground( |
| 1547 profiles::kAvatarBubbleAccountsBackgroundColor)); | 1744 profiles::kAvatarBubbleAccountsBackgroundColor)); |
| 1548 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | 1745 views::GridLayout* layout = |
| 1746 CreateSingleColumnLayout(view, GetFixedMenuWidth()); | |
| 1549 | 1747 |
| 1550 Profile* profile = browser_->profile(); | 1748 Profile* profile = browser_->profile(); |
| 1551 std::string primary_account = | 1749 std::string primary_account = |
| 1552 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); | 1750 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); |
| 1553 DCHECK(!primary_account.empty()); | 1751 DCHECK(!primary_account.empty()); |
| 1554 std::vector<std::string>accounts = | 1752 std::vector<std::string>accounts = |
| 1555 profiles::GetSecondaryAccountsForProfile(profile, primary_account); | 1753 profiles::GetSecondaryAccountsForProfile(profile, primary_account); |
| 1556 | 1754 |
| 1557 // Get state of authentication error, if any. | 1755 // Get state of authentication error, if any. |
| 1558 std::string error_account_id = GetAuthErrorAccountId(profile); | 1756 std::string error_account_id = GetAuthErrorAccountId(profile); |
| 1559 | 1757 |
| 1560 // The primary account should always be listed first. | 1758 // The primary account should always be listed first. |
| 1561 // TODO(rogerta): we still need to further differentiate the primary account | 1759 // TODO(rogerta): we still need to further differentiate the primary account |
| 1562 // from the others in the UI, so more work is likely required here: | 1760 // from the others in the UI, so more work is likely required here: |
| 1563 // crbug.com/311124. | 1761 // crbug.com/311124. |
| 1564 CreateAccountButton(layout, primary_account, true, | 1762 CreateAccountButton(layout, primary_account, true, |
| 1565 error_account_id == primary_account, kFixedMenuWidth); | 1763 error_account_id == primary_account, GetFixedMenuWidth()); |
| 1566 for (size_t i = 0; i < accounts.size(); ++i) | 1764 for (size_t i = 0; i < accounts.size(); ++i) |
| 1567 CreateAccountButton(layout, accounts[i], false, | 1765 CreateAccountButton(layout, accounts[i], false, |
| 1568 error_account_id == accounts[i], kFixedMenuWidth); | 1766 error_account_id == accounts[i], GetFixedMenuWidth()); |
| 1569 | 1767 |
| 1570 if (!profile->IsSupervised()) { | 1768 if (!profile->IsSupervised()) { |
| 1571 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 1769 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 1572 | 1770 |
| 1573 add_account_link_ = CreateLink(l10n_util::GetStringFUTF16( | 1771 add_account_link_ = CreateLink(l10n_util::GetStringFUTF16( |
| 1574 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this); | 1772 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this); |
| 1575 add_account_link_->SetBorder(views::Border::CreateEmptyBorder( | 1773 add_account_link_->SetBorder(views::Border::CreateEmptyBorder( |
| 1576 0, views::kButtonVEdgeMarginNew, | 1774 0, views::kButtonVEdgeMarginNew, |
| 1577 views::kRelatedControlVerticalSpacing, 0)); | 1775 views::kRelatedControlVerticalSpacing, 0)); |
| 1578 layout->StartRow(1, 0); | 1776 layout->StartRow(1, 0); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1868 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2066 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 1869 IncognitoModePrefs::DISABLED; | 2067 IncognitoModePrefs::DISABLED; |
| 1870 return incognito_available && !browser_->profile()->IsGuestSession(); | 2068 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 1871 } | 2069 } |
| 1872 | 2070 |
| 1873 void ProfileChooserView::PostActionPerformed( | 2071 void ProfileChooserView::PostActionPerformed( |
| 1874 ProfileMetrics::ProfileDesktopMenu action_performed) { | 2072 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 1875 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 2073 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 1876 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 2074 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 1877 } | 2075 } |
| OLD | NEW |