| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <cmath> | 7 #include <cmath> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 int Label::GetBaseline() { | 61 int Label::GetBaseline() { |
| 62 return GetInsets().top() + font_.GetBaseline(); | 62 return GetInsets().top() + font_.GetBaseline(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 int Label::GetHeightForWidth(int w) { | 65 int Label::GetHeightForWidth(int w) { |
| 66 if (!is_multi_line_) | 66 if (!is_multi_line_) |
| 67 return View::GetHeightForWidth(w); | 67 return View::GetHeightForWidth(w); |
| 68 | 68 |
| 69 w = std::max(0, w - GetInsets().width()); | 69 w = std::max(0, w - GetInsets().width()); |
| 70 int h = font_.GetHeight(); | 70 int h = font_.GetHeight(); |
| 71 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags()); | 71 gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(text_), font_, &w, &h, |
| 72 ComputeMultiLineFlags()); |
| 72 return h + GetInsets().height(); | 73 return h + GetInsets().height(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void Label::DidChangeBounds(const gfx::Rect& previous, | 76 void Label::DidChangeBounds(const gfx::Rect& previous, |
| 76 const gfx::Rect& current) { | 77 const gfx::Rect& current) { |
| 77 text_size_valid_ &= !is_multi_line_; | 78 text_size_valid_ &= !is_multi_line_; |
| 78 } | 79 } |
| 79 | 80 |
| 80 void Label::Paint(gfx::Canvas* canvas) { | 81 void Label::Paint(gfx::Canvas* canvas) { |
| 81 PaintBackground(canvas); | 82 PaintBackground(canvas); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // SizeStringInt() to calculate the desired width, it doesn't seem to work | 288 // SizeStringInt() to calculate the desired width, it doesn't seem to work |
| 288 // on Linux. | 289 // on Linux. |
| 289 int w = is_multi_line_ ? | 290 int w = is_multi_line_ ? |
| 290 GetAvailableRect().width() : std::numeric_limits<int>::max(); | 291 GetAvailableRect().width() : std::numeric_limits<int>::max(); |
| 291 int h = font_.GetHeight(); | 292 int h = font_.GetHeight(); |
| 292 // For single-line strings, ignore the available width and calculate how | 293 // For single-line strings, ignore the available width and calculate how |
| 293 // wide the text wants to be. | 294 // wide the text wants to be. |
| 294 int flags = ComputeMultiLineFlags(); | 295 int flags = ComputeMultiLineFlags(); |
| 295 if (!is_multi_line_) | 296 if (!is_multi_line_) |
| 296 flags |= gfx::Canvas::NO_ELLIPSIS; | 297 flags |= gfx::Canvas::NO_ELLIPSIS; |
| 297 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags); | 298 gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(text_), font_, &w, &h, |
| 299 flags); |
| 298 text_size_.SetSize(w, h); | 300 text_size_.SetSize(w, h); |
| 299 text_size_valid_ = true; | 301 text_size_valid_ = true; |
| 300 } | 302 } |
| 301 | 303 |
| 302 return text_size_; | 304 return text_size_; |
| 303 } | 305 } |
| 304 | 306 |
| 305 // static | 307 // static |
| 306 gfx::Font Label::GetDefaultFont() { | 308 gfx::Font Label::GetDefaultFont() { |
| 307 return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); | 309 return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 font_, GetAvailableRect().width(), true)); | 445 font_, GetAvailableRect().width(), true)); |
| 444 } else { | 446 } else { |
| 445 *paint_text = text_; | 447 *paint_text = text_; |
| 446 } | 448 } |
| 447 | 449 |
| 448 *text_bounds = GetTextBounds(); | 450 *text_bounds = GetTextBounds(); |
| 449 *flags = ComputeMultiLineFlags(); | 451 *flags = ComputeMultiLineFlags(); |
| 450 } | 452 } |
| 451 | 453 |
| 452 } // namespace views | 454 } // namespace views |
| OLD | NEW |