Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / layout / LayoutImageResource.cpp
blob85e24d61d56493228c2276e38b94076d114c9807
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>
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.
28 #include "config.h"
29 #include "core/layout/LayoutImageResource.h"
31 #include "core/layout/LayoutImage.h"
33 namespace blink {
35 LayoutImageResource::LayoutImageResource()
36 : m_layoutObject(nullptr)
37 , m_cachedImage(nullptr)
41 LayoutImageResource::~LayoutImageResource()
45 void LayoutImageResource::initialize(LayoutObject* layoutObject)
47 ASSERT(!m_layoutObject);
48 ASSERT(layoutObject);
49 m_layoutObject = layoutObject;
52 void LayoutImageResource::shutdown()
54 ASSERT(m_layoutObject);
56 if (m_cachedImage)
57 m_cachedImage->removeClient(m_layoutObject);
60 void LayoutImageResource::setImageResource(ImageResource* newImage)
62 ASSERT(m_layoutObject);
64 if (m_cachedImage == newImage)
65 return;
67 if (m_cachedImage)
68 m_cachedImage->removeClient(m_layoutObject);
69 m_cachedImage = newImage;
70 if (m_cachedImage) {
71 m_cachedImage->addClient(m_layoutObject);
72 if (m_cachedImage->errorOccurred())
73 m_layoutObject->imageChanged(m_cachedImage.get());
74 } else {
75 m_layoutObject->imageChanged(m_cachedImage.get());
79 void LayoutImageResource::resetAnimation()
81 ASSERT(m_layoutObject);
83 if (!m_cachedImage)
84 return;
86 image()->resetAnimation();
88 m_layoutObject->setShouldDoFullPaintInvalidation();
91 void LayoutImageResource::setContainerSizeForLayoutObject(const IntSize& imageContainerSize)
93 ASSERT(m_layoutObject);
94 if (m_cachedImage)
95 m_cachedImage->setContainerSizeForLayoutObject(m_layoutObject, imageContainerSize, m_layoutObject->style()->effectiveZoom());
98 LayoutSize LayoutImageResource::getImageSize(float multiplier, ImageResource::SizeType type) const
100 if (!m_cachedImage)
101 return LayoutSize();
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());
105 return size;
108 } // namespace blink