mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +00:00
LibWeb: Show pseudo-elements in DOM whose parent has no other children
If a DOM node is an element with pseudo-elements, but it has no child DOM nodes and is not a shadow host, then the code that serializes its pseudo-elements would get skipped, making them not show up in the inspector.
This commit is contained in:
parent
9738070676
commit
173daec9db
Notes:
github-actions[bot]
2024-08-07 14:15:42 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/173daec9db3 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/994
|
@ -1141,6 +1141,17 @@ JS::GCPtr<Layout::NodeWithStyle> Element::get_pseudo_element_node(CSS::Selector:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Element::has_pseudo_elements() const
|
||||||
|
{
|
||||||
|
if (m_pseudo_element_data) {
|
||||||
|
for (auto& pseudo_element : *m_pseudo_element_data) {
|
||||||
|
if (pseudo_element.layout_node)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Element::clear_pseudo_element_nodes(Badge<Layout::TreeBuilder>)
|
void Element::clear_pseudo_element_nodes(Badge<Layout::TreeBuilder>)
|
||||||
{
|
{
|
||||||
if (m_pseudo_element_data) {
|
if (m_pseudo_element_data) {
|
||||||
|
|
|
@ -245,6 +245,7 @@ public:
|
||||||
|
|
||||||
void set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement::Type, JS::GCPtr<Layout::NodeWithStyle>);
|
void set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement::Type, JS::GCPtr<Layout::NodeWithStyle>);
|
||||||
JS::GCPtr<Layout::NodeWithStyle> get_pseudo_element_node(CSS::Selector::PseudoElement::Type) const;
|
JS::GCPtr<Layout::NodeWithStyle> get_pseudo_element_node(CSS::Selector::PseudoElement::Type) const;
|
||||||
|
bool has_pseudo_elements() const;
|
||||||
void clear_pseudo_element_nodes(Badge<Layout::TreeBuilder>);
|
void clear_pseudo_element_nodes(Badge<Layout::TreeBuilder>);
|
||||||
void serialize_pseudo_elements_as_json(JsonArraySerializer<StringBuilder>& children_array) const;
|
void serialize_pseudo_elements_as_json(JsonArraySerializer<StringBuilder>& children_array) const;
|
||||||
|
|
||||||
|
|
|
@ -1362,7 +1362,10 @@ void Node::serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& object) c
|
||||||
|
|
||||||
MUST((object.add("visible"sv, !!layout_node())));
|
MUST((object.add("visible"sv, !!layout_node())));
|
||||||
|
|
||||||
if (has_child_nodes() || (is_element() && static_cast<DOM::Element const*>(this)->is_shadow_host())) {
|
auto const* element = is_element() ? static_cast<DOM::Element const*>(this) : nullptr;
|
||||||
|
|
||||||
|
if (has_child_nodes()
|
||||||
|
|| (element && (element->is_shadow_host() || element->has_pseudo_elements()))) {
|
||||||
auto children = MUST(object.add_array("children"sv));
|
auto children = MUST(object.add_array("children"sv));
|
||||||
auto add_child = [&children](DOM::Node const& child) {
|
auto add_child = [&children](DOM::Node const& child) {
|
||||||
if (child.is_uninteresting_whitespace_node())
|
if (child.is_uninteresting_whitespace_node())
|
||||||
|
@ -1374,9 +1377,7 @@ void Node::serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& object) c
|
||||||
};
|
};
|
||||||
for_each_child(add_child);
|
for_each_child(add_child);
|
||||||
|
|
||||||
if (is_element()) {
|
if (element) {
|
||||||
auto const* element = static_cast<DOM::Element const*>(this);
|
|
||||||
|
|
||||||
// Pseudo-elements don't have DOM nodes,so we have to add them separately.
|
// Pseudo-elements don't have DOM nodes,so we have to add them separately.
|
||||||
element->serialize_pseudo_elements_as_json(children);
|
element->serialize_pseudo_elements_as_json(children);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue