| 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() |
| 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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 selection_background_color_) | 980 selection_background_color_) |
| 958 : requested_selection_text_color_; | 981 : requested_selection_text_color_; |
| 959 | 982 |
| 960 ApplyTextColors(); | 983 ApplyTextColors(); |
| 961 SchedulePaint(); | 984 SchedulePaint(); |
| 962 } | 985 } |
| 963 | 986 |
| 964 void Label::ApplyTextColors() const { | 987 void Label::ApplyTextColors() const { |
| 965 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; | 988 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; |
| 966 bool subpixel_rendering_suppressed = | 989 bool subpixel_rendering_suppressed = |
| 967 SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_; | 990 SkColorGetA(background_color_) != SK_AlphaOPAQUE || |
| 991 !subpixel_rendering_enabled_; |
| 968 for (size_t i = 0; i < lines_.size(); ++i) { | 992 for (size_t i = 0; i < lines_.size(); ++i) { |
| 969 lines_[i]->SetColor(color); | 993 lines_[i]->SetColor(color); |
| 970 lines_[i]->set_selection_color(actual_selection_text_color_); | 994 lines_[i]->set_selection_color(actual_selection_text_color_); |
| 971 lines_[i]->set_selection_background_focused_color( | 995 lines_[i]->set_selection_background_focused_color( |
| 972 selection_background_color_); | 996 selection_background_color_); |
| 973 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); | 997 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); |
| 974 } | 998 } |
| 975 } | 999 } |
| 976 | 1000 |
| 977 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { | 1001 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 .WriteText(GetSelectedText()); | 1056 .WriteText(GetSelectedText()); |
| 1033 } | 1057 } |
| 1034 | 1058 |
| 1035 void Label::BuildContextMenuContents() { | 1059 void Label::BuildContextMenuContents() { |
| 1036 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1060 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 1037 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, | 1061 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, |
| 1038 IDS_APP_SELECT_ALL); | 1062 IDS_APP_SELECT_ALL); |
| 1039 } | 1063 } |
| 1040 | 1064 |
| 1041 } // namespace views | 1065 } // namespace views |
| OLD | NEW |