WebCore:
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Jul 2009 01:04:19 +0000 (01:04 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Jul 2009 01:04:19 +0000 (01:04 +0000)
2009-07-13  Erik Arvidsson  <arv@chromium.org>

        Reviewed by Darin Adler and Maciej Stachowiak.

        Implement HTML5 draggable
        https://bugs.webkit.org/show_bug.cgi?id=26262

        This adds support for the HTML5 draggable attribute and its DOM binding. It maps the draggable property
        to the CSS properties -webkit-user-drag and -webkit-user-select respectively.

        Spec: http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#the-draggable-attribute

        Test: fast/html/draggable.html

        * css/html.css:
        * html/HTMLAnchorElement.cpp:
        (WebCore::HTMLAnchorElement::draggable):
        * html/HTMLAnchorElement.h:
        * html/HTMLAttributeNames.in:
        * html/HTMLElement.cpp:
        (WebCore::HTMLElement::draggable):
        (WebCore::HTMLElement::setDraggable):
        * html/HTMLElement.h:
        * html/HTMLElement.idl:
        * html/HTMLImageElement.cpp:
        (WebCore::HTMLImageElement::draggable):
        * html/HTMLImageElement.h:

LayoutTests:

2009-07-13  Erik Arvidsson  <arv@chromium.org>

        Reviewed by Darin Adler and Maciej Stachowiak.

        Implement HTML5 draggable
        https://bugs.webkit.org/show_bug.cgi?id=26262

        This adds support for the HTML5 draggable attribute and its DOM binding. It maps the draggable property
        to the CSS properties -webkit-user-drag and -webkit-user-select respectively.

        Spec: http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#the-draggable-attribute

        * fast/html/draggable-expected.txt: Added.
        * fast/html/draggable.html: Added.
        * fast/html/resources: Added.
        * fast/html/resources/images: Added.
        * fast/html/resources/images/lime.png: Added.

        * fast/dom/resources/domListEnumeration.js: Updated.
        * fast/dom/domListEnumeration-expected.txt: Updated.

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/domListEnumeration-expected.txt
LayoutTests/fast/dom/resources/domListEnumeration.js
LayoutTests/fast/html/draggable-expected.txt [new file with mode: 0644]
LayoutTests/fast/html/draggable.html [new file with mode: 0644]
LayoutTests/fast/html/resources/images/lime.png [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLAnchorElement.cpp
WebCore/html/HTMLAnchorElement.h
WebCore/html/HTMLAttributeNames.in
WebCore/html/HTMLElement.cpp
WebCore/html/HTMLElement.h
WebCore/html/HTMLElement.idl
WebCore/html/HTMLImageElement.cpp
WebCore/html/HTMLImageElement.h

index de80062..48d3b2e 100644 (file)
@@ -1,3 +1,24 @@
+2009-07-13  Erik Arvidsson  <arv@chromium.org>
+
+        Reviewed by Darin Adler and Maciej Stachowiak.
+
+        Implement HTML5 draggable
+        https://bugs.webkit.org/show_bug.cgi?id=26262
+
+        This adds support for the HTML5 draggable attribute and its DOM binding. It maps the draggable property
+        to the CSS properties -webkit-user-drag and -webkit-user-select respectively.
+
+        Spec: http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#the-draggable-attribute
+
+        * fast/html/draggable-expected.txt: Added.
+        * fast/html/draggable.html: Added.
+        * fast/html/resources: Added.
+        * fast/html/resources/images: Added.
+        * fast/html/resources/images/lime.png: Added.
+
+        * fast/dom/resources/domListEnumeration.js: Updated.
+        * fast/dom/domListEnumeration-expected.txt: Updated.
+
 2009-07-13  Simon Fraser  <simon.fraser@apple.com>
 
         Reviewed by Dan Bernstein.
index 2e775a3..d38c1c9 100644 (file)
@@ -32,7 +32,7 @@ PASS resultArray[2].i is '2'
 PASS resultArray[2].item is namedNodeMap.item(2)
 
 [object HTMLFormElement]
-PASS resultArray.length is 130
+PASS resultArray.length is 131
 PASS resultArray[0].i is '0'
 PASS resultArray[0].item is document.getElementsByTagName('select')[0]
 PASS resultArray[1].i is '1'
@@ -41,7 +41,7 @@ PASS resultArray[2].i is '2'
 PASS resultArray[2].item is document.getElementsByTagName('select')[2]
 
 [object HTMLSelectElement]
-PASS resultArray.length is 135
+PASS resultArray.length is 136
 PASS resultArray[0].i is '0'
 PASS resultArray[0].item is document.getElementsByTagName('option')[0]
 PASS resultArray[1].i is '1'
index 4673347..0eb37c4 100644 (file)
@@ -130,7 +130,7 @@ shouldBe("resultArray[2].item", "namedNodeMap.item(2)");
 // HTMLFormElement
 var htmlFormElement = document.getElementsByTagName('form')[0];
 resultArray = iterateList(htmlFormElement);
-shouldBe("resultArray.length", "130");
+shouldBe("resultArray.length", "131");
 shouldBe("resultArray[0].i", "'0'");
 shouldBe("resultArray[0].item", "document.getElementsByTagName('select')[0]");
 shouldBe("resultArray[1].i", "'1'");
@@ -141,7 +141,7 @@ shouldBe("resultArray[2].item", "document.getElementsByTagName('select')[2]");
 // HTMLSelectElement
 var htmlSelectElement = document.getElementsByTagName('select')[0];
 resultArray = iterateList(htmlSelectElement);
-shouldBe("resultArray.length", "135");
+shouldBe("resultArray.length", "136");
 shouldBe("resultArray[0].i", "'0'");
 shouldBe("resultArray[0].item", "document.getElementsByTagName('option')[0]");
 shouldBe("resultArray[1].i", "'1'");
diff --git a/LayoutTests/fast/html/draggable-expected.txt b/LayoutTests/fast/html/draggable-expected.txt
new file mode 100644 (file)
index 0000000..8a20d85
--- /dev/null
@@ -0,0 +1,45 @@
+Intrinsic
+
+ webkit.org <a no href> <span>
+draggable attr set to true
+
+ webkit.org <a no href> <span>
+draggable attr set to false
+
+ webkit.org <a no href> <span>
+draggable attr set to maybe
+
+ webkit.org <a no href> <span>
+draggable dom prop set to true
+
+ webkit.org <a no href> <span>
+draggable dom prop set to false
+
+ webkit.org <a no href> <span>
+dom - attr
+----------
+true - null
+true - null
+false - null
+false - null
+true - true
+true - true
+true - true
+true - true
+false - false
+false - false
+false - false
+false - false
+true - maybe
+true - maybe
+false - maybe
+false - maybe
+true - true
+true - true
+true - true
+true - true
+false - false
+false - false
+false - false
+false - false
+
diff --git a/LayoutTests/fast/html/draggable.html b/LayoutTests/fast/html/draggable.html
new file mode 100644 (file)
index 0000000..df5d487
--- /dev/null
@@ -0,0 +1,91 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>HTML5 Draggable</title>
+<style>
+
+[draggable="true"] {
+    outline: 1px solid lime;
+}
+
+[draggable="false"] {
+    outline: 1px solid pink;
+}
+
+</style>
+<script>
+
+function test()
+{
+    var elements = document.querySelectorAll('body > :not(h2)');
+
+    for (var i = 16; i < 24; i++) {
+        elements[i].draggable = i < 20;
+    }
+
+    var s = 'dom - attr\n----------\n';
+    for (var i = 0; i < elements.length; i++) {
+        s += elements[i].draggable + ' - ' + elements[i].getAttribute('draggable') + '\n';
+    }
+
+    var pre = document.createElement('pre');
+    pre.textContent = s;
+    document.body.appendChild(pre);
+    
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();    
+};
+
+document.ondragstart = function(e)
+{
+    e.dataTransfer.setData('Text', e.target.textContent || e.target.src || e.target.href);
+};
+
+</script>
+</head>
+<body onload="test()">
+
+<h2>Intrinsic</h2>
+
+<img src="resources/images/lime.png">
+<a href="http://webgkit.org">webkit.org</a>
+<a>&lt;a no href&gt;</a>
+<span>&lt;span&gt;</span>
+
+<h2>draggable attr set to true</h2>
+
+<img src="resources/images/lime.png" draggable="true">
+<a href="http://webgkit.org" draggable="true">webkit.org</a>
+<a draggable="true">&lt;a no href&gt;</a>
+<span draggable="true">&lt;span&gt;</span>
+
+<h2>draggable attr set to false</h2>
+
+<img src="resources/images/lime.png" draggable="false">
+<a href="http://webgkit.org" draggable="false">webkit.org</a>
+<a draggable="false">&lt;a no href&gt;</a>
+<span draggable="false">&lt;span&gt;</span>
+
+<h2>draggable attr set to maybe</h2>
+
+<img src="resources/images/lime.png" draggable="maybe">
+<a href="http://webgkit.org" draggable="maybe">webkit.org</a>
+<a draggable="maybe">&lt;a no href&gt;</a>
+<span draggable="maybe">&lt;span&gt;</span>
+
+<h2>draggable dom prop set to true</h2>
+
+<img src="resources/images/lime.png">
+<a href="http://webgkit.org">webkit.org</a>
+<a>&lt;a no href&gt;</a>
+<span>&lt;span&gt;</span>
+
+<h2>draggable dom prop set to false</h2>
+
+<img src="resources/images/lime.png">
+<a href="http://webgkit.org">webkit.org</a>
+<a>&lt;a no href&gt;</a>
+<span>&lt;span&gt;</span>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/html/resources/images/lime.png b/LayoutTests/fast/html/resources/images/lime.png
new file mode 100644 (file)
index 0000000..4ba905a
Binary files /dev/null and b/LayoutTests/fast/html/resources/images/lime.png differ
index 2b805f0..9f7212d 100644 (file)
@@ -1,3 +1,31 @@
+2009-07-13  Erik Arvidsson  <arv@chromium.org>
+
+        Reviewed by Darin Adler and Maciej Stachowiak.
+
+        Implement HTML5 draggable
+        https://bugs.webkit.org/show_bug.cgi?id=26262
+
+        This adds support for the HTML5 draggable attribute and its DOM binding. It maps the draggable property
+        to the CSS properties -webkit-user-drag and -webkit-user-select respectively.
+
+        Spec: http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#the-draggable-attribute
+
+        Test: fast/html/draggable.html
+
+        * css/html.css:
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::draggable):
+        * html/HTMLAnchorElement.h:
+        * html/HTMLAttributeNames.in:
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::draggable):
+        (WebCore::HTMLElement::setDraggable):
+        * html/HTMLElement.h:
+        * html/HTMLElement.idl:
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::draggable):
+        * html/HTMLImageElement.h:
+
 2009-07-13  Simon Fraser  <simon.fraser@apple.com>
 
         Reviewed by Dan Bernstein.
index 09362cd..d511279 100644 (file)
@@ -350,6 +350,17 @@ void HTMLAnchorElement::setCoords(const AtomicString& value)
     setAttribute(coordsAttr, value);
 }
 
+bool HTMLAnchorElement::draggable() const
+{
+    // Should be draggable if we have an href attribute.
+    const AtomicString& value = getAttribute(draggableAttr);
+    if (equalIgnoringCase(value, "true"))
+        return true;
+    if (equalIgnoringCase(value, "false"))
+        return false;
+    return hasAttribute(hrefAttr);
+}
+
 KURL HTMLAnchorElement::href() const
 {
     return document()->completeURL(getAttribute(hrefAttr));
index dd4b6f9..bccc5db 100644 (file)
@@ -58,6 +58,8 @@ public:
     const AtomicString& coords() const;
     void setCoords(const AtomicString&);
 
+    virtual bool draggable() const;
+
     KURL href() const;
     void setHref(const AtomicString&);
 
index 0fc45d7..bd37b96 100644 (file)
@@ -69,6 +69,7 @@ defer
 dir
 direction
 disabled
+draggable
 enctype
 end
 expanded
index 8acc6bd..d201482 100644 (file)
@@ -143,6 +143,13 @@ void HTMLElement::parseMappedAttribute(MappedAttribute *attr)
     } else if (attr->name() == dirAttr) {
         addCSSProperty(attr, CSSPropertyDirection, attr->value());
         addCSSProperty(attr, CSSPropertyUnicodeBidi, hasLocalName(bdoTag) ? CSSValueBidiOverride : CSSValueEmbed);
+    } else if (attr->name() == draggableAttr) {
+        const AtomicString& value = attr->value();
+        if (equalIgnoringCase(value, "true")) {
+            addCSSProperty(attr, CSSPropertyWebkitUserDrag, CSSValueElement);
+            addCSSProperty(attr, CSSPropertyWebkitUserSelect, CSSValueNone);
+        } else if (equalIgnoringCase(value, "false"))
+            addCSSProperty(attr, CSSPropertyWebkitUserDrag, CSSValueNone);
     }
 // standard events
     else if (attr->name() == onclickAttr) {
@@ -692,6 +699,16 @@ void HTMLElement::setContentEditable(const String &enabled)
         setAttribute(contenteditableAttr, enabled.isEmpty() ? "true" : enabled);
 }
 
+bool HTMLElement::draggable() const
+{
+    return equalIgnoringCase(getAttribute(draggableAttr), "true");
+}
+
+void HTMLElement::setDraggable(bool value)
+{
+    setAttribute(draggableAttr, value ? "true" : "false");
+}
+
 void HTMLElement::click()
 {
     dispatchSimulatedClick(0, false, false);
index 60152cd..21b3bb5 100644 (file)
@@ -79,6 +79,9 @@ public:
     virtual void setContentEditable(MappedAttribute*);
     virtual void setContentEditable(const String&);
 
+    virtual bool draggable() const;
+    void setDraggable(bool);
+
     void click();
 
     virtual void accessKeyAction(bool sendToAnyElement);
index 38f960a..6b9e1d0 100644 (file)
@@ -36,6 +36,7 @@ module html {
                  attribute [ConvertNullToNullString, Reflect=class] DOMString className;
 
                  attribute long            tabIndex;
+                 attribute boolean         draggable;
 
         // Extensions
                  attribute [ConvertNullToNullString] DOMString innerHTML
index c4bf5dc..31e7f5e 100644 (file)
@@ -319,6 +319,12 @@ void HTMLImageElement::setBorder(const String& value)
     setAttribute(borderAttr, value);
 }
 
+bool HTMLImageElement::draggable() const
+{
+    // Image elements are draggable by default.
+    return !equalIgnoringCase(getAttribute(draggableAttr), "false");
+}
+
 void HTMLImageElement::setHeight(int value)
 {
     setAttribute(heightAttr, String::number(value));
index ae2ce38..5e82186 100644 (file)
@@ -81,6 +81,8 @@ public:
     String border() const;
     void setBorder(const String&);
 
+    virtual bool draggable() const;
+
     void setHeight(int);
 
     int hspace() const;