| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 | 126 |
| 127 static SVGSVGElement* svgRootElement(Page* page) | 127 static SVGSVGElement* svgRootElement(Page* page) |
| 128 { | 128 { |
| 129 if (!page) | 129 if (!page) |
| 130 return nullptr; | 130 return nullptr; |
| 131 LocalFrame* frame = toLocalFrame(page->mainFrame()); | 131 LocalFrame* frame = toLocalFrame(page->mainFrame()); |
| 132 return frame->document()->accessSVGExtensions().rootElement(); | 132 return frame->document()->accessSVGExtensions().rootElement(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void SVGImage::setContainerSize(const IntSize& size) | 135 void SVGImage::setContainerSize(const LayoutSize& size) |
| 136 { | 136 { |
| 137 if (!usesContainerSize()) | 137 if (!usesContainerSize()) |
| 138 return; | 138 return; |
| 139 | 139 |
| 140 SVGSVGElement* rootElement = svgRootElement(m_page.get()); | 140 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 141 if (!rootElement) | 141 if (!rootElement) |
| 142 return; | 142 return; |
| 143 | 143 |
| 144 FrameView* view = frameView(); | 144 FrameView* view = frameView(); |
| 145 view->resize(this->containerSize()); | 145 view->resize(roundedIntSize(this->containerSize())); |
| 146 | 146 |
| 147 LayoutSVGRoot* layoutObject = toLayoutSVGRoot(rootElement->layoutObject()); | 147 LayoutSVGRoot* layoutObject = toLayoutSVGRoot(rootElement->layoutObject()); |
| 148 if (!layoutObject) | 148 if (!layoutObject) |
| 149 return; | 149 return; |
| 150 layoutObject->setContainerSize(size); | 150 layoutObject->setContainerSize(size); |
| 151 } | 151 } |
| 152 | 152 |
| 153 IntSize SVGImage::containerSize() const | 153 LayoutSize SVGImage::containerSize() const |
| 154 { | 154 { |
| 155 SVGSVGElement* rootElement = svgRootElement(m_page.get()); | 155 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 156 if (!rootElement) | 156 if (!rootElement) |
| 157 return IntSize(); | 157 return LayoutSize(); |
| 158 | 158 |
| 159 LayoutSVGRoot* layoutObject = toLayoutSVGRoot(rootElement->layoutObject()); | 159 LayoutSVGRoot* layoutObject = toLayoutSVGRoot(rootElement->layoutObject()); |
| 160 if (!layoutObject) | 160 if (!layoutObject) |
| 161 return IntSize(); | 161 return LayoutSize(); |
| 162 | 162 |
| 163 // If a container size is available it has precedence. | 163 // If a container size is available it has precedence. |
| 164 IntSize containerSize = layoutObject->containerSize(); | 164 LayoutSize containerSize = layoutObject->containerSize(); |
| 165 if (!containerSize.isEmpty()) | 165 if (!containerSize.isEmpty()) |
| 166 return containerSize; | 166 return containerSize; |
| 167 | 167 |
| 168 // Assure that a container size is always given for a non-identity zoom leve
l. | 168 // Assure that a container size is always given for a non-identity zoom leve
l. |
| 169 ASSERT(layoutObject->style()->effectiveZoom() == 1); | 169 ASSERT(layoutObject->style()->effectiveZoom() == 1); |
| 170 | 170 |
| 171 FloatSize intrinsicSize; | 171 FloatSize intrinsicSize; |
| 172 double intrinsicRatio = 0; | 172 double intrinsicRatio = 0; |
| 173 layoutObject->computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio
); | 173 layoutObject->computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio
); |
| 174 | 174 |
| 175 if (intrinsicSize.isEmpty() && intrinsicRatio) { | 175 if (intrinsicSize.isEmpty() && intrinsicRatio) { |
| 176 if (!intrinsicSize.width() && intrinsicSize.height()) | 176 if (!intrinsicSize.width() && intrinsicSize.height()) |
| 177 intrinsicSize.setWidth(intrinsicSize.height() * intrinsicRatio); | 177 intrinsicSize.setWidth(intrinsicSize.height() * intrinsicRatio); |
| 178 else if (intrinsicSize.width() && !intrinsicSize.height()) | 178 else if (intrinsicSize.width() && !intrinsicSize.height()) |
| 179 intrinsicSize.setHeight(intrinsicSize.width() / intrinsicRatio); | 179 intrinsicSize.setHeight(intrinsicSize.width() / intrinsicRatio); |
| 180 } | 180 } |
| 181 | 181 |
| 182 // TODO(davve): In order to maintain aspect ratio the intrinsic | 182 // TODO(davve): In order to maintain aspect ratio the intrinsic |
| 183 // size is faked from the viewBox as a last resort. This may cause | 183 // size is faked from the viewBox as a last resort. This may cause |
| 184 // unwanted side effects. Preferably we should be able to signal | 184 // unwanted side effects. Preferably we should be able to signal |
| 185 // the intrinsic ratio in another way. | 185 // the intrinsic ratio in another way. |
| 186 if (intrinsicSize.isEmpty()) | 186 if (intrinsicSize.isEmpty()) |
| 187 intrinsicSize = rootElement->currentViewBoxRect().size(); | 187 intrinsicSize = rootElement->currentViewBoxRect().size(); |
| 188 | 188 |
| 189 if (!intrinsicSize.isEmpty()) | 189 if (!intrinsicSize.isEmpty()) |
| 190 return expandedIntSize(intrinsicSize); | 190 return LayoutSize(intrinsicSize); |
| 191 | 191 |
| 192 // As last resort, use CSS replaced element fallback size. | 192 // As last resort, use CSS replaced element fallback size. |
| 193 return IntSize(300, 150); | 193 return LayoutSize(300, 150); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl
oatSize containerSize, float zoom, const FloatRect& dstRect, | 196 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl
oatSize containerSize, float zoom, const FloatRect& dstRect, |
| 197 const FloatRect& srcRect, const KURL& url) | 197 const FloatRect& srcRect, const KURL& url) |
| 198 { | 198 { |
| 199 if (!m_page) | 199 if (!m_page) |
| 200 return; | 200 return; |
| 201 | 201 |
| 202 // Temporarily disable the image observer to prevent changeInRect() calls du
e re-laying out the image. | 202 // Temporarily disable the image observer to prevent changeInRect() calls du
e re-laying out the image. |
| 203 ImageObserverDisabler imageObserverDisabler(this); | 203 ImageObserverDisabler imageObserverDisabler(this); |
| 204 | 204 |
| 205 IntSize roundedContainerSize = roundedIntSize(containerSize); | 205 setContainerSize(LayoutSize(containerSize)); |
| 206 setContainerSize(roundedContainerSize); | |
| 207 | 206 |
| 208 FloatRect scaledSrc = srcRect; | 207 FloatRect scaledSrc = srcRect; |
| 209 scaledSrc.scale(1 / zoom); | 208 scaledSrc.scale(1 / zoom); |
| 210 | 209 |
| 211 // Compensate for the container size rounding by adjusting the source rect. | |
| 212 FloatSize adjustedSrcSize = scaledSrc.size(); | |
| 213 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); | |
| 214 scaledSrc.setSize(adjustedSrcSize); | |
| 215 | |
| 216 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation
, ClampImageToSourceRect, url); | 210 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation
, ClampImageToSourceRect, url); |
| 217 } | 211 } |
| 218 | 212 |
| 219 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() | 213 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() |
| 220 { | 214 { |
| 221 if (!m_page) | 215 if (!m_page) |
| 222 return nullptr; | 216 return nullptr; |
| 223 | 217 |
| 224 SkPictureRecorder recorder; | 218 SkPictureRecorder recorder; |
| 225 SkCanvas* canvas = recorder.beginRecording(width(), height()); | 219 SkCanvas* canvas = recorder.beginRecording(width(), height()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 if (!m_page) | 281 if (!m_page) |
| 288 return; | 282 return; |
| 289 | 283 |
| 290 drawInternal(canvas, paint, dstRect, srcRect, shouldRespectImageOrientation,
clampMode, KURL()); | 284 drawInternal(canvas, paint, dstRect, srcRect, shouldRespectImageOrientation,
clampMode, KURL()); |
| 291 } | 285 } |
| 292 | 286 |
| 293 void SVGImage::drawInternal(SkCanvas* canvas, const SkPaint& paint, const FloatR
ect& dstRect, const FloatRect& srcRect, | 287 void SVGImage::drawInternal(SkCanvas* canvas, const SkPaint& paint, const FloatR
ect& dstRect, const FloatRect& srcRect, |
| 294 RespectImageOrientationEnum, ImageClampingMode, const KURL& url) | 288 RespectImageOrientationEnum, ImageClampingMode, const KURL& url) |
| 295 { | 289 { |
| 296 FrameView* view = frameView(); | 290 FrameView* view = frameView(); |
| 297 view->resize(containerSize()); | 291 view->resize(roundedIntSize(containerSize())); |
| 298 | 292 |
| 299 // Always call processUrlFragment, even if the url is empty, because | 293 // Always call processUrlFragment, even if the url is empty, because |
| 300 // there may have been a previous url/fragment that needs to be reset. | 294 // there may have been a previous url/fragment that needs to be reset. |
| 301 view->processUrlFragment(url); | 295 view->processUrlFragment(url); |
| 302 | 296 |
| 303 SkPictureBuilder imagePicture(dstRect); | 297 SkPictureBuilder imagePicture(dstRect); |
| 304 { | 298 { |
| 305 ClipRecorder clipRecorder(imagePicture.context(), *this, DisplayItem::Cl
ipNodeImage, LayoutRect(enclosingIntRect(dstRect))); | 299 ClipRecorder clipRecorder(imagePicture.context(), *this, DisplayItem::Cl
ipNodeImage, LayoutRect(enclosingIntRect(dstRect))); |
| 306 | 300 |
| 307 // We can only draw the entire frame, clipped to the rect we want. So co
mpute where the top left | 301 // We can only draw the entire frame, clipped to the rect we want. So co
mpute where the top left |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 frame->view()->setCanHaveScrollbars(false); // SVG Images will always sy
nthesize a viewBox, if it's not available, and thus never see scrollbars. | 489 frame->view()->setCanHaveScrollbars(false); // SVG Images will always sy
nthesize a viewBox, if it's not available, and thus never see scrollbars. |
| 496 frame->view()->setTransparent(true); // SVG Images are transparent. | 490 frame->view()->setTransparent(true); // SVG Images are transparent. |
| 497 | 491 |
| 498 m_page = page.release(); | 492 m_page = page.release(); |
| 499 | 493 |
| 500 TRACE_EVENT0("blink", "SVGImage::dataChanged::load"); | 494 TRACE_EVENT0("blink", "SVGImage::dataChanged::load"); |
| 501 loader.load(FrameLoadRequest(0, blankURL(), SubstituteData(data(), Atomi
cString("image/svg+xml", AtomicString::ConstructFromLiteral), | 495 loader.load(FrameLoadRequest(0, blankURL(), SubstituteData(data(), Atomi
cString("image/svg+xml", AtomicString::ConstructFromLiteral), |
| 502 AtomicString("UTF-8", AtomicString::ConstructFromLiteral), KURL(), F
orceSynchronousLoad))); | 496 AtomicString("UTF-8", AtomicString::ConstructFromLiteral), KURL(), F
orceSynchronousLoad))); |
| 503 | 497 |
| 504 // Set the intrinsic size before a container size is available. | 498 // Set the intrinsic size before a container size is available. |
| 505 m_intrinsicSize = containerSize(); | 499 m_intrinsicSize = roundedIntSize(containerSize()); |
| 506 } | 500 } |
| 507 | 501 |
| 508 return m_page; | 502 return m_page; |
| 509 } | 503 } |
| 510 | 504 |
| 511 String SVGImage::filenameExtension() const | 505 String SVGImage::filenameExtension() const |
| 512 { | 506 { |
| 513 return "svg"; | 507 return "svg"; |
| 514 } | 508 } |
| 515 | 509 |
| 516 } | 510 } |
| OLD | NEW |