2012-08-14 02:04:19 +04: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).
|
|
|
|
|
2013-07-19 12:40:02 +04:00
|
|
|
#ifndef mozilla_css_ImageLoader_h___
|
|
|
|
#define mozilla_css_ImageLoader_h___
|
|
|
|
|
2012-08-14 02:04:19 +04:00
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2014-05-09 19:23:14 +04:00
|
|
|
#include "nsTArray.h"
|
2012-08-14 02:04:19 +04:00
|
|
|
#include "imgIRequest.h"
|
2012-08-14 03:04:17 +04:00
|
|
|
#include "imgIOnloadBlocker.h"
|
2012-10-12 20:11:22 +04:00
|
|
|
#include "imgINotificationObserver.h"
|
2012-08-25 20:33:51 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-08-14 02:04:19 +04:00
|
|
|
|
2014-05-09 19:23:14 +04:00
|
|
|
class imgIContainer;
|
2012-08-14 02:04:19 +04:00
|
|
|
class nsIFrame;
|
|
|
|
class nsIDocument;
|
|
|
|
class nsPresContext;
|
|
|
|
class nsIURI;
|
|
|
|
class nsIPrincipal;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2014-06-19 04:57:51 +04:00
|
|
|
struct ImageValue;
|
2014-05-09 19:23:14 +04:00
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
class ImageLoader MOZ_FINAL : public imgINotificationObserver,
|
2012-08-25 20:33:51 +04:00
|
|
|
public imgIOnloadBlocker {
|
2012-08-14 02:04:19 +04:00
|
|
|
public:
|
2012-08-24 21:50:49 +04:00
|
|
|
typedef mozilla::css::ImageValue Image;
|
|
|
|
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit ImageLoader(nsIDocument* aDocument)
|
2012-08-14 02:04:19 +04:00
|
|
|
: mDocument(aDocument),
|
|
|
|
mInClone(false)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2012-08-14 03:04:17 +04:00
|
|
|
NS_DECL_IMGIONLOADBLOCKER
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_DECL_IMGINOTIFICATIONOBSERVER
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
void DropDocumentReference();
|
|
|
|
|
2012-08-24 21:50:49 +04:00
|
|
|
void MaybeRegisterCSSImage(Image* aImage);
|
|
|
|
void DeregisterCSSImage(Image* aImage);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
void AssociateRequestToFrame(imgIRequest* aRequest,
|
|
|
|
nsIFrame* aFrame);
|
|
|
|
|
|
|
|
void DisassociateRequestFromFrame(imgIRequest* aRequest,
|
|
|
|
nsIFrame* aFrame);
|
|
|
|
|
|
|
|
void DropRequestsForFrame(nsIFrame* aFrame);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetAnimationMode(uint16_t aMode);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
2014-09-05 08:27:16 +04:00
|
|
|
// The prescontext for this ImageLoader's document. We need it to be passed
|
|
|
|
// in because this can be called during presentation destruction after the
|
|
|
|
// presshell pointer on the document has been cleared.
|
|
|
|
void ClearFrames(nsPresContext* aPresContext);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
void LoadImage(nsIURI* aURI, nsIPrincipal* aPrincipal, nsIURI* aReferrer,
|
2012-08-24 21:50:49 +04:00
|
|
|
Image* aCSSValue);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
void DestroyRequest(imgIRequest* aRequest);
|
|
|
|
|
|
|
|
private:
|
2014-06-24 02:40:01 +04:00
|
|
|
~ImageLoader() {}
|
|
|
|
|
2012-08-14 02:04:19 +04:00
|
|
|
// 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 21:50:49 +04:00
|
|
|
typedef nsTHashtable<nsPtrHashKey<Image> > ImageHashSet;
|
2012-08-14 02:04:19 +04:00
|
|
|
typedef nsClassHashtable<nsISupportsHashKey,
|
|
|
|
FrameSet> RequestToFrameMap;
|
|
|
|
typedef nsClassHashtable<nsPtrHashKey<nsIFrame>,
|
|
|
|
RequestSet> FrameToRequestMap;
|
|
|
|
|
2012-08-24 21:50:49 +04:00
|
|
|
void AddImage(Image* aCSSImage);
|
|
|
|
void RemoveImage(Image* aCSSImage);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
nsPresContext* GetPresContext();
|
|
|
|
|
2014-11-08 02:40:12 +03:00
|
|
|
void DoRedraw(FrameSet* aFrameSet, bool aForcePaint);
|
2012-08-14 02:04:19 +04:00
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
SetAnimationModeEnumerator(nsISupports* aKey, FrameSet* aValue,
|
|
|
|
void* aClosure);
|
|
|
|
|
2014-09-05 08:27:16 +04:00
|
|
|
static PLDHashOperator
|
|
|
|
DeregisterRequestEnumerator(nsISupports* aKey, FrameSet* aValue,
|
|
|
|
void* aClosure);
|
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
nsresult OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
|
|
|
|
nsresult OnFrameComplete(imgIRequest* aRequest);
|
|
|
|
nsresult OnImageIsAnimated(imgIRequest* aRequest);
|
|
|
|
nsresult OnFrameUpdate(imgIRequest* aRequest);
|
2012-10-12 20:11:22 +04:00
|
|
|
|
2012-08-14 02:04:19 +04: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
|
2013-07-19 12:40:02 +04:00
|
|
|
|
|
|
|
#endif /* mozilla_css_ImageLoader_h___ */
|