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

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: call super::OnEnabledChanged() 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') | 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 if (ShouldShowDefaultTooltip()) { 326 if (ShouldShowDefaultTooltip()) {
327 // Note that |render_text_| is never elided (see the comment in Init() too). 327 // Note that |render_text_| is never elided (see the comment in Init() too).
328 tooltip->assign(render_text_->GetDisplayText()); 328 tooltip->assign(render_text_->GetDisplayText());
329 return true; 329 return true;
330 } 330 }
331 331
332 return false; 332 return false;
333 } 333 }
334 334
335 void Label::OnEnabledChanged() { 335 void Label::OnEnabledChanged() {
336 RecalculateColors(); 336 ApplyTextColors();
337 View::OnEnabledChanged();
337 } 338 }
338 339
339 std::unique_ptr<gfx::RenderText> Label::CreateRenderText( 340 std::unique_ptr<gfx::RenderText> Label::CreateRenderText(
340 const base::string16& text, 341 const base::string16& text,
341 gfx::HorizontalAlignment alignment, 342 gfx::HorizontalAlignment alignment,
342 gfx::DirectionalityMode directionality, 343 gfx::DirectionalityMode directionality,
343 gfx::ElideBehavior elide_behavior) { 344 gfx::ElideBehavior elide_behavior) {
344 std::unique_ptr<gfx::RenderText> render_text( 345 std::unique_ptr<gfx::RenderText> render_text(
345 render_text_->CreateInstanceOfSameType()); 346 render_text_->CreateInstanceOfSameType());
346 render_text->SetHorizontalAlignment(alignment); 347 render_text->SetHorizontalAlignment(alignment);
347 render_text->SetDirectionalityMode(directionality); 348 render_text->SetDirectionalityMode(directionality);
348 render_text->SetElideBehavior(elide_behavior); 349 render_text->SetElideBehavior(elide_behavior);
349 render_text->SetObscured(obscured()); 350 render_text->SetObscured(obscured());
350 render_text->SetMinLineHeight(line_height()); 351 render_text->SetMinLineHeight(line_height());
351 render_text->SetFontList(font_list()); 352 render_text->SetFontList(font_list());
352 render_text->set_shadows(shadows()); 353 render_text->set_shadows(shadows());
353 render_text->SetCursorEnabled(false); 354 render_text->SetCursorEnabled(false);
354 render_text->SetText(text); 355 render_text->SetText(text);
355 return render_text; 356 return render_text;
356 } 357 }
357 358
358 void Label::PaintText(gfx::Canvas* canvas) { 359 void Label::PaintText(gfx::Canvas* canvas) {
359 MaybeBuildRenderTextLines(); 360 MaybeBuildRenderTextLines();
tapted 2016/06/14 11:15:54 This was the call triggering a second paint
360 for (size_t i = 0; i < lines_.size(); ++i) 361 for (size_t i = 0; i < lines_.size(); ++i)
361 lines_[i]->Draw(canvas); 362 lines_[i]->Draw(canvas);
362 } 363 }
363 364
364 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { 365 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) {
365 if (previous_bounds.size() != size()) 366 if (previous_bounds.size() != size())
366 InvalidateLayout(); 367 InvalidateLayout();
367 } 368 }
368 369
369 void Label::OnPaint(gfx::Canvas* canvas) { 370 void Label::OnPaint(gfx::Canvas* canvas) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 std::unique_ptr<gfx::RenderText> line = 476 std::unique_ptr<gfx::RenderText> line =
476 CreateRenderText(lines[i], alignment, directionality, elide_behavior); 477 CreateRenderText(lines[i], alignment, directionality, elide_behavior);
477 line->SetDisplayRect(rect); 478 line->SetDisplayRect(rect);
478 lines_.push_back(std::move(line)); 479 lines_.push_back(std::move(line));
479 rect.set_y(rect.y() + rect.height()); 480 rect.set_y(rect.y() + rect.height());
480 } 481 }
481 // Append the remaining text to the last visible line. 482 // Append the remaining text to the last visible line.
482 for (size_t i = lines_.size(); i < lines.size(); ++i) 483 for (size_t i = lines_.size(); i < lines.size(); ++i)
483 lines_.back()->SetText(lines_.back()->text() + lines[i]); 484 lines_.back()->SetText(lines_.back()->text() + lines[i]);
484 } 485 }
485 RecalculateColors(); 486 ApplyTextColors();
486 } 487 }
487 488
488 gfx::Rect Label::GetFocusBounds() { 489 gfx::Rect Label::GetFocusBounds() {
489 MaybeBuildRenderTextLines(); 490 MaybeBuildRenderTextLines();
tapted 2016/06/14 11:15:54 There's a call here as well, but GetFocusBounds()
490 491
491 gfx::Rect focus_bounds; 492 gfx::Rect focus_bounds;
492 if (lines_.empty()) { 493 if (lines_.empty()) {
493 focus_bounds = gfx::Rect(GetTextSize()); 494 focus_bounds = gfx::Rect(GetTextSize());
494 } else { 495 } else {
495 for (size_t i = 0; i < lines_.size(); ++i) { 496 for (size_t i = 0; i < lines_.size(); ++i) {
496 gfx::Point origin; 497 gfx::Point origin;
497 origin += lines_[i]->GetLineOffset(0); 498 origin += lines_[i]->GetLineOffset(0);
498 focus_bounds.Union(gfx::Rect(origin, lines_[i]->GetStringSize())); 499 focus_bounds.Union(gfx::Rect(origin, lines_[i]->GetStringSize()));
499 } 500 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 void Label::RecalculateColors() { 555 void Label::RecalculateColors() {
555 actual_enabled_color_ = auto_color_readability_ ? 556 actual_enabled_color_ = auto_color_readability_ ?
556 color_utils::GetReadableColor(requested_enabled_color_, 557 color_utils::GetReadableColor(requested_enabled_color_,
557 background_color_) : 558 background_color_) :
558 requested_enabled_color_; 559 requested_enabled_color_;
559 actual_disabled_color_ = auto_color_readability_ ? 560 actual_disabled_color_ = auto_color_readability_ ?
560 color_utils::GetReadableColor(requested_disabled_color_, 561 color_utils::GetReadableColor(requested_disabled_color_,
561 background_color_) : 562 background_color_) :
562 requested_disabled_color_; 563 requested_disabled_color_;
563 564
565 ApplyTextColors();
566 SchedulePaint();
567 }
568
569 void Label::ApplyTextColors() {
564 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; 570 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_;
565 bool subpixel_rendering_suppressed = 571 bool subpixel_rendering_suppressed =
566 SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_; 572 SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_;
567 for (size_t i = 0; i < lines_.size(); ++i) { 573 for (size_t i = 0; i < lines_.size(); ++i) {
568 lines_[i]->SetColor(color); 574 lines_[i]->SetColor(color);
569 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); 575 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed);
570 } 576 }
571 SchedulePaint();
572 } 577 }
573 578
574 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { 579 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) {
575 if (!enabled_color_set_) { 580 if (!enabled_color_set_) {
576 requested_enabled_color_ = theme->GetSystemColor( 581 requested_enabled_color_ = theme->GetSystemColor(
577 ui::NativeTheme::kColorId_LabelEnabledColor); 582 ui::NativeTheme::kColorId_LabelEnabledColor);
578 } 583 }
579 if (!disabled_color_set_) { 584 if (!disabled_color_set_) {
580 requested_disabled_color_ = theme->GetSystemColor( 585 requested_disabled_color_ = theme->GetSystemColor(
581 ui::NativeTheme::kColorId_LabelDisabledColor); 586 ui::NativeTheme::kColorId_LabelDisabledColor);
582 } 587 }
583 if (!background_color_set_) { 588 if (!background_color_set_) {
584 background_color_ = theme->GetSystemColor( 589 background_color_ = theme->GetSystemColor(
585 ui::NativeTheme::kColorId_LabelBackgroundColor); 590 ui::NativeTheme::kColorId_LabelBackgroundColor);
586 } 591 }
587 RecalculateColors(); 592 RecalculateColors();
588 } 593 }
589 594
590 bool Label::ShouldShowDefaultTooltip() const { 595 bool Label::ShouldShowDefaultTooltip() const {
591 const gfx::Size text_size = GetTextSize(); 596 const gfx::Size text_size = GetTextSize();
592 const gfx::Size size = GetContentsBounds().size(); 597 const gfx::Size size = GetContentsBounds().size();
593 return !obscured() && (text_size.width() > size.width() || 598 return !obscured() && (text_size.width() > size.width() ||
594 (multi_line() && text_size.height() > size.height())); 599 (multi_line() && text_size.height() > size.height()));
595 } 600 }
596 601
597 } // namespace views 602 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/label.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698