1 | /* |
2 | * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE |
17 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
18 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
22 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
23 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
24 | * SUCH DAMAGE. |
25 | */ |
26 | |
27 | #pragma once |
28 | |
29 | #include "CSSImageGeneratorValue.h" |
30 | #include "CachedImageClient.h" |
31 | #include "CachedResourceHandle.h" |
32 | #include "FilterOperations.h" |
33 | #include "Image.h" |
34 | #include <wtf/Function.h> |
35 | |
36 | namespace WebCore { |
37 | |
38 | class CachedImage; |
39 | class FilterSubimageObserverProxy; |
40 | class RenderElement; |
41 | class Document; |
42 | class StyleResolver; |
43 | |
44 | class CSSFilterImageValue final : public CSSImageGeneratorValue { |
45 | friend class FilterSubimageObserverProxy; |
46 | public: |
47 | static Ref<CSSFilterImageValue> create(Ref<CSSValue>&& imageValue, Ref<CSSValue>&& filterValue) |
48 | { |
49 | return adoptRef(*new CSSFilterImageValue(WTFMove(imageValue), WTFMove(filterValue))); |
50 | } |
51 | |
52 | ~CSSFilterImageValue(); |
53 | |
54 | String customCSSText() const; |
55 | |
56 | RefPtr<Image> image(RenderElement*, const FloatSize&); |
57 | bool isFixedSize() const { return true; } |
58 | FloatSize fixedSize(const RenderElement*); |
59 | |
60 | bool isPending() const; |
61 | bool knownToBeOpaque(const RenderElement&) const; |
62 | |
63 | void loadSubimages(CachedResourceLoader&, const ResourceLoaderOptions&); |
64 | |
65 | bool traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const; |
66 | |
67 | bool equals(const CSSFilterImageValue&) const; |
68 | |
69 | bool equalInputImages(const CSSFilterImageValue&) const; |
70 | |
71 | void createFilterOperations(StyleResolver*); |
72 | |
73 | const FilterOperations& filterOperations() const { return m_filterOperations; } |
74 | void setFilterOperations(const FilterOperations& filterOperations) |
75 | { |
76 | m_filterOperations = filterOperations; |
77 | } |
78 | CachedImage* cachedImage() const { return m_cachedImage.get(); } |
79 | |
80 | private: |
81 | CSSFilterImageValue(Ref<CSSValue>&& imageValue, Ref<CSSValue>&& filterValue) |
82 | : CSSImageGeneratorValue(FilterImageClass) |
83 | , m_imageValue(WTFMove(imageValue)) |
84 | , m_filterValue(WTFMove(filterValue)) |
85 | , m_filterSubimageObserver(this) |
86 | { |
87 | } |
88 | |
89 | class FilterSubimageObserverProxy final : public CachedImageClient { |
90 | public: |
91 | FilterSubimageObserverProxy(CSSFilterImageValue* ownerValue) |
92 | : m_ownerValue(ownerValue) |
93 | , m_ready(false) |
94 | { |
95 | } |
96 | |
97 | virtual ~FilterSubimageObserverProxy() = default; |
98 | void imageChanged(CachedImage*, const IntRect* = nullptr) final; |
99 | void setReady(bool ready) { m_ready = ready; } |
100 | private: |
101 | CSSFilterImageValue* m_ownerValue; |
102 | bool m_ready; |
103 | }; |
104 | |
105 | void filterImageChanged(const IntRect&); |
106 | |
107 | Ref<CSSValue> m_imageValue; |
108 | Ref<CSSValue> m_filterValue; |
109 | |
110 | FilterOperations m_filterOperations; |
111 | |
112 | CachedResourceHandle<CachedImage> m_cachedImage; |
113 | |
114 | FilterSubimageObserverProxy m_filterSubimageObserver; |
115 | }; |
116 | |
117 | } // namespace WebCore |
118 | |
119 | SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSFilterImageValue, isFilterImageValue()) |
120 | |