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 nsSprocketLayout_h___ michael@0: #define nsSprocketLayout_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsBoxLayout.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIFrame.h" michael@0: michael@0: class nsBoxSize michael@0: { michael@0: public: michael@0: michael@0: nsBoxSize(); michael@0: michael@0: nscoord pref; michael@0: nscoord min; michael@0: nscoord max; michael@0: nscoord flex; michael@0: nscoord left; michael@0: nscoord right; michael@0: bool collapsed; michael@0: bool bogus; michael@0: michael@0: nsBoxSize* next; michael@0: michael@0: void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW; michael@0: void operator delete(void* aPtr, size_t sz); michael@0: }; michael@0: michael@0: class nsComputedBoxSize michael@0: { michael@0: public: michael@0: nsComputedBoxSize(); michael@0: michael@0: nscoord size; michael@0: bool valid; michael@0: bool resized; michael@0: nsComputedBoxSize* next; michael@0: michael@0: void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW; michael@0: void operator delete(void* aPtr, size_t sz); michael@0: }; michael@0: michael@0: #define GET_WIDTH(size, isHorizontal) (isHorizontal ? size.width : size.height) michael@0: #define GET_HEIGHT(size, isHorizontal) (isHorizontal ? size.height : size.width) michael@0: #define GET_X(size, isHorizontal) (isHorizontal ? size.x : size.y) michael@0: #define GET_Y(size, isHorizontal) (isHorizontal ? size.y : size.x) michael@0: #define GET_COORD(aX, aY, isHorizontal) (isHorizontal ? aX : aY) michael@0: michael@0: #define SET_WIDTH(size, coord, isHorizontal) if (isHorizontal) { (size).width = (coord); } else { (size).height = (coord); } michael@0: #define SET_HEIGHT(size, coord, isHorizontal) if (isHorizontal) { (size).height = (coord); } else { (size).width = (coord); } michael@0: #define SET_X(size, coord, isHorizontal) if (isHorizontal) { (size).x = (coord); } else { (size).y = (coord); } michael@0: #define SET_Y(size, coord, isHorizontal) if (isHorizontal) { (size).y = (coord); } else { (size).x = (coord); } michael@0: michael@0: #define SET_COORD(aX, aY, coord, isHorizontal) if (isHorizontal) { aX = (coord); } else { aY = (coord); } michael@0: michael@0: nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr& aNewLayout); michael@0: michael@0: class nsSprocketLayout : public nsBoxLayout { michael@0: michael@0: public: michael@0: michael@0: friend nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr& aNewLayout); michael@0: static void Shutdown(); michael@0: michael@0: NS_IMETHOD Layout(nsIFrame* aBox, nsBoxLayoutState& aState) MOZ_OVERRIDE; michael@0: michael@0: virtual nsSize GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nsSize GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nsSize GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nscoord GetAscent(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: michael@0: nsSprocketLayout(); michael@0: michael@0: static bool IsHorizontal(nsIFrame* aBox); michael@0: michael@0: static void SetLargestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal); michael@0: static void SetSmallestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal); michael@0: michael@0: static void AddLargestSize(nsSize& aSize, const nsSize& aSizeToAdd, bool aIsHorizontal); michael@0: static void AddSmallestSize(nsSize& aSize, const nsSize& aSizeToAdd, bool aIsHorizontal); michael@0: static void AddCoord(nscoord& aCoord, nscoord aCoordToAdd); michael@0: michael@0: protected: michael@0: michael@0: michael@0: void ComputeChildsNextPosition(nsIFrame* aBox, michael@0: const nscoord& aCurX, michael@0: const nscoord& aCurY, michael@0: nscoord& aNextX, michael@0: nscoord& aNextY, michael@0: const nsRect& aChildSize); michael@0: michael@0: void ChildResized(nsIFrame* aBox, michael@0: nsBoxLayoutState& aState, michael@0: nsIFrame* aChild, michael@0: nsBoxSize* aChildBoxSize, michael@0: nsComputedBoxSize* aChildComputedBoxSize, michael@0: nsBoxSize* aBoxSizes, michael@0: nsComputedBoxSize* aComputedBoxSizes, michael@0: const nsRect& aChildLayoutRect, michael@0: nsRect& aChildActualRect, michael@0: nsRect& aContainingRect, michael@0: int32_t aFlexes, michael@0: bool& aFinished); michael@0: michael@0: void AlignChildren(nsIFrame* aBox, michael@0: nsBoxLayoutState& aState); michael@0: michael@0: virtual void ComputeChildSizes(nsIFrame* aBox, michael@0: nsBoxLayoutState& aState, michael@0: nscoord& aGivenSize, michael@0: nsBoxSize* aBoxSizes, michael@0: nsComputedBoxSize*& aComputedBoxSizes); michael@0: michael@0: michael@0: virtual void PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState, michael@0: nsBoxSize*& aBoxSizes, nscoord& aMinSize, michael@0: nscoord& aMaxSize, int32_t& aFlexes); michael@0: michael@0: virtual void InvalidateComputedSizes(nsComputedBoxSize* aComputedBoxSizes); michael@0: michael@0: virtual bool GetDefaultFlex(int32_t& aFlex); michael@0: michael@0: virtual void GetFrameState(nsIFrame* aBox, nsFrameState& aState); michael@0: michael@0: private: michael@0: michael@0: michael@0: // because the sprocket layout manager has no instance variables. We michael@0: // can make a static one and reuse it everywhere. michael@0: static nsBoxLayout* gInstance; michael@0: michael@0: }; michael@0: michael@0: #endif michael@0: