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

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

Issue 2811032: Revert 50784 - Canvas refactoring part 3.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 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/button/text_button.cc ('k') | views/controls/menu/menu_controller.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/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "app/resource_bundle.h" 11 #include "app/resource_bundle.h"
12 #include "app/text_elider.h" 12 #include "app/text_elider.h"
13 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "gfx/canvas_skia.h" 16 #include "gfx/canvas.h"
17 #include "gfx/color_utils.h" 17 #include "gfx/color_utils.h"
18 #include "gfx/font.h" 18 #include "gfx/font.h"
19 #include "gfx/insets.h" 19 #include "gfx/insets.h"
20 #include "views/background.h" 20 #include "views/background.h"
21 21
22 namespace views { 22 namespace views {
23 23
24 // static 24 // static
25 const char Label::kViewClassName[] = "views/Label"; 25 const char Label::kViewClassName[] = "views/Label";
26 SkColor Label::kEnabledColor, Label::kDisabledColor; 26 SkColor Label::kEnabledColor, Label::kDisabledColor;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 int Label::GetBaseline() { 60 int Label::GetBaseline() {
61 return GetInsets().top() + font_.baseline(); 61 return GetInsets().top() + font_.baseline();
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_.height();
70 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags()); 70 gfx::Canvas::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) {
80 PaintBackground(canvas); 80 PaintBackground(canvas);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // SizeStringInt() to calculate the desired width, it doesn't seem to work 381 // SizeStringInt() to calculate the desired width, it doesn't seem to work
382 // on Linux. 382 // on Linux.
383 int w = is_multi_line_ ? 383 int w = is_multi_line_ ?
384 GetAvailableRect().width() : std::numeric_limits<int>::max(); 384 GetAvailableRect().width() : std::numeric_limits<int>::max();
385 int h = font_.height(); 385 int h = font_.height();
386 // For single-line strings, ignore the available width and calculate how 386 // For single-line strings, ignore the available width and calculate how
387 // wide the text wants to be. 387 // wide the text wants to be.
388 int flags = ComputeMultiLineFlags(); 388 int flags = ComputeMultiLineFlags();
389 if (!is_multi_line_) 389 if (!is_multi_line_)
390 flags |= gfx::Canvas::NO_ELLIPSIS; 390 flags |= gfx::Canvas::NO_ELLIPSIS;
391 gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags); 391 gfx::Canvas::SizeStringInt(text_, font_, &w, &h, flags);
392 text_size_.SetSize(w, h); 392 text_size_.SetSize(w, h);
393 text_size_valid_ = true; 393 text_size_valid_ = true;
394 } 394 }
395 395
396 return text_size_; 396 return text_size_;
397 } 397 }
398 398
399 int Label::ComputeMultiLineFlags() const { 399 int Label::ComputeMultiLineFlags() const {
400 if (!is_multi_line_) 400 if (!is_multi_line_)
401 return 0; 401 return 0;
(...skipping 24 matching lines...) Expand all
426 } 426 }
427 427
428 gfx::Rect Label::GetAvailableRect() const { 428 gfx::Rect Label::GetAvailableRect() const {
429 gfx::Rect bounds(gfx::Point(), size()); 429 gfx::Rect bounds(gfx::Point(), size());
430 gfx::Insets insets(GetInsets()); 430 gfx::Insets insets(GetInsets());
431 bounds.Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); 431 bounds.Inset(insets.left(), insets.top(), insets.right(), insets.bottom());
432 return bounds; 432 return bounds;
433 } 433 }
434 434
435 } // namespace views 435 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/button/text_button.cc ('k') | views/controls/menu/menu_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698