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