Line data Source code
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 final : public imgINotificationObserver,
23 : public imgIOnloadBlocker
24 : {
25 : public:
26 : nsImageBoxListener();
27 :
28 : NS_DECL_ISUPPORTS
29 : NS_DECL_IMGINOTIFICATIONOBSERVER
30 : NS_DECL_IMGIONLOADBLOCKER
31 :
32 92 : void SetFrame(nsImageBoxFrame *frame) { mFrame = frame; }
33 :
34 : private:
35 : virtual ~nsImageBoxListener();
36 :
37 : nsImageBoxFrame *mFrame;
38 : };
39 :
40 : class nsImageBoxFrame final : public nsLeafBoxFrame
41 : {
42 : public:
43 : typedef mozilla::image::DrawResult DrawResult;
44 : typedef mozilla::layers::ImageContainer ImageContainer;
45 : typedef mozilla::layers::LayerManager LayerManager;
46 :
47 : friend class nsDisplayXULImage;
48 323 : NS_DECL_FRAMEARENA_HELPERS(nsImageBoxFrame)
49 :
50 : virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override;
51 : virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override;
52 : virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override;
53 : virtual void MarkIntrinsicISizesDirty() override;
54 :
55 : nsresult Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData);
56 :
57 : friend nsIFrame* NS_NewImageBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
58 :
59 : virtual void Init(nsIContent* aContent,
60 : nsContainerFrame* aParent,
61 : nsIFrame* asPrevInFlow) override;
62 :
63 : virtual nsresult AttributeChanged(int32_t aNameSpaceID,
64 : nsIAtom* aAttribute,
65 : int32_t aModType) override;
66 :
67 : virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) override;
68 :
69 : virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
70 :
71 : #ifdef DEBUG_FRAME_DUMP
72 : virtual nsresult GetFrameName(nsAString& aResult) const override;
73 : #endif
74 :
75 : /**
76 : * Update mUseSrcAttr from appropriate content attributes or from
77 : * style, throw away the current image, and load the appropriate
78 : * image.
79 : * */
80 : void UpdateImage();
81 :
82 : /**
83 : * Update mLoadFlags from content attributes. Does not attempt to reload the
84 : * image using the new load flags.
85 : */
86 : void UpdateLoadFlags();
87 :
88 : virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
89 : const nsRect& aDirtyRect,
90 : const nsDisplayListSet& aLists) override;
91 :
92 : virtual ~nsImageBoxFrame();
93 :
94 : DrawResult PaintImage(gfxContext& aRenderingContext,
95 : const nsRect& aDirtyRect,
96 : nsPoint aPt, uint32_t aFlags);
97 :
98 : bool CanOptimizeToImageLayer();
99 :
100 : nsRect GetDestRect(const nsPoint& aOffset, Maybe<nsPoint>& aAnchorPoint);
101 :
102 : protected:
103 : explicit nsImageBoxFrame(nsStyleContext* aContext);
104 :
105 : virtual void GetImageSize();
106 :
107 : private:
108 : nsresult OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
109 : nsresult OnDecodeComplete(imgIRequest* aRequest);
110 : nsresult OnLoadComplete(imgIRequest* aRequest, nsresult aStatus);
111 : nsresult OnImageIsAnimated(imgIRequest* aRequest);
112 : nsresult OnFrameUpdate(imgIRequest* aRequest);
113 :
114 : nsRect mSubRect; ///< If set, indicates that only the portion of the image specified by the rect should be used.
115 : nsSize mIntrinsicSize;
116 : nsSize mImageSize;
117 :
118 : RefPtr<imgRequestProxy> mImageRequest;
119 : nsCOMPtr<imgINotificationObserver> mListener;
120 :
121 : int32_t mLoadFlags;
122 :
123 : // Boolean variable to determine if the current image request has been
124 : // registered with the refresh driver.
125 : bool mRequestRegistered;
126 :
127 : bool mUseSrcAttr; ///< Whether or not the image src comes from an attribute.
128 : bool mSuppressStyleCheck;
129 : }; // class nsImageBoxFrame
130 :
131 : class nsDisplayXULImage final : public nsDisplayImageContainer
132 : {
133 : public:
134 341 : nsDisplayXULImage(nsDisplayListBuilder* aBuilder,
135 341 : nsImageBoxFrame* aFrame) :
136 341 : nsDisplayImageContainer(aBuilder, aFrame) {
137 341 : MOZ_COUNT_CTOR(nsDisplayXULImage);
138 341 : }
139 : #ifdef NS_BUILD_REFCNT_LOGGING
140 682 : virtual ~nsDisplayXULImage() {
141 341 : MOZ_COUNT_DTOR(nsDisplayXULImage);
142 341 : }
143 : #endif
144 :
145 : virtual bool CanOptimizeToImageLayer(LayerManager* aManager,
146 : nsDisplayListBuilder* aBuilder) override;
147 : virtual already_AddRefed<imgIContainer> GetImage() override;
148 : virtual nsRect GetDestRect() override;
149 1413 : virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) override
150 : {
151 1413 : *aSnap = true;
152 1413 : return nsRect(ToReferenceFrame(), Frame()->GetSize());
153 : }
154 : virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override;
155 : virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
156 : const nsDisplayItemGeometry* aGeometry,
157 : nsRegion* aInvalidRegion) override;
158 : // Doesn't handle HitTest because nsLeafBoxFrame already creates an
159 : // event receiver for us
160 : virtual void Paint(nsDisplayListBuilder* aBuilder,
161 : gfxContext* aCtx) override;
162 2839 : NS_DISPLAY_DECL_NAME("XULImage", TYPE_XUL_IMAGE)
163 : };
164 :
165 : #endif /* nsImageBoxFrame_h___ */
|