Add runtime flag to enable/disable CSS variables (in addition to existing compile...
authormacpherson@chromium.org <macpherson@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2012 05:23:57 +0000 (05:23 +0000)
committermacpherson@chromium.org <macpherson@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2012 05:23:57 +0000 (05:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=89542

Reviewed by Dimitri Glazkov.

Source/WebCore:

Added fast/css/variables/build-supports-variables.html to test runtime flag in test environment.
Updated all other css variables tests to enable the runtime flag from JS.

* css/CSSParser.cpp:
(WebCore::CSSParserContext::CSSParserContext):
(WebCore::operator==):
(WebCore::CSSParser::cssVariablesEnabled):
(WebCore):
(WebCore::CSSParser::detectDashToken):
(WebCore::CSSParser::lex):
* css/CSSParser.h:
(CSSParser):
* css/CSSParserMode.h:
(CSSParserContext):
* page/Settings.h:
(Settings):
(WebCore::Settings::setCSSVariablesEnabled):
(WebCore::Settings::cssVariablesEnabled):

Source/WebKit/chromium:

* features.gypi:
* public/WebSettings.h:
* src/WebSettingsImpl.cpp:
(WebKit::WebSettingsImpl::setExperimentalCSSVariablesEnabled):
(WebKit):
* src/WebSettingsImpl.h:
(WebSettingsImpl):

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

32 files changed:
LayoutTests/fast/css/variables/border-width.html
LayoutTests/fast/css/variables/build-supports-variables-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/variables/build-supports-variables.html [new file with mode: 0644]
LayoutTests/fast/css/variables/colors-test.html
LayoutTests/fast/css/variables/complex-cycle.html
LayoutTests/fast/css/variables/computed-style.html
LayoutTests/fast/css/variables/inherited-values.html
LayoutTests/fast/css/variables/inline-styles.html
LayoutTests/fast/css/variables/invalid-shorthand.html
LayoutTests/fast/css/variables/invalid-variable-value.html
LayoutTests/fast/css/variables/multi-level-cycle.html
LayoutTests/fast/css/variables/redefinition.html
LayoutTests/fast/css/variables/shorthand.html
LayoutTests/fast/css/variables/simple-cycle.html
LayoutTests/fast/css/variables/transform-test.html
LayoutTests/fast/css/variables/undefined.html
LayoutTests/fast/css/variables/use-before-defined.html
LayoutTests/fast/css/variables/var-inside-shorthand.html
LayoutTests/fast/css/variables/variable-chain.html
Source/WebCore/ChangeLog
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSParser.h
Source/WebCore/css/CSSParserMode.h
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/page/Settings.h
Source/WebCore/testing/InternalSettings.cpp
Source/WebCore/testing/InternalSettings.h
Source/WebCore/testing/InternalSettings.idl
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebSettings.h
Source/WebKit/chromium/src/WebSettingsImpl.cpp
Source/WebKit/chromium/src/WebSettingsImpl.h

index 235c127..ff31300 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 div {
   border-color: green;
diff --git a/LayoutTests/fast/css/variables/build-supports-variables-expected.txt b/LayoutTests/fast/css/variables/build-supports-variables-expected.txt
new file mode 100644 (file)
index 0000000..f033a50
--- /dev/null
@@ -0,0 +1 @@
+YES
diff --git a/LayoutTests/fast/css/variables/build-supports-variables.html b/LayoutTests/fast/css/variables/build-supports-variables.html
new file mode 100644 (file)
index 0000000..4900cb5
--- /dev/null
@@ -0,0 +1,9 @@
+<body>NO</body>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+internals.settings.setCSSVariablesEnabled(true);
+if (internals.settings.cssVariablesEnabled())
+    document.body.innerHTML = "YES";
+</script>
index aede39d..aafdb27 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 body {
     -webkit-var-foreground: green;
index 01a7699..359c8bf 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 body {
     -webkit-var-a: -webkit-var(f);
index 07b481e..c4d642f 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 body {
     -webkit-var-a: bold;
index 59bfaca..a2e3f09 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 body {
     -webkit-var-foreground: green;
index 9a1be6b..1dc23bd 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <body style="-webkit-var-a: green;">
 <div style="color: -webkit-var(a);">
 This text should be green on a white background.
index c98e4d3..57ff7ee 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 div {
     -webkit-var-a: 10px solid green;
index 4cd0757..de18d79 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 div {
     -webkit-var-a: green;
index 6c864a0..3772b14 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 .a {
     -webkit-var-a: -webkit-var(b);
index e438f5a..a0218b1 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 body {
     -webkit-var-a: red;
index 5d2992e..58abfb0 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 div {
     -webkit-var-myborder: 10px solid green;
index 4d1e63f..6a8f3fc 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 body {
     -webkit-var-a: -webkit-var(a);
index cc63ce4..310ed3d 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 div {
     display: inline-block;
index 7743104..0db9e73 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 body {
     border: -webkit-var(myborder);
index bba41be..3b2689c 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 div {
     color: -webkit-var(a);
index 069a58f..c2a790b 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 body {
     -webkit-var-MyBorderColor: green;
index a15d5bc..c432605 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
 <style>
 body {
     -webkit-var-c: green;
index e0fde22..6c4367f 100644 (file)
@@ -1,3 +1,29 @@
+2012-06-25  Luke Macpherson  <macpherson@chromium.org>
+
+        Add runtime flag to enable/disable CSS variables (in addition to existing compile-time flag).
+        https://bugs.webkit.org/show_bug.cgi?id=89542
+
+        Reviewed by Dimitri Glazkov.
+
+        Added fast/css/variables/build-supports-variables.html to test runtime flag in test environment.
+        Updated all other css variables tests to enable the runtime flag from JS.
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParserContext::CSSParserContext):
+        (WebCore::operator==):
+        (WebCore::CSSParser::cssVariablesEnabled):
+        (WebCore):
+        (WebCore::CSSParser::detectDashToken):
+        (WebCore::CSSParser::lex):
+        * css/CSSParser.h:
+        (CSSParser):
+        * css/CSSParserMode.h:
+        (CSSParserContext):
+        * page/Settings.h:
+        (Settings):
+        (WebCore::Settings::setCSSVariablesEnabled):
+        (WebCore::Settings::cssVariablesEnabled):
+
 2012-06-25  Simon Hausmann  <simon.hausmann@nokia.com>
 
         Unreviewed build fix after r121223.
index a2ccb77..262ace4 100644 (file)
@@ -194,6 +194,9 @@ CSSParserContext::CSSParserContext(CSSParserMode mode, const KURL& baseURL)
     , isCSSCustomFilterEnabled(false)
     , isCSSRegionsEnabled(false)
     , isCSSGridLayoutEnabled(false)
+#if ENABLE(CSS_VARIABLES)
+    , isCSSVariablesEnabled(false)
+#endif
     , needsSiteSpecificQuirks(false)
     , enforcesCSSMIMETypeInNoQuirksMode(true)
 {
@@ -207,6 +210,9 @@ CSSParserContext::CSSParserContext(Document* document, const KURL& baseURL, cons
     , isCSSCustomFilterEnabled(document->settings() ? document->settings()->isCSSCustomFilterEnabled() : false)
     , isCSSRegionsEnabled(document->cssRegionsEnabled())
     , isCSSGridLayoutEnabled(document->cssGridLayoutEnabled())
+#if ENABLE(CSS_VARIABLES)
+    , isCSSVariablesEnabled(document->settings() ? document->settings()->cssVariablesEnabled() : false)
+#endif
     , needsSiteSpecificQuirks(document->settings() ? document->settings()->needsSiteSpecificQuirks() : false)
     , enforcesCSSMIMETypeInNoQuirksMode(!document->settings() || document->settings()->enforceCSSMIMETypeInNoQuirksMode())
 {
@@ -221,6 +227,9 @@ bool operator==(const CSSParserContext& a, const CSSParserContext& b)
         && a.isCSSCustomFilterEnabled == b.isCSSCustomFilterEnabled
         && a.isCSSRegionsEnabled == b.isCSSRegionsEnabled
         && a.isCSSGridLayoutEnabled == b.isCSSGridLayoutEnabled
+#if ENABLE(CSS_VARIABLES)
+        && a.isCSSVariablesEnabled == b.isCSSVariablesEnabled
+#endif
         && a.needsSiteSpecificQuirks == b.needsSiteSpecificQuirks
         && a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode;
 }
@@ -1082,6 +1091,25 @@ PassRefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& strin
     return static_pointer_cast<CSSValueList>(dummyStyle->getPropertyCSSValue(CSSPropertyFontFamily));
 }
 
+#if ENABLE(CSS_VARIABLES)
+bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, Document* document)
+{
+    ASSERT(!string.isEmpty());
+
+    CSSParserContext context(document);
+
+    if (parseSimpleLengthValue(declaration, propertyID, string, important, context.mode))
+        return true;
+    if (parseColorValue(declaration, propertyID, string, important, context.mode))
+        return true;
+    if (parseKeywordValue(declaration, propertyID, string, important, context))
+        return true;
+
+    CSSParser parser(context);
+    return parser.parseValue(declaration, propertyID, string, important, static_cast<StyleSheetContents*>(0));
+}
+#endif
+
 bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
 {
     ASSERT(!string.isEmpty());
@@ -2968,6 +2996,11 @@ bool CSSParser::parseFillShorthand(CSSPropertyID propId, const CSSPropertyID* pr
 }
 
 #if ENABLE(CSS_VARIABLES)
+bool CSSParser::cssVariablesEnabled() const
+{
+    return m_context.isCSSVariablesEnabled;
+}
+
 void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr<CSSParserValueList> value, bool important)
 {
     StringBuilder builder;
@@ -8597,7 +8630,7 @@ inline void CSSParser::detectDashToken(int length)
         else if (isASCIIAlphaCaselessEqual(name[10], 'x') && isEqualToCSSIdentifier(name + 1, "webkit-ma"))
             m_token = MAXFUNCTION;
 #if ENABLE(CSS_VARIABLES)
-        else if (isASCIIAlphaCaselessEqual(name[10], 'r') && isEqualToCSSIdentifier(name + 1, "webkit-va"))
+        else if (cssVariablesEnabled() && isASCIIAlphaCaselessEqual(name[10], 'r') && isEqualToCSSIdentifier(name + 1, "webkit-va"))
             m_token = VARFUNCTION;
 #endif
     } else if (length == 12 && isEqualToCSSIdentifier(name + 1, "webkit-calc"))
@@ -8939,7 +8972,7 @@ restartAfterComment:
 
     case CharacterDash:
 #if ENABLE(CSS_VARIABLES)
-        if (m_currentCharacter[10] == '-' && isEqualToCSSIdentifier(m_currentCharacter, "webkit-var") && isIdentifierStartAfterDash(m_currentCharacter + 11)) {
+        if (cssVariablesEnabled() && m_currentCharacter[10] == '-' && isEqualToCSSIdentifier(m_currentCharacter, "webkit-var") && isIdentifierStartAfterDash(m_currentCharacter + 11)) {
             // handle variable declarations
             m_currentCharacter += 11;
             parseIdentifier(result, hasEscape);
index b037f03..625e1e0 100644 (file)
@@ -92,6 +92,8 @@ public:
     bool parseQuotes(CSSPropertyID, bool important);
 
 #if ENABLE(CSS_VARIABLES)
+    static bool parseValue(StylePropertySet*, CSSPropertyID, const String&, bool important, Document*);
+    bool cssVariablesEnabled() const;
     void storeVariableDeclaration(const CSSParserString&, PassOwnPtr<CSSParserValueList>, bool important);
 #endif
 
index d9200b7..5228e98 100644 (file)
@@ -65,6 +65,9 @@ struct CSSParserContext {
     bool isCSSCustomFilterEnabled;
     bool isCSSRegionsEnabled;
     bool isCSSGridLayoutEnabled;
+#if ENABLE(CSS_VARIABLES)
+    bool isCSSVariablesEnabled;
+#endif
     bool needsSiteSpecificQuirks;
     bool enforcesCSSMIMETypeInNoQuirksMode;
 };
index 2a077dd..de3a0a9 100644 (file)
@@ -3325,7 +3325,7 @@ void StyleResolver::resolveVariables(CSSPropertyID id, CSSValue* value, Vector<s
 
     // FIXME: It would be faster not to re-parse from strings, but for now CSS property validation lives inside the parser so we do it there.
     RefPtr<StylePropertySet> resultSet = StylePropertySet::create();
-    if (!CSSParser::parseValue(resultSet.get(), id, expression.second, false, CSSStrictMode, 0))
+    if (!CSSParser::parseValue(resultSet.get(), id, expression.second, false, document()))
         return; // expression failed to parse.
 
     for (unsigned i = 0; i < resultSet->propertyCount(); i++) {
index d846fa0..3dc45bc 100644 (file)
@@ -331,6 +331,14 @@ namespace WebCore {
         bool cssRegionsEnabled() const { return false; }
 #endif
 
+#if ENABLE(CSS_VARIABLES)
+        void setCSSVariablesEnabled(bool enabled) { m_cssVariablesEnabled = enabled; }
+        bool cssVariablesEnabled() const { return true; }
+#else
+        void setCSSVariablesEnabled(bool) { }
+        bool cssVariablesEnabled() const { return false; }
+#endif
+
         void setRegionBasedColumnsEnabled(bool enabled) { m_regionBasedColumnsEnabled = enabled; }
         bool regionBasedColumnsEnabled() const { return m_regionBasedColumnsEnabled; }
 
@@ -677,6 +685,9 @@ namespace WebCore {
 #if ENABLE(CSS_REGIONS)
         bool m_cssRegionsEnabled : 1;
 #endif
+#if ENABLE(CSS_VARIABLES)
+        bool m_cssVariablesEnabled : 1;
+#endif
         bool m_regionBasedColumnsEnabled : 1;
         bool m_cssGridLayoutEnabled : 1;
         bool m_downloadableBinaryFontsEnabled : 1;
index 71d0013..bf43923 100644 (file)
@@ -348,6 +348,18 @@ void InternalSettings::setCSSExclusionsEnabled(bool enabled, ExceptionCode& ec)
     RuntimeEnabledFeatures::setCSSExclusionsEnabled(enabled);
 }
 
+void InternalSettings::setCSSVariablesEnabled(bool enabled, ExceptionCode& ec)
+{
+    InternalSettingsGuardForSettings();
+    settings()->setCSSVariablesEnabled(enabled);
+}
+
+bool InternalSettings::cssVariablesEnabled(ExceptionCode& ec)
+{
+    InternalSettingsGuardForSettingsReturn(false);
+    return settings()->cssVariablesEnabled();
+}
+
 void InternalSettings::setMediaPlaybackRequiresUserGesture(bool enabled, ExceptionCode& ec)
 {
     InternalSettingsGuardForSettings();
index a87f96f..127da42 100644 (file)
@@ -75,6 +75,8 @@ public:
     void setEnableScrollAnimator(bool enabled, ExceptionCode&);
     bool scrollAnimatorEnabled(ExceptionCode&);
     void setCSSExclusionsEnabled(bool enabled, ExceptionCode&);
+    void setCSSVariablesEnabled(bool enabled, ExceptionCode&);
+    bool cssVariablesEnabled(ExceptionCode&);
     void setMediaPlaybackRequiresUserGesture(bool, ExceptionCode&);
     void setEditingBehavior(const String&, ExceptionCode&);
     void setFixedPositionCreatesStackingContext(bool, ExceptionCode&);
index 0af538a..1965f05 100644 (file)
@@ -54,6 +54,8 @@ module window {
         void setEnableScrollAnimator(in boolean enabled) raises(DOMException);
         boolean scrollAnimatorEnabled() raises(DOMException);
         void setCSSExclusionsEnabled(in boolean enabled) raises(DOMException);
+        void setCSSVariablesEnabled(in boolean enabled) raises(DOMException);
+        boolean cssVariablesEnabled() raises(DOMException);
         void setMediaPlaybackRequiresUserGesture(in boolean enabled) raises(DOMException);
         void setEditingBehavior(in DOMString behavior) raises(DOMException);
         void setFixedPositionCreatesStackingContext(in boolean creates) raises(DOMException);
index 5ac96ef..b653ebd 100644 (file)
@@ -1,3 +1,18 @@
+2012-06-25  Luke Macpherson  <macpherson@chromium.org>
+
+        Add runtime flag to enable/disable CSS variables (in addition to existing compile-time flag).
+        https://bugs.webkit.org/show_bug.cgi?id=89542
+
+        Reviewed by Dimitri Glazkov.
+
+        * features.gypi:
+        * public/WebSettings.h:
+        * src/WebSettingsImpl.cpp:
+        (WebKit::WebSettingsImpl::setExperimentalCSSVariablesEnabled):
+        (WebKit):
+        * src/WebSettingsImpl.h:
+        (WebSettingsImpl):
+
 2012-06-25  Adrienne Walker  <enne@google.com>
 
         [chromium] Add WebPluginScrollbar and WebPluginScrollbarClient stub implementations
index bab5c38..5ec5c50 100644 (file)
@@ -105,6 +105,7 @@ public:
     virtual void setExperimentalCSSRegionsEnabled(bool) = 0;
     virtual void setExperimentalCSSGridLayoutEnabled(bool) = 0;
     virtual void setExperimentalCSSCustomFilterEnabled(bool) = 0;
+    virtual void setExperimentalCSSVariablesEnabled(bool) = 0;
     virtual void setOpenGLMultisamplingEnabled(bool) = 0;
     virtual void setPrivilegedWebGLExtensionsEnabled(bool) = 0;
     virtual void setWebGLErrorsToConsoleEnabled(bool) = 0;
index 43c433c..e4d3ad8 100644 (file)
@@ -338,6 +338,11 @@ void WebSettingsImpl::setExperimentalCSSCustomFilterEnabled(bool enabled)
     m_settings->setCSSCustomFilterEnabled(enabled);
 }
 
+void WebSettingsImpl::setExperimentalCSSVariablesEnabled(bool enabled)
+{
+    m_settings->setCSSVariablesEnabled(enabled);
+}
+
 void WebSettingsImpl::setOpenGLMultisamplingEnabled(bool enabled)
 {
     m_settings->setOpenGLMultisamplingEnabled(enabled);
index 9a65c2a..ddd8911 100644 (file)
@@ -97,6 +97,7 @@ public:
     virtual void setExperimentalCSSRegionsEnabled(bool);
     virtual void setExperimentalCSSGridLayoutEnabled(bool);
     virtual void setExperimentalCSSCustomFilterEnabled(bool);
+    virtual void setExperimentalCSSVariablesEnabled(bool);
     virtual void setOpenGLMultisamplingEnabled(bool);
     virtual void setPrivilegedWebGLExtensionsEnabled(bool);
     virtual void setWebGLErrorsToConsoleEnabled(bool);