mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Make LayoutNodeHelpers::text_content return a cow
This commit is contained in:
parent
409bd3d989
commit
6fe294fa5b
7 changed files with 32 additions and 19 deletions
|
@ -87,7 +87,7 @@ use servo_arc::Arc;
|
|||
use servo_atoms::Atom;
|
||||
use servo_url::ServoUrl;
|
||||
use smallvec::SmallVec;
|
||||
use std::borrow::ToOwned;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::{Cell, UnsafeCell};
|
||||
use std::cmp;
|
||||
use std::default::Default;
|
||||
|
@ -1326,7 +1326,7 @@ pub trait LayoutNodeHelpers<'dom> {
|
|||
unsafe fn init_style_and_layout_data(self, _: OpaqueStyleAndLayoutData);
|
||||
unsafe fn take_style_and_layout_data(self) -> OpaqueStyleAndLayoutData;
|
||||
|
||||
fn text_content(self) -> String;
|
||||
fn text_content(self) -> Cow<'dom, str>;
|
||||
fn selection(self) -> Option<Range<usize>>;
|
||||
fn image_url(self) -> Option<ServoUrl>;
|
||||
fn image_density(self) -> Option<f64>;
|
||||
|
@ -1456,17 +1456,17 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
|||
val
|
||||
}
|
||||
|
||||
fn text_content(self) -> String {
|
||||
fn text_content(self) -> Cow<'dom, str> {
|
||||
if let Some(text) = self.downcast::<Text>() {
|
||||
return text.upcast().data_for_layout().to_owned();
|
||||
return text.upcast().data_for_layout().into();
|
||||
}
|
||||
|
||||
if let Some(input) = self.downcast::<HTMLInputElement>() {
|
||||
return input.value_for_layout().into_owned();
|
||||
return input.value_for_layout();
|
||||
}
|
||||
|
||||
if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
|
||||
return area.value_for_layout();
|
||||
return area.value_for_layout().into();
|
||||
}
|
||||
|
||||
panic!("not text!")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue