1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/xul/nsSprocketLayout.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,142 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsSprocketLayout_h___ 1.10 +#define nsSprocketLayout_h___ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "nsBoxLayout.h" 1.14 +#include "nsCOMPtr.h" 1.15 +#include "nsIFrame.h" 1.16 + 1.17 +class nsBoxSize 1.18 +{ 1.19 +public: 1.20 + 1.21 + nsBoxSize(); 1.22 + 1.23 + nscoord pref; 1.24 + nscoord min; 1.25 + nscoord max; 1.26 + nscoord flex; 1.27 + nscoord left; 1.28 + nscoord right; 1.29 + bool collapsed; 1.30 + bool bogus; 1.31 + 1.32 + nsBoxSize* next; 1.33 + 1.34 + void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW; 1.35 + void operator delete(void* aPtr, size_t sz); 1.36 +}; 1.37 + 1.38 +class nsComputedBoxSize 1.39 +{ 1.40 +public: 1.41 + nsComputedBoxSize(); 1.42 + 1.43 + nscoord size; 1.44 + bool valid; 1.45 + bool resized; 1.46 + nsComputedBoxSize* next; 1.47 + 1.48 + void* operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW; 1.49 + void operator delete(void* aPtr, size_t sz); 1.50 +}; 1.51 + 1.52 +#define GET_WIDTH(size, isHorizontal) (isHorizontal ? size.width : size.height) 1.53 +#define GET_HEIGHT(size, isHorizontal) (isHorizontal ? size.height : size.width) 1.54 +#define GET_X(size, isHorizontal) (isHorizontal ? size.x : size.y) 1.55 +#define GET_Y(size, isHorizontal) (isHorizontal ? size.y : size.x) 1.56 +#define GET_COORD(aX, aY, isHorizontal) (isHorizontal ? aX : aY) 1.57 + 1.58 +#define SET_WIDTH(size, coord, isHorizontal) if (isHorizontal) { (size).width = (coord); } else { (size).height = (coord); } 1.59 +#define SET_HEIGHT(size, coord, isHorizontal) if (isHorizontal) { (size).height = (coord); } else { (size).width = (coord); } 1.60 +#define SET_X(size, coord, isHorizontal) if (isHorizontal) { (size).x = (coord); } else { (size).y = (coord); } 1.61 +#define SET_Y(size, coord, isHorizontal) if (isHorizontal) { (size).y = (coord); } else { (size).x = (coord); } 1.62 + 1.63 +#define SET_COORD(aX, aY, coord, isHorizontal) if (isHorizontal) { aX = (coord); } else { aY = (coord); } 1.64 + 1.65 +nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr<nsBoxLayout>& aNewLayout); 1.66 + 1.67 +class nsSprocketLayout : public nsBoxLayout { 1.68 + 1.69 +public: 1.70 + 1.71 + friend nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr<nsBoxLayout>& aNewLayout); 1.72 + static void Shutdown(); 1.73 + 1.74 + NS_IMETHOD Layout(nsIFrame* aBox, nsBoxLayoutState& aState) MOZ_OVERRIDE; 1.75 + 1.76 + virtual nsSize GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; 1.77 + virtual nsSize GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; 1.78 + virtual nsSize GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; 1.79 + virtual nscoord GetAscent(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; 1.80 + 1.81 + nsSprocketLayout(); 1.82 + 1.83 + static bool IsHorizontal(nsIFrame* aBox); 1.84 + 1.85 + static void SetLargestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal); 1.86 + static void SetSmallestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal); 1.87 + 1.88 + static void AddLargestSize(nsSize& aSize, const nsSize& aSizeToAdd, bool aIsHorizontal); 1.89 + static void AddSmallestSize(nsSize& aSize, const nsSize& aSizeToAdd, bool aIsHorizontal); 1.90 + static void AddCoord(nscoord& aCoord, nscoord aCoordToAdd); 1.91 + 1.92 +protected: 1.93 + 1.94 + 1.95 + void ComputeChildsNextPosition(nsIFrame* aBox, 1.96 + const nscoord& aCurX, 1.97 + const nscoord& aCurY, 1.98 + nscoord& aNextX, 1.99 + nscoord& aNextY, 1.100 + const nsRect& aChildSize); 1.101 + 1.102 + void ChildResized(nsIFrame* aBox, 1.103 + nsBoxLayoutState& aState, 1.104 + nsIFrame* aChild, 1.105 + nsBoxSize* aChildBoxSize, 1.106 + nsComputedBoxSize* aChildComputedBoxSize, 1.107 + nsBoxSize* aBoxSizes, 1.108 + nsComputedBoxSize* aComputedBoxSizes, 1.109 + const nsRect& aChildLayoutRect, 1.110 + nsRect& aChildActualRect, 1.111 + nsRect& aContainingRect, 1.112 + int32_t aFlexes, 1.113 + bool& aFinished); 1.114 + 1.115 + void AlignChildren(nsIFrame* aBox, 1.116 + nsBoxLayoutState& aState); 1.117 + 1.118 + virtual void ComputeChildSizes(nsIFrame* aBox, 1.119 + nsBoxLayoutState& aState, 1.120 + nscoord& aGivenSize, 1.121 + nsBoxSize* aBoxSizes, 1.122 + nsComputedBoxSize*& aComputedBoxSizes); 1.123 + 1.124 + 1.125 + virtual void PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState, 1.126 + nsBoxSize*& aBoxSizes, nscoord& aMinSize, 1.127 + nscoord& aMaxSize, int32_t& aFlexes); 1.128 + 1.129 + virtual void InvalidateComputedSizes(nsComputedBoxSize* aComputedBoxSizes); 1.130 + 1.131 + virtual bool GetDefaultFlex(int32_t& aFlex); 1.132 + 1.133 + virtual void GetFrameState(nsIFrame* aBox, nsFrameState& aState); 1.134 + 1.135 +private: 1.136 + 1.137 + 1.138 + // because the sprocket layout manager has no instance variables. We 1.139 + // can make a static one and reuse it everywhere. 1.140 + static nsBoxLayout* gInstance; 1.141 + 1.142 +}; 1.143 + 1.144 +#endif 1.145 +