2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "core/rendering/style/StyleFetchedImageSet.h"
29 #include "core/css/CSSImageSetValue.h"
30 #include "core/fetch/ImageResource.h"
31 #include "core/rendering/RenderObject.h"
35 StyleFetchedImageSet::StyleFetchedImageSet(ImageResource* image, float imageScaleFactor, CSSImageSetValue* value)
36 : m_bestFitImage(image)
37 , m_imageScaleFactor(imageScaleFactor)
38 , m_imageSetValue(value)
40 m_isImageResourceSet = true;
41 m_bestFitImage->addClient(this);
45 StyleFetchedImageSet::~StyleFetchedImageSet()
47 m_bestFitImage->removeClient(this);
50 PassRefPtrWillBeRawPtr<CSSValue> StyleFetchedImageSet::cssValue() const
52 return m_imageSetValue;
55 bool StyleFetchedImageSet::canRender(const RenderObject& renderer, float multiplier) const
57 return m_bestFitImage->canRender(renderer, multiplier);
60 bool StyleFetchedImageSet::isLoaded() const
62 return m_bestFitImage->isLoaded();
65 bool StyleFetchedImageSet::errorOccurred() const
67 return m_bestFitImage->errorOccurred();
70 LayoutSize StyleFetchedImageSet::imageSize(const RenderObject* renderer, float multiplier) const
72 LayoutSize scaledImageSize = m_bestFitImage->imageSizeForRenderer(renderer, multiplier);
73 scaledImageSize.scale(1 / m_imageScaleFactor);
74 return scaledImageSize;
77 bool StyleFetchedImageSet::imageHasRelativeWidth() const
79 return m_bestFitImage->imageHasRelativeWidth();
82 bool StyleFetchedImageSet::imageHasRelativeHeight() const
84 return m_bestFitImage->imageHasRelativeHeight();
87 void StyleFetchedImageSet::computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
89 m_bestFitImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
92 bool StyleFetchedImageSet::usesImageContainerSize() const
94 return m_bestFitImage->usesImageContainerSize();
97 void StyleFetchedImageSet::setContainerSizeForRenderer(const RenderObject* renderer, const IntSize& imageContainerSize, float imageContainerZoomFactor)
99 m_bestFitImage->setContainerSizeForRenderer(renderer, imageContainerSize, imageContainerZoomFactor);
102 void StyleFetchedImageSet::addClient(RenderObject* renderer)
104 m_bestFitImage->addClient(renderer);
107 void StyleFetchedImageSet::removeClient(RenderObject* renderer)
109 m_bestFitImage->removeClient(renderer);
112 PassRefPtr<Image> StyleFetchedImageSet::image(RenderObject* renderer, const IntSize&) const
114 return m_bestFitImage->imageForRenderer(renderer);
117 bool StyleFetchedImageSet::knownToBeOpaque(const RenderObject* renderer) const
119 return m_bestFitImage->currentFrameKnownToBeOpaque(renderer);
122 } // namespace WebCore