mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-02 15:46:33 +00:00
LibWeb: Make Node::parent_element return GC::Ptr
This is useful for people like myself who run with debug mode to more reliably get stacktraces without spinning up a debugger.
This commit is contained in:
parent
a14481ee05
commit
3e17b1c9ae
Notes:
github-actions[bot]
2025-04-18 09:08:36 +00:00
Author: https://github.com/shannonbooth
Commit: 3e17b1c9ae
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4393
18 changed files with 48 additions and 54 deletions
|
@ -1440,7 +1440,7 @@ void Document::update_layout(UpdateLayoutReason reason)
|
|||
if (node_invalidation.rebuild_layout_tree) {
|
||||
// We mark layout tree for rebuild starting from parent element to correctly invalidate
|
||||
// "display" property change to/from "contents" value.
|
||||
if (auto* parent_element = node.parent_element()) {
|
||||
if (auto parent_element = node.parent_element()) {
|
||||
parent_element->set_needs_layout_tree_update(true);
|
||||
} else {
|
||||
node.set_needs_layout_tree_update(true);
|
||||
|
|
|
@ -2626,7 +2626,7 @@ Optional<String> Element::locate_a_namespace_prefix(Optional<String> const& name
|
|||
}
|
||||
|
||||
// 3. If element’s parent element is not null, then return the result of running locate a namespace prefix on that element using namespace.
|
||||
if (auto* parent = this->parent_element())
|
||||
if (auto parent = this->parent_element())
|
||||
return parent->locate_a_namespace_prefix(namespace_);
|
||||
|
||||
// 4. Return null
|
||||
|
@ -2881,7 +2881,7 @@ bool Element::check_visibility(Optional<CheckVisibilityOptions> options)
|
|||
return false;
|
||||
|
||||
// 2. If an ancestor of this in the flat tree has content-visibility: hidden, return false.
|
||||
for (auto* element = parent_element(); element; element = element->parent_element()) {
|
||||
for (auto element = parent_element(); element; element = element->parent_element()) {
|
||||
if (element->computed_properties()->content_visibility() == CSS::ContentVisibility::Hidden)
|
||||
return false;
|
||||
}
|
||||
|
@ -3151,7 +3151,7 @@ Element const* Element::list_owner() const
|
|||
return nullptr;
|
||||
|
||||
// 2. Let ancestor be the element's parent.
|
||||
auto const* ancestor = parent_element();
|
||||
auto ancestor = parent_element();
|
||||
|
||||
// AC-HOC: There may not be any parent element in a shadow tree.
|
||||
if (!ancestor)
|
||||
|
@ -3692,7 +3692,7 @@ void Element::inherit_counters()
|
|||
{
|
||||
// 1. If element is the root of its document tree, the element has an initially-empty CSS counters set.
|
||||
// Return.
|
||||
auto* parent = parent_element();
|
||||
auto parent = parent_element();
|
||||
if (parent == nullptr) {
|
||||
// NOTE: We represent an empty counters set with `m_counters_set = nullptr`.
|
||||
m_counters_set = nullptr;
|
||||
|
@ -3765,14 +3765,14 @@ Optional<String> Element::lang() const
|
|||
|
||||
// 3. If the node's parent is a shadow root
|
||||
// Use the language of that shadow root's host.
|
||||
if (auto const* parent = parent_element()) {
|
||||
if (auto parent = parent_element()) {
|
||||
if (parent->is_shadow_root())
|
||||
return parent->shadow_root()->host()->lang();
|
||||
}
|
||||
|
||||
// 4. If the node's parent element is not null
|
||||
// Use the language of that parent element.
|
||||
if (auto const* parent = parent_element())
|
||||
if (auto parent = parent_element())
|
||||
return parent->lang();
|
||||
|
||||
// 5. Otherwise
|
||||
|
|
|
@ -582,20 +582,14 @@ private:
|
|||
template<>
|
||||
inline bool Node::fast_is<Element>() const { return is_element(); }
|
||||
|
||||
inline Element* Node::parent_element()
|
||||
inline GC::Ptr<Element> Node::parent_element()
|
||||
{
|
||||
auto* parent = this->parent();
|
||||
if (!parent || !is<Element>(parent))
|
||||
return nullptr;
|
||||
return static_cast<Element*>(parent);
|
||||
return as_if<Element>(this->parent());
|
||||
}
|
||||
|
||||
inline Element const* Node::parent_element() const
|
||||
inline GC::Ptr<Element const> Node::parent_element() const
|
||||
{
|
||||
auto const* parent = this->parent();
|
||||
if (!parent || !is<Element>(parent))
|
||||
return nullptr;
|
||||
return static_cast<Element const*>(parent);
|
||||
return as_if<Element>(this->parent());
|
||||
}
|
||||
|
||||
inline bool Element::has_class(FlyString const& class_name, CaseSensitivity case_sensitivity) const
|
||||
|
|
|
@ -2051,7 +2051,7 @@ Optional<String> Node::locate_a_namespace(Optional<String> const& prefix) const
|
|||
}
|
||||
|
||||
// 5. If its parent element is null, then return null.
|
||||
auto* parent_element = element.parent_element();
|
||||
auto parent_element = element.parent_element();
|
||||
if (!element.parent_element())
|
||||
return {};
|
||||
|
||||
|
@ -2090,7 +2090,7 @@ Optional<String> Node::locate_a_namespace(Optional<String> const& prefix) const
|
|||
|
||||
// Otherwise
|
||||
// 1. If its parent element is null, then return null.
|
||||
auto* parent_element = this->parent_element();
|
||||
auto parent_element = this->parent_element();
|
||||
if (!parent_element)
|
||||
return {};
|
||||
|
||||
|
@ -2153,7 +2153,7 @@ Optional<String> Node::lookup_prefix(Optional<String> namespace_) const
|
|||
|
||||
// Otherwise
|
||||
// Return the result of locating a namespace prefix for its parent element, if its parent element is non-null; otherwise null.
|
||||
auto* parent_element = this->parent_element();
|
||||
auto parent_element = this->parent_element();
|
||||
if (!parent_element)
|
||||
return {};
|
||||
|
||||
|
|
|
@ -261,8 +261,8 @@ public:
|
|||
Node* parent_node() { return parent(); }
|
||||
Node const* parent_node() const { return parent(); }
|
||||
|
||||
Element* parent_element();
|
||||
Element const* parent_element() const;
|
||||
GC::Ptr<Element> parent_element();
|
||||
GC::Ptr<Element const> parent_element() const;
|
||||
|
||||
virtual void inserted();
|
||||
virtual void post_connection();
|
||||
|
|
|
@ -56,7 +56,7 @@ bool is_an_assigned_slottable(GC::Ref<Node> node)
|
|||
GC::Ptr<HTML::HTMLSlotElement> find_a_slot(Slottable const& slottable, OpenFlag open_flag)
|
||||
{
|
||||
// 1. If slottable’s parent is null, then return null.
|
||||
auto* parent = slottable.visit([](auto& node) { return node->parent_element(); });
|
||||
auto parent = slottable.visit([](auto& node) { return node->parent_element(); });
|
||||
if (!parent)
|
||||
return nullptr;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue