Title: [111387] trunk
Revision
111387
Author
[email protected]
Date
2012-03-20 05:38:45 -0700 (Tue, 20 Mar 2012)

Log Message

Let CSSImageValue inherit directly from CSSValue.
<http://webkit.org/b/81635>

Reviewed by Antti Koivisto.

Source/WebCore: 

This removes the last of the CSSPrimitiveValue subclasses, which will
open up the class to heavier refactoring.

Those CSSImageValues that used to represent the 'none' value are now
simply created as CSSPrimitiveValue identifiers by the parser.

Test: fast/css/image-value-type.html

* css/CSSCursorImageValue.cpp:
(WebCore::CSSCursorImageValue::~CSSCursorImageValue):
(WebCore::CSSCursorImageValue::updateIfSVGCursorIsUsed):
(WebCore::CSSCursorImageValue::cachedImage):
* css/CSSImageValue.cpp:
(WebCore::CSSImageValue::CSSImageValue):
(WebCore::CSSImageValue::cachedOrPendingImage):
(WebCore::CSSImageValue::cachedImage):
(WebCore::CSSImageValue::customCssText):
* css/CSSImageValue.h:
(WebCore::CSSImageValue::url):
* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseFillImage):
(WebCore::CSSParser::parseBorderImage):
* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyCursor::applyValue):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::collectMatchingRulesForList):
* css/CSSValue.h:
(WebCore::CSSValue::isPrimitiveValue):

LayoutTests: 

Added a test to document the fact that image values are no longer CSSPrimitiveValues.
Updated setPrimitiveValue.html and expectation to reflect this as well.

* fast/css/image-value-type-expected.txt: Added.
* fast/css/image-value-type.html: Added.
* fast/dom/setPrimitiveValue-expected.txt:
* fast/dom/setPrimitiveValue.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (111386 => 111387)


--- trunk/LayoutTests/ChangeLog	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/LayoutTests/ChangeLog	2012-03-20 12:38:45 UTC (rev 111387)
@@ -1,3 +1,18 @@
+2012-03-20  Andreas Kling  <[email protected]>
+
+        Let CSSImageValue inherit directly from CSSValue.
+        <http://webkit.org/b/81635>
+
+        Reviewed by Antti Koivisto.
+
+        Added a test to document the fact that image values are no longer CSSPrimitiveValues.
+        Updated setPrimitiveValue.html and expectation to reflect this as well.
+
+        * fast/css/image-value-type-expected.txt: Added.
+        * fast/css/image-value-type.html: Added.
+        * fast/dom/setPrimitiveValue-expected.txt:
+        * fast/dom/setPrimitiveValue.html:
+
 2012-03-20  Csaba Osztrogonác  <[email protected]>
 
         [Qt][Mac] Unreviewed gardening, skip new failing tests to paint the bot green.

Added: trunk/LayoutTests/fast/css/image-value-type-expected.txt (0 => 111387)


--- trunk/LayoutTests/fast/css/image-value-type-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/image-value-type-expected.txt	2012-03-20 12:38:45 UTC (rev 111387)
@@ -0,0 +1,10 @@
+Documents that CSS image values are not primitive values anymore.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS imageValue.cssValueType is CSSValue.CSS_CUSTOM
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/image-value-type.html (0 => 111387)


--- trunk/LayoutTests/fast/css/image-value-type.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/image-value-type.html	2012-03-20 12:38:45 UTC (rev 111387)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+<style>
+div#test {
+    background-image: url(stars.gif);
+}
+</style>
+</head>
+<body>
+<script>
+
+description("Documents that CSS image values are not primitive values anymore.");
+
+var style = document.styleSheets[1].rules[0].style;
+var imageValue = style.getPropertyCSSValue('background-image');
+
+shouldBe("imageValue.cssValueType", "CSSValue.CSS_CUSTOM");
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/fast/dom/setPrimitiveValue-expected.txt (111386 => 111387)


--- trunk/LayoutTests/fast/dom/setPrimitiveValue-expected.txt	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/LayoutTests/fast/dom/setPrimitiveValue-expected.txt	2012-03-20 12:38:45 UTC (rev 111387)
@@ -1,3 +1,2 @@
 Test CSSPrimitiveValue setters.
 setFloatValue NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7
-setStringValue NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7

Modified: trunk/LayoutTests/fast/dom/setPrimitiveValue.html (111386 => 111387)


--- trunk/LayoutTests/fast/dom/setPrimitiveValue.html	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/LayoutTests/fast/dom/setPrimitiveValue.html	2012-03-20 12:38:45 UTC (rev 111387)
@@ -5,7 +5,6 @@
     position: absolute;
     left: 250px;
     top: 100px;
-    background-image: url(stars.gif);
 }
 </style>
 <script>
@@ -22,7 +21,6 @@
     var textRule = document.styleSheets[0].cssRules[0];
     var s = textRule.style;
     var leftValue = s.getPropertyCSSValue("left");
-    var bgImageValue = s.getPropertyCSSValue("background-image");
     var console = document.getElementById("console");
 
     try
@@ -35,17 +33,6 @@
         line.innerText = "setFloatValue " + e.message;
         console.appendChild(line);
     }
-
-    try
-    {
-        bgImageValue.setStringValue(bgImageValue.primitiveType, "stripes.gif");
-    }
-    catch (e)
-    {
-        var line = document.createElement("div");
-        line.innerText = "setStringValue " + e.message;
-        console.appendChild(line);
-    }
 }
 
 </script>

Modified: trunk/Source/WebCore/ChangeLog (111386 => 111387)


--- trunk/Source/WebCore/ChangeLog	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/Source/WebCore/ChangeLog	2012-03-20 12:38:45 UTC (rev 111387)
@@ -1,3 +1,40 @@
+2012-03-20  Andreas Kling  <[email protected]>
+
+        Let CSSImageValue inherit directly from CSSValue.
+        <http://webkit.org/b/81635>
+
+        Reviewed by Antti Koivisto.
+
+        This removes the last of the CSSPrimitiveValue subclasses, which will
+        open up the class to heavier refactoring.
+
+        Those CSSImageValues that used to represent the 'none' value are now
+        simply created as CSSPrimitiveValue identifiers by the parser.
+
+        Test: fast/css/image-value-type.html
+
+        * css/CSSCursorImageValue.cpp:
+        (WebCore::CSSCursorImageValue::~CSSCursorImageValue):
+        (WebCore::CSSCursorImageValue::updateIfSVGCursorIsUsed):
+        (WebCore::CSSCursorImageValue::cachedImage):
+        * css/CSSImageValue.cpp:
+        (WebCore::CSSImageValue::CSSImageValue):
+        (WebCore::CSSImageValue::cachedOrPendingImage):
+        (WebCore::CSSImageValue::cachedImage):
+        (WebCore::CSSImageValue::customCssText):
+        * css/CSSImageValue.h:
+        (WebCore::CSSImageValue::url):
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseValue):
+        (WebCore::CSSParser::parseFillImage):
+        (WebCore::CSSParser::parseBorderImage):
+        * css/CSSStyleApplyProperty.cpp:
+        (WebCore::ApplyPropertyCursor::applyValue):
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::collectMatchingRulesForList):
+        * css/CSSValue.h:
+        (WebCore::CSSValue::isPrimitiveValue):
+
 2012-03-20  Pavel Feldman  <[email protected]>
 
         Web Inspector: call .length as the last check when detecting arrays.

Modified: trunk/Source/WebCore/css/CSSCursorImageValue.cpp (111386 => 111387)


--- trunk/Source/WebCore/css/CSSCursorImageValue.cpp	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/Source/WebCore/css/CSSCursorImageValue.cpp	2012-03-20 12:38:45 UTC (rev 111387)
@@ -63,8 +63,7 @@
 CSSCursorImageValue::~CSSCursorImageValue()
 {
 #if ENABLE(SVG)
-    const String& url = ""
-    if (!isSVGCursorIdentifier(url))
+    if (!isSVGCursorIdentifier(url()))
         return;
 
     HashSet<SVGElement*>::const_iterator it = m_referencedElements.begin();
@@ -73,7 +72,7 @@
     for (; it != end; ++it) {
         SVGElement* referencedElement = *it;
         referencedElement->cursorImageValueRemoved();
-        if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url, referencedElement->document()))
+        if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url(), referencedElement->document()))
             cursorElement->removeClient(referencedElement);
     }
 #endif
@@ -87,11 +86,10 @@
     if (!element || !element->isSVGElement())
         return false;
 
-    const String& url = ""
-    if (!isSVGCursorIdentifier(url))
+    if (!isSVGCursorIdentifier(url()))
         return false;
 
-    if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url, element->document())) {
+    if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url(), element->document())) {
         // FIXME: This will override hot spot specified in CSS, which is probably incorrect.
         SVGLengthContext lengthContext(0);
         float x = roundf(cursorElement->x().value(lengthContext));
@@ -116,17 +114,15 @@
 
 StyleCachedImage* CSSCursorImageValue::cachedImage(CachedResourceLoader* loader)
 {
-    String url = ""
-
 #if ENABLE(SVG)
-    if (isSVGCursorIdentifier(url) && loader && loader->document()) {
+    if (isSVGCursorIdentifier(url()) && loader && loader->document()) {
         // FIXME: This will fail if the <cursor> element is in a shadow DOM (bug 59827)
-        if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url, loader->document()))
-            url = ""
+        if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url(), loader->document()))
+            return CSSImageValue::cachedImage(loader, cursorElement->href());
     }
 #endif
 
-    return CSSImageValue::cachedImage(loader, url);
+    return CSSImageValue::cachedImage(loader, url());
 }
 
 #if ENABLE(SVG)

Modified: trunk/Source/WebCore/css/CSSImageValue.cpp (111386 => 111387)


--- trunk/Source/WebCore/css/CSSImageValue.cpp	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/Source/WebCore/css/CSSImageValue.cpp	2012-03-20 12:38:45 UTC (rev 111387)
@@ -22,6 +22,7 @@
 #include "CSSImageValue.h"
 
 #include "CSSCursorImageValue.h"
+#include "CSSParser.h"
 #include "CSSValueKeywords.h"
 #include "Document.h"
 #include "MemoryCache.h"
@@ -33,25 +34,22 @@
 namespace WebCore {
 
 CSSImageValue::CSSImageValue(ClassType classType, const String& url)
-    : CSSPrimitiveValue(classType, url, CSS_URI)
+    : CSSValue(classType)
+    , m_url(url)
     , m_accessedImage(false)
 {
 }
 
-CSSImageValue::CSSImageValue()
-    : CSSPrimitiveValue(ImageClass, CSSValueNone)
-    , m_accessedImage(true)
-{
-}
-
 CSSImageValue::CSSImageValue(const String& url)
-    : CSSPrimitiveValue(ImageClass, url, CSS_URI)
+    : CSSValue(ImageClass)
+    , m_url(url)
     , m_accessedImage(false)
 {
 }
 
 CSSImageValue::CSSImageValue(const String& url, StyleImage* image)
-    : CSSPrimitiveValue(ImageClass, url, CSS_URI)
+    : CSSValue(ImageClass)
+    , m_url(url)
     , m_image(image)
     , m_accessedImage(true)
 {
@@ -63,9 +61,6 @@
 
 StyleImage* CSSImageValue::cachedOrPendingImage()
 {
-    if (getIdent() == CSSValueNone)
-        return 0;
-
     if (!m_image)
         m_image = StylePendingImage::create(this);
 
@@ -76,7 +71,7 @@
 {
     if (isCursorImageValue())
         return static_cast<CSSCursorImageValue*>(this)->cachedImage(loader);
-    return cachedImage(loader, getStringValue());
+    return cachedImage(loader, m_url);
 }
 
 StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader, const String& url)
@@ -107,4 +102,9 @@
     m_accessedImage = false;
 }
 
+String CSSImageValue::customCssText() const
+{
+    return "url(" + quoteCSSURLIfNeeded(m_url) + ")";
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/CSSImageValue.h (111386 => 111387)


--- trunk/Source/WebCore/css/CSSImageValue.h	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/Source/WebCore/css/CSSImageValue.h	2012-03-20 12:38:45 UTC (rev 111387)
@@ -1,6 +1,6 @@
 /*
  * (C) 1999-2003 Lars Knoll ([email protected])
- * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2008, 2012 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -21,7 +21,7 @@
 #ifndef CSSImageValue_h
 #define CSSImageValue_h
 
-#include "CSSPrimitiveValue.h"
+#include "CSSValue.h"
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
@@ -30,9 +30,8 @@
 class StyleCachedImage;
 class StyleImage;
 
-class CSSImageValue : public CSSPrimitiveValue {
+class CSSImageValue : public CSSValue {
 public:
-    static PassRefPtr<CSSImageValue> create() { return adoptRef(new CSSImageValue); }
     static PassRefPtr<CSSImageValue> create(const String& url) { return adoptRef(new CSSImageValue(url)); }
     static PassRefPtr<CSSImageValue> create(const String& url, StyleImage* image) { return adoptRef(new CSSImageValue(url, image)); }
     ~CSSImageValue();
@@ -41,6 +40,10 @@
     // Returns a StyleCachedImage if the image is cached already, otherwise a StylePendingImage.
     StyleImage* cachedOrPendingImage();
 
+    const String& url() { return m_url; }
+
+    String customCssText() const;
+
 protected:
     CSSImageValue(ClassType, const String& url);
 
@@ -49,10 +52,10 @@
     void clearCachedImage();
 
 private:
-    CSSImageValue();
     explicit CSSImageValue(const String& url);
-    explicit CSSImageValue(const String& url, StyleImage*);
+    CSSImageValue(const String& url, StyleImage*);
 
+    String m_url;
     RefPtr<StyleImage> m_image;
     bool m_accessedImage;
 };

Modified: trunk/Source/WebCore/css/CSSParser.cpp (111386 => 111387)


--- trunk/Source/WebCore/css/CSSParser.cpp	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2012-03-20 12:38:45 UTC (rev 111387)
@@ -1309,7 +1309,7 @@
     case CSSPropertyBorderImageSource:
     case CSSPropertyWebkitMaskBoxImageSource:
         if (id == CSSValueNone) {
-            parsedValue = CSSImageValue::create();
+            parsedValue = cssValuePool()->createIdentifierValue(CSSValueNone);
             m_valueList->next();
         } else if (value->unit == CSSPrimitiveValue::CSS_URI) {
             if (m_styleSheet) {
@@ -3002,7 +3002,7 @@
 bool CSSParser::parseFillImage(CSSParserValueList* valueList, RefPtr<CSSValue>& value)
 {
     if (valueList->current()->id == CSSValueNone) {
-        value = CSSImageValue::create();
+        value = cssValuePool()->createIdentifierValue(CSSValueNone);
         return true;
     }
     if (valueList->current()->unit == CSSPrimitiveValue::CSS_URI) {
@@ -5541,7 +5541,7 @@
                 else
                     return false;
             } else if (val->id == CSSValueNone)
-                context.commitImage(CSSImageValue::create());
+                context.commitImage(cssValuePool()->createIdentifierValue(CSSValueNone));
         }
 
         if (!context.canAdvance() && context.allowImageSlice()) {

Modified: trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp (111386 => 111387)


--- trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2012-03-20 12:38:45 UTC (rev 111387)
@@ -1082,18 +1082,16 @@
             selector->style()->setCursor(CURSOR_AUTO);
             for (int i = 0; i < len; i++) {
                 CSSValue* item = list->itemWithoutBoundsCheck(i);
-                if (!item->isPrimitiveValue())
-                    continue;
-                CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(item);
-                if (primitiveValue->isURI()) {
-                    if (primitiveValue->isCursorImageValue()) {
-                        CSSCursorImageValue* image = static_cast<CSSCursorImageValue*>(primitiveValue);
-                        if (image->updateIfSVGCursorIsUsed(selector->element())) // Elements with SVG cursors are not allowed to share style.
-                            selector->style()->setUnique();
-                        selector->style()->addCursor(selector->cachedOrPendingFromValue(CSSPropertyCursor, image), image->hotSpot());
-                    }
-                } else if (primitiveValue->isIdent())
-                    selector->style()->setCursor(*primitiveValue);
+                if (item->isCursorImageValue()) {
+                    CSSCursorImageValue* image = static_cast<CSSCursorImageValue*>(item);
+                    if (image->updateIfSVGCursorIsUsed(selector->element())) // Elements with SVG cursors are not allowed to share style.
+                        selector->style()->setUnique();
+                    selector->style()->addCursor(selector->cachedOrPendingFromValue(CSSPropertyCursor, image), image->hotSpot());
+                } else if (item->isPrimitiveValue()) {
+                    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(item);
+                    if (primitiveValue->isIdent())
+                        selector->style()->setCursor(*primitiveValue);
+                }
             }
         } else if (value->isPrimitiveValue()) {
             CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (111386 => 111387)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-03-20 12:38:45 UTC (rev 111387)
@@ -3044,6 +3044,12 @@
                 didSet = true;
             }
 
+            if (item->isImageValue()) {
+                m_style->setContent(cachedOrPendingFromValue(CSSPropertyContent, static_cast<CSSImageValue*>(item)), didSet);
+                didSet = true;
+                continue;
+            }
+
             if (!item->isPrimitiveValue())
                 continue;
 
@@ -3064,11 +3070,6 @@
                 didSet = true;
                 // register the fact that the attribute value affects the style
                 m_features.attrsInRules.add(attr.localName().impl());
-            } else if (contentValue->isURI()) {
-                if (!contentValue->isImageValue())
-                    break;
-                m_style->setContent(cachedOrPendingFromValue(CSSPropertyContent, static_cast<CSSImageValue*>(contentValue)), didSet);
-                didSet = true;
             } else if (contentValue->isCounter()) {
                 Counter* counterValue = contentValue->getCounterValue();
                 EListStyleType listStyleType = NoneListStyle;

Modified: trunk/Source/WebCore/css/CSSValue.h (111386 => 111387)


--- trunk/Source/WebCore/css/CSSValue.h	2012-03-20 12:27:12 UTC (rev 111386)
+++ trunk/Source/WebCore/css/CSSValue.h	2012-03-20 12:38:45 UTC (rev 111387)
@@ -56,7 +56,7 @@
     String cssText() const;
     void setCssText(const String&, ExceptionCode&) { } // FIXME: Not implemented.
 
-    bool isPrimitiveValue() const { return m_classType <= PrimitiveClass; }
+    bool isPrimitiveValue() const { return m_classType == PrimitiveClass; }
     bool isValueList() const { return m_classType >= ValueListClass; }
 
     bool isAspectRatioValue() const { return m_classType == AspectRatioClass; }
@@ -93,10 +93,11 @@
 
     static const size_t ClassTypeBits = 5;
     enum ClassType {
-        // Primitive class types must appear before PrimitiveClass.
+        PrimitiveClass,
+
+        // Image classes.
         ImageClass,
         CursorImageClass,
-        PrimitiveClass,
 
         // Image generator classes.
         CanvasClass,
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to