• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  * Copyright (C) 2004, 2009 Apple Inc. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef ImageLoader_h
24 #define ImageLoader_h
25 
26 #include "AtomicString.h"
27 #include "CachedResourceClient.h"
28 #include "CachedResourceHandle.h"
29 
30 namespace WebCore {
31 
32 class Element;
33 class ImageLoadEventSender;
34 
35 class ImageLoader : public CachedResourceClient {
36 public:
37     ImageLoader(Element*);
38     virtual ~ImageLoader();
39 
40     // This function should be called when the element is attached to a document; starts
41     // loading if a load hasn't already been started.
42     void updateFromElement();
43 
44     // This function should be called whenever the 'src' attribute is set, even if its value
45     // doesn't change; starts new load unconditionally (matches Firefox and Opera behavior).
46     void updateFromElementIgnoringPreviousError();
47 
element()48     Element* element() const { return m_element; }
imageComplete()49     bool imageComplete() const { return m_imageComplete; }
50 
image()51     CachedImage* image() const { return m_image.get(); }
52     void setImage(CachedImage*);
53 
setLoadManually(bool loadManually)54     void setLoadManually(bool loadManually) { m_loadManually = loadManually; }
55 
haveFiredLoadEvent()56     bool haveFiredLoadEvent() const { return m_firedLoad; }
57 
58     static void dispatchPendingLoadEvents();
59 
60 protected:
61     virtual void notifyFinished(CachedResource*);
62 
63 private:
64     virtual void dispatchLoadEvent() = 0;
65     virtual String sourceURI(const AtomicString&) const = 0;
66 
67     friend class ImageLoadEventSender;
68     void dispatchPendingLoadEvent();
69 
70     void setLoadingImage(CachedImage*);
71 
72     Element* m_element;
73     CachedResourceHandle<CachedImage> m_image;
74     AtomicString m_failedLoadURL;
75     bool m_firedLoad : 1;
76     bool m_imageComplete : 1;
77     bool m_loadManually : 1;
78 };
79 
80 }
81 
82 #endif
83