mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:48:11 +00:00
LibWeb: Rename "for_each_in_subtree(_of_type)" to "for_each_in_inclusive_subtree(_of_type)"
This is because it includes the initial node that the function was called on, which makes it "inclusive" as according to the spec. This is important as there are non-inclusive variants, particularly used in the node mutation algorithms.
This commit is contained in:
parent
f482628fe5
commit
ca71ac484b
12 changed files with 29 additions and 29 deletions
|
@ -37,7 +37,7 @@ StyleInvalidator::StyleInvalidator(DOM::Document& document)
|
||||||
if (!m_document.should_invalidate_styles_on_attribute_changes())
|
if (!m_document.should_invalidate_styles_on_attribute_changes())
|
||||||
return;
|
return;
|
||||||
auto& style_resolver = m_document.style_resolver();
|
auto& style_resolver = m_document.style_resolver();
|
||||||
m_document.for_each_in_subtree_of_type<DOM::Element>([&](auto& element) {
|
m_document.for_each_in_inclusive_subtree_of_type<DOM::Element>([&](auto& element) {
|
||||||
m_elements_and_matching_rules_before.set(&element, style_resolver.collect_matching_rules(element));
|
m_elements_and_matching_rules_before.set(&element, style_resolver.collect_matching_rules(element));
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
@ -48,7 +48,7 @@ StyleInvalidator::~StyleInvalidator()
|
||||||
if (!m_document.should_invalidate_styles_on_attribute_changes())
|
if (!m_document.should_invalidate_styles_on_attribute_changes())
|
||||||
return;
|
return;
|
||||||
auto& style_resolver = m_document.style_resolver();
|
auto& style_resolver = m_document.style_resolver();
|
||||||
m_document.for_each_in_subtree_of_type<DOM::Element>([&](auto& element) {
|
m_document.for_each_in_inclusive_subtree_of_type<DOM::Element>([&](auto& element) {
|
||||||
auto maybe_matching_rules_before = m_elements_and_matching_rules_before.get(&element);
|
auto maybe_matching_rules_before = m_elements_and_matching_rules_before.get(&element);
|
||||||
if (!maybe_matching_rules_before.has_value()) {
|
if (!maybe_matching_rules_before.has_value()) {
|
||||||
element.set_needs_style_update(true);
|
element.set_needs_style_update(true);
|
||||||
|
|
|
@ -114,7 +114,7 @@ void Document::removed_last_ref()
|
||||||
// Gather up all the descendants of this document and prune them from the tree.
|
// Gather up all the descendants of this document and prune them from the tree.
|
||||||
// FIXME: This could definitely be more elegant.
|
// FIXME: This could definitely be more elegant.
|
||||||
NonnullRefPtrVector<Node> descendants;
|
NonnullRefPtrVector<Node> descendants;
|
||||||
for_each_in_subtree([&](auto& node) {
|
for_each_in_inclusive_subtree([&](auto& node) {
|
||||||
if (&node != this)
|
if (&node != this)
|
||||||
descendants.append(node);
|
descendants.append(node);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
@ -316,7 +316,7 @@ void Document::tear_down_layout_tree()
|
||||||
|
|
||||||
NonnullRefPtrVector<Layout::Node> layout_nodes;
|
NonnullRefPtrVector<Layout::Node> layout_nodes;
|
||||||
|
|
||||||
m_layout_root->for_each_in_subtree([&](auto& layout_node) {
|
m_layout_root->for_each_in_inclusive_subtree([&](auto& layout_node) {
|
||||||
layout_nodes.append(layout_node);
|
layout_nodes.append(layout_node);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
@ -505,7 +505,7 @@ void Document::set_hovered_node(Node* node)
|
||||||
NonnullRefPtrVector<Element> Document::get_elements_by_name(const String& name) const
|
NonnullRefPtrVector<Element> Document::get_elements_by_name(const String& name) const
|
||||||
{
|
{
|
||||||
NonnullRefPtrVector<Element> elements;
|
NonnullRefPtrVector<Element> elements;
|
||||||
for_each_in_subtree_of_type<Element>([&](auto& element) {
|
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||||
if (element.attribute(HTML::AttributeNames::name) == name)
|
if (element.attribute(HTML::AttributeNames::name) == name)
|
||||||
elements.append(element);
|
elements.append(element);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
@ -518,7 +518,7 @@ NonnullRefPtrVector<Element> Document::get_elements_by_tag_name(const FlyString&
|
||||||
// FIXME: Support "*" for tag_name
|
// FIXME: Support "*" for tag_name
|
||||||
// https://dom.spec.whatwg.org/#concept-getelementsbytagname
|
// https://dom.spec.whatwg.org/#concept-getelementsbytagname
|
||||||
NonnullRefPtrVector<Element> elements;
|
NonnullRefPtrVector<Element> elements;
|
||||||
for_each_in_subtree_of_type<Element>([&](auto& element) {
|
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||||
if (element.namespace_() == Namespace::HTML
|
if (element.namespace_() == Namespace::HTML
|
||||||
? element.local_name().to_lowercase() == tag_name.to_lowercase()
|
? element.local_name().to_lowercase() == tag_name.to_lowercase()
|
||||||
: element.local_name() == tag_name) {
|
: element.local_name() == tag_name) {
|
||||||
|
@ -532,7 +532,7 @@ NonnullRefPtrVector<Element> Document::get_elements_by_tag_name(const FlyString&
|
||||||
NonnullRefPtrVector<Element> Document::get_elements_by_class_name(const FlyString& class_name) const
|
NonnullRefPtrVector<Element> Document::get_elements_by_class_name(const FlyString& class_name) const
|
||||||
{
|
{
|
||||||
NonnullRefPtrVector<Element> elements;
|
NonnullRefPtrVector<Element> elements;
|
||||||
for_each_in_subtree_of_type<Element>([&](auto& element) {
|
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||||
if (element.has_class(class_name, in_quirks_mode() ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
if (element.has_class(class_name, in_quirks_mode() ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
||||||
elements.append(element);
|
elements.append(element);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
@ -661,7 +661,7 @@ NonnullRefPtrVector<HTML::HTMLScriptElement> Document::take_scripts_to_execute_a
|
||||||
|
|
||||||
void Document::adopt_node(Node& subtree_root)
|
void Document::adopt_node(Node& subtree_root)
|
||||||
{
|
{
|
||||||
subtree_root.for_each_in_subtree([&](auto& node) {
|
subtree_root.for_each_in_inclusive_subtree([&](auto& node) {
|
||||||
node.set_document({}, *this);
|
node.set_document({}, *this);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|
|
@ -350,7 +350,7 @@ NonnullRefPtrVector<Element> Element::get_elements_by_tag_name(const FlyString&
|
||||||
// FIXME: Support "*" for tag_name
|
// FIXME: Support "*" for tag_name
|
||||||
// https://dom.spec.whatwg.org/#concept-getelementsbytagname
|
// https://dom.spec.whatwg.org/#concept-getelementsbytagname
|
||||||
NonnullRefPtrVector<Element> elements;
|
NonnullRefPtrVector<Element> elements;
|
||||||
for_each_in_subtree_of_type<Element>([&](auto& element) {
|
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||||
if (element.namespace_() == Namespace::HTML
|
if (element.namespace_() == Namespace::HTML
|
||||||
? element.local_name().to_lowercase() == tag_name.to_lowercase()
|
? element.local_name().to_lowercase() == tag_name.to_lowercase()
|
||||||
: element.local_name() == tag_name) {
|
: element.local_name() == tag_name) {
|
||||||
|
@ -364,7 +364,7 @@ NonnullRefPtrVector<Element> Element::get_elements_by_tag_name(const FlyString&
|
||||||
NonnullRefPtrVector<Element> Element::get_elements_by_class_name(const FlyString& class_name) const
|
NonnullRefPtrVector<Element> Element::get_elements_by_class_name(const FlyString& class_name) const
|
||||||
{
|
{
|
||||||
NonnullRefPtrVector<Element> elements;
|
NonnullRefPtrVector<Element> elements;
|
||||||
for_each_in_subtree_of_type<Element>([&](auto& element) {
|
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||||
if (element.has_class(class_name, m_document->in_quirks_mode() ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
if (element.has_class(class_name, m_document->in_quirks_mode() ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
||||||
elements.append(element);
|
elements.append(element);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
|
|
@ -114,7 +114,7 @@ RefPtr<Layout::Node> Node::create_layout_node()
|
||||||
|
|
||||||
void Node::invalidate_style()
|
void Node::invalidate_style()
|
||||||
{
|
{
|
||||||
for_each_in_subtree_of_type<Element>([&](auto& element) {
|
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||||
element.set_needs_style_update(true);
|
element.set_needs_style_update(true);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
RefPtr<Element> get_element_by_id(const FlyString& id) const
|
RefPtr<Element> get_element_by_id(const FlyString& id) const
|
||||||
{
|
{
|
||||||
RefPtr<Element> found_element;
|
RefPtr<Element> found_element;
|
||||||
static_cast<const NodeType*>(this)->template for_each_in_subtree_of_type<Element>([&](auto& element) {
|
static_cast<const NodeType*>(this)->template for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||||
if (element.attribute(HTML::AttributeNames::id) == id) {
|
if (element.attribute(HTML::AttributeNames::id) == id) {
|
||||||
found_element = &element;
|
found_element = &element;
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
|
|
@ -40,7 +40,7 @@ RefPtr<Element> ParentNode::query_selector(const StringView& selector_text)
|
||||||
dump_selector(selector.value());
|
dump_selector(selector.value());
|
||||||
|
|
||||||
RefPtr<Element> result;
|
RefPtr<Element> result;
|
||||||
for_each_in_subtree_of_type<Element>([&](auto& element) {
|
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||||
if (SelectorEngine::matches(selector.value(), element)) {
|
if (SelectorEngine::matches(selector.value(), element)) {
|
||||||
result = element;
|
result = element;
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
@ -60,7 +60,7 @@ NonnullRefPtrVector<Element> ParentNode::query_selector_all(const StringView& se
|
||||||
dump_selector(selector.value());
|
dump_selector(selector.value());
|
||||||
|
|
||||||
NonnullRefPtrVector<Element> elements;
|
NonnullRefPtrVector<Element> elements;
|
||||||
for_each_in_subtree_of_type<Element>([&](auto& element) {
|
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||||
if (SelectorEngine::matches(selector.value(), element)) {
|
if (SelectorEngine::matches(selector.value(), element)) {
|
||||||
elements.append(element);
|
elements.append(element);
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ void HTMLFormElement::submit_form(RefPtr<HTMLElement> submitter, bool from_submi
|
||||||
|
|
||||||
Vector<URLQueryParam> parameters;
|
Vector<URLQueryParam> parameters;
|
||||||
|
|
||||||
for_each_in_subtree_of_type<HTMLInputElement>([&](auto& node) {
|
for_each_in_inclusive_subtree_of_type<HTMLInputElement>([&](auto& node) {
|
||||||
auto& input = downcast<HTMLInputElement>(node);
|
auto& input = downcast<HTMLInputElement>(node);
|
||||||
if (!input.name().is_null() && (input.type() != "submit" || &input == submitter))
|
if (!input.name().is_null() && (input.type() != "submit" || &input == submitter))
|
||||||
parameters.append({ input.name(), input.value() });
|
parameters.append({ input.name(), input.value() });
|
||||||
|
|
|
@ -48,7 +48,7 @@ void InitialContainingBlockBox::build_stacking_context_tree()
|
||||||
|
|
||||||
set_stacking_context(make<StackingContext>(*this, nullptr));
|
set_stacking_context(make<StackingContext>(*this, nullptr));
|
||||||
|
|
||||||
for_each_in_subtree_of_type<Box>([&](Box& box) {
|
for_each_in_inclusive_subtree_of_type<Box>([&](Box& box) {
|
||||||
if (&box == this)
|
if (&box == this)
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
if (!box.establishes_stacking_context()) {
|
if (!box.establishes_stacking_context()) {
|
||||||
|
@ -101,7 +101,7 @@ void InitialContainingBlockBox::recompute_selection_states()
|
||||||
|
|
||||||
auto selection = this->selection().normalized();
|
auto selection = this->selection().normalized();
|
||||||
|
|
||||||
for_each_in_subtree([&](auto& layout_node) {
|
for_each_in_inclusive_subtree([&](auto& layout_node) {
|
||||||
if (!selection.is_valid()) {
|
if (!selection.is_valid()) {
|
||||||
// Everything gets SelectionState::None.
|
// Everything gets SelectionState::None.
|
||||||
} else if (&layout_node == selection.start().layout_node && &layout_node == selection.end().layout_node) {
|
} else if (&layout_node == selection.start().layout_node && &layout_node == selection.end().layout_node) {
|
||||||
|
|
|
@ -120,7 +120,7 @@ Label* Label::label_for_control_node(LabelableNode& control)
|
||||||
if (id.is_empty())
|
if (id.is_empty())
|
||||||
return label;
|
return label;
|
||||||
|
|
||||||
control.document().layout_node()->for_each_in_subtree_of_type<Label>([&](auto& node) {
|
control.document().layout_node()->for_each_in_inclusive_subtree_of_type<Label>([&](auto& node) {
|
||||||
if (node.dom_node().for_() == id) {
|
if (node.dom_node().for_() == id) {
|
||||||
label = &node;
|
label = &node;
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
@ -144,7 +144,7 @@ LabelableNode* Label::control_node()
|
||||||
if (for_.is_empty())
|
if (for_.is_empty())
|
||||||
return control;
|
return control;
|
||||||
|
|
||||||
document().layout_node()->for_each_in_subtree_of_type<LabelableNode>([&](auto& node) {
|
document().layout_node()->for_each_in_inclusive_subtree_of_type<LabelableNode>([&](auto& node) {
|
||||||
if (node.dom_node().attribute(HTML::AttributeNames::id) == for_) {
|
if (node.dom_node().attribute(HTML::AttributeNames::id) == for_) {
|
||||||
control = &node;
|
control = &node;
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
|
|
@ -139,7 +139,7 @@ void RadioButton::set_checked_within_group()
|
||||||
dom_node().set_checked(true);
|
dom_node().set_checked(true);
|
||||||
String name = dom_node().name();
|
String name = dom_node().name();
|
||||||
|
|
||||||
document().for_each_in_subtree_of_type<HTML::HTMLInputElement>([&](auto& element) {
|
document().for_each_in_inclusive_subtree_of_type<HTML::HTMLInputElement>([&](auto& element) {
|
||||||
if (element.checked() && (element.layout_node() != this) && (element.name() == name))
|
if (element.checked() && (element.layout_node() != this) && (element.name() == name))
|
||||||
element.set_checked(false);
|
element.set_checked(false);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
|
|
@ -155,7 +155,7 @@ RefPtr<Node> TreeBuilder::build(DOM::Node& dom_node)
|
||||||
template<CSS::Display display, typename Callback>
|
template<CSS::Display display, typename Callback>
|
||||||
void TreeBuilder::for_each_in_tree_with_display(NodeWithStyle& root, Callback callback)
|
void TreeBuilder::for_each_in_tree_with_display(NodeWithStyle& root, Callback callback)
|
||||||
{
|
{
|
||||||
root.for_each_in_subtree_of_type<Box>([&](auto& box) {
|
root.for_each_in_inclusive_subtree_of_type<Box>([&](auto& box) {
|
||||||
if (box.computed_values().display() == display)
|
if (box.computed_values().display() == display)
|
||||||
callback(box);
|
callback(box);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
|
|
@ -140,52 +140,52 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
IterationDecision for_each_in_subtree(Callback callback) const
|
IterationDecision for_each_in_inclusive_subtree(Callback callback) const
|
||||||
{
|
{
|
||||||
if (callback(static_cast<const T&>(*this)) == IterationDecision::Break)
|
if (callback(static_cast<const T&>(*this)) == IterationDecision::Break)
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||||
if (child->for_each_in_subtree(callback) == IterationDecision::Break)
|
if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break)
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
}
|
}
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
IterationDecision for_each_in_subtree(Callback callback)
|
IterationDecision for_each_in_inclusive_subtree(Callback callback)
|
||||||
{
|
{
|
||||||
if (callback(static_cast<T&>(*this)) == IterationDecision::Break)
|
if (callback(static_cast<T&>(*this)) == IterationDecision::Break)
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||||
if (child->for_each_in_subtree(callback) == IterationDecision::Break)
|
if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break)
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
}
|
}
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename Callback>
|
template<typename U, typename Callback>
|
||||||
IterationDecision for_each_in_subtree_of_type(Callback callback)
|
IterationDecision for_each_in_inclusive_subtree_of_type(Callback callback)
|
||||||
{
|
{
|
||||||
if (is<U>(static_cast<const T&>(*this))) {
|
if (is<U>(static_cast<const T&>(*this))) {
|
||||||
if (callback(static_cast<U&>(*this)) == IterationDecision::Break)
|
if (callback(static_cast<U&>(*this)) == IterationDecision::Break)
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
}
|
}
|
||||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||||
if (child->template for_each_in_subtree_of_type<U>(callback) == IterationDecision::Break)
|
if (child->template for_each_in_inclusive_subtree_of_type<U>(callback) == IterationDecision::Break)
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
}
|
}
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename Callback>
|
template<typename U, typename Callback>
|
||||||
IterationDecision for_each_in_subtree_of_type(Callback callback) const
|
IterationDecision for_each_in_inclusive_subtree_of_type(Callback callback) const
|
||||||
{
|
{
|
||||||
if (is<U>(static_cast<const T&>(*this))) {
|
if (is<U>(static_cast<const T&>(*this))) {
|
||||||
if (callback(static_cast<const U&>(*this)) == IterationDecision::Break)
|
if (callback(static_cast<const U&>(*this)) == IterationDecision::Break)
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
}
|
}
|
||||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||||
if (child->template for_each_in_subtree_of_type<U>(callback) == IterationDecision::Break)
|
if (child->template for_each_in_inclusive_subtree_of_type<U>(callback) == IterationDecision::Break)
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
}
|
}
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue