KHtml

SVGImageLoader.cpp
1 /*
2  Copyright (C) 2005, 2005 Alexander Kellett <[email protected]>
3  2008 Rob Buis <[email protected]>
4 
5  This file is part of the WebKit project
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #if ENABLE(SVG)
24 
25 #include "Attr.h"
26 #include "DocLoader.h"
27 #include "Document.h"
28 
29 #include "SVGImageElement.h"
30 #include "SVGLength.h"
31 #include "SVGNames.h"
32 
33 #include "RenderImage.h"
34 
35 namespace WebCore
36 {
37 
38 SVGImageLoader::SVGImageLoader(SVGImageElement *node)
39  : HTMLImageLoader(node)
40 {
41 }
42 
43 SVGImageLoader::~SVGImageLoader()
44 {
45 }
46 
47 // FIXME - Refactor most of this code into WebCore::HTMLImageLoader or a shared WebCore::ImageLoader base class
48 void SVGImageLoader::updateFromElement()
49 {
50  SVGImageElement *imageElement = static_cast<SVGImageElement *>(element());
51  WebCore::Document *doc = imageElement->ownerDocument();
52 
53  CachedImage *newImage = 0;
54  if (!imageElement->href().isEmpty()) {
55  KURL uri = imageElement->baseURI();
56  if (!uri.isEmpty()) {
57  uri = KURL(uri, imageElement->href());
58  } else {
59  uri = KURL(imageElement->href());
60  }
61  newImage = doc->docLoader()->requestImage(uri.string());
62  }
63 
64  CachedImage *oldImage = image();
65  if (newImage != oldImage) {
66  setLoadingImage(newImage);
67  if (newImage) {
68  newImage->addClient(this);
69  }
70  if (oldImage) {
71  oldImage->removeClient(this);
72  }
73  }
74 
75  if (RenderImage *renderer = static_cast<RenderImage *>(imageElement->renderer())) {
76  renderer->resetAnimation();
77  }
78 }
79 
80 void SVGImageLoader::dispatchLoadEvent()
81 {
82  if (!haveFiredLoadEvent() && image()) {
83  setHaveFiredLoadEvent(true);
84  if (image()->errorOccurred()) {
85  // FIXME: We're supposed to put the document in an "error state" per the spec.
86  } else if (static_cast<SVGImageElement *>(element())->externalResourcesRequiredBaseValue()) {
87  static_cast<SVGElement *>(element())->sendSVGLoadEventIfPossible(true);
88  }
89  }
90 }
91 
92 }
93 
94 #endif // ENABLE(SVG)
The Document interface represents the entire HTML or XML document.
Definition: dom_doc.h:246
Document ownerDocument() const
The Document object associated with this node.
Definition: dom_node.cpp:306
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:48:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.