Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 render_text->SetMinLineHeight(line_height()); | 443 render_text->SetMinLineHeight(line_height()); |
| 444 render_text->SetFontList(font_list()); | 444 render_text->SetFontList(font_list()); |
| 445 render_text->set_shadows(shadows()); | 445 render_text->set_shadows(shadows()); |
| 446 render_text->SetCursorEnabled(false); | 446 render_text->SetCursorEnabled(false); |
| 447 render_text->SetText(text); | 447 render_text->SetText(text); |
| 448 return render_text; | 448 return render_text; |
| 449 } | 449 } |
| 450 | 450 |
| 451 void Label::PaintText(gfx::Canvas* canvas) { | 451 void Label::PaintText(gfx::Canvas* canvas) { |
| 452 MaybeBuildRenderTextLines(); | 452 MaybeBuildRenderTextLines(); |
| 453 | |
| 453 for (size_t i = 0; i < lines_.size(); ++i) | 454 for (size_t i = 0; i < lines_.size(); ++i) |
| 454 lines_[i]->Draw(canvas); | 455 lines_[i]->Draw(canvas); |
| 456 | |
| 457 #if DCHECK_IS_ON() | |
| 458 if (!lines_.empty()) { | |
|
sadrul
2017/02/08 02:13:56
early return insrtead
Evan Stade
2017/02/11 00:18:07
Done.
| |
| 459 // Attempt to ensure that if we're using subpixel rendering, we're painting | |
| 460 // to an opaque background. What we don't want to find is an ancestor in the | |
| 461 // hierarchy that paints to a non-opaque layer. | |
| 462 if (!lines_[0]->subpixel_rendering_suppressed()) { | |
|
sadrul
2017/02/08 02:13:56
ditto
Evan Stade
2017/02/11 00:18:07
Done.
| |
| 463 for (View* view = this; view; view = view->parent()) { | |
| 464 if (view->background()) | |
|
sadrul
2017/02/08 02:13:56
Maybe you can continue with the loop if SkColorGet
Evan Stade
2017/02/11 00:18:07
Done.
| |
| 465 break; | |
| 466 if (view->layer()) { | |
| 467 DCHECK(view->layer()->fills_bounds_opaquely()) | |
| 468 << " Ancestor view has a non-opaque layer: " | |
| 469 << view->GetClassName() << " with ID " << view->id(); | |
| 470 break; | |
| 471 } | |
| 472 } | |
| 473 } | |
| 474 } | |
| 475 #endif | |
| 476 | |
| 455 } | 477 } |
| 456 | 478 |
| 457 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 479 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 458 if (previous_bounds.size() != size()) | 480 if (previous_bounds.size() != size()) |
| 459 InvalidateLayout(); | 481 InvalidateLayout(); |
| 460 } | 482 } |
| 461 | 483 |
| 462 void Label::OnPaint(gfx::Canvas* canvas) { | 484 void Label::OnPaint(gfx::Canvas* canvas) { |
| 463 View::OnPaint(canvas); | 485 View::OnPaint(canvas); |
| 464 if (is_first_paint_text_) { | 486 if (is_first_paint_text_) { |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 972 selection_background_color_) | 994 selection_background_color_) |
| 973 : requested_selection_text_color_; | 995 : requested_selection_text_color_; |
| 974 | 996 |
| 975 ApplyTextColors(); | 997 ApplyTextColors(); |
| 976 SchedulePaint(); | 998 SchedulePaint(); |
| 977 } | 999 } |
| 978 | 1000 |
| 979 void Label::ApplyTextColors() const { | 1001 void Label::ApplyTextColors() const { |
| 980 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; | 1002 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; |
| 981 bool subpixel_rendering_suppressed = | 1003 bool subpixel_rendering_suppressed = |
| 982 SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_; | 1004 SkColorGetA(background_color_) != SK_AlphaOPAQUE || |
| 1005 !subpixel_rendering_enabled_; | |
| 983 for (size_t i = 0; i < lines_.size(); ++i) { | 1006 for (size_t i = 0; i < lines_.size(); ++i) { |
| 984 lines_[i]->SetColor(color); | 1007 lines_[i]->SetColor(color); |
| 985 lines_[i]->set_selection_color(actual_selection_text_color_); | 1008 lines_[i]->set_selection_color(actual_selection_text_color_); |
| 986 lines_[i]->set_selection_background_focused_color( | 1009 lines_[i]->set_selection_background_focused_color( |
| 987 selection_background_color_); | 1010 selection_background_color_); |
| 988 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); | 1011 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); |
| 989 } | 1012 } |
| 990 } | 1013 } |
| 991 | 1014 |
| 992 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { | 1015 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1047 .WriteText(GetSelectedText()); | 1070 .WriteText(GetSelectedText()); |
| 1048 } | 1071 } |
| 1049 | 1072 |
| 1050 void Label::BuildContextMenuContents() { | 1073 void Label::BuildContextMenuContents() { |
| 1051 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1074 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 1052 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, | 1075 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, |
| 1053 IDS_APP_SELECT_ALL); | 1076 IDS_APP_SELECT_ALL); |
| 1054 } | 1077 } |
| 1055 | 1078 |
| 1056 } // namespace views | 1079 } // namespace views |
| OLD | NEW |