aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorBen <bennyschulenburg@gmx.de>2024-09-10 07:06:50 +0000
committerGitHub <noreply@github.com>2024-09-10 07:06:50 +0000
commit8286dd33a539fe063dd438f6ce74d9445a9c973a (patch)
treefcdba17fe0edfeb0833abe822ae0e1b9a1b0a930 /components/script/dom
parent7ec22306e80c85f2c3fc15bb83cec4170ec1a254 (diff)
downloadservo-8286dd33a539fe063dd438f6ce74d9445a9c973a.tar.gz
servo-8286dd33a539fe063dd438f6ce74d9445a9c973a.zip
script: fixed document title being set to Some("") instead of None (#33354)
* Fixed document title being set to "" instead of None Signed-off-by: Benjamin Vincent Schulenburg <bennyschulenburg@gmx.de> * Update components/script/dom/document.rs Co-authored-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Ben <bennyschulenburg@gmx.de> --------- Signed-off-by: Benjamin Vincent Schulenburg <bennyschulenburg@gmx.de> Signed-off-by: Ben <bennyschulenburg@gmx.de> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/document.rs56
1 files changed, 30 insertions, 26 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index b09d7ec19e9..21559dee10f 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -1235,11 +1235,39 @@ impl Document {
}
}
+ /// Determine the title of the [`Document`] according to the specification at:
+ /// <https://html.spec.whatwg.org/multipage/#document.title>. The difference
+ /// here is that when the title isn't specified `None` is returned.
+ fn title(&self) -> Option<DOMString> {
+ let title = self.GetDocumentElement().and_then(|root| {
+ if root.namespace() == &ns!(svg) && root.local_name() == &local_name!("svg") {
+ // Step 1.
+ root.upcast::<Node>()
+ .child_elements()
+ .find(|node| {
+ node.namespace() == &ns!(svg) && node.local_name() == &local_name!("title")
+ })
+ .map(DomRoot::upcast::<Node>)
+ } else {
+ // Step 2.
+ root.upcast::<Node>()
+ .traverse_preorder(ShadowIncluding::No)
+ .find(|node| node.is::<HTMLTitleElement>())
+ }
+ });
+
+ title.map(|title| {
+ // Steps 3-4.
+ let value = title.child_text_content();
+ DOMString::from(str_join(split_html_space_chars(&value), " "))
+ })
+ }
+
/// Sends this document's title to the constellation.
pub fn send_title_to_embedder(&self) {
let window = self.window();
if window.is_top_level() {
- let title = Some(String::from(self.Title()));
+ let title = self.title().map(String::from);
self.send_to_embedder(EmbedderMsg::ChangePageTitle(title));
}
}
@@ -4635,31 +4663,7 @@ impl DocumentMethods for Document {
// https://html.spec.whatwg.org/multipage/#document.title
fn Title(&self) -> DOMString {
- let title = self.GetDocumentElement().and_then(|root| {
- if root.namespace() == &ns!(svg) && root.local_name() == &local_name!("svg") {
- // Step 1.
- root.upcast::<Node>()
- .child_elements()
- .find(|node| {
- node.namespace() == &ns!(svg) && node.local_name() == &local_name!("title")
- })
- .map(DomRoot::upcast::<Node>)
- } else {
- // Step 2.
- root.upcast::<Node>()
- .traverse_preorder(ShadowIncluding::No)
- .find(|node| node.is::<HTMLTitleElement>())
- }
- });
-
- match title {
- None => DOMString::new(),
- Some(ref title) => {
- // Steps 3-4.
- let value = title.child_text_content();
- DOMString::from(str_join(split_html_space_chars(&value), " "))
- },
- }
+ self.title().unwrap_or_else(|| DOMString::from(""))
}
// https://html.spec.whatwg.org/multipage/#document.title