Chromium Code Reviews| Index: third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp |
| diff --git a/third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp b/third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp |
| index eb5a60a4f93f66709a82faeb434a34e6a39f251c..64ed3bef897a89bf6255d54df379ec09961ea892 100644 |
| --- a/third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp |
| +++ b/third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp |
| @@ -36,7 +36,49 @@ std::pair<unsigned, unsigned> GetMarkerPaintOffsets( |
| } |
| } |
| +static LineLayoutItem enclosingUnderlineObject( |
| + const InlineTextBox* inlineTextBox) { |
| + bool firstLine = inlineTextBox->isFirstLineStyle(); |
| + for (LineLayoutItem current = inlineTextBox->parent()->getLineLayoutItem(); |
| + ;) { |
| + if (current.isLayoutBlock()) |
| + return current; |
| + if (!current.isLayoutInline() || current.isRubyText()) |
| + return nullptr; |
| + |
| + const ComputedStyle& styleToUse = current.styleRef(firstLine); |
| + if (styleToUse.getTextDecoration() & TextDecorationUnderline) |
| + return current; |
| + |
| + current = current.parent(); |
| + if (!current) |
| + return current; |
| + |
| + if (Node* node = current.node()) { |
| + if (isHTMLAnchorElement(node) || node->hasTagName(HTMLNames::fontTag)) |
| + return current; |
| + } |
| + } |
| +} |
| + |
| +static LayoutUnit computeUnderlineOffsetForUnder( |
| + const ComputedStyle& style, |
| + const InlineTextBox* inlineTextBox) { |
| + const RootInlineBox& root = inlineTextBox->root(); |
| + LineLayoutItem decorationObject = enclosingUnderlineObject(inlineTextBox); |
| + if (style.isFlippedLinesWritingMode()) { |
| + LayoutUnit position = inlineTextBox->logicalTop(); |
| + return position - |
| + root.minLogicalTopForUnderline(decorationObject, position); |
| + } else { |
| + LayoutUnit position = inlineTextBox->logicalBottom(); |
| + return root.maxLogicalBottomForUnderline(decorationObject, position) - |
| + position; |
| + } |
| +} |
| + |
| static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition, |
| + const ComputedStyle& style, |
| const FontMetrics& fontMetrics, |
| const InlineTextBox* inlineTextBox, |
| const float textDecorationThickness) { |
| @@ -64,11 +106,9 @@ static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition, |
| case TextUnderlinePositionUnder: { |
| // Position underline relative to the under edge of the lowest element's |
| // content box. |
| - const LayoutUnit offset = |
| - inlineTextBox->root().maxLogicalTop() - inlineTextBox->logicalTop(); |
| - if (offset > 0) |
| - return (inlineTextBox->logicalHeight() + gap + offset).toInt(); |
| - return (inlineTextBox->logicalHeight() + gap).toInt(); |
| + LayoutUnit offset = computeUnderlineOffsetForUnder(style, inlineTextBox); |
| + offset = inlineTextBox->logicalHeight() + std::max(offset, LayoutUnit()); |
| + return offset.toInt() + gap; |
| } |
| } |
| @@ -1099,9 +1139,10 @@ void InlineTextBoxPainter::paintDecorations( |
| for (const AppliedTextDecoration& decoration : decorations) { |
| TextDecoration lines = decoration.lines(); |
| if ((lines & TextDecorationUnderline) && fontData) { |
| - const int underlineOffset = computeUnderlineOffset( |
| - styleToUse.getTextUnderlinePosition(), fontData->getFontMetrics(), |
| - &m_inlineTextBox, textDecorationThickness); |
| + const int underlineOffset = |
| + computeUnderlineOffset(styleToUse.getTextUnderlinePosition(), |
| + styleToUse, fontData->getFontMetrics(), |
|
drott
2017/01/23 10:30:37
If you're passing ComputedStyle styleToUse as a wh
kojii
2017/01/23 13:17:44
Done.
|
| + &m_inlineTextBox, textDecorationThickness); |
| AppliedDecorationPainter decorationPainter( |
| context, FloatPoint(localOrigin) + FloatPoint(0, underlineOffset), |
| width.toFloat(), decoration, textDecorationThickness, doubleOffset, 1, |