1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // A class that handles style system image loads (other image loads are handled
6 // by the nodes in the content tree).
8 #ifndef mozilla_css_ImageLoader_h___
9 #define mozilla_css_ImageLoader_h___
11 #include "nsClassHashtable.h"
12 #include "nsHashKeys.h"
14 #include "imgIRequest.h"
15 #include "imgIOnloadBlocker.h"
16 #include "imgINotificationObserver.h"
17 #include "mozilla/Attributes.h"
31 class ImageLoader MOZ_FINAL
: public imgINotificationObserver
,
32 public imgIOnloadBlocker
{
34 typedef mozilla::css::ImageValue Image
;
36 explicit ImageLoader(nsIDocument
* aDocument
)
37 : mDocument(aDocument
),
40 MOZ_ASSERT(mDocument
);
44 NS_DECL_IMGIONLOADBLOCKER
45 NS_DECL_IMGINOTIFICATIONOBSERVER
47 void DropDocumentReference();
49 void MaybeRegisterCSSImage(Image
* aImage
);
50 void DeregisterCSSImage(Image
* aImage
);
52 void AssociateRequestToFrame(imgIRequest
* aRequest
,
55 void DisassociateRequestFromFrame(imgIRequest
* aRequest
,
58 void DropRequestsForFrame(nsIFrame
* aFrame
);
60 void SetAnimationMode(uint16_t aMode
);
64 void LoadImage(nsIURI
* aURI
, nsIPrincipal
* aPrincipal
, nsIURI
* aReferrer
,
67 void DestroyRequest(imgIRequest
* aRequest
);
72 // We need to be able to look up the frames associated with a request (for
73 // delivering notifications) and the requests associated with a frame (when
74 // the frame goes away). Thus we maintain hashtables going both ways. These
75 // should always be in sync.
77 typedef nsTArray
<nsIFrame
*> FrameSet
;
78 typedef nsTArray
<nsCOMPtr
<imgIRequest
> > RequestSet
;
79 typedef nsTHashtable
<nsPtrHashKey
<Image
> > ImageHashSet
;
80 typedef nsClassHashtable
<nsISupportsHashKey
,
81 FrameSet
> RequestToFrameMap
;
82 typedef nsClassHashtable
<nsPtrHashKey
<nsIFrame
>,
83 RequestSet
> FrameToRequestMap
;
85 void AddImage(Image
* aCSSImage
);
86 void RemoveImage(Image
* aCSSImage
);
88 nsPresContext
* GetPresContext();
90 void DoRedraw(FrameSet
* aFrameSet
);
92 static PLDHashOperator
93 SetAnimationModeEnumerator(nsISupports
* aKey
, FrameSet
* aValue
,
96 nsresult
OnStartContainer(imgIRequest
*aRequest
, imgIContainer
* aImage
);
97 nsresult
OnStopFrame(imgIRequest
*aRequest
);
98 nsresult
OnImageIsAnimated(imgIRequest
*aRequest
);
99 nsresult
FrameChanged(imgIRequest
* aRequest
);
100 // Do not override OnDataAvailable since background images are not
101 // displayed incrementally; they are displayed after the entire image
104 // A map of imgIRequests to the nsIFrames that are using them.
105 RequestToFrameMap mRequestToFrameMap
;
107 // A map of nsIFrames to the imgIRequests they use.
108 FrameToRequestMap mFrameToRequestMap
;
110 // A weak pointer to our document. Nulled out by DropDocumentReference.
111 nsIDocument
* mDocument
;
113 // The set of all nsCSSValue::Images (whether they're associated a frame or
114 // not). We'll need this when we go away to remove any requests associated
115 // with our document from those Images.
116 ImageHashSet mImages
;
118 // Are we cloning? If so, ignore any notifications we get.
123 } // namespace mozilla
125 #endif /* mozilla_css_ImageLoader_h___ */