Chromium Code Reviews| Index: ui/gfx/render_text_mac.cc |
| diff --git a/ui/gfx/render_text_mac.cc b/ui/gfx/render_text_mac.cc |
| index a6367141fe8fada68628d05355661d717e1fcfaf..399228084c923879e3a41234e6c7d711797c90c9 100644 |
| --- a/ui/gfx/render_text_mac.cc |
| +++ b/ui/gfx/render_text_mac.cc |
| @@ -158,7 +158,7 @@ void RenderTextMac::DrawVisualText(Canvas* canvas) { |
| renderer.DrawPosText(&run.glyph_positions[0], &run.glyphs[0], |
| run.glyphs.size()); |
| renderer.DrawDecorations(run.origin.x(), run.origin.y(), run.width, |
| - run.style); |
| + run.underline, run.strike, run.diagonal_strike); |
| } |
| } |
| @@ -168,7 +168,10 @@ RenderTextMac::TextRun::TextRun() |
| width(0), |
| font_style(Font::NORMAL), |
| text_size(0), |
| - foreground(SK_ColorBLACK) { |
| + foreground(SK_ColorBLACK), |
| + underline(false), |
| + strike(false), |
| + diagonal_strike(false) { |
| } |
| RenderTextMac::TextRun::~TextRun() { |
| @@ -176,44 +179,40 @@ RenderTextMac::TextRun::~TextRun() { |
| void RenderTextMac::ApplyStyles(CFMutableAttributedStringRef attr_string, |
| CTFontRef font) { |
| - // Clear attributes and reserve space to hold the maximum number of entries, |
| - // which is at most three per style range per the code below. |
| - attributes_.reset(CFArrayCreateMutable(NULL, 3 * style_ranges().size(), |
| - &kCFTypeArrayCallBacks)); |
| + // Temporarily apply composition underlines and selection colors. |
| + ApplyCompositionAndSelectionStyles(); |
| - // https://developer.apple.com/library/mac/#documentation/Carbon/Reference/CoreText_StringAttributes_Ref/Reference/reference.html |
| - for (size_t i = 0; i < style_ranges().size(); ++i) { |
| - const StyleRange& style = style_ranges()[i]; |
| - const CFRange range = CFRangeMake(style.range.start(), |
| - style.range.length()); |
| - |
| - // Note: CFAttributedStringSetAttribute() does not appear to retain the |
| - // values passed in, as can be verified via CFGetRetainCount(). To ensure |
| - // the attribute objects do not leak, they are saved to |attributes_|. |
| + // Note: CFAttributedStringSetAttribute() does not appear to retain the values |
| + // passed in, as can be verified via CFGetRetainCount(). To ensure the |
| + // attribute objects do not leak, they are saved to |attributes_|. |
| + // Clear the attributes storage. |
| + attributes_.reset(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks)); |
| + // https://developer.apple.com/library/mac/#documentation/Carbon/Reference/CoreText_StringAttributes_Ref/Reference/reference.html |
| + internal::StyleIterator style(colors(), styles()); |
| + const size_t text_length = text().length(); |
| + for (size_t i = 0, end = 0; i < text_length; i = end) { |
| + end = TextIndexToLayoutIndex(style.GetRange().end()); |
|
Alexei Svitkine (slow)
2013/01/31 16:33:34
Again, this seems to be comparing a LayoutIndex wi
msw
2013/01/31 20:27:39
Done.
|
| + const CFRange range = CFRangeMake(i, end - i); |
| base::mac::ScopedCFTypeRef<CGColorRef> foreground( |
| - gfx::CGColorCreateFromSkColor(style.foreground)); |
| + gfx::CGColorCreateFromSkColor(style.color())); |
| CFAttributedStringSetAttribute(attr_string, range, |
| - kCTForegroundColorAttributeName, |
| - foreground); |
| + kCTForegroundColorAttributeName, foreground); |
| CFArrayAppendValue(attributes_, foreground); |
| - if (style.underline) { |
| + if (style.style(UNDERLINE)) { |
| CTUnderlineStyle value = kCTUnderlineStyleSingle; |
| - base::mac::ScopedCFTypeRef<CFNumberRef> underline( |
| + base::mac::ScopedCFTypeRef<CFNumberRef> underline_value( |
| CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
| CFAttributedStringSetAttribute(attr_string, range, |
| kCTUnderlineStyleAttributeName, |
| - underline); |
| - CFArrayAppendValue(attributes_, underline); |
| + underline_value); |
| + CFArrayAppendValue(attributes_, underline_value); |
| } |
| - if (style.font_style & (Font::BOLD | Font::ITALIC)) { |
| - int traits = 0; |
| - if (style.font_style & Font::BOLD) |
| - traits |= kCTFontBoldTrait; |
| - if (style.font_style & Font::ITALIC) |
| - traits |= kCTFontItalicTrait; |
| + const int traits = (style.style(BOLD) ? kCTFontBoldTrait : 0) | |
| + (style.style(ITALIC) ? kCTFontItalicTrait : 0); |
| + if (traits != 0) { |
| base::mac::ScopedCFTypeRef<CTFontRef> styled_font( |
| CTFontCreateCopyWithSymbolicTraits(font, 0.0, NULL, traits, traits)); |
| // TODO(asvitkine): Handle |styled_font| == NULL case better. |
| @@ -223,7 +222,12 @@ void RenderTextMac::ApplyStyles(CFMutableAttributedStringRef attr_string, |
| CFArrayAppendValue(attributes_, styled_font); |
| } |
| } |
| + |
| + style.UpdatePosition(LayoutIndexToTextIndex(end)); |
| } |
| + |
| + // Undo the temporarily applied composition underlines and selection colors. |
| + UndoCompositionAndSelectionStyles(); |
| } |
| void RenderTextMac::ComputeRuns() { |
| @@ -283,7 +287,7 @@ void RenderTextMac::ComputeRuns() { |
| } |
| // TODO(asvitkine): Style boundaries are not necessarily per-run. Handle |
| - // this better. |
| + // this better. Also, support strike and diagonal_strike. |
| CFDictionaryRef attributes = CTRunGetAttributes(ct_run); |
| CTFontRef ct_font = |
| base::mac::GetValueFromDictionary<CTFontRef>(attributes, |
| @@ -310,7 +314,7 @@ void RenderTextMac::ComputeRuns() { |
| attributes, kCTUnderlineStyleAttributeName); |
| CTUnderlineStyle value = kCTUnderlineStyleNone; |
| if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value)) |
| - run->style.underline = (value == kCTUnderlineStyleSingle); |
| + run->underline = (value == kCTUnderlineStyleSingle); |
| run_origin.offset(run_width, 0); |
| } |