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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 } | 393 } |
394 | 394 |
395 if (target->isSVGElement()) { | 395 if (target->isSVGElement()) { |
396 buildShadowAndInstanceTree(toSVGElement(target)); | 396 buildShadowAndInstanceTree(toSVGElement(target)); |
397 invalidateDependentShadowTrees(); | 397 invalidateDependentShadowTrees(); |
398 } | 398 } |
399 | 399 |
400 ASSERT(!m_needsShadowTreeRecreation); | 400 ASSERT(!m_needsShadowTreeRecreation); |
401 } | 401 } |
402 | 402 |
403 inline void transferUseWidthAndHeightIfNeeded(const SVGUseElement& use, Element& element) | |
pdr.
2014/04/29 04:30:59
It may be better to put the relevant code from thi
| |
404 { | |
405 if (isSVGSymbolElement(element)) { | |
406 // Spec (<use> on <symbol>): This generated 'svg' will always have expli cit values for attributes width and height. | |
407 // If attributes width and/or height are provided on the 'use' element, then these attributes | |
408 // will be transferred to the generated 'svg'. If attributes width and/o r height are not specified, | |
409 // the generated 'svg' element will use values of 100% for these attribu tes. | |
410 element.setAttribute(SVGNames::widthAttr, use.hasAttribute(SVGNames::wid thAttr) ? use.getAttribute(SVGNames::widthAttr) : "100%"); | |
411 element.setAttribute(SVGNames::heightAttr, use.hasAttribute(SVGNames::he ightAttr) ? use.getAttribute(SVGNames::heightAttr) : "100%"); | |
412 } else if (isSVGSVGElement(element)) { | |
413 // Spec (<use> on <svg>): If attributes width and/or height are provided on the 'use' element, then these | |
414 // values will override the corresponding attributes on the 'svg' in the generated tree. | |
415 if (use.hasAttribute(SVGNames::widthAttr)) | |
Erik Dahlström (inactive)
2014/04/29 13:01:02
Will this work if the width/height attributes are
| |
416 element.setAttribute(SVGNames::widthAttr, use.getAttribute(SVGNames: :widthAttr)); | |
417 if (use.hasAttribute(SVGNames::heightAttr)) | |
418 element.setAttribute(SVGNames::heightAttr, use.getAttribute(SVGNames ::heightAttr)); | |
419 } | |
420 } | |
421 | |
403 void SVGUseElement::buildShadowAndInstanceTree(SVGElement* target) | 422 void SVGUseElement::buildShadowAndInstanceTree(SVGElement* target) |
404 { | 423 { |
405 ASSERT(!m_targetElementInstance); | 424 ASSERT(!m_targetElementInstance); |
406 | 425 |
407 // <use> creates a "user agent" shadow root. Do not build the shadow/instanc e tree for <use> | 426 // <use> creates a "user agent" shadow root. Do not build the shadow/instanc e tree for <use> |
408 // elements living in a user agent shadow tree because they will get expande d in a second | 427 // elements living in a user agent shadow tree because they will get expande d in a second |
409 // pass -- see expandUseElementsInShadowTree(). | 428 // pass -- see expandUseElementsInShadowTree(). |
410 if (inUseShadowTree()) | 429 if (inUseShadowTree()) |
411 return; | 430 return; |
412 | 431 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 ASSERT(m_targetElementInstance); | 464 ASSERT(m_targetElementInstance); |
446 ASSERT(!m_targetElementInstance->shadowTreeElement()); | 465 ASSERT(!m_targetElementInstance->shadowTreeElement()); |
447 ASSERT(m_targetElementInstance->correspondingUseElement() == this); | 466 ASSERT(m_targetElementInstance->correspondingUseElement() == this); |
448 ASSERT(m_targetElementInstance->directUseElement() == this); | 467 ASSERT(m_targetElementInstance->directUseElement() == this); |
449 ASSERT(m_targetElementInstance->correspondingElement() == target); | 468 ASSERT(m_targetElementInstance->correspondingElement() == target); |
450 | 469 |
451 ShadowRoot* shadowTreeRootElement = userAgentShadowRoot(); | 470 ShadowRoot* shadowTreeRootElement = userAgentShadowRoot(); |
452 ASSERT(shadowTreeRootElement); | 471 ASSERT(shadowTreeRootElement); |
453 | 472 |
454 // Build shadow tree from instance tree | 473 // Build shadow tree from instance tree |
455 // This also handles the special cases: <use> on <symbol>, <use> on <svg>. | 474 // This clones the element corresponding to the target element instance |
456 buildShadowTree(target, m_targetElementInstance.get()); | 475 buildShadowTree(target, m_targetElementInstance.get()); |
457 | 476 |
458 // Expand all <use> elements in the shadow tree. | 477 // Expand all <use> elements in the shadow tree. |
459 // Expand means: replace the actual <use> element by what it references. | 478 // Expand means: replace the actual <use> element by what it references. |
460 expandUseElementsInShadowTree(shadowTreeRootElement); | 479 expandUseElementsInShadowTree(shadowTreeRootElement); |
461 | 480 |
481 transferUseWidthAndHeightIfNeeded(*this, *toSVGElement(shadowTreeRootElement ->firstChild())); | |
462 // Expand all <symbol> elements in the shadow tree. | 482 // Expand all <symbol> elements in the shadow tree. |
463 // Expand means: replace the actual <symbol> element by the <svg> element. | 483 // Expand means: replace the actual <symbol> element by the <svg> element. |
464 expandSymbolElementsInShadowTree(shadowTreeRootElement); | 484 expandSymbolElementsInShadowTree(shadowTreeRootElement); |
465 | 485 |
466 // Now that the shadow tree is completly expanded, we can associate | 486 // Now that the shadow tree is completly expanded, we can associate |
467 // shadow tree elements <-> instances in the instance tree. | 487 // shadow tree elements <-> instances in the instance tree. |
468 associateInstancesWithShadowTreeElements(shadowTreeRootElement->firstChild() , m_targetElementInstance.get()); | 488 associateInstancesWithShadowTreeElements(shadowTreeRootElement->firstChild() , m_targetElementInstance.get()); |
469 | 489 |
470 // If no shadow tree element is present, this means that the reference root | 490 // If no shadow tree element is present, this means that the reference root |
471 // element was removed, as it is disallowed (ie. <use> on <foreignObject>) | 491 // element was removed, as it is disallowed (ie. <use> on <foreignObject>) |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 RefPtr<SVGGElement> cloneParent = SVGGElement::create(referencedScope()- >document()); | 715 RefPtr<SVGGElement> cloneParent = SVGGElement::create(referencedScope()- >document()); |
696 use->cloneChildNodes(cloneParent.get()); | 716 use->cloneChildNodes(cloneParent.get()); |
697 | 717 |
698 // Spec: In the generated content, the 'use' will be replaced by 'g', wh ere all attributes from the | 718 // Spec: In the generated content, the 'use' will be replaced by 'g', wh ere all attributes from the |
699 // 'use' element except for x, y, width, height and xlink:href are trans ferred to the generated 'g' element. | 719 // 'use' element except for x, y, width, height and xlink:href are trans ferred to the generated 'g' element. |
700 transferUseAttributesToReplacedElement(use, cloneParent.get()); | 720 transferUseAttributesToReplacedElement(use, cloneParent.get()); |
701 | 721 |
702 if (target && !isDisallowedElement(target)) { | 722 if (target && !isDisallowedElement(target)) { |
703 RefPtr<Element> newChild = target->cloneElementWithChildren(); | 723 RefPtr<Element> newChild = target->cloneElementWithChildren(); |
704 ASSERT(newChild->isSVGElement()); | 724 ASSERT(newChild->isSVGElement()); |
725 transferUseWidthAndHeightIfNeeded(*use, *newChild); | |
pdr.
2014/04/29 04:30:59
I think the use width/height code would go here.
| |
726 | |
705 cloneParent->appendChild(newChild.release()); | 727 cloneParent->appendChild(newChild.release()); |
706 } | 728 } |
707 | 729 |
708 // We don't walk the target tree element-by-element, and clone each elem ent, | 730 // We don't walk the target tree element-by-element, and clone each elem ent, |
709 // but instead use cloneElementWithChildren(). This is an optimization f or the common | 731 // but instead use cloneElementWithChildren(). This is an optimization f or the common |
710 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>). | 732 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>). |
711 // Though if there are disallowed elements in the subtree, we have to re move them. | 733 // Though if there are disallowed elements in the subtree, we have to re move them. |
712 // For instance: <use> on <g> containing <foreignObject> (indirect case) . | 734 // For instance: <use> on <g> containing <foreignObject> (indirect case) . |
713 if (subtreeContainsDisallowedElement(cloneParent.get())) | 735 if (subtreeContainsDisallowedElement(cloneParent.get())) |
714 removeDisallowedElementsFromSubtree(*cloneParent); | 736 removeDisallowedElementsFromSubtree(*cloneParent); |
(...skipping 22 matching lines...) Expand all Loading... | |
737 // Spec: The referenced 'symbol' and its contents are deep-cloned into t he generated tree, | 759 // Spec: The referenced 'symbol' and its contents are deep-cloned into t he generated tree, |
738 // with the exception that the 'symbol' is replaced by an 'svg'. This ge nerated 'svg' will | 760 // with the exception that the 'symbol' is replaced by an 'svg'. This ge nerated 'svg' will |
739 // always have explicit values for attributes width and height. If attri butes width and/or | 761 // always have explicit values for attributes width and height. If attri butes width and/or |
740 // height are provided on the 'use' element, then these attributes will be transferred to | 762 // height are provided on the 'use' element, then these attributes will be transferred to |
741 // the generated 'svg'. If attributes width and/or height are not specif ied, the generated | 763 // the generated 'svg'. If attributes width and/or height are not specif ied, the generated |
742 // 'svg' element will use values of 100% for these attributes. | 764 // 'svg' element will use values of 100% for these attributes. |
743 ASSERT(referencedScope()); | 765 ASSERT(referencedScope()); |
744 RefPtr<SVGSVGElement> svgElement = SVGSVGElement::create(referencedScope ()->document()); | 766 RefPtr<SVGSVGElement> svgElement = SVGSVGElement::create(referencedScope ()->document()); |
745 | 767 |
746 // Transfer all data (attributes, etc.) from <symbol> to the new <svg> e lement. | 768 // Transfer all data (attributes, etc.) from <symbol> to the new <svg> e lement. |
747 svgElement->cloneDataFromElement(*toElement(element)); | 769 svgElement->cloneDataFromElement(*toElement(element)); |
pdr.
2014/04/29 04:30:59
I think the symbol-specific width/height code woul
| |
748 | 770 |
749 // Only clone symbol children, and add them to the new <svg> element | 771 // Only clone symbol children, and add them to the new <svg> element |
750 for (Node* child = element->firstChild(); child; child = child->nextSibl ing()) { | 772 for (Node* child = element->firstChild(); child; child = child->nextSibl ing()) { |
751 RefPtr<Node> newChild = child->cloneNode(true); | 773 RefPtr<Node> newChild = child->cloneNode(true); |
752 svgElement->appendChild(newChild.release()); | 774 svgElement->appendChild(newChild.release()); |
753 } | 775 } |
754 | 776 |
755 // We don't walk the target tree element-by-element, and clone each elem ent, | 777 // We don't walk the target tree element-by-element, and clone each elem ent, |
756 // but instead use cloneNode(deep=true). This is an optimization for the common | 778 // but instead use cloneNode(deep=true). This is an optimization for the common |
757 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>). | 779 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>). |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
965 | 987 |
966 if (m_resource) | 988 if (m_resource) |
967 m_resource->removeClient(this); | 989 m_resource->removeClient(this); |
968 | 990 |
969 m_resource = resource; | 991 m_resource = resource; |
970 if (m_resource) | 992 if (m_resource) |
971 m_resource->addClient(this); | 993 m_resource->addClient(this); |
972 } | 994 } |
973 | 995 |
974 } | 996 } |
OLD | NEW |