| 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 // Prevent the bubble from being re-shown if it's already showing. |
| 118 suppress_mouse_released_action_ = ProfileChooserView::IsShowing(); |
| 119 return MenuButton::OnMousePressed(event); |
| 120 } |
| 121 |
| 122 void NewAvatarButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 123 if (suppress_mouse_released_action_) |
| 124 suppress_mouse_released_action_ = false; |
| 125 else |
| 126 MenuButton::OnMouseReleased(event); |
| 127 } |
| 128 |
| 114 void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { | 129 void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { |
| 115 UpdateAvatarButtonAndRelayoutParent(); | 130 UpdateAvatarButtonAndRelayoutParent(); |
| 116 } | 131 } |
| 117 | 132 |
| 118 void NewAvatarButton::OnProfileWasRemoved( | 133 void NewAvatarButton::OnProfileWasRemoved( |
| 119 const base::FilePath& profile_path, | 134 const base::FilePath& profile_path, |
| 120 const base::string16& profile_name) { | 135 const base::string16& profile_name) { |
| 121 UpdateAvatarButtonAndRelayoutParent(); | 136 UpdateAvatarButtonAndRelayoutParent(); |
| 122 } | 137 } |
| 123 | 138 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 151 // We want the button to resize if the new text is shorter. | 166 // We want the button to resize if the new text is shorter. |
| 152 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); | 167 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
| 153 SetMinSize(gfx::Size()); | 168 SetMinSize(gfx::Size()); |
| 154 InvalidateLayout(); | 169 InvalidateLayout(); |
| 155 | 170 |
| 156 // Because the width of the button might have changed, the parent browser | 171 // Because the width of the button might have changed, the parent browser |
| 157 // frame needs to recalculate the button bounds and redraw it. | 172 // frame needs to recalculate the button bounds and redraw it. |
| 158 if (parent()) | 173 if (parent()) |
| 159 parent()->Layout(); | 174 parent()->Layout(); |
| 160 } | 175 } |
| OLD | NEW |