1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 /**
8 
9   Author:
10   Eric D Vaughan
11 
12 **/
13 
14 #ifndef nsBoxLayoutState_h___
15 #define nsBoxLayoutState_h___
16 
17 #include "nsCOMPtr.h"
18 #include "nsPresContext.h"
19 #include "nsIFrame.h"
20 
21 class gfxContext;
22 namespace mozilla {
23 class PresShell;
24 struct ReflowInput;
25 }  // namespace mozilla
26 
27 class MOZ_STACK_CLASS nsBoxLayoutState {
28   using ReflowInput = mozilla::ReflowInput;
29 
30  public:
31   explicit nsBoxLayoutState(nsPresContext* aPresContext,
32                             gfxContext* 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   mozilla::PresShell* PresShell() const { return mPresContext->PresShell(); }
40 
LayoutFlags()41   nsIFrame::ReflowChildFlags LayoutFlags() const { return mLayoutFlags; }
SetLayoutFlags(nsIFrame::ReflowChildFlags aFlags)42   void SetLayoutFlags(nsIFrame::ReflowChildFlags aFlags) {
43     mLayoutFlags = aFlags;
44   }
45 
46   // if true no one under us will paint during reflow.
SetPaintingDisabled(bool aDisable)47   void SetPaintingDisabled(bool aDisable) { mPaintingDisabled = aDisable; }
PaintingDisabled()48   bool PaintingDisabled() const { return mPaintingDisabled; }
49 
50   // The rendering context may be null for specialized uses of
51   // nsBoxLayoutState and should be null-checked before it is used.
52   // However, passing a null rendering context to the constructor when
53   // doing box layout or intrinsic size calculation will cause bugs.
GetRenderingContext()54   gfxContext* GetRenderingContext() const { return mRenderingContext; }
55 
56   struct AutoReflowDepth {
AutoReflowDepthAutoReflowDepth57     explicit AutoReflowDepth(nsBoxLayoutState& aState) : mState(aState) {
58       ++mState.mReflowDepth;
59     }
~AutoReflowDepthAutoReflowDepth60     ~AutoReflowDepth() { --mState.mReflowDepth; }
61     nsBoxLayoutState& mState;
62   };
63 
64   // The HTML reflow input that lives outside the box-block boundary.
65   // May not be set reliably yet.
OuterReflowInput()66   const ReflowInput* OuterReflowInput() { return mOuterReflowInput; }
67 
GetReflowDepth()68   uint16_t GetReflowDepth() { return mReflowDepth; }
69 
70  private:
71   RefPtr<nsPresContext> mPresContext;
72   gfxContext* mRenderingContext;
73   const ReflowInput* mOuterReflowInput;
74   nsIFrame::ReflowChildFlags mLayoutFlags;
75   uint16_t mReflowDepth;
76   bool mPaintingDisabled;
77 };
78 
79 #endif
80