Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | // |
michael@0 | 7 | // Eric Vaughan |
michael@0 | 8 | // Netscape Communications |
michael@0 | 9 | // |
michael@0 | 10 | // See documentation in associated header file |
michael@0 | 11 | // |
michael@0 | 12 | |
michael@0 | 13 | |
michael@0 | 14 | /* |
michael@0 | 15 | * The nsGridRowGroupLayout implements the <rows> or <columns> tag in a grid. |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | #include "nsGridRowGroupLayout.h" |
michael@0 | 19 | #include "nsCOMPtr.h" |
michael@0 | 20 | #include "nsIScrollableFrame.h" |
michael@0 | 21 | #include "nsBoxLayoutState.h" |
michael@0 | 22 | #include "nsGridLayout2.h" |
michael@0 | 23 | #include "nsGridRow.h" |
michael@0 | 24 | #include "nsHTMLReflowState.h" |
michael@0 | 25 | |
michael@0 | 26 | already_AddRefed<nsBoxLayout> NS_NewGridRowGroupLayout() |
michael@0 | 27 | { |
michael@0 | 28 | nsRefPtr<nsBoxLayout> layout = new nsGridRowGroupLayout(); |
michael@0 | 29 | return layout.forget(); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | nsGridRowGroupLayout::nsGridRowGroupLayout():nsGridRowLayout(), mRowCount(0) |
michael@0 | 33 | { |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | nsGridRowGroupLayout::~nsGridRowGroupLayout() |
michael@0 | 37 | { |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | void |
michael@0 | 41 | nsGridRowGroupLayout::ChildAddedOrRemoved(nsIFrame* aBox, nsBoxLayoutState& aState) |
michael@0 | 42 | { |
michael@0 | 43 | int32_t index = 0; |
michael@0 | 44 | nsGrid* grid = GetGrid(aBox, &index); |
michael@0 | 45 | bool isHorizontal = IsHorizontal(aBox); |
michael@0 | 46 | |
michael@0 | 47 | if (grid) |
michael@0 | 48 | grid->RowAddedOrRemoved(aState, index, isHorizontal); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | void |
michael@0 | 52 | nsGridRowGroupLayout::AddWidth(nsSize& aSize, nscoord aSize2, bool aIsHorizontal) |
michael@0 | 53 | { |
michael@0 | 54 | nscoord& size = GET_WIDTH(aSize, aIsHorizontal); |
michael@0 | 55 | |
michael@0 | 56 | if (size == NS_INTRINSICSIZE || aSize2 == NS_INTRINSICSIZE) |
michael@0 | 57 | size = NS_INTRINSICSIZE; |
michael@0 | 58 | else |
michael@0 | 59 | size += aSize2; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | nsSize |
michael@0 | 63 | nsGridRowGroupLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) |
michael@0 | 64 | { |
michael@0 | 65 | nsSize vpref = nsGridRowLayout::GetPrefSize(aBox, aState); |
michael@0 | 66 | |
michael@0 | 67 | |
michael@0 | 68 | /* It is possible that we could have some extra columns. This is when less columns in XUL were |
michael@0 | 69 | * defined that needed. And example might be a grid with 3 defined columns but a row with 4 cells in |
michael@0 | 70 | * it. We would need an extra column to make the grid work. But because that extra column does not |
michael@0 | 71 | * have a box associated with it we must add its size in manually. Remember we could have extra rows |
michael@0 | 72 | * as well. |
michael@0 | 73 | */ |
michael@0 | 74 | |
michael@0 | 75 | int32_t index = 0; |
michael@0 | 76 | nsGrid* grid = GetGrid(aBox, &index); |
michael@0 | 77 | |
michael@0 | 78 | if (grid) |
michael@0 | 79 | { |
michael@0 | 80 | // make sure we add in extra columns sizes as well |
michael@0 | 81 | bool isHorizontal = IsHorizontal(aBox); |
michael@0 | 82 | int32_t extraColumns = grid->GetExtraColumnCount(isHorizontal); |
michael@0 | 83 | int32_t start = grid->GetColumnCount(isHorizontal) - grid->GetExtraColumnCount(isHorizontal); |
michael@0 | 84 | for (int32_t i=0; i < extraColumns; i++) |
michael@0 | 85 | { |
michael@0 | 86 | nscoord pref = |
michael@0 | 87 | grid->GetPrefRowHeight(aState, i+start, !isHorizontal); // GetPrefColumnWidth |
michael@0 | 88 | |
michael@0 | 89 | AddWidth(vpref, pref, isHorizontal); |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | return vpref; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | nsSize |
michael@0 | 97 | nsGridRowGroupLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) |
michael@0 | 98 | { |
michael@0 | 99 | nsSize maxSize = nsGridRowLayout::GetMaxSize(aBox, aState); |
michael@0 | 100 | |
michael@0 | 101 | int32_t index = 0; |
michael@0 | 102 | nsGrid* grid = GetGrid(aBox, &index); |
michael@0 | 103 | |
michael@0 | 104 | if (grid) |
michael@0 | 105 | { |
michael@0 | 106 | // make sure we add in extra columns sizes as well |
michael@0 | 107 | bool isHorizontal = IsHorizontal(aBox); |
michael@0 | 108 | int32_t extraColumns = grid->GetExtraColumnCount(isHorizontal); |
michael@0 | 109 | int32_t start = grid->GetColumnCount(isHorizontal) - grid->GetExtraColumnCount(isHorizontal); |
michael@0 | 110 | for (int32_t i=0; i < extraColumns; i++) |
michael@0 | 111 | { |
michael@0 | 112 | nscoord max = |
michael@0 | 113 | grid->GetMaxRowHeight(aState, i+start, !isHorizontal); // GetMaxColumnWidth |
michael@0 | 114 | |
michael@0 | 115 | AddWidth(maxSize, max, isHorizontal); |
michael@0 | 116 | } |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | return maxSize; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | nsSize |
michael@0 | 123 | nsGridRowGroupLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) |
michael@0 | 124 | { |
michael@0 | 125 | nsSize minSize = nsGridRowLayout::GetMinSize(aBox, aState); |
michael@0 | 126 | |
michael@0 | 127 | int32_t index = 0; |
michael@0 | 128 | nsGrid* grid = GetGrid(aBox, &index); |
michael@0 | 129 | |
michael@0 | 130 | if (grid) |
michael@0 | 131 | { |
michael@0 | 132 | // make sure we add in extra columns sizes as well |
michael@0 | 133 | bool isHorizontal = IsHorizontal(aBox); |
michael@0 | 134 | int32_t extraColumns = grid->GetExtraColumnCount(isHorizontal); |
michael@0 | 135 | int32_t start = grid->GetColumnCount(isHorizontal) - grid->GetExtraColumnCount(isHorizontal); |
michael@0 | 136 | for (int32_t i=0; i < extraColumns; i++) |
michael@0 | 137 | { |
michael@0 | 138 | nscoord min = |
michael@0 | 139 | grid->GetMinRowHeight(aState, i+start, !isHorizontal); // GetMinColumnWidth |
michael@0 | 140 | AddWidth(minSize, min, isHorizontal); |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | return minSize; |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | /* |
michael@0 | 148 | * Run down through our children dirtying them recursively. |
michael@0 | 149 | */ |
michael@0 | 150 | void |
michael@0 | 151 | nsGridRowGroupLayout::DirtyRows(nsIFrame* aBox, nsBoxLayoutState& aState) |
michael@0 | 152 | { |
michael@0 | 153 | if (aBox) { |
michael@0 | 154 | // mark us dirty |
michael@0 | 155 | // XXXldb We probably don't want to walk up the ancestor chain |
michael@0 | 156 | // calling MarkIntrinsicWidthsDirty for every row group. |
michael@0 | 157 | aState.PresShell()->FrameNeedsReflow(aBox, nsIPresShell::eTreeChange, |
michael@0 | 158 | NS_FRAME_IS_DIRTY); |
michael@0 | 159 | nsIFrame* child = aBox->GetChildBox(); |
michael@0 | 160 | |
michael@0 | 161 | while(child) { |
michael@0 | 162 | |
michael@0 | 163 | // walk into scrollframes |
michael@0 | 164 | nsIFrame* deepChild = nsGrid::GetScrolledBox(child); |
michael@0 | 165 | |
michael@0 | 166 | // walk into other monuments |
michael@0 | 167 | nsIGridPart* monument = nsGrid::GetPartFromBox(deepChild); |
michael@0 | 168 | if (monument) |
michael@0 | 169 | monument->DirtyRows(deepChild, aState); |
michael@0 | 170 | |
michael@0 | 171 | child = child->GetNextBox(); |
michael@0 | 172 | } |
michael@0 | 173 | } |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | |
michael@0 | 177 | void |
michael@0 | 178 | nsGridRowGroupLayout::CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32_t& aComputedColumnCount) |
michael@0 | 179 | { |
michael@0 | 180 | if (aBox) { |
michael@0 | 181 | int32_t startCount = aRowCount; |
michael@0 | 182 | |
michael@0 | 183 | nsIFrame* child = aBox->GetChildBox(); |
michael@0 | 184 | |
michael@0 | 185 | while(child) { |
michael@0 | 186 | |
michael@0 | 187 | // first see if it is a scrollframe. If so walk down into it and get the scrolled child |
michael@0 | 188 | nsIFrame* deepChild = nsGrid::GetScrolledBox(child); |
michael@0 | 189 | |
michael@0 | 190 | nsIGridPart* monument = nsGrid::GetPartFromBox(deepChild); |
michael@0 | 191 | if (monument) { |
michael@0 | 192 | monument->CountRowsColumns(deepChild, aRowCount, aComputedColumnCount); |
michael@0 | 193 | child = child->GetNextBox(); |
michael@0 | 194 | deepChild = child; |
michael@0 | 195 | continue; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | child = child->GetNextBox(); |
michael@0 | 199 | |
michael@0 | 200 | // if not a monument. Then count it. It will be a bogus row |
michael@0 | 201 | aRowCount++; |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | mRowCount = aRowCount - startCount; |
michael@0 | 205 | } |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | |
michael@0 | 209 | /** |
michael@0 | 210 | * Fill out the given row structure recursively |
michael@0 | 211 | */ |
michael@0 | 212 | int32_t |
michael@0 | 213 | nsGridRowGroupLayout::BuildRows(nsIFrame* aBox, nsGridRow* aRows) |
michael@0 | 214 | { |
michael@0 | 215 | int32_t rowCount = 0; |
michael@0 | 216 | |
michael@0 | 217 | if (aBox) { |
michael@0 | 218 | nsIFrame* child = aBox->GetChildBox(); |
michael@0 | 219 | |
michael@0 | 220 | while(child) { |
michael@0 | 221 | |
michael@0 | 222 | // first see if it is a scrollframe. If so walk down into it and get the scrolled child |
michael@0 | 223 | nsIFrame* deepChild = nsGrid::GetScrolledBox(child); |
michael@0 | 224 | |
michael@0 | 225 | nsIGridPart* monument = nsGrid::GetPartFromBox(deepChild); |
michael@0 | 226 | if (monument) { |
michael@0 | 227 | rowCount += monument->BuildRows(deepChild, &aRows[rowCount]); |
michael@0 | 228 | child = child->GetNextBox(); |
michael@0 | 229 | deepChild = child; |
michael@0 | 230 | continue; |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | aRows[rowCount].Init(child, true); |
michael@0 | 234 | |
michael@0 | 235 | child = child->GetNextBox(); |
michael@0 | 236 | |
michael@0 | 237 | // if not a monument. Then count it. It will be a bogus row |
michael@0 | 238 | rowCount++; |
michael@0 | 239 | } |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | return rowCount; |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | nsMargin |
michael@0 | 246 | nsGridRowGroupLayout::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal) |
michael@0 | 247 | { |
michael@0 | 248 | // group have border and padding added to the total margin |
michael@0 | 249 | |
michael@0 | 250 | nsMargin margin = nsGridRowLayout::GetTotalMargin(aBox, aIsHorizontal); |
michael@0 | 251 | |
michael@0 | 252 | // make sure we have the scrollframe on the outside if it has one. |
michael@0 | 253 | // that's where the border is. |
michael@0 | 254 | aBox = nsGrid::GetScrollBox(aBox); |
michael@0 | 255 | |
michael@0 | 256 | // add our border/padding to it |
michael@0 | 257 | nsMargin borderPadding(0,0,0,0); |
michael@0 | 258 | aBox->GetBorderAndPadding(borderPadding); |
michael@0 | 259 | margin += borderPadding; |
michael@0 | 260 | |
michael@0 | 261 | return margin; |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 |