diff options
author | webbeef <me@webbeef.org> | 2024-09-09 15:41:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-09 22:41:02 +0000 |
commit | 193f5926171b59d5b8175621074e5d543f983a31 (patch) | |
tree | 5dfd8364d0206b7ba48a4ad22c765989f544be79 /components/script | |
parent | e5150dbda1f89ff07294dbd1ca4e8f4f08cf4874 (diff) | |
download | servo-193f5926171b59d5b8175621074e5d543f983a31.tar.gz servo-193f5926171b59d5b8175621074e5d543f983a31.zip |
Send less title changes to the embedder (#33287)
Instead of sending a title change for each incremental parsing change, we now do it when:
- the element is bound to the tree.
- the parser is done with the element (in pop()).
- the title content changes after the parsing, eg. using document.title .
Signed-off-by: webbeef <me@webbeef.org>
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/htmltitleelement.rs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/components/script/dom/htmltitleelement.rs b/components/script/dom/htmltitleelement.rs index abc16d0d037..c88261e5987 100644 --- a/components/script/dom/htmltitleelement.rs +++ b/components/script/dom/htmltitleelement.rs @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use std::cell::Cell; + use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; use js::rust::HandleObject; @@ -19,6 +21,7 @@ use crate::dom::virtualmethods::VirtualMethods; #[dom_struct] pub struct HTMLTitleElement { htmlelement: HTMLElement, + popped: Cell<bool>, } impl HTMLTitleElement { @@ -29,6 +32,7 @@ impl HTMLTitleElement { ) -> HTMLTitleElement { HTMLTitleElement { htmlelement: HTMLElement::new_inherited(local_name, prefix, document), + popped: Cell::new(false), } } @@ -47,6 +51,13 @@ impl HTMLTitleElement { proto, ) } + + fn notify_title_changed(&self) { + let node = self.upcast::<Node>(); + if node.is_in_doc() { + node.owner_doc().title_changed(); + } + } } impl HTMLTitleElementMethods for HTMLTitleElement { @@ -70,9 +81,11 @@ impl VirtualMethods for HTMLTitleElement { if let Some(s) = self.super_type() { s.children_changed(mutation); } - let node = self.upcast::<Node>(); - if node.is_in_doc() { - node.owner_doc().title_changed(); + + // Notify of title changes only after the initial full parsing + // of the element. + if self.popped.get() { + self.notify_title_changed(); } } @@ -85,4 +98,16 @@ impl VirtualMethods for HTMLTitleElement { node.owner_doc().title_changed(); } } + + fn pop(&self) { + if let Some(s) = self.super_type() { + s.pop(); + } + + self.popped.set(true); + + // Initial notification of title change, once the full text + // is available. + self.notify_title_changed(); + } } |