| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org> | 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org> |
| 3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
| 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 | 129 |
| 130 static SVGSVGElement* svgRootElement(Page* page) | 130 static SVGSVGElement* svgRootElement(Page* page) |
| 131 { | 131 { |
| 132 if (!page) | 132 if (!page) |
| 133 return nullptr; | 133 return nullptr; |
| 134 LocalFrame* frame = toLocalFrame(page->mainFrame()); | 134 LocalFrame* frame = toLocalFrame(page->mainFrame()); |
| 135 return frame->document()->accessSVGExtensions().rootElement(); | 135 return frame->document()->accessSVGExtensions().rootElement(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void SVGImage::setContainerSize(const IntSize& size) | |
| 139 { | |
| 140 SVGSVGElement* rootElement = svgRootElement(m_page.get()); | |
| 141 if (!rootElement) | |
| 142 return; | |
| 143 | |
| 144 FrameView* view = frameView(); | |
| 145 view->resize(this->containerSize()); | |
| 146 | |
| 147 LayoutSVGRoot* layoutObject = toLayoutSVGRoot(rootElement->layoutObject()); | |
| 148 if (!layoutObject) | |
| 149 return; | |
| 150 layoutObject->setContainerSize(size); | |
| 151 } | |
| 152 | |
| 153 IntSize SVGImage::containerSize() const | 138 IntSize SVGImage::containerSize() const |
| 154 { | 139 { |
| 155 SVGSVGElement* rootElement = svgRootElement(m_page.get()); | 140 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 156 if (!rootElement) | 141 if (!rootElement) |
| 157 return IntSize(); | 142 return IntSize(); |
| 158 | 143 |
| 159 LayoutSVGRoot* layoutObject = toLayoutSVGRoot(rootElement->layoutObject()); | 144 LayoutSVGRoot* layoutObject = toLayoutSVGRoot(rootElement->layoutObject()); |
| 160 if (!layoutObject) | 145 if (!layoutObject) |
| 161 return IntSize(); | 146 return IntSize(); |
| 162 | 147 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl
oatSize containerSize, float zoom, const FloatRect& dstRect, | 181 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl
oatSize containerSize, float zoom, const FloatRect& dstRect, |
| 197 const FloatRect& srcRect, const KURL& url) | 182 const FloatRect& srcRect, const KURL& url) |
| 198 { | 183 { |
| 199 if (!m_page) | 184 if (!m_page) |
| 200 return; | 185 return; |
| 201 | 186 |
| 202 // Temporarily disable the image observer to prevent changeInRect() calls du
e re-laying out the image. | 187 // Temporarily disable the image observer to prevent changeInRect() calls du
e re-laying out the image. |
| 203 ImageObserverDisabler imageObserverDisabler(this); | 188 ImageObserverDisabler imageObserverDisabler(this); |
| 204 | 189 |
| 205 IntSize roundedContainerSize = roundedIntSize(containerSize); | 190 IntSize roundedContainerSize = roundedIntSize(containerSize); |
| 206 setContainerSize(roundedContainerSize); | 191 |
| 192 if (SVGSVGElement* rootElement = svgRootElement(m_page.get())) { |
| 193 if (LayoutSVGRoot* layoutObject = toLayoutSVGRoot(rootElement->layoutObj
ect())) |
| 194 layoutObject->setContainerSize(roundedContainerSize); |
| 195 } |
| 207 | 196 |
| 208 FloatRect scaledSrc = srcRect; | 197 FloatRect scaledSrc = srcRect; |
| 209 scaledSrc.scale(1 / zoom); | 198 scaledSrc.scale(1 / zoom); |
| 210 | 199 |
| 211 // Compensate for the container size rounding by adjusting the source rect. | 200 // Compensate for the container size rounding by adjusting the source rect. |
| 212 FloatSize adjustedSrcSize = scaledSrc.size(); | 201 FloatSize adjustedSrcSize = scaledSrc.size(); |
| 213 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); | 202 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); |
| 214 scaledSrc.setSize(adjustedSrcSize); | 203 scaledSrc.setSize(adjustedSrcSize); |
| 215 | 204 |
| 216 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation
, ClampImageToSourceRect, url); | 205 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation
, ClampImageToSourceRect, url); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 501 |
| 513 return m_page; | 502 return m_page; |
| 514 } | 503 } |
| 515 | 504 |
| 516 String SVGImage::filenameExtension() const | 505 String SVGImage::filenameExtension() const |
| 517 { | 506 { |
| 518 return "svg"; | 507 return "svg"; |
| 519 } | 508 } |
| 520 | 509 |
| 521 } // namespace blink | 510 } // namespace blink |
| OLD | NEW |