Bumping manifests a=b2g-bump
[gecko.git] / layout / xul / nsBoxFrame.h
blob1e249641c35878189547197ba8fbfcc9684917fa
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/. */
6 /**
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.
12 **/
14 #ifndef nsBoxFrame_h___
15 #define nsBoxFrame_h___
17 #include "mozilla/Attributes.h"
18 #include "nsCOMPtr.h"
19 #include "nsContainerFrame.h"
20 #include "nsBoxLayout.h"
22 class nsBoxLayoutState;
24 nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
25 nsStyleContext* aContext,
26 bool aIsRoot,
27 nsBoxLayout* aLayoutManager);
28 nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
29 nsStyleContext* aContext);
31 class nsBoxFrame : public nsContainerFrame
33 public:
34 NS_DECL_FRAMEARENA_HELPERS
35 #ifdef DEBUG
36 NS_DECL_QUERYFRAME_TARGET(nsBoxFrame)
37 NS_DECL_QUERYFRAME
38 #endif
40 friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
41 nsStyleContext* aContext,
42 bool aIsRoot,
43 nsBoxLayout* aLayoutManager);
44 friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
45 nsStyleContext* aContext);
47 // gets the rect inside our border and debug border. If you wish to paint inside a box
48 // call this method to get the rect so you don't draw on the debug border or outer border.
50 virtual void SetLayoutManager(nsBoxLayout* aLayout) MOZ_OVERRIDE { mLayoutManager = aLayout; }
51 virtual nsBoxLayout* GetLayoutManager() MOZ_OVERRIDE { return mLayoutManager; }
53 virtual nsresult RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIFrame* aChild) MOZ_OVERRIDE;
55 virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
56 virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
57 virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
58 virtual nscoord GetFlex(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
59 virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
60 #ifdef DEBUG_LAYOUT
61 virtual nsresult SetDebug(nsBoxLayoutState& aBoxLayoutState, bool aDebug) MOZ_OVERRIDE;
62 virtual nsresult GetDebug(bool& aDebug) MOZ_OVERRIDE;
63 #endif
64 virtual Valignment GetVAlign() const MOZ_OVERRIDE { return mValign; }
65 virtual Halignment GetHAlign() const MOZ_OVERRIDE { return mHalign; }
66 NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
68 virtual bool ComputesOwnOverflowArea() MOZ_OVERRIDE { return false; }
70 // ----- child and sibling operations ---
72 // ----- public methods -------
74 virtual void Init(nsIContent* aContent,
75 nsContainerFrame* aParent,
76 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
79 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
80 nsIAtom* aAttribute,
81 int32_t aModType) MOZ_OVERRIDE;
83 virtual void MarkIntrinsicISizesDirty() MOZ_OVERRIDE;
84 virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
85 virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
87 virtual void Reflow(nsPresContext* aPresContext,
88 nsHTMLReflowMetrics& aDesiredSize,
89 const nsHTMLReflowState& aReflowState,
90 nsReflowStatus& aStatus) MOZ_OVERRIDE;
92 virtual void SetInitialChildList(ChildListID aListID,
93 nsFrameList& aChildList) MOZ_OVERRIDE;
94 virtual void AppendFrames(ChildListID aListID,
95 nsFrameList& aFrameList) MOZ_OVERRIDE;
96 virtual void InsertFrames(ChildListID aListID,
97 nsIFrame* aPrevFrame,
98 nsFrameList& aFrameList) MOZ_OVERRIDE;
99 virtual void RemoveFrame(ChildListID aListID,
100 nsIFrame* aOldFrame) MOZ_OVERRIDE;
102 virtual nsContainerFrame* GetContentInsertionFrame() MOZ_OVERRIDE;
104 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
106 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
108 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
110 // record that children that are ignorable whitespace should be excluded
111 // (When content was loaded via the XUL content sink, it's already
112 // been excluded, but we need this for when the XUL namespace is used
113 // in other MIME types or when the XUL CSS display types are used with
114 // non-XUL elements.)
116 // This is bogus, but it's what we've always done.
117 // (Given that we're replaced, we need to say we're a replaced element
118 // that contains a block so nsHTMLReflowState doesn't tell us to be
119 // NS_INTRINSICSIZE wide.)
120 return nsContainerFrame::IsFrameOfType(aFlags &
121 ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock | eXULBox |
122 nsIFrame::eExcludesIgnorableWhitespace));
125 #ifdef DEBUG_FRAME_DUMP
126 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
127 #endif
129 virtual void DidReflow(nsPresContext* aPresContext,
130 const nsHTMLReflowState* aReflowState,
131 nsDidReflowStatus aStatus) MOZ_OVERRIDE;
133 virtual bool HonorPrintBackgroundSettings() MOZ_OVERRIDE;
135 virtual ~nsBoxFrame();
137 nsBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, bool aIsRoot = false, nsBoxLayout* aLayoutManager = nullptr);
139 // virtual so nsStackFrame, nsButtonBoxFrame, nsSliderFrame and nsMenuFrame
140 // can override it
141 virtual void BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
142 const nsRect& aDirtyRect,
143 const nsDisplayListSet& aLists);
145 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
146 const nsRect& aDirtyRect,
147 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
149 #ifdef DEBUG_LAYOUT
150 virtual void SetDebugOnChildList(nsBoxLayoutState& aState, nsIFrame* aChild, bool aDebug);
151 nsresult DisplayDebugInfoFor(nsIFrame* aBox,
152 nsPoint& aPoint);
153 #endif
155 static nsresult LayoutChildAt(nsBoxLayoutState& aState, nsIFrame* aBox, const nsRect& aRect);
158 * Utility method to redirect events on descendants to this frame.
159 * Supports 'allowevents' attribute on descendant elements to allow those
160 * elements and their descendants to receive events.
162 void WrapListsInRedirector(nsDisplayListBuilder* aBuilder,
163 const nsDisplayListSet& aIn,
164 const nsDisplayListSet& aOut);
167 * This defaults to true, but some box frames (nsListBoxBodyFrame for
168 * example) don't support ordinals in their children.
170 virtual bool SupportsOrdinalsInChildren();
172 protected:
173 #ifdef DEBUG_LAYOUT
174 virtual void GetBoxName(nsAutoString& aName) MOZ_OVERRIDE;
175 void PaintXULDebugBackground(nsRenderingContext& aRenderingContext,
176 nsPoint aPt);
177 void PaintXULDebugOverlay(nsRenderingContext& aRenderingContext,
178 nsPoint aPt);
179 #endif
181 virtual bool GetInitialEqualSize(bool& aEqualSize);
182 virtual void GetInitialOrientation(bool& aIsHorizontal);
183 virtual void GetInitialDirection(bool& aIsNormal);
184 virtual bool GetInitialHAlignment(Halignment& aHalign);
185 virtual bool GetInitialVAlignment(Valignment& aValign);
186 virtual bool GetInitialAutoStretch(bool& aStretch);
188 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
190 nsSize mPrefSize;
191 nsSize mMinSize;
192 nsSize mMaxSize;
193 nscoord mFlex;
194 nscoord mAscent;
196 nsCOMPtr<nsBoxLayout> mLayoutManager;
198 // Get the point associated with this event. Returns true if a single valid
199 // point was found. Otherwise false.
200 bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent, nsPoint& aPoint);
201 // Gets the event coordinates relative to the widget offset associated with
202 // this frame. Return true if a single valid point was found.
203 bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent, nsIntPoint& aPoint);
205 protected:
206 void RegUnregAccessKey(bool aDoReg);
208 void CheckBoxOrder();
210 private:
212 #ifdef DEBUG_LAYOUT
213 nsresult SetDebug(nsPresContext* aPresContext, bool aDebug);
214 bool GetInitialDebug(bool& aDebug);
215 void GetDebugPref(nsPresContext* aPresContext);
217 void GetDebugBorder(nsMargin& aInset);
218 void GetDebugPadding(nsMargin& aInset);
219 void GetDebugMargin(nsMargin& aInset);
221 nsresult GetFrameSizeWithMargin(nsIFrame* aBox, nsSize& aSize);
223 void PixelMarginToTwips(nsPresContext* aPresContext, nsMargin& aMarginPixels);
225 void GetValue(nsPresContext* aPresContext, const nsSize& a, const nsSize& b, char* value);
226 void GetValue(nsPresContext* aPresContext, int32_t a, int32_t b, char* value);
227 void DrawSpacer(nsPresContext* aPresContext, nsRenderingContext& aRenderingContext, bool aHorizontal, int32_t flex, nscoord x, nscoord y, nscoord size, nscoord spacerSize);
228 void DrawLine(nsRenderingContext& aRenderingContext, bool aHorizontal, nscoord x1, nscoord y1, nscoord x2, nscoord y2);
229 void FillRect(nsRenderingContext& aRenderingContext, bool aHorizontal, nscoord x, nscoord y, nscoord width, nscoord height);
230 #endif
231 virtual void UpdateMouseThrough();
233 void CacheAttributes();
235 // instance variables.
236 Halignment mHalign;
237 Valignment mValign;
239 #ifdef DEBUG_LAYOUT
240 static bool gDebug;
241 static nsIFrame* mDebugChild;
242 #endif
244 }; // class nsBoxFrame
246 #endif