Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / style / StyleFetchedImageSet.cpp
1 /*
2  * Copyright (C) 2012 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25
26 #include "config.h"
27 #include "core/rendering/style/StyleFetchedImageSet.h"
28
29 #include "core/css/CSSImageSetValue.h"
30 #include "core/fetch/ImageResource.h"
31 #include "core/rendering/RenderObject.h"
32
33 namespace blink {
34
35 StyleFetchedImageSet::StyleFetchedImageSet(ImageResource* image, float imageScaleFactor, CSSImageSetValue* value)
36     : m_bestFitImage(image)
37     , m_imageScaleFactor(imageScaleFactor)
38     , m_imageSetValue(value)
39 {
40     m_isImageResourceSet = true;
41     m_bestFitImage->addClient(this);
42 }
43
44
45 StyleFetchedImageSet::~StyleFetchedImageSet()
46 {
47     m_bestFitImage->removeClient(this);
48 }
49
50 PassRefPtrWillBeRawPtr<CSSValue> StyleFetchedImageSet::cssValue() const
51 {
52     return m_imageSetValue;
53 }
54
55 bool StyleFetchedImageSet::canRender(const RenderObject& renderer, float multiplier) const
56 {
57     return m_bestFitImage->canRender(renderer, multiplier);
58 }
59
60 bool StyleFetchedImageSet::isLoaded() const
61 {
62     return m_bestFitImage->isLoaded();
63 }
64
65 bool StyleFetchedImageSet::errorOccurred() const
66 {
67     return m_bestFitImage->errorOccurred();
68 }
69
70 LayoutSize StyleFetchedImageSet::imageSize(const RenderObject* renderer, float multiplier) const
71 {
72     LayoutSize scaledImageSize = m_bestFitImage->imageSizeForRenderer(renderer, multiplier);
73     scaledImageSize.scale(1 / m_imageScaleFactor);
74     return scaledImageSize;
75 }
76
77 bool StyleFetchedImageSet::imageHasRelativeWidth() const
78 {
79     return m_bestFitImage->imageHasRelativeWidth();
80 }
81
82 bool StyleFetchedImageSet::imageHasRelativeHeight() const
83 {
84     return m_bestFitImage->imageHasRelativeHeight();
85 }
86
87 void StyleFetchedImageSet::computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
88 {
89     m_bestFitImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
90 }
91
92 bool StyleFetchedImageSet::usesImageContainerSize() const
93 {
94     return m_bestFitImage->usesImageContainerSize();
95 }
96
97 void StyleFetchedImageSet::setContainerSizeForRenderer(const RenderObject* renderer, const IntSize& imageContainerSize, float imageContainerZoomFactor)
98 {
99     m_bestFitImage->setContainerSizeForRenderer(renderer, imageContainerSize, imageContainerZoomFactor);
100 }
101
102 void StyleFetchedImageSet::addClient(RenderObject* renderer)
103 {
104     m_bestFitImage->addClient(renderer);
105 }
106
107 void StyleFetchedImageSet::removeClient(RenderObject* renderer)
108 {
109     m_bestFitImage->removeClient(renderer);
110 }
111
112 PassRefPtr<Image> StyleFetchedImageSet::image(RenderObject* renderer, const IntSize&) const
113 {
114     return m_bestFitImage->imageForRenderer(renderer);
115 }
116
117 bool StyleFetchedImageSet::knownToBeOpaque(const RenderObject* renderer) const
118 {
119     return m_bestFitImage->currentFrameKnownToBeOpaque(renderer);
120 }
121
122 } // namespace blink