text-align start / end failure in table cells
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Apr 2017 20:59:36 +0000 (20:59 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Apr 2017 20:59:36 +0000 (20:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141417
<rdar://problem/31051672>

Reviewed by Antti Koivisto.

Source/WebCore:

Apply "text-align: center" on th elements when parent's computed value for the 'text-align' property
is its initial value, unless it is explicitly set.

Test: fast/table/center-th-when-parent-has-initial-text-align.html

* css/CSSProperties.json:
* css/StyleBuilderCustom.h:
(WebCore::StyleBuilderCustom::applyInitialTextAlign):
(WebCore::StyleBuilderCustom::applyValueTextAlign):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::adjustRenderStyle):
(WebCore::StyleResolver::applyProperty):
* rendering/style/RenderStyle.h:
(WebCore::RenderStyle::hasExplicitlySetTextAlign):
(WebCore::RenderStyle::setHasExplicitlySetTextAlign):
(WebCore::RenderStyle::NonInheritedFlags::hasExplicitlySetTextAlign):
(WebCore::RenderStyle::NonInheritedFlags::setHasExplicitlySetTextAlign):

LayoutTests:

* fast/table/center-th-when-parent-has-initial-text-align-expected.html: Added.
* fast/table/center-th-when-parent-has-initial-text-align.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/table/center-th-when-parent-has-initial-text-align-expected.html [new file with mode: 0644]
LayoutTests/fast/table/center-th-when-parent-has-initial-text-align.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSProperties.json
Source/WebCore/css/StyleBuilderCustom.h
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/rendering/style/RenderStyle.h

index 1d2f6b5..1ea9553 100644 (file)
@@ -1,3 +1,14 @@
+2017-04-14  Zalan Bujtas  <zalan@apple.com>
+
+        text-align start / end failure in table cells
+        https://bugs.webkit.org/show_bug.cgi?id=141417
+        <rdar://problem/31051672>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/table/center-th-when-parent-has-initial-text-align-expected.html: Added.
+        * fast/table/center-th-when-parent-has-initial-text-align.html: Added.
+
 2017-04-13  Saam Barati  <sbarati@apple.com>
 
         WebAssembly: We should be able to postMessage a JSWebAssemblyModule
diff --git a/LayoutTests/fast/table/center-th-when-parent-has-initial-text-align-expected.html b/LayoutTests/fast/table/center-th-when-parent-has-initial-text-align-expected.html
new file mode 100644 (file)
index 0000000..6f388a7
--- /dev/null
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that th is text-align centered when parent has initial value.</title>
+<style>
+    table { 
+    width: 500px; border: 1px solid green; 
+}
+</style>
+<table><tbody>
+    <tr><th style="text-align: center">no explicit style</th></tr>
+    <tr><th style="text-align: left">th initial</th></tr>
+    <tr><th style="text-align: left">th start</th></tr>
+    <tr><th style="text-align: center">th center</th></tr>
+    <tr><th style="text-align: right">th end</th></tr>
+    <tr><th style="text-align: center">tr initial</th></tr>
+    <tr><th style="text-align: center">tr start</th></tr>
+    <tr><th style="text-align: center">tr center</th></tr>
+    <tr><th style="text-align: right">tr end</th></tr>
+    <tr><th style="text-align: left">tr initial, th initial</th></tr>
+    <tr><th style="text-align: left">tr initial, th start</th></tr>
+    <tr><th style="text-align: left">tr start, th start</th></tr>
+    <tr><th style="text-align: left">tr end, th initial</th></tr>
+    <tr><th style="text-align: left">tr end, th start</th></tr>
+</tbody></table>
+</body>
+</html>
diff --git a/LayoutTests/fast/table/center-th-when-parent-has-initial-text-align.html b/LayoutTests/fast/table/center-th-when-parent-has-initial-text-align.html
new file mode 100644 (file)
index 0000000..1c91d44
--- /dev/null
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that th is text-align centered when parent has initial value.</title>
+<style>
+    table { 
+    width: 500px; border: 1px solid green; 
+}
+</style>
+<table><tbody>
+    <tr><th>no explicit style</th></tr>
+    <tr><th style="text-align: initial">th initial</th></tr>
+    <tr><th style="text-align: start">th start</th></tr>
+    <tr><th style="text-align: center">th center</th></tr>
+    <tr><th style="text-align: end">th end</th></tr>
+    <tr style="text-align: initial"><th>tr initial</th></tr>
+    <tr style="text-align: start"><th>tr start</th></tr>
+    <tr style="text-align: center"><th>tr center</th></tr>
+    <tr style="text-align: end"><th>tr end</th></tr>
+    <tr style="text-align: initial"><th style="text-align: initial">tr initial, th initial</th></tr>
+    <tr style="text-align: initial"><th style="text-align: start">tr initial, th start</th></tr>
+    <tr style="text-align: start"><th style="text-align: start">tr start, th start</th></tr>
+    <tr style="text-align: end"><th style="text-align: initial">tr end, th initial</th></tr>
+    <tr style="text-align: end"><th style="text-align: start">tr end, th start</th></tr>
+</tbody></table>
+</body>
+</html>
index de10e13..75881b1 100644 (file)
@@ -1,3 +1,29 @@
+2017-04-14  Zalan Bujtas  <zalan@apple.com>
+
+        text-align start / end failure in table cells
+        https://bugs.webkit.org/show_bug.cgi?id=141417
+        <rdar://problem/31051672>
+
+        Reviewed by Antti Koivisto.
+
+        Apply "text-align: center" on th elements when parent's computed value for the 'text-align' property
+        is its initial value, unless it is explicitly set.
+
+        Test: fast/table/center-th-when-parent-has-initial-text-align.html
+
+        * css/CSSProperties.json:
+        * css/StyleBuilderCustom.h:
+        (WebCore::StyleBuilderCustom::applyInitialTextAlign):
+        (WebCore::StyleBuilderCustom::applyValueTextAlign):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::adjustRenderStyle):
+        (WebCore::StyleResolver::applyProperty):
+        * rendering/style/RenderStyle.h:
+        (WebCore::RenderStyle::hasExplicitlySetTextAlign):
+        (WebCore::RenderStyle::setHasExplicitlySetTextAlign):
+        (WebCore::RenderStyle::NonInheritedFlags::hasExplicitlySetTextAlign):
+        (WebCore::RenderStyle::NonInheritedFlags::setHasExplicitlySetTextAlign):
+
 2017-04-14  Andy Estes  <aestes@apple.com>
 
         [ios-simulator] API test WebKit2.DataDetectionReferenceDate timing out
