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

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

Issue 14654018: Make Label's NO_ELIDE setting actually not elide, and change the default (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 359
360 void Label::Init(const string16& text, const gfx::Font& font) { 360 void Label::Init(const string16& text, const gfx::Font& font) {
361 font_ = font; 361 font_ = font;
362 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; 362 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false;
363 auto_color_readability_ = true; 363 auto_color_readability_ = true;
364 UpdateColorsFromTheme(ui::NativeTheme::instance()); 364 UpdateColorsFromTheme(ui::NativeTheme::instance());
365 horizontal_alignment_ = gfx::ALIGN_CENTER; 365 horizontal_alignment_ = gfx::ALIGN_CENTER;
366 line_height_ = 0; 366 line_height_ = 0;
367 is_multi_line_ = false; 367 is_multi_line_ = false;
368 allow_character_break_ = false; 368 allow_character_break_ = false;
369 elide_behavior_ = NO_ELIDE; 369 elide_behavior_ = ELIDE_AT_END;
370 collapse_when_hidden_ = false; 370 collapse_when_hidden_ = false;
371 directionality_mode_ = USE_UI_DIRECTIONALITY; 371 directionality_mode_ = USE_UI_DIRECTIONALITY;
372 has_focus_border_ = false; 372 has_focus_border_ = false;
373 enabled_shadow_color_ = 0; 373 enabled_shadow_color_ = 0;
374 disabled_shadow_color_ = 0; 374 disabled_shadow_color_ = 0;
375 shadow_offset_.SetPoint(1, 1); 375 shadow_offset_.SetPoint(1, 1);
376 has_shadow_ = false; 376 has_shadow_ = false;
377 cached_heights_.resize(kCachedSizeLimit); 377 cached_heights_.resize(kCachedSizeLimit);
378 ResetCachedSize(); 378 ResetCachedSize();
379 379
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 gfx::Rect bounds(size()); 471 gfx::Rect bounds(size());
472 bounds.Inset(GetInsets()); 472 bounds.Inset(GetInsets());
473 return bounds; 473 return bounds;
474 } 474 }
475 475
476 void Label::CalculateDrawStringParams(string16* paint_text, 476 void Label::CalculateDrawStringParams(string16* paint_text,
477 gfx::Rect* text_bounds, 477 gfx::Rect* text_bounds,
478 int* flags) const { 478 int* flags) const {
479 DCHECK(paint_text && text_bounds && flags); 479 DCHECK(paint_text && text_bounds && flags);
480 480
481 // TODO(msw): Use ElideRectangleText to support eliding multi-line text. 481 // TODO(msw): Use ElideRectangleText to support eliding multi-line text. Once
482 if (elide_behavior_ == ELIDE_AS_EMAIL) { 482 // this is done, we can set NO_ELLIPSIS unconditionally at the bottom.
483 *paint_text = ui::ElideEmail(text_, font_, GetAvailableRect().width()); 483 if (is_multi_line_ || (elide_behavior_ == NO_ELIDE)) {
484 *paint_text = text_;
484 } else if (elide_behavior_ == ELIDE_IN_MIDDLE) { 485 } else if (elide_behavior_ == ELIDE_IN_MIDDLE) {
485 *paint_text = ui::ElideText(text_, font_, GetAvailableRect().width(), 486 *paint_text = ui::ElideText(text_, font_, GetAvailableRect().width(),
486 ui::ELIDE_IN_MIDDLE); 487 ui::ELIDE_IN_MIDDLE);
487 } else if (elide_behavior_ == ELIDE_AT_END) { 488 } else if (elide_behavior_ == ELIDE_AT_END) {
488 *paint_text = ui::ElideText(text_, font_, GetAvailableRect().width(), 489 *paint_text = ui::ElideText(text_, font_, GetAvailableRect().width(),
489 ui::ELIDE_AT_END); 490 ui::ELIDE_AT_END);
490 } else { 491 } else {
491 *paint_text = text_; 492 DCHECK_EQ(ELIDE_AS_EMAIL, elide_behavior_);
493 *paint_text = ui::ElideEmail(text_, font_, GetAvailableRect().width());
492 } 494 }
493 495
494 *text_bounds = GetTextBounds(); 496 *text_bounds = GetTextBounds();
495 *flags = ComputeDrawStringFlags(); 497 *flags = ComputeDrawStringFlags();
498 if (!is_multi_line_ || (elide_behavior_ == NO_ELIDE))
499 *flags |= gfx::Canvas::NO_ELLIPSIS;
496 } 500 }
497 501
498 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { 502 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) {
499 if (!enabled_color_set_) { 503 if (!enabled_color_set_) {
500 requested_enabled_color_ = theme->GetSystemColor( 504 requested_enabled_color_ = theme->GetSystemColor(
501 ui::NativeTheme::kColorId_LabelEnabledColor); 505 ui::NativeTheme::kColorId_LabelEnabledColor);
502 } 506 }
503 if (!disabled_color_set_) { 507 if (!disabled_color_set_) {
504 requested_disabled_color_ = theme->GetSystemColor( 508 requested_disabled_color_ = theme->GetSystemColor(
505 ui::NativeTheme::kColorId_LabelDisabledColor); 509 ui::NativeTheme::kColorId_LabelDisabledColor);
(...skipping 11 matching lines...) Expand all
517 for (int i = 0; i < kCachedSizeLimit; ++i) 521 for (int i = 0; i < kCachedSizeLimit; ++i)
518 cached_heights_[i] = gfx::Size(); 522 cached_heights_[i] = gfx::Size();
519 } 523 }
520 524
521 bool Label::ShouldShowDefaultTooltip() const { 525 bool Label::ShouldShowDefaultTooltip() const {
522 return !is_multi_line_ && 526 return !is_multi_line_ &&
523 font_.GetStringWidth(text_) > GetAvailableRect().width(); 527 font_.GetStringWidth(text_) > GetAvailableRect().width();
524 } 528 }
525 529
526 } // namespace views 530 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698