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/. */
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.
14 #ifndef nsBoxFrame_h___
15 #define nsBoxFrame_h___
17 #include "mozilla/Attributes.h"
19 #include "nsContainerFrame.h"
20 #include "nsBoxLayout.h"
22 class nsBoxLayoutState
;
30 nsIFrame
* NS_NewBoxFrame(nsIPresShell
* aPresShell
,
31 nsStyleContext
* aContext
,
33 nsBoxLayout
* aLayoutManager
);
34 nsIFrame
* NS_NewBoxFrame(nsIPresShell
* aPresShell
,
35 nsStyleContext
* aContext
);
37 class nsBoxFrame
: public nsContainerFrame
40 typedef mozilla::gfx::DrawTarget DrawTarget
;
43 NS_DECL_FRAMEARENA_HELPERS
45 NS_DECL_QUERYFRAME_TARGET(nsBoxFrame
)
49 friend nsIFrame
* NS_NewBoxFrame(nsIPresShell
* aPresShell
,
50 nsStyleContext
* aContext
,
52 nsBoxLayout
* aLayoutManager
);
53 friend nsIFrame
* NS_NewBoxFrame(nsIPresShell
* aPresShell
,
54 nsStyleContext
* aContext
);
56 // gets the rect inside our border and debug border. If you wish to paint inside a box
57 // call this method to get the rect so you don't draw on the debug border or outer border.
59 virtual void SetLayoutManager(nsBoxLayout
* aLayout
) MOZ_OVERRIDE
{ mLayoutManager
= aLayout
; }
60 virtual nsBoxLayout
* GetLayoutManager() MOZ_OVERRIDE
{ return mLayoutManager
; }
62 virtual nsresult
RelayoutChildAtOrdinal(nsBoxLayoutState
& aState
, nsIFrame
* aChild
) MOZ_OVERRIDE
;
64 virtual nsSize
GetPrefSize(nsBoxLayoutState
& aBoxLayoutState
) MOZ_OVERRIDE
;
65 virtual nsSize
GetMinSize(nsBoxLayoutState
& aBoxLayoutState
) MOZ_OVERRIDE
;
66 virtual nsSize
GetMaxSize(nsBoxLayoutState
& aBoxLayoutState
) MOZ_OVERRIDE
;
67 virtual nscoord
GetFlex(nsBoxLayoutState
& aBoxLayoutState
) MOZ_OVERRIDE
;
68 virtual nscoord
GetBoxAscent(nsBoxLayoutState
& aBoxLayoutState
) MOZ_OVERRIDE
;
70 virtual nsresult
SetDebug(nsBoxLayoutState
& aBoxLayoutState
, bool aDebug
) MOZ_OVERRIDE
;
71 virtual nsresult
GetDebug(bool& aDebug
) MOZ_OVERRIDE
;
73 virtual Valignment
GetVAlign() const MOZ_OVERRIDE
{ return mValign
; }
74 virtual Halignment
GetHAlign() const MOZ_OVERRIDE
{ return mHalign
; }
75 NS_IMETHOD
DoLayout(nsBoxLayoutState
& aBoxLayoutState
) MOZ_OVERRIDE
;
77 virtual bool ComputesOwnOverflowArea() MOZ_OVERRIDE
{ return false; }
79 // ----- child and sibling operations ---
81 // ----- public methods -------
83 virtual void Init(nsIContent
* aContent
,
84 nsContainerFrame
* aParent
,
85 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
88 virtual nsresult
AttributeChanged(int32_t aNameSpaceID
,
90 int32_t aModType
) MOZ_OVERRIDE
;
92 virtual void MarkIntrinsicISizesDirty() MOZ_OVERRIDE
;
93 virtual nscoord
GetMinISize(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
94 virtual nscoord
GetPrefISize(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
96 virtual void Reflow(nsPresContext
* aPresContext
,
97 nsHTMLReflowMetrics
& aDesiredSize
,
98 const nsHTMLReflowState
& aReflowState
,
99 nsReflowStatus
& aStatus
) MOZ_OVERRIDE
;
101 virtual void SetInitialChildList(ChildListID aListID
,
102 nsFrameList
& aChildList
) MOZ_OVERRIDE
;
103 virtual void AppendFrames(ChildListID aListID
,
104 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
105 virtual void InsertFrames(ChildListID aListID
,
106 nsIFrame
* aPrevFrame
,
107 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
108 virtual void RemoveFrame(ChildListID aListID
,
109 nsIFrame
* aOldFrame
) MOZ_OVERRIDE
;
111 virtual nsContainerFrame
* GetContentInsertionFrame() MOZ_OVERRIDE
;
113 virtual void DidSetStyleContext(nsStyleContext
* aOldStyleContext
) MOZ_OVERRIDE
;
115 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
117 virtual bool IsFrameOfType(uint32_t aFlags
) const MOZ_OVERRIDE
119 // record that children that are ignorable whitespace should be excluded
120 // (When content was loaded via the XUL content sink, it's already
121 // been excluded, but we need this for when the XUL namespace is used
122 // in other MIME types or when the XUL CSS display types are used with
123 // non-XUL elements.)
125 // This is bogus, but it's what we've always done.
126 // (Given that we're replaced, we need to say we're a replaced element
127 // that contains a block so nsHTMLReflowState doesn't tell us to be
128 // NS_INTRINSICSIZE wide.)
129 return nsContainerFrame::IsFrameOfType(aFlags
&
130 ~(nsIFrame::eReplaced
| nsIFrame::eReplacedContainsBlock
| eXULBox
|
131 nsIFrame::eExcludesIgnorableWhitespace
));
134 #ifdef DEBUG_FRAME_DUMP
135 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
;
138 virtual void DidReflow(nsPresContext
* aPresContext
,
139 const nsHTMLReflowState
* aReflowState
,
140 nsDidReflowStatus aStatus
) MOZ_OVERRIDE
;
142 virtual bool HonorPrintBackgroundSettings() MOZ_OVERRIDE
;
144 virtual ~nsBoxFrame();
146 explicit nsBoxFrame(nsStyleContext
* aContext
, bool aIsRoot
= false, nsBoxLayout
* aLayoutManager
= nullptr);
148 // virtual so nsStackFrame, nsButtonBoxFrame, nsSliderFrame and nsMenuFrame
150 virtual void BuildDisplayListForChildren(nsDisplayListBuilder
* aBuilder
,
151 const nsRect
& aDirtyRect
,
152 const nsDisplayListSet
& aLists
);
154 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
155 const nsRect
& aDirtyRect
,
156 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
159 virtual void SetDebugOnChildList(nsBoxLayoutState
& aState
, nsIFrame
* aChild
, bool aDebug
);
160 nsresult
DisplayDebugInfoFor(nsIFrame
* aBox
,
164 static nsresult
LayoutChildAt(nsBoxLayoutState
& aState
, nsIFrame
* aBox
, const nsRect
& aRect
);
167 * Utility method to redirect events on descendants to this frame.
168 * Supports 'allowevents' attribute on descendant elements to allow those
169 * elements and their descendants to receive events.
171 void WrapListsInRedirector(nsDisplayListBuilder
* aBuilder
,
172 const nsDisplayListSet
& aIn
,
173 const nsDisplayListSet
& aOut
);
176 * This defaults to true, but some box frames (nsListBoxBodyFrame for
177 * example) don't support ordinals in their children.
179 virtual bool SupportsOrdinalsInChildren();
183 virtual void GetBoxName(nsAutoString
& aName
) MOZ_OVERRIDE
;
184 void PaintXULDebugBackground(nsRenderingContext
& aRenderingContext
,
186 void PaintXULDebugOverlay(DrawTarget
& aRenderingContext
,
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
);
197 virtual void DestroyFrom(nsIFrame
* aDestructRoot
) MOZ_OVERRIDE
;
205 nsCOMPtr
<nsBoxLayout
> mLayoutManager
;
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
, nsIntPoint
& aPoint
);
215 void RegUnregAccessKey(bool aDoReg
);
217 void CheckBoxOrder();
222 nsresult
SetDebug(nsPresContext
* aPresContext
, bool aDebug
);
223 bool GetInitialDebug(bool& aDebug
);
224 void GetDebugPref(nsPresContext
* aPresContext
);
226 void GetDebugBorder(nsMargin
& aInset
);
227 void GetDebugPadding(nsMargin
& aInset
);
228 void GetDebugMargin(nsMargin
& aInset
);
230 nsresult
GetFrameSizeWithMargin(nsIFrame
* aBox
, nsSize
& aSize
);
232 void PixelMarginToTwips(nsPresContext
* aPresContext
, nsMargin
& aMarginPixels
);
234 void GetValue(nsPresContext
* aPresContext
, const nsSize
& a
, const nsSize
& b
, char* value
);
235 void GetValue(nsPresContext
* aPresContext
, int32_t a
, int32_t b
, char* value
);
236 void DrawSpacer(nsPresContext
* aPresContext
, DrawTarget
& aDrawTarget
, bool aHorizontal
, int32_t flex
, nscoord x
, nscoord y
, nscoord size
, nscoord spacerSize
);
237 void DrawLine(DrawTarget
& aDrawTarget
, bool aHorizontal
, nscoord x1
, nscoord y1
, nscoord x2
, nscoord y2
);
238 void FillRect(DrawTarget
& aDrawTarget
, bool aHorizontal
, nscoord x
, nscoord y
, nscoord width
, nscoord height
);
240 virtual void UpdateMouseThrough();
242 void CacheAttributes();
244 // instance variables.
250 static nsIFrame
* mDebugChild
;
253 }; // class nsBoxFrame