[CSSRegions]Flag regions with custom styling
authormihnea@adobe.com <mihnea@adobe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Oct 2011 17:33:07 +0000 (17:33 +0000)
committermihnea@adobe.com <mihnea@adobe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Oct 2011 17:33:07 +0000 (17:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=70733

Reviewed by David Hyatt.

Region elements that have custom region styling are now marked accordingly.

Source/WebCore:

Test: fast/regions/render-region-custom-style-mark.html

* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::checkRegionStyle):
* css/CSSStyleSelector.h:
* rendering/RenderRegion.cpp:
(WebCore::RenderRegion::RenderRegion):
(WebCore::RenderRegion::styleDidChange):
* rendering/RenderRegion.h:
(WebCore::RenderRegion::hasCustomRegionStyle):
(WebCore::RenderRegion::setHasCustomRegionStyle):
* rendering/RenderTreeAsText.cpp:
(WebCore::writeRenderFlowThreads):

LayoutTests:

* fast/regions/render-region-custom-style-mark.html: Added.
* platform/chromium/test_expectations.txt:
* platform/mac-snowleopard/fast/regions/render-region-custom-style-mark-expected.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/regions/render-region-custom-style-mark.html [new file with mode: 0644]
LayoutTests/platform/chromium/test_expectations.txt
LayoutTests/platform/mac-snowleopard/fast/regions/render-region-custom-style-mark-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSStyleSelector.cpp
Source/WebCore/css/CSSStyleSelector.h
Source/WebCore/rendering/RenderRegion.cpp
Source/WebCore/rendering/RenderRegion.h
Source/WebCore/rendering/RenderTreeAsText.cpp

index 7202a57..11aa35b 100755 (executable)
@@ -1,3 +1,16 @@
+2011-10-27  Mihnea Ovidenie  <mihnea@adobe.com>
+
+        [CSSRegions]Flag regions with custom styling
+        https://bugs.webkit.org/show_bug.cgi?id=70733
+
+        Reviewed by David Hyatt.
+
+        Region elements that have custom region styling are now marked accordingly.
+
+        * fast/regions/render-region-custom-style-mark.html: Added.
+        * platform/chromium/test_expectations.txt:
+        * platform/mac-snowleopard/fast/regions/render-region-custom-style-mark-expected.txt: Added.
+
 2011-10-27  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r98556.
diff --git a/LayoutTests/fast/regions/render-region-custom-style-mark.html b/LayoutTests/fast/regions/render-region-custom-style-mark.html
new file mode 100644 (file)
index 0000000..98b16c0
--- /dev/null
@@ -0,0 +1,38 @@
+<!doctype html>
+<html>
+    <!--
+    Tests that regions with region styling rules associated are identified and flagged correctly.
+    -->
+    <head>
+        <style>
+            @-webkit-region #region1 { p { margin-top: 10px; } }
+            @-webkit-region #region2 { p { margin-left: 5px; } }
+
+            #article { -webkit-flow-into: flow1; }
+            #region1, #region2, #region3 { width: 200px; height: 50px; }
+            .region {  -webkit-flow-from: flow1; }
+
+            @-webkit-region #region3 { p { color: red; } }
+        </style>
+    </head>
+    <body>
+        <div id="article">
+            <p>First para goes into region.</p>
+            Text goes into region
+            <p>Second para goes into region.</p>
+            <p>Third para goes into region.</p>
+            Text goes into region
+            <p>Fourth para goes into region.</p>
+        </div>
+        <div id="region1" class="region"></div>
+        <div id="region2" class="region"></div>
+        <div id="region3"></div>
+        <script>
+            // When the element is no longer a region, the region styling should not apply anymore.
+            document.getElementById("region2").className = "";
+            // When the element becomes a region, the region styling should be applied.
+            document.getElementById("region3").className = "region";
+        </script>
+    </body>
+</html>
+
index 257c01c..d559043 100644 (file)
@@ -3329,6 +3329,7 @@ BUGWK62048 SKIP : css3/flexbox = PASS
 
 // CSS Regions support not yet enabled.
 BUGWK57312 SKIP : fast/regions = PASS
+BUGWK70733 SKIP : fast/regions/render-region-custom-style-mark.html = FAIL
 
 // CSS Exclusions support not yet enabled.
 BUGWK57311 SKIP : fast/exclusions = PASS
diff --git a/LayoutTests/platform/mac-snowleopard/fast/regions/render-region-custom-style-mark-expected.txt b/LayoutTests/platform/mac-snowleopard/fast/regions/render-region-custom-style-mark-expected.txt
new file mode 100644 (file)
index 0000000..e674ea9
--- /dev/null
@@ -0,0 +1,34 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x166
+  RenderBlock {HTML} at (0,0) size 800x166
+    RenderBody {BODY} at (8,8) size 784x150
+      RenderRegion {DIV} at (0,0) size 200x50
+      RenderBlock {DIV} at (0,50) size 200x50
+      RenderRegion {DIV} at (0,100) size 200x50
+Flow Threads
+  Thread with flow-name 'flow1'
+    layer at (0,0) size 200x100
+      RenderFlowThread at (0,0) size 200x100
+        RenderBlock {DIV} at (0,16) size 200x188
+          RenderBlock {P} at (0,0) size 200x18
+            RenderText {#text} at (0,0) size 168x18
+              text run at (0,0) width 168: "First para goes into region."
+          RenderBlock (anonymous) at (0,34) size 200x18
+            RenderText {#text} at (0,0) size 134x18
+              text run at (0,0) width 134: "Text goes into region"
+          RenderBlock {P} at (0,68) size 200x18
+            RenderText {#text} at (0,0) size 187x18
+              text run at (0,0) width 187: "Second para goes into region."
+          RenderBlock {P} at (0,102) size 200x18
+            RenderText {#text} at (0,0) size 175x18
+              text run at (0,0) width 175: "Third para goes into region."
+          RenderBlock (anonymous) at (0,136) size 200x18
+            RenderText {#text} at (0,0) size 134x18
+              text run at (0,0) width 134: "Text goes into region"
+          RenderBlock {P} at (0,170) size 200x18
+            RenderText {#text} at (0,0) size 182x18
+              text run at (0,0) width 182: "Fourth para goes into region."
+  Regions for flow 'flow1'
+    RenderRegion {DIV} #region1 region style: 1
+    RenderRegion {DIV} #region3 region style: 1
index a59ae72..2c00f98 100755 (executable)
@@ -1,3 +1,26 @@
+2011-10-27  Mihnea Ovidenie  <mihnea@adobe.com>
+
+        [CSSRegions]Flag regions with custom styling
+        https://bugs.webkit.org/show_bug.cgi?id=70733
+
+        Reviewed by David Hyatt.
+
+        Region elements that have custom region styling are now marked accordingly.
+
+        Test: fast/regions/render-region-custom-style-mark.html
+
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::checkRegionStyle):
+        * css/CSSStyleSelector.h:
+        * rendering/RenderRegion.cpp:
+        (WebCore::RenderRegion::RenderRegion):
+        (WebCore::RenderRegion::styleDidChange):
+        * rendering/RenderRegion.h:
+        (WebCore::RenderRegion::hasCustomRegionStyle):
+        (WebCore::RenderRegion::setHasCustomRegionStyle):
+        * rendering/RenderTreeAsText.cpp:
+        (WebCore::writeRenderFlowThreads):
+
 2011-10-27  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r98556.
index 1d2ec84..63784a2 100644 (file)
@@ -1644,6 +1644,22 @@ void CSSStyleSelector::adjustRenderStyle(RenderStyle* style, RenderStyle* parent
 #endif
 }
 
+bool CSSStyleSelector::checkRegionStyle(Element* e)
+{
+    m_checker.clearHasUnknownPseudoElements();
+    m_checker.setPseudoStyle(NOPSEUDO);
+
+    for (Vector<RefPtr<CSSRegionStyleRule> >::iterator it = m_regionStyleRules.begin(); it != m_regionStyleRules.end(); ++it) {
+        const CSSSelectorList& regionSelectorList = (*it)->selectorList();
+        for (CSSSelector* s = regionSelectorList.first(); s; s = regionSelectorList.next(s)) {
+            if (m_checker.checkSelector(s, e))
+                return true;
+        }
+    }
+
+    return false;
+}
+
 void CSSStyleSelector::updateFont()
 {
     if (!m_fontDirty)
index 7299456..a650907 100644 (file)
@@ -191,6 +191,8 @@ public:
     void addPageStyle(PassRefPtr<CSSPageRule>);
     void addRegionStyleRule(PassRefPtr<CSSRegionStyleRule>);
 
+    bool checkRegionStyle(Element*);
+
     bool usesSiblingRules() const { return m_features.siblingRules; }
     bool usesFirstLineRules() const { return m_features.usesFirstLineRules; }
     bool usesBeforeAfterRules() const { return m_features.usesBeforeAfterRules; }
index 515687b..fe60f69 100644 (file)
@@ -30,6 +30,7 @@
 #include "config.h"
 #include "RenderRegion.h"
 
+#include "CSSStyleSelector.h"
 #include "GraphicsContext.h"
 #include "HitTestResult.h"
 #include "IntRect.h"
@@ -45,6 +46,7 @@ RenderRegion::RenderRegion(Node* node, RenderFlowThread* flowThread)
     , m_flowThread(flowThread)
     , m_parentFlowThread(0)
     , m_isValid(false)
+    , m_hasCustomRegionStyle(false)
 {
 }
 
@@ -127,6 +129,17 @@ bool RenderRegion::nodeAtPoint(const HitTestRequest& request, HitTestResult& res
     return false;
 }
 
+void RenderRegion::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
+{
+    RenderReplaced::styleDidChange(diff, oldStyle);
+    bool customRegionStyle = false;
+    if (node()) {
+        Element* regionElement = static_cast<Element*>(node());
+        customRegionStyle = view()->document()->styleSelector()->checkRegionStyle(regionElement);
+    }
+    setHasCustomRegionStyle(customRegionStyle);
+}
+
 void RenderRegion::layout()
 {
     RenderReplaced::layout();
index ca9c8d6..cc8bd01 100644 (file)
@@ -48,6 +48,8 @@ public:
     virtual void paintReplaced(PaintInfo&, const LayoutPoint&);
     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
 
+    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
+
     void setRegionRect(const LayoutRect& rect) { m_regionRect = rect; }
     LayoutRect regionRect() const { return m_regionRect; }
     LayoutRect regionOverflowRect() const;
@@ -61,6 +63,9 @@ public:
     bool isValid() const { return m_isValid; }
     void setIsValid(bool valid) { m_isValid = valid; }
 
+    bool hasCustomRegionStyle() const { return m_hasCustomRegionStyle; }
+    void setHasCustomRegionStyle(bool hasCustomRegionStyle) { m_hasCustomRegionStyle = hasCustomRegionStyle; }
+
     virtual void layout();
 
     RenderBoxRegionInfo* renderBoxRegionInfo(const RenderBox*) const;
@@ -94,6 +99,7 @@ private:
     HashMap<const RenderBox*, RenderBoxRegionInfo*> m_renderBoxRegionInfo;
 
     bool m_isValid;
+    bool m_hasCustomRegionStyle;
 };
 
 inline RenderRegion* toRenderRegion(RenderObject* object)
index 8ff972c..cb86402 100644 (file)
@@ -687,6 +687,8 @@ static void writeRenderFlowThreads(TextStream& ts, RenderView* renderView, const
                         Element* element = static_cast<Element*>(renderRegion->node());
                         ts << " #" << element->idForStyleResolution();
                     }
+                    if (renderRegion->hasCustomRegionStyle())
+                        ts << " region style: 1";
                 }
                 if (!renderRegion->isValid())
                     ts << " invalid";