mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Pass an Element to collect_text.
This commit is contained in:
parent
6e745b5a00
commit
a701397a9d
1 changed files with 9 additions and 11 deletions
|
@ -7,13 +7,12 @@ use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods
|
||||||
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::ElementDerived;
|
|
||||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, ElementCast, HTMLElementCast, NodeCast, TextDerived};
|
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, ElementCast, HTMLElementCast, NodeCast, TextDerived};
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLOptionElementDerived};
|
use dom::bindings::codegen::InheritTypes::{HTMLOptionElementDerived};
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived};
|
use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived};
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{AttributeMutation, ElementTypeId};
|
use dom::element::{Element, AttributeMutation, ElementTypeId};
|
||||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||||
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
|
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
|
||||||
use dom::node::{Node, NodeTypeId};
|
use dom::node::{Node, NodeTypeId};
|
||||||
|
@ -61,19 +60,18 @@ impl HTMLOptionElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_text(node: &&Node, value: &mut DOMString) {
|
fn collect_text(element: &Element, value: &mut DOMString) {
|
||||||
let elem = ElementCast::to_ref(*node).unwrap();
|
let svg_script = *element.namespace() == ns!(SVG) && element.local_name() == &atom!("script");
|
||||||
let svg_script = *elem.namespace() == ns!(SVG) && elem.local_name() == &atom!("script");
|
let html_script = element.is_htmlscriptelement();
|
||||||
let html_script = node.is_htmlscriptelement();
|
|
||||||
if svg_script || html_script {
|
if svg_script || html_script {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
for child in node.children() {
|
for child in NodeCast::from_ref(element).children() {
|
||||||
if child.r().is_text() {
|
if child.r().is_text() {
|
||||||
let characterdata = CharacterDataCast::to_ref(child.r()).unwrap();
|
let characterdata = CharacterDataCast::to_ref(child.r()).unwrap();
|
||||||
value.push_str(&characterdata.Data());
|
value.push_str(&characterdata.Data());
|
||||||
} else if child.is_element() {
|
} else if let Some(element_child) = ElementCast::to_ref(&*child) {
|
||||||
collect_text(&child.r(), value);
|
collect_text(element_child, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,9 +89,9 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
||||||
|
|
||||||
// https://www.whatwg.org/html/#dom-option-text
|
// https://www.whatwg.org/html/#dom-option-text
|
||||||
fn Text(&self) -> DOMString {
|
fn Text(&self) -> DOMString {
|
||||||
let node = NodeCast::from_ref(self);
|
let element = ElementCast::from_ref(self);
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
collect_text(&node, &mut content);
|
collect_text(element, &mut content);
|
||||||
str_join(split_html_space_chars(&content), " ")
|
str_join(split_html_space_chars(&content), " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue