Format style component.

This commit is contained in:
chansuke 2018-09-09 16:24:45 +02:00 committed by Emilio Cobos Álvarez
parent 31fc6cd565
commit 8dab4d659a
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
120 changed files with 2207 additions and 1417 deletions

View file

@ -86,7 +86,6 @@ use std::ptr;
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
use stylist::CascadeData;
#[inline]
fn elements_with_id<'a, 'le>(
array: *const structs::nsTArray<*mut RawGeckoElement>,
@ -172,12 +171,11 @@ impl<'lr> TShadowRoot for GeckoShadowRoot<'lr> {
Self: 'a,
{
let author_styles = unsafe {
(self.0.mServoStyles.mPtr
as *const structs::RawServoAuthorStyles
as *const bindings::RawServoAuthorStyles).as_ref()?
(self.0.mServoStyles.mPtr as *const structs::RawServoAuthorStyles
as *const bindings::RawServoAuthorStyles)
.as_ref()?
};
let author_styles = AuthorStyles::<GeckoStyleSheet>::from_ffi(author_styles);
debug_assert!(
@ -375,7 +373,8 @@ impl<'ln> TNode for GeckoNode<'ln> {
fn first_child(&self) -> Option<Self> {
unsafe {
self.0
.mFirstChild.raw::<nsIContent>()
.mFirstChild
.raw::<nsIContent>()
.as_ref()
.map(GeckoNode::from_content)
}
@ -395,7 +394,8 @@ impl<'ln> TNode for GeckoNode<'ln> {
fn next_sibling(&self) -> Option<Self> {
unsafe {
self.0
.mNextSibling.raw::<nsIContent>()
.mNextSibling
.raw::<nsIContent>()
.as_ref()
.map(GeckoNode::from_content)
}
@ -600,7 +600,7 @@ impl<'le> GeckoElement<'le> {
if self.is_svg_element() {
let svg_class = unsafe { bindings::Gecko_GetSVGAnimatedClass(self.0).as_ref() };
if let Some(c) = svg_class {
return Some(c)
return Some(c);
}
}
@ -672,8 +672,7 @@ impl<'le> GeckoElement<'le> {
// For the bit usage, see nsContentSlots::GetExtendedSlots.
let e_slots = s._base.mExtendedSlots &
!structs::nsIContent_nsContentSlots_sNonOwningExtendedSlotsFlag;
(e_slots as *const structs::FragmentOrElement_nsExtendedDOMSlots)
.as_ref()
(e_slots as *const structs::FragmentOrElement_nsExtendedDOMSlots).as_ref()
})
}
@ -719,9 +718,8 @@ impl<'le> GeckoElement<'le> {
.and_then(|n| n.as_element());
debug_assert!(
binding_parent == unsafe {
bindings::Gecko_GetBindingParent(self.0).map(GeckoElement)
}
binding_parent ==
unsafe { bindings::Gecko_GetBindingParent(self.0).map(GeckoElement) }
);
binding_parent
}
@ -730,8 +728,9 @@ impl<'le> GeckoElement<'le> {
#[inline]
fn non_xul_xbl_binding_parent_raw_content(&self) -> *mut nsIContent {
debug_assert!(!self.is_xul_element());
self.extended_slots()
.map_or(ptr::null_mut(), |slots| slots._base.mBindingParent.raw::<nsIContent>())
self.extended_slots().map_or(ptr::null_mut(), |slots| {
slots._base.mBindingParent.raw::<nsIContent>()
})
}
#[inline]
@ -747,7 +746,8 @@ impl<'le> GeckoElement<'le> {
#[inline]
fn state_internal(&self) -> u64 {
if !self.as_node()
if !self
.as_node()
.get_bool_flag(nsINode_BooleanFlag::ElementHasLockedStyleStates)
{
return self.0.mState.mStates;
@ -878,9 +878,7 @@ impl<'le> GeckoElement<'le> {
return false;
}
match self.containing_shadow_host() {
Some(e) => {
e.is_svg_element() && e.local_name() == &*local_name!("use")
},
Some(e) => e.is_svg_element() && e.local_name() == &*local_name!("use"),
None => false,
}
}
@ -934,13 +932,12 @@ impl<'le> GeckoElement<'le> {
debug_assert_eq!(to.is_some(), from.is_some());
combined_duration > 0.0f32 && from != to &&
from.unwrap()
.animate(
to.as_ref().unwrap(),
Procedure::Interpolate { progress: 0.5 },
)
.is_ok()
combined_duration > 0.0f32 && from != to && from
.unwrap()
.animate(
to.as_ref().unwrap(),
Procedure::Interpolate { progress: 0.5 },
).is_ok()
}
}
@ -980,7 +977,9 @@ fn get_animation_rule(
let effect_count = unsafe { Gecko_GetAnimationEffectCount(element.0) };
// Also, we should try to reuse the PDB, to avoid creating extra rule nodes.
let mut animation_values = AnimationValueMap::with_capacity_and_hasher(
effect_count.min(ANIMATABLE_PROPERTY_COUNT), Default::default());
effect_count.min(ANIMATABLE_PROPERTY_COUNT),
Default::default(),
);
if unsafe {
Gecko_GetAnimationRule(
element.0,
@ -1084,10 +1083,12 @@ impl<'le> TElement for GeckoElement<'le> {
fn inheritance_parent(&self) -> Option<Self> {
if self.implemented_pseudo_element().is_some() {
return self.pseudo_element_originating_element()
return self.pseudo_element_originating_element();
}
self.as_node().flattened_tree_parent().and_then(|n| n.as_element())
self.as_node()
.flattened_tree_parent()
.and_then(|n| n.as_element())
}
fn traversal_children(&self) -> LayoutIterator<GeckoChildrenIterator<'le>> {
@ -1095,8 +1096,10 @@ impl<'le> TElement for GeckoElement<'le> {
// StyleChildrenIterator::IsNeeded does, except that it might return
// true if we used to (but no longer) have anonymous content from
// ::before/::after, XBL bindings, or nsIAnonymousContentCreators.
if self.is_in_anonymous_subtree() || self.has_xbl_binding_with_content() ||
self.is_html_slot_element() || self.shadow_root().is_some() ||
if self.is_in_anonymous_subtree() ||
self.has_xbl_binding_with_content() ||
self.is_html_slot_element() ||
self.shadow_root().is_some() ||
self.may_have_anonymous_children()
{
unsafe {
@ -1157,17 +1160,16 @@ impl<'le> TElement for GeckoElement<'le> {
// Bug 1466580 tracks running the Android layout tests on automation.
//
// The actual bindgen bug still needs reduction.
let assigned_nodes: &[structs::RefPtr<structs::nsINode>] =
if !cfg!(target_os = "android") {
debug_assert_eq!(
unsafe { bindings::Gecko_GetAssignedNodes(self.0) },
&slot.mAssignedNodes as *const _,
);
let assigned_nodes: &[structs::RefPtr<structs::nsINode>] = if !cfg!(target_os = "android") {
debug_assert_eq!(
unsafe { bindings::Gecko_GetAssignedNodes(self.0) },
&slot.mAssignedNodes as *const _,
);
&*slot.mAssignedNodes
} else {
unsafe { &**bindings::Gecko_GetAssignedNodes(self.0) }
};
&*slot.mAssignedNodes
} else {
unsafe { &**bindings::Gecko_GetAssignedNodes(self.0) }
};
debug_assert_eq!(
mem::size_of::<structs::RefPtr<structs::nsINode>>(),
@ -1239,11 +1241,10 @@ impl<'le> TElement for GeckoElement<'le> {
}
fn owner_doc_matches_for_testing(&self, device: &Device) -> bool {
self.as_node().owner_doc().0 as *const structs::nsIDocument ==
device
.pres_context()
.mDocument
.raw::<structs::nsIDocument>()
self.as_node().owner_doc().0 as *const structs::nsIDocument == device
.pres_context()
.mDocument
.raw::<structs::nsIDocument>()
}
fn style_attribute(&self) -> Option<ArcBorrow<Locked<PropertyDeclarationBlock>>> {
@ -1378,7 +1379,8 @@ impl<'le> TElement for GeckoElement<'le> {
self.unset_flags(
ELEMENT_HAS_DIRTY_DESCENDANTS_FOR_SERVO as u32 |
ELEMENT_HAS_ANIMATION_ONLY_DIRTY_DESCENDANTS_FOR_SERVO as u32 |
NODE_DESCENDANTS_NEED_FRAMES as u32 | NODE_NEEDS_FRAME as u32,
NODE_DESCENDANTS_NEED_FRAMES as u32 |
NODE_NEEDS_FRAME as u32,
)
}
@ -1438,8 +1440,10 @@ impl<'le> TElement for GeckoElement<'le> {
unsafe fn clear_data(&self) {
let ptr = self.0.mServoData.get();
self.unset_flags(
ELEMENT_HAS_SNAPSHOT as u32 | ELEMENT_HANDLED_SNAPSHOT as u32 |
structs::Element_kAllServoDescendantBits | NODE_NEEDS_FRAME as u32,
ELEMENT_HAS_SNAPSHOT as u32 |
ELEMENT_HANDLED_SNAPSHOT as u32 |
structs::Element_kAllServoDescendantBits |
NODE_NEEDS_FRAME as u32,
);
if !ptr.is_null() {
debug!("Dropping ElementData for {:?}", self);
@ -1668,8 +1672,7 @@ impl<'le> TElement for GeckoElement<'le> {
let transition_property: TransitionProperty = property.into();
let mut property_check_helper = |property: LonghandId| -> bool {
let property =
property.to_physical(after_change_style.writing_mode);
let property = property.to_physical(after_change_style.writing_mode);
transitions_to_keep.insert(property);
self.needs_transitions_update_per_property(
property,
@ -1681,8 +1684,7 @@ impl<'le> TElement for GeckoElement<'le> {
};
match transition_property {
TransitionProperty::Custom(..) |
TransitionProperty::Unsupported(..) => {},
TransitionProperty::Custom(..) | TransitionProperty::Unsupported(..) => {},
TransitionProperty::Shorthand(ref shorthand) => {
if shorthand.longhands().any(property_check_helper) {
return true;
@ -1713,11 +1715,7 @@ impl<'le> TElement for GeckoElement<'le> {
}
}
fn match_element_lang(
&self,
override_lang: Option<Option<AttrValue>>,
value: &Lang,
) -> bool {
fn match_element_lang(&self, override_lang: Option<Option<AttrValue>>, value: &Lang) -> bool {
// Gecko supports :lang() from CSS Selectors 3, which only accepts a
// single language tag, and which performs simple dash-prefix matching
// on it.
@ -1860,7 +1858,8 @@ impl<'le> TElement for GeckoElement<'le> {
));
}
let active = self.state()
let active = self
.state()
.intersects(NonTSPseudoClass::Active.state_flag());
if active {
let declarations = unsafe { Gecko_GetActiveLinkAttrDeclarationBlock(self.0) };
@ -2070,7 +2069,10 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
#[inline]
fn is_root(&self) -> bool {
if self.as_node().get_bool_flag(nsINode_BooleanFlag::ParentIsContent) {
if self
.as_node()
.get_bool_flag(nsINode_BooleanFlag::ParentIsContent)
{
return false;
}
@ -2078,12 +2080,17 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
return false;
}
debug_assert!(self.as_node().parent_node().map_or(false, |p| p.is_document()));
debug_assert!(
self.as_node()
.parent_node()
.map_or(false, |p| p.is_document())
);
unsafe { bindings::Gecko_IsRootElement(self.0) }
}
fn is_empty(&self) -> bool {
!self.as_node()
!self
.as_node()
.dom_children()
.any(|child| unsafe { Gecko_IsSignificantChild(child.0, true) })
}
@ -2194,7 +2201,8 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
},
NonTSPseudoClass::MozOnlyWhitespace => {
flags_setter(self, ElementSelectorFlags::HAS_EMPTY_SELECTOR);
if self.as_node()
if self
.as_node()
.dom_children()
.any(|c| c.contains_non_whitespace_content())
{
@ -2246,9 +2254,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
None => false,
}
},
NonTSPseudoClass::Dir(ref dir) => {
self.state().intersects(dir.element_state())
}
NonTSPseudoClass::Dir(ref dir) => self.state().intersects(dir.element_state()),
}
}