1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4 *           (C) 2001 Dirk Mueller (mueller@kde.org)
5 *           (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
9 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
10 * Copyright (C) 2013 Google Inc. All rights reserved.
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public License
23 * along with this library; see the file COPYING.LIB.  If not, write to
24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA.
26 */
27
28#include "config.h"
29#include "core/dom/TextLinkColors.h"
30
31#include "core/css/CSSPrimitiveValue.h"
32#include "core/rendering/RenderTheme.h"
33#include "wtf/text/WTFString.h"
34
35namespace blink {
36
37TextLinkColors::TextLinkColors()
38    : m_textColor(Color::black)
39{
40    resetLinkColor();
41    resetVisitedLinkColor();
42    resetActiveLinkColor();
43}
44
45void TextLinkColors::resetLinkColor()
46{
47    m_linkColor = Color(0, 0, 238);
48}
49
50void TextLinkColors::resetVisitedLinkColor()
51{
52    m_visitedLinkColor = Color(85, 26, 139);
53}
54
55void TextLinkColors::resetActiveLinkColor()
56{
57    m_activeLinkColor = Color(255, 0, 0);
58}
59
60static Color colorForCSSValue(CSSValueID cssValueId)
61{
62    struct ColorValue {
63        CSSValueID cssValueId;
64        RGBA32 color;
65    };
66
67    static const ColorValue colorValues[] = {
68        { CSSValueAqua, 0xFF00FFFF },
69        { CSSValueBlack, 0xFF000000 },
70        { CSSValueBlue, 0xFF0000FF },
71        { CSSValueFuchsia, 0xFFFF00FF },
72        { CSSValueGray, 0xFF808080 },
73        { CSSValueGreen, 0xFF008000  },
74        { CSSValueGrey, 0xFF808080 },
75        { CSSValueLime, 0xFF00FF00 },
76        { CSSValueMaroon, 0xFF800000 },
77        { CSSValueNavy, 0xFF000080 },
78        { CSSValueOlive, 0xFF808000  },
79        { CSSValueOrange, 0xFFFFA500 },
80        { CSSValuePurple, 0xFF800080 },
81        { CSSValueRed, 0xFFFF0000 },
82        { CSSValueSilver, 0xFFC0C0C0 },
83        { CSSValueTeal, 0xFF008080  },
84        { CSSValueTransparent, 0x00000000 },
85        { CSSValueWhite, 0xFFFFFFFF },
86        { CSSValueYellow, 0xFFFFFF00 },
87        { CSSValueInvalid, CSSValueInvalid }
88    };
89
90    for (const ColorValue* col = colorValues; col->cssValueId; ++col) {
91        if (col->cssValueId == cssValueId)
92            return col->color;
93    }
94    return RenderTheme::theme().systemColor(cssValueId);
95}
96
97Color TextLinkColors::colorFromPrimitiveValue(const CSSPrimitiveValue* value, Color currentColor, bool forVisitedLink) const
98{
99    if (value->isRGBColor())
100        return Color(value->getRGBA32Value());
101
102    CSSValueID valueID = value->getValueID();
103    switch (valueID) {
104    case 0:
105        return Color();
106    case CSSValueWebkitText:
107        return textColor();
108    case CSSValueWebkitLink:
109        return forVisitedLink ? visitedLinkColor() : linkColor();
110    case CSSValueWebkitActivelink:
111        return activeLinkColor();
112    case CSSValueWebkitFocusRingColor:
113        return RenderTheme::theme().focusRingColor();
114    case CSSValueInvert: // We don't support outline-color: invert
115    case CSSValueCurrentcolor:
116        return currentColor;
117    default:
118        return colorForCSSValue(valueID);
119    }
120}
121
122}
123