Simple line layout:: Add text-decoration support.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Jan 2016 19:42:22 +0000 (19:42 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Jan 2016 19:42:22 +0000 (19:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=152623

Reviewed by Antti Koivisto.

Source/WebCore:

This patch enables text-decoration for simple line layout.
-webkit-text-underline-position: under requires normal line layout context, skip it for now.

Test: fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration.html

* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::canUseForStyle):
(WebCore::SimpleLineLayout::printReason):
* rendering/SimpleLineLayoutFunctions.cpp:
(WebCore::SimpleLineLayout::paintFlow): In case of multiple RenderText renderers (long text), it's ok
to pass the first text renderer as they all share the same set of decorations.

LayoutTests:

Existing tests cases also cover decoration correctness.

* fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration-expected.html: Added.
* fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194500 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration-expected.html [new file with mode: 0644]
LayoutTests/fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/SimpleLineLayout.cpp
Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp

index 0d056cf..2dbc56b 100644 (file)
@@ -1,3 +1,15 @@
+2016-01-02  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout:: Add text-decoration support.
+        https://bugs.webkit.org/show_bug.cgi?id=152623
+
+        Reviewed by Antti Koivisto.
+
+        Existing tests cases also cover decoration correctness.
+
+        * fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration-expected.html: Added.
+        * fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration.html: Added.
+
 2016-01-01  Brady Eidson  <beidson@apple.com>
 
         Modern IDB: storage/indexeddb/database-deletepending-flag.html fails.
diff --git a/LayoutTests/fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration-expected.html b/LayoutTests/fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration-expected.html
new file mode 100644 (file)
index 0000000..9f387ea
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we paint simple line layout text-decoration correctly.</title>
+<script>
+    if (window.internals)
+        internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+</head>
+<body>
+<div style="text-decoration: underline;"><br>supported<br><br>supported<br></div>
+<div style="text-decoration: underline;"><br></div>
+<div style="text-decoration: underline;"><br><br></div>
+<div style="text-decoration: underline; -webkit-text-underline-position: under;">not supported</div>
+<div style="text-decoration: underline; -webkit-text-underline-position: auto;">supported</div>
+<div style="text-decoration: underline; -webkit-text-underline-position: alphabetic;">supported</div>
+<div style="text-decoration: line-through;">supported</div>
+<div style="text-decoration: overline;">supported</div>
+</body>
diff --git a/LayoutTests/fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration.html b/LayoutTests/fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration.html
new file mode 100644 (file)
index 0000000..9e8a19a
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we paint simple line layout text-decoration correctly.</title>
+</head>
+<body>
+<div style="text-decoration: underline;"><br>supported<br><br>supported<br></div>
+<div style="text-decoration: underline;"><br></div>
+<div style="text-decoration: underline;"><br><br></div>
+<div style="text-decoration: underline; -webkit-text-underline-position: under;">not supported</div>
+<div style="text-decoration: underline; -webkit-text-underline-position: auto;">supported</div>
+<div style="text-decoration: underline; -webkit-text-underline-position: alphabetic;">supported</div>
+<div style="text-decoration: line-through;">supported</div>
+<div style="text-decoration: overline;">supported</div>
+</body>
index da448b5..f2fbe16 100644 (file)
@@ -1,3 +1,22 @@
+2016-01-02  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout:: Add text-decoration support.
+        https://bugs.webkit.org/show_bug.cgi?id=152623
+
+        Reviewed by Antti Koivisto.
+
+        This patch enables text-decoration for simple line layout.
+        -webkit-text-underline-position: under requires normal line layout context, skip it for now.
+
+        Test: fast/css3-text/css3-text-decoration/simple-line-layout-text-decoration.html
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::canUseForStyle):
+        (WebCore::SimpleLineLayout::printReason):
+        * rendering/SimpleLineLayoutFunctions.cpp:
+        (WebCore::SimpleLineLayout::paintFlow): In case of multiple RenderText renderers (long text), it's ok
+        to pass the first text renderer as they all share the same set of decorations. 
+
 2015-12-31  Andy Estes  <aestes@apple.com>
 
         Replace WTF::move with WTFMove
