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>
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.
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.
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.
29 #include "core/layout/LayoutImageResource.h"
31 #include "core/layout/LayoutImage.h"
35 LayoutImageResource::LayoutImageResource()
36 : m_layoutObject(nullptr)
37 , m_cachedImage(nullptr)
41 LayoutImageResource::~LayoutImageResource()
45 void LayoutImageResource::initialize(LayoutObject
* layoutObject
)
47 ASSERT(!m_layoutObject
);
49 m_layoutObject
= layoutObject
;
52 void LayoutImageResource::shutdown()
54 ASSERT(m_layoutObject
);
57 m_cachedImage
->removeClient(m_layoutObject
);
60 void LayoutImageResource::setImageResource(ImageResource
* newImage
)
62 ASSERT(m_layoutObject
);
64 if (m_cachedImage
== newImage
)
68 m_cachedImage
->removeClient(m_layoutObject
);
69 m_cachedImage
= newImage
;
71 m_cachedImage
->addClient(m_layoutObject
);
72 if (m_cachedImage
->errorOccurred())
73 m_layoutObject
->imageChanged(m_cachedImage
.get());
75 m_layoutObject
->imageChanged(m_cachedImage
.get());
79 void LayoutImageResource::resetAnimation()
81 ASSERT(m_layoutObject
);
86 image()->resetAnimation();
88 m_layoutObject
->setShouldDoFullPaintInvalidation();
91 void LayoutImageResource::setContainerSizeForLayoutObject(const IntSize
& imageContainerSize
)
93 ASSERT(m_layoutObject
);
95 m_cachedImage
->setContainerSizeForLayoutObject(m_layoutObject
, imageContainerSize
, m_layoutObject
->style()->effectiveZoom());
98 LayoutSize
LayoutImageResource::getImageSize(float multiplier
, ImageResource::SizeType type
) const
102 LayoutSize size
= m_cachedImage
->imageSizeForLayoutObject(m_layoutObject
, multiplier
, type
);
103 if (m_layoutObject
&& m_layoutObject
->isLayoutImage() && size
.width() && size
.height())
104 size
.scale(toLayoutImage(m_layoutObject
)->imageDevicePixelRatio());