layout/xul/grid/nsGridCell.cpp

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:66f913c199e9
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 //
7 // Eric Vaughan
8 // Netscape Communications
9 //
10 // See documentation in associated header file
11 //
12
13 #include "nsGridCell.h"
14 #include "nsFrame.h"
15 #include "nsBox.h"
16 #include "nsGridLayout2.h"
17
18
19 nsGridCell::nsGridCell():mBoxInColumn(nullptr),mBoxInRow(nullptr)
20 {
21 MOZ_COUNT_CTOR(nsGridCell);
22 }
23
24 nsGridCell::~nsGridCell()
25 {
26 MOZ_COUNT_DTOR(nsGridCell);
27 }
28
29 nsSize
30 nsGridCell::GetPrefSize(nsBoxLayoutState& aState)
31 {
32 nsSize sum(0,0);
33
34 // take our 2 children and add them up.
35 // we are as wide as the widest child plus its left offset
36 // we are tall as the tallest child plus its top offset
37
38 if (mBoxInColumn) {
39 nsSize pref = mBoxInColumn->GetPrefSize(aState);
40
41 nsBox::AddMargin(mBoxInColumn, pref);
42 nsGridLayout2::AddOffset(aState, mBoxInColumn, pref);
43
44 nsBoxLayout::AddLargestSize(sum, pref);
45 }
46
47 if (mBoxInRow) {
48 nsSize pref = mBoxInRow->GetPrefSize(aState);
49
50 nsBox::AddMargin(mBoxInRow, pref);
51 nsGridLayout2::AddOffset(aState, mBoxInRow, pref);
52
53 nsBoxLayout::AddLargestSize(sum, pref);
54 }
55
56 return sum;
57 }
58
59 nsSize
60 nsGridCell::GetMinSize(nsBoxLayoutState& aState)
61 {
62 nsSize sum(0, 0);
63
64 // take our 2 children and add them up.
65 // we are as wide as the widest child plus its left offset
66 // we are tall as the tallest child plus its top offset
67
68 if (mBoxInColumn) {
69 nsSize min = mBoxInColumn->GetMinSize(aState);
70
71 nsBox::AddMargin(mBoxInColumn, min);
72 nsGridLayout2::AddOffset(aState, mBoxInColumn, min);
73
74 nsBoxLayout::AddLargestSize(sum, min);
75 }
76
77 if (mBoxInRow) {
78 nsSize min = mBoxInRow->GetMinSize(aState);
79
80 nsBox::AddMargin(mBoxInRow, min);
81 nsGridLayout2::AddOffset(aState, mBoxInRow, min);
82
83 nsBoxLayout::AddLargestSize(sum, min);
84 }
85
86 return sum;
87 }
88
89 nsSize
90 nsGridCell::GetMaxSize(nsBoxLayoutState& aState)
91 {
92 nsSize sum(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
93
94 // take our 2 children and add them up.
95 // we are as wide as the smallest child plus its left offset
96 // we are tall as the shortest child plus its top offset
97
98 if (mBoxInColumn) {
99 nsSize max = mBoxInColumn->GetMaxSize(aState);
100
101 nsBox::AddMargin(mBoxInColumn, max);
102 nsGridLayout2::AddOffset(aState, mBoxInColumn, max);
103
104 nsBoxLayout::AddSmallestSize(sum, max);
105 }
106
107 if (mBoxInRow) {
108 nsSize max = mBoxInRow->GetMaxSize(aState);
109
110 nsBox::AddMargin(mBoxInRow, max);
111 nsGridLayout2::AddOffset(aState, mBoxInRow, max);
112
113 nsBoxLayout::AddSmallestSize(sum, max);
114 }
115
116 return sum;
117 }
118
119
120 bool
121 nsGridCell::IsCollapsed()
122 {
123 return ((mBoxInColumn && mBoxInColumn->IsCollapsed()) ||
124 (mBoxInRow && mBoxInRow->IsCollapsed()));
125 }
126
127

mercurial