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

Unified Diff: third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.cpp

Issue 1468913002: Find In Page hides the text when text color matches text search hightlight color. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update paintSelectionBackground to use new helper function Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.cpp
diff --git a/third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.cpp b/third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.cpp
index bac8976e35ac6e246d80beb64a79d6c2c440115b..2ede1eb4846af46abd2eb51ba5b218bda22bb46a 100644
--- a/third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.cpp
+++ b/third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.cpp
@@ -65,11 +65,15 @@ void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
// TODO(chrishtr): passing the cull rect is incorrect.
DrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox, displayItemType, FloatRect(paintInfo.cullRect().m_rect));
InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers(
- paintInfo.context, paintOffset, style,
+ paintInfo, paintOffset, style,
textLayoutObject.scaledFont(), true);
if (!m_svgInlineTextBox.textFragments().isEmpty())
paintTextFragments(paintInfo, parentLayoutObject);
+
+ InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers(
+ paintInfo, paintOffset, style,
+ textLayoutObject.scaledFont(), false);
fs 2015/12/17 10:10:55 Maybe we should change this 'background' bool to a
ramya.v 2015/12/18 03:43:33 Done.
}
}
@@ -169,17 +173,12 @@ void SVGInlineTextBoxPainter::paintSelectionBackground(const PaintInfo& paintInf
int startPosition, endPosition;
m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition);
- int fragmentStartPosition = 0;
- int fragmentEndPosition = 0;
AffineTransform fragmentTransform;
- unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size();
+ Vector<SVGTextFragmentWithRange> fragmentInfoList = collectFragments(startPosition, endPosition);
+ unsigned textFragmentsSize = fragmentInfoList.size();
for (unsigned i = 0; i < textFragmentsSize; ++i) {
fs 2015/12/17 10:10:55 Using a range-based loop here would be an improvem
ramya.v 2015/12/18 03:43:32 Done.
- const SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at(i);
-
- fragmentStartPosition = startPosition;
- fragmentEndPosition = endPosition;
- if (!m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
- continue;
+ SVGTextFragmentWithRange& fragmentInfo = fragmentInfoList.at(i);
+ const SVGTextFragment& fragment = *(fragmentInfo.fragment);
GraphicsContextStateSaver stateSaver(paintInfo.context);
fragment.buildFragmentTransform(fragmentTransform);
@@ -187,7 +186,7 @@ void SVGInlineTextBoxPainter::paintSelectionBackground(const PaintInfo& paintInf
paintInfo.context.concatCTM(fragmentTransform);
paintInfo.context.setFillColor(backgroundColor);
- paintInfo.context.fillRect(m_svgInlineTextBox.selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor);
+ paintInfo.context.fillRect(m_svgInlineTextBox.selectionRectForTextFragment(fragment, fragmentInfo.fragmentStartPosition, fragmentInfo.fragmentEndPosition, style), backgroundColor);
}
}
@@ -401,15 +400,19 @@ void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, const Comput
paintTextWithShadows(paintInfo, style, textRun, fragment, endPosition, fragment.length, resourceMode);
}
-void SVGInlineTextBoxPainter::paintTextMatchMarker(GraphicsContext& context, const LayoutPoint&, DocumentMarker* marker, const ComputedStyle& style, const Font& font)
+Vector<SVGTextFragmentWithRange> SVGInlineTextBoxPainter::collectTextMatches(const PaintInfo& paintInfo, DocumentMarker* marker)
{
- // SVG is only interested in the TextMatch markers.
+ Vector<SVGTextFragmentWithRange> textMatchInfoList;
+
+ // SVG does not support grammar or spellcheck markers, so skip anything but TextMatch.
if (marker->type() != DocumentMarker::TextMatch)
- return;
+ return textMatchInfoList;
+
+ if (!LineLayoutPaintShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem())->frame()->editor().markedTextMatchesAreHighlighted())
+ return textMatchInfoList;
LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutPaintShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem()));
- AffineTransform fragmentTransform;
for (InlineTextBox* box = textLayoutObject.firstTextBox(); box; box = box->nextTextBox()) {
fs 2015/12/17 10:10:54 I still don't think this additional nesting is nee
ramya.v 2015/12/18 03:43:32 Done.
if (!box->isSVGInlineTextBox())
continue;
@@ -422,32 +425,87 @@ void SVGInlineTextBoxPainter::paintTextMatchMarker(GraphicsContext& context, con
if (markerStartPosition >= markerEndPosition)
continue;
- const Vector<SVGTextFragment>& fragments = textBox->textFragments();
- unsigned textFragmentsSize = fragments.size();
+ Vector<SVGTextFragmentWithRange> fragmentList = collectFragments(markerStartPosition, markerEndPosition);
+ unsigned textFragmentsSize = fragmentList.size();
for (unsigned i = 0; i < textFragmentsSize; ++i) {
- const SVGTextFragment& fragment = fragments.at(i);
-
- int fragmentStartPosition = markerStartPosition;
- int fragmentEndPosition = markerEndPosition;
- if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
- continue;
-
- FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style);
- fragment.buildFragmentTransform(fragmentTransform);
-
- // Draw the marker highlight.
- if (LineLayoutPaintShim::layoutObjectFrom(m_svgInlineTextBox.lineLayoutItem())->frame()->editor().markedTextMatchesAreHighlighted()) {
- Color color = marker->activeMatch() ?
- LayoutTheme::theme().platformActiveTextSearchHighlightColor() :
- LayoutTheme::theme().platformInactiveTextSearchHighlightColor();
- GraphicsContextStateSaver stateSaver(context);
- if (!fragmentTransform.isIdentity())
- context.concatCTM(fragmentTransform);
- context.setFillColor(color);
- context.fillRect(fragmentRect, color);
- }
+ textMatchInfoList.append(fragmentList.at(i));
fs 2015/12/17 10:10:55 Use appendVector or appendRange instead. Per above
ramya.v 2015/12/18 03:43:32 Done.
}
}
+ return textMatchInfoList;
+}
+
+Vector<SVGTextFragmentWithRange> SVGInlineTextBoxPainter::collectFragments(int startPosition, int endPosition)
fs 2015/12/17 10:10:54 collectFragmentsInRange or something more narrow l
ramya.v 2015/12/18 03:43:33 Done.
+{
+ Vector<SVGTextFragmentWithRange> fragmentInfoList;
+ const Vector<SVGTextFragment>& fragments = m_svgInlineTextBox.textFragments();
+ unsigned textFragmentsSize = fragments.size();
+ for (unsigned i = 0; i < textFragmentsSize; ++i) {
fs 2015/12/17 10:10:55 Use a range-based for-loop.
ramya.v 2015/12/18 03:43:32 Done.
+ const SVGTextFragment& fragment = fragments.at(i);
+
+ int fragmentStartPosition = startPosition;
+ int fragmentEndPosition = endPosition;
+ if (!m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
+ continue;
+
+ SVGTextFragmentWithRange fragmentInfo;
+ fragmentInfo.fragment = &fragment;
+ fragmentInfo.fragmentStartPosition = fragmentStartPosition;
+ fragmentInfo.fragmentEndPosition = fragmentEndPosition;
+
+ fragmentInfoList.append(fragmentInfo);
fs 2015/12/17 10:10:55 With a constructor for SVGTextFragmentWithRange, t
ramya.v 2015/12/18 03:43:33 Done.
+ }
+ return fragmentInfoList;
+}
+
+void SVGInlineTextBoxPainter::paintTextMatchMarkerForeground(const PaintInfo& paintInfo, const LayoutPoint& point, DocumentMarker* marker, const ComputedStyle& style, const Font& font)
+{
+ Vector<SVGTextFragmentWithRange> textMatchInfoList = collectTextMatches(paintInfo, marker);
+ unsigned textFragmentsSize = textMatchInfoList.size();
+ if (textFragmentsSize == 0)
+ return;
+
+ Color textColor = marker->activeMatch() ?
fs 2015/12/17 10:10:55 Same comment as for other instances of this.
ramya.v 2015/12/18 03:43:33 Done.
+ LayoutTheme::theme().platformTextSearchColor(true) :
+ LayoutTheme::theme().platformTextSearchColor(false);
+
+ AffineTransform fragmentTransform;
+ for (unsigned i = 0; i < textFragmentsSize; ++i) {
fs 2015/12/17 10:10:55 Use range-based for-loop.
ramya.v 2015/12/18 03:43:33 Done.
+ SVGTextFragmentWithRange& textMatchInfo = textMatchInfoList.at(i);
+ const SVGTextFragment& fragment = *(textMatchInfo.fragment);
+ GraphicsContextStateSaver stateSaver(paintInfo.context);
+ fragment.buildFragmentTransform(fragmentTransform);
+ if (!fragmentTransform.isIdentity())
+ paintInfo.context.concatCTM(fragmentTransform);
+ RefPtr<ComputedStyle> markerStyle = ComputedStyle::clone(style);
+ markerStyle->setFillPaintColor(textColor);
+ TextRun textRun = m_svgInlineTextBox.constructTextRun(*markerStyle, fragment);
+ paintTextWithShadows(paintInfo, *markerStyle, textRun, fragment, textMatchInfo.fragmentStartPosition, textMatchInfo.fragmentEndPosition, ApplyToFillMode);
+ }
+}
+
+void SVGInlineTextBoxPainter::paintTextMatchMarkerBackground(const PaintInfo& paintInfo, const LayoutPoint& point, DocumentMarker* marker, const ComputedStyle& style, const Font& font)
+{
+ Vector<SVGTextFragmentWithRange> textMatchInfoList = collectTextMatches(paintInfo, marker);
+ unsigned textFragmentsSize = textMatchInfoList.size();
+ if (textFragmentsSize == 0)
+ return;
+
+ Color color = marker->activeMatch() ?
fs 2015/12/17 10:10:55 Again.
ramya.v 2015/12/18 03:43:32 Done.
+ LayoutTheme::theme().platformTextSearchHighlightColor(true) :
+ LayoutTheme::theme().platformTextSearchHighlightColor(false);
+
+ AffineTransform fragmentTransform;
+ for (unsigned i = 0; i < textFragmentsSize; ++i) {
fs 2015/12/17 10:10:54 Use range-based for-loop.
ramya.v 2015/12/18 03:43:33 Done.
+ SVGTextFragmentWithRange& textMatchInfo = textMatchInfoList.at(i);
+ const SVGTextFragment& fragment = *(textMatchInfo.fragment);
+ GraphicsContextStateSaver stateSaver(paintInfo.context);
+ fragment.buildFragmentTransform(fragmentTransform);
+ if (!fragmentTransform.isIdentity())
+ paintInfo.context.concatCTM(fragmentTransform);
+ FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment(fragment, textMatchInfo.fragmentStartPosition, textMatchInfo.fragmentEndPosition, style);
+ paintInfo.context.setFillColor(color);
+ paintInfo.context.fillRect(fragmentRect, color);
+ }
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698