| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/animation/animatable/AnimatableColor.h" | 31 #include "core/animation/animatable/AnimatableColor.h" |
| 32 | 32 |
| 33 #include "platform/animation/AnimationUtilities.h" | |
| 34 | 33 |
| 35 namespace blink { | 34 namespace blink { |
| 36 | 35 |
| 37 AnimatableColorImpl::AnimatableColorImpl(float red, | 36 AnimatableColorImpl::AnimatableColorImpl(float red, |
| 38 float green, | 37 float green, |
| 39 float blue, | 38 float blue, |
| 40 float alpha) | 39 float alpha) |
| 41 : m_alpha(clampTo(alpha, 0.0f, 1.0f)), | 40 : m_alpha(clampTo(alpha, 0.0f, 1.0f)), |
| 42 m_red(clampTo(red, 0.0f, 1.0f)), | 41 m_red(clampTo(red, 0.0f, 1.0f)), |
| 43 m_green(clampTo(green, 0.0f, 1.0f)), | 42 m_green(clampTo(green, 0.0f, 1.0f)), |
| 44 m_blue(clampTo(blue, 0.0f, 1.0f)) {} | 43 m_blue(clampTo(blue, 0.0f, 1.0f)) {} |
| 45 | 44 |
| 46 AnimatableColorImpl::AnimatableColorImpl(Color color) | 45 AnimatableColorImpl::AnimatableColorImpl(Color color) |
| 47 : m_alpha(color.alpha() / 255.0f), | 46 : m_alpha(color.alpha() / 255.0f), |
| 48 m_red(color.red() / 255.0f * m_alpha), | 47 m_red(color.red() / 255.0f * m_alpha), |
| 49 m_green(color.green() / 255.0f * m_alpha), | 48 m_green(color.green() / 255.0f * m_alpha), |
| 50 m_blue(color.blue() / 255.0f * m_alpha) {} | 49 m_blue(color.blue() / 255.0f * m_alpha) {} |
| 51 | 50 |
| 52 Color AnimatableColorImpl::toColor() const { | |
| 53 if (!m_alpha) | |
| 54 return Color::transparent; | |
| 55 return Color(m_red / m_alpha, m_green / m_alpha, m_blue / m_alpha, m_alpha); | |
| 56 } | |
| 57 | |
| 58 AnimatableColorImpl AnimatableColorImpl::interpolateTo( | |
| 59 const AnimatableColorImpl& to, | |
| 60 double fraction) const { | |
| 61 return AnimatableColorImpl( | |
| 62 blend(m_red, to.m_red, fraction), blend(m_green, to.m_green, fraction), | |
| 63 blend(m_blue, to.m_blue, fraction), blend(m_alpha, to.m_alpha, fraction)); | |
| 64 } | |
| 65 | |
| 66 bool AnimatableColorImpl::operator==(const AnimatableColorImpl& other) const { | 51 bool AnimatableColorImpl::operator==(const AnimatableColorImpl& other) const { |
| 67 return m_red == other.m_red && m_green == other.m_green && | 52 return m_red == other.m_red && m_green == other.m_green && |
| 68 m_blue == other.m_blue && m_alpha == other.m_alpha; | 53 m_blue == other.m_blue && m_alpha == other.m_alpha; |
| 69 } | 54 } |
| 70 | 55 |
| 71 PassRefPtr<AnimatableColor> AnimatableColor::create( | 56 PassRefPtr<AnimatableColor> AnimatableColor::create( |
| 72 const AnimatableColorImpl& color, | 57 const AnimatableColorImpl& color, |
| 73 const AnimatableColorImpl& visitedLinkColor) { | 58 const AnimatableColorImpl& visitedLinkColor) { |
| 74 return adoptRef(new AnimatableColor(color, visitedLinkColor)); | 59 return adoptRef(new AnimatableColor(color, visitedLinkColor)); |
| 75 } | 60 } |
| 76 | 61 |
| 77 PassRefPtr<AnimatableValue> AnimatableColor::interpolateTo( | |
| 78 const AnimatableValue* value, | |
| 79 double fraction) const { | |
| 80 const AnimatableColor* color = toAnimatableColor(value); | |
| 81 return create( | |
| 82 m_color.interpolateTo(color->m_color, fraction), | |
| 83 m_visitedLinkColor.interpolateTo(color->m_visitedLinkColor, fraction)); | |
| 84 } | |
| 85 | |
| 86 bool AnimatableColor::equalTo(const AnimatableValue* value) const { | 62 bool AnimatableColor::equalTo(const AnimatableValue* value) const { |
| 87 const AnimatableColor* color = toAnimatableColor(value); | 63 const AnimatableColor* color = toAnimatableColor(value); |
| 88 return m_color == color->m_color && | 64 return m_color == color->m_color && |
| 89 m_visitedLinkColor == color->m_visitedLinkColor; | 65 m_visitedLinkColor == color->m_visitedLinkColor; |
| 90 } | 66 } |
| 91 | 67 |
| 92 } // namespace blink | 68 } // namespace blink |
| OLD | NEW |