Skip to content

Commit

Permalink
style: Fix Servo build.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Feb 12, 2020
1 parent cccac2c commit 8c6fe09
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
18 changes: 14 additions & 4 deletions components/style/properties/properties.mako.rs
Expand Up @@ -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<PseudoElement>,
}

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()
Expand Down Expand Up @@ -3000,7 +3008,7 @@ impl ComputedValues {
impl ComputedValues {
/// Create a new refcounted `ComputedValues`
pub fn new(
_: Option<<&PseudoElement>,
pseudo: Option<<&PseudoElement>,
custom_properties: Option<Arc<crate::custom_properties::CustomPropertiesMap>>,
writing_mode: WritingMode,
flags: ComputedValueFlags,
Expand All @@ -3020,7 +3028,8 @@ impl ComputedValues {
% for style_struct in data.active_style_structs():
${style_struct.ident},
% endfor
}
},
pseudo: pseudo.cloned(),
})
}

Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -3867,7 +3876,8 @@ mod lazy_static_module {
rules: None,
visited_style: None,
flags: ComputedValueFlags::empty(),
}
},
pseudo: None,
};
}
}
Expand Down
18 changes: 17 additions & 1 deletion components/style/rule_tree/mod.rs
Expand Up @@ -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<W: Write>(&self, writer: &mut W) {
if let Some(ref rule) = self.0.as_first() {
let rule = rule.read_unchecked();
Expand All @@ -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<PropertyDeclarationBlock> = match self.0.borrow() {
ArcUnionBorrow::First(ref rule) => &rule.get().read_unchecked().block,
Expand Down Expand Up @@ -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.
Expand All @@ -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());
}
}
Expand Down
5 changes: 5 additions & 0 deletions components/style/servo/media_queries.rs
Expand Up @@ -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<f32, CSSPixel> {
SideOffsets2D::zero()
Expand Down
8 changes: 8 additions & 0 deletions components/style/values/computed/length_percentage.rs
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<T: Send + Sync>() {}
std::mem::transmute::<u64, LengthVariant>(0u64);
std::mem::transmute::<u64, PercentageVariant>(0u64);
std::mem::transmute::<u64, CalcVariant>(0u64);
std::mem::transmute::<u64, LengthPercentage>(0u64);
assert_send_and_sync::<LengthVariant>();
assert_send_and_sync::<PercentageVariant>();
assert_send_and_sync::<CalcLengthPercentage>();
}

impl Drop for LengthPercentage {
Expand Down
12 changes: 11 additions & 1 deletion components/style/values/specified/calc.rs
Expand Up @@ -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())));
}

Expand Down

0 comments on commit 8c6fe09

Please sign in to comment.