mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-25 20:22:18 +03:00
LibWeb: Add DOM tree version counter
This patch adds a u64 version counter to DOM::Document that increments whenever the tree structure changes (via node insertion or removal), or an element attribute is changed somehow. This will be used as a crude invalidation mechanism for HTMLCollection to cache its elements.
This commit is contained in:
parent
cf7c933312
commit
cf60f52a78
Notes:
sideshowbarker
2024-07-16 22:16:50 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/cf60f52a78 Pull-request: https://github.com/SerenityOS/serenity/pull/23640 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/tcl3 Reviewed-by: https://github.com/trflynn89
@ -97,6 +97,11 @@ public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> construct_impl(JS::Realm&);
|
||||
virtual ~Document() override;
|
||||
|
||||
// AD-HOC: This number increments whenever a node is added or removed from the document, or an element attribute changes.
|
||||
// It can be used as a crude invalidation mechanism for caches that depend on the DOM structure.
|
||||
u64 dom_tree_version() const { return m_dom_tree_version; }
|
||||
void bump_dom_tree_version() { ++m_dom_tree_version; }
|
||||
|
||||
WebIDL::ExceptionOr<void> populate_with_html_head_and_body();
|
||||
|
||||
JS::GCPtr<Selection::Selection> get_selection() const;
|
||||
@ -846,6 +851,8 @@ private:
|
||||
mutable JS::GCPtr<WebIDL::ObservableArray> m_adopted_style_sheets;
|
||||
|
||||
Vector<JS::NonnullGCPtr<DOM::ShadowRoot>> m_shadow_roots;
|
||||
|
||||
u64 m_dom_tree_version { 0 };
|
||||
};
|
||||
|
||||
template<>
|
||||
|
@ -437,6 +437,8 @@ void Element::run_attribute_change_steps(FlyString const& local_name, Optional<S
|
||||
// AD-HOC: Run our own internal attribute change handler.
|
||||
attribute_changed(local_name, value);
|
||||
invalidate_style_after_attribute_change(local_name);
|
||||
|
||||
document().bump_dom_tree_version();
|
||||
}
|
||||
|
||||
void Element::attribute_changed(FlyString const& name, Optional<String> const& value)
|
||||
|
@ -207,6 +207,8 @@ void Node::set_text_content(Optional<String> const& maybe_content)
|
||||
|
||||
document().invalidate_style();
|
||||
document().invalidate_layout();
|
||||
|
||||
document().bump_dom_tree_version();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-node-nodevalue
|
||||
@ -510,6 +512,8 @@ void Node::insert_before(JS::NonnullGCPtr<Node> node, JS::GCPtr<Node> child, boo
|
||||
invalidate_style();
|
||||
|
||||
document().invalidate_layout();
|
||||
|
||||
document().bump_dom_tree_version();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-pre-insert
|
||||
@ -703,6 +707,8 @@ void Node::remove(bool suppress_observers)
|
||||
// In the future, we should find a way to only invalidate the parts that actually need it.
|
||||
document().invalidate_style();
|
||||
document().invalidate_layout();
|
||||
|
||||
document().bump_dom_tree_version();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-replace
|
||||
|
Loading…
Reference in New Issue
Block a user