From d4c40e3aad39092c3b51db886956a1e043939c34 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 27 Jul 2022 19:51:49 +0100 Subject: [PATCH] LibWeb: Extract the ParentNode IDL mixin --- Userland/Libraries/LibWeb/DOM/Document.idl | 18 ++------------- .../Libraries/LibWeb/DOM/DocumentFragment.idl | 18 ++------------- Userland/Libraries/LibWeb/DOM/Element.idl | 15 +------------ Userland/Libraries/LibWeb/DOM/ParentNode.idl | 22 +++++++++++++++++++ 4 files changed, 27 insertions(+), 46 deletions(-) create mode 100644 Userland/Libraries/LibWeb/DOM/ParentNode.idl diff --git a/Userland/Libraries/LibWeb/DOM/Document.idl b/Userland/Libraries/LibWeb/DOM/Document.idl index f5dd1cdf61..d3b7c6ea6e 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.idl +++ b/Userland/Libraries/LibWeb/DOM/Document.idl @@ -11,6 +11,7 @@ #import #import #import +#import #import #import #import @@ -18,8 +19,8 @@ #import #import +// https://dom.spec.whatwg.org/#document interface Document : Node { - constructor(); boolean hasFocus(); @@ -92,26 +93,11 @@ interface Document : Node { attribute DOMString title; - // FIXME: These should all come from a ParentNode mixin - readonly attribute Element? firstElementChild; - readonly attribute Element? lastElementChild; - readonly attribute unsigned long childElementCount; - - [CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes); - [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); - [CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes); - - Element? querySelector(DOMString selectors); - [NewObject] NodeList querySelectorAll(DOMString selectors); - - [SameObject] readonly attribute HTMLCollection children; - readonly boolean hidden; readonly DOMString visibilityState; [NewObject] NodeIterator createNodeIterator(Node root, optional unsigned long whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null); [NewObject] TreeWalker createTreeWalker(Node root, optional unsigned long whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null); - }; Document includes GlobalEventHandlers; diff --git a/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl b/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl index fcee29e72c..f618c67968 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl +++ b/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl @@ -2,25 +2,11 @@ #import #import #import +#import +// https://dom.spec.whatwg.org/#documentfragment interface DocumentFragment : Node { - constructor(); Element? getElementById(DOMString id); - - // FIXME: These should all come from a ParentNode mixin - readonly attribute Element? firstElementChild; - readonly attribute Element? lastElementChild; - readonly attribute unsigned long childElementCount; - - [CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes); - [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); - [CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes); - - Element? querySelector(DOMString selectors); - [NewObject] NodeList querySelectorAll(DOMString selectors); - - [SameObject] readonly attribute HTMLCollection children; - }; diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index 2f3ff86805..e2d461d8bb 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -4,6 +4,7 @@ #import #import #import +#import #import #import @@ -46,20 +47,6 @@ interface Element : Node { [ImplementedAs=style_for_bindings] readonly attribute CSSStyleDeclaration style; - // FIXME: These should all come from a ParentNode mixin (up to and including children) - readonly attribute Element? firstElementChild; - readonly attribute Element? lastElementChild; - readonly attribute unsigned long childElementCount; - - [CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes); - [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); - [CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes); - - Element? querySelector(DOMString selectors); - [NewObject] NodeList querySelectorAll(DOMString selectors); - - [SameObject] readonly attribute HTMLCollection children; - DOMRect getBoundingClientRect(); DOMRectList getClientRects(); diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.idl b/Userland/Libraries/LibWeb/DOM/ParentNode.idl new file mode 100644 index 0000000000..fe0151b56f --- /dev/null +++ b/Userland/Libraries/LibWeb/DOM/ParentNode.idl @@ -0,0 +1,22 @@ +#import +#import +#import + +// https://dom.spec.whatwg.org/#parentnode +interface mixin ParentNode { + [SameObject] readonly attribute HTMLCollection children; + readonly attribute Element? firstElementChild; + readonly attribute Element? lastElementChild; + readonly attribute unsigned long childElementCount; + + [CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes); + [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); + [CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes); + + Element? querySelector(DOMString selectors); + [NewObject] NodeList querySelectorAll(DOMString selectors); +}; + +Document includes ParentNode; +DocumentFragment includes ParentNode; +Element includes ParentNode;