| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return false; | 109 return false; |
| 110 } | 110 } |
| 111 walker.next(); | 111 walker.next(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Because SVG image rendering disallows external resources and links, these | 114 // Because SVG image rendering disallows external resources and links, these |
| 115 // images effectively are restricted to a single security origin. | 115 // images effectively are restricted to a single security origin. |
| 116 return true; | 116 return true; |
| 117 } | 117 } |
| 118 | 118 |
| 119 static SVGSVGElement* svgRootElement(Page* page) |
| 120 { |
| 121 if (!page) |
| 122 return 0; |
| 123 LocalFrame* frame = page->mainFrame(); |
| 124 return toSVGDocument(frame->document())->rootElement(); |
| 125 } |
| 126 |
| 119 void SVGImage::setContainerSize(const IntSize& size) | 127 void SVGImage::setContainerSize(const IntSize& size) |
| 120 { | 128 { |
| 121 if (!m_page || !usesContainerSize()) | 129 if (!usesContainerSize()) |
| 122 return; | 130 return; |
| 123 | 131 |
| 124 LocalFrame* frame = m_page->mainFrame(); | 132 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 125 SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement()
; | |
| 126 if (!rootElement) | 133 if (!rootElement) |
| 127 return; | 134 return; |
| 128 | 135 |
| 129 FrameView* view = frameView(); | 136 FrameView* view = frameView(); |
| 130 view->resize(this->containerSize()); | 137 view->resize(this->containerSize()); |
| 131 | 138 |
| 132 RenderSVGRoot* renderer = toRenderSVGRoot(rootElement->renderer()); | 139 RenderSVGRoot* renderer = toRenderSVGRoot(rootElement->renderer()); |
| 133 if (!renderer) | 140 if (!renderer) |
| 134 return; | 141 return; |
| 135 renderer->setContainerSize(size); | 142 renderer->setContainerSize(size); |
| 136 } | 143 } |
| 137 | 144 |
| 138 IntSize SVGImage::containerSize() const | 145 IntSize SVGImage::containerSize() const |
| 139 { | 146 { |
| 140 if (!m_page) | 147 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 141 return IntSize(); | |
| 142 LocalFrame* frame = m_page->mainFrame(); | |
| 143 SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement()
; | |
| 144 if (!rootElement) | 148 if (!rootElement) |
| 145 return IntSize(); | 149 return IntSize(); |
| 146 | 150 |
| 147 RenderSVGRoot* renderer = toRenderSVGRoot(rootElement->renderer()); | 151 RenderSVGRoot* renderer = toRenderSVGRoot(rootElement->renderer()); |
| 148 if (!renderer) | 152 if (!renderer) |
| 149 return IntSize(); | 153 return IntSize(); |
| 150 | 154 |
| 151 // If a container size is available it has precedence. | 155 // If a container size is available it has precedence. |
| 152 IntSize containerSize = renderer->containerSize(); | 156 IntSize containerSize = renderer->containerSize(); |
| 153 if (!containerSize.isEmpty()) | 157 if (!containerSize.isEmpty()) |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 imageObserver()->didDraw(this); | 288 imageObserver()->didDraw(this); |
| 285 | 289 |
| 286 // Start any (SMIL) animations if needed. This will restart or continue | 290 // Start any (SMIL) animations if needed. This will restart or continue |
| 287 // animations if preceded by calls to resetAnimation or stopAnimation | 291 // animations if preceded by calls to resetAnimation or stopAnimation |
| 288 // respectively. | 292 // respectively. |
| 289 startAnimation(); | 293 startAnimation(); |
| 290 } | 294 } |
| 291 | 295 |
| 292 RenderBox* SVGImage::embeddedContentBox() const | 296 RenderBox* SVGImage::embeddedContentBox() const |
| 293 { | 297 { |
| 294 if (!m_page) | 298 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 295 return 0; | |
| 296 LocalFrame* frame = m_page->mainFrame(); | |
| 297 SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement()
; | |
| 298 if (!rootElement) | 299 if (!rootElement) |
| 299 return 0; | 300 return 0; |
| 300 return toRenderBox(rootElement->renderer()); | 301 return toRenderBox(rootElement->renderer()); |
| 301 } | 302 } |
| 302 | 303 |
| 303 FrameView* SVGImage::frameView() const | 304 FrameView* SVGImage::frameView() const |
| 304 { | 305 { |
| 305 if (!m_page) | 306 if (!m_page) |
| 306 return 0; | 307 return 0; |
| 307 | 308 |
| 308 return m_page->mainFrame()->view(); | 309 return m_page->mainFrame()->view(); |
| 309 } | 310 } |
| 310 | 311 |
| 311 bool SVGImage::hasRelativeWidth() const | 312 bool SVGImage::hasRelativeWidth() const |
| 312 { | 313 { |
| 313 if (!m_page) | 314 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 314 return false; | |
| 315 LocalFrame* frame = m_page->mainFrame(); | |
| 316 SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement()
; | |
| 317 if (!rootElement) | 315 if (!rootElement) |
| 318 return false; | 316 return false; |
| 319 return rootElement->intrinsicWidth().isPercent(); | 317 return rootElement->intrinsicWidth().isPercent(); |
| 320 } | 318 } |
| 321 | 319 |
| 322 bool SVGImage::hasRelativeHeight() const | 320 bool SVGImage::hasRelativeHeight() const |
| 323 { | 321 { |
| 324 if (!m_page) | 322 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 325 return false; | |
| 326 LocalFrame* frame = m_page->mainFrame(); | |
| 327 SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement()
; | |
| 328 if (!rootElement) | 323 if (!rootElement) |
| 329 return false; | 324 return false; |
| 330 return rootElement->intrinsicHeight().isPercent(); | 325 return rootElement->intrinsicHeight().isPercent(); |
| 331 } | 326 } |
| 332 | 327 |
| 333 void SVGImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrin
sicHeight, FloatSize& intrinsicRatio) | 328 void SVGImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrin
sicHeight, FloatSize& intrinsicRatio) |
| 334 { | 329 { |
| 335 if (!m_page) | 330 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 336 return; | |
| 337 LocalFrame* frame = m_page->mainFrame(); | |
| 338 SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement()
; | |
| 339 if (!rootElement) | 331 if (!rootElement) |
| 340 return; | 332 return; |
| 341 | 333 |
| 342 intrinsicWidth = rootElement->intrinsicWidth(); | 334 intrinsicWidth = rootElement->intrinsicWidth(); |
| 343 intrinsicHeight = rootElement->intrinsicHeight(); | 335 intrinsicHeight = rootElement->intrinsicHeight(); |
| 344 if (rootElement->preserveAspectRatio()->currentValue()->align() == SVGPreser
veAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) | 336 if (rootElement->preserveAspectRatio()->currentValue()->align() == SVGPreser
veAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) |
| 345 return; | 337 return; |
| 346 | 338 |
| 347 intrinsicRatio = rootElement->viewBox()->currentValue()->value().size(); | 339 intrinsicRatio = rootElement->viewBox()->currentValue()->value().size(); |
| 348 if (intrinsicRatio.isEmpty() && intrinsicWidth.isFixed() && intrinsicHeight.
isFixed()) | 340 if (intrinsicRatio.isEmpty() && intrinsicWidth.isFixed() && intrinsicHeight.
isFixed()) |
| 349 intrinsicRatio = FloatSize(floatValueForLength(intrinsicWidth, 0), float
ValueForLength(intrinsicHeight, 0)); | 341 intrinsicRatio = FloatSize(floatValueForLength(intrinsicWidth, 0), float
ValueForLength(intrinsicHeight, 0)); |
| 350 } | 342 } |
| 351 | 343 |
| 352 // FIXME: support catchUpIfNecessary. | 344 // FIXME: support catchUpIfNecessary. |
| 353 void SVGImage::startAnimation(bool /* catchUpIfNecessary */) | 345 void SVGImage::startAnimation(bool /* catchUpIfNecessary */) |
| 354 { | 346 { |
| 355 if (!m_page) | 347 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 356 return; | |
| 357 LocalFrame* frame = m_page->mainFrame(); | |
| 358 SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement()
; | |
| 359 if (!rootElement || !rootElement->animationsPaused()) | 348 if (!rootElement || !rootElement->animationsPaused()) |
| 360 return; | 349 return; |
| 361 rootElement->unpauseAnimations(); | 350 rootElement->unpauseAnimations(); |
| 362 } | 351 } |
| 363 | 352 |
| 364 void SVGImage::stopAnimation() | 353 void SVGImage::stopAnimation() |
| 365 { | 354 { |
| 366 if (!m_page) | 355 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 367 return; | |
| 368 LocalFrame* frame = m_page->mainFrame(); | |
| 369 SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement()
; | |
| 370 if (!rootElement) | 356 if (!rootElement) |
| 371 return; | 357 return; |
| 372 rootElement->pauseAnimations(); | 358 rootElement->pauseAnimations(); |
| 373 } | 359 } |
| 374 | 360 |
| 375 void SVGImage::resetAnimation() | 361 void SVGImage::resetAnimation() |
| 376 { | 362 { |
| 377 if (!m_page) | 363 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 378 return; | |
| 379 LocalFrame* frame = m_page->mainFrame(); | |
| 380 SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement()
; | |
| 381 if (!rootElement) | 364 if (!rootElement) |
| 382 return; | 365 return; |
| 383 rootElement->pauseAnimations(); | 366 rootElement->pauseAnimations(); |
| 384 rootElement->setCurrentTime(0); | 367 rootElement->setCurrentTime(0); |
| 385 } | 368 } |
| 386 | 369 |
| 387 bool SVGImage::hasAnimations() const | 370 bool SVGImage::hasAnimations() const |
| 388 { | 371 { |
| 389 if (!m_page) | 372 SVGSVGElement* rootElement = svgRootElement(m_page.get()); |
| 390 return false; | |
| 391 LocalFrame* frame = m_page->mainFrame(); | |
| 392 SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement()
; | |
| 393 if (!rootElement) | 373 if (!rootElement) |
| 394 return false; | 374 return false; |
| 395 return rootElement->timeContainer()->hasAnimations() || frame->document()->t
imeline().hasPendingUpdates(); | 375 return rootElement->timeContainer()->hasAnimations() || m_page->mainFrame()-
>document()->timeline().hasPendingUpdates(); |
| 396 } | 376 } |
| 397 | 377 |
| 398 bool SVGImage::dataChanged(bool allDataReceived) | 378 bool SVGImage::dataChanged(bool allDataReceived) |
| 399 { | 379 { |
| 400 TRACE_EVENT0("webkit", "SVGImage::dataChanged"); | 380 TRACE_EVENT0("webkit", "SVGImage::dataChanged"); |
| 401 | 381 |
| 402 // Don't do anything if is an empty image. | 382 // Don't do anything if is an empty image. |
| 403 if (!data()->size()) | 383 if (!data()->size()) |
| 404 return true; | 384 return true; |
| 405 | 385 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 421 |
| 442 return m_page; | 422 return m_page; |
| 443 } | 423 } |
| 444 | 424 |
| 445 String SVGImage::filenameExtension() const | 425 String SVGImage::filenameExtension() const |
| 446 { | 426 { |
| 447 return "svg"; | 427 return "svg"; |
| 448 } | 428 } |
| 449 | 429 |
| 450 } | 430 } |
| OLD | NEW |