Auto merge of #5617 - nox:wholetext, r=jdm

This commit is contained in:
bors-servo 2015-04-10 05:13:53 -05:00
commit 7d3ba8c7e2
5 changed files with 31 additions and 28 deletions

View file

@ -486,6 +486,7 @@ pub trait NodeHelpers<'a> {
fn traverse_preorder(self) -> TreeIterator<'a>; fn traverse_preorder(self) -> TreeIterator<'a>;
fn inclusively_following_siblings(self) -> NodeSiblingIterator; fn inclusively_following_siblings(self) -> NodeSiblingIterator;
fn inclusively_preceding_siblings(self) -> ReverseSiblingIterator;
fn to_trusted_node_address(self) -> TrustedNodeAddress; fn to_trusted_node_address(self) -> TrustedNodeAddress;
@ -754,6 +755,12 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
} }
} }
fn inclusively_preceding_siblings(self) -> ReverseSiblingIterator {
ReverseSiblingIterator {
current: Some(Temporary::from_rooted(self)),
}
}
fn is_inclusive_ancestor_of(self, parent: JSRef<Node>) -> bool { fn is_inclusive_ancestor_of(self, parent: JSRef<Node>) -> bool {
self == parent || parent.ancestors().any(|ancestor| ancestor.root().r() == self) self == parent || parent.ancestors().any(|ancestor| ancestor.root().r() == self)
} }

View file

@ -2,16 +2,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::TextBinding; use dom::bindings::codegen::Bindings::TextBinding::{self, TextMethods};
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::TextDerived; use dom::bindings::codegen::InheritTypes::{CharacterDataCast, TextDerived};
use dom::bindings::codegen::InheritTypes::NodeCast;
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef; use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::js::{JSRef, Temporary};
use dom::characterdata::CharacterData; use dom::characterdata::{CharacterData, CharacterDataHelpers};
use dom::document::Document; use dom::document::Document;
use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::node::{Node, NodeTypeId}; use dom::node::{Node, NodeHelpers, NodeTypeId};
use util::str::DOMString; use util::str::DOMString;
/// An HTML text node. /// An HTML text node.
@ -44,3 +45,21 @@ impl Text {
} }
} }
impl<'a> TextMethods for JSRef<'a, Text> {
// https://dom.spec.whatwg.org/#dom-text-wholetext
fn WholeText(self) -> DOMString {
let first = NodeCast::from_ref(self).inclusively_preceding_siblings()
.map(|node| node.root())
.take_while(|node| node.r().is_text())
.last().unwrap();
let nodes = first.r().inclusively_following_siblings().map(|node| node.root())
.take_while(|node| node.r().is_text());
let mut text = DOMString::new();
for node in nodes {
let cdata = CharacterDataCast::to_ref(node.r()).unwrap();
text.push_str(&cdata.data());
}
text
}
}

View file

@ -14,5 +14,5 @@
[Constructor(optional DOMString data = "")] [Constructor(optional DOMString data = "")]
interface Text : CharacterData { interface Text : CharacterData {
//[NewObject] Text splitText(unsigned long offset); //[NewObject] Text splitText(unsigned long offset);
//readonly attribute DOMString wholeText; readonly attribute DOMString wholeText;
}; };

View file

@ -339,18 +339,12 @@
[Text interface: operation splitText(unsigned long)] [Text interface: operation splitText(unsigned long)]
expected: FAIL expected: FAIL
[Text interface: attribute wholeText]
expected: FAIL
[Text interface: document.createTextNode("abc") must inherit property "splitText" with the proper type (0)] [Text interface: document.createTextNode("abc") must inherit property "splitText" with the proper type (0)]
expected: FAIL expected: FAIL
[Text interface: calling splitText(unsigned long) on document.createTextNode("abc") with too few arguments must throw TypeError] [Text interface: calling splitText(unsigned long) on document.createTextNode("abc") with too few arguments must throw TypeError]
expected: FAIL expected: FAIL
[Text interface: document.createTextNode("abc") must inherit property "wholeText" with the proper type (1)]
expected: FAIL
[CharacterData interface: document.createTextNode("abc") must inherit property "before" with the proper type (9)] [CharacterData interface: document.createTextNode("abc") must inherit property "before" with the proper type (9)]
expected: FAIL expected: FAIL

View file

@ -1,17 +0,0 @@
[Node-properties.html]
type: testharness
[detachedTextNode.wholeText]
expected: FAIL
[foreignTextNode.wholeText]
expected: FAIL
[detachedForeignTextNode.wholeText]
expected: FAIL
[xmlTextNode.wholeText]
expected: FAIL
[detachedXmlTextNode.wholeText]
expected: FAIL