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