summaryrefslogtreecommitdiffstats
path: root/WebCore/rendering/InlineTextBox.cpp
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2010-11-04 12:00:17 -0700
committerJohn Reck <jreck@google.com>2010-11-09 11:35:04 -0800
commite14391e94c850b8bd03680c23b38978db68687a8 (patch)
tree3fed87e6620fecaf3edc7259ae58a11662bedcb2 /WebCore/rendering/InlineTextBox.cpp
parent1bd705833a68f07850cf7e204b26f8d328d16951 (diff)
downloadexternal_webkit-e14391e94c850b8bd03680c23b38978db68687a8.zip
external_webkit-e14391e94c850b8bd03680c23b38978db68687a8.tar.gz
external_webkit-e14391e94c850b8bd03680c23b38978db68687a8.tar.bz2
Merge Webkit at r70949: Initial merge by git.
Change-Id: I77b8645c083b5d0da8dba73ed01d4014aab9848e
Diffstat (limited to 'WebCore/rendering/InlineTextBox.cpp')
-rw-r--r--WebCore/rendering/InlineTextBox.cpp212
1 files changed, 125 insertions, 87 deletions
diff --git a/WebCore/rendering/InlineTextBox.cpp b/WebCore/rendering/InlineTextBox.cpp
index cf100e0..43b025a 100644
--- a/WebCore/rendering/InlineTextBox.cpp
+++ b/WebCore/rendering/InlineTextBox.cpp
@@ -154,12 +154,19 @@ IntRect InlineTextBox::selectionRect(int tx, int ty, int startPos, int endPos)
}
IntRect r = enclosingIntRect(f.selectionRectForText(TextRun(characters, len, textObj->allowTabs(), textPos(), m_toAdd, !isLeftToRightDirection(), m_dirOverride),
- IntPoint(tx + m_x, ty + selTop), selHeight, sPos, ePos));
- if (r.x() > tx + m_x + m_logicalWidth)
- r.setWidth(0);
- else if (r.right() - 1 > tx + m_x + m_logicalWidth)
- r.setWidth(tx + m_x + m_logicalWidth - r.x());
- return r;
+ IntPoint(), selHeight, sPos, ePos));
+
+ int logicalWidth = r.width();
+ if (r.x() > m_logicalWidth)
+ logicalWidth = 0;
+ else if (r.right() > m_logicalWidth)
+ logicalWidth = m_logicalWidth - r.x();
+
+ IntPoint topPoint = m_isVertical ? IntPoint(tx + selTop, ty + m_y + r.x()) : IntPoint(tx + m_x + r.x(), ty + selTop);
+ int width = m_isVertical ? selHeight : logicalWidth;
+ int height = m_isVertical ? logicalWidth : selHeight;
+
+ return IntRect(topPoint, IntSize(width, height));
}
void InlineTextBox::deleteLine(RenderArena* arena)
@@ -302,7 +309,7 @@ bool InlineTextBox::nodeAtPoint(const HitTestRequest&, HitTestResult& result, in
if (isLineBreak())
return false;
- IntRect rect(tx + m_x, ty + m_y, m_logicalWidth, logicalHeight());
+ IntRect rect(tx + m_x, ty + m_y, width(), height());
if (m_truncation != cFullTruncation && visibleToHitTesting() && rect.intersects(result.rectForPoint(x, y))) {
renderer()->updateHitTestResult(result, IntPoint(x - tx, y - ty));
if (!result.addNodeToRectBasedTestResult(renderer()->node(), x, y, rect))
@@ -311,13 +318,15 @@ bool InlineTextBox::nodeAtPoint(const HitTestRequest&, HitTestResult& result, in
return false;
}
-FloatSize InlineTextBox::applyShadowToGraphicsContext(GraphicsContext* context, const ShadowData* shadow, const FloatRect& textRect, bool stroked, bool opaque)
+FloatSize InlineTextBox::applyShadowToGraphicsContext(GraphicsContext* context, const ShadowData* shadow, const FloatRect& textRect, bool stroked, bool opaque, bool vertical)
{
if (!shadow)
return FloatSize();
FloatSize extraOffset;
- FloatSize shadowOffset(shadow->x(), shadow->y());
+ int shadowX = vertical ? shadow->y() : shadow->x();
+ int shadowY = vertical ? -shadow->x() : shadow->y();
+ FloatSize shadowOffset(shadowX, shadowY);
int shadowBlur = shadow->blur();
const Color& shadowColor = shadow->color();
@@ -336,7 +345,8 @@ FloatSize InlineTextBox::applyShadowToGraphicsContext(GraphicsContext* context,
return extraOffset;
}
-static void paintTextWithShadows(GraphicsContext* context, const Font& font, const TextRun& textRun, int startOffset, int endOffset, int truncationPoint, const IntPoint& textOrigin, int x, int y, int w, int h, const ShadowData* shadow, bool stroked)
+static void paintTextWithShadows(GraphicsContext* context, const Font& font, const TextRun& textRun, int startOffset, int endOffset, int truncationPoint, const IntPoint& textOrigin,
+ const IntRect& boxRect, const ShadowData* shadow, bool stroked, bool vertical)
{
Color fillColor = context->fillColor();
ColorSpace fillColorSpace = context->fillColorSpace();
@@ -347,7 +357,7 @@ static void paintTextWithShadows(GraphicsContext* context, const Font& font, con
do {
IntSize extraOffset;
if (shadow)
- extraOffset = roundedIntSize(InlineTextBox::applyShadowToGraphicsContext(context, shadow, FloatRect(x, y, w, h), stroked, opaque));
+ extraOffset = roundedIntSize(InlineTextBox::applyShadowToGraphicsContext(context, shadow, boxRect, stroked, opaque, vertical));
else if (!opaque)
context->setFillColor(fillColor, fillColorSpace);
@@ -375,18 +385,22 @@ static void paintTextWithShadows(GraphicsContext* context, const Font& font, con
void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
{
if (isLineBreak() || !paintInfo.shouldPaintWithinRoot(renderer()) || renderer()->style()->visibility() != VISIBLE ||
- m_truncation == cFullTruncation || paintInfo.phase == PaintPhaseOutline)
+ m_truncation == cFullTruncation || paintInfo.phase == PaintPhaseOutline || !m_len)
return;
ASSERT(paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintPhaseChildOutlines);
// FIXME: Technically we're potentially incorporating other visual overflow that had nothing to do with us.
// Would it be simpler to just check our own shadow and stroke overflow by hand here?
- int leftOverflow = parent()->x() - parent()->leftVisualOverflow();
- int rightOverflow = parent()->rightVisualOverflow() - (parent()->x() + parent()->logicalWidth());
- int xPos = tx + m_x - leftOverflow;
- int w = logicalWidth() + leftOverflow + rightOverflow;
- if (xPos >= paintInfo.rect.right() || xPos + w <= paintInfo.rect.x())
+ int logicalLeftOverflow = parent()->logicalLeft() - parent()->logicalLeftVisualOverflow();
+ int logicalRightOverflow = parent()->logicalRightVisualOverflow() - (parent()->logicalLeft() + parent()->logicalWidth());
+ int logicalStart = logicalLeft() - logicalLeftOverflow + (isVertical() ? ty : tx);
+ int logicalExtent = logicalWidth() + logicalLeftOverflow + logicalRightOverflow;
+
+ int paintEnd = isVertical() ? paintInfo.rect.bottom() : paintInfo.rect.right();
+ int paintStart = isVertical() ? paintInfo.rect.y() : paintInfo.rect.x();
+
+ if (logicalStart >= paintEnd || logicalStart + logicalExtent <= paintStart)
return;
bool isPrinting = textRenderer()->document()->printing();
@@ -410,18 +424,39 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
int widthOfVisibleText = toRenderText(renderer())->width(m_start, m_truncation, textPos(), m_firstLine);
int widthOfHiddenText = m_logicalWidth - widthOfVisibleText;
// FIXME: The hit testing logic also needs to take this translation int account.
- tx += isLeftToRightDirection() ? widthOfHiddenText : -widthOfHiddenText;
+ if (!m_isVertical)
+ tx += isLeftToRightDirection() ? widthOfHiddenText : -widthOfHiddenText;
+ else
+ ty += isLeftToRightDirection() ? widthOfHiddenText : -widthOfHiddenText;
}
}
GraphicsContext* context = paintInfo.context;
+ RenderStyle* styleToUse = renderer()->style(m_firstLine);
+
+ ty -= styleToUse->isHorizontalWritingMode() ? 0 : logicalHeight();
+
+ IntPoint boxOrigin(m_x, m_y);
+ adjustForFlippedBlocksWritingMode(boxOrigin);
+ boxOrigin.move(tx, ty);
+
+ IntPoint textOrigin = IntPoint(boxOrigin.x(), boxOrigin.y() + styleToUse->font().ascent());
+ IntRect boxRect(boxOrigin, IntSize(logicalWidth(), logicalHeight()));
+
+ if (m_isVertical) {
+ context->save();
+ context->translate(boxRect.x(), boxRect.bottom());
+ context->rotate(static_cast<float>(deg2rad(90.)));
+ context->translate(-boxRect.x(), -boxRect.bottom());
+ }
+
+
// Determine whether or not we have composition underlines to draw.
bool containsComposition = renderer()->node() && renderer()->frame()->editor()->compositionNode() == renderer()->node();
bool useCustomUnderlines = containsComposition && renderer()->frame()->editor()->compositionUsesCustomUnderlines();
// Set our font.
- RenderStyle* styleToUse = renderer()->style(m_firstLine);
int d = styleToUse->textDecorationsInEffect();
const Font& font = styleToUse->font();
@@ -435,20 +470,17 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
#endif
if (containsComposition && !useCustomUnderlines)
- paintCompositionBackground(context, tx, ty, styleToUse, font,
+ paintCompositionBackground(context, boxOrigin, styleToUse, font,
renderer()->frame()->editor()->compositionStart(),
renderer()->frame()->editor()->compositionEnd());
- paintDocumentMarkers(context, tx, ty, styleToUse, font, true);
+ paintDocumentMarkers(context, boxOrigin, styleToUse, font, true);
if (haveSelection && !useCustomUnderlines)
- paintSelection(context, tx, ty, styleToUse, font);
+ paintSelection(context, boxOrigin, styleToUse, font);
}
// 2. Now paint the foreground, including text and decorations like underline/overline (in quirks mode only).
- if (m_len <= 0)
- return;
-
Color textFillColor;
Color textStrokeColor;
float textStrokeWidth = styleToUse->textStrokeWidth();
@@ -517,8 +549,6 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
if (hasHyphen())
adjustCharactersAndLengthForHyphen(charactersWithHyphen, styleToUse, characters, length);
- int baseline = renderer()->style(m_firstLine)->font().ascent();
- IntPoint textOrigin(m_x + tx, m_y + ty + baseline);
TextRun textRun(characters, length, textRenderer()->allowTabs(), textPos(), m_toAdd, !isLeftToRightDirection(), m_dirOverride || styleToUse->visuallyOrdered());
int sPos = 0;
@@ -541,9 +571,9 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
updateGraphicsContext(context, textFillColor, textStrokeColor, textStrokeWidth, styleToUse->colorSpace());
if (!paintSelectedTextSeparately || ePos <= sPos) {
// FIXME: Truncate right-to-left text correctly.
- paintTextWithShadows(context, font, textRun, 0, length, length, textOrigin, m_x + tx, m_y + ty, logicalWidth(), logicalHeight(), textShadow, textStrokeWidth > 0);
+ paintTextWithShadows(context, font, textRun, 0, length, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, m_isVertical);
} else
- paintTextWithShadows(context, font, textRun, ePos, sPos, length, textOrigin, m_x + tx, m_y + ty, logicalWidth(), logicalHeight(), textShadow, textStrokeWidth > 0);
+ paintTextWithShadows(context, font, textRun, ePos, sPos, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, m_isVertical);
if (textStrokeWidth > 0)
context->restore();
@@ -555,20 +585,20 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
context->save();
updateGraphicsContext(context, selectionFillColor, selectionStrokeColor, selectionStrokeWidth, styleToUse->colorSpace());
- paintTextWithShadows(context, font, textRun, sPos, ePos, length, textOrigin, m_x + tx, m_y + ty, logicalWidth(), logicalHeight(), selectionShadow, selectionStrokeWidth > 0);
+ paintTextWithShadows(context, font, textRun, sPos, ePos, length, textOrigin, boxRect, selectionShadow, selectionStrokeWidth > 0, m_isVertical);
if (selectionStrokeWidth > 0)
context->restore();
}
// Paint decorations
- if (d != TDNONE && paintInfo.phase != PaintPhaseSelection && renderer()->document()->inQuirksMode()) {
- context->setStrokeColor(styleToUse->visitedDependentColor(CSSPropertyColor), styleToUse->colorSpace());
- paintDecoration(context, tx, ty, d, textShadow);
+ if (d != TDNONE && paintInfo.phase != PaintPhaseSelection) {
+ updateGraphicsContext(context, textFillColor, textStrokeColor, textStrokeWidth, styleToUse->colorSpace());
+ paintDecoration(context, boxOrigin, d, textShadow);
}
if (paintInfo.phase == PaintPhaseForeground) {
- paintDocumentMarkers(context, tx, ty, styleToUse, font, false);
+ paintDocumentMarkers(context, boxOrigin, styleToUse, font, false);
if (useCustomUnderlines) {
const Vector<CompositionUnderline>& underlines = renderer()->frame()->editor()->customCompositionUnderlines();
@@ -585,7 +615,7 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
if (underline.startOffset <= end()) {
// underline intersects this run. Paint it.
- paintCompositionUnderline(context, tx, ty, underline);
+ paintCompositionUnderline(context, boxOrigin, underline);
if (underline.endOffset > end() + 1)
// underline also runs into the next run. Bail now, no more marker advancement.
break;
@@ -595,6 +625,9 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
}
}
}
+
+ if (m_isVertical)
+ context->restore();
}
void InlineTextBox::selectionStartEnd(int& sPos, int& ePos)
@@ -615,7 +648,7 @@ void InlineTextBox::selectionStartEnd(int& sPos, int& ePos)
ePos = min(endPos - m_start, (int)m_len);
}
-void InlineTextBox::paintSelection(GraphicsContext* context, int tx, int ty, RenderStyle* style, const Font& font)
+void InlineTextBox::paintSelection(GraphicsContext* context, const IntPoint& boxOrigin, RenderStyle* style, const Font& font)
{
// See if we have a selection to paint at all.
int sPos, ePos;
@@ -635,8 +668,7 @@ void InlineTextBox::paintSelection(GraphicsContext* context, int tx, int ty, Ren
context->save();
updateGraphicsContext(context, c, c, 0, style->colorSpace()); // Don't draw text at all!
- int y = selectionTop();
- int h = selectionHeight();
+
// If the text is truncated, let the thing being painted in the truncation
// draw its own highlight.
int length = m_truncation != cNoTruncation ? m_truncation : m_len;
@@ -648,14 +680,17 @@ void InlineTextBox::paintSelection(GraphicsContext* context, int tx, int ty, Ren
ePos = length;
}
- context->clip(IntRect(m_x + tx, y + ty, m_logicalWidth, h));
+ int deltaY = logicalTop() - selectionTop();
+ int selHeight = selectionHeight();
+ IntPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
+ context->clip(IntRect(localOrigin, IntSize(m_logicalWidth, selHeight)));
context->drawHighlightForText(font, TextRun(characters, length, textRenderer()->allowTabs(), textPos(), m_toAdd,
!isLeftToRightDirection(), m_dirOverride || style->visuallyOrdered()),
- IntPoint(m_x + tx, y + ty), h, c, style->colorSpace(), sPos, ePos);
+ localOrigin, selHeight, c, style->colorSpace(), sPos, ePos);
context->restore();
}
-void InlineTextBox::paintCompositionBackground(GraphicsContext* context, int tx, int ty, RenderStyle* style, const Font& font, int startPos, int endPos)
+void InlineTextBox::paintCompositionBackground(GraphicsContext* context, const IntPoint& boxOrigin, RenderStyle* style, const Font& font, int startPos, int endPos)
{
int offset = m_start;
int sPos = max(startPos - offset, 0);
@@ -670,11 +705,12 @@ void InlineTextBox::paintCompositionBackground(GraphicsContext* context, int tx,
updateGraphicsContext(context, c, c, 0, style->colorSpace()); // Don't draw text at all!
- int y = selectionTop();
- int h = selectionHeight();
+ int deltaY = logicalTop() - selectionTop();
+ int selHeight = selectionHeight();
+ IntPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
context->drawHighlightForText(font, TextRun(textRenderer()->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_toAdd,
!isLeftToRightDirection(), m_dirOverride || style->visuallyOrdered()),
- IntPoint(m_x + tx, y + ty), h, c, style->colorSpace(), sPos, ePos);
+ localOrigin, selHeight, c, style->colorSpace(), sPos, ePos);
context->restore();
}
@@ -698,19 +734,18 @@ void InlineTextBox::paintCustomHighlight(int tx, int ty, const AtomicString& typ
#endif
-void InlineTextBox::paintDecoration(GraphicsContext* context, int tx, int ty, int deco, const ShadowData* shadow)
+void InlineTextBox::paintDecoration(GraphicsContext* context, const IntPoint& boxOrigin, int deco, const ShadowData* shadow)
{
- tx += m_x;
- ty += m_y;
-
if (m_truncation == cFullTruncation)
return;
+ IntPoint localOrigin = boxOrigin;
+
int width = m_logicalWidth;
if (m_truncation != cNoTruncation) {
width = toRenderText(renderer())->width(m_start, m_truncation, textPos(), m_firstLine);
if (!isLeftToRightDirection())
- tx += (m_logicalWidth - width);
+ localOrigin.move(m_logicalWidth - width, 0);
}
// Get the text decoration colors.
@@ -723,24 +758,27 @@ void InlineTextBox::paintDecoration(GraphicsContext* context, int tx, int ty, in
bool linesAreOpaque = !isPrinting && (!(deco & UNDERLINE) || underline.alpha() == 255) && (!(deco & OVERLINE) || overline.alpha() == 255) && (!(deco & LINE_THROUGH) || linethrough.alpha() == 255);
- int baseline = renderer()->style(m_firstLine)->font().ascent();
+ RenderStyle* styleToUse = renderer()->style(m_firstLine);
+ int baseline = styleToUse->font().ascent();
bool setClip = false;
int extraOffset = 0;
if (!linesAreOpaque && shadow && shadow->next()) {
context->save();
- IntRect clipRect(tx, ty, width, baseline + 2);
+ IntRect clipRect(localOrigin, IntSize(width, baseline + 2));
for (const ShadowData* s = shadow; s; s = s->next()) {
- IntRect shadowRect(tx, ty, width, baseline + 2);
+ IntRect shadowRect(localOrigin, IntSize(width, baseline + 2));
shadowRect.inflate(s->blur());
- shadowRect.move(s->x(), s->y());
+ int shadowX = m_isVertical ? s->y() : s->x();
+ int shadowY = m_isVertical ? -s->x() : s->y();
+ shadowRect.move(shadowX, shadowY);
clipRect.unite(shadowRect);
- extraOffset = max(extraOffset, max(0, s->y()) + s->blur());
+ extraOffset = max(extraOffset, max(0, shadowY) + s->blur());
}
context->save();
context->clip(clipRect);
extraOffset += baseline + 2;
- ty += extraOffset;
+ localOrigin.move(0, extraOffset);
setClip = true;
}
@@ -751,10 +789,12 @@ void InlineTextBox::paintDecoration(GraphicsContext* context, int tx, int ty, in
if (shadow) {
if (!shadow->next()) {
// The last set of lines paints normally inside the clip.
- ty -= extraOffset;
+ localOrigin.move(0, -extraOffset);
extraOffset = 0;
}
- context->setShadow(IntSize(shadow->x(), shadow->y() - extraOffset), shadow->blur(), shadow->color(), colorSpace);
+ int shadowX = m_isVertical ? shadow->y() : shadow->x();
+ int shadowY = m_isVertical ? -shadow->x() : shadow->y();
+ context->setShadow(IntSize(shadowX, shadowY - extraOffset), shadow->blur(), shadow->color(), colorSpace);
setShadow = true;
shadow = shadow->next();
}
@@ -763,17 +803,17 @@ void InlineTextBox::paintDecoration(GraphicsContext* context, int tx, int ty, in
context->setStrokeColor(underline, colorSpace);
context->setStrokeStyle(SolidStroke);
// Leave one pixel of white between the baseline and the underline.
- context->drawLineForText(IntPoint(tx, ty + baseline + 1), width, isPrinting);
+ context->drawLineForText(IntPoint(localOrigin.x(), localOrigin.y() + baseline + 1), width, isPrinting);
}
if (deco & OVERLINE) {
context->setStrokeColor(overline, colorSpace);
context->setStrokeStyle(SolidStroke);
- context->drawLineForText(IntPoint(tx, ty), width, isPrinting);
+ context->drawLineForText(localOrigin, width, isPrinting);
}
if (deco & LINE_THROUGH) {
context->setStrokeColor(linethrough, colorSpace);
context->setStrokeStyle(SolidStroke);
- context->drawLineForText(IntPoint(tx, ty + 2 * baseline / 3), width, isPrinting);
+ context->drawLineForText(IntPoint(localOrigin.x(), localOrigin.y() + 2 * baseline / 3), width, isPrinting);
}
} while (shadow);
@@ -798,7 +838,7 @@ static GraphicsContext::TextCheckingLineStyle textCheckingLineStyleForMarkerType
}
}
-void InlineTextBox::paintSpellingOrGrammarMarker(GraphicsContext* pt, int tx, int ty, const DocumentMarker& marker, RenderStyle* style, const Font& font, bool grammar)
+void InlineTextBox::paintSpellingOrGrammarMarker(GraphicsContext* pt, const IntPoint& boxOrigin, const DocumentMarker& marker, RenderStyle* style, const Font& font, bool grammar)
{
// Never print spelling/grammar markers (5327887)
if (textRenderer()->document()->printing())
@@ -827,18 +867,19 @@ void InlineTextBox::paintSpellingOrGrammarMarker(GraphicsContext* pt, int tx, in
endPosition = min<int>(endPosition, m_truncation);
// Calculate start & width
- IntPoint startPoint(tx + m_x, ty + selectionTop());
+ int deltaY = logicalTop() - selectionTop();
+ int selHeight = selectionHeight();
+ IntPoint startPoint(boxOrigin.x(), boxOrigin.y() - deltaY);
TextRun run(textRenderer()->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_toAdd, !isLeftToRightDirection(), m_dirOverride || style->visuallyOrdered());
- int h = selectionHeight();
-
- IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, startPoint, h, startPosition, endPosition));
+
+ IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, startPoint, selHeight, startPosition, endPosition));
start = markerRect.x() - startPoint.x();
width = markerRect.width();
// Store rendered rects for bad grammar markers, so we can hit-test against it elsewhere in order to
// display a toolTip. We don't do this for misspelling markers.
if (grammar) {
- markerRect.move(-tx, -ty);
+ markerRect.move(-boxOrigin.x(), -boxOrigin.y());
markerRect = renderer()->localToAbsoluteQuad(FloatRect(markerRect)).enclosingBoundingBox();
renderer()->document()->markers()->setRenderedRectForMarker(renderer()->node(), marker, markerRect);
}
@@ -861,25 +902,25 @@ void InlineTextBox::paintSpellingOrGrammarMarker(GraphicsContext* pt, int tx, in
// In larger fonts, though, place the underline up near the baseline to prevent a big gap.
underlineOffset = baseline + 2;
}
- pt->drawLineForTextChecking(IntPoint(tx + m_x + start, ty + m_y + underlineOffset), width, textCheckingLineStyleForMarkerType(marker.type));
+ pt->drawLineForTextChecking(IntPoint(boxOrigin.x() + start, boxOrigin.y() + underlineOffset), width, textCheckingLineStyleForMarkerType(marker.type));
}
-void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, int tx, int ty, const DocumentMarker& marker, RenderStyle* style, const Font& font)
+void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const IntPoint& boxOrigin, const DocumentMarker& marker, RenderStyle* style, const Font& font)
{
// 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 y = selectionTop();
- int h = selectionHeight();
-
+ int deltaY = logicalTop() - selectionTop();
+ int selHeight = selectionHeight();
+
int sPos = max(marker.startOffset - m_start, (unsigned)0);
int ePos = min(marker.endOffset - m_start, (unsigned)m_len);
TextRun run(textRenderer()->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_toAdd, !isLeftToRightDirection(), m_dirOverride || style->visuallyOrdered());
// Always compute and store the rect associated with this marker. The computed rect is in absolute coordinates.
- IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoint(m_x, y), h, sPos, ePos));
+ IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoint(m_x, selectionTop()), selHeight, sPos, ePos));
markerRect = renderer()->localToAbsoluteQuad(FloatRect(markerRect)).enclosingBoundingBox();
renderer()->document()->markers()->setRenderedRectForMarker(renderer()->node(), marker, markerRect);
-
+
// Optionally highlight the text
if (renderer()->frame()->editor()->markedTextMatchesAreHighlighted()) {
Color color = marker.activeMatch ?
@@ -887,13 +928,13 @@ void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, int tx, int ty, co
renderer()->theme()->platformInactiveTextSearchHighlightColor();
pt->save();
updateGraphicsContext(pt, color, color, 0, style->colorSpace()); // Don't draw text at all!
- pt->clip(IntRect(tx + m_x, ty + y, m_logicalWidth, h));
- pt->drawHighlightForText(font, run, IntPoint(m_x + tx, y + ty), h, color, style->colorSpace(), sPos, ePos);
+ pt->clip(IntRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_logicalWidth, selHeight));
+ pt->drawHighlightForText(font, run, IntPoint(boxOrigin.x(), boxOrigin.y() - deltaY), selHeight, color, style->colorSpace(), sPos, ePos);
pt->restore();
}
}
-void InlineTextBox::computeRectForReplacementMarker(int /*tx*/, int /*ty*/, const DocumentMarker& marker, RenderStyle* style, const Font& font)
+void InlineTextBox::computeRectForReplacementMarker(const DocumentMarker& marker, RenderStyle* style, const Font& font)
{
// Replacement markers are not actually drawn, but their rects need to be computed for hit testing.
int y = selectionTop();
@@ -910,7 +951,7 @@ void InlineTextBox::computeRectForReplacementMarker(int /*tx*/, int /*ty*/, cons
renderer()->document()->markers()->setRenderedRectForMarker(renderer()->node(), marker, markerRect);
}
-void InlineTextBox::paintDocumentMarkers(GraphicsContext* pt, int tx, int ty, RenderStyle* style, const Font& font, bool background)
+void InlineTextBox::paintDocumentMarkers(GraphicsContext* pt, const IntPoint& boxOrigin, RenderStyle* style, const Font& font, bool background)
{
if (!renderer()->node())
return;
@@ -954,17 +995,17 @@ void InlineTextBox::paintDocumentMarkers(GraphicsContext* pt, int tx, int ty, Re
// marker intersects this run. Paint it.
switch (marker.type) {
case DocumentMarker::Spelling:
- paintSpellingOrGrammarMarker(pt, tx, ty, marker, style, font, false);
+ paintSpellingOrGrammarMarker(pt, boxOrigin, marker, style, font, false);
break;
case DocumentMarker::Grammar:
- paintSpellingOrGrammarMarker(pt, tx, ty, marker, style, font, true);
+ paintSpellingOrGrammarMarker(pt, boxOrigin, marker, style, font, true);
break;
case DocumentMarker::TextMatch:
- paintTextMatchMarker(pt, tx, ty, marker, style, font);
+ paintTextMatchMarker(pt, boxOrigin, marker, style, font);
break;
case DocumentMarker::CorrectionIndicator:
- computeRectForReplacementMarker(tx, ty, marker, style, font);
- paintSpellingOrGrammarMarker(pt, tx, ty, marker, style, font, false);
+ computeRectForReplacementMarker(marker, style, font);
+ paintSpellingOrGrammarMarker(pt, boxOrigin, marker, style, font, false);
break;
case DocumentMarker::Replacement:
case DocumentMarker::RejectedCorrection:
@@ -977,11 +1018,8 @@ void InlineTextBox::paintDocumentMarkers(GraphicsContext* pt, int tx, int ty, Re
}
-void InlineTextBox::paintCompositionUnderline(GraphicsContext* ctx, int tx, int ty, const CompositionUnderline& underline)
+void InlineTextBox::paintCompositionUnderline(GraphicsContext* ctx, const IntPoint& boxOrigin, const CompositionUnderline& underline)
{
- tx += m_x;
- ty += m_y;
-
if (m_truncation == cFullTruncation)
return;
@@ -1022,7 +1060,7 @@ void InlineTextBox::paintCompositionUnderline(GraphicsContext* ctx, int tx, int
ctx->setStrokeColor(underline.color, renderer()->style()->colorSpace());
ctx->setStrokeThickness(lineThickness);
- ctx->drawLineForText(IntPoint(tx + start, ty + logicalHeight() - lineThickness), width, textRenderer()->document()->printing());
+ ctx->drawLineForText(IntPoint(boxOrigin.x() + start, boxOrigin.y() + logicalHeight() - lineThickness), width, textRenderer()->document()->printing());
}
int InlineTextBox::caretMinOffset() const