Auto merge of #20065 - emilio:note-stuff, r=nox

style: Cleanup GeckoElement::note_explicit_hints

What it's doing is not so complicated.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20065)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-02-16 15:33:48 -05:00 committed by GitHub
commit d423e54d58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 42 deletions

View file

@ -692,33 +692,14 @@ impl<'le> GeckoElement<'le> {
unsafe { Gecko_GetDocumentLWTheme(node.owner_doc().0) }
}
/// Only safe to call on the main thread, with exclusive access to the element and
/// its ancestors.
/// This function is also called after display property changed for SMIL animation.
/// Only safe to call on the main thread, with exclusive access to the
/// element and its ancestors.
///
/// This function is also called after display property changed for SMIL
/// animation.
///
/// Also this function schedules style flush.
unsafe fn maybe_restyle<'a>(
&self,
data: &'a mut ElementData,
animation_only: bool,
) -> bool {
if !data.has_styles() {
return false;
}
// Propagate the bit up the chain.
if animation_only {
bindings::Gecko_NoteAnimationOnlyDirtyElement(self.0);
} else {
bindings::Gecko_NoteDirtyElement(self.0);
}
// Ensure and return the RestyleData.
true
}
/// Set restyle and change hints to the element data.
pub fn note_explicit_hints(
pub unsafe fn note_explicit_hints(
&self,
restyle_hint: nsRestyleHint,
change_hint: nsChangeHint,
@ -735,20 +716,25 @@ impl<'le> GeckoElement<'le> {
restyle_hint.has_non_animation_hint()),
"Animation restyle hints should not appear with non-animation restyle hints");
let mut maybe_data = self.mutate_data();
let should_restyle = maybe_data.as_mut().map_or(false, |d| unsafe {
self.maybe_restyle(d, restyle_hint.has_animation_hint())
});
if should_restyle {
maybe_data
.as_mut()
.unwrap()
.hint
.insert(restyle_hint.into());
maybe_data.as_mut().unwrap().damage |= damage;
let mut data = match self.mutate_data() {
Some(d) => d,
None => {
debug!("(Element not styled, discarding hints)");
return;
}
};
debug_assert!(data.has_styles(), "how?");
// Propagate the bit up the chain.
if restyle_hint.has_animation_hint() {
bindings::Gecko_NoteAnimationOnlyDirtyElement(self.0);
} else {
debug!("(Element not styled, discarding hints)");
bindings::Gecko_NoteDirtyElement(self.0);
}
data.hint.insert(restyle_hint);
data.damage |= damage;
}
/// This logic is duplicated in Gecko's nsIContent::IsRootOfAnonymousSubtree.
@ -1320,8 +1306,7 @@ impl<'le> TElement for GeckoElement<'le> {
}
/// Process various tasks that are a result of animation-only restyle.
fn process_post_animation(&self,
tasks: PostAnimationTasks) {
fn process_post_animation(&self, tasks: PostAnimationTasks) {
use gecko_bindings::structs::nsChangeHint_nsChangeHint_Empty;
use gecko_bindings::structs::nsRestyleHint_eRestyle_Subtree;
@ -1336,8 +1321,12 @@ impl<'le> TElement for GeckoElement<'le> {
.map_or(true, |p| !p.is_before_or_after()),
"display property animation shouldn't run on pseudo elements \
since it's only for SMIL");
self.note_explicit_hints(nsRestyleHint_eRestyle_Subtree,
nsChangeHint_nsChangeHint_Empty);
unsafe {
self.note_explicit_hints(
nsRestyleHint_eRestyle_Subtree,
nsChangeHint_nsChangeHint_Empty,
);
}
}
}

View file

@ -3565,7 +3565,7 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool {
}
#[no_mangle]
pub extern "C" fn Servo_NoteExplicitHints(
pub unsafe extern "C" fn Servo_NoteExplicitHints(
element: RawGeckoElementBorrowed,
restyle_hint: nsRestyleHint,
change_hint: nsChangeHint,