| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde
.org> | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde
.org> |
| 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 5 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 5 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 6 * Copyright (C) 2012 University of Szeged | 6 * Copyright (C) 2012 University of Szeged |
| 7 * Copyright (C) 2012 Renata Hodovan <reni@webkit.org> | 7 * Copyright (C) 2012 Renata Hodovan <reni@webkit.org> |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 Element* next = ElementTraversal::nextSkippingChildren(*element, &su
btree); | 579 Element* next = ElementTraversal::nextSkippingChildren(*element, &su
btree); |
| 580 // The subtree is not in document so this won't generate events that
could mutate the tree. | 580 // The subtree is not in document so this won't generate events that
could mutate the tree. |
| 581 element->parentNode()->removeChild(element); | 581 element->parentNode()->removeChild(element); |
| 582 element = next; | 582 element = next; |
| 583 } else { | 583 } else { |
| 584 element = ElementTraversal::next(*element, &subtree); | 584 element = ElementTraversal::next(*element, &subtree); |
| 585 } | 585 } |
| 586 } | 586 } |
| 587 } | 587 } |
| 588 | 588 |
| 589 static void moveChildrenToReplacementElement(ContainerNode& sourceRoot, Containe
rNode& destinationRoot) |
| 590 { |
| 591 for (RefPtrWillBeRawPtr<Node> child = sourceRoot.firstChild(); child; ) { |
| 592 RefPtrWillBeRawPtr<Node> nextChild = child->nextSibling(); |
| 593 destinationRoot.appendChild(child); |
| 594 child = nextChild.release(); |
| 595 } |
| 596 } |
| 597 |
| 598 // Spec: In the generated content, the 'use' will be replaced by 'g', where all |
| 599 // attributes from the 'use' element except for x, y, width, height and |
| 600 // xlink:href are transferred to the generated 'g' element. |
| 601 static void removeAttributesFromReplacementElement(SVGElement& replacementElemen
t) |
| 602 { |
| 603 replacementElement.removeAttribute(SVGNames::xAttr); |
| 604 replacementElement.removeAttribute(SVGNames::yAttr); |
| 605 replacementElement.removeAttribute(SVGNames::widthAttr); |
| 606 replacementElement.removeAttribute(SVGNames::heightAttr); |
| 607 replacementElement.removeAttribute(SVGNames::hrefAttr); |
| 608 replacementElement.removeAttribute(XLinkNames::hrefAttr); |
| 609 } |
| 610 |
| 589 bool SVGUseElement::expandUseElementsInShadowTree() | 611 bool SVGUseElement::expandUseElementsInShadowTree() |
| 590 { | 612 { |
| 591 // Why expand the <use> elements in the shadow tree here, and not just | 613 // Why expand the <use> elements in the shadow tree here, and not just |
| 592 // do this directly in buildShadowTree, if we encounter a <use> element? | 614 // do this directly in buildShadowTree, if we encounter a <use> element? |
| 593 // | 615 // |
| 594 // Short answer: Because we may miss to expand some elements. For example, i
f a <symbol> | 616 // Short answer: Because we may miss to expand some elements. For example, i
f a <symbol> |
| 595 // contains <use> tags, we'd miss them. So once we're done with setting up t
he | 617 // contains <use> tags, we'd miss them. So once we're done with setting up t
he |
| 596 // actual shadow tree (after the special case modification for svg/symbol) w
e have | 618 // actual shadow tree (after the special case modification for svg/symbol) w
e have |
| 597 // to walk it completely and expand all <use> elements. | 619 // to walk it completely and expand all <use> elements. |
| 598 ShadowRoot* shadowRoot = userAgentShadowRoot(); | 620 ShadowRoot* shadowRoot = userAgentShadowRoot(); |
| 599 for (RefPtrWillBeRawPtr<SVGUseElement> use = Traversal<SVGUseElement>::first
Within(*shadowRoot); use; ) { | 621 for (RefPtrWillBeRawPtr<SVGUseElement> use = Traversal<SVGUseElement>::first
Within(*shadowRoot); use; ) { |
| 600 ASSERT(!use->resourceIsStillLoading()); | 622 ASSERT(!use->resourceIsStillLoading()); |
| 601 | 623 |
| 602 SVGElement* target = 0; | 624 SVGElement* target = 0; |
| 603 if (hasCycleUseReferencing(toSVGUseElement(use->correspondingElement()),
use.get(), target)) | 625 if (hasCycleUseReferencing(toSVGUseElement(use->correspondingElement()),
use.get(), target)) |
| 604 return false; | 626 return false; |
| 605 | 627 |
| 606 if (target && isDisallowedElement(target)) | 628 if (target && isDisallowedElement(target)) |
| 607 return false; | 629 return false; |
| 608 // Don't ASSERT(target) here, it may be "pending", too. | 630 // Don't ASSERT(target) here, it may be "pending", too. |
| 609 // Setup sub-shadow tree root node | 631 // Setup sub-shadow tree root node |
| 610 RefPtrWillBeRawPtr<SVGGElement> cloneParent = SVGGElement::create(refere
ncedScope()->document()); | 632 RefPtrWillBeRawPtr<SVGGElement> cloneParent = SVGGElement::create(refere
ncedScope()->document()); |
| 633 // Transfer all data (attributes, etc.) from <use> to the new <g> elemen
t. |
| 634 cloneParent->cloneDataFromElement(*use); |
| 611 cloneParent->setCorrespondingElement(use->correspondingElement()); | 635 cloneParent->setCorrespondingElement(use->correspondingElement()); |
| 612 | 636 |
| 613 // Move already cloned elements to the new <g> element | 637 removeAttributesFromReplacementElement(*cloneParent); |
| 614 for (RefPtrWillBeRawPtr<Node> child = use->firstChild(); child; ) { | |
| 615 RefPtrWillBeRawPtr<Node> nextChild = child->nextSibling(); | |
| 616 cloneParent->appendChild(child); | |
| 617 child = nextChild.release(); | |
| 618 } | |
| 619 | 638 |
| 620 // Spec: In the generated content, the 'use' will be replaced by 'g', wh
ere all attributes from the | 639 // Move already cloned elements to the new <g> element. |
| 621 // 'use' element except for x, y, width, height and xlink:href are trans
ferred to the generated 'g' element. | 640 moveChildrenToReplacementElement(*use, *cloneParent); |
| 622 transferUseAttributesToReplacedElement(use.get(), cloneParent.get()); | |
| 623 | 641 |
| 624 if (target) { | 642 if (target) { |
| 625 RefPtrWillBeRawPtr<Node> newChild = cloneNodeAndAssociate(*target); | 643 RefPtrWillBeRawPtr<Node> newChild = cloneNodeAndAssociate(*target); |
| 626 ASSERT(newChild->isSVGElement()); | 644 ASSERT(newChild->isSVGElement()); |
| 627 transferUseWidthAndHeightIfNeeded(*use, toSVGElement(newChild.get())
, *target); | 645 transferUseWidthAndHeightIfNeeded(*use, toSVGElement(newChild.get())
, *target); |
| 628 cloneParent->appendChild(newChild.release()); | 646 cloneParent->appendChild(newChild.release()); |
| 629 } | 647 } |
| 630 | 648 |
| 631 // We don't walk the target tree element-by-element, and clone each elem
ent, | 649 // We don't walk the target tree element-by-element, and clone each elem
ent, |
| 632 // but instead use cloneElementWithChildren(). This is an optimization f
or the common | 650 // but instead use cloneElementWithChildren(). This is an optimization f
or the common |
| (...skipping 22 matching lines...) Expand all Loading... |
| 655 // always have explicit values for attributes width and height. If attri
butes width and/or | 673 // always have explicit values for attributes width and height. If attri
butes width and/or |
| 656 // height are provided on the 'use' element, then these attributes will
be transferred to | 674 // height are provided on the 'use' element, then these attributes will
be transferred to |
| 657 // the generated 'svg'. If attributes width and/or height are not specif
ied, the generated | 675 // the generated 'svg'. If attributes width and/or height are not specif
ied, the generated |
| 658 // 'svg' element will use values of 100% for these attributes. | 676 // 'svg' element will use values of 100% for these attributes. |
| 659 ASSERT(referencedScope()); | 677 ASSERT(referencedScope()); |
| 660 RefPtrWillBeRawPtr<SVGSVGElement> svgElement = SVGSVGElement::create(ref
erencedScope()->document()); | 678 RefPtrWillBeRawPtr<SVGSVGElement> svgElement = SVGSVGElement::create(ref
erencedScope()->document()); |
| 661 // Transfer all data (attributes, etc.) from <symbol> to the new <svg> e
lement. | 679 // Transfer all data (attributes, etc.) from <symbol> to the new <svg> e
lement. |
| 662 svgElement->cloneDataFromElement(*symbol); | 680 svgElement->cloneDataFromElement(*symbol); |
| 663 svgElement->setCorrespondingElement(symbol->correspondingElement()); | 681 svgElement->setCorrespondingElement(symbol->correspondingElement()); |
| 664 | 682 |
| 665 // Move already cloned elements to the new <svg> element | 683 // Move already cloned elements to the new <svg> element. |
| 666 for (RefPtrWillBeRawPtr<Node> child = symbol->firstChild(); child; ) { | 684 moveChildrenToReplacementElement(*symbol, *svgElement); |
| 667 RefPtrWillBeRawPtr<Node> nextChild = child->nextSibling(); | |
| 668 svgElement->appendChild(child); | |
| 669 child = nextChild.release(); | |
| 670 } | |
| 671 | 685 |
| 672 // We don't walk the target tree element-by-element, and clone each elem
ent, | 686 // We don't walk the target tree element-by-element, and clone each elem
ent, |
| 673 // but instead use cloneNode(deep=true). This is an optimization for the
common | 687 // but instead use cloneNode(deep=true). This is an optimization for the
common |
| 674 // case where <use> doesn't contain disallowed elements (ie. <foreignObj
ect>). | 688 // case where <use> doesn't contain disallowed elements (ie. <foreignObj
ect>). |
| 675 // Though if there are disallowed elements in the subtree, we have to re
move them. | 689 // Though if there are disallowed elements in the subtree, we have to re
move them. |
| 676 // For instance: <use> on <g> containing <foreignObject> (indirect case)
. | 690 // For instance: <use> on <g> containing <foreignObject> (indirect case)
. |
| 677 if (subtreeContainsDisallowedElement(svgElement.get())) | 691 if (subtreeContainsDisallowedElement(svgElement.get())) |
| 678 removeDisallowedElementsFromSubtree(*svgElement); | 692 removeDisallowedElementsFromSubtree(*svgElement); |
| 679 | 693 |
| 680 RefPtrWillBeRawPtr<SVGElement> replacingElement(svgElement.get()); | 694 RefPtrWillBeRawPtr<SVGElement> replacingElement(svgElement.get()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 702 WillBeHeapVector<RefPtrWillBeMember<SVGElement>> instances; | 716 WillBeHeapVector<RefPtrWillBeMember<SVGElement>> instances; |
| 703 instances.appendRange(rawInstances.begin(), rawInstances.end()); | 717 instances.appendRange(rawInstances.begin(), rawInstances.end()); |
| 704 for (auto& instance : instances) { | 718 for (auto& instance : instances) { |
| 705 if (RefPtrWillBeRawPtr<SVGUseElement> element = instance->correspondingU
seElement()) { | 719 if (RefPtrWillBeRawPtr<SVGUseElement> element = instance->correspondingU
seElement()) { |
| 706 ASSERT(element->inDocument()); | 720 ASSERT(element->inDocument()); |
| 707 element->invalidateShadowTree(); | 721 element->invalidateShadowTree(); |
| 708 } | 722 } |
| 709 } | 723 } |
| 710 } | 724 } |
| 711 | 725 |
| 712 void SVGUseElement::transferUseAttributesToReplacedElement(SVGElement* from, SVG
Element* to) const | |
| 713 { | |
| 714 ASSERT(from); | |
| 715 ASSERT(to); | |
| 716 | |
| 717 to->cloneDataFromElement(*from); | |
| 718 | |
| 719 to->removeAttribute(SVGNames::xAttr); | |
| 720 to->removeAttribute(SVGNames::yAttr); | |
| 721 to->removeAttribute(SVGNames::widthAttr); | |
| 722 to->removeAttribute(SVGNames::heightAttr); | |
| 723 to->removeAttribute(SVGNames::hrefAttr); | |
| 724 to->removeAttribute(XLinkNames::hrefAttr); | |
| 725 } | |
| 726 | |
| 727 bool SVGUseElement::selfHasRelativeLengths() const | 726 bool SVGUseElement::selfHasRelativeLengths() const |
| 728 { | 727 { |
| 729 if (m_x->currentValue()->isRelative() | 728 if (m_x->currentValue()->isRelative() |
| 730 || m_y->currentValue()->isRelative() | 729 || m_y->currentValue()->isRelative() |
| 731 || m_width->currentValue()->isRelative() | 730 || m_width->currentValue()->isRelative() |
| 732 || m_height->currentValue()->isRelative()) | 731 || m_height->currentValue()->isRelative()) |
| 733 return true; | 732 return true; |
| 734 | 733 |
| 735 if (!m_targetElementInstance) | 734 if (!m_targetElementInstance) |
| 736 return false; | 735 return false; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 | 816 |
| 818 if (m_resource) | 817 if (m_resource) |
| 819 m_resource->removeClient(this); | 818 m_resource->removeClient(this); |
| 820 | 819 |
| 821 m_resource = resource; | 820 m_resource = resource; |
| 822 if (m_resource) | 821 if (m_resource) |
| 823 m_resource->addClient(this); | 822 m_resource->addClient(this); |
| 824 } | 823 } |
| 825 | 824 |
| 826 } // namespace blink | 825 } // namespace blink |
| OLD | NEW |