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

Side by Side Diff: ui/gfx/render_text_mac.cc

Issue 24883002: Uses and returns the fractional width in text eliding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix per more feedback Created 7 years, 2 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
OLDNEW
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/gfx/render_text_mac.h" 5 #include "ui/gfx/render_text_mac.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/mac/foundation_util.h" 13 #include "base/mac/foundation_util.h"
14 #include "base/mac/scoped_cftyperef.h" 14 #include "base/mac/scoped_cftyperef.h"
15 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
16 #include "skia/ext/skia_utils_mac.h" 16 #include "skia/ext/skia_utils_mac.h"
17 17
18 namespace gfx { 18 namespace gfx {
19 19
20 RenderTextMac::RenderTextMac() : common_baseline_(0), runs_valid_(false) { 20 RenderTextMac::RenderTextMac() : common_baseline_(0), runs_valid_(false) {
21 } 21 }
22 22
23 RenderTextMac::~RenderTextMac() { 23 RenderTextMac::~RenderTextMac() {
24 } 24 }
25 25
26 Size RenderTextMac::GetStringSize() { 26 Size RenderTextMac::GetStringSize() {
27 EnsureLayout(); 27 EnsureLayout();
sky 2013/10/08 02:12:56 How about return ToCeiledSize(GetStringSizeF()) ?
jianli 2013/10/08 18:29:48 Returning both ceiled width and height will cause
28 return Size(std::ceil(string_size_.width()), string_size_.height());
29 }
30
31 SizeF RenderTextMac::GetStringSizeF() {
32 EnsureLayout();
28 return string_size_; 33 return string_size_;
29 } 34 }
30 35
31 int RenderTextMac::GetBaseline() { 36 int RenderTextMac::GetBaseline() {
32 EnsureLayout(); 37 EnsureLayout();
33 return common_baseline_; 38 return common_baseline_;
34 } 39 }
35 40
36 SelectionModel RenderTextMac::FindCursorPosition(const Point& point) { 41 SelectionModel RenderTextMac::FindCursorPosition(const Point& point) {
37 // TODO(asvitkine): Implement this. http://crbug.com/131618 42 // TODO(asvitkine): Implement this. http://crbug.com/131618
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 double width = CTLineGetTypographicBounds(line_, &ascent, &descent, &leading); 147 double width = CTLineGetTypographicBounds(line_, &ascent, &descent, &leading);
143 // Ensure ascent and descent are not smaller than ones of the font list. 148 // Ensure ascent and descent are not smaller than ones of the font list.
144 // Keep them tall enough to draw often-used characters. 149 // Keep them tall enough to draw often-used characters.
145 // For example, if a text field contains a Japanese character, which is 150 // For example, if a text field contains a Japanese character, which is
146 // smaller than Latin ones, and then later a Latin one is inserted, this 151 // smaller than Latin ones, and then later a Latin one is inserted, this
147 // ensures that the text baseline does not shift. 152 // ensures that the text baseline does not shift.
148 CGFloat font_list_height = font_list().GetHeight(); 153 CGFloat font_list_height = font_list().GetHeight();
149 CGFloat font_list_baseline = font_list().GetBaseline(); 154 CGFloat font_list_baseline = font_list().GetBaseline();
150 ascent = std::max(ascent, font_list_baseline); 155 ascent = std::max(ascent, font_list_baseline);
151 descent = std::max(descent, font_list_height - font_list_baseline); 156 descent = std::max(descent, font_list_height - font_list_baseline);
152 string_size_ = Size(std::ceil(width), ascent + descent + leading); 157 string_size_ = SizeF(width, ascent + descent + leading);
153 common_baseline_ = ascent; 158 common_baseline_ = ascent;
154 } 159 }
155 160
156 void RenderTextMac::DrawVisualText(Canvas* canvas) { 161 void RenderTextMac::DrawVisualText(Canvas* canvas) {
157 DCHECK(line_); 162 DCHECK(line_);
158 if (!runs_valid_) 163 if (!runs_valid_)
159 ComputeRuns(); 164 ComputeRuns();
160 165
161 internal::SkiaTextRenderer renderer(canvas); 166 internal::SkiaTextRenderer renderer(canvas);
162 ApplyFadeEffects(&renderer); 167 ApplyFadeEffects(&renderer);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 run_origin.offset(run_width, 0); 338 run_origin.offset(run_width, 0);
334 } 339 }
335 runs_valid_ = true; 340 runs_valid_ = true;
336 } 341 }
337 342
338 RenderText* RenderText::CreateInstance() { 343 RenderText* RenderText::CreateInstance() {
339 return new RenderTextMac; 344 return new RenderTextMac;
340 } 345 }
341 346
342 } // namespace gfx 347 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698