1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 : #ifndef nsImageBoxFrame_h___
38 : #define nsImageBoxFrame_h___
39 :
40 : #include "nsLeafBoxFrame.h"
41 :
42 : #include "imgILoader.h"
43 : #include "imgIRequest.h"
44 : #include "imgIContainer.h"
45 : #include "nsStubImageDecoderObserver.h"
46 :
47 : class nsImageBoxFrame;
48 :
49 : class nsImageBoxListener : public nsStubImageDecoderObserver
50 : {
51 : public:
52 : nsImageBoxListener();
53 : virtual ~nsImageBoxListener();
54 :
55 : NS_DECL_ISUPPORTS
56 : // imgIDecoderObserver (override nsStubImageDecoderObserver)
57 : NS_IMETHOD OnStartContainer(imgIRequest *request, imgIContainer *image);
58 : NS_IMETHOD OnStopContainer(imgIRequest *request, imgIContainer *image);
59 : NS_IMETHOD OnStopDecode(imgIRequest *request, nsresult status,
60 : const PRUnichar *statusArg);
61 : NS_IMETHOD OnImageIsAnimated(imgIRequest* aRequest);
62 :
63 : // imgIContainerObserver (override nsStubImageDecoderObserver)
64 : NS_IMETHOD FrameChanged(imgIRequest *aRequest,
65 : imgIContainer *aContainer,
66 : const nsIntRect *aDirtyRect);
67 :
68 0 : void SetFrame(nsImageBoxFrame *frame) { mFrame = frame; }
69 :
70 : private:
71 : nsImageBoxFrame *mFrame;
72 : };
73 :
74 : class nsImageBoxFrame : public nsLeafBoxFrame
75 : {
76 : public:
77 : NS_DECL_FRAMEARENA_HELPERS
78 :
79 : // nsIBox
80 : virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState);
81 : virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState);
82 : virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState);
83 : virtual void MarkIntrinsicWidthsDirty();
84 :
85 : friend nsIFrame* NS_NewImageBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
86 :
87 : // nsIBox frame interface
88 :
89 : NS_IMETHOD Init(nsIContent* aContent,
90 : nsIFrame* aParent,
91 : nsIFrame* asPrevInFlow);
92 :
93 : NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
94 : nsIAtom* aAttribute,
95 : PRInt32 aModType);
96 :
97 : virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
98 :
99 : virtual void DestroyFrom(nsIFrame* aDestructRoot);
100 :
101 : virtual nsIAtom* GetType() const;
102 : #ifdef DEBUG
103 : NS_IMETHOD GetFrameName(nsAString& aResult) const;
104 : #endif
105 :
106 : /**
107 : * Update mUseSrcAttr from appropriate content attributes or from
108 : * style, throw away the current image, and load the appropriate
109 : * image.
110 : * */
111 : void UpdateImage();
112 :
113 : /**
114 : * Update mLoadFlags from content attributes. Does not attempt to reload the
115 : * image using the new load flags.
116 : */
117 : void UpdateLoadFlags();
118 :
119 : NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
120 : const nsRect& aDirtyRect,
121 : const nsDisplayListSet& aLists);
122 :
123 : NS_IMETHOD OnStartContainer(imgIRequest *request, imgIContainer *image);
124 : NS_IMETHOD OnStopContainer(imgIRequest *request, imgIContainer *image);
125 : NS_IMETHOD OnStopDecode(imgIRequest *request,
126 : nsresult status,
127 : const PRUnichar *statusArg);
128 : NS_IMETHOD OnImageIsAnimated(imgIRequest* aRequest);
129 :
130 : NS_IMETHOD FrameChanged(imgIRequest *aRequest,
131 : imgIContainer *aContainer,
132 : const nsIntRect *aDirtyRect);
133 :
134 : virtual ~nsImageBoxFrame();
135 :
136 : void PaintImage(nsRenderingContext& aRenderingContext,
137 : const nsRect& aDirtyRect,
138 : nsPoint aPt, PRUint32 aFlags);
139 :
140 : protected:
141 : nsImageBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext);
142 :
143 : virtual void GetImageSize();
144 :
145 : private:
146 :
147 : nsRect mSubRect; ///< If set, indicates that only the portion of the image specified by the rect should be used.
148 : nsSize mIntrinsicSize;
149 : nsSize mImageSize;
150 :
151 : // Boolean variable to determine if the current image request has been
152 : // registered with the refresh driver.
153 : bool mRequestRegistered;
154 :
155 : nsCOMPtr<imgIRequest> mImageRequest;
156 : nsCOMPtr<imgIDecoderObserver> mListener;
157 :
158 : PRInt32 mLoadFlags;
159 :
160 : bool mUseSrcAttr; ///< Whether or not the image src comes from an attribute.
161 : bool mSuppressStyleCheck;
162 : }; // class nsImageBoxFrame
163 :
164 : #endif /* nsImageBoxFrame_h___ */
|