|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 #ifndef nsImageBoxFrame_h___ |
|
6 #define nsImageBoxFrame_h___ |
|
7 |
|
8 #include "mozilla/Attributes.h" |
|
9 #include "nsLeafBoxFrame.h" |
|
10 |
|
11 #include "imgILoader.h" |
|
12 #include "imgIRequest.h" |
|
13 #include "imgIContainer.h" |
|
14 #include "imgINotificationObserver.h" |
|
15 #include "imgIOnloadBlocker.h" |
|
16 |
|
17 class imgRequestProxy; |
|
18 class nsImageBoxFrame; |
|
19 |
|
20 class nsDisplayXULImage; |
|
21 |
|
22 class nsImageBoxListener : public imgINotificationObserver, |
|
23 public imgIOnloadBlocker |
|
24 { |
|
25 public: |
|
26 nsImageBoxListener(); |
|
27 virtual ~nsImageBoxListener(); |
|
28 |
|
29 NS_DECL_ISUPPORTS |
|
30 NS_DECL_IMGINOTIFICATIONOBSERVER |
|
31 NS_DECL_IMGIONLOADBLOCKER |
|
32 |
|
33 void SetFrame(nsImageBoxFrame *frame) { mFrame = frame; } |
|
34 |
|
35 private: |
|
36 nsImageBoxFrame *mFrame; |
|
37 }; |
|
38 |
|
39 class nsImageBoxFrame : public nsLeafBoxFrame |
|
40 { |
|
41 public: |
|
42 typedef mozilla::layers::LayerManager LayerManager; |
|
43 |
|
44 friend class nsDisplayXULImage; |
|
45 NS_DECL_FRAMEARENA_HELPERS |
|
46 |
|
47 virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
48 virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
49 virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
50 virtual void MarkIntrinsicWidthsDirty() MOZ_OVERRIDE; |
|
51 |
|
52 nsresult Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData); |
|
53 |
|
54 friend nsIFrame* NS_NewImageBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
55 |
|
56 virtual void Init(nsIContent* aContent, |
|
57 nsIFrame* aParent, |
|
58 nsIFrame* asPrevInFlow) MOZ_OVERRIDE; |
|
59 |
|
60 virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
|
61 nsIAtom* aAttribute, |
|
62 int32_t aModType) MOZ_OVERRIDE; |
|
63 |
|
64 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE; |
|
65 |
|
66 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
|
67 |
|
68 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
69 #ifdef DEBUG_FRAME_DUMP |
|
70 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; |
|
71 #endif |
|
72 |
|
73 /** |
|
74 * Update mUseSrcAttr from appropriate content attributes or from |
|
75 * style, throw away the current image, and load the appropriate |
|
76 * image. |
|
77 * */ |
|
78 void UpdateImage(); |
|
79 |
|
80 /** |
|
81 * Update mLoadFlags from content attributes. Does not attempt to reload the |
|
82 * image using the new load flags. |
|
83 */ |
|
84 void UpdateLoadFlags(); |
|
85 |
|
86 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
|
87 const nsRect& aDirtyRect, |
|
88 const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
|
89 |
|
90 virtual ~nsImageBoxFrame(); |
|
91 |
|
92 void PaintImage(nsRenderingContext& aRenderingContext, |
|
93 const nsRect& aDirtyRect, |
|
94 nsPoint aPt, uint32_t aFlags); |
|
95 |
|
96 already_AddRefed<mozilla::layers::ImageContainer> GetContainer(LayerManager* aManager); |
|
97 protected: |
|
98 nsImageBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext); |
|
99 |
|
100 virtual void GetImageSize(); |
|
101 |
|
102 private: |
|
103 nsresult OnStartContainer(imgIRequest *request, imgIContainer *image); |
|
104 nsresult OnStopDecode(imgIRequest *request); |
|
105 nsresult OnStopRequest(imgIRequest *request, nsresult status); |
|
106 nsresult OnImageIsAnimated(imgIRequest* aRequest); |
|
107 nsresult FrameChanged(imgIRequest *aRequest); |
|
108 |
|
109 nsRect mSubRect; ///< If set, indicates that only the portion of the image specified by the rect should be used. |
|
110 nsSize mIntrinsicSize; |
|
111 nsSize mImageSize; |
|
112 |
|
113 // Boolean variable to determine if the current image request has been |
|
114 // registered with the refresh driver. |
|
115 bool mRequestRegistered; |
|
116 |
|
117 nsRefPtr<imgRequestProxy> mImageRequest; |
|
118 nsCOMPtr<imgINotificationObserver> mListener; |
|
119 |
|
120 int32_t mLoadFlags; |
|
121 |
|
122 bool mUseSrcAttr; ///< Whether or not the image src comes from an attribute. |
|
123 bool mSuppressStyleCheck; |
|
124 bool mFireEventOnDecode; |
|
125 }; // class nsImageBoxFrame |
|
126 |
|
127 class nsDisplayXULImage : public nsDisplayImageContainer { |
|
128 public: |
|
129 nsDisplayXULImage(nsDisplayListBuilder* aBuilder, |
|
130 nsImageBoxFrame* aFrame) : |
|
131 nsDisplayImageContainer(aBuilder, aFrame) { |
|
132 MOZ_COUNT_CTOR(nsDisplayXULImage); |
|
133 } |
|
134 #ifdef NS_BUILD_REFCNT_LOGGING |
|
135 virtual ~nsDisplayXULImage() { |
|
136 MOZ_COUNT_DTOR(nsDisplayXULImage); |
|
137 } |
|
138 #endif |
|
139 |
|
140 virtual already_AddRefed<ImageContainer> GetContainer(LayerManager* aManager, |
|
141 nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE; |
|
142 virtual void ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset) MOZ_OVERRIDE; |
|
143 virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE |
|
144 { |
|
145 *aSnap = true; |
|
146 return nsRect(ToReferenceFrame(), Frame()->GetSize()); |
|
147 } |
|
148 virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder, |
|
149 const nsDisplayItemGeometry* aGeometry, |
|
150 nsRegion* aInvalidRegion) MOZ_OVERRIDE; |
|
151 // Doesn't handle HitTest because nsLeafBoxFrame already creates an |
|
152 // event receiver for us |
|
153 virtual void Paint(nsDisplayListBuilder* aBuilder, |
|
154 nsRenderingContext* aCtx) MOZ_OVERRIDE; |
|
155 NS_DISPLAY_DECL_NAME("XULImage", TYPE_XUL_IMAGE) |
|
156 }; |
|
157 |
|
158 #endif /* nsImageBoxFrame_h___ */ |