| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 198 } |
| 199 | 199 |
| 200 void SVGSVGElement::setCurrentTranslate(const FloatPoint& point) | 200 void SVGSVGElement::setCurrentTranslate(const FloatPoint& point) |
| 201 { | 201 { |
| 202 m_translation->setValue(point); | 202 m_translation->setValue(point); |
| 203 updateCurrentTranslate(); | 203 updateCurrentTranslate(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void SVGSVGElement::updateCurrentTranslate() | 206 void SVGSVGElement::updateCurrentTranslate() |
| 207 { | 207 { |
| 208 if (LayoutObject* object = renderer()) | 208 if (LayoutObject* object = layoutObject()) |
| 209 object->setNeedsLayoutAndFullPaintInvalidation(); | 209 object->setNeedsLayoutAndFullPaintInvalidation(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void SVGSVGElement::parseAttribute(const QualifiedName& name, const AtomicString
& value) | 212 void SVGSVGElement::parseAttribute(const QualifiedName& name, const AtomicString
& value) |
| 213 { | 213 { |
| 214 if (!nearestViewportElement()) { | 214 if (!nearestViewportElement()) { |
| 215 bool setListener = true; | 215 bool setListener = true; |
| 216 | 216 |
| 217 // Only handle events if we're the outermost <svg> element | 217 // Only handle events if we're the outermost <svg> element |
| 218 if (name == HTMLNames::onunloadAttr) | 218 if (name == HTMLNames::onunloadAttr) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 invalidateRelativeLengthClients(); | 287 invalidateRelativeLengthClients(); |
| 288 | 288 |
| 289 // At the SVG/HTML boundary (aka LayoutSVGRoot), the width and | 289 // At the SVG/HTML boundary (aka LayoutSVGRoot), the width and |
| 290 // height attributes can affect the replaced size so we need | 290 // height attributes can affect the replaced size so we need |
| 291 // to mark it for updating. | 291 // to mark it for updating. |
| 292 // | 292 // |
| 293 // FIXME: For width/height animated as XML attributes on SVG | 293 // FIXME: For width/height animated as XML attributes on SVG |
| 294 // roots, there is an attribute synchronization missing. See | 294 // roots, there is an attribute synchronization missing. See |
| 295 // http://crbug.com/364807 | 295 // http://crbug.com/364807 |
| 296 if (widthChanged || heightChanged) { | 296 if (widthChanged || heightChanged) { |
| 297 LayoutObject* layoutObject = renderer(); | 297 LayoutObject* layoutObject = this->layoutObject(); |
| 298 if (layoutObject && layoutObject->isSVGRoot()) { | 298 if (layoutObject && layoutObject->isSVGRoot()) { |
| 299 invalidateSVGPresentationAttributeStyle(); | 299 invalidateSVGPresentationAttributeStyle(); |
| 300 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracin
g::create(StyleChangeReason::SVGContainerSizeChange)); | 300 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracin
g::create(StyleChangeReason::SVGContainerSizeChange)); |
| 301 } | 301 } |
| 302 } else { | 302 } else { |
| 303 invalidateSVGPresentationAttributeStyle(); | 303 invalidateSVGPresentationAttributeStyle(); |
| 304 setNeedsStyleRecalc(LocalStyleChange, | 304 setNeedsStyleRecalc(LocalStyleChange, |
| 305 StyleChangeReasonForTracing::fromAttribute(attrName)); | 305 StyleChangeReasonForTracing::fromAttribute(attrName)); |
| 306 } | 306 } |
| 307 } | 307 } |
| 308 | 308 |
| 309 if (SVGFitToViewBox::isKnownAttribute(attrName)) { | 309 if (SVGFitToViewBox::isKnownAttribute(attrName)) { |
| 310 updateRelativeLengthsOrViewBox = true; | 310 updateRelativeLengthsOrViewBox = true; |
| 311 if (LayoutObject* object = renderer()) | 311 if (LayoutObject* object = layoutObject()) |
| 312 object->setNeedsTransformUpdate(); | 312 object->setNeedsTransformUpdate(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 SVGElement::InvalidationGuard invalidationGuard(this); | 315 SVGElement::InvalidationGuard invalidationGuard(this); |
| 316 | 316 |
| 317 if (updateRelativeLengthsOrViewBox | 317 if (updateRelativeLengthsOrViewBox |
| 318 || SVGZoomAndPan::isKnownAttribute(attrName)) { | 318 || SVGZoomAndPan::isKnownAttribute(attrName)) { |
| 319 if (renderer()) | 319 if (layoutObject()) |
| 320 markForLayoutAndParentResourceInvalidation(renderer()); | 320 markForLayoutAndParentResourceInvalidation(layoutObject()); |
| 321 return; | 321 return; |
| 322 } | 322 } |
| 323 | 323 |
| 324 SVGGraphicsElement::svgAttributeChanged(attrName); | 324 SVGGraphicsElement::svgAttributeChanged(attrName); |
| 325 } | 325 } |
| 326 | 326 |
| 327 // FloatRect::intersects does not consider horizontal or vertical lines (because
of isEmpty()). | 327 // FloatRect::intersects does not consider horizontal or vertical lines (because
of isEmpty()). |
| 328 static bool intersectsAllowingEmpty(const FloatRect& r1, const FloatRect& r2) | 328 static bool intersectsAllowingEmpty(const FloatRect& r1, const FloatRect& r2) |
| 329 { | 329 { |
| 330 if (r1.width() < 0 || r1.height() < 0 || r2.width() < 0 || r2.height() < 0) | 330 if (r1.width() < 0 || r1.height() < 0 || r2.width() < 0 || r2.height() < 0) |
| 331 return false; | 331 return false; |
| 332 | 332 |
| 333 return r1.x() < r2.maxX() && r2.x() < r1.maxX() | 333 return r1.x() < r2.maxX() && r2.x() < r1.maxX() |
| 334 && r1.y() < r2.maxY() && r2.y() < r1.maxY(); | 334 && r1.y() < r2.maxY() && r2.y() < r1.maxY(); |
| 335 } | 335 } |
| 336 | 336 |
| 337 // One of the element types that can cause graphics to be drawn onto the target
canvas. | 337 // One of the element types that can cause graphics to be drawn onto the target
canvas. |
| 338 // Specifically: circle, ellipse, image, line, path, polygon, polyline, rect, te
xt and use. | 338 // Specifically: circle, ellipse, image, line, path, polygon, polyline, rect, te
xt and use. |
| 339 static bool isIntersectionOrEnclosureTarget(LayoutObject* renderer) | 339 static bool isIntersectionOrEnclosureTarget(LayoutObject* renderer) |
| 340 { | 340 { |
| 341 return renderer->isSVGShape() | 341 return renderer->isSVGShape() |
| 342 || renderer->isSVGText() | 342 || renderer->isSVGText() |
| 343 || renderer->isSVGImage() | 343 || renderer->isSVGImage() |
| 344 || isSVGUseElement(*renderer->node()); | 344 || isSVGUseElement(*renderer->node()); |
| 345 } | 345 } |
| 346 | 346 |
| 347 bool SVGSVGElement::checkIntersectionOrEnclosure(const SVGElement& element, cons
t FloatRect& rect, | 347 bool SVGSVGElement::checkIntersectionOrEnclosure(const SVGElement& element, cons
t FloatRect& rect, |
| 348 CheckIntersectionOrEnclosure mode) const | 348 CheckIntersectionOrEnclosure mode) const |
| 349 { | 349 { |
| 350 LayoutObject* renderer = element.renderer(); | 350 LayoutObject* renderer = element.layoutObject(); |
| 351 ASSERT(!renderer || renderer->style()); | 351 ASSERT(!renderer || renderer->style()); |
| 352 if (!renderer || renderer->style()->pointerEvents() == PE_NONE) | 352 if (!renderer || renderer->style()->pointerEvents() == PE_NONE) |
| 353 return false; | 353 return false; |
| 354 | 354 |
| 355 if (!isIntersectionOrEnclosureTarget(renderer)) | 355 if (!isIntersectionOrEnclosureTarget(renderer)) |
| 356 return false; | 356 return false; |
| 357 | 357 |
| 358 AffineTransform ctm = toSVGGraphicsElement(element).computeCTM(AncestorScope
, DisallowStyleUpdate, this); | 358 AffineTransform ctm = toSVGGraphicsElement(element).computeCTM(AncestorScope
, DisallowStyleUpdate, this); |
| 359 FloatRect mappedRepaintRect = ctm.mapRect(renderer->paintInvalidationRectInL
ocalCoordinates()); | 359 FloatRect mappedRepaintRect = ctm.mapRect(renderer->paintInvalidationRectInL
ocalCoordinates()); |
| 360 | 360 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 if (!hasEmptyViewBox()) { | 480 if (!hasEmptyViewBox()) { |
| 481 FloatSize size = currentViewportSize(); | 481 FloatSize size = currentViewportSize(); |
| 482 viewBoxTransform = viewBoxToViewTransform(size.width(), size.height()); | 482 viewBoxTransform = viewBoxToViewTransform(size.width(), size.height()); |
| 483 } | 483 } |
| 484 | 484 |
| 485 AffineTransform transform; | 485 AffineTransform transform; |
| 486 if (!isOutermostSVGSVGElement()) { | 486 if (!isOutermostSVGSVGElement()) { |
| 487 SVGLengthContext lengthContext(this); | 487 SVGLengthContext lengthContext(this); |
| 488 transform.translate(m_x->currentValue()->value(lengthContext), m_y->curr
entValue()->value(lengthContext)); | 488 transform.translate(m_x->currentValue()->value(lengthContext), m_y->curr
entValue()->value(lengthContext)); |
| 489 } else if (mode == SVGElement::ScreenScope) { | 489 } else if (mode == SVGElement::ScreenScope) { |
| 490 if (LayoutObject* renderer = this->renderer()) { | 490 if (LayoutObject* renderer = this->layoutObject()) { |
| 491 FloatPoint location; | 491 FloatPoint location; |
| 492 float zoomFactor = 1; | 492 float zoomFactor = 1; |
| 493 | 493 |
| 494 // At the SVG/HTML boundary (aka LayoutSVGRoot), we apply the localT
oBorderBoxTransform | 494 // At the SVG/HTML boundary (aka LayoutSVGRoot), we apply the localT
oBorderBoxTransform |
| 495 // to map an element from SVG viewport coordinates to CSS box coordi
nates. | 495 // to map an element from SVG viewport coordinates to CSS box coordi
nates. |
| 496 // LayoutSVGRoot's localToAbsolute method expects CSS box coordinate
s. | 496 // LayoutSVGRoot's localToAbsolute method expects CSS box coordinate
s. |
| 497 // We also need to adjust for the zoom level factored into CSS coord
inates (bug #96361). | 497 // We also need to adjust for the zoom level factored into CSS coord
inates (bug #96361). |
| 498 if (renderer->isSVGRoot()) { | 498 if (renderer->isSVGRoot()) { |
| 499 location = toLayoutSVGRoot(renderer)->localToBorderBoxTransform(
).mapPoint(location); | 499 location = toLayoutSVGRoot(renderer)->localToBorderBoxTransform(
).mapPoint(location); |
| 500 zoomFactor = 1 / renderer->style()->effectiveZoom(); | 500 zoomFactor = 1 / renderer->style()->effectiveZoom(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 } | 608 } |
| 609 | 609 |
| 610 FloatRect SVGSVGElement::currentViewBoxRect() const | 610 FloatRect SVGSVGElement::currentViewBoxRect() const |
| 611 { | 611 { |
| 612 if (m_useCurrentView) | 612 if (m_useCurrentView) |
| 613 return m_viewSpec ? m_viewSpec->viewBox()->currentValue()->value() : Flo
atRect(); | 613 return m_viewSpec ? m_viewSpec->viewBox()->currentValue()->value() : Flo
atRect(); |
| 614 | 614 |
| 615 FloatRect useViewBox = viewBox()->currentValue()->value(); | 615 FloatRect useViewBox = viewBox()->currentValue()->value(); |
| 616 if (!useViewBox.isEmpty()) | 616 if (!useViewBox.isEmpty()) |
| 617 return useViewBox; | 617 return useViewBox; |
| 618 if (!renderer() || !renderer()->isSVGRoot()) | 618 if (!layoutObject() || !layoutObject()->isSVGRoot()) |
| 619 return FloatRect(); | 619 return FloatRect(); |
| 620 if (!toLayoutSVGRoot(renderer())->isEmbeddedThroughSVGImage()) | 620 if (!toLayoutSVGRoot(layoutObject())->isEmbeddedThroughSVGImage()) |
| 621 return FloatRect(); | 621 return FloatRect(); |
| 622 | 622 |
| 623 // If no viewBox is specified but non-relative width/height values, then we | 623 // If no viewBox is specified but non-relative width/height values, then we |
| 624 // should always synthesize a viewBox if we're embedded through a SVGImage. | 624 // should always synthesize a viewBox if we're embedded through a SVGImage. |
| 625 return FloatRect(FloatPoint(), FloatSize(floatValueForLength(intrinsicWidth(
), 0), floatValueForLength(intrinsicHeight(), 0))); | 625 return FloatRect(FloatPoint(), FloatSize(floatValueForLength(intrinsicWidth(
), 0), floatValueForLength(intrinsicHeight(), 0))); |
| 626 } | 626 } |
| 627 | 627 |
| 628 FloatSize SVGSVGElement::currentViewportSize() const | 628 FloatSize SVGSVGElement::currentViewportSize() const |
| 629 { | 629 { |
| 630 if (!renderer()) | 630 if (!layoutObject()) |
| 631 return FloatSize(); | 631 return FloatSize(); |
| 632 | 632 |
| 633 if (renderer()->isSVGRoot()) { | 633 if (layoutObject()->isSVGRoot()) { |
| 634 LayoutRect contentBoxRect = toLayoutSVGRoot(renderer())->contentBoxRect(
); | 634 LayoutRect contentBoxRect = toLayoutSVGRoot(layoutObject())->contentBoxR
ect(); |
| 635 return FloatSize(contentBoxRect.width() / renderer()->style()->effective
Zoom(), contentBoxRect.height() / renderer()->style()->effectiveZoom()); | 635 return FloatSize(contentBoxRect.width() / layoutObject()->style()->effec
tiveZoom(), contentBoxRect.height() / layoutObject()->style()->effectiveZoom()); |
| 636 } | 636 } |
| 637 | 637 |
| 638 FloatRect viewportRect = toLayoutSVGViewportContainer(renderer())->viewport(
); | 638 FloatRect viewportRect = toLayoutSVGViewportContainer(layoutObject())->viewp
ort(); |
| 639 return FloatSize(viewportRect.width(), viewportRect.height()); | 639 return FloatSize(viewportRect.width(), viewportRect.height()); |
| 640 } | 640 } |
| 641 | 641 |
| 642 bool SVGSVGElement::hasIntrinsicWidth() const | 642 bool SVGSVGElement::hasIntrinsicWidth() const |
| 643 { | 643 { |
| 644 return width()->currentValue()->unitType() != LengthTypePercentage; | 644 return width()->currentValue()->unitType() != LengthTypePercentage; |
| 645 } | 645 } |
| 646 | 646 |
| 647 bool SVGSVGElement::hasIntrinsicHeight() const | 647 bool SVGSVGElement::hasIntrinsicHeight() const |
| 648 { | 648 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 679 | 679 |
| 680 AffineTransform transform; | 680 AffineTransform transform; |
| 681 if (transformList->concatenate(transform)) | 681 if (transformList->concatenate(transform)) |
| 682 ctm *= transform; | 682 ctm *= transform; |
| 683 | 683 |
| 684 return ctm; | 684 return ctm; |
| 685 } | 685 } |
| 686 | 686 |
| 687 void SVGSVGElement::setupInitialView(const String& fragmentIdentifier, Element*
anchorNode) | 687 void SVGSVGElement::setupInitialView(const String& fragmentIdentifier, Element*
anchorNode) |
| 688 { | 688 { |
| 689 LayoutObject* renderer = this->renderer(); | 689 LayoutObject* renderer = this->layoutObject(); |
| 690 SVGViewSpec* view = m_viewSpec.get(); | 690 SVGViewSpec* view = m_viewSpec.get(); |
| 691 if (view) | 691 if (view) |
| 692 view->reset(); | 692 view->reset(); |
| 693 | 693 |
| 694 bool hadUseCurrentView = m_useCurrentView; | 694 bool hadUseCurrentView = m_useCurrentView; |
| 695 m_useCurrentView = false; | 695 m_useCurrentView = false; |
| 696 | 696 |
| 697 if (fragmentIdentifier.startsWith("xpointer(")) { | 697 if (fragmentIdentifier.startsWith("xpointer(")) { |
| 698 // FIXME: XPointer references are ignored (https://bugs.webkit.org/show_
bug.cgi?id=17491) | 698 // FIXME: XPointer references are ignored (https://bugs.webkit.org/show_
bug.cgi?id=17491) |
| 699 if (renderer && hadUseCurrentView) | 699 if (renderer && hadUseCurrentView) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 718 // Spec: If the SVG fragment identifier addresses a 'view' element within an
SVG document (e.g., MyDrawing.svg#MyView | 718 // Spec: If the SVG fragment identifier addresses a 'view' element within an
SVG document (e.g., MyDrawing.svg#MyView |
| 719 // or MyDrawing.svg#xpointer(id('MyView'))) then the closest ancestor 'svg'
element is displayed in the viewport. | 719 // or MyDrawing.svg#xpointer(id('MyView'))) then the closest ancestor 'svg'
element is displayed in the viewport. |
| 720 // Any view specification attributes included on the given 'view' element ov
erride the corresponding view specification | 720 // Any view specification attributes included on the given 'view' element ov
erride the corresponding view specification |
| 721 // attributes on the closest ancestor 'svg' element. | 721 // attributes on the closest ancestor 'svg' element. |
| 722 if (isSVGViewElement(anchorNode)) { | 722 if (isSVGViewElement(anchorNode)) { |
| 723 SVGViewElement& viewElement = toSVGViewElement(*anchorNode); | 723 SVGViewElement& viewElement = toSVGViewElement(*anchorNode); |
| 724 | 724 |
| 725 if (SVGSVGElement* svg = viewElement.ownerSVGElement()) { | 725 if (SVGSVGElement* svg = viewElement.ownerSVGElement()) { |
| 726 svg->inheritViewAttributes(&viewElement); | 726 svg->inheritViewAttributes(&viewElement); |
| 727 | 727 |
| 728 if (LayoutObject* renderer = svg->renderer()) | 728 if (LayoutObject* renderer = svg->layoutObject()) |
| 729 markForLayoutAndParentResourceInvalidation(renderer); | 729 markForLayoutAndParentResourceInvalidation(renderer); |
| 730 | 730 |
| 731 return; | 731 return; |
| 732 } | 732 } |
| 733 } | 733 } |
| 734 | 734 |
| 735 // If we previously had a view and didn't get a new one, we need to | 735 // If we previously had a view and didn't get a new one, we need to |
| 736 // layout again. | 736 // layout again. |
| 737 if (renderer && hadUseCurrentView) | 737 if (renderer && hadUseCurrentView) |
| 738 markForLayoutAndParentResourceInvalidation(renderer); | 738 markForLayoutAndParentResourceInvalidation(renderer); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 visitor->trace(m_width); | 785 visitor->trace(m_width); |
| 786 visitor->trace(m_height); | 786 visitor->trace(m_height); |
| 787 visitor->trace(m_translation); | 787 visitor->trace(m_translation); |
| 788 visitor->trace(m_timeContainer); | 788 visitor->trace(m_timeContainer); |
| 789 visitor->trace(m_viewSpec); | 789 visitor->trace(m_viewSpec); |
| 790 SVGGraphicsElement::trace(visitor); | 790 SVGGraphicsElement::trace(visitor); |
| 791 SVGFitToViewBox::trace(visitor); | 791 SVGFitToViewBox::trace(visitor); |
| 792 } | 792 } |
| 793 | 793 |
| 794 } // namespace blink | 794 } // namespace blink |
| OLD | NEW |