dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / dom / range_3.lucb
#==============================================================================================
#
# range_3 - DOM::Range: cloning and deleting contents, client rects, contextual fragments
#
# DESCRIPTION:
# Port of LibWeb/DOM/Range.cpp (lines 925-1305: cloneContents / "clone the contents",
# deleteContents, getClientRects, getBoundingClientRect, createContextualFragment) and
# the inline functions of Range.h (detach, for_each_contained and the boundary point
# mutators that CharacterData, Node and Text use).
#
#==============================================================================================
# mark: Cloning =================================================================================
## Ported from Range.cpp:924 Web::DOM::Range::clone_contents.
# https://dom.spec.whatwg.org/#dom-range-clonecontents
pub func dom_range_clone_contents(this: DomRange*) -> DomDocumentFragment*!:
return try dom_range_clone_the_contents(this)
## Ported from Range.cpp:930 Web::DOM::Range::clone_the_contents.
# https://dom.spec.whatwg.org/#concept-range-clone
func dom_range_clone_the_contents(this: DomRange*) -> DomDocumentFragment*!:
let realm = bind_platform_object_realm(this.bind_platform_object())
# 1. Let fragment be a new DocumentFragment node whose node document is range’s start node’s node document.
let fragment = realm_create_dom_document_fragment(realm, dom_node_document(dom_abstract_range_start_container(this.dom_abstract_range())))
# 2. If range is collapsed, then return fragment.
if dom_abstract_range_collapsed(this.dom_abstract_range()):
return fragment
# 3. Let original start node, original start offset, original end node, and original end offset
# be range’s start node, start offset, end node, and end offset, respectively.
let original_start_node = this.abstract_range.m_start_container
let original_start_offset = this.abstract_range.m_start_offset
let original_end_node = this.abstract_range.m_end_container
let original_end_offset = this.abstract_range.m_end_offset
# 4. If original start node is original end node and it is a CharacterData node, then:
if original_start_node == original_end_node and is_dom_character_data(original_start_node):
# 1. Let clone be a clone of original start node.
let clone = try dom_node_clone_node(original_start_node)
# 2. Set the data of clone to the result of substringing data with node original start node,
# offset original start offset, and count original end offset minus original start offset.
let result = try dom_character_data_substring_data((DomCharacterData*)original_start_node, (usize)original_start_offset, (usize)(original_end_offset -% original_start_offset))
dom_range_set_clone_data(clone, result)
# 3. Append clone to fragment.
_ = try dom_node_append_child(fragment.dom_node(), clone)
# 4. Return fragment.
return fragment
# 5. Let common ancestor be original start node.
var common_ancestor = original_start_node
# 6. While common ancestor is not an inclusive ancestor of original end node, set common ancestor to its own parent.
while not tree_node_is_inclusive_ancestor_of(common_ancestor, original_end_node):
common_ancestor = dom_node_parent_node(common_ancestor) else trap("VERIFY: parent node")
# 7. Let first partially contained child be null.
var first_partially_contained_child: DomNode*? = none
# 8. If original start node is not an inclusive ancestor of original end node,
# set first partially contained child to the first child of common ancestor that is partially contained in range.
if not tree_node_is_inclusive_ancestor_of(original_start_node, original_end_node):
var child_node = tree_node_first_child(common_ancestor)
while let child = child_node:
if dom_range_partially_contains_node(this, child):
first_partially_contained_child = child
break
child_node = tree_node_next_sibling(child)
# 9. Let last partially contained child be null.
var last_partially_contained_child: DomNode*? = none
# 10. If original end node is not an inclusive ancestor of original start node,
# set last partially contained child to the last child of common ancestor that is partially contained in range.
if not tree_node_is_inclusive_ancestor_of(original_end_node, original_start_node):
var child_node = tree_node_last_child(common_ancestor)
while let child = child_node:
if dom_range_partially_contains_node(this, child):
last_partially_contained_child = child
break
child_node = tree_node_previous_sibling(child)
# 11. Let contained children be a list of all children of common ancestor that are contained in range, in tree order.
var contained_children: ak.Vector[DomNode*]
for node in dom_node_children(common_ancestor):
if dom_range_contains_node(this, node):
ak.vector_append_t(&contained_children, node)
# 12. If any member of contained children is a doctype, then throw a "HierarchyRequestError" DOMException.
for child in ak.vector_span(&contained_children):
if is_dom_document_type(child):
try idl_throw(.idl_dom_exception(idl_hierarchy_request_error_create(realm, ak.utf16_string_from_str("Contained child is a DocumentType"))))
# 13. If first partially contained child is a CharacterData node, then:
if first_partially_contained_child != none and is_dom_character_data(first_partially_contained_child else trap("unreachable")):
# 1. Let clone be a clone of original start node.
let clone = try dom_node_clone_node(original_start_node)
# 2. Set the data of clone to the result of substringing data with node original start node, offset original start offset,
# and count original start node’s length minus original start offset.
let result = try dom_character_data_substring_data((DomCharacterData*)original_start_node, (usize)original_start_offset, dom_node_length(original_start_node) -% (usize)original_start_offset)
dom_range_set_clone_data(clone, result)
# 3. Append clone to fragment.
_ = try dom_node_append_child(fragment.dom_node(), clone)
# 14. Otherwise, if first partially contained child is not null:
elif let first_child = first_partially_contained_child:
# 1. Let clone be a clone of first partially contained child.
let clone = try dom_node_clone_node(first_child)
# 2. Append clone to fragment.
_ = try dom_node_append_child(fragment.dom_node(), clone)
# 3. Let subrange be a new live range whose start is (original start node, original start offset) and whose end is (first partially contained child, first partially contained child’s length).
let subrange = dom_range_create_dom_node(original_start_node, original_start_offset, first_child, (u32)dom_node_length(first_child))
# 4. Let subfragment be the result of cloning the contents of subrange.
let subfragment = try dom_range_clone_the_contents(subrange)
# 5. Append subfragment to clone.
_ = try dom_node_append_child(clone, subfragment.dom_node())
# 15. For each contained child in contained children.
for contained_child in ak.vector_span(&contained_children):
# 1. Let clone be a clone of contained child with the clone children flag set.
let clone = try dom_node_clone_node(contained_child, none, true)
# 2. Append clone to fragment.
_ = try dom_node_append_child(fragment.dom_node(), clone)
# 16. If last partially contained child is a CharacterData node, then:
if last_partially_contained_child != none and is_dom_character_data(last_partially_contained_child else trap("unreachable")):
# 1. Let clone be a clone of original end node.
let clone = try dom_node_clone_node(original_end_node)
# 2. Set the data of clone to the result of substringing data with node original end node, offset 0, and count original end offset.
let result = try dom_character_data_substring_data((DomCharacterData*)original_end_node, 0, (usize)original_end_offset)
dom_range_set_clone_data(clone, result)
# 3. Append clone to fragment.
_ = try dom_node_append_child(fragment.dom_node(), clone)
# 17. Otherwise, if last partially contained child is not null:
elif let last_child = last_partially_contained_child:
# 1. Let clone be a clone of last partially contained child.
let clone = try dom_node_clone_node(last_child)
# 2. Append clone to fragment.
_ = try dom_node_append_child(fragment.dom_node(), clone)
# 3. Let subrange be a new live range whose start is (last partially contained child, 0) and whose end is (original end node, original end offset).
let subrange = dom_range_create_dom_node(last_child, 0, original_end_node, original_end_offset)
# 4. Let subfragment be the result of cloning the contents of subrange.
let subfragment = try dom_range_clone_the_contents(subrange)
# 5. Append subfragment to clone.
_ = try dom_node_append_child(clone, subfragment.dom_node())
# 18. Return fragment.
return fragment
# mark: Deleting ================================================================================
## Ported from Range.cpp:1086 Web::DOM::Range::delete_contents.
# https://dom.spec.whatwg.org/#dom-range-deletecontents
pub func dom_range_delete_contents(this: DomRange*) -> !:
# 1. If this is collapsed, then return.
if dom_abstract_range_collapsed(this.dom_abstract_range()):
return
# 2. Let originalStartNode, originalStartOffset, originalEndNode, and originalEndOffset be this’s start node,
# start offset, end node, and end offset, respectively.
let original_start_node = this.abstract_range.m_start_container
let original_start_offset = this.abstract_range.m_start_offset
let original_end_node = this.abstract_range.m_end_container
let original_end_offset = this.abstract_range.m_end_offset
# 3. If originalStartNode is originalEndNode and it is a CharacterData node:
if original_start_node == original_end_node and is_dom_character_data(original_start_node):
# 1. Replace data of originalStartNode with originalStartOffset, originalEndOffset − originalStartOffset, and
# the empty string.
try dom_character_data_replace_data((DomCharacterData*)original_start_node, (usize)original_start_offset, (usize)(original_end_offset -% original_start_offset), ak.utf16_view_new())
# 2. Return.
return
# 4. Let nodesToRemove be a list of all the nodes that are contained in this, in tree order, omitting any node
# whose parent is also contained in this.
var nodes_to_remove: ak.Vector[DomNode*?]
let end_next_sibling = tree_node_next_sibling(dom_abstract_range_end_container(this.dom_abstract_range()))
var node_cursor: DomNode*? = dom_abstract_range_start_container(this.dom_abstract_range())
while node_cursor != end_next_sibling:
let node = node_cursor else break
if dom_range_contains_node(this, node):
let parent = dom_node_parent_node(node)
if parent == none or not dom_range_contains_node(this, parent else trap("unreachable")):
ak.vector_append_t(&nodes_to_remove, node)
node_cursor = tree_node_next_in_pre_order(node)
# 5. Let newNode and newOffset be null.
var new_node: DomNode*? = none
var new_offset: usize = 0
# 6. If originalStartNode is an inclusive ancestor of originalEndNode, then set newNode to originalStartNode and
# newOffset to originalStartOffset.
if tree_node_is_inclusive_ancestor_of(original_start_node, original_end_node):
new_node = original_start_node
new_offset = (usize)original_start_offset
# 7. Otherwise
else:
# 1. Let referenceNode be originalStartNode.
var reference_node = original_start_node
# 2. While referenceNode’s parent is non-null and is not an inclusive ancestor of originalEndNode:
# set referenceNode to its parent.
while let parent = dom_node_parent_node(reference_node):
if tree_node_is_inclusive_ancestor_of(parent, original_end_node):
break
reference_node = parent
# 3. Set newNode to referenceNode’s parent and newOffset to referenceNode’s index + 1.
new_node = dom_node_parent_node(reference_node)
new_offset = tree_node_index(reference_node) + 1
# 8. Set this’s start and end to (newNode, newOffset).
let new_node_value = new_node else trap("VERIFY: new node")
try dom_range_set_start(this, new_node_value, (u32)new_offset)
try dom_range_set_end(this, new_node_value, (u32)new_offset)
# 9. If originalStartNode is a CharacterData node, then replace data of originalStartNode with
# originalStartOffset, originalStartNode’s length − originalStartOffset, and the empty string.
if is_dom_character_data(original_start_node):
try dom_character_data_replace_data((DomCharacterData*)original_start_node, (usize)original_start_offset, dom_node_length(original_start_node) -% (usize)original_start_offset, ak.utf16_view_new())
# 10. For each node of nodesToRemove, in tree order: remove node.
for node in ak.vector_span(&nodes_to_remove):
dom_node_remove(node else trap("VERIFY: node to remove"))
# 11. If originalEndNode is a CharacterData node, then replace data of originalEndNode with 0, originalEndOffset,
# and the empty string.
if is_dom_character_data(original_end_node):
try dom_character_data_replace_data((DomCharacterData*)original_end_node, 0, (usize)original_end_offset, ak.utf16_view_new())
# mark: Client rects ============================================================================
## `static_cast<double>(CSSPixels)`.
func dom_range_css_pixels_to_double(value: gfx.CssPixels) -> f64:
return gfx.css_pixels_to_double_const(&value)
## Ported from Range.cpp:1164 Web::DOM::Range::get_client_rects.
# https://drafts.csswg.org/cssom-view/#dom-element-getclientrects
# https://drafts.csswg.org/cssom-view/#extensions-to-the-range-interface
pub func dom_range_get_client_rects(this: DomRange*) -> GeometryDomRectList*:
let realm = bind_platform_object_realm(this.bind_platform_object())
let document = dom_node_document(dom_abstract_range_start_container(this.dom_abstract_range()))
# 1. return an empty DOMRectList object if the range is not in the document
var no_rects: ak.Vector[GeometryDomRect*?]
if dom_document_navigable(document) == none:
return geometry_dom_rect_list_create(realm, no_rects)
dom_document_update_layout(document, DomUpdateLayoutReason.range_get_client_rects)
var rects: ak.Vector[GeometryDomRect*?]
# FIXME: take Range collapsed into consideration
# 2. Iterate the node included in Range
var start_node = dom_abstract_range_start_container(this.dom_abstract_range())
if not is_dom_text(start_node):
start_node = tree_node_child_at_index(start_node, (usize)this.abstract_range.m_start_offset) else trap("VERIFY: child at start offset")
var end_node = dom_abstract_range_end_container(this.dom_abstract_range())
if not is_dom_text(end_node):
# end offset shouldn't be 0
if this.abstract_range.m_end_offset == 0:
return geometry_dom_rect_list_create(realm, no_rects)
end_node = tree_node_child_at_index(end_node, (usize)(this.abstract_range.m_end_offset - 1)) else trap("VERIFY: child at end offset")
var node_cursor: DomNode*? = start_node
while let node = node_cursor:
if node == tree_node_next_in_pre_order(end_node):
break
var selection_state = PaintPaintableSelectionState.full
if node == start_node and node == end_node:
if this.abstract_range.m_start_offset == this.abstract_range.m_end_offset:
selection_state = PaintPaintableSelectionState.none_
else:
selection_state = PaintPaintableSelectionState.start_and_end
elif node == start_node:
selection_state = PaintPaintableSelectionState.start
elif node == end_node:
selection_state = PaintPaintableSelectionState.end
let node_type = (DomNodeType)dom_node_node_type(node)
if node_type == DomNodeType.element_node:
# 1. For each element selected by the range, whose parent is not selected by the range, include the border
# areas returned by invoking getClientRects() on the element.
if dom_range_contains_node(this, node) and not dom_range_contains_node(this, tree_node_parent(node) else trap("VERIFY: parent")):
let element = (DomElement*)node
let element_rects = dom_element_get_client_rects(element)
for rect in ak.vector_span_const(&element_rects):
let dom_rect = geometry_dom_rect_construct_impl(realm, dom_range_css_pixels_to_double(gfx.css_pixel_rect_x(&rect)), dom_range_css_pixels_to_double(gfx.css_pixel_rect_y(&rect)), dom_range_css_pixels_to_double(gfx.css_pixel_rect_width(&rect)), dom_range_css_pixels_to_double(gfx.css_pixel_rect_height(&rect))) else trap("MUST: DOMRect::construct_impl")
ak.vector_append_t(&rects, dom_rect)
elif node_type == DomNodeType.text_node:
# 2. For each Text node selected or partially selected by the range (including when the boundary-points
# are identical), include scaled DOMRect object (for the part that is selected, not the whole line box).
let paintable = dom_node_paintable(node)
if paintable != none and selection_state != PaintPaintableSelectionState.none_:
let text_paintable = paintable else trap("unreachable")
var paintable_lines: PaintPaintableWithLines*? = none
if let containing_block = paint_paintable_containing_block(text_paintable):
paintable_lines = as_if_paint_paintable_with_lines(containing_block)
if let lines = paintable_lines:
let fragments = paint_paintable_with_lines_fragments_const(lines)
for fragment in &ak.vector_span_const(&fragments):
let rect = paint_paintable_fragment_range_rect(fragment, selection_state, (usize)dom_abstract_range_start_offset(this.dom_abstract_range()), (usize)dom_abstract_range_end_offset(this.dom_abstract_range()))
ak.vector_append_t(&rects, geometry_dom_rect_create(realm, gfx.css_pixel_rect_to_type_f32(&rect)))
else:
let description = dom_node_debug_description(node)
let description_view = ak.string_bytes_as_string_view(&description)
ak.dbgln(f"FIXME: Failed to get client rects for node {ak.string_view_text(description_view)}")
node_cursor = tree_node_next_in_pre_order(node)
return geometry_dom_rect_list_create(realm, rects)
## A `Gfx::Rect<double>` (the template has no double instantiation in gfx).
struct DomRangeDoubleRect:
var x: f64
var y: f64
var width: f64
var height: f64
## Gfx::Rect<double>::unite (Rect.h:470, with unite_horizontally and unite_vertically).
func dom_range_double_rect_unite(this: DomRangeDoubleRect*, other: DomRangeDoubleRect):
if this.width <= 0.0 or this.height <= 0.0:
*this = other
return
if other.width <= 0.0 or other.height <= 0.0:
return
let new_left = this.x if this.x < other.x else other.x
let new_right = this.x + this.width if this.x + this.width > other.x + other.width else other.x + other.width
this.x = new_left
this.width = new_right - this.x
let new_top = this.y if this.y < other.y else other.y
let new_bottom = this.y + this.height if this.y + this.height > other.y + other.height else other.y + other.height
this.y = new_top
this.height = new_bottom - this.y
## Ported from Range.cpp:1231 Web::DOM::Range::get_bounding_client_rect.
# https://w3c.github.io/csswg-drafts/cssom-view/#dom-range-getboundingclientrect
pub func dom_range_get_bounding_client_rect(this: DomRange*) -> GeometryDomRect*:
let realm = bind_platform_object_realm(this.bind_platform_object())
# 1. Let list be the result of invoking getClientRects() on element.
let list = dom_range_get_client_rects(this)
# 2. If the list is empty return a DOMRect object whose x, y, width and height members are zero.
if geometry_dom_rect_list_length(list) == 0:
return geometry_dom_rect_construct_impl(realm, 0.0, 0.0, 0.0, 0.0) else trap("FIXME: should propagate errors")
# 3. If all rectangles in list have zero width or height, return the first rectangle in list.
var all_rectangle_has_zero_width_or_height = true
for i: u32 in 0..<geometry_dom_rect_list_length(list):
let rect = geometry_dom_rect_list_item(list, i) else trap("VERIFY: rect")
if geometry_dom_rect_read_only_width(rect) != 0.0 and geometry_dom_rect_read_only_height(rect) != 0.0:
all_rectangle_has_zero_width_or_height = false
break
if all_rectangle_has_zero_width_or_height:
return geometry_dom_rect_list_item(list, 0) else trap("VERIFY: rect")
# 4. Otherwise, return a DOMRect object describing the smallest rectangle that includes all of the rectangles in
# list of which the height or width is not zero.
let first_rect = geometry_dom_rect_list_item(list, 0) else trap("VERIFY: rect")
var bounding_rect = DomRangeDoubleRect(x = geometry_dom_rect_read_only_x(first_rect), y = geometry_dom_rect_read_only_y(first_rect), width = geometry_dom_rect_read_only_width(first_rect), height = geometry_dom_rect_read_only_height(first_rect))
for i: u32 in 1..<geometry_dom_rect_list_length(list):
let rect = geometry_dom_rect_list_item(list, i) else trap("VERIFY: rect")
if geometry_dom_rect_read_only_width(rect) == 0.0 or geometry_dom_rect_read_only_height(rect) == 0.0:
continue
dom_range_double_rect_unite(&bounding_rect, DomRangeDoubleRect(x = geometry_dom_rect_read_only_x(rect), y = geometry_dom_rect_read_only_y(rect), width = geometry_dom_rect_read_only_width(rect), height = geometry_dom_rect_read_only_height(rect)))
# bounding_rect.to_type<float>()
let float_rect = gfx.FloatRect(m_location = gfx.FloatPoint(m_x = (f32)bounding_rect.x, m_y = (f32)bounding_rect.y), m_size = gfx.FloatSize(m_width = (f32)bounding_rect.width, m_height = (f32)bounding_rect.height))
return geometry_dom_rect_create(realm, float_rect)
# mark: Contextual fragments ====================================================================
## Ported from Range.cpp:1266 Web::DOM::Range::create_contextual_fragment.
# https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-range-createcontextualfragment
pub func dom_range_create_contextual_fragment(this: DomRange*, string: TrustedTypesTrustedHtmlOrString) -> DomDocumentFragment*!:
# 1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with
# TrustedHTML, this's relevant global object, string, "Range createContextualFragment", and "script".
# (TrustedTypes::Script.to_string() is "'script'".)
let compliant_string = try trusted_types_get_trusted_type_compliant_string(TrustedTypesTrustedTypeName.trusted_html, html_relevant_global_object((JsObject*)this), dom_element_trusted_html_or_string_as_trusted_type(string), TrustedTypesInjectionSink.range_create_contextual_fragment, ak.string_from_str("'script'"))
# 2. Let node be this's start node.
let node = dom_abstract_range_start_container(this.dom_abstract_range())
# 3. Let element be null.
var element: DomElement*? = none
let node_type = (DomNodeType)dom_node_node_type(node)
# 4. If node implements Element, set element to node.
if node_type == DomNodeType.element_node:
element = (DomElement*)node
# 5. Otherwise, if node implements Text or Comment node, set element to node's parent element.
elif node_type == DomNodeType.text_node or node_type == DomNodeType.comment_node:
element = dom_node_parent_element(node)
# 6. If either element is null or all of the following are true:
# - element's node document is an HTML document,
# - element's local name is "html"; and
# - element's namespace is the HTML namespace;
if element == none or is_html_html_element(element else trap("unreachable")):
# then set element to the result of creating an element given this's node document,
# "body", and the HTML namespace.
element = try dom_create_element(dom_node_document(node), html_tag_names_body, namespace_html)
# 7. Return the result of invoking the fragment parsing algorithm steps with element, compliantString, and Fragment.
let context = element else trap("unreachable")
let compliant_utf8 = ak.utf16_string_base_to_utf8_but_should_be_ported_to_utf16(&compliant_string.utf16_string_base)
return try dom_element_parse_fragment(context, ak.string_bytes_as_string_view(&compliant_utf8), HtmlParserScriptingMode.fragment)
# mark: Range.h =================================================================================
## Ported from Range.h:69 Web::DOM::Range::detach.
# https://dom.spec.whatwg.org/#dom-range-detach
pub func dom_range_detach(this: DomRange*):
# The detach() method steps are to do nothing.
# Note: Its functionality (disabling a Range object) was removed, but the method itself is preserved for compatibility.
return
## Ported from Range.h:100 Web::DOM::Range::for_each_contained.
pub func dom_range_for_each_contained_const(this: DomRange*, callback: ak.Function1[DomNode*, ak.IterationDecision]):
dom_range_for_each_contained(this, callback)
## Ported from Range.h:106 Web::DOM::Range::for_each_contained.
pub func dom_range_for_each_contained(this: DomRange*, callback: ak.Function1[DomNode*, ak.IterationDecision]):
let call = callback.call else trap("VERIFY: callback")
var end: DomNode*? = this.abstract_range.m_end_container
while let end_node = end:
if tree_node_next_sibling(end_node) != none:
break
end = tree_node_parent(end_node)
if let end_node = end:
end = tree_node_next_sibling(end_node)
var node_cursor: DomNode*? = this.abstract_range.m_start_container
while let node = node_cursor:
if node_cursor == end:
break
if dom_range_contains_node(this, node):
if call(callback.context, node) == ak.IterationDecision.break_:
return
node_cursor = tree_node_next_in_pre_order(node)
## Ported from Range.h:143 Web::DOM::Range::set_start_node.
pub func dom_range_set_start_node(this: DomRange*, node: DomNode*):
this.abstract_range.m_start_container = node
## Ported from Range.h:144 Web::DOM::Range::set_start_offset.
pub func dom_range_set_start_offset(this: DomRange*, offset: u32):
this.abstract_range.m_start_offset = offset
## Ported from Range.h:145 Web::DOM::Range::set_end_node.
pub func dom_range_set_end_node(this: DomRange*, node: DomNode*):
this.abstract_range.m_end_container = node
## Ported from Range.h:146 Web::DOM::Range::set_end_offset.
pub func dom_range_set_end_offset(this: DomRange*, offset: u32):
this.abstract_range.m_end_offset = offset
## Ported from Range.h:148 Web::DOM::Range::increase_start_offset.
pub func dom_range_increase_start_offset(this: DomRange*, count: u32):
this.abstract_range.m_start_offset = this.abstract_range.m_start_offset +% count
## Ported from Range.h:149 Web::DOM::Range::increase_end_offset.
pub func dom_range_increase_end_offset(this: DomRange*, count: u32):
this.abstract_range.m_end_offset = this.abstract_range.m_end_offset +% count
## Ported from Range.h:150 Web::DOM::Range::decrease_start_offset.
pub func dom_range_decrease_start_offset(this: DomRange*, count: u32):
this.abstract_range.m_start_offset = this.abstract_range.m_start_offset -% count
## Ported from Range.h:151 Web::DOM::Range::decrease_end_offset.
pub func dom_range_decrease_end_offset(this: DomRange*, count: u32):
this.abstract_range.m_end_offset = this.abstract_range.m_end_offset -% count