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

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

Issue 3083022: Rework gfx::Font by moving platform-specific code into inner classes.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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 | « views/controls/combobox/native_combobox_win.cc ('k') | 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) 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 if (!IsVisible() && collapse_when_hidden_) 51 if (!IsVisible() && collapse_when_hidden_)
52 return gfx::Size(); 52 return gfx::Size();
53 53
54 gfx::Size prefsize(GetTextSize()); 54 gfx::Size prefsize(GetTextSize());
55 gfx::Insets insets = GetInsets(); 55 gfx::Insets insets = GetInsets();
56 prefsize.Enlarge(insets.width(), insets.height()); 56 prefsize.Enlarge(insets.width(), insets.height());
57 return prefsize; 57 return prefsize;
58 } 58 }
59 59
60 int Label::GetBaseline() { 60 int Label::GetBaseline() {
61 return GetInsets().top() + font_.baseline(); 61 return GetInsets().top() + font_.GetBaseline();
62 } 62 }
63 63
64 int Label::GetHeightForWidth(int w) { 64 int Label::GetHeightForWidth(int w) {
65 if (!is_multi_line_) 65 if (!is_multi_line_)
66 return View::GetHeightForWidth(w); 66 return View::GetHeightForWidth(w);
67 67
68 w = std::max(0, w - GetInsets().width()); 68 w = std::max(0, w - GetInsets().width());
69 int h = font_.height(); 69 int h = font_.GetHeight();
70 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags()); 70 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags());
71 return h + GetInsets().height(); 71 return h + GetInsets().height();
72 } 72 }
73 73
74 void Label::DidChangeBounds(const gfx::Rect& previous, 74 void Label::DidChangeBounds(const gfx::Rect& previous,
75 const gfx::Rect& current) { 75 const gfx::Rect& current) {
76 text_size_valid_ &= !is_multi_line_; 76 text_size_valid_ &= !is_multi_line_;
77 } 77 }
78 78
79 void Label::Paint(gfx::Canvas* canvas) { 79 void Label::Paint(gfx::Canvas* canvas) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 285 }
286 286
287 gfx::Size Label::GetTextSize() const { 287 gfx::Size Label::GetTextSize() const {
288 if (!text_size_valid_) { 288 if (!text_size_valid_) {
289 // For single-line strings, we supply the largest possible width, because 289 // For single-line strings, we supply the largest possible width, because
290 // while adding NO_ELLIPSIS to the flags works on Windows for forcing 290 // while adding NO_ELLIPSIS to the flags works on Windows for forcing
291 // SizeStringInt() to calculate the desired width, it doesn't seem to work 291 // SizeStringInt() to calculate the desired width, it doesn't seem to work
292 // on Linux. 292 // on Linux.
293 int w = is_multi_line_ ? 293 int w = is_multi_line_ ?
294 GetAvailableRect().width() : std::numeric_limits<int>::max(); 294 GetAvailableRect().width() : std::numeric_limits<int>::max();
295 int h = font_.height(); 295 int h = font_.GetHeight();
296 // For single-line strings, ignore the available width and calculate how 296 // For single-line strings, ignore the available width and calculate how
297 // wide the text wants to be. 297 // wide the text wants to be.
298 int flags = ComputeMultiLineFlags(); 298 int flags = ComputeMultiLineFlags();
299 if (!is_multi_line_) 299 if (!is_multi_line_)
300 flags |= gfx::Canvas::NO_ELLIPSIS; 300 flags |= gfx::Canvas::NO_ELLIPSIS;
301 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags); 301 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags);
302 text_size_.SetSize(w, h); 302 text_size_.SetSize(w, h);
303 text_size_valid_ = true; 303 text_size_valid_ = true;
304 } 304 }
305 305
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 *paint_text = gfx::ElideText(text_, font_, width(), true); 444 *paint_text = gfx::ElideText(text_, font_, width(), true);
445 } else { 445 } else {
446 *paint_text = text_; 446 *paint_text = text_;
447 } 447 }
448 448
449 *text_bounds = GetTextBounds(); 449 *text_bounds = GetTextBounds();
450 *flags = ComputeMultiLineFlags(); 450 *flags = ComputeMultiLineFlags();
451 } 451 }
452 452
453 } // namespace views 453 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/combobox/native_combobox_win.cc ('k') | views/controls/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698