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