aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/node.rs
diff options
context:
space:
mode:
authorMs2ger <Ms2ger@gmail.com>2016-04-11 17:50:01 +0200
committerMs2ger <Ms2ger@gmail.com>2016-05-09 14:26:30 +0200
commita5be5a82c1c19f7261c08cf1a34b562688bb31aa (patch)
treed7dcb0eec515cb0a80fa86239b19915f8336c59f /components/script/dom/node.rs
parent9a8c81773a7dc51301e52ce3f02f8ea55984365a (diff)
downloadservo-a5be5a82c1c19f7261c08cf1a34b562688bb31aa.tar.gz
servo-a5be5a82c1c19f7261c08cf1a34b562688bb31aa.zip
Move some code from ServoThreadSafeLayoutNode::text_content into script.
Diffstat (limited to 'components/script/dom/node.rs')
-rw-r--r--components/script/dom/node.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 3a77fb6fe6d..d9d9343680d 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -32,7 +32,7 @@ use dom::bindings::reflector::{Reflectable, reflect_dom_object};
use dom::bindings::trace::JSTraceable;
use dom::bindings::trace::RootedVec;
use dom::bindings::xmlname::namespace_from_domstring;
-use dom::characterdata::CharacterData;
+use dom::characterdata::{CharacterData, LayoutCharacterDataHelpers};
use dom::document::{Document, DocumentSource, IsHTMLDocument};
use dom::documentfragment::DocumentFragment;
use dom::documenttype::DocumentType;
@@ -41,6 +41,8 @@ use dom::eventtarget::EventTarget;
use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlcollection::HTMLCollection;
use dom::htmlelement::HTMLElement;
+use dom::htmlinputelement::{HTMLInputElement, LayoutHTMLInputElementHelpers};
+use dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaElementHelpers};
use dom::nodelist::NodeList;
use dom::processinginstruction::ProcessingInstruction;
use dom::range::WeakRangeVec;
@@ -958,6 +960,8 @@ pub trait LayoutNodeHelpers {
unsafe fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData>;
unsafe fn init_style_and_layout_data(&self, OpaqueStyleAndLayoutData);
+
+ fn text_content(&self) -> String;
}
impl LayoutNodeHelpers for LayoutJS<Node> {
@@ -1048,6 +1052,23 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
debug_assert!((*self.unsafe_get()).style_and_layout_data.get().is_none());
(*self.unsafe_get()).style_and_layout_data.set(Some(val));
}
+
+ #[allow(unsafe_code)]
+ fn text_content(&self) -> String {
+ if let Some(text) = self.downcast::<Text>() {
+ return unsafe { text.upcast().data_for_layout().to_owned() };
+ }
+
+ if let Some(input) = self.downcast::<HTMLInputElement>() {
+ return unsafe { input.value_for_layout() };
+ }
+
+ if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
+ return unsafe { area.get_value_for_layout() };
+ }
+
+ panic!("not text!")
+ }
}