| OLD | NEW |
| 1 Sky DOM APIs | 1 Sky DOM APIs |
| 2 ============ | 2 ============ |
| 3 | 3 |
| 4 ```javascript | 4 ```javascript |
| 5 | 5 |
| 6 // DOM | 6 // DOM |
| 7 | 7 |
| 8 typedef ChildNode (Element or Text); | 8 typedef ChildNode (Element or Text); |
| 9 typedef ChildArgument (Element or Text or String); | 9 typedef ChildArgument (Element or Text or String); |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 void insertBefore(ChildArgument... nodes); // O(N) in number of arguments plus
all their descendants | 23 void insertBefore(ChildArgument... nodes); // O(N) in number of arguments plus
all their descendants |
| 24 void insertAfter(ChildArgument... nodes); // O(N) in number of arguments plus
all their descendants | 24 void insertAfter(ChildArgument... nodes); // O(N) in number of arguments plus
all their descendants |
| 25 void replaceWith(ChildArgument... nodes); // O(N) in number of descendants plu
s arguments plus all their descendants | 25 void replaceWith(ChildArgument... nodes); // O(N) in number of descendants plu
s arguments plus all their descendants |
| 26 void remove(); // O(N) in number of descendants | 26 void remove(); // O(N) in number of descendants |
| 27 Node cloneNode(Boolean deep = false); // O(1) if deep=false, O(N) in the numbe
r of descendants if deep=true | 27 Node cloneNode(Boolean deep = false); // O(1) if deep=false, O(N) in the numbe
r of descendants if deep=true |
| 28 | 28 |
| 29 // called when parentNode changes | 29 // called when parentNode changes |
| 30 virtual void parentChangeCallback(ParentNode? oldParent, ParentNode? newParent
, ChildNode? previousSibling, ChildNode? nextSibling); // O(N) in descendants (c
alls attached/detached) | 30 virtual void parentChangeCallback(ParentNode? oldParent, ParentNode? newParent
, ChildNode? previousSibling, ChildNode? nextSibling); // O(N) in descendants (c
alls attached/detached) |
| 31 virtual void attachedCallback(); // noop | 31 virtual void attachedCallback(); // noop |
| 32 virtual void detachedCallback(); // noop | 32 virtual void detachedCallback(); // noop |
| 33 |
| 34 readonly attribute ElementStyleDeclarationList? style; // O(1) |
| 35 // for nodes that aren't reachable from the Application Document, returns nu
ll |
| 36 // (so in particular orphaned subtrees and nodes in module documents don't h
ave one) |
| 37 // -- should be updated when the node's parent chain changes (same time as,
e.g., |
| 38 // the id hashtable is updated) |
| 39 // also always returns null for ContentElement elements and ShadowRoot nodes |
| 40 readonly attribute RenderNode? renderNode; // O(1) |
| 41 // this will be null until the first time it is rendered |
| 42 // it becomes null again when it is taken out of the rendering (see style.md
) |
| 43 abstract virtual LayoutManagerConstructor getLayoutManager(); // O(1) |
| 44 void resetLayoutManager(); // O(1) |
| 45 // if renderNode is non-null: |
| 46 // sets renderNode.layoutManager to null |
| 47 // sets renderNode.needsManager to true |
| 33 } | 48 } |
| 34 | 49 |
| 35 abstract class ParentNode : Node { | 50 abstract class ParentNode : Node { |
| 36 readonly attribute ChildNode? firstChild; // O(1) | 51 readonly attribute ChildNode? firstChild; // O(1) |
| 37 readonly attribute ChildNode? lastChild; // O(1) | 52 readonly attribute ChildNode? lastChild; // O(1) |
| 38 | 53 |
| 39 // Returns a new Array every time. | 54 // Returns a new Array every time. |
| 40 Array<ChildNode> getChildNodes(); // O(N) in number of child nodes | 55 Array<ChildNode> getChildNodes(); // O(N) in number of child nodes |
| 41 Array<Element> getChildElements(); // O(N) in number of child nodes // TODO(ia
nh): might not be necessary if we have the parser drop unnecessary whitespace te
xt nodes | 56 Array<Element> getChildElements(); // O(N) in number of child nodes // TODO(ia
nh): might not be necessary if we have the parser drop unnecessary whitespace te
xt nodes |
| 42 | 57 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 62 // Returns a new Array and new Attr instances every time. | 77 // Returns a new Array and new Attr instances every time. |
| 63 Array<Attr> getAttributes(); // O(N) in number of attributes | 78 Array<Attr> getAttributes(); // O(N) in number of attributes |
| 64 | 79 |
| 65 readonly attribute ShadowRoot? shadowRoot; // O(1) // returns the shadow root | 80 readonly attribute ShadowRoot? shadowRoot; // O(1) // returns the shadow root |
| 66 Array<ContentElement> getDestinationInsertionPoints(); // O(N) in number of in
sertion points the node is in | 81 Array<ContentElement> getDestinationInsertionPoints(); // O(N) in number of in
sertion points the node is in |
| 67 | 82 |
| 68 virtual void endTagParsedCallback(); // noop | 83 virtual void endTagParsedCallback(); // noop |
| 69 virtual void attributeChangeCallback(String name, String? oldValue, String? ne
wValue); // noop | 84 virtual void attributeChangeCallback(String name, String? oldValue, String? ne
wValue); // noop |
| 70 // TODO(ianh): does a node ever need to know when it's been redistributed? | 85 // TODO(ianh): does a node ever need to know when it's been redistributed? |
| 71 | 86 |
| 72 readonly attribute ElementStyleDeclarationList style; // O(1) | |
| 73 readonly attribute RenderNode? renderNode; // O(1) | |
| 74 // this will be null until the first time it is rendered | |
| 75 virtual LayoutManagerConstructor getLayoutManager(); // O(1) | 87 virtual LayoutManagerConstructor getLayoutManager(); // O(1) |
| 76 // default implementation looks up the 'display' property and returns the va
lue: | 88 // default implementation looks up the 'display' property and returns the va
lue: |
| 77 // if (renderNode) | 89 // if (renderNode) |
| 78 // return renderNode.getProperty(phDisplay); | 90 // return renderNode.getProperty(phDisplay); |
| 79 // return null; | 91 // return null; |
| 80 void resetLayoutManager(); // O(1) | |
| 81 // if renderNode is non-null: | |
| 82 // sets renderNode.layoutManager to null | |
| 83 // sets renderNode.needsManager to true | |
| 84 } | 92 } |
| 85 | 93 |
| 86 class Text : Node { | 94 class Text : Node { |
| 87 constructor (String value = ''); // O(1) | 95 constructor (String value = ''); // O(1) |
| 88 attribute String value; // O(1) | 96 attribute String value; // O(1) |
| 89 | 97 |
| 90 void replaceWith(String node); // O(1) // special case override of Node.replac
eWith() | 98 void replaceWith(String node); // O(1) // special case override of Node.replac
eWith() |
| 91 | 99 |
| 92 virtual void valueChangeCallback(String? oldValue, String? newValue); // noop | 100 virtual void valueChangeCallback(String? oldValue, String? newValue); // noop |
| 101 |
| 102 virtual LayoutManagerConstructor getLayoutManager(); // O(1) |
| 103 // default implementation returns TextLayoutManager's constructor |
| 93 } | 104 } |
| 94 | 105 |
| 95 class DocumentFragment : ParentNode { | 106 class DocumentFragment : ParentNode { |
| 96 constructor (ChildArguments... nodes); // O(N) in number of arguments plus all
their descendants | 107 constructor (ChildArguments... nodes); // O(N) in number of arguments plus all
their descendants |
| 97 } | 108 } |
| 98 | 109 |
| 99 abstract class TreeScope : ParentNode { | 110 abstract class TreeScope : ParentNode { |
| 100 readonly attribute Document? ownerDocument; // O(1) | 111 readonly attribute Document? ownerDocument; // O(1) |
| 101 readonly attribute TreeScope? parentScope; // O(1) | 112 readonly attribute TreeScope? parentScope; // O(1) |
| 102 | 113 |
| 103 Element? findId(String id); // O(1) | 114 Element? findId(String id); // O(1) |
| 104 } | 115 } |
| 105 | 116 |
| 106 class ShadowRoot : TreeScope { | 117 class ShadowRoot : TreeScope { |
| 107 constructor (Element host); // O(1) // note that there is no way in the API to
use a newly created ShadowRoot | 118 constructor (Element host); // O(1) // note that there is no way in the API to
use a newly created ShadowRoot |
| 108 readonly attribute Element host; // O(1) | 119 readonly attribute Element host; // O(1) |
| 109 } | 120 } |
| 110 | 121 |
| 111 class Document : TreeScope { | 122 class Document : TreeScope { |
| 112 constructor (ChildArguments... nodes); // O(N) in number of arguments plus all
their descendants | 123 constructor (ChildArguments... nodes); // O(N) in number of arguments plus all
their descendants |
| 124 |
| 125 virtual LayoutManagerConstructor getLayoutManager(); // O(1) |
| 126 // default implementation returns sky.rootLayoutManager; |
| 113 } | 127 } |
| 114 | 128 |
| 115 class SelectorQuery { | 129 attribute LayoutManagerConstructor rootLayoutManager; // O(1) |
| 116 constructor (String selector); // O(F()) where F() is the complexity of the se
lector | 130 // initially configured to return BlockLayoutManager |
| 117 | |
| 118 Boolean matches(Element element); // O(F()) | |
| 119 Element? find(Element root); // O(N*F())+O(M) where N is the number of descend
ants and M the average depth of the tree | |
| 120 Element? find(DocumentFragment root); // O(N*F())+O(M) where N is the number o
f descendants and M the average depth of the tree | |
| 121 Element? find(TreeScope root); // O(N*F()) where N is the number of descendant
s | |
| 122 Array<Element> findAll(Element root); // O(N*F())+O(N*M) where N is the number
of descendants and M the average depth of the tree | |
| 123 Array<Element> findAll(DocumentFragment root); // O(N*F())+O(N*M) where N is t
he number of descendants and M the average depth of the tree | |
| 124 Array<Element> findAll(TreeScope root); // O(N*F()) where N is the number of d
escendants | |
| 125 } | |
| 126 | 131 |
| 127 | 132 |
| 128 // BUILT-IN ELEMENTS | 133 // BUILT-IN ELEMENTS |
| 129 | 134 |
| 130 class ImportElement : Element { | 135 class ImportElement : Element { |
| 131 constructor (Dictionary<String> attributes, ChildArguments... nodes); // O(M+N
), M = number of attributes, N = number of nodes plus all their descendants | 136 constructor (Dictionary<String> attributes, ChildArguments... nodes); // O(M+N
), M = number of attributes, N = number of nodes plus all their descendants |
| 132 constructor (ChildArguments... nodes); // shorthand | 137 constructor (ChildArguments... nodes); // shorthand |
| 133 constructor (Dictionary<String> attributes); // shorthand | 138 constructor (Dictionary<String> attributes); // shorthand |
| 134 constructor (); // shorthand | 139 constructor (); // shorthand |
| 135 constructor attribute String tagName; // O(1) // "import" | 140 constructor attribute String tagName; // O(1) // "import" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 252 |
| 248 interface ElementConstructor { | 253 interface ElementConstructor { |
| 249 constructor (Dictionary<String> attributes, ChildArguments... nodes); // O(M+N
), M = number of attributes, N = number of nodes plus all their descendants | 254 constructor (Dictionary<String> attributes, ChildArguments... nodes); // O(M+N
), M = number of attributes, N = number of nodes plus all their descendants |
| 250 constructor (ChildArguments... nodes); // shorthand | 255 constructor (ChildArguments... nodes); // shorthand |
| 251 constructor (Dictionary<String> attributes); // shorthand | 256 constructor (Dictionary<String> attributes); // shorthand |
| 252 constructor (); // shorthand | 257 constructor (); // shorthand |
| 253 | 258 |
| 254 constructor attribute String tagName; | 259 constructor attribute String tagName; |
| 255 constructor attribute Boolean shadow; | 260 constructor attribute Boolean shadow; |
| 256 } | 261 } |
| 262 |
| 263 class SelectorQuery { |
| 264 constructor (String selector); // O(F()) where F() is the complexity of the se
lector |
| 265 |
| 266 Boolean matches(Element element); // O(F()) |
| 267 Element? find(Element root); // O(N*F())+O(M) where N is the number of descend
ants and M the average depth of the tree |
| 268 Element? find(DocumentFragment root); // O(N*F())+O(M) where N is the number o
f descendants and M the average depth of the tree |
| 269 Element? find(TreeScope root); // O(N*F()) where N is the number of descendant
s |
| 270 Array<Element> findAll(Element root); // O(N*F())+O(N*M) where N is the number
of descendants and M the average depth of the tree |
| 271 Array<Element> findAll(DocumentFragment root); // O(N*F())+O(N*M) where N is t
he number of descendants and M the average depth of the tree |
| 272 Array<Element> findAll(TreeScope root); // O(N*F()) where N is the number of d
escendants |
| 273 } |
| 257 ``` | 274 ``` |
| OLD | NEW |