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 static void removeAttributesFromReplacementElement(SVGElement& to) | |
pdr.
2016/03/02 21:24:35
It looks like this area is primed to extract out t
fs
2016/03/02 21:30:01
I suspect this function might stay alive even afte
| |
599 { | |
600 to.removeAttribute(SVGNames::xAttr); | |
601 to.removeAttribute(SVGNames::yAttr); | |
602 to.removeAttribute(SVGNames::widthAttr); | |
603 to.removeAttribute(SVGNames::heightAttr); | |
604 to.removeAttribute(SVGNames::hrefAttr); | |
605 to.removeAttribute(XLinkNames::hrefAttr); | |
606 } | |
607 | |
589 bool SVGUseElement::expandUseElementsInShadowTree() | 608 bool SVGUseElement::expandUseElementsInShadowTree() |
590 { | 609 { |
591 // Why expand the <use> elements in the shadow tree here, and not just | 610 // 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? | 611 // do this directly in buildShadowTree, if we encounter a <use> element? |
593 // | 612 // |
594 // Short answer: Because we may miss to expand some elements. For example, i f a <symbol> | 613 // 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 | 614 // 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 | 615 // actual shadow tree (after the special case modification for svg/symbol) w e have |
597 // to walk it completely and expand all <use> elements. | 616 // to walk it completely and expand all <use> elements. |
598 ShadowRoot* shadowRoot = userAgentShadowRoot(); | 617 ShadowRoot* shadowRoot = userAgentShadowRoot(); |
599 for (RefPtrWillBeRawPtr<SVGUseElement> use = Traversal<SVGUseElement>::first Within(*shadowRoot); use; ) { | 618 for (RefPtrWillBeRawPtr<SVGUseElement> use = Traversal<SVGUseElement>::first Within(*shadowRoot); use; ) { |
600 ASSERT(!use->resourceIsStillLoading()); | 619 ASSERT(!use->resourceIsStillLoading()); |
601 | 620 |
602 SVGElement* target = 0; | 621 SVGElement* target = 0; |
603 if (hasCycleUseReferencing(toSVGUseElement(use->correspondingElement()), use.get(), target)) | 622 if (hasCycleUseReferencing(toSVGUseElement(use->correspondingElement()), use.get(), target)) |
604 return false; | 623 return false; |
605 | 624 |
606 if (target && isDisallowedElement(target)) | 625 if (target && isDisallowedElement(target)) |
607 return false; | 626 return false; |
608 // Don't ASSERT(target) here, it may be "pending", too. | 627 // Don't ASSERT(target) here, it may be "pending", too. |
609 // Setup sub-shadow tree root node | 628 // Setup sub-shadow tree root node |
610 RefPtrWillBeRawPtr<SVGGElement> cloneParent = SVGGElement::create(refere ncedScope()->document()); | 629 RefPtrWillBeRawPtr<SVGGElement> cloneParent = SVGGElement::create(refere ncedScope()->document()); |
630 // Transfer all data (attributes, etc.) from <use> to the new <g> elemen t. | |
631 cloneParent->cloneDataFromElement(*use); | |
611 cloneParent->setCorrespondingElement(use->correspondingElement()); | 632 cloneParent->setCorrespondingElement(use->correspondingElement()); |
612 | 633 |
613 // Move already cloned elements to the new <g> element | |
614 for (RefPtrWillBeRawPtr<Node> child = use->firstChild(); child; ) { | |
615 RefPtrWillBeRawPtr<Node> nextChild = child->nextSibling(); | |
616 cloneParent->appendChild(child); | |
617 child = nextChild.release(); | |
618 } | |
619 | |
620 // Spec: In the generated content, the 'use' will be replaced by 'g', wh ere all attributes from the | 634 // Spec: In the generated content, the 'use' will be replaced by 'g', wh ere all attributes from the |
621 // 'use' element except for x, y, width, height and xlink:href are trans ferred to the generated 'g' element. | 635 // 'use' element except for x, y, width, height and xlink:href are trans ferred to the generated 'g' element. |
622 transferUseAttributesToReplacedElement(use.get(), cloneParent.get()); | 636 removeAttributesFromReplacementElement(*cloneParent); |
637 | |
638 // Move already cloned elements to the new <g> element. | |
639 moveChildrenToReplacementElement(*use, *cloneParent); | |
623 | 640 |
624 if (target) { | 641 if (target) { |
625 RefPtrWillBeRawPtr<Node> newChild = cloneNodeAndAssociate(*target); | 642 RefPtrWillBeRawPtr<Node> newChild = cloneNodeAndAssociate(*target); |
626 ASSERT(newChild->isSVGElement()); | 643 ASSERT(newChild->isSVGElement()); |
627 transferUseWidthAndHeightIfNeeded(*use, toSVGElement(newChild.get()) , *target); | 644 transferUseWidthAndHeightIfNeeded(*use, toSVGElement(newChild.get()) , *target); |
628 cloneParent->appendChild(newChild.release()); | 645 cloneParent->appendChild(newChild.release()); |
629 } | 646 } |
630 | 647 |
631 // We don't walk the target tree element-by-element, and clone each elem ent, | 648 // 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 | 649 // 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 | 672 // 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 | 673 // 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 | 674 // 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. | 675 // 'svg' element will use values of 100% for these attributes. |
659 ASSERT(referencedScope()); | 676 ASSERT(referencedScope()); |
660 RefPtrWillBeRawPtr<SVGSVGElement> svgElement = SVGSVGElement::create(ref erencedScope()->document()); | 677 RefPtrWillBeRawPtr<SVGSVGElement> svgElement = SVGSVGElement::create(ref erencedScope()->document()); |
661 // Transfer all data (attributes, etc.) from <symbol> to the new <svg> e lement. | 678 // Transfer all data (attributes, etc.) from <symbol> to the new <svg> e lement. |
662 svgElement->cloneDataFromElement(*symbol); | 679 svgElement->cloneDataFromElement(*symbol); |
663 svgElement->setCorrespondingElement(symbol->correspondingElement()); | 680 svgElement->setCorrespondingElement(symbol->correspondingElement()); |
664 | 681 |
665 // Move already cloned elements to the new <svg> element | 682 // Move already cloned elements to the new <svg> element. |
666 for (RefPtrWillBeRawPtr<Node> child = symbol->firstChild(); child; ) { | 683 moveChildrenToReplacementElement(*symbol, *svgElement); |
667 RefPtrWillBeRawPtr<Node> nextChild = child->nextSibling(); | |
668 svgElement->appendChild(child); | |
669 child = nextChild.release(); | |
670 } | |
671 | 684 |
672 // We don't walk the target tree element-by-element, and clone each elem ent, | 685 // 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 | 686 // 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>). | 687 // 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. | 688 // 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) . | 689 // For instance: <use> on <g> containing <foreignObject> (indirect case) . |
677 if (subtreeContainsDisallowedElement(svgElement.get())) | 690 if (subtreeContainsDisallowedElement(svgElement.get())) |
678 removeDisallowedElementsFromSubtree(*svgElement); | 691 removeDisallowedElementsFromSubtree(*svgElement); |
679 | 692 |
680 RefPtrWillBeRawPtr<SVGElement> replacingElement(svgElement.get()); | 693 RefPtrWillBeRawPtr<SVGElement> replacingElement(svgElement.get()); |
(...skipping 21 matching lines...) Expand all Loading... | |
702 WillBeHeapVector<RefPtrWillBeMember<SVGElement>> instances; | 715 WillBeHeapVector<RefPtrWillBeMember<SVGElement>> instances; |
703 instances.appendRange(rawInstances.begin(), rawInstances.end()); | 716 instances.appendRange(rawInstances.begin(), rawInstances.end()); |
704 for (auto& instance : instances) { | 717 for (auto& instance : instances) { |
705 if (RefPtrWillBeRawPtr<SVGUseElement> element = instance->correspondingU seElement()) { | 718 if (RefPtrWillBeRawPtr<SVGUseElement> element = instance->correspondingU seElement()) { |
706 ASSERT(element->inDocument()); | 719 ASSERT(element->inDocument()); |
707 element->invalidateShadowTree(); | 720 element->invalidateShadowTree(); |
708 } | 721 } |
709 } | 722 } |
710 } | 723 } |
711 | 724 |
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 | 725 bool SVGUseElement::selfHasRelativeLengths() const |
728 { | 726 { |
729 if (m_x->currentValue()->isRelative() | 727 if (m_x->currentValue()->isRelative() |
730 || m_y->currentValue()->isRelative() | 728 || m_y->currentValue()->isRelative() |
731 || m_width->currentValue()->isRelative() | 729 || m_width->currentValue()->isRelative() |
732 || m_height->currentValue()->isRelative()) | 730 || m_height->currentValue()->isRelative()) |
733 return true; | 731 return true; |
734 | 732 |
735 if (!m_targetElementInstance) | 733 if (!m_targetElementInstance) |
736 return false; | 734 return false; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 | 815 |
818 if (m_resource) | 816 if (m_resource) |
819 m_resource->removeClient(this); | 817 m_resource->removeClient(this); |
820 | 818 |
821 m_resource = resource; | 819 m_resource = resource; |
822 if (m_resource) | 820 if (m_resource) |
823 m_resource->addClient(this); | 821 m_resource->addClient(this); |
824 } | 822 } |
825 | 823 |
826 } // namespace blink | 824 } // namespace blink |
OLD | NEW |