michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // A class that handles style system image loads (other image loads are handled michael@0: // by the nodes in the content tree). michael@0: michael@0: #ifndef mozilla_css_ImageLoader_h___ michael@0: #define mozilla_css_ImageLoader_h___ michael@0: michael@0: #include "nsClassHashtable.h" michael@0: #include "nsHashKeys.h" michael@0: #include "nsCSSValue.h" michael@0: #include "imgIRequest.h" michael@0: #include "imgIOnloadBlocker.h" michael@0: #include "imgINotificationObserver.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsIFrame; michael@0: class nsIDocument; michael@0: class nsPresContext; michael@0: class nsIURI; michael@0: class nsIPrincipal; michael@0: michael@0: namespace mozilla { michael@0: namespace css { michael@0: michael@0: class ImageLoader MOZ_FINAL : public imgINotificationObserver, michael@0: public imgIOnloadBlocker { michael@0: public: michael@0: typedef mozilla::css::ImageValue Image; michael@0: michael@0: ImageLoader(nsIDocument* aDocument) michael@0: : mDocument(aDocument), michael@0: mInClone(false) michael@0: { michael@0: MOZ_ASSERT(mDocument); michael@0: } michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_IMGIONLOADBLOCKER michael@0: NS_DECL_IMGINOTIFICATIONOBSERVER michael@0: michael@0: void DropDocumentReference(); michael@0: michael@0: void MaybeRegisterCSSImage(Image* aImage); michael@0: void DeregisterCSSImage(Image* aImage); michael@0: michael@0: void AssociateRequestToFrame(imgIRequest* aRequest, michael@0: nsIFrame* aFrame); michael@0: michael@0: void DisassociateRequestFromFrame(imgIRequest* aRequest, michael@0: nsIFrame* aFrame); michael@0: michael@0: void DropRequestsForFrame(nsIFrame* aFrame); michael@0: michael@0: void SetAnimationMode(uint16_t aMode); michael@0: michael@0: void ClearFrames(); michael@0: michael@0: void LoadImage(nsIURI* aURI, nsIPrincipal* aPrincipal, nsIURI* aReferrer, michael@0: Image* aCSSValue); michael@0: michael@0: void DestroyRequest(imgIRequest* aRequest); michael@0: michael@0: private: michael@0: // We need to be able to look up the frames associated with a request (for michael@0: // delivering notifications) and the requests associated with a frame (when michael@0: // the frame goes away). Thus we maintain hashtables going both ways. These michael@0: // should always be in sync. michael@0: michael@0: typedef nsTArray FrameSet; michael@0: typedef nsTArray > RequestSet; michael@0: typedef nsTHashtable > ImageHashSet; michael@0: typedef nsClassHashtable RequestToFrameMap; michael@0: typedef nsClassHashtable, michael@0: RequestSet> FrameToRequestMap; michael@0: michael@0: void AddImage(Image* aCSSImage); michael@0: void RemoveImage(Image* aCSSImage); michael@0: michael@0: nsPresContext* GetPresContext(); michael@0: michael@0: void DoRedraw(FrameSet* aFrameSet); michael@0: michael@0: static PLDHashOperator michael@0: SetAnimationModeEnumerator(nsISupports* aKey, FrameSet* aValue, michael@0: void* aClosure); michael@0: michael@0: nsresult OnStartContainer(imgIRequest *aRequest, imgIContainer* aImage); michael@0: nsresult OnStopFrame(imgIRequest *aRequest); michael@0: nsresult OnImageIsAnimated(imgIRequest *aRequest); michael@0: nsresult FrameChanged(imgIRequest* aRequest); michael@0: // Do not override OnDataAvailable since background images are not michael@0: // displayed incrementally; they are displayed after the entire image michael@0: // has been loaded. michael@0: michael@0: // A map of imgIRequests to the nsIFrames that are using them. michael@0: RequestToFrameMap mRequestToFrameMap; michael@0: michael@0: // A map of nsIFrames to the imgIRequests they use. michael@0: FrameToRequestMap mFrameToRequestMap; michael@0: michael@0: // A weak pointer to our document. Nulled out by DropDocumentReference. michael@0: nsIDocument* mDocument; michael@0: michael@0: // The set of all nsCSSValue::Images (whether they're associated a frame or michael@0: // not). We'll need this when we go away to remove any requests associated michael@0: // with our document from those Images. michael@0: ImageHashSet mImages; michael@0: michael@0: // Are we cloning? If so, ignore any notifications we get. michael@0: bool mInClone; michael@0: }; michael@0: michael@0: } // namespace css michael@0: } // namespace mozilla michael@0: michael@0: #endif /* mozilla_css_ImageLoader_h___ */