mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Implement "child text content" concept; use it where appropriate.
This commit is contained in:
parent
872ec89a9c
commit
9073a2f4c6
4 changed files with 8 additions and 11 deletions
|
@ -2667,7 +2667,7 @@ impl DocumentMethods for Document {
|
||||||
None => DOMString::new(),
|
None => DOMString::new(),
|
||||||
Some(ref title) => {
|
Some(ref title) => {
|
||||||
// Steps 3-4.
|
// Steps 3-4.
|
||||||
let value = Node::collect_text_contents(title.children());
|
let value = title.child_text_content();
|
||||||
DOMString::from(str_join(split_html_space_chars(&value), " "))
|
DOMString::from(str_join(split_html_space_chars(&value), " "))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -713,7 +713,7 @@ impl HTMLScriptElementMethods for HTMLScriptElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-script-text
|
// https://html.spec.whatwg.org/multipage/#dom-script-text
|
||||||
fn Text(&self) -> DOMString {
|
fn Text(&self) -> DOMString {
|
||||||
Node::collect_text_contents(self.upcast::<Node>().children())
|
self.upcast::<Node>().child_text_content()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-script-text
|
// https://html.spec.whatwg.org/multipage/#dom-script-text
|
||||||
|
|
|
@ -8,11 +8,9 @@ use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::inheritance::Castable;
|
use dom::bindings::inheritance::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::characterdata::CharacterData;
|
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{ChildrenMutation, Node};
|
use dom::node::{ChildrenMutation, Node};
|
||||||
use dom::text::Text;
|
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use html5ever_atoms::LocalName;
|
use html5ever_atoms::LocalName;
|
||||||
|
|
||||||
|
@ -41,13 +39,7 @@ impl HTMLTitleElement {
|
||||||
impl HTMLTitleElementMethods for HTMLTitleElement {
|
impl HTMLTitleElementMethods for HTMLTitleElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
||||||
fn Text(&self) -> DOMString {
|
fn Text(&self) -> DOMString {
|
||||||
let mut content = String::new();
|
self.upcast::<Node>().child_text_content()
|
||||||
for child in self.upcast::<Node>().children() {
|
|
||||||
if let Some(text) = child.downcast::<Text>() {
|
|
||||||
content.push_str(&text.upcast::<CharacterData>().data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DOMString::from(content)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
||||||
|
|
|
@ -1788,6 +1788,11 @@ impl Node {
|
||||||
copy
|
copy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://html.spec.whatwg.org/multipage/#child-text-content
|
||||||
|
pub fn child_text_content(&self) -> DOMString {
|
||||||
|
Node::collect_text_contents(self.children())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> DOMString {
|
pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> DOMString {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
for node in iterator {
|
for node in iterator {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue