Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | // A class that handles style system image loads (other image loads are handled |
michael@0 | 6 | // by the nodes in the content tree). |
michael@0 | 7 | |
michael@0 | 8 | #ifndef mozilla_css_ImageLoader_h___ |
michael@0 | 9 | #define mozilla_css_ImageLoader_h___ |
michael@0 | 10 | |
michael@0 | 11 | #include "nsClassHashtable.h" |
michael@0 | 12 | #include "nsHashKeys.h" |
michael@0 | 13 | #include "nsCSSValue.h" |
michael@0 | 14 | #include "imgIRequest.h" |
michael@0 | 15 | #include "imgIOnloadBlocker.h" |
michael@0 | 16 | #include "imgINotificationObserver.h" |
michael@0 | 17 | #include "mozilla/Attributes.h" |
michael@0 | 18 | |
michael@0 | 19 | class nsIFrame; |
michael@0 | 20 | class nsIDocument; |
michael@0 | 21 | class nsPresContext; |
michael@0 | 22 | class nsIURI; |
michael@0 | 23 | class nsIPrincipal; |
michael@0 | 24 | |
michael@0 | 25 | namespace mozilla { |
michael@0 | 26 | namespace css { |
michael@0 | 27 | |
michael@0 | 28 | class ImageLoader MOZ_FINAL : public imgINotificationObserver, |
michael@0 | 29 | public imgIOnloadBlocker { |
michael@0 | 30 | public: |
michael@0 | 31 | typedef mozilla::css::ImageValue Image; |
michael@0 | 32 | |
michael@0 | 33 | ImageLoader(nsIDocument* aDocument) |
michael@0 | 34 | : mDocument(aDocument), |
michael@0 | 35 | mInClone(false) |
michael@0 | 36 | { |
michael@0 | 37 | MOZ_ASSERT(mDocument); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | NS_DECL_ISUPPORTS |
michael@0 | 41 | NS_DECL_IMGIONLOADBLOCKER |
michael@0 | 42 | NS_DECL_IMGINOTIFICATIONOBSERVER |
michael@0 | 43 | |
michael@0 | 44 | void DropDocumentReference(); |
michael@0 | 45 | |
michael@0 | 46 | void MaybeRegisterCSSImage(Image* aImage); |
michael@0 | 47 | void DeregisterCSSImage(Image* aImage); |
michael@0 | 48 | |
michael@0 | 49 | void AssociateRequestToFrame(imgIRequest* aRequest, |
michael@0 | 50 | nsIFrame* aFrame); |
michael@0 | 51 | |
michael@0 | 52 | void DisassociateRequestFromFrame(imgIRequest* aRequest, |
michael@0 | 53 | nsIFrame* aFrame); |
michael@0 | 54 | |
michael@0 | 55 | void DropRequestsForFrame(nsIFrame* aFrame); |
michael@0 | 56 | |
michael@0 | 57 | void SetAnimationMode(uint16_t aMode); |
michael@0 | 58 | |
michael@0 | 59 | void ClearFrames(); |
michael@0 | 60 | |
michael@0 | 61 | void LoadImage(nsIURI* aURI, nsIPrincipal* aPrincipal, nsIURI* aReferrer, |
michael@0 | 62 | Image* aCSSValue); |
michael@0 | 63 | |
michael@0 | 64 | void DestroyRequest(imgIRequest* aRequest); |
michael@0 | 65 | |
michael@0 | 66 | private: |
michael@0 | 67 | // We need to be able to look up the frames associated with a request (for |
michael@0 | 68 | // delivering notifications) and the requests associated with a frame (when |
michael@0 | 69 | // the frame goes away). Thus we maintain hashtables going both ways. These |
michael@0 | 70 | // should always be in sync. |
michael@0 | 71 | |
michael@0 | 72 | typedef nsTArray<nsIFrame*> FrameSet; |
michael@0 | 73 | typedef nsTArray<nsCOMPtr<imgIRequest> > RequestSet; |
michael@0 | 74 | typedef nsTHashtable<nsPtrHashKey<Image> > ImageHashSet; |
michael@0 | 75 | typedef nsClassHashtable<nsISupportsHashKey, |
michael@0 | 76 | FrameSet> RequestToFrameMap; |
michael@0 | 77 | typedef nsClassHashtable<nsPtrHashKey<nsIFrame>, |
michael@0 | 78 | RequestSet> FrameToRequestMap; |
michael@0 | 79 | |
michael@0 | 80 | void AddImage(Image* aCSSImage); |
michael@0 | 81 | void RemoveImage(Image* aCSSImage); |
michael@0 | 82 | |
michael@0 | 83 | nsPresContext* GetPresContext(); |
michael@0 | 84 | |
michael@0 | 85 | void DoRedraw(FrameSet* aFrameSet); |
michael@0 | 86 | |
michael@0 | 87 | static PLDHashOperator |
michael@0 | 88 | SetAnimationModeEnumerator(nsISupports* aKey, FrameSet* aValue, |
michael@0 | 89 | void* aClosure); |
michael@0 | 90 | |
michael@0 | 91 | nsresult OnStartContainer(imgIRequest *aRequest, imgIContainer* aImage); |
michael@0 | 92 | nsresult OnStopFrame(imgIRequest *aRequest); |
michael@0 | 93 | nsresult OnImageIsAnimated(imgIRequest *aRequest); |
michael@0 | 94 | nsresult FrameChanged(imgIRequest* aRequest); |
michael@0 | 95 | // Do not override OnDataAvailable since background images are not |
michael@0 | 96 | // displayed incrementally; they are displayed after the entire image |
michael@0 | 97 | // has been loaded. |
michael@0 | 98 | |
michael@0 | 99 | // A map of imgIRequests to the nsIFrames that are using them. |
michael@0 | 100 | RequestToFrameMap mRequestToFrameMap; |
michael@0 | 101 | |
michael@0 | 102 | // A map of nsIFrames to the imgIRequests they use. |
michael@0 | 103 | FrameToRequestMap mFrameToRequestMap; |
michael@0 | 104 | |
michael@0 | 105 | // A weak pointer to our document. Nulled out by DropDocumentReference. |
michael@0 | 106 | nsIDocument* mDocument; |
michael@0 | 107 | |
michael@0 | 108 | // The set of all nsCSSValue::Images (whether they're associated a frame or |
michael@0 | 109 | // not). We'll need this when we go away to remove any requests associated |
michael@0 | 110 | // with our document from those Images. |
michael@0 | 111 | ImageHashSet mImages; |
michael@0 | 112 | |
michael@0 | 113 | // Are we cloning? If so, ignore any notifications we get. |
michael@0 | 114 | bool mInClone; |
michael@0 | 115 | }; |
michael@0 | 116 | |
michael@0 | 117 | } // namespace css |
michael@0 | 118 | } // namespace mozilla |
michael@0 | 119 | |
michael@0 | 120 | #endif /* mozilla_css_ImageLoader_h___ */ |