Bug 1698786: part 2) Change some compile-time dependent `printf`s to `MOZ_LOG` in...
[gecko.git] / layout / xul / nsBoxFrame.h
blobf1875d9bad6cc0576474b5402ac37e427945f207
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /**
9 Eric D Vaughan
10 nsBoxFrame is a frame that can lay its children out either vertically or
11 horizontally. It lays them out according to a min max or preferred size.
13 **/
15 #ifndef nsBoxFrame_h___
16 #define nsBoxFrame_h___
18 #include "mozilla/Attributes.h"
19 #include "nsCOMPtr.h"
20 #include "nsContainerFrame.h"
21 #include "nsBoxLayout.h"
23 class nsBoxLayoutState;
25 namespace mozilla {
26 class PresShell;
27 namespace gfx {
28 class DrawTarget;
29 } // namespace gfx
30 } // namespace mozilla
32 nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell,
33 mozilla::ComputedStyle* aStyle, bool aIsRoot,
34 nsBoxLayout* aLayoutManager);
35 nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell,
36 mozilla::ComputedStyle* aStyle);
38 class nsBoxFrame : public nsContainerFrame {
39 protected:
40 typedef mozilla::gfx::DrawTarget DrawTarget;
42 public:
43 NS_DECL_FRAMEARENA_HELPERS(nsBoxFrame)
44 #ifdef DEBUG
45 NS_DECL_QUERYFRAME
46 #endif
48 friend nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell,
49 ComputedStyle* aStyle, bool aIsRoot,
50 nsBoxLayout* aLayoutManager);
51 friend nsIFrame* NS_NewBoxFrame(mozilla::PresShell* aPresShell,
52 ComputedStyle* aStyle);
54 // gets the rect inside our border and debug border. If you wish to paint
55 // inside a box call this method to get the rect so you don't draw on the
56 // debug border or outer border.
58 virtual void SetXULLayoutManager(nsBoxLayout* aLayout) override {
59 mLayoutManager = aLayout;
61 virtual nsBoxLayout* GetXULLayoutManager() override { return mLayoutManager; }
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 virtual Valignment GetXULVAlign() const override { return mValign; }
69 virtual Halignment GetXULHAlign() const override { return mHalign; }
70 NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override;
72 virtual bool XULComputesOwnOverflowArea() override { return false; }
74 // ----- child and sibling operations ---
76 // ----- public methods -------
78 virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
79 nsIFrame* aPrevInFlow) override;
81 virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
82 int32_t aModType) override;
84 virtual void MarkIntrinsicISizesDirty() override;
85 virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
86 virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;
88 virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
89 const ReflowInput& aReflowInput,
90 nsReflowStatus& aStatus) override;
92 virtual void SetInitialChildList(ChildListID aListID,
93 nsFrameList& aChildList) override;
94 virtual void AppendFrames(ChildListID aListID,
95 nsFrameList& aFrameList) override;
96 virtual void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
97 const nsLineList::iterator* aPrevFrameLine,
98 nsFrameList& aFrameList) override;
99 virtual void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
101 virtual nsContainerFrame* GetContentInsertionFrame() override;
103 virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
105 virtual bool IsFrameOfType(uint32_t aFlags) const override {
106 // record that children that are ignorable whitespace should be excluded
107 // (When content was loaded via the XUL content sink, it's already
108 // been excluded, but we need this for when the XUL namespace is used
109 // in other MIME types or when the XUL CSS display types are used with
110 // non-XUL elements.)
112 // This is bogus, but it's what we've always done.
113 // (Given that we're replaced, we need to say we're a replaced element
114 // that contains a block so ReflowInput doesn't tell us to be
115 // NS_UNCONSTRAINEDSIZE wide.)
116 return nsContainerFrame::IsFrameOfType(
117 aFlags &
118 ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock | eXULBox));
121 #ifdef DEBUG_FRAME_DUMP
122 virtual nsresult GetFrameName(nsAString& aResult) const override;
123 #endif
125 virtual void DidReflow(nsPresContext* aPresContext,
126 const ReflowInput* aReflowInput) override;
128 virtual bool HonorPrintBackgroundSettings() const override;
130 // virtual so nsStackFrame, nsButtonBoxFrame, nsSliderFrame and nsMenuFrame
131 // can override it
132 virtual void BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
133 const nsDisplayListSet& aLists);
135 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
136 const nsDisplayListSet& aLists) override;
138 static nsresult LayoutChildAt(nsBoxLayoutState& aState, nsIFrame* aBox,
139 const nsRect& aRect);
142 * Utility method to redirect events on descendants to this frame.
143 * Supports 'allowevents' attribute on descendant elements to allow those
144 * elements and their descendants to receive events.
146 void WrapListsInRedirector(nsDisplayListBuilder* aBuilder,
147 const nsDisplayListSet& aIn,
148 const nsDisplayListSet& aOut);
151 * Return our wrapper block, if any.
153 void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
155 private:
156 explicit nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
157 : nsBoxFrame(aStyle, aPresContext, kClassID, false, nullptr) {}
159 protected:
160 nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext, ClassID aID,
161 bool aIsRoot = false, nsBoxLayout* aLayoutManager = nullptr);
162 virtual ~nsBoxFrame();
164 virtual bool GetInitialEqualSize(bool& aEqualSize);
165 virtual void GetInitialOrientation(bool& aIsHorizontal);
166 virtual void GetInitialDirection(bool& aIsNormal);
167 virtual bool GetInitialHAlignment(Halignment& aHalign);
168 virtual bool GetInitialVAlignment(Valignment& aValign);
169 virtual bool GetInitialAutoStretch(bool& aStretch);
171 virtual void DestroyFrom(nsIFrame* aDestructRoot,
172 PostDestroyData& aPostDestroyData) override;
174 nsSize mPrefSize;
175 nsSize mMinSize;
176 nsSize mMaxSize;
177 nscoord mFlex;
178 nscoord mAscent;
180 nsCOMPtr<nsBoxLayout> mLayoutManager;
182 // Get the point associated with this event. Returns true if a single valid
183 // point was found. Otherwise false.
184 bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent, nsPoint& aPoint);
185 // Gets the event coordinates relative to the widget offset associated with
186 // this frame. Return true if a single valid point was found.
187 bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent,
188 mozilla::LayoutDeviceIntPoint& aPoint);
190 private:
191 void CacheAttributes();
193 // instance variables.
194 Halignment mHalign;
195 Valignment mValign;
197 }; // class nsBoxFrame
199 #endif