Chromium Code Reviews| Index: third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp |
| diff --git a/third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp b/third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp |
| index 83a42eecc02a4f4c41dd621161a7c034ac7bae10..86883ef3b5f678b6dbab8810f80b8f07c28bab50 100644 |
| --- a/third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp |
| +++ b/third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp |
| @@ -156,7 +156,7 @@ void InlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& |
| // 1. Paint backgrounds behind text if needed. Examples of such backgrounds include selection |
| // and composition highlights. |
| if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseTextClip && !isPrinting) { |
| - paintDocumentMarkers(context, boxOrigin, styleToUse, font, true); |
| + paintDocumentMarkers(paintInfo, boxOrigin, styleToUse, font, true); |
| if (haveSelection && !paintsCompositionMarkers(textBoxLayoutObject)) { |
| if (combinedText) |
| @@ -243,7 +243,7 @@ void InlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& |
| } |
| if (paintInfo.phase == PaintPhaseForeground) |
| - paintDocumentMarkers(context, boxOrigin, styleToUse, font, false); |
| + paintDocumentMarkers(paintInfo, boxOrigin, styleToUse, font, false); |
| if (shouldRotate) |
| context.concatCTM(TextPainter::rotation(boxRect, TextPainter::Counterclockwise)); |
| @@ -298,7 +298,7 @@ void InlineTextBoxPainter::paintSingleCompositionBackgroundRun(GraphicsContext& |
| context.drawHighlightForText(font, m_inlineTextBox.constructTextRun(style, font), localOrigin, selHeight, backgroundColor, sPos, ePos); |
| } |
| -void InlineTextBoxPainter::paintDocumentMarkers(GraphicsContext& context, const LayoutPoint& boxOrigin, const ComputedStyle& style, const Font& font, bool background) |
| +void InlineTextBoxPainter::paintDocumentMarkers(const PaintInfo& paintInfo, const LayoutPoint& boxOrigin, const ComputedStyle& style, const Font& font, bool background) |
| { |
| if (!m_inlineTextBox.lineLayoutItem().node()) |
| return; |
| @@ -319,8 +319,6 @@ void InlineTextBoxPainter::paintDocumentMarkers(GraphicsContext& context, const |
| continue; |
| break; |
| case DocumentMarker::TextMatch: |
| - if (!background) |
| - continue; |
| break; |
|
fs
2015/12/17 10:10:54
Nit: Maybe drop this too now that TextMatch is in
ramya.v
2015/12/18 03:43:32
Done.
|
| case DocumentMarker::Composition: |
| break; |
| @@ -341,21 +339,24 @@ void InlineTextBoxPainter::paintDocumentMarkers(GraphicsContext& context, const |
| // marker intersects this run. Paint it. |
| switch (marker->type()) { |
| case DocumentMarker::Spelling: |
| - m_inlineTextBox.paintDocumentMarker(context, boxOrigin, marker, style, font, false); |
| + m_inlineTextBox.paintDocumentMarker(paintInfo.context, boxOrigin, marker, style, font, false); |
| break; |
| case DocumentMarker::Grammar: |
| - m_inlineTextBox.paintDocumentMarker(context, boxOrigin, marker, style, font, true); |
| + m_inlineTextBox.paintDocumentMarker(paintInfo.context, boxOrigin, marker, style, font, true); |
| break; |
| case DocumentMarker::TextMatch: |
| - m_inlineTextBox.paintTextMatchMarker(context, boxOrigin, marker, style, font); |
| + if (background) |
| + m_inlineTextBox.paintTextMatchMarkerBackground(paintInfo, boxOrigin, marker, style, font); |
| + else |
| + m_inlineTextBox.paintTextMatchMarkerForeground(paintInfo, boxOrigin, marker, style, font); |
| break; |
| case DocumentMarker::Composition: |
| { |
| CompositionUnderline underline(marker->startOffset(), marker->endOffset(), marker->underlineColor(), marker->thick(), marker->backgroundColor()); |
| if (background) |
| - paintSingleCompositionBackgroundRun(context, boxOrigin, style, font, underline.backgroundColor, underlinePaintStart(underline), underlinePaintEnd(underline)); |
| + paintSingleCompositionBackgroundRun(paintInfo.context, boxOrigin, style, font, underline.backgroundColor, underlinePaintStart(underline), underlinePaintEnd(underline)); |
| else |
| - paintCompositionUnderline(context, boxOrigin, underline); |
| + paintCompositionUnderline(paintInfo.context, boxOrigin, underline); |
| } |
| break; |
| default: |
| @@ -830,8 +831,39 @@ void InlineTextBoxPainter::paintCompositionUnderline(GraphicsContext& context, c |
| context.drawLineForText(FloatPoint(boxOrigin.x() + start, (boxOrigin.y() + m_inlineTextBox.logicalHeight() - lineThickness).toFloat()), width, m_inlineTextBox.lineLayoutItem().document().printing()); |
| } |
| -void InlineTextBoxPainter::paintTextMatchMarker(GraphicsContext& context, const LayoutPoint& boxOrigin, DocumentMarker* marker, const ComputedStyle& style, const Font& font) |
| +void InlineTextBoxPainter::paintTextMatchMarkerForeground(const PaintInfo& paintInfo, const LayoutPoint& boxOrigin, DocumentMarker* marker, const ComputedStyle& style, const Font& font) |
| { |
| + if (!LineLayoutPaintShim::layoutObjectFrom(m_inlineTextBox.lineLayoutItem())->frame()->editor().markedTextMatchesAreHighlighted()) |
| + return; |
| + |
| + // TODO(ramya.v): Extract this into a helper function and share many copies of this code. |
| + int sPos = std::max(marker->startOffset() - m_inlineTextBox.start(), (unsigned)0); |
| + int ePos = std::min(marker->endOffset() - m_inlineTextBox.start(), m_inlineTextBox.len()); |
| + TextRun run = m_inlineTextBox.constructTextRun(style, font); |
| + |
| + Color textColor = marker->activeMatch() ? |
|
fs
2015/12/17 10:10:54
Could just pass the predicate as the argument inst
ramya.v
2015/12/18 03:43:32
Done.
|
| + LayoutTheme::theme().platformTextSearchColor(true) : |
| + LayoutTheme::theme().platformTextSearchColor(false); |
| + if (style.visitedDependentColor(CSSPropertyColor) == textColor) |
| + return; |
| + TextPainter::Style textStyle; |
| + // When we use the text as a clip, we only care about the alpha, thus we make all the colors black. |
|
fs
2015/12/17 10:10:54
This comment doesn't appear to make much sense in
ramya.v
2015/12/18 03:43:32
Done.
|
| + textStyle.currentColor = textStyle.fillColor = textStyle.strokeColor = textStyle.emphasisMarkColor = textColor; |
| + textStyle.strokeWidth = style.textStrokeWidth(); |
| + textStyle.shadow = 0; |
| + |
| + LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), m_inlineTextBox.logicalHeight())); |
| + LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().ascent()); |
| + TextPainter textPainter(paintInfo.context, font, run, textOrigin, boxRect, m_inlineTextBox.isHorizontal()); |
| + |
| + textPainter.paint(sPos, ePos, m_inlineTextBox.len(), textStyle, 0); |
| +} |
| + |
| +void InlineTextBoxPainter::paintTextMatchMarkerBackground(const PaintInfo& paintInfo, const LayoutPoint& boxOrigin, DocumentMarker* marker, const ComputedStyle& style, const Font& font) |
| +{ |
| + if (!LineLayoutPaintShim::layoutObjectFrom(m_inlineTextBox.lineLayoutItem())->frame()->editor().markedTextMatchesAreHighlighted()) |
| + return; |
| + |
| // Use same y positioning and height as for selection, so that when the selection and this highlight are on |
| // the same word there are no pieces sticking out. |
| int deltaY = m_inlineTextBox.lineLayoutItem().style()->isFlippedLinesWritingMode() ? m_inlineTextBox.root().selectionBottom() - m_inlineTextBox.logicalBottom() : m_inlineTextBox.logicalTop() - m_inlineTextBox.root().selectionTop(); |
| @@ -841,31 +873,13 @@ void InlineTextBoxPainter::paintTextMatchMarker(GraphicsContext& context, const |
| int ePos = std::min(marker->endOffset() - m_inlineTextBox.start(), m_inlineTextBox.len()); |
| TextRun run = m_inlineTextBox.constructTextRun(style, font); |
| - // Optionally highlight the text |
| - if (LineLayoutPaintShim::layoutObjectFrom(m_inlineTextBox.lineLayoutItem())->frame()->editor().markedTextMatchesAreHighlighted()) { |
| - Color color = marker->activeMatch() ? |
| - LayoutTheme::theme().platformActiveTextSearchHighlightColor() : |
| - LayoutTheme::theme().platformInactiveTextSearchHighlightColor(); |
| - GraphicsContextStateSaver stateSaver(context); |
| - context.clip(FloatRect(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toFloat(), m_inlineTextBox.logicalWidth().toFloat(), selHeight)); |
| - context.drawHighlightForText(font, run, FloatPoint(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toFloat()), selHeight, color, sPos, ePos); |
| - |
| - // Also Highlight the text with color:transparent |
| - if (style.visitedDependentColor(CSSPropertyColor) == Color::transparent) { |
| - int length = m_inlineTextBox.len(); |
| - TextPainter::Style textStyle; |
| - // When we use the text as a clip, we only care about the alpha, thus we make all the colors black. |
| - textStyle.currentColor = textStyle.fillColor = textStyle.strokeColor = textStyle.emphasisMarkColor = Color::black; |
| - textStyle.strokeWidth = style.textStrokeWidth(); |
| - textStyle.shadow = 0; |
| - |
| - LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), m_inlineTextBox.logicalHeight())); |
| - LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().ascent()); |
| - TextPainter textPainter(context, font, run, textOrigin, boxRect, m_inlineTextBox.isHorizontal()); |
| - |
| - textPainter.paint(sPos, ePos, length, textStyle, 0); |
| - } |
| - } |
| + Color color = marker->activeMatch() ? |
|
fs
2015/12/17 10:10:54
Same suggestion as for the equivalent code above (
ramya.v
2015/12/18 03:43:32
Done.
|
| + LayoutTheme::theme().platformTextSearchHighlightColor(true) : |
| + LayoutTheme::theme().platformTextSearchHighlightColor(false); |
| + GraphicsContext& pt = paintInfo.context; |
|
fs
2015/12/17 10:10:54
pt -> context
ramya.v
2015/12/18 03:43:32
Done.
|
| + GraphicsContextStateSaver stateSaver(pt); |
| + pt.clip(FloatRect(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toFloat(), m_inlineTextBox.logicalWidth().toFloat(), selHeight)); |
| + pt.drawHighlightForText(font, run, FloatPoint(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toFloat()), selHeight, color, sPos, ePos); |
| } |