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.
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.
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.
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.
24 #include "core/css/resolver/ElementStyleResources.h"
26 #include "core/css/CSSGradientValue.h"
27 #include "core/css/CSSSVGDocumentValue.h"
28 #include "core/rendering/style/StyleGeneratedImage.h"
29 #include "core/rendering/style/StyleImage.h"
30 #include "core/rendering/style/StylePendingImage.h"
31 #include "platform/graphics/filters/FilterOperation.h"
35 ElementStyleResources::ElementStyleResources()
36 : m_deviceScaleFactor(1)
40 PassRefPtr<StyleImage> ElementStyleResources::styleImage(Document& document, const TextLinkColors& textLinkColors, Color currentColor, CSSPropertyID property, CSSValue* value)
42 if (value->isImageValue())
43 return cachedOrPendingFromValue(document, property, toCSSImageValue(value));
45 if (value->isImageGeneratorValue()) {
46 if (value->isGradientValue())
47 return generatedOrPendingFromValue(property, toCSSGradientValue(value)->gradientWithStylesResolved(textLinkColors, currentColor).get());
48 return generatedOrPendingFromValue(property, toCSSImageGeneratorValue(value));
51 if (value->isImageSetValue())
52 return setOrPendingFromValue(property, toCSSImageSetValue(value));
54 if (value->isCursorImageValue())
55 return cursorOrPendingFromValue(property, toCSSCursorImageValue(value));
60 PassRefPtr<StyleImage> ElementStyleResources::generatedOrPendingFromValue(CSSPropertyID property, CSSImageGeneratorValue* value)
62 if (value->isPending()) {
63 m_pendingImageProperties.set(property, value);
64 return StylePendingImage::create(value);
66 return StyleGeneratedImage::create(value);
69 PassRefPtr<StyleImage> ElementStyleResources::setOrPendingFromValue(CSSPropertyID property, CSSImageSetValue* value)
71 RefPtr<StyleImage> image = value->cachedOrPendingImageSet(m_deviceScaleFactor);
72 if (image && image->isPendingImage())
73 m_pendingImageProperties.set(property, value);
74 return image.release();
77 PassRefPtr<StyleImage> ElementStyleResources::cachedOrPendingFromValue(Document& document, CSSPropertyID property, CSSImageValue* value)
79 RefPtr<StyleImage> image = value->cachedOrPendingImage();
81 if (image->isPendingImage())
82 m_pendingImageProperties.set(property, value);
84 value->restoreCachedResourceIfNeeded(document);
86 return image.release();
89 PassRefPtr<StyleImage> ElementStyleResources::cursorOrPendingFromValue(CSSPropertyID property, CSSCursorImageValue* value)
91 RefPtr<StyleImage> image = value->cachedOrPendingImage(m_deviceScaleFactor);
92 if (image && image->isPendingImage())
93 m_pendingImageProperties.set(property, value);
94 return image.release();
97 void ElementStyleResources::clearPendingImageProperties()
99 m_pendingImageProperties.clear();
102 void ElementStyleResources::clearPendingSVGDocuments()
104 m_pendingSVGDocuments.clear();
107 void ElementStyleResources::addPendingSVGDocument(FilterOperation* filterOperation, CSSSVGDocumentValue* cssSVGDocumentValue)
109 m_pendingSVGDocuments.set(filterOperation, cssSVGDocumentValue);