mirror of
https://github.com/servo/servo.git
synced 2025-07-31 03:00:29 +01:00
Auto merge of #5617 - nox:wholetext, r=jdm
This commit is contained in:
commit
7d3ba8c7e2
5 changed files with 31 additions and 28 deletions
|
@ -486,6 +486,7 @@ pub trait NodeHelpers<'a> {
|
|||
|
||||
fn traverse_preorder(self) -> TreeIterator<'a>;
|
||||
fn inclusively_following_siblings(self) -> NodeSiblingIterator;
|
||||
fn inclusively_preceding_siblings(self) -> ReverseSiblingIterator;
|
||||
|
||||
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 {
|
||||
self == parent || parent.ancestors().any(|ancestor| ancestor.root().r() == self)
|
||||
}
|
||||
|
|
|
@ -2,16 +2,17 @@
|
|||
* 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/. */
|
||||
|
||||
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::InheritTypes::TextDerived;
|
||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, TextDerived};
|
||||
use dom::bindings::codegen::InheritTypes::NodeCast;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JSRef, Temporary};
|
||||
use dom::characterdata::CharacterData;
|
||||
use dom::characterdata::{CharacterData, CharacterDataHelpers};
|
||||
use dom::document::Document;
|
||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
use dom::node::{Node, NodeTypeId};
|
||||
use dom::node::{Node, NodeHelpers, NodeTypeId};
|
||||
use util::str::DOMString;
|
||||
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,5 +14,5 @@
|
|||
[Constructor(optional DOMString data = "")]
|
||||
interface Text : CharacterData {
|
||||
//[NewObject] Text splitText(unsigned long offset);
|
||||
//readonly attribute DOMString wholeText;
|
||||
readonly attribute DOMString wholeText;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue