| Index: Source/core/rendering/InlineTextBox.cpp
|
| diff --git a/Source/core/rendering/InlineTextBox.cpp b/Source/core/rendering/InlineTextBox.cpp
|
| index 24b24c55749c3ca464c6740252b51483da5dfaaf..819ad9d32570409f59b7b74d13d6ffb88dbc4fae 100644
|
| --- a/Source/core/rendering/InlineTextBox.cpp
|
| +++ b/Source/core/rendering/InlineTextBox.cpp
|
| @@ -33,7 +33,7 @@
|
| #include "core/editing/InputMethodController.h"
|
| #include "core/frame/LocalFrame.h"
|
| #include "core/page/Page.h"
|
| -#include "core/paint/BoxPainter.h"
|
| +#include "core/paint/InlineTextBoxPainter.h"
|
| #include "core/rendering/AbstractInlineTextBox.h"
|
| #include "core/rendering/EllipsisBox.h"
|
| #include "core/rendering/HitTestResult.h"
|
| @@ -71,10 +71,6 @@ COMPILE_ASSERT(sizeof(InlineTextBox) == sizeof(SameSizeAsInlineTextBox), InlineT
|
| typedef WTF::HashMap<const InlineTextBox*, LayoutRect> InlineTextBoxOverflowMap;
|
| static InlineTextBoxOverflowMap* gTextBoxesWithOverflow;
|
|
|
| -typedef WTF::HashMap<const InlineTextBox*, TextBlobPtr> InlineTextBoxBlobCacheMap;
|
| -static InlineTextBoxBlobCacheMap* gTextBlobCache;
|
| -
|
| -static const int misspellingLineThickness = 3;
|
|
|
| void InlineTextBox::destroy()
|
| {
|
| @@ -82,16 +78,14 @@ void InlineTextBox::destroy()
|
|
|
| if (!knownToHaveNoOverflow() && gTextBoxesWithOverflow)
|
| gTextBoxesWithOverflow->remove(this);
|
| - if (gTextBlobCache)
|
| - gTextBlobCache->remove(this);
|
| + InlineTextBoxPainter::removeFromTextBlobCache(*this);
|
| InlineBox::destroy();
|
| }
|
|
|
| void InlineTextBox::markDirty()
|
| {
|
| // FIXME: Is it actually possible to try and paint a dirty InlineTextBox?
|
| - if (gTextBlobCache)
|
| - gTextBlobCache->remove(this);
|
| + InlineTextBoxPainter::removeFromTextBlobCache(*this);
|
|
|
| m_len = 0;
|
| m_start = 0;
|
| @@ -133,21 +127,6 @@ LayoutUnit InlineTextBox::lineHeight() const
|
| return toRenderBoxModelObject(renderer().parent())->lineHeight(isFirstLineStyle(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine);
|
| }
|
|
|
| -LayoutUnit InlineTextBox::selectionTop()
|
| -{
|
| - return root().selectionTop();
|
| -}
|
| -
|
| -LayoutUnit InlineTextBox::selectionBottom()
|
| -{
|
| - return root().selectionBottom();
|
| -}
|
| -
|
| -LayoutUnit InlineTextBox::selectionHeight()
|
| -{
|
| - return root().selectionHeight();
|
| -}
|
| -
|
| bool InlineTextBox::isSelected(int startPos, int endPos) const
|
| {
|
| int sPos = std::max(startPos - m_start, 0);
|
| @@ -213,8 +192,8 @@ LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos)
|
|
|
| FontCachePurgePreventer fontCachePurgePreventer;
|
|
|
| - LayoutUnit selTop = selectionTop();
|
| - LayoutUnit selHeight = selectionHeight();
|
| + LayoutUnit selTop = root().selectionTop();
|
| + LayoutUnit selHeight = root().selectionHeight();
|
| RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
|
| const Font& font = styleToUse->font();
|
|
|
| @@ -378,199 +357,7 @@ bool InlineTextBox::getEmphasisMarkPosition(RenderStyle* style, TextEmphasisPosi
|
|
|
| void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit /*lineTop*/, LayoutUnit /*lineBottom*/)
|
| {
|
| - if (isLineBreak() || !paintInfo.shouldPaintWithinRoot(&renderer()) || renderer().style()->visibility() != VISIBLE
|
| - || m_truncation == cFullTruncation || paintInfo.phase == PaintPhaseOutline || !m_len)
|
| - return;
|
| -
|
| - ASSERT(paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintPhaseChildOutlines);
|
| -
|
| - LayoutRect logicalVisualOverflow = logicalOverflowRect();
|
| - LayoutUnit logicalStart = logicalVisualOverflow.x() + (isHorizontal() ? paintOffset.x() : paintOffset.y());
|
| - LayoutUnit logicalExtent = logicalVisualOverflow.width();
|
| -
|
| - LayoutUnit paintEnd = isHorizontal() ? paintInfo.rect.maxX() : paintInfo.rect.maxY();
|
| - LayoutUnit paintStart = isHorizontal() ? paintInfo.rect.x() : paintInfo.rect.y();
|
| -
|
| - // When subpixel font scaling is enabled text runs are positioned at
|
| - // subpixel boundaries on the x-axis and thus there is no reason to
|
| - // snap the x value. We still round the y-axis to ensure consistent
|
| - // line heights.
|
| - LayoutPoint adjustedPaintOffset = RuntimeEnabledFeatures::subpixelFontScalingEnabled()
|
| - ? LayoutPoint(paintOffset.x(), paintOffset.y().round())
|
| - : roundedIntPoint(paintOffset);
|
| -
|
| - if (logicalStart >= paintEnd || logicalStart + logicalExtent <= paintStart)
|
| - return;
|
| -
|
| - bool isPrinting = renderer().document().printing();
|
| -
|
| - // Determine whether or not we're selected.
|
| - bool haveSelection = !isPrinting && paintInfo.phase != PaintPhaseTextClip && selectionState() != RenderObject::SelectionNone;
|
| - if (!haveSelection && paintInfo.phase == PaintPhaseSelection)
|
| - // When only painting the selection, don't bother to paint if there is none.
|
| - return;
|
| -
|
| - if (m_truncation != cNoTruncation) {
|
| - if (renderer().containingBlock()->style()->isLeftToRightDirection() != isLeftToRightDirection()) {
|
| - // Make the visible fragment of text hug the edge closest to the rest of the run by moving the origin
|
| - // at which we start drawing text.
|
| - // e.g. In the case of LTR text truncated in an RTL Context, the correct behavior is:
|
| - // |Hello|CBA| -> |...He|CBA|
|
| - // In order to draw the fragment "He" aligned to the right edge of it's box, we need to start drawing
|
| - // farther to the right.
|
| - // NOTE: WebKit's behavior differs from that of IE which appears to just overlay the ellipsis on top of the
|
| - // truncated string i.e. |Hello|CBA| -> |...lo|CBA|
|
| - LayoutUnit widthOfVisibleText = renderer().width(m_start, m_truncation, textPos(), isLeftToRightDirection() ? LTR : RTL, isFirstLineStyle());
|
| - LayoutUnit widthOfHiddenText = m_logicalWidth - widthOfVisibleText;
|
| - // FIXME: The hit testing logic also needs to take this translation into account.
|
| - LayoutSize truncationOffset(isLeftToRightDirection() ? widthOfHiddenText : -widthOfHiddenText, 0);
|
| - adjustedPaintOffset.move(isHorizontal() ? truncationOffset : truncationOffset.transposedSize());
|
| - }
|
| - }
|
| -
|
| - GraphicsContext* context = paintInfo.context;
|
| - RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
|
| -
|
| - adjustedPaintOffset.move(0, styleToUse->isHorizontalWritingMode() ? 0 : -logicalHeight());
|
| -
|
| - FloatPoint boxOrigin = locationIncludingFlipping();
|
| - boxOrigin.move(adjustedPaintOffset.x().toFloat(), adjustedPaintOffset.y().toFloat());
|
| - FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), logicalHeight()));
|
| -
|
| - RenderCombineText* combinedText = styleToUse->hasTextCombine() && renderer().isCombineText() && toRenderCombineText(renderer()).isCombined() ? &toRenderCombineText(renderer()) : 0;
|
| -
|
| - bool shouldRotate = !isHorizontal() && !combinedText;
|
| - if (shouldRotate)
|
| - context->concatCTM(rotation(boxRect, Clockwise));
|
| -
|
| - // Determine whether or not we have composition underlines to draw.
|
| - bool containsComposition = renderer().node() && renderer().frame()->inputMethodController().compositionNode() == renderer().node();
|
| - bool useCustomUnderlines = containsComposition && renderer().frame()->inputMethodController().compositionUsesCustomUnderlines();
|
| -
|
| - // Determine text colors.
|
| - TextPainter::Style textStyle = TextPainter::textPaintingStyle(renderer(), styleToUse, paintInfo.forceBlackText(), isPrinting);
|
| - TextPainter::Style selectionStyle = TextPainter::selectionPaintingStyle(renderer(), haveSelection, paintInfo.forceBlackText(), isPrinting, textStyle);
|
| - bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection);
|
| - bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != selectionStyle;
|
| -
|
| - // Set our font.
|
| - const Font& font = styleToUse->font();
|
| -
|
| - FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().ascent());
|
| - if (combinedText)
|
| - combinedText->adjustTextOrigin(textOrigin, boxRect);
|
| -
|
| - // 1. Paint backgrounds behind text if needed. Examples of such backgrounds include selection
|
| - // and composition highlights.
|
| - if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseTextClip && !isPrinting) {
|
| - if (containsComposition) {
|
| - paintCompositionBackgrounds(context, boxOrigin, styleToUse, font, useCustomUnderlines);
|
| - }
|
| -
|
| - paintDocumentMarkers(context, boxOrigin, styleToUse, font, true);
|
| -
|
| - if (haveSelection && !useCustomUnderlines)
|
| - paintSelection(context, boxOrigin, styleToUse, font, selectionStyle.fillColor);
|
| - }
|
| -
|
| - // 2. Now paint the foreground, including text and decorations like underline/overline (in quirks mode only).
|
| - int length = m_len;
|
| - int maximumLength;
|
| - StringView string;
|
| - if (!combinedText) {
|
| - string = renderer().text().createView();
|
| - if (static_cast<unsigned>(length) != string.length() || m_start)
|
| - string.narrow(m_start, length);
|
| - maximumLength = renderer().textLength() - m_start;
|
| - } else {
|
| - combinedText->getStringToRender(m_start, string, length);
|
| - maximumLength = length;
|
| - }
|
| -
|
| - StringBuilder charactersWithHyphen;
|
| - TextRun textRun = constructTextRun(styleToUse, font, string, maximumLength, hasHyphen() ? &charactersWithHyphen : 0);
|
| - if (hasHyphen())
|
| - length = textRun.length();
|
| -
|
| - int selectionStart = 0;
|
| - int selectionEnd = 0;
|
| - if (paintSelectedTextOnly || paintSelectedTextSeparately)
|
| - selectionStartEnd(selectionStart, selectionEnd);
|
| -
|
| - bool respectHyphen = selectionEnd == m_len && hasHyphen();
|
| - if (respectHyphen)
|
| - selectionEnd = textRun.length();
|
| -
|
| - if (m_truncation != cNoTruncation) {
|
| - selectionStart = std::min<int>(selectionStart, m_truncation);
|
| - selectionEnd = std::min<int>(selectionEnd, m_truncation);
|
| - length = m_truncation;
|
| - }
|
| -
|
| - TextPainter textPainter(context, font, textRun, textOrigin, boxRect, isHorizontal());
|
| - TextEmphasisPosition emphasisMarkPosition;
|
| - bool hasTextEmphasis = getEmphasisMarkPosition(styleToUse, emphasisMarkPosition);
|
| - if (hasTextEmphasis)
|
| - textPainter.setEmphasisMark(styleToUse->textEmphasisMarkString(), emphasisMarkPosition);
|
| - if (combinedText)
|
| - textPainter.setCombinedText(combinedText);
|
| -
|
| - if (!paintSelectedTextOnly) {
|
| - // FIXME: Truncate right-to-left text correctly.
|
| - int startOffset = 0;
|
| - int endOffset = length;
|
| - if (paintSelectedTextSeparately && selectionStart < selectionEnd) {
|
| - startOffset = selectionEnd;
|
| - endOffset = selectionStart;
|
| - }
|
| -
|
| - // FIXME: This cache should probably ultimately be held somewhere else.
|
| - // A hashmap is convenient to avoid a memory hit when the
|
| - // RuntimeEnabledFeature is off.
|
| - bool textBlobIsCacheable = RuntimeEnabledFeatures::textBlobEnabled() && startOffset == 0 && endOffset == length;
|
| - TextBlobPtr* cachedTextBlob = 0;
|
| - if (textBlobIsCacheable) {
|
| - if (!gTextBlobCache)
|
| - gTextBlobCache = new InlineTextBoxBlobCacheMap;
|
| - cachedTextBlob = &gTextBlobCache->add(this, nullptr).storedValue->value;
|
| - }
|
| - textPainter.paint(startOffset, endOffset, length, textStyle, cachedTextBlob);
|
| - }
|
| -
|
| - if ((paintSelectedTextOnly || paintSelectedTextSeparately) && selectionStart < selectionEnd) {
|
| - // paint only the text that is selected
|
| - textPainter.paint(selectionStart, selectionEnd, length, selectionStyle);
|
| - }
|
| -
|
| - // Paint decorations
|
| - TextDecoration textDecorations = styleToUse->textDecorationsInEffect();
|
| - if (textDecorations != TextDecorationNone && !paintSelectedTextOnly) {
|
| - GraphicsContextStateSaver stateSaver(*context, false);
|
| - TextPainter::updateGraphicsContext(context, textStyle, isHorizontal(), stateSaver);
|
| - if (combinedText)
|
| - context->concatCTM(rotation(boxRect, Clockwise));
|
| - paintDecoration(context, boxOrigin, textDecorations);
|
| - if (combinedText)
|
| - context->concatCTM(rotation(boxRect, Counterclockwise));
|
| - }
|
| -
|
| - if (paintInfo.phase == PaintPhaseForeground) {
|
| - paintDocumentMarkers(context, boxOrigin, styleToUse, font, false);
|
| -
|
| - // Paint custom underlines for compositions.
|
| - if (useCustomUnderlines) {
|
| - const Vector<CompositionUnderline>& underlines = renderer().frame()->inputMethodController().customCompositionUnderlines();
|
| - CompositionUnderlineRangeFilter filter(underlines, start(), end());
|
| - for (CompositionUnderlineRangeFilter::ConstIterator it = filter.begin(); it != filter.end(); ++it) {
|
| - if (it->color == Color::transparent)
|
| - continue;
|
| - paintCompositionUnderline(context, boxOrigin, *it);
|
| - }
|
| - }
|
| - }
|
| -
|
| - if (shouldRotate)
|
| - context->concatCTM(rotation(boxRect, Counterclockwise));
|
| + InlineTextBoxPainter(*this).paint(paintInfo, paintOffset);
|
| }
|
|
|
| void InlineTextBox::selectionStartEnd(int& sPos, int& ePos) const
|
| @@ -591,560 +378,14 @@ void InlineTextBox::selectionStartEnd(int& sPos, int& ePos) const
|
| ePos = std::min(endPos - m_start, (int)m_len);
|
| }
|
|
|
| -void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, Color textColor)
|
| -{
|
| - // See if we have a selection to paint at all.
|
| - int sPos, ePos;
|
| - selectionStartEnd(sPos, ePos);
|
| - if (sPos >= ePos)
|
| - return;
|
| -
|
| - Color c = renderer().selectionBackgroundColor();
|
| - if (!c.alpha())
|
| - return;
|
| -
|
| - // If the text color ends up being the same as the selection background, invert the selection
|
| - // background.
|
| - if (textColor == c)
|
| - c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
|
| -
|
| - // 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;
|
| - StringView string = renderer().text().createView();
|
| -
|
| - if (string.length() != static_cast<unsigned>(length) || m_start)
|
| - string.narrow(m_start, length);
|
| -
|
| - StringBuilder charactersWithHyphen;
|
| - bool respectHyphen = ePos == length && hasHyphen();
|
| - TextRun textRun = constructTextRun(style, font, string, renderer().textLength() - m_start, respectHyphen ? &charactersWithHyphen : 0);
|
| - if (respectHyphen)
|
| - ePos = textRun.length();
|
| -
|
| - LayoutUnit selectionBottom = root().selectionBottom();
|
| - LayoutUnit selectionTop = root().selectionTopAdjustedForPrecedingBlock();
|
| -
|
| - int deltaY = roundToInt(renderer().style()->isFlippedLinesWritingMode() ? selectionBottom - logicalBottom() : logicalTop() - selectionTop);
|
| - int selHeight = std::max(0, roundToInt(selectionBottom - selectionTop));
|
| -
|
| - FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
|
| - FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight));
|
| -
|
| - GraphicsContextStateSaver stateSaver(*context);
|
| - context->clip(clipRect);
|
| - context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, sPos, ePos);
|
| -}
|
| -
|
| -unsigned InlineTextBox::underlinePaintStart(const CompositionUnderline& underline)
|
| -{
|
| - return std::max(static_cast<unsigned>(m_start), underline.startOffset);
|
| -}
|
| -
|
| -unsigned InlineTextBox::underlinePaintEnd(const CompositionUnderline& underline)
|
| -{
|
| - unsigned paintEnd = std::min(end() + 1, underline.endOffset); // end() points at the last char, not past it.
|
| - if (m_truncation != cNoTruncation)
|
| - paintEnd = std::min(paintEnd, static_cast<unsigned>(m_start + m_truncation));
|
| - return paintEnd;
|
| -}
|
| -
|
| -void InlineTextBox::paintSingleCompositionBackgroundRun(GraphicsContext* context, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, Color backgroundColor, int startPos, int endPos)
|
| -{
|
| - int sPos = std::max(startPos - m_start, 0);
|
| - int ePos = std::min(endPos - m_start, static_cast<int>(m_len));
|
| - if (sPos >= ePos)
|
| - return;
|
| -
|
| - int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
|
| - int selHeight = selectionHeight();
|
| - FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
|
| - context->drawHighlightForText(font, constructTextRun(style, font), localOrigin, selHeight, backgroundColor, sPos, ePos);
|
| -}
|
| -
|
| -static StrokeStyle textDecorationStyleToStrokeStyle(TextDecorationStyle decorationStyle)
|
| -{
|
| - StrokeStyle strokeStyle = SolidStroke;
|
| - switch (decorationStyle) {
|
| - case TextDecorationStyleSolid:
|
| - strokeStyle = SolidStroke;
|
| - break;
|
| - case TextDecorationStyleDouble:
|
| - strokeStyle = DoubleStroke;
|
| - break;
|
| - case TextDecorationStyleDotted:
|
| - strokeStyle = DottedStroke;
|
| - break;
|
| - case TextDecorationStyleDashed:
|
| - strokeStyle = DashedStroke;
|
| - break;
|
| - case TextDecorationStyleWavy:
|
| - strokeStyle = WavyStroke;
|
| - break;
|
| - }
|
| -
|
| - return strokeStyle;
|
| -}
|
| -
|
| -static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition, const FontMetrics& fontMetrics, const InlineTextBox* inlineTextBox, const float textDecorationThickness)
|
| -{
|
| - // Compute the gap between the font and the underline. Use at least one
|
| - // pixel gap, if underline is thick then use a bigger gap.
|
| - int gap = 0;
|
| -
|
| - // Underline position of zero means draw underline on Baseline Position,
|
| - // in Blink we need at least 1-pixel gap to adding following check.
|
| - // Positive underline Position means underline should be drawn above baselin e
|
| - // and negative value means drawing below baseline, negating the value as in Blink
|
| - // downward Y-increases.
|
| -
|
| - if (fontMetrics.underlinePosition())
|
| - gap = -fontMetrics.underlinePosition();
|
| - else
|
| - gap = std::max<int>(1, ceilf(textDecorationThickness / 2.f));
|
| -
|
| - // FIXME: We support only horizontal text for now.
|
| - switch (underlinePosition) {
|
| - case TextUnderlinePositionAuto:
|
| - return fontMetrics.ascent() + gap; // Position underline near the alphabetic baseline.
|
| - case TextUnderlinePositionUnder: {
|
| - // Position underline relative to the under edge of the lowest element's content box.
|
| - const float offset = inlineTextBox->root().maxLogicalTop() - inlineTextBox->logicalTop();
|
| - if (offset > 0)
|
| - return inlineTextBox->logicalHeight() + gap + offset;
|
| - return inlineTextBox->logicalHeight() + gap;
|
| - }
|
| - }
|
| -
|
| - ASSERT_NOT_REACHED();
|
| - return fontMetrics.ascent() + gap;
|
| -}
|
| -
|
| -static void adjustStepToDecorationLength(float& step, float& controlPointDistance, float length)
|
| -{
|
| - ASSERT(step > 0);
|
| -
|
| - if (length <= 0)
|
| - return;
|
| -
|
| - unsigned stepCount = static_cast<unsigned>(length / step);
|
| -
|
| - // Each Bezier curve starts at the same pixel that the previous one
|
| - // ended. We need to subtract (stepCount - 1) pixels when calculating the
|
| - // length covered to account for that.
|
| - float uncoveredLength = length - (stepCount * step - (stepCount - 1));
|
| - float adjustment = uncoveredLength / stepCount;
|
| - step += adjustment;
|
| - controlPointDistance += adjustment;
|
| -}
|
| -
|
| -/*
|
| - * Draw one cubic Bezier curve and repeat the same pattern long the the decoration's axis.
|
| - * The start point (p1), controlPoint1, controlPoint2 and end point (p2) of the Bezier curve
|
| - * form a diamond shape:
|
| - *
|
| - * step
|
| - * |-----------|
|
| - *
|
| - * controlPoint1
|
| - * +
|
| - *
|
| - *
|
| - * . .
|
| - * . .
|
| - * . .
|
| - * (x1, y1) p1 + . + p2 (x2, y2) - <--- Decoration's axis
|
| - * . . |
|
| - * . . |
|
| - * . . | controlPointDistance
|
| - * |
|
| - * |
|
| - * + -
|
| - * controlPoint2
|
| - *
|
| - * |-----------|
|
| - * step
|
| - */
|
| -static void strokeWavyTextDecoration(GraphicsContext* context, FloatPoint p1, FloatPoint p2, float strokeThickness)
|
| -{
|
| - context->adjustLineToPixelBoundaries(p1, p2, strokeThickness, context->strokeStyle());
|
| -
|
| - Path path;
|
| - path.moveTo(p1);
|
| -
|
| - // Distance between decoration's axis and Bezier curve's control points.
|
| - // The height of the curve is based on this distance. Use a minimum of 6 pixels distance since
|
| - // the actual curve passes approximately at half of that distance, that is 3 pixels.
|
| - // The minimum height of the curve is also approximately 3 pixels. Increases the curve's height
|
| - // as strockThickness increases to make the curve looks better.
|
| - float controlPointDistance = 3 * std::max<float>(2, strokeThickness);
|
| -
|
| - // Increment used to form the diamond shape between start point (p1), control
|
| - // points and end point (p2) along the axis of the decoration. Makes the
|
| - // curve wider as strockThickness increases to make the curve looks better.
|
| - float step = 2 * std::max<float>(2, strokeThickness);
|
| -
|
| - bool isVerticalLine = (p1.x() == p2.x());
|
| -
|
| - if (isVerticalLine) {
|
| - ASSERT(p1.x() == p2.x());
|
| -
|
| - float xAxis = p1.x();
|
| - float y1;
|
| - float y2;
|
| -
|
| - if (p1.y() < p2.y()) {
|
| - y1 = p1.y();
|
| - y2 = p2.y();
|
| - } else {
|
| - y1 = p2.y();
|
| - y2 = p1.y();
|
| - }
|
| -
|
| - adjustStepToDecorationLength(step, controlPointDistance, y2 - y1);
|
| - FloatPoint controlPoint1(xAxis + controlPointDistance, 0);
|
| - FloatPoint controlPoint2(xAxis - controlPointDistance, 0);
|
| -
|
| - for (float y = y1; y + 2 * step <= y2;) {
|
| - controlPoint1.setY(y + step);
|
| - controlPoint2.setY(y + step);
|
| - y += 2 * step;
|
| - path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(xAxis, y));
|
| - }
|
| - } else {
|
| - ASSERT(p1.y() == p2.y());
|
| -
|
| - float yAxis = p1.y();
|
| - float x1;
|
| - float x2;
|
| -
|
| - if (p1.x() < p2.x()) {
|
| - x1 = p1.x();
|
| - x2 = p2.x();
|
| - } else {
|
| - x1 = p2.x();
|
| - x2 = p1.x();
|
| - }
|
| -
|
| - adjustStepToDecorationLength(step, controlPointDistance, x2 - x1);
|
| - FloatPoint controlPoint1(0, yAxis + controlPointDistance);
|
| - FloatPoint controlPoint2(0, yAxis - controlPointDistance);
|
| -
|
| - for (float x = x1; x + 2 * step <= x2;) {
|
| - controlPoint1.setX(x + step);
|
| - controlPoint2.setX(x + step);
|
| - x += 2 * step;
|
| - path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(x, yAxis));
|
| - }
|
| - }
|
| -
|
| - context->setShouldAntialias(true);
|
| - context->strokePath(path);
|
| -}
|
| -
|
| -static bool shouldSetDecorationAntialias(TextDecorationStyle decorationStyle)
|
| -{
|
| - return decorationStyle == TextDecorationStyleDotted || decorationStyle == TextDecorationStyleDashed;
|
| -}
|
| -
|
| -static bool shouldSetDecorationAntialias(TextDecorationStyle underline, TextDecorationStyle overline, TextDecorationStyle linethrough)
|
| -{
|
| - return shouldSetDecorationAntialias(underline) || shouldSetDecorationAntialias(overline) || shouldSetDecorationAntialias(linethrough);
|
| -}
|
| -
|
| -static void paintAppliedDecoration(GraphicsContext* context, FloatPoint start, float width, float doubleOffset, int wavyOffsetFactor,
|
| - RenderObject::AppliedTextDecoration decoration, float thickness, bool antialiasDecoration, bool isPrinting)
|
| -{
|
| - context->setStrokeStyle(textDecorationStyleToStrokeStyle(decoration.style));
|
| - context->setStrokeColor(decoration.color);
|
| -
|
| - switch (decoration.style) {
|
| - case TextDecorationStyleWavy:
|
| - strokeWavyTextDecoration(context, start + FloatPoint(0, doubleOffset * wavyOffsetFactor), start + FloatPoint(width, doubleOffset * wavyOffsetFactor), thickness);
|
| - break;
|
| - case TextDecorationStyleDotted:
|
| - case TextDecorationStyleDashed:
|
| - context->setShouldAntialias(antialiasDecoration);
|
| - // Fall through
|
| - default:
|
| - context->drawLineForText(start, width, isPrinting);
|
| -
|
| - if (decoration.style == TextDecorationStyleDouble)
|
| - context->drawLineForText(start + FloatPoint(0, doubleOffset), width, isPrinting);
|
| - }
|
| -}
|
| -
|
| -void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint& boxOrigin, TextDecoration deco)
|
| -{
|
| - GraphicsContextStateSaver stateSaver(*context);
|
| -
|
| - if (m_truncation == cFullTruncation)
|
| - return;
|
| -
|
| - FloatPoint localOrigin = boxOrigin;
|
| -
|
| - float width = m_logicalWidth;
|
| - if (m_truncation != cNoTruncation) {
|
| - width = renderer().width(m_start, m_truncation, textPos(), isLeftToRightDirection() ? LTR : RTL, isFirstLineStyle());
|
| - if (!isLeftToRightDirection())
|
| - localOrigin.move(m_logicalWidth - width, 0);
|
| - }
|
| -
|
| - // Get the text decoration colors.
|
| - RenderObject::AppliedTextDecoration underline, overline, linethrough;
|
| - renderer().getTextDecorations(deco, underline, overline, linethrough, true);
|
| - if (isFirstLineStyle())
|
| - renderer().getTextDecorations(deco, underline, overline, linethrough, true, true);
|
| -
|
| - // Use a special function for underlines to get the positioning exactly right.
|
| - bool isPrinting = renderer().document().printing();
|
| -
|
| - RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
|
| - int baseline = styleToUse->fontMetrics().ascent();
|
| -
|
| - // Set the thick of the line to be 10% (or something else ?)of the computed font size and not less than 1px.
|
| - // Using computedFontSize should take care of zoom as well.
|
| -
|
| - // Update Underline thickness, in case we have Faulty Font Metrics calculating underline thickness by old method.
|
| - float textDecorationThickness = styleToUse->fontMetrics().underlineThickness();
|
| - int fontHeightInt = (int)(styleToUse->fontMetrics().floatHeight() + 0.5);
|
| - if ((textDecorationThickness == 0.f) || (textDecorationThickness >= (fontHeightInt >> 1)))
|
| - textDecorationThickness = std::max(1.f, styleToUse->computedFontSize() / 10.f);
|
| -
|
| - context->setStrokeThickness(textDecorationThickness);
|
| -
|
| - bool antialiasDecoration = shouldSetDecorationAntialias(overline.style, underline.style, linethrough.style)
|
| - && BoxPainter::shouldAntialiasLines(context);
|
| -
|
| - // Offset between lines - always non-zero, so lines never cross each other.
|
| - float doubleOffset = textDecorationThickness + 1.f;
|
| -
|
| - if (deco & TextDecorationUnderline) {
|
| - const int underlineOffset = computeUnderlineOffset(styleToUse->textUnderlinePosition(), styleToUse->fontMetrics(), this, textDecorationThickness);
|
| - paintAppliedDecoration(context, localOrigin + FloatPoint(0, underlineOffset), width, doubleOffset, 1, underline, textDecorationThickness, antialiasDecoration, isPrinting);
|
| - }
|
| - if (deco & TextDecorationOverline) {
|
| - paintAppliedDecoration(context, localOrigin, width, -doubleOffset, 1, overline, textDecorationThickness, antialiasDecoration, isPrinting);
|
| - }
|
| - if (deco & TextDecorationLineThrough) {
|
| - const float lineThroughOffset = 2 * baseline / 3;
|
| - paintAppliedDecoration(context, localOrigin + FloatPoint(0, lineThroughOffset), width, doubleOffset, 0, linethrough, textDecorationThickness, antialiasDecoration, isPrinting);
|
| - }
|
| -}
|
| -
|
| -static GraphicsContext::DocumentMarkerLineStyle lineStyleForMarkerType(DocumentMarker::MarkerType markerType)
|
| -{
|
| - switch (markerType) {
|
| - case DocumentMarker::Spelling:
|
| - return GraphicsContext::DocumentMarkerSpellingLineStyle;
|
| - case DocumentMarker::Grammar:
|
| - return GraphicsContext::DocumentMarkerGrammarLineStyle;
|
| - default:
|
| - ASSERT_NOT_REACHED();
|
| - return GraphicsContext::DocumentMarkerSpellingLineStyle;
|
| - }
|
| -}
|
| -
|
| void InlineTextBox::paintDocumentMarker(GraphicsContext* pt, const FloatPoint& boxOrigin, DocumentMarker* marker, RenderStyle* style, const Font& font, bool grammar)
|
| {
|
| - // Never print spelling/grammar markers (5327887)
|
| - if (renderer().document().printing())
|
| - return;
|
| -
|
| - if (m_truncation == cFullTruncation)
|
| - return;
|
| -
|
| - float start = 0; // start of line to draw, relative to tx
|
| - float width = m_logicalWidth; // how much line to draw
|
| -
|
| - // Determine whether we need to measure text
|
| - bool markerSpansWholeBox = true;
|
| - if (m_start <= (int)marker->startOffset())
|
| - markerSpansWholeBox = false;
|
| - if ((end() + 1) != marker->endOffset()) // end points at the last char, not past it
|
| - markerSpansWholeBox = false;
|
| - if (m_truncation != cNoTruncation)
|
| - markerSpansWholeBox = false;
|
| -
|
| - if (!markerSpansWholeBox || grammar) {
|
| - int startPosition = std::max<int>(marker->startOffset() - m_start, 0);
|
| - int endPosition = std::min<int>(marker->endOffset() - m_start, m_len);
|
| -
|
| - if (m_truncation != cNoTruncation)
|
| - endPosition = std::min<int>(endPosition, m_truncation);
|
| -
|
| - // Calculate start & width
|
| - int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
|
| - int selHeight = selectionHeight();
|
| - FloatPoint startPoint(boxOrigin.x(), boxOrigin.y() - deltaY);
|
| - TextRun run = constructTextRun(style, font);
|
| -
|
| - // FIXME: Convert the document markers to float rects.
|
| - 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(-boxOrigin.x(), -boxOrigin.y());
|
| - markerRect = renderer().localToAbsoluteQuad(FloatRect(markerRect)).enclosingBoundingBox();
|
| - toRenderedDocumentMarker(marker)->setRenderedRect(markerRect);
|
| - }
|
| - }
|
| -
|
| - // IMPORTANT: The misspelling underline is not considered when calculating the text bounds, so we have to
|
| - // make sure to fit within those bounds. This means the top pixel(s) of the underline will overlap the
|
| - // bottom pixel(s) of the glyphs in smaller font sizes. The alternatives are to increase the line spacing (bad!!)
|
| - // or decrease the underline thickness. The overlap is actually the most useful, and matches what AppKit does.
|
| - // So, we generally place the underline at the bottom of the text, but in larger fonts that's not so good so
|
| - // we pin to two pixels under the baseline.
|
| - int lineThickness = misspellingLineThickness;
|
| - int baseline = renderer().style(isFirstLineStyle())->fontMetrics().ascent();
|
| - int descent = logicalHeight() - baseline;
|
| - int underlineOffset;
|
| - if (descent <= (2 + lineThickness)) {
|
| - // Place the underline at the very bottom of the text in small/medium fonts.
|
| - underlineOffset = logicalHeight() - lineThickness;
|
| - } else {
|
| - // In larger fonts, though, place the underline up near the baseline to prevent a big gap.
|
| - underlineOffset = baseline + 2;
|
| - }
|
| - pt->drawLineForDocumentMarker(FloatPoint(boxOrigin.x() + start, boxOrigin.y() + underlineOffset), width, lineStyleForMarkerType(marker->type()));
|
| + InlineTextBoxPainter(*this).paintDocumentMarker(pt, boxOrigin, marker, style, font, grammar);
|
| }
|
|
|
| void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPoint& boxOrigin, 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 deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
|
| - int selHeight = selectionHeight();
|
| -
|
| - int sPos = std::max(marker->startOffset() - m_start, (unsigned)0);
|
| - int ePos = std::min(marker->endOffset() - m_start, (unsigned)m_len);
|
| - TextRun run = constructTextRun(style, font);
|
| -
|
| - // Always compute and store the rect associated with this marker. The computed rect is in absolute coordinates.
|
| - IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoint(x(), selectionTop()), selHeight, sPos, ePos));
|
| - markerRect = renderer().localToAbsoluteQuad(FloatRect(markerRect)).enclosingBoundingBox();
|
| - toRenderedDocumentMarker(marker)->setRenderedRect(markerRect);
|
| -
|
| - // Optionally highlight the text
|
| - if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) {
|
| - Color color = marker->activeMatch() ?
|
| - RenderTheme::theme().platformActiveTextSearchHighlightColor() :
|
| - RenderTheme::theme().platformInactiveTextSearchHighlightColor();
|
| - GraphicsContextStateSaver stateSaver(*pt);
|
| - pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_logicalWidth, selHeight));
|
| - pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin.y() - deltaY), selHeight, color, sPos, ePos);
|
| - }
|
| -}
|
| -
|
| -void InlineTextBox::paintCompositionBackgrounds(GraphicsContext* pt, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, bool useCustomUnderlines)
|
| -{
|
| - if (useCustomUnderlines) {
|
| - // Paint custom background highlights for compositions.
|
| - const Vector<CompositionUnderline>& underlines = renderer().frame()->inputMethodController().customCompositionUnderlines();
|
| - CompositionUnderlineRangeFilter filter(underlines, start(), end());
|
| - for (CompositionUnderlineRangeFilter::ConstIterator it = filter.begin(); it != filter.end(); ++it) {
|
| - if (it->backgroundColor == Color::transparent)
|
| - continue;
|
| - paintSingleCompositionBackgroundRun(pt, boxOrigin, style, font, it->backgroundColor, underlinePaintStart(*it), underlinePaintEnd(*it));
|
| - }
|
| -
|
| - } else {
|
| - paintSingleCompositionBackgroundRun(pt, boxOrigin, style, font, RenderTheme::theme().platformDefaultCompositionBackgroundColor(),
|
| - renderer().frame()->inputMethodController().compositionStart(),
|
| - renderer().frame()->inputMethodController().compositionEnd());
|
| - }
|
| -}
|
| -
|
| -void InlineTextBox::paintDocumentMarkers(GraphicsContext* pt, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, bool background)
|
| -{
|
| - if (!renderer().node())
|
| - return;
|
| -
|
| - DocumentMarkerVector markers = renderer().document().markers().markersFor(renderer().node());
|
| - DocumentMarkerVector::const_iterator markerIt = markers.begin();
|
| -
|
| - // Give any document markers that touch this run a chance to draw before the text has been drawn.
|
| - // Note end() points at the last char, not one past it like endOffset and ranges do.
|
| - for ( ; markerIt != markers.end(); ++markerIt) {
|
| - DocumentMarker* marker = *markerIt;
|
| -
|
| - // Paint either the background markers or the foreground markers, but not both
|
| - switch (marker->type()) {
|
| - case DocumentMarker::Grammar:
|
| - case DocumentMarker::Spelling:
|
| - if (background)
|
| - continue;
|
| - break;
|
| - case DocumentMarker::TextMatch:
|
| - if (!background)
|
| - continue;
|
| - break;
|
| - default:
|
| - continue;
|
| - }
|
| -
|
| - if (marker->endOffset() <= start())
|
| - // marker is completely before this run. This might be a marker that sits before the
|
| - // first run we draw, or markers that were within runs we skipped due to truncation.
|
| - continue;
|
| -
|
| - if (marker->startOffset() > end())
|
| - // marker is completely after this run, bail. A later run will paint it.
|
| - break;
|
| -
|
| - // marker intersects this run. Paint it.
|
| - switch (marker->type()) {
|
| - case DocumentMarker::Spelling:
|
| - paintDocumentMarker(pt, boxOrigin, marker, style, font, false);
|
| - break;
|
| - case DocumentMarker::Grammar:
|
| - paintDocumentMarker(pt, boxOrigin, marker, style, font, true);
|
| - break;
|
| - case DocumentMarker::TextMatch:
|
| - paintTextMatchMarker(pt, boxOrigin, marker, style, font);
|
| - break;
|
| - default:
|
| - ASSERT_NOT_REACHED();
|
| - }
|
| -
|
| - }
|
| -}
|
| -
|
| -void InlineTextBox::paintCompositionUnderline(GraphicsContext* ctx, const FloatPoint& boxOrigin, const CompositionUnderline& underline)
|
| -{
|
| - if (m_truncation == cFullTruncation)
|
| - return;
|
| -
|
| - unsigned paintStart = underlinePaintStart(underline);
|
| - unsigned paintEnd = underlinePaintEnd(underline);
|
| -
|
| - // start of line to draw, relative to paintOffset.
|
| - float start = paintStart == static_cast<unsigned>(m_start) ? 0 :
|
| - renderer().width(m_start, paintStart - m_start, textPos(), isLeftToRightDirection() ? LTR : RTL, isFirstLineStyle());
|
| - // how much line to draw
|
| - float width = (paintStart == static_cast<unsigned>(m_start) && paintEnd == static_cast<unsigned>(end()) + 1) ? m_logicalWidth :
|
| - renderer().width(paintStart, paintEnd - paintStart, textPos() + start, isLeftToRightDirection() ? LTR : RTL, isFirstLineStyle());
|
| -
|
| - // Thick marked text underlines are 2px thick as long as there is room for the 2px line under the baseline.
|
| - // All other marked text underlines are 1px thick.
|
| - // If there's not enough space the underline will touch or overlap characters.
|
| - int lineThickness = 1;
|
| - int baseline = renderer().style(isFirstLineStyle())->fontMetrics().ascent();
|
| - if (underline.thick && logicalHeight() - baseline >= 2)
|
| - lineThickness = 2;
|
| -
|
| - // We need to have some space between underlines of subsequent clauses, because some input methods do not use different underline styles for those.
|
| - // We make each line shorter, which has a harmless side effect of shortening the first and last clauses, too.
|
| - start += 1;
|
| - width -= 2;
|
| -
|
| - ctx->setStrokeColor(underline.color);
|
| - ctx->setStrokeThickness(lineThickness);
|
| - ctx->drawLineForText(FloatPoint(boxOrigin.x() + start, boxOrigin.y() + logicalHeight() - lineThickness), width, renderer().document().printing());
|
| + InlineTextBoxPainter(*this).paintTextMatchMarker(pt, boxOrigin, marker, style, font);
|
| }
|
|
|
| int InlineTextBox::caretMinOffset() const
|
|
|