nsBoxFrame.h 9.5 KB

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