index 2d977a3..c54438b 100644 (file)
                 }
             ],
             "codegen-properties": {
-                "converter": "TextAlign"
+                "converter": "TextAlign",
+                "custom": "Initial|Value"
             },
             "specification": {
                 "category": "css-22",
index 52b95ef..802f1fb 100644 (file)
@@ -126,6 +126,8 @@ public:
     static void applyValueBaselineShift(StyleResolver&, CSSValue&);
     static void applyValueDirection(StyleResolver&, CSSValue&);
     static void applyValueVerticalAlign(StyleResolver&, CSSValue&);
+    static void applyInitialTextAlign(StyleResolver&);
+    static void applyValueTextAlign(StyleResolver&, CSSValue&);
 #if ENABLE(DASHBOARD_SUPPORT)
     static void applyValueWebkitDashboardRegion(StyleResolver&, CSSValue&);
 #endif
@@ -170,6 +172,18 @@ inline void StyleBuilderCustom::applyValueDirection(StyleResolver& styleResolver
     styleResolver.style()->setHasExplicitlySetDirection(true);
 }
 
+inline void StyleBuilderCustom::applyInitialTextAlign(StyleResolver& styleResolver)
+{
+    styleResolver.style()->setTextAlign(RenderStyle::initialTextAlign());
+    styleResolver.style()->setHasExplicitlySetTextAlign(true);
+}
+
+inline void StyleBuilderCustom::applyValueTextAlign(StyleResolver& styleResolver, CSSValue& value)
+{
+    styleResolver.style()->setTextAlign(StyleBuilderConverter::convertTextAlign(styleResolver, value));
+    styleResolver.style()->setHasExplicitlySetTextAlign(true);
+}
+
 inline void StyleBuilderCustom::resetEffectiveZoom(StyleResolver& styleResolver)
 {
     // Reset the zoom in effect. This allows the setZoom method to accurately compute a new zoom in effect.
index 1abfe9b..a33dc71 100644 (file)
@@ -844,9 +844,11 @@ void StyleResolver::adjustRenderStyle(RenderStyle& style, const RenderStyle& par
                 style.setFloating(NoFloat);
             }
 
-            // FIXME: We shouldn't be overriding start/-webkit-auto like this. Do it in html.css instead.
-            // Table headers with a text-align of -webkit-auto will change the text-align to center.
-            if (element->hasTagName(thTag) && style.textAlign() == TASTART)
+            // User agents are expected to have a rule in their user agent stylesheet that matches th elements that have a parent
+            // node whose computed value for the 'text-align' property is its initial value, whose declaration block consists of
+            // just a single declaration that sets the 'text-align' property to the value 'center'.
+            // https://html.spec.whatwg.org/multipage/rendering.html#rendering
+            if (element->hasTagName(thTag) && !style.hasExplicitlySetTextAlign() && parentStyle.textAlign() == RenderStyle::initialTextAlign())
                 style.setTextAlign(CENTER);
 
             if (element->hasTagName(legendTag))
index fdede46..e4657b1 100644 (file)
@@ -1393,6 +1393,9 @@ public:
     bool hasExplicitlySetWritingMode() const { return m_nonInheritedFlags.hasExplicitlySetWritingMode(); }
     void setHasExplicitlySetWritingMode(bool v) { m_nonInheritedFlags.setHasExplicitlySetWritingMode(v); }
 
+    bool hasExplicitlySetTextAlign() const { return m_nonInheritedFlags.hasExplicitlySetTextAlign(); }
+    void setHasExplicitlySetTextAlign(bool value) { m_nonInheritedFlags.setHasExplicitlySetTextAlign(value); }
+
     // A unique style is one that has matches something that makes it impossible to share.
     bool unique() const { return m_nonInheritedFlags.isUnique(); }
     void setUnique() { m_nonInheritedFlags.setIsUnique(); }
@@ -1806,6 +1809,9 @@ private:
         bool hasExplicitlySetWritingMode() const { return getBoolean(hasExplicitlySetWritingModeOffset); }
         void setHasExplicitlySetWritingMode(bool value) { updateBoolean(value, hasExplicitlySetWritingModeOffset); }
 
+        bool hasExplicitlySetTextAlign() const { return getBoolean(hasExplicitlySetTextAlignOffset); }
+        void setHasExplicitlySetTextAlign(bool value) { updateBoolean(value, hasExplicitlySetTextAlignOffset); }
+
         static ptrdiff_t flagsMemoryOffset() { return OBJECT_OFFSETOF(NonInheritedFlags, m_flags); }
         static uint64_t flagIsaffectedByActive() { return oneBitMask << affectedByActiveOffset; }
         static uint64_t flagIsaffectedByHover() { return oneBitMask << affectedByHoverOffset; }
@@ -1880,11 +1886,13 @@ private:
         static const unsigned hasViewportUnitsOffset = pseudoBitsOffset + pseudoBitsBitCount;
 
         // Byte 7.
+        static const unsigned hasExplicitlySetTextAlignBitCount = 1;
+        static const unsigned hasExplicitlySetTextAlignOffset = hasViewportUnitsOffset + hasViewportUnitsBitCount;
         static const unsigned styleTypeBitCount = 6;
-        static const unsigned styleTypePadding = 2;
+        static const unsigned styleTypePadding = 1;
         static const unsigned styleTypeAndPaddingBitCount = styleTypeBitCount + styleTypePadding;
         static const uint64_t styleTypeMask = (oneBitMask << styleTypeAndPaddingBitCount) - 1;
-        static const unsigned styleTypeOffset = hasViewportUnitsBitCount + hasViewportUnitsOffset;
+        static const unsigned styleTypeOffset = hasExplicitlySetTextAlignOffset + hasExplicitlySetTextAlignBitCount;
 
         // Byte 8.
         static const unsigned isUniqueOffset = styleTypeOffset + styleTypeAndPaddingBitCount;