Skip to content
Permalink
Browse files

style: Fix servo build, and appease tidy / fmt.

  • Loading branch information...
emilio committed Apr 11, 2019
1 parent 8c004c0 commit 49842f50312787fc4f89c88536d7fc9e87583b06

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -26,7 +26,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use style::computed_values::{font_stretch, font_style, font_variant_caps, font_weight};
use style::properties::style_structs::Font as FontStyleStruct;
use style::values::computed::font::SingleFontFamily;
use style::values::computed::font::{GenericFontFamily, SingleFontFamily};
use unicode_script::Script;

macro_rules! ot_tag {
@@ -564,9 +564,14 @@ impl<'a> From<&'a SingleFontFamily> for FontFamilyName {
FontFamilyName::Specific(family_name.name.clone())
},

SingleFontFamily::Generic(ref generic_name) => {
FontFamilyName::Generic(generic_name.clone())
},
SingleFontFamily::Generic(generic) => FontFamilyName::Generic(match generic {
GenericFontFamily::None => panic!("Shouldn't appear in style"),
GenericFontFamily::Serif => atom!("serif"),
GenericFontFamily::SansSerif => atom!("sans-serif"),
GenericFontFamily::Monospace => atom!("monospace"),
GenericFontFamily::Cursive => atom!("cursive"),
GenericFontFamily::Fantasy => atom!("fantasy"),
}),
}
}
}
@@ -19,9 +19,10 @@ use std::fmt;
use std::sync::Arc;
use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues;
use style::values::computed::length::{MaxSize, NonNegativeLengthOrAuto, Size};
use style::values::computed::length::{
MaxSize, NonNegativeLengthOrAuto, NonNegativeLengthPercentageOrNormal, Size,
};
use style::values::generics::column::ColumnCount;
use style::values::Either;

