OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/button/label_button.h" | 5 #include "ui/views/controls/button/label_button.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "ui/base/animation/throb_animation.h" | 9 #include "ui/base/animation/throb_animation.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
11 #include "ui/native_theme/native_theme.h" | 11 #include "ui/native_theme/native_theme.h" |
12 #include "ui/views/controls/button/label_button_border.h" | 12 #include "ui/views/controls/button/label_button_border.h" |
13 #include "ui/views/focus_border.h" | 13 #include "ui/views/focus_border.h" |
14 #include "ui/views/window/dialog_delegate.h" | 14 #include "ui/views/window/dialog_delegate.h" |
15 | 15 |
16 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
17 #include "ui/gfx/color_utils.h" | 17 #include "ui/gfx/color_utils.h" |
18 #include "ui/native_theme/native_theme_win.h" | 18 #include "ui/native_theme/native_theme_win.h" |
19 #endif | 19 #endif |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // The spacing between the icon and text. | 23 // The spacing between the icon and text. |
24 const int kSpacing = 5; | 24 const int kSpacing = 5; |
25 | 25 |
26 // The length of the hover fade animation. | 26 // The length of the hover fade animation. |
27 const int kHoverAnimationDurationMs = 170; | 27 const int kHoverAnimationDurationMs = 170; |
28 | 28 |
29 // Blue button style default font color. | |
30 const SkColor kBlueButtonTextColor = SK_ColorWHITE; | |
31 | |
32 // Blue button style default font color. | |
msw
2013/05/16 17:07:36
you mean shadow color...
benwells
2013/05/17 02:24:32
Done.
| |
33 const SkColor kBlueButtonShadowColor = SkColorSetRGB(0x53, 0x8C, 0xEA); | |
34 | |
29 } // namespace | 35 } // namespace |
30 | 36 |
31 namespace views { | 37 namespace views { |
32 | 38 |
33 // static | 39 // static |
34 const char LabelButton::kViewClassName[] = "views/LabelButton"; | 40 const char LabelButton::kViewClassName[] = "views/LabelButton"; |
35 | 41 |
36 LabelButton::LabelButton(ButtonListener* listener, const string16& text) | 42 LabelButton::LabelButton(ButtonListener* listener, const string16& text) |
37 : CustomButton(listener), | 43 : CustomButton(listener), |
38 image_(new ImageView()), | 44 image_(new ImageView()), |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 if (style == STYLE_BUTTON || style == STYLE_NATIVE_TEXTBUTTON) { | 150 if (style == STYLE_BUTTON || style == STYLE_NATIVE_TEXTBUTTON) { |
145 label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 151 label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
146 set_focusable(true); | 152 set_focusable(true); |
147 } | 153 } |
148 if (style == STYLE_BUTTON) { | 154 if (style == STYLE_BUTTON) { |
149 set_min_size(gfx::Size(70, 31)); | 155 set_min_size(gfx::Size(70, 31)); |
150 const SkColor color = GetNativeTheme()->GetSystemColor( | 156 const SkColor color = GetNativeTheme()->GetSystemColor( |
151 ui::NativeTheme::kColorId_WindowBackground); | 157 ui::NativeTheme::kColorId_WindowBackground); |
152 label_->SetShadowColors(color, color); | 158 label_->SetShadowColors(color, color); |
153 label_->SetShadowOffset(0, 1); | 159 label_->SetShadowOffset(0, 1); |
160 } else if (style == STYLE_BLUE_BUTTON) { | |
161 label_->SetShadowColors(kBlueButtonShadowColor, kBlueButtonShadowColor); | |
162 label_->SetShadowOffset(1, 1); | |
msw
2013/05/16 17:07:36
This should be (0, 1) like above to drop the shado
benwells
2013/05/17 02:24:32
Done.
| |
154 } | 163 } |
155 // Invalidate the layout to pickup the new insets from the border. | 164 // Invalidate the layout to pickup the new insets from the border. |
156 InvalidateLayout(); | 165 InvalidateLayout(); |
157 ResetColorsFromNativeTheme(); | 166 ResetColorsFromNativeTheme(); |
158 } | 167 } |
159 | 168 |
160 gfx::Size LabelButton::GetPreferredSize() { | 169 gfx::Size LabelButton::GetPreferredSize() { |
161 // Accommodate bold text in case this STYLE_BUTTON button is made default. | 170 // Accommodate bold text in case this STYLE_BUTTON button is made default. |
162 const gfx::Font font = label_->font(); | 171 const gfx::Font font = label_->font(); |
163 if (style_ == STYLE_BUTTON) | 172 if (style_ == STYLE_BUTTON) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 theme->GetSystemColor(ui::NativeTheme::kColorId_TextButtonHoverColor), | 215 theme->GetSystemColor(ui::NativeTheme::kColorId_TextButtonHoverColor), |
207 theme->GetSystemColor(ui::NativeTheme::kColorId_TextButtonDisabledColor), | 216 theme->GetSystemColor(ui::NativeTheme::kColorId_TextButtonDisabledColor), |
208 }; | 217 }; |
209 | 218 |
210 // Certain styles do not change text color when hovered or pressed. | 219 // Certain styles do not change text color when hovered or pressed. |
211 bool constant_text_color = style() == STYLE_BUTTON; | 220 bool constant_text_color = style() == STYLE_BUTTON; |
212 #if defined(OS_WIN) | 221 #if defined(OS_WIN) |
213 constant_text_color |= (style() == STYLE_NATIVE_TEXTBUTTON && | 222 constant_text_color |= (style() == STYLE_NATIVE_TEXTBUTTON && |
214 theme == ui::NativeThemeWin::instance()); | 223 theme == ui::NativeThemeWin::instance()); |
215 #endif | 224 #endif |
225 if (style() == STYLE_BLUE_BUTTON) { | |
226 colors[STATE_NORMAL] = kBlueButtonTextColor; | |
227 colors[STATE_DISABLED] = kBlueButtonTextColor; | |
228 constant_text_color = true; | |
229 } | |
230 | |
216 if (constant_text_color) | 231 if (constant_text_color) |
217 colors[STATE_HOVERED] = colors[STATE_PRESSED] = colors[STATE_NORMAL]; | 232 colors[STATE_HOVERED] = colors[STATE_PRESSED] = colors[STATE_NORMAL]; |
218 | 233 |
219 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) { | 234 for (size_t state = STATE_NORMAL; state < STATE_COUNT; ++state) { |
220 if (!explicitly_set_colors_[state]) { | 235 if (!explicitly_set_colors_[state]) { |
221 SetTextColor(static_cast<ButtonState>(state), colors[state]); | 236 SetTextColor(static_cast<ButtonState>(state), colors[state]); |
222 explicitly_set_colors_[state] = false; | 237 explicitly_set_colors_[state] = false; |
223 } | 238 } |
224 } | 239 } |
225 } | 240 } |
226 | 241 |
227 void LabelButton::StateChanged() { | 242 void LabelButton::StateChanged() { |
228 const gfx::Size previous_image_size(image_->GetPreferredSize()); | 243 const gfx::Size previous_image_size(image_->GetPreferredSize()); |
229 image_->SetImage(GetImage(state())); | 244 image_->SetImage(GetImage(state())); |
230 const SkColor color = button_state_colors_[state()]; | 245 SkColor color = button_state_colors_[state()]; |
231 if (state() != STATE_DISABLED && label_->enabled_color() != color) | 246 if (state() != STATE_DISABLED && label_->enabled_color() != color) |
232 label_->SetEnabledColor(color); | 247 label_->SetEnabledColor(color); |
233 label_->SetEnabled(state() != STATE_DISABLED); | 248 label_->SetEnabled(state() != STATE_DISABLED); |
234 if (image_->GetPreferredSize() != previous_image_size) | 249 if (image_->GetPreferredSize() != previous_image_size) |
235 Layout(); | 250 Layout(); |
236 } | 251 } |
237 | 252 |
238 void LabelButton::Layout() { | 253 void LabelButton::Layout() { |
239 gfx::Rect child_area(GetLocalBounds()); | 254 gfx::Rect child_area(GetLocalBounds()); |
240 child_area.Inset(GetInsets()); | 255 child_area.Inset(GetInsets()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 params->button.indeterminate = false; | 349 params->button.indeterminate = false; |
335 params->button.is_default = is_default_; | 350 params->button.is_default = is_default_; |
336 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); | 351 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); |
337 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON; | 352 params->button.has_border = style() == STYLE_NATIVE_TEXTBUTTON; |
338 params->button.classic_state = 0; | 353 params->button.classic_state = 0; |
339 params->button.background_color = GetNativeTheme()->GetSystemColor( | 354 params->button.background_color = GetNativeTheme()->GetSystemColor( |
340 ui::NativeTheme::kColorId_TextButtonBackgroundColor); | 355 ui::NativeTheme::kColorId_TextButtonBackgroundColor); |
341 } | 356 } |
342 | 357 |
343 } // namespace views | 358 } // namespace views |
OLD | NEW |