Skip to content

Commit

Permalink
Bug 1765550 - Move transitions and animations to nsStyleUIReset. r=dshin
Browse files Browse the repository at this point in the history
This mostly just moves code around, to minimize potential behavior
changes. There are some cleanups that we should try to do long term
(this "have an array with n different counts" is pretty weird).

But for now this should unblock people.

The destination struct (nsStyleUIReset) was chosen mainly because it's
small and non-inherited, and it doesn't seem like a worse place than
nsStyleDisplay.

Differential Revision: https://phabricator.services.mozilla.com/D144183
  • Loading branch information
emilio committed Apr 20, 2022
1 parent 78ac4ac commit d781272
Show file tree
Hide file tree
Showing 19 changed files with 1,009 additions and 1,019 deletions.
98 changes: 49 additions & 49 deletions devtools/shared/css/generated/properties-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2955,19 +2955,6 @@ exports.CSS_PROPERTIES = {
"overflow-x",
"overflow-y",
"overflow-anchor",
"transition-duration",
"transition-timing-function",
"transition-property",
"transition-delay",
"animation-name",
"animation-duration",
"animation-timing-function",
"animation-iteration-count",
"animation-direction",
"animation-play-state",
"animation-fill-mode",
"animation-delay",
"animation-timeline",
"transform",
"rotate",
"scale",
Expand Down Expand Up @@ -3222,6 +3209,19 @@ exports.CSS_PROPERTIES = {
"user-select",
"-moz-window-dragging",
"-moz-force-broken-image-icon",
"transition-duration",
"transition-timing-function",
"transition-property",
"transition-delay",
"animation-name",
"animation-duration",
"animation-timing-function",
"animation-iteration-count",
"animation-direction",
"animation-play-state",
"animation-fill-mode",
"animation-delay",
"animation-timeline",
"-moz-box-align",
"-moz-box-direction",
"-moz-box-flex",
Expand Down Expand Up @@ -11778,6 +11778,42 @@ exports.PREFERENCES = [
"zoom",
"layout.css.zoom-transform-hack.enabled"
],
[
"-moz-transform",
"layout.css.prefixes.transforms"
],
[
"-moz-perspective",
"layout.css.prefixes.transforms"
],
[
"-moz-perspective-origin",
"layout.css.prefixes.transforms"
],
[
"-moz-backface-visibility",
"layout.css.prefixes.transforms"
],
[
"-moz-transform-style",
"layout.css.prefixes.transforms"
],
[
"-moz-transform-origin",
"layout.css.prefixes.transforms"
],
[
"-moz-font-feature-settings",
"layout.css.prefixes.font-features"
],
[
"-moz-font-language-override",
"layout.css.prefixes.font-features"
],
[
"-moz-box-sizing",
"layout.css.prefixes.box-sizing"
],
[
"-moz-transition-duration",
"layout.css.prefixes.transitions"
Expand Down Expand Up @@ -11826,42 +11862,6 @@ exports.PREFERENCES = [
"-moz-animation-delay",
"layout.css.prefixes.animations"
],
[
"-moz-transform",
"layout.css.prefixes.transforms"
],
[
"-moz-perspective",
"layout.css.prefixes.transforms"
],
[
"-moz-perspective-origin",
"layout.css.prefixes.transforms"
],
[
"-moz-backface-visibility",
"layout.css.prefixes.transforms"
],
[
"-moz-transform-style",
"layout.css.prefixes.transforms"
],
[
"-moz-transform-origin",
"layout.css.prefixes.transforms"
],
[
"-moz-font-feature-settings",
"layout.css.prefixes.font-features"
],
[
"-moz-font-language-override",
"layout.css.prefixes.font-features"
],
[
"-moz-box-sizing",
"layout.css.prefixes.box-sizing"
],
[
"-moz-border-image",
"layout.css.prefixes.border-image"
Expand Down
66 changes: 26 additions & 40 deletions layout/style/nsAnimationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,15 @@
#include <algorithm> // std::stable_sort
#include <math.h>

namespace mozilla {
namespace dom {
struct ComputedEffectTiming;
struct EffectTiming;
struct OptionalEffectTiming;
} // namespace dom
} // namespace mozilla

using namespace mozilla;
using namespace mozilla::css;
using mozilla::dom::Animation;
using mozilla::dom::AnimationEffect;
using mozilla::dom::AnimationPlayState;
using mozilla::dom::ComputedEffectTiming;
using mozilla::dom::CSSAnimation;
using mozilla::dom::EffectTiming;
using mozilla::dom::Element;
using mozilla::dom::KeyframeEffect;
using mozilla::dom::MutationObservers;
using mozilla::dom::OptionalEffectTiming;
using mozilla::dom::ScrollTimeline;

////////////////////////// nsAnimationManager ////////////////////////////
Expand Down Expand Up @@ -255,31 +244,30 @@ static already_AddRefed<dom::AnimationTimeline> GetTimeline(
// with the new StyleAnimation.
static already_AddRefed<CSSAnimation> BuildAnimation(
nsPresContext* aPresContext, const NonOwningAnimationTarget& aTarget,
const nsStyleDisplay& aStyleDisplay, uint32_t animIdx,
const nsStyleUIReset& aStyle, uint32_t animIdx,
ServoCSSAnimationBuilder& aBuilder,
nsAnimationManager::CSSAnimationCollection* aCollection) {
MOZ_ASSERT(aPresContext);

nsAtom* animationName = aStyleDisplay.GetAnimationName(animIdx);
nsAtom* animationName = aStyle.GetAnimationName(animIdx);
nsTArray<Keyframe> keyframes;
if (!aBuilder.BuildKeyframes(
*aTarget.mElement, aPresContext, animationName,
aStyleDisplay.GetAnimationTimingFunction(animIdx), keyframes)) {
if (!aBuilder.BuildKeyframes(*aTarget.mElement, aPresContext, animationName,
aStyle.GetAnimationTimingFunction(animIdx),
keyframes)) {
return nullptr;
}

TimingParams timing = TimingParamsFromCSSParams(
aStyleDisplay.GetAnimationDuration(animIdx),
aStyleDisplay.GetAnimationDelay(animIdx),
aStyleDisplay.GetAnimationIterationCount(animIdx),
aStyleDisplay.GetAnimationDirection(animIdx),
aStyleDisplay.GetAnimationFillMode(animIdx));
aStyle.GetAnimationDuration(animIdx), aStyle.GetAnimationDelay(animIdx),
aStyle.GetAnimationIterationCount(animIdx),
aStyle.GetAnimationDirection(animIdx),
aStyle.GetAnimationFillMode(animIdx));

bool isStylePaused = aStyleDisplay.GetAnimationPlayState(animIdx) ==
StyleAnimationPlayState::Paused;
bool isStylePaused =
aStyle.GetAnimationPlayState(animIdx) == StyleAnimationPlayState::Paused;

RefPtr<dom::AnimationTimeline> timeline =
GetTimeline(aStyleDisplay.GetTimeline(animIdx), aPresContext, aTarget);
GetTimeline(aStyle.GetTimeline(animIdx), aPresContext, aTarget);

// Find the matching animation with animation name in the old list
// of animations and remove the matched animation from the list.
Expand Down Expand Up @@ -330,13 +318,13 @@ static already_AddRefed<CSSAnimation> BuildAnimation(

static nsAnimationManager::OwningCSSAnimationPtrArray BuildAnimations(
nsPresContext* aPresContext, const NonOwningAnimationTarget& aTarget,
const nsStyleDisplay& aStyleDisplay, ServoCSSAnimationBuilder& aBuilder,
const nsStyleUIReset& aStyle, ServoCSSAnimationBuilder& aBuilder,
nsAnimationManager::CSSAnimationCollection* aCollection,
nsTHashSet<RefPtr<nsAtom>>& aReferencedAnimations) {
nsAnimationManager::OwningCSSAnimationPtrArray result;

for (size_t animIdx = aStyleDisplay.mAnimationNameCount; animIdx-- != 0;) {
nsAtom* name = aStyleDisplay.GetAnimationName(animIdx);
for (size_t animIdx = aStyle.mAnimationNameCount; animIdx-- != 0;) {
nsAtom* name = aStyle.GetAnimationName(animIdx);
// CSS Animations whose animation-name does not match a @keyframes rule do
// not generate animation events. This includes when the animation-name is
// "none" which is represented by an empty name in the StyleAnimation.
Expand All @@ -347,8 +335,8 @@ static nsAnimationManager::OwningCSSAnimationPtrArray BuildAnimations(
}

aReferencedAnimations.Insert(name);
RefPtr<CSSAnimation> dest = BuildAnimation(
aPresContext, aTarget, aStyleDisplay, animIdx, aBuilder, aCollection);
RefPtr<CSSAnimation> dest = BuildAnimation(aPresContext, aTarget, aStyle,
animIdx, aBuilder, aCollection);
if (!dest) {
continue;
}
Expand All @@ -368,10 +356,8 @@ void nsAnimationManager::UpdateAnimations(dom::Element* aElement,
"Should not update animations that are not attached to the "
"document tree");

const nsStyleDisplay* disp =
aComputedStyle ? aComputedStyle->StyleDisplay() : nullptr;

if (!disp || disp->mDisplay == StyleDisplay::None) {
if (!aComputedStyle ||
aComputedStyle->StyleDisplay()->mDisplay == StyleDisplay::None) {
// If we are in a display:none subtree we will have no computed values.
// However, if we are on the root of display:none subtree, the computed
// values might not have been cleared yet.
Expand All @@ -385,12 +371,12 @@ void nsAnimationManager::UpdateAnimations(dom::Element* aElement,
NonOwningAnimationTarget target(aElement, aPseudoType);
ServoCSSAnimationBuilder builder(aComputedStyle);

DoUpdateAnimations(target, *disp, builder);
DoUpdateAnimations(target, *aComputedStyle->StyleUIReset(), builder);
}

void nsAnimationManager::DoUpdateAnimations(
const NonOwningAnimationTarget& aTarget,
const nsStyleDisplay& aStyleDisplay, ServoCSSAnimationBuilder& aBuilder) {
const NonOwningAnimationTarget& aTarget, const nsStyleUIReset& aStyle,
ServoCSSAnimationBuilder& aBuilder) {
// Everything that causes our animation data to change triggers a
// style change, which in turn triggers a non-animation restyle.
// Likewise, when we initially construct frames, we're not in a
Expand All @@ -399,8 +385,8 @@ void nsAnimationManager::DoUpdateAnimations(
CSSAnimationCollection* collection =
CSSAnimationCollection::GetAnimationCollection(aTarget.mElement,
aTarget.mPseudoType);
if (!collection && aStyleDisplay.mAnimationNameCount == 1 &&
aStyleDisplay.mAnimations[0].GetName() == nsGkAtoms::_empty) {
if (!collection && aStyle.mAnimationNameCount == 1 &&
aStyle.mAnimations[0].GetName() == nsGkAtoms::_empty) {
return;
}

Expand All @@ -409,8 +395,8 @@ void nsAnimationManager::DoUpdateAnimations(
// Build the updated animations list, extracting matching animations from
// the existing collection as we go.
OwningCSSAnimationPtrArray newAnimations =
BuildAnimations(mPresContext, aTarget, aStyleDisplay, aBuilder,
collection, mMaybeReferencedAnimations);
BuildAnimations(mPresContext, aTarget, aStyle, aBuilder, collection,
mMaybeReferencedAnimations);

if (newAnimations.IsEmpty()) {
if (collection) {
Expand Down
5 changes: 3 additions & 2 deletions layout/style/nsAnimationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
#include "nsISupportsImpl.h"
#include "nsTHashSet.h"

struct nsStyleDisplay;
class ServoCSSAnimationBuilder;

struct nsStyleUIReset;

namespace mozilla {
class ComputedStyle;

Expand Down Expand Up @@ -91,7 +92,7 @@ class nsAnimationManager final
nsTHashSet<RefPtr<nsAtom>> mMaybeReferencedAnimations;

void DoUpdateAnimations(const mozilla::NonOwningAnimationTarget& aTarget,
const nsStyleDisplay& aStyleDisplay,
const nsStyleUIReset& aStyle,
ServoCSSAnimationBuilder& aBuilder);
};

Expand Down
Loading

0 comments on commit d781272

Please sign in to comment.