diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 5c9ff1256dd..aabb2e69b67 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -840,7 +840,10 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> match text_content { TextContent::Text(string) => { - let info = Box::new(UnscannedTextFragmentInfo::new(string, node.selection())); + let info = Box::new(UnscannedTextFragmentInfo::new( + string.into(), + node.selection(), + )); let specific_fragment_info = SpecificFragmentInfo::UnscannedText(info); fragments .fragments @@ -857,7 +860,8 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> for content_item in content_items.into_iter() { let specific_fragment_info = match content_item { ContentItem::String(string) => { - let info = Box::new(UnscannedTextFragmentInfo::new(string, None)); + let info = + Box::new(UnscannedTextFragmentInfo::new(string.into(), None)); SpecificFragmentInfo::UnscannedText(info) }, content_item => { diff --git a/components/layout/display_list/conversions.rs b/components/layout/display_list/conversions.rs index 2759c5f65ac..ecf20be3869 100644 --- a/components/layout/display_list/conversions.rs +++ b/components/layout/display_list/conversions.rs @@ -95,7 +95,7 @@ impl ToLayout for TransformStyle { type Type = wr::TransformStyle; fn to_layout(&self) -> Self::Type { match *self { - TransformStyle::Auto | TransformStyle::Flat => wr::TransformStyle::Flat, + TransformStyle::Flat => wr::TransformStyle::Flat, TransformStyle::Preserve3d => wr::TransformStyle::Preserve3D, } } diff --git a/components/layout/table.rs b/components/layout/table.rs index 190f6693256..80f5ac43032 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -309,7 +309,7 @@ impl Flow for TableFlow { percentage: match *specified_inline_size { Size::Auto => 0.0, Size::LengthPercentage(ref lp) => { - lp.0.as_percentage().map_or(0.0, |p| p.0) + lp.0.to_percentage().map_or(0.0, |p| p.0) }, }, preferred: Au(0), diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 58fb40bde3a..0d959b7456c 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -437,7 +437,7 @@ impl Flow for TableRowFlow { .unwrap_or(child_base.intrinsic_inline_sizes.minimum_inline_size), percentage: match child_specified_inline_size { Size::Auto => 0.0, - Size::LengthPercentage(ref lp) => lp.0.as_percentage().map_or(0.0, |p| p.0), + Size::LengthPercentage(ref lp) => lp.0.to_percentage().map_or(0.0, |p| p.0), }, preferred: child_base.intrinsic_inline_sizes.preferred_inline_size, constrained: match child_specified_inline_size { diff --git a/components/layout_2020/sizing.rs b/components/layout_2020/sizing.rs index dc7513a7859..676c7eb347a 100644 --- a/components/layout_2020/sizing.rs +++ b/components/layout_2020/sizing.rs @@ -117,12 +117,12 @@ impl BoxContentSizes { .auto_is(Length::zero); let max_inline_size = match style.max_box_size().inline { MaxSize::None => None, - MaxSize::LengthPercentage(ref lp) => lp.as_length(), + MaxSize::LengthPercentage(ref lp) => lp.to_length(), }; let clamp = |l: Length| l.clamp_between_extremums(min_inline_size, max_inline_size); // Percentages for 'width' are treated as 'auto' - let inline_size = inline_size.map(|lp| lp.as_length()); + let inline_size = inline_size.map(|lp| lp.to_length()); // The (inner) min/max-content are only used for 'auto' let mut outer = match inline_size.non_auto().flatten() { None => { diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index f6fb8d4000a..30b384f3884 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -59,7 +59,7 @@ impl ComputedValuesExt for ComputedValues { } else { &position.height }; - matches!(size, Size::LengthPercentage(lp) if lp.0.as_length().is_some()) + matches!(size, Size::LengthPercentage(lp) if lp.0.to_length().is_some()) } fn inline_box_offsets_are_both_non_auto(&self) -> bool { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 1962bba3a53..d3e61867518 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2902,6 +2902,7 @@ pub struct ComputedValues { impl ComputedValues { /// Returns the pseudo-element that this style represents. + #[cfg(feature = "servo")] pub fn pseudo(&self) -> Option<<&PseudoElement> { self.pseudo.as_ref() } diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs index c726e6fbff7..9def9108046 100644 --- a/components/style/rule_tree/mod.rs +++ b/components/style/rule_tree/mod.rs @@ -1718,6 +1718,7 @@ impl Clone for StrongRuleNode { } impl Drop for StrongRuleNode { + #[cfg_attr(feature = "servo", allow(unused_mut))] fn drop(&mut self) { let node = unsafe { &*self.ptr() }; diff --git a/components/style/values/computed/length_percentage.rs b/components/style/values/computed/length_percentage.rs index 6851bc0c674..7c1e831f7df 100644 --- a/components/style/values/computed/length_percentage.rs +++ b/components/style/values/computed/length_percentage.rs @@ -378,6 +378,19 @@ impl LengthPercentage { } } + /// Converts to a `` if possible. + #[inline] + pub fn to_percentage(&self) -> Option { + match self.unpack() { + Unpacked::Length(..) => None, + Unpacked::Percentage(p) => Some(p), + Unpacked::Calc(ref c) => { + debug_assert!(!c.length.is_zero()); + None + } + } + } + /// Return the specified percentage if any. #[inline] pub fn specified_percentage(&self) -> Option { @@ -405,7 +418,7 @@ impl LengthPercentage { /// Convert the computed value into used value. #[inline] - fn maybe_to_used_value(&self, container_len: Option) -> Option { + pub fn maybe_to_used_value(&self, container_len: Option) -> Option { self.maybe_percentage_relative_to(container_len).map(Au::from) } diff --git a/components/style/values/generics/counters.rs b/components/style/values/generics/counters.rs index 9ed8cdba68b..88c83f87357 100644 --- a/components/style/values/generics/counters.rs +++ b/components/style/values/generics/counters.rs @@ -168,8 +168,9 @@ pub enum GenericContent { pub use self::GenericContent as Content; impl Content { + /// Whether `self` represents list of items. #[inline] - pub(crate) fn is_items(&self) -> bool { + pub fn is_items(&self) -> bool { matches!(*self, Self::Items(..)) } diff --git a/components/style/values/specified/counters.rs b/components/style/values/specified/counters.rs index 15898b58f47..0849cc19116 100644 --- a/components/style/values/specified/counters.rs +++ b/components/style/values/specified/counters.rs @@ -113,6 +113,7 @@ impl Parse for Content { // normal | none | [ | | open-quote | close-quote | no-open-quote | // no-close-quote ]+ // TODO: , attr() + #[cfg_attr(feature = "servo", allow(unused_mut))] fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, diff --git a/components/style_traits/owned_str.rs b/components/style_traits/owned_str.rs index 42a83a07713..ebfdcd5e066 100644 --- a/components/style_traits/owned_str.rs +++ b/components/style_traits/owned_str.rs @@ -38,6 +38,34 @@ impl DerefMut for OwnedStr { } } +impl OwnedStr { + /// Convert the OwnedStr into a boxed str. + #[inline] + pub fn into_box(self) -> Box { + self.into_string().into_boxed_str() + } + + /// Convert the OwnedStr into a `String`. + #[inline] + pub fn into_string(self) -> String { + unsafe { String::from_utf8_unchecked(self.0.into_vec()) } + } +} + +impl From for String { + #[inline] + fn from(b: OwnedStr) -> Self { + b.into_string() + } +} + +impl From for Box { + #[inline] + fn from(b: OwnedStr) -> Self { + b.into_box() + } +} + impl From> for OwnedStr { #[inline] fn from(b: Box) -> Self {