summaryrefslogtreecommitdiffstats
path: root/WebCore/rendering/InlineTextBox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/rendering/InlineTextBox.cpp')
-rw-r--r--WebCore/rendering/InlineTextBox.cpp87
1 files changed, 46 insertions, 41 deletions
diff --git a/WebCore/rendering/InlineTextBox.cpp b/WebCore/rendering/InlineTextBox.cpp
index 43b025a..9c96cc6 100644
--- a/WebCore/rendering/InlineTextBox.cpp
+++ b/WebCore/rendering/InlineTextBox.cpp
@@ -64,6 +64,11 @@ int InlineTextBox::selectionTop()
return root()->selectionTop();
}
+int InlineTextBox::selectionBottom()
+{
+ return root()->selectionBottom();
+}
+
int InlineTextBox::selectionHeight()
{
return root()->selectionHeight();
@@ -162,11 +167,13 @@ IntRect InlineTextBox::selectionRect(int tx, int ty, int startPos, int endPos)
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;
+ IntPoint topPoint = isHorizontal() ? IntPoint(tx + m_x + r.x(), ty + selTop) : IntPoint(tx + selTop, ty + m_y + r.x());
+ int width = isHorizontal() ? logicalWidth : selHeight;
+ int height = isHorizontal() ? selHeight : logicalWidth;
- return IntRect(topPoint, IntSize(width, height));
+ IntRect result = IntRect(topPoint, IntSize(width, height));
+ flipForWritingMode(result);
+ return result;
}
void InlineTextBox::deleteLine(RenderArena* arena)
@@ -309,23 +316,25 @@ bool InlineTextBox::nodeAtPoint(const HitTestRequest&, HitTestResult& result, in
if (isLineBreak())
return false;
- IntRect rect(tx + m_x, ty + m_y, width(), height());
+ IntPoint boxOrigin = locationIncludingFlipping();
+ boxOrigin.move(tx, ty);
+ IntRect rect(boxOrigin, IntSize(width(), height()));
if (m_truncation != cFullTruncation && visibleToHitTesting() && rect.intersects(result.rectForPoint(x, y))) {
- renderer()->updateHitTestResult(result, IntPoint(x - tx, y - ty));
+ renderer()->updateHitTestResult(result, flipForWritingMode(IntPoint(x - tx, y - ty)));
if (!result.addNodeToRectBasedTestResult(renderer()->node(), x, y, rect))
return true;
}
return false;
}
-FloatSize InlineTextBox::applyShadowToGraphicsContext(GraphicsContext* context, const ShadowData* shadow, const FloatRect& textRect, bool stroked, bool opaque, bool vertical)
+FloatSize InlineTextBox::applyShadowToGraphicsContext(GraphicsContext* context, const ShadowData* shadow, const FloatRect& textRect, bool stroked, bool opaque, bool horizontal)
{
if (!shadow)
return FloatSize();
FloatSize extraOffset;
- int shadowX = vertical ? shadow->y() : shadow->x();
- int shadowY = vertical ? -shadow->x() : shadow->y();
+ int shadowX = horizontal ? shadow->x() : shadow->y();
+ int shadowY = horizontal ? shadow->y() : -shadow->x();
FloatSize shadowOffset(shadowX, shadowY);
int shadowBlur = shadow->blur();
const Color& shadowColor = shadow->color();
@@ -346,7 +355,7 @@ FloatSize InlineTextBox::applyShadowToGraphicsContext(GraphicsContext* context,
}
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)
+ const IntRect& boxRect, const ShadowData* shadow, bool stroked, bool horizontal)
{
Color fillColor = context->fillColor();
ColorSpace fillColorSpace = context->fillColorSpace();
@@ -357,7 +366,7 @@ static void paintTextWithShadows(GraphicsContext* context, const Font& font, con
do {
IntSize extraOffset;
if (shadow)
- extraOffset = roundedIntSize(InlineTextBox::applyShadowToGraphicsContext(context, shadow, boxRect, stroked, opaque, vertical));
+ extraOffset = roundedIntSize(InlineTextBox::applyShadowToGraphicsContext(context, shadow, boxRect, stroked, opaque, horizontal));
else if (!opaque)
context->setFillColor(fillColor, fillColorSpace);
@@ -394,11 +403,11 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
// Would it be simpler to just check our own shadow and stroke overflow by hand here?
int logicalLeftOverflow = parent()->logicalLeft() - parent()->logicalLeftVisualOverflow();
int logicalRightOverflow = parent()->logicalRightVisualOverflow() - (parent()->logicalLeft() + parent()->logicalWidth());
- int logicalStart = logicalLeft() - logicalLeftOverflow + (isVertical() ? ty : tx);
+ int logicalStart = logicalLeft() - logicalLeftOverflow + (isHorizontal() ? tx : ty);
int logicalExtent = logicalWidth() + logicalLeftOverflow + logicalRightOverflow;
- int paintEnd = isVertical() ? paintInfo.rect.bottom() : paintInfo.rect.right();
- int paintStart = isVertical() ? paintInfo.rect.y() : paintInfo.rect.x();
+ int paintEnd = isHorizontal() ? paintInfo.rect.right() : paintInfo.rect.bottom();
+ int paintStart = isHorizontal() ? paintInfo.rect.x() : paintInfo.rect.y();
if (logicalStart >= paintEnd || logicalStart + logicalExtent <= paintStart)
return;
@@ -424,7 +433,7 @@ 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.
- if (!m_isVertical)
+ if (isHorizontal())
tx += isLeftToRightDirection() ? widthOfHiddenText : -widthOfHiddenText;
else
ty += isLeftToRightDirection() ? widthOfHiddenText : -widthOfHiddenText;
@@ -437,14 +446,12 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
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());
+ IntPoint boxOrigin = locationIncludingFlipping();
+ boxOrigin.move(tx, ty);
IntRect boxRect(boxOrigin, IntSize(logicalWidth(), logicalHeight()));
+ IntPoint textOrigin = IntPoint(boxOrigin.x(), boxOrigin.y() + styleToUse->font().ascent());
- if (m_isVertical) {
+ if (!isHorizontal()) {
context->save();
context->translate(boxRect.x(), boxRect.bottom());
context->rotate(static_cast<float>(deg2rad(90.)));
@@ -571,9 +578,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, boxRect, textShadow, textStrokeWidth > 0, m_isVertical);
+ paintTextWithShadows(context, font, textRun, 0, length, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, isHorizontal());
} else
- paintTextWithShadows(context, font, textRun, ePos, sPos, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, m_isVertical);
+ paintTextWithShadows(context, font, textRun, ePos, sPos, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, isHorizontal());
if (textStrokeWidth > 0)
context->restore();
@@ -585,7 +592,7 @@ 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, boxRect, selectionShadow, selectionStrokeWidth > 0, m_isVertical);
+ paintTextWithShadows(context, font, textRun, sPos, ePos, length, textOrigin, boxRect, selectionShadow, selectionStrokeWidth > 0, isHorizontal());
if (selectionStrokeWidth > 0)
context->restore();
@@ -626,7 +633,7 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
}
}
- if (m_isVertical)
+ if (!isHorizontal())
context->restore();
}
@@ -680,7 +687,7 @@ void InlineTextBox::paintSelection(GraphicsContext* context, const IntPoint& box
ePos = length;
}
- int deltaY = logicalTop() - selectionTop();
+ int deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
int selHeight = selectionHeight();
IntPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
context->clip(IntRect(localOrigin, IntSize(m_logicalWidth, selHeight)));
@@ -705,7 +712,7 @@ void InlineTextBox::paintCompositionBackground(GraphicsContext* context, const I
updateGraphicsContext(context, c, c, 0, style->colorSpace()); // Don't draw text at all!
- int deltaY = logicalTop() - selectionTop();
+ int deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : 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,
@@ -769,8 +776,8 @@ void InlineTextBox::paintDecoration(GraphicsContext* context, const IntPoint& bo
for (const ShadowData* s = shadow; s; s = s->next()) {
IntRect shadowRect(localOrigin, IntSize(width, baseline + 2));
shadowRect.inflate(s->blur());
- int shadowX = m_isVertical ? s->y() : s->x();
- int shadowY = m_isVertical ? -s->x() : s->y();
+ int shadowX = isHorizontal() ? s->x() : s->y();
+ int shadowY = isHorizontal() ? s->y() : -s->x();
shadowRect.move(shadowX, shadowY);
clipRect.unite(shadowRect);
extraOffset = max(extraOffset, max(0, shadowY) + s->blur());
@@ -792,8 +799,8 @@ void InlineTextBox::paintDecoration(GraphicsContext* context, const IntPoint& bo
localOrigin.move(0, -extraOffset);
extraOffset = 0;
}
- int shadowX = m_isVertical ? shadow->y() : shadow->x();
- int shadowY = m_isVertical ? -shadow->x() : shadow->y();
+ int shadowX = isHorizontal() ? shadow->x() : shadow->y();
+ int shadowY = isHorizontal() ? shadow->y() : -shadow->x();
context->setShadow(IntSize(shadowX, shadowY - extraOffset), shadow->blur(), shadow->color(), colorSpace);
setShadow = true;
shadow = shadow->next();
@@ -867,7 +874,7 @@ void InlineTextBox::paintSpellingOrGrammarMarker(GraphicsContext* pt, const IntP
endPosition = min<int>(endPosition, m_truncation);
// Calculate start & width
- int deltaY = logicalTop() - selectionTop();
+ int deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : 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());
@@ -909,7 +916,7 @@ void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const IntPoint& bo
{
// 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 = logicalTop() - selectionTop();
+ int deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
int selHeight = selectionHeight();
int sPos = max(marker.startOffset - m_start, (unsigned)0);
@@ -1080,15 +1087,13 @@ unsigned InlineTextBox::caretMaxRenderedOffset() const
int InlineTextBox::textPos() const
{
- if (x() == 0)
+ if (logicalLeft() == 0)
return 0;
-
RenderBlock* blockElement = renderer()->containingBlock();
- return !isLeftToRightDirection() ? x() - blockElement->borderRight() - blockElement->paddingRight()
- : x() - blockElement->borderLeft() - blockElement->paddingLeft();
+ return logicalLeft() - blockElement->borderStart() - blockElement->paddingStart();
}
-int InlineTextBox::offsetForPosition(int _x, bool includePartialGlyphs) const
+int InlineTextBox::offsetForPosition(int lineOffset, bool includePartialGlyphs) const
{
if (isLineBreak())
return 0;
@@ -1097,7 +1102,7 @@ int InlineTextBox::offsetForPosition(int _x, bool includePartialGlyphs) const
RenderStyle* style = text->style(m_firstLine);
const Font* f = &style->font();
return f->offsetForPosition(TextRun(textRenderer()->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_toAdd, !isLeftToRightDirection(), m_dirOverride || style->visuallyOrdered()),
- _x - m_x, includePartialGlyphs);
+ lineOffset - logicalLeft(), includePartialGlyphs);
}
int InlineTextBox::positionForOffset(int offset) const
@@ -1106,7 +1111,7 @@ int InlineTextBox::positionForOffset(int offset) const
ASSERT(offset <= m_start + m_len);
if (isLineBreak())
- return m_x;
+ return logicalLeft();
RenderText* text = toRenderText(renderer());
const Font& f = text->style(m_firstLine)->font();
@@ -1114,7 +1119,7 @@ int InlineTextBox::positionForOffset(int offset) const
int to = !isLeftToRightDirection() ? m_len : offset - m_start;
// FIXME: Do we need to add rightBearing here?
return enclosingIntRect(f.selectionRectForText(TextRun(text->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_toAdd, !isLeftToRightDirection(), m_dirOverride),
- IntPoint(m_x, 0), 0, from, to)).right();
+ IntPoint(logicalLeft(), 0), 0, from, to)).right();
}
bool InlineTextBox::containsCaretOffset(int offset) const