michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsBox_h___ michael@0: #define nsBox_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsIFrame.h" michael@0: michael@0: class nsITheme; michael@0: michael@0: class nsBox : public nsIFrame { michael@0: michael@0: public: michael@0: michael@0: friend class nsIFrame; michael@0: michael@0: static void Shutdown(); michael@0: michael@0: virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nscoord GetFlex(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: michael@0: virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: michael@0: virtual bool IsCollapsed() MOZ_OVERRIDE; michael@0: michael@0: virtual void SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, michael@0: bool aRemoveOverflowAreas = false) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult GetBorder(nsMargin& aBorderAndPadding) MOZ_OVERRIDE; michael@0: virtual nsresult GetPadding(nsMargin& aBorderAndPadding) MOZ_OVERRIDE; michael@0: virtual nsresult GetMargin(nsMargin& aMargin) MOZ_OVERRIDE; michael@0: michael@0: virtual Valignment GetVAlign() const MOZ_OVERRIDE { return vAlign_Top; } michael@0: virtual Halignment GetHAlign() const MOZ_OVERRIDE { return hAlign_Left; } michael@0: michael@0: virtual nsresult RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIFrame* aChild) MOZ_OVERRIDE; michael@0: michael@0: #ifdef DEBUG_LAYOUT michael@0: NS_IMETHOD GetDebugBoxAt(const nsPoint& aPoint, nsIFrame** aBox); michael@0: virtual nsresult GetDebug(bool& aDebug) MOZ_OVERRIDE; michael@0: virtual nsresult SetDebug(nsBoxLayoutState& aState, bool aDebug) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult DumpBox(FILE* out) MOZ_OVERRIDE; michael@0: NS_HIDDEN_(void) PropagateDebug(nsBoxLayoutState& aState); michael@0: #endif michael@0: michael@0: nsBox(); michael@0: virtual ~nsBox(); michael@0: michael@0: /** michael@0: * Returns true if this box clips its children, e.g., if this box is an sc michael@0: rollbox. michael@0: */ michael@0: virtual bool DoesClipChildren(); michael@0: virtual bool ComputesOwnOverflowArea() = 0; michael@0: michael@0: NS_HIDDEN_(nsresult) SyncLayout(nsBoxLayoutState& aBoxLayoutState); michael@0: michael@0: bool DoesNeedRecalc(const nsSize& aSize); michael@0: bool DoesNeedRecalc(nscoord aCoord); michael@0: void SizeNeedsRecalc(nsSize& aSize); michael@0: void CoordNeedsRecalc(nscoord& aCoord); michael@0: michael@0: void AddBorderAndPadding(nsSize& aSize); michael@0: michael@0: static void AddBorderAndPadding(nsIFrame* aBox, nsSize& aSize); michael@0: static void AddMargin(nsIFrame* aChild, nsSize& aSize); michael@0: static void AddMargin(nsSize& aSize, const nsMargin& aMargin); michael@0: michael@0: static nsSize BoundsCheckMinMax(const nsSize& aMinSize, const nsSize& aMaxSize); michael@0: static nsSize BoundsCheck(const nsSize& aMinSize, const nsSize& aPrefSize, const nsSize& aMaxSize); michael@0: static nscoord BoundsCheck(nscoord aMinSize, nscoord aPrefSize, nscoord aMaxSize); michael@0: michael@0: protected: michael@0: michael@0: #ifdef DEBUG_LAYOUT michael@0: virtual void AppendAttribute(const nsAutoString& aAttribute, const nsAutoString& aValue, nsAutoString& aResult); michael@0: michael@0: virtual void ListBox(nsAutoString& aResult); michael@0: #endif michael@0: michael@0: virtual void GetLayoutFlags(uint32_t& aFlags); michael@0: michael@0: NS_HIDDEN_(nsresult) BeginLayout(nsBoxLayoutState& aState); michael@0: NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState); michael@0: NS_HIDDEN_(nsresult) EndLayout(nsBoxLayoutState& aState); michael@0: michael@0: #ifdef DEBUG_LAYOUT michael@0: virtual void GetBoxName(nsAutoString& aName); michael@0: NS_HIDDEN_(void) PropagateDebug(nsBoxLayoutState& aState); michael@0: #endif michael@0: michael@0: static bool gGotTheme; michael@0: static nsITheme* gTheme; michael@0: michael@0: enum eMouseThrough { michael@0: unset, michael@0: never, michael@0: always michael@0: }; michael@0: michael@0: private: michael@0: michael@0: //nscoord mX; michael@0: //nscoord mY; michael@0: }; michael@0: michael@0: #ifdef DEBUG_LAYOUT michael@0: #define NS_BOX_ASSERTION(box,expr,str) \ michael@0: if (!(expr)) { \ michael@0: box->DumpBox(stdout); \ michael@0: NS_DebugBreak(NSDebugAssertion, str, #expr, __FILE__, __LINE__); \ michael@0: } michael@0: #else michael@0: #define NS_BOX_ASSERTION(box,expr,str) {} michael@0: #endif michael@0: michael@0: #endif michael@0: