Skip to content

Commit

Permalink
style: Move content property out of mako.
Browse files Browse the repository at this point in the history
  • Loading branch information
gootorov committed Feb 6, 2018
1 parent 2557274 commit 7a00066
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 281 deletions.
15 changes: 7 additions & 8 deletions components/layout/construct.rs
Expand Up @@ -37,14 +37,12 @@ use script_layout_interface::{LayoutElementType, LayoutNodeType, is_image_data};
use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode};
use servo_config::opts;
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use std::collections::LinkedList;
use std::marker::PhantomData;
use std::mem;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use style::computed_values::caption_side::T as CaptionSide;
use style::computed_values::content::ContentItem;
use style::computed_values::display::T as Display;
use style::computed_values::empty_cells::T as EmptyCells;
use style::computed_values::float::T as Float;
Expand All @@ -58,6 +56,7 @@ use style::properties::longhands::list_style_image;
use style::selector_parser::{PseudoElement, RestyleDamage};
use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::Either;
use style::values::computed::counters::ContentItem;
use table::TableFlow;
use table_caption::TableCaptionFlow;
use table_cell::TableCellFlow;
Expand Down Expand Up @@ -598,7 +597,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
// Add whitespace results. They will be stripped out later on when
// between block elements, and retained when between inline elements.
let fragment_info = SpecificFragmentInfo::UnscannedText(
Box::new(UnscannedTextFragmentInfo::new(" ".to_owned(), None))
Box::new(UnscannedTextFragmentInfo::new(Box::<str>::from(" "), None))
);
let fragment = Fragment::from_opaque_node_and_style(whitespace_node,
whitespace_pseudo,
Expand Down Expand Up @@ -754,7 +753,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
ContentItem::String(string) => {
let info = Box::new(UnscannedTextFragmentInfo::new(string, None));
SpecificFragmentInfo::UnscannedText(info)
}
},
content_item => {
let content_item = Box::new(GeneratedContentInfo::ContentItem(content_item));
SpecificFragmentInfo::GeneratedContent(content_item)
Expand Down Expand Up @@ -873,7 +872,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
whitespace_damage)) => {
// Instantiate the whitespace fragment.
let fragment_info = SpecificFragmentInfo::UnscannedText(
Box::new(UnscannedTextFragmentInfo::new(" ".to_owned(), None))
Box::new(UnscannedTextFragmentInfo::new(Box::<str>::from(" "), None))
);
let fragment =
Fragment::from_opaque_node_and_style(whitespace_node,
Expand All @@ -895,7 +894,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
if is_empty && node_style.has_padding_or_border() {
// An empty inline box needs at least one fragment to draw its background and borders.
let info = SpecificFragmentInfo::UnscannedText(
Box::new(UnscannedTextFragmentInfo::new(String::new(), None))
Box::new(UnscannedTextFragmentInfo::new(Box::<str>::from(""), None))
);
let fragment = Fragment::from_opaque_node_and_style(node.opaque(),
node.get_pseudo_element_type(),
Expand Down Expand Up @@ -1296,7 +1295,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
unscanned_marker_fragments.push_back(Fragment::new(
node,
SpecificFragmentInfo::UnscannedText(
Box::new(UnscannedTextFragmentInfo::new(text, None))
Box::new(UnscannedTextFragmentInfo::new(Box::<str>::from(text), None))
),
self.layout_context));
let marker_fragments =
Expand Down Expand Up @@ -1899,7 +1898,7 @@ where
E: TElement,
{
let info = SpecificFragmentInfo::UnscannedText(
Box::new(UnscannedTextFragmentInfo::new(String::from(text), None))
Box::new(UnscannedTextFragmentInfo::new(Box::<str>::from(text), None))
);
let text_style = context.stylist.style_for_anonymous::<E>(
&context.guards,
Expand Down
8 changes: 4 additions & 4 deletions components/layout/fragment.rs
Expand Up @@ -44,7 +44,6 @@ use style::computed_values::border_collapse::T as BorderCollapse;
use style::computed_values::box_sizing::T as BoxSizing;
use style::computed_values::clear::T as Clear;
use style::computed_values::color::T as Color;
use style::computed_values::content::ContentItem;
use style::computed_values::display::T as Display;
use style::computed_values::mix_blend_mode::T as MixBlendMode;
use style::computed_values::overflow_wrap::T as OverflowWrap;
Expand All @@ -61,6 +60,7 @@ use style::servo::restyle_damage::ServoRestyleDamage;
use style::str::char_is_whitespace;
use style::values::{self, Either, Auto};
use style::values::computed::{Length, LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::computed::counters::ContentItem;
use style::values::generics::box_::VerticalAlign;
use style::values::generics::transform;
use text;
Expand Down Expand Up @@ -570,9 +570,9 @@ pub struct UnscannedTextFragmentInfo {
impl UnscannedTextFragmentInfo {
/// Creates a new instance of `UnscannedTextFragmentInfo` from the given text.
#[inline]
pub fn new(text: String, selection: Option<Range<ByteIndex>>) -> UnscannedTextFragmentInfo {
pub fn new(text: Box<str>, selection: Option<Range<ByteIndex>>) -> UnscannedTextFragmentInfo {
UnscannedTextFragmentInfo {
text: text.into_boxed_str(),
text: text,
selection: selection,
}
}
Expand Down Expand Up @@ -760,7 +760,7 @@ impl Fragment {
let mut ellipsis_fragment = self.transform(
self.border_box.size,
SpecificFragmentInfo::UnscannedText(
Box::new(UnscannedTextFragmentInfo::new(text_overflow_string, None))
Box::new(UnscannedTextFragmentInfo::new(text_overflow_string.into_boxed_str(), None))
)
);
unscanned_ellipsis_fragments.push_back(ellipsis_fragment);
Expand Down
8 changes: 4 additions & 4 deletions components/layout/generated_content.rs
Expand Up @@ -15,12 +15,12 @@ use gfx::display_list::OpaqueNode;
use script_layout_interface::wrapper_traits::PseudoElementType;
use smallvec::SmallVec;
use std::collections::{HashMap, LinkedList};
use style::computed_values::content::ContentItem;
use style::computed_values::display::T as Display;
use style::computed_values::list_style_type::T as ListStyleType;
use style::properties::ComputedValues;
use style::selector_parser::RestyleDamage;
use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::computed::counters::ContentItem;
use text::TextRunScanner;
use traversal::InorderFlowTraversal;

Expand Down Expand Up @@ -189,7 +189,7 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> {
let temporary_counter = Counter::new();
let counter = self.traversal
.counters
.get(&*counter_name)
.get(&**counter_name)
.unwrap_or(&temporary_counter);
new_info = counter.render(self.traversal.layout_context,
fragment.node,
Expand All @@ -204,7 +204,7 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> {
let temporary_counter = Counter::new();
let counter = self.traversal
.counters
.get(&*counter_name)
.get(&**counter_name)
.unwrap_or(&temporary_counter);
new_info = counter.render(self.traversal.layout_context,
fragment.node,
Expand Down Expand Up @@ -437,7 +437,7 @@ fn render_text(layout_context: &LayoutContext,
-> Option<SpecificFragmentInfo> {
let mut fragments = LinkedList::new();
let info = SpecificFragmentInfo::UnscannedText(
Box::new(UnscannedTextFragmentInfo::new(string, None))
Box::new(UnscannedTextFragmentInfo::new(string.into_boxed_str(), None))
);
fragments.push_back(Fragment::from_opaque_node_and_style(node,
pseudo,
Expand Down
2 changes: 1 addition & 1 deletion components/layout/text.rs
Expand Up @@ -532,7 +532,7 @@ fn split_first_fragment_at_newline_if_necessary(fragments: &mut LinkedList<Fragm
first_fragment.transform(
first_fragment.border_box.size,
SpecificFragmentInfo::UnscannedText(Box::new(
UnscannedTextFragmentInfo::new(string_before, selection_before)
UnscannedTextFragmentInfo::new(string_before.into_boxed_str(), selection_before)
))
)
};
Expand Down
10 changes: 5 additions & 5 deletions components/layout/wrapper.rs
Expand Up @@ -34,9 +34,9 @@ use atomic_refcell::{AtomicRef, AtomicRefMut};
use data::{LayoutData, LayoutDataFlags, StyleAndLayoutData};
use script_layout_interface::wrapper_traits::{ThreadSafeLayoutElement, ThreadSafeLayoutNode};
use script_layout_interface::wrapper_traits::GetLayoutData;
use style::computed_values::content::{self, ContentItem};
use style::dom::{NodeInfo, TNode};
use style::selector_parser::RestyleDamage;
use style::values::computed::counters::{Content, ContentItem};

pub trait LayoutNodeLayoutData {
/// Similar to borrow_data*, but returns the full PersistentLayoutData rather
Expand Down Expand Up @@ -114,14 +114,14 @@ impl<T: ThreadSafeLayoutNode> ThreadSafeLayoutNodeHelpers for T {
let style = self.as_element().unwrap().resolved_style();

return match style.as_ref().get_counters().content {
content::T::Items(ref value) if !value.is_empty() => {
TextContent::GeneratedContent((*value).clone())
Content::Items(ref value) if !value.is_empty() => {
TextContent::GeneratedContent((*value).to_vec())
}
_ => TextContent::GeneratedContent(vec![]),
};
}

return TextContent::Text(self.node_text_content());
TextContent::Text(self.node_text_content().into_boxed_str())
}

fn restyle_damage(self) -> RestyleDamage {
Expand Down Expand Up @@ -156,7 +156,7 @@ impl<T: ThreadSafeLayoutNode> ThreadSafeLayoutNodeHelpers for T {
}

pub enum TextContent {
Text(String),
Text(Box<str>),
GeneratedContent(Vec<ContentItem>),
}

Expand Down
56 changes: 28 additions & 28 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -5459,8 +5459,7 @@ clip-path
}

pub fn set_content(&mut self, v: longhands::content::computed_value::T, device: &Device) {
use properties::longhands::content::computed_value::T;
use properties::longhands::content::computed_value::ContentItem;
use values::computed::counters::{Content, ContentItem};
use values::generics::CounterStyleOrNone;
use gecko_bindings::structs::nsStyleContentData;
use gecko_bindings::structs::nsStyleContentType;
Expand Down Expand Up @@ -5494,23 +5493,23 @@ clip-path
}

match v {
T::None |
T::Normal => {
Content::None |
Content::Normal => {
// Ensure destructors run, otherwise we could leak.
if !self.gecko.mContents.is_empty() {
unsafe {
Gecko_ClearAndResizeStyleContents(&mut self.gecko, 0);
}
}
},
T::MozAltContent => {
Content::MozAltContent => {
unsafe {
Gecko_ClearAndResizeStyleContents(&mut self.gecko, 1);
*self.gecko.mContents[0].mContent.mString.as_mut() = ptr::null_mut();
}
self.gecko.mContents[0].mType = eStyleContentType_AltContent;
},
T::Items(items) => {
Content::Items(items) => {
unsafe {
Gecko_ClearAndResizeStyleContents(&mut self.gecko,
items.len() as u32);
Expand All @@ -5522,26 +5521,27 @@ clip-path
unsafe {
*self.gecko.mContents[i].mContent.mString.as_mut() = ptr::null_mut();
}
match item {
ContentItem::String(value) => {
match *item {
ContentItem::String(ref value) => {
self.gecko.mContents[i].mType = eStyleContentType_String;
unsafe {
// NB: we share allocators, so doing this is fine.
*self.gecko.mContents[i].mContent.mString.as_mut() =
as_utf16_and_forget(&value);
}
}
ContentItem::Attr(attr) => {
ContentItem::Attr(ref attr) => {
self.gecko.mContents[i].mType = eStyleContentType_Attr;
let s = if let Some((_, ns)) = attr.namespace {
format!("{}|{}", ns, attr.attribute)
} else {
attr.attribute.into()
};
unsafe {
// NB: we share allocators, so doing this is fine.
*self.gecko.mContents[i].mContent.mString.as_mut() =
as_utf16_and_forget(&s);
*self.gecko.mContents[i].mContent.mString.as_mut() = match attr.namespace {
Some((_, ns)) => {
as_utf16_and_forget(&format!("{}|{}", ns, attr.attribute))
},
None => {
as_utf16_and_forget(&attr.attribute)
}
};
}
}
ContentItem::OpenQuote
Expand All @@ -5552,13 +5552,13 @@ clip-path
=> self.gecko.mContents[i].mType = eStyleContentType_NoOpenQuote,
ContentItem::NoCloseQuote
=> self.gecko.mContents[i].mType = eStyleContentType_NoCloseQuote,
ContentItem::Counter(name, style) => {
ContentItem::Counter(ref name, ref style) => {
set_counter_function(&mut self.gecko.mContents[i],
eStyleContentType_Counter, &name, "", style, device);
eStyleContentType_Counter, &name, "", style.clone(), device);
}
ContentItem::Counters(name, sep, style) => {
ContentItem::Counters(ref name, ref sep, ref style) => {
set_counter_function(&mut self.gecko.mContents[i],
eStyleContentType_Counters, &name, &sep, style, device);
eStyleContentType_Counters, &name, &sep, style.clone(), device);
}
ContentItem::Url(ref url) => {
unsafe {
Expand Down Expand Up @@ -5586,22 +5586,22 @@ clip-path
pub fn clone_content(&self) -> longhands::content::computed_value::T {
use gecko::conversions::string_from_chars_pointer;
use gecko_bindings::structs::nsStyleContentType::*;
use properties::longhands::content::computed_value::{T, ContentItem};
use values::computed::counters::{Content, ContentItem};
use values::Either;
use values::generics::CounterStyleOrNone;
use values::specified::url::SpecifiedUrl;
use values::specified::Attr;

if self.gecko.mContents.is_empty() {
return T::Normal;
return Content::Normal;
}

if self.gecko.mContents.len() == 1 &&
self.gecko.mContents[0].mType == eStyleContentType_AltContent {
return T::MozAltContent;
return Content::MozAltContent;
}

T::Items(
Content::Items(
self.gecko.mContents.iter().map(|gecko_content| {
match gecko_content.mType {
eStyleContentType_OpenQuote => ContentItem::OpenQuote,
Expand All @@ -5611,7 +5611,7 @@ clip-path
eStyleContentType_String => {
let gecko_chars = unsafe { gecko_content.mContent.mString.as_ref() };
let string = unsafe { string_from_chars_pointer(*gecko_chars) };
ContentItem::String(string)
ContentItem::String(string.into_boxed_str())
},
eStyleContentType_Attr => {
let gecko_chars = unsafe { gecko_content.mContent.mString.as_ref() };
Expand Down Expand Up @@ -5641,10 +5641,10 @@ clip-path
unreachable!("counter function shouldn't have single string type"),
};
if gecko_content.mType == eStyleContentType_Counter {
ContentItem::Counter(ident, style)
ContentItem::Counter(ident.into_boxed_str(), style)
} else {
let separator = gecko_function.mSeparator.to_string();
ContentItem::Counters(ident, separator, style)
ContentItem::Counters(ident.into_boxed_str(), separator.into_boxed_str(), style)
}
},
eStyleContentType_Image => {
Expand All @@ -5659,7 +5659,7 @@ clip-path
},
_ => panic!("Found unexpected value in style struct for content property"),
}
}).collect()
}).collect::<Vec<_>>().into_boxed_slice()
)
}

Expand Down

0 comments on commit 7a00066

Please sign in to comment.