Title: [132966] trunk
Revision
132966
Author
[email protected]
Date
2012-10-30 17:03:27 -0700 (Tue, 30 Oct 2012)

Log Message

cssText for cursor property doesn't include hotspot
https://bugs.webkit.org/show_bug.cgi?id=99530

Patch by Rick Byers <[email protected]> on 2012-10-30
Reviewed by Darin Adler.

Source/WebCore:

Implement customCssText in CSSCursorImageValue to include the hotspot when present.
Also explicitly track whether or not a hotspot was supplied in the parser,
while still using the existing convention of (-1,-1) to denote no hotspot
in the rest of the system.

Test: fast/css/cursor-parsing.html

* css/CSSCursorImageValue.cpp:
(WebCore::CSSCursorImageValue::customCssText):
* css/CSSCursorImageValue.h:
(CSSCursorImageValue):

LayoutTests:

Add simple test for parsing of CSS cursor property.

* fast/css/cursor-parsing-expected.txt: Added.
* fast/css/cursor-parsing.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (132965 => 132966)


--- trunk/LayoutTests/ChangeLog	2012-10-31 00:00:12 UTC (rev 132965)
+++ trunk/LayoutTests/ChangeLog	2012-10-31 00:03:27 UTC (rev 132966)
@@ -1,3 +1,15 @@
+2012-10-30  Rick Byers  <[email protected]>
+
+        cssText for cursor property doesn't include hotspot
+        https://bugs.webkit.org/show_bug.cgi?id=99530
+
+        Reviewed by Darin Adler.
+
+        Add simple test for parsing of CSS cursor property.
+
+        * fast/css/cursor-parsing-expected.txt: Added.
+        * fast/css/cursor-parsing.html: Added.
+
 2012-10-30  Roger Fong  <[email protected]>
 
         Unreviewed. Test should not be run on Apple Windows port: fast/images/exif-orientation-image-document.html

Added: trunk/LayoutTests/fast/css/cursor-parsing-expected.txt (0 => 132966)


--- trunk/LayoutTests/fast/css/cursor-parsing-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/cursor-parsing-expected.txt	2012-10-31 00:03:27 UTC (rev 132966)
@@ -0,0 +1,33 @@
+Test the parsing of the cursor property.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Test a bunch of cursor rules which should round-trip exactly.
+PASS roundtripCssRule("cursor: auto;") is "cursor: auto;"
+PASS roundtripCssRule("cursor: none;") is "cursor: none;"
+PASS roundtripCssRule("cursor: copy;") is "cursor: copy;"
+PASS roundtripCssRule("cursor: -webkit-grabbing;") is "cursor: -webkit-grabbing;"
+PASS roundtripCssRule("cursor: url(file:///foo.png);") is "cursor: url(file:///foo.png);"
+PASS roundtripCssRule("cursor: url(file:///foo.png), crosshair;") is "cursor: url(file:///foo.png), crosshair;"
+PASS roundtripCssRule("cursor: url(file:///foo.png), url(file:///foo2.png), pointer;") is "cursor: url(file:///foo.png), url(file:///foo2.png), pointer;"
+PASS roundtripCssRule("cursor: url(file:///foo.png) 12 3, pointer;") is "cursor: url(file:///foo.png) 12 3, pointer;"
+PASS roundtripCssRule("cursor: url(file:///foo.png) 0 0, pointer;") is "cursor: url(file:///foo.png) 0 0, pointer;"
+PASS roundtripCssRule("cursor: url(file:///foo.png) 12 3, url(file:///foo2.png), url(file:///foo3.png) 6 7, crosshair;") is "cursor: url(file:///foo.png) 12 3, url(file:///foo2.png), url(file:///foo3.png) 6 7, crosshair;"
+PASS roundtripCssRule("cursor: url(file:///foo.png) -2 3, pointer;") is "cursor: url(file:///foo.png) -2 3, pointer;"
+PASS roundtripCssRule("cursor: url(file:///foo.png) 2 -3, pointer;") is "cursor: url(file:///foo.png) 2 -3, pointer;"
+PASS roundtripCssRule("cursor: url(file:///foo.png) -1 -1, pointer;") is "cursor: url(file:///foo.png) -1 -1, pointer;"
+
+Test a bunch of invalid cursor rules which shouldn't parse at all.
+PASS roundtripCssRule("cursor: nonexistent;") is ""
+PASS roundtripCssRule("cursor: ltr;") is ""
+PASS roundtripCssRule("cursor: inline;") is ""
+PASS roundtripCssRule("cursor: url(file:///foo.png), url(file:///foo2.png);") is ""
+PASS roundtripCssRule("cursor: url(file:///foo.png) 12;") is ""
+PASS roundtripCssRule("cursor: url(file:///foo.png) 12 3 5;") is ""
+PASS roundtripCssRule("cursor: url(file:///foo.png) x y;") is ""
+PASS roundtripCssRule("cursor: url(file:///foo.png) auto;") is ""
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/cursor-parsing.html (0 => 132966)


--- trunk/LayoutTests/fast/css/cursor-parsing.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/cursor-parsing.html	2012-10-31 00:03:27 UTC (rev 132966)
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description("Test the parsing of the cursor property.");
+
+function makeCursorRule(rule)
+{
+    return "cursor: " + rule + ";";
+}
+
+function testCursorRule(rule)
+{
+    var cssText = makeCursorRule(rule);
+    shouldBeEqualToString('roundtripCssRule("' + cssText + '")', cssText);
+}
+
+function testInvalidCursorRule(rule)
+{
+    shouldBeEqualToString('roundtripCssRule("' + makeCursorRule(rule) + '")', '');
+}
+
+function roundtripCssRule(cssText)
+{
+    var div = document.createElement("div");
+    div.setAttribute("style", cssText);
+    document.body.appendChild(div);
+    var result = div.style.cssText;
+    document.body.removeChild(div);
+    return result;
+}
+
+// Note that any absolute URL will suffice for these tests (can't use relative URLs
+// since they'll be converted to absolute form in the output).  I chose file URLs just
+// to avoid triggering any network activity.
+
+debug('Test a bunch of cursor rules which should round-trip exactly.');
+testCursorRule('auto');
+testCursorRule('none');
+testCursorRule('copy');
+testCursorRule('-webkit-grabbing');
+testCursorRule('url(file:///foo.png)');   //  IE compatibility 
+testCursorRule('url(file:///foo.png), crosshair');
+testCursorRule('url(file:///foo.png), url(file:///foo2.png), pointer');
+testCursorRule('url(file:///foo.png) 12 3, pointer');
+testCursorRule('url(file:///foo.png) 0 0, pointer');
+testCursorRule('url(file:///foo.png) 12 3, url(file:///foo2.png), url(file:///foo3.png) 6 7, crosshair');
+testCursorRule('url(file:///foo.png) -2 3, pointer');
+testCursorRule('url(file:///foo.png) 2 -3, pointer');
+testCursorRule('url(file:///foo.png) -1 -1, pointer');
+
+debug('');
+debug('Test a bunch of invalid cursor rules which shouldn\'t parse at all.');
+testInvalidCursorRule('nonexistent');
+testInvalidCursorRule('ltr');
+testInvalidCursorRule('inline');
+testInvalidCursorRule('url(file:///foo.png), url(file:///foo2.png)');
+testInvalidCursorRule('url(file:///foo.png) 12');
+testInvalidCursorRule('url(file:///foo.png) 12 3 5');
+testInvalidCursorRule('url(file:///foo.png) x y');
+testInvalidCursorRule('url(file:///foo.png) auto');
+
+successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (132965 => 132966)


--- trunk/Source/WebCore/ChangeLog	2012-10-31 00:00:12 UTC (rev 132965)
+++ trunk/Source/WebCore/ChangeLog	2012-10-31 00:03:27 UTC (rev 132966)
@@ -1,3 +1,22 @@
+2012-10-30  Rick Byers  <[email protected]>
+
+        cssText for cursor property doesn't include hotspot
+        https://bugs.webkit.org/show_bug.cgi?id=99530
+
+        Reviewed by Darin Adler.
+
+        Implement customCssText in CSSCursorImageValue to include the hotspot when present.
+        Also explicitly track whether or not a hotspot was supplied in the parser,
+        while still using the existing convention of (-1,-1) to denote no hotspot
+        in the rest of the system.
+
+        Test: fast/css/cursor-parsing.html
+
+        * css/CSSCursorImageValue.cpp:
+        (WebCore::CSSCursorImageValue::customCssText):
+        * css/CSSCursorImageValue.h:
+        (CSSCursorImageValue):
+
 2012-10-30  Kenneth Russell  <[email protected]>
 
         Temporarily restrict use of ImageBufferSkia::copyToPlatformTexture until bugs resolved

Modified: trunk/Source/WebCore/css/CSSCursorImageValue.cpp (132965 => 132966)


--- trunk/Source/WebCore/css/CSSCursorImageValue.cpp	2012-10-31 00:00:12 UTC (rev 132965)
+++ trunk/Source/WebCore/css/CSSCursorImageValue.cpp	2012-10-31 00:03:27 UTC (rev 132966)
@@ -56,8 +56,9 @@
 }
 #endif
 
-CSSCursorImageValue::CSSCursorImageValue(const String& url, const IntPoint& hotSpot)
+CSSCursorImageValue::CSSCursorImageValue(const String& url, bool hasHotSpot, const IntPoint& hotSpot)
     : CSSImageValue(CursorImageClass, url)
+    , m_hasHotSpot(hasHotSpot)
     , m_hotSpot(hotSpot)
 {
 }
@@ -80,6 +81,19 @@
 #endif
 }
 
+String CSSCursorImageValue::customCssText() const
+{
+    StringBuilder result;
+    result.append(CSSImageValue::customCssText());
+    if (m_hasHotSpot) {
+        result.append(' ');
+        result.appendNumber(m_hotSpot.x());
+        result.append(' ');
+        result.appendNumber(m_hotSpot.y());
+    }
+    return result.toString();
+}
+
 bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element)
 {
 #if !ENABLE(SVG)
@@ -94,6 +108,7 @@
     if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url(), element->document())) {
         // FIXME: This will override hot spot specified in CSS, which is probably incorrect.
         SVGLengthContext lengthContext(0);
+        m_hasHotSpot = true;
         float x = roundf(cursorElement->x().value(lengthContext));
         m_hotSpot.setX(static_cast<int>(x));
 

Modified: trunk/Source/WebCore/css/CSSCursorImageValue.h (132965 => 132966)


--- trunk/Source/WebCore/css/CSSCursorImageValue.h	2012-10-31 00:00:12 UTC (rev 132965)
+++ trunk/Source/WebCore/css/CSSCursorImageValue.h	2012-10-31 00:03:27 UTC (rev 132966)
@@ -32,15 +32,24 @@
 
 class CSSCursorImageValue : public CSSImageValue {
 public:
-    static PassRefPtr<CSSCursorImageValue> create(const String& url, const IntPoint& hotSpot)
+    static PassRefPtr<CSSCursorImageValue> create(const String& url, bool hasHotSpot, const IntPoint& hotSpot)
     {
-        return adoptRef(new CSSCursorImageValue(url, hotSpot));
+        return adoptRef(new CSSCursorImageValue(url, hasHotSpot, hotSpot));
     }
 
     ~CSSCursorImageValue();
 
-    IntPoint hotSpot() const { return m_hotSpot; }
+    bool hasHotSpot() const { return m_hasHotSpot; }
 
+    IntPoint hotSpot() const
+    {
+        if (m_hasHotSpot)
+            return m_hotSpot;
+        return IntPoint(-1, -1);
+    }
+
+    String customCssText() const;
+
     bool updateIfSVGCursorIsUsed(Element*);
     StyleCachedImage* cachedImage(CachedResourceLoader*);
 
@@ -51,8 +60,9 @@
     void reportDescendantMemoryUsage(MemoryObjectInfo*) const;
 
 private:
-    CSSCursorImageValue(const String& url, const IntPoint& hotSpot);
+    CSSCursorImageValue(const String& url, bool hasHotSpot, const IntPoint& hotSpot);
 
+    bool m_hasHotSpot;
     IntPoint m_hotSpot;
 
 #if ENABLE(SVG)

Modified: trunk/Source/WebCore/css/CSSParser.cpp (132965 => 132966)


--- trunk/Source/WebCore/css/CSSParser.cpp	2012-10-31 00:00:12 UTC (rev 132965)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2012-10-31 00:03:27 UTC (rev 132966)
@@ -1874,15 +1874,18 @@
                 coords.append(int(value->fValue));
                 value = m_valueList->next();
             }
+            bool hasHotSpot = false;
             IntPoint hotSpot(-1, -1);
             int nrcoords = coords.size();
             if (nrcoords > 0 && nrcoords != 2)
                 return false;
-            if (nrcoords == 2)
+            if (nrcoords == 2) {
+                hasHotSpot = true;
                 hotSpot = IntPoint(coords[0], coords[1]);
+            }
 
             if (!uri.isNull())
-                list->append(CSSCursorImageValue::create(completeURL(uri), hotSpot));
+                list->append(CSSCursorImageValue::create(completeURL(uri), hasHotSpot, hotSpot));
 
             if ((inStrictMode() && !value) || (value && !(value->unit == CSSParserValue::Operator && value->iValue == ',')))
                 return false;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to