1 | /* |
2 | * Copyright (C) 1999 Lars Knoll <knoll@kde.org> |
3 | * Copyright (C) 1999 Antti Koivisto <koivisto@kde.org> |
4 | * Copyright (C) 2006 Allan Sandfeld Jensen <kde@carewolf.com> |
5 | * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> |
6 | * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserved. |
7 | * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> |
8 | * |
9 | * This library is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU Library General Public |
11 | * License as published by the Free Software Foundation; either |
12 | * version 2 of the License, or (at your option) any later version. |
13 | * |
14 | * This library is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | * Library General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU Library General Public License |
20 | * along with this library; see the file COPYING.LIB. If not, write to |
21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 | * Boston, MA 02110-1301, USA. |
23 | * |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "CachedImage.h" |
29 | #include "CachedResourceHandle.h" |
30 | #include "StyleImage.h" |
31 | #include <wtf/IsoMalloc.h> |
32 | #include <wtf/WeakPtr.h> |
33 | |
34 | namespace WebCore { |
35 | |
36 | class CachedImage; |
37 | class RenderElement; |
38 | |
39 | class RenderImageResource { |
40 | WTF_MAKE_NONCOPYABLE(RenderImageResource); WTF_MAKE_ISO_ALLOCATED(RenderImageResource); |
41 | public: |
42 | RenderImageResource(); |
43 | virtual ~RenderImageResource() = default; |
44 | |
45 | virtual void initialize(RenderElement& renderer) { initialize(renderer, nullptr); } |
46 | virtual void shutdown(); |
47 | |
48 | void setCachedImage(CachedImage*); |
49 | CachedImage* cachedImage() const { return m_cachedImage.get(); } |
50 | |
51 | void resetAnimation(); |
52 | |
53 | virtual RefPtr<Image> image(const IntSize& size = { }) const; |
54 | virtual bool errorOccurred() const { return m_cachedImage && m_cachedImage->errorOccurred(); } |
55 | |
56 | virtual void setContainerContext(const IntSize&, const URL&); |
57 | |
58 | virtual bool imageHasRelativeWidth() const { return m_cachedImage && m_cachedImage->imageHasRelativeWidth(); } |
59 | virtual bool imageHasRelativeHeight() const { return m_cachedImage && m_cachedImage->imageHasRelativeHeight(); } |
60 | |
61 | inline LayoutSize imageSize(float multiplier) const { return imageSize(multiplier, CachedImage::UsedSize); } |
62 | inline LayoutSize intrinsicSize(float multiplier) const { return imageSize(multiplier, CachedImage::IntrinsicSize); } |
63 | |
64 | virtual WrappedImagePtr imagePtr() const { return m_cachedImage.get(); } |
65 | |
66 | protected: |
67 | RenderElement* renderer() const { return m_renderer.get(); } |
68 | void initialize(RenderElement&, CachedImage*); |
69 | |
70 | private: |
71 | virtual LayoutSize imageSize(float multiplier, CachedImage::SizeType) const; |
72 | |
73 | WeakPtr<RenderElement> m_renderer; |
74 | CachedResourceHandle<CachedImage> m_cachedImage; |
75 | bool m_cachedImageRemoveClientIsNeeded { true }; |
76 | }; |
77 | |
78 | } // namespace WebCore |
79 | |