Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: ui/views/controls/label.cc

Issue 2661313005: Add extra DCHECKing to try to catch subpixel rendering on a non-opaque (Closed)
Patch Set: checkpoint Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 for (size_t i = 0; i < lines_.size(); ++i) 453
454 for (size_t i = 0; i < lines_.size(); ++i) {
454 lines_[i]->Draw(canvas); 455 lines_[i]->Draw(canvas);
456 #if DCHECK_IS_ON()
457 // Attempt to ensure that if we're using subpixel rendering, we're painting
458 // to an opaque background. What we don't want to find is an ancestor in the
459 // hierarchy that paints to a non-opaque layer.
460 if (!lines_[i]->subpixel_rendering_suppressed()) {
Daniel Erat 2017/02/06 22:35:49 as a minor optimization, you can skip the stuff in
Evan Stade 2017/02/07 23:55:19 yea, we can just do this for the first line since
461 for (View* view = this; view; view = view->parent()) {
462 if (view->background())
463 break;
sadrul 2017/02/07 03:36:39 The background could be non-opaque (e.g. solid-col
Evan Stade 2017/02/07 23:51:23 Correct, that's the situation I was referring to i
464 if (view->layer()) {
465 DCHECK(view->layer()->fills_bounds_opaquely())
466 << " Ancestor view has a non-opaque layer: "
467 << view->GetClassName() << " with ID " << view->id();
468 break;
469 }
470 }
471 }
472 #endif
473 }
455 } 474 }
456 475
457 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { 476 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) {
458 if (previous_bounds.size() != size()) 477 if (previous_bounds.size() != size())
459 InvalidateLayout(); 478 InvalidateLayout();
460 } 479 }
461 480
462 void Label::OnPaint(gfx::Canvas* canvas) { 481 void Label::OnPaint(gfx::Canvas* canvas) {
463 View::OnPaint(canvas); 482 View::OnPaint(canvas);
464 if (is_first_paint_text_) { 483 if (is_first_paint_text_) {
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 selection_background_color_) 976 selection_background_color_)
958 : requested_selection_text_color_; 977 : requested_selection_text_color_;
959 978
960 ApplyTextColors(); 979 ApplyTextColors();
961 SchedulePaint(); 980 SchedulePaint();
962 } 981 }
963 982
964 void Label::ApplyTextColors() const { 983 void Label::ApplyTextColors() const {
965 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; 984 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_;
966 bool subpixel_rendering_suppressed = 985 bool subpixel_rendering_suppressed =
967 SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_; 986 SkColorGetA(background_color_) != SK_AlphaOPAQUE ||
987 !subpixel_rendering_enabled_;
968 for (size_t i = 0; i < lines_.size(); ++i) { 988 for (size_t i = 0; i < lines_.size(); ++i) {
969 lines_[i]->SetColor(color); 989 lines_[i]->SetColor(color);
970 lines_[i]->set_selection_color(actual_selection_text_color_); 990 lines_[i]->set_selection_color(actual_selection_text_color_);
971 lines_[i]->set_selection_background_focused_color( 991 lines_[i]->set_selection_background_focused_color(
972 selection_background_color_); 992 selection_background_color_);
973 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); 993 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed);
974 } 994 }
975 } 995 }
976 996
977 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { 997 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 .WriteText(GetSelectedText()); 1052 .WriteText(GetSelectedText());
1033 } 1053 }
1034 1054
1035 void Label::BuildContextMenuContents() { 1055 void Label::BuildContextMenuContents() {
1036 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); 1056 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY);
1037 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, 1057 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL,
1038 IDS_APP_SELECT_ALL); 1058 IDS_APP_SELECT_ALL);
1039 } 1059 }
1040 1060
1041 } // namespace views 1061 } // namespace views
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698