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

@ -12,6 +12,7 @@ use crate::str::str_join;
use crate::str::{read_exponent, read_fraction, HTML_SPACE_CHARACTERS};
use crate::str::{read_numbers, split_commas, split_html_space_chars};
use crate::values::specified::Length;
use crate::values::AtomString;
use crate::{Atom, LocalName, Namespace, Prefix};
use app_units::Au;
use cssparser::{self, Color, RGBA};
@ -354,7 +355,7 @@ impl AttrValue {
}
}
pub fn eval_selector(&self, selector: &AttrSelectorOperation<&String>) -> bool {
pub fn eval_selector(&self, selector: &AttrSelectorOperation<&AtomString>) -> bool {
// FIXME(SimonSapin) this can be more efficient by matching on `(self, selector)` variants
// and doing Atom comparisons instead of string comparisons where possible,
// with SelectorImpl::AttrValue changed to Atom.

View file

@ -16,7 +16,6 @@ use selectors::matching::{self, MatchingContext, MatchingMode};
use selectors::parser::{Combinator, Component, LocalName, SelectorImpl};
use selectors::{Element, NthIndexCache, SelectorList};
use smallvec::SmallVec;
use std::borrow::Borrow;
/// <https://dom.spec.whatwg.org/#dom-element-matches>
pub fn element_matches<E>(
@ -354,11 +353,14 @@ where
ref name,
ref lower_name,
} = *local_name;
if element.is_html_element_in_html_document() {
element.local_name() == lower_name.borrow()
let chosen_name = if element.is_html_element_in_html_document() {
lower_name
} else {
element.local_name() == name.borrow()
}
name
};
element.local_name() == &**chosen_name
}
/// Fast paths for querySelector with a single simple selector.

View file

@ -128,7 +128,7 @@ bitflags! {
/// https://html.spec.whatwg.org/multipage/#centered-alignment
const IN_MODAL_DIALOG_STATE = 1 << 53;
/// https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees
/// https://html.spec.whatwg.org/multipage/#inert-subtrees
const IN_MOZINERT_STATE = 1 << 54;
/// State for the topmost dialog element in top layer
const IN_TOPMOST_MODAL_DIALOG_STATE = 1 << 55;

View file

@ -307,7 +307,7 @@ fn eval_prefers_reduced_motion(device: &Device, query_value: Option<PrefersReduc
/// Possible values for prefers-contrast media query.
/// https://drafts.csswg.org/mediaqueries-5/#prefers-contrast
#[derive(Clone, Copy, Debug, FromPrimitive, PartialEq, Parse, ToCss)]
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)]
#[repr(u8)]
pub enum PrefersContrast {
/// More contrast is preferred. Corresponds to an accessibility theme
@ -331,7 +331,7 @@ fn eval_prefers_contrast(device: &Device, query_value: Option<PrefersContrast>)
/// Possible values for the forced-colors media query.
/// https://drafts.csswg.org/mediaqueries-5/#forced-colors
#[derive(Clone, Copy, Debug, FromPrimitive, PartialEq, Parse, ToCss)]
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)]
#[repr(u8)]
pub enum ForcedColors {
/// Page colors are not being forced.

View file

@ -147,6 +147,13 @@ impl PartialEq for WeakAtom {
}
}
impl PartialEq<Atom> for WeakAtom {
#[inline]
fn eq(&self, other: &Atom) -> bool {
self == &**other
}
}
unsafe impl Send for Atom {}
unsafe impl Sync for Atom {}
unsafe impl Sync for WeakAtom {}

View file

@ -47,7 +47,7 @@ impl PrecomputedHash for Namespace {
}
/// A Gecko WeakNamespace is a wrapped WeakAtom.
#[derive(Hash, Deref)]
#[derive(Deref, Hash)]
pub struct WeakNamespace(WeakAtom);
impl Deref for Namespace {

View file

@ -66,7 +66,7 @@ impl Invalidation {
/// Whether we should invalidate just the element, or the whole subtree within
/// it.
#[derive(Copy, Clone, Debug, Eq, MallocSizeOf, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Ord, PartialEq, PartialOrd)]
enum InvalidationKind {
None = 0,
Element,

View file

@ -138,15 +138,19 @@ pub type LocalName = crate::values::AtomIdent;
#[cfg(feature = "gecko")]
pub use crate::gecko_string_cache::Namespace;
#[cfg(feature = "servo")]
pub use html5ever::LocalName;
#[cfg(feature = "servo")]
pub use html5ever::Namespace;
#[cfg(feature = "servo")]
pub use html5ever::Prefix;
#[cfg(feature = "servo")]
pub use servo_atoms::Atom;
#[cfg(feature = "servo")]
#[allow(missing_docs)]
pub type LocalName = crate::values::GenericAtomIdent<html5ever::LocalNameStaticSet>;
#[cfg(feature = "servo")]
#[allow(missing_docs)]
pub type Namespace = crate::values::GenericAtomIdent<html5ever::NamespaceStaticSet>;
#[cfg(feature = "servo")]
#[allow(missing_docs)]
pub type Prefix = crate::values::GenericAtomIdent<html5ever::PrefixStaticSet>;
pub use style_traits::arc_slice::ArcSlice;
pub use style_traits::owned_slice::OwnedSlice;
pub use style_traits::owned_str::OwnedStr;

View file

@ -134,6 +134,23 @@ macro_rules! profiler_label {
($label_type:ident) => {};
}
#[cfg(feature = "servo")]
macro_rules! local_name {
($s:tt) => {
$crate::values::GenericAtomIdent(html5ever::local_name!($s))
};
}
#[cfg(feature = "servo")]
macro_rules! ns {
() => {
$crate::values::GenericAtomIdent(html5ever::ns!())
};
($s:tt) => {
$crate::values::GenericAtomIdent(html5ever::ns!($s))
};
}
#[cfg(feature = "gecko")]
macro_rules! local_name {
($s:tt) => {

View file

@ -111,7 +111,7 @@ def main():
p.name: {"pref": getattr(p, pref_attr)}
for prop in properties_list
if prop.enabled_in_content()
for p in [prop] + prop.alias
for p in [prop] + prop.aliases
}
for kind, properties_list in [
("longhands", properties.longhands),

View file

@ -948,7 +948,8 @@
input.parse_entirely(|input| parse_value(context, input)).map(|longhands| {
% for sub_property in shorthand.sub_properties:
% if sub_property.may_be_disabled_in(shorthand, engine):
if NonCustomPropertyId::from(LonghandId::${sub_property.camel_case}).allowed_in_ignoring_rule_type(context) {
if NonCustomPropertyId::from(LonghandId::${sub_property.camel_case})
.allowed_in_ignoring_rule_type(context) {
% endif
declarations.push(PropertyDeclaration::${sub_property.camel_case}(
longhands.${sub_property.ident}
@ -984,7 +985,10 @@
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let parse_one = |c: &ParserContext, input: &mut Parser<'i, 't>| -> Result<crate::properties::longhands::${to_rust_ident(first_property)}::SpecifiedValue, ParseError<'i>> {
let parse_one = |c: &ParserContext, input: &mut Parser<'i, 't>| -> Result<
crate::properties::longhands::${to_rust_ident(first_property)}::SpecifiedValue,
ParseError<'i>
> {
${parser_function}(c, input)
};
@ -1028,7 +1032,10 @@
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let rect = Rect::parse_with(context, input, |c, i| -> Result<crate::properties::longhands::${to_rust_ident(sub_property_pattern % "top")}::SpecifiedValue, ParseError<'i>> {
let rect = Rect::parse_with(context, input, |c, i| -> Result<
crate::properties::longhands::${to_rust_ident(sub_property_pattern % "top")}::SpecifiedValue,
ParseError<'i>
> {
% if allow_quirks != "No":
${parser_function}_quirky(c, i, specified::AllowQuirks::${allow_quirks})
% else:

View file

@ -37,7 +37,7 @@ ${helpers.single_keyword(
gecko_enum_prefix="StyleInert",
animation_value_type="discrete",
enabled_in="ua",
spec="Nonstandard (https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees)",
spec="Nonstandard (https://html.spec.whatwg.org/multipage/#inert-subtrees)",
)}
${helpers.single_keyword(

View file

@ -60,6 +60,7 @@ ${helpers.predefined_type(
initial_specified_value="specified::Image::None",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image",
boxed=engine == "servo-2013",
servo_restyle_damage="rebuild_and_reflow",
)}

View file

@ -54,7 +54,8 @@ pub use self::cascade::*;
<%!
from collections import defaultdict
from data import Method, PropertyRestrictions, Keyword, to_rust_ident, to_camel_case, RULE_VALUES, SYSTEM_FONT_LONGHANDS
from data import Method, PropertyRestrictions, Keyword, to_rust_ident, \
to_camel_case, RULE_VALUES, SYSTEM_FONT_LONGHANDS
import os.path
%>
@ -1199,7 +1200,10 @@ impl LonghandId {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<PropertyDeclaration, ParseError<'i>> {
type ParsePropertyFn = for<'i, 't> fn(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<PropertyDeclaration, ParseError<'i>>;
type ParsePropertyFn = for<'i, 't> fn(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<PropertyDeclaration, ParseError<'i>>;
static PARSE_PROPERTY: [ParsePropertyFn; ${len(data.longhands)}] = [
% for property in data.longhands:
longhands::${property.ident}::parse_declared,

View file

@ -4,6 +4,7 @@
//! Servo's media-query device and expression representation.
use crate::context::QuirksMode;
use crate::custom_properties::CssEnvironment;
use crate::media_queries::media_feature::{AllowsRanges, ParsingRequirements};
use crate::media_queries::media_feature::{Evaluator, MediaFeatureDescription};
@ -33,6 +34,9 @@ pub struct Device {
viewport_size: Size2D<f32, CSSPixel>,
/// The current device pixel ratio, from CSS pixels to device pixels.
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
/// The current quirks mode.
#[ignore_malloc_size_of = "Pure stack type"]
quirks_mode: QuirksMode,
/// The font size of the root element
/// This is set when computing the style of the root
@ -60,6 +64,7 @@ impl Device {
/// Trivially construct a new `Device`.
pub fn new(
media_type: MediaType,
quirks_mode: QuirksMode,
viewport_size: Size2D<f32, CSSPixel>,
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
) -> Device {
@ -67,6 +72,7 @@ impl Device {
media_type,
viewport_size,
device_pixel_ratio,
quirks_mode,
// FIXME(bz): Seems dubious?
root_font_size: AtomicU32::new(FONT_MEDIUM_PX.to_bits()),
used_root_font_size: AtomicBool::new(false),
@ -101,6 +107,11 @@ impl Device {
.store(size.px().to_bits(), Ordering::Relaxed)
}
/// Get the quirks mode of the current device.
pub fn quirks_mode(&self) -> QuirksMode {
self.quirks_mode
}
/// Sets the body text color for the "inherit color from body" quirk.
///
/// <https://quirks.spec.whatwg.org/#the-tables-inherit-color-from-body-quirk>

View file

@ -15,6 +15,7 @@ use crate::properties::longhands::display::computed_value::T as Display;
use crate::properties::{ComputedValues, PropertyFlags};
use crate::selector_parser::AttrValue as SelectorAttrValue;
use crate::selector_parser::{PseudoElementCascadeType, SelectorParser};
use crate::values::{AtomIdent, AtomString};
use crate::{Atom, CaseSensitivityExt, LocalName, Namespace, Prefix};
use cssparser::{serialize_identifier, CowRcStr, Parser as CssParser, SourceLocation, ToCss};
use fxhash::FxHashMap;
@ -66,10 +67,6 @@ pub enum PseudoElement {
/// The count of all pseudo-elements.
pub const PSEUDO_COUNT: usize = PseudoElement::ServoInlineAbsolute as usize + 1;
impl ::selectors::parser::PseudoElement for PseudoElement {
type Impl = SelectorImpl;
}
impl ToCss for PseudoElement {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
@ -96,6 +93,10 @@ impl ToCss for PseudoElement {
}
}
impl ::selectors::parser::PseudoElement for PseudoElement {
type Impl = SelectorImpl;
}
/// The number of eager pseudo-elements. Keep this in sync with cascade_type.
pub const EAGER_PSEUDO_COUNT: usize = 3;
@ -344,7 +345,6 @@ impl ToCss for NonTSPseudoClass {
Fullscreen => ":fullscreen",
Hover => ":hover",
Indeterminate => ":indeterminate",
MozInert => ":-moz-inert",
Link => ":link",
PlaceholderShown => ":placeholder-shown",
ReadWrite => ":read-write",
@ -402,15 +402,13 @@ impl ::selectors::SelectorImpl for SelectorImpl {
type NonTSPseudoClass = NonTSPseudoClass;
type ExtraMatchingData = InvalidationMatchingData;
type AttrValue = String;
type Identifier = Atom;
type ClassName = Atom;
type PartName = Atom;
type AttrValue = AtomString;
type Identifier = AtomIdent;
type LocalName = LocalName;
type NamespacePrefix = Prefix;
type NamespaceUrl = Namespace;
type BorrowedLocalName = LocalName;
type BorrowedNamespaceUrl = Namespace;
type BorrowedLocalName = html5ever::LocalName;
type BorrowedNamespaceUrl = html5ever::Namespace;
}
impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
@ -434,7 +432,6 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
"fullscreen" => Fullscreen,
"hover" => Hover,
"indeterminate" => Indeterminate,
"-moz-inert" => MozInert,
"link" => Link,
"placeholder-shown" => PlaceholderShown,
"read-write" => ReadWrite,
@ -697,15 +694,15 @@ impl ElementSnapshot for ServoElementSnapshot {
.map(|v| v.as_atom())
}
fn is_part(&self, _name: &Atom) -> bool {
fn is_part(&self, _name: &AtomIdent) -> bool {
false
}
fn imported_part(&self, _: &Atom) -> Option<Atom> {
fn imported_part(&self, _: &AtomIdent) -> Option<AtomIdent> {
None
}
fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
fn has_class(&self, name: &AtomIdent, case_sensitivity: CaseSensitivity) -> bool {
self.get_attr(&ns!(), &local_name!("class"))
.map_or(false, |v| {
v.as_tokens()
@ -716,11 +713,11 @@ impl ElementSnapshot for ServoElementSnapshot {
fn each_class<F>(&self, mut callback: F)
where
F: FnMut(&Atom),
F: FnMut(&AtomIdent),
{
if let Some(v) = self.get_attr(&ns!(), &local_name!("class")) {
for class in v.as_tokens() {
callback(class);
callback(AtomIdent::cast(class));
}
}
}
@ -728,7 +725,7 @@ impl ElementSnapshot for ServoElementSnapshot {
fn lang_attr(&self) -> Option<SelectorAttrValue> {
self.get_attr(&ns!(xml), &local_name!("lang"))
.or_else(|| self.get_attr(&ns!(), &local_name!("lang")))
.map(|v| String::from(v as &str))
.map(|v| SelectorAttrValue::from(v as &str))
}
}
@ -738,7 +735,7 @@ impl ServoElementSnapshot {
&self,
ns: &NamespaceConstraint<&Namespace>,
local_name: &LocalName,
operation: &AttrSelectorOperation<&String>,
operation: &AttrSelectorOperation<&AtomString>,
) -> bool {
match *ns {
NamespaceConstraint::Specific(ref ns) => self

View file

@ -107,11 +107,17 @@ impl CssUrl {
///
/// This is only for shape images and masks in Gecko, thus unimplemented for
/// now so somebody notices when trying to do so.
pub fn parse_with_cors_anonymous<'i, 't>(
_context: &ParserContext,
_input: &mut Parser<'i, 't>,
pub fn parse_with_cors_mode<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
cors_mode: CorsMode,
) -> Result<Self, ParseError<'i>> {
unimplemented!("Need to record somewhere that the request needs to be CORS-enabled")
let url = input.expect_url()?;
Ok(Self::parse_from_string(
url.as_ref().to_owned(),
context,
cors_mode,
))
}
}
@ -120,12 +126,7 @@ impl Parse for CssUrl {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let url = input.expect_url()?;
Ok(Self::parse_from_string(
url.as_ref().to_owned(),
context,
CorsMode::None,
))
Self::parse_with_cors_mode(context, input, CorsMode::None)
}
}

View file

@ -179,3 +179,11 @@ pub type CssStringWriter = ::nsstring::nsACString;
/// needs to allocate a temporary string.
#[cfg(feature = "gecko")]
pub type CssString = ::nsstring::nsCString;
/// String. The comments for the Gecko types explain the need for this abstraction.
#[cfg(feature = "servo")]
pub type CssStringWriter = String;
/// String. The comments for the Gecko types explain the need for this abstraction.
#[cfg(feature = "servo")]
pub type CssString = String;

View file

@ -9,7 +9,6 @@ use crate::computed_value_flags::ComputedValueFlags;
use crate::dom::TElement;
use crate::properties::longhands::display::computed_value::T as Display;
use crate::properties::longhands::float::computed_value::T as Float;
use crate::properties::longhands::overflow_x::computed_value::T as Overflow;
use crate::properties::longhands::position::computed_value::T as Position;
use crate::properties::{self, ComputedValues, StyleBuilder};
@ -153,7 +152,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
}
}
/// https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees
/// https://html.spec.whatwg.org/multipage/#inert-subtrees
///
/// If -moz-inert is applied then add:
/// -moz-user-focus: none;
@ -168,6 +167,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
///
/// NOTE: If this or the pointer-events tweak is removed, then
/// minimal-xul.css and the scrollbar style caching need to be tweaked.
#[cfg(feature = "gecko")]
fn adjust_for_inert(&mut self) {
use crate::values::specified::ui::CursorKind;
use crate::values::specified::ui::UserSelect;
@ -529,6 +529,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// parent, but we need to make sure it's still scrollable.
#[cfg(feature = "gecko")]
fn adjust_for_text_control_editing_root(&mut self) {
use crate::properties::longhands::overflow_x::computed_value::T as Overflow;
use crate::selector_parser::PseudoElement;
if self.style.pseudo != Some(&PseudoElement::MozTextControlEditingRoot) {

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")
}