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

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

Issue 258063009: retry r266622: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: initialize color values Created 6 years, 7 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 | Annotate | Revision Log
« 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <vector> 10 #include <vector>
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 OnPaintBorder(canvas); 371 OnPaintBorder(canvas);
372 372
373 base::string16 paint_text; 373 base::string16 paint_text;
374 gfx::Rect text_bounds; 374 gfx::Rect text_bounds;
375 int flags = 0; 375 int flags = 0;
376 CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 376 CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
377 PaintText(canvas, paint_text, text_bounds, flags); 377 PaintText(canvas, paint_text, text_bounds, flags);
378 } 378 }
379 379
380 void Label::OnNativeThemeChanged(const ui::NativeTheme* theme) { 380 void Label::OnNativeThemeChanged(const ui::NativeTheme* theme) {
381 UpdateColorsFromTheme(theme); 381 if (!enabled_color_set_) {
382 requested_enabled_color_ = theme->GetSystemColor(
383 ui::NativeTheme::kColorId_LabelEnabledColor);
384 }
385 if (!disabled_color_set_) {
386 requested_disabled_color_ = theme->GetSystemColor(
387 ui::NativeTheme::kColorId_LabelDisabledColor);
388 }
389 if (!background_color_set_) {
390 background_color_ = theme->GetSystemColor(
391 ui::NativeTheme::kColorId_LabelBackgroundColor);
392 }
393 RecalculateColors();
382 } 394 }
383 395
384 void Label::Init(const base::string16& text, const gfx::FontList& font_list) { 396 void Label::Init(const base::string16& text, const gfx::FontList& font_list) {
385 font_list_ = font_list; 397 font_list_ = font_list;
386 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; 398 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false;
387 auto_color_readability_ = true; 399 auto_color_readability_ = true;
388 UpdateColorsFromTheme(ui::NativeTheme::instance()); 400 OnNativeThemeChanged(ui::NativeTheme::instance());
sky 2014/04/28 23:22:15 Won't this end up invoking a virtual function from
Evan Stade 2014/04/29 19:20:26 Is that a problem in this case? AFAIK it will do w
389 horizontal_alignment_ = gfx::ALIGN_CENTER; 401 horizontal_alignment_ = gfx::ALIGN_CENTER;
390 line_height_ = 0; 402 line_height_ = 0;
391 is_multi_line_ = false; 403 is_multi_line_ = false;
392 is_obscured_ = false; 404 is_obscured_ = false;
393 allow_character_break_ = false; 405 allow_character_break_ = false;
394 elide_behavior_ = ELIDE_AT_END; 406 elide_behavior_ = ELIDE_AT_END;
395 collapse_when_hidden_ = false; 407 collapse_when_hidden_ = false;
396 directionality_mode_ = USE_UI_DIRECTIONALITY; 408 directionality_mode_ = USE_UI_DIRECTIONALITY;
397 enabled_shadow_color_ = 0; 409 enabled_shadow_color_ = 0;
398 disabled_shadow_color_ = 0; 410 disabled_shadow_color_ = 0;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 case gfx::ALIGN_RIGHT: 484 case gfx::ALIGN_RIGHT:
473 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; 485 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
474 break; 486 break;
475 } 487 }
476 488
477 if (!is_multi_line_) 489 if (!is_multi_line_)
478 return flags; 490 return flags;
479 491
480 flags |= gfx::Canvas::MULTI_LINE; 492 flags |= gfx::Canvas::MULTI_LINE;
481 #if !defined(OS_WIN) 493 #if !defined(OS_WIN)
482 // Don't elide multiline labels on Linux. 494 // Don't elide multiline labels on Linux.
483 // Todo(davemoore): Do we depend on eliding multiline text? 495 // Todo(davemoore): Do we depend on eliding multiline text?
484 // Pango insists on limiting the number of lines to one if text is 496 // Pango insists on limiting the number of lines to one if text is
485 // elided. You can get around this if you can pass a maximum height 497 // elided. You can get around this if you can pass a maximum height
486 // but we don't currently have that data when we call the pango code. 498 // but we don't currently have that data when we call the pango code.
487 flags |= gfx::Canvas::NO_ELLIPSIS; 499 flags |= gfx::Canvas::NO_ELLIPSIS;
488 #endif 500 #endif
489 if (allow_character_break_) 501 if (allow_character_break_)
490 flags |= gfx::Canvas::CHARACTER_BREAK; 502 flags |= gfx::Canvas::CHARACTER_BREAK;
491 503
492 return flags; 504 return flags;
493 } 505 }
494 506
495 gfx::Rect Label::GetAvailableRect() const { 507 gfx::Rect Label::GetAvailableRect() const {
496 gfx::Rect bounds(size()); 508 gfx::Rect bounds(size());
497 bounds.Inset(GetInsets()); 509 bounds.Inset(GetInsets());
(...skipping 29 matching lines...) Expand all
527 *paint_text = 539 *paint_text =
528 gfx::ElideEmail(layout_text(), font_list_, GetAvailableRect().width()); 540 gfx::ElideEmail(layout_text(), font_list_, GetAvailableRect().width());
529 } 541 }
530 542
531 *text_bounds = GetTextBounds(); 543 *text_bounds = GetTextBounds();
532 *flags = ComputeDrawStringFlags(); 544 *flags = ComputeDrawStringFlags();
533 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE)) 545 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE))
534 *flags |= gfx::Canvas::NO_ELLIPSIS; 546 *flags |= gfx::Canvas::NO_ELLIPSIS;
535 } 547 }
536 548
537 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) {
538 if (!enabled_color_set_) {
539 requested_enabled_color_ = theme->GetSystemColor(
540 ui::NativeTheme::kColorId_LabelEnabledColor);
541 }
542 if (!disabled_color_set_) {
543 requested_disabled_color_ = theme->GetSystemColor(
544 ui::NativeTheme::kColorId_LabelDisabledColor);
545 }
546 if (!background_color_set_) {
547 background_color_ = theme->GetSystemColor(
548 ui::NativeTheme::kColorId_LabelBackgroundColor);
549 }
550 RecalculateColors();
551 }
552
553 void Label::ResetCachedSize() { 549 void Label::ResetCachedSize() {
554 text_size_valid_ = false; 550 text_size_valid_ = false;
555 cached_heights_cursor_ = 0; 551 cached_heights_cursor_ = 0;
556 for (int i = 0; i < kCachedSizeLimit; ++i) 552 for (int i = 0; i < kCachedSizeLimit; ++i)
557 cached_heights_[i] = gfx::Size(); 553 cached_heights_[i] = gfx::Size();
558 } 554 }
559 555
560 bool Label::ShouldShowDefaultTooltip() const { 556 bool Label::ShouldShowDefaultTooltip() const {
561 return !is_multi_line_ && !is_obscured_ && 557 return !is_multi_line_ && !is_obscured_ &&
562 gfx::GetStringWidth(layout_text(), font_list_) > 558 gfx::GetStringWidth(layout_text(), font_list_) >
563 GetAvailableRect().width(); 559 GetAvailableRect().width();
564 } 560 }
565 561
566 } // namespace views 562 } // 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