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

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

Issue 251703002: retry r266042: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync 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
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());
389 horizontal_alignment_ = gfx::ALIGN_CENTER; 400 horizontal_alignment_ = gfx::ALIGN_CENTER;
390 line_height_ = 0; 401 line_height_ = 0;
391 is_multi_line_ = false; 402 is_multi_line_ = false;
392 is_obscured_ = false; 403 is_obscured_ = false;
393 allow_character_break_ = false; 404 allow_character_break_ = false;
394 elide_behavior_ = ELIDE_AT_END; 405 elide_behavior_ = ELIDE_AT_END;
395 collapse_when_hidden_ = false; 406 collapse_when_hidden_ = false;
396 directionality_mode_ = USE_UI_DIRECTIONALITY; 407 directionality_mode_ = USE_UI_DIRECTIONALITY;
397 enabled_shadow_color_ = 0; 408 enabled_shadow_color_ = 0;
398 disabled_shadow_color_ = 0; 409 disabled_shadow_color_ = 0;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 case gfx::ALIGN_RIGHT: 483 case gfx::ALIGN_RIGHT:
473 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; 484 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
474 break; 485 break;
475 } 486 }
476 487
477 if (!is_multi_line_) 488 if (!is_multi_line_)
478 return flags; 489 return flags;
479 490
480 flags |= gfx::Canvas::MULTI_LINE; 491 flags |= gfx::Canvas::MULTI_LINE;
481 #if !defined(OS_WIN) 492 #if !defined(OS_WIN)
482 // Don't elide multiline labels on Linux. 493 // Don't elide multiline labels on Linux.
483 // Todo(davemoore): Do we depend on eliding multiline text? 494 // Todo(davemoore): Do we depend on eliding multiline text?
484 // Pango insists on limiting the number of lines to one if text is 495 // 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 496 // 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. 497 // but we don't currently have that data when we call the pango code.
487 flags |= gfx::Canvas::NO_ELLIPSIS; 498 flags |= gfx::Canvas::NO_ELLIPSIS;
488 #endif 499 #endif
489 if (allow_character_break_) 500 if (allow_character_break_)
490 flags |= gfx::Canvas::CHARACTER_BREAK; 501 flags |= gfx::Canvas::CHARACTER_BREAK;
491 502
492 return flags; 503 return flags;
493 } 504 }
494 505
495 gfx::Rect Label::GetAvailableRect() const { 506 gfx::Rect Label::GetAvailableRect() const {
496 gfx::Rect bounds(size()); 507 gfx::Rect bounds(size());
497 bounds.Inset(GetInsets()); 508 bounds.Inset(GetInsets());
(...skipping 29 matching lines...) Expand all
527 *paint_text = 538 *paint_text =
528 gfx::ElideEmail(layout_text(), font_list_, GetAvailableRect().width()); 539 gfx::ElideEmail(layout_text(), font_list_, GetAvailableRect().width());
529 } 540 }
530 541
531 *text_bounds = GetTextBounds(); 542 *text_bounds = GetTextBounds();
532 *flags = ComputeDrawStringFlags(); 543 *flags = ComputeDrawStringFlags();
533 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE)) 544 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE))
534 *flags |= gfx::Canvas::NO_ELLIPSIS; 545 *flags |= gfx::Canvas::NO_ELLIPSIS;
535 } 546 }
536 547
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() { 548 void Label::ResetCachedSize() {
554 text_size_valid_ = false; 549 text_size_valid_ = false;
555 cached_heights_cursor_ = 0; 550 cached_heights_cursor_ = 0;
556 for (int i = 0; i < kCachedSizeLimit; ++i) 551 for (int i = 0; i < kCachedSizeLimit; ++i)
557 cached_heights_[i] = gfx::Size(); 552 cached_heights_[i] = gfx::Size();
558 } 553 }
559 554
560 bool Label::ShouldShowDefaultTooltip() const { 555 bool Label::ShouldShowDefaultTooltip() const {
561 return !is_multi_line_ && !is_obscured_ && 556 return !is_multi_line_ && !is_obscured_ &&
562 gfx::GetStringWidth(layout_text(), font_list_) > 557 gfx::GetStringWidth(layout_text(), font_list_) >
563 GetAvailableRect().width(); 558 GetAvailableRect().width();
564 } 559 }
565 560
566 } // namespace views 561 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698