[GTK] Menu list button doesn't use the text color from the theme
[WebKit-https.git] / Source / WebCore / rendering / RenderImageResource.cpp
1 /*
2  * Copyright (C) 1999 Lars Knoll <knoll@kde.org>
3  * Copyright (C) 1999 Antti Koivisto <koivisto@kde.org>
4  * Copyright (C) 2000 Dirk Mueller <mueller@kde.org>
5  * Copyright (C) 2006 Allan Sandfeld Jensen <kde@carewolf.com>
6  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
7  * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
8  * Copyright (C) 2010 Google Inc. All rights reserved.
9  * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public License
22  * along with this library; see the file COPYING.LIB.  If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA 02110-1301, USA.
25  *
26  */
27
28 #include "config.h"
29 #include "RenderImageResource.h"
30
31 #include "CachedImage.h"
32 #include "Image.h"
33 #include "RenderElement.h"
34 #include "RenderImage.h"
35 #include "RenderImageResourceStyleImage.h"
36
37 namespace WebCore {
38
39 RenderImageResource::RenderImageResource()
40     : m_renderer(0)
41 {
42 }
43
44 RenderImageResource::~RenderImageResource()
45 {
46 }
47
48 void RenderImageResource::initialize(RenderElement* renderer)
49 {
50     ASSERT(!m_renderer);
51     ASSERT(renderer);
52     m_renderer = renderer;
53 }
54
55 void RenderImageResource::shutdown()
56 {
57     ASSERT(m_renderer);
58
59     if (m_cachedImage)
60         m_cachedImage->removeClient(m_renderer);
61 }
62
63 void RenderImageResource::setCachedImage(CachedImage* newImage)
64 {
65     ASSERT(m_renderer);
66
67     if (m_cachedImage == newImage)
68         return;
69
70     if (m_cachedImage)
71         m_cachedImage->removeClient(m_renderer);
72     m_cachedImage = newImage;
73     if (m_cachedImage) {
74         m_cachedImage->addClient(m_renderer);
75         if (m_cachedImage->errorOccurred())
76             m_renderer->imageChanged(m_cachedImage.get());
77     }
78 }
79
80 void RenderImageResource::resetAnimation()
81 {
82     ASSERT(m_renderer);
83
84     if (!m_cachedImage)
85         return;
86
87     image()->resetAnimation();
88
89     if (!m_renderer->needsLayout())
90         m_renderer->repaint();
91 }
92
93 RefPtr<Image> RenderImageResource::image(int, int) const
94 {
95     return m_cachedImage ? m_cachedImage->imageForRenderer(m_renderer) : Image::nullImage();
96 }
97
98 bool RenderImageResource::errorOccurred() const
99 {
100     return m_cachedImage && m_cachedImage->errorOccurred();
101 }
102
103 void RenderImageResource::setContainerSizeForRenderer(const IntSize& imageContainerSize)
104 {
105     ASSERT(m_renderer);
106     if (m_cachedImage)
107         m_cachedImage->setContainerSizeForRenderer(m_renderer, imageContainerSize, m_renderer->style().effectiveZoom());
108 }
109
110 bool RenderImageResource::imageHasRelativeWidth() const
111 {
112     return m_cachedImage ? m_cachedImage->imageHasRelativeWidth() : false;
113 }
114
115 bool RenderImageResource::imageHasRelativeHeight() const
116 {
117     return m_cachedImage ? m_cachedImage->imageHasRelativeHeight() : false;
118 }
119
120 LayoutSize RenderImageResource::imageSize(float multiplier) const
121 {
122     return getImageSize(multiplier, CachedImage::UsedSize);
123 }
124
125 LayoutSize RenderImageResource::intrinsicSize(float multiplier) const
126 {
127     return getImageSize(multiplier, CachedImage::IntrinsicSize);
128 }
129
130 LayoutSize RenderImageResource::getImageSize(float multiplier, CachedImage::SizeType type) const
131 {
132     if (!m_cachedImage)
133         return LayoutSize();
134     LayoutSize size = m_cachedImage->imageSizeForRenderer(m_renderer, multiplier, type);
135     if (is<RenderImage>(m_renderer))
136         size.scale(downcast<RenderImage>(*m_renderer).imageDevicePixelRatio());
137     return size;
138 }
139
140 } // namespace WebCore