Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 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 | |
| 35 | namespace WebCore { |
| 36 | |
| 37 | TextLinkColors::TextLinkColors() |
| 38 | : m_textColor(Color::black) |
| 39 | { |
| 40 | resetLinkColor(); |
| 41 | resetVisitedLinkColor(); |
| 42 | resetActiveLinkColor(); |
| 43 | } |
| 44 | |
| 45 | void TextLinkColors::resetLinkColor() |
| 46 | { |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 47 | m_linkColor = StyleColor(0, 0, 238); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void TextLinkColors::resetVisitedLinkColor() |
| 51 | { |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 52 | m_visitedLinkColor = StyleColor(85, 26, 139); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void TextLinkColors::resetActiveLinkColor() |
| 56 | { |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 57 | m_activeLinkColor = StyleColor(255, 0, 0); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static 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::defaultTheme()->systemColor(cssValueId); |
| 95 | } |
| 96 | |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 97 | StyleColor TextLinkColors::colorFromPrimitiveValue(const CSSPrimitiveValue* value, bool forVisitedLink) const |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 98 | { |
| 99 | if (value->isRGBColor()) |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 100 | return StyleColor(value->getRGBA32Value()); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 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::focusRingColor(); |
| 114 | case CSSValueCurrentcolor: |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 115 | return StyleColor::currentColor(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 116 | default: |
| 117 | return colorForCSSValue(valueID); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | } |