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