Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1 | /* |
| 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 Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 26 | #include "core/css/CSSGradientValue.h" |
| 27 | #include "core/css/CSSSVGDocumentValue.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 28 | #include "core/rendering/style/StyleGeneratedImage.h" |
| 29 | #include "core/rendering/style/StyleImage.h" |
| 30 | #include "core/rendering/style/StylePendingImage.h" |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 31 | #include "platform/graphics/filters/FilterOperation.h" |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | ElementStyleResources::ElementStyleResources() |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 36 | : m_deviceScaleFactor(1) |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
Bo Liu | f91f5fa | 2014-05-01 10:37:55 -0700 | [diff] [blame] | 40 | PassRefPtr<StyleImage> ElementStyleResources::styleImage(Document& document, const TextLinkColors& textLinkColors, Color currentColor, CSSPropertyID property, CSSValue* value) |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 41 | { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 42 | if (value->isImageValue()) |
Bo Liu | f91f5fa | 2014-05-01 10:37:55 -0700 | [diff] [blame] | 43 | return cachedOrPendingFromValue(document, property, toCSSImageValue(value)); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 44 | |
| 45 | if (value->isImageGeneratorValue()) { |
| 46 | if (value->isGradientValue()) |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 47 | return generatedOrPendingFromValue(property, toCSSGradientValue(value)->gradientWithStylesResolved(textLinkColors, currentColor).get()); |
| 48 | return generatedOrPendingFromValue(property, toCSSImageGeneratorValue(value)); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | if (value->isImageSetValue()) |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 52 | return setOrPendingFromValue(property, toCSSImageSetValue(value)); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 53 | |
| 54 | if (value->isCursorImageValue()) |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 55 | return cursorOrPendingFromValue(property, toCSSCursorImageValue(value)); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 56 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 57 | return nullptr; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | PassRefPtr<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 | |
| 69 | PassRefPtr<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 Liu | f91f5fa | 2014-05-01 10:37:55 -0700 | [diff] [blame] | 77 | PassRefPtr<StyleImage> ElementStyleResources::cachedOrPendingFromValue(Document& document, CSSPropertyID property, CSSImageValue* value) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 78 | { |
| 79 | RefPtr<StyleImage> image = value->cachedOrPendingImage(); |
Bo Liu | f91f5fa | 2014-05-01 10:37:55 -0700 | [diff] [blame] | 80 | if (image) { |
| 81 | if (image->isPendingImage()) |
| 82 | m_pendingImageProperties.set(property, value); |
| 83 | else |
| 84 | value->restoreCachedResourceIfNeeded(document); |
| 85 | } |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 86 | return image.release(); |
| 87 | } |
| 88 | |
| 89 | PassRefPtr<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 Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Torne (Richard Coles) | 43e7502 | 2014-03-21 14:26:12 +0000 | [diff] [blame] | 97 | void ElementStyleResources::clearPendingImageProperties() |
| 98 | { |
| 99 | m_pendingImageProperties.clear(); |
| 100 | } |
| 101 | |
| 102 | void ElementStyleResources::clearPendingSVGDocuments() |
| 103 | { |
| 104 | m_pendingSVGDocuments.clear(); |
| 105 | } |
| 106 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 107 | void ElementStyleResources::addPendingSVGDocument(FilterOperation* filterOperation, CSSSVGDocumentValue* cssSVGDocumentValue) |
| 108 | { |
| 109 | m_pendingSVGDocuments.set(filterOperation, cssSVGDocumentValue); |
| 110 | } |
| 111 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 112 | } |