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 if (!enabled_color_set_) { | 381 UpdateColorsFromTheme(theme); |
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(); | |
394 } | 382 } |
395 | 383 |
396 void Label::Init(const base::string16& text, const gfx::FontList& font_list) { | 384 void Label::Init(const base::string16& text, const gfx::FontList& font_list) { |
397 font_list_ = font_list; | 385 font_list_ = font_list; |
398 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; | 386 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; |
399 auto_color_readability_ = true; | 387 auto_color_readability_ = true; |
| 388 UpdateColorsFromTheme(ui::NativeTheme::instance()); |
400 horizontal_alignment_ = gfx::ALIGN_CENTER; | 389 horizontal_alignment_ = gfx::ALIGN_CENTER; |
401 line_height_ = 0; | 390 line_height_ = 0; |
402 is_multi_line_ = false; | 391 is_multi_line_ = false; |
403 is_obscured_ = false; | 392 is_obscured_ = false; |
404 allow_character_break_ = false; | 393 allow_character_break_ = false; |
405 elide_behavior_ = ELIDE_AT_END; | 394 elide_behavior_ = ELIDE_AT_END; |
406 collapse_when_hidden_ = false; | 395 collapse_when_hidden_ = false; |
407 directionality_mode_ = USE_UI_DIRECTIONALITY; | 396 directionality_mode_ = USE_UI_DIRECTIONALITY; |
408 enabled_shadow_color_ = 0; | 397 enabled_shadow_color_ = 0; |
409 disabled_shadow_color_ = 0; | 398 disabled_shadow_color_ = 0; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 case gfx::ALIGN_RIGHT: | 472 case gfx::ALIGN_RIGHT: |
484 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; | 473 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; |
485 break; | 474 break; |
486 } | 475 } |
487 | 476 |
488 if (!is_multi_line_) | 477 if (!is_multi_line_) |
489 return flags; | 478 return flags; |
490 | 479 |
491 flags |= gfx::Canvas::MULTI_LINE; | 480 flags |= gfx::Canvas::MULTI_LINE; |
492 #if !defined(OS_WIN) | 481 #if !defined(OS_WIN) |
493 // Don't elide multiline labels on Linux. | 482 // Don't elide multiline labels on Linux. |
494 // Todo(davemoore): Do we depend on eliding multiline text? | 483 // Todo(davemoore): Do we depend on eliding multiline text? |
495 // Pango insists on limiting the number of lines to one if text is | 484 // Pango insists on limiting the number of lines to one if text is |
496 // elided. You can get around this if you can pass a maximum height | 485 // elided. You can get around this if you can pass a maximum height |
497 // but we don't currently have that data when we call the pango code. | 486 // but we don't currently have that data when we call the pango code. |
498 flags |= gfx::Canvas::NO_ELLIPSIS; | 487 flags |= gfx::Canvas::NO_ELLIPSIS; |
499 #endif | 488 #endif |
500 if (allow_character_break_) | 489 if (allow_character_break_) |
501 flags |= gfx::Canvas::CHARACTER_BREAK; | 490 flags |= gfx::Canvas::CHARACTER_BREAK; |
502 | 491 |
503 return flags; | 492 return flags; |
504 } | 493 } |
505 | 494 |
506 gfx::Rect Label::GetAvailableRect() const { | 495 gfx::Rect Label::GetAvailableRect() const { |
507 gfx::Rect bounds(size()); | 496 gfx::Rect bounds(size()); |
508 bounds.Inset(GetInsets()); | 497 bounds.Inset(GetInsets()); |
(...skipping 29 matching lines...) Expand all Loading... |
538 *paint_text = | 527 *paint_text = |
539 gfx::ElideEmail(layout_text(), font_list_, GetAvailableRect().width()); | 528 gfx::ElideEmail(layout_text(), font_list_, GetAvailableRect().width()); |
540 } | 529 } |
541 | 530 |
542 *text_bounds = GetTextBounds(); | 531 *text_bounds = GetTextBounds(); |
543 *flags = ComputeDrawStringFlags(); | 532 *flags = ComputeDrawStringFlags(); |
544 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE)) | 533 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE)) |
545 *flags |= gfx::Canvas::NO_ELLIPSIS; | 534 *flags |= gfx::Canvas::NO_ELLIPSIS; |
546 } | 535 } |
547 | 536 |
| 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 |
548 void Label::ResetCachedSize() { | 553 void Label::ResetCachedSize() { |
549 text_size_valid_ = false; | 554 text_size_valid_ = false; |
550 cached_heights_cursor_ = 0; | 555 cached_heights_cursor_ = 0; |
551 for (int i = 0; i < kCachedSizeLimit; ++i) | 556 for (int i = 0; i < kCachedSizeLimit; ++i) |
552 cached_heights_[i] = gfx::Size(); | 557 cached_heights_[i] = gfx::Size(); |
553 } | 558 } |
554 | 559 |
555 bool Label::ShouldShowDefaultTooltip() const { | 560 bool Label::ShouldShowDefaultTooltip() const { |
556 return !is_multi_line_ && !is_obscured_ && | 561 return !is_multi_line_ && !is_obscured_ && |
557 gfx::GetStringWidth(layout_text(), font_list_) > | 562 gfx::GetStringWidth(layout_text(), font_list_) > |
558 GetAvailableRect().width(); | 563 GetAvailableRect().width(); |
559 } | 564 } |
560 | 565 |
561 } // namespace views | 566 } // namespace views |
OLD | NEW |