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

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

Issue 2065003002: Do not SchedulePaint() inside views::Label::OnPaint() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a test Created 4 years, 6 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 | « ui/views/controls/label.h ('k') | ui/views/controls/label_unittest.cc » ('j') | 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if (ShouldShowDefaultTooltip()) { 338 if (ShouldShowDefaultTooltip()) {
339 // Note that |render_text_| is never elided (see the comment in Init() too). 339 // Note that |render_text_| is never elided (see the comment in Init() too).
340 tooltip->assign(render_text_->GetDisplayText()); 340 tooltip->assign(render_text_->GetDisplayText());
341 return true; 341 return true;
342 } 342 }
343 343
344 return false; 344 return false;
345 } 345 }
346 346
347 void Label::OnEnabledChanged() { 347 void Label::OnEnabledChanged() {
348 RecalculateColors(); 348 ApplyTextColors();
349 View::OnEnabledChanged();
349 } 350 }
350 351
351 std::unique_ptr<gfx::RenderText> Label::CreateRenderText( 352 std::unique_ptr<gfx::RenderText> Label::CreateRenderText(
352 const base::string16& text, 353 const base::string16& text,
353 gfx::HorizontalAlignment alignment, 354 gfx::HorizontalAlignment alignment,
354 gfx::DirectionalityMode directionality, 355 gfx::DirectionalityMode directionality,
355 gfx::ElideBehavior elide_behavior) { 356 gfx::ElideBehavior elide_behavior) {
356 std::unique_ptr<gfx::RenderText> render_text( 357 std::unique_ptr<gfx::RenderText> render_text(
357 render_text_->CreateInstanceOfSameType()); 358 render_text_->CreateInstanceOfSameType());
358 render_text->SetHorizontalAlignment(alignment); 359 render_text->SetHorizontalAlignment(alignment);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 std::unique_ptr<gfx::RenderText> line = 489 std::unique_ptr<gfx::RenderText> line =
489 CreateRenderText(lines[i], alignment, directionality, elide_behavior); 490 CreateRenderText(lines[i], alignment, directionality, elide_behavior);
490 line->SetDisplayRect(rect); 491 line->SetDisplayRect(rect);
491 lines_.push_back(std::move(line)); 492 lines_.push_back(std::move(line));
492 rect.set_y(rect.y() + rect.height()); 493 rect.set_y(rect.y() + rect.height());
493 } 494 }
494 // Append the remaining text to the last visible line. 495 // Append the remaining text to the last visible line.
495 for (size_t i = lines_.size(); i < lines.size(); ++i) 496 for (size_t i = lines_.size(); i < lines.size(); ++i)
496 lines_.back()->SetText(lines_.back()->text() + lines[i]); 497 lines_.back()->SetText(lines_.back()->text() + lines[i]);
497 } 498 }
498 RecalculateColors(); 499 ApplyTextColors();
499 } 500 }
500 501
501 gfx::Rect Label::GetFocusBounds() { 502 gfx::Rect Label::GetFocusBounds() {
502 MaybeBuildRenderTextLines(); 503 MaybeBuildRenderTextLines();
503 504
504 gfx::Rect focus_bounds; 505 gfx::Rect focus_bounds;
505 if (lines_.empty()) { 506 if (lines_.empty()) {
506 focus_bounds = gfx::Rect(GetTextSize()); 507 focus_bounds = gfx::Rect(GetTextSize());
507 } else { 508 } else {
508 for (size_t i = 0; i < lines_.size(); ++i) { 509 for (size_t i = 0; i < lines_.size(); ++i) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 void Label::RecalculateColors() { 568 void Label::RecalculateColors() {
568 actual_enabled_color_ = auto_color_readability_ ? 569 actual_enabled_color_ = auto_color_readability_ ?
569 color_utils::GetReadableColor(requested_enabled_color_, 570 color_utils::GetReadableColor(requested_enabled_color_,
570 background_color_) : 571 background_color_) :
571 requested_enabled_color_; 572 requested_enabled_color_;
572 actual_disabled_color_ = auto_color_readability_ ? 573 actual_disabled_color_ = auto_color_readability_ ?
573 color_utils::GetReadableColor(requested_disabled_color_, 574 color_utils::GetReadableColor(requested_disabled_color_,
574 background_color_) : 575 background_color_) :
575 requested_disabled_color_; 576 requested_disabled_color_;
576 577
578 ApplyTextColors();
579 SchedulePaint();
580 }
581
582 void Label::ApplyTextColors() {
577 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; 583 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_;
578 bool subpixel_rendering_suppressed = 584 bool subpixel_rendering_suppressed =
579 SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_; 585 SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_;
580 for (size_t i = 0; i < lines_.size(); ++i) { 586 for (size_t i = 0; i < lines_.size(); ++i) {
581 lines_[i]->SetColor(color); 587 lines_[i]->SetColor(color);
582 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); 588 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed);
583 } 589 }
584 SchedulePaint();
585 } 590 }
586 591
587 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { 592 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) {
588 if (!enabled_color_set_) { 593 if (!enabled_color_set_) {
589 requested_enabled_color_ = theme->GetSystemColor( 594 requested_enabled_color_ = theme->GetSystemColor(
590 ui::NativeTheme::kColorId_LabelEnabledColor); 595 ui::NativeTheme::kColorId_LabelEnabledColor);
591 } 596 }
592 if (!disabled_color_set_) { 597 if (!disabled_color_set_) {
593 requested_disabled_color_ = theme->GetSystemColor( 598 requested_disabled_color_ = theme->GetSystemColor(
594 ui::NativeTheme::kColorId_LabelDisabledColor); 599 ui::NativeTheme::kColorId_LabelDisabledColor);
595 } 600 }
596 if (!background_color_set_) { 601 if (!background_color_set_) {
597 background_color_ = theme->GetSystemColor( 602 background_color_ = theme->GetSystemColor(
598 ui::NativeTheme::kColorId_LabelBackgroundColor); 603 ui::NativeTheme::kColorId_LabelBackgroundColor);
599 } 604 }
600 RecalculateColors(); 605 RecalculateColors();
601 } 606 }
602 607
603 bool Label::ShouldShowDefaultTooltip() const { 608 bool Label::ShouldShowDefaultTooltip() const {
604 const gfx::Size text_size = GetTextSize(); 609 const gfx::Size text_size = GetTextSize();
605 const gfx::Size size = GetContentsBounds().size(); 610 const gfx::Size size = GetContentsBounds().size();
606 return !obscured() && (text_size.width() > size.width() || 611 return !obscured() && (text_size.width() > size.width() ||
607 (multi_line() && text_size.height() > size.height())); 612 (multi_line() && text_size.height() > size.height()));
608 } 613 }
609 614
610 } // namespace views 615 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/label.h ('k') | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698