OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/animation/CSSVisibilityInterpolationType.h" | 5 #include "core/animation/CSSVisibilityInterpolationType.h" |
6 | 6 |
7 #include "core/css/CSSPrimitiveValueMappings.h" | 7 #include "core/css/CSSPrimitiveValueMappings.h" |
8 #include "core/css/resolver/StyleResolverState.h" | 8 #include "core/css/resolver/StyleResolverState.h" |
9 #include "wtf/PtrUtil.h" | 9 #include "wtf/PtrUtil.h" |
10 #include <memory> | 10 #include <memory> |
(...skipping 12 matching lines...) Expand all Loading... |
23 EVisibility visibility() const { | 23 EVisibility visibility() const { |
24 DCHECK(m_isSingle); | 24 DCHECK(m_isSingle); |
25 return m_start; | 25 return m_start; |
26 } | 26 } |
27 | 27 |
28 EVisibility visibility(double fraction) const { | 28 EVisibility visibility(double fraction) const { |
29 if (m_isSingle || fraction <= 0) | 29 if (m_isSingle || fraction <= 0) |
30 return m_start; | 30 return m_start; |
31 if (fraction >= 1) | 31 if (fraction >= 1) |
32 return m_end; | 32 return m_end; |
33 if (m_start == EVisibility::kVisible || m_end == EVisibility::kVisible) | 33 DCHECK(m_start == EVisibility::kVisible || m_end == EVisibility::kVisible); |
34 return EVisibility::kVisible; | 34 return EVisibility::kVisible; |
35 return fraction < 0.5 ? m_start : m_end; | |
36 } | 35 } |
37 | 36 |
38 DECLARE_NON_INTERPOLABLE_VALUE_TYPE(); | 37 DECLARE_NON_INTERPOLABLE_VALUE_TYPE(); |
39 | 38 |
40 private: | 39 private: |
41 CSSVisibilityNonInterpolableValue(EVisibility start, EVisibility end) | 40 CSSVisibilityNonInterpolableValue(EVisibility start, EVisibility end) |
42 : m_start(start), m_end(end), m_isSingle(m_start == m_end) {} | 41 : m_start(start), m_end(end), m_isSingle(m_start == m_end) {} |
43 | 42 |
44 const EVisibility m_start; | 43 const EVisibility m_start; |
45 const EVisibility m_end; | 44 const EVisibility m_end; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 153 |
155 InterpolationValue | 154 InterpolationValue |
156 CSSVisibilityInterpolationType::maybeConvertStandardPropertyUnderlyingValue( | 155 CSSVisibilityInterpolationType::maybeConvertStandardPropertyUnderlyingValue( |
157 const ComputedStyle& style) const { | 156 const ComputedStyle& style) const { |
158 return createVisibilityValue(style.visibility()); | 157 return createVisibilityValue(style.visibility()); |
159 } | 158 } |
160 | 159 |
161 PairwiseInterpolationValue CSSVisibilityInterpolationType::maybeMergeSingles( | 160 PairwiseInterpolationValue CSSVisibilityInterpolationType::maybeMergeSingles( |
162 InterpolationValue&& start, | 161 InterpolationValue&& start, |
163 InterpolationValue&& end) const { | 162 InterpolationValue&& end) const { |
164 return PairwiseInterpolationValue( | 163 EVisibility startVisibility = |
165 InterpolableNumber::create(0), InterpolableNumber::create(1), | 164 toCSSVisibilityNonInterpolableValue(*start.nonInterpolableValue) |
166 CSSVisibilityNonInterpolableValue::create( | 165 .visibility(); |
167 toCSSVisibilityNonInterpolableValue(*start.nonInterpolableValue) | 166 EVisibility endVisibility = |
168 .visibility(), | 167 toCSSVisibilityNonInterpolableValue(*end.nonInterpolableValue) |
169 toCSSVisibilityNonInterpolableValue(*end.nonInterpolableValue) | 168 .visibility(); |
170 .visibility())); | 169 // One side must be "visible". |
| 170 // Spec: https://drafts.csswg.org/css-transitions/#animtype-visibility |
| 171 if (startVisibility != endVisibility && |
| 172 startVisibility != EVisibility::kVisible && |
| 173 endVisibility != EVisibility::kVisible) { |
| 174 return nullptr; |
| 175 } |
| 176 return PairwiseInterpolationValue(InterpolableNumber::create(0), |
| 177 InterpolableNumber::create(1), |
| 178 CSSVisibilityNonInterpolableValue::create( |
| 179 startVisibility, endVisibility)); |
171 } | 180 } |
172 | 181 |
173 void CSSVisibilityInterpolationType::composite( | 182 void CSSVisibilityInterpolationType::composite( |
174 UnderlyingValueOwner& underlyingValueOwner, | 183 UnderlyingValueOwner& underlyingValueOwner, |
175 double underlyingFraction, | 184 double underlyingFraction, |
176 const InterpolationValue& value, | 185 const InterpolationValue& value, |
177 double interpolationFraction) const { | 186 double interpolationFraction) const { |
178 underlyingValueOwner.set(*this, value); | 187 underlyingValueOwner.set(*this, value); |
179 } | 188 } |
180 | 189 |
181 void CSSVisibilityInterpolationType::applyStandardPropertyValue( | 190 void CSSVisibilityInterpolationType::applyStandardPropertyValue( |
182 const InterpolableValue& interpolableValue, | 191 const InterpolableValue& interpolableValue, |
183 const NonInterpolableValue* nonInterpolableValue, | 192 const NonInterpolableValue* nonInterpolableValue, |
184 StyleResolverState& state) const { | 193 StyleResolverState& state) const { |
185 // Visibility interpolation has been deferred to application time here due to | 194 // Visibility interpolation has been deferred to application time here due to |
186 // its non-linear behaviour. | 195 // its non-linear behaviour. |
187 double fraction = toInterpolableNumber(interpolableValue).value(); | 196 double fraction = toInterpolableNumber(interpolableValue).value(); |
188 EVisibility visibility = | 197 EVisibility visibility = |
189 toCSSVisibilityNonInterpolableValue(nonInterpolableValue) | 198 toCSSVisibilityNonInterpolableValue(nonInterpolableValue) |
190 ->visibility(fraction); | 199 ->visibility(fraction); |
191 state.style()->setVisibility(visibility); | 200 state.style()->setVisibility(visibility); |
192 } | 201 } |
193 | 202 |
194 } // namespace blink | 203 } // namespace blink |
OLD | NEW |