Implement CSSSupportsRule
https://bugs.webkit.org/show_bug.cgi?id=104822

Patch by Pablo Flouret <pablof@motorola.com> on 2013-01-16
Reviewed by Allan Sandfeld Jensen.

Source/WebCore:

http://dev.w3.org/csswg/css3-conditional/#the-csssupportsrule-interface

Right now, @supports is not implemented as a proper CSSRule. Apart from
the CSSOM implications it gives wrong results when, for instance, an
@supports rule is nested inside a @media rule.

Test: css3/supports-cssom.html

* CMakeLists.txt:
* DerivedSources.cpp:
* DerivedSources.make:
* DerivedSources.pri:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.exp.in:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
    Add CSSSupportsRule.* and associated files.

* bindings/js/JSCSSRuleCustom.cpp:
(WebCore::toJS):
* bindings/objc/DOMCSS.mm:
(kitClass):
* bindings/v8/custom/V8CSSRuleCustom.cpp:
(WebCore::wrap):
    Create the correct wrappers for the rule.

* css/CSSGrammar.y.in:
* css/CSSParser.cpp:
(WebCore::CSSParser::createSupportsRule):
(WebCore::CSSParser::markSupportsRuleHeaderStart):
(WebCore::CSSParser::markSupportsRuleHeaderEnd):
* css/CSSParser.h:
    Create the supports rule when parsing and add it where it corresponds,
    instead of directly adding the child rules to the stylesheet.

* css/CSSPropertySourceData.h:
* css/CSSRule.h:
* css/CSSRule.idl:
    Add SUPPORTS_RULE type to enums.

* css/CSSSupportsRule.cpp: Added.
(WebCore::CSSSupportsRule::CSSSupportsRule):
(WebCore::CSSSupportsRule::~CSSSupportsRule):
(WebCore::CSSSupportsRule::cssText):
(WebCore::CSSSupportsRule::conditionText):
* css/CSSSupportsRule.h: Added.
(WebCore::CSSSupportsRule::create):
* css/CSSSupportsRule.idl: Added.
    DOM interface.

* css/RuleSet.cpp:
(WebCore::RuleSet::addChildRules):
    Add rules included in the @supports rule.

* css/StyleResolver.cpp:
(WebCore::collectCSSOMWrappers):
    Collect CSSSupportsRule wrappers.

* css/StyleRule.cpp:
(WebCore::StyleRuleBase::reportMemoryUsage):
(WebCore::StyleRuleBase::destroy):
(WebCore::StyleRuleBase::copy):
(WebCore::StyleRuleBase::createCSSOMWrapper):
(WebCore::StyleRuleSupports::StyleRuleSupports):
* css/StyleRule.h:
(StyleRuleBase):
(WebCore::StyleRuleBase::isSupportsRule):
(StyleRuleSupports):
(WebCore::StyleRuleSupports::create):
(WebCore::StyleRuleSupports::conditionText):
(WebCore::StyleRuleSupports::conditionIsSupported):
(WebCore::StyleRuleSupports::copy):
(WebCore::toStyleRuleSupports):
    New subclass of StyleRuleBlock: StyleRuleSupports.

* css/StyleSheetContents.cpp:
(WebCore::childRulesHaveFailedOrCanceledSubresources):
* inspector/InspectorStyleSheet.cpp:
(flattenSourceData):
(WebCore::asCSSRuleList):
    Handle @supports rules where needed.

LayoutTests:

* css3/supports-cssom-expected.txt: Added.
* css3/supports-cssom.html: Added.
* css3/supports-expected.txt:
* css3/supports.html:

* platform/chromium/TestExpectations:
* platform/efl/TestExpectations:
* platform/gtk/TestExpectations:
* platform/mac/TestExpectations:
* platform/qt/TestExpectations:
* platform/win/TestExpectations:
* platform/wincairo/TestExpectations:
* platform/wk2/TestExpectations:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@139866 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/css/CSSSupportsRule.h b/Source/WebCore/css/CSSSupportsRule.h
new file mode 100644
index 0000000..7c5e244
--- /dev/null
+++ b/Source/WebCore/css/CSSSupportsRule.h
@@ -0,0 +1,63 @@
+/* Copyright (C) 2012 Motorola Mobility Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Motorola Mobility Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CSSSupportsRule_h
+#define CSSSupportsRule_h
+
+#include "CSSGroupingRule.h"
+
+#if ENABLE(CSS3_CONDITIONAL_RULES)
+
+namespace WebCore {
+
+class CSSRule;
+class StyleRuleSupports;
+
+class CSSSupportsRule : public CSSGroupingRule {
+public:
+    static PassRefPtr<CSSSupportsRule> create(StyleRuleSupports* rule, CSSStyleSheet* sheet)
+    {
+        return adoptRef(new CSSSupportsRule(rule, sheet));
+    }
+
+    virtual ~CSSSupportsRule() { }
+
+    virtual CSSRule::Type type() const OVERRIDE { return SUPPORTS_RULE; }
+    virtual String cssText() const OVERRIDE;
+
+    String conditionText() const;
+
+private:
+    CSSSupportsRule(StyleRuleSupports*, CSSStyleSheet*);
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(CSS3_CONDITIONAL_RULES)
+
+#endif // CSSSupportsRule_h