index 78f546f..44e681d 100644 (file)
@@ -62,57 +62,57 @@ void toggleSimpleLineLayout();
 #endif
 
 enum AvoidanceReason_ : uint64_t {
-    FlowIsInsideRegion                  = 1LLU  << 0,
-    FlowHasHorizonalWritingMode         = 1LLU  << 1,
-    FlowHasOutline                      = 1LLU  << 2,
-    FlowIsRuby                          = 1LLU  << 3,
-    FlowIsPaginated                     = 1LLU  << 4,
-    FlowHasTextOverflow                 = 1LLU  << 5,
-    FlowIsDepricatedFlexBox             = 1LLU  << 6,
-    FlowParentIsPlaceholderElement      = 1LLU  << 7,
-    FlowParentIsTextAreaWithWrapping    = 1LLU  << 8,
-    FlowHasNonSupportedChild            = 1LLU  << 9,
-    FlowHasUnsupportedFloat             = 1LLU  << 10,
-    FlowHasTextDecoration               = 1LLU  << 11,
-    FlowIsJustifyAligned                = 1LLU  << 12,
-    FlowHasOverflowVisible              = 1LLU  << 13,
-    FlowIsNotLTR                        = 1LLU  << 14,
-    FlowHasLineBoxContainProperty       = 1LLU  << 15,
-    FlowIsNotTopToBottom                = 1LLU  << 16,
-    FlowHasLineBreak                    = 1LLU  << 17,
-    FlowHasWordBreak                    = 1LLU  << 18,
-    FlowHasNonNormalUnicodeBiDi         = 1LLU  << 19,
-    FlowHasRTLOrdering                  = 1LLU  << 20,
-    FlowHasLineAlignEdges               = 1LLU  << 21,
-    FlowHasLineSnap                     = 1LLU  << 22,
-    FlowHasHypensAuto                   = 1LLU  << 23,
-    FlowHasTextEmphasisFillOrMark       = 1LLU  << 24,
-    FlowHasTextShadow                   = 1LLU  << 25,
-    FlowHasPseudoFirstLine              = 1LLU  << 26,
-    FlowHasPseudoFirstLetter            = 1LLU  << 27,
-    FlowHasTextCombine                  = 1LLU  << 28,
-    FlowHasTextFillBox                  = 1LLU  << 29,
-    FlowHasBorderFitLines               = 1LLU  << 30,
-    FlowHasNonAutoLineBreak             = 1LLU  << 31,
-    FlowHasNonAutoTrailingWord          = 1LLU  << 32,
-    FlowHasSVGFont                      = 1LLU  << 33,
-    FlowTextIsEmpty                     = 1LLU  << 34,
-    FlowTextHasNoBreakSpace             = 1LLU  << 35,
-    FlowTextHasSoftHyphen               = 1LLU  << 36,
-    FlowTextHasDirectionCharacter       = 1LLU  << 37,
-    FlowIsMissingPrimaryFont            = 1LLU  << 38,
-    FlowFontIsMissingGlyph              = 1LLU  << 39,
-    FlowTextIsCombineText               = 1LLU  << 40,
-    FlowTextIsRenderCounter             = 1LLU  << 41,
-    FlowTextIsRenderQuote               = 1LLU  << 42,
-    FlowTextIsTextFragment              = 1LLU  << 43,
-    FlowTextIsSVGInlineText             = 1LLU  << 44,
-    FlowFontIsNotSimple                 = 1LLU  << 45,
-    FeatureIsDisabled                   = 1LLU  << 46,
-    FlowHasNoParent                     = 1LLU  << 47,
-    FlowHasNoChild                      = 1LLU  << 48,
-    FlowChildIsSelected                 = 1LLU  << 49,
-    EndOfReasons                        = 1LLU  << 50
+    FlowIsInsideRegion                    = 1LLU  << 0,
+    FlowHasHorizonalWritingMode           = 1LLU  << 1,
+    FlowHasOutline                        = 1LLU  << 2,
+    FlowIsRuby                            = 1LLU  << 3,
+    FlowIsPaginated                       = 1LLU  << 4,
+    FlowHasTextOverflow                   = 1LLU  << 5,
+    FlowIsDepricatedFlexBox               = 1LLU  << 6,
+    FlowParentIsPlaceholderElement        = 1LLU  << 7,
+    FlowParentIsTextAreaWithWrapping      = 1LLU  << 8,
+    FlowHasNonSupportedChild              = 1LLU  << 9,
+    FlowHasUnsupportedFloat               = 1LLU  << 10,
+    FlowHasUnsupportedUnderlineDecoration = 1LLU  << 11,
+    FlowIsJustifyAligned                  = 1LLU  << 12,
+    FlowHasOverflowVisible                = 1LLU  << 13,
+    FlowIsNotLTR                          = 1LLU  << 14,
+    FlowHasLineBoxContainProperty         = 1LLU  << 15,
+    FlowIsNotTopToBottom                  = 1LLU  << 16,
+    FlowHasLineBreak                      = 1LLU  << 17,
+    FlowHasWordBreak                      = 1LLU  << 18,
+    FlowHasNonNormalUnicodeBiDi           = 1LLU  << 19,
+    FlowHasRTLOrdering                    = 1LLU  << 20,
+    FlowHasLineAlignEdges                 = 1LLU  << 21,
+    FlowHasLineSnap                       = 1LLU  << 22,
+    FlowHasHypensAuto                     = 1LLU  << 23,
+    FlowHasTextEmphasisFillOrMark         = 1LLU  << 24,
+    FlowHasTextShadow                     = 1LLU  << 25,
+    FlowHasPseudoFirstLine                = 1LLU  << 26,
+    FlowHasPseudoFirstLetter              = 1LLU  << 27,
+    FlowHasTextCombine                    = 1LLU  << 28,
+    FlowHasTextFillBox                    = 1LLU  << 29,
+    FlowHasBorderFitLines                 = 1LLU  << 30,
+    FlowHasNonAutoLineBreak               = 1LLU  << 31,
+    FlowHasNonAutoTrailingWord            = 1LLU  << 32,
+    FlowHasSVGFont                        = 1LLU  << 33,
+    FlowTextIsEmpty                       = 1LLU  << 34,
+    FlowTextHasNoBreakSpace               = 1LLU  << 35,
+    FlowTextHasSoftHyphen                 = 1LLU  << 36,
+    FlowTextHasDirectionCharacter         = 1LLU  << 37,
+    FlowIsMissingPrimaryFont              = 1LLU  << 38,
+    FlowFontIsMissingGlyph                = 1LLU  << 39,
+    FlowTextIsCombineText                 = 1LLU  << 40,
+    FlowTextIsRenderCounter               = 1LLU  << 41,
+    FlowTextIsRenderQuote                 = 1LLU  << 42,
+    FlowTextIsTextFragment                = 1LLU  << 43,
+    FlowTextIsSVGInlineText               = 1LLU  << 44,
+    FlowFontIsNotSimple                   = 1LLU  << 45,
+    FeatureIsDisabled                     = 1LLU  << 46,
+    FlowHasNoParent                       = 1LLU  << 47,
+    FlowHasNoChild                        = 1LLU  << 48,
+    FlowChildIsSelected                   = 1LLU  << 49,
+    EndOfReasons                          = 1LLU  << 50
 };
 const unsigned NoReason = 0;
 
