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 "CachedResourceClient.h"
27 #include "CachedResourceHandle.h"
28 #include <wtf/text/AtomicString.h>
29 
30 namespace WebCore {
31 
32 class Element;
33 class ImageLoadEventSender;
34 class RenderImageResource;
35 
36 class ImageLoader : public CachedResourceClient {
37 public:
38     ImageLoader(Element*);
39     virtual ~ImageLoader();
40 
41     // This function should be called when the element is attached to a document; starts
42     // loading if a load hasn't already been started.
43     void updateFromElement();
44 
45     // This function should be called whenever the 'src' attribute is set, even if its value
46     // doesn't change; starts new load unconditionally (matches Firefox and Opera behavior).
47     void updateFromElementIgnoringPreviousError();
48 
49     void elementWillMoveToNewOwnerDocument();
50 
element()51     Element* element() const { return m_element; }
imageComplete()52     bool imageComplete() const { return m_imageComplete; }
53 
image()54     CachedImage* image() const { return m_image.get(); }
55     void setImage(CachedImage*); // Cancels pending beforeload and load events, and doesn't dispatch new ones.
56 
setLoadManually(bool loadManually)57     void setLoadManually(bool loadManually) { m_loadManually = loadManually; }
58 
haveFiredBeforeLoadEvent()59     bool haveFiredBeforeLoadEvent() const { return m_firedBeforeLoad; }
haveFiredLoadEvent()60     bool haveFiredLoadEvent() const { return m_firedLoad; }
61 
62     static void dispatchPendingBeforeLoadEvents();
63     static void dispatchPendingLoadEvents();
64 
65 protected:
66     virtual void notifyFinished(CachedResource*);
67 
68 private:
69     virtual void dispatchLoadEvent() = 0;
70     virtual String sourceURI(const AtomicString&) const = 0;
71 
72     friend class ImageEventSender;
73     void dispatchPendingBeforeLoadEvent();
74     void dispatchPendingLoadEvent();
75 
76     RenderImageResource* renderImageResource();
77     void updateRenderer();
78 
79     Element* m_element;
80     CachedResourceHandle<CachedImage> m_image;
81     AtomicString m_failedLoadURL;
82     bool m_firedBeforeLoad : 1;
83     bool m_firedLoad : 1;
84     bool m_imageComplete : 1;
85     bool m_loadManually : 1;
86 };
87 
88 }
89 
90 #endif
91