| 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" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { | 94 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { |
| 95 button_state_colors_[for_state] = color; | 95 button_state_colors_[for_state] = color; |
| 96 if (for_state == STATE_DISABLED) | 96 if (for_state == STATE_DISABLED) |
| 97 label_->SetDisabledColor(color); | 97 label_->SetDisabledColor(color); |
| 98 else if (for_state == state()) | 98 else if (for_state == state()) |
| 99 label_->SetEnabledColor(color); | 99 label_->SetEnabledColor(color); |
| 100 explicitly_set_colors_[for_state] = true; | 100 explicitly_set_colors_[for_state] = true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void LabelButton::SetHaloColor(SkColor color) { | |
| 104 label_->set_halo_color(color); | |
| 105 } | |
| 106 | |
| 107 bool LabelButton::GetTextMultiLine() const { | 103 bool LabelButton::GetTextMultiLine() const { |
| 108 return label_->is_multi_line(); | 104 return label_->is_multi_line(); |
| 109 } | 105 } |
| 110 | 106 |
| 111 void LabelButton::SetTextMultiLine(bool text_multi_line) { | 107 void LabelButton::SetTextMultiLine(bool text_multi_line) { |
| 112 label_->SetMultiLine(text_multi_line); | 108 label_->SetMultiLine(text_multi_line); |
| 113 } | 109 } |
| 114 | 110 |
| 115 const gfx::FontList& LabelButton::GetFontList() const { | 111 const gfx::FontList& LabelButton::GetFontList() const { |
| 116 return label_->font_list(); | 112 return label_->font_list(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 size.set_height(std::min(max_size_.height(), size.height())); | 215 size.set_height(std::min(max_size_.height(), size.height())); |
| 220 return size; | 216 return size; |
| 221 } | 217 } |
| 222 | 218 |
| 223 void LabelButton::Layout() { | 219 void LabelButton::Layout() { |
| 224 gfx::HorizontalAlignment adjusted_alignment = GetHorizontalAlignment(); | 220 gfx::HorizontalAlignment adjusted_alignment = GetHorizontalAlignment(); |
| 225 if (base::i18n::IsRTL() && adjusted_alignment != gfx::ALIGN_CENTER) | 221 if (base::i18n::IsRTL() && adjusted_alignment != gfx::ALIGN_CENTER) |
| 226 adjusted_alignment = (adjusted_alignment == gfx::ALIGN_LEFT) ? | 222 adjusted_alignment = (adjusted_alignment == gfx::ALIGN_LEFT) ? |
| 227 gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT; | 223 gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT; |
| 228 | 224 |
| 229 gfx::Rect child_area(GetChildAreaBounds()); | 225 gfx::Rect child_area(GetLocalBounds()); |
| 230 child_area.Inset(GetInsets()); | 226 child_area.Inset(GetInsets()); |
| 231 | 227 |
| 232 gfx::Size image_size(image_->GetPreferredSize()); | 228 gfx::Size image_size(image_->GetPreferredSize()); |
| 233 image_size.SetToMin(child_area.size()); | 229 image_size.SetToMin(child_area.size()); |
| 234 | 230 |
| 235 // The label takes any remaining width after sizing the image, unless both | 231 // The label takes any remaining width after sizing the image, unless both |
| 236 // views are centered. In that case, using the tighter preferred label width | 232 // views are centered. In that case, using the tighter preferred label width |
| 237 // avoids wasted space within the label that would look like awkward padding. | 233 // avoids wasted space within the label that would look like awkward padding. |
| 238 gfx::Size label_size(child_area.size()); | 234 gfx::Size label_size(child_area.size()); |
| 239 if (!image_size.IsEmpty() && !label_size.IsEmpty()) { | 235 if (!image_size.IsEmpty() && !label_size.IsEmpty()) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 268 |
| 273 scoped_ptr<LabelButtonBorder> LabelButton::CreateDefaultBorder() const { | 269 scoped_ptr<LabelButtonBorder> LabelButton::CreateDefaultBorder() const { |
| 274 return scoped_ptr<LabelButtonBorder>(new LabelButtonBorder(style_)); | 270 return scoped_ptr<LabelButtonBorder>(new LabelButtonBorder(style_)); |
| 275 } | 271 } |
| 276 | 272 |
| 277 void LabelButton::SetBorder(scoped_ptr<Border> border) { | 273 void LabelButton::SetBorder(scoped_ptr<Border> border) { |
| 278 border_is_themed_border_ = false; | 274 border_is_themed_border_ = false; |
| 279 View::SetBorder(border.Pass()); | 275 View::SetBorder(border.Pass()); |
| 280 } | 276 } |
| 281 | 277 |
| 282 gfx::Rect LabelButton::GetChildAreaBounds() { | |
| 283 return GetLocalBounds(); | |
| 284 } | |
| 285 | |
| 286 void LabelButton::OnPaint(gfx::Canvas* canvas) { | 278 void LabelButton::OnPaint(gfx::Canvas* canvas) { |
| 287 View::OnPaint(canvas); | 279 View::OnPaint(canvas); |
| 288 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); | 280 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
| 289 } | 281 } |
| 290 | 282 |
| 291 void LabelButton::OnFocus() { | 283 void LabelButton::OnFocus() { |
| 292 View::OnFocus(); | 284 View::OnFocus(); |
| 293 // Typically the border renders differently when focused. | 285 // Typically the border renders differently when focused. |
| 294 SchedulePaint(); | 286 SchedulePaint(); |
| 295 } | 287 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 // Don't override borders set by others. | 359 // Don't override borders set by others. |
| 368 if (!border_is_themed_border_) | 360 if (!border_is_themed_border_) |
| 369 return; | 361 return; |
| 370 | 362 |
| 371 scoped_ptr<LabelButtonBorder> label_button_border = CreateDefaultBorder(); | 363 scoped_ptr<LabelButtonBorder> label_button_border = CreateDefaultBorder(); |
| 372 | 364 |
| 373 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 365 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 374 views::LinuxUI* linux_ui = views::LinuxUI::instance(); | 366 views::LinuxUI* linux_ui = views::LinuxUI::instance(); |
| 375 if (linux_ui) { | 367 if (linux_ui) { |
| 376 SetBorder(linux_ui->CreateNativeBorder( | 368 SetBorder(linux_ui->CreateNativeBorder( |
| 377 this, label_button_border.Pass())); | 369 this, label_button_border.PassAs<Border>())); |
| 378 } else | 370 } else |
| 379 #endif | 371 #endif |
| 380 { | 372 { |
| 381 SetBorder(label_button_border.PassAs<Border>()); | 373 SetBorder(label_button_border.PassAs<Border>()); |
| 382 } | 374 } |
| 383 | 375 |
| 384 border_is_themed_border_ = true; | 376 border_is_themed_border_ = true; |
| 385 } | 377 } |
| 386 | 378 |
| 387 void LabelButton::StateChanged() { | 379 void LabelButton::StateChanged() { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 return ui::NativeTheme::kNormal; | 429 return ui::NativeTheme::kNormal; |
| 438 } | 430 } |
| 439 | 431 |
| 440 ui::NativeTheme::State LabelButton::GetForegroundThemeState( | 432 ui::NativeTheme::State LabelButton::GetForegroundThemeState( |
| 441 ui::NativeTheme::ExtraParams* params) const { | 433 ui::NativeTheme::ExtraParams* params) const { |
| 442 GetExtraParams(params); | 434 GetExtraParams(params); |
| 443 return ui::NativeTheme::kHovered; | 435 return ui::NativeTheme::kHovered; |
| 444 } | 436 } |
| 445 | 437 |
| 446 } // namespace views | 438 } // namespace views |
| OLD | NEW |