style: implement -moz-inert CSS property.

-moz-inert CSS property reflects inert subtrees concept and can be used to implement HTML:dialog element and HTML:inert attribute

Differential Revision: https://phabricator.services.mozilla.com/D81701
This commit is contained in:
Alexander Surkov 2020-07-26 21:30:56 +00:00 committed by Emilio Cobos Álvarez
parent cd8c07abac
commit 32f92d18a8
6 changed files with 69 additions and 0 deletions

View file

@ -145,6 +145,9 @@ bitflags! {
/// ///
/// https://html.spec.whatwg.org/multipage/#centered-alignment /// https://html.spec.whatwg.org/multipage/#centered-alignment
const IN_MODAL_DIALOG_STATE = 1 << 53; const IN_MODAL_DIALOG_STATE = 1 << 53;
/// https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees
const IN_MOZINERT_STATE = 1 << 54;
} }
} }

View file

@ -48,6 +48,7 @@ macro_rules! apply_non_ts_list {
("-moz-drag-over", MozDragOver, IN_DRAGOVER_STATE, _), ("-moz-drag-over", MozDragOver, IN_DRAGOVER_STATE, _),
("target", Target, IN_TARGET_STATE, _), ("target", Target, IN_TARGET_STATE, _),
("indeterminate", Indeterminate, IN_INDETERMINATE_STATE, _), ("indeterminate", Indeterminate, IN_INDETERMINATE_STATE, _),
("-moz-inert", MozInert, IN_MOZINERT_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS),
("-moz-devtools-highlighted", MozDevtoolsHighlighted, IN_DEVTOOLS_HIGHLIGHTED_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), ("-moz-devtools-highlighted", MozDevtoolsHighlighted, IN_DEVTOOLS_HIGHLIGHTED_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS),
("-moz-styleeditor-transitioning", MozStyleeditorTransitioning, IN_STYLEEDITOR_TRANSITIONING_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), ("-moz-styleeditor-transitioning", MozStyleeditorTransitioning, IN_STYLEEDITOR_TRANSITIONING_STATE, PSEUDO_CLASS_ENABLED_IN_UA_SHEETS),
("fullscreen", Fullscreen, IN_FULLSCREEN_STATE, _), ("fullscreen", Fullscreen, IN_FULLSCREEN_STATE, _),

View file

@ -2022,6 +2022,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
NonTSPseudoClass::Checked | NonTSPseudoClass::Checked |
NonTSPseudoClass::Fullscreen | NonTSPseudoClass::Fullscreen |
NonTSPseudoClass::Indeterminate | NonTSPseudoClass::Indeterminate |
NonTSPseudoClass::MozInert |
NonTSPseudoClass::PlaceholderShown | NonTSPseudoClass::PlaceholderShown |
NonTSPseudoClass::Target | NonTSPseudoClass::Target |
NonTSPseudoClass::Valid | NonTSPseudoClass::Valid |

View file

@ -29,6 +29,17 @@ ${helpers.single_keyword(
gecko_enum_prefix="StylePointerEvents", gecko_enum_prefix="StylePointerEvents",
)} )}
${helpers.single_keyword(
"-moz-inert",
"none inert",
engines="gecko",
gecko_ffi_name="mInert",
gecko_enum_prefix="StyleInert",
animation_value_type="discrete",
enabled_in="ua",
spec="Nonstandard (https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees)",
)}
${helpers.single_keyword( ${helpers.single_keyword(
"-moz-user-input", "-moz-user-input",
"auto none", "auto none",

View file

@ -349,6 +349,7 @@ impl ToCss for NonTSPseudoClass {
Fullscreen => ":fullscreen", Fullscreen => ":fullscreen",
Hover => ":hover", Hover => ":hover",
Indeterminate => ":indeterminate", Indeterminate => ":indeterminate",
MozInert => ":-moz-inert",
Link => ":link", Link => ":link",
PlaceholderShown => ":placeholder-shown", PlaceholderShown => ":placeholder-shown",
ReadWrite => ":read-write", ReadWrite => ":read-write",
@ -438,6 +439,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
"fullscreen" => Fullscreen, "fullscreen" => Fullscreen,
"hover" => Hover, "hover" => Hover,
"indeterminate" => Indeterminate, "indeterminate" => Indeterminate,
"-moz-inert" => MozInert,
"link" => Link, "link" => Link,
"placeholder-shown" => PlaceholderShown, "placeholder-shown" => PlaceholderShown,
"read-write" => ReadWrite, "read-write" => ReadWrite,

View file

@ -153,6 +153,56 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
} }
} }
/// https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees
///
/// If -moz-inert is applied then add:
/// -moz-user-focus: none;
/// -moz-user-input: none;
/// -moz-user-modify: read-only;
/// user-select: none;
/// pointer-events: none;
/// cursor: default;
fn adjust_for_inert(&mut self) {
use properties::longhands::_moz_inert::computed_value::T as Inert;
use properties::longhands::_moz_user_focus::computed_value::T as UserFocus;
use properties::longhands::_moz_user_input::computed_value::T as UserInput;
use properties::longhands::_moz_user_modify::computed_value::T as UserModify;
use properties::longhands::pointer_events::computed_value::T as PointerEvents;
use properties::longhands::cursor::computed_value::T as Cursor;
use crate::values::specified::ui::CursorKind;
use crate::values::specified::ui::UserSelect;
let needs_update = {
let ui = self.style.get_inherited_ui();
if ui.clone__moz_inert() == Inert::None {
return;
}
ui.clone__moz_user_focus() != UserFocus::None ||
ui.clone__moz_user_input() != UserInput::None ||
ui.clone__moz_user_modify() != UserModify::ReadOnly ||
ui.clone_pointer_events() != PointerEvents::None ||
ui.clone_cursor().keyword != CursorKind::Default ||
ui.clone_cursor().images != Default::default()
};
if needs_update {
let ui = self.style.mutate_inherited_ui();
ui.set__moz_user_focus(UserFocus::None);
ui.set__moz_user_input(UserInput::None);
ui.set__moz_user_modify(UserModify::ReadOnly);
ui.set_pointer_events(PointerEvents::None);
ui.set_cursor(Cursor {
images: Default::default(),
keyword: CursorKind::Default,
});
}
if self.style.get_ui().clone_user_select() != UserSelect::None {
self.style.mutate_ui().set_user_select(UserSelect::None);
}
}
/// Whether we should skip any item-based display property blockification on /// Whether we should skip any item-based display property blockification on
/// this element. /// this element.
fn skip_item_display_fixup<E>(&self, element: Option<E>) -> bool fn skip_item_display_fixup<E>(&self, element: Option<E>) -> bool
@ -855,6 +905,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {
self.adjust_for_appearance(element); self.adjust_for_appearance(element);
self.adjust_for_inert();
} }
self.set_bits(); self.set_bits();
} }