nsBoxLayoutState.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. Author:
  7. Eric D Vaughan
  8. **/
  9. #ifndef nsBoxLayoutState_h___
  10. #define nsBoxLayoutState_h___
  11. #include "nsCOMPtr.h"
  12. #include "nsPresContext.h"
  13. #include "nsIPresShell.h"
  14. class nsRenderingContext;
  15. namespace mozilla {
  16. struct ReflowInput;
  17. } // namespace mozilla
  18. class MOZ_STACK_CLASS nsBoxLayoutState
  19. {
  20. using ReflowInput = mozilla::ReflowInput;
  21. public:
  22. explicit nsBoxLayoutState(nsPresContext* aPresContext,
  23. nsRenderingContext* aRenderingContext = nullptr,
  24. // see OuterReflowInput() below
  25. const ReflowInput* aOuterReflowInput = nullptr,
  26. uint16_t aReflowDepth = 0);
  27. nsBoxLayoutState(const nsBoxLayoutState& aState);
  28. nsPresContext* PresContext() const { return mPresContext; }
  29. nsIPresShell* PresShell() const { return mPresContext->PresShell(); }
  30. uint32_t LayoutFlags() const { return mLayoutFlags; }
  31. void SetLayoutFlags(uint32_t aFlags) { mLayoutFlags = aFlags; }
  32. // if true no one under us will paint during reflow.
  33. void SetPaintingDisabled(bool aDisable) { mPaintingDisabled = aDisable; }
  34. bool PaintingDisabled() const { return mPaintingDisabled; }
  35. // The rendering context may be null for specialized uses of
  36. // nsBoxLayoutState and should be null-checked before it is used.
  37. // However, passing a null rendering context to the constructor when
  38. // doing box layout or intrinsic size calculation will cause bugs.
  39. nsRenderingContext* GetRenderingContext() const { return mRenderingContext; }
  40. struct AutoReflowDepth {
  41. explicit AutoReflowDepth(nsBoxLayoutState& aState)
  42. : mState(aState) { ++mState.mReflowDepth; }
  43. ~AutoReflowDepth() { --mState.mReflowDepth; }
  44. nsBoxLayoutState& mState;
  45. };
  46. // The HTML reflow state that lives outside the box-block boundary.
  47. // May not be set reliably yet.
  48. const ReflowInput* OuterReflowInput() { return mOuterReflowInput; }
  49. uint16_t GetReflowDepth() { return mReflowDepth; }
  50. private:
  51. RefPtr<nsPresContext> mPresContext;
  52. nsRenderingContext *mRenderingContext;
  53. const ReflowInput *mOuterReflowInput;
  54. uint32_t mLayoutFlags;
  55. uint16_t mReflowDepth;
  56. bool mPaintingDisabled;
  57. };
  58. #endif