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 "CachedImageClient.h" 27#include "CachedResourceHandle.h" 28#include "Timer.h" 29#include <wtf/text/AtomicString.h> 30 31namespace WebCore { 32 33class Element; 34class ImageLoader; 35class RenderImageResource; 36 37template<typename T> class EventSender; 38typedef EventSender<ImageLoader> ImageEventSender; 39 40class ImageLoader : public CachedImageClient { 41public: 42 explicit ImageLoader(Element*); 43 virtual ~ImageLoader(); 44 45 // This function should be called when the element is attached to a document; starts 46 // loading if a load hasn't already been started. 47 void updateFromElement(); 48 49 // This function should be called whenever the 'src' attribute is set, even if its value 50 // doesn't change; starts new load unconditionally (matches Firefox and Opera behavior). 51 void updateFromElementIgnoringPreviousError(); 52 53 void elementDidMoveToNewDocument(); 54 55 Element* element() const { return m_element; } 56 bool imageComplete() const { return m_imageComplete; } 57 58 CachedImage* image() const { return m_image.get(); } 59 void setImage(CachedImage*); // Cancels pending beforeload and load events, and doesn't dispatch new ones. 60 61 void setLoadManually(bool loadManually) { m_loadManually = loadManually; } 62 63 bool hasPendingBeforeLoadEvent() const { return m_hasPendingBeforeLoadEvent; } 64 bool hasPendingActivity() const { return m_hasPendingLoadEvent || m_hasPendingErrorEvent; } 65 66 void dispatchPendingEvent(ImageEventSender*); 67 68 static void dispatchPendingBeforeLoadEvents(); 69 static void dispatchPendingLoadEvents(); 70 static void dispatchPendingErrorEvents(); 71 72protected: 73 virtual void notifyFinished(CachedResource*); 74 75private: 76 virtual void dispatchLoadEvent() = 0; 77 virtual String sourceURI(const AtomicString&) const = 0; 78 79 void updatedHasPendingEvent(); 80 81 void dispatchPendingBeforeLoadEvent(); 82 void dispatchPendingLoadEvent(); 83 void dispatchPendingErrorEvent(); 84 85 RenderImageResource* renderImageResource(); 86 void updateRenderer(); 87 88 void setImageWithoutConsideringPendingLoadEvent(CachedImage*); 89 void clearFailedLoadURL(); 90 91 void timerFired(Timer<ImageLoader>*); 92 93 Element* m_element; 94 CachedResourceHandle<CachedImage> m_image; 95 Timer<ImageLoader> m_derefElementTimer; 96 AtomicString m_failedLoadURL; 97 bool m_hasPendingBeforeLoadEvent : 1; 98 bool m_hasPendingLoadEvent : 1; 99 bool m_hasPendingErrorEvent : 1; 100 bool m_imageComplete : 1; 101 bool m_loadManually : 1; 102 bool m_elementIsProtected : 1; 103}; 104 105} 106 107#endif 108