OLD | NEW |
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> |
(...skipping 27 matching lines...) Expand all Loading... |
38 return SelectionModel(); | 38 return SelectionModel(); |
39 } | 39 } |
40 | 40 |
41 std::vector<RenderText::FontSpan> RenderTextMac::GetFontSpansForTesting() { | 41 std::vector<RenderText::FontSpan> RenderTextMac::GetFontSpansForTesting() { |
42 EnsureLayout(); | 42 EnsureLayout(); |
43 if (!runs_valid_) | 43 if (!runs_valid_) |
44 ComputeRuns(); | 44 ComputeRuns(); |
45 | 45 |
46 std::vector<RenderText::FontSpan> spans; | 46 std::vector<RenderText::FontSpan> spans; |
47 for (size_t i = 0; i < runs_.size(); ++i) { | 47 for (size_t i = 0; i < runs_.size(); ++i) { |
48 Font font(runs_[i].font_name, runs_[i].text_size); | 48 gfx::Font font(runs_[i].font_name, runs_[i].text_size); |
49 const CFRange cf_range = CTRunGetStringRange(runs_[i].ct_run); | 49 const CFRange cf_range = CTRunGetStringRange(runs_[i].ct_run); |
50 const Range range(cf_range.location, cf_range.location + cf_range.length); | 50 const Range range(cf_range.location, cf_range.location + cf_range.length); |
51 spans.push_back(RenderText::FontSpan(font, range)); | 51 spans.push_back(RenderText::FontSpan(font, range)); |
52 } | 52 } |
53 | 53 |
54 return spans; | 54 return spans; |
55 } | 55 } |
56 | 56 |
57 int RenderTextMac::GetLayoutTextBaseline() { | 57 int RenderTextMac::GetLayoutTextBaseline() { |
58 EnsureLayout(); | 58 EnsureLayout(); |
(...skipping 27 matching lines...) Expand all Loading... |
86 size_t RenderTextMac::TextIndexToLayoutIndex(size_t index) const { | 86 size_t RenderTextMac::TextIndexToLayoutIndex(size_t index) const { |
87 // TODO(asvitkine): Implement this. http://crbug.com/131618 | 87 // TODO(asvitkine): Implement this. http://crbug.com/131618 |
88 return index; | 88 return index; |
89 } | 89 } |
90 | 90 |
91 size_t RenderTextMac::LayoutIndexToTextIndex(size_t index) const { | 91 size_t RenderTextMac::LayoutIndexToTextIndex(size_t index) const { |
92 // TODO(asvitkine): Implement this. http://crbug.com/131618 | 92 // TODO(asvitkine): Implement this. http://crbug.com/131618 |
93 return index; | 93 return index; |
94 } | 94 } |
95 | 95 |
96 bool RenderTextMac::IsValidCursorIndex(size_t index) { | 96 bool RenderTextMac::IsCursorablePosition(size_t position) { |
97 // TODO(asvitkine): Implement this. http://crbug.com/131618 | 97 // TODO(asvitkine): Implement this. http://crbug.com/131618 |
98 return IsValidLogicalIndex(index); | 98 return true; |
99 } | 99 } |
100 | 100 |
101 void RenderTextMac::ResetLayout() { | 101 void RenderTextMac::ResetLayout() { |
102 line_.reset(); | 102 line_.reset(); |
103 attributes_.reset(); | 103 attributes_.reset(); |
104 runs_.clear(); | 104 runs_.clear(); |
105 runs_valid_ = false; | 105 runs_valid_ = false; |
106 } | 106 } |
107 | 107 |
108 void RenderTextMac::EnsureLayout() { | 108 void RenderTextMac::EnsureLayout() { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // Clear the attributes storage. | 204 // Clear the attributes storage. |
205 attributes_.reset(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks)); | 205 attributes_.reset(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks)); |
206 | 206 |
207 // https://developer.apple.com/library/mac/#documentation/Carbon/Reference/Cor
eText_StringAttributes_Ref/Reference/reference.html | 207 // https://developer.apple.com/library/mac/#documentation/Carbon/Reference/Cor
eText_StringAttributes_Ref/Reference/reference.html |
208 internal::StyleIterator style(colors(), styles()); | 208 internal::StyleIterator style(colors(), styles()); |
209 const size_t layout_text_length = GetLayoutText().length(); | 209 const size_t layout_text_length = GetLayoutText().length(); |
210 for (size_t i = 0, end = 0; i < layout_text_length; i = end) { | 210 for (size_t i = 0, end = 0; i < layout_text_length; i = end) { |
211 end = TextIndexToLayoutIndex(style.GetRange().end()); | 211 end = TextIndexToLayoutIndex(style.GetRange().end()); |
212 const CFRange range = CFRangeMake(i, end - i); | 212 const CFRange range = CFRangeMake(i, end - i); |
213 base::ScopedCFTypeRef<CGColorRef> foreground( | 213 base::ScopedCFTypeRef<CGColorRef> foreground( |
214 CGColorCreateFromSkColor(style.color())); | 214 gfx::CGColorCreateFromSkColor(style.color())); |
215 CFAttributedStringSetAttribute(attr_string, range, | 215 CFAttributedStringSetAttribute(attr_string, range, |
216 kCTForegroundColorAttributeName, foreground); | 216 kCTForegroundColorAttributeName, foreground); |
217 CFArrayAppendValue(attributes_, foreground); | 217 CFArrayAppendValue(attributes_, foreground); |
218 | 218 |
219 if (style.style(UNDERLINE)) { | 219 if (style.style(UNDERLINE)) { |
220 CTUnderlineStyle value = kCTUnderlineStyleSingle; | 220 CTUnderlineStyle value = kCTUnderlineStyleSingle; |
221 base::ScopedCFTypeRef<CFNumberRef> underline_value( | 221 base::ScopedCFTypeRef<CFNumberRef> underline_value( |
222 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 222 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
223 CFAttributedStringSetAttribute(attr_string, range, | 223 CFAttributedStringSetAttribute(attr_string, range, |
224 kCTUnderlineStyleAttributeName, | 224 kCTUnderlineStyleAttributeName, |
(...skipping 22 matching lines...) Expand all Loading... |
247 } | 247 } |
248 | 248 |
249 void RenderTextMac::ComputeRuns() { | 249 void RenderTextMac::ComputeRuns() { |
250 DCHECK(line_); | 250 DCHECK(line_); |
251 | 251 |
252 CFArrayRef ct_runs = CTLineGetGlyphRuns(line_); | 252 CFArrayRef ct_runs = CTLineGetGlyphRuns(line_); |
253 const CFIndex ct_runs_count = CFArrayGetCount(ct_runs); | 253 const CFIndex ct_runs_count = CFArrayGetCount(ct_runs); |
254 | 254 |
255 // TODO(asvitkine): Don't use GetLineOffset() until draw time, since it may be | 255 // TODO(asvitkine): Don't use GetLineOffset() until draw time, since it may be |
256 // updated based on alignment changes without resetting the layout. | 256 // updated based on alignment changes without resetting the layout. |
257 Vector2d text_offset = GetLineOffset(0); | 257 gfx::Vector2d text_offset = GetLineOffset(0); |
258 // Skia will draw glyphs with respect to the baseline. | 258 // Skia will draw glyphs with respect to the baseline. |
259 text_offset += Vector2d(0, common_baseline_); | 259 text_offset += gfx::Vector2d(0, common_baseline_); |
260 | 260 |
261 const SkScalar x = SkIntToScalar(text_offset.x()); | 261 const SkScalar x = SkIntToScalar(text_offset.x()); |
262 const SkScalar y = SkIntToScalar(text_offset.y()); | 262 const SkScalar y = SkIntToScalar(text_offset.y()); |
263 SkPoint run_origin = SkPoint::Make(x, y); | 263 SkPoint run_origin = SkPoint::Make(x, y); |
264 | 264 |
265 const CFRange empty_cf_range = CFRangeMake(0, 0); | 265 const CFRange empty_cf_range = CFRangeMake(0, 0); |
266 for (CFIndex i = 0; i < ct_runs_count; ++i) { | 266 for (CFIndex i = 0; i < ct_runs_count; ++i) { |
267 CTRunRef ct_run = | 267 CTRunRef ct_run = |
268 base::mac::CFCast<CTRunRef>(CFArrayGetValueAtIndex(ct_runs, i)); | 268 base::mac::CFCast<CTRunRef>(CFArrayGetValueAtIndex(ct_runs, i)); |
269 const size_t glyph_count = CTRunGetGlyphCount(ct_run); | 269 const size_t glyph_count = CTRunGetGlyphCount(ct_run); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(ct_font); | 318 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(ct_font); |
319 if (traits & kCTFontBoldTrait) | 319 if (traits & kCTFontBoldTrait) |
320 run->font_style |= Font::BOLD; | 320 run->font_style |= Font::BOLD; |
321 if (traits & kCTFontItalicTrait) | 321 if (traits & kCTFontItalicTrait) |
322 run->font_style |= Font::ITALIC; | 322 run->font_style |= Font::ITALIC; |
323 | 323 |
324 const CGColorRef foreground = | 324 const CGColorRef foreground = |
325 base::mac::GetValueFromDictionary<CGColorRef>( | 325 base::mac::GetValueFromDictionary<CGColorRef>( |
326 attributes, kCTForegroundColorAttributeName); | 326 attributes, kCTForegroundColorAttributeName); |
327 if (foreground) | 327 if (foreground) |
328 run->foreground = CGColorRefToSkColor(foreground); | 328 run->foreground = gfx::CGColorRefToSkColor(foreground); |
329 | 329 |
330 const CFNumberRef underline = | 330 const CFNumberRef underline = |
331 base::mac::GetValueFromDictionary<CFNumberRef>( | 331 base::mac::GetValueFromDictionary<CFNumberRef>( |
332 attributes, kCTUnderlineStyleAttributeName); | 332 attributes, kCTUnderlineStyleAttributeName); |
333 CTUnderlineStyle value = kCTUnderlineStyleNone; | 333 CTUnderlineStyle value = kCTUnderlineStyleNone; |
334 if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value)) | 334 if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value)) |
335 run->underline = (value == kCTUnderlineStyleSingle); | 335 run->underline = (value == kCTUnderlineStyleSingle); |
336 | 336 |
337 run_origin.offset(run_width, 0); | 337 run_origin.offset(run_width, 0); |
338 } | 338 } |
339 runs_valid_ = true; | 339 runs_valid_ = true; |
340 } | 340 } |
341 | 341 |
342 RenderText* RenderText::CreateInstance() { | 342 RenderText* RenderText::CreateInstance() { |
343 return new RenderTextMac; | 343 return new RenderTextMac; |
344 } | 344 } |
345 | 345 |
346 } // namespace gfx | 346 } // namespace gfx |
OLD | NEW |