This source file includes following definitions.
- square
- m_blue
- m_blue
- toColor
- interpolateTo
- addWith
- distanceTo
- create
- interpolateTo
- addWith
- equalTo
- distanceTo
#include "config.h"
#include "core/animation/AnimatableColor.h"
#include "platform/animation/AnimationUtilities.h"
#include "wtf/MathExtras.h"
namespace {
double square(double x)
{
return x * x;
}
}
namespace WebCore {
AnimatableColorImpl::AnimatableColorImpl(float red, float green, float blue, float alpha)
: m_alpha(clampTo(alpha, 0.0f, 1.0f))
, m_red(clampTo(red, 0.0f, 1.0f))
, m_green(clampTo(green, 0.0f, 1.0f))
, m_blue(clampTo(blue, 0.0f, 1.0f))
{
}
AnimatableColorImpl::AnimatableColorImpl(Color color)
: m_alpha(color.alpha() / 255.0f)
, m_red(color.red() / 255.0f * m_alpha)
, m_green(color.green() / 255.0f * m_alpha)
, m_blue(color.blue() / 255.0f * m_alpha)
{
}
Color AnimatableColorImpl::toColor() const
{
if (!m_alpha)
return Color::transparent;
return Color(m_red / m_alpha, m_green / m_alpha, m_blue / m_alpha, m_alpha);
}
AnimatableColorImpl AnimatableColorImpl::interpolateTo(const AnimatableColorImpl& to, double fraction) const
{
return AnimatableColorImpl(blend(m_red, to.m_red, fraction),
blend(m_green, to.m_green, fraction),
blend(m_blue, to.m_blue, fraction),
blend(m_alpha, to.m_alpha, fraction));
}
AnimatableColorImpl AnimatableColorImpl::addWith(const AnimatableColorImpl& addend) const
{
return AnimatableColorImpl(m_red + addend.m_red,
m_green + addend.m_green,
m_blue + addend.m_blue,
m_alpha + addend.m_alpha);
}
bool AnimatableColorImpl::operator==(const AnimatableColorImpl& other) const
{
return m_red == other.m_red
&& m_green == other.m_green
&& m_blue == other.m_blue
&& m_alpha == other.m_alpha;
}
double AnimatableColorImpl::distanceTo(const AnimatableColorImpl& other) const
{
return sqrt(square(m_red - other.m_red)
+ square(m_green - other.m_green)
+ square(m_blue - other.m_blue)
+ square(m_alpha - other.m_alpha));
}
PassRefPtrWillBeRawPtr<AnimatableColor> AnimatableColor::create(const AnimatableColorImpl& color, const AnimatableColorImpl& visitedLinkColor)
{
return adoptRefWillBeNoop(new AnimatableColor(color, visitedLinkColor));
}
PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableColor::interpolateTo(const AnimatableValue* value, double fraction) const
{
const AnimatableColor* color = toAnimatableColor(value);
return create(m_color.interpolateTo(color->m_color, fraction),
m_visitedLinkColor.interpolateTo(color->m_visitedLinkColor, fraction));
}
PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableColor::addWith(const AnimatableValue* value) const
{
const AnimatableColor* color = toAnimatableColor(value);
return create(m_color.addWith(color->m_color),
m_visitedLinkColor.addWith(color->m_visitedLinkColor));
}
bool AnimatableColor::equalTo(const AnimatableValue* value) const
{
const AnimatableColor* color = toAnimatableColor(value);
return m_color == color->m_color && m_visitedLinkColor == color->m_visitedLinkColor;
}
double AnimatableColor::distanceTo(const AnimatableValue* value) const
{
const AnimatableColor* color = toAnimatableColor(value);
return m_color.distanceTo(color->m_color);
}
}