nsBox.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #ifndef nsBox_h___
  6. #define nsBox_h___
  7. #include "mozilla/Attributes.h"
  8. #include "nsIFrame.h"
  9. class nsITheme;
  10. class nsBox : public nsIFrame {
  11. public:
  12. friend class nsIFrame;
  13. static void Shutdown();
  14. virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override;
  15. virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override;
  16. virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override;
  17. virtual nscoord GetXULFlex() override;
  18. virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override;
  19. virtual nsSize GetXULMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) override;
  20. virtual bool IsXULCollapsed() override;
  21. virtual void SetXULBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect,
  22. bool aRemoveOverflowAreas = false) override;
  23. virtual nsresult GetXULBorder(nsMargin& aBorderAndPadding) override;
  24. virtual nsresult GetXULPadding(nsMargin& aBorderAndPadding) override;
  25. virtual nsresult GetXULMargin(nsMargin& aMargin) override;
  26. virtual Valignment GetXULVAlign() const override { return vAlign_Top; }
  27. virtual Halignment GetXULHAlign() const override { return hAlign_Left; }
  28. virtual nsresult XULRelayoutChildAtOrdinal(nsIFrame* aChild) override;
  29. #ifdef DEBUG_LAYOUT
  30. NS_IMETHOD GetDebugBoxAt(const nsPoint& aPoint, nsIFrame** aBox);
  31. virtual nsresult GetXULDebug(bool& aDebug) override;
  32. virtual nsresult SetXULDebug(nsBoxLayoutState& aState, bool aDebug) override;
  33. virtual nsresult XULDumpBox(FILE* out) override;
  34. void PropagateDebug(nsBoxLayoutState& aState);
  35. #endif
  36. nsBox();
  37. virtual ~nsBox();
  38. /**
  39. * Returns true if this box clips its children, e.g., if this box is an sc
  40. rollbox.
  41. */
  42. virtual bool DoesClipChildren();
  43. virtual bool ComputesOwnOverflowArea() = 0;
  44. nsresult SyncLayout(nsBoxLayoutState& aBoxLayoutState);
  45. bool DoesNeedRecalc(const nsSize& aSize);
  46. bool DoesNeedRecalc(nscoord aCoord);
  47. void SizeNeedsRecalc(nsSize& aSize);
  48. void CoordNeedsRecalc(nscoord& aCoord);
  49. void AddBorderAndPadding(nsSize& aSize);
  50. static void AddBorderAndPadding(nsIFrame* aBox, nsSize& aSize);
  51. static void AddMargin(nsIFrame* aChild, nsSize& aSize);
  52. static void AddMargin(nsSize& aSize, const nsMargin& aMargin);
  53. static nsSize BoundsCheckMinMax(const nsSize& aMinSize, const nsSize& aMaxSize);
  54. static nsSize BoundsCheck(const nsSize& aMinSize, const nsSize& aPrefSize, const nsSize& aMaxSize);
  55. static nscoord BoundsCheck(nscoord aMinSize, nscoord aPrefSize, nscoord aMaxSize);
  56. static nsIFrame* GetChildXULBox(const nsIFrame* aFrame);
  57. static nsIFrame* GetNextXULBox(const nsIFrame* aFrame);
  58. static nsIFrame* GetParentXULBox(const nsIFrame* aFrame);
  59. protected:
  60. #ifdef DEBUG_LAYOUT
  61. virtual void AppendAttribute(const nsAutoString& aAttribute, const nsAutoString& aValue, nsAutoString& aResult);
  62. virtual void ListBox(nsAutoString& aResult);
  63. #endif
  64. nsresult BeginXULLayout(nsBoxLayoutState& aState);
  65. NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState);
  66. nsresult EndXULLayout(nsBoxLayoutState& aState);
  67. #ifdef DEBUG_LAYOUT
  68. virtual void GetBoxName(nsAutoString& aName);
  69. void PropagateDebug(nsBoxLayoutState& aState);
  70. #endif
  71. static bool gGotTheme;
  72. static nsITheme* gTheme;
  73. enum eMouseThrough {
  74. unset,
  75. never,
  76. always
  77. };
  78. private:
  79. //nscoord mX;
  80. //nscoord mY;
  81. };
  82. #ifdef DEBUG_LAYOUT
  83. #define NS_BOX_ASSERTION(box,expr,str) \
  84. if (!(expr)) { \
  85. box->XULDumpBox(stdout); \
  86. NS_DebugBreak(NSDebugAssertion, str, #expr, __FILE__, __LINE__); \
  87. }
  88. #else
  89. #define NS_BOX_ASSERTION(box,expr,str) {}
  90. #endif
  91. #endif