From 8c6fe09dce9ad399d3e188a252f88a5647bd2080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 10 Feb 2020 16:09:18 +0100 Subject: [PATCH] style: Fix Servo build. --- components/style/properties/properties.mako.rs | 18 ++++++++++++++---- components/style/rule_tree/mod.rs | 18 +++++++++++++++++- components/style/servo/media_queries.rs | 5 +++++ .../style/values/computed/length_percentage.rs | 8 ++++++++ components/style/values/specified/calc.rs | 12 +++++++++++- 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index ff5d5b5bf56d..1962bba3a534 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2895,9 +2895,17 @@ pub struct ComputedValues { /// We maintain this distinction in servo to reduce the amount of special /// casing. inner: ComputedValuesInner, + + /// The pseudo-element that we're using. + pseudo: Option, } impl ComputedValues { + /// Returns the pseudo-element that this style represents. + pub fn pseudo(&self) -> Option<<&PseudoElement> { + self.pseudo.as_ref() + } + /// Returns whether this style's display value is equal to contents. pub fn is_display_contents(&self) -> bool { self.get_box().clone_display().is_contents() @@ -3000,7 +3008,7 @@ impl ComputedValues { impl ComputedValues { /// Create a new refcounted `ComputedValues` pub fn new( - _: Option<<&PseudoElement>, + pseudo: Option<<&PseudoElement>, custom_properties: Option>, writing_mode: WritingMode, flags: ComputedValueFlags, @@ -3020,7 +3028,8 @@ impl ComputedValues { % for style_struct in data.active_style_structs(): ${style_struct.ident}, % endfor - } + }, + pseudo: pseudo.cloned(), }) } @@ -3835,7 +3844,7 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES; #[allow(missing_docs)] mod lazy_static_module { use crate::logical_geometry::WritingMode; - use create::computed_value_flags::ComputedValueFlags; + use crate::computed_value_flags::ComputedValueFlags; use servo_arc::Arc; use super::{ComputedValues, ComputedValuesInner, longhands, style_structs}; @@ -3867,7 +3876,8 @@ mod lazy_static_module { rules: None, visited_style: None, flags: ComputedValueFlags::empty(), - } + }, + pseudo: None, }; } } diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs index 8a36e2f20d2d..c726e6fbff7b 100644 --- a/components/style/rule_tree/mod.rs +++ b/components/style/rule_tree/mod.rs @@ -138,6 +138,7 @@ impl StyleSource { // This is totally unsafe, should be removed when we figure out the cause of // bug 1607553. + #[cfg(feature = "gecko")] unsafe fn dump_unchecked(&self, writer: &mut W) { if let Some(ref rule) = self.0.as_first() { let rule = rule.read_unchecked(); @@ -149,6 +150,7 @@ impl StyleSource { // This is totally unsafe, should be removed when we figure out the cause of // bug 1607553. #[inline] + #[cfg(feature = "gecko")] unsafe fn read_unchecked(&self) -> &PropertyDeclarationBlock { let block: &Locked = match self.0.borrow() { ArcUnionBorrow::First(ref rule) => &rule.get().read_unchecked().block, @@ -1739,10 +1741,23 @@ impl Drop for StrongRuleNode { return; } - if cfg!(debug_assertions) || crate::gecko_bindings::structs::GECKO_IS_NIGHTLY { + #[cfg(feature = "gecko")] + #[inline(always)] + fn assert_on_release() -> bool { + crate::gecko_bindings::structs::GECKO_IS_NIGHTLY + } + + #[cfg(feature = "servo")] + fn assert_on_release() -> bool { + false + } + + if cfg!(debug_assertions) || assert_on_release() { let children = node.children.read(); if !children.is_empty() { let mut crash_str = vec![]; + + #[cfg(feature = "gecko")] unsafe { // Try to unsafely collect some information of this before // crashing the process. @@ -1755,6 +1770,7 @@ impl Drop for StrongRuleNode { crash_str.push(b'\n'); }); } + panic!("Children left in the rule tree on drop: {}", String::from_utf8_lossy(&crash_str).trim()); } } diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index b1e752234e5e..fa288a927291 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -165,6 +165,11 @@ impl Device { RGBA::new(255, 255, 255, 255) } + /// Returns the default color color. + pub fn default_color(&self) -> RGBA { + RGBA::new(0, 0, 0, 255) + } + /// Returns safe area insets pub fn safe_area_insets(&self) -> SideOffsets2D { SideOffsets2D::zero() diff --git a/components/style/values/computed/length_percentage.rs b/components/style/values/computed/length_percentage.rs index f6537c3ecefc..6851bc0c674b 100644 --- a/components/style/values/computed/length_percentage.rs +++ b/components/style/values/computed/length_percentage.rs @@ -73,6 +73,10 @@ pub struct CalcVariant { ptr: *mut CalcLengthPercentage, } +// `CalcLengthPercentage` is `Send + Sync` as asserted below. +unsafe impl Send for CalcVariant {} +unsafe impl Sync for CalcVariant {} + #[doc(hidden)] #[derive(Copy, Clone)] #[repr(C)] @@ -130,10 +134,14 @@ enum Tag { // All the members should be 64 bits, even in 32-bit builds. #[allow(unused)] unsafe fn static_assert() { + fn assert_send_and_sync() {} std::mem::transmute::(0u64); std::mem::transmute::(0u64); std::mem::transmute::(0u64); std::mem::transmute::(0u64); + assert_send_and_sync::(); + assert_send_and_sync::(); + assert_send_and_sync::(); } impl Drop for LengthPercentage { diff --git a/components/style/values/specified/calc.rs b/components/style/values/specified/calc.rs index 18c2af379b7a..d008792eee51 100644 --- a/components/style/values/specified/calc.rs +++ b/components/style/values/specified/calc.rs @@ -881,7 +881,17 @@ impl CalcNode { return Ok(MathFunction::Calc); } - if !static_prefs::pref!("layout.css.comparison-functions.enabled") { + #[cfg(feature = "gecko")] + fn comparison_functions_enabled() -> bool { + static_prefs::pref!("layout.css.comparison-functions.enabled") + } + + #[cfg(feature = "servo")] + fn comparison_functions_enabled() -> bool { + false + } + + if !comparison_functions_enabled() { return Err(location.new_unexpected_token_error(Token::Function(name.clone()))); }