diff options
Diffstat (limited to 'components/script/dom/text.rs')
-rw-r--r-- | components/script/dom/text.rs | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/components/script/dom/text.rs b/components/script/dom/text.rs index 0343b373931..64fae977556 100644 --- a/components/script/dom/text.rs +++ b/components/script/dom/text.rs @@ -1,21 +1,20 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * 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 https://mozilla.org/MPL/2.0/. */ -use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods; -use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; -use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::codegen::Bindings::TextBinding::{self, TextMethods}; -use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::error::{Error, Fallible}; -use dom::bindings::inheritance::Castable; -use dom::bindings::js::Root; -use dom::bindings::js::RootedReference; -use dom::bindings::str::DOMString; -use dom::characterdata::CharacterData; -use dom::document::Document; -use dom::node::Node; -use dom::window::Window; +use crate::dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods; +use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; +use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; +use crate::dom::bindings::codegen::Bindings::TextBinding::TextMethods; +use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; +use crate::dom::bindings::error::{Error, Fallible}; +use crate::dom::bindings::inheritance::Castable; +use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::str::DOMString; +use crate::dom::characterdata::CharacterData; +use crate::dom::document::Document; +use crate::dom::node::Node; +use crate::dom::window::Window; use dom_struct::dom_struct; /// An HTML text node. @@ -25,18 +24,18 @@ pub struct Text { } impl Text { - fn new_inherited(text: DOMString, document: &Document) -> Text { + pub fn new_inherited(text: DOMString, document: &Document) -> Text { Text { - characterdata: CharacterData::new_inherited(text, document) + characterdata: CharacterData::new_inherited(text, document), } } - pub fn new(text: DOMString, document: &Document) -> Root<Text> { - Node::reflect_node(box Text::new_inherited(text, document), - document, TextBinding::Wrap) + pub fn new(text: DOMString, document: &Document) -> DomRoot<Text> { + Node::reflect_node(Box::new(Text::new_inherited(text, document)), document) } - pub fn Constructor(window: &Window, text: DOMString) -> Fallible<Root<Text>> { + #[allow(non_snake_case)] + pub fn Constructor(window: &Window, text: DOMString) -> Fallible<DomRoot<Text>> { let document = window.Document(); Ok(Text::new(text, &document)) } @@ -45,7 +44,7 @@ impl Text { impl TextMethods for Text { // https://dom.spec.whatwg.org/#dom-text-splittext // https://dom.spec.whatwg.org/#concept-text-split - fn SplitText(&self, offset: u32) -> Fallible<Root<Text>> { + fn SplitText(&self, offset: u32) -> Fallible<DomRoot<Text>> { let cdata = self.upcast::<CharacterData>(); // Step 1. let length = cdata.Length(); @@ -65,9 +64,12 @@ impl TextMethods for Text { let parent = node.GetParentNode(); if let Some(ref parent) = parent { // Step 7.1. - parent.InsertBefore(new_node.upcast(), node.GetNextSibling().r()).unwrap(); + parent + .InsertBefore(new_node.upcast(), node.GetNextSibling().as_deref()) + .unwrap(); // Steps 7.2-3. - node.ranges().move_to_following_text_sibling_above(node, offset, new_node.upcast()); + node.ranges() + .move_to_following_text_sibling_above(node, offset, new_node.upcast()); // Steps 7.4-5. parent.ranges().increment_at(&parent, node.index() + 1); } @@ -79,11 +81,15 @@ impl TextMethods for Text { // https://dom.spec.whatwg.org/#dom-text-wholetext fn WholeText(&self) -> DOMString { - let first = self.upcast::<Node>().inclusively_preceding_siblings() - .take_while(|node| node.is::<Text>()) - .last().unwrap(); - let nodes = first.inclusively_following_siblings() - .take_while(|node| node.is::<Text>()); + let first = self + .upcast::<Node>() + .inclusively_preceding_siblings() + .take_while(|node| node.is::<Text>()) + .last() + .unwrap(); + let nodes = first + .inclusively_following_siblings() + .take_while(|node| node.is::<Text>()); let mut text = String::new(); for ref node in nodes { let cdata = node.downcast::<CharacterData>().unwrap(); |