mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
style: Make Servo deal with CSS property prefs more correctly.
Right now you could still set preffed-off properties from CSSStyleDeclaration.
This commit is contained in:
parent
030509e66b
commit
650e947c94
4 changed files with 54 additions and 16 deletions
|
@ -164,9 +164,17 @@ macro_rules! css_properties(
|
||||||
( $([$getter:ident, $setter:ident, $id:expr],)* ) => (
|
( $([$getter:ident, $setter:ident, $id:expr],)* ) => (
|
||||||
$(
|
$(
|
||||||
fn $getter(&self) -> DOMString {
|
fn $getter(&self) -> DOMString {
|
||||||
|
debug_assert!(
|
||||||
|
$id.enabled_for_all_content(),
|
||||||
|
"Someone forgot a #[Pref] annotation"
|
||||||
|
);
|
||||||
self.get_property_value($id)
|
self.get_property_value($id)
|
||||||
}
|
}
|
||||||
fn $setter(&self, value: DOMString) -> ErrorResult {
|
fn $setter(&self, value: DOMString) -> ErrorResult {
|
||||||
|
debug_assert!(
|
||||||
|
$id.enabled_for_all_content(),
|
||||||
|
"Someone forgot a #[Pref] annotation"
|
||||||
|
);
|
||||||
self.set_property($id, value, DOMString::new())
|
self.set_property($id, value, DOMString::new())
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
|
@ -238,6 +246,10 @@ impl CSSStyleDeclaration {
|
||||||
return Err(Error::NoModificationAllowed);
|
return Err(Error::NoModificationAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !id.enabled_for_all_content() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
self.owner.mutate_associated_block(|pdb, changed| {
|
self.owner.mutate_associated_block(|pdb, changed| {
|
||||||
if value.is_empty() {
|
if value.is_empty() {
|
||||||
// Step 3
|
// Step 3
|
||||||
|
|
|
@ -244,8 +244,10 @@ partial interface CSSStyleDeclaration {
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString whiteSpace;
|
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString whiteSpace;
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString white-space;
|
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString white-space;
|
||||||
|
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString writingMode;
|
[Pref="layout.writing-mode.enabled", CEReactions, SetterThrows, TreatNullAs=EmptyString]
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString writing-mode;
|
attribute DOMString writingMode;
|
||||||
|
[Pref="layout.writing-mode.enabled", CEReactions, SetterThrows, TreatNullAs=EmptyString]
|
||||||
|
attribute DOMString writing-mode;
|
||||||
|
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString letterSpacing;
|
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString letterSpacing;
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString letter-spacing;
|
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString letter-spacing;
|
||||||
|
@ -385,13 +387,20 @@ partial interface CSSStyleDeclaration {
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString imageRendering;
|
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString imageRendering;
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString image-rendering;
|
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString image-rendering;
|
||||||
|
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString columnCount;
|
[Pref="layout.column-count.enabled", CEReactions, SetterThrows, TreatNullAs=EmptyString]
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString column-count;
|
attribute DOMString columnCount;
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString columnWidth;
|
[Pref="layout.column-count.enabled", CEReactions, SetterThrows, TreatNullAs=EmptyString]
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString column-width;
|
attribute DOMString column-count;
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString columns;
|
[Pref="layout.column-width.enabled", CEReactions, SetterThrows, TreatNullAs=EmptyString]
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString columnGap;
|
attribute DOMString columnWidth;
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString column-gap;
|
[Pref="layout.column-width.enabled", CEReactions, SetterThrows, TreatNullAs=EmptyString]
|
||||||
|
attribute DOMString column-width;
|
||||||
|
[Pref="layout.columns.enabled", CEReactions, SetterThrows, TreatNullAs=EmptyString]
|
||||||
|
attribute DOMString columns;
|
||||||
|
[Pref="layout.column-gap.enabled", CEReactions, SetterThrows, TreatNullAs=EmptyString]
|
||||||
|
attribute DOMString columnGap;
|
||||||
|
[Pref="layout.column-gap.enabled", CEReactions, SetterThrows, TreatNullAs=EmptyString]
|
||||||
|
attribute DOMString column-gap;
|
||||||
|
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString transition;
|
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString transition;
|
||||||
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString transitionDuration;
|
[CEReactions, SetterThrows, TreatNullAs=EmptyString] attribute DOMString transitionDuration;
|
||||||
|
|
|
@ -1626,16 +1626,35 @@ impl PropertyId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn allowed_in(&self, context: &ParserContext) -> bool {
|
fn non_custom_id(&self) -> Option<NonCustomPropertyId> {
|
||||||
let id: NonCustomPropertyId = match *self {
|
Some(match *self {
|
||||||
// Custom properties are allowed everywhere
|
PropertyId::Custom(_) => return None,
|
||||||
PropertyId::Custom(_) => return true,
|
|
||||||
PropertyId::Shorthand(shorthand_id) => shorthand_id.into(),
|
PropertyId::Shorthand(shorthand_id) => shorthand_id.into(),
|
||||||
PropertyId::Longhand(longhand_id) => longhand_id.into(),
|
PropertyId::Longhand(longhand_id) => longhand_id.into(),
|
||||||
PropertyId::ShorthandAlias(_, alias_id) => alias_id.into(),
|
PropertyId::ShorthandAlias(_, alias_id) => alias_id.into(),
|
||||||
PropertyId::LonghandAlias(_, alias_id) => alias_id.into(),
|
PropertyId::LonghandAlias(_, alias_id) => alias_id.into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the property is enabled for all content regardless of the
|
||||||
|
/// stylesheet it was declared on (that is, in practice only checks prefs).
|
||||||
|
#[inline]
|
||||||
|
pub fn enabled_for_all_content(&self) -> bool {
|
||||||
|
let id = match self.non_custom_id() {
|
||||||
|
// Custom properties are allowed everywhere
|
||||||
|
None => return true,
|
||||||
|
Some(id) => id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
id.enabled_for_all_content()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn allowed_in(&self, context: &ParserContext) -> bool {
|
||||||
|
let id = match self.non_custom_id() {
|
||||||
|
// Custom properties are allowed everywhere
|
||||||
|
None => return true,
|
||||||
|
Some(id) => id,
|
||||||
|
};
|
||||||
id.allowed_in(context)
|
id.allowed_in(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3818,8 +3837,7 @@ impl fmt::Debug for AliasId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(emilio): This macro doesn't account for experimental properties, so
|
// NOTE(emilio): Callers are responsible to deal with prefs.
|
||||||
// even with the pref disabled you can set them from CSSOM in Servo.
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! css_properties_accessors {
|
macro_rules! css_properties_accessors {
|
||||||
($macro_name: ident) => {
|
($macro_name: ident) => {
|
||||||
|
|
|
@ -61,7 +61,6 @@
|
||||||
"layout.column-gap.enabled": false,
|
"layout.column-gap.enabled": false,
|
||||||
"layout.column-width.enabled": false,
|
"layout.column-width.enabled": false,
|
||||||
"layout.columns.enabled": false,
|
"layout.columns.enabled": false,
|
||||||
"layout.text-orientation.enabled": false,
|
|
||||||
"layout.viewport.enabled": false,
|
"layout.viewport.enabled": false,
|
||||||
"layout.writing-mode.enabled": false,
|
"layout.writing-mode.enabled": false,
|
||||||
"network.http-cache.disabled": false,
|
"network.http-cache.disabled": false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue