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 "nsGridRowLeafFrame.h" michael@0: #include "nsGridRowLeafLayout.h" michael@0: #include "nsGridRow.h" michael@0: #include "nsBoxLayoutState.h" michael@0: #include "nsGridLayout2.h" michael@0: michael@0: already_AddRefed NS_NewGridRowLeafLayout(); michael@0: michael@0: nsIFrame* michael@0: NS_NewGridRowLeafFrame(nsIPresShell* aPresShell, michael@0: nsStyleContext* aContext) michael@0: { michael@0: nsCOMPtr layout = NS_NewGridRowLeafLayout(); michael@0: return new (aPresShell) nsGridRowLeafFrame(aPresShell, aContext, false, michael@0: layout); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsGridRowLeafFrame) michael@0: michael@0: /* michael@0: * Our border and padding could be affected by our columns or rows. michael@0: * Let's go check it out. michael@0: */ michael@0: nsresult michael@0: nsGridRowLeafFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding) michael@0: { michael@0: // if our columns have made our padding larger add it in. michael@0: nsresult rv = nsBoxFrame::GetBorderAndPadding(aBorderAndPadding); michael@0: michael@0: nsIGridPart* part = nsGrid::GetPartFromBox(this); michael@0: if (!part) michael@0: return rv; michael@0: michael@0: int32_t index = 0; michael@0: nsGrid* grid = part->GetGrid(this, &index); michael@0: michael@0: if (!grid) michael@0: return rv; michael@0: michael@0: bool isHorizontal = IsHorizontal(); michael@0: michael@0: nsBoxLayoutState state(PresContext()); michael@0: michael@0: int32_t firstIndex = 0; michael@0: int32_t lastIndex = 0; michael@0: nsGridRow* firstRow = nullptr; michael@0: nsGridRow* lastRow = nullptr; michael@0: grid->GetFirstAndLastRow(state, firstIndex, lastIndex, firstRow, lastRow, isHorizontal); michael@0: michael@0: // only the first and last rows can be affected. michael@0: if (firstRow && firstRow->GetBox() == this) { michael@0: michael@0: nscoord top = 0; michael@0: nscoord bottom = 0; michael@0: grid->GetRowOffsets(state, firstIndex, top, bottom, isHorizontal); michael@0: michael@0: if (isHorizontal) { michael@0: if (top > aBorderAndPadding.top) michael@0: aBorderAndPadding.top = top; michael@0: } else { michael@0: if (top > aBorderAndPadding.left) michael@0: aBorderAndPadding.left = top; michael@0: } michael@0: } michael@0: michael@0: if (lastRow && lastRow->GetBox() == this) { michael@0: michael@0: nscoord top = 0; michael@0: nscoord bottom = 0; michael@0: grid->GetRowOffsets(state, lastIndex, top, bottom, isHorizontal); michael@0: michael@0: if (isHorizontal) { michael@0: if (bottom > aBorderAndPadding.bottom) michael@0: aBorderAndPadding.bottom = bottom; michael@0: } else { michael@0: if (bottom > aBorderAndPadding.right) michael@0: aBorderAndPadding.right = bottom; michael@0: } michael@0: michael@0: } michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: