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