| 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/label.h" | 5 #include "ui/views/controls/label.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 OnPaintBorder(canvas); | 371 OnPaintBorder(canvas); |
| 372 | 372 |
| 373 base::string16 paint_text; | 373 base::string16 paint_text; |
| 374 gfx::Rect text_bounds; | 374 gfx::Rect text_bounds; |
| 375 int flags = 0; | 375 int flags = 0; |
| 376 CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 376 CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 377 PaintText(canvas, paint_text, text_bounds, flags); | 377 PaintText(canvas, paint_text, text_bounds, flags); |
| 378 } | 378 } |
| 379 | 379 |
| 380 void Label::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 380 void Label::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 381 UpdateColorsFromTheme(theme); | 381 if (!enabled_color_set_) { |
| 382 requested_enabled_color_ = theme->GetSystemColor( |
| 383 ui::NativeTheme::kColorId_LabelEnabledColor); |
| 384 } |
| 385 if (!disabled_color_set_) { |
| 386 requested_disabled_color_ = theme->GetSystemColor( |
| 387 ui::NativeTheme::kColorId_LabelDisabledColor); |
| 388 } |
| 389 if (!background_color_set_) { |
| 390 background_color_ = theme->GetSystemColor( |
| 391 ui::NativeTheme::kColorId_LabelBackgroundColor); |
| 392 } |
| 393 RecalculateColors(); |
| 382 } | 394 } |
| 383 | 395 |
| 384 void Label::Init(const base::string16& text, const gfx::FontList& font_list) { | 396 void Label::Init(const base::string16& text, const gfx::FontList& font_list) { |
| 385 font_list_ = font_list; | 397 font_list_ = font_list; |
| 386 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; | 398 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; |
| 387 auto_color_readability_ = true; | 399 auto_color_readability_ = true; |
| 388 UpdateColorsFromTheme(ui::NativeTheme::instance()); | |
| 389 horizontal_alignment_ = gfx::ALIGN_CENTER; | 400 horizontal_alignment_ = gfx::ALIGN_CENTER; |
| 390 line_height_ = 0; | 401 line_height_ = 0; |
| 391 is_multi_line_ = false; | 402 is_multi_line_ = false; |
| 392 is_obscured_ = false; | 403 is_obscured_ = false; |
| 393 allow_character_break_ = false; | 404 allow_character_break_ = false; |
| 394 elide_behavior_ = ELIDE_AT_END; | 405 elide_behavior_ = ELIDE_AT_END; |
| 395 collapse_when_hidden_ = false; | 406 collapse_when_hidden_ = false; |
| 396 directionality_mode_ = USE_UI_DIRECTIONALITY; | 407 directionality_mode_ = USE_UI_DIRECTIONALITY; |
| 397 enabled_shadow_color_ = 0; | 408 enabled_shadow_color_ = 0; |
| 398 disabled_shadow_color_ = 0; | 409 disabled_shadow_color_ = 0; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 *paint_text = | 538 *paint_text = |
| 528 gfx::ElideEmail(layout_text(), font_list_, GetAvailableRect().width()); | 539 gfx::ElideEmail(layout_text(), font_list_, GetAvailableRect().width()); |
| 529 } | 540 } |
| 530 | 541 |
| 531 *text_bounds = GetTextBounds(); | 542 *text_bounds = GetTextBounds(); |
| 532 *flags = ComputeDrawStringFlags(); | 543 *flags = ComputeDrawStringFlags(); |
| 533 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE)) | 544 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE)) |
| 534 *flags |= gfx::Canvas::NO_ELLIPSIS; | 545 *flags |= gfx::Canvas::NO_ELLIPSIS; |
| 535 } | 546 } |
| 536 | 547 |
| 537 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { | |
| 538 if (!enabled_color_set_) { | |
| 539 requested_enabled_color_ = theme->GetSystemColor( | |
| 540 ui::NativeTheme::kColorId_LabelEnabledColor); | |
| 541 } | |
| 542 if (!disabled_color_set_) { | |
| 543 requested_disabled_color_ = theme->GetSystemColor( | |
| 544 ui::NativeTheme::kColorId_LabelDisabledColor); | |
| 545 } | |
| 546 if (!background_color_set_) { | |
| 547 background_color_ = theme->GetSystemColor( | |
| 548 ui::NativeTheme::kColorId_LabelBackgroundColor); | |
| 549 } | |
| 550 RecalculateColors(); | |
| 551 } | |
| 552 | |
| 553 void Label::ResetCachedSize() { | 548 void Label::ResetCachedSize() { |
| 554 text_size_valid_ = false; | 549 text_size_valid_ = false; |
| 555 cached_heights_cursor_ = 0; | 550 cached_heights_cursor_ = 0; |
| 556 for (int i = 0; i < kCachedSizeLimit; ++i) | 551 for (int i = 0; i < kCachedSizeLimit; ++i) |
| 557 cached_heights_[i] = gfx::Size(); | 552 cached_heights_[i] = gfx::Size(); |
| 558 } | 553 } |
| 559 | 554 |
| 560 bool Label::ShouldShowDefaultTooltip() const { | 555 bool Label::ShouldShowDefaultTooltip() const { |
| 561 return !is_multi_line_ && !is_obscured_ && | 556 return !is_multi_line_ && !is_obscured_ && |
| 562 gfx::GetStringWidth(layout_text(), font_list_) > | 557 gfx::GetStringWidth(layout_text(), font_list_) > |
| 563 GetAvailableRect().width(); | 558 GetAvailableRect().width(); |
| 564 } | 559 } |
| 565 | 560 |
| 566 } // namespace views | 561 } // namespace views |
| OLD | NEW |