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: // michael@0: // Eric Vaughan michael@0: // Netscape Communications michael@0: // michael@0: // See documentation in associated header file michael@0: // michael@0: michael@0: #include "nsGridCell.h" michael@0: #include "nsFrame.h" michael@0: #include "nsBox.h" michael@0: #include "nsGridLayout2.h" michael@0: michael@0: michael@0: nsGridCell::nsGridCell():mBoxInColumn(nullptr),mBoxInRow(nullptr) michael@0: { michael@0: MOZ_COUNT_CTOR(nsGridCell); michael@0: } michael@0: michael@0: nsGridCell::~nsGridCell() michael@0: { michael@0: MOZ_COUNT_DTOR(nsGridCell); michael@0: } michael@0: michael@0: nsSize michael@0: nsGridCell::GetPrefSize(nsBoxLayoutState& aState) michael@0: { michael@0: nsSize sum(0,0); michael@0: michael@0: // take our 2 children and add them up. michael@0: // we are as wide as the widest child plus its left offset michael@0: // we are tall as the tallest child plus its top offset michael@0: michael@0: if (mBoxInColumn) { michael@0: nsSize pref = mBoxInColumn->GetPrefSize(aState); michael@0: michael@0: nsBox::AddMargin(mBoxInColumn, pref); michael@0: nsGridLayout2::AddOffset(aState, mBoxInColumn, pref); michael@0: michael@0: nsBoxLayout::AddLargestSize(sum, pref); michael@0: } michael@0: michael@0: if (mBoxInRow) { michael@0: nsSize pref = mBoxInRow->GetPrefSize(aState); michael@0: michael@0: nsBox::AddMargin(mBoxInRow, pref); michael@0: nsGridLayout2::AddOffset(aState, mBoxInRow, pref); michael@0: michael@0: nsBoxLayout::AddLargestSize(sum, pref); michael@0: } michael@0: michael@0: return sum; michael@0: } michael@0: michael@0: nsSize michael@0: nsGridCell::GetMinSize(nsBoxLayoutState& aState) michael@0: { michael@0: nsSize sum(0, 0); michael@0: michael@0: // take our 2 children and add them up. michael@0: // we are as wide as the widest child plus its left offset michael@0: // we are tall as the tallest child plus its top offset michael@0: michael@0: if (mBoxInColumn) { michael@0: nsSize min = mBoxInColumn->GetMinSize(aState); michael@0: michael@0: nsBox::AddMargin(mBoxInColumn, min); michael@0: nsGridLayout2::AddOffset(aState, mBoxInColumn, min); michael@0: michael@0: nsBoxLayout::AddLargestSize(sum, min); michael@0: } michael@0: michael@0: if (mBoxInRow) { michael@0: nsSize min = mBoxInRow->GetMinSize(aState); michael@0: michael@0: nsBox::AddMargin(mBoxInRow, min); michael@0: nsGridLayout2::AddOffset(aState, mBoxInRow, min); michael@0: michael@0: nsBoxLayout::AddLargestSize(sum, min); michael@0: } michael@0: michael@0: return sum; michael@0: } michael@0: michael@0: nsSize michael@0: nsGridCell::GetMaxSize(nsBoxLayoutState& aState) michael@0: { michael@0: nsSize sum(NS_INTRINSICSIZE, NS_INTRINSICSIZE); michael@0: michael@0: // take our 2 children and add them up. michael@0: // we are as wide as the smallest child plus its left offset michael@0: // we are tall as the shortest child plus its top offset michael@0: michael@0: if (mBoxInColumn) { michael@0: nsSize max = mBoxInColumn->GetMaxSize(aState); michael@0: michael@0: nsBox::AddMargin(mBoxInColumn, max); michael@0: nsGridLayout2::AddOffset(aState, mBoxInColumn, max); michael@0: michael@0: nsBoxLayout::AddSmallestSize(sum, max); michael@0: } michael@0: michael@0: if (mBoxInRow) { michael@0: nsSize max = mBoxInRow->GetMaxSize(aState); michael@0: michael@0: nsBox::AddMargin(mBoxInRow, max); michael@0: nsGridLayout2::AddOffset(aState, mBoxInRow, max); michael@0: michael@0: nsBoxLayout::AddSmallestSize(sum, max); michael@0: } michael@0: michael@0: return sum; michael@0: } michael@0: michael@0: michael@0: bool michael@0: nsGridCell::IsCollapsed() michael@0: { michael@0: return ((mBoxInColumn && mBoxInColumn->IsCollapsed()) || michael@0: (mBoxInRow && mBoxInRow->IsCollapsed())); michael@0: } michael@0: michael@0: