1 /* 2 * Copyright (C) 1999 Lars Knoll <knoll (at) kde.org> 3 * Copyright (C) 1999 Antti Koivisto <koivisto (at) kde.org> 4 * Copyright (C) 2000 Dirk Mueller <mueller (at) kde.org> 5 * Copyright (C) 2006 Allan Sandfeld Jensen <kde (at) carewolf.com> 6 * Copyright (C) 2006 Samuel Weinig <sam.weinig (at) 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 (at) 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 "core/rendering/RenderImageResource.h" 30 31 #include "core/rendering/RenderImage.h" 32 #include "core/rendering/RenderObject.h" 33 34 namespace blink { 35 36 RenderImageResource::RenderImageResource() 37 : m_renderer(0) 38 , m_cachedImage(0) 39 { 40 } 41 42 RenderImageResource::~RenderImageResource() 43 { 44 } 45 46 void RenderImageResource::initialize(RenderObject* renderer) 47 { 48 ASSERT(!m_renderer); 49 ASSERT(renderer); 50 m_renderer = renderer; 51 } 52 53 void RenderImageResource::shutdown() 54 { 55 ASSERT(m_renderer); 56 57 if (m_cachedImage) 58 m_cachedImage->removeClient(m_renderer); 59 } 60 61 void RenderImageResource::setImageResource(ImageResource* newImage) 62 { 63 ASSERT(m_renderer); 64 65 if (m_cachedImage == newImage) 66 return; 67 68 if (m_cachedImage) 69 m_cachedImage->removeClient(m_renderer); 70 m_cachedImage = newImage; 71 if (m_cachedImage) { 72 m_cachedImage->addClient(m_renderer); 73 if (m_cachedImage->errorOccurred()) 74 m_renderer->imageChanged(m_cachedImage.get()); 75 } else { 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 m_renderer->setShouldDoFullPaintInvalidation(true); 90 } 91 92 void RenderImageResource::setContainerSizeForRenderer(const IntSize& imageContainerSize) 93 { 94 ASSERT(m_renderer); 95 if (m_cachedImage) 96 m_cachedImage->setContainerSizeForRenderer(m_renderer, imageContainerSize, m_renderer->style()->effectiveZoom()); 97 } 98 99 LayoutSize RenderImageResource::getImageSize(float multiplier, ImageResource::SizeType type) const 100 { 101 if (!m_cachedImage) 102 return LayoutSize(); 103 LayoutSize size = m_cachedImage->imageSizeForRenderer(m_renderer, multiplier, type); 104 if (m_renderer && m_renderer->isRenderImage()) 105 size.scale(toRenderImage(m_renderer)->imageDevicePixelRatio()); 106 return size; 107 } 108 109 } // namespace blink 110