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

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

Issue 343853002: Fix new avatar button appearance regressions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused label halo code; update example. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/controls/label.h ('k') | ui/views/examples/label_example.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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 void Label::PaintText(gfx::Canvas* canvas, 314 void Label::PaintText(gfx::Canvas* canvas,
315 const base::string16& text, 315 const base::string16& text,
316 const gfx::Rect& text_bounds, 316 const gfx::Rect& text_bounds,
317 int flags) { 317 int flags) {
318 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; 318 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_;
319 if (elide_behavior_ == gfx::FADE_TAIL) { 319 if (elide_behavior_ == gfx::FADE_TAIL) {
320 canvas->DrawFadedString(text, font_list_, color, text_bounds, flags); 320 canvas->DrawFadedString(text, font_list_, color, text_bounds, flags);
321 } else { 321 } else {
322 canvas->DrawStringRectWithShadows(text, font_list_, color, text_bounds, 322 canvas->DrawStringRectWithShadows(text, font_list_, color, text_bounds,
323 line_height_, flags, shadows_); 323 line_height_, flags, shadows_);
324
325 if (SkColorGetA(halo_color_) != SK_AlphaTRANSPARENT) {
326 canvas->DrawStringRectWithHalo(text, font_list_, color, halo_color_,
327 text_bounds, flags);
328 }
329 } 324 }
330 325
331 if (HasFocus()) { 326 if (HasFocus()) {
332 gfx::Rect focus_bounds = text_bounds; 327 gfx::Rect focus_bounds = text_bounds;
333 focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding); 328 focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding);
334 canvas->DrawFocusRect(focus_bounds); 329 canvas->DrawFocusRect(focus_bounds);
335 } 330 }
336 } 331 }
337 332
338 gfx::Size Label::GetTextSize() const { 333 gfx::Size Label::GetTextSize() const {
339 if (!text_size_valid_) { 334 if (!text_size_valid_) {
340 // For single-line strings, we supply the largest possible width, because 335 // For single-line strings, we supply the largest possible width, because
341 // while adding NO_ELLIPSIS to the flags works on Windows for forcing 336 // while adding NO_ELLIPSIS to the flags works on Windows for forcing
342 // SizeStringInt() to calculate the desired width, it doesn't seem to work 337 // SizeStringInt() to calculate the desired width, it doesn't seem to work
343 // on Linux. 338 // on Linux.
344 int w = is_multi_line_ ? 339 int w = is_multi_line_ ?
345 GetAvailableRect().width() : std::numeric_limits<int>::max(); 340 GetAvailableRect().width() : std::numeric_limits<int>::max();
346 int h = font_list_.GetHeight(); 341 int h = font_list_.GetHeight();
347 // For single-line strings, ignore the available width and calculate how 342 // For single-line strings, ignore the available width and calculate how
348 // wide the text wants to be. 343 // wide the text wants to be.
349 int flags = ComputeDrawStringFlags(); 344 int flags = ComputeDrawStringFlags();
350 if (!is_multi_line_) 345 if (!is_multi_line_)
351 flags |= gfx::Canvas::NO_ELLIPSIS; 346 flags |= gfx::Canvas::NO_ELLIPSIS;
352 gfx::Canvas::SizeStringInt( 347 gfx::Canvas::SizeStringInt(
353 layout_text(), font_list_, &w, &h, line_height_, flags); 348 layout_text(), font_list_, &w, &h, line_height_, flags);
354 text_size_.SetSize(w, h); 349 text_size_.SetSize(w, h);
350 const gfx::Insets shadow_margin = -gfx::ShadowValue::GetMargin(shadows_);
351 text_size_.Enlarge(shadow_margin.width(), shadow_margin.height());
355 text_size_valid_ = true; 352 text_size_valid_ = true;
356 } 353 }
357 354
358 return text_size_; 355 return text_size_;
359 } 356 }
360 357
361 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { 358 void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) {
362 text_size_valid_ &= !is_multi_line_; 359 text_size_valid_ &= !is_multi_line_;
363 } 360 }
364 361
(...skipping 22 matching lines...) Expand all
387 auto_color_readability_ = true; 384 auto_color_readability_ = true;
388 UpdateColorsFromTheme(ui::NativeTheme::instance()); 385 UpdateColorsFromTheme(ui::NativeTheme::instance());
389 horizontal_alignment_ = gfx::ALIGN_CENTER; 386 horizontal_alignment_ = gfx::ALIGN_CENTER;
390 line_height_ = 0; 387 line_height_ = 0;
391 is_multi_line_ = false; 388 is_multi_line_ = false;
392 is_obscured_ = false; 389 is_obscured_ = false;
393 allow_character_break_ = false; 390 allow_character_break_ = false;
394 elide_behavior_ = gfx::ELIDE_TAIL; 391 elide_behavior_ = gfx::ELIDE_TAIL;
395 collapse_when_hidden_ = false; 392 collapse_when_hidden_ = false;
396 directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI; 393 directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI;
397 halo_color_ = SK_ColorTRANSPARENT;
398 cached_heights_.resize(kCachedSizeLimit); 394 cached_heights_.resize(kCachedSizeLimit);
399 ResetCachedSize(); 395 ResetCachedSize();
400 396
401 SetText(text); 397 SetText(text);
402 } 398 }
403 399
404 void Label::RecalculateColors() { 400 void Label::RecalculateColors() {
405 actual_enabled_color_ = auto_color_readability_ ? 401 actual_enabled_color_ = auto_color_readability_ ?
406 color_utils::GetReadableColor(requested_enabled_color_, 402 color_utils::GetReadableColor(requested_enabled_color_,
407 background_color_) : 403 background_color_) :
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 cached_heights_[i] = gfx::Size(); 535 cached_heights_[i] = gfx::Size();
540 } 536 }
541 537
542 bool Label::ShouldShowDefaultTooltip() const { 538 bool Label::ShouldShowDefaultTooltip() const {
543 return !is_multi_line_ && !is_obscured_ && 539 return !is_multi_line_ && !is_obscured_ &&
544 gfx::GetStringWidth(layout_text(), font_list_) > 540 gfx::GetStringWidth(layout_text(), font_list_) >
545 GetAvailableRect().width(); 541 GetAvailableRect().width();
546 } 542 }
547 543
548 } // namespace views 544 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/label.h ('k') | ui/views/examples/label_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698