File indexing completed on 2024-04-28 11:39:15

0001 /*
0002     Copyright (C) 2005, 2005 Alexander Kellett <lypanov@kde.org>
0003                   2008 Rob Buis <buis@kde.org>
0004 
0005     This file is part of the WebKit project
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This library is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015     Library General Public License for more details.
0016 
0017     You should have received a copy of the GNU Library General Public License
0018     along with this library; see the file COPYING.LIB.  If not, write to
0019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020     Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #if ENABLE(SVG)
0024 
0025 #include "Attr.h"
0026 #include "DocLoader.h"
0027 #include "Document.h"
0028 
0029 #include "SVGImageElement.h"
0030 #include "SVGLength.h"
0031 #include "SVGNames.h"
0032 
0033 #include "RenderImage.h"
0034 
0035 namespace WebCore
0036 {
0037 
0038 SVGImageLoader::SVGImageLoader(SVGImageElement *node)
0039     : HTMLImageLoader(node)
0040 {
0041 }
0042 
0043 SVGImageLoader::~SVGImageLoader()
0044 {
0045 }
0046 
0047 // FIXME - Refactor most of this code into WebCore::HTMLImageLoader or a shared WebCore::ImageLoader base class
0048 void SVGImageLoader::updateFromElement()
0049 {
0050     SVGImageElement *imageElement = static_cast<SVGImageElement *>(element());
0051     WebCore::Document *doc = imageElement->ownerDocument();
0052 
0053     CachedImage *newImage = 0;
0054     if (!imageElement->href().isEmpty()) {
0055         KURL uri = imageElement->baseURI();
0056         if (!uri.isEmpty()) {
0057             uri = KURL(uri, imageElement->href());
0058         } else {
0059             uri = KURL(imageElement->href());
0060         }
0061         newImage = doc->docLoader()->requestImage(uri.string());
0062     }
0063 
0064     CachedImage *oldImage = image();
0065     if (newImage != oldImage) {
0066         setLoadingImage(newImage);
0067         if (newImage) {
0068             newImage->addClient(this);
0069         }
0070         if (oldImage) {
0071             oldImage->removeClient(this);
0072         }
0073     }
0074 
0075     if (RenderImage *renderer = static_cast<RenderImage *>(imageElement->renderer())) {
0076         renderer->resetAnimation();
0077     }
0078 }
0079 
0080 void SVGImageLoader::dispatchLoadEvent()
0081 {
0082     if (!haveFiredLoadEvent() && image()) {
0083         setHaveFiredLoadEvent(true);
0084         if (image()->errorOccurred()) {
0085             // FIXME: We're supposed to put the document in an "error state" per the spec.
0086         } else if (static_cast<SVGImageElement *>(element())->externalResourcesRequiredBaseValue()) {
0087             static_cast<SVGElement *>(element())->sendSVGLoadEventIfPossible(true);
0088         }
0089     }
0090 }
0091 
0092 }
0093 
0094 #endif // ENABLE(SVG)