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

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

Issue 712003005: Support vertical centering of multi-line labels. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update multi-line label unittests. Created 6 years, 1 month 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 | « no previous file | 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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // from the use of GetTextExtentPoint32() on Windows. 430 // from the use of GetTextExtentPoint32() on Windows.
431 origin.Offset((available.width() + 1 - text_size.width()) / 2, 0); 431 origin.Offset((available.width() + 1 - text_size.width()) / 2, 0);
432 break; 432 break;
433 case gfx::ALIGN_RIGHT: 433 case gfx::ALIGN_RIGHT:
434 origin.set_x(available.right() - text_size.width()); 434 origin.set_x(available.right() - text_size.width());
435 break; 435 break;
436 default: 436 default:
437 NOTREACHED(); 437 NOTREACHED();
438 break; 438 break;
439 } 439 }
440 text_size.set_height(available.height()); 440 if (!multi_line_)
441 text_size.set_height(available.height());
442 // Support vertical centering of multi-line labels: http://crbug.com/429595
443 origin.Offset(0, std::max(0, (available.height() - text_size.height())) / 2);
441 return gfx::Rect(origin, text_size); 444 return gfx::Rect(origin, text_size);
442 } 445 }
443 446
444 int Label::ComputeDrawStringFlags() const { 447 int Label::ComputeDrawStringFlags() const {
445 int flags = 0; 448 int flags = 0;
446 449
447 // We can't use subpixel rendering if the background is non-opaque. 450 // We can't use subpixel rendering if the background is non-opaque.
448 if (SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_) 451 if (SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_)
449 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; 452 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
450 453
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 542 }
540 543
541 bool Label::ShouldShowDefaultTooltip() const { 544 bool Label::ShouldShowDefaultTooltip() const {
542 const gfx::Size text_size = GetTextSize(); 545 const gfx::Size text_size = GetTextSize();
543 const gfx::Size size = GetContentsBounds().size(); 546 const gfx::Size size = GetContentsBounds().size();
544 return !obscured() && (text_size.width() > size.width() || 547 return !obscured() && (text_size.width() > size.width() ||
545 (multi_line_ && text_size.height() > size.height())); 548 (multi_line_ && text_size.height() > size.height()));
546 } 549 }
547 550
548 } // namespace views 551 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698