diff --git a/Libraries/LibWeb/HTML/AttributeNames.h b/Libraries/LibWeb/HTML/AttributeNames.h index c6606be6ae2..757d13b8a35 100644 --- a/Libraries/LibWeb/HTML/AttributeNames.h +++ b/Libraries/LibWeb/HTML/AttributeNames.h @@ -73,6 +73,7 @@ namespace AttributeNames { __ENUMERATE_HTML_ATTRIBUTE(dirname, "dirname") \ __ENUMERATE_HTML_ATTRIBUTE(disabled, "disabled") \ __ENUMERATE_HTML_ATTRIBUTE(download, "download") \ + __ENUMERATE_HTML_ATTRIBUTE(draggable, "draggable") \ __ENUMERATE_HTML_ATTRIBUTE(enctype, "enctype") \ __ENUMERATE_HTML_ATTRIBUTE(ended, "ended") \ __ENUMERATE_HTML_ATTRIBUTE(enterkeyhint, "enterkeyhint") \ diff --git a/Libraries/LibWeb/HTML/HTMLElement.cpp b/Libraries/LibWeb/HTML/HTMLElement.cpp index 67afa68e4e1..94b2e7f4527 100644 --- a/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -2093,4 +2094,41 @@ String HTMLElement::access_key_label() const return String {}; } +// https://html.spec.whatwg.org/multipage/dnd.html#dom-draggable +bool HTMLElement::draggable() const +{ + auto attribute = get_attribute(HTML::AttributeNames::draggable); + + // If an element's draggable content attribute has the state True, the draggable IDL attribute must return true. + if (attribute.has_value() && attribute->equals_ignoring_ascii_case("true"sv)) { + return true; + } + + // If an element's draggable content attribute has the state False, the draggable IDL attribute must return false. + if (attribute.has_value() && attribute->equals_ignoring_ascii_case("false"sv)) { + return false; + } + + // Otherwise, the element's draggable content attribute has the state Auto. + + // If the element is an img element, the draggable IDL attribute must return true. + if (is(*this)) { + return true; + } + + // If the element is an object element that represents an image, the draggable IDL attribute must return true. + if (is(*this)) { + if (auto type_attribute = get_attribute(HTML::AttributeNames::type); type_attribute.has_value() && type_attribute->equals_ignoring_ascii_case("image"sv)) + return true; + } + + // If the element is an a element with an href content attribute, the draggable IDL attribute must return true. + if (is(*this) && has_attribute(HTML::AttributeNames::href)) { + return true; + } + + // Otherwise, the draggable IDL attribute must return false. + return false; +} + } diff --git a/Libraries/LibWeb/HTML/HTMLElement.h b/Libraries/LibWeb/HTML/HTMLElement.h index 9cc01fce06e..be840e4771e 100644 --- a/Libraries/LibWeb/HTML/HTMLElement.h +++ b/Libraries/LibWeb/HTML/HTMLElement.h @@ -157,6 +157,9 @@ public: bool is_inert() const { return m_inert; } + bool draggable() const; + void set_draggable(bool draggable) { MUST(set_attribute(HTML::AttributeNames::draggable, draggable ? "true"_string : "false"_string)); } + virtual bool is_valid_invoker_command(String&) { return false; } virtual void invoker_command_steps(DOM::Element&, String&) { } diff --git a/Libraries/LibWeb/HTML/HTMLElement.idl b/Libraries/LibWeb/HTML/HTMLElement.idl index 38d0b4e1a38..60e8e4fc6b7 100644 --- a/Libraries/LibWeb/HTML/HTMLElement.idl +++ b/Libraries/LibWeb/HTML/HTMLElement.idl @@ -23,7 +23,7 @@ interface HTMLElement : Element { undefined click(); [Reflect=accesskey, CEReactions] attribute DOMString accessKey; readonly attribute DOMString accessKeyLabel; - [FIXME, CEReactions] attribute boolean draggable; + [CEReactions] attribute boolean draggable; [FIXME, CEReactions] attribute boolean spellcheck; [FIXME, CEReactions] attribute DOMString autocapitalize; [FIXME, CEReactions] attribute boolean autocorrect; diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/editing/dnd/dom/draggable.txt b/Tests/LibWeb/Text/expected/wpt-import/html/editing/dnd/dom/draggable.txt new file mode 100644 index 00000000000..723d9f40d42 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/editing/dnd/dom/draggable.txt @@ -0,0 +1,32 @@ +Harness status: OK + +Found 27 tests + +27 Pass +Pass an element should have a draggable property +Pass a
element should have a draggable property +Pass an element should have a draggable property +Pass an element should be draggable by default +Pass a
element should not be draggable by default +Pass an element should be draggable by default +Pass an element with draggable="true" should be draggable +Pass a
element with draggable="true" should be draggable +Pass an element with draggable="true" should be draggable +Pass an element with draggable="false" should not be draggable +Pass a
element with draggable="false" should not be draggable +Pass an element with draggable="false" should not be draggable +Pass an element with draggable="auto" should be draggable +Pass a
element with draggable="auto" should not be draggable +Pass an element with draggable="auto" should be draggable +Pass an element with draggable="foo" should be draggable +Pass a
element with draggable="foo" should not be draggable +Pass an element with draggable="foo" should be draggable +Pass an element with the draggable property set to true through a script should be draggable +Pass a
element with the draggable property set to true through a script should be draggable +Pass an element with the draggable property set to true through a script should be draggable +Pass an element with the draggable property set to false through a script should not be draggable +Pass a
element with the draggable property set to false through a script should not be draggable +Pass an element with the draggable property set to false through a script should not be draggable +Pass an element with the draggable property set to "foo" through a script should be draggable +Pass a
element with the draggable property set to "foo" through a script should be draggable +Pass an element with the draggable property set to "foo" through a script should be draggable \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/editing/dnd/dom/draggable.html b/Tests/LibWeb/Text/input/wpt-import/html/editing/dnd/dom/draggable.html new file mode 100644 index 00000000000..08ec1080583 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/editing/dnd/dom/draggable.html @@ -0,0 +1,207 @@ + + +drag & drop – draggable attribute + + + + + + + +
+ +
+ +
+ . +
+ +
+ +
+ . +
+ +
+ +
+ . +
+ +
+ +
+ . +
+ +
+ +
+ . +
+ +
+ +
+ . +
+ +
+ +
+ . +
+ +
+ +
+ . +
+ +
+ + +
+ + + + + + + diff --git a/Tests/LibWeb/Text/input/wpt-import/html/editing/dnd/resources/1x1-transparent.gif b/Tests/LibWeb/Text/input/wpt-import/html/editing/dnd/resources/1x1-transparent.gif new file mode 100644 index 00000000000..e565824aafa Binary files /dev/null and b/Tests/LibWeb/Text/input/wpt-import/html/editing/dnd/resources/1x1-transparent.gif differ