2017-10-27 01:08:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2016-03-22 10:20:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/KeyframeUtils.h"
|
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include <algorithm> // For std::stable_sort, std::min
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "jsapi.h" // For most JSAPI
|
2021-07-13 14:52:42 +03:00
|
|
|
#include "js/ForOfIterator.h" // For JS::ForOfIterator
|
|
|
|
#include "js/PropertyAndElement.h" // JS_Enumerate, JS_GetProperty, JS_GetPropertyById
|
2018-03-22 21:20:41 +03:00
|
|
|
#include "mozilla/ComputedStyle.h"
|
2016-03-22 10:20:37 +03:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2016-09-04 10:34:21 +03:00
|
|
|
#include "mozilla/RangedArray.h"
|
2016-12-01 04:34:54 +03:00
|
|
|
#include "mozilla/ServoBindingTypes.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2017-12-01 12:35:47 +03:00
|
|
|
#include "mozilla/ServoCSSParser.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_dom.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/StyleAnimationValue.h"
|
2016-03-22 10:20:37 +03:00
|
|
|
#include "mozilla/TimingParams.h"
|
|
|
|
#include "mozilla/dom/BaseKeyframeTypesBinding.h" // For FastBaseKeyframe etc.
|
2020-03-07 02:05:15 +03:00
|
|
|
#include "mozilla/dom/BindingCallContext.h"
|
2019-01-08 09:45:18 +03:00
|
|
|
#include "mozilla/dom/Document.h" // For Document::AreWebAnimationsImplicitKeyframesEnabled
|
2016-03-22 10:31:09 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2018-05-07 05:07:06 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffect.h" // For PropertyValuesPair etc.
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffectBinding.h"
|
2018-04-05 20:42:42 +03:00
|
|
|
#include "mozilla/dom/Nullable.h"
|
2016-09-04 10:33:38 +03:00
|
|
|
#include "nsCSSPropertyIDSet.h"
|
2016-03-22 10:20:37 +03:00
|
|
|
#include "nsCSSProps.h"
|
2019-02-19 16:44:33 +03:00
|
|
|
#include "nsCSSPseudoElements.h" // For PseudoStyleType
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsContentUtils.h" // For GetContextForContent
|
2017-06-14 09:18:25 +03:00
|
|
|
#include "nsIScriptError.h"
|
2019-03-29 18:11:22 +03:00
|
|
|
#include "nsPresContextInlines.h"
|
2016-03-22 10:20:37 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
|
2018-04-05 20:42:42 +03:00
|
|
|
using mozilla::dom::Nullable;
|
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Internal data types
|
|
|
|
//
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For the aAllowList parameter of AppendStringOrStringSequence and
|
|
|
|
// GetPropertyValuesPairs.
|
|
|
|
enum class ListAllowance { eDisallow, eAllow };
|
|
|
|
|
2016-03-22 10:33:11 +03:00
|
|
|
/**
|
|
|
|
* A property-values pair obtained from the open-ended properties
|
|
|
|
* discovered on a regular keyframe or property-indexed keyframe object.
|
|
|
|
*
|
|
|
|
* Single values (as required by a regular keyframe, and as also supported
|
|
|
|
* on property-indexed keyframes) are stored as the only element in
|
|
|
|
* mValues.
|
|
|
|
*/
|
|
|
|
struct PropertyValuesPair {
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID mProperty;
|
2020-12-17 17:04:35 +03:00
|
|
|
nsTArray<nsCString> mValues;
|
2016-03-22 10:20:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An additional property (for a property-values pair) found on a
|
|
|
|
* BaseKeyframe or BasePropertyIndexedKeyframe object.
|
|
|
|
*/
|
|
|
|
struct AdditionalProperty {
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID mProperty;
|
2016-03-22 10:20:37 +03:00
|
|
|
size_t mJsidIndex; // Index into |ids| in GetPropertyValuesPairs.
|
|
|
|
|
|
|
|
struct PropertyComparator {
|
|
|
|
bool Equals(const AdditionalProperty& aLhs,
|
|
|
|
const AdditionalProperty& aRhs) const {
|
|
|
|
return aLhs.mProperty == aRhs.mProperty;
|
|
|
|
}
|
|
|
|
bool LessThan(const AdditionalProperty& aLhs,
|
|
|
|
const AdditionalProperty& aRhs) const {
|
|
|
|
return nsCSSProps::PropertyIDLNameSortPosition(aLhs.mProperty) <
|
|
|
|
nsCSSProps::PropertyIDLNameSortPosition(aRhs.mProperty);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data for a segment in a keyframe animation of a given property
|
|
|
|
* whose value is a StyleAnimationValue.
|
|
|
|
*
|
2016-03-22 10:36:45 +03:00
|
|
|
* KeyframeValueEntry is used in GetAnimationPropertiesFromKeyframes
|
|
|
|
* to gather data for each individual segment.
|
2016-03-22 10:20:37 +03:00
|
|
|
*/
|
2016-03-22 10:36:45 +03:00
|
|
|
struct KeyframeValueEntry {
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID mProperty;
|
2017-02-08 06:00:36 +03:00
|
|
|
AnimationValue mValue;
|
2016-12-01 04:34:54 +03:00
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
float mOffset;
|
|
|
|
Maybe<ComputedTimingFunction> mTimingFunction;
|
2016-12-04 02:07:40 +03:00
|
|
|
dom::CompositeOperation mComposite;
|
2016-03-22 10:20:37 +03:00
|
|
|
|
|
|
|
struct PropertyOffsetComparator {
|
|
|
|
static bool Equals(const KeyframeValueEntry& aLhs,
|
|
|
|
const KeyframeValueEntry& aRhs) {
|
|
|
|
return aLhs.mProperty == aRhs.mProperty && aLhs.mOffset == aRhs.mOffset;
|
|
|
|
}
|
|
|
|
static bool LessThan(const KeyframeValueEntry& aLhs,
|
|
|
|
const KeyframeValueEntry& aRhs) {
|
|
|
|
// First, sort by property IDL name.
|
|
|
|
int32_t order = nsCSSProps::PropertyIDLNameSortPosition(aLhs.mProperty) -
|
|
|
|
nsCSSProps::PropertyIDLNameSortPosition(aRhs.mProperty);
|
|
|
|
if (order != 0) {
|
|
|
|
return order < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then, by offset.
|
|
|
|
return aLhs.mOffset < aRhs.mOffset;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-03-22 10:25:38 +03:00
|
|
|
class ComputedOffsetComparator {
|
|
|
|
public:
|
|
|
|
static bool Equals(const Keyframe& aLhs, const Keyframe& aRhs) {
|
|
|
|
return aLhs.mComputedOffset == aRhs.mComputedOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool LessThan(const Keyframe& aLhs, const Keyframe& aRhs) {
|
|
|
|
return aLhs.mComputedOffset < aRhs.mComputedOffset;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Internal helper method declarations
|
|
|
|
//
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
2020-02-07 00:22:32 +03:00
|
|
|
static void GetKeyframeListFromKeyframeSequence(
|
|
|
|
JSContext* aCx, dom::Document* aDocument, JS::ForOfIterator& aIterator,
|
|
|
|
nsTArray<Keyframe>& aResult, const char* aContext, ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-02-15 09:05:06 +03:00
|
|
|
static bool ConvertKeyframeSequence(JSContext* aCx, dom::Document* aDocument,
|
2016-03-22 10:25:38 +03:00
|
|
|
JS::ForOfIterator& aIterator,
|
2020-02-07 00:22:32 +03:00
|
|
|
const char* aContext,
|
2016-03-22 10:25:38 +03:00
|
|
|
nsTArray<Keyframe>& aResult);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
static bool GetPropertyValuesPairs(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aObject,
|
|
|
|
ListAllowance aAllowLists,
|
|
|
|
nsTArray<PropertyValuesPair>& aResult);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
static bool AppendStringOrStringSequenceToArray(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
ListAllowance aAllowLists,
|
2020-12-17 17:04:35 +03:00
|
|
|
nsTArray<nsCString>& aValues);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
static bool AppendValueAsString(JSContext* aCx, nsTArray<nsCString>& aValues,
|
2016-03-22 10:20:37 +03:00
|
|
|
JS::Handle<JS::Value> aValue);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-14 06:43:47 +03:00
|
|
|
static Maybe<PropertyValuePair> MakePropertyValuePair(
|
2020-12-17 17:04:35 +03:00
|
|
|
nsCSSPropertyID aProperty, const nsACString& aStringValue,
|
2019-02-15 09:05:06 +03:00
|
|
|
dom::Document* aDocument);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-22 10:25:38 +03:00
|
|
|
static bool HasValidOffsets(const nsTArray<Keyframe>& aKeyframes);
|
|
|
|
|
2017-05-30 11:24:08 +03:00
|
|
|
#ifdef DEBUG
|
2016-06-28 10:10:10 +03:00
|
|
|
static void MarkAsComputeValuesFailureKey(PropertyValuePair& aPair);
|
|
|
|
|
2018-02-01 07:04:04 +03:00
|
|
|
#endif
|
2016-06-28 10:10:10 +03:00
|
|
|
|
2017-06-14 07:51:27 +03:00
|
|
|
static nsTArray<ComputedKeyframeValues> GetComputedKeyframeValues(
|
|
|
|
const nsTArray<Keyframe>& aKeyframes, dom::Element* aElement,
|
2020-07-22 02:12:35 +03:00
|
|
|
PseudoStyleType aPseudoType, const ComputedStyle* aComputedValues);
|
2017-06-14 07:51:27 +03:00
|
|
|
|
|
|
|
static void BuildSegmentsFromValueEntries(
|
|
|
|
nsTArray<KeyframeValueEntry>& aEntries,
|
2018-03-22 21:20:41 +03:00
|
|
|
nsTArray<AnimationProperty>& aResult);
|
2017-06-14 07:51:27 +03:00
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
static void GetKeyframeListFromPropertyIndexedKeyframe(
|
2019-02-15 09:05:06 +03:00
|
|
|
JSContext* aCx, dom::Document* aDocument, JS::Handle<JS::Value> aValue,
|
2016-03-22 10:20:37 +03:00
|
|
|
nsTArray<Keyframe>& aResult, ErrorResult& aRv);
|
|
|
|
|
2016-03-22 10:25:38 +03:00
|
|
|
static bool HasImplicitKeyframeValues(const nsTArray<Keyframe>& aKeyframes,
|
2019-02-15 09:05:06 +03:00
|
|
|
dom::Document* aDocument);
|
2016-03-22 10:25:38 +03:00
|
|
|
|
2017-06-15 05:54:36 +03:00
|
|
|
static void DistributeRange(const Range<Keyframe>& aRange);
|
2016-05-27 13:09:06 +03:00
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Public API
|
|
|
|
//
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
nsTArray<Keyframe> KeyframeUtils::GetKeyframesFromObject(
|
2019-02-15 09:05:06 +03:00
|
|
|
JSContext* aCx, dom::Document* aDocument, JS::Handle<JSObject*> aFrames,
|
2020-02-07 00:22:32 +03:00
|
|
|
const char* aContext, ErrorResult& aRv) {
|
2016-03-22 10:25:38 +03:00
|
|
|
MOZ_ASSERT(!aRv.Failed());
|
|
|
|
|
|
|
|
nsTArray<Keyframe> keyframes;
|
|
|
|
|
|
|
|
if (!aFrames) {
|
|
|
|
// The argument was explicitly null meaning no keyframes.
|
|
|
|
return keyframes;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point we know we have an object. We try to convert it to a
|
|
|
|
// sequence of keyframes first, and if that fails due to not being iterable,
|
|
|
|
// we try to convert it to a property-indexed keyframe.
|
|
|
|
JS::Rooted<JS::Value> objectValue(aCx, JS::ObjectValue(*aFrames));
|
|
|
|
JS::ForOfIterator iter(aCx);
|
|
|
|
if (!iter.init(objectValue, JS::ForOfIterator::AllowNonIterable)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return keyframes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iter.valueIsIterable()) {
|
2020-02-07 00:22:32 +03:00
|
|
|
GetKeyframeListFromKeyframeSequence(aCx, aDocument, iter, keyframes,
|
|
|
|
aContext, aRv);
|
2016-03-22 10:25:38 +03:00
|
|
|
} else {
|
2016-07-13 07:22:25 +03:00
|
|
|
GetKeyframeListFromPropertyIndexedKeyframe(aCx, aDocument, objectValue,
|
|
|
|
keyframes, aRv);
|
2016-03-22 10:25:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
MOZ_ASSERT(keyframes.IsEmpty(),
|
|
|
|
"Should not set any keyframes when there is an error");
|
|
|
|
return keyframes;
|
|
|
|
}
|
|
|
|
|
2019-02-15 09:05:06 +03:00
|
|
|
if (!dom::Document::AreWebAnimationsImplicitKeyframesEnabled(aCx, nullptr) &&
|
2018-07-14 03:23:03 +03:00
|
|
|
HasImplicitKeyframeValues(keyframes, aDocument)) {
|
2016-03-22 10:25:38 +03:00
|
|
|
keyframes.Clear();
|
2021-05-10 15:20:17 +03:00
|
|
|
aRv.ThrowNotSupportedError(
|
|
|
|
"Animation to or from an underlying value is not yet supported");
|
2016-03-22 10:25:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return keyframes;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
void KeyframeUtils::DistributeKeyframes(nsTArray<Keyframe>& aKeyframes) {
|
2016-03-22 10:35:53 +03:00
|
|
|
if (aKeyframes.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-10 12:40:53 +03:00
|
|
|
// If the first keyframe has an unspecified offset, fill it in with 0%.
|
|
|
|
// If there is only a single keyframe, then it gets 100%.
|
2016-03-22 10:35:53 +03:00
|
|
|
if (aKeyframes.Length() > 1) {
|
|
|
|
Keyframe& firstElement = aKeyframes[0];
|
|
|
|
firstElement.mComputedOffset = firstElement.mOffset.valueOr(0.0);
|
2016-05-10 12:40:53 +03:00
|
|
|
// We will fill in the last keyframe's offset below
|
|
|
|
} else {
|
|
|
|
Keyframe& lastElement = aKeyframes.LastElement();
|
|
|
|
lastElement.mComputedOffset = lastElement.mOffset.valueOr(1.0);
|
2016-03-22 10:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fill in remaining missing offsets.
|
2016-09-01 01:42:12 +03:00
|
|
|
const Keyframe* const last = &aKeyframes.LastElement();
|
|
|
|
const RangedPtr<Keyframe> begin(aKeyframes.Elements(), aKeyframes.Length());
|
2016-05-27 13:09:06 +03:00
|
|
|
RangedPtr<Keyframe> keyframeA = begin;
|
2016-05-10 12:40:53 +03:00
|
|
|
while (keyframeA != last) {
|
|
|
|
// Find keyframe A and keyframe B *between* which we will apply spacing.
|
|
|
|
RangedPtr<Keyframe> keyframeB = keyframeA + 1;
|
2016-05-27 13:09:06 +03:00
|
|
|
while (keyframeB->mOffset.isNothing() && keyframeB != last) {
|
2016-05-10 12:40:53 +03:00
|
|
|
++keyframeB;
|
2016-03-22 10:35:53 +03:00
|
|
|
}
|
2016-05-27 13:09:06 +03:00
|
|
|
keyframeB->mComputedOffset = keyframeB->mOffset.valueOr(1.0);
|
2016-05-10 12:40:53 +03:00
|
|
|
|
|
|
|
// Fill computed offsets in (keyframe A, keyframe B).
|
2017-06-13 10:09:19 +03:00
|
|
|
DistributeRange(Range<Keyframe>(keyframeA, keyframeB + 1));
|
2016-05-10 12:40:53 +03:00
|
|
|
keyframeA = keyframeB;
|
2016-03-22 10:35:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
nsTArray<AnimationProperty> KeyframeUtils::GetAnimationPropertiesFromKeyframes(
|
2016-05-25 12:10:53 +03:00
|
|
|
const nsTArray<Keyframe>& aKeyframes, dom::Element* aElement,
|
2020-07-22 02:12:35 +03:00
|
|
|
PseudoStyleType aPseudoType, const ComputedStyle* aStyle,
|
|
|
|
dom::CompositeOperation aEffectComposite) {
|
2017-10-25 09:34:50 +03:00
|
|
|
nsTArray<AnimationProperty> result;
|
|
|
|
|
2017-06-14 07:51:27 +03:00
|
|
|
const nsTArray<ComputedKeyframeValues> computedValues =
|
2020-07-22 02:12:35 +03:00
|
|
|
GetComputedKeyframeValues(aKeyframes, aElement, aPseudoType, aStyle);
|
2017-10-25 09:34:50 +03:00
|
|
|
if (computedValues.IsEmpty()) {
|
|
|
|
// In rare cases GetComputedKeyframeValues might fail and return an empty
|
|
|
|
// array, in which case we likewise return an empty array from here.
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-06-14 07:51:27 +03:00
|
|
|
MOZ_ASSERT(aKeyframes.Length() == computedValues.Length(),
|
2016-05-25 12:10:53 +03:00
|
|
|
"Array length mismatch");
|
|
|
|
|
|
|
|
nsTArray<KeyframeValueEntry> entries(aKeyframes.Length());
|
|
|
|
|
|
|
|
const size_t len = aKeyframes.Length();
|
|
|
|
for (size_t i = 0; i < len; ++i) {
|
|
|
|
const Keyframe& frame = aKeyframes[i];
|
2017-06-14 07:51:27 +03:00
|
|
|
for (auto& value : computedValues[i]) {
|
2016-05-25 12:10:53 +03:00
|
|
|
MOZ_ASSERT(frame.mComputedOffset != Keyframe::kComputedOffsetNotSet,
|
|
|
|
"Invalid computed offset");
|
|
|
|
KeyframeValueEntry* entry = entries.AppendElement();
|
|
|
|
entry->mOffset = frame.mComputedOffset;
|
|
|
|
entry->mProperty = value.mProperty;
|
|
|
|
entry->mValue = value.mValue;
|
|
|
|
entry->mTimingFunction = frame.mTimingFunction;
|
2018-08-16 19:24:52 +03:00
|
|
|
// The following assumes that CompositeOperation is a strict subset of
|
|
|
|
// CompositeOperationOrAuto.
|
2016-12-04 02:07:40 +03:00
|
|
|
entry->mComposite =
|
2018-08-16 19:24:52 +03:00
|
|
|
frame.mComposite == dom::CompositeOperationOrAuto::Auto
|
|
|
|
? aEffectComposite
|
|
|
|
: static_cast<dom::CompositeOperation>(frame.mComposite);
|
2016-05-25 12:10:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 06:41:02 +03:00
|
|
|
BuildSegmentsFromValueEntries(entries, result);
|
2016-03-22 10:34:14 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
bool KeyframeUtils::IsAnimatableProperty(nsCSSPropertyID aProperty) {
|
2017-06-14 09:23:45 +03:00
|
|
|
// Regardless of the backend type, treat the 'display' property as not
|
2018-03-28 18:29:42 +03:00
|
|
|
// animatable. (Servo will report it as being animatable, since it is
|
|
|
|
// in fact animatable by SMIL.)
|
2017-06-14 09:23:45 +03:00
|
|
|
if (aProperty == eCSSProperty_display) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-28 18:29:42 +03:00
|
|
|
return Servo_Property_IsAnimatable(aProperty);
|
2016-05-13 11:38:25 +03:00
|
|
|
}
|
2016-03-22 10:25:38 +03:00
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Internal helpers
|
|
|
|
//
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
2016-03-22 10:25:38 +03:00
|
|
|
/**
|
|
|
|
* Converts a JS object to an IDL sequence<Keyframe>.
|
|
|
|
*
|
|
|
|
* @param aCx The JSContext corresponding to |aIterator|.
|
2016-07-13 07:22:25 +03:00
|
|
|
* @param aDocument The document to use when parsing CSS properties.
|
2016-03-22 10:25:38 +03:00
|
|
|
* @param aIterator An already-initialized ForOfIterator for the JS
|
|
|
|
* object to iterate over as a sequence.
|
|
|
|
* @param aResult The array into which the resulting Keyframe objects will be
|
|
|
|
* appended.
|
2020-02-07 00:22:32 +03:00
|
|
|
* @param aContext The context string to prepend to thrown exceptions.
|
2016-03-22 10:25:38 +03:00
|
|
|
* @param aRv Out param to store any errors thrown by this function.
|
|
|
|
*/
|
2020-02-07 00:22:32 +03:00
|
|
|
static void GetKeyframeListFromKeyframeSequence(
|
|
|
|
JSContext* aCx, dom::Document* aDocument, JS::ForOfIterator& aIterator,
|
|
|
|
nsTArray<Keyframe>& aResult, const char* aContext, ErrorResult& aRv) {
|
2016-03-22 10:25:38 +03:00
|
|
|
MOZ_ASSERT(!aRv.Failed());
|
|
|
|
MOZ_ASSERT(aResult.IsEmpty());
|
|
|
|
|
|
|
|
// Convert the object in aIterator to a sequence of keyframes producing
|
|
|
|
// an array of Keyframe objects.
|
2020-02-07 00:22:32 +03:00
|
|
|
if (!ConvertKeyframeSequence(aCx, aDocument, aIterator, aContext, aResult)) {
|
2016-03-22 10:25:38 +03:00
|
|
|
aResult.Clear();
|
2020-02-07 00:22:32 +03:00
|
|
|
aRv.NoteJSContextException(aCx);
|
2016-03-22 10:25:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the sequence<> had zero elements, we won't generate any
|
|
|
|
// keyframes.
|
|
|
|
if (aResult.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the keyframes are loosely sorted and with values all
|
|
|
|
// between 0% and 100%.
|
|
|
|
if (!HasValidOffsets(aResult)) {
|
|
|
|
aResult.Clear();
|
2019-09-20 05:19:18 +03:00
|
|
|
aRv.ThrowTypeError<dom::MSG_INVALID_KEYFRAME_OFFSETS>();
|
2016-03-22 10:25:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a JS object wrapped by the given JS::ForIfIterator to an
|
|
|
|
* IDL sequence<Keyframe> and stores the resulting Keyframe objects in
|
|
|
|
* aResult.
|
|
|
|
*/
|
2019-02-15 09:05:06 +03:00
|
|
|
static bool ConvertKeyframeSequence(JSContext* aCx, dom::Document* aDocument,
|
2016-03-22 10:25:38 +03:00
|
|
|
JS::ForOfIterator& aIterator,
|
2020-02-07 00:22:32 +03:00
|
|
|
const char* aContext,
|
2016-03-22 10:25:38 +03:00
|
|
|
nsTArray<Keyframe>& aResult) {
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
2020-03-04 04:03:16 +03:00
|
|
|
// Parsing errors should only be reported after we have finished iterating
|
|
|
|
// through all values. If we have any early returns while iterating, we should
|
2020-03-07 00:04:07 +03:00
|
|
|
// ignore parsing errors.
|
|
|
|
IgnoredErrorResult parseEasingResult;
|
2016-03-22 10:25:38 +03:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
bool done;
|
|
|
|
if (!aIterator.next(&value, &done)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Each value found when iterating the object must be an object
|
|
|
|
// or null/undefined (which gets treated as a default {} dictionary
|
|
|
|
// value).
|
|
|
|
if (!value.isObject() && !value.isNullOrUndefined()) {
|
2020-02-06 23:40:36 +03:00
|
|
|
dom::ThrowErrorMessage<dom::MSG_NOT_OBJECT>(
|
2020-03-07 02:05:16 +03:00
|
|
|
aCx, aContext, "Element of sequence<Keyframe> argument");
|
2016-03-22 10:25:38 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the JS value into a BaseKeyframe dictionary value.
|
|
|
|
dom::binding_detail::FastBaseKeyframe keyframeDict;
|
2020-05-06 01:40:57 +03:00
|
|
|
dom::BindingCallContext callCx(aCx, aContext);
|
2020-03-07 02:05:15 +03:00
|
|
|
if (!keyframeDict.Init(callCx, value,
|
2016-03-22 10:25:38 +03:00
|
|
|
"Element of sequence<Keyframe> argument")) {
|
2020-03-04 04:03:16 +03:00
|
|
|
// This may happen if the value type of the member of BaseKeyframe is
|
|
|
|
// invalid. e.g. `offset` only accept a double value, so if we provide a
|
|
|
|
// string, we enter this branch.
|
|
|
|
// Besides, keyframeDict.Init() should throw a Type Error message already,
|
|
|
|
// so we don't have to do it again.
|
2016-03-22 10:25:38 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Keyframe* keyframe = aResult.AppendElement(fallible);
|
|
|
|
if (!keyframe) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-04 04:03:16 +03:00
|
|
|
|
2016-03-22 10:25:38 +03:00
|
|
|
if (!keyframeDict.mOffset.IsNull()) {
|
|
|
|
keyframe->mOffset.emplace(keyframeDict.mOffset.Value());
|
|
|
|
}
|
|
|
|
|
2018-08-15 03:51:28 +03:00
|
|
|
if (StaticPrefs::dom_animations_api_compositing_enabled()) {
|
2018-08-16 19:24:52 +03:00
|
|
|
keyframe->mComposite = keyframeDict.mComposite;
|
2016-12-04 02:07:41 +03:00
|
|
|
}
|
|
|
|
|
2016-03-22 10:25:38 +03:00
|
|
|
// Look for additional property-values pairs on the object.
|
|
|
|
nsTArray<PropertyValuesPair> propertyValuePairs;
|
|
|
|
if (value.isObject()) {
|
|
|
|
JS::Rooted<JSObject*> object(aCx, &value.toObject());
|
|
|
|
if (!GetPropertyValuesPairs(aCx, object, ListAllowance::eDisallow,
|
|
|
|
propertyValuePairs)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 06:35:47 +03:00
|
|
|
if (!parseEasingResult.Failed()) {
|
2020-11-12 23:34:01 +03:00
|
|
|
keyframe->mTimingFunction =
|
|
|
|
TimingParams::ParseEasing(keyframeDict.mEasing, parseEasingResult);
|
2017-10-02 06:35:47 +03:00
|
|
|
// Even if the above fails, we still need to continue reading off all the
|
|
|
|
// properties since checking the validity of easing should be treated as
|
|
|
|
// a separate step that happens *after* all the other processing in this
|
|
|
|
// loop since (since it is never likely to be handled by WebIDL unlike the
|
|
|
|
// rest of this loop).
|
|
|
|
}
|
|
|
|
|
2016-03-22 10:25:38 +03:00
|
|
|
for (PropertyValuesPair& pair : propertyValuePairs) {
|
|
|
|
MOZ_ASSERT(pair.mValues.Length() == 1);
|
2017-06-14 06:43:47 +03:00
|
|
|
|
|
|
|
Maybe<PropertyValuePair> valuePair =
|
2018-04-24 16:51:55 +03:00
|
|
|
MakePropertyValuePair(pair.mProperty, pair.mValues[0], aDocument);
|
2017-06-14 06:43:47 +03:00
|
|
|
if (!valuePair) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-30 22:15:35 +03:00
|
|
|
keyframe->mPropertyValues.AppendElement(std::move(valuePair.ref()));
|
2016-06-28 10:10:10 +03:00
|
|
|
|
2017-05-30 11:24:08 +03:00
|
|
|
#ifdef DEBUG
|
2016-06-28 10:10:10 +03:00
|
|
|
// When we go to convert keyframes into arrays of property values we
|
|
|
|
// call StyleAnimation::ComputeValues. This should normally return true
|
|
|
|
// but in order to test the case where it does not, BaseKeyframeDict
|
|
|
|
// includes a chrome-only member that can be set to indicate that
|
|
|
|
// ComputeValues should fail for shorthand property values on that
|
|
|
|
// keyframe.
|
|
|
|
if (nsCSSProps::IsShorthand(pair.mProperty) &&
|
|
|
|
keyframeDict.mSimulateComputeValuesFailure) {
|
|
|
|
MarkAsComputeValuesFailureKey(keyframe->mPropertyValues.LastElement());
|
|
|
|
}
|
2017-05-30 11:24:08 +03:00
|
|
|
#endif
|
2016-03-22 10:25:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 06:35:47 +03:00
|
|
|
// Throw any errors we encountered while parsing 'easing' properties.
|
|
|
|
if (parseEasingResult.MaybeSetPendingException(aCx)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-22 10:25:38 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
/**
|
|
|
|
* Reads the property-values pairs from the specified JS object.
|
|
|
|
*
|
|
|
|
* @param aObject The JS object to look at.
|
|
|
|
* @param aAllowLists If eAllow, values will be converted to
|
|
|
|
* (DOMString or sequence<DOMString); if eDisallow, values
|
|
|
|
* will be converted to DOMString.
|
|
|
|
* @param aResult The array into which the enumerated property-values
|
|
|
|
* pairs will be stored.
|
|
|
|
* @return false on failure or JS exception thrown while interacting
|
|
|
|
* with aObject; true otherwise.
|
|
|
|
*/
|
|
|
|
static bool GetPropertyValuesPairs(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aObject,
|
|
|
|
ListAllowance aAllowLists,
|
|
|
|
nsTArray<PropertyValuesPair>& aResult) {
|
|
|
|
nsTArray<AdditionalProperty> properties;
|
|
|
|
|
|
|
|
// Iterate over all the properties on aObject and append an
|
|
|
|
// entry to properties for them.
|
|
|
|
//
|
|
|
|
// We don't compare the jsids that we encounter with those for
|
|
|
|
// the explicit dictionary members, since we know that none
|
|
|
|
// of the CSS property IDL names clash with them.
|
|
|
|
JS::Rooted<JS::IdVector> ids(aCx, JS::IdVector(aCx));
|
|
|
|
if (!JS_Enumerate(aCx, aObject, &ids)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (size_t i = 0, n = ids.length(); i < n; i++) {
|
2020-01-08 04:21:30 +03:00
|
|
|
nsAutoJSCString propName;
|
2016-03-22 10:20:37 +03:00
|
|
|
if (!propName.init(aCx, ids[i])) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-23 22:56:33 +03:00
|
|
|
|
|
|
|
// Basically, we have to handle "cssOffset" and "cssFloat" specially here:
|
|
|
|
// "cssOffset" => eCSSProperty_offset
|
|
|
|
// "cssFloat" => eCSSProperty_float
|
|
|
|
// This means if the attribute is the string "cssOffset"/"cssFloat", we use
|
|
|
|
// CSS "offset"/"float" property.
|
|
|
|
// https://drafts.csswg.org/web-animations/#property-name-conversion
|
|
|
|
nsCSSPropertyID property = nsCSSPropertyID::eCSSProperty_UNKNOWN;
|
|
|
|
if (propName.EqualsLiteral("cssOffset")) {
|
|
|
|
property = nsCSSPropertyID::eCSSProperty_offset;
|
|
|
|
} else if (propName.EqualsLiteral("cssFloat")) {
|
|
|
|
property = nsCSSPropertyID::eCSSProperty_float;
|
|
|
|
} else if (!propName.EqualsLiteral("offset") &&
|
|
|
|
!propName.EqualsLiteral("float")) {
|
|
|
|
property = nsCSSProps::LookupPropertyByIDLName(
|
|
|
|
propName, CSSEnabledState::ForAllContent);
|
|
|
|
}
|
|
|
|
|
2018-03-28 18:29:42 +03:00
|
|
|
if (KeyframeUtils::IsAnimatableProperty(property)) {
|
2016-03-22 10:20:37 +03:00
|
|
|
AdditionalProperty* p = properties.AppendElement();
|
|
|
|
p->mProperty = property;
|
|
|
|
p->mJsidIndex = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the entries by IDL name and then get each value and
|
|
|
|
// convert it either to a DOMString or to a
|
|
|
|
// (DOMString or sequence<DOMString>), depending on aAllowLists,
|
|
|
|
// and build up aResult.
|
|
|
|
properties.Sort(AdditionalProperty::PropertyComparator());
|
|
|
|
|
|
|
|
for (AdditionalProperty& p : properties) {
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
if (!JS_GetPropertyById(aCx, aObject, ids[p.mJsidIndex], &value)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PropertyValuesPair* pair = aResult.AppendElement();
|
|
|
|
pair->mProperty = p.mProperty;
|
|
|
|
if (!AppendStringOrStringSequenceToArray(aCx, value, aAllowLists,
|
|
|
|
pair->mValues)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts aValue to DOMString, if aAllowLists is eDisallow, or
|
|
|
|
* to (DOMString or sequence<DOMString>) if aAllowLists is aAllow.
|
|
|
|
* The resulting strings are appended to aValues.
|
|
|
|
*/
|
|
|
|
static bool AppendStringOrStringSequenceToArray(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
ListAllowance aAllowLists,
|
2020-12-17 17:04:35 +03:00
|
|
|
nsTArray<nsCString>& aValues) {
|
2016-03-22 10:20:37 +03:00
|
|
|
if (aAllowLists == ListAllowance::eAllow && aValue.isObject()) {
|
|
|
|
// The value is an object, and we want to allow lists; convert
|
|
|
|
// aValue to (DOMString or sequence<DOMString>).
|
|
|
|
JS::ForOfIterator iter(aCx);
|
|
|
|
if (!iter.init(aValue, JS::ForOfIterator::AllowNonIterable)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (iter.valueIsIterable()) {
|
|
|
|
// If the object is iterable, convert it to sequence<DOMString>.
|
|
|
|
JS::Rooted<JS::Value> element(aCx);
|
|
|
|
for (;;) {
|
|
|
|
bool done;
|
|
|
|
if (!iter.next(&element, &done)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!AppendValueAsString(aCx, aValues, element)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Either the object is not iterable, or aAllowLists doesn't want
|
|
|
|
// a list; convert it to DOMString.
|
|
|
|
if (!AppendValueAsString(aCx, aValues, aValue)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts aValue to DOMString and appends it to aValues.
|
|
|
|
*/
|
2020-12-17 17:04:35 +03:00
|
|
|
static bool AppendValueAsString(JSContext* aCx, nsTArray<nsCString>& aValues,
|
2016-03-22 10:20:37 +03:00
|
|
|
JS::Handle<JS::Value> aValue) {
|
|
|
|
return ConvertJSValueToString(aCx, aValue, dom::eStringify, dom::eStringify,
|
|
|
|
*aValues.AppendElement());
|
|
|
|
}
|
|
|
|
|
2017-06-14 09:18:25 +03:00
|
|
|
static void ReportInvalidPropertyValueToConsole(
|
2020-12-17 17:04:35 +03:00
|
|
|
nsCSSPropertyID aProperty, const nsACString& aInvalidPropertyValue,
|
2019-02-15 09:05:06 +03:00
|
|
|
dom::Document* aDoc) {
|
2019-06-09 00:26:12 +03:00
|
|
|
AutoTArray<nsString, 2> params;
|
2020-12-17 17:04:35 +03:00
|
|
|
params.AppendElement(NS_ConvertUTF8toUTF16(aInvalidPropertyValue));
|
2019-06-09 00:26:12 +03:00
|
|
|
CopyASCIItoUTF16(nsCSSProps::GetStringValue(aProperty),
|
|
|
|
*params.AppendElement());
|
2017-06-14 09:18:25 +03:00
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "Animation"_ns,
|
2019-06-09 00:26:12 +03:00
|
|
|
aDoc, nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"InvalidKeyframePropertyValue", params);
|
2017-06-14 09:18:25 +03:00
|
|
|
}
|
|
|
|
|
2016-03-22 10:25:38 +03:00
|
|
|
/**
|
|
|
|
* Construct a PropertyValuePair parsing the given string into a suitable
|
|
|
|
* nsCSSValue object.
|
|
|
|
*
|
|
|
|
* @param aProperty The CSS property.
|
|
|
|
* @param aStringValue The property value to parse.
|
|
|
|
* @param aDocument The document to use when parsing.
|
2017-06-14 06:43:47 +03:00
|
|
|
* @return The constructed PropertyValuePair, or Nothing() if |aStringValue| is
|
|
|
|
* an invalid property value.
|
2016-03-22 10:25:38 +03:00
|
|
|
*/
|
2017-06-14 06:43:47 +03:00
|
|
|
static Maybe<PropertyValuePair> MakePropertyValuePair(
|
2020-12-17 17:04:35 +03:00
|
|
|
nsCSSPropertyID aProperty, const nsACString& aStringValue,
|
2019-02-15 09:05:06 +03:00
|
|
|
dom::Document* aDocument) {
|
2016-03-22 10:25:38 +03:00
|
|
|
MOZ_ASSERT(aDocument);
|
2017-06-14 06:43:47 +03:00
|
|
|
Maybe<PropertyValuePair> result;
|
2017-05-30 11:24:08 +03:00
|
|
|
|
2018-03-25 20:42:10 +03:00
|
|
|
ServoCSSParser::ParsingEnvironment env =
|
|
|
|
ServoCSSParser::GetParsingEnvironment(aDocument);
|
|
|
|
RefPtr<RawServoDeclarationBlock> servoDeclarationBlock =
|
|
|
|
ServoCSSParser::ParseProperty(aProperty, aStringValue, env);
|
2016-03-22 10:25:38 +03:00
|
|
|
|
2018-03-25 20:42:10 +03:00
|
|
|
if (servoDeclarationBlock) {
|
2018-05-30 22:15:35 +03:00
|
|
|
result.emplace(aProperty, std::move(servoDeclarationBlock));
|
2018-03-25 20:42:10 +03:00
|
|
|
} else {
|
|
|
|
ReportInvalidPropertyValueToConsole(aProperty, aStringValue, aDocument);
|
|
|
|
}
|
|
|
|
return result;
|
2016-03-22 10:25:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks that the given keyframes are loosely ordered (each keyframe's
|
|
|
|
* offset that is not null is greater than or equal to the previous
|
|
|
|
* non-null offset) and that all values are within the range [0.0, 1.0].
|
|
|
|
*
|
|
|
|
* @return true if the keyframes' offsets are correctly ordered and
|
|
|
|
* within range; false otherwise.
|
|
|
|
*/
|
|
|
|
static bool HasValidOffsets(const nsTArray<Keyframe>& aKeyframes) {
|
|
|
|
double offset = 0.0;
|
|
|
|
for (const Keyframe& keyframe : aKeyframes) {
|
|
|
|
if (keyframe.mOffset) {
|
|
|
|
double thisOffset = keyframe.mOffset.value();
|
|
|
|
if (thisOffset < offset || thisOffset > 1.0f) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
offset = thisOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-30 11:24:08 +03:00
|
|
|
#ifdef DEBUG
|
2016-06-28 10:10:10 +03:00
|
|
|
/**
|
|
|
|
* Takes a property-value pair for a shorthand property and modifies the
|
|
|
|
* value to indicate that when we call StyleAnimationValue::ComputeValues on
|
|
|
|
* that value we should behave as if that function had failed.
|
|
|
|
*
|
|
|
|
* @param aPair The PropertyValuePair to modify. |aPair.mProperty| must be
|
|
|
|
* a shorthand property.
|
|
|
|
*/
|
|
|
|
static void MarkAsComputeValuesFailureKey(PropertyValuePair& aPair) {
|
|
|
|
MOZ_ASSERT(nsCSSProps::IsShorthand(aPair.mProperty),
|
|
|
|
"Only shorthand property values can be marked as failure values");
|
|
|
|
|
2017-05-30 11:24:08 +03:00
|
|
|
aPair.mSimulateComputeValuesFailure = true;
|
2016-06-28 10:10:10 +03:00
|
|
|
}
|
|
|
|
|
2018-02-01 07:04:04 +03:00
|
|
|
#endif
|
2016-06-28 10:10:10 +03:00
|
|
|
|
2017-06-14 07:51:27 +03:00
|
|
|
/**
|
|
|
|
* The variation of the above function. This is for Servo backend.
|
|
|
|
*/
|
|
|
|
static nsTArray<ComputedKeyframeValues> GetComputedKeyframeValues(
|
|
|
|
const nsTArray<Keyframe>& aKeyframes, dom::Element* aElement,
|
2020-07-22 02:12:35 +03:00
|
|
|
PseudoStyleType aPseudoType, const ComputedStyle* aComputedStyle) {
|
2017-06-14 07:51:27 +03:00
|
|
|
MOZ_ASSERT(aElement);
|
|
|
|
|
2017-10-25 09:34:50 +03:00
|
|
|
nsTArray<ComputedKeyframeValues> result;
|
|
|
|
|
2017-06-14 07:51:27 +03:00
|
|
|
nsPresContext* presContext = nsContentUtils::GetContextForContent(aElement);
|
2017-10-25 09:34:50 +03:00
|
|
|
if (!presContext) {
|
|
|
|
// This has been reported to happen with some combinations of content
|
|
|
|
// (particularly involving resize events and layout flushes? See bug 1407898
|
|
|
|
// and bug 1408420) but no reproducible steps have been found.
|
|
|
|
// For now we just return an empty array.
|
|
|
|
return result;
|
|
|
|
}
|
2017-06-14 07:51:27 +03:00
|
|
|
|
2018-03-29 14:15:46 +03:00
|
|
|
result = presContext->StyleSet()->GetComputedKeyframeValuesFor(
|
2020-07-22 02:12:35 +03:00
|
|
|
aKeyframes, aElement, aPseudoType, aComputedStyle);
|
2017-10-25 09:34:50 +03:00
|
|
|
return result;
|
2017-06-14 07:51:27 +03:00
|
|
|
}
|
|
|
|
|
2016-12-04 02:07:40 +03:00
|
|
|
static void AppendInitialSegment(AnimationProperty* aAnimationProperty,
|
|
|
|
const KeyframeValueEntry& aFirstEntry) {
|
|
|
|
AnimationPropertySegment* segment =
|
|
|
|
aAnimationProperty->mSegments.AppendElement();
|
|
|
|
segment->mFromKey = 0.0f;
|
|
|
|
segment->mToKey = aFirstEntry.mOffset;
|
2017-02-04 08:57:08 +03:00
|
|
|
segment->mToValue = aFirstEntry.mValue;
|
2016-12-04 02:07:40 +03:00
|
|
|
segment->mToComposite = aFirstEntry.mComposite;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void AppendFinalSegment(AnimationProperty* aAnimationProperty,
|
|
|
|
const KeyframeValueEntry& aLastEntry) {
|
|
|
|
AnimationPropertySegment* segment =
|
|
|
|
aAnimationProperty->mSegments.AppendElement();
|
|
|
|
segment->mFromKey = aLastEntry.mOffset;
|
2017-02-04 08:57:08 +03:00
|
|
|
segment->mFromValue = aLastEntry.mValue;
|
2016-12-04 02:07:40 +03:00
|
|
|
segment->mFromComposite = aLastEntry.mComposite;
|
|
|
|
segment->mToKey = 1.0f;
|
|
|
|
segment->mTimingFunction = aLastEntry.mTimingFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a newly created AnimationProperty if one was created to fill-in the
|
|
|
|
// missing keyframe, nullptr otherwise (if we decided not to fill the keyframe
|
2018-07-14 03:23:03 +03:00
|
|
|
// becase we don't support implicit keyframes).
|
2016-12-04 02:07:40 +03:00
|
|
|
static AnimationProperty* HandleMissingInitialKeyframe(
|
|
|
|
nsTArray<AnimationProperty>& aResult, const KeyframeValueEntry& aEntry) {
|
|
|
|
MOZ_ASSERT(aEntry.mOffset != 0.0f,
|
|
|
|
"The offset of the entry should not be 0.0");
|
|
|
|
|
2018-07-14 03:23:03 +03:00
|
|
|
// If the preference for implicit keyframes is not enabled, don't fill in the
|
|
|
|
// missing keyframe.
|
|
|
|
if (!StaticPrefs::dom_animations_api_implicit_keyframes_enabled()) {
|
2016-12-04 02:07:40 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationProperty* result = aResult.AppendElement();
|
|
|
|
result->mProperty = aEntry.mProperty;
|
|
|
|
|
|
|
|
AppendInitialSegment(result, aEntry);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HandleMissingFinalKeyframe(
|
|
|
|
nsTArray<AnimationProperty>& aResult, const KeyframeValueEntry& aEntry,
|
|
|
|
AnimationProperty* aCurrentAnimationProperty) {
|
|
|
|
MOZ_ASSERT(aEntry.mOffset != 1.0f,
|
|
|
|
"The offset of the entry should not be 1.0");
|
|
|
|
|
2018-07-14 03:23:03 +03:00
|
|
|
// If the preference for implicit keyframes is not enabled, don't fill
|
|
|
|
// in the missing keyframe.
|
|
|
|
if (!StaticPrefs::dom_animations_api_implicit_keyframes_enabled()) {
|
2016-12-04 02:07:40 +03:00
|
|
|
// If we have already appended a new entry for the property so we have to
|
|
|
|
// remove it.
|
|
|
|
if (aCurrentAnimationProperty) {
|
2018-03-13 16:51:33 +03:00
|
|
|
aResult.RemoveLastElement();
|
2016-12-04 02:07:40 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If |aCurrentAnimationProperty| is nullptr, that means this is the first
|
|
|
|
// entry for the property, we have to append a new AnimationProperty for this
|
|
|
|
// property.
|
|
|
|
if (!aCurrentAnimationProperty) {
|
|
|
|
aCurrentAnimationProperty = aResult.AppendElement();
|
|
|
|
aCurrentAnimationProperty->mProperty = aEntry.mProperty;
|
|
|
|
|
|
|
|
// If we have only one entry whose offset is neither 1 nor 0 for this
|
|
|
|
// property, we need to append the initial segment as well.
|
|
|
|
if (aEntry.mOffset != 0.0f) {
|
|
|
|
AppendInitialSegment(aCurrentAnimationProperty, aEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AppendFinalSegment(aCurrentAnimationProperty, aEntry);
|
|
|
|
}
|
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
/**
|
|
|
|
* Builds an array of AnimationProperty objects to represent the keyframe
|
|
|
|
* animation segments in aEntries.
|
|
|
|
*/
|
2016-08-27 06:41:02 +03:00
|
|
|
static void BuildSegmentsFromValueEntries(
|
|
|
|
nsTArray<KeyframeValueEntry>& aEntries,
|
2016-03-22 10:20:37 +03:00
|
|
|
nsTArray<AnimationProperty>& aResult) {
|
|
|
|
if (aEntries.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the KeyframeValueEntry objects so that all entries for a given
|
|
|
|
// property are together, and the entries are sorted by offset otherwise.
|
|
|
|
std::stable_sort(aEntries.begin(), aEntries.end(),
|
|
|
|
&KeyframeValueEntry::PropertyOffsetComparator::LessThan);
|
|
|
|
|
|
|
|
// For a given index i, we want to generate a segment from aEntries[i]
|
|
|
|
// to aEntries[j], if:
|
|
|
|
//
|
|
|
|
// * j > i,
|
|
|
|
// * aEntries[i + 1]'s offset/property is different from aEntries[i]'s, and
|
|
|
|
// * aEntries[j - 1]'s offset/property is different from aEntries[j]'s.
|
|
|
|
//
|
|
|
|
// That will eliminate runs of same offset/property values where there's no
|
|
|
|
// point generating zero length segments in the middle of the animation.
|
|
|
|
//
|
|
|
|
// Additionally we need to generate a zero length segment at offset 0 and at
|
|
|
|
// offset 1, if we have multiple values for a given property at that offset,
|
|
|
|
// since we need to retain the very first and very last value so they can
|
|
|
|
// be used for reverse and forward filling.
|
2016-06-09 02:12:52 +03:00
|
|
|
//
|
|
|
|
// Typically, for each property in |aEntries|, we expect there to be at least
|
|
|
|
// one KeyframeValueEntry with offset 0.0, and at least one with offset 1.0.
|
|
|
|
// However, since it is possible that when building |aEntries|, the call to
|
|
|
|
// StyleAnimationValue::ComputeValues might fail, this can't be guaranteed.
|
2016-12-04 02:07:40 +03:00
|
|
|
// Furthermore, if additive animation is disabled, the following loop takes
|
|
|
|
// care to identify properties that lack a value at offset 0.0/1.0 and drops
|
|
|
|
// those properties from |aResult|.
|
2016-03-22 10:20:37 +03:00
|
|
|
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID lastProperty = eCSSProperty_UNKNOWN;
|
2016-03-22 10:20:37 +03:00
|
|
|
AnimationProperty* animationProperty = nullptr;
|
|
|
|
|
|
|
|
size_t i = 0, n = aEntries.Length();
|
|
|
|
|
2016-06-09 02:12:52 +03:00
|
|
|
while (i < n) {
|
2016-12-04 02:07:40 +03:00
|
|
|
// If we've reached the end of the array of entries, synthesize a final (and
|
|
|
|
// initial) segment if necessary.
|
2016-06-09 02:12:52 +03:00
|
|
|
if (i + 1 == n) {
|
2016-12-04 02:07:40 +03:00
|
|
|
if (aEntries[i].mOffset != 1.0f) {
|
|
|
|
HandleMissingFinalKeyframe(aResult, aEntries[i], animationProperty);
|
|
|
|
} else if (aEntries[i].mOffset == 1.0f && !animationProperty) {
|
|
|
|
// If the last entry with offset 1 and no animation property, that means
|
|
|
|
// it is the only entry for this property so append a single segment
|
|
|
|
// from 0 offset to |aEntry[i].offset|.
|
|
|
|
Unused << HandleMissingInitialKeyframe(aResult, aEntries[i]);
|
2016-06-09 02:12:52 +03:00
|
|
|
}
|
2016-12-04 02:07:40 +03:00
|
|
|
animationProperty = nullptr;
|
2016-06-09 02:12:52 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aEntries[i].mProperty != eCSSProperty_UNKNOWN &&
|
|
|
|
aEntries[i + 1].mProperty != eCSSProperty_UNKNOWN,
|
|
|
|
"Each entry should specify a valid property");
|
|
|
|
|
2016-12-04 02:07:40 +03:00
|
|
|
// No keyframe for this property at offset 0.
|
2016-06-09 02:12:52 +03:00
|
|
|
if (aEntries[i].mProperty != lastProperty && aEntries[i].mOffset != 0.0f) {
|
2016-12-04 02:07:40 +03:00
|
|
|
// If we don't support additive animation we can't fill in the missing
|
|
|
|
// keyframes and we should just skip this property altogether. Since the
|
|
|
|
// entries are sorted by offset for a given property, and since we don't
|
|
|
|
// update |lastProperty|, we will keep hitting this condition until we
|
|
|
|
// change property.
|
|
|
|
animationProperty = HandleMissingInitialKeyframe(aResult, aEntries[i]);
|
|
|
|
if (animationProperty) {
|
|
|
|
lastProperty = aEntries[i].mProperty;
|
|
|
|
} else {
|
|
|
|
// Skip this entry if we did not handle the missing entry.
|
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
2016-06-09 02:12:52 +03:00
|
|
|
}
|
|
|
|
|
2017-01-31 18:30:19 +03:00
|
|
|
// Skip this entry if the next entry has the same offset except for initial
|
|
|
|
// and final ones. We will handle missing keyframe in the next loop
|
|
|
|
// if the property is changed on the next entry.
|
|
|
|
if (aEntries[i].mProperty == aEntries[i + 1].mProperty &&
|
|
|
|
aEntries[i].mOffset == aEntries[i + 1].mOffset &&
|
|
|
|
aEntries[i].mOffset != 1.0f && aEntries[i].mOffset != 0.0f) {
|
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-04 02:07:40 +03:00
|
|
|
// No keyframe for this property at offset 1.
|
2016-06-09 02:12:52 +03:00
|
|
|
if (aEntries[i].mProperty != aEntries[i + 1].mProperty &&
|
|
|
|
aEntries[i].mOffset != 1.0f) {
|
2016-12-04 02:07:40 +03:00
|
|
|
HandleMissingFinalKeyframe(aResult, aEntries[i], animationProperty);
|
|
|
|
// Move on to new property.
|
|
|
|
animationProperty = nullptr;
|
2016-06-09 02:12:52 +03:00
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-31 18:30:19 +03:00
|
|
|
// Starting from i + 1, determine the next [i, j] interval from which to
|
|
|
|
// generate a segment. Basically, j is i + 1, but there are some special
|
|
|
|
// cases for offset 0 and 1, so we need to handle them specifically.
|
|
|
|
// Note: From this moment, we make sure [i + 1] is valid and
|
|
|
|
// there must be an initial entry (i.e. mOffset = 0.0) and
|
|
|
|
// a final entry (i.e. mOffset = 1.0). Besides, all the entries
|
|
|
|
// with the same offsets except for initial/final ones are filtered
|
|
|
|
// out already.
|
|
|
|
size_t j = i + 1;
|
2016-03-22 10:20:37 +03:00
|
|
|
if (aEntries[i].mOffset == 0.0f && aEntries[i + 1].mOffset == 0.0f) {
|
|
|
|
// We need to generate an initial zero-length segment.
|
|
|
|
MOZ_ASSERT(aEntries[i].mProperty == aEntries[i + 1].mProperty);
|
2017-01-30 06:51:04 +03:00
|
|
|
while (j + 1 < n && aEntries[j + 1].mOffset == 0.0f &&
|
2016-06-09 02:12:52 +03:00
|
|
|
aEntries[j + 1].mProperty == aEntries[j].mProperty) {
|
2016-03-22 10:20:37 +03:00
|
|
|
++j;
|
|
|
|
}
|
|
|
|
} else if (aEntries[i].mOffset == 1.0f) {
|
2016-06-09 02:12:52 +03:00
|
|
|
if (aEntries[i + 1].mOffset == 1.0f &&
|
|
|
|
aEntries[i + 1].mProperty == aEntries[i].mProperty) {
|
2016-03-22 10:20:37 +03:00
|
|
|
// We need to generate a final zero-length segment.
|
2016-06-09 02:12:52 +03:00
|
|
|
while (j + 1 < n && aEntries[j + 1].mOffset == 1.0f &&
|
|
|
|
aEntries[j + 1].mProperty == aEntries[j].mProperty) {
|
2016-03-22 10:20:37 +03:00
|
|
|
++j;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// New property.
|
|
|
|
MOZ_ASSERT(aEntries[i].mProperty != aEntries[i + 1].mProperty);
|
2016-06-09 02:12:52 +03:00
|
|
|
animationProperty = nullptr;
|
2016-03-22 10:20:37 +03:00
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we've moved on to a new property, create a new AnimationProperty
|
|
|
|
// to insert segments into.
|
|
|
|
if (aEntries[i].mProperty != lastProperty) {
|
|
|
|
MOZ_ASSERT(aEntries[i].mOffset == 0.0f);
|
2016-06-09 02:12:52 +03:00
|
|
|
MOZ_ASSERT(!animationProperty);
|
2016-03-22 10:20:37 +03:00
|
|
|
animationProperty = aResult.AppendElement();
|
|
|
|
animationProperty->mProperty = aEntries[i].mProperty;
|
|
|
|
lastProperty = aEntries[i].mProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(animationProperty, "animationProperty should be valid pointer.");
|
|
|
|
|
|
|
|
// Now generate the segment.
|
|
|
|
AnimationPropertySegment* segment =
|
|
|
|
animationProperty->mSegments.AppendElement();
|
2016-12-01 04:34:54 +03:00
|
|
|
segment->mFromKey = aEntries[i].mOffset;
|
|
|
|
segment->mToKey = aEntries[j].mOffset;
|
2017-02-04 08:57:08 +03:00
|
|
|
segment->mFromValue = aEntries[i].mValue;
|
|
|
|
segment->mToValue = aEntries[j].mValue;
|
2016-03-22 10:20:37 +03:00
|
|
|
segment->mTimingFunction = aEntries[i].mTimingFunction;
|
2016-12-01 04:34:54 +03:00
|
|
|
segment->mFromComposite = aEntries[i].mComposite;
|
|
|
|
segment->mToComposite = aEntries[j].mComposite;
|
2016-03-22 10:20:37 +03:00
|
|
|
|
|
|
|
i = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-22 10:25:38 +03:00
|
|
|
/**
|
|
|
|
* Converts a JS object representing a property-indexed keyframe into
|
|
|
|
* an array of Keyframe objects.
|
|
|
|
*
|
|
|
|
* @param aCx The JSContext for |aValue|.
|
2016-07-13 07:22:25 +03:00
|
|
|
* @param aDocument The document to use when parsing CSS properties.
|
2016-03-22 10:25:38 +03:00
|
|
|
* @param aValue The JS object.
|
|
|
|
* @param aResult The array into which the resulting AnimationProperty
|
|
|
|
* objects will be appended.
|
|
|
|
* @param aRv Out param to store any errors thrown by this function.
|
|
|
|
*/
|
|
|
|
static void GetKeyframeListFromPropertyIndexedKeyframe(
|
2019-02-15 09:05:06 +03:00
|
|
|
JSContext* aCx, dom::Document* aDocument, JS::Handle<JS::Value> aValue,
|
2016-03-22 10:25:38 +03:00
|
|
|
nsTArray<Keyframe>& aResult, ErrorResult& aRv) {
|
|
|
|
MOZ_ASSERT(aValue.isObject());
|
|
|
|
MOZ_ASSERT(aResult.IsEmpty());
|
|
|
|
MOZ_ASSERT(!aRv.Failed());
|
|
|
|
|
|
|
|
// Convert the object to a property-indexed keyframe dictionary to
|
|
|
|
// get its explicit dictionary members.
|
|
|
|
dom::binding_detail::FastBasePropertyIndexedKeyframe keyframeDict;
|
2020-03-07 02:05:15 +03:00
|
|
|
// XXXbz Pass in the method name from callers and set up a BindingCallContext?
|
|
|
|
if (!keyframeDict.Init(aCx, aValue, "BasePropertyIndexedKeyframe argument")) {
|
2016-03-22 10:25:38 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all the property--value-list pairs off the object.
|
|
|
|
JS::Rooted<JSObject*> object(aCx, &aValue.toObject());
|
|
|
|
nsTArray<PropertyValuesPair> propertyValuesPairs;
|
|
|
|
if (!GetPropertyValuesPairs(aCx, object, ListAllowance::eAllow,
|
|
|
|
propertyValuesPairs)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a set of keyframes for each property.
|
2021-03-11 15:04:54 +03:00
|
|
|
nsTHashMap<nsFloatHashKey, Keyframe> processedKeyframes;
|
2016-03-22 10:25:38 +03:00
|
|
|
for (const PropertyValuesPair& pair : propertyValuesPairs) {
|
|
|
|
size_t count = pair.mValues.Length();
|
|
|
|
if (count == 0) {
|
|
|
|
// No animation values for this property.
|
|
|
|
continue;
|
|
|
|
}
|
2016-12-04 02:07:40 +03:00
|
|
|
|
|
|
|
// If we only have one value, we should animate from the underlying value
|
2018-07-14 03:23:03 +03:00
|
|
|
// but not if the pref for supporting implicit keyframes is disabled.
|
|
|
|
if (!StaticPrefs::dom_animations_api_implicit_keyframes_enabled() &&
|
|
|
|
count == 1) {
|
2021-05-10 15:20:17 +03:00
|
|
|
aRv.ThrowNotSupportedError(
|
|
|
|
"Animation to or from an underlying value is not yet supported");
|
2016-03-22 10:25:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t n = pair.mValues.Length() - 1;
|
|
|
|
size_t i = 0;
|
|
|
|
|
2020-12-17 17:04:35 +03:00
|
|
|
for (const nsCString& stringValue : pair.mValues) {
|
2017-02-10 09:21:15 +03:00
|
|
|
// For single-valued lists, the single value should be added to a
|
|
|
|
// keyframe with offset 1.
|
|
|
|
double offset = n ? i++ / double(n) : 1;
|
2021-03-11 15:04:54 +03:00
|
|
|
Keyframe& keyframe = processedKeyframes.LookupOrInsert(offset);
|
|
|
|
if (keyframe.mPropertyValues.IsEmpty()) {
|
|
|
|
keyframe.mComputedOffset = offset;
|
2016-03-22 10:25:38 +03:00
|
|
|
}
|
2017-06-14 06:43:47 +03:00
|
|
|
|
|
|
|
Maybe<PropertyValuePair> valuePair =
|
2018-04-24 16:51:55 +03:00
|
|
|
MakePropertyValuePair(pair.mProperty, stringValue, aDocument);
|
2017-06-14 06:43:47 +03:00
|
|
|
if (!valuePair) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-11 15:04:54 +03:00
|
|
|
keyframe.mPropertyValues.AppendElement(std::move(valuePair.ref()));
|
2016-03-22 10:25:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.SetCapacity(processedKeyframes.Count());
|
2021-03-11 15:04:54 +03:00
|
|
|
std::transform(processedKeyframes.begin(), processedKeyframes.end(),
|
|
|
|
MakeBackInserter(aResult), [](auto& entry) {
|
|
|
|
return std::move(*entry.GetModifiableData());
|
|
|
|
});
|
2016-03-22 10:25:38 +03:00
|
|
|
|
|
|
|
aResult.Sort(ComputedOffsetComparator());
|
2017-10-18 10:12:21 +03:00
|
|
|
|
|
|
|
// Fill in any specified offsets
|
|
|
|
//
|
|
|
|
// This corresponds to step 5, "Otherwise," branch, substeps 5-6 of
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#processing-a-keyframes-argument
|
2017-10-18 10:12:21 +03:00
|
|
|
const FallibleTArray<Nullable<double>>* offsets = nullptr;
|
|
|
|
AutoTArray<Nullable<double>, 1> singleOffset;
|
|
|
|
auto& offset = keyframeDict.mOffset;
|
|
|
|
if (offset.IsDouble()) {
|
|
|
|
singleOffset.AppendElement(offset.GetAsDouble());
|
|
|
|
// dom::Sequence is a fallible but AutoTArray is infallible and we need to
|
|
|
|
// point to one or the other. Fortunately, fallible and infallible array
|
|
|
|
// types can be implicitly converted provided they are const.
|
|
|
|
const FallibleTArray<Nullable<double>>& asFallibleArray = singleOffset;
|
|
|
|
offsets = &asFallibleArray;
|
|
|
|
} else if (offset.IsDoubleOrNullSequence()) {
|
|
|
|
offsets = &offset.GetAsDoubleOrNullSequence();
|
|
|
|
}
|
|
|
|
// If offset.IsNull() is true, then we want to leave the mOffset member of
|
|
|
|
// each keyframe with its initialized value of null. By leaving |offsets|
|
|
|
|
// as nullptr here, we skip updating mOffset below.
|
|
|
|
|
|
|
|
size_t offsetsToFill =
|
|
|
|
offsets ? std::min(offsets->Length(), aResult.Length()) : 0;
|
|
|
|
for (size_t i = 0; i < offsetsToFill; i++) {
|
|
|
|
if (!offsets->ElementAt(i).IsNull()) {
|
|
|
|
aResult[i].mOffset.emplace(offsets->ElementAt(i).Value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the keyframes are loosely sorted and that any specified offsets
|
|
|
|
// are between 0.0 and 1.0 inclusive.
|
|
|
|
//
|
|
|
|
// This corresponds to steps 6-7 of
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#processing-a-keyframes-argument
|
2017-10-18 10:12:21 +03:00
|
|
|
//
|
|
|
|
// In the spec, TypeErrors arising from invalid offsets and easings are thrown
|
|
|
|
// at the end of the procedure since it assumes we initially store easing
|
|
|
|
// values as strings and then later parse them.
|
|
|
|
//
|
|
|
|
// However, we will parse easing members immediately when we process them
|
|
|
|
// below. In order to maintain the relative order in which TypeErrors are
|
|
|
|
// thrown according to the spec, namely exceptions arising from invalid
|
|
|
|
// offsets are thrown before exceptions arising from invalid easings, we check
|
|
|
|
// the offsets here.
|
|
|
|
if (!HasValidOffsets(aResult)) {
|
|
|
|
aResult.Clear();
|
2019-09-20 05:19:18 +03:00
|
|
|
aRv.ThrowTypeError<dom::MSG_INVALID_KEYFRAME_OFFSETS>();
|
2017-10-18 10:12:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill in any easings.
|
|
|
|
//
|
|
|
|
// This corresponds to step 5, "Otherwise," branch, substeps 7-11 of
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#processing-a-keyframes-argument
|
2017-10-18 10:12:21 +03:00
|
|
|
FallibleTArray<Maybe<ComputedTimingFunction>> easings;
|
2020-12-17 17:04:35 +03:00
|
|
|
auto parseAndAppendEasing = [&](const nsACString& easingString,
|
2017-10-18 10:12:21 +03:00
|
|
|
ErrorResult& aRv) {
|
2020-11-12 23:34:01 +03:00
|
|
|
auto easing = TimingParams::ParseEasing(easingString, aRv);
|
2018-05-30 22:15:35 +03:00
|
|
|
if (!aRv.Failed() && !easings.AppendElement(std::move(easing), fallible)) {
|
2017-10-18 10:12:21 +03:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto& easing = keyframeDict.mEasing;
|
2020-12-17 17:04:35 +03:00
|
|
|
if (easing.IsUTF8String()) {
|
|
|
|
parseAndAppendEasing(easing.GetAsUTF8String(), aRv);
|
2017-10-18 10:12:21 +03:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
aResult.Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2020-12-17 17:04:35 +03:00
|
|
|
for (const auto& easingString : easing.GetAsUTF8StringSequence()) {
|
2017-10-18 10:12:21 +03:00
|
|
|
parseAndAppendEasing(easingString, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
aResult.Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If |easings| is empty, then we are supposed to fill it in with the value
|
|
|
|
// "linear" and then repeat the list as necessary.
|
|
|
|
//
|
|
|
|
// However, for Keyframe.mTimingFunction we represent "linear" as a None
|
|
|
|
// value. Since we have not assigned 'mTimingFunction' for any of the
|
|
|
|
// keyframes in |aResult| they will already have their initial None value
|
|
|
|
// (i.e. linear). As a result, if |easings| is empty, we don't need to do
|
|
|
|
// anything.
|
|
|
|
if (!easings.IsEmpty()) {
|
|
|
|
for (size_t i = 0; i < aResult.Length(); i++) {
|
|
|
|
aResult[i].mTimingFunction = easings[i % easings.Length()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill in any composite operations.
|
|
|
|
//
|
|
|
|
// This corresponds to step 5, "Otherwise," branch, substep 12 of
|
2017-12-15 23:55:08 +03:00
|
|
|
// https://drafts.csswg.org/web-animations/#processing-a-keyframes-argument
|
2018-07-14 03:23:03 +03:00
|
|
|
if (StaticPrefs::dom_animations_api_compositing_enabled()) {
|
2018-08-15 03:51:28 +03:00
|
|
|
const FallibleTArray<dom::CompositeOperationOrAuto>* compositeOps = nullptr;
|
|
|
|
AutoTArray<dom::CompositeOperationOrAuto, 1> singleCompositeOp;
|
2018-07-14 03:23:03 +03:00
|
|
|
auto& composite = keyframeDict.mComposite;
|
2018-08-15 03:51:28 +03:00
|
|
|
if (composite.IsCompositeOperationOrAuto()) {
|
|
|
|
singleCompositeOp.AppendElement(
|
|
|
|
composite.GetAsCompositeOperationOrAuto());
|
|
|
|
const FallibleTArray<dom::CompositeOperationOrAuto>& asFallibleArray =
|
2018-07-14 03:23:03 +03:00
|
|
|
singleCompositeOp;
|
|
|
|
compositeOps = &asFallibleArray;
|
2018-08-15 03:51:28 +03:00
|
|
|
} else if (composite.IsCompositeOperationOrAutoSequence()) {
|
|
|
|
compositeOps = &composite.GetAsCompositeOperationOrAutoSequence();
|
2018-07-14 03:23:03 +03:00
|
|
|
}
|
2017-10-18 10:12:21 +03:00
|
|
|
|
2018-07-14 03:23:03 +03:00
|
|
|
// Fill in and repeat as needed.
|
|
|
|
if (compositeOps && !compositeOps->IsEmpty()) {
|
|
|
|
size_t length = compositeOps->Length();
|
|
|
|
for (size_t i = 0; i < aResult.Length(); i++) {
|
2018-08-16 19:24:52 +03:00
|
|
|
aResult[i].mComposite = compositeOps->ElementAt(i % length);
|
2018-01-11 10:20:49 +03:00
|
|
|
}
|
2017-10-18 10:12:21 +03:00
|
|
|
}
|
|
|
|
}
|
2016-03-22 10:25:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the supplied set of keyframes has keyframe values for
|
|
|
|
* any property for which it does not also supply a value for the 0% and 100%
|
2018-07-14 03:23:03 +03:00
|
|
|
* offsets. The check is not entirely accurate but should detect most common
|
|
|
|
* cases.
|
2016-03-22 10:25:38 +03:00
|
|
|
*
|
|
|
|
* @param aKeyframes The set of keyframes to analyze.
|
|
|
|
* @param aDocument The document to use when parsing keyframes so we can
|
|
|
|
* try to detect where we have an invalid value at 0%/100%.
|
|
|
|
*/
|
2018-07-14 03:23:03 +03:00
|
|
|
static bool HasImplicitKeyframeValues(const nsTArray<Keyframe>& aKeyframes,
|
2019-02-15 09:05:06 +03:00
|
|
|
dom::Document* aDocument) {
|
2016-03-22 10:25:38 +03:00
|
|
|
// We are looking to see if that every property referenced in |aKeyframes|
|
|
|
|
// has a valid property at offset 0.0 and 1.0. The check as to whether a
|
|
|
|
// property is valid or not, however, is not precise. We only check if the
|
|
|
|
// property can be parsed, NOT whether it can also be converted to a
|
|
|
|
// StyleAnimationValue since doing that requires a target element bound to
|
|
|
|
// a document which we might not always have at the point where we want to
|
|
|
|
// perform this check.
|
|
|
|
//
|
2018-07-14 03:23:03 +03:00
|
|
|
// This is only a temporary measure until we ship implicit keyframes and
|
|
|
|
// remove the corresponding pref.
|
2016-03-22 10:25:38 +03:00
|
|
|
// So as long as this check catches most cases, and we don't do anything
|
|
|
|
// horrible in one of the cases we can't detect, it should be sufficient.
|
|
|
|
|
2016-08-17 04:46:58 +03:00
|
|
|
nsCSSPropertyIDSet properties; // All properties encountered.
|
|
|
|
nsCSSPropertyIDSet propertiesWithFromValue; // Those with a defined 0% value.
|
|
|
|
nsCSSPropertyIDSet propertiesWithToValue; // Those with a defined 100% value.
|
2016-03-22 10:25:38 +03:00
|
|
|
|
2016-08-17 04:37:48 +03:00
|
|
|
auto addToPropertySets = [&](nsCSSPropertyID aProperty, double aOffset) {
|
2016-03-22 10:25:38 +03:00
|
|
|
properties.AddProperty(aProperty);
|
|
|
|
if (aOffset == 0.0) {
|
|
|
|
propertiesWithFromValue.AddProperty(aProperty);
|
|
|
|
} else if (aOffset == 1.0) {
|
|
|
|
propertiesWithToValue.AddProperty(aProperty);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0, len = aKeyframes.Length(); i < len; i++) {
|
|
|
|
const Keyframe& frame = aKeyframes[i];
|
|
|
|
|
2017-06-15 05:47:32 +03:00
|
|
|
// We won't have called DistributeKeyframes when this is called so
|
2016-03-22 10:25:38 +03:00
|
|
|
// we can't use frame.mComputedOffset. Instead we do a rough version
|
|
|
|
// of that algorithm that substitutes null offsets with 0.0 for the first
|
|
|
|
// frame, 1.0 for the last frame, and 0.5 for everything else.
|
|
|
|
double computedOffset = i == len - 1 ? 1.0 : i == 0 ? 0.0 : 0.5;
|
|
|
|
double offsetToUse = frame.mOffset ? frame.mOffset.value() : computedOffset;
|
|
|
|
|
|
|
|
for (const PropertyValuePair& pair : frame.mPropertyValues) {
|
|
|
|
if (nsCSSProps::IsShorthand(pair.mProperty)) {
|
2018-03-25 20:42:10 +03:00
|
|
|
MOZ_ASSERT(pair.mServoDeclarationBlock);
|
2016-03-22 10:25:38 +03:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(prop, pair.mProperty,
|
2019-04-26 02:03:04 +03:00
|
|
|
CSSEnabledState::ForAllContent) {
|
2016-03-22 10:25:38 +03:00
|
|
|
addToPropertySets(*prop, offsetToUse);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addToPropertySets(pair.mProperty, offsetToUse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return !propertiesWithFromValue.Equals(properties) ||
|
|
|
|
!propertiesWithToValue.Equals(properties);
|
|
|
|
}
|
|
|
|
|
2016-05-10 12:40:53 +03:00
|
|
|
/**
|
2017-06-15 05:54:36 +03:00
|
|
|
* Distribute the offsets of all keyframes in between the endpoints of the
|
|
|
|
* given range.
|
2016-05-27 13:09:06 +03:00
|
|
|
*
|
2017-06-15 05:54:36 +03:00
|
|
|
* @param aRange The sequence of keyframes between whose endpoints we should
|
|
|
|
* distribute offsets.
|
2016-05-27 13:09:06 +03:00
|
|
|
*/
|
2017-06-15 05:54:36 +03:00
|
|
|
static void DistributeRange(const Range<Keyframe>& aRange) {
|
|
|
|
const Range<Keyframe> rangeToAdjust =
|
|
|
|
Range<Keyframe>(aRange.begin() + 1, aRange.end() - 1);
|
|
|
|
const size_t n = aRange.length() - 1;
|
|
|
|
const double startOffset = aRange[0].mComputedOffset;
|
|
|
|
const double diffOffset = aRange[n].mComputedOffset - startOffset;
|
|
|
|
for (auto iter = rangeToAdjust.begin(); iter != rangeToAdjust.end(); ++iter) {
|
|
|
|
size_t index = iter - aRange.begin();
|
2016-05-27 13:09:06 +03:00
|
|
|
iter->mComputedOffset = startOffset + double(index) / n * diffOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
} // namespace mozilla
|