| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "views/controls/label.h" | 5 #include "views/controls/label.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <limits> |
| 8 | 9 |
| 9 #include "app/gfx/canvas.h" | 10 #include "app/gfx/canvas.h" |
| 10 #include "app/gfx/color_utils.h" | 11 #include "app/gfx/color_utils.h" |
| 11 #include "app/gfx/font.h" | 12 #include "app/gfx/font.h" |
| 12 #include "app/gfx/insets.h" | 13 #include "app/gfx/insets.h" |
| 13 #include "app/gfx/text_elider.h" | 14 #include "app/gfx/text_elider.h" |
| 14 #include "app/l10n_util.h" | 15 #include "app/l10n_util.h" |
| 15 #include "app/resource_bundle.h" | 16 #include "app/resource_bundle.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 258 |
| 258 const GURL Label::GetURL() const { | 259 const GURL Label::GetURL() const { |
| 259 if (url_set_) | 260 if (url_set_) |
| 260 return url_; | 261 return url_; |
| 261 else | 262 else |
| 262 return GURL(WideToUTF8(text_)); | 263 return GURL(WideToUTF8(text_)); |
| 263 } | 264 } |
| 264 | 265 |
| 265 gfx::Size Label::GetTextSize() { | 266 gfx::Size Label::GetTextSize() { |
| 266 if (!text_size_valid_) { | 267 if (!text_size_valid_) { |
| 267 text_size_.SetSize(font_.GetStringWidth(text_), font_.height()); | 268 // Multi-line labels need a boundary width (see GetHeightForWidth). |
| 269 DCHECK(!is_multi_line_); |
| 270 int h = 0, w = std::numeric_limits<int>::max(); |
| 271 gfx::Canvas cc(0, 0, true); |
| 272 cc.SizeStringInt(text_, font_, &w, &h, 0); |
| 273 text_size_.SetSize(w, font_.height()); |
| 268 if (highlighted_) | 274 if (highlighted_) |
| 269 text_size_.Enlarge(1, 1); | 275 text_size_.Enlarge(1, 1); |
| 270 text_size_valid_ = true; | 276 text_size_valid_ = true; |
| 271 } | 277 } |
| 272 | 278 |
| 273 return text_size_; | 279 return text_size_; |
| 274 } | 280 } |
| 275 | 281 |
| 276 int Label::GetHeightForWidth(int w) { | 282 int Label::GetHeightForWidth(int w) { |
| 277 if (is_multi_line_) { | 283 if (is_multi_line_) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 } | 494 } |
| 489 | 495 |
| 490 bool Label::GetAccessibleState(AccessibilityTypes::State* state) { | 496 bool Label::GetAccessibleState(AccessibilityTypes::State* state) { |
| 491 DCHECK(state); | 497 DCHECK(state); |
| 492 | 498 |
| 493 *state = AccessibilityTypes::STATE_READONLY; | 499 *state = AccessibilityTypes::STATE_READONLY; |
| 494 return true; | 500 return true; |
| 495 } | 501 } |
| 496 | 502 |
| 497 } // namespace views | 503 } // namespace views |
| OLD | NEW |