Back to index

lightning-sunbird  0.9+nobinonly
nsSprocketLayout.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsSprocketLayout_h___
00039 #define nsSprocketLayout_h___
00040 
00041 #include "nsBoxLayout.h"
00042 #include "nsCOMPtr.h"
00043 
00044 class nsBoxSize
00045 {
00046 public:
00047 
00048   nsBoxSize();
00049 
00050   nscoord pref;
00051   nscoord min;
00052   nscoord max;
00053   nscoord ascent;
00054   nscoord flex;
00055   nscoord left;
00056   nscoord right;
00057   PRBool  collapsed;
00058   PRBool  bogus;
00059 
00060   nsBoxSize* next;
00061 
00062   void Clear();
00063   void Add(const nsSize& minSize, 
00064            const nsSize& prefSize,
00065            const nsSize& maxSize,
00066            nscoord ascent,
00067            nscoord flex,
00068            PRBool aIsHorizontal);
00069 
00070   void Add(const nsMargin& aMargin, PRBool aIsHorizontal);
00071   void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW;
00072   void operator delete(void* aPtr, size_t sz);
00073 
00074 };
00075 
00076 class nsComputedBoxSize
00077 {
00078 public:
00079   nsComputedBoxSize();
00080 
00081   nscoord size;
00082   PRBool  valid;
00083   PRBool  resized;
00084   nsComputedBoxSize* next;
00085 
00086   void Clear();
00087   void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW;
00088   void operator delete(void* aPtr, size_t sz);
00089 
00090 };
00091 
00092 #define GET_WIDTH(size, isHorizontal) (isHorizontal ? size.width : size.height)
00093 #define GET_HEIGHT(size, isHorizontal) (isHorizontal ? size.height : size.width)
00094 #define GET_X(size, isHorizontal) (isHorizontal ? size.x : size.y)
00095 #define GET_Y(size, isHorizontal) (isHorizontal ? size.y : size.x)
00096 #define GET_COORD(aX, aY, isHorizontal) (isHorizontal ? aX : aY)
00097 
00098 #define SET_WIDTH(size, coord, isHorizontal)  if (isHorizontal) { (size).width  = (coord); } else { (size).height = (coord); }
00099 #define SET_HEIGHT(size, coord, isHorizontal) if (isHorizontal) { (size).height = (coord); } else { (size).width  = (coord); }
00100 #define SET_X(size, coord, isHorizontal) if (isHorizontal) { (size).x = (coord); } else { (size).y  = (coord); }
00101 #define SET_Y(size, coord, isHorizontal) if (isHorizontal) { (size).y = (coord); } else { (size).x  = (coord); }
00102 
00103 #define SET_COORD(aX, aY, coord, isHorizontal) if (isHorizontal) { aX = (coord); } else { aY  = (coord); }
00104 
00105 nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr<nsIBoxLayout>& aNewLayout);
00106 
00107 class nsSprocketLayout : public nsBoxLayout {
00108 
00109 public:
00110 
00111   friend nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr<nsIBoxLayout>& aNewLayout);
00112   static void Shutdown();
00113 
00114   NS_IMETHOD Layout(nsIBox* aBox, nsBoxLayoutState& aState);
00115 
00116   NS_IMETHOD GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00117   NS_IMETHOD GetMinSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00118   NS_IMETHOD GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00119   NS_IMETHOD GetFlex(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nscoord& aFlex);
00120   NS_IMETHOD GetAscent(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nscoord& aAscent);
00121   NS_IMETHOD IsCollapsed(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, PRBool& aCollapsed);
00122 
00123   nsSprocketLayout();
00124 
00125   static PRBool IsHorizontal(nsIBox* aBox);
00126 
00127   static void SetLargestSize(nsSize& aSize1, const nsSize& aSize2, PRBool aIsHorizontal);
00128   static void SetSmallestSize(nsSize& aSize1, const nsSize& aSize2, PRBool aIsHorizontal);
00129 
00130   static void AddLargestSize(nsSize& aSize, const nsSize& aSizeToAdd, PRBool aIsHorizontal);
00131   static void AddSmallestSize(nsSize& aSize, const nsSize& aSizeToAdd, PRBool aIsHorizontal);
00132   static void AddCoord(nscoord& aCoord, nscoord aCoordToAdd);
00133 
00134 protected:
00135 
00136 
00137   virtual void ComputeChildsNextPosition(nsIBox* aBox,
00138                                          nsIBox* aChild, 
00139                                          nscoord& aCurX, 
00140                                          nscoord& aCurY, 
00141                                          nscoord& aNextX, 
00142                                          nscoord& aNextY, 
00143                                          const nsRect& aChildSize, 
00144                                          const nsRect& aContainingRect,
00145                                          nscoord childAscent,
00146                                          nscoord aMaxAscent);
00147 
00148   virtual void ChildResized(nsIBox* aBox,
00149                             nsBoxLayoutState& aState, 
00150                            nsIBox* aChild,
00151                            nsBoxSize* aChildBoxSize, 
00152                            nsComputedBoxSize* aChildComputedBoxSize, 
00153                            nsBoxSize* aBoxSizes, 
00154                            nsComputedBoxSize* aComputedBoxSizes, 
00155                            const nsRect& aChildLayoutRect, 
00156                            nsRect& aChildActualRect, 
00157                            nsRect& aContainingRect, 
00158                            PRInt32 aFlexes, 
00159                            PRBool& aFinished);
00160 
00161   virtual void ComputeChildSizes(nsIBox* aBox, 
00162                          nsBoxLayoutState& aState, 
00163                          nscoord& aGivenSize, 
00164                          nsBoxSize* aBoxSizes, 
00165                          nsComputedBoxSize*& aComputedBoxSizes);
00166 
00167 
00168   virtual void PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsBoxSize*& aBoxSizes, nsComputedBoxSize*& aComputedBoxSizes, nscoord& aMinSize, nscoord& aMaxSize, PRInt32& aFlexes);
00169 
00170   virtual void InvalidateComputedSizes(nsComputedBoxSize* aComputedBoxSizes);
00171 
00172   virtual PRBool GetDefaultFlex(PRInt32& aFlex);
00173 
00174   virtual void GetFrameState(nsIBox* aBox, nsFrameState& aState);
00175 
00176 private:
00177 
00178 
00179   // because the sprocket layout manager has no instance variables. We 
00180   // can make a static on and reuse it everywhere.
00181   static nsIBoxLayout* gInstance;
00182 
00183 };
00184 
00185 #endif
00186