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 12 matching lines...) Expand all Loading... | |
| 23 #include "ui/base/cursor/cursor.h" | 23 #include "ui/base/cursor/cursor.h" |
| 24 #include "ui/base/default_style.h" | 24 #include "ui/base/default_style.h" |
| 25 #include "ui/base/material_design/material_design_controller.h" | 25 #include "ui/base/material_design/material_design_controller.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/color_utils.h" | 28 #include "ui/gfx/color_utils.h" |
| 29 #include "ui/gfx/geometry/insets.h" | 29 #include "ui/gfx/geometry/insets.h" |
| 30 #include "ui/gfx/text_elider.h" | 30 #include "ui/gfx/text_elider.h" |
| 31 #include "ui/native_theme/native_theme.h" | 31 #include "ui/native_theme/native_theme.h" |
| 32 #include "ui/strings/grit/ui_strings.h" | 32 #include "ui/strings/grit/ui_strings.h" |
| 33 #include "ui/views/background.h" | |
| 33 #include "ui/views/controls/menu/menu_runner.h" | 34 #include "ui/views/controls/menu/menu_runner.h" |
| 34 #include "ui/views/focus/focus_manager.h" | 35 #include "ui/views/focus/focus_manager.h" |
| 35 #include "ui/views/native_cursor.h" | 36 #include "ui/views/native_cursor.h" |
| 36 #include "ui/views/selection_controller.h" | 37 #include "ui/views/selection_controller.h" |
| 37 | 38 |
| 38 namespace views { | 39 namespace views { |
| 39 // static | 40 // static |
| 40 const char Label::kViewClassName[] = "Label"; | 41 const char Label::kViewClassName[] = "Label"; |
| 41 const int Label::kFocusBorderPadding = 1; | 42 const int Label::kFocusBorderPadding = 1; |
| 42 | 43 |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 render_text->SetMinLineHeight(line_height()); | 444 render_text->SetMinLineHeight(line_height()); |
| 444 render_text->SetFontList(font_list()); | 445 render_text->SetFontList(font_list()); |
| 445 render_text->set_shadows(shadows()); | 446 render_text->set_shadows(shadows()); |
| 446 render_text->SetCursorEnabled(false); | 447 render_text->SetCursorEnabled(false); |
| 447 render_text->SetText(text); | 448 render_text->SetText(text); |
| 448 return render_text; | 449 return render_text; |
| 449 } | 450 } |
| 450 | 451 |
| 451 void Label::PaintText(gfx::Canvas* canvas) { | 452 void Label::PaintText(gfx::Canvas* canvas) { |
| 452 MaybeBuildRenderTextLines(); | 453 MaybeBuildRenderTextLines(); |
| 454 | |
| 453 for (size_t i = 0; i < lines_.size(); ++i) | 455 for (size_t i = 0; i < lines_.size(); ++i) |
| 454 lines_[i]->Draw(canvas); | 456 lines_[i]->Draw(canvas); |
| 457 | |
| 458 #if DCHECK_IS_ON() | |
|
msw
2017/02/11 00:49:37
optional nit: it might be nice to have this as a s
Evan Stade
2017/02/11 01:42:37
I share your concern about the unnoticed early ret
| |
| 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_.empty() || lines_[0]->subpixel_rendering_suppressed()) | |
| 463 return; | |
| 464 | |
| 465 for (View* view = this; view; view = view->parent()) { | |
| 466 if (view->background() && | |
| 467 SkColorGetA(view->background()->get_color()) == SK_AlphaOPAQUE) | |
| 468 break; | |
| 469 | |
| 470 if (view->layer()) { | |
| 471 DCHECK(view->layer()->fills_bounds_opaquely()) | |
| 472 << " Ancestor view has a non-opaque layer: " << view->GetClassName() | |
| 473 << " with ID " << view->id(); | |
| 474 break; | |
| 475 } | |
| 476 } | |
| 477 #endif | |
| 455 } | 478 } |
| 456 | 479 |
| 457 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 480 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 458 if (previous_bounds.size() != size()) | 481 if (previous_bounds.size() != size()) |
| 459 InvalidateLayout(); | 482 InvalidateLayout(); |
| 460 } | 483 } |
| 461 | 484 |
| 462 void Label::OnPaint(gfx::Canvas* canvas) { | 485 void Label::OnPaint(gfx::Canvas* canvas) { |
| 463 View::OnPaint(canvas); | 486 View::OnPaint(canvas); |
| 464 if (is_first_paint_text_) { | 487 if (is_first_paint_text_) { |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 972 selection_background_color_) | 995 selection_background_color_) |
| 973 : requested_selection_text_color_; | 996 : requested_selection_text_color_; |
| 974 | 997 |
| 975 ApplyTextColors(); | 998 ApplyTextColors(); |
| 976 SchedulePaint(); | 999 SchedulePaint(); |
| 977 } | 1000 } |
| 978 | 1001 |
| 979 void Label::ApplyTextColors() const { | 1002 void Label::ApplyTextColors() const { |
| 980 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; | 1003 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; |
| 981 bool subpixel_rendering_suppressed = | 1004 bool subpixel_rendering_suppressed = |
| 982 SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_; | 1005 SkColorGetA(background_color_) != SK_AlphaOPAQUE || |
| 1006 !subpixel_rendering_enabled_; | |
| 983 for (size_t i = 0; i < lines_.size(); ++i) { | 1007 for (size_t i = 0; i < lines_.size(); ++i) { |
| 984 lines_[i]->SetColor(color); | 1008 lines_[i]->SetColor(color); |
| 985 lines_[i]->set_selection_color(actual_selection_text_color_); | 1009 lines_[i]->set_selection_color(actual_selection_text_color_); |
| 986 lines_[i]->set_selection_background_focused_color( | 1010 lines_[i]->set_selection_background_focused_color( |
| 987 selection_background_color_); | 1011 selection_background_color_); |
| 988 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); | 1012 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); |
| 989 } | 1013 } |
| 990 } | 1014 } |
| 991 | 1015 |
| 992 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { | 1016 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1047 .WriteText(GetSelectedText()); | 1071 .WriteText(GetSelectedText()); |
| 1048 } | 1072 } |
| 1049 | 1073 |
| 1050 void Label::BuildContextMenuContents() { | 1074 void Label::BuildContextMenuContents() { |
| 1051 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1075 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 1052 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, | 1076 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, |
| 1053 IDS_APP_SELECT_ALL); | 1077 IDS_APP_SELECT_ALL); |
| 1054 } | 1078 } |
| 1055 | 1079 |
| 1056 } // namespace views | 1080 } // namespace views |
| OLD | NEW |