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 :
6 : /**
7 :
8 : Eric D Vaughan
9 : nsBoxFrame is a frame that can lay its children out either vertically or horizontally.
10 : It lays them out according to a min max or preferred size.
11 :
12 : **/
13 :
14 : #ifndef nsBoxFrame_h___
15 : #define nsBoxFrame_h___
16 :
17 : #include "mozilla/Attributes.h"
18 : #include "nsCOMPtr.h"
19 : #include "nsContainerFrame.h"
20 : #include "nsBoxLayout.h"
21 :
22 : class nsBoxLayoutState;
23 :
24 : namespace mozilla {
25 : namespace gfx {
26 : class DrawTarget;
27 : } // namespace gfx
28 : } // namespace mozilla
29 :
30 : nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
31 : nsStyleContext* aContext,
32 : bool aIsRoot,
33 : nsBoxLayout* aLayoutManager);
34 : nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
35 : nsStyleContext* aContext);
36 :
37 : class nsBoxFrame : public nsContainerFrame
38 : {
39 : protected:
40 : typedef mozilla::gfx::DrawTarget DrawTarget;
41 :
42 : public:
43 3629 : NS_DECL_FRAMEARENA_HELPERS(nsBoxFrame)
44 : #ifdef DEBUG
45 : NS_DECL_QUERYFRAME
46 : #endif
47 :
48 : friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
49 : nsStyleContext* aContext,
50 : bool aIsRoot,
51 : nsBoxLayout* aLayoutManager);
52 : friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
53 : nsStyleContext* aContext);
54 :
55 : // gets the rect inside our border and debug border. If you wish to paint inside a box
56 : // call this method to get the rect so you don't draw on the debug border or outer border.
57 :
58 312 : virtual void SetXULLayoutManager(nsBoxLayout* aLayout) override { mLayoutManager = aLayout; }
59 0 : virtual nsBoxLayout* GetXULLayoutManager() override { return mLayoutManager; }
60 :
61 : virtual nsresult XULRelayoutChildAtOrdinal(nsIFrame* aChild) override;
62 :
63 : virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override;
64 : virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override;
65 : virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override;
66 : virtual nscoord GetXULFlex() override;
67 : virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override;
68 : #ifdef DEBUG_LAYOUT
69 : virtual nsresult SetXULDebug(nsBoxLayoutState& aBoxLayoutState, bool aDebug) override;
70 : virtual nsresult GetXULDebug(bool& aDebug) override;
71 : #endif
72 994 : virtual Valignment GetXULVAlign() const override { return mValign; }
73 881 : virtual Halignment GetXULHAlign() const override { return mHalign; }
74 : NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override;
75 :
76 652 : virtual bool ComputesOwnOverflowArea() override { return false; }
77 :
78 : // ----- child and sibling operations ---
79 :
80 : // ----- public methods -------
81 :
82 : virtual void Init(nsIContent* aContent,
83 : nsContainerFrame* aParent,
84 : nsIFrame* aPrevInFlow) override;
85 :
86 :
87 : virtual nsresult AttributeChanged(int32_t aNameSpaceID,
88 : nsIAtom* aAttribute,
89 : int32_t aModType) override;
90 :
91 : virtual void MarkIntrinsicISizesDirty() override;
92 : virtual nscoord GetMinISize(gfxContext *aRenderingContext) override;
93 : virtual nscoord GetPrefISize(gfxContext *aRenderingContext) override;
94 :
95 : virtual void Reflow(nsPresContext* aPresContext,
96 : ReflowOutput& aDesiredSize,
97 : const ReflowInput& aReflowInput,
98 : nsReflowStatus& aStatus) override;
99 :
100 : virtual void SetInitialChildList(ChildListID aListID,
101 : nsFrameList& aChildList) override;
102 : virtual void AppendFrames(ChildListID aListID,
103 : nsFrameList& aFrameList) override;
104 : virtual void InsertFrames(ChildListID aListID,
105 : nsIFrame* aPrevFrame,
106 : nsFrameList& aFrameList) override;
107 : virtual void RemoveFrame(ChildListID aListID,
108 : nsIFrame* aOldFrame) override;
109 :
110 : virtual nsContainerFrame* GetContentInsertionFrame() override;
111 :
112 : virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) override;
113 :
114 22060 : virtual bool IsFrameOfType(uint32_t aFlags) const override
115 : {
116 : // record that children that are ignorable whitespace should be excluded
117 : // (When content was loaded via the XUL content sink, it's already
118 : // been excluded, but we need this for when the XUL namespace is used
119 : // in other MIME types or when the XUL CSS display types are used with
120 : // non-XUL elements.)
121 :
122 : // This is bogus, but it's what we've always done.
123 : // (Given that we're replaced, we need to say we're a replaced element
124 : // that contains a block so ReflowInput doesn't tell us to be
125 : // NS_INTRINSICSIZE wide.)
126 22060 : return nsContainerFrame::IsFrameOfType(aFlags &
127 : ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock | eXULBox |
128 22060 : nsIFrame::eExcludesIgnorableWhitespace));
129 : }
130 :
131 : #ifdef DEBUG_FRAME_DUMP
132 : virtual nsresult GetFrameName(nsAString& aResult) const override;
133 : #endif
134 :
135 : virtual void DidReflow(nsPresContext* aPresContext,
136 : const ReflowInput* aReflowInput,
137 : nsDidReflowStatus aStatus) override;
138 :
139 : virtual bool HonorPrintBackgroundSettings() override;
140 :
141 : // virtual so nsStackFrame, nsButtonBoxFrame, nsSliderFrame and nsMenuFrame
142 : // can override it
143 : virtual void BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
144 : const nsRect& aDirtyRect,
145 : const nsDisplayListSet& aLists);
146 :
147 : virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
148 : const nsRect& aDirtyRect,
149 : const nsDisplayListSet& aLists) override;
150 :
151 : #ifdef DEBUG_LAYOUT
152 : virtual void SetDebugOnChildList(nsBoxLayoutState& aState, nsIFrame* aChild, bool aDebug);
153 : nsresult DisplayDebugInfoFor(nsIFrame* aBox,
154 : nsPoint& aPoint);
155 : #endif
156 :
157 : static nsresult LayoutChildAt(nsBoxLayoutState& aState, nsIFrame* aBox, const nsRect& aRect);
158 :
159 : /**
160 : * Utility method to redirect events on descendants to this frame.
161 : * Supports 'allowevents' attribute on descendant elements to allow those
162 : * elements and their descendants to receive events.
163 : */
164 : void WrapListsInRedirector(nsDisplayListBuilder* aBuilder,
165 : const nsDisplayListSet& aIn,
166 : const nsDisplayListSet& aOut);
167 :
168 : /**
169 : * This defaults to true, but some box frames (nsListBoxBodyFrame for
170 : * example) don't support ordinals in their children.
171 : */
172 : virtual bool SupportsOrdinalsInChildren();
173 :
174 : private:
175 105 : explicit nsBoxFrame(nsStyleContext* aContext)
176 105 : : nsBoxFrame(aContext, kClassID, false, nullptr) {}
177 : protected:
178 : nsBoxFrame(nsStyleContext* aContext, ClassID aID, bool aIsRoot = false,
179 : nsBoxLayout* aLayoutManager = nullptr);
180 : virtual ~nsBoxFrame();
181 :
182 : #ifdef DEBUG_LAYOUT
183 : virtual void GetBoxName(nsAutoString& aName) override;
184 : void PaintXULDebugBackground(gfxContext& aRenderingContext,
185 : nsPoint aPt);
186 : void PaintXULDebugOverlay(DrawTarget& aRenderingContext,
187 : nsPoint aPt);
188 : #endif
189 :
190 : virtual bool GetInitialEqualSize(bool& aEqualSize);
191 : virtual void GetInitialOrientation(bool& aIsHorizontal);
192 : virtual void GetInitialDirection(bool& aIsNormal);
193 : virtual bool GetInitialHAlignment(Halignment& aHalign);
194 : virtual bool GetInitialVAlignment(Valignment& aValign);
195 : virtual bool GetInitialAutoStretch(bool& aStretch);
196 :
197 : virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
198 :
199 : nsSize mPrefSize;
200 : nsSize mMinSize;
201 : nsSize mMaxSize;
202 : nscoord mFlex;
203 : nscoord mAscent;
204 :
205 : nsCOMPtr<nsBoxLayout> mLayoutManager;
206 :
207 : // Get the point associated with this event. Returns true if a single valid
208 : // point was found. Otherwise false.
209 : bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent, nsPoint& aPoint);
210 : // Gets the event coordinates relative to the widget offset associated with
211 : // this frame. Return true if a single valid point was found.
212 : bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent,
213 : mozilla::LayoutDeviceIntPoint& aPoint);
214 :
215 : protected:
216 : void RegUnregAccessKey(bool aDoReg);
217 :
218 : void CheckBoxOrder();
219 :
220 : private:
221 :
222 : #ifdef DEBUG_LAYOUT
223 : nsresult SetXULDebug(nsPresContext* aPresContext, bool aDebug);
224 : bool GetInitialDebug(bool& aDebug);
225 : void GetDebugPref();
226 :
227 : void GetDebugBorder(nsMargin& aInset);
228 : void GetDebugPadding(nsMargin& aInset);
229 : void GetDebugMargin(nsMargin& aInset);
230 :
231 : nsresult GetFrameSizeWithMargin(nsIFrame* aBox, nsSize& aSize);
232 :
233 : void PixelMarginToTwips(nsMargin& aMarginPixels);
234 :
235 : void GetValue(nsPresContext* aPresContext, const nsSize& a, const nsSize& b, char* value);
236 : void GetValue(nsPresContext* aPresContext, int32_t a, int32_t b, char* value);
237 : void DrawSpacer(nsPresContext* aPresContext, DrawTarget& aDrawTarget, bool aHorizontal, int32_t flex, nscoord x, nscoord y, nscoord size, nscoord spacerSize);
238 : void DrawLine(DrawTarget& aDrawTarget, bool aHorizontal, nscoord x1, nscoord y1, nscoord x2, nscoord y2);
239 : void FillRect(DrawTarget& aDrawTarget, bool aHorizontal, nscoord x, nscoord y, nscoord width, nscoord height);
240 : #endif
241 : virtual void UpdateMouseThrough();
242 :
243 : void CacheAttributes();
244 :
245 : // instance variables.
246 : Halignment mHalign;
247 : Valignment mValign;
248 :
249 : #ifdef DEBUG_LAYOUT
250 : static bool gDebug;
251 : static nsIFrame* mDebugChild;
252 : #endif
253 :
254 : }; // class nsBoxFrame
255 :
256 : #endif
257 :
|