OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. | 2 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. |
3 * Copyright (C) 2013 Apple Inc. All rights reserved. | 3 * Copyright (C) 2013 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 ASSERT(client); | 49 ASSERT(client); |
50 | 50 |
51 if (m_imageForContainerMap.contains(client)) | 51 if (m_imageForContainerMap.contains(client)) |
52 m_imageForContainerMap.remove(client); | 52 m_imageForContainerMap.remove(client); |
53 } | 53 } |
54 | 54 |
55 void SVGImageCache::setContainerSizeForRenderer(const CachedImageClient* client,
const IntSize& containerSize, float containerZoom) | 55 void SVGImageCache::setContainerSizeForRenderer(const CachedImageClient* client,
const IntSize& containerSize, float containerZoom) |
56 { | 56 { |
57 ASSERT(client); | 57 ASSERT(client); |
58 ASSERT(!containerSize.isEmpty()); | 58 ASSERT(!containerSize.isEmpty()); |
| 59 ASSERT(containerZoom); |
59 | 60 |
60 FloatSize containerSizeWithoutZoom(containerSize); | 61 FloatSize containerSizeWithoutZoom(containerSize); |
61 containerSizeWithoutZoom.scale(1 / containerZoom); | 62 containerSizeWithoutZoom.scale(1 / containerZoom); |
62 | 63 |
63 ImageForContainerMap::iterator imageIt = m_imageForContainerMap.find(client)
; | 64 m_imageForContainerMap.set(client, SVGImageForContainer::create(m_svgImage,
containerSizeWithoutZoom, containerZoom)); |
64 if (imageIt == m_imageForContainerMap.end()) { | |
65 RefPtr<SVGImageForContainer> image = SVGImageForContainer::create(m_svgI
mage, containerSizeWithoutZoom, 1, containerZoom); | |
66 m_imageForContainerMap.set(client, image); | |
67 } else { | |
68 imageIt->value->setSize(containerSizeWithoutZoom); | |
69 imageIt->value->setZoom(containerZoom); | |
70 } | |
71 } | 65 } |
72 | 66 |
73 IntSize SVGImageCache::imageSizeForRenderer(const RenderObject* renderer) const | 67 IntSize SVGImageCache::imageSizeForRenderer(const RenderObject* renderer) const |
74 { | 68 { |
75 IntSize imageSize = m_svgImage->size(); | 69 IntSize imageSize = m_svgImage->size(); |
76 if (!renderer) | 70 if (!renderer) |
77 return imageSize; | 71 return imageSize; |
78 | 72 |
79 ImageForContainerMap::const_iterator it = m_imageForContainerMap.find(render
er); | 73 ImageForContainerMap::const_iterator it = m_imageForContainerMap.find(render
er); |
80 if (it == m_imageForContainerMap.end()) | 74 if (it == m_imageForContainerMap.end()) |
81 return imageSize; | 75 return imageSize; |
82 | 76 |
83 RefPtr<SVGImageForContainer> image = it->value; | 77 RefPtr<SVGImageForContainer> image = it->value; |
84 FloatSize size = image->containerSize(); | 78 ASSERT(!image->size().isEmpty()); |
85 if (!size.isEmpty()) { | 79 return image->size(); |
86 size.scale(image->zoom()); | |
87 imageSize.setWidth(size.width()); | |
88 imageSize.setHeight(size.height()); | |
89 } | |
90 | |
91 return imageSize; | |
92 } | 80 } |
93 | 81 |
94 // FIXME: This doesn't take into account the animation timeline so animations wi
ll not | 82 // FIXME: This doesn't take into account the animation timeline so animations wi
ll not |
95 // restart on page load, nor will two animations in different pages have differe
nt timelines. | 83 // restart on page load, nor will two animations in different pages have differe
nt timelines. |
96 Image* SVGImageCache::imageForRenderer(const RenderObject* renderer) | 84 Image* SVGImageCache::imageForRenderer(const RenderObject* renderer) |
97 { | 85 { |
98 if (!renderer) | 86 if (!renderer) |
99 return Image::nullImage(); | 87 return Image::nullImage(); |
100 | 88 |
101 // The cache needs to know the size of the renderer before querying an image
for it. | |
102 ImageForContainerMap::iterator it = m_imageForContainerMap.find(renderer); | 89 ImageForContainerMap::iterator it = m_imageForContainerMap.find(renderer); |
103 if (it == m_imageForContainerMap.end()) | 90 if (it == m_imageForContainerMap.end()) |
104 return Image::nullImage(); | 91 return Image::nullImage(); |
105 | 92 |
106 RefPtr<SVGImageForContainer> image = it->value; | 93 RefPtr<SVGImageForContainer> image = it->value; |
107 ASSERT(!image->containerSize().isEmpty()); | 94 ASSERT(!image->size().isEmpty()); |
108 | |
109 // FIXME: Set the page scale in setContainerSizeForRenderer instead of looki
ng it up here. | |
110 Page* page = renderer->document()->page(); | |
111 image->setPageScale(page->deviceScaleFactor() * page->pageScaleFactor()); | |
112 | |
113 return image.get(); | 95 return image.get(); |
114 } | 96 } |
115 | 97 |
116 } // namespace WebCore | 98 } // namespace WebCore |
117 | 99 |
118 #endif // ENABLE(SVG) | 100 #endif // ENABLE(SVG) |
OLD | NEW |