Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 | #include "nsGridLayout2.h" |
michael@0 | 14 | #include "nsGridRowGroupLayout.h" |
michael@0 | 15 | #include "nsGridRow.h" |
michael@0 | 16 | #include "nsBox.h" |
michael@0 | 17 | #include "nsIScrollableFrame.h" |
michael@0 | 18 | #include "nsSprocketLayout.h" |
michael@0 | 19 | #include "nsHTMLReflowState.h" |
michael@0 | 20 | |
michael@0 | 21 | nsresult |
michael@0 | 22 | NS_NewGridLayout2( nsIPresShell* aPresShell, nsBoxLayout** aNewLayout) |
michael@0 | 23 | { |
michael@0 | 24 | *aNewLayout = new nsGridLayout2(aPresShell); |
michael@0 | 25 | NS_IF_ADDREF(*aNewLayout); |
michael@0 | 26 | |
michael@0 | 27 | return NS_OK; |
michael@0 | 28 | |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | nsGridLayout2::nsGridLayout2(nsIPresShell* aPresShell):nsStackLayout() |
michael@0 | 32 | { |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | // static |
michael@0 | 36 | void |
michael@0 | 37 | nsGridLayout2::AddOffset(nsBoxLayoutState& aState, nsIFrame* aChild, nsSize& aSize) |
michael@0 | 38 | { |
michael@0 | 39 | nsMargin offset; |
michael@0 | 40 | GetOffset(aState, aChild, offset); |
michael@0 | 41 | aSize.width += offset.left; |
michael@0 | 42 | aSize.height += offset.top; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | NS_IMETHODIMP |
michael@0 | 46 | nsGridLayout2::Layout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) |
michael@0 | 47 | { |
michael@0 | 48 | // XXX This should be set a better way! |
michael@0 | 49 | mGrid.SetBox(aBox); |
michael@0 | 50 | NS_ASSERTION(aBox->GetLayoutManager() == this, "setting incorrect box"); |
michael@0 | 51 | |
michael@0 | 52 | nsresult rv = nsStackLayout::Layout(aBox, aBoxLayoutState); |
michael@0 | 53 | #ifdef DEBUG_grid |
michael@0 | 54 | mGrid.PrintCellMap(); |
michael@0 | 55 | #endif |
michael@0 | 56 | return rv; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | void |
michael@0 | 60 | nsGridLayout2::IntrinsicWidthsDirty(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState) |
michael@0 | 61 | { |
michael@0 | 62 | nsStackLayout::IntrinsicWidthsDirty(aBox, aBoxLayoutState); |
michael@0 | 63 | // XXXldb We really don't need to do all the work that NeedsRebuild |
michael@0 | 64 | // does; we just need to mark intrinsic widths dirty on the |
michael@0 | 65 | // (row/column)(s/-groups). |
michael@0 | 66 | mGrid.NeedsRebuild(aBoxLayoutState); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | nsGrid* |
michael@0 | 70 | nsGridLayout2::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequestor) |
michael@0 | 71 | { |
michael@0 | 72 | // XXX This should be set a better way! |
michael@0 | 73 | mGrid.SetBox(aBox); |
michael@0 | 74 | NS_ASSERTION(aBox->GetLayoutManager() == this, "setting incorrect box"); |
michael@0 | 75 | return &mGrid; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | void |
michael@0 | 79 | nsGridLayout2::AddWidth(nsSize& aSize, nscoord aSize2, bool aIsHorizontal) |
michael@0 | 80 | { |
michael@0 | 81 | nscoord& size = GET_WIDTH(aSize, aIsHorizontal); |
michael@0 | 82 | |
michael@0 | 83 | if (size != NS_INTRINSICSIZE) { |
michael@0 | 84 | if (aSize2 == NS_INTRINSICSIZE) |
michael@0 | 85 | size = NS_INTRINSICSIZE; |
michael@0 | 86 | else |
michael@0 | 87 | size += aSize2; |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | nsSize |
michael@0 | 92 | nsGridLayout2::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState) |
michael@0 | 93 | { |
michael@0 | 94 | nsSize minSize = nsStackLayout::GetMinSize(aBox, aState); |
michael@0 | 95 | |
michael@0 | 96 | // if there are no <rows> tags that will sum up our columns, |
michael@0 | 97 | // sum up our columns here. |
michael@0 | 98 | nsSize total(0,0); |
michael@0 | 99 | nsIFrame* rowsBox = mGrid.GetRowsBox(); |
michael@0 | 100 | nsIFrame* columnsBox = mGrid.GetColumnsBox(); |
michael@0 | 101 | if (!rowsBox || !columnsBox) { |
michael@0 | 102 | if (!rowsBox) { |
michael@0 | 103 | // max height is the sum of our rows |
michael@0 | 104 | int32_t rows = mGrid.GetRowCount(); |
michael@0 | 105 | for (int32_t i=0; i < rows; i++) |
michael@0 | 106 | { |
michael@0 | 107 | nscoord height = mGrid.GetMinRowHeight(aState, i, true); |
michael@0 | 108 | AddWidth(total, height, false); // AddHeight |
michael@0 | 109 | } |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | if (!columnsBox) { |
michael@0 | 113 | // max height is the sum of our rows |
michael@0 | 114 | int32_t columns = mGrid.GetColumnCount(); |
michael@0 | 115 | for (int32_t i=0; i < columns; i++) |
michael@0 | 116 | { |
michael@0 | 117 | nscoord width = mGrid.GetMinRowHeight(aState, i, false); |
michael@0 | 118 | AddWidth(total, width, true); // AddWidth |
michael@0 | 119 | } |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | AddMargin(aBox, total); |
michael@0 | 123 | AddOffset(aState, aBox, total); |
michael@0 | 124 | AddLargestSize(minSize, total); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | return minSize; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | nsSize |
michael@0 | 131 | nsGridLayout2::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState) |
michael@0 | 132 | { |
michael@0 | 133 | nsSize pref = nsStackLayout::GetPrefSize(aBox, aState); |
michael@0 | 134 | |
michael@0 | 135 | // if there are no <rows> tags that will sum up our columns, |
michael@0 | 136 | // sum up our columns here. |
michael@0 | 137 | nsSize total(0,0); |
michael@0 | 138 | nsIFrame* rowsBox = mGrid.GetRowsBox(); |
michael@0 | 139 | nsIFrame* columnsBox = mGrid.GetColumnsBox(); |
michael@0 | 140 | if (!rowsBox || !columnsBox) { |
michael@0 | 141 | if (!rowsBox) { |
michael@0 | 142 | // max height is the sum of our rows |
michael@0 | 143 | int32_t rows = mGrid.GetRowCount(); |
michael@0 | 144 | for (int32_t i=0; i < rows; i++) |
michael@0 | 145 | { |
michael@0 | 146 | nscoord height = mGrid.GetPrefRowHeight(aState, i, true); |
michael@0 | 147 | AddWidth(total, height, false); // AddHeight |
michael@0 | 148 | } |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | if (!columnsBox) { |
michael@0 | 152 | // max height is the sum of our rows |
michael@0 | 153 | int32_t columns = mGrid.GetColumnCount(); |
michael@0 | 154 | for (int32_t i=0; i < columns; i++) |
michael@0 | 155 | { |
michael@0 | 156 | nscoord width = mGrid.GetPrefRowHeight(aState, i, false); |
michael@0 | 157 | AddWidth(total, width, true); // AddWidth |
michael@0 | 158 | } |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | AddMargin(aBox, total); |
michael@0 | 162 | AddOffset(aState, aBox, total); |
michael@0 | 163 | AddLargestSize(pref, total); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | return pref; |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | nsSize |
michael@0 | 170 | nsGridLayout2::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState) |
michael@0 | 171 | { |
michael@0 | 172 | nsSize maxSize = nsStackLayout::GetMaxSize(aBox, aState); |
michael@0 | 173 | |
michael@0 | 174 | // if there are no <rows> tags that will sum up our columns, |
michael@0 | 175 | // sum up our columns here. |
michael@0 | 176 | nsSize total(NS_INTRINSICSIZE, NS_INTRINSICSIZE); |
michael@0 | 177 | nsIFrame* rowsBox = mGrid.GetRowsBox(); |
michael@0 | 178 | nsIFrame* columnsBox = mGrid.GetColumnsBox(); |
michael@0 | 179 | if (!rowsBox || !columnsBox) { |
michael@0 | 180 | if (!rowsBox) { |
michael@0 | 181 | total.height = 0; |
michael@0 | 182 | // max height is the sum of our rows |
michael@0 | 183 | int32_t rows = mGrid.GetRowCount(); |
michael@0 | 184 | for (int32_t i=0; i < rows; i++) |
michael@0 | 185 | { |
michael@0 | 186 | nscoord height = mGrid.GetMaxRowHeight(aState, i, true); |
michael@0 | 187 | AddWidth(total, height, false); // AddHeight |
michael@0 | 188 | } |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | if (!columnsBox) { |
michael@0 | 192 | total.width = 0; |
michael@0 | 193 | // max height is the sum of our rows |
michael@0 | 194 | int32_t columns = mGrid.GetColumnCount(); |
michael@0 | 195 | for (int32_t i=0; i < columns; i++) |
michael@0 | 196 | { |
michael@0 | 197 | nscoord width = mGrid.GetMaxRowHeight(aState, i, false); |
michael@0 | 198 | AddWidth(total, width, true); // AddWidth |
michael@0 | 199 | } |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | AddMargin(aBox, total); |
michael@0 | 203 | AddOffset(aState, aBox, total); |
michael@0 | 204 | AddSmallestSize(maxSize, total); |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | return maxSize; |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | int32_t |
michael@0 | 211 | nsGridLayout2::BuildRows(nsIFrame* aBox, nsGridRow* aRows) |
michael@0 | 212 | { |
michael@0 | 213 | if (aBox) { |
michael@0 | 214 | aRows[0].Init(aBox, true); |
michael@0 | 215 | return 1; |
michael@0 | 216 | } |
michael@0 | 217 | return 0; |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | nsMargin |
michael@0 | 221 | nsGridLayout2::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal) |
michael@0 | 222 | { |
michael@0 | 223 | nsMargin margin(0,0,0,0); |
michael@0 | 224 | return margin; |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | void |
michael@0 | 228 | nsGridLayout2::ChildrenInserted(nsIFrame* aBox, nsBoxLayoutState& aState, |
michael@0 | 229 | nsIFrame* aPrevBox, |
michael@0 | 230 | const nsFrameList::Slice& aNewChildren) |
michael@0 | 231 | { |
michael@0 | 232 | mGrid.NeedsRebuild(aState); |
michael@0 | 233 | } |
michael@0 | 234 | |
michael@0 | 235 | void |
michael@0 | 236 | nsGridLayout2::ChildrenAppended(nsIFrame* aBox, nsBoxLayoutState& aState, |
michael@0 | 237 | const nsFrameList::Slice& aNewChildren) |
michael@0 | 238 | { |
michael@0 | 239 | mGrid.NeedsRebuild(aState); |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | void |
michael@0 | 243 | nsGridLayout2::ChildrenRemoved(nsIFrame* aBox, nsBoxLayoutState& aState, |
michael@0 | 244 | nsIFrame* aChildList) |
michael@0 | 245 | { |
michael@0 | 246 | mGrid.NeedsRebuild(aState); |
michael@0 | 247 | } |
michael@0 | 248 | |
michael@0 | 249 | void |
michael@0 | 250 | nsGridLayout2::ChildrenSet(nsIFrame* aBox, nsBoxLayoutState& aState, |
michael@0 | 251 | nsIFrame* aChildList) |
michael@0 | 252 | { |
michael@0 | 253 | mGrid.NeedsRebuild(aState); |
michael@0 | 254 | } |
michael@0 | 255 | |
michael@0 | 256 | NS_IMPL_ADDREF_INHERITED(nsGridLayout2, nsStackLayout) |
michael@0 | 257 | NS_IMPL_RELEASE_INHERITED(nsGridLayout2, nsStackLayout) |
michael@0 | 258 | |
michael@0 | 259 | NS_INTERFACE_MAP_BEGIN(nsGridLayout2) |
michael@0 | 260 | NS_INTERFACE_MAP_ENTRY(nsIGridPart) |
michael@0 | 261 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart) |
michael@0 | 262 | NS_INTERFACE_MAP_END_INHERITING(nsStackLayout) |