#[allow(unsafe_code)]
unsafe impl crate::flow::HasBaseFlow for MulticolFlow {}
@@ -106,8 +107,10 @@ impl Flow for MulticolFlow {
{
let style = &self.block_flow.fragment.style;
let column_gap = match style.get_position().column_gap {
Either::First(len) => len.0.to_pixel_length(content_inline_size).into(),
Either::Second(_normal) => {
NonNegativeLengthPercentageOrNormal::LengthPercentage(len) => {
len.0.to_pixel_length(content_inline_size).into()
},
NonNegativeLengthPercentageOrNormal::Normal => {
self.block_flow.fragment.style.get_font().font_size.size()
},
};
@@ -643,6 +643,7 @@ impl LayoutElementHelpers for LayoutDom<Element> {
};

if let Some(font_family) = font_family {
// FIXME(emilio): This in Gecko parses a whole family list.
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::FontFamily(font_family::SpecifiedValue::Values(
@@ -20,7 +20,7 @@ gecko = ["style_traits/gecko", "fallible/known_system_malloc"]
use_bindgen = ["bindgen", "regex", "toml"]
servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever",
"cssparser/serde", "encoding_rs", "malloc_size_of/servo", "arrayvec/use_union",
"servo_url", "string_cache", "crossbeam-channel"]
"servo_url", "string_cache", "crossbeam-channel", "to_shmem/servo", "servo_arc/servo"]
gecko_debug = []

[dependencies]
@@ -70,7 +70,7 @@ impl FontMetricsProvider for ServoMetricsProvider {
ServoMetricsProvider
}

fn get_size(&self, _font_name: &Atom, _font_family: u8) -> Au {
fn get_size(&self, _: &Atom, _: crate::values::computed::font::GenericFontFamily) -> Au {
unreachable!("Dummy provider should never be used to compute font size")
}
}
@@ -123,7 +123,7 @@ impl MallocSizeOf for CssUrl {
}

/// A key type for URL_VALUE_TABLE.
#[derive(Hash, PartialEq, Eq)]
#[derive(Eq, Hash, PartialEq)]
struct CssUrlDataKey(*const CssUrlData);

unsafe impl Sync for CssUrlDataKey {}
@@ -25,7 +25,7 @@ use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCs
use crate::stylesheets::{CssRuleType, Origin, UrlExtraData};
use super::*;
use crate::values::computed::Context;
use crate::selector_parser::{SelectorImpl};
use crate::selector_parser::SelectorImpl;
use selectors::SelectorList;

/// The animation rules.
@@ -495,8 +495,7 @@ ${helpers.predefined_type(
// a lot of code with `if product == gecko` conditionals, we have a
// dummy system font module that does nothing

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, SpecifiedValueInfo, ToCss)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
/// void enum for system font, can never exist
pub enum SystemFont {}
impl SystemFont {
@@ -29,8 +29,7 @@ use style_traits::{ParseError, StyleParseErrorKind};
/// A pseudo-element, both public and private.
///
/// NB: If you add to this list, be sure to update `each_simple_pseudo_element` too.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
#[allow(missing_docs)]
#[repr(usize)]
pub enum PseudoElement {
@@ -265,8 +264,7 @@ pub type Lang = Box<str>;

/// A non tree-structural pseudo-class.
/// See https://drafts.csswg.org/selectors-4/#structural-pseudos
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
#[allow(missing_docs)]
pub enum NonTSPseudoClass {
Active,
@@ -12,7 +12,7 @@ use std::fmt::{self, Write};
// nonzero optimization is important in keeping the size of SpecifiedUrl below
// the threshold.
use crate::values::computed::{Context, ToComputedValue};
use std::sync::Arc;
use servo_arc::Arc;
use style_traits::{CssWriter, ParseError, ToCss};

/// A CSS url() value for servo.
@@ -26,7 +26,7 @@ use style_traits::{CssWriter, ParseError, ToCss};
///
/// TODO(emilio): This should be shrunk by making CssUrl a wrapper type of an
/// arc, and keep the serialization in that Arc. See gecko/url.rs for example.
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, SpecifiedValueInfo)]
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, SpecifiedValueInfo, ToShmem)]
pub struct CssUrl {
/// The original URI. This might be optional since we may insert computed
/// values of images into the cascade directly, and we don't bother to
@@ -15,7 +15,6 @@ use std::cell::UnsafeCell;
use std::fmt;
#[cfg(feature = "servo")]
use std::mem;
#[cfg(feature = "gecko")]
use std::mem::ManuallyDrop;
#[cfg(feature = "gecko")]
use std::ptr;
@@ -124,11 +123,7 @@ impl<'a> Drop for SharedRwLockReadGuard<'a> {
fn drop(&mut self) {
// Unsafe: self.lock is private to this module, only ever set after `read()`,
// and never copied or cloned (see `compile_time_assert` below).
if let Some(arc) = self.0.arc {
unsafe {
arc.force_unlock_read();
}
}
unsafe { self.0.arc.force_unlock_read() }
}
}

@@ -166,12 +161,6 @@ impl<T: fmt::Debug> fmt::Debug for Locked<T> {
}

impl<T> Locked<T> {
#[cfg(feature = "servo")]
#[inline]
fn is_read_only_lock(&self) -> bool {
false
}

#[cfg(feature = "gecko")]
#[inline]
fn is_read_only_lock(&self) -> bool {
@@ -199,10 +188,14 @@ impl<T> Locked<T> {

/// Access the data for reading.
pub fn read_with<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a T {
#[cfg(feature = "gecko")]
assert!(
self.is_read_only_lock() || self.same_lock_as(guard.0.as_ref().map(|r| &**r)),
"Locked::read_with called with a guard from an unrelated SharedRwLock"
);
#[cfg(not(feature = "gecko"))]
assert!(self.same_lock_as(&guard.0));

let ptr = self.data.get();

// Unsafe:
@@ -223,10 +216,14 @@ impl<T> Locked<T> {

/// Access the data for writing.
pub fn write_with<'a>(&'a self, guard: &'a mut SharedRwLockWriteGuard) -> &'a mut T {
#[cfg(feature = "gecko")]
assert!(
!self.is_read_only_lock() && self.same_lock_as(Some(&guard.0)),
"Locked::write_with called with a guard from a read only or unrelated SharedRwLock"
);
#[cfg(not(feature = "gecko"))]
assert!(self.same_lock_as(&guard.0));

let ptr = self.data.get();

// Unsafe:
@@ -39,6 +39,7 @@ use std::fmt;
#[cfg(feature = "gecko")]
use std::mem::{self, ManuallyDrop};
use style_traits::ParsingMode;
#[cfg(feature = "gecko")]
use to_shmem::{SharedMemoryBuilder, ToShmem};

pub use self::counter_style_rule::CounterStyleRule;
@@ -29,6 +29,7 @@ use std::mem::{self, ManuallyDrop};
#[cfg(feature = "servo")]
use std::slice;
use style_traits::{CssWriter, ParseError, ToCss};
#[cfg(feature = "gecko")]
use to_shmem::{SharedMemoryBuilder, ToShmem};

pub use crate::values::computed::Length as MozScriptMinSize;
@@ -284,7 +285,7 @@ pub enum FontFamilyNameSyntax {
Identifiers,
}

#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToResolvedValue)]
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToShmem)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, Hash))]
/// A set of faces that vary in weight, width or slope.
pub enum SingleFontFamily {
@@ -299,7 +300,10 @@ pub enum SingleFontFamily {
/// The order here is important, if you change it make sure that
/// `gfxPlatformFontList.h`s ranged array and `gfxFontFamilyList`'s
/// sSingleGenerics are updated as well.
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, Parse, ToCss, ToResolvedValue)]
#[derive(
Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, Parse, ToCss, ToResolvedValue, ToShmem,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(u8)]
#[allow(missing_docs)]
pub enum GenericFontFamily {
@@ -373,6 +377,35 @@ impl SingleFontFamily {
}))
}

#[cfg(feature = "servo")]
/// Get the corresponding font-family with Atom
pub fn from_atom(input: Atom) -> SingleFontFamily {
match input {
atom!("serif") => return SingleFontFamily::Generic(GenericFontFamily::Serif),
atom!("sans-serif") => return SingleFontFamily::Generic(GenericFontFamily::SansSerif),
atom!("cursive") => return SingleFontFamily::Generic(GenericFontFamily::Cursive),
atom!("fantasy") => return SingleFontFamily::Generic(GenericFontFamily::Fantasy),
atom!("monospace") => return SingleFontFamily::Generic(GenericFontFamily::Monospace),
_ => {},
}

match_ignore_ascii_case! { &input,
"serif" => return SingleFontFamily::Generic(GenericFontFamily::Serif),
"sans-serif" => return SingleFontFamily::Generic(GenericFontFamily::SansSerif),
"cursive" => return SingleFontFamily::Generic(GenericFontFamily::Cursive),
"fantasy" => return SingleFontFamily::Generic(GenericFontFamily::Fantasy),
"monospace" => return SingleFontFamily::Generic(GenericFontFamily::Monospace),
_ => {}
}

// We don't know if it's quoted or not. So we set it to
// quoted by default.
SingleFontFamily::FamilyName(FamilyName {
name: input,
syntax: FontFamilyNameSyntax::Quoted,
})
}

#[cfg(feature = "gecko")]
/// Get the corresponding font-family with family name
fn from_font_family_name(family: &structs::FontFamilyName) -> SingleFontFamily {
@@ -389,7 +422,7 @@ impl SingleFontFamily {
}

#[cfg(feature = "servo")]
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToResolvedValue)]
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem)]
/// A list of SingleFontFamily
pub struct FontFamilyList(Box<[SingleFontFamily]>);

@@ -501,7 +534,7 @@ impl FontFamilyList {
let mut iter = self.iter();
if let Some(SingleFontFamily::Generic(f)) = iter.next() {
if iter.next().is_none() {
return Some(f);
return Some(f.clone());
}
}
None
Oops, something went wrong.

0 comments on commit 49842f5

Please sign in to comment.
You can’t perform that action at this time.