mirror of
https://github.com/servo/servo.git
synced 2025-06-13 19:04:30 +00:00
Auto merge of #11092 - Ms2ger:text_content, r=jdm
Move some code from ServoThreadSafeLayoutNode::text_content into script. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11092) <!-- Reviewable:end -->
This commit is contained in:
commit
71eaba2c35
2 changed files with 23 additions and 18 deletions
|
@ -58,7 +58,6 @@ use script::layout_interface::TrustedNodeAddress;
|
|||
use selectors::matching::{DeclarationBlock, ElementFlags};
|
||||
use selectors::parser::{AttrSelector, NamespaceConstraint};
|
||||
use smallvec::VecLike;
|
||||
use std::borrow::ToOwned;
|
||||
use std::cell::{Ref, RefCell, RefMut};
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::{transmute, transmute_copy};
|
||||
|
@ -1137,22 +1136,7 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
|
|||
}
|
||||
|
||||
let this = unsafe { self.get_jsmanaged() };
|
||||
if let Some(text) = this.downcast::<Text>() {
|
||||
let data = unsafe {
|
||||
text.upcast().data_for_layout().to_owned()
|
||||
};
|
||||
return TextContent::Text(data);
|
||||
}
|
||||
if let Some(input) = this.downcast::<HTMLInputElement>() {
|
||||
let data = unsafe { input.value_for_layout() };
|
||||
return TextContent::Text(data);
|
||||
}
|
||||
if let Some(area) = this.downcast::<HTMLTextAreaElement>() {
|
||||
let data = unsafe { area.get_value_for_layout() };
|
||||
return TextContent::Text(data);
|
||||
}
|
||||
|
||||
unreachable!("not text!")
|
||||
return TextContent::Text(this.text_content());
|
||||
}
|
||||
|
||||
fn selection(&self) -> Option<Range<ByteIndex>> {
|
||||
|
|
|
@ -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!")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue