Inspector crashes when trying to inspect a page with CSS variables
authormacpherson@chromium.org <macpherson@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2012 00:15:54 +0000 (00:15 +0000)
committermacpherson@chromium.org <macpherson@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2012 00:15:54 +0000 (00:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=89818

Reviewed by Antti Koivisto.

Patch works by fixing treating handling of CSSPropertyID == CSSPropertyVariable as a special case,
and looking up the author-defined property name from the CSSValue.

Added test inspector/styles/variables/css-variables.html that inspects an element using CSS variables.
Test is skipped when variables are compiled out.

* css/CSSProperty.cpp:
(WebCore::CSSProperty::cssName):
(WebCore):
(WebCore::CSSProperty::cssText):
* css/CSSProperty.h:
(CSSProperty):
* css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::PropertySetCSSStyleDeclaration::item):
* css/StylePropertySet.cpp:
(WebCore::StylePropertySet::asText):
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyle::populateAllProperties):

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

16 files changed:
LayoutTests/inspector/styles/variables/css-variables-expected.txt [new file with mode: 0644]
LayoutTests/inspector/styles/variables/css-variables.html [new file with mode: 0644]
LayoutTests/platform/chromium/TestExpectations
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/mac/TestExpectations
LayoutTests/platform/qt/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/css/CSSGrammar.y
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSProperty.cpp
Source/WebCore/css/CSSProperty.h
Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
Source/WebCore/css/StylePropertySet.cpp
Source/WebCore/inspector/InspectorStyleSheet.cpp
Tools/Scripts/webkitpy/layout_tests/port/webkit.py
Tools/Scripts/webkitpy/layout_tests/port/webkit_unittest.py

diff --git a/LayoutTests/inspector/styles/variables/css-variables-expected.txt b/LayoutTests/inspector/styles/variables/css-variables-expected.txt
new file mode 100644 (file)
index 0000000..b9886e3
--- /dev/null
@@ -0,0 +1,24 @@
+Tests that webkit css variables can be loaded correctly.
+
+Text
+[expanded] 
+color: green;
+    #inspected - -webkit-var(a) css-variables.html:7
+display: block;
+    div - block user agent stylesheet
+
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+#inspected  { (css-variables.html:7)
+-webkit-var-a: green;
+color: -webkit-var(a);
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+
diff --git a/LayoutTests/inspector/styles/variables/css-variables.html b/LayoutTests/inspector/styles/variables/css-variables.html
new file mode 100644 (file)
index 0000000..95be549
--- /dev/null
@@ -0,0 +1,40 @@
+<html>
+<head>
+<script>
+internals.settings.setCSSVariablesEnabled(true);
+</script>
+<style>
+#inspected {
+    -webkit-var-a: green;
+    color: -webkit-var(a);
+}
+
+</style>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/elements-test.js"></script>
+<script>
+
+function test()
+{
+    WebInspector.showPanel("elements");
+    InspectorTest.selectNodeAndWaitForStylesWithComputed("inspected", dumpAllStyles);
+
+    function dumpAllStyles()
+    {
+        InspectorTest.dumpSelectedElementStyles();
+        InspectorTest.completeTest();
+    }
+}
+
+</script>
+</head>
+
+<body onload="runTest()">
+<p>
+Tests that webkit css variables can be loaded correctly.
+</p>
+
+<div id="inspected">Text</div>
+
+</body>
+</html>
index ae36986..456c72f 100644 (file)
@@ -158,6 +158,7 @@ BUGGBILLOCK SKIP : webintents/intent-tag.html = PASS
 
 // CSS Variables are not yet enabled.
 BUGWK85580 SKIP : fast/css/variables = PASS
+BUGWK85580 SKIP : inspector/styles/variables = PASS
 
 // CSS image-resolution is not yet enabled.
 BUGWK85262 SKIP : fast/css/image-resolution = PASS
index 1d6a4a4..29cf8a7 100644 (file)
@@ -318,6 +318,7 @@ BUGWK79203 SKIP : fast/mediastream = TEXT
 
 // CSS Variables are not yet enabled.
 BUGWK85580 SKIP : fast/css/variables = PASS TEXT
+BUGWK85580 SKIP : inspector/styles/variables = PASS
 
 // CSS image-resolution is not yet enabled.
 BUGWK85262 SKIP : fast/css/image-resolution = PASS TEXT
index bdeeaac..d296f61 100644 (file)
@@ -11,6 +11,7 @@ BUGWK76439 DEBUG : fast/dom/shadow/content-element-outside-shadow.html = TEXT
 
 // CSS Variables are not yet enabled.
 BUGWK85580 SKIP : fast/css/variables = PASS
+BUGWK85580 SKIP : inspector/styles/variables = PASS
 
 // UndoManager is not yet enabled.
 BUGWK87908 SKIP : editing/undomanager = PASS
index c1c8970..20937a0 100644 (file)
@@ -73,6 +73,7 @@ BUGWK88198 : svg/stroke/non-scaling-stroke-pattern.svg = PASS IMAGE
 
 // CSS Variables are not yet enabled.
 BUGWK85580 SKIP : fast/css/variables = PASS
+BUGWK85580 SKIP : inspector/styles/variables = PASS
 
 // UndoManager is not yet enabled.
 BUGWK87908 SKIP : editing/undomanager = PASS
index a9a647e..3dcfeb3 100644 (file)
@@ -1,3 +1,29 @@
+2012-07-04  Luke Macpherson  <macpherson@chromium.org>
+
+        Inspector crashes when trying to inspect a page with CSS variables
+        https://bugs.webkit.org/show_bug.cgi?id=89818
+
+        Reviewed by Antti Koivisto.
+
+        Patch works by fixing treating handling of CSSPropertyID == CSSPropertyVariable as a special case,
+        and looking up the author-defined property name from the CSSValue.
+
+        Added test inspector/styles/variables/css-variables.html that inspects an element using CSS variables.
+        Test is skipped when variables are compiled out.
+
+        * css/CSSProperty.cpp:
+        (WebCore::CSSProperty::cssName):
+        (WebCore):
+        (WebCore::CSSProperty::cssText):
+        * css/CSSProperty.h:
+        (CSSProperty):
+        * css/PropertySetCSSStyleDeclaration.cpp:
+        (WebCore::PropertySetCSSStyleDeclaration::item):
+        * css/StylePropertySet.cpp:
+        (WebCore::StylePropertySet::asText):
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::InspectorStyle::populateAllProperties):
+
 2012-07-04  Anthony Scian  <ascian@rim.com>
 
         Web Inspector [JSC]: Implement ScriptCallStack::stackTrace
index 827abed..c7c10b5 100644 (file)
@@ -1360,7 +1360,7 @@ declaration:
         CSSParser* p = static_cast<CSSParser*>(parser);
         p->storeVariableDeclaration($1, p->sinkFloatingValueList($4), $5);
         $$ = true;
-        p->markPropertyEnd($5, $$);
+        p->markPropertyEnd($5, true);
 #else
         $$ = false;
 #endif
index 5060331..015d930 100644 (file)
@@ -3012,13 +3012,16 @@ bool CSSParser::cssVariablesEnabled() const
 
 void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr<CSSParserValueList> value, bool important)
 {
+    ASSERT(name.length > 12);
+    AtomicString variableName = String(name.characters + 12, name.length - 12);
+
     StringBuilder builder;
     for (unsigned i = 0, size = value->size(); i < size; i++) {
         if (i)
             builder.append(' ');
         builder.append(value->valueAt(i)->createCSSValue()->cssText());
     }
-    addProperty(CSSPropertyVariable, CSSVariableValue::create(name, builder.toString()), important, false);
+    addProperty(CSSPropertyVariable, CSSVariableValue::create(variableName, builder.toString()), important, false);
 }
 #endif
 
@@ -8981,21 +8984,16 @@ restartAfterComment:
     }
 
     case CharacterDash:
-#if ENABLE(CSS_VARIABLES)
-        if (cssVariablesEnabled() && isEqualToCSSIdentifier(m_currentCharacter, "webkit-var") && m_currentCharacter[10] == '-' && isIdentifierStartAfterDash(m_currentCharacter + 11)) {
-            // handle variable declarations
-            m_currentCharacter += 11;
-            parseIdentifier(result, hasEscape);
-            m_token = VAR_DEFINITION;
-            yylval->string.characters = m_tokenStart;
-            yylval->string.length = result - m_tokenStart;
-        } else
-#endif
         if (isIdentifierStartAfterDash(m_currentCharacter)) {
             --m_currentCharacter;
             parseIdentifier(result, hasEscape);
             m_token = IDENT;
 
+#if ENABLE(CSS_VARIABLES)
+            if (cssVariablesEnabled() && isEqualToCSSIdentifier(m_tokenStart + 1, "webkit-var") && m_tokenStart[11] == '-' && isIdentifierStartAfterDash(m_tokenStart + 12))
+                m_token = VAR_DEFINITION;
+            else
+#endif
             if (*m_currentCharacter == '(') {
                 m_token = FUNCTION;
                 if (!hasEscape)
index 01519f3..76cc8ea 100644 (file)
 #include "RenderStyleConstants.h"
 #include "StylePropertyShorthand.h"
 
+#if ENABLE(CSS_VARIABLES)
+#include "CSSVariableValue.h"
+#endif
+
 namespace WebCore {
 
 struct SameSizeAsCSSProperty {
@@ -35,9 +39,20 @@ struct SameSizeAsCSSProperty {
 
 COMPILE_ASSERT(sizeof(CSSProperty) == sizeof(SameSizeAsCSSProperty), CSSProperty_should_stay_small);
 
+String CSSProperty::cssName() const
+{
+#if ENABLE(CSS_VARIABLES)
+    if (id() == CSSPropertyVariable) {
+        ASSERT(value()->isVariableValue());
+        return "-webkit-var-" + static_cast<CSSVariableValue*>(value())->name();
+    }
+#endif
+    return String(getPropertyName(id()));
+}
+
 String CSSProperty::cssText() const
 {
-    return String(getPropertyName(id())) + ": " + m_value->cssText() + (isImportant() ? " !important" : "") + "; ";
+    return cssName() + ": " + m_value->cssText() + (isImportant() ? " !important" : "") + "; ";
 }
 
 void CSSProperty::wrapValueInCommaSeparatedList()
index b746d80..7124146 100644 (file)
@@ -51,6 +51,7 @@ public:
 
     CSSValue* value() const { return m_value.get(); }
 
+    String cssName() const;
     String cssText() const;
 
     void wrapValueInCommaSeparatedList();
index 2ad4d20..5eb297c 100644 (file)
@@ -139,7 +139,7 @@ String PropertySetCSSStyleDeclaration::item(unsigned i) const
 {
     if (i >= m_propertySet->propertyCount())
         return "";
-    return getPropertyName(m_propertySet->propertyAt(i).id());
+    return m_propertySet->propertyAt(i).cssName();
 }
 
 String PropertySetCSSStyleDeclaration::cssText() const
index 7fc836f..0c25a5a 100644 (file)
@@ -662,6 +662,11 @@ String StylePropertySet::asText() const
         String value;
 
         switch (propertyID) {
+#if ENABLE(CSS_VARIABLES)
+        case CSSPropertyVariable:
+            result.append(prop.cssText());
+            continue;
+#endif
         case CSSPropertyBackgroundPositionX:
             positionXProp = &prop;
             continue;
index 3cd9150..5f5bb05 100644 (file)
@@ -1116,7 +1116,7 @@ bool InspectorStyleSheet::ensureSourceData()
         return false;
 
     RefPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::create();
-    CSSParser p(CSSStrictMode);
+    CSSParser p(m_pageStyleSheet->ownerDocument());
     OwnPtr<RuleSourceDataList> ruleSourceDataResult = adoptPtr(new RuleSourceDataList());
     p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, ruleSourceDataResult.get());
     m_parsedStyleSheet->setSourceData(ruleSourceDataResult.release());
index d954e76..fad6f7a 100755 (executable)
@@ -298,7 +298,7 @@ class WebKitPort(Port):
             "WebCoreHas3DRendering": ["animations/3d", "transforms/3d"],
             "WebGLShader": ["fast/canvas/webgl", "compositing/webgl", "http/tests/canvas/webgl"],
             "MHTMLArchive": ["mhtml"],
-            "CSSVariableValue": ["fast/css/variables"],
+            "CSSVariableValue": ["fast/css/variables", "inspector/styles/variables"],
         }
 
     def _has_test_in_directories(self, directory_lists, test_list):
index aab6543..6b45d42 100755 (executable)
@@ -100,6 +100,7 @@ class WebKitPortTest(port_testcase.PortTestCase):
             "http/tests/canvas/webgl",  # Requires WebGLShader
             "mhtml",  # Requires MHTMLArchive
             "fast/css/variables",  # Requires CSS Variables
+            "inspector/styles/variables",  # Requires CSS Variables
         ])
 
         result_directories = set(TestWebKitPort(symbols_string, None)._skipped_tests_for_unsupported_features(test_list=['mathml/foo.html']))