@@ -211,8 +211,8 @@ static AvoidanceReasonFlags canUseForStyle(const RenderStyle& style, IncludeReas
     AvoidanceReasonFlags reasons = { };
     if (style.textOverflow())
         SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextOverflow, reasons, includeReasons);
-    if (style.textDecorationsInEffect() != TextDecorationNone)
-        SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextDecoration, reasons, includeReasons);
+    if ((style.textDecorationsInEffect() & TextDecorationUnderline) && style.textUnderlinePosition() == TextUnderlinePositionUnder)
+        SET_REASON_AND_RETURN_IF_NEEDED(FlowHasUnsupportedUnderlineDecoration, reasons, includeReasons);
     if (style.textAlign() == JUSTIFY)
         SET_REASON_AND_RETURN_IF_NEEDED(FlowIsJustifyAligned, reasons, includeReasons);
     // Non-visible overflow should be pretty easy to support.
@@ -820,8 +820,8 @@ static void printReason(AvoidanceReason reason, TextStream& stream)
     case FlowHasUnsupportedFloat:
         stream << "complicated float";
         break;
-    case FlowHasTextDecoration:
-        stream << "text-decoration";
+    case FlowHasUnsupportedUnderlineDecoration:
+        stream << "text-underline-position: under";
         break;
     case FlowIsJustifyAligned:
         stream << "text-align: justify";
index 21f75b7..da05218 100644 (file)
 #include "InlineTextBox.h"
 #include "PaintInfo.h"
 #include "RenderBlockFlow.h"
+#include "RenderIterator.h"
 #include "RenderStyle.h"
 #include "RenderText.h"
 #include "RenderView.h"
 #include "Settings.h"
 #include "SimpleLineLayoutResolver.h"
 #include "Text.h"
+#include "TextDecorationPainter.h"
 #include "TextPaintStyle.h"
 #include "TextPainter.h"
 
@@ -78,6 +80,16 @@ void paintFlow(const RenderBlockFlow& flow, const Layout& layout, PaintInfo& pai
     textPainter.setFont(style.fontCascade());
     textPainter.setTextPaintStyle(computeTextPaintStyle(flow.frame(), style, paintInfo));
 
+    Optional<TextDecorationPainter> textDecorationPainter;
+    if (style.textDecorationsInEffect() != TextDecorationNone) {
+        const RenderText* textRenderer = childrenOfType<RenderText>(flow).first();
+        if (textRenderer) {
+            textDecorationPainter = TextDecorationPainter(paintInfo.context(), style.textDecorationsInEffect(), *textRenderer, false);
+            textDecorationPainter->setFont(style.fontCascade());
+            textDecorationPainter->setBaseline(style.fontMetrics().ascent());
+        }
+    }
+
     LayoutRect paintRect = paintInfo.rect;
     paintRect.moveBy(-paintOffset);
 
@@ -100,6 +112,10 @@ void paintFlow(const RenderBlockFlow& flow, const Layout& layout, PaintInfo& pai
         textRun.setXPos(0);
         FloatPoint textOrigin = FloatPoint(rect.x() + paintOffset.x(), roundToDevicePixel(run.baselinePosition() + paintOffset.y(), deviceScaleFactor));
         textPainter.paintText(textRun, textRun.length(), rect, textOrigin);
+        if (textDecorationPainter) {
+            textDecorationPainter->setWidth(rect.width());
+            textDecorationPainter->paintTextDecoration(textRun, textOrigin, rect.location() + paintOffset);
+        }
         if (debugBordersEnabled)
             paintDebugBorders(paintInfo.context(), LayoutRect(run.rect()), paintOffset);
     }