DeprecatedCSSOMRGBColor.h [plain text]
#pragma once
#include "DeprecatedCSSOMPrimitiveValue.h"
#include "RGBColor.h"
#include <wtf/RefPtr.h>
namespace WebCore {
class DeprecatedCSSOMRGBColor final : public RefCounted<DeprecatedCSSOMRGBColor> {
public:
static Ref<DeprecatedCSSOMRGBColor> create(const RGBColor& color, CSSStyleDeclaration& owner)
{
return adoptRef(*new DeprecatedCSSOMRGBColor(color, owner));
}
DeprecatedCSSOMPrimitiveValue* red() { return m_red.get(); }
DeprecatedCSSOMPrimitiveValue* green() { return m_green.get(); }
DeprecatedCSSOMPrimitiveValue* blue() { return m_blue.get(); }
DeprecatedCSSOMPrimitiveValue* alpha() { return m_alpha.get(); }
Color color() const { return Color(m_rgbColor); }
private:
DeprecatedCSSOMRGBColor(const RGBColor& color, CSSStyleDeclaration& owner)
: m_rgbColor(color.rgbColor())
{
unsigned value = (m_rgbColor >> 16) & 0xFF;
auto result = CSSPrimitiveValue::create(value, CSSPrimitiveValue::CSS_NUMBER);
m_red = result->createDeprecatedCSSOMPrimitiveWrapper(owner);
value = (m_rgbColor >> 8) & 0xFF;
result = CSSPrimitiveValue::create(value, CSSPrimitiveValue::CSS_NUMBER);
m_green = result->createDeprecatedCSSOMPrimitiveWrapper(owner);
value = m_rgbColor & 0xFF;
result = CSSPrimitiveValue::create(value, CSSPrimitiveValue::CSS_NUMBER);
m_blue = result->createDeprecatedCSSOMPrimitiveWrapper(owner);
float alphaValue = static_cast<float>((m_rgbColor >> 24) & 0xFF) / 0xFF;
result = CSSPrimitiveValue::create(alphaValue, CSSPrimitiveValue::CSS_NUMBER);
m_alpha = result->createDeprecatedCSSOMPrimitiveWrapper(owner);
}
RGBA32 m_rgbColor;
RefPtr<DeprecatedCSSOMPrimitiveValue> m_red;
RefPtr<DeprecatedCSSOMPrimitiveValue> m_green;
RefPtr<DeprecatedCSSOMPrimitiveValue> m_blue;
RefPtr<DeprecatedCSSOMPrimitiveValue> m_alpha;
};
}