blob: 60643ae2a8eab74ccc38330b236c7fe126262872 [file] [log] [blame]
Ben Murdoch591b9582013-07-10 11:41:44 +01001/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
4 * Copyright (C) 2013 Google Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "config.h"
24#include "core/css/resolver/ElementStyleResources.h"
25
Ben Murdoche69819b2013-07-17 14:56:49 +010026#include "core/css/CSSGradientValue.h"
27#include "core/css/CSSSVGDocumentValue.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010028#include "core/rendering/style/StyleGeneratedImage.h"
29#include "core/rendering/style/StyleImage.h"
30#include "core/rendering/style/StylePendingImage.h"
Torne (Richard Coles)a854de02013-12-18 16:25:25 +000031#include "platform/graphics/filters/FilterOperation.h"
Ben Murdoch591b9582013-07-10 11:41:44 +010032
33namespace WebCore {
34
35ElementStyleResources::ElementStyleResources()
Torne (Richard Coles)09380292014-02-21 12:17:33 +000036 : m_deviceScaleFactor(1)
Ben Murdoch591b9582013-07-10 11:41:44 +010037{
38}
39
Bo Liuf91f5fa2014-05-01 10:37:55 -070040PassRefPtr<StyleImage> ElementStyleResources::styleImage(Document& document, const TextLinkColors& textLinkColors, Color currentColor, CSSPropertyID property, CSSValue* value)
Ben Murdoch591b9582013-07-10 11:41:44 +010041{
Ben Murdoche69819b2013-07-17 14:56:49 +010042 if (value->isImageValue())
Bo Liuf91f5fa2014-05-01 10:37:55 -070043 return cachedOrPendingFromValue(document, property, toCSSImageValue(value));
Ben Murdoche69819b2013-07-17 14:56:49 +010044
45 if (value->isImageGeneratorValue()) {
46 if (value->isGradientValue())
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010047 return generatedOrPendingFromValue(property, toCSSGradientValue(value)->gradientWithStylesResolved(textLinkColors, currentColor).get());
48 return generatedOrPendingFromValue(property, toCSSImageGeneratorValue(value));
Ben Murdoche69819b2013-07-17 14:56:49 +010049 }
50
51 if (value->isImageSetValue())
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +010052 return setOrPendingFromValue(property, toCSSImageSetValue(value));
Ben Murdoche69819b2013-07-17 14:56:49 +010053
54 if (value->isCursorImageValue())
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010055 return cursorOrPendingFromValue(property, toCSSCursorImageValue(value));
Ben Murdoche69819b2013-07-17 14:56:49 +010056
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000057 return nullptr;
Ben Murdoche69819b2013-07-17 14:56:49 +010058}
59
60PassRefPtr<StyleImage> ElementStyleResources::generatedOrPendingFromValue(CSSPropertyID property, CSSImageGeneratorValue* value)
61{
62 if (value->isPending()) {
63 m_pendingImageProperties.set(property, value);
64 return StylePendingImage::create(value);
65 }
66 return StyleGeneratedImage::create(value);
67}
68
69PassRefPtr<StyleImage> ElementStyleResources::setOrPendingFromValue(CSSPropertyID property, CSSImageSetValue* value)
70{
71 RefPtr<StyleImage> image = value->cachedOrPendingImageSet(m_deviceScaleFactor);
72 if (image && image->isPendingImage())
73 m_pendingImageProperties.set(property, value);
74 return image.release();
75}
76
Bo Liuf91f5fa2014-05-01 10:37:55 -070077PassRefPtr<StyleImage> ElementStyleResources::cachedOrPendingFromValue(Document& document, CSSPropertyID property, CSSImageValue* value)
Ben Murdoche69819b2013-07-17 14:56:49 +010078{
79 RefPtr<StyleImage> image = value->cachedOrPendingImage();
Bo Liuf91f5fa2014-05-01 10:37:55 -070080 if (image) {
81 if (image->isPendingImage())
82 m_pendingImageProperties.set(property, value);
83 else
84 value->restoreCachedResourceIfNeeded(document);
85 }
Ben Murdoche69819b2013-07-17 14:56:49 +010086 return image.release();
87}
88
89PassRefPtr<StyleImage> ElementStyleResources::cursorOrPendingFromValue(CSSPropertyID property, CSSCursorImageValue* value)
90{
91 RefPtr<StyleImage> image = value->cachedOrPendingImage(m_deviceScaleFactor);
92 if (image && image->isPendingImage())
93 m_pendingImageProperties.set(property, value);
94 return image.release();
Ben Murdoch591b9582013-07-10 11:41:44 +010095}
96
Torne (Richard Coles)43e75022014-03-21 14:26:12 +000097void ElementStyleResources::clearPendingImageProperties()
98{
99 m_pendingImageProperties.clear();
100}
101
102void ElementStyleResources::clearPendingSVGDocuments()
103{
104 m_pendingSVGDocuments.clear();
105}
106
Ben Murdoch591b9582013-07-10 11:41:44 +0100107void ElementStyleResources::addPendingSVGDocument(FilterOperation* filterOperation, CSSSVGDocumentValue* cssSVGDocumentValue)
108{
109 m_pendingSVGDocuments.set(filterOperation, cssSVGDocumentValue);
110}
111
Ben Murdoch591b9582013-07-10 11:41:44 +0100112}