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/new_avatar_button.h" | 5 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" |
| 6 | 6 |
| 7 #include "base/win/windows_version.h" | 7 #include "base/win/windows_version.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/browser/profiles/profiles_state.h" | 10 #include "chrome/browser/profiles/profiles_state.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | |
| 12 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 15 #include "ui/views/border.h" | 16 #include "ui/views/border.h" |
| 16 #include "ui/views/controls/button/label_button_border.h" | 17 #include "ui/views/controls/button/label_button_border.h" |
| 17 #include "ui/views/painter.h" | 18 #include "ui/views/painter.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], | 22 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 43 | 44 |
| 44 NewAvatarButton::NewAvatarButton( | 45 NewAvatarButton::NewAvatarButton( |
| 45 views::ButtonListener* listener, | 46 views::ButtonListener* listener, |
| 46 const base::string16& profile_name, | 47 const base::string16& profile_name, |
| 47 AvatarButtonStyle button_style, | 48 AvatarButtonStyle button_style, |
| 48 Browser* browser) | 49 Browser* browser) |
| 49 : MenuButton(listener, | 50 : MenuButton(listener, |
| 50 profiles::GetAvatarButtonTextForProfile(browser->profile()), | 51 profiles::GetAvatarButtonTextForProfile(browser->profile()), |
| 51 NULL, | 52 NULL, |
| 52 true), | 53 true), |
| 53 browser_(browser) { | 54 browser_(browser), |
| 55 suppress_mouse_released_action_(false) { | |
| 54 set_animate_on_state_change(false); | 56 set_animate_on_state_change(false); |
| 55 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); | 57 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); |
| 56 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); | 58 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); |
| 57 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); | 59 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); |
| 58 SetTextShadows(gfx::ShadowValues(10, | 60 SetTextShadows(gfx::ShadowValues(10, |
| 59 gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); | 61 gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); |
| 60 SetTextSubpixelRenderingEnabled(false); | 62 SetTextSubpixelRenderingEnabled(false); |
| 61 | 63 |
| 62 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 64 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 63 if (button_style == THEMED_BUTTON) { | 65 if (button_style == THEMED_BUTTON) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 | 106 |
| 105 NewAvatarButton::~NewAvatarButton() { | 107 NewAvatarButton::~NewAvatarButton() { |
| 106 g_browser_process->profile_manager()-> | 108 g_browser_process->profile_manager()-> |
| 107 GetProfileInfoCache().RemoveObserver(this); | 109 GetProfileInfoCache().RemoveObserver(this); |
| 108 SigninErrorController* error = | 110 SigninErrorController* error = |
| 109 profiles::GetSigninErrorController(browser_->profile()); | 111 profiles::GetSigninErrorController(browser_->profile()); |
| 110 if (error) | 112 if (error) |
| 111 error->RemoveObserver(this); | 113 error->RemoveObserver(this); |
| 112 } | 114 } |
| 113 | 115 |
| 116 bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) { | |
| 117 // If the avatar bubble is showing then don't reshow it when the mouse is | |
|
msw
2014/08/20 21:12:36
nit: aim for one-liners, like "Prevent the bubble
Mike Lerman
2014/08/21 15:15:36
Done.
| |
| 118 // released. | |
| 119 suppress_mouse_released_action_ = ProfileChooserView::IsShowing(); | |
| 120 | |
| 121 // We want to show the avatar bubble on mouse release; that is the standard | |
| 122 // behavior for buttons. | |
| 123 return true; | |
|
msw
2014/08/20 21:12:36
Return MenuButton::OnMousePressed. Remove comment
Mike Lerman
2014/08/21 15:15:36
Done.
| |
| 124 } | |
| 125 | |
| 126 bool NewAvatarButton::IsMouseReleaseActionSuppressed() { | |
|
msw
2014/08/20 21:12:36
Remove this and instead override NewAvatarButton::
Mike Lerman
2014/08/21 15:15:36
That is much cleaner. I didn't imagine swallowing
| |
| 127 if (suppress_mouse_released_action_) { | |
| 128 suppress_mouse_released_action_ = false; | |
| 129 return true; | |
| 130 } | |
| 131 return false; | |
| 132 } | |
| 133 | |
| 114 void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { | 134 void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { |
| 115 UpdateAvatarButtonAndRelayoutParent(); | 135 UpdateAvatarButtonAndRelayoutParent(); |
| 116 } | 136 } |
| 117 | 137 |
| 118 void NewAvatarButton::OnProfileWasRemoved( | 138 void NewAvatarButton::OnProfileWasRemoved( |
| 119 const base::FilePath& profile_path, | 139 const base::FilePath& profile_path, |
| 120 const base::string16& profile_name) { | 140 const base::string16& profile_name) { |
| 121 UpdateAvatarButtonAndRelayoutParent(); | 141 UpdateAvatarButtonAndRelayoutParent(); |
| 122 } | 142 } |
| 123 | 143 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 151 // We want the button to resize if the new text is shorter. | 171 // We want the button to resize if the new text is shorter. |
| 152 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); | 172 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
| 153 SetMinSize(gfx::Size()); | 173 SetMinSize(gfx::Size()); |
| 154 InvalidateLayout(); | 174 InvalidateLayout(); |
| 155 | 175 |
| 156 // Because the width of the button might have changed, the parent browser | 176 // Because the width of the button might have changed, the parent browser |
| 157 // frame needs to recalculate the button bounds and redraw it. | 177 // frame needs to recalculate the button bounds and redraw it. |
| 158 if (parent()) | 178 if (parent()) |
| 159 parent()->Layout(); | 179 parent()->Layout(); |
| 160 } | 180 } |
| OLD | NEW |