Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | * code for managing absolutely positioned children of a rendering |
michael@0 | 8 | * object that is a containing block for them |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include "nsAbsoluteContainingBlock.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsContainerFrame.h" |
michael@0 | 14 | #include "nsGkAtoms.h" |
michael@0 | 15 | #include "nsIPresShell.h" |
michael@0 | 16 | #include "nsHTMLReflowState.h" |
michael@0 | 17 | #include "nsPresContext.h" |
michael@0 | 18 | #include "nsCSSFrameConstructor.h" |
michael@0 | 19 | |
michael@0 | 20 | #ifdef DEBUG |
michael@0 | 21 | #include "nsBlockFrame.h" |
michael@0 | 22 | |
michael@0 | 23 | static void PrettyUC(nscoord aSize, char* aBuf) |
michael@0 | 24 | { |
michael@0 | 25 | if (NS_UNCONSTRAINEDSIZE == aSize) { |
michael@0 | 26 | strcpy(aBuf, "UC"); |
michael@0 | 27 | } else { |
michael@0 | 28 | if((int32_t)0xdeadbeef == aSize) { |
michael@0 | 29 | strcpy(aBuf, "deadbeef"); |
michael@0 | 30 | } else { |
michael@0 | 31 | sprintf(aBuf, "%d", aSize); |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | } |
michael@0 | 35 | #endif |
michael@0 | 36 | |
michael@0 | 37 | nsresult |
michael@0 | 38 | nsAbsoluteContainingBlock::SetInitialChildList(nsIFrame* aDelegatingFrame, |
michael@0 | 39 | ChildListID aListID, |
michael@0 | 40 | nsFrameList& aChildList) |
michael@0 | 41 | { |
michael@0 | 42 | NS_PRECONDITION(mChildListID == aListID, "unexpected child list name"); |
michael@0 | 43 | #ifdef DEBUG |
michael@0 | 44 | nsFrame::VerifyDirtyBitSet(aChildList); |
michael@0 | 45 | #endif |
michael@0 | 46 | mAbsoluteFrames.SetFrames(aChildList); |
michael@0 | 47 | return NS_OK; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | nsresult |
michael@0 | 51 | nsAbsoluteContainingBlock::AppendFrames(nsIFrame* aDelegatingFrame, |
michael@0 | 52 | ChildListID aListID, |
michael@0 | 53 | nsFrameList& aFrameList) |
michael@0 | 54 | { |
michael@0 | 55 | NS_ASSERTION(mChildListID == aListID, "unexpected child list"); |
michael@0 | 56 | |
michael@0 | 57 | // Append the frames to our list of absolutely positioned frames |
michael@0 | 58 | #ifdef DEBUG |
michael@0 | 59 | nsFrame::VerifyDirtyBitSet(aFrameList); |
michael@0 | 60 | #endif |
michael@0 | 61 | mAbsoluteFrames.AppendFrames(nullptr, aFrameList); |
michael@0 | 62 | |
michael@0 | 63 | // no damage to intrinsic widths, since absolutely positioned frames can't |
michael@0 | 64 | // change them |
michael@0 | 65 | aDelegatingFrame->PresContext()->PresShell()-> |
michael@0 | 66 | FrameNeedsReflow(aDelegatingFrame, nsIPresShell::eResize, |
michael@0 | 67 | NS_FRAME_HAS_DIRTY_CHILDREN); |
michael@0 | 68 | |
michael@0 | 69 | return NS_OK; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | nsresult |
michael@0 | 73 | nsAbsoluteContainingBlock::InsertFrames(nsIFrame* aDelegatingFrame, |
michael@0 | 74 | ChildListID aListID, |
michael@0 | 75 | nsIFrame* aPrevFrame, |
michael@0 | 76 | nsFrameList& aFrameList) |
michael@0 | 77 | { |
michael@0 | 78 | NS_ASSERTION(mChildListID == aListID, "unexpected child list"); |
michael@0 | 79 | NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == aDelegatingFrame, |
michael@0 | 80 | "inserting after sibling frame with different parent"); |
michael@0 | 81 | |
michael@0 | 82 | #ifdef DEBUG |
michael@0 | 83 | nsFrame::VerifyDirtyBitSet(aFrameList); |
michael@0 | 84 | #endif |
michael@0 | 85 | mAbsoluteFrames.InsertFrames(nullptr, aPrevFrame, aFrameList); |
michael@0 | 86 | |
michael@0 | 87 | // no damage to intrinsic widths, since absolutely positioned frames can't |
michael@0 | 88 | // change them |
michael@0 | 89 | aDelegatingFrame->PresContext()->PresShell()-> |
michael@0 | 90 | FrameNeedsReflow(aDelegatingFrame, nsIPresShell::eResize, |
michael@0 | 91 | NS_FRAME_HAS_DIRTY_CHILDREN); |
michael@0 | 92 | |
michael@0 | 93 | return NS_OK; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | void |
michael@0 | 97 | nsAbsoluteContainingBlock::RemoveFrame(nsIFrame* aDelegatingFrame, |
michael@0 | 98 | ChildListID aListID, |
michael@0 | 99 | nsIFrame* aOldFrame) |
michael@0 | 100 | { |
michael@0 | 101 | NS_ASSERTION(mChildListID == aListID, "unexpected child list"); |
michael@0 | 102 | nsIFrame* nif = aOldFrame->GetNextInFlow(); |
michael@0 | 103 | if (nif) { |
michael@0 | 104 | static_cast<nsContainerFrame*>(nif->GetParent()) |
michael@0 | 105 | ->DeleteNextInFlowChild(nif, false); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | mAbsoluteFrames.DestroyFrame(aOldFrame); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | nsresult |
michael@0 | 112 | nsAbsoluteContainingBlock::Reflow(nsContainerFrame* aDelegatingFrame, |
michael@0 | 113 | nsPresContext* aPresContext, |
michael@0 | 114 | const nsHTMLReflowState& aReflowState, |
michael@0 | 115 | nsReflowStatus& aReflowStatus, |
michael@0 | 116 | const nsRect& aContainingBlock, |
michael@0 | 117 | bool aConstrainHeight, |
michael@0 | 118 | bool aCBWidthChanged, |
michael@0 | 119 | bool aCBHeightChanged, |
michael@0 | 120 | nsOverflowAreas* aOverflowAreas) |
michael@0 | 121 | { |
michael@0 | 122 | nsReflowStatus reflowStatus = NS_FRAME_COMPLETE; |
michael@0 | 123 | |
michael@0 | 124 | bool reflowAll = aReflowState.ShouldReflowAllKids(); |
michael@0 | 125 | |
michael@0 | 126 | nsIFrame* kidFrame; |
michael@0 | 127 | nsOverflowContinuationTracker tracker(aDelegatingFrame, true); |
michael@0 | 128 | for (kidFrame = mAbsoluteFrames.FirstChild(); kidFrame; kidFrame = kidFrame->GetNextSibling()) { |
michael@0 | 129 | bool kidNeedsReflow = reflowAll || NS_SUBTREE_DIRTY(kidFrame) || |
michael@0 | 130 | FrameDependsOnContainer(kidFrame, aCBWidthChanged, aCBHeightChanged); |
michael@0 | 131 | if (kidNeedsReflow && !aPresContext->HasPendingInterrupt()) { |
michael@0 | 132 | // Reflow the frame |
michael@0 | 133 | nsReflowStatus kidStatus = NS_FRAME_COMPLETE; |
michael@0 | 134 | ReflowAbsoluteFrame(aDelegatingFrame, aPresContext, aReflowState, |
michael@0 | 135 | aContainingBlock, |
michael@0 | 136 | aConstrainHeight, kidFrame, kidStatus, |
michael@0 | 137 | aOverflowAreas); |
michael@0 | 138 | nsIFrame* nextFrame = kidFrame->GetNextInFlow(); |
michael@0 | 139 | if (!NS_FRAME_IS_FULLY_COMPLETE(kidStatus)) { |
michael@0 | 140 | // Need a continuation |
michael@0 | 141 | if (!nextFrame) { |
michael@0 | 142 | nextFrame = |
michael@0 | 143 | aPresContext->PresShell()->FrameConstructor()-> |
michael@0 | 144 | CreateContinuingFrame(aPresContext, kidFrame, aDelegatingFrame); |
michael@0 | 145 | } |
michael@0 | 146 | // Add it as an overflow container. |
michael@0 | 147 | //XXXfr This is a hack to fix some of our printing dataloss. |
michael@0 | 148 | // See bug 154892. Not sure how to do it "right" yet; probably want |
michael@0 | 149 | // to keep continuations within an nsAbsoluteContainingBlock eventually. |
michael@0 | 150 | tracker.Insert(nextFrame, kidStatus); |
michael@0 | 151 | NS_MergeReflowStatusInto(&reflowStatus, kidStatus); |
michael@0 | 152 | } |
michael@0 | 153 | else { |
michael@0 | 154 | // Delete any continuations |
michael@0 | 155 | if (nextFrame) { |
michael@0 | 156 | nsOverflowContinuationTracker::AutoFinish fini(&tracker, kidFrame); |
michael@0 | 157 | static_cast<nsContainerFrame*>(nextFrame->GetParent()) |
michael@0 | 158 | ->DeleteNextInFlowChild(nextFrame, true); |
michael@0 | 159 | } |
michael@0 | 160 | } |
michael@0 | 161 | } |
michael@0 | 162 | else { |
michael@0 | 163 | tracker.Skip(kidFrame, reflowStatus); |
michael@0 | 164 | if (aOverflowAreas) { |
michael@0 | 165 | aDelegatingFrame->ConsiderChildOverflow(*aOverflowAreas, kidFrame); |
michael@0 | 166 | } |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | // Make a CheckForInterrupt call, here, not just HasPendingInterrupt. That |
michael@0 | 170 | // will make sure that we end up reflowing aDelegatingFrame in cases when |
michael@0 | 171 | // one of our kids interrupted. Otherwise we'd set the dirty or |
michael@0 | 172 | // dirty-children bit on the kid in the condition below, and then when |
michael@0 | 173 | // reflow completes and we go to mark dirty bits on all ancestors of that |
michael@0 | 174 | // kid we'll immediately bail out, because the kid already has a dirty bit. |
michael@0 | 175 | // In particular, we won't set any dirty bits on aDelegatingFrame, so when |
michael@0 | 176 | // the following reflow happens we won't reflow the kid in question. This |
michael@0 | 177 | // might be slightly suboptimal in cases where |kidFrame| itself did not |
michael@0 | 178 | // interrupt, since we'll trigger a reflow of it too when it's not strictly |
michael@0 | 179 | // needed. But the logic to not do that is enough more complicated, and |
michael@0 | 180 | // the case enough of an edge case, that this is probably better. |
michael@0 | 181 | if (kidNeedsReflow && aPresContext->CheckForInterrupt(aDelegatingFrame)) { |
michael@0 | 182 | if (aDelegatingFrame->GetStateBits() & NS_FRAME_IS_DIRTY) { |
michael@0 | 183 | kidFrame->AddStateBits(NS_FRAME_IS_DIRTY); |
michael@0 | 184 | } else { |
michael@0 | 185 | kidFrame->AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN); |
michael@0 | 186 | } |
michael@0 | 187 | } |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | // Abspos frames can't cause their parent to be incomplete, |
michael@0 | 191 | // only overflow incomplete. |
michael@0 | 192 | if (NS_FRAME_IS_NOT_COMPLETE(reflowStatus)) |
michael@0 | 193 | NS_FRAME_SET_OVERFLOW_INCOMPLETE(reflowStatus); |
michael@0 | 194 | |
michael@0 | 195 | NS_MergeReflowStatusInto(&aReflowStatus, reflowStatus); |
michael@0 | 196 | return NS_OK; |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | static inline bool IsFixedPaddingSize(const nsStyleCoord& aCoord) |
michael@0 | 200 | { return aCoord.ConvertsToLength(); } |
michael@0 | 201 | static inline bool IsFixedMarginSize(const nsStyleCoord& aCoord) |
michael@0 | 202 | { return aCoord.ConvertsToLength(); } |
michael@0 | 203 | static inline bool IsFixedOffset(const nsStyleCoord& aCoord) |
michael@0 | 204 | { return aCoord.ConvertsToLength(); } |
michael@0 | 205 | |
michael@0 | 206 | bool |
michael@0 | 207 | nsAbsoluteContainingBlock::FrameDependsOnContainer(nsIFrame* f, |
michael@0 | 208 | bool aCBWidthChanged, |
michael@0 | 209 | bool aCBHeightChanged) |
michael@0 | 210 | { |
michael@0 | 211 | const nsStylePosition* pos = f->StylePosition(); |
michael@0 | 212 | // See if f's position might have changed because it depends on a |
michael@0 | 213 | // placeholder's position |
michael@0 | 214 | // This can happen in the following cases: |
michael@0 | 215 | // 1) Vertical positioning. "top" must be auto and "bottom" must be auto |
michael@0 | 216 | // (otherwise the vertical position is completely determined by |
michael@0 | 217 | // whichever of them is not auto and the height). |
michael@0 | 218 | // 2) Horizontal positioning. "left" must be auto and "right" must be auto |
michael@0 | 219 | // (otherwise the horizontal position is completely determined by |
michael@0 | 220 | // whichever of them is not auto and the width). |
michael@0 | 221 | // See nsHTMLReflowState::InitAbsoluteConstraints -- these are the |
michael@0 | 222 | // only cases when we call CalculateHypotheticalBox(). |
michael@0 | 223 | if ((pos->mOffset.GetTopUnit() == eStyleUnit_Auto && |
michael@0 | 224 | pos->mOffset.GetBottomUnit() == eStyleUnit_Auto) || |
michael@0 | 225 | (pos->mOffset.GetLeftUnit() == eStyleUnit_Auto && |
michael@0 | 226 | pos->mOffset.GetRightUnit() == eStyleUnit_Auto)) { |
michael@0 | 227 | return true; |
michael@0 | 228 | } |
michael@0 | 229 | if (!aCBWidthChanged && !aCBHeightChanged) { |
michael@0 | 230 | // skip getting style data |
michael@0 | 231 | return false; |
michael@0 | 232 | } |
michael@0 | 233 | const nsStylePadding* padding = f->StylePadding(); |
michael@0 | 234 | const nsStyleMargin* margin = f->StyleMargin(); |
michael@0 | 235 | if (aCBWidthChanged) { |
michael@0 | 236 | // See if f's width might have changed. |
michael@0 | 237 | // If border-left, border-right, padding-left, padding-right, |
michael@0 | 238 | // width, min-width, and max-width are all lengths, 'none', or enumerated, |
michael@0 | 239 | // then our frame width does not depend on the parent width. |
michael@0 | 240 | // Note that borders never depend on the parent width |
michael@0 | 241 | // XXX All of the enumerated values except -moz-available are ok too. |
michael@0 | 242 | if (pos->WidthDependsOnContainer() || |
michael@0 | 243 | pos->MinWidthDependsOnContainer() || |
michael@0 | 244 | pos->MaxWidthDependsOnContainer() || |
michael@0 | 245 | !IsFixedPaddingSize(padding->mPadding.GetLeft()) || |
michael@0 | 246 | !IsFixedPaddingSize(padding->mPadding.GetRight())) { |
michael@0 | 247 | return true; |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | // See if f's position might have changed. If we're RTL then the |
michael@0 | 251 | // rules are slightly different. We'll assume percentage or auto |
michael@0 | 252 | // margins will always induce a dependency on the size |
michael@0 | 253 | if (!IsFixedMarginSize(margin->mMargin.GetLeft()) || |
michael@0 | 254 | !IsFixedMarginSize(margin->mMargin.GetRight())) { |
michael@0 | 255 | return true; |
michael@0 | 256 | } |
michael@0 | 257 | if (f->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) { |
michael@0 | 258 | // Note that even if 'left' is a length, our position can |
michael@0 | 259 | // still depend on the containing block width, because if |
michael@0 | 260 | // 'right' is also a length we will discard 'left' and be |
michael@0 | 261 | // positioned relative to the containing block right edge. |
michael@0 | 262 | // 'left' length and 'right' auto is the only combination |
michael@0 | 263 | // we can be sure of. |
michael@0 | 264 | if (!IsFixedOffset(pos->mOffset.GetLeft()) || |
michael@0 | 265 | pos->mOffset.GetRightUnit() != eStyleUnit_Auto) { |
michael@0 | 266 | return true; |
michael@0 | 267 | } |
michael@0 | 268 | } else { |
michael@0 | 269 | if (!IsFixedOffset(pos->mOffset.GetLeft())) { |
michael@0 | 270 | return true; |
michael@0 | 271 | } |
michael@0 | 272 | } |
michael@0 | 273 | } |
michael@0 | 274 | if (aCBHeightChanged) { |
michael@0 | 275 | // See if f's height might have changed. |
michael@0 | 276 | // If border-top, border-bottom, padding-top, padding-bottom, |
michael@0 | 277 | // min-height, and max-height are all lengths or 'none', |
michael@0 | 278 | // and height is a length or height and bottom are auto and top is not auto, |
michael@0 | 279 | // then our frame height does not depend on the parent height. |
michael@0 | 280 | // Note that borders never depend on the parent height |
michael@0 | 281 | if ((pos->HeightDependsOnContainer() && |
michael@0 | 282 | !(pos->mHeight.GetUnit() == eStyleUnit_Auto && |
michael@0 | 283 | pos->mOffset.GetBottomUnit() == eStyleUnit_Auto && |
michael@0 | 284 | pos->mOffset.GetTopUnit() != eStyleUnit_Auto)) || |
michael@0 | 285 | pos->MinHeightDependsOnContainer() || |
michael@0 | 286 | pos->MaxHeightDependsOnContainer() || |
michael@0 | 287 | !IsFixedPaddingSize(padding->mPadding.GetTop()) || |
michael@0 | 288 | !IsFixedPaddingSize(padding->mPadding.GetBottom())) { |
michael@0 | 289 | return true; |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | // See if f's position might have changed. |
michael@0 | 293 | if (!IsFixedMarginSize(margin->mMargin.GetTop()) || |
michael@0 | 294 | !IsFixedMarginSize(margin->mMargin.GetBottom())) { |
michael@0 | 295 | return true; |
michael@0 | 296 | } |
michael@0 | 297 | if (!IsFixedOffset(pos->mOffset.GetTop())) { |
michael@0 | 298 | return true; |
michael@0 | 299 | } |
michael@0 | 300 | } |
michael@0 | 301 | return false; |
michael@0 | 302 | } |
michael@0 | 303 | |
michael@0 | 304 | void |
michael@0 | 305 | nsAbsoluteContainingBlock::DestroyFrames(nsIFrame* aDelegatingFrame, |
michael@0 | 306 | nsIFrame* aDestructRoot) |
michael@0 | 307 | { |
michael@0 | 308 | mAbsoluteFrames.DestroyFramesFrom(aDestructRoot); |
michael@0 | 309 | } |
michael@0 | 310 | |
michael@0 | 311 | void |
michael@0 | 312 | nsAbsoluteContainingBlock::MarkSizeDependentFramesDirty() |
michael@0 | 313 | { |
michael@0 | 314 | DoMarkFramesDirty(false); |
michael@0 | 315 | } |
michael@0 | 316 | |
michael@0 | 317 | void |
michael@0 | 318 | nsAbsoluteContainingBlock::MarkAllFramesDirty() |
michael@0 | 319 | { |
michael@0 | 320 | DoMarkFramesDirty(true); |
michael@0 | 321 | } |
michael@0 | 322 | |
michael@0 | 323 | void |
michael@0 | 324 | nsAbsoluteContainingBlock::DoMarkFramesDirty(bool aMarkAllDirty) |
michael@0 | 325 | { |
michael@0 | 326 | for (nsIFrame* kidFrame = mAbsoluteFrames.FirstChild(); |
michael@0 | 327 | kidFrame; |
michael@0 | 328 | kidFrame = kidFrame->GetNextSibling()) { |
michael@0 | 329 | if (aMarkAllDirty) { |
michael@0 | 330 | kidFrame->AddStateBits(NS_FRAME_IS_DIRTY); |
michael@0 | 331 | } else if (FrameDependsOnContainer(kidFrame, true, true)) { |
michael@0 | 332 | // Add the weakest flags that will make sure we reflow this frame later |
michael@0 | 333 | kidFrame->AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN); |
michael@0 | 334 | } |
michael@0 | 335 | } |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | // XXX Optimize the case where it's a resize reflow and the absolutely |
michael@0 | 339 | // positioned child has the exact same size and position and skip the |
michael@0 | 340 | // reflow... |
michael@0 | 341 | |
michael@0 | 342 | // When bug 154892 is checked in, make sure that when |
michael@0 | 343 | // mChildListID == kFixedList, the height is unconstrained. |
michael@0 | 344 | // since we don't allow replicated frames to split. |
michael@0 | 345 | |
michael@0 | 346 | nsresult |
michael@0 | 347 | nsAbsoluteContainingBlock::ReflowAbsoluteFrame(nsIFrame* aDelegatingFrame, |
michael@0 | 348 | nsPresContext* aPresContext, |
michael@0 | 349 | const nsHTMLReflowState& aReflowState, |
michael@0 | 350 | const nsRect& aContainingBlock, |
michael@0 | 351 | bool aConstrainHeight, |
michael@0 | 352 | nsIFrame* aKidFrame, |
michael@0 | 353 | nsReflowStatus& aStatus, |
michael@0 | 354 | nsOverflowAreas* aOverflowAreas) |
michael@0 | 355 | { |
michael@0 | 356 | #ifdef DEBUG |
michael@0 | 357 | if (nsBlockFrame::gNoisyReflow) { |
michael@0 | 358 | nsFrame::IndentBy(stdout,nsBlockFrame::gNoiseIndent); |
michael@0 | 359 | printf("abs pos "); |
michael@0 | 360 | if (aKidFrame) { |
michael@0 | 361 | nsAutoString name; |
michael@0 | 362 | aKidFrame->GetFrameName(name); |
michael@0 | 363 | printf("%s ", NS_LossyConvertUTF16toASCII(name).get()); |
michael@0 | 364 | } |
michael@0 | 365 | |
michael@0 | 366 | char width[16]; |
michael@0 | 367 | char height[16]; |
michael@0 | 368 | PrettyUC(aReflowState.AvailableWidth(), width); |
michael@0 | 369 | PrettyUC(aReflowState.AvailableHeight(), height); |
michael@0 | 370 | printf(" a=%s,%s ", width, height); |
michael@0 | 371 | PrettyUC(aReflowState.ComputedWidth(), width); |
michael@0 | 372 | PrettyUC(aReflowState.ComputedHeight(), height); |
michael@0 | 373 | printf("c=%s,%s \n", width, height); |
michael@0 | 374 | } |
michael@0 | 375 | AutoNoisyIndenter indent(nsBlockFrame::gNoisy); |
michael@0 | 376 | #endif // DEBUG |
michael@0 | 377 | |
michael@0 | 378 | nscoord availWidth = aContainingBlock.width; |
michael@0 | 379 | if (availWidth == -1) { |
michael@0 | 380 | NS_ASSERTION(aReflowState.ComputedWidth() != NS_UNCONSTRAINEDSIZE, |
michael@0 | 381 | "Must have a useful width _somewhere_"); |
michael@0 | 382 | availWidth = |
michael@0 | 383 | aReflowState.ComputedWidth() + aReflowState.ComputedPhysicalPadding().LeftRight(); |
michael@0 | 384 | } |
michael@0 | 385 | |
michael@0 | 386 | nsHTMLReflowMetrics kidDesiredSize(aReflowState); |
michael@0 | 387 | nsHTMLReflowState kidReflowState(aPresContext, aReflowState, aKidFrame, |
michael@0 | 388 | nsSize(availWidth, NS_UNCONSTRAINEDSIZE), |
michael@0 | 389 | aContainingBlock.width, |
michael@0 | 390 | aContainingBlock.height); |
michael@0 | 391 | |
michael@0 | 392 | // Send the WillReflow() notification and position the frame |
michael@0 | 393 | aKidFrame->WillReflow(aPresContext); |
michael@0 | 394 | |
michael@0 | 395 | // Get the border values |
michael@0 | 396 | const nsMargin& border = aReflowState.mStyleBorder->GetComputedBorder(); |
michael@0 | 397 | |
michael@0 | 398 | bool constrainHeight = (aReflowState.AvailableHeight() != NS_UNCONSTRAINEDSIZE) |
michael@0 | 399 | && aConstrainHeight |
michael@0 | 400 | // Don't split if told not to (e.g. for fixed frames) |
michael@0 | 401 | && (aDelegatingFrame->GetType() != nsGkAtoms::inlineFrame) |
michael@0 | 402 | //XXX we don't handle splitting frames for inline absolute containing blocks yet |
michael@0 | 403 | && (aKidFrame->GetRect().y <= aReflowState.AvailableHeight()); |
michael@0 | 404 | // Don't split things below the fold. (Ideally we shouldn't *have* |
michael@0 | 405 | // anything totally below the fold, but we can't position frames |
michael@0 | 406 | // across next-in-flow breaks yet. |
michael@0 | 407 | if (constrainHeight) { |
michael@0 | 408 | kidReflowState.AvailableHeight() = aReflowState.AvailableHeight() - border.top |
michael@0 | 409 | - kidReflowState.ComputedPhysicalMargin().top; |
michael@0 | 410 | if (NS_AUTOOFFSET != kidReflowState.ComputedPhysicalOffsets().top) |
michael@0 | 411 | kidReflowState.AvailableHeight() -= kidReflowState.ComputedPhysicalOffsets().top; |
michael@0 | 412 | } |
michael@0 | 413 | |
michael@0 | 414 | // Do the reflow |
michael@0 | 415 | nsresult rv = aKidFrame->Reflow(aPresContext, kidDesiredSize, kidReflowState, aStatus); |
michael@0 | 416 | |
michael@0 | 417 | // If we're solving for 'left' or 'top', then compute it now that we know the |
michael@0 | 418 | // width/height |
michael@0 | 419 | if ((NS_AUTOOFFSET == kidReflowState.ComputedPhysicalOffsets().left) || |
michael@0 | 420 | (NS_AUTOOFFSET == kidReflowState.ComputedPhysicalOffsets().top)) { |
michael@0 | 421 | nscoord aContainingBlockWidth = aContainingBlock.width; |
michael@0 | 422 | nscoord aContainingBlockHeight = aContainingBlock.height; |
michael@0 | 423 | |
michael@0 | 424 | if (-1 == aContainingBlockWidth) { |
michael@0 | 425 | // Get the containing block width/height |
michael@0 | 426 | kidReflowState.ComputeContainingBlockRectangle(aPresContext, |
michael@0 | 427 | &aReflowState, |
michael@0 | 428 | aContainingBlockWidth, |
michael@0 | 429 | aContainingBlockHeight); |
michael@0 | 430 | } |
michael@0 | 431 | |
michael@0 | 432 | if (NS_AUTOOFFSET == kidReflowState.ComputedPhysicalOffsets().left) { |
michael@0 | 433 | NS_ASSERTION(NS_AUTOOFFSET != kidReflowState.ComputedPhysicalOffsets().right, |
michael@0 | 434 | "Can't solve for both left and right"); |
michael@0 | 435 | kidReflowState.ComputedPhysicalOffsets().left = aContainingBlockWidth - |
michael@0 | 436 | kidReflowState.ComputedPhysicalOffsets().right - |
michael@0 | 437 | kidReflowState.ComputedPhysicalMargin().right - |
michael@0 | 438 | kidDesiredSize.Width() - |
michael@0 | 439 | kidReflowState.ComputedPhysicalMargin().left; |
michael@0 | 440 | } |
michael@0 | 441 | if (NS_AUTOOFFSET == kidReflowState.ComputedPhysicalOffsets().top) { |
michael@0 | 442 | kidReflowState.ComputedPhysicalOffsets().top = aContainingBlockHeight - |
michael@0 | 443 | kidReflowState.ComputedPhysicalOffsets().bottom - |
michael@0 | 444 | kidReflowState.ComputedPhysicalMargin().bottom - |
michael@0 | 445 | kidDesiredSize.Height() - |
michael@0 | 446 | kidReflowState.ComputedPhysicalMargin().top; |
michael@0 | 447 | } |
michael@0 | 448 | } |
michael@0 | 449 | |
michael@0 | 450 | // Position the child relative to our padding edge |
michael@0 | 451 | nsRect rect(border.left + kidReflowState.ComputedPhysicalOffsets().left + kidReflowState.ComputedPhysicalMargin().left, |
michael@0 | 452 | border.top + kidReflowState.ComputedPhysicalOffsets().top + kidReflowState.ComputedPhysicalMargin().top, |
michael@0 | 453 | kidDesiredSize.Width(), kidDesiredSize.Height()); |
michael@0 | 454 | |
michael@0 | 455 | // Offset the frame rect by the given origin of the absolute containing block. |
michael@0 | 456 | // If the frame is auto-positioned on both sides of an axis, it will be |
michael@0 | 457 | // positioned based on its containing block and we don't need to offset. |
michael@0 | 458 | if (aContainingBlock.TopLeft() != nsPoint(0, 0)) { |
michael@0 | 459 | if (!(kidReflowState.mStylePosition->mOffset.GetLeftUnit() == eStyleUnit_Auto && |
michael@0 | 460 | kidReflowState.mStylePosition->mOffset.GetRightUnit() == eStyleUnit_Auto)) { |
michael@0 | 461 | rect.x += aContainingBlock.x; |
michael@0 | 462 | } |
michael@0 | 463 | if (!(kidReflowState.mStylePosition->mOffset.GetTopUnit() == eStyleUnit_Auto && |
michael@0 | 464 | kidReflowState.mStylePosition->mOffset.GetBottomUnit() == eStyleUnit_Auto)) { |
michael@0 | 465 | rect.y += aContainingBlock.y; |
michael@0 | 466 | } |
michael@0 | 467 | } |
michael@0 | 468 | |
michael@0 | 469 | aKidFrame->SetRect(rect); |
michael@0 | 470 | |
michael@0 | 471 | nsView* view = aKidFrame->GetView(); |
michael@0 | 472 | if (view) { |
michael@0 | 473 | // Size and position the view and set its opacity, visibility, content |
michael@0 | 474 | // transparency, and clip |
michael@0 | 475 | nsContainerFrame::SyncFrameViewAfterReflow(aPresContext, aKidFrame, view, |
michael@0 | 476 | kidDesiredSize.VisualOverflow()); |
michael@0 | 477 | } else { |
michael@0 | 478 | nsContainerFrame::PositionChildViews(aKidFrame); |
michael@0 | 479 | } |
michael@0 | 480 | |
michael@0 | 481 | aKidFrame->DidReflow(aPresContext, &kidReflowState, nsDidReflowStatus::FINISHED); |
michael@0 | 482 | |
michael@0 | 483 | #ifdef DEBUG |
michael@0 | 484 | if (nsBlockFrame::gNoisyReflow) { |
michael@0 | 485 | nsFrame::IndentBy(stdout,nsBlockFrame::gNoiseIndent - 1); |
michael@0 | 486 | printf("abs pos "); |
michael@0 | 487 | if (aKidFrame) { |
michael@0 | 488 | nsAutoString name; |
michael@0 | 489 | aKidFrame->GetFrameName(name); |
michael@0 | 490 | printf("%s ", NS_LossyConvertUTF16toASCII(name).get()); |
michael@0 | 491 | } |
michael@0 | 492 | printf("%p rect=%d,%d,%d,%d\n", static_cast<void*>(aKidFrame), |
michael@0 | 493 | rect.x, rect.y, rect.width, rect.height); |
michael@0 | 494 | } |
michael@0 | 495 | #endif |
michael@0 | 496 | |
michael@0 | 497 | if (aOverflowAreas) { |
michael@0 | 498 | aOverflowAreas->UnionWith(kidDesiredSize.mOverflowAreas + rect.TopLeft()); |
michael@0 | 499 | } |
michael@0 | 500 | |
michael@0 | 501 | return rv; |
michael@0 | 502 | } |