Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (222506 => 222507)
--- trunk/Source/WebCore/rendering/InlineTextBox.cpp 2017-09-26 18:08:23 UTC (rev 222506)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp 2017-09-26 18:12:50 UTC (rev 222507)
@@ -488,9 +488,7 @@
// and composition underlines.
if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseTextClip && !isPrinting) {
if (containsComposition && !useCustomUnderlines)
- paintCompositionBackground(context, boxOrigin, lineStyle, font,
- renderer().frame().editor().compositionStart(),
- renderer().frame().editor().compositionEnd());
+ paintCompositionBackground(context, boxOrigin, lineStyle, font);
paintDocumentMarkers(context, boxOrigin, lineStyle, font, true);
@@ -689,6 +687,7 @@
unsigned length = m_truncation != cNoTruncation ? m_truncation : len();
+ // FIXME: Adjust text run for combined text.
String hyphenatedString;
bool respectHyphen = selectionEnd == length && hasHyphen();
if (respectHyphen)
@@ -716,24 +715,40 @@
#endif
}
-void InlineTextBox::paintCompositionBackground(GraphicsContext& context, const FloatPoint& boxOrigin, const RenderStyle& style, const FontCascade& font, unsigned startPos, unsigned endPos)
+inline void InlineTextBox::paintTextSubrangeBackground(GraphicsContext& context, const FloatPoint& boxOrigin, const RenderStyle& style, const FontCascade& font, const Color& color, unsigned startOffset, unsigned endOffset)
{
- unsigned selectionStart = clampedOffset(startPos);
- unsigned selectionEnd = clampedOffset(endPos);
- if (selectionStart >= selectionEnd)
+ startOffset = clampedOffset(startOffset);
+ endOffset = clampedOffset(endOffset);
+ if (startOffset >= endOffset)
return;
- GraphicsContextStateSaver stateSaver(context);
- Color compositionColor = Color::compositionFill;
- updateGraphicsContext(context, TextPaintStyle(compositionColor)); // Don't draw text at all!
+ GraphicsContextStateSaver stateSaver { context };
+ updateGraphicsContext(context, TextPaintStyle { color }); // Don't draw text at all!
+ // Use same y positioning and height as for selection, so that when the selection and this subrange are on
+ // the same word there are no pieces sticking out.
LayoutUnit deltaY = renderer().style().isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
LayoutRect selectionRect = LayoutRect(boxOrigin.x(), boxOrigin.y() - deltaY, 0, selectionHeight());
+
+ // FIXME: Adjust text run for combined text and hyphenation.
TextRun textRun = constructTextRun(style);
- font.adjustSelectionRectForText(textRun, selectionRect, selectionStart, selectionEnd);
- context.fillRect(snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), textRun.ltr()), compositionColor);
+ font.adjustSelectionRectForText(textRun, selectionRect, startOffset, endOffset);
+ context.fillRect(snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), textRun.ltr()), color);
}
+void InlineTextBox::paintCompositionBackground(GraphicsContext& context, const FloatPoint& boxOrigin, const RenderStyle& style, const FontCascade& font)
+{
+ paintTextSubrangeBackground(context, boxOrigin, style, font, renderer().frame().editor().compositionStart(), renderer().frame().editor().compositionEnd(), Color::compositionFill);
+}
+
+void InlineTextBox::paintTextMatchMarker(GraphicsContext& context, const FloatPoint& boxOrigin, const RenderStyle& style, const FontCascade& font, const MarkerSubrange& subrange, bool isActiveMatch)
+{
+ if (!renderer().frame().editor().markedTextMatchesAreHighlighted())
+ return;
+ auto highlightColor = isActiveMatch ? renderer().theme().platformActiveTextSearchHighlightColor() : renderer().theme().platformInactiveTextSearchHighlightColor();
+ paintTextSubrangeBackground(context, boxOrigin, style, font, highlightColor, subrange.startOffset, subrange.endOffset);
+}
+
static inline void mirrorRTLSegment(float logicalWidth, TextDirection direction, float& start, float width)
{
if (direction == LTR)
@@ -783,7 +798,7 @@
context.concatCTM(rotation(boxRect, Counterclockwise));
}
-void InlineTextBox::paintDocumentMarker(GraphicsContext& context, const FloatPoint& boxOrigin, const MarkerSubrange& subrange, const RenderStyle& style, const FontCascade& font)
+void InlineTextBox::paintDocumentMarker(GraphicsContext& context, const FloatPoint& boxOrigin, const RenderStyle& style, const FontCascade& font, const MarkerSubrange& subrange)
{
// Never print spelling/grammar markers (5327887)
if (renderer().document().printing())
@@ -812,6 +827,7 @@
endPosition = std::min(endPosition, static_cast<unsigned>(m_truncation));
// Calculate start & width
+ // FIXME: Adjust text run for combined text and hyphenation.
int deltaY = renderer().style().isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
int selHeight = selectionHeight();
FloatPoint startPoint(boxOrigin.x(), boxOrigin.y() - deltaY);
@@ -865,31 +881,6 @@
context.drawLineForDocumentMarker(FloatPoint(boxOrigin.x() + start, boxOrigin.y() + underlineOffset), width, lineStyleForSubrangeType(subrange.type));
}
-void InlineTextBox::paintTextMatchMarker(GraphicsContext& context, const FloatPoint& boxOrigin, const MarkerSubrange& subrange, const RenderStyle& style, const FontCascade& font, bool isActiveMatch)
-{
- if (!renderer().frame().editor().markedTextMatchesAreHighlighted())
- return;
-
- auto color = isActiveMatch ? renderer().theme().platformActiveTextSearchHighlightColor() : renderer().theme().platformInactiveTextSearchHighlightColor();
- GraphicsContextStateSaver stateSaver(context);
- updateGraphicsContext(context, TextPaintStyle(color)); // Don't draw text at all!
-
- // 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.
- LayoutUnit deltaY = renderer().style().isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
- LayoutRect selectionRect = LayoutRect(boxOrigin.x(), boxOrigin.y() - deltaY, 0, this->selectionHeight());
-
- unsigned sPos = clampedOffset(subrange.startOffset);
- unsigned ePos = clampedOffset(subrange.endOffset);
- TextRun run = constructTextRun(style);
- font.adjustSelectionRectForText(run, selectionRect, sPos, ePos);
-
- if (selectionRect.isEmpty())
- return;
-
- context.fillRect(snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), run.ltr()), color);
-}
-
void InlineTextBox::paintDocumentMarkers(GraphicsContext& context, const FloatPoint& boxOrigin, const RenderStyle& style, const FontCascade& font, bool background)
{
if (!renderer().textNode())
@@ -984,9 +975,9 @@
for (auto& subrange : subdivide(subranges, OverlapStrategy::Frontmost)) {
if (subrange.type == MarkerSubrange::TextMatch)
- paintTextMatchMarker(context, boxOrigin, subrange, style, font, subrange.marker->isActiveMatch());
+ paintTextMatchMarker(context, boxOrigin, style, font, subrange, subrange.marker->isActiveMatch());
else
- paintDocumentMarker(context, boxOrigin, subrange, style, font);
+ paintDocumentMarker(context, boxOrigin, style, font, subrange);
}
}
Modified: trunk/Source/WebCore/rendering/InlineTextBox.h (222506 => 222507)
--- trunk/Source/WebCore/rendering/InlineTextBox.h 2017-09-26 18:08:23 UTC (rev 222506)
+++ trunk/Source/WebCore/rendering/InlineTextBox.h 2017-09-26 18:12:50 UTC (rev 222507)
@@ -123,6 +123,8 @@
void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) override;
bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom, HitTestAction) override;
+ unsigned clampedOffset(unsigned) const;
+
private:
void deleteLine() final;
void extractLine() final;
@@ -152,19 +154,20 @@
virtual int offsetForPosition(float x, bool includePartialGlyphs = true) const;
virtual float positionForOffset(unsigned offset) const;
-protected:
- void paintCompositionBackground(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, unsigned startPos, unsigned endPos);
- void paintDocumentMarkers(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, bool background);
- void paintCompositionUnderline(GraphicsContext&, const FloatPoint& boxOrigin, const CompositionUnderline&);
- unsigned clampedOffset(unsigned) const;
-
private:
void paintDecoration(GraphicsContext&, const FontCascade&, RenderCombineText*, const TextRun&, const FloatPoint& textOrigin, const FloatRect& boxRect,
TextDecoration, TextPaintStyle, const ShadowData*, const FloatRect& clipOutRect);
- void paintSelection(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, const Color& textColor);
- void paintDocumentMarker(GraphicsContext&, const FloatPoint& boxOrigin, const MarkerSubrange&, const RenderStyle&, const FontCascade&);
- void paintTextMatchMarker(GraphicsContext&, const FloatPoint& boxOrigin, const MarkerSubrange&, const RenderStyle&, const FontCascade&, bool isActiveMatch);
+ void paintSelection(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, const Color&);
+ void paintDocumentMarker(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, const MarkerSubrange&);
+ void paintDocumentMarkers(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, bool background);
+ void paintTextMatchMarker(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, const MarkerSubrange&, bool isActiveMatch);
+
+ void paintCompositionBackground(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&);
+ void paintCompositionUnderline(GraphicsContext&, const FloatPoint& boxOrigin, const CompositionUnderline&);
+
+ void paintTextSubrangeBackground(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, const Color&, unsigned startOffset, unsigned endOffset);
+
ExpansionBehavior expansionBehavior() const;
void behavesLikeText() const = delete;