| 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 "RenderImageResourceStyleImage.h" |
| 30 | |
| 31 | #include "CachedImage.h" |
| 32 | #include "RenderElement.h" |
| 33 | #include "StyleCachedImage.h" |
| 34 | #include <wtf/IsoMallocInlines.h> |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderImageResourceStyleImage); |
| 39 | |
| 40 | RenderImageResourceStyleImage::RenderImageResourceStyleImage(StyleImage& styleImage) |
| 41 | : m_styleImage(styleImage) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | void RenderImageResourceStyleImage::initialize(RenderElement& renderer) |
| 46 | { |
| 47 | RenderImageResource::initialize(renderer, m_styleImage->isCachedImage() ? m_styleImage.get().cachedImage() : nullptr); |
| 48 | m_styleImage->addClient(this->renderer()); |
| 49 | } |
| 50 | |
| 51 | void RenderImageResourceStyleImage::shutdown() |
| 52 | { |
| 53 | RenderImageResource::shutdown(); |
| 54 | if (renderer()) |
| 55 | m_styleImage->removeClient(renderer()); |
| 56 | } |
| 57 | |
| 58 | RefPtr<Image> RenderImageResourceStyleImage::image(const IntSize& size) const |
| 59 | { |
| 60 | // Generated content may trigger calls to image() while we're still pending, don't assert but gracefully exit. |
| 61 | if (m_styleImage->isPending()) |
| 62 | return &Image::nullImage(); |
| 63 | if (auto image = m_styleImage->image(renderer(), size)) |
| 64 | return image; |
| 65 | return &Image::nullImage(); |
| 66 | } |
| 67 | |
| 68 | void RenderImageResourceStyleImage::setContainerContext(const IntSize& size, const URL&) |
| 69 | { |
| 70 | ASSERT(renderer()); |
| 71 | m_styleImage->setContainerContextForRenderer(*renderer(), size, renderer()->style().effectiveZoom()); |
| 72 | } |
| 73 | |
| 74 | } // namespace WebCore |
| 75 | |