Chromium Code Reviews| 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 |
| 11 * License as published by the Free Software Foundation; either | 11 * License as published by the Free Software Foundation; either |
| 12 * version 2 of the License, or (at your option) any later version. | 12 * version 2 of the License, or (at your option) any later version. |
| 13 * | 13 * |
| 14 * This library is distributed in the hope that it will be useful, | 14 * This library is distributed in the hope that it will be useful, |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 * Library General Public License for more details. | 17 * Library General Public License for more details. |
| 18 * | 18 * |
| 19 * You should have received a copy of the GNU Library General Public License | 19 * You should have received a copy of the GNU Library General Public License |
| 20 * along with this library; see the file COPYING.LIB. If not, write to | 20 * along with this library; see the file COPYING.LIB. If not, write to |
| 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 22 * Boston, MA 02110-1301, USA. | 22 * Boston, MA 02110-1301, USA. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 | 26 |
| 27 #include "core/svg/SVGUseElement.h" | 27 #include "core/svg/SVGUseElement.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 30 #include "core/SVGNames.h" | |
| 30 #include "core/XLinkNames.h" | 31 #include "core/XLinkNames.h" |
| 31 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
| 32 #include "core/dom/ElementTraversal.h" | 33 #include "core/dom/ElementTraversal.h" |
| 33 #include "core/events/Event.h" | 34 #include "core/events/Event.h" |
| 34 #include "core/dom/shadow/ElementShadow.h" | 35 #include "core/dom/shadow/ElementShadow.h" |
| 35 #include "core/dom/shadow/ShadowRoot.h" | 36 #include "core/dom/shadow/ShadowRoot.h" |
| 36 #include "core/fetch/FetchRequest.h" | 37 #include "core/fetch/FetchRequest.h" |
| 37 #include "core/fetch/ResourceFetcher.h" | 38 #include "core/fetch/ResourceFetcher.h" |
| 38 #include "core/layout/svg/LayoutSVGTransformableContainer.h" | 39 #include "core/layout/svg/LayoutSVGTransformableContainer.h" |
| 39 #include "core/svg/SVGGElement.h" | 40 #include "core/svg/SVGGElement.h" |
| 40 #include "core/svg/SVGLengthContext.h" | 41 #include "core/svg/SVGLengthContext.h" |
| 41 #include "core/svg/SVGSVGElement.h" | 42 #include "core/svg/SVGSVGElement.h" |
| 42 #include "core/xml/parser/XMLDocumentParser.h" | 43 #include "core/xml/parser/XMLDocumentParser.h" |
| 43 | 44 |
| 44 namespace blink { | 45 namespace blink { |
| 45 | 46 |
| 47 static SVGUseEventSender& svgUseLoadEventSender() | |
| 48 { | |
| 49 DEFINE_STATIC_LOCAL(SVGUseEventSender, sharedLoadEventSender, (EventTypeName s::load)); | |
| 50 return sharedLoadEventSender; | |
| 51 } | |
| 52 | |
| 46 inline SVGUseElement::SVGUseElement(Document& document) | 53 inline SVGUseElement::SVGUseElement(Document& document) |
| 47 : SVGGraphicsElement(SVGNames::useTag, document) | 54 : SVGGraphicsElement(SVGNames::useTag, document) |
| 48 , SVGURIReference(this) | 55 , SVGURIReference(this) |
| 49 , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(SVG LengthMode::Width), AllowNegativeLengths)) | 56 , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(SVG LengthMode::Width), AllowNegativeLengths)) |
| 50 , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(SVG LengthMode::Height), AllowNegativeLengths)) | 57 , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(SVG LengthMode::Height), AllowNegativeLengths)) |
| 51 , m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::cr eate(SVGLengthMode::Width), ForbidNegativeLengths)) | 58 , m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::cr eate(SVGLengthMode::Width), ForbidNegativeLengths)) |
| 52 , m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength:: create(SVGLengthMode::Height), ForbidNegativeLengths)) | 59 , m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength:: create(SVGLengthMode::Height), ForbidNegativeLengths)) |
| 53 , m_haveFiredLoadEvent(false) | 60 , m_haveFiredLoadEvent(false) |
| 54 , m_needsShadowTreeRecreation(false) | 61 , m_needsShadowTreeRecreation(false) |
| 55 , m_svgLoadEventTimer(this, &SVGElement::svgLoadEventTimerFired) | |
| 56 { | 62 { |
| 57 ASSERT(hasCustomStyleCallbacks()); | 63 ASSERT(hasCustomStyleCallbacks()); |
| 58 | 64 |
| 59 addToPropertyMap(m_x); | 65 addToPropertyMap(m_x); |
| 60 addToPropertyMap(m_y); | 66 addToPropertyMap(m_y); |
| 61 addToPropertyMap(m_width); | 67 addToPropertyMap(m_width); |
| 62 addToPropertyMap(m_height); | 68 addToPropertyMap(m_height); |
| 63 } | 69 } |
| 64 | 70 |
| 65 PassRefPtrWillBeRawPtr<SVGUseElement> SVGUseElement::create(Document& document) | 71 PassRefPtrWillBeRawPtr<SVGUseElement> SVGUseElement::create(Document& document) |
| 66 { | 72 { |
| 67 // Always build a user agent #shadow-root for SVGUseElement. | 73 // Always build a user agent #shadow-root for SVGUseElement. |
| 68 RefPtrWillBeRawPtr<SVGUseElement> use = adoptRefWillBeNoop(new SVGUseElement (document)); | 74 RefPtrWillBeRawPtr<SVGUseElement> use = adoptRefWillBeNoop(new SVGUseElement (document)); |
| 69 use->ensureUserAgentShadowRoot(); | 75 use->ensureUserAgentShadowRoot(); |
| 70 return use.release(); | 76 return use.release(); |
| 71 } | 77 } |
| 72 | 78 |
| 73 SVGUseElement::~SVGUseElement() | 79 SVGUseElement::~SVGUseElement() |
| 74 { | 80 { |
| 75 setDocumentResource(0); | 81 setDocumentResource(0); |
| 76 #if !ENABLE(OILPAN) | 82 #if !ENABLE(OILPAN) |
| 77 clearResourceReferences(); | 83 clearResourceReferences(); |
| 78 #endif | 84 #endif |
| 85 svgUseLoadEventSender().cancelEvent(this); | |
| 79 } | 86 } |
| 80 | 87 |
| 81 DEFINE_TRACE(SVGUseElement) | 88 DEFINE_TRACE(SVGUseElement) |
| 82 { | 89 { |
| 83 visitor->trace(m_x); | 90 visitor->trace(m_x); |
| 84 visitor->trace(m_y); | 91 visitor->trace(m_y); |
| 85 visitor->trace(m_width); | 92 visitor->trace(m_width); |
| 86 visitor->trace(m_height); | 93 visitor->trace(m_height); |
| 87 visitor->trace(m_targetElementInstance); | 94 visitor->trace(m_targetElementInstance); |
| 88 SVGGraphicsElement::trace(visitor); | 95 SVGGraphicsElement::trace(visitor); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 100 | 107 |
| 101 Node::InsertionNotificationRequest SVGUseElement::insertedInto(ContainerNode* ro otParent) | 108 Node::InsertionNotificationRequest SVGUseElement::insertedInto(ContainerNode* ro otParent) |
| 102 { | 109 { |
| 103 // This functions exists to assure assumptions made in the code regarding SV GElementInstance creation/destruction are satisfied. | 110 // This functions exists to assure assumptions made in the code regarding SV GElementInstance creation/destruction are satisfied. |
| 104 SVGGraphicsElement::insertedInto(rootParent); | 111 SVGGraphicsElement::insertedInto(rootParent); |
| 105 if (!rootParent->inDocument()) | 112 if (!rootParent->inDocument()) |
| 106 return InsertionDone; | 113 return InsertionDone; |
| 107 ASSERT(!m_targetElementInstance || !isWellFormedDocument(&document())); | 114 ASSERT(!m_targetElementInstance || !isWellFormedDocument(&document())); |
| 108 ASSERT(!hasPendingResources() || !isWellFormedDocument(&document())); | 115 ASSERT(!hasPendingResources() || !isWellFormedDocument(&document())); |
| 109 invalidateShadowTree(); | 116 invalidateShadowTree(); |
| 110 if (!isStructurallyExternal()) | |
| 111 sendSVGLoadEventIfPossibleAsynchronously(); | |
| 112 return InsertionDone; | 117 return InsertionDone; |
| 113 } | 118 } |
| 114 | 119 |
| 115 void SVGUseElement::removedFrom(ContainerNode* rootParent) | 120 void SVGUseElement::removedFrom(ContainerNode* rootParent) |
| 116 { | 121 { |
| 117 SVGGraphicsElement::removedFrom(rootParent); | 122 SVGGraphicsElement::removedFrom(rootParent); |
| 118 if (rootParent->inDocument()) | 123 if (rootParent->inDocument()) |
| 119 clearResourceReferences(); | 124 clearResourceReferences(); |
| 120 } | 125 } |
| 121 | 126 |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 || m_width->currentValue()->isRelative() | 714 || m_width->currentValue()->isRelative() |
| 710 || m_height->currentValue()->isRelative()) | 715 || m_height->currentValue()->isRelative()) |
| 711 return true; | 716 return true; |
| 712 | 717 |
| 713 if (!m_targetElementInstance) | 718 if (!m_targetElementInstance) |
| 714 return false; | 719 return false; |
| 715 | 720 |
| 716 return m_targetElementInstance->hasRelativeLengths(); | 721 return m_targetElementInstance->hasRelativeLengths(); |
| 717 } | 722 } |
| 718 | 723 |
| 724 void SVGUseElement::dispatchPendingEvent(SVGUseEventSender* eventSender) | |
| 725 { | |
| 726 ASSERT_UNUSED(eventSender, eventSender == &svgUseLoadEventSender()); | |
| 727 ASSERT(isStructurallyExternal() && m_haveFiredLoadEvent); | |
| 728 dispatchEvent(Event::create(EventTypeNames::load)); | |
| 729 } | |
| 730 | |
| 719 void SVGUseElement::notifyFinished(Resource* resource) | 731 void SVGUseElement::notifyFinished(Resource* resource) |
| 720 { | 732 { |
| 721 if (!inDocument()) | 733 if (!inDocument()) |
| 722 return; | 734 return; |
| 723 | 735 |
| 724 invalidateShadowTree(); | 736 invalidateShadowTree(); |
| 725 if (resource->errorOccurred()) | 737 if (resource->errorOccurred()) |
| 726 dispatchEvent(Event::create(EventTypeNames::error)); | 738 dispatchEvent(Event::create(EventTypeNames::error)); |
|
fs
2015/05/20 14:43:34
It might make sense to have the 'error' event be e
| |
| 727 else if (!resource->wasCanceled()) { | 739 else if (!resource->wasCanceled()) { |
| 728 if (m_haveFiredLoadEvent) | 740 if (m_haveFiredLoadEvent) |
| 729 return; | 741 return; |
| 730 if (!isStructurallyExternal()) | 742 if (!isStructurallyExternal()) |
| 731 return; | 743 return; |
| 732 ASSERT(!m_haveFiredLoadEvent); | 744 ASSERT(!m_haveFiredLoadEvent); |
| 733 m_haveFiredLoadEvent = true; | 745 m_haveFiredLoadEvent = true; |
| 734 sendSVGLoadEventIfPossibleAsynchronously(); | 746 svgUseLoadEventSender().dispatchEventSoon(this); |
| 735 } | 747 } |
| 736 } | 748 } |
| 737 | 749 |
| 738 bool SVGUseElement::resourceIsStillLoading() | 750 bool SVGUseElement::resourceIsStillLoading() |
| 739 { | 751 { |
| 740 if (m_resource && m_resource->isLoading()) | 752 if (m_resource && m_resource->isLoading()) |
| 741 return true; | 753 return true; |
| 742 return false; | 754 return false; |
| 743 } | 755 } |
| 744 | 756 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 762 | 774 |
| 763 if (m_resource) | 775 if (m_resource) |
| 764 m_resource->removeClient(this); | 776 m_resource->removeClient(this); |
| 765 | 777 |
| 766 m_resource = resource; | 778 m_resource = resource; |
| 767 if (m_resource) | 779 if (m_resource) |
| 768 m_resource->addClient(this); | 780 m_resource->addClient(this); |
| 769 } | 781 } |
| 770 | 782 |
| 771 } | 783 } |
| OLD | NEW |