Title: [195560] trunk/Source/WebCore
Revision
195560
Author
[email protected]
Date
2016-01-25 15:33:05 -0800 (Mon, 25 Jan 2016)

Log Message

Resolving direction and writing mode properties should not mutate document
https://bugs.webkit.org/show_bug.cgi?id=153446

Reviewed by Andreas Kling.

Replace directionSetOnDocumentElement/writingModeSetOnDocumentElement document flags them with style flags.

* css/StyleBuilderCustom.h:
(WebCore::StyleBuilderCustom::applyValueDirection):
(WebCore::StyleBuilderCustom::resetEffectiveZoom):
(WebCore::StyleBuilderCustom::applyValueWebkitWritingMode):
(WebCore::StyleBuilderCustom::applyValueWebkitTextOrientation):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::styleForElement):
* dom/Document.cpp:
(WebCore::Document::Document):
* dom/Document.h:
(WebCore::Document::markers):
(WebCore::Document::directionSetOnDocumentElement): Deleted.
(WebCore::Document::writingModeSetOnDocumentElement): Deleted.
(WebCore::Document::setDirectionSetOnDocumentElement): Deleted.
(WebCore::Document::setWritingModeSetOnDocumentElement): Deleted.
* rendering/RenderBox.cpp:
(WebCore::RenderBox::styleDidChange):
* rendering/style/RenderStyle.h:
* style/StyleResolveForDocument.cpp:
(WebCore::Style::resolveForDocument):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (195559 => 195560)


--- trunk/Source/WebCore/ChangeLog	2016-01-25 23:12:44 UTC (rev 195559)
+++ trunk/Source/WebCore/ChangeLog	2016-01-25 23:33:05 UTC (rev 195560)
@@ -1,3 +1,33 @@
+2016-01-25  Antti Koivisto  <[email protected]>
+
+        Resolving direction and writing mode properties should not mutate document
+        https://bugs.webkit.org/show_bug.cgi?id=153446
+
+        Reviewed by Andreas Kling.
+
+        Replace directionSetOnDocumentElement/writingModeSetOnDocumentElement document flags them with style flags.
+
+        * css/StyleBuilderCustom.h:
+        (WebCore::StyleBuilderCustom::applyValueDirection):
+        (WebCore::StyleBuilderCustom::resetEffectiveZoom):
+        (WebCore::StyleBuilderCustom::applyValueWebkitWritingMode):
+        (WebCore::StyleBuilderCustom::applyValueWebkitTextOrientation):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::styleForElement):
+        * dom/Document.cpp:
+        (WebCore::Document::Document):
+        * dom/Document.h:
+        (WebCore::Document::markers):
+        (WebCore::Document::directionSetOnDocumentElement): Deleted.
+        (WebCore::Document::writingModeSetOnDocumentElement): Deleted.
+        (WebCore::Document::setDirectionSetOnDocumentElement): Deleted.
+        (WebCore::Document::setWritingModeSetOnDocumentElement): Deleted.
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::styleDidChange):
+        * rendering/style/RenderStyle.h:
+        * style/StyleResolveForDocument.cpp:
+        (WebCore::Style::resolveForDocument):
+
 2016-01-25  Sam Weinig  <[email protected]>
 
         Fix the ASAN build.

Modified: trunk/Source/WebCore/css/StyleBuilderCustom.h (195559 => 195560)


--- trunk/Source/WebCore/css/StyleBuilderCustom.h	2016-01-25 23:12:44 UTC (rev 195559)
+++ trunk/Source/WebCore/css/StyleBuilderCustom.h	2016-01-25 23:33:05 UTC (rev 195560)
@@ -164,10 +164,7 @@
 inline void StyleBuilderCustom::applyValueDirection(StyleResolver& styleResolver, CSSValue& value)
 {
     styleResolver.style()->setDirection(downcast<CSSPrimitiveValue>(value));
-
-    Element* element = styleResolver.element();
-    if (element && styleResolver.element() == element->document().documentElement())
-        element->document().setDirectionSetOnDocumentElement(true);
+    styleResolver.style()->setHasExplicitlySetDirection(true);
 }
 
 inline void StyleBuilderCustom::resetEffectiveZoom(StyleResolver& styleResolver)
@@ -707,11 +704,7 @@
 inline void StyleBuilderCustom::applyValueWebkitWritingMode(StyleResolver& styleResolver, CSSValue& value)
 {
     styleResolver.setWritingMode(downcast<CSSPrimitiveValue>(value));
-
-    // FIXME: It is not ok to modify document state while applying style.
-    auto& state = styleResolver.state();
-    if (state.element() && state.element() == state.document().documentElement())
-        state.document().setWritingModeSetOnDocumentElement(true);
+    styleResolver.style()->setHasExplicitlySetWritingMode(true);
 }
 
 inline void StyleBuilderCustom::applyValueWebkitTextOrientation(StyleResolver& styleResolver, CSSValue& value)

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (195559 => 195560)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2016-01-25 23:12:44 UTC (rev 195559)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2016-01-25 23:33:05 UTC (rev 195560)
@@ -696,13 +696,6 @@
     m_state = State(element, parentStyle, regionForStyling, selectorFilter);
     State& state = m_state;
 
-    if (&element == m_document.documentElement() && matchingBehavior == MatchAllRules) {
-        // These bits may be set when resolving document element style.
-        // FIXME: Style resolver shouldn't mutate document.
-        m_document.setDirectionSetOnDocumentElement(false);
-        m_document.setWritingModeSetOnDocumentElement(false);
-    }
-
     if (sharingBehavior == AllowStyleSharing) {
         if (RenderStyle* sharedStyle = locateSharedStyle()) {
             state.clear();

Modified: trunk/Source/WebCore/dom/Document.cpp (195559 => 195560)


--- trunk/Source/WebCore/dom/Document.cpp	2016-01-25 23:12:44 UTC (rev 195559)
+++ trunk/Source/WebCore/dom/Document.cpp	2016-01-25 23:33:05 UTC (rev 195560)
@@ -516,8 +516,6 @@
     , m_loadEventDelayCount(0)
     , m_loadEventDelayTimer(*this, &Document::loadEventDelayTimerFired)
     , m_referrerPolicy(ReferrerPolicyDefault)
-    , m_directionSetOnDocumentElement(false)
-    , m_writingModeSetOnDocumentElement(false)
     , m_writeRecursionIsTooDeep(false)
     , m_writeRecursionDepth(0)
     , m_lastHandledUserGestureTimestamp(0)

Modified: trunk/Source/WebCore/dom/Document.h (195559 => 195560)


--- trunk/Source/WebCore/dom/Document.h	2016-01-25 23:12:44 UTC (rev 195559)
+++ trunk/Source/WebCore/dom/Document.h	2016-01-25 23:33:05 UTC (rev 195560)
@@ -932,11 +932,6 @@
 
     DocumentMarkerController& markers() const { return *m_markers; }
 
-    bool directionSetOnDocumentElement() const { return m_directionSetOnDocumentElement; }
-    bool writingModeSetOnDocumentElement() const { return m_writingModeSetOnDocumentElement; }
-    void setDirectionSetOnDocumentElement(bool b) { m_directionSetOnDocumentElement = b; }
-    void setWritingModeSetOnDocumentElement(bool b) { m_writingModeSetOnDocumentElement = b; }
-
     bool execCommand(const String& command, bool userInterface = false, const String& value = String());
     bool queryCommandEnabled(const String& command);
     bool queryCommandIndeterm(const String& command);
@@ -1662,9 +1657,6 @@
 
     ReferrerPolicy m_referrerPolicy;
 
-    bool m_directionSetOnDocumentElement;
-    bool m_writingModeSetOnDocumentElement;
-
 #if ENABLE(WEB_TIMING)
     DocumentTiming m_documentTiming;
 #endif

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (195559 => 195560)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2016-01-25 23:12:44 UTC (rev 195559)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2016-01-25 23:33:05 UTC (rev 195560)
@@ -384,12 +384,13 @@
 
     if (isDocElementRenderer || isBodyRenderer) {
         // Propagate the new writing mode and direction up to the RenderView.
+        auto* documentElementRenderer = document().documentElement()->renderer();
         RenderStyle& viewStyle = view().style();
         bool viewChangedWritingMode = false;
         bool rootStyleChanged = false;
         bool viewStyleChanged = false;
-        RenderObject* rootRenderer = isBodyRenderer ? document().documentElement()->renderer() : nullptr;
-        if (viewStyle.direction() != newStyle.direction() && (isDocElementRenderer || !document().directionSetOnDocumentElement())) {
+        auto* rootRenderer = isBodyRenderer ? documentElementRenderer : nullptr;
+        if (viewStyle.direction() != newStyle.direction() && (isDocElementRenderer || !documentElementRenderer->style().hasExplicitlySetDirection())) {
             viewStyle.setDirection(newStyle.direction());
             viewStyleChanged = true;
             if (isBodyRenderer) {
@@ -399,7 +400,7 @@
             setNeedsLayoutAndPrefWidthsRecalc();
         }
 
-        if (viewStyle.writingMode() != newStyle.writingMode() && (isDocElementRenderer || !document().writingModeSetOnDocumentElement())) {
+        if (viewStyle.writingMode() != newStyle.writingMode() && (isDocElementRenderer || !documentElementRenderer->style().hasExplicitlySetWritingMode())) {
             viewStyle.setWritingMode(newStyle.writingMode());
             viewChangedWritingMode = true;
             viewStyleChanged = true;

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (195559 => 195560)


--- trunk/Source/WebCore/rendering/style/RenderStyle.h	2016-01-25 23:12:44 UTC (rev 195559)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h	2016-01-25 23:33:05 UTC (rev 195560)
@@ -275,6 +275,12 @@
         bool isLink() const { return getBoolean(isLinkOffset); }
         void setIsLink(bool value) { updateBoolean(value, isLinkOffset); }
 
+        bool hasExplicitlySetDirection() const { return getBoolean(hasExplicitlySetDirectionOffset); }
+        void setHasExplicitlySetDirection(bool value) { updateBoolean(value, hasExplicitlySetDirectionOffset); }
+
+        bool hasExplicitlySetWritingMode() const { return getBoolean(hasExplicitlySetWritingModeOffset); }
+        void setHasExplicitlySetWritingMode(bool value) { updateBoolean(value, hasExplicitlySetWritingModeOffset); }
+
         static ptrdiff_t flagsMemoryOffset() { return OBJECT_OFFSETOF(NonInheritedFlags, m_flags); }
         static uint64_t flagIsaffectedByActive() { return oneBitMask << affectedByActiveOffset; }
         static uint64_t flagIsaffectedByHover() { return oneBitMask << affectedByHoverOffset; }
@@ -354,15 +360,17 @@
         static const uint64_t tableLayoutBitMask = oneBitMask;
         static const unsigned tableLayoutOffset = explicitInheritanceOffset + explicitInheritanceBitCount;
         static const unsigned verticalAlignBitCount = 4;
-        static const unsigned verticalAlignPadding = 2;
-        static const unsigned verticalAlignAndPaddingBitCount = verticalAlignBitCount + verticalAlignPadding;
         static const uint64_t verticalAlignMask = (oneBitMask << verticalAlignBitCount) - 1;
         static const unsigned verticalAlignOffset = tableLayoutOffset + tableLayoutBitCount;
+        static const unsigned hasExplicitlySetDirectionBitcount = 1;
+        static const unsigned hasExplicitlySetDirectionOffset = verticalAlignOffset + verticalAlignBitCount;
+        static const unsigned hasExplicitlySetWritingModeBitcount = 1;
+        static const unsigned hasExplicitlySetWritingModeOffset = hasExplicitlySetDirectionOffset + hasExplicitlySetDirectionBitcount;
 
         // Byte 6.
         static const unsigned pseudoBitsBitCount = 7;
         static const uint64_t pseudoBitsMask = (oneBitMask << pseudoBitsBitCount) - 1;
-        static const unsigned pseudoBitsOffset = verticalAlignOffset + verticalAlignBitCount;
+        static const unsigned pseudoBitsOffset = hasExplicitlySetWritingModeOffset + hasExplicitlySetWritingModeBitcount;
 
         static const unsigned hasViewportUnitsBitCount = 1;
         static const uint64_t hasViewportUnitsBitMask = (oneBitMask << hasViewportUnitsBitCount) - 1;
@@ -386,7 +394,7 @@
         static const unsigned isLinkOffset = affectedByDragOffset + 1;
 
 
-        // Only 60 bits are assigned. There are 4 bits available currently used as padding to improve code generation.
+        // Only 60 bits are assigned. There are 2 bits available currently used as padding to improve code generation.
         // If you add more style bits here, you will also need to update RenderStyle::copyNonInheritedFrom().
         uint64_t m_flags;
     };
@@ -744,6 +752,7 @@
 
     TextDirection direction() const { return static_cast<TextDirection>(inherited_flags._direction); }
     bool isLeftToRightDirection() const { return direction() == LTR; }
+    bool hasExplicitlySetDirection() const { return noninherited_flags.hasExplicitlySetDirection(); }
 
     const Length& specifiedLineHeight() const;
     Length lineHeight() const;
@@ -1381,6 +1390,7 @@
     void setTextDecorationSkip(TextDecorationSkip skip) { SET_VAR(rareInheritedData, m_textDecorationSkip, skip); }
     void setTextUnderlinePosition(TextUnderlinePosition v) { SET_VAR(rareInheritedData, m_textUnderlinePosition, v); }
     void setDirection(TextDirection v) { inherited_flags._direction = v; }
+    void setHasExplicitlySetDirection(bool v) { noninherited_flags.setHasExplicitlySetDirection(v); }
 #if ENABLE(IOS_TEXT_AUTOSIZING)
     void setSpecifiedLineHeight(Length v);
 #endif
@@ -1865,6 +1875,9 @@
         return true;
     }
 
+    bool hasExplicitlySetWritingMode() const { return noninherited_flags.hasExplicitlySetWritingMode(); }
+    void setHasExplicitlySetWritingMode(bool v) { noninherited_flags.setHasExplicitlySetWritingMode(v); }
+
     // A unique style is one that has matches something that makes it impossible to share.
     bool unique() const { return noninherited_flags.isUnique(); }
     void setUnique() { noninherited_flags.setIsUnique(); }

Modified: trunk/Source/WebCore/style/StyleResolveForDocument.cpp (195559 => 195560)


--- trunk/Source/WebCore/style/StyleResolveForDocument.cpp	2016-01-25 23:12:44 UTC (rev 195559)
+++ trunk/Source/WebCore/style/StyleResolveForDocument.cpp	2016-01-25 23:33:05 UTC (rev 195560)
@@ -78,11 +78,11 @@
         // If there is no body, then use the document element.
         auto* body = document.bodyOrFrameset();
         RenderObject* bodyRenderer = body ? body->renderer() : nullptr;
-        if (bodyRenderer && !document.writingModeSetOnDocumentElement())
+        if (bodyRenderer && !docElementRenderer->style().hasExplicitlySetWritingMode())
             documentStyle.get().setWritingMode(bodyRenderer->style().writingMode());
         else
             documentStyle.get().setWritingMode(docElementRenderer->style().writingMode());
-        if (bodyRenderer && !document.directionSetOnDocumentElement())
+        if (bodyRenderer && !docElementRenderer->style().hasExplicitlySetDirection())
             documentStyle.get().setDirection(bodyRenderer->style().direction());
         else
             documentStyle.get().setDirection(docElementRenderer->style().direction());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to