| 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/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" | 
| 10 #include "ui/gfx/animation/throb_animation.h" | 10 #include "ui/gfx/animation/throb_animation.h" | 
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" | 
| 12 #include "ui/gfx/font_list.h" | 12 #include "ui/gfx/font_list.h" | 
| 13 #include "ui/gfx/sys_color_change_listener.h" | 13 #include "ui/gfx/sys_color_change_listener.h" | 
| 14 #include "ui/native_theme/native_theme.h" | 14 #include "ui/native_theme/native_theme.h" | 
| 15 #include "ui/views/background.h" | 15 #include "ui/views/background.h" | 
| 16 #include "ui/views/controls/button/label_button_border.h" | 16 #include "ui/views/controls/button/label_button_border.h" | 
| 17 #include "ui/views/painter.h" | 17 #include "ui/views/painter.h" | 
| 18 #include "ui/views/window/dialog_delegate.h" | 18 #include "ui/views/window/dialog_delegate.h" | 
| 19 | 19 | 
|  | 20 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 
|  | 21 #include "ui/views/linux_ui/linux_ui.h" | 
|  | 22 #endif | 
|  | 23 | 
| 20 namespace { | 24 namespace { | 
| 21 | 25 | 
| 22 // The spacing between the icon and text. | 26 // The spacing between the icon and text. | 
| 23 const int kSpacing = 5; | 27 const int kSpacing = 5; | 
| 24 | 28 | 
| 25 // Default text and shadow colors for STYLE_BUTTON. | 29 // Default text and shadow colors for STYLE_BUTTON. | 
| 26 const SkColor kStyleButtonTextColor = SK_ColorBLACK; | 30 const SkColor kStyleButtonTextColor = SK_ColorBLACK; | 
| 27 const SkColor kStyleButtonShadowColor = SK_ColorWHITE; | 31 const SkColor kStyleButtonShadowColor = SK_ColorWHITE; | 
| 28 | 32 | 
| 29 }  // namespace | 33 }  // namespace | 
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 148   } | 152   } | 
| 149   if (style == STYLE_BUTTON) { | 153   if (style == STYLE_BUTTON) { | 
| 150     label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 154     label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 
| 151     SetFocusable(true); | 155     SetFocusable(true); | 
| 152   } | 156   } | 
| 153   if (style == STYLE_BUTTON) | 157   if (style == STYLE_BUTTON) | 
| 154     set_min_size(gfx::Size(70, 33)); | 158     set_min_size(gfx::Size(70, 33)); | 
| 155 | 159 | 
| 156   ResetColorsFromNativeTheme(); | 160   ResetColorsFromNativeTheme(); | 
| 157 | 161 | 
| 158   // Set the border and invalidate the layout to pickup its new insets. | 162   UpdateThemedBorder(new LabelButtonBorder(style_)); | 
| 159   set_border(new LabelButtonBorder(style)); | 163 | 
|  | 164   // Invalidate the layout to pickup the new insets from the border. | 
| 160   InvalidateLayout(); | 165   InvalidateLayout(); | 
| 161 } | 166 } | 
| 162 | 167 | 
| 163 void LabelButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { | 168 void LabelButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { | 
| 164   focus_painter_ = focus_painter.Pass(); | 169   focus_painter_ = focus_painter.Pass(); | 
| 165 } | 170 } | 
| 166 | 171 | 
| 167 gfx::Size LabelButton::GetPreferredSize() { | 172 gfx::Size LabelButton::GetPreferredSize() { | 
| 168   // Use a temporary label copy for sizing to avoid calculation side-effects. | 173   // Use a temporary label copy for sizing to avoid calculation side-effects. | 
| 169   const gfx::FontList& font_list = GetFontList(); | 174   const gfx::FontList& font_list = GetFontList(); | 
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 327       SetTextColor(static_cast<ButtonState>(state), colors[state]); | 332       SetTextColor(static_cast<ButtonState>(state), colors[state]); | 
| 328       explicitly_set_colors_[state] = false; | 333       explicitly_set_colors_[state] = false; | 
| 329     } | 334     } | 
| 330   } | 335   } | 
| 331 } | 336 } | 
| 332 | 337 | 
| 333 void LabelButton::UpdateImage() { | 338 void LabelButton::UpdateImage() { | 
| 334   image_->SetImage(GetImage(state())); | 339   image_->SetImage(GetImage(state())); | 
| 335 } | 340 } | 
| 336 | 341 | 
|  | 342 void LabelButton::UpdateThemedBorder(LabelButtonBorder* label_button_border) { | 
|  | 343 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 
|  | 344   views::LinuxUI* linux_ui = views::LinuxUI::instance(); | 
|  | 345   if (linux_ui) { | 
|  | 346     set_border(linux_ui->CreateNativeBorder(this, label_button_border)); | 
|  | 347   } else | 
|  | 348 #endif | 
|  | 349   { | 
|  | 350     set_border(label_button_border); | 
|  | 351   } | 
|  | 352 } | 
|  | 353 | 
| 337 void LabelButton::StateChanged() { | 354 void LabelButton::StateChanged() { | 
| 338   const gfx::Size previous_image_size(image_->GetPreferredSize()); | 355   const gfx::Size previous_image_size(image_->GetPreferredSize()); | 
| 339   UpdateImage(); | 356   UpdateImage(); | 
| 340   const SkColor color = button_state_colors_[state()]; | 357   const SkColor color = button_state_colors_[state()]; | 
| 341   if (state() != STATE_DISABLED && label_->enabled_color() != color) | 358   if (state() != STATE_DISABLED && label_->enabled_color() != color) | 
| 342     label_->SetEnabledColor(color); | 359     label_->SetEnabledColor(color); | 
| 343   label_->SetEnabled(state() != STATE_DISABLED); | 360   label_->SetEnabled(state() != STATE_DISABLED); | 
| 344   if (image_->GetPreferredSize() != previous_image_size) | 361   if (image_->GetPreferredSize() != previous_image_size) | 
| 345     Layout(); | 362     Layout(); | 
| 346 } | 363 } | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 384   return ui::NativeTheme::kNormal; | 401   return ui::NativeTheme::kNormal; | 
| 385 } | 402 } | 
| 386 | 403 | 
| 387 ui::NativeTheme::State LabelButton::GetForegroundThemeState( | 404 ui::NativeTheme::State LabelButton::GetForegroundThemeState( | 
| 388     ui::NativeTheme::ExtraParams* params) const { | 405     ui::NativeTheme::ExtraParams* params) const { | 
| 389   GetExtraParams(params); | 406   GetExtraParams(params); | 
| 390   return ui::NativeTheme::kHovered; | 407   return ui::NativeTheme::kHovered; | 
| 391 } | 408 } | 
| 392 | 409 | 
| 393 }  // namespace views | 410 }  // namespace views | 
| OLD | NEW | 
|---|