Ver código fonte

LibWeb/SVG: Implement default_tab_index_value for a element

Another FIXME bites the dust :^)
Jamie Mansfield 11 meses atrás
pai
commit
9c4e80a3ec

+ 12 - 0
Tests/LibWeb/Text/expected/HTML/tabIndex-attribute.txt

@@ -0,0 +1,12 @@
+p.tabIndex initial value: -1
+h1.tabIndex initial value: -1
+a.tabIndex initial value: 0
+area.tabIndex initial value: 0
+button.tabIndex initial value: 0
+frame.tabIndex initial value: 0
+iframe.tabIndex initial value: 0
+input.tabIndex initial value: 0
+object.tabIndex initial value: 0
+select.tabIndex initial value: 0
+textarea.tabIndex initial value: 0
+svg.a.tabIndex initial value: 0

+ 41 - 0
Tests/LibWeb/Text/input/HTML/tabIndex-attribute.html

@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+    function tabIndexTest(tagName, element) {
+        println(`${tagName}.tabIndex initial value: ${element.tabIndex}`);
+    }
+
+    test(() => {
+        const controlTagNamesToTest = [
+            "p",
+            "h1",
+        ];
+        const tagNamesToTest = [
+            "a",
+            "area",
+            "button",
+            "frame",
+            "iframe",
+            "input",
+            "object",
+            "select",
+            "textarea",
+        ];
+        const svgTagNamesToTest = [
+            "a",
+        ];
+
+        for (const tagName of controlTagNamesToTest) {
+            const element = document.createElement(tagName);
+            tabIndexTest(tagName, element);
+        }
+        for (const tagName of tagNamesToTest) {
+            const element = document.createElement(tagName);
+            tabIndexTest(tagName, element);
+        }
+        for (const tagName of svgTagNamesToTest) {
+            const element = document.createElementNS("http://www.w3.org/2000/svg", tagName);
+            tabIndexTest(`svg.${tagName}`, element);
+        }
+    });
+</script>

+ 0 - 1
Userland/Libraries/LibWeb/DOM/Element.cpp

@@ -1184,7 +1184,6 @@ i32 Element::default_tab_index_value() const
     // The default value is 0 if the element is an a, area, button, frame, iframe, input, object, select, textarea, or SVG a element, or is a summary element that is a summary for its parent details.
     // The default value is 0 if the element is an a, area, button, frame, iframe, input, object, select, textarea, or SVG a element, or is a summary element that is a summary for its parent details.
     // The default value is −1 otherwise.
     // The default value is −1 otherwise.
     // Note: The varying default value based on element type is a historical artifact.
     // Note: The varying default value based on element type is a historical artifact.
-    // FIXME: We currently do not have the SVG a element.
     return -1;
     return -1;
 }
 }
 
 

+ 7 - 0
Userland/Libraries/LibWeb/SVG/SVGAElement.cpp

@@ -43,6 +43,13 @@ void SVGAElement::attribute_changed(FlyString const& name, Optional<String> cons
     }
     }
 }
 }
 
 
+// https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
+i32 SVGAElement::default_tab_index_value() const
+{
+    // See the base function for the spec comments.
+    return 0;
+}
+
 // https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__relList
 // https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__relList
 JS::NonnullGCPtr<DOM::DOMTokenList> SVGAElement::rel_list()
 JS::NonnullGCPtr<DOM::DOMTokenList> SVGAElement::rel_list()
 {
 {

+ 1 - 0
Userland/Libraries/LibWeb/SVG/SVGAElement.h

@@ -33,6 +33,7 @@ private:
 
 
     // ^DOM::Element
     // ^DOM::Element
     virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
     virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
+    virtual i32 default_tab_index_value() const override;
 
 
     JS::GCPtr<DOM::DOMTokenList> m_rel_list;
     JS::GCPtr<DOM::DOMTokenList> m_rel_list;
 };
 };