ImageLoader.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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/. */
  4. // A class that handles style system image loads (other image loads are handled
  5. // by the nodes in the content tree).
  6. #ifndef mozilla_css_ImageLoader_h___
  7. #define mozilla_css_ImageLoader_h___
  8. #include "nsClassHashtable.h"
  9. #include "nsHashKeys.h"
  10. #include "nsTArray.h"
  11. #include "imgIRequest.h"
  12. #include "imgIOnloadBlocker.h"
  13. #include "imgINotificationObserver.h"
  14. #include "mozilla/Attributes.h"
  15. class imgIContainer;
  16. class nsIFrame;
  17. class nsIDocument;
  18. class nsPresContext;
  19. class nsIURI;
  20. class nsIPrincipal;
  21. namespace mozilla {
  22. namespace css {
  23. struct ImageValue;
  24. class ImageLoader final : public imgINotificationObserver,
  25. public imgIOnloadBlocker
  26. {
  27. public:
  28. typedef mozilla::css::ImageValue Image;
  29. explicit ImageLoader(nsIDocument* aDocument)
  30. : mDocument(aDocument),
  31. mInClone(false)
  32. {
  33. MOZ_ASSERT(mDocument);
  34. }
  35. NS_DECL_ISUPPORTS
  36. NS_DECL_IMGIONLOADBLOCKER
  37. NS_DECL_IMGINOTIFICATIONOBSERVER
  38. void DropDocumentReference();
  39. void MaybeRegisterCSSImage(Image* aImage);
  40. void DeregisterCSSImage(Image* aImage);
  41. void AssociateRequestToFrame(imgIRequest* aRequest,
  42. nsIFrame* aFrame);
  43. void DisassociateRequestFromFrame(imgIRequest* aRequest,
  44. nsIFrame* aFrame);
  45. void DropRequestsForFrame(nsIFrame* aFrame);
  46. void SetAnimationMode(uint16_t aMode);
  47. // The prescontext for this ImageLoader's document. We need it to be passed
  48. // in because this can be called during presentation destruction after the
  49. // presshell pointer on the document has been cleared.
  50. void ClearFrames(nsPresContext* aPresContext);
  51. void LoadImage(nsIURI* aURI, nsIPrincipal* aPrincipal, nsIURI* aReferrer,
  52. Image* aCSSValue);
  53. void DestroyRequest(imgIRequest* aRequest);
  54. void FlushUseCounters();
  55. private:
  56. ~ImageLoader() {}
  57. // We need to be able to look up the frames associated with a request (for
  58. // delivering notifications) and the requests associated with a frame (when
  59. // the frame goes away). Thus we maintain hashtables going both ways. These
  60. // should always be in sync.
  61. typedef nsTArray<nsIFrame*> FrameSet;
  62. typedef nsTArray<nsCOMPtr<imgIRequest> > RequestSet;
  63. typedef nsTHashtable<nsPtrHashKey<Image> > ImageHashSet;
  64. typedef nsClassHashtable<nsISupportsHashKey,
  65. FrameSet> RequestToFrameMap;
  66. typedef nsClassHashtable<nsPtrHashKey<nsIFrame>,
  67. RequestSet> FrameToRequestMap;
  68. void AddImage(Image* aCSSImage);
  69. void RemoveImage(Image* aCSSImage);
  70. nsPresContext* GetPresContext();
  71. void DoRedraw(FrameSet* aFrameSet, bool aForcePaint);
  72. nsresult OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
  73. nsresult OnFrameComplete(imgIRequest* aRequest);
  74. nsresult OnImageIsAnimated(imgIRequest* aRequest);
  75. nsresult OnFrameUpdate(imgIRequest* aRequest);
  76. // A map of imgIRequests to the nsIFrames that are using them.
  77. RequestToFrameMap mRequestToFrameMap;
  78. // A map of nsIFrames to the imgIRequests they use.
  79. FrameToRequestMap mFrameToRequestMap;
  80. // A weak pointer to our document. Nulled out by DropDocumentReference.
  81. nsIDocument* mDocument;
  82. // The set of all nsCSSValue::Images (whether they're associated a frame or
  83. // not). We'll need this when we go away to remove any requests associated
  84. // with our document from those Images.
  85. ImageHashSet mImages;
  86. // Are we cloning? If so, ignore any notifications we get.
  87. bool mInClone;
  88. };
  89. } // namespace css
  90. } // namespace mozilla
  91. #endif /* mozilla_css_ImageLoader_h___ */