From fa27ac05445552425380ac76e6730e244d403fda Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Fri, 6 Jan 2017 21:16:39 +1100 Subject: [PATCH] Add function to convert NonTSPseudoClass to CSSPseudoClassType --- components/style/build_gecko.rs | 2 + components/style/gecko/selector_parser.rs | 21 +++++ .../style/gecko_bindings/structs_debug.rs | 87 +++++++++++++++++++ .../style/gecko_bindings/structs_release.rs | 87 +++++++++++++++++++ 4 files changed, 197 insertions(+) diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index 2eec1be1ce3..2b75121f1d0 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -254,6 +254,7 @@ mod bindings { "mozilla::ServoStyleSheet", "mozilla::ServoElementSnapshot.*", "mozilla::ConsumeStyleBehavior", + "mozilla::CSSPseudoClassType", "mozilla::css::SheetParsingMode", "mozilla::TraversalRootBehavior", "mozilla::DisplayItemClip", // Needed because bindgen generates @@ -472,6 +473,7 @@ mod bindings { "ThreadSafeURIHolder", "ThreadSafePrincipalHolder", "ConsumeStyleBehavior", + "CSSPseudoClassType", "TraversalRootBehavior", "FontFamilyList", "FontFamilyType", diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index 44ea037ef62..1c02ed98d28 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -6,6 +6,7 @@ use cssparser::ToCss; use element_state::ElementState; +use gecko_bindings::structs::CSSPseudoClassType; use selector_parser::{SelectorParser, PseudoElementCascadeType}; use selector_parser::{attr_equals_selector_is_shareable, attr_exists_selector_is_shareable}; use selectors::parser::AttrSelector; @@ -197,6 +198,26 @@ impl NonTSPseudoClass { Visited => ElementState::empty(), } } + + /// Convert NonTSPseudoClass to Gecko's CSSPseudoClassType. + pub fn to_gecko_pseudoclasstype(&self) -> Option { + use gecko_bindings::structs::CSSPseudoClassType::*; + use self::NonTSPseudoClass::*; + Some(match *self { + AnyLink => anyLink, + Link => link, + Visited => visited, + Active => active, + Focus => focus, + Fullscreen => fullscreen, + Hover => hover, + Enabled => enabled, + Disabled => disabled, + Checked => checked, + Indeterminate => indeterminate, + ReadWrite | ReadOnly => { return None; } + }) + } } /// The dummy struct we use to implement our selector parsing. diff --git a/components/style/gecko_bindings/structs_debug.rs b/components/style/gecko_bindings/structs_debug.rs index 25ed0cb366f..4c8b3956b93 100644 --- a/components/style/gecko_bindings/structs_debug.rs +++ b/components/style/gecko_bindings/structs_debug.rs @@ -3204,6 +3204,93 @@ pub mod root { root::mozilla::StyleShapeSource; pub type StyleShapeOutside = root::mozilla::StyleShapeSource; + #[repr(u8)] + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + pub enum CSSPseudoClassType { + empty = 0, + mozOnlyWhitespace = 1, + mozEmptyExceptChildrenWithLocalname = 2, + lang = 3, + mozBoundElement = 4, + root = 5, + any = 6, + firstChild = 7, + firstNode = 8, + lastChild = 9, + lastNode = 10, + onlyChild = 11, + firstOfType = 12, + lastOfType = 13, + onlyOfType = 14, + nthChild = 15, + nthLastChild = 16, + nthOfType = 17, + nthLastOfType = 18, + mozIsHTML = 19, + unresolved = 20, + mozNativeAnonymous = 21, + mozSystemMetric = 22, + mozLocaleDir = 23, + mozLWTheme = 24, + mozLWThemeBrightText = 25, + mozLWThemeDarkText = 26, + mozWindowInactive = 27, + mozTableBorderNonzero = 28, + mozBrowserFrame = 29, + scope = 30, + negation = 31, + dir = 32, + link = 33, + mozAnyLink = 34, + anyLink = 35, + visited = 36, + active = 37, + checked = 38, + disabled = 39, + enabled = 40, + focus = 41, + focusWithin = 42, + hover = 43, + mozDragOver = 44, + target = 45, + indeterminate = 46, + mozDevtoolsHighlighted = 47, + mozStyleeditorTransitioning = 48, + fullscreen = 49, + mozFullScreen = 50, + mozFocusRing = 51, + mozBroken = 52, + mozLoading = 53, + mozUserDisabled = 54, + mozSuppressed = 55, + mozHandlerClickToPlay = 56, + mozHandlerVulnerableUpdatable = 57, + mozHandlerVulnerableNoUpdate = 58, + mozHandlerDisabled = 59, + mozHandlerBlocked = 60, + mozHandlerCrashed = 61, + mozMathIncrementScriptLevel = 62, + required = 63, + optional = 64, + valid = 65, + invalid = 66, + inRange = 67, + outOfRange = 68, + defaultPseudo = 69, + placeholderShown = 70, + mozReadOnly = 71, + mozReadWrite = 72, + mozSubmitInvalid = 73, + mozUIInvalid = 74, + mozUIValid = 75, + mozMeterOptimum = 76, + mozMeterSubOptimum = 77, + mozMeterSubSubOptimum = 78, + mozPlaceholder = 79, + Count = 80, + NotPseudo = 81, + MAX = 82, + } #[test] fn __bindgen_test_layout_template_3() { assert_eq!(::std::mem::size_of::>() diff --git a/components/style/gecko_bindings/structs_release.rs b/components/style/gecko_bindings/structs_release.rs index 99e02860158..f226110a161 100644 --- a/components/style/gecko_bindings/structs_release.rs +++ b/components/style/gecko_bindings/structs_release.rs @@ -3186,6 +3186,93 @@ pub mod root { root::mozilla::StyleShapeSource; pub type StyleShapeOutside = root::mozilla::StyleShapeSource; + #[repr(u8)] + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + pub enum CSSPseudoClassType { + empty = 0, + mozOnlyWhitespace = 1, + mozEmptyExceptChildrenWithLocalname = 2, + lang = 3, + mozBoundElement = 4, + root = 5, + any = 6, + firstChild = 7, + firstNode = 8, + lastChild = 9, + lastNode = 10, + onlyChild = 11, + firstOfType = 12, + lastOfType = 13, + onlyOfType = 14, + nthChild = 15, + nthLastChild = 16, + nthOfType = 17, + nthLastOfType = 18, + mozIsHTML = 19, + unresolved = 20, + mozNativeAnonymous = 21, + mozSystemMetric = 22, + mozLocaleDir = 23, + mozLWTheme = 24, + mozLWThemeBrightText = 25, + mozLWThemeDarkText = 26, + mozWindowInactive = 27, + mozTableBorderNonzero = 28, + mozBrowserFrame = 29, + scope = 30, + negation = 31, + dir = 32, + link = 33, + mozAnyLink = 34, + anyLink = 35, + visited = 36, + active = 37, + checked = 38, + disabled = 39, + enabled = 40, + focus = 41, + focusWithin = 42, + hover = 43, + mozDragOver = 44, + target = 45, + indeterminate = 46, + mozDevtoolsHighlighted = 47, + mozStyleeditorTransitioning = 48, + fullscreen = 49, + mozFullScreen = 50, + mozFocusRing = 51, + mozBroken = 52, + mozLoading = 53, + mozUserDisabled = 54, + mozSuppressed = 55, + mozHandlerClickToPlay = 56, + mozHandlerVulnerableUpdatable = 57, + mozHandlerVulnerableNoUpdate = 58, + mozHandlerDisabled = 59, + mozHandlerBlocked = 60, + mozHandlerCrashed = 61, + mozMathIncrementScriptLevel = 62, + required = 63, + optional = 64, + valid = 65, + invalid = 66, + inRange = 67, + outOfRange = 68, + defaultPseudo = 69, + placeholderShown = 70, + mozReadOnly = 71, + mozReadWrite = 72, + mozSubmitInvalid = 73, + mozUIInvalid = 74, + mozUIValid = 75, + mozMeterOptimum = 76, + mozMeterSubOptimum = 77, + mozMeterSubSubOptimum = 78, + mozPlaceholder = 79, + Count = 80, + NotPseudo = 81, + MAX = 82, + } #[test] fn __bindgen_test_layout_template_3() { assert_eq!(::std::mem::size_of::>()