| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |