| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) 2007 Apple Inc. All rights reserved. | 4 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 5 * Copyright (C) 2014 Google, Inc. | 5 * Copyright (C) 2014 Google, Inc. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "core/css/CSSHelper.h" | 30 #include "core/css/CSSHelper.h" |
| 31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
| 32 #include "core/dom/ElementTraversal.h" | 32 #include "core/dom/ElementTraversal.h" |
| 33 #include "core/dom/StaticNodeList.h" | 33 #include "core/dom/StaticNodeList.h" |
| 34 #include "core/editing/FrameSelection.h" | 34 #include "core/editing/FrameSelection.h" |
| 35 #include "core/events/EventListener.h" | 35 #include "core/events/EventListener.h" |
| 36 #include "core/frame/LocalFrame.h" | 36 #include "core/frame/LocalFrame.h" |
| 37 #include "core/page/FrameTree.h" | 37 #include "core/page/FrameTree.h" |
| 38 #include "core/frame/FrameView.h" | 38 #include "core/frame/FrameView.h" |
| 39 #include "core/frame/UseCounter.h" | 39 #include "core/frame/UseCounter.h" |
| 40 #include "core/rendering/RenderObject.h" | 40 #include "core/layout/LayoutObject.h" |
| 41 #include "core/rendering/svg/RenderSVGModelObject.h" | 41 #include "core/rendering/svg/RenderSVGModelObject.h" |
| 42 #include "core/rendering/svg/RenderSVGRoot.h" | 42 #include "core/rendering/svg/RenderSVGRoot.h" |
| 43 #include "core/rendering/svg/RenderSVGViewportContainer.h" | 43 #include "core/rendering/svg/RenderSVGViewportContainer.h" |
| 44 #include "core/svg/SVGAngleTearOff.h" | 44 #include "core/svg/SVGAngleTearOff.h" |
| 45 #include "core/svg/SVGNumberTearOff.h" | 45 #include "core/svg/SVGNumberTearOff.h" |
| 46 #include "core/svg/SVGPreserveAspectRatio.h" | 46 #include "core/svg/SVGPreserveAspectRatio.h" |
| 47 #include "core/svg/SVGRectTearOff.h" | 47 #include "core/svg/SVGRectTearOff.h" |
| 48 #include "core/svg/SVGTransform.h" | 48 #include "core/svg/SVGTransform.h" |
| 49 #include "core/svg/SVGTransformList.h" | 49 #include "core/svg/SVGTransformList.h" |
| 50 #include "core/svg/SVGTransformTearOff.h" | 50 #include "core/svg/SVGTransformTearOff.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 197 } |
| 198 | 198 |
| 199 void SVGSVGElement::setCurrentTranslate(const FloatPoint& point) | 199 void SVGSVGElement::setCurrentTranslate(const FloatPoint& point) |
| 200 { | 200 { |
| 201 m_translation->setValue(point); | 201 m_translation->setValue(point); |
| 202 updateCurrentTranslate(); | 202 updateCurrentTranslate(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void SVGSVGElement::updateCurrentTranslate() | 205 void SVGSVGElement::updateCurrentTranslate() |
| 206 { | 206 { |
| 207 if (RenderObject* object = renderer()) | 207 if (LayoutObject* object = renderer()) |
| 208 object->setNeedsLayoutAndFullPaintInvalidation(); | 208 object->setNeedsLayoutAndFullPaintInvalidation(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void SVGSVGElement::parseAttribute(const QualifiedName& name, const AtomicString
& value) | 211 void SVGSVGElement::parseAttribute(const QualifiedName& name, const AtomicString
& value) |
| 212 { | 212 { |
| 213 if (!nearestViewportElement()) { | 213 if (!nearestViewportElement()) { |
| 214 bool setListener = true; | 214 bool setListener = true; |
| 215 | 215 |
| 216 // Only handle events if we're the outermost <svg> element | 216 // Only handle events if we're the outermost <svg> element |
| 217 if (name == HTMLNames::onunloadAttr) | 217 if (name == HTMLNames::onunloadAttr) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 invalidateRelativeLengthClients(); | 276 invalidateRelativeLengthClients(); |
| 277 | 277 |
| 278 // At the SVG/HTML boundary (aka RenderSVGRoot), the width and | 278 // At the SVG/HTML boundary (aka RenderSVGRoot), the width and |
| 279 // height attributes can affect the replaced size so we need | 279 // height attributes can affect the replaced size so we need |
| 280 // to mark it for updating. | 280 // to mark it for updating. |
| 281 // | 281 // |
| 282 // FIXME: For width/height animated as XML attributes on SVG | 282 // FIXME: For width/height animated as XML attributes on SVG |
| 283 // roots, there is an attribute synchronization missing. See | 283 // roots, there is an attribute synchronization missing. See |
| 284 // http://crbug.com/364807 | 284 // http://crbug.com/364807 |
| 285 if (widthChanged || heightChanged) { | 285 if (widthChanged || heightChanged) { |
| 286 RenderObject* renderObject = renderer(); | 286 LayoutObject* layoutObject = renderer(); |
| 287 if (renderObject && renderObject->isSVGRoot()) { | 287 if (layoutObject && layoutObject->isSVGRoot()) { |
| 288 invalidateSVGPresentationAttributeStyle(); | 288 invalidateSVGPresentationAttributeStyle(); |
| 289 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracin
g::create(StyleChangeReason::SVGContainerSizeChange)); | 289 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracin
g::create(StyleChangeReason::SVGContainerSizeChange)); |
| 290 } | 290 } |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 | 293 |
| 294 if (SVGFitToViewBox::isKnownAttribute(attrName)) { | 294 if (SVGFitToViewBox::isKnownAttribute(attrName)) { |
| 295 updateRelativeLengthsOrViewBox = true; | 295 updateRelativeLengthsOrViewBox = true; |
| 296 if (RenderObject* object = renderer()) | 296 if (LayoutObject* object = renderer()) |
| 297 object->setNeedsTransformUpdate(); | 297 object->setNeedsTransformUpdate(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 SVGElement::InvalidationGuard invalidationGuard(this); | 300 SVGElement::InvalidationGuard invalidationGuard(this); |
| 301 | 301 |
| 302 if (updateRelativeLengthsOrViewBox | 302 if (updateRelativeLengthsOrViewBox |
| 303 || SVGZoomAndPan::isKnownAttribute(attrName)) { | 303 || SVGZoomAndPan::isKnownAttribute(attrName)) { |
| 304 if (renderer()) | 304 if (renderer()) |
| 305 markForLayoutAndParentResourceInvalidation(renderer()); | 305 markForLayoutAndParentResourceInvalidation(renderer()); |
| 306 return; | 306 return; |
| 307 } | 307 } |
| 308 | 308 |
| 309 SVGGraphicsElement::svgAttributeChanged(attrName); | 309 SVGGraphicsElement::svgAttributeChanged(attrName); |
| 310 } | 310 } |
| 311 | 311 |
| 312 // FloatRect::intersects does not consider horizontal or vertical lines (because
of isEmpty()). | 312 // FloatRect::intersects does not consider horizontal or vertical lines (because
of isEmpty()). |
| 313 static bool intersectsAllowingEmpty(const FloatRect& r1, const FloatRect& r2) | 313 static bool intersectsAllowingEmpty(const FloatRect& r1, const FloatRect& r2) |
| 314 { | 314 { |
| 315 if (r1.width() < 0 || r1.height() < 0 || r2.width() < 0 || r2.height() < 0) | 315 if (r1.width() < 0 || r1.height() < 0 || r2.width() < 0 || r2.height() < 0) |
| 316 return false; | 316 return false; |
| 317 | 317 |
| 318 return r1.x() < r2.maxX() && r2.x() < r1.maxX() | 318 return r1.x() < r2.maxX() && r2.x() < r1.maxX() |
| 319 && r1.y() < r2.maxY() && r2.y() < r1.maxY(); | 319 && r1.y() < r2.maxY() && r2.y() < r1.maxY(); |
| 320 } | 320 } |
| 321 | 321 |
| 322 // One of the element types that can cause graphics to be drawn onto the target
canvas. | 322 // One of the element types that can cause graphics to be drawn onto the target
canvas. |
| 323 // Specifically: circle, ellipse, image, line, path, polygon, polyline, rect, te
xt and use. | 323 // Specifically: circle, ellipse, image, line, path, polygon, polyline, rect, te
xt and use. |
| 324 static bool isIntersectionOrEnclosureTarget(RenderObject* renderer) | 324 static bool isIntersectionOrEnclosureTarget(LayoutObject* renderer) |
| 325 { | 325 { |
| 326 return renderer->isSVGShape() | 326 return renderer->isSVGShape() |
| 327 || renderer->isSVGText() | 327 || renderer->isSVGText() |
| 328 || renderer->isSVGImage() | 328 || renderer->isSVGImage() |
| 329 || isSVGUseElement(*renderer->node()); | 329 || isSVGUseElement(*renderer->node()); |
| 330 } | 330 } |
| 331 | 331 |
| 332 bool SVGSVGElement::checkIntersectionOrEnclosure(const SVGElement& element, cons
t FloatRect& rect, | 332 bool SVGSVGElement::checkIntersectionOrEnclosure(const SVGElement& element, cons
t FloatRect& rect, |
| 333 CheckIntersectionOrEnclosure mode) const | 333 CheckIntersectionOrEnclosure mode) const |
| 334 { | 334 { |
| 335 RenderObject* renderer = element.renderer(); | 335 LayoutObject* renderer = element.renderer(); |
| 336 ASSERT(!renderer || renderer->style()); | 336 ASSERT(!renderer || renderer->style()); |
| 337 if (!renderer || renderer->style()->pointerEvents() == PE_NONE) | 337 if (!renderer || renderer->style()->pointerEvents() == PE_NONE) |
| 338 return false; | 338 return false; |
| 339 | 339 |
| 340 if (!isIntersectionOrEnclosureTarget(renderer)) | 340 if (!isIntersectionOrEnclosureTarget(renderer)) |
| 341 return false; | 341 return false; |
| 342 | 342 |
| 343 AffineTransform ctm = toSVGGraphicsElement(element).computeCTM(AncestorScope
, DisallowStyleUpdate, this); | 343 AffineTransform ctm = toSVGGraphicsElement(element).computeCTM(AncestorScope
, DisallowStyleUpdate, this); |
| 344 FloatRect mappedRepaintRect = ctm.mapRect(renderer->paintInvalidationRectInL
ocalCoordinates()); | 344 FloatRect mappedRepaintRect = ctm.mapRect(renderer->paintInvalidationRectInL
ocalCoordinates()); |
| 345 | 345 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 if (!hasEmptyViewBox()) { | 465 if (!hasEmptyViewBox()) { |
| 466 FloatSize size = currentViewportSize(); | 466 FloatSize size = currentViewportSize(); |
| 467 viewBoxTransform = viewBoxToViewTransform(size.width(), size.height()); | 467 viewBoxTransform = viewBoxToViewTransform(size.width(), size.height()); |
| 468 } | 468 } |
| 469 | 469 |
| 470 AffineTransform transform; | 470 AffineTransform transform; |
| 471 if (!isOutermostSVGSVGElement()) { | 471 if (!isOutermostSVGSVGElement()) { |
| 472 SVGLengthContext lengthContext(this); | 472 SVGLengthContext lengthContext(this); |
| 473 transform.translate(m_x->currentValue()->value(lengthContext), m_y->curr
entValue()->value(lengthContext)); | 473 transform.translate(m_x->currentValue()->value(lengthContext), m_y->curr
entValue()->value(lengthContext)); |
| 474 } else if (mode == SVGElement::ScreenScope) { | 474 } else if (mode == SVGElement::ScreenScope) { |
| 475 if (RenderObject* renderer = this->renderer()) { | 475 if (LayoutObject* renderer = this->renderer()) { |
| 476 FloatPoint location; | 476 FloatPoint location; |
| 477 float zoomFactor = 1; | 477 float zoomFactor = 1; |
| 478 | 478 |
| 479 // At the SVG/HTML boundary (aka RenderSVGRoot), we apply the localT
oBorderBoxTransform | 479 // At the SVG/HTML boundary (aka RenderSVGRoot), we apply the localT
oBorderBoxTransform |
| 480 // to map an element from SVG viewport coordinates to CSS box coordi
nates. | 480 // to map an element from SVG viewport coordinates to CSS box coordi
nates. |
| 481 // RenderSVGRoot's localToAbsolute method expects CSS box coordinate
s. | 481 // RenderSVGRoot's localToAbsolute method expects CSS box coordinate
s. |
| 482 // We also need to adjust for the zoom level factored into CSS coord
inates (bug #96361). | 482 // We also need to adjust for the zoom level factored into CSS coord
inates (bug #96361). |
| 483 if (renderer->isSVGRoot()) { | 483 if (renderer->isSVGRoot()) { |
| 484 location = toRenderSVGRoot(renderer)->localToBorderBoxTransform(
).mapPoint(location); | 484 location = toRenderSVGRoot(renderer)->localToBorderBoxTransform(
).mapPoint(location); |
| 485 zoomFactor = 1 / renderer->style()->effectiveZoom(); | 485 zoomFactor = 1 / renderer->style()->effectiveZoom(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 510 { | 510 { |
| 511 // FIXME: We should respect display: none on the documentElement svg element | 511 // FIXME: We should respect display: none on the documentElement svg element |
| 512 // but many things in FrameView and SVGImage depend on the RenderSVGRoot whe
n | 512 // but many things in FrameView and SVGImage depend on the RenderSVGRoot whe
n |
| 513 // they should instead depend on the RenderView. | 513 // they should instead depend on the RenderView. |
| 514 // https://bugs.webkit.org/show_bug.cgi?id=103493 | 514 // https://bugs.webkit.org/show_bug.cgi?id=103493 |
| 515 if (document().documentElement() == this) | 515 if (document().documentElement() == this) |
| 516 return true; | 516 return true; |
| 517 return Element::rendererIsNeeded(style); | 517 return Element::rendererIsNeeded(style); |
| 518 } | 518 } |
| 519 | 519 |
| 520 RenderObject* SVGSVGElement::createRenderer(const RenderStyle&) | 520 LayoutObject* SVGSVGElement::createRenderer(const RenderStyle&) |
| 521 { | 521 { |
| 522 if (isOutermostSVGSVGElement()) | 522 if (isOutermostSVGSVGElement()) |
| 523 return new RenderSVGRoot(this); | 523 return new RenderSVGRoot(this); |
| 524 | 524 |
| 525 return new RenderSVGViewportContainer(this); | 525 return new RenderSVGViewportContainer(this); |
| 526 } | 526 } |
| 527 | 527 |
| 528 Node::InsertionNotificationRequest SVGSVGElement::insertedInto(ContainerNode* ro
otParent) | 528 Node::InsertionNotificationRequest SVGSVGElement::insertedInto(ContainerNode* ro
otParent) |
| 529 { | 529 { |
| 530 if (rootParent->inDocument()) { | 530 if (rootParent->inDocument()) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 | 665 |
| 666 AffineTransform transform; | 666 AffineTransform transform; |
| 667 if (transformList->concatenate(transform)) | 667 if (transformList->concatenate(transform)) |
| 668 ctm *= transform; | 668 ctm *= transform; |
| 669 | 669 |
| 670 return ctm; | 670 return ctm; |
| 671 } | 671 } |
| 672 | 672 |
| 673 void SVGSVGElement::setupInitialView(const String& fragmentIdentifier, Element*
anchorNode) | 673 void SVGSVGElement::setupInitialView(const String& fragmentIdentifier, Element*
anchorNode) |
| 674 { | 674 { |
| 675 RenderObject* renderer = this->renderer(); | 675 LayoutObject* renderer = this->renderer(); |
| 676 SVGViewSpec* view = m_viewSpec.get(); | 676 SVGViewSpec* view = m_viewSpec.get(); |
| 677 if (view) | 677 if (view) |
| 678 view->reset(); | 678 view->reset(); |
| 679 | 679 |
| 680 bool hadUseCurrentView = m_useCurrentView; | 680 bool hadUseCurrentView = m_useCurrentView; |
| 681 m_useCurrentView = false; | 681 m_useCurrentView = false; |
| 682 | 682 |
| 683 if (fragmentIdentifier.startsWith("xpointer(")) { | 683 if (fragmentIdentifier.startsWith("xpointer(")) { |
| 684 // FIXME: XPointer references are ignored (https://bugs.webkit.org/show_
bug.cgi?id=17491) | 684 // FIXME: XPointer references are ignored (https://bugs.webkit.org/show_
bug.cgi?id=17491) |
| 685 if (renderer && hadUseCurrentView) | 685 if (renderer && hadUseCurrentView) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 704 // Spec: If the SVG fragment identifier addresses a ‘view’ element within an
SVG document (e.g., MyDrawing.svg#MyView | 704 // Spec: If the SVG fragment identifier addresses a ‘view’ element within an
SVG document (e.g., MyDrawing.svg#MyView |
| 705 // or MyDrawing.svg#xpointer(id('MyView'))) then the closest ancestor ‘svg’
element is displayed in the viewport. | 705 // or MyDrawing.svg#xpointer(id('MyView'))) then the closest ancestor ‘svg’
element is displayed in the viewport. |
| 706 // Any view specification attributes included on the given ‘view’ element ov
erride the corresponding view specification | 706 // Any view specification attributes included on the given ‘view’ element ov
erride the corresponding view specification |
| 707 // attributes on the closest ancestor ‘svg’ element. | 707 // attributes on the closest ancestor ‘svg’ element. |
| 708 if (isSVGViewElement(anchorNode)) { | 708 if (isSVGViewElement(anchorNode)) { |
| 709 SVGViewElement& viewElement = toSVGViewElement(*anchorNode); | 709 SVGViewElement& viewElement = toSVGViewElement(*anchorNode); |
| 710 | 710 |
| 711 if (SVGSVGElement* svg = viewElement.ownerSVGElement()) { | 711 if (SVGSVGElement* svg = viewElement.ownerSVGElement()) { |
| 712 svg->inheritViewAttributes(&viewElement); | 712 svg->inheritViewAttributes(&viewElement); |
| 713 | 713 |
| 714 if (RenderObject* renderer = svg->renderer()) | 714 if (LayoutObject* renderer = svg->renderer()) |
| 715 markForLayoutAndParentResourceInvalidation(renderer); | 715 markForLayoutAndParentResourceInvalidation(renderer); |
| 716 | 716 |
| 717 return; | 717 return; |
| 718 } | 718 } |
| 719 } | 719 } |
| 720 | 720 |
| 721 // If we previously had a view and didn't get a new one, we need to | 721 // If we previously had a view and didn't get a new one, we need to |
| 722 // layout again. | 722 // layout again. |
| 723 if (renderer && hadUseCurrentView) | 723 if (renderer && hadUseCurrentView) |
| 724 markForLayoutAndParentResourceInvalidation(renderer); | 724 markForLayoutAndParentResourceInvalidation(renderer); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 visitor->trace(m_width); | 771 visitor->trace(m_width); |
| 772 visitor->trace(m_height); | 772 visitor->trace(m_height); |
| 773 visitor->trace(m_translation); | 773 visitor->trace(m_translation); |
| 774 visitor->trace(m_timeContainer); | 774 visitor->trace(m_timeContainer); |
| 775 visitor->trace(m_viewSpec); | 775 visitor->trace(m_viewSpec); |
| 776 SVGGraphicsElement::trace(visitor); | 776 SVGGraphicsElement::trace(visitor); |
| 777 SVGFitToViewBox::trace(visitor); | 777 SVGFitToViewBox::trace(visitor); |
| 778 } | 778 } |
| 779 | 779 |
| 780 } // namespace blink | 780 } // namespace blink |
| OLD | NEW |