servo: Merge #14878 - stylo: Add :-moz-browser-frame pseudo-class (from upsuper:bug1329076); r=heycam

This is the servo part of [bug 1329076](https://bugzilla.mozilla.org/show_bug.cgi?id=1329076) which has been reviewed by @heycam.

Note that it adds some documents on top of the patches on MozReview.

r? @heycam

Source-Repo: https://github.com/servo/servo
Source-Revision: 540efc3e8819f127b18b5ea8d85da6d8282a52be
This commit is contained in:
Xidorn Quan 2017-01-06 02:35:42 -08:00
Родитель df3cfd5bdf
Коммит f6c20ab641
6 изменённых файлов: 247 добавлений и 3 удалений

Просмотреть файл

@ -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",

Просмотреть файл

@ -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;
@ -153,6 +154,10 @@ pub enum NonTSPseudoClass {
ReadWrite,
/// :read-only
ReadOnly,
// Internal pseudo-classes
/// :-moz-browser-frame
MozBrowserFrame,
}
impl ToCss for NonTSPseudoClass {
@ -172,11 +177,35 @@ impl ToCss for NonTSPseudoClass {
Indeterminate => ":indeterminate",
ReadWrite => ":read-write",
ReadOnly => ":read-only",
MozBrowserFrame => ":-moz-browser-frame",
})
}
}
impl NonTSPseudoClass {
/// A pseudo-class is internal if it can only be used inside
/// user agent style sheets.
pub fn is_internal(&self) -> bool {
use self::NonTSPseudoClass::*;
match *self {
AnyLink |
Link |
Visited |
Active |
Focus |
Fullscreen |
Hover |
Enabled |
Disabled |
Checked |
Indeterminate |
ReadWrite |
ReadOnly => false,
MozBrowserFrame => true,
}
}
/// Get the state flag associated with a pseudo-class, if any.
pub fn state_flag(&self) -> ElementState {
use element_state::*;
@ -194,9 +223,31 @@ impl NonTSPseudoClass {
AnyLink |
Link |
Visited => ElementState::empty(),
Visited |
MozBrowserFrame => ElementState::empty(),
}
}
/// Convert NonTSPseudoClass to Gecko's CSSPseudoClassType.
pub fn to_gecko_pseudoclasstype(&self) -> Option<CSSPseudoClassType> {
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,
MozBrowserFrame => mozBrowserFrame,
ReadWrite | ReadOnly => { return None; }
})
}
}
/// The dummy struct we use to implement our selector parsing.
@ -245,10 +296,18 @@ impl<'a> ::selectors::Parser for SelectorParser<'a> {
"indeterminate" => Indeterminate,
"read-write" => ReadWrite,
"read-only" => ReadOnly,
// Internal
"-moz-browser-frame" => MozBrowserFrame,
_ => return Err(())
};
if !pseudo_class.is_internal() || self.in_user_agent_stylesheet() {
Ok(pseudo_class)
} else {
Err(())
}
}
fn parse_pseudo_element(&self, name: Cow<str>) -> Result<PseudoElement, ()> {

Просмотреть файл

@ -26,7 +26,7 @@ use gecko_bindings::bindings;
use gecko_bindings::bindings::{Gecko_DropStyleChildrenIterator, Gecko_MaybeCreateStyleChildrenIterator};
use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetLastChild, Gecko_GetNextStyleChild};
use gecko_bindings::bindings::{Gecko_GetServoDeclarationBlock, Gecko_IsHTMLElementInHTMLDocument};
use gecko_bindings::bindings::{Gecko_IsLink, Gecko_IsRootElement};
use gecko_bindings::bindings::{Gecko_IsLink, Gecko_IsRootElement, Gecko_MatchesElement};
use gecko_bindings::bindings::{Gecko_IsUnvisitedLink, Gecko_IsVisitedLink, Gecko_Namespace};
use gecko_bindings::bindings::{Gecko_SetNodeFlags, Gecko_UnsetNodeFlags};
use gecko_bindings::bindings::Gecko_ClassOrClassList;
@ -519,6 +519,10 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
NonTSPseudoClass::ReadOnly => {
!self.get_state().contains(pseudo_class.state_flag())
}
NonTSPseudoClass::MozBrowserFrame => unsafe {
Gecko_MatchesElement(pseudo_class.to_gecko_pseudoclasstype().unwrap(), self.0)
}
}
}

Просмотреть файл

@ -10,6 +10,7 @@ use gecko_bindings::structs::RawGeckoPresContext;
use gecko_bindings::structs::ThreadSafeURIHolder;
use gecko_bindings::structs::ThreadSafePrincipalHolder;
use gecko_bindings::structs::ConsumeStyleBehavior;
use gecko_bindings::structs::CSSPseudoClassType;
use gecko_bindings::structs::TraversalRootBehavior;
use gecko_bindings::structs::FontFamilyList;
use gecko_bindings::structs::FontFamilyType;
@ -370,6 +371,10 @@ extern "C" {
extern "C" {
pub fn Gecko_IsRootElement(element: RawGeckoElementBorrowed) -> bool;
}
extern "C" {
pub fn Gecko_MatchesElement(type_: CSSPseudoClassType,
element: RawGeckoElementBorrowed) -> bool;
}
extern "C" {
pub fn Gecko_LocalName(element: RawGeckoElementBorrowed) -> *mut nsIAtom;
}

Просмотреть файл

@ -3204,6 +3204,93 @@ pub mod root {
root::mozilla::StyleShapeSource<root::mozilla::StyleGeometryBox>;
pub type StyleShapeOutside =
root::mozilla::StyleShapeSource<root::mozilla::StyleShapeOutsideShapeBox>;
#[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::<root::mozilla::StyleShapeSource<root::mozilla::StyleGeometryBox>>()

Просмотреть файл

@ -3186,6 +3186,93 @@ pub mod root {
root::mozilla::StyleShapeSource<root::mozilla::StyleGeometryBox>;
pub type StyleShapeOutside =
root::mozilla::StyleShapeSource<root::mozilla::StyleShapeOutsideShapeBox>;
#[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::<root::mozilla::StyleShapeSource<root::mozilla::StyleGeometryBox>>()