Title: [222889] trunk/Source/WebCore
Revision
222889
Author
[email protected]
Date
2017-10-04 16:58:02 -0700 (Wed, 04 Oct 2017)

Log Message

Have TextDecorationPainter hold an OptionSet of decorations
https://bugs.webkit.org/show_bug.cgi?id=177889

Reviewed by Simon Fraser.

Currently TextDecorationPainter implicitly maintains the set of one or more TextDecoration
flags in a instance variable bitmask of type TextDecoration. Instead we should represent
this set explicitly as an OptionSet to improve readability of the code.

For now we have the TextDecorationPainter constructor and TextDecorationPainter::stylesForRenderer()
to take the set of decorations as an unsigned value to avoid the need to update callers.
We will look to apply a similar change throughout the code in <https://bugs.webkit.org/show_bug.cgi?id=176844>.

No functionality changed. So, no new tests.

* rendering/TextDecorationPainter.cpp:
(WebCore::TextDecorationPainter::TextDecorationPainter): For now, changed data type for passed
decorations from TextDecoration to unsigned to convey that it is a bitmask.
(WebCore::TextDecorationPainter::paintTextDecoration): Renamed linesAreOpaque to areLinesOpaque
while I am here. Fixed some minor style issues.
(WebCore::collectStylesForRenderer): Modified to take the remaining decorations as an OptionSet,
and removed an unnecessary copy of these decorations by taking advantage of the fact that they
are passed by value.
(WebCore::TextDecorationPainter::stylesForRenderer): Convert the passed decorations to an OptionSet as needed to
pass to collectStylesForRenderer().
* rendering/TextDecorationPainter.h: Change m_decoration from TextDecoration to OptionSet<TextDecoration>
and rename it to m_decorations to reflect that it is used as a set of one or more TextDecoration flags.
Also remove unnecessary initializer for m_isPrinting while I am here and group it with the other boolean,
m_isHorizontal. There is exactly one constructor for this class and it initializes m_isPrinting.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (222888 => 222889)


--- trunk/Source/WebCore/ChangeLog	2017-10-04 23:51:47 UTC (rev 222888)
+++ trunk/Source/WebCore/ChangeLog	2017-10-04 23:58:02 UTC (rev 222889)
@@ -1,3 +1,35 @@
+2017-10-04  Daniel Bates  <[email protected]>
+
+        Have TextDecorationPainter hold an OptionSet of decorations
+        https://bugs.webkit.org/show_bug.cgi?id=177889
+
+        Reviewed by Simon Fraser.
+
+        Currently TextDecorationPainter implicitly maintains the set of one or more TextDecoration
+        flags in a instance variable bitmask of type TextDecoration. Instead we should represent
+        this set explicitly as an OptionSet to improve readability of the code.
+
+        For now we have the TextDecorationPainter constructor and TextDecorationPainter::stylesForRenderer()
+        to take the set of decorations as an unsigned value to avoid the need to update callers.
+        We will look to apply a similar change throughout the code in <https://bugs.webkit.org/show_bug.cgi?id=176844>.
+
+        No functionality changed. So, no new tests.
+
+        * rendering/TextDecorationPainter.cpp:
+        (WebCore::TextDecorationPainter::TextDecorationPainter): For now, changed data type for passed
+        decorations from TextDecoration to unsigned to convey that it is a bitmask.
+        (WebCore::TextDecorationPainter::paintTextDecoration): Renamed linesAreOpaque to areLinesOpaque
+        while I am here. Fixed some minor style issues.
+        (WebCore::collectStylesForRenderer): Modified to take the remaining decorations as an OptionSet,
+        and removed an unnecessary copy of these decorations by taking advantage of the fact that they
+        are passed by value.
+        (WebCore::TextDecorationPainter::stylesForRenderer): Convert the passed decorations to an OptionSet as needed to
+        pass to collectStylesForRenderer().
+        * rendering/TextDecorationPainter.h: Change m_decoration from TextDecoration to OptionSet<TextDecoration>
+        and rename it to m_decorations to reflect that it is used as a set of one or more TextDecoration flags.
+        Also remove unnecessary initializer for m_isPrinting while I am here and group it with the other boolean,
+        m_isHorizontal. There is exactly one constructor for this class and it initializes m_isPrinting.
+
 2017-10-04  Matt Baker  <[email protected]>
 
         Web Inspector: Improve CanvasManager recording events

Modified: trunk/Source/WebCore/rendering/TextDecorationPainter.cpp (222888 => 222889)


--- trunk/Source/WebCore/rendering/TextDecorationPainter.cpp	2017-10-04 23:51:47 UTC (rev 222888)
+++ trunk/Source/WebCore/rendering/TextDecorationPainter.cpp	2017-10-04 23:58:02 UTC (rev 222889)
@@ -241,12 +241,12 @@
     return strokeStyle;
 }
 
-TextDecorationPainter::TextDecorationPainter(GraphicsContext& context, TextDecoration decoration, const RenderText& renderer, bool isFirstLine, PseudoId pseudoId)
+TextDecorationPainter::TextDecorationPainter(GraphicsContext& context, unsigned decorations, const RenderText& renderer, bool isFirstLine, PseudoId pseudoId)
     : m_context { context }
-    , m_decoration { decoration }
+    , m_decorations { OptionSet<TextDecoration>::fromRaw(decorations) }
     , m_wavyOffset { wavyOffsetFromDecoration() }
     , m_isPrinting { renderer.document().printing() }
-    , m_styles { stylesForRenderer(renderer, m_decoration, isFirstLine, pseudoId) }
+    , m_styles { stylesForRenderer(renderer, decorations, isFirstLine, pseudoId) }
     , m_lineStyle { isFirstLine ? renderer.firstLineStyle() : renderer.style() }
 {
 }
@@ -262,7 +262,7 @@
     m_context.setStrokeThickness(textDecorationThickness);
     FloatPoint localOrigin = boxOrigin;
 
-    auto paintDecoration = [&](TextDecoration decoration, TextDecorationStyle style, const Color& color, const FloatPoint& start, const FloatPoint& end, int offset) {
+    auto paintDecoration = [&] (TextDecoration decoration, TextDecorationStyle style, const Color& color, const FloatPoint& start, const FloatPoint& end, int offset) {
         m_context.setStrokeColor(color);
 
         auto strokeStyle = textDecorationStyleToStrokeStyle(style);
@@ -285,13 +285,12 @@
         }
     };
 
-    bool linesAreOpaque = !m_isPrinting
-        && (!(m_decoration & TextDecorationUnderline) || m_styles.underlineColor.isOpaque())
-        && (!(m_decoration & TextDecorationOverline) || m_styles.overlineColor.isOpaque())
-        && (!(m_decoration & TextDecorationLineThrough) || m_styles.linethroughColor.isOpaque());
+    bool areLinesOpaque = !m_isPrinting && (!m_decorations.contains(TextDecorationUnderline) || m_styles.underlineColor.isOpaque())
+        && (!m_decorations.contains(TextDecorationOverline) || m_styles.overlineColor.isOpaque())
+        && (!m_decorations.contains(TextDecorationLineThrough) || m_styles.linethroughColor.isOpaque());
 
     int extraOffset = 0;
-    bool clipping = !linesAreOpaque && m_shadow && m_shadow->next();
+    bool clipping = !areLinesOpaque && m_shadow && m_shadow->next();
     if (clipping) {
         FloatRect clipRect(localOrigin, FloatSize(m_width, m_baseline + 2));
         for (const ShadowData* shadow = m_shadow; shadow; shadow = shadow->next()) {
@@ -323,22 +322,22 @@
             m_context.setShadow(FloatSize(shadowX, shadowY - extraOffset), shadow->radius(), shadow->color());
             shadow = shadow->next();
         }
-        
-        // These decorations should match the visual overflows computed in visualOverflowForDecorations()
-        if (m_decoration & TextDecorationUnderline) {
-            const int offset = computeUnderlineOffset(m_lineStyle.textUnderlinePosition(), m_lineStyle.fontMetrics(), m_inlineTextBox, textDecorationThickness);
+
+        // These decorations should match the visual overflows computed in visualOverflowForDecorations().
+        if (m_decorations.contains(TextDecorationUnderline)) {
+            int offset = computeUnderlineOffset(m_lineStyle.textUnderlinePosition(), m_lineStyle.fontMetrics(), m_inlineTextBox, textDecorationThickness);
             float wavyOffset = m_styles.underlineStyle == TextDecorationStyleWavy ? m_wavyOffset : 0;
             FloatPoint start = localOrigin + FloatSize(0, offset + wavyOffset);
             FloatPoint end = localOrigin + FloatSize(m_width, offset + wavyOffset);
             paintDecoration(TextDecorationUnderline, m_styles.underlineStyle, m_styles.underlineColor, start, end, offset);
         }
-        if (m_decoration & TextDecorationOverline) {
+        if (m_decorations.contains(TextDecorationOverline)) {
             float wavyOffset = m_styles.overlineStyle == TextDecorationStyleWavy ? m_wavyOffset : 0;
             FloatPoint start = localOrigin - FloatSize(0, wavyOffset);
             FloatPoint end = localOrigin + FloatSize(m_width, -wavyOffset);
             paintDecoration(TextDecorationOverline, m_styles.overlineStyle, m_styles.overlineColor, start, end, 0);
         }
-        if (m_decoration & TextDecorationLineThrough) {
+        if (m_decorations.contains(TextDecorationLineThrough)) {
             FloatPoint start = localOrigin + FloatSize(0, 2 * m_baseline / 3);
             FloatPoint end = localOrigin + FloatSize(m_width, 2 * m_baseline / 3);
             paintDecoration(TextDecorationLineThrough, m_styles.linethroughStyle, m_styles.linethroughColor, start, end, 0);
@@ -367,25 +366,24 @@
     return style.visitedDependentColor(CSSPropertyWebkitTextFillColor);
 }
 
-static void collectStylesForRenderer(TextDecorationPainter::Styles& result, const RenderObject& renderer, unsigned requestedDecorations, bool firstLineStyle, PseudoId pseudoId)
+static void collectStylesForRenderer(TextDecorationPainter::Styles& result, const RenderObject& renderer, OptionSet<TextDecoration> remainingDecorations, bool firstLineStyle, PseudoId pseudoId)
 {
-    unsigned remainingDecoration = requestedDecorations;
-    auto extractDecorations = [&] (const RenderStyle& style, unsigned decorations) {
+    auto extractDecorations = [&] (const RenderStyle& style, OptionSet<TextDecoration> decorations) {
         auto color = decorationColor(style);
         auto decorationStyle = style.textDecorationStyle();
 
-        if (decorations & TextDecorationUnderline) {
-            remainingDecoration &= ~TextDecorationUnderline;
+        if (decorations.contains(TextDecorationUnderline)) {
+            remainingDecorations -= TextDecorationUnderline;
             result.underlineColor = color;
             result.underlineStyle = decorationStyle;
         }
-        if (decorations & TextDecorationOverline) {
-            remainingDecoration &= ~TextDecorationOverline;
+        if (decorations.contains(TextDecorationOverline)) {
+            remainingDecorations -= TextDecorationOverline;
             result.overlineColor = color;
             result.overlineStyle = decorationStyle;
         }
-        if (decorations & TextDecorationLineThrough) {
-            remainingDecoration &= ~TextDecorationLineThrough;
+        if (decorations.contains(TextDecorationLineThrough)) {
+            remainingDecorations -= TextDecorationLineThrough;
             result.linethroughColor = color;
             result.linethroughStyle = decorationStyle;
         }
@@ -404,7 +402,7 @@
     auto* current = &renderer;
     do {
         const auto& style = styleForRenderer(*current);
-        extractDecorations(style, style.textDecoration());
+        extractDecorations(style, OptionSet<TextDecoration>::fromRaw(style.textDecoration()));
 
         if (current->isRubyText())
             return;
@@ -413,22 +411,22 @@
         if (current && current->isAnonymousBlock() && downcast<RenderBlock>(*current).continuation())
             current = downcast<RenderBlock>(*current).continuation();
 
-        if (!remainingDecoration)
+        if (remainingDecorations.isEmpty())
             break;
 
     } while (current && !is<HTMLAnchorElement>(current->node()) && !is<HTMLFontElement>(current->node()));
 
     // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
-    if (remainingDecoration && current)
-        extractDecorations(styleForRenderer(*current), remainingDecoration);
+    if (!remainingDecorations.isEmpty() && current)
+        extractDecorations(styleForRenderer(*current), remainingDecorations);
 }
 
 auto TextDecorationPainter::stylesForRenderer(const RenderObject& renderer, unsigned requestedDecorations, bool firstLineStyle, PseudoId pseudoId) -> Styles
 {
     Styles result;
-    collectStylesForRenderer(result, renderer, requestedDecorations, false, pseudoId);
+    collectStylesForRenderer(result, renderer, OptionSet<TextDecoration>::fromRaw(requestedDecorations), false, pseudoId);
     if (firstLineStyle)
-        collectStylesForRenderer(result, renderer, requestedDecorations, true, pseudoId);
+        collectStylesForRenderer(result, renderer, OptionSet<TextDecoration>::fromRaw(requestedDecorations), true, pseudoId);
     return result;
 }
 

Modified: trunk/Source/WebCore/rendering/TextDecorationPainter.h (222888 => 222889)


--- trunk/Source/WebCore/rendering/TextDecorationPainter.h	2017-10-04 23:51:47 UTC (rev 222888)
+++ trunk/Source/WebCore/rendering/TextDecorationPainter.h	2017-10-04 23:58:02 UTC (rev 222889)
@@ -25,6 +25,7 @@
 #include "Color.h"
 #include "FloatPoint.h"
 #include "RenderStyleConstants.h"
+#include <wtf/OptionSet.h>
 
 namespace WebCore {
 
@@ -40,7 +41,8 @@
     
 class TextDecorationPainter {
 public:
-    TextDecorationPainter(GraphicsContext&, TextDecoration, const RenderText&, bool isFirstLine, PseudoId = NOPSEUDO);
+    // FIXME: Make decorations an OptionSet<TextDecoration>. See <https://bugs.webkit.org/show_bug.cgi?id=176844>.
+    TextDecorationPainter(GraphicsContext&, unsigned decorations, const RenderText&, bool isFirstLine, PseudoId = NOPSEUDO);
     
     void setInlineTextBox(const InlineTextBox* inlineTextBox) { m_inlineTextBox = inlineTextBox; }
     void setFont(const FontCascade& font) { m_font = &font; }
@@ -59,21 +61,22 @@
         TextDecorationStyle overlineStyle;
         TextDecorationStyle linethroughStyle;
     };
+    // FIXME: Make requestedDecorations an OptionSet<TextDecoration>. See <https://bugs.webkit.org/show_bug.cgi?id=176844>.
     static Styles stylesForRenderer(const RenderObject&, unsigned requestedDecorations, bool firstLineStyle = false, PseudoId = NOPSEUDO);
         
 private:
     GraphicsContext& m_context;
-    TextDecoration m_decoration;
+    OptionSet<TextDecoration> m_decorations;
     float m_wavyOffset;
-    bool m_isPrinting { false };
     float m_width { 0 };
     float m_baseline { 0 };
     FloatPoint m_boxOrigin;
+    bool m_isPrinting;
     bool m_isHorizontal { true };
     const ShadowData* m_shadow { nullptr };
     const InlineTextBox* m_inlineTextBox { nullptr };
     const FontCascade* m_font { nullptr };
-    
+
     Styles m_styles;
     const RenderStyle& m_lineStyle;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to