Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "AnimValuesStyleRule.h"
8 : #include "nsRuleData.h"
9 : #include "mozilla/GeckoStyleContext.h"
10 :
11 : namespace mozilla {
12 :
13 104 : NS_IMPL_ISUPPORTS(AnimValuesStyleRule, nsIStyleRule)
14 :
15 : void
16 116 : AnimValuesStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
17 : {
18 116 : GeckoStyleContext *contextParent = aRuleData->mStyleContext->GetParent();
19 116 : if (contextParent && contextParent->HasPseudoElementData()) {
20 : // Don't apply transitions or animations to things inside of
21 : // pseudo-elements.
22 : // FIXME (Bug 522599): Add tests for this.
23 :
24 : // Prevent structs from being cached on the rule node since we're inside
25 : // a pseudo-element, as we could determine cacheability differently
26 : // when walking the rule tree for a style context that is not inside
27 : // a pseudo-element. Note that nsRuleNode::GetStyle##name_ and GetStyleData
28 : // will never look at cached structs when we're animating things inside
29 : // a pseduo-element, so that we don't incorrectly return a struct that
30 : // is only appropriate for non-pseudo-elements.
31 0 : aRuleData->mConditions.SetUncacheable();
32 0 : return;
33 : }
34 :
35 232 : for (auto iter = mAnimationValues.ConstIter(); !iter.Done(); iter.Next()) {
36 116 : nsCSSPropertyID property = static_cast<nsCSSPropertyID>(iter.Key());
37 232 : if (aRuleData->mSIDs & nsCachedStyleData::GetBitForSID(
38 116 : nsCSSProps::kSIDTable[property])) {
39 18 : nsCSSValue *prop = aRuleData->ValueFor(property);
40 18 : if (prop->GetUnit() == eCSSUnit_Null) {
41 : DebugOnly<bool> ok =
42 20 : StyleAnimationValue::UncomputeValue(property, iter.Data(),
43 20 : *prop);
44 10 : MOZ_ASSERT(ok, "could not store computed value");
45 : }
46 : }
47 : }
48 : }
49 :
50 : bool
51 0 : AnimValuesStyleRule::MightMapInheritedStyleData()
52 : {
53 0 : return mStyleBits & NS_STYLE_INHERITED_STRUCT_MASK;
54 : }
55 :
56 : bool
57 0 : AnimValuesStyleRule::GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
58 : nsCSSValue* aValue)
59 : {
60 0 : MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet");
61 : return false;
62 : }
63 :
64 : void
65 4 : AnimValuesStyleRule::AddValue(nsCSSPropertyID aProperty,
66 : const StyleAnimationValue &aValue)
67 : {
68 4 : MOZ_ASSERT(aProperty != eCSSProperty_UNKNOWN,
69 : "Unexpected css property");
70 4 : mAnimationValues.Put(aProperty, aValue);
71 4 : mStyleBits |=
72 4 : nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[aProperty]);
73 4 : }
74 :
75 : void
76 4 : AnimValuesStyleRule::AddValue(nsCSSPropertyID aProperty,
77 : StyleAnimationValue&& aValue)
78 : {
79 4 : MOZ_ASSERT(aProperty != eCSSProperty_UNKNOWN,
80 : "Unexpected css property");
81 4 : mAnimationValues.Put(aProperty, Move(aValue));
82 4 : mStyleBits |=
83 4 : nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[aProperty]);
84 4 : }
85 :
86 : bool
87 0 : AnimValuesStyleRule::GetValue(nsCSSPropertyID aProperty,
88 : StyleAnimationValue& aValue) const
89 : {
90 0 : return mAnimationValues.Get(aProperty, &aValue);
91 : }
92 :
93 : #ifdef DEBUG
94 : void
95 0 : AnimValuesStyleRule::List(FILE* out, int32_t aIndent) const
96 : {
97 0 : nsAutoCString str;
98 0 : for (int32_t index = aIndent; --index >= 0; ) {
99 0 : str.AppendLiteral(" ");
100 : }
101 0 : str.AppendLiteral("[anim values] { ");
102 0 : for (auto iter = mAnimationValues.ConstIter(); !iter.Done(); iter.Next()) {
103 0 : nsCSSPropertyID property = static_cast<nsCSSPropertyID>(iter.Key());
104 0 : str.Append(nsCSSProps::GetStringValue(property));
105 0 : str.AppendLiteral(": ");
106 0 : nsAutoString value;
107 : Unused <<
108 0 : StyleAnimationValue::UncomputeValue(property, iter.Data(), value);
109 0 : AppendUTF16toUTF8(value, str);
110 0 : str.AppendLiteral("; ");
111 : }
112 0 : str.AppendLiteral("}\n");
113 0 : fprintf_stderr(out, "%s", str.get());
114 0 : }
115 : #endif
116 :
117 : } // namespace mozilla
|