Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 25 ASSERT(m_isSingle); | 25 ASSERT(m_isSingle); |
| 26 return m_start; | 26 return m_start; |
| 27 } | 27 } |
| 28 | 28 |
| 29 EVisibility visibility(double fraction) const | 29 EVisibility visibility(double fraction) const |
| 30 { | 30 { |
| 31 if (m_isSingle || fraction <= 0) | 31 if (m_isSingle || fraction <= 0) |
| 32 return m_start; | 32 return m_start; |
| 33 if (fraction >= 1) | 33 if (fraction >= 1) |
| 34 return m_end; | 34 return m_end; |
| 35 if (m_start == VISIBLE || m_end == VISIBLE) | 35 if (m_start == EVisibility::Visible || m_end == EVisibility::Visible) |
| 36 return VISIBLE; | 36 return EVisibility::Visible; |
| 37 return fraction < 0.5 ? m_start : m_end; | 37 return fraction < 0.5 ? m_start : m_end; |
| 38 } | 38 } |
| 39 | 39 |
| 40 DECLARE_NON_INTERPOLABLE_VALUE_TYPE(); | 40 DECLARE_NON_INTERPOLABLE_VALUE_TYPE(); |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 CSSVisibilityNonInterpolableValue(EVisibility start, EVisibility end) | 43 CSSVisibilityNonInterpolableValue(EVisibility start, EVisibility end) |
| 44 : m_start(start) | 44 : m_start(start) |
| 45 , m_end(end) | 45 , m_end(end) |
| 46 , m_isSingle(m_start == m_end) | 46 , m_isSingle(m_start == m_end) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 | 80 |
| 81 class ParentVisibilityChecker : public InterpolationType::ConversionChecker { | 81 class ParentVisibilityChecker : public InterpolationType::ConversionChecker { |
| 82 public: | 82 public: |
| 83 static std::unique_ptr<ParentVisibilityChecker> create(EVisibility visibilit y) | 83 static std::unique_ptr<ParentVisibilityChecker> create(EVisibility visibilit y) |
| 84 { | 84 { |
| 85 return wrapUnique(new ParentVisibilityChecker(visibility)); | 85 return wrapUnique(new ParentVisibilityChecker(visibility)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 ParentVisibilityChecker(EVisibility visibility) | 89 ParentVisibilityChecker(EVisibility visibility) |
| 90 : m_visibility(visibility) | 90 : m_visibility(static_cast<double>(visibility)) |
| 91 { } | 91 { } |
| 92 | 92 |
| 93 bool isValid(const InterpolationEnvironment& environment, const Interpolatio nValue& underlying) const final | 93 bool isValid(const InterpolationEnvironment& environment, const Interpolatio nValue& underlying) const final |
| 94 { | 94 { |
| 95 return m_visibility == environment.state().parentStyle()->visibility(); | 95 return static_cast<EVisibility>(m_visibility) == environment.state().par entStyle()->visibility(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 // TODO(sashab): Why is this being stored as a double? | |
|
Bugs Nash
2016/07/28 01:25:12
Should a question be put in as a TODO? Maybe do th
sashab
2016/07/29 06:25:50
Seems to be added by alancutter@ here:
https://cod
alancutter (OOO until 2018)
2016/07/29 09:16:47
This is indeed a mistake, feel free to make it sto
| |
| 98 const double m_visibility; | 99 const double m_visibility; |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 InterpolationValue CSSVisibilityInterpolationType::createVisibilityValue(EVisibi lity visibility) const | 102 InterpolationValue CSSVisibilityInterpolationType::createVisibilityValue(EVisibi lity visibility) const |
| 102 { | 103 { |
| 103 return InterpolationValue(InterpolableNumber::create(0), CSSVisibilityNonInt erpolableValue::create(visibility, visibility)); | 104 return InterpolationValue(InterpolableNumber::create(0), CSSVisibilityNonInt erpolableValue::create(visibility, visibility)); |
| 104 } | 105 } |
| 105 | 106 |
| 106 InterpolationValue CSSVisibilityInterpolationType::maybeConvertNeutral(const Int erpolationValue& underlying, ConversionCheckers& conversionCheckers) const | 107 InterpolationValue CSSVisibilityInterpolationType::maybeConvertNeutral(const Int erpolationValue& underlying, ConversionCheckers& conversionCheckers) const |
| 107 { | 108 { |
| 108 double underlyingFraction = toInterpolableNumber(*underlying.interpolableVal ue).value(); | 109 double underlyingFraction = toInterpolableNumber(*underlying.interpolableVal ue).value(); |
| 109 EVisibility underlyingVisibility = toCSSVisibilityNonInterpolableValue(*unde rlying.nonInterpolableValue).visibility(underlyingFraction); | 110 EVisibility underlyingVisibility = toCSSVisibilityNonInterpolableValue(*unde rlying.nonInterpolableValue).visibility(underlyingFraction); |
| 110 conversionCheckers.append(UnderlyingVisibilityChecker::create(underlyingVisi bility)); | 111 conversionCheckers.append(UnderlyingVisibilityChecker::create(underlyingVisi bility)); |
| 111 return createVisibilityValue(underlyingVisibility); | 112 return createVisibilityValue(underlyingVisibility); |
| 112 } | 113 } |
| 113 | 114 |
| 114 InterpolationValue CSSVisibilityInterpolationType::maybeConvertInitial(const Sty leResolverState&, ConversionCheckers&) const | 115 InterpolationValue CSSVisibilityInterpolationType::maybeConvertInitial(const Sty leResolverState&, ConversionCheckers&) const |
| 115 { | 116 { |
| 116 return createVisibilityValue(VISIBLE); | 117 return createVisibilityValue(EVisibility::Visible); |
| 117 } | 118 } |
| 118 | 119 |
| 119 InterpolationValue CSSVisibilityInterpolationType::maybeConvertInherit(const Sty leResolverState& state, ConversionCheckers& conversionCheckers) const | 120 InterpolationValue CSSVisibilityInterpolationType::maybeConvertInherit(const Sty leResolverState& state, ConversionCheckers& conversionCheckers) const |
| 120 { | 121 { |
| 121 if (!state.parentStyle()) | 122 if (!state.parentStyle()) |
| 122 return nullptr; | 123 return nullptr; |
| 123 EVisibility inheritedVisibility = state.parentStyle()->visibility(); | 124 EVisibility inheritedVisibility = state.parentStyle()->visibility(); |
| 124 conversionCheckers.append(ParentVisibilityChecker::create(inheritedVisibilit y)); | 125 conversionCheckers.append(ParentVisibilityChecker::create(inheritedVisibilit y)); |
| 125 return createVisibilityValue(inheritedVisibility); | 126 return createVisibilityValue(inheritedVisibility); |
| 126 } | 127 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 | 166 |
| 166 void CSSVisibilityInterpolationType::apply(const InterpolableValue& interpolable Value, const NonInterpolableValue* nonInterpolableValue, InterpolationEnvironmen t& environment) const | 167 void CSSVisibilityInterpolationType::apply(const InterpolableValue& interpolable Value, const NonInterpolableValue* nonInterpolableValue, InterpolationEnvironmen t& environment) const |
| 167 { | 168 { |
| 168 // Visibility interpolation has been deferred to application time here due t o its non-linear behaviour. | 169 // Visibility interpolation has been deferred to application time here due t o its non-linear behaviour. |
| 169 double fraction = toInterpolableNumber(interpolableValue).value(); | 170 double fraction = toInterpolableNumber(interpolableValue).value(); |
| 170 EVisibility visibility = toCSSVisibilityNonInterpolableValue(nonInterpolable Value)->visibility(fraction); | 171 EVisibility visibility = toCSSVisibilityNonInterpolableValue(nonInterpolable Value)->visibility(fraction); |
| 171 environment.state().style()->setVisibility(visibility); | 172 environment.state().style()->setVisibility(visibility); |
| 172 } | 173 } |
| 173 | 174 |
| 174 } // namespace blink | 175 } // namespace blink |
| OLD | NEW |