/src/mozilla-central/layout/xul/nsImageBoxFrame.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | #ifndef nsImageBoxFrame_h___ |
7 | | #define nsImageBoxFrame_h___ |
8 | | |
9 | | #include "mozilla/Attributes.h" |
10 | | #include "nsLeafBoxFrame.h" |
11 | | |
12 | | #include "imgILoader.h" |
13 | | #include "imgIRequest.h" |
14 | | #include "imgIContainer.h" |
15 | | |
16 | | class imgRequestProxy; |
17 | | class nsImageBoxFrame; |
18 | | |
19 | | class nsDisplayXULImage; |
20 | | |
21 | | class nsImageBoxListener final : public imgINotificationObserver |
22 | | { |
23 | | public: |
24 | | explicit nsImageBoxListener(nsImageBoxFrame *frame); |
25 | | |
26 | | NS_DECL_ISUPPORTS |
27 | | NS_DECL_IMGINOTIFICATIONOBSERVER |
28 | | |
29 | 0 | void ClearFrame() { mFrame = nullptr; } |
30 | | |
31 | | private: |
32 | | virtual ~nsImageBoxListener(); |
33 | | |
34 | | nsImageBoxFrame *mFrame; |
35 | | }; |
36 | | |
37 | | class nsImageBoxFrame final : public nsLeafBoxFrame |
38 | | { |
39 | | public: |
40 | | typedef mozilla::image::ImgDrawResult ImgDrawResult; |
41 | | typedef mozilla::layers::ImageContainer ImageContainer; |
42 | | typedef mozilla::layers::LayerManager LayerManager; |
43 | | |
44 | | friend class nsDisplayXULImage; |
45 | | NS_DECL_FRAMEARENA_HELPERS(nsImageBoxFrame) |
46 | | |
47 | | virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; |
48 | | virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; |
49 | | virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override; |
50 | | virtual void MarkIntrinsicISizesDirty() override; |
51 | | |
52 | | nsresult Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData); |
53 | | |
54 | | friend nsIFrame* NS_NewImageBoxFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle); |
55 | | |
56 | | virtual void Init(nsIContent* aContent, |
57 | | nsContainerFrame* aParent, |
58 | | nsIFrame* asPrevInFlow) override; |
59 | | |
60 | | virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
61 | | nsAtom* aAttribute, |
62 | | int32_t aModType) override; |
63 | | |
64 | | virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override; |
65 | | |
66 | | virtual void DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) override; |
67 | | |
68 | | #ifdef DEBUG_FRAME_DUMP |
69 | | virtual nsresult GetFrameName(nsAString& aResult) const override; |
70 | | #endif |
71 | | |
72 | | /** |
73 | | * Update mUseSrcAttr from appropriate content attributes or from |
74 | | * style, throw away the current image, and load the appropriate |
75 | | * image. |
76 | | * */ |
77 | | void UpdateImage(); |
78 | | |
79 | | /** |
80 | | * Update mLoadFlags from content attributes. Does not attempt to reload the |
81 | | * image using the new load flags. |
82 | | */ |
83 | | void UpdateLoadFlags(); |
84 | | |
85 | | virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
86 | | const nsDisplayListSet& aLists) override; |
87 | | |
88 | | virtual ~nsImageBoxFrame(); |
89 | | |
90 | | already_AddRefed<imgIContainer> GetImageContainerForPainting(const nsPoint& aPt, |
91 | | ImgDrawResult& aDrawResult, |
92 | | Maybe<nsPoint>& aAnchorPoint, |
93 | | nsRect& aDest); |
94 | | |
95 | | ImgDrawResult PaintImage(gfxContext& aRenderingContext, |
96 | | const nsRect& aDirtyRect, |
97 | | nsPoint aPt, uint32_t aFlags); |
98 | | |
99 | | ImgDrawResult CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, |
100 | | mozilla::wr::IpcResourceUpdateQueue& aResources, |
101 | | const mozilla::layers::StackingContextHelper& aSc, |
102 | | mozilla::layers::WebRenderLayerManager* aManager, |
103 | | nsDisplayItem* aItem, |
104 | | nsPoint aPt, |
105 | | uint32_t aFlags); |
106 | | |
107 | | bool CanOptimizeToImageLayer(); |
108 | | |
109 | | nsRect GetDestRect(const nsPoint& aOffset, Maybe<nsPoint>& aAnchorPoint); |
110 | | |
111 | | protected: |
112 | | explicit nsImageBoxFrame(ComputedStyle* aStyle); |
113 | | |
114 | | virtual void GetImageSize(); |
115 | | |
116 | | private: |
117 | | nsresult OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage); |
118 | | nsresult OnDecodeComplete(imgIRequest* aRequest); |
119 | | nsresult OnLoadComplete(imgIRequest* aRequest, nsresult aStatus); |
120 | | nsresult OnImageIsAnimated(imgIRequest* aRequest); |
121 | | nsresult OnFrameUpdate(imgIRequest* aRequest); |
122 | | |
123 | | nsRect mSubRect; ///< If set, indicates that only the portion of the image specified by the rect should be used. |
124 | | nsSize mIntrinsicSize; |
125 | | nsSize mImageSize; |
126 | | |
127 | | RefPtr<imgRequestProxy> mImageRequest; |
128 | | nsCOMPtr<imgINotificationObserver> mListener; |
129 | | |
130 | | int32_t mLoadFlags; |
131 | | |
132 | | // Boolean variable to determine if the current image request has been |
133 | | // registered with the refresh driver. |
134 | | bool mRequestRegistered; |
135 | | |
136 | | bool mUseSrcAttr; ///< Whether or not the image src comes from an attribute. |
137 | | bool mSuppressStyleCheck; |
138 | | }; // class nsImageBoxFrame |
139 | | |
140 | | class nsDisplayXULImage final : public nsDisplayImageContainer |
141 | | { |
142 | | public: |
143 | | nsDisplayXULImage(nsDisplayListBuilder* aBuilder, |
144 | | nsImageBoxFrame* aFrame) : |
145 | 0 | nsDisplayImageContainer(aBuilder, aFrame) { |
146 | 0 | MOZ_COUNT_CTOR(nsDisplayXULImage); |
147 | 0 | } |
148 | | #ifdef NS_BUILD_REFCNT_LOGGING |
149 | | virtual ~nsDisplayXULImage() { |
150 | | MOZ_COUNT_DTOR(nsDisplayXULImage); |
151 | | } |
152 | | #endif |
153 | | |
154 | | virtual bool CanOptimizeToImageLayer(LayerManager* aManager, |
155 | | nsDisplayListBuilder* aBuilder) override; |
156 | | virtual already_AddRefed<imgIContainer> GetImage() override; |
157 | | virtual nsRect GetDestRect() const override; |
158 | | virtual void UpdateDrawResult(mozilla::image::ImgDrawResult aResult) override |
159 | 0 | { |
160 | 0 | nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, aResult); |
161 | 0 | } |
162 | | virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, |
163 | | bool* aSnap) const override |
164 | 0 | { |
165 | 0 | *aSnap = true; |
166 | 0 | return nsRect(ToReferenceFrame(), Frame()->GetSize()); |
167 | 0 | } |
168 | | virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override; |
169 | | virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder, |
170 | | const nsDisplayItemGeometry* aGeometry, |
171 | | nsRegion* aInvalidRegion) const override; |
172 | | // Doesn't handle HitTest because nsLeafBoxFrame already creates an |
173 | | // event receiver for us |
174 | | virtual void Paint(nsDisplayListBuilder* aBuilder, |
175 | | gfxContext* aCtx) override; |
176 | | |
177 | | virtual bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder, |
178 | | mozilla::wr::IpcResourceUpdateQueue& aResources, |
179 | | const StackingContextHelper& aSc, |
180 | | mozilla::layers::WebRenderLayerManager* aManager, |
181 | | nsDisplayListBuilder* aDisplayListBuilder) override; |
182 | | |
183 | | NS_DISPLAY_DECL_NAME("XULImage", TYPE_XUL_IMAGE) |
184 | | }; |
185 | | |
186 | | #endif /* nsImageBoxFrame_h___ */ |