mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Add a ValueInfo trait for exposing types needed by devtools.
Most of types just derive it using proc_macro directly. Some of value types need manual impl. In my current plan, this new trait will be used in bug 1434130 to expose values as well. Bug: 1455576 Reviewed-by: emilio MozReview-Commit-ID: LI7fy45VkRw
This commit is contained in:
parent
276fb7e04b
commit
7fe7b2ffb1
66 changed files with 615 additions and 249 deletions
|
@ -42,7 +42,8 @@ use selector_parser::PseudoElement;
|
|||
use selectors::parser::SelectorParseErrorKind;
|
||||
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
||||
use shared_lock::StylesheetGuards;
|
||||
use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCss};
|
||||
use style_traits::{CssWriter, ParseError, ParsingMode};
|
||||
use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
||||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
#[cfg(feature = "servo")] use values::Either;
|
||||
use values::generics::text::LineHeight;
|
||||
|
@ -541,6 +542,24 @@ impl NonCustomPropertyId {
|
|||
|
||||
false
|
||||
}
|
||||
|
||||
/// The supported types of this property. The return value should be
|
||||
/// style_traits::CssType when it can become a bitflags type.
|
||||
fn supported_types(&self) -> u8 {
|
||||
const SUPPORTED_TYPES: [u8; ${len(data.longhands) + len(data.shorthands)}] = [
|
||||
% for prop in data.longhands:
|
||||
<${prop.specified_type()} as SpecifiedValueInfo>::SUPPORTED_TYPES,
|
||||
% endfor
|
||||
% for prop in data.shorthands:
|
||||
% if prop.name == "all":
|
||||
0, // 'all' accepts no value other than CSS-wide keywords
|
||||
% else:
|
||||
<shorthands::${prop.ident}::Longhands as SpecifiedValueInfo>::SUPPORTED_TYPES,
|
||||
% endif
|
||||
% endfor
|
||||
];
|
||||
SUPPORTED_TYPES[self.0]
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LonghandId> for NonCustomPropertyId {
|
||||
|
@ -1713,6 +1732,19 @@ impl PropertyId {
|
|||
};
|
||||
id.allowed_in(context)
|
||||
}
|
||||
|
||||
/// Whether the property supports the given CSS type.
|
||||
/// `ty` should a bitflags of constants in style_traits::CssType.
|
||||
pub fn supports_type(&self, ty: u8) -> bool {
|
||||
let non_custom_id: NonCustomPropertyId = match *self {
|
||||
PropertyId::Custom(_) => return false,
|
||||
PropertyId::Shorthand(id) => id.into(),
|
||||
PropertyId::Longhand(id) => id.into(),
|
||||
PropertyId::ShorthandAlias(id, _) => id.into(),
|
||||
PropertyId::LonghandAlias(id, _) => id.into(),
|
||||
};
|
||||
non_custom_id.supported_types() & ty != 0
|
||||
}
|
||||
}
|
||||
|
||||
/// A declaration using a CSS-wide keyword.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue