script/dom/execcommand/
basecommand.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use crate::dom::bindings::codegen::Bindings::RangeBinding::RangeMethods;
6use crate::dom::bindings::str::DOMString;
7use crate::dom::range::Range;
8use crate::dom::selection::Selection;
9
10pub(crate) trait BaseCommand {
11    fn execute(&self, selection: &Selection, value: DOMString) -> bool;
12
13    /// <https://w3c.github.io/editing/docs/execCommand/#delete-the-selection>
14    fn delete_the_selection(&self, _selection: &Selection, active_range: &Range) {
15        // Step 1. If the active range is null, abort these steps and do nothing.
16        //
17        // Always passed in as argument
18
19        // Step 2. Canonicalize whitespace at the active range's start.
20        // TODO
21
22        // Step 3. Canonicalize whitespace at the active range's end.
23        // TODO
24
25        // Step 4. Let (start node, start offset) be the last equivalent point for the active range's start.
26        // TODO
27
28        // Step 5. Let (end node, end offset) be the first equivalent point for the active range's end.
29        // TODO
30
31        // Step 6. If (end node, end offset) is not after (start node, start offset):
32        // TODO
33
34        // Step 7. If start node is a Text node and start offset is 0, set start offset to the index of start node,
35        // then set start node to its parent.
36        // TODO
37
38        // Step 8. If end node is a Text node and end offset is its length, set end offset to one plus the index of end node,
39        // then set end node to its parent.
40        // TODO
41
42        // Step 9. Call collapse(start node, start offset) on the context object's selection.
43        // TODO
44
45        // Step 10. Call extend(end node, end offset) on the context object's selection.
46        // TODO
47
48        // Step 11.
49        //
50        // This step does not exist in the spec
51
52        // Step 12. Let start block be the active range's start node.
53        // TODO
54
55        // Step 13. While start block's parent is in the same editing host and start block is an inline node, set start block to its parent.
56        // TODO
57
58        // Step 14. If start block is neither a block node nor an editing host, or "span" is not an allowed child of start block,
59        // or start block is a td or th, set start block to null.
60        // TODO
61
62        // Step 15. Let end block be the active range's end node.
63        // TODO
64
65        // Step 16. While end block's parent is in the same editing host and end block is an inline node, set end block to its parent.
66        // TODO
67
68        // Step 17. If end block is neither a block node nor an editing host, or "span" is not an allowed child of end block,
69        // or end block is a td or th, set end block to null.
70        // TODO
71
72        // Step 18.
73        //
74        // This step does not exist in the spec
75
76        // Step 19. Record current states and values, and let overrides be the result.
77        // TODO
78
79        // Step 20.
80        //
81        // This step does not exist in the spec
82
83        // Step 21. If start node and end node are the same, and start node is an editable Text node:
84        //
85        // As per the spec:
86        // > NOTE: This whole piece of the algorithm is based on deleteContents() in DOM Range, copy-pasted and then adjusted to fit.
87        let _ = active_range.DeleteContents();
88
89        // Step 22. If start node is an editable Text node, call deleteData() on it, with start offset as
90        // the first argument and (length of start node − start offset) as the second argument.
91        // TODO
92
93        // Step 23. Let node list be a list of nodes, initially empty.
94        // TODO
95
96        // Step 24. For each node contained in the active range, append node to node list if the
97        // last member of node list (if any) is not an ancestor of node; node is editable;
98        // and node is not a thead, tbody, tfoot, tr, th, or td.
99        // TODO
100
101        // Step 25. For each node in node list:
102        // TODO
103
104        // Step 26. If end node is an editable Text node, call deleteData(0, end offset) on it.
105        // TODO
106
107        // Step 27. Canonicalize whitespace at the active range's start, with fix collapsed space false.
108        // TODO
109
110        // Step 28. Canonicalize whitespace at the active range's end, with fix collapsed space false.
111        // TODO
112
113        // Step 29.
114        //
115        // This step does not exist in the spec
116
117        // Step 30. If block merging is false, or start block or end block is null, or start block is not
118        // in the same editing host as end block, or start block and end block are the same:
119        // TODO
120
121        // Step 31. If start block has one child, which is a collapsed block prop, remove its child from it.
122        // TODO
123
124        // Step 32. If start block is an ancestor of end block:
125        // TODO
126
127        // Step 33. Otherwise, if start block is a descendant of end block:
128        // TODO
129
130        // Step 34. Otherwise:
131        // TODO
132
133        // Step 35.
134        //
135        // This step does not exist in the spec
136
137        // Step 36. Let ancestor be start block.
138        // TODO
139
140        // Step 37. While ancestor has an inclusive ancestor ol in the same editing host whose nextSibling is
141        // also an ol in the same editing host, or an inclusive ancestor ul in the same editing host whose nextSibling
142        // is also a ul in the same editing host:
143        // TODO
144
145        // Step 38. Restore the values from values.
146        // TODO
147
148        // Step 39. If start block has no children, call createElement("br") on the context object and
149        // append the result as the last child of start block.
150        // TODO
151
152        // Step 40. Remove extraneous line breaks at the end of start block.
153        // TODO
154
155        // Step 41. Restore states and values from overrides.
156        // TODO
157    }
158}