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 df8bcaffbe438ee4db98cbb3d1662a92db6e96be..676cfa54a7d84bbde86584002f282d07c4fca604 100644 |
| --- a/chrome/browser/ui/views/profiles/profile_chooser_view.cc |
| +++ b/chrome/browser/ui/views/profiles/profile_chooser_view.cc |
| @@ -141,6 +141,7 @@ class BackgroundColorHoverButton : public views::LabelButton { |
| SetMinSize(gfx::Size(0, |
| kButtonHeight + views::kRelatedControlVerticalSpacing)); |
| SetImage(STATE_NORMAL, icon); |
| + SetFocusable(true); |
| } |
| virtual ~BackgroundColorHoverButton() {} |
| @@ -202,17 +203,18 @@ class RightAlignedIconLabelButton : public views::LabelButton { |
| // EditableProfilePhoto ------------------------------------------------- |
| // A custom Image control that shows a "change" button when moused over. |
| -class EditableProfilePhoto : public views::ImageView { |
| +class EditableProfilePhoto : public views::LabelButton { |
| public: |
| EditableProfilePhoto(views::ButtonListener* listener, |
| const gfx::Image& icon, |
| bool is_editing_allowed, |
| const gfx::Rect& bounds) |
| - : views::ImageView(), |
| - change_photo_button_(NULL) { |
| + : views::LabelButton(listener, base::string16()), |
| + photo_overlay_(NULL) { |
| gfx::Image image = profiles::GetSizedAvatarIcon( |
| icon, true, kLargeImageSide, kLargeImageSide); |
| - SetImage(image.ToImageSkia()); |
| + SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); |
| + SetBorder(views::Border::NullBorder()); |
| SetBoundsRect(bounds); |
| // Calculate the circular mask that will be used to display the photo. |
| @@ -220,32 +222,32 @@ class EditableProfilePhoto : public views::ImageView { |
| SkIntToScalar(bounds.height() / 2), |
| SkIntToScalar(bounds.width() / 2)); |
| - if (!is_editing_allowed) |
| + if (!is_editing_allowed) { |
| + SetEnabled(false); |
| return; |
| + } |
| + SetFocusable(true); |
| set_notify_enter_exit_on_child(true); |
| - // Button overlay that appears when hovering over the image. |
| - change_photo_button_ = new views::LabelButton(listener, base::string16()); |
| - change_photo_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| - change_photo_button_->SetBorder(views::Border::NullBorder()); |
| + // Photo overlay that appears when hovering over the button. |
| + photo_overlay_ = new views::ImageView(); |
| const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); |
| - change_photo_button_->set_background( |
| + photo_overlay_->set_background( |
| views::Background::CreateSolidBackground(kBackgroundColor)); |
| - change_photo_button_->SetImage(views::LabelButton::STATE_NORMAL, |
| - *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| - IDR_ICON_PROFILES_EDIT_CAMERA)); |
| + photo_overlay_->SetImage(*ui::ResourceBundle::GetSharedInstance(). |
| + GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_CAMERA)); |
| - change_photo_button_->SetSize(bounds.size()); |
| - change_photo_button_->SetVisible(false); |
| - AddChildView(change_photo_button_); |
| + photo_overlay_->SetSize(bounds.size()); |
| + photo_overlay_->SetVisible(false); |
| + AddChildView(photo_overlay_); |
| } |
| virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| // Display the profile picture as a circle. |
| canvas->ClipPath(circular_mask_, true); |
| - views::ImageView::OnPaint(canvas); |
| + views::LabelButton::OnPaint(canvas); |
| } |
| virtual void PaintChildren(gfx::Canvas* canvas, |
| @@ -255,25 +257,32 @@ class EditableProfilePhoto : public views::ImageView { |
| View::PaintChildren(canvas, cull_set); |
| } |
| - views::LabelButton* change_photo_button() { return change_photo_button_; } |
| - |
| private: |
| - // views::View: |
| - virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { |
| - if (change_photo_button_) |
| - change_photo_button_->SetVisible(true); |
| + // views::CustomButton: |
| + virtual void StateChanged() OVERRIDE { |
| + bool show_overlay = |
| + (state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus()); |
| + if (photo_overlay_) |
| + photo_overlay_->SetVisible(show_overlay); |
| + } |
| + |
| + virtual void OnFocus() OVERRIDE { |
| + views::LabelButton::OnFocus(); |
| + if (photo_overlay_) |
|
msw
2014/08/20 20:49:56
nit: maybe SetState(STATE_HOVERED)?
noms (inactive)
2014/08/20 21:11:48
Hmm, setting the state here and in OnBlur leads to
msw
2014/08/20 21:20:08
Ignore my suggestion if it works better as-is.
noms (inactive)
2014/08/20 21:44:18
Done.
|
| + photo_overlay_->SetVisible(true); |
| } |
| - virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE { |
| - if (change_photo_button_) |
| - change_photo_button_->SetVisible(false); |
| + virtual void OnBlur() OVERRIDE { |
| + views::LabelButton::OnBlur(); |
| + if (photo_overlay_) |
|
msw
2014/08/20 20:49:56
nit: maybe add |&& state() != STATE_HOVERED|
noms (inactive)
2014/08/20 21:11:48
Hmm, but it's definitely going to to be in a hover
msw
2014/08/20 21:20:08
You can ignore my comment above. Only address this
noms (inactive)
2014/08/20 21:44:18
Did this now that i didn't do the other one :)
Yay
|
| + photo_overlay_->SetVisible(false); |
| } |
| gfx::Path circular_mask_; |
| - // Button that is shown when hovering over the image view. Can be NULL if |
| + // Image that is shown when hovering over the image button. Can be NULL if |
| // the photo isn't allowed to be edited (e.g. for guest profiles). |
| - views::LabelButton* change_photo_button_; |
| + views::ImageView* photo_overlay_; |
| DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); |
| }; |
| @@ -300,6 +309,7 @@ class EditableProfileName : public RightAlignedIconLabelButton, |
| return; |
| } |
| + SetFocusable(true); |
| // Show an "edit" pencil icon when hovering over. In the default state, |
| // we need to create an empty placeholder of the correct size, so that |
| // the text doesn't jump around when the hovered icon appears. |
| @@ -362,6 +372,16 @@ class EditableProfileName : public RightAlignedIconLabelButton, |
| RightAlignedIconLabelButton::Layout(); |
| } |
| + virtual void OnFocus() OVERRIDE { |
| + RightAlignedIconLabelButton::OnFocus(); |
| + SetState(views::CustomButton::STATE_HOVERED); |
|
msw
2014/08/20 20:49:56
nit: you may be able to remove "views::CustomButto
noms (inactive)
2014/08/20 21:44:18
Done.
|
| + } |
| + |
| + virtual void OnBlur() OVERRIDE { |
| + RightAlignedIconLabelButton::OnBlur(); |
| + SetState(views::CustomButton::STATE_NORMAL); |
| + } |
| + |
| // Textfield that is shown when editing the profile name. Can be NULL if |
| // the profile name isn't allowed to be edited (e.g. for guest profiles). |
| views::Textfield* profile_name_textfield_; |
| @@ -386,6 +406,7 @@ class TitleCard : public views::View { |
| rb->GetImageSkiaNamed(IDR_BACK_P)); |
| back_button_->SetImage(views::ImageButton::STATE_DISABLED, |
| rb->GetImageSkiaNamed(IDR_BACK_D)); |
| + back_button_->SetFocusable(true); |
| *back_button = back_button_; |
| title_label_ = new views::Label(message); |
| @@ -729,8 +750,7 @@ void ProfileChooserView::ButtonPressed(views::Button* sender, |
| ShowView(account_management_available ? |
| profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : |
| profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); |
| - } else if (current_profile_photo_ && |
| - sender == current_profile_photo_->change_photo_button()) { |
| + } else if (sender == current_profile_photo_) { |
| avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); |
| PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); |
| } else if (sender == signin_current_profile_link_) { |
| @@ -1133,6 +1153,7 @@ views::View* ProfileChooserView::CreateCurrentProfileView( |
| auth_error_email_button_->SetTextColor( |
| views::LabelButton::STATE_NORMAL, |
| views::Link::GetDefaultEnabledColor()); |
| + auth_error_email_button_->SetFocusable(true); |
| layout->AddView(auth_error_email_button_); |
| } else { |
| views::Label* email_label = new views::Label(avatar_item.sync_state); |