Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/button/text_button.h" | 5 #include "views/controls/button/text_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 color_(kEnabledColor), | 258 color_(kEnabledColor), |
| 259 color_enabled_(kEnabledColor), | 259 color_enabled_(kEnabledColor), |
| 260 color_disabled_(kDisabledColor), | 260 color_disabled_(kDisabledColor), |
| 261 color_highlight_(kHighlightColor), | 261 color_highlight_(kHighlightColor), |
| 262 color_hover_(kHoverColor), | 262 color_hover_(kHoverColor), |
| 263 text_halo_color_(0), | 263 text_halo_color_(0), |
| 264 has_text_halo_(false), | 264 has_text_halo_(false), |
| 265 active_text_shadow_color_(0), | 265 active_text_shadow_color_(0), |
| 266 inactive_text_shadow_color_(0), | 266 inactive_text_shadow_color_(0), |
| 267 has_shadow_(false), | 267 has_shadow_(false), |
| 268 shadow_offset_(gfx::Point(1, 1)), | |
| 268 max_width_(0), | 269 max_width_(0), |
| 269 normal_has_border_(false), | 270 normal_has_border_(false), |
| 270 show_multiple_icon_states_(true), | 271 show_multiple_icon_states_(true), |
| 271 is_default_(false), | 272 is_default_(false), |
| 272 prefix_type_(PREFIX_NONE) { | 273 prefix_type_(PREFIX_NONE) { |
| 273 SetText(text); | 274 SetText(text); |
| 274 SetAnimationDuration(kHoverAnimationDurationMs); | 275 SetAnimationDuration(kHoverAnimationDurationMs); |
| 275 } | 276 } |
| 276 | 277 |
| 277 TextButtonBase::~TextButtonBase() { | 278 TextButtonBase::~TextButtonBase() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 has_text_halo_ = true; | 323 has_text_halo_ = true; |
| 323 } | 324 } |
| 324 | 325 |
| 325 void TextButtonBase::SetTextShadowColors(SkColor active_color, | 326 void TextButtonBase::SetTextShadowColors(SkColor active_color, |
| 326 SkColor inactive_color) { | 327 SkColor inactive_color) { |
| 327 active_text_shadow_color_ = active_color; | 328 active_text_shadow_color_ = active_color; |
| 328 inactive_text_shadow_color_ = inactive_color; | 329 inactive_text_shadow_color_ = inactive_color; |
| 329 has_shadow_ = true; | 330 has_shadow_ = true; |
| 330 } | 331 } |
| 331 | 332 |
| 333 void TextButtonBase::SetTextShadowOffset(int x, int y) { | |
| 334 shadow_offset_ = gfx::Point(x, y); | |
|
sky
2011/05/02 14:26:27
SetPoint
| |
| 335 } | |
| 336 | |
| 332 void TextButtonBase::ClearMaxTextSize() { | 337 void TextButtonBase::ClearMaxTextSize() { |
| 333 max_text_size_ = text_size_; | 338 max_text_size_ = text_size_; |
| 334 } | 339 } |
| 335 | 340 |
| 336 void TextButtonBase::SetNormalHasBorder(bool normal_has_border) { | 341 void TextButtonBase::SetNormalHasBorder(bool normal_has_border) { |
| 337 normal_has_border_ = normal_has_border; | 342 normal_has_border_ = normal_has_border; |
| 338 } | 343 } |
| 339 | 344 |
| 340 void TextButtonBase::SetShowMultipleIconStates(bool show_multiple_icon_states) { | 345 void TextButtonBase::SetShowMultipleIconStates(bool show_multiple_icon_states) { |
| 341 show_multiple_icon_states_ = show_multiple_icon_states; | 346 show_multiple_icon_states_ = show_multiple_icon_states; |
| 342 } | 347 } |
| 343 | 348 |
| 349 void TextButtonBase::ClearEmbellishing() { | |
| 350 has_shadow_ = false; | |
| 351 has_text_halo_ = false; | |
| 352 } | |
| 353 | |
| 344 gfx::Size TextButtonBase::GetPreferredSize() { | 354 gfx::Size TextButtonBase::GetPreferredSize() { |
| 345 gfx::Insets insets = GetInsets(); | 355 gfx::Insets insets = GetInsets(); |
| 346 | 356 |
| 347 // Use the max size to set the button boundaries. | 357 // Use the max size to set the button boundaries. |
| 348 gfx::Size prefsize(max_text_size_.width() + insets.width(), | 358 gfx::Size prefsize(max_text_size_.width() + insets.width(), |
| 349 max_text_size_.height() + insets.height()); | 359 max_text_size_.height() + insets.height()); |
| 350 | 360 |
| 351 if (max_width_ > 0) | 361 if (max_width_ > 0) |
| 352 prefsize.set_width(std::min(max_width_, prefsize.width())); | 362 prefsize.set_width(std::min(max_width_, prefsize.width())); |
| 353 | 363 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 text_, font_, text_color, text_halo_color_, | 479 text_, font_, text_color, text_halo_color_, |
| 470 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 480 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
| 471 text_bounds.height(), draw_string_flags); | 481 text_bounds.height(), draw_string_flags); |
| 472 } else if (has_shadow_) { | 482 } else if (has_shadow_) { |
| 473 SkColor shadow_color = | 483 SkColor shadow_color = |
| 474 GetWidget()->IsActive() ? active_text_shadow_color_ : | 484 GetWidget()->IsActive() ? active_text_shadow_color_ : |
| 475 inactive_text_shadow_color_; | 485 inactive_text_shadow_color_; |
| 476 canvas->DrawStringInt(text_, | 486 canvas->DrawStringInt(text_, |
| 477 font_, | 487 font_, |
| 478 shadow_color, | 488 shadow_color, |
| 479 text_bounds.x() + 1, | 489 text_bounds.x() + shadow_offset_.x(), |
| 480 text_bounds.y() + 1, | 490 text_bounds.y() + shadow_offset_.y(), |
| 481 text_bounds.width(), | 491 text_bounds.width(), |
| 482 text_bounds.height(), | 492 text_bounds.height(), |
| 483 draw_string_flags); | 493 draw_string_flags); |
| 484 canvas->DrawStringInt(text_, | 494 canvas->DrawStringInt(text_, |
| 485 font_, | 495 font_, |
| 486 text_color, | 496 text_color, |
| 487 text_bounds.x(), | 497 text_bounds.x(), |
| 488 text_bounds.y(), | 498 text_bounds.y(), |
| 489 text_bounds.width(), | 499 text_bounds.width(), |
| 490 text_bounds.height(), | 500 text_bounds.height(), |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 } | 727 } |
| 718 } | 728 } |
| 719 } | 729 } |
| 720 | 730 |
| 721 return bounds; | 731 return bounds; |
| 722 } | 732 } |
| 723 | 733 |
| 724 } // namespace views | 734 } // namespace views |
| 725 | 735 |
| 726 | 736 |
| OLD | NEW |