nsSprocketLayout.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 nsSprocketLayout_h___
  6. #define nsSprocketLayout_h___
  7. #include "mozilla/Attributes.h"
  8. #include "nsBoxLayout.h"
  9. #include "nsCOMPtr.h"
  10. #include "nsIFrame.h"
  11. class nsBoxSize
  12. {
  13. public:
  14. nsBoxSize();
  15. nscoord pref;
  16. nscoord min;
  17. nscoord max;
  18. nscoord flex;
  19. nscoord left;
  20. nscoord right;
  21. bool collapsed;
  22. bool bogus;
  23. nsBoxSize* next;
  24. void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW;
  25. void operator delete(void* aPtr, size_t sz);
  26. };
  27. class nsComputedBoxSize
  28. {
  29. public:
  30. nsComputedBoxSize();
  31. nscoord size;
  32. bool valid;
  33. bool resized;
  34. nsComputedBoxSize* next;
  35. void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW;
  36. void operator delete(void* aPtr, size_t sz);
  37. };
  38. #define GET_WIDTH(size, isHorizontal) (isHorizontal ? size.width : size.height)
  39. #define GET_HEIGHT(size, isHorizontal) (isHorizontal ? size.height : size.width)
  40. #define GET_X(size, isHorizontal) (isHorizontal ? size.x : size.y)
  41. #define GET_Y(size, isHorizontal) (isHorizontal ? size.y : size.x)
  42. #define GET_COORD(aX, aY, isHorizontal) (isHorizontal ? aX : aY)
  43. #define SET_WIDTH(size, coord, isHorizontal) if (isHorizontal) { (size).width = (coord); } else { (size).height = (coord); }
  44. #define SET_HEIGHT(size, coord, isHorizontal) if (isHorizontal) { (size).height = (coord); } else { (size).width = (coord); }
  45. #define SET_X(size, coord, isHorizontal) if (isHorizontal) { (size).x = (coord); } else { (size).y = (coord); }
  46. #define SET_Y(size, coord, isHorizontal) if (isHorizontal) { (size).y = (coord); } else { (size).x = (coord); }
  47. #define SET_COORD(aX, aY, coord, isHorizontal) if (isHorizontal) { aX = (coord); } else { aY = (coord); }
  48. nsresult NS_NewSprocketLayout(nsCOMPtr<nsBoxLayout>& aNewLayout);
  49. class nsSprocketLayout : public nsBoxLayout {
  50. public:
  51. friend nsresult NS_NewSprocketLayout(nsCOMPtr<nsBoxLayout>& aNewLayout);
  52. static void Shutdown();
  53. NS_IMETHOD XULLayout(nsIFrame* aBox, nsBoxLayoutState& aState) override;
  54. virtual nsSize GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override;
  55. virtual nsSize GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override;
  56. virtual nsSize GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override;
  57. virtual nscoord GetAscent(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) override;
  58. nsSprocketLayout();
  59. static bool IsXULHorizontal(nsIFrame* aBox);
  60. static void SetLargestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal);
  61. static void SetSmallestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal);
  62. static void AddLargestSize(nsSize& aSize, const nsSize& aSizeToAdd, bool aIsHorizontal);
  63. static void AddSmallestSize(nsSize& aSize, const nsSize& aSizeToAdd, bool aIsHorizontal);
  64. static void AddCoord(nscoord& aCoord, nscoord aCoordToAdd);
  65. protected:
  66. void ComputeChildsNextPosition(nsIFrame* aBox,
  67. const nscoord& aCurX,
  68. const nscoord& aCurY,
  69. nscoord& aNextX,
  70. nscoord& aNextY,
  71. const nsRect& aChildSize);
  72. void ChildResized(nsIFrame* aBox,
  73. nsBoxLayoutState& aState,
  74. nsIFrame* aChild,
  75. nsBoxSize* aChildBoxSize,
  76. nsComputedBoxSize* aChildComputedBoxSize,
  77. nsBoxSize* aBoxSizes,
  78. nsComputedBoxSize* aComputedBoxSizes,
  79. const nsRect& aChildLayoutRect,
  80. nsRect& aChildActualRect,
  81. nsRect& aContainingRect,
  82. int32_t aFlexes,
  83. bool& aFinished);
  84. void AlignChildren(nsIFrame* aBox,
  85. nsBoxLayoutState& aState);
  86. virtual void ComputeChildSizes(nsIFrame* aBox,
  87. nsBoxLayoutState& aState,
  88. nscoord& aGivenSize,
  89. nsBoxSize* aBoxSizes,
  90. nsComputedBoxSize*& aComputedBoxSizes);
  91. virtual void PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState,
  92. nsBoxSize*& aBoxSizes, nscoord& aMinSize,
  93. nscoord& aMaxSize, int32_t& aFlexes);
  94. virtual void InvalidateComputedSizes(nsComputedBoxSize* aComputedBoxSizes);
  95. virtual bool GetDefaultFlex(int32_t& aFlex);
  96. virtual void GetFrameState(nsIFrame* aBox, nsFrameState& aState);
  97. private:
  98. // because the sprocket layout manager has no instance variables. We
  99. // can make a static one and reuse it everywhere.
  100. static nsBoxLayout* gInstance;
  101. };
  102. #endif