| 1 | /* |
| 2 | * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 | * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #pragma once |
| 22 | |
| 23 | #include "DeprecatedCSSOMPrimitiveValue.h" |
| 24 | #include "RGBColor.h" |
| 25 | #include <wtf/RefPtr.h> |
| 26 | |
| 27 | namespace WebCore { |
| 28 | |
| 29 | class DeprecatedCSSOMRGBColor final : public RefCounted<DeprecatedCSSOMRGBColor> { |
| 30 | public: |
| 31 | static Ref<DeprecatedCSSOMRGBColor> create(const RGBColor& color, CSSStyleDeclaration& owner) |
| 32 | { |
| 33 | return adoptRef(*new DeprecatedCSSOMRGBColor(color, owner)); |
| 34 | } |
| 35 | |
| 36 | DeprecatedCSSOMPrimitiveValue* red() { return m_red.get(); } |
| 37 | DeprecatedCSSOMPrimitiveValue* green() { return m_green.get(); } |
| 38 | DeprecatedCSSOMPrimitiveValue* blue() { return m_blue.get(); } |
| 39 | DeprecatedCSSOMPrimitiveValue* alpha() { return m_alpha.get(); } |
| 40 | |
| 41 | Color color() const { return Color(m_rgbColor); } |
| 42 | |
| 43 | private: |
| 44 | DeprecatedCSSOMRGBColor(const RGBColor& color, CSSStyleDeclaration& owner) |
| 45 | : m_rgbColor(color.rgbColor()) |
| 46 | { |
| 47 | // Red |
| 48 | unsigned value = (m_rgbColor >> 16) & 0xFF; |
| 49 | auto result = CSSPrimitiveValue::create(value, CSSPrimitiveValue::CSS_NUMBER); |
| 50 | m_red = result->createDeprecatedCSSOMPrimitiveWrapper(owner); |
| 51 | |
| 52 | // Green |
| 53 | value = (m_rgbColor >> 8) & 0xFF; |
| 54 | result = CSSPrimitiveValue::create(value, CSSPrimitiveValue::CSS_NUMBER); |
| 55 | m_green = result->createDeprecatedCSSOMPrimitiveWrapper(owner); |
| 56 | |
| 57 | // Blue |
| 58 | value = m_rgbColor & 0xFF; |
| 59 | result = CSSPrimitiveValue::create(value, CSSPrimitiveValue::CSS_NUMBER); |
| 60 | m_blue = result->createDeprecatedCSSOMPrimitiveWrapper(owner); |
| 61 | |
| 62 | // Alpha |
| 63 | float alphaValue = static_cast<float>((m_rgbColor >> 24) & 0xFF) / 0xFF; |
| 64 | result = CSSPrimitiveValue::create(alphaValue, CSSPrimitiveValue::CSS_NUMBER); |
| 65 | m_alpha = result->createDeprecatedCSSOMPrimitiveWrapper(owner); |
| 66 | } |
| 67 | |
| 68 | RGBA32 m_rgbColor; |
| 69 | RefPtr<DeprecatedCSSOMPrimitiveValue> m_red; |
| 70 | RefPtr<DeprecatedCSSOMPrimitiveValue> m_green; |
| 71 | RefPtr<DeprecatedCSSOMPrimitiveValue> m_blue; |
| 72 | RefPtr<DeprecatedCSSOMPrimitiveValue> m_alpha; |
| 73 | }; |
| 74 | |
| 75 | } // namespace WebCore |
| 76 | |