2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-04-12 10:18:44 +04:00
|
|
|
#ifndef nsAnimationManager_h_
|
|
|
|
#define nsAnimationManager_h_
|
|
|
|
|
2012-09-14 20:10:08 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-04-12 10:18:44 +04:00
|
|
|
#include "AnimationCommon.h"
|
2020-05-06 01:41:04 +03:00
|
|
|
#include "mozilla/dom/CSSAnimation.h"
|
2017-05-13 10:34:38 +03:00
|
|
|
#include "mozilla/Keyframe.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2018-01-27 15:17:27 +03:00
|
|
|
#include "nsISupportsImpl.h"
|
2021-03-24 20:56:46 +03:00
|
|
|
#include "nsTHashSet.h"
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2018-04-09 14:16:00 +03:00
|
|
|
class ServoCSSAnimationBuilder;
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2022-04-20 18:13:54 +03:00
|
|
|
struct nsStyleUIReset;
|
|
|
|
|
2011-04-12 10:18:44 +04:00
|
|
|
namespace mozilla {
|
2018-03-22 21:20:41 +03:00
|
|
|
class ComputedStyle;
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
enum class PseudoStyleType : uint8_t;
|
2017-07-21 06:42:42 +03:00
|
|
|
struct NonOwningAnimationTarget;
|
2017-07-20 16:41:12 +03:00
|
|
|
|
2014-10-20 08:55:46 +04:00
|
|
|
} /* namespace mozilla */
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsAnimationManager final
|
2018-01-27 15:17:27 +03:00
|
|
|
: public mozilla::CommonAnimationManager<mozilla::dom::CSSAnimation> {
|
2011-04-12 10:18:44 +04:00
|
|
|
public:
|
2014-08-20 08:58:22 +04:00
|
|
|
explicit nsAnimationManager(nsPresContext* aPresContext)
|
2018-01-27 15:17:27 +03:00
|
|
|
: mozilla::CommonAnimationManager<mozilla::dom::CSSAnimation>(
|
|
|
|
aPresContext) {}
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2016-03-09 06:55:39 +03:00
|
|
|
typedef mozilla::AnimationCollection<mozilla::dom::CSSAnimation>
|
|
|
|
CSSAnimationCollection;
|
|
|
|
typedef nsTArray<RefPtr<mozilla::dom::CSSAnimation>>
|
|
|
|
OwningCSSAnimationPtrArray;
|
|
|
|
|
2018-04-17 01:28:00 +03:00
|
|
|
~nsAnimationManager() override = default;
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2017-03-06 03:54:06 +03:00
|
|
|
/**
|
|
|
|
* This function does the same thing as the above UpdateAnimations()
|
|
|
|
* but with servo's computed values.
|
|
|
|
*/
|
|
|
|
void UpdateAnimations(mozilla::dom::Element* aElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
mozilla::PseudoStyleType aPseudoType,
|
2018-03-22 21:20:41 +03:00
|
|
|
const mozilla::ComputedStyle* aComputedValues);
|
2018-04-17 01:28:00 +03:00
|
|
|
|
2017-05-13 10:34:38 +03:00
|
|
|
// Utility function to walk through |aIter| to find the Keyframe with
|
|
|
|
// matching offset and timing function but stopping as soon as the offset
|
|
|
|
// differs from |aOffset| (i.e. it assumes a sorted iterator).
|
|
|
|
//
|
|
|
|
// If a matching Keyframe is found,
|
|
|
|
// Returns true and sets |aIndex| to the index of the matching Keyframe
|
|
|
|
// within |aIter|.
|
|
|
|
//
|
|
|
|
// If no matching Keyframe is found,
|
|
|
|
// Returns false and sets |aIndex| to the index in the iterator of the
|
|
|
|
// first Keyframe with an offset differing to |aOffset| or, if the end
|
|
|
|
// of the iterator is reached, sets |aIndex| to the index after the last
|
|
|
|
// Keyframe.
|
|
|
|
template <class IterType, class TimingFunctionType>
|
|
|
|
static bool FindMatchingKeyframe(
|
|
|
|
IterType&& aIter, double aOffset,
|
|
|
|
const TimingFunctionType& aTimingFunctionToMatch, size_t& aIndex) {
|
|
|
|
aIndex = 0;
|
|
|
|
for (mozilla::Keyframe& keyframe : aIter) {
|
|
|
|
if (keyframe.mOffset.value() != aOffset) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (keyframe.mTimingFunction == aTimingFunctionToMatch) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
++aIndex;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-02 14:15:59 +03:00
|
|
|
bool AnimationMayBeReferenced(nsAtom* aName) const {
|
|
|
|
return mMaybeReferencedAnimations.Contains(aName);
|
|
|
|
}
|
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
private:
|
2018-02-02 14:15:59 +03:00
|
|
|
// This includes all animation names referenced regardless of whether a
|
|
|
|
// corresponding `@keyframes` rule is available.
|
|
|
|
//
|
|
|
|
// It may contain names which are no longer referenced, but it should always
|
|
|
|
// contain names which are currently referenced, so that it is usable for
|
|
|
|
// style invalidation.
|
2021-03-24 20:56:46 +03:00
|
|
|
nsTHashSet<RefPtr<nsAtom>> mMaybeReferencedAnimations;
|
2018-02-02 14:15:59 +03:00
|
|
|
|
2017-03-06 03:50:09 +03:00
|
|
|
void DoUpdateAnimations(const mozilla::NonOwningAnimationTarget& aTarget,
|
2022-04-20 18:13:54 +03:00
|
|
|
const nsStyleUIReset& aStyle,
|
2018-04-09 14:16:00 +03:00
|
|
|
ServoCSSAnimationBuilder& aBuilder);
|
2011-04-12 10:18:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined(nsAnimationManager_h_) */
|