mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
style: Manually implement collect_completion_keywords for some types.
Bug: 1434130 Reviewed-by: emilio MozReview-Commit-ID: 6T35uylxgho
This commit is contained in:
parent
0f7f9eebc0
commit
07de715bb5
7 changed files with 209 additions and 34 deletions
|
@ -15,11 +15,11 @@ use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use servo_arc::{Arc, RawOffsetArc};
|
use servo_arc::{Arc, RawOffsetArc};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use style_traits::{ParseError, SpecifiedValueInfo};
|
use style_traits::ParseError;
|
||||||
|
|
||||||
/// A CSS url() value for gecko.
|
/// A CSS url() value for gecko.
|
||||||
#[css(function = "url")]
|
#[css(function = "url")]
|
||||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
#[derive(Clone, Debug, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||||
pub struct CssUrl {
|
pub struct CssUrl {
|
||||||
/// The URL in unresolved string form.
|
/// The URL in unresolved string form.
|
||||||
///
|
///
|
||||||
|
@ -120,8 +120,6 @@ impl MallocSizeOf for CssUrl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpecifiedValueInfo for CssUrl {}
|
|
||||||
|
|
||||||
/// A specified url() value for general usage.
|
/// A specified url() value for general usage.
|
||||||
#[derive(Clone, Debug, SpecifiedValueInfo, ToComputedValue, ToCss)]
|
#[derive(Clone, Debug, SpecifiedValueInfo, ToComputedValue, ToCss)]
|
||||||
pub struct SpecifiedUrl {
|
pub struct SpecifiedUrl {
|
||||||
|
|
|
@ -27,7 +27,7 @@ use smallvec::SmallVec;
|
||||||
use std::{cmp, ptr};
|
use std::{cmp, ptr};
|
||||||
use std::mem::{self, ManuallyDrop};
|
use std::mem::{self, ManuallyDrop};
|
||||||
#[cfg(feature = "gecko")] use hash::FnvHashMap;
|
#[cfg(feature = "gecko")] use hash::FnvHashMap;
|
||||||
use style_traits::{ParseError, SpecifiedValueInfo};
|
use style_traits::{KeywordsCollectFn, ParseError, SpecifiedValueInfo};
|
||||||
use super::ComputedValues;
|
use super::ComputedValues;
|
||||||
use values::{CSSFloat, CustomIdent, Either};
|
use values::{CSSFloat, CustomIdent, Either};
|
||||||
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
|
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
|
||||||
|
@ -172,7 +172,14 @@ impl From<nsCSSPropertyID> for TransitionProperty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpecifiedValueInfo for TransitionProperty {}
|
impl SpecifiedValueInfo for TransitionProperty {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
// `transition-property` can actually accept all properties and
|
||||||
|
// arbitrary identifiers, but `all` is a special one we'd like
|
||||||
|
// to list.
|
||||||
|
f(&["all"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if this nsCSSPropertyID is one of the transitionable properties.
|
/// Returns true if this nsCSSPropertyID is one of the transitionable properties.
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
|
|
@ -11,7 +11,8 @@ use num_traits::One;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
use style_traits::{CssWriter, KeywordsCollectFn, ParseError};
|
||||||
|
use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
||||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-fonts-4/#feature-tag-value
|
/// https://drafts.csswg.org/css-fonts-4/#feature-tag-value
|
||||||
|
@ -181,8 +182,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Length> SpecifiedValueInfo for KeywordInfo<Length> {
|
impl<L> SpecifiedValueInfo for KeywordInfo<L> {
|
||||||
const SUPPORTED_TYPES: u8 = <KeywordSize as SpecifiedValueInfo>::SUPPORTED_TYPES;
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
<KeywordSize as SpecifiedValueInfo>::collect_completion_keywords(f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CSS font keywords
|
/// CSS font keywords
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
use counter_style::{parse_counter_style_name, Symbols};
|
use counter_style::{parse_counter_style_name, Symbols};
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use style_traits::{ParseError, StyleParseErrorKind};
|
use style_traits::{KeywordsCollectFn, ParseError};
|
||||||
|
use style_traits::{SpecifiedValueInfo, StyleParseErrorKind};
|
||||||
use super::CustomIdent;
|
use super::CustomIdent;
|
||||||
|
|
||||||
pub mod background;
|
pub mod background;
|
||||||
|
@ -79,8 +80,7 @@ impl SymbolsType {
|
||||||
/// Since wherever <counter-style> is used, 'none' is a valid value as
|
/// Since wherever <counter-style> is used, 'none' is a valid value as
|
||||||
/// well, we combine them into one type to make code simpler.
|
/// well, we combine them into one type to make code simpler.
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, SpecifiedValueInfo, ToComputedValue,
|
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss)]
|
||||||
ToCss)]
|
|
||||||
pub enum CounterStyleOrNone {
|
pub enum CounterStyleOrNone {
|
||||||
/// `none`
|
/// `none`
|
||||||
None,
|
None,
|
||||||
|
@ -138,6 +138,22 @@ impl Parse for CounterStyleOrNone {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for CounterStyleOrNone {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
// XXX The best approach for implementing this is probably
|
||||||
|
// having a CounterStyleName type wrapping CustomIdent, and
|
||||||
|
// put the predefined list for that type in counter_style mod.
|
||||||
|
// But that's a non-trivial change itself, so we use a simpler
|
||||||
|
// approach here.
|
||||||
|
macro_rules! predefined {
|
||||||
|
($($name:expr,)+) => {
|
||||||
|
f(&["none", "symbols", $($name,)+]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
include!("../../counter_style/predefined.rs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A wrapper of Non-negative values.
|
/// A wrapper of Non-negative values.
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
|
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
|
||||||
|
|
|
@ -10,13 +10,13 @@ use cssparser::Parser;
|
||||||
use gecko_bindings::structs;
|
use gecko_bindings::structs;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::{CssWriter, ParseError, ToCss};
|
use style_traits::{CssWriter, KeywordsCollectFn, ParseError, SpecifiedValueInfo, ToCss};
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
/// Constants shared by multiple CSS Box Alignment properties
|
/// Constants shared by multiple CSS Box Alignment properties
|
||||||
///
|
///
|
||||||
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
||||||
#[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue)]
|
#[derive(MallocSizeOf, ToComputedValue)]
|
||||||
pub struct AlignFlags: u8 {
|
pub struct AlignFlags: u8 {
|
||||||
// Enumeration stored in the lower 5 bits:
|
// Enumeration stored in the lower 5 bits:
|
||||||
/// 'auto'
|
/// 'auto'
|
||||||
|
@ -135,8 +135,7 @@ pub enum AxisDirection {
|
||||||
/// Shared value for the `align-content` and `justify-content` properties.
|
/// Shared value for the `align-content` and `justify-content` properties.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#content-distribution>
|
/// <https://drafts.csswg.org/css-align/#content-distribution>
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
ToComputedValue, ToCss)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
pub struct ContentDistribution {
|
pub struct ContentDistribution {
|
||||||
primary: AlignFlags,
|
primary: AlignFlags,
|
||||||
|
@ -192,6 +191,9 @@ impl ContentDistribution {
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
axis: AxisDirection,
|
axis: AxisDirection,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
// NOTE Please also update the `list_keywords` function below
|
||||||
|
// when this function is updated.
|
||||||
|
|
||||||
// Try to parse normal first
|
// Try to parse normal first
|
||||||
if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
|
if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
|
||||||
return Ok(ContentDistribution::normal());
|
return Ok(ContentDistribution::normal());
|
||||||
|
@ -228,13 +230,25 @@ impl ContentDistribution {
|
||||||
content_position | overflow_position,
|
content_position | overflow_position,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_keywords(f: KeywordsCollectFn, axis: AxisDirection) {
|
||||||
|
f(&["normal"]);
|
||||||
|
if axis == AxisDirection::Block {
|
||||||
|
list_baseline_keywords(f);
|
||||||
|
}
|
||||||
|
list_content_distribution_keywords(f);
|
||||||
|
list_overflow_position_keywords(f);
|
||||||
|
f(&["start", "end", "flex-start", "flex-end", "center"]);
|
||||||
|
if axis == AxisDirection::Inline {
|
||||||
|
f(&["left", "right"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Value for the `align-content` property.
|
/// Value for the `align-content` property.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#propdef-align-content>
|
/// <https://drafts.csswg.org/css-align/#propdef-align-content>
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
ToComputedValue, ToCss)]
|
|
||||||
pub struct AlignContent(pub ContentDistribution);
|
pub struct AlignContent(pub ContentDistribution);
|
||||||
|
|
||||||
impl Parse for AlignContent {
|
impl Parse for AlignContent {
|
||||||
|
@ -242,6 +256,8 @@ impl Parse for AlignContent {
|
||||||
_: &ParserContext,
|
_: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
// NOTE Please also update `impl SpecifiedValueInfo` below when
|
||||||
|
// this function is updated.
|
||||||
Ok(AlignContent(ContentDistribution::parse(
|
Ok(AlignContent(ContentDistribution::parse(
|
||||||
input,
|
input,
|
||||||
AxisDirection::Block,
|
AxisDirection::Block,
|
||||||
|
@ -249,6 +265,12 @@ impl Parse for AlignContent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for AlignContent {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
ContentDistribution::list_keywords(f, AxisDirection::Block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl From<u16> for AlignContent {
|
impl From<u16> for AlignContent {
|
||||||
fn from(bits: u16) -> Self {
|
fn from(bits: u16) -> Self {
|
||||||
|
@ -266,8 +288,7 @@ impl From<AlignContent> for u16 {
|
||||||
/// Value for the `justify-content` property.
|
/// Value for the `justify-content` property.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#propdef-align-content>
|
/// <https://drafts.csswg.org/css-align/#propdef-align-content>
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
ToComputedValue, ToCss)]
|
|
||||||
pub struct JustifyContent(pub ContentDistribution);
|
pub struct JustifyContent(pub ContentDistribution);
|
||||||
|
|
||||||
impl Parse for JustifyContent {
|
impl Parse for JustifyContent {
|
||||||
|
@ -275,6 +296,8 @@ impl Parse for JustifyContent {
|
||||||
_: &ParserContext,
|
_: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
// NOTE Please also update `impl SpecifiedValueInfo` below when
|
||||||
|
// this function is updated.
|
||||||
Ok(JustifyContent(ContentDistribution::parse(
|
Ok(JustifyContent(ContentDistribution::parse(
|
||||||
input,
|
input,
|
||||||
AxisDirection::Inline,
|
AxisDirection::Inline,
|
||||||
|
@ -282,6 +305,12 @@ impl Parse for JustifyContent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for JustifyContent {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
ContentDistribution::list_keywords(f, AxisDirection::Inline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl From<u16> for JustifyContent {
|
impl From<u16> for JustifyContent {
|
||||||
fn from(bits: u16) -> Self {
|
fn from(bits: u16) -> Self {
|
||||||
|
@ -297,8 +326,7 @@ impl From<JustifyContent> for u16 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/css-align/#self-alignment>
|
/// <https://drafts.csswg.org/css-align/#self-alignment>
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
ToComputedValue, ToCss)]
|
|
||||||
pub struct SelfAlignment(pub AlignFlags);
|
pub struct SelfAlignment(pub AlignFlags);
|
||||||
|
|
||||||
impl SelfAlignment {
|
impl SelfAlignment {
|
||||||
|
@ -323,6 +351,9 @@ impl SelfAlignment {
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
axis: AxisDirection,
|
axis: AxisDirection,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
// NOTE Please also update the `list_keywords` function below
|
||||||
|
// when this function is updated.
|
||||||
|
|
||||||
// <baseline-position>
|
// <baseline-position>
|
||||||
//
|
//
|
||||||
// It's weird that this accepts <baseline-position>, but not
|
// It's weird that this accepts <baseline-position>, but not
|
||||||
|
@ -343,13 +374,19 @@ impl SelfAlignment {
|
||||||
let self_position = parse_self_position(input, axis)?;
|
let self_position = parse_self_position(input, axis)?;
|
||||||
Ok(SelfAlignment(overflow_position | self_position))
|
Ok(SelfAlignment(overflow_position | self_position))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_keywords(f: KeywordsCollectFn, axis: AxisDirection) {
|
||||||
|
list_baseline_keywords(f);
|
||||||
|
list_auto_normal_stretch(f);
|
||||||
|
list_overflow_position_keywords(f);
|
||||||
|
list_self_position_keywords(f, axis);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The specified value of the align-self property.
|
/// The specified value of the align-self property.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#propdef-align-self>
|
/// <https://drafts.csswg.org/css-align/#propdef-align-self>
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
ToComputedValue, ToCss)]
|
|
||||||
pub struct AlignSelf(pub SelfAlignment);
|
pub struct AlignSelf(pub SelfAlignment);
|
||||||
|
|
||||||
impl Parse for AlignSelf {
|
impl Parse for AlignSelf {
|
||||||
|
@ -357,6 +394,8 @@ impl Parse for AlignSelf {
|
||||||
_: &ParserContext,
|
_: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
// NOTE Please also update `impl SpecifiedValueInfo` below when
|
||||||
|
// this function is updated.
|
||||||
Ok(AlignSelf(SelfAlignment::parse(
|
Ok(AlignSelf(SelfAlignment::parse(
|
||||||
input,
|
input,
|
||||||
AxisDirection::Block,
|
AxisDirection::Block,
|
||||||
|
@ -364,6 +403,12 @@ impl Parse for AlignSelf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for AlignSelf {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
SelfAlignment::list_keywords(f, AxisDirection::Block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<u8> for AlignSelf {
|
impl From<u8> for AlignSelf {
|
||||||
fn from(bits: u8) -> Self {
|
fn from(bits: u8) -> Self {
|
||||||
AlignSelf(SelfAlignment(AlignFlags::from_bits_truncate(bits)))
|
AlignSelf(SelfAlignment(AlignFlags::from_bits_truncate(bits)))
|
||||||
|
@ -379,8 +424,7 @@ impl From<AlignSelf> for u8 {
|
||||||
/// The specified value of the justify-self property.
|
/// The specified value of the justify-self property.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#propdef-justify-self>
|
/// <https://drafts.csswg.org/css-align/#propdef-justify-self>
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
ToComputedValue, ToCss)]
|
|
||||||
pub struct JustifySelf(pub SelfAlignment);
|
pub struct JustifySelf(pub SelfAlignment);
|
||||||
|
|
||||||
impl Parse for JustifySelf {
|
impl Parse for JustifySelf {
|
||||||
|
@ -388,6 +432,8 @@ impl Parse for JustifySelf {
|
||||||
_: &ParserContext,
|
_: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
// NOTE Please also update `impl SpecifiedValueInfo` below when
|
||||||
|
// this function is updated.
|
||||||
Ok(JustifySelf(SelfAlignment::parse(
|
Ok(JustifySelf(SelfAlignment::parse(
|
||||||
input,
|
input,
|
||||||
AxisDirection::Inline,
|
AxisDirection::Inline,
|
||||||
|
@ -395,6 +441,12 @@ impl Parse for JustifySelf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for JustifySelf {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
SelfAlignment::list_keywords(f, AxisDirection::Inline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<u8> for JustifySelf {
|
impl From<u8> for JustifySelf {
|
||||||
fn from(bits: u8) -> Self {
|
fn from(bits: u8) -> Self {
|
||||||
JustifySelf(SelfAlignment(AlignFlags::from_bits_truncate(bits)))
|
JustifySelf(SelfAlignment(AlignFlags::from_bits_truncate(bits)))
|
||||||
|
@ -410,8 +462,7 @@ impl From<JustifySelf> for u8 {
|
||||||
/// Value of the `align-items` property
|
/// Value of the `align-items` property
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#self-alignment>
|
/// <https://drafts.csswg.org/css-align/#self-alignment>
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
ToComputedValue, ToCss)]
|
|
||||||
pub struct AlignItems(pub AlignFlags);
|
pub struct AlignItems(pub AlignFlags);
|
||||||
|
|
||||||
impl AlignItems {
|
impl AlignItems {
|
||||||
|
@ -429,6 +480,9 @@ impl Parse for AlignItems {
|
||||||
_: &ParserContext,
|
_: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
// NOTE Please also update `impl SpecifiedValueInfo` below when
|
||||||
|
// this function is updated.
|
||||||
|
|
||||||
// <baseline-position>
|
// <baseline-position>
|
||||||
if let Ok(baseline) = input.try(parse_baseline) {
|
if let Ok(baseline) = input.try(parse_baseline) {
|
||||||
return Ok(AlignItems(baseline));
|
return Ok(AlignItems(baseline));
|
||||||
|
@ -447,11 +501,19 @@ impl Parse for AlignItems {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for AlignItems {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
list_baseline_keywords(f);
|
||||||
|
list_normal_stretch(f);
|
||||||
|
list_overflow_position_keywords(f);
|
||||||
|
list_self_position_keywords(f, AxisDirection::Block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Value of the `justify-items` property
|
/// Value of the `justify-items` property
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#justify-items-property>
|
/// <https://drafts.csswg.org/css-align/#justify-items-property>
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
|
||||||
ToCss)]
|
|
||||||
pub struct JustifyItems(pub AlignFlags);
|
pub struct JustifyItems(pub AlignFlags);
|
||||||
|
|
||||||
impl JustifyItems {
|
impl JustifyItems {
|
||||||
|
@ -473,6 +535,9 @@ impl Parse for JustifyItems {
|
||||||
_: &ParserContext,
|
_: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
// NOTE Please also update `impl SpecifiedValueInfo` below when
|
||||||
|
// this function is updated.
|
||||||
|
|
||||||
// <baseline-position>
|
// <baseline-position>
|
||||||
//
|
//
|
||||||
// It's weird that this accepts <baseline-position>, but not
|
// It's weird that this accepts <baseline-position>, but not
|
||||||
|
@ -500,10 +565,22 @@ impl Parse for JustifyItems {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for JustifyItems {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
list_baseline_keywords(f);
|
||||||
|
list_normal_stretch(f);
|
||||||
|
list_legacy_keywords(f);
|
||||||
|
list_overflow_position_keywords(f);
|
||||||
|
list_self_position_keywords(f, AxisDirection::Inline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// auto | normal | stretch
|
// auto | normal | stretch
|
||||||
fn parse_auto_normal_stretch<'i, 't>(
|
fn parse_auto_normal_stretch<'i, 't>(
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<AlignFlags, ParseError<'i>> {
|
) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
|
// NOTE Please also update the `list_auto_normal_stretch` function
|
||||||
|
// below when this function is updated.
|
||||||
try_match_ident_ignore_ascii_case! { input,
|
try_match_ident_ignore_ascii_case! { input,
|
||||||
"auto" => Ok(AlignFlags::AUTO),
|
"auto" => Ok(AlignFlags::AUTO),
|
||||||
"normal" => Ok(AlignFlags::NORMAL),
|
"normal" => Ok(AlignFlags::NORMAL),
|
||||||
|
@ -511,16 +588,28 @@ fn parse_auto_normal_stretch<'i, 't>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_auto_normal_stretch(f: KeywordsCollectFn) {
|
||||||
|
f(&["auto", "normal", "stretch"]);
|
||||||
|
}
|
||||||
|
|
||||||
// normal | stretch
|
// normal | stretch
|
||||||
fn parse_normal_stretch<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
fn parse_normal_stretch<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
|
// NOTE Please also update the `list_normal_stretch` function below
|
||||||
|
// when this function is updated.
|
||||||
try_match_ident_ignore_ascii_case! { input,
|
try_match_ident_ignore_ascii_case! { input,
|
||||||
"normal" => Ok(AlignFlags::NORMAL),
|
"normal" => Ok(AlignFlags::NORMAL),
|
||||||
"stretch" => Ok(AlignFlags::STRETCH),
|
"stretch" => Ok(AlignFlags::STRETCH),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_normal_stretch(f: KeywordsCollectFn) {
|
||||||
|
f(&["normal", "stretch"]);
|
||||||
|
}
|
||||||
|
|
||||||
// <baseline-position>
|
// <baseline-position>
|
||||||
fn parse_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
fn parse_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
|
// NOTE Please also update the `list_baseline_keywords` function
|
||||||
|
// below when this function is updated.
|
||||||
try_match_ident_ignore_ascii_case! { input,
|
try_match_ident_ignore_ascii_case! { input,
|
||||||
"baseline" => Ok(AlignFlags::BASELINE),
|
"baseline" => Ok(AlignFlags::BASELINE),
|
||||||
"first" => {
|
"first" => {
|
||||||
|
@ -534,10 +623,16 @@ fn parse_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, Pars
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_baseline_keywords(f: KeywordsCollectFn) {
|
||||||
|
f(&["baseline", "first baseline", "last baseline"]);
|
||||||
|
}
|
||||||
|
|
||||||
// <content-distribution>
|
// <content-distribution>
|
||||||
fn parse_content_distribution<'i, 't>(
|
fn parse_content_distribution<'i, 't>(
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<AlignFlags, ParseError<'i>> {
|
) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
|
// NOTE Please also update the `list_content_distribution_keywords`
|
||||||
|
// function below when this function is updated.
|
||||||
try_match_ident_ignore_ascii_case! { input,
|
try_match_ident_ignore_ascii_case! { input,
|
||||||
"stretch" => Ok(AlignFlags::STRETCH),
|
"stretch" => Ok(AlignFlags::STRETCH),
|
||||||
"space-between" => Ok(AlignFlags::SPACE_BETWEEN),
|
"space-between" => Ok(AlignFlags::SPACE_BETWEEN),
|
||||||
|
@ -546,21 +641,33 @@ fn parse_content_distribution<'i, 't>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_content_distribution_keywords(f: KeywordsCollectFn) {
|
||||||
|
f(&["stretch", "space-between", "space-around", "space-evenly"]);
|
||||||
|
}
|
||||||
|
|
||||||
// <overflow-position>
|
// <overflow-position>
|
||||||
fn parse_overflow_position<'i, 't>(
|
fn parse_overflow_position<'i, 't>(
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<AlignFlags, ParseError<'i>> {
|
) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
|
// NOTE Please also update the `list_overflow_position_keywords`
|
||||||
|
// function below when this function is updated.
|
||||||
try_match_ident_ignore_ascii_case! { input,
|
try_match_ident_ignore_ascii_case! { input,
|
||||||
"safe" => Ok(AlignFlags::SAFE),
|
"safe" => Ok(AlignFlags::SAFE),
|
||||||
"unsafe" => Ok(AlignFlags::UNSAFE),
|
"unsafe" => Ok(AlignFlags::UNSAFE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_overflow_position_keywords(f: KeywordsCollectFn) {
|
||||||
|
f(&["safe", "unsafe"]);
|
||||||
|
}
|
||||||
|
|
||||||
// <self-position> | left | right in the inline axis.
|
// <self-position> | left | right in the inline axis.
|
||||||
fn parse_self_position<'i, 't>(
|
fn parse_self_position<'i, 't>(
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
axis: AxisDirection,
|
axis: AxisDirection,
|
||||||
) -> Result<AlignFlags, ParseError<'i>> {
|
) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
|
// NOTE Please also update the `list_self_position_keywords`
|
||||||
|
// function below when this function is updated.
|
||||||
Ok(try_match_ident_ignore_ascii_case! { input,
|
Ok(try_match_ident_ignore_ascii_case! { input,
|
||||||
"start" => AlignFlags::START,
|
"start" => AlignFlags::START,
|
||||||
"end" => AlignFlags::END,
|
"end" => AlignFlags::END,
|
||||||
|
@ -574,9 +681,21 @@ fn parse_self_position<'i, 't>(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_self_position_keywords(f: KeywordsCollectFn, axis: AxisDirection) {
|
||||||
|
f(&[
|
||||||
|
"start", "end", "flex-start", "flex-end",
|
||||||
|
"center", "self-start", "self-end",
|
||||||
|
]);
|
||||||
|
if axis == AxisDirection::Inline {
|
||||||
|
f(&["left", "right"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_left_right_center<'i, 't>(
|
fn parse_left_right_center<'i, 't>(
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<AlignFlags, ParseError<'i>> {
|
) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
|
// NOTE Please also update the `list_legacy_keywords` function below
|
||||||
|
// when this function is updated.
|
||||||
Ok(try_match_ident_ignore_ascii_case! { input,
|
Ok(try_match_ident_ignore_ascii_case! { input,
|
||||||
"left" => AlignFlags::LEFT,
|
"left" => AlignFlags::LEFT,
|
||||||
"right" => AlignFlags::RIGHT,
|
"right" => AlignFlags::RIGHT,
|
||||||
|
@ -586,6 +705,8 @@ fn parse_left_right_center<'i, 't>(
|
||||||
|
|
||||||
// legacy | [ legacy && [ left | right | center ] ]
|
// legacy | [ legacy && [ left | right | center ] ]
|
||||||
fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
|
// NOTE Please also update the `list_legacy_keywords` function below
|
||||||
|
// when this function is updated.
|
||||||
let flags = try_match_ident_ignore_ascii_case! { input,
|
let flags = try_match_ident_ignore_ascii_case! { input,
|
||||||
"legacy" => {
|
"legacy" => {
|
||||||
let flags = input.try(parse_left_right_center)
|
let flags = input.try(parse_left_right_center)
|
||||||
|
@ -601,3 +722,7 @@ fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseE
|
||||||
input.expect_ident_matching("legacy")?;
|
input.expect_ident_matching("legacy")?;
|
||||||
Ok(AlignFlags::LEGACY | flags)
|
Ok(AlignFlags::LEGACY | flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn list_legacy_keywords(f: KeywordsCollectFn) {
|
||||||
|
f(&["legacy", "left", "right", "center"]);
|
||||||
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ use servo_url::ServoUrl;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::{CssType, CssWriter, ParseError, StyleParseErrorKind};
|
use style_traits::{CssType, CssWriter, KeywordsCollectFn, ParseError};
|
||||||
use style_traits::{SpecifiedValueInfo, ToCss};
|
use style_traits::{StyleParseErrorKind, SpecifiedValueInfo, ToCss};
|
||||||
use values::{Either, None_};
|
use values::{Either, None_};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use values::computed::{Context, Position as ComputedPosition, ToComputedValue};
|
use values::computed::{Context, Position as ComputedPosition, ToComputedValue};
|
||||||
|
@ -57,6 +57,25 @@ pub type Gradient = generic::Gradient<
|
||||||
|
|
||||||
impl SpecifiedValueInfo for Gradient {
|
impl SpecifiedValueInfo for Gradient {
|
||||||
const SUPPORTED_TYPES: u8 = CssType::GRADIENT;
|
const SUPPORTED_TYPES: u8 = CssType::GRADIENT;
|
||||||
|
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
// This list here should keep sync with that in Gradient::parse.
|
||||||
|
f(&[
|
||||||
|
"linear-gradient",
|
||||||
|
"-webkit-linear-gradient",
|
||||||
|
"-moz-linear-gradient",
|
||||||
|
"repeating-linear-gradient",
|
||||||
|
"-webkit-repeating-linear-gradient",
|
||||||
|
"-moz-repeating-linear-gradient",
|
||||||
|
"radial-gradient",
|
||||||
|
"-webkit-radial-gradient",
|
||||||
|
"-moz-radial-gradient",
|
||||||
|
"repeating-radial-gradient",
|
||||||
|
"-webkit-repeating-radial-gradient",
|
||||||
|
"-moz-repeating-radial-gradient",
|
||||||
|
"-webkit-gradient",
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A specified gradient kind.
|
/// A specified gradient kind.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
//! A list of common mouse cursors per CSS3-UI § 8.1.1.
|
//! A list of common mouse cursors per CSS3-UI § 8.1.1.
|
||||||
|
|
||||||
use super::{CssWriter, SpecifiedValueInfo, ToCss};
|
use super::{CssWriter, KeywordsCollectFn, SpecifiedValueInfo, ToCss};
|
||||||
|
|
||||||
macro_rules! define_cursor {
|
macro_rules! define_cursor {
|
||||||
(
|
(
|
||||||
|
@ -58,7 +58,14 @@ macro_rules! define_cursor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpecifiedValueInfo for CursorKind {}
|
impl SpecifiedValueInfo for CursorKind {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
f(&[
|
||||||
|
$($c_css,)+
|
||||||
|
$($g_css,)+
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue