Chromium Code Reviews| Index: chrome/browser/ui/views/profiles/profile_chooser_view.cc |
| diff --git a/chrome/browser/ui/views/profiles/profile_chooser_view.cc b/chrome/browser/ui/views/profiles/profile_chooser_view.cc |
| index 58f1f07f44c0ca924f9243e9b776736e1652f1d3..8e57c16da577de9a154713144dc3a0bfec2a61bc 100644 |
| --- a/chrome/browser/ui/views/profiles/profile_chooser_view.cc |
| +++ b/chrome/browser/ui/views/profiles/profile_chooser_view.cc |
| @@ -91,7 +91,7 @@ const int kFixedSwitchUserViewWidth = 320; |
| const int kLargeImageSide = 88; |
| const int kMediumImageSide = 40; |
| -const int kTextfieldLabelHorizontalSpacing = 4; |
| +const int kProfileBarHeight = 56; |
| const int kProfileHorizontalSpacing = 16; |
| const int kVerticalSpacing = 16; |
| @@ -182,6 +182,13 @@ class BackgroundColorHoverButton : public views::LabelButton { |
| set_request_focus_on_press(true); |
| } |
| + explicit BackgroundColorHoverButton(views::ButtonListener* listener) |
| + : views::LabelButton(listener, base::string16()) { |
| + SetMinSize(gfx::Size(0, kProfileBarHeight)); |
| + SetFocusForPlatform(); |
| + set_request_focus_on_press(true); |
| + } |
| + |
| ~BackgroundColorHoverButton() override {} |
| private: |
| @@ -311,6 +318,7 @@ class EditableProfilePhoto : public views::LabelButton { |
| bool is_editing_allowed, |
| const gfx::Rect& bounds) |
| : views::LabelButton(listener, base::string16()), |
| + interactive_(true), |
| photo_overlay_(NULL) { |
| const int icon_image_side = switches::IsMaterialDesignUserMenu() |
| ? kMediumImageSide : kLargeImageSide; |
| @@ -325,7 +333,7 @@ class EditableProfilePhoto : public views::LabelButton { |
| SkIntToScalar(bounds.height() / 2), |
| SkIntToScalar(bounds.width() / 2)); |
| - if (!is_editing_allowed) { |
| + if (switches::IsMaterialDesignUserMenu() || !is_editing_allowed) { |
| SetEnabled(false); |
| return; |
| } |
| @@ -339,9 +347,7 @@ class EditableProfilePhoto : public views::LabelButton { |
| photo_overlay_->set_background( |
| views::Background::CreateSolidBackground(kBackgroundColor)); |
| photo_overlay_->SetImage(gfx::CreateVectorIcon( |
| - gfx::VectorIconId::PHOTO_CAMERA, |
| - switches::IsMaterialDesignUserMenu() ? 22u : 48u, |
| - SkColorSetRGB(0x33, 0x33, 0x33))); |
| + gfx::VectorIconId::PHOTO_CAMERA, 48u, SkColorSetRGB(0x33, 0x33, 0x33))); |
| photo_overlay_->SetSize(bounds.size()); |
| photo_overlay_->SetVisible(false); |
| @@ -361,6 +367,10 @@ class EditableProfilePhoto : public views::LabelButton { |
| View::PaintChildren(context); |
| } |
| + bool CanProcessEventsWithinSubtree() const override { return interactive_; } |
| + |
| + void set_interactive(bool interactive) { interactive_ = interactive; } |
| + |
| private: |
| // views::CustomButton: |
| void StateChanged() override { |
| @@ -383,6 +393,7 @@ class EditableProfilePhoto : public views::LabelButton { |
| photo_overlay_->SetVisible(false); |
| } |
| + bool interactive_; |
| gfx::Path circular_mask_; |
| // Image that is shown when hovering over the image button. Can be NULL if |
| @@ -395,6 +406,7 @@ class EditableProfilePhoto : public views::LabelButton { |
| // EditableProfileName ------------------------------------------------- |
| // A custom text control that turns into a textfield for editing when clicked. |
| +// For non-material-design user menu only. |
| class EditableProfileName : public views::View, |
| public views::ButtonListener { |
| public: |
| @@ -413,8 +425,6 @@ class EditableProfileName : public views::View, |
| label_ = new views::Label(text); |
| label_->SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); |
| label_->SetFontList(medium_font_list); |
| - if (switches::IsMaterialDesignUserMenu()) |
| - label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| AddChildView(label_); |
| return; |
| } |
| @@ -438,23 +448,16 @@ class EditableProfileName : public views::View, |
| SkColorSetRGB(0x20, 0x20, 0x20))); |
| // We need to add a left padding as well as a small top/bottom padding |
| // to the text to account for the textfield's border. |
| - if (switches::IsMaterialDesignUserMenu()) { |
| - button_->SetBorder(views::Border::CreateEmptyBorder( |
| - 2, kTextfieldLabelHorizontalSpacing, 2, 0)); |
| - } else { |
| - const int kIconTextLabelButtonSpacing = 5; |
| - button_->SetBorder(views::Border::CreateEmptyBorder( |
| - 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); |
| - } |
| + const int kIconTextLabelButtonSpacing = 5; |
| + button_->SetBorder(views::Border::CreateEmptyBorder( |
| + 2, kIconSize + kIconTextLabelButtonSpacing, 2, 0)); |
| AddChildView(button_); |
| profile_name_textfield_ = new views::Textfield(); |
| // Textfield that overlaps the button. |
| profile_name_textfield_->set_controller(controller); |
| profile_name_textfield_->SetFontList(medium_font_list); |
| - profile_name_textfield_->SetHorizontalAlignment( |
| - switches::IsMaterialDesignUserMenu() |
| - ? gfx::ALIGN_LEFT : gfx::ALIGN_CENTER); |
| + profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| profile_name_textfield_->SetVisible(false); |
| AddChildView(profile_name_textfield_); |
| } |
| @@ -724,6 +727,7 @@ void ProfileChooserView::ResetView() { |
| manage_accounts_link_ = NULL; |
| signin_current_profile_link_ = NULL; |
| auth_error_email_button_ = NULL; |
| + current_profile_card_ = NULL; |
| current_profile_photo_ = NULL; |
| current_profile_name_ = NULL; |
| users_button_ = NULL; |
| @@ -980,7 +984,8 @@ void ProfileChooserView::ButtonPressed(views::Button* sender, |
| ShowViewFromMode(account_management_available ? |
| profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : |
| profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); |
| - } else if (sender == current_profile_photo_) { |
| + } else if (sender == current_profile_photo_ || |
| + sender == current_profile_card_) { |
| avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); |
| PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); |
| } else if (sender == signin_current_profile_link_) { |
| @@ -1487,22 +1492,23 @@ views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( |
| const AvatarMenu::Item& avatar_item, |
| bool is_guest) { |
| views::View* view = new views::View(); |
| - int column_width = GetFixedMenuWidth() - 2 * views::kMaterialHorizontalMargin; |
| - views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); |
| - layout->SetInsets(views::kRelatedControlVerticalSpacing, |
| - views::kMaterialHorizontalMargin, |
| - views::kRelatedControlVerticalSpacing, |
| - views::kMaterialHorizontalMargin); |
| + const int content_width = |
|
Roger Tawa OOO till Jul 10th
2016/06/09 14:21:06
|content_width| seems to be used only at line 1582
|
| + GetFixedMenuWidth() - 2 * views::kMaterialHorizontalMargin; |
| + views::GridLayout* layout = |
| + CreateSingleColumnLayout(view, GetFixedMenuWidth()); |
| + layout->SetInsets(views::kRelatedControlVerticalSpacing, 0, |
| + views::kRelatedControlVerticalSpacing, 0); |
| + current_profile_card_ = new BackgroundColorHoverButton(this); |
| // Profile picture, left-aligned. |
| - const int profile_bar_height = 56; |
| - current_profile_photo_ = new EditableProfilePhoto( |
| + EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto( |
| this, avatar_item.icon, !is_guest, |
| - gfx::Rect(0, (profile_bar_height - kMediumImageSide) / 2, |
| + gfx::Rect(0, (kProfileBarHeight - kMediumImageSide) / 2, |
| kMediumImageSide, kMediumImageSide)); |
| - SizedContainer* profile_container = |
| - new SizedContainer(gfx::Size(column_width, profile_bar_height)); |
| - profile_container->AddChildView(current_profile_photo_); |
| + current_profile_photo->SetX(views::kMaterialHorizontalMargin); |
| + gfx::Rect photo_bounds = current_profile_photo->bounds(); |
| + current_profile_card_->AddChildView(current_profile_photo); |
| + current_profile_photo->set_interactive(false); |
| // Add supervised badge for supervised profile. |
| if (browser_->profile()->IsSupervised()) { |
| @@ -1510,126 +1516,110 @@ views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( |
| views::ImageView* supervised_icon = new views::ImageView(); |
| supervised_icon->SetImage(CreateBadgeForProfile(browser_->profile())); |
| gfx::Size preferred_size = supervised_icon->GetPreferredSize(); |
| - gfx::Rect parent_bounds = current_profile_photo_->bounds(); |
| supervised_icon->SetBounds( |
| - parent_bounds.right() - preferred_size.width() + badge_spacing, |
| - parent_bounds.bottom() - preferred_size.height() + badge_spacing, |
| + photo_bounds.right() - preferred_size.width() + badge_spacing, |
| + photo_bounds.bottom() - preferred_size.height() + badge_spacing, |
| preferred_size.width(), |
| preferred_size.height()); |
| - profile_container->AddChildView(supervised_icon); |
| + current_profile_card_->AddChildView(supervised_icon); |
| + supervised_icon->set_interactive(false); |
| } |
| // Profile name, left-aligned to the right of profile icon. |
| - bool editing_allowed = !is_guest && |
| - !browser_->profile()->IsLegacySupervised(); |
| - current_profile_name_ = new EditableProfileName( |
| - this, |
| - profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()), |
| - editing_allowed); |
| - gfx::Rect photo_bounds = current_profile_photo_->bounds(); |
| - const int textfield_left_margin = |
| - kProfileHorizontalSpacing - |
| - (editing_allowed ? kTextfieldLabelHorizontalSpacing : 0); |
| - current_profile_name_->SetBounds( |
| - photo_bounds.width() + textfield_left_margin, |
| + views::Label* current_profile_name = new views::Label( |
| + profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())); |
| + current_profile_name->SetFontList( |
| + (&ui::ResourceBundle::GetSharedInstance()) |
| + ->GetFontList(ui::ResourceBundle::MediumFont)); |
| + current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + current_profile_name->SetBounds( |
| + photo_bounds.right() + kProfileHorizontalSpacing, |
| views::kRelatedControlVerticalSpacing, |
| - profile_container->GetPreferredSize().width() - photo_bounds.width() |
| - - textfield_left_margin, |
| - profile_container->GetPreferredSize().height() / 2 |
| - - views::kRelatedControlVerticalSpacing); |
| - profile_container->AddChildView(current_profile_name_); |
| - |
| - // Center-align the avatar name if the profile is not signed in. |
| - if (is_guest || !avatar_item.signed_in) { |
| - current_profile_name_->SetY( |
| - (profile_container->GetPreferredSize().height() |
| - - current_profile_name_->height()) / 2); |
| + GetFixedMenuWidth() - photo_bounds.right() - kProfileHorizontalSpacing - |
| + views::kMaterialHorizontalMargin, |
| + kProfileBarHeight / 2 - views::kRelatedControlVerticalSpacing); |
| + current_profile_card_->AddChildView(current_profile_name); |
| + |
| + if (avatar_item.signed_in && !switches::IsEnableAccountConsistency()) { |
| + views::Label* email_label = new views::Label(avatar_item.username); |
| + email_label->SetElideBehavior(gfx::ELIDE_EMAIL); |
| + email_label->SetEnabled(false); |
| + email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + email_label->SetBounds( |
| + photo_bounds.right() + kProfileHorizontalSpacing, |
| + kProfileBarHeight / 2, |
| + GetFixedMenuWidth() - photo_bounds.right() - kProfileHorizontalSpacing - |
| + views::kMaterialHorizontalMargin, |
| + kProfileBarHeight / 2 - views::kRelatedControlVerticalSpacing); |
| + current_profile_card_->AddChildView(email_label); |
| layout->StartRow(1, 0); |
| - layout->AddView(profile_container); |
| + layout->AddView(current_profile_card_); |
| + return view; |
| + } else { |
| + // Center-align the avatar name and add to the view. |
| + current_profile_name->SetY( |
| + (kProfileBarHeight - current_profile_name->height()) / 2); |
| + layout->StartRow(1, 0); |
| + layout->AddView(current_profile_card_); |
| } |
| - if (is_guest) |
| + if (is_guest) { |
| + current_profile_card_->SetEnabled(false); |
| return view; |
| + } |
| - // The available links depend on the type of profile that is active. |
| - if (avatar_item.signed_in) { |
| - // Calculate the position and size for links available for signed-in |
| - // profiles. |
| - const int x_coordinate = photo_bounds.width() + kProfileHorizontalSpacing; |
| - const int y_coordinate = profile_container->GetPreferredSize().height() / 2; |
| - const int width = profile_container->GetPreferredSize().width() |
| - - photo_bounds.width() - kProfileHorizontalSpacing; |
| - const int height = profile_container->GetPreferredSize().height() / 2 |
| - - views::kRelatedControlVerticalSpacing; |
| - layout->StartRow(1, 0); |
| - |
| - if (switches::IsEnableAccountConsistency()) { |
| - base::string16 link_title = l10n_util::GetStringUTF16( |
| - IsProfileChooser(view_mode_) ? |
| - IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : |
| - IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
| - manage_accounts_link_ = CreateLink(link_title, this); |
| - manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| - manage_accounts_link_->SetBounds( |
| - x_coordinate, y_coordinate, width, height); |
| - profile_container->AddChildView(manage_accounts_link_); |
| - } else { |
| - // Badge the email address if there's an authentication error. |
| - if (HasAuthError(browser_->profile())) { |
| - auth_error_email_button_ = |
| - new RightAlignedIconLabelButton(this, avatar_item.username); |
| - auth_error_email_button_->SetElideBehavior(gfx::ELIDE_EMAIL); |
| - auth_error_email_button_->SetImage( |
| - views::LabelButton::STATE_NORMAL, |
| - gfx::CreateVectorIcon(gfx::VectorIconId::WARNING, 12, |
| - gfx::kChromeIconGrey)); |
| - auth_error_email_button_->SetFocusForPlatform(); |
| - auth_error_email_button_->set_request_focus_on_press(true); |
| - gfx::Insets insets = |
| - views::LabelButtonAssetBorder::GetDefaultInsetsForStyle( |
| - views::Button::STYLE_TEXTBUTTON); |
| - auth_error_email_button_->SetBorder(views::Border::CreateEmptyBorder( |
| - insets.top(), insets.left(), insets.bottom(), insets.right())); |
| - auth_error_email_button_->SetBounds( |
| - x_coordinate - insets.left(), y_coordinate, width, height); |
| - profile_container->AddChildView(auth_error_email_button_); |
| - } else { |
| - views::Label* email_label = new views::Label(avatar_item.username); |
| - email_label->SetElideBehavior(gfx::ELIDE_EMAIL); |
| - email_label->SetEnabled(false); |
| - email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| - email_label->SetBounds(x_coordinate, y_coordinate, width, height); |
| - profile_container->AddChildView(email_label); |
| - } |
| - } |
| - layout->AddView(profile_container); |
| - } else { |
| + if (!avatar_item.signed_in) { |
| SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( |
| browser_->profile()->GetOriginalProfile()); |
| - if (signin_manager->IsSigninAllowed()) { |
| - views::Label* promo = new views::Label( |
| - l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); |
| - promo->SetMultiLine(true); |
| - promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| - layout->StartRowWithPadding(1, 0, 0, |
| - views::kRelatedControlVerticalSpacing); |
| - layout->StartRow(1, 0); |
| - layout->AddView(promo); |
| + if (!signin_manager->IsSigninAllowed()) |
| + return view; |
| + } |
| - signin_current_profile_link_ = new views::BlueButton( |
| + // Add a layout with horizontal insets to accomodate the extra links under |
| + // the active profile card. |
| + views::View* links_view = new views::View(); |
| + views::GridLayout* links_layout = |
| + CreateSingleColumnLayout(links_view, content_width); |
| + links_layout->SetInsets(0, views::kMaterialHorizontalMargin, |
| + 0, views::kMaterialHorizontalMargin); |
| + |
| + if (avatar_item.signed_in) { |
| + // Implies that account consistency is turned on |
| + base::string16 link_title = l10n_util::GetStringUTF16( |
| + IsProfileChooser(view_mode_) ? |
| + IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : |
| + IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
| + manage_accounts_link_ = CreateLink(link_title, this); |
| + manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + links_layout->StartRowWithPadding(1, 0, 0, |
| + views::kRelatedControlVerticalSpacing); |
| + links_layout->StartRow(1, 0); |
| + links_layout->AddView(manage_accounts_link_); |
| + } else { |
| + // Implies that account is not signed in and signin is allowed |
| + views::Label* promo = new views::Label( |
| + l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); |
| + promo->SetMultiLine(true); |
| + promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + links_layout->StartRowWithPadding(1, 0, 0, |
| + views::kRelatedControlVerticalSpacing); |
| + links_layout->StartRow(1, 0); |
| + links_layout->AddView(promo); |
| + signin_current_profile_link_ = new views::BlueButton( |
| this, l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL, |
| l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| - signin_current_profile_link_->SetMinSize(gfx::Size(0, 36)); |
| - layout->StartRowWithPadding(1, 0, 0, |
| - views::kRelatedControlVerticalSpacing); |
| - layout->StartRow(1, 0); |
| - layout->AddView(signin_current_profile_link_); |
| - content::RecordAction( |
| - base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); |
| - layout->StartRowWithPadding(1, 0, 0, |
| - views::kLabelToControlVerticalSpacing); |
| - } |
| + signin_current_profile_link_->SetMinSize(gfx::Size(0, 36)); |
| + links_layout->StartRowWithPadding(1, 0, 0, |
| + views::kRelatedControlVerticalSpacing); |
| + links_layout->StartRow(1, 0); |
| + links_layout->AddView(signin_current_profile_link_); |
| + content::RecordAction( |
| + base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); |
| + links_layout->StartRowWithPadding(1, 0, 0, |
| + views::kLabelToControlVerticalSpacing); |
| } |
| + layout->StartRow(1, 0); |
| + layout->AddView(links_view); |
| return view; |
| } |