зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1241784 - Part 1: Add a helper function for Element.animate(). r=birtles
Therefore, CSSPseudoElement.animate() can also use it.
This commit is contained in:
Родитель
e64f114346
Коммит
c0917bf747
|
@ -137,13 +137,15 @@
|
|||
#include "nsITextControlElement.h"
|
||||
#include "nsITextControlFrame.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "mozilla/dom/CSSPseudoElement.h"
|
||||
#include "mozilla/dom/DocumentFragment.h"
|
||||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
#include "mozilla/dom/KeyframeEffectBinding.h"
|
||||
#include "mozilla/dom/WindowBinding.h"
|
||||
#include "mozilla/dom/ElementBinding.h"
|
||||
#include "mozilla/dom/VRDevice.h"
|
||||
#include "nsComputedDOMStyle.h"
|
||||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "nsComputedDOMStyle.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
@ -3307,7 +3309,31 @@ Element::Animate(JSContext* aContext,
|
|||
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
|
||||
ErrorResult& aError)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> ownerGlobal = GetOwnerGlobal();
|
||||
Nullable<ElementOrCSSPseudoElement> target;
|
||||
target.SetValue().SetAsElement() = this;
|
||||
return Animate(target, aContext, aFrames, aOptions, aError);
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<Animation>
|
||||
Element::Animate(const Nullable<ElementOrCSSPseudoElement>& aTarget,
|
||||
JSContext* aContext,
|
||||
JS::Handle<JSObject*> aFrames,
|
||||
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
|
||||
ErrorResult& aError)
|
||||
{
|
||||
MOZ_ASSERT(!aTarget.IsNull() &&
|
||||
(aTarget.Value().IsElement() ||
|
||||
aTarget.Value().IsCSSPseudoElement()),
|
||||
"aTarget should be initialized");
|
||||
|
||||
RefPtr<Element> referenceElement;
|
||||
if (aTarget.Value().IsElement()) {
|
||||
referenceElement = &aTarget.Value().GetAsElement();
|
||||
} else {
|
||||
referenceElement = aTarget.Value().GetAsCSSPseudoElement().ParentElement();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> ownerGlobal = referenceElement->GetOwnerGlobal();
|
||||
if (!ownerGlobal) {
|
||||
aError.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
|
@ -3327,17 +3353,16 @@ Element::Animate(JSContext* aContext,
|
|||
}
|
||||
}
|
||||
|
||||
Nullable<ElementOrCSSPseudoElement> target;
|
||||
target.SetValue().SetAsElement() = this;
|
||||
RefPtr<KeyframeEffect> effect =
|
||||
KeyframeEffect::Constructor(global, target, frames,
|
||||
TimingParams::FromOptionsUnion(aOptions, target), aError);
|
||||
KeyframeEffect::Constructor(global, aTarget, frames,
|
||||
TimingParams::FromOptionsUnion(aOptions, aTarget), aError);
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Animation> animation =
|
||||
Animation::Constructor(global, effect, OwnerDoc()->Timeline(), aError);
|
||||
Animation::Constructor(global, effect,
|
||||
referenceElement->OwnerDoc()->Timeline(), aError);
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/WindowBinding.h"
|
||||
#include "mozilla/dom/ElementBinding.h"
|
||||
#include "mozilla/dom/Nullable.h"
|
||||
#include "Units.h"
|
||||
|
||||
class nsIFrame;
|
||||
|
@ -56,6 +57,7 @@ namespace mozilla {
|
|||
namespace dom {
|
||||
struct ScrollIntoViewOptions;
|
||||
struct ScrollToOptions;
|
||||
class ElementOrCSSPseudoElement;
|
||||
class UnrestrictedDoubleOrKeyframeAnimationOptions;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -826,11 +828,20 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
already_AddRefed<Animation> Animate(
|
||||
JSContext* aContext,
|
||||
JS::Handle<JSObject*> aFrames,
|
||||
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
|
||||
ErrorResult& aError);
|
||||
already_AddRefed<Animation>
|
||||
Animate(JSContext* aContext,
|
||||
JS::Handle<JSObject*> aFrames,
|
||||
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
|
||||
ErrorResult& aError);
|
||||
|
||||
// A helper method that factors out the common functionality needed by
|
||||
// Element::Animate and CSSPseudoElement::Animate
|
||||
static already_AddRefed<Animation>
|
||||
Animate(const Nullable<ElementOrCSSPseudoElement>& aTarget,
|
||||
JSContext* aContext,
|
||||
JS::Handle<JSObject*> aFrames,
|
||||
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
|
||||
ErrorResult& aError);
|
||||
|
||||
// Note: GetAnimations will flush style while GetAnimationsUnsorted won't.
|
||||
void GetAnimations(nsTArray<RefPtr<Animation>>& aAnimations);
|
||||
|
|
Загрузка…
Ссылка в новой задаче