Miscellaneous build / tidy fixes.

This commit is contained in:
Emilio Cobos Álvarez 2021-02-26 12:40:48 +01:00
parent 5158f65810
commit 31e8e418ea
66 changed files with 566 additions and 294 deletions

View file

@ -510,10 +510,11 @@ trivial_to_computed_value!(u16);
trivial_to_computed_value!(u32);
trivial_to_computed_value!(usize);
trivial_to_computed_value!(Atom);
trivial_to_computed_value!(crate::values::AtomIdent);
#[cfg(feature = "servo")]
trivial_to_computed_value!(html5ever::Namespace);
trivial_to_computed_value!(crate::Namespace);
#[cfg(feature = "servo")]
trivial_to_computed_value!(html5ever::Prefix);
trivial_to_computed_value!(crate::Prefix);
trivial_to_computed_value!(String);
trivial_to_computed_value!(Box<str>);
trivial_to_computed_value!(crate::OwnedStr);

View file

@ -117,7 +117,7 @@ pub use self::GenericCrossFadeElement as CrossFadeElement;
pub use self::GenericCrossFadeImage as CrossFadeImage;
/// https://drafts.csswg.org/css-images-4/#image-set-notation
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem, ToCss)]
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToShmem)]
#[css(comma, function = "image-set")]
#[repr(C)]
pub struct GenericImageSet<Image, Resolution> {

View file

@ -68,7 +68,7 @@ pub fn serialize_atom_identifier<Static, W>(
dest: &mut W,
) -> fmt::Result
where
Static: ::string_cache::StaticAtomSet,
Static: string_cache::StaticAtomSet,
W: Write,
{
serialize_identifier(&ident, dest)
@ -90,7 +90,7 @@ pub fn serialize_atom_name<Static, W>(
dest: &mut W,
) -> fmt::Result
where
Static: ::string_cache::StaticAtomSet,
Static: string_cache::StaticAtomSet,
W: Write,
{
serialize_name(&ident, dest)
@ -114,13 +114,27 @@ where
)]
pub struct AtomString(pub Atom);
#[cfg(feature = "servo")]
impl AsRef<str> for AtomString {
fn as_ref(&self) -> &str {
&*self.0
}
}
impl cssparser::ToCss for AtomString {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
W: Write,
{
self.0
.with_str(|s| cssparser::CssStringWriter::new(dest).write_str(s))
#[cfg(feature = "servo")]
{
cssparser::CssStringWriter::new(dest).write_str(self.as_ref())
}
#[cfg(feature = "gecko")]
{
self.0
.with_str(|s| cssparser::CssStringWriter::new(dest).write_str(s))
}
}
}
@ -138,24 +152,138 @@ impl<'a> From<&'a str> for AtomString {
}
}
/// A generic CSS `<ident>` stored as an `Atom`.
#[cfg(feature = "servo")]
#[repr(transparent)]
#[derive(Deref)]
pub struct GenericAtomIdent<Set>(pub string_cache::Atom<Set>)
where
Set: string_cache::StaticAtomSet;
/// A generic CSS `<ident>` stored as an `Atom`, for the default atom set.
#[cfg(feature = "servo")]
pub type AtomIdent = GenericAtomIdent<servo_atoms::AtomStaticSet>;
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> style_traits::SpecifiedValueInfo for GenericAtomIdent<Set> {}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> Default for GenericAtomIdent<Set> {
fn default() -> Self {
Self(string_cache::Atom::default())
}
}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> std::fmt::Debug for GenericAtomIdent<Set> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(f)
}
}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> std::hash::Hash for GenericAtomIdent<Set> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.hash(state)
}
}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> Eq for GenericAtomIdent<Set> {}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> PartialEq for GenericAtomIdent<Set> {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> Clone for GenericAtomIdent<Set> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> to_shmem::ToShmem for GenericAtomIdent<Set> {
fn to_shmem(&self, builder: &mut to_shmem::SharedMemoryBuilder) -> to_shmem::Result<Self> {
use std::mem::ManuallyDrop;
let atom = self.0.to_shmem(builder)?;
Ok(ManuallyDrop::new(Self(ManuallyDrop::into_inner(atom))))
}
}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> malloc_size_of::MallocSizeOf for GenericAtomIdent<Set> {
fn size_of(&self, ops: &mut malloc_size_of::MallocSizeOfOps) -> usize {
self.0.size_of(ops)
}
}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> cssparser::ToCss for GenericAtomIdent<Set> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
W: Write,
{
serialize_atom_identifier(&self.0, dest)
}
}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> PrecomputedHash for GenericAtomIdent<Set> {
#[inline]
fn precomputed_hash(&self) -> u32 {
self.0.precomputed_hash()
}
}
#[cfg(feature = "servo")]
impl<'a, Set: string_cache::StaticAtomSet> From<&'a str> for GenericAtomIdent<Set> {
#[inline]
fn from(string: &str) -> Self {
Self(string_cache::Atom::from(string))
}
}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> std::borrow::Borrow<string_cache::Atom<Set>>
for GenericAtomIdent<Set>
{
#[inline]
fn borrow(&self) -> &string_cache::Atom<Set> {
&self.0
}
}
#[cfg(feature = "servo")]
impl<Set: string_cache::StaticAtomSet> GenericAtomIdent<Set> {
/// Constructs a new GenericAtomIdent.
#[inline]
pub fn new(atom: string_cache::Atom<Set>) -> Self {
Self(atom)
}
/// Cast an atom ref to an AtomIdent ref.
#[inline]
pub fn cast<'a>(atom: &'a string_cache::Atom<Set>) -> &'a Self {
let ptr = atom as *const _ as *const Self;
// safety: repr(transparent)
unsafe { &*ptr }
}
}
/// A CSS `<ident>` stored as an `Atom`.
#[cfg(feature = "gecko")]
#[repr(transparent)]
#[derive(
Clone,
Debug,
Default,
Deref,
Eq,
Hash,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToResolvedValue,
ToShmem,
Clone, Debug, Default, Deref, Eq, Hash, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem,
)]
pub struct AtomIdent(pub Atom);
#[cfg(feature = "gecko")]
impl cssparser::ToCss for AtomIdent {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
@ -165,6 +293,7 @@ impl cssparser::ToCss for AtomIdent {
}
}
#[cfg(feature = "gecko")]
impl PrecomputedHash for AtomIdent {
#[inline]
fn precomputed_hash(&self) -> u32 {
@ -172,6 +301,7 @@ impl PrecomputedHash for AtomIdent {
}
}
#[cfg(feature = "gecko")]
impl<'a> From<&'a str> for AtomIdent {
#[inline]
fn from(string: &str) -> Self {
@ -179,9 +309,15 @@ impl<'a> From<&'a str> for AtomIdent {
}
}
#[cfg(feature = "gecko")]
impl AtomIdent {
/// Constructs a new AtomIdent.
#[inline]
pub fn new(atom: Atom) -> Self {
Self(atom)
}
/// Like `Atom::with` but for `AtomIdent`.
#[cfg(feature = "gecko")]
pub unsafe fn with<F, R>(ptr: *const crate::gecko_bindings::structs::nsAtom, callback: F) -> R
where
F: FnOnce(&Self) -> R,

View file

@ -74,14 +74,15 @@ trivial_to_resolved_value!(Box<str>);
trivial_to_resolved_value!(crate::OwnedStr);
trivial_to_resolved_value!(cssparser::RGBA);
trivial_to_resolved_value!(crate::Atom);
trivial_to_resolved_value!(crate::values::AtomIdent);
trivial_to_resolved_value!(app_units::Au);
trivial_to_resolved_value!(computed::url::ComputedUrl);
#[cfg(feature = "gecko")]
trivial_to_resolved_value!(computed::url::ComputedImageUrl);
#[cfg(feature = "servo")]
trivial_to_resolved_value!(html5ever::Namespace);
trivial_to_resolved_value!(crate::Namespace);
#[cfg(feature = "servo")]
trivial_to_resolved_value!(html5ever::Prefix);
trivial_to_resolved_value!(crate::Prefix);
trivial_to_resolved_value!(computed::LengthPercentage);
trivial_to_resolved_value!(style_traits::values::specified::AllowedNumericType);

View file

@ -1144,15 +1144,6 @@ impl Parse for PaintWorklet {
}
impl MozImageRect {
#[cfg(not(feature = "gecko"))]
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>,
_cors_mode: CorsMode,
) -> Result<Self, ParseError<'i>> {
Err(input.new_error_for_next_token())
}
#[cfg(feature = "gecko")]
fn parse<'i, 't>(
context: &ParserContext,

View file

@ -12,7 +12,7 @@ use cssparser::{Parser, Token};
use style_traits::{ParseError, StyleParseErrorKind};
/// A specified resolution.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToShmem, SpecifiedValueInfo)]
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
pub enum Resolution {
/// Dots per inch.
#[css(dimension)]

View file

@ -4,8 +4,6 @@
//! Specified types for CSS values related to tables.
use crate::parser::ParserContext;
/// Specified values for the `caption-side` property.
///
/// Note that despite having "physical" names, these are actually interpreted
@ -15,7 +13,7 @@ use crate::parser::ParserContext;
///
/// https://drafts.csswg.org/css-tables/#propdef-caption-side
#[cfg(feature = "gecko")]
fn caption_side_non_standard_enabled(_context: &ParserContext) -> bool {
fn caption_side_non_standard_enabled(_: &crate::parser::ParserContext) -> bool {
static_prefs::pref!("layout.css.caption-side-non-standard.enabled")
}