[CSS Parser] Add support for @-webkit-region rules
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Oct 2016 16:35:09 +0000 (16:35 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Oct 2016 16:35:09 +0000 (16:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163787

Reviewed by Zalan Bujtas.

* css/StyleRule.cpp:
(WebCore::StyleRuleRegion::StyleRuleRegion):
* css/StyleRule.h:
* css/parser/CSSAtRuleID.cpp:
(WebCore::cssAtRuleID):
* css/parser/CSSAtRuleID.h:
* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::consumeAtRule):
(WebCore::CSSParserImpl::consumePageRule):
(WebCore::CSSParserImpl::consumeRegionRule):
* css/parser/CSSParserImpl.h:

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

Source/WebCore/ChangeLog
Source/WebCore/css/StyleRule.cpp
Source/WebCore/css/StyleRule.h
Source/WebCore/css/parser/CSSAtRuleID.cpp
Source/WebCore/css/parser/CSSAtRuleID.h
Source/WebCore/css/parser/CSSParserImpl.cpp
Source/WebCore/css/parser/CSSParserImpl.h

index a420fc4..4a6d86c 100644 (file)
@@ -1,3 +1,22 @@
+2016-10-21  Dave Hyatt  <hyatt@apple.com>
+
+        [CSS Parser] Add support for @-webkit-region rules
+        https://bugs.webkit.org/show_bug.cgi?id=163787
+
+        Reviewed by Zalan Bujtas.
+
+        * css/StyleRule.cpp:
+        (WebCore::StyleRuleRegion::StyleRuleRegion):
+        * css/StyleRule.h:
+        * css/parser/CSSAtRuleID.cpp:
+        (WebCore::cssAtRuleID):
+        * css/parser/CSSAtRuleID.h:
+        * css/parser/CSSParserImpl.cpp:
+        (WebCore::CSSParserImpl::consumeAtRule):
+        (WebCore::CSSParserImpl::consumePageRule):
+        (WebCore::CSSParserImpl::consumeRegionRule):
+        * css/parser/CSSParserImpl.h:
+
 2016-10-21  David Kilzer  <ddkilzer@apple.com>
 
         Bug 163757: Use IntSize::unclampedArea() in PDFDocumentImage::updateCachedImageIfNeeded()
index 1ec31a8..b1e951c 100644 (file)
@@ -371,6 +371,12 @@ StyleRuleRegion::StyleRuleRegion(Vector<std::unique_ptr<CSSParserSelector>>* sel
     m_selectorList.adoptSelectorVector(*selectors);
 }
 
+StyleRuleRegion::StyleRuleRegion(CSSSelectorList& selectors, Vector<RefPtr<StyleRuleBase>>& adoptRules)
+    : StyleRuleGroup(Region, adoptRules)
+    , m_selectorList(WTFMove(selectors))
+{
+}
+    
 StyleRuleRegion::StyleRuleRegion(const StyleRuleRegion& o)
     : StyleRuleGroup(o)
     , m_selectorList(o.m_selectorList)
index 0bfc02b..6706605 100644 (file)
@@ -236,13 +236,19 @@ public:
     {
         return adoptRef(*new StyleRuleRegion(selectors, adoptRules));
     }
-
+    
+    static Ref<StyleRuleRegion> create(CSSSelectorList& selectors, Vector<RefPtr<StyleRuleBase>>& adoptRules)
+    {
+        return adoptRef(*new StyleRuleRegion(selectors, adoptRules));
+    }
+    
     const CSSSelectorList& selectorList() const { return m_selectorList; }
 
     Ref<StyleRuleRegion> copy() const { return adoptRef(*new StyleRuleRegion(*this)); }
 
 private:
     StyleRuleRegion(Vector<std::unique_ptr<CSSParserSelector>>*, Vector<RefPtr<StyleRuleBase>>& adoptRules);
+    StyleRuleRegion(CSSSelectorList&, Vector<RefPtr<StyleRuleBase>>&);
     StyleRuleRegion(const StyleRuleRegion&);
     
     CSSSelectorList m_selectorList;
index 3f6c6d1..c0c3144 100644 (file)
@@ -56,6 +56,10 @@ CSSAtRuleID cssAtRuleID(StringView name)
         return CSSAtRuleWebkitKeyframes;
     if (equalIgnoringASCIICase(name, "apply"))
         return CSSAtRuleApply;
+#if ENABLE(CSS_REGIONS)
+    if (equalIgnoringASCIICase(name, "-webkit-region"))
+        return CSSAtRuleWebkitRegion;
+#endif
     return CSSAtRuleInvalid;
 }
 
index 9b83a29..e360a7f 100644 (file)
@@ -47,6 +47,7 @@ enum CSSAtRuleID {
 
     CSSAtRuleWebkitKeyframes = 10,
     CSSAtRuleApply = 11,
+    CSSAtRuleWebkitRegion = 12
 };
 
 CSSAtRuleID cssAtRuleID(StringView name);
index c3d7ba9..25e0f6f 100644 (file)
@@ -422,6 +422,10 @@ RefPtr<StyleRuleBase> CSSParserImpl::consumeAtRule(CSSParserTokenRange& range, A
         return consumeKeyframesRule(false, prelude, block);
     case CSSAtRulePage:
         return consumePageRule(prelude, block);
+#if ENABLE(CSS_REGIONS)
+    case CSSAtRuleWebkitRegion:
+        return consumeRegionRule(prelude, block);
+#endif
     default:
         return nullptr; // Parse error, unrecognised at-rule with block
     }
@@ -635,6 +639,32 @@ RefPtr<StyleRulePage> CSSParserImpl::consumePageRule(CSSParserTokenRange prelude
     return page;
 }
 
+#if ENABLE(CSS_REGIONS)
+RefPtr<StyleRuleRegion> CSSParserImpl::consumeRegionRule(CSSParserTokenRange prelude, CSSParserTokenRange block)
+{
+    CSSSelectorList selectorList = CSSSelectorParser::parseSelector(prelude, m_context, m_styleSheet.get());
+    if (!selectorList.isValid())
+        return nullptr; // Parse error, invalid selector list
+
+    if (m_observerWrapper) {
+        m_observerWrapper->observer().startRuleHeader(StyleRule::Region, m_observerWrapper->startOffset(prelude));
+        m_observerWrapper->observer().endRuleHeader(m_observerWrapper->endOffset(prelude));
+        m_observerWrapper->observer().startRuleBody(m_observerWrapper->previousTokenStartOffset(block));
+    }
+    
+    Vector<RefPtr<StyleRuleBase>> rules;
+    consumeRuleList(block, RegularRuleList, [&rules](RefPtr<StyleRuleBase> rule) {
+        rules.append(rule);
+    });
+    
+    if (m_observerWrapper)
+        m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(block));
+    
+    return StyleRuleRegion::create(selectorList, rules);
+
+}
+#endif
+
 // FIXME-NEWPARSER: Support "apply"
 /*void CSSParserImpl::consumeApplyRule(CSSParserTokenRange prelude)
 {
index 2b0869c..c0b1578 100644 (file)
@@ -123,6 +123,9 @@ private:
     RefPtr<StyleRuleFontFace> consumeFontFaceRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
     RefPtr<StyleRuleKeyframes> consumeKeyframesRule(bool webkitPrefixed, CSSParserTokenRange prelude, CSSParserTokenRange block);
     RefPtr<StyleRulePage> consumePageRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
+#if ENABLE(CSS_REGIONS)
+    RefPtr<StyleRuleRegion> consumeRegionRule(CSSParserTokenRange prelude, CSSParserTokenRange block);
+#endif
     // Updates m_parsedProperties
     
     // FIXME-NEWPARSER: Support "apply"