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 | /* rendering object for CSS display:inline objects */ |
michael@0 | 7 | |
michael@0 | 8 | #include "nsInlineFrame.h" |
michael@0 | 9 | #include "nsLineLayout.h" |
michael@0 | 10 | #include "nsBlockFrame.h" |
michael@0 | 11 | #include "nsPlaceholderFrame.h" |
michael@0 | 12 | #include "nsGkAtoms.h" |
michael@0 | 13 | #include "nsStyleContext.h" |
michael@0 | 14 | #include "nsPresContext.h" |
michael@0 | 15 | #include "nsRenderingContext.h" |
michael@0 | 16 | #include "nsCSSAnonBoxes.h" |
michael@0 | 17 | #include "nsAutoPtr.h" |
michael@0 | 18 | #include "RestyleManager.h" |
michael@0 | 19 | #include "nsDisplayList.h" |
michael@0 | 20 | #include "mozilla/Likely.h" |
michael@0 | 21 | |
michael@0 | 22 | #ifdef DEBUG |
michael@0 | 23 | #undef NOISY_PUSHING |
michael@0 | 24 | #endif |
michael@0 | 25 | |
michael@0 | 26 | using namespace mozilla; |
michael@0 | 27 | using namespace mozilla::layout; |
michael@0 | 28 | |
michael@0 | 29 | |
michael@0 | 30 | ////////////////////////////////////////////////////////////////////// |
michael@0 | 31 | |
michael@0 | 32 | // Basic nsInlineFrame methods |
michael@0 | 33 | |
michael@0 | 34 | nsIFrame* |
michael@0 | 35 | NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 36 | { |
michael@0 | 37 | return new (aPresShell) nsInlineFrame(aContext); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | NS_IMPL_FRAMEARENA_HELPERS(nsInlineFrame) |
michael@0 | 41 | |
michael@0 | 42 | NS_QUERYFRAME_HEAD(nsInlineFrame) |
michael@0 | 43 | NS_QUERYFRAME_ENTRY(nsInlineFrame) |
michael@0 | 44 | NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame) |
michael@0 | 45 | |
michael@0 | 46 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 47 | nsresult |
michael@0 | 48 | nsInlineFrame::GetFrameName(nsAString& aResult) const |
michael@0 | 49 | { |
michael@0 | 50 | return MakeFrameName(NS_LITERAL_STRING("Inline"), aResult); |
michael@0 | 51 | } |
michael@0 | 52 | #endif |
michael@0 | 53 | |
michael@0 | 54 | nsIAtom* |
michael@0 | 55 | nsInlineFrame::GetType() const |
michael@0 | 56 | { |
michael@0 | 57 | return nsGkAtoms::inlineFrame; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | void |
michael@0 | 61 | nsInlineFrame::InvalidateFrame(uint32_t aDisplayItemKey) |
michael@0 | 62 | { |
michael@0 | 63 | if (IsSVGText()) { |
michael@0 | 64 | nsIFrame* svgTextFrame = |
michael@0 | 65 | nsLayoutUtils::GetClosestFrameOfType(GetParent(), |
michael@0 | 66 | nsGkAtoms::svgTextFrame); |
michael@0 | 67 | svgTextFrame->InvalidateFrame(); |
michael@0 | 68 | return; |
michael@0 | 69 | } |
michael@0 | 70 | nsInlineFrameBase::InvalidateFrame(aDisplayItemKey); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | void |
michael@0 | 74 | nsInlineFrame::InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey) |
michael@0 | 75 | { |
michael@0 | 76 | if (IsSVGText()) { |
michael@0 | 77 | nsIFrame* svgTextFrame = |
michael@0 | 78 | nsLayoutUtils::GetClosestFrameOfType(GetParent(), |
michael@0 | 79 | nsGkAtoms::svgTextFrame); |
michael@0 | 80 | svgTextFrame->InvalidateFrame(); |
michael@0 | 81 | return; |
michael@0 | 82 | } |
michael@0 | 83 | nsInlineFrameBase::InvalidateFrameWithRect(aRect, aDisplayItemKey); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | static inline bool |
michael@0 | 87 | IsMarginZero(const nsStyleCoord &aCoord) |
michael@0 | 88 | { |
michael@0 | 89 | return aCoord.GetUnit() == eStyleUnit_Auto || |
michael@0 | 90 | nsLayoutUtils::IsMarginZero(aCoord); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | /* virtual */ bool |
michael@0 | 94 | nsInlineFrame::IsSelfEmpty() |
michael@0 | 95 | { |
michael@0 | 96 | #if 0 |
michael@0 | 97 | // I used to think inline frames worked this way, but it seems they |
michael@0 | 98 | // don't. At least not in our codebase. |
michael@0 | 99 | if (GetPresContext()->CompatibilityMode() == eCompatibility_FullStandards) { |
michael@0 | 100 | return false; |
michael@0 | 101 | } |
michael@0 | 102 | #endif |
michael@0 | 103 | const nsStyleMargin* margin = StyleMargin(); |
michael@0 | 104 | const nsStyleBorder* border = StyleBorder(); |
michael@0 | 105 | const nsStylePadding* padding = StylePadding(); |
michael@0 | 106 | // XXX Top and bottom removed, since they shouldn't affect things, but this |
michael@0 | 107 | // doesn't really match with nsLineLayout.cpp's setting of |
michael@0 | 108 | // ZeroEffectiveSpanBox, anymore, so what should this really be? |
michael@0 | 109 | bool haveRight = |
michael@0 | 110 | border->GetComputedBorderWidth(NS_SIDE_RIGHT) != 0 || |
michael@0 | 111 | !nsLayoutUtils::IsPaddingZero(padding->mPadding.GetRight()) || |
michael@0 | 112 | !IsMarginZero(margin->mMargin.GetRight()); |
michael@0 | 113 | bool haveLeft = |
michael@0 | 114 | border->GetComputedBorderWidth(NS_SIDE_LEFT) != 0 || |
michael@0 | 115 | !nsLayoutUtils::IsPaddingZero(padding->mPadding.GetLeft()) || |
michael@0 | 116 | !IsMarginZero(margin->mMargin.GetLeft()); |
michael@0 | 117 | if (haveLeft || haveRight) { |
michael@0 | 118 | if (GetStateBits() & NS_FRAME_PART_OF_IBSPLIT) { |
michael@0 | 119 | bool haveStart, haveEnd; |
michael@0 | 120 | if (NS_STYLE_DIRECTION_LTR == StyleVisibility()->mDirection) { |
michael@0 | 121 | haveStart = haveLeft; |
michael@0 | 122 | haveEnd = haveRight; |
michael@0 | 123 | } else { |
michael@0 | 124 | haveStart = haveRight; |
michael@0 | 125 | haveEnd = haveLeft; |
michael@0 | 126 | } |
michael@0 | 127 | // For ib-split frames, ignore things we know we'll skip in GetSkipSides. |
michael@0 | 128 | // XXXbz should we be doing this for non-ib-split frames too, in a more |
michael@0 | 129 | // general way? |
michael@0 | 130 | |
michael@0 | 131 | // Get the first continuation eagerly, as a performance optimization, to |
michael@0 | 132 | // avoid having to get it twice.. |
michael@0 | 133 | nsIFrame* firstCont = FirstContinuation(); |
michael@0 | 134 | return |
michael@0 | 135 | (!haveStart || firstCont->FrameIsNonFirstInIBSplit()) && |
michael@0 | 136 | (!haveEnd || firstCont->FrameIsNonLastInIBSplit()); |
michael@0 | 137 | } |
michael@0 | 138 | return false; |
michael@0 | 139 | } |
michael@0 | 140 | return true; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | bool |
michael@0 | 144 | nsInlineFrame::IsEmpty() |
michael@0 | 145 | { |
michael@0 | 146 | if (!IsSelfEmpty()) { |
michael@0 | 147 | return false; |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | for (nsIFrame *kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) { |
michael@0 | 151 | if (!kid->IsEmpty()) |
michael@0 | 152 | return false; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | return true; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | nsIFrame::FrameSearchResult |
michael@0 | 159 | nsInlineFrame::PeekOffsetCharacter(bool aForward, int32_t* aOffset, |
michael@0 | 160 | bool aRespectClusters) |
michael@0 | 161 | { |
michael@0 | 162 | // Override the implementation in nsFrame, to skip empty inline frames |
michael@0 | 163 | NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range"); |
michael@0 | 164 | int32_t startOffset = *aOffset; |
michael@0 | 165 | if (startOffset < 0) |
michael@0 | 166 | startOffset = 1; |
michael@0 | 167 | if (aForward == (startOffset == 0)) { |
michael@0 | 168 | // We're before the frame and moving forward, or after it and moving backwards: |
michael@0 | 169 | // skip to the other side, but keep going. |
michael@0 | 170 | *aOffset = 1 - startOffset; |
michael@0 | 171 | } |
michael@0 | 172 | return CONTINUE; |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | void |
michael@0 | 176 | nsInlineFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, |
michael@0 | 177 | const nsRect& aDirtyRect, |
michael@0 | 178 | const nsDisplayListSet& aLists) |
michael@0 | 179 | { |
michael@0 | 180 | BuildDisplayListForInline(aBuilder, aDirtyRect, aLists); |
michael@0 | 181 | |
michael@0 | 182 | // The sole purpose of this is to trigger display of the selection |
michael@0 | 183 | // window for Named Anchors, which don't have any children and |
michael@0 | 184 | // normally don't have any size, but in Editor we use CSS to display |
michael@0 | 185 | // an image to represent this "hidden" element. |
michael@0 | 186 | if (!mFrames.FirstChild()) { |
michael@0 | 187 | DisplaySelectionOverlay(aBuilder, aLists.Content()); |
michael@0 | 188 | } |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | ////////////////////////////////////////////////////////////////////// |
michael@0 | 192 | // Reflow methods |
michael@0 | 193 | |
michael@0 | 194 | /* virtual */ void |
michael@0 | 195 | nsInlineFrame::AddInlineMinWidth(nsRenderingContext *aRenderingContext, |
michael@0 | 196 | nsIFrame::InlineMinWidthData *aData) |
michael@0 | 197 | { |
michael@0 | 198 | DoInlineIntrinsicWidth(aRenderingContext, aData, nsLayoutUtils::MIN_WIDTH); |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | /* virtual */ void |
michael@0 | 202 | nsInlineFrame::AddInlinePrefWidth(nsRenderingContext *aRenderingContext, |
michael@0 | 203 | nsIFrame::InlinePrefWidthData *aData) |
michael@0 | 204 | { |
michael@0 | 205 | DoInlineIntrinsicWidth(aRenderingContext, aData, nsLayoutUtils::PREF_WIDTH); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | /* virtual */ nsSize |
michael@0 | 209 | nsInlineFrame::ComputeSize(nsRenderingContext *aRenderingContext, |
michael@0 | 210 | nsSize aCBSize, nscoord aAvailableWidth, |
michael@0 | 211 | nsSize aMargin, nsSize aBorder, nsSize aPadding, |
michael@0 | 212 | uint32_t aFlags) |
michael@0 | 213 | { |
michael@0 | 214 | // Inlines and text don't compute size before reflow. |
michael@0 | 215 | return nsSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE); |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | nsRect |
michael@0 | 219 | nsInlineFrame::ComputeTightBounds(gfxContext* aContext) const |
michael@0 | 220 | { |
michael@0 | 221 | // be conservative |
michael@0 | 222 | if (StyleContext()->HasTextDecorationLines()) { |
michael@0 | 223 | return GetVisualOverflowRect(); |
michael@0 | 224 | } |
michael@0 | 225 | return ComputeSimpleTightBounds(aContext); |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | void |
michael@0 | 229 | nsInlineFrame::ReparentFloatsForInlineChild(nsIFrame* aOurLineContainer, |
michael@0 | 230 | nsIFrame* aFrame, |
michael@0 | 231 | bool aReparentSiblings) |
michael@0 | 232 | { |
michael@0 | 233 | // XXXbz this would be better if it took a nsFrameList or a frame |
michael@0 | 234 | // list slice.... |
michael@0 | 235 | NS_ASSERTION(aOurLineContainer->GetNextContinuation() || |
michael@0 | 236 | aOurLineContainer->GetPrevContinuation(), |
michael@0 | 237 | "Don't call this when we have no continuation, it's a waste"); |
michael@0 | 238 | if (!aFrame) { |
michael@0 | 239 | NS_ASSERTION(aReparentSiblings, "Why did we get called?"); |
michael@0 | 240 | return; |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | nsIFrame* ancestor = aFrame; |
michael@0 | 244 | do { |
michael@0 | 245 | ancestor = ancestor->GetParent(); |
michael@0 | 246 | if (!ancestor) |
michael@0 | 247 | return; |
michael@0 | 248 | } while (!ancestor->IsFloatContainingBlock()); |
michael@0 | 249 | |
michael@0 | 250 | if (ancestor == aOurLineContainer) |
michael@0 | 251 | return; |
michael@0 | 252 | |
michael@0 | 253 | nsBlockFrame* ourBlock = nsLayoutUtils::GetAsBlock(aOurLineContainer); |
michael@0 | 254 | NS_ASSERTION(ourBlock, "Not a block, but broke vertically?"); |
michael@0 | 255 | nsBlockFrame* frameBlock = nsLayoutUtils::GetAsBlock(ancestor); |
michael@0 | 256 | NS_ASSERTION(frameBlock, "ancestor not a block"); |
michael@0 | 257 | |
michael@0 | 258 | while (true) { |
michael@0 | 259 | ourBlock->ReparentFloats(aFrame, frameBlock, false); |
michael@0 | 260 | |
michael@0 | 261 | if (!aReparentSiblings) |
michael@0 | 262 | return; |
michael@0 | 263 | nsIFrame* next = aFrame->GetNextSibling(); |
michael@0 | 264 | if (!next) |
michael@0 | 265 | return; |
michael@0 | 266 | if (next->GetParent() == aFrame->GetParent()) { |
michael@0 | 267 | aFrame = next; |
michael@0 | 268 | continue; |
michael@0 | 269 | } |
michael@0 | 270 | // This is paranoid and will hardly ever get hit ... but we can't actually |
michael@0 | 271 | // trust that the frames in the sibling chain all have the same parent, |
michael@0 | 272 | // because lazy reparenting may be going on. If we find a different |
michael@0 | 273 | // parent we need to redo our analysis. |
michael@0 | 274 | ReparentFloatsForInlineChild(aOurLineContainer, next, aReparentSiblings); |
michael@0 | 275 | return; |
michael@0 | 276 | } |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | static void |
michael@0 | 280 | ReparentChildListStyle(nsPresContext* aPresContext, |
michael@0 | 281 | const nsFrameList::Slice& aFrames, |
michael@0 | 282 | nsIFrame* aParentFrame) |
michael@0 | 283 | { |
michael@0 | 284 | RestyleManager* restyleManager = aPresContext->RestyleManager(); |
michael@0 | 285 | |
michael@0 | 286 | for (nsFrameList::Enumerator e(aFrames); !e.AtEnd(); e.Next()) { |
michael@0 | 287 | NS_ASSERTION(e.get()->GetParent() == aParentFrame, "Bogus parentage"); |
michael@0 | 288 | restyleManager->ReparentStyleContext(e.get()); |
michael@0 | 289 | nsLayoutUtils::MarkDescendantsDirty(e.get()); |
michael@0 | 290 | } |
michael@0 | 291 | } |
michael@0 | 292 | |
michael@0 | 293 | nsresult |
michael@0 | 294 | nsInlineFrame::Reflow(nsPresContext* aPresContext, |
michael@0 | 295 | nsHTMLReflowMetrics& aMetrics, |
michael@0 | 296 | const nsHTMLReflowState& aReflowState, |
michael@0 | 297 | nsReflowStatus& aStatus) |
michael@0 | 298 | { |
michael@0 | 299 | DO_GLOBAL_REFLOW_COUNT("nsInlineFrame"); |
michael@0 | 300 | DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus); |
michael@0 | 301 | if (nullptr == aReflowState.mLineLayout) { |
michael@0 | 302 | return NS_ERROR_INVALID_ARG; |
michael@0 | 303 | } |
michael@0 | 304 | if (IsFrameTreeTooDeep(aReflowState, aMetrics, aStatus)) { |
michael@0 | 305 | return NS_OK; |
michael@0 | 306 | } |
michael@0 | 307 | |
michael@0 | 308 | bool lazilySetParentPointer = false; |
michael@0 | 309 | |
michael@0 | 310 | nsIFrame* lineContainer = aReflowState.mLineLayout->LineContainerFrame(); |
michael@0 | 311 | |
michael@0 | 312 | // Check for an overflow list with our prev-in-flow |
michael@0 | 313 | nsInlineFrame* prevInFlow = (nsInlineFrame*)GetPrevInFlow(); |
michael@0 | 314 | if (prevInFlow) { |
michael@0 | 315 | AutoFrameListPtr prevOverflowFrames(aPresContext, |
michael@0 | 316 | prevInFlow->StealOverflowFrames()); |
michael@0 | 317 | if (prevOverflowFrames) { |
michael@0 | 318 | // When pushing and pulling frames we need to check for whether any |
michael@0 | 319 | // views need to be reparented. |
michael@0 | 320 | nsContainerFrame::ReparentFrameViewList(*prevOverflowFrames, prevInFlow, |
michael@0 | 321 | this); |
michael@0 | 322 | |
michael@0 | 323 | // Check if we should do the lazilySetParentPointer optimization. |
michael@0 | 324 | // Only do it in simple cases where we're being reflowed for the |
michael@0 | 325 | // first time, nothing (e.g. bidi resolution) has already given |
michael@0 | 326 | // us children, and there's no next-in-flow, so all our frames |
michael@0 | 327 | // will be taken from prevOverflowFrames. |
michael@0 | 328 | if ((GetStateBits() & NS_FRAME_FIRST_REFLOW) && mFrames.IsEmpty() && |
michael@0 | 329 | !GetNextInFlow()) { |
michael@0 | 330 | // If our child list is empty, just put the new frames into it. |
michael@0 | 331 | // Note that we don't set the parent pointer for the new frames. Instead wait |
michael@0 | 332 | // to do this until we actually reflow the frame. If the overflow list contains |
michael@0 | 333 | // thousands of frames this is a big performance issue (see bug #5588) |
michael@0 | 334 | mFrames.SetFrames(*prevOverflowFrames); |
michael@0 | 335 | lazilySetParentPointer = true; |
michael@0 | 336 | } else { |
michael@0 | 337 | // Assign all floats to our block if necessary |
michael@0 | 338 | if (lineContainer && lineContainer->GetPrevContinuation()) { |
michael@0 | 339 | ReparentFloatsForInlineChild(lineContainer, |
michael@0 | 340 | prevOverflowFrames->FirstChild(), |
michael@0 | 341 | true); |
michael@0 | 342 | } |
michael@0 | 343 | // Insert the new frames at the beginning of the child list |
michael@0 | 344 | // and set their parent pointer |
michael@0 | 345 | const nsFrameList::Slice& newFrames = |
michael@0 | 346 | mFrames.InsertFrames(this, nullptr, *prevOverflowFrames); |
michael@0 | 347 | // If our prev in flow was under the first continuation of a first-line |
michael@0 | 348 | // frame then we need to reparent the style contexts to remove the |
michael@0 | 349 | // the special first-line styling. In the lazilySetParentPointer case |
michael@0 | 350 | // we reparent the style contexts when we set their parents in |
michael@0 | 351 | // nsInlineFrame::ReflowFrames and nsInlineFrame::ReflowInlineFrame. |
michael@0 | 352 | if (aReflowState.mLineLayout->GetInFirstLine()) { |
michael@0 | 353 | ReparentChildListStyle(aPresContext, newFrames, this); |
michael@0 | 354 | } |
michael@0 | 355 | } |
michael@0 | 356 | } |
michael@0 | 357 | } |
michael@0 | 358 | |
michael@0 | 359 | // It's also possible that we have an overflow list for ourselves |
michael@0 | 360 | #ifdef DEBUG |
michael@0 | 361 | if (GetStateBits() & NS_FRAME_FIRST_REFLOW) { |
michael@0 | 362 | // If it's our initial reflow, then we should not have an overflow list. |
michael@0 | 363 | // However, add an assertion in case we get reflowed more than once with |
michael@0 | 364 | // the initial reflow reason |
michael@0 | 365 | nsFrameList* overflowFrames = GetOverflowFrames(); |
michael@0 | 366 | NS_ASSERTION(!overflowFrames || overflowFrames->IsEmpty(), |
michael@0 | 367 | "overflow list is not empty for initial reflow"); |
michael@0 | 368 | } |
michael@0 | 369 | #endif |
michael@0 | 370 | if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) { |
michael@0 | 371 | DrainFlags flags = |
michael@0 | 372 | lazilySetParentPointer ? eDontReparentFrames : DrainFlags(0); |
michael@0 | 373 | if (aReflowState.mLineLayout->GetInFirstLine()) { |
michael@0 | 374 | flags = DrainFlags(flags | eInFirstLine); |
michael@0 | 375 | } |
michael@0 | 376 | DrainSelfOverflowListInternal(flags, lineContainer); |
michael@0 | 377 | } |
michael@0 | 378 | |
michael@0 | 379 | // Set our own reflow state (additional state above and beyond |
michael@0 | 380 | // aReflowState) |
michael@0 | 381 | InlineReflowState irs; |
michael@0 | 382 | irs.mPrevFrame = nullptr; |
michael@0 | 383 | irs.mLineContainer = lineContainer; |
michael@0 | 384 | irs.mLineLayout = aReflowState.mLineLayout; |
michael@0 | 385 | irs.mNextInFlow = (nsInlineFrame*) GetNextInFlow(); |
michael@0 | 386 | irs.mSetParentPointer = lazilySetParentPointer; |
michael@0 | 387 | |
michael@0 | 388 | nsresult rv; |
michael@0 | 389 | if (mFrames.IsEmpty()) { |
michael@0 | 390 | // Try to pull over one frame before starting so that we know |
michael@0 | 391 | // whether we have an anonymous block or not. |
michael@0 | 392 | bool complete; |
michael@0 | 393 | (void) PullOneFrame(aPresContext, irs, &complete); |
michael@0 | 394 | } |
michael@0 | 395 | |
michael@0 | 396 | rv = ReflowFrames(aPresContext, aReflowState, irs, aMetrics, aStatus); |
michael@0 | 397 | |
michael@0 | 398 | ReflowAbsoluteFrames(aPresContext, aMetrics, aReflowState, aStatus); |
michael@0 | 399 | |
michael@0 | 400 | // Note: the line layout code will properly compute our |
michael@0 | 401 | // overflow-rect state for us. |
michael@0 | 402 | |
michael@0 | 403 | NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics); |
michael@0 | 404 | return rv; |
michael@0 | 405 | } |
michael@0 | 406 | |
michael@0 | 407 | bool |
michael@0 | 408 | nsInlineFrame::DrainSelfOverflowListInternal(DrainFlags aFlags, |
michael@0 | 409 | nsIFrame* aLineContainer) |
michael@0 | 410 | { |
michael@0 | 411 | AutoFrameListPtr overflowFrames(PresContext(), StealOverflowFrames()); |
michael@0 | 412 | if (overflowFrames) { |
michael@0 | 413 | NS_ASSERTION(mFrames.NotEmpty(), "overflow list w/o frames"); |
michael@0 | 414 | // The frames on our own overflowlist may have been pushed by a |
michael@0 | 415 | // previous lazilySetParentPointer Reflow so we need to ensure the |
michael@0 | 416 | // correct parent pointer. This is sometimes skipped by Reflow. |
michael@0 | 417 | if (!(aFlags & eDontReparentFrames)) { |
michael@0 | 418 | nsIFrame* firstChild = overflowFrames->FirstChild(); |
michael@0 | 419 | if (aLineContainer && aLineContainer->GetPrevContinuation()) { |
michael@0 | 420 | ReparentFloatsForInlineChild(aLineContainer, firstChild, true); |
michael@0 | 421 | } |
michael@0 | 422 | const bool inFirstLine = (aFlags & eInFirstLine); |
michael@0 | 423 | RestyleManager* restyleManager = PresContext()->RestyleManager(); |
michael@0 | 424 | for (nsIFrame* f = firstChild; f; f = f->GetNextSibling()) { |
michael@0 | 425 | f->SetParent(this); |
michael@0 | 426 | if (inFirstLine) { |
michael@0 | 427 | restyleManager->ReparentStyleContext(f); |
michael@0 | 428 | nsLayoutUtils::MarkDescendantsDirty(f); |
michael@0 | 429 | } |
michael@0 | 430 | } |
michael@0 | 431 | } |
michael@0 | 432 | bool result = !overflowFrames->IsEmpty(); |
michael@0 | 433 | mFrames.AppendFrames(nullptr, *overflowFrames); |
michael@0 | 434 | return result; |
michael@0 | 435 | } |
michael@0 | 436 | return false; |
michael@0 | 437 | } |
michael@0 | 438 | |
michael@0 | 439 | /* virtual */ bool |
michael@0 | 440 | nsInlineFrame::DrainSelfOverflowList() |
michael@0 | 441 | { |
michael@0 | 442 | nsIFrame* lineContainer = nsLayoutUtils::FindNearestBlockAncestor(this); |
michael@0 | 443 | // Add the eInFirstLine flag if we have a ::first-line ancestor frame. |
michael@0 | 444 | // No need to look further than the nearest line container though. |
michael@0 | 445 | DrainFlags flags = DrainFlags(0); |
michael@0 | 446 | for (nsIFrame* p = GetParent(); p != lineContainer; p = p->GetParent()) { |
michael@0 | 447 | if (p->GetType() == nsGkAtoms::lineFrame) { |
michael@0 | 448 | flags = DrainFlags(flags | eInFirstLine); |
michael@0 | 449 | break; |
michael@0 | 450 | } |
michael@0 | 451 | } |
michael@0 | 452 | return DrainSelfOverflowListInternal(flags, lineContainer); |
michael@0 | 453 | } |
michael@0 | 454 | |
michael@0 | 455 | /* virtual */ bool |
michael@0 | 456 | nsInlineFrame::CanContinueTextRun() const |
michael@0 | 457 | { |
michael@0 | 458 | // We can continue a text run through an inline frame |
michael@0 | 459 | return true; |
michael@0 | 460 | } |
michael@0 | 461 | |
michael@0 | 462 | /* virtual */ void |
michael@0 | 463 | nsInlineFrame::PullOverflowsFromPrevInFlow() |
michael@0 | 464 | { |
michael@0 | 465 | nsInlineFrame* prevInFlow = static_cast<nsInlineFrame*>(GetPrevInFlow()); |
michael@0 | 466 | if (prevInFlow) { |
michael@0 | 467 | nsPresContext* presContext = PresContext(); |
michael@0 | 468 | AutoFrameListPtr prevOverflowFrames(presContext, |
michael@0 | 469 | prevInFlow->StealOverflowFrames()); |
michael@0 | 470 | if (prevOverflowFrames) { |
michael@0 | 471 | // Assume that our prev-in-flow has the same line container that we do. |
michael@0 | 472 | nsContainerFrame::ReparentFrameViewList(*prevOverflowFrames, prevInFlow, |
michael@0 | 473 | this); |
michael@0 | 474 | mFrames.InsertFrames(this, nullptr, *prevOverflowFrames); |
michael@0 | 475 | } |
michael@0 | 476 | } |
michael@0 | 477 | } |
michael@0 | 478 | |
michael@0 | 479 | nsresult |
michael@0 | 480 | nsInlineFrame::ReflowFrames(nsPresContext* aPresContext, |
michael@0 | 481 | const nsHTMLReflowState& aReflowState, |
michael@0 | 482 | InlineReflowState& irs, |
michael@0 | 483 | nsHTMLReflowMetrics& aMetrics, |
michael@0 | 484 | nsReflowStatus& aStatus) |
michael@0 | 485 | { |
michael@0 | 486 | nsresult rv = NS_OK; |
michael@0 | 487 | aStatus = NS_FRAME_COMPLETE; |
michael@0 | 488 | |
michael@0 | 489 | nsLineLayout* lineLayout = aReflowState.mLineLayout; |
michael@0 | 490 | bool inFirstLine = aReflowState.mLineLayout->GetInFirstLine(); |
michael@0 | 491 | RestyleManager* restyleManager = aPresContext->RestyleManager(); |
michael@0 | 492 | WritingMode wm = aReflowState.GetWritingMode(); |
michael@0 | 493 | nscoord startEdge = 0; |
michael@0 | 494 | // Don't offset by our start borderpadding if we have a prev continuation or |
michael@0 | 495 | // if we're in a part of an {ib} split other than the first one. |
michael@0 | 496 | if (!GetPrevContinuation() && !FrameIsNonFirstInIBSplit()) { |
michael@0 | 497 | startEdge = aReflowState.ComputedLogicalBorderPadding().IStart(wm); |
michael@0 | 498 | } |
michael@0 | 499 | nscoord availableISize = aReflowState.AvailableISize(); |
michael@0 | 500 | NS_ASSERTION(availableISize != NS_UNCONSTRAINEDSIZE, |
michael@0 | 501 | "should no longer use available widths"); |
michael@0 | 502 | // Subtract off inline axis border+padding from availableISize |
michael@0 | 503 | availableISize -= startEdge; |
michael@0 | 504 | availableISize -= aReflowState.ComputedLogicalBorderPadding().IEnd(wm); |
michael@0 | 505 | lineLayout->BeginSpan(this, &aReflowState, startEdge, |
michael@0 | 506 | startEdge + availableISize, &mBaseline); |
michael@0 | 507 | |
michael@0 | 508 | // First reflow our principal children. |
michael@0 | 509 | nsIFrame* frame = mFrames.FirstChild(); |
michael@0 | 510 | bool done = false; |
michael@0 | 511 | while (frame) { |
michael@0 | 512 | // Check if we should lazily set the child frame's parent pointer. |
michael@0 | 513 | if (irs.mSetParentPointer) { |
michael@0 | 514 | bool havePrevBlock = |
michael@0 | 515 | irs.mLineContainer && irs.mLineContainer->GetPrevContinuation(); |
michael@0 | 516 | nsIFrame* child = frame; |
michael@0 | 517 | do { |
michael@0 | 518 | // If our block is the first in flow, then any floats under the pulled |
michael@0 | 519 | // frame must already belong to our block. |
michael@0 | 520 | if (havePrevBlock) { |
michael@0 | 521 | // This has to happen before we update frame's parent; we need to |
michael@0 | 522 | // know frame's ancestry under its old block. |
michael@0 | 523 | // The blockChildren.ContainsFrame check performed by |
michael@0 | 524 | // ReparentFloatsForInlineChild here may be slow, but we can't |
michael@0 | 525 | // easily avoid it because we don't know where 'frame' originally |
michael@0 | 526 | // came from. If we really really have to optimize this we could |
michael@0 | 527 | // cache whether frame->GetParent() is under its containing blocks |
michael@0 | 528 | // overflowList or not. |
michael@0 | 529 | ReparentFloatsForInlineChild(irs.mLineContainer, child, false); |
michael@0 | 530 | } |
michael@0 | 531 | child->SetParent(this); |
michael@0 | 532 | if (inFirstLine) { |
michael@0 | 533 | restyleManager->ReparentStyleContext(child); |
michael@0 | 534 | nsLayoutUtils::MarkDescendantsDirty(child); |
michael@0 | 535 | } |
michael@0 | 536 | // We also need to do the same for |frame|'s next-in-flows that are in |
michael@0 | 537 | // the sibling list. Otherwise, if we reflow |frame| and it's complete |
michael@0 | 538 | // we'll crash when trying to delete its next-in-flow. |
michael@0 | 539 | // This scenario doesn't happen often, but it can happen. |
michael@0 | 540 | nsIFrame* nextSibling = child->GetNextSibling(); |
michael@0 | 541 | child = child->GetNextInFlow(); |
michael@0 | 542 | if (MOZ_UNLIKELY(child)) { |
michael@0 | 543 | while (child != nextSibling && nextSibling) { |
michael@0 | 544 | nextSibling = nextSibling->GetNextSibling(); |
michael@0 | 545 | } |
michael@0 | 546 | if (!nextSibling) { |
michael@0 | 547 | child = nullptr; |
michael@0 | 548 | } |
michael@0 | 549 | } |
michael@0 | 550 | MOZ_ASSERT(!child || mFrames.ContainsFrame(child)); |
michael@0 | 551 | } while (child); |
michael@0 | 552 | |
michael@0 | 553 | // Fix the parent pointer for ::first-letter child frame next-in-flows, |
michael@0 | 554 | // so nsFirstLetterFrame::Reflow can destroy them safely (bug 401042). |
michael@0 | 555 | nsIFrame* realFrame = nsPlaceholderFrame::GetRealFrameFor(frame); |
michael@0 | 556 | if (realFrame->GetType() == nsGkAtoms::letterFrame) { |
michael@0 | 557 | nsIFrame* child = realFrame->GetFirstPrincipalChild(); |
michael@0 | 558 | if (child) { |
michael@0 | 559 | NS_ASSERTION(child->GetType() == nsGkAtoms::textFrame, |
michael@0 | 560 | "unexpected frame type"); |
michael@0 | 561 | nsIFrame* nextInFlow = child->GetNextInFlow(); |
michael@0 | 562 | for ( ; nextInFlow; nextInFlow = nextInFlow->GetNextInFlow()) { |
michael@0 | 563 | NS_ASSERTION(nextInFlow->GetType() == nsGkAtoms::textFrame, |
michael@0 | 564 | "unexpected frame type"); |
michael@0 | 565 | if (mFrames.ContainsFrame(nextInFlow)) { |
michael@0 | 566 | nextInFlow->SetParent(this); |
michael@0 | 567 | if (inFirstLine) { |
michael@0 | 568 | restyleManager->ReparentStyleContext(nextInFlow); |
michael@0 | 569 | nsLayoutUtils::MarkDescendantsDirty(nextInFlow); |
michael@0 | 570 | } |
michael@0 | 571 | } |
michael@0 | 572 | else { |
michael@0 | 573 | #ifdef DEBUG |
michael@0 | 574 | // Once we find a next-in-flow that isn't ours none of the |
michael@0 | 575 | // remaining next-in-flows should be either. |
michael@0 | 576 | for ( ; nextInFlow; nextInFlow = nextInFlow->GetNextInFlow()) { |
michael@0 | 577 | NS_ASSERTION(!mFrames.ContainsFrame(nextInFlow), |
michael@0 | 578 | "unexpected letter frame flow"); |
michael@0 | 579 | } |
michael@0 | 580 | #endif |
michael@0 | 581 | break; |
michael@0 | 582 | } |
michael@0 | 583 | } |
michael@0 | 584 | } |
michael@0 | 585 | } |
michael@0 | 586 | } |
michael@0 | 587 | MOZ_ASSERT(frame->GetParent() == this); |
michael@0 | 588 | |
michael@0 | 589 | if (!done) { |
michael@0 | 590 | bool reflowingFirstLetter = lineLayout->GetFirstLetterStyleOK(); |
michael@0 | 591 | rv = ReflowInlineFrame(aPresContext, aReflowState, irs, frame, aStatus); |
michael@0 | 592 | done = NS_FAILED(rv) || |
michael@0 | 593 | NS_INLINE_IS_BREAK(aStatus) || |
michael@0 | 594 | (!reflowingFirstLetter && NS_FRAME_IS_NOT_COMPLETE(aStatus)); |
michael@0 | 595 | if (done) { |
michael@0 | 596 | if (!irs.mSetParentPointer) { |
michael@0 | 597 | break; |
michael@0 | 598 | } |
michael@0 | 599 | // Keep reparenting the remaining siblings, but don't reflow them. |
michael@0 | 600 | nsFrameList* pushedFrames = GetOverflowFrames(); |
michael@0 | 601 | if (pushedFrames && pushedFrames->FirstChild() == frame) { |
michael@0 | 602 | // Don't bother if |frame| was pushed to our overflow list. |
michael@0 | 603 | break; |
michael@0 | 604 | } |
michael@0 | 605 | } else { |
michael@0 | 606 | irs.mPrevFrame = frame; |
michael@0 | 607 | } |
michael@0 | 608 | } |
michael@0 | 609 | frame = frame->GetNextSibling(); |
michael@0 | 610 | } |
michael@0 | 611 | |
michael@0 | 612 | // Attempt to pull frames from our next-in-flow until we can't |
michael@0 | 613 | if (!done && GetNextInFlow()) { |
michael@0 | 614 | while (true) { |
michael@0 | 615 | bool reflowingFirstLetter = lineLayout->GetFirstLetterStyleOK(); |
michael@0 | 616 | bool isComplete; |
michael@0 | 617 | if (!frame) { // Could be non-null if we pulled a first-letter frame and |
michael@0 | 618 | // it created a continuation, since we don't push those. |
michael@0 | 619 | frame = PullOneFrame(aPresContext, irs, &isComplete); |
michael@0 | 620 | } |
michael@0 | 621 | #ifdef NOISY_PUSHING |
michael@0 | 622 | printf("%p pulled up %p\n", this, frame); |
michael@0 | 623 | #endif |
michael@0 | 624 | if (nullptr == frame) { |
michael@0 | 625 | if (!isComplete) { |
michael@0 | 626 | aStatus = NS_FRAME_NOT_COMPLETE; |
michael@0 | 627 | } |
michael@0 | 628 | break; |
michael@0 | 629 | } |
michael@0 | 630 | rv = ReflowInlineFrame(aPresContext, aReflowState, irs, frame, aStatus); |
michael@0 | 631 | if (NS_FAILED(rv) || |
michael@0 | 632 | NS_INLINE_IS_BREAK(aStatus) || |
michael@0 | 633 | (!reflowingFirstLetter && NS_FRAME_IS_NOT_COMPLETE(aStatus))) { |
michael@0 | 634 | break; |
michael@0 | 635 | } |
michael@0 | 636 | irs.mPrevFrame = frame; |
michael@0 | 637 | frame = frame->GetNextSibling(); |
michael@0 | 638 | } |
michael@0 | 639 | } |
michael@0 | 640 | |
michael@0 | 641 | NS_ASSERTION(!NS_FRAME_IS_COMPLETE(aStatus) || !GetOverflowFrames(), |
michael@0 | 642 | "We can't be complete AND have overflow frames!"); |
michael@0 | 643 | |
michael@0 | 644 | // If after reflowing our children they take up no area then make |
michael@0 | 645 | // sure that we don't either. |
michael@0 | 646 | // |
michael@0 | 647 | // Note: CSS demands that empty inline elements still affect the |
michael@0 | 648 | // line-height calculations. However, continuations of an inline |
michael@0 | 649 | // that are empty we force to empty so that things like collapsed |
michael@0 | 650 | // whitespace in an inline element don't affect the line-height. |
michael@0 | 651 | aMetrics.ISize() = lineLayout->EndSpan(this); |
michael@0 | 652 | |
michael@0 | 653 | // Compute final width. |
michael@0 | 654 | |
michael@0 | 655 | // Make sure to not include our start border and padding if we have a prev |
michael@0 | 656 | // continuation or if we're in a part of an {ib} split other than the first |
michael@0 | 657 | // one. |
michael@0 | 658 | if (!GetPrevContinuation() && !FrameIsNonFirstInIBSplit()) { |
michael@0 | 659 | aMetrics.ISize() += aReflowState.ComputedLogicalBorderPadding().IStart(wm); |
michael@0 | 660 | } |
michael@0 | 661 | |
michael@0 | 662 | /* |
michael@0 | 663 | * We want to only apply the end border and padding if we're the last |
michael@0 | 664 | * continuation and either not in an {ib} split or the last part of it. To |
michael@0 | 665 | * be the last continuation we have to be complete (so that we won't get a |
michael@0 | 666 | * next-in-flow) and have no non-fluid continuations on our continuation |
michael@0 | 667 | * chain. |
michael@0 | 668 | */ |
michael@0 | 669 | if (NS_FRAME_IS_COMPLETE(aStatus) && |
michael@0 | 670 | !LastInFlow()->GetNextContinuation() && |
michael@0 | 671 | !FrameIsNonLastInIBSplit()) { |
michael@0 | 672 | aMetrics.Width() += aReflowState.ComputedLogicalBorderPadding().IEnd(wm); |
michael@0 | 673 | } |
michael@0 | 674 | |
michael@0 | 675 | nsRefPtr<nsFontMetrics> fm; |
michael@0 | 676 | float inflation = nsLayoutUtils::FontSizeInflationFor(this); |
michael@0 | 677 | nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm), inflation); |
michael@0 | 678 | aReflowState.rendContext->SetFont(fm); |
michael@0 | 679 | |
michael@0 | 680 | if (fm) { |
michael@0 | 681 | // Compute final height of the frame. |
michael@0 | 682 | // |
michael@0 | 683 | // Do things the standard css2 way -- though it's hard to find it |
michael@0 | 684 | // in the css2 spec! It's actually found in the css1 spec section |
michael@0 | 685 | // 4.4 (you will have to read between the lines to really see |
michael@0 | 686 | // it). |
michael@0 | 687 | // |
michael@0 | 688 | // The height of our box is the sum of our font size plus the top |
michael@0 | 689 | // and bottom border and padding. The height of children do not |
michael@0 | 690 | // affect our height. |
michael@0 | 691 | aMetrics.SetTopAscent(fm->MaxAscent()); |
michael@0 | 692 | aMetrics.Height() = fm->MaxHeight(); |
michael@0 | 693 | } else { |
michael@0 | 694 | NS_WARNING("Cannot get font metrics - defaulting sizes to 0"); |
michael@0 | 695 | aMetrics.SetTopAscent(aMetrics.Height() = 0); |
michael@0 | 696 | } |
michael@0 | 697 | aMetrics.SetTopAscent(aMetrics.TopAscent() + aReflowState.ComputedPhysicalBorderPadding().top); |
michael@0 | 698 | aMetrics.Height() += aReflowState.ComputedPhysicalBorderPadding().top + |
michael@0 | 699 | aReflowState.ComputedPhysicalBorderPadding().bottom; |
michael@0 | 700 | |
michael@0 | 701 | // For now our overflow area is zero. The real value will be |
michael@0 | 702 | // computed in |nsLineLayout::RelativePositionFrames|. |
michael@0 | 703 | aMetrics.mOverflowAreas.Clear(); |
michael@0 | 704 | |
michael@0 | 705 | #ifdef NOISY_FINAL_SIZE |
michael@0 | 706 | ListTag(stdout); |
michael@0 | 707 | printf(": metrics=%d,%d ascent=%d\n", |
michael@0 | 708 | aMetrics.Width(), aMetrics.Height(), aMetrics.TopAscent()); |
michael@0 | 709 | #endif |
michael@0 | 710 | |
michael@0 | 711 | return rv; |
michael@0 | 712 | } |
michael@0 | 713 | |
michael@0 | 714 | nsresult |
michael@0 | 715 | nsInlineFrame::ReflowInlineFrame(nsPresContext* aPresContext, |
michael@0 | 716 | const nsHTMLReflowState& aReflowState, |
michael@0 | 717 | InlineReflowState& irs, |
michael@0 | 718 | nsIFrame* aFrame, |
michael@0 | 719 | nsReflowStatus& aStatus) |
michael@0 | 720 | { |
michael@0 | 721 | nsLineLayout* lineLayout = aReflowState.mLineLayout; |
michael@0 | 722 | bool reflowingFirstLetter = lineLayout->GetFirstLetterStyleOK(); |
michael@0 | 723 | bool pushedFrame; |
michael@0 | 724 | nsresult rv = |
michael@0 | 725 | lineLayout->ReflowFrame(aFrame, aStatus, nullptr, pushedFrame); |
michael@0 | 726 | |
michael@0 | 727 | if (NS_FAILED(rv)) { |
michael@0 | 728 | return rv; |
michael@0 | 729 | } |
michael@0 | 730 | |
michael@0 | 731 | if (NS_INLINE_IS_BREAK_BEFORE(aStatus)) { |
michael@0 | 732 | if (aFrame != mFrames.FirstChild()) { |
michael@0 | 733 | // Change break-before status into break-after since we have |
michael@0 | 734 | // already placed at least one child frame. This preserves the |
michael@0 | 735 | // break-type so that it can be propagated upward. |
michael@0 | 736 | aStatus = NS_FRAME_NOT_COMPLETE | |
michael@0 | 737 | NS_INLINE_BREAK | NS_INLINE_BREAK_AFTER | |
michael@0 | 738 | (aStatus & NS_INLINE_BREAK_TYPE_MASK); |
michael@0 | 739 | PushFrames(aPresContext, aFrame, irs.mPrevFrame, irs); |
michael@0 | 740 | } |
michael@0 | 741 | else { |
michael@0 | 742 | // Preserve reflow status when breaking-before our first child |
michael@0 | 743 | // and propagate it upward without modification. |
michael@0 | 744 | } |
michael@0 | 745 | return NS_OK; |
michael@0 | 746 | } |
michael@0 | 747 | |
michael@0 | 748 | // Create a next-in-flow if needed. |
michael@0 | 749 | if (!NS_FRAME_IS_FULLY_COMPLETE(aStatus)) { |
michael@0 | 750 | nsIFrame* newFrame; |
michael@0 | 751 | rv = CreateNextInFlow(aFrame, newFrame); |
michael@0 | 752 | if (NS_FAILED(rv)) { |
michael@0 | 753 | return rv; |
michael@0 | 754 | } |
michael@0 | 755 | } |
michael@0 | 756 | |
michael@0 | 757 | if (NS_INLINE_IS_BREAK_AFTER(aStatus)) { |
michael@0 | 758 | nsIFrame* nextFrame = aFrame->GetNextSibling(); |
michael@0 | 759 | if (nextFrame) { |
michael@0 | 760 | NS_FRAME_SET_INCOMPLETE(aStatus); |
michael@0 | 761 | PushFrames(aPresContext, nextFrame, aFrame, irs); |
michael@0 | 762 | } |
michael@0 | 763 | else { |
michael@0 | 764 | // We must return an incomplete status if there are more child |
michael@0 | 765 | // frames remaining in a next-in-flow that follows this frame. |
michael@0 | 766 | nsInlineFrame* nextInFlow = static_cast<nsInlineFrame*>(GetNextInFlow()); |
michael@0 | 767 | while (nextInFlow) { |
michael@0 | 768 | if (nextInFlow->mFrames.NotEmpty()) { |
michael@0 | 769 | NS_FRAME_SET_INCOMPLETE(aStatus); |
michael@0 | 770 | break; |
michael@0 | 771 | } |
michael@0 | 772 | nextInFlow = static_cast<nsInlineFrame*>(nextInFlow->GetNextInFlow()); |
michael@0 | 773 | } |
michael@0 | 774 | } |
michael@0 | 775 | return NS_OK; |
michael@0 | 776 | } |
michael@0 | 777 | |
michael@0 | 778 | if (!NS_FRAME_IS_FULLY_COMPLETE(aStatus) && !reflowingFirstLetter) { |
michael@0 | 779 | nsIFrame* nextFrame = aFrame->GetNextSibling(); |
michael@0 | 780 | if (nextFrame) { |
michael@0 | 781 | PushFrames(aPresContext, nextFrame, aFrame, irs); |
michael@0 | 782 | } |
michael@0 | 783 | } |
michael@0 | 784 | return NS_OK; |
michael@0 | 785 | } |
michael@0 | 786 | |
michael@0 | 787 | nsIFrame* |
michael@0 | 788 | nsInlineFrame::PullOneFrame(nsPresContext* aPresContext, |
michael@0 | 789 | InlineReflowState& irs, |
michael@0 | 790 | bool* aIsComplete) |
michael@0 | 791 | { |
michael@0 | 792 | bool isComplete = true; |
michael@0 | 793 | |
michael@0 | 794 | nsIFrame* frame = nullptr; |
michael@0 | 795 | nsInlineFrame* nextInFlow = irs.mNextInFlow; |
michael@0 | 796 | while (nextInFlow) { |
michael@0 | 797 | frame = nextInFlow->mFrames.FirstChild(); |
michael@0 | 798 | if (!frame) { |
michael@0 | 799 | // The nextInFlow's principal list has no frames, try its overflow list. |
michael@0 | 800 | nsFrameList* overflowFrames = nextInFlow->GetOverflowFrames(); |
michael@0 | 801 | if (overflowFrames) { |
michael@0 | 802 | frame = overflowFrames->RemoveFirstChild(); |
michael@0 | 803 | if (overflowFrames->IsEmpty()) { |
michael@0 | 804 | // We're stealing the only frame - delete the overflow list. |
michael@0 | 805 | nextInFlow->DestroyOverflowList(); |
michael@0 | 806 | } else { |
michael@0 | 807 | // We leave the remaining frames on the overflow list (rather than |
michael@0 | 808 | // putting them on nextInFlow's principal list) so we don't have to |
michael@0 | 809 | // set up the parent for them. |
michael@0 | 810 | } |
michael@0 | 811 | // ReparentFloatsForInlineChild needs it to be on a child list - |
michael@0 | 812 | // we remove it again below. |
michael@0 | 813 | nextInFlow->mFrames.SetFrames(frame); |
michael@0 | 814 | } |
michael@0 | 815 | } |
michael@0 | 816 | |
michael@0 | 817 | if (frame) { |
michael@0 | 818 | // If our block has no next continuation, then any floats belonging to |
michael@0 | 819 | // the pulled frame must belong to our block already. This check ensures |
michael@0 | 820 | // we do no extra work in the common non-vertical-breaking case. |
michael@0 | 821 | if (irs.mLineContainer && irs.mLineContainer->GetNextContinuation()) { |
michael@0 | 822 | // The blockChildren.ContainsFrame check performed by |
michael@0 | 823 | // ReparentFloatsForInlineChild will be fast because frame's ancestor |
michael@0 | 824 | // will be the first child of its containing block. |
michael@0 | 825 | ReparentFloatsForInlineChild(irs.mLineContainer, frame, false); |
michael@0 | 826 | } |
michael@0 | 827 | nextInFlow->mFrames.RemoveFirstChild(); |
michael@0 | 828 | // nsFirstLineFrame::PullOneFrame calls ReparentStyleContext. |
michael@0 | 829 | |
michael@0 | 830 | mFrames.InsertFrame(this, irs.mPrevFrame, frame); |
michael@0 | 831 | isComplete = false; |
michael@0 | 832 | if (irs.mLineLayout) { |
michael@0 | 833 | irs.mLineLayout->SetDirtyNextLine(); |
michael@0 | 834 | } |
michael@0 | 835 | nsContainerFrame::ReparentFrameView(frame, nextInFlow, this); |
michael@0 | 836 | break; |
michael@0 | 837 | } |
michael@0 | 838 | nextInFlow = static_cast<nsInlineFrame*>(nextInFlow->GetNextInFlow()); |
michael@0 | 839 | irs.mNextInFlow = nextInFlow; |
michael@0 | 840 | } |
michael@0 | 841 | |
michael@0 | 842 | *aIsComplete = isComplete; |
michael@0 | 843 | return frame; |
michael@0 | 844 | } |
michael@0 | 845 | |
michael@0 | 846 | void |
michael@0 | 847 | nsInlineFrame::PushFrames(nsPresContext* aPresContext, |
michael@0 | 848 | nsIFrame* aFromChild, |
michael@0 | 849 | nsIFrame* aPrevSibling, |
michael@0 | 850 | InlineReflowState& aState) |
michael@0 | 851 | { |
michael@0 | 852 | NS_PRECONDITION(aFromChild, "null pointer"); |
michael@0 | 853 | NS_PRECONDITION(aPrevSibling, "pushing first child"); |
michael@0 | 854 | NS_PRECONDITION(aPrevSibling->GetNextSibling() == aFromChild, "bad prev sibling"); |
michael@0 | 855 | |
michael@0 | 856 | #ifdef NOISY_PUSHING |
michael@0 | 857 | printf("%p pushing aFromChild %p, disconnecting from prev sib %p\n", |
michael@0 | 858 | this, aFromChild, aPrevSibling); |
michael@0 | 859 | #endif |
michael@0 | 860 | |
michael@0 | 861 | // Add the frames to our overflow list (let our next in flow drain |
michael@0 | 862 | // our overflow list when it is ready) |
michael@0 | 863 | SetOverflowFrames(mFrames.RemoveFramesAfter(aPrevSibling)); |
michael@0 | 864 | if (aState.mLineLayout) { |
michael@0 | 865 | aState.mLineLayout->SetDirtyNextLine(); |
michael@0 | 866 | } |
michael@0 | 867 | } |
michael@0 | 868 | |
michael@0 | 869 | |
michael@0 | 870 | ////////////////////////////////////////////////////////////////////// |
michael@0 | 871 | |
michael@0 | 872 | int |
michael@0 | 873 | nsInlineFrame::GetLogicalSkipSides(const nsHTMLReflowState* aReflowState) const |
michael@0 | 874 | { |
michael@0 | 875 | int skip = 0; |
michael@0 | 876 | if (!IsFirst()) { |
michael@0 | 877 | nsInlineFrame* prev = (nsInlineFrame*) GetPrevContinuation(); |
michael@0 | 878 | if ((GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) || |
michael@0 | 879 | (prev && (prev->mRect.height || prev->mRect.width))) { |
michael@0 | 880 | // Prev continuation is not empty therefore we don't render our start |
michael@0 | 881 | // border edge. |
michael@0 | 882 | skip |= LOGICAL_SIDE_I_START; |
michael@0 | 883 | } |
michael@0 | 884 | else { |
michael@0 | 885 | // If the prev continuation is empty, then go ahead and let our start |
michael@0 | 886 | // edge border render. |
michael@0 | 887 | } |
michael@0 | 888 | } |
michael@0 | 889 | if (!IsLast()) { |
michael@0 | 890 | nsInlineFrame* next = (nsInlineFrame*) GetNextContinuation(); |
michael@0 | 891 | if ((GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) || |
michael@0 | 892 | (next && (next->mRect.height || next->mRect.width))) { |
michael@0 | 893 | // Next continuation is not empty therefore we don't render our end |
michael@0 | 894 | // border edge. |
michael@0 | 895 | skip |= LOGICAL_SIDE_I_END; |
michael@0 | 896 | } |
michael@0 | 897 | else { |
michael@0 | 898 | // If the next continuation is empty, then go ahead and let our end |
michael@0 | 899 | // edge border render. |
michael@0 | 900 | } |
michael@0 | 901 | } |
michael@0 | 902 | |
michael@0 | 903 | if (GetStateBits() & NS_FRAME_PART_OF_IBSPLIT) { |
michael@0 | 904 | // All but the last part of an {ib} split should skip the "end" side (as |
michael@0 | 905 | // determined by this frame's direction) and all but the first part of such |
michael@0 | 906 | // a split should skip the "start" side. But figuring out which part of |
michael@0 | 907 | // the split we are involves getting our first continuation, which might be |
michael@0 | 908 | // expensive. So don't bother if we already have the relevant bits set. |
michael@0 | 909 | if (skip != LOGICAL_SIDES_I_BOTH) { |
michael@0 | 910 | // We're missing one of the skip bits, so check whether we need to set it. |
michael@0 | 911 | // Only get the first continuation once, as an optimization. |
michael@0 | 912 | nsIFrame* firstContinuation = FirstContinuation(); |
michael@0 | 913 | if (firstContinuation->FrameIsNonLastInIBSplit()) { |
michael@0 | 914 | skip |= LOGICAL_SIDE_I_END; |
michael@0 | 915 | } |
michael@0 | 916 | if (firstContinuation->FrameIsNonFirstInIBSplit()) { |
michael@0 | 917 | skip |= LOGICAL_SIDE_I_START; |
michael@0 | 918 | } |
michael@0 | 919 | } |
michael@0 | 920 | } |
michael@0 | 921 | |
michael@0 | 922 | return skip; |
michael@0 | 923 | } |
michael@0 | 924 | |
michael@0 | 925 | nscoord |
michael@0 | 926 | nsInlineFrame::GetBaseline() const |
michael@0 | 927 | { |
michael@0 | 928 | return mBaseline; |
michael@0 | 929 | } |
michael@0 | 930 | |
michael@0 | 931 | #ifdef ACCESSIBILITY |
michael@0 | 932 | a11y::AccType |
michael@0 | 933 | nsInlineFrame::AccessibleType() |
michael@0 | 934 | { |
michael@0 | 935 | // Broken image accessibles are created here, because layout |
michael@0 | 936 | // replaces the image or image control frame with an inline frame |
michael@0 | 937 | nsIAtom *tagAtom = mContent->Tag(); |
michael@0 | 938 | if (tagAtom == nsGkAtoms::input) // Broken <input type=image ... /> |
michael@0 | 939 | return a11y::eHTMLButtonType; |
michael@0 | 940 | if (tagAtom == nsGkAtoms::img) // Create accessible for broken <img> |
michael@0 | 941 | return a11y::eHyperTextType; |
michael@0 | 942 | |
michael@0 | 943 | return a11y::eNoType; |
michael@0 | 944 | } |
michael@0 | 945 | #endif |
michael@0 | 946 | |
michael@0 | 947 | ////////////////////////////////////////////////////////////////////// |
michael@0 | 948 | |
michael@0 | 949 | // nsLineFrame implementation |
michael@0 | 950 | |
michael@0 | 951 | nsIFrame* |
michael@0 | 952 | NS_NewFirstLineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 953 | { |
michael@0 | 954 | return new (aPresShell) nsFirstLineFrame(aContext); |
michael@0 | 955 | } |
michael@0 | 956 | |
michael@0 | 957 | NS_IMPL_FRAMEARENA_HELPERS(nsFirstLineFrame) |
michael@0 | 958 | |
michael@0 | 959 | void |
michael@0 | 960 | nsFirstLineFrame::Init(nsIContent* aContent, nsIFrame* aParent, |
michael@0 | 961 | nsIFrame* aPrevInFlow) |
michael@0 | 962 | { |
michael@0 | 963 | nsInlineFrame::Init(aContent, aParent, aPrevInFlow); |
michael@0 | 964 | if (!aPrevInFlow) { |
michael@0 | 965 | MOZ_ASSERT(StyleContext()->GetPseudo() == nsCSSPseudoElements::firstLine); |
michael@0 | 966 | return; |
michael@0 | 967 | } |
michael@0 | 968 | |
michael@0 | 969 | // This frame is a continuation - fixup the style context if aPrevInFlow |
michael@0 | 970 | // is the first-in-flow (the only one with a ::first-line pseudo). |
michael@0 | 971 | if (aPrevInFlow->StyleContext()->GetPseudo() == nsCSSPseudoElements::firstLine) { |
michael@0 | 972 | MOZ_ASSERT(FirstInFlow() == aPrevInFlow); |
michael@0 | 973 | // Create a new style context that is a child of the parent |
michael@0 | 974 | // style context thus removing the ::first-line style. This way |
michael@0 | 975 | // we behave as if an anonymous (unstyled) span was the child |
michael@0 | 976 | // of the parent frame. |
michael@0 | 977 | nsStyleContext* parentContext = aParent->StyleContext(); |
michael@0 | 978 | nsRefPtr<nsStyleContext> newSC = PresContext()->StyleSet()-> |
michael@0 | 979 | ResolveAnonymousBoxStyle(nsCSSAnonBoxes::mozLineFrame, parentContext); |
michael@0 | 980 | SetStyleContext(newSC); |
michael@0 | 981 | } else { |
michael@0 | 982 | MOZ_ASSERT(FirstInFlow() != aPrevInFlow); |
michael@0 | 983 | MOZ_ASSERT(aPrevInFlow->StyleContext()->GetPseudo() == |
michael@0 | 984 | nsCSSAnonBoxes::mozLineFrame); |
michael@0 | 985 | } |
michael@0 | 986 | } |
michael@0 | 987 | |
michael@0 | 988 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 989 | nsresult |
michael@0 | 990 | nsFirstLineFrame::GetFrameName(nsAString& aResult) const |
michael@0 | 991 | { |
michael@0 | 992 | return MakeFrameName(NS_LITERAL_STRING("Line"), aResult); |
michael@0 | 993 | } |
michael@0 | 994 | #endif |
michael@0 | 995 | |
michael@0 | 996 | nsIAtom* |
michael@0 | 997 | nsFirstLineFrame::GetType() const |
michael@0 | 998 | { |
michael@0 | 999 | return nsGkAtoms::lineFrame; |
michael@0 | 1000 | } |
michael@0 | 1001 | |
michael@0 | 1002 | nsIFrame* |
michael@0 | 1003 | nsFirstLineFrame::PullOneFrame(nsPresContext* aPresContext, InlineReflowState& irs, |
michael@0 | 1004 | bool* aIsComplete) |
michael@0 | 1005 | { |
michael@0 | 1006 | nsIFrame* frame = nsInlineFrame::PullOneFrame(aPresContext, irs, aIsComplete); |
michael@0 | 1007 | if (frame && !GetPrevInFlow()) { |
michael@0 | 1008 | // We are a first-line frame. Fixup the child frames |
michael@0 | 1009 | // style-context that we just pulled. |
michael@0 | 1010 | NS_ASSERTION(frame->GetParent() == this, "Incorrect parent?"); |
michael@0 | 1011 | aPresContext->RestyleManager()->ReparentStyleContext(frame); |
michael@0 | 1012 | nsLayoutUtils::MarkDescendantsDirty(frame); |
michael@0 | 1013 | } |
michael@0 | 1014 | return frame; |
michael@0 | 1015 | } |
michael@0 | 1016 | |
michael@0 | 1017 | nsresult |
michael@0 | 1018 | nsFirstLineFrame::Reflow(nsPresContext* aPresContext, |
michael@0 | 1019 | nsHTMLReflowMetrics& aMetrics, |
michael@0 | 1020 | const nsHTMLReflowState& aReflowState, |
michael@0 | 1021 | nsReflowStatus& aStatus) |
michael@0 | 1022 | { |
michael@0 | 1023 | if (nullptr == aReflowState.mLineLayout) { |
michael@0 | 1024 | return NS_ERROR_INVALID_ARG; |
michael@0 | 1025 | } |
michael@0 | 1026 | |
michael@0 | 1027 | nsIFrame* lineContainer = aReflowState.mLineLayout->LineContainerFrame(); |
michael@0 | 1028 | |
michael@0 | 1029 | // Check for an overflow list with our prev-in-flow |
michael@0 | 1030 | nsFirstLineFrame* prevInFlow = (nsFirstLineFrame*)GetPrevInFlow(); |
michael@0 | 1031 | if (prevInFlow) { |
michael@0 | 1032 | AutoFrameListPtr prevOverflowFrames(aPresContext, |
michael@0 | 1033 | prevInFlow->StealOverflowFrames()); |
michael@0 | 1034 | if (prevOverflowFrames) { |
michael@0 | 1035 | // Assign all floats to our block if necessary |
michael@0 | 1036 | if (lineContainer && lineContainer->GetPrevContinuation()) { |
michael@0 | 1037 | ReparentFloatsForInlineChild(lineContainer, |
michael@0 | 1038 | prevOverflowFrames->FirstChild(), |
michael@0 | 1039 | true); |
michael@0 | 1040 | } |
michael@0 | 1041 | const nsFrameList::Slice& newFrames = |
michael@0 | 1042 | mFrames.InsertFrames(this, nullptr, *prevOverflowFrames); |
michael@0 | 1043 | ReparentChildListStyle(aPresContext, newFrames, this); |
michael@0 | 1044 | } |
michael@0 | 1045 | } |
michael@0 | 1046 | |
michael@0 | 1047 | // It's also possible that we have an overflow list for ourselves. |
michael@0 | 1048 | DrainSelfOverflowList(); |
michael@0 | 1049 | |
michael@0 | 1050 | // Set our own reflow state (additional state above and beyond |
michael@0 | 1051 | // aReflowState) |
michael@0 | 1052 | InlineReflowState irs; |
michael@0 | 1053 | irs.mPrevFrame = nullptr; |
michael@0 | 1054 | irs.mLineContainer = lineContainer; |
michael@0 | 1055 | irs.mLineLayout = aReflowState.mLineLayout; |
michael@0 | 1056 | irs.mNextInFlow = (nsInlineFrame*) GetNextInFlow(); |
michael@0 | 1057 | |
michael@0 | 1058 | nsresult rv; |
michael@0 | 1059 | bool wasEmpty = mFrames.IsEmpty(); |
michael@0 | 1060 | if (wasEmpty) { |
michael@0 | 1061 | // Try to pull over one frame before starting so that we know |
michael@0 | 1062 | // whether we have an anonymous block or not. |
michael@0 | 1063 | bool complete; |
michael@0 | 1064 | PullOneFrame(aPresContext, irs, &complete); |
michael@0 | 1065 | } |
michael@0 | 1066 | |
michael@0 | 1067 | if (nullptr == GetPrevInFlow()) { |
michael@0 | 1068 | // XXX This is pretty sick, but what we do here is to pull-up, in |
michael@0 | 1069 | // advance, all of the next-in-flows children. We re-resolve their |
michael@0 | 1070 | // style while we are at at it so that when we reflow they have |
michael@0 | 1071 | // the right style. |
michael@0 | 1072 | // |
michael@0 | 1073 | // All of this is so that text-runs reflow properly. |
michael@0 | 1074 | irs.mPrevFrame = mFrames.LastChild(); |
michael@0 | 1075 | for (;;) { |
michael@0 | 1076 | bool complete; |
michael@0 | 1077 | nsIFrame* frame = PullOneFrame(aPresContext, irs, &complete); |
michael@0 | 1078 | if (!frame) { |
michael@0 | 1079 | break; |
michael@0 | 1080 | } |
michael@0 | 1081 | irs.mPrevFrame = frame; |
michael@0 | 1082 | } |
michael@0 | 1083 | irs.mPrevFrame = nullptr; |
michael@0 | 1084 | } |
michael@0 | 1085 | |
michael@0 | 1086 | NS_ASSERTION(!aReflowState.mLineLayout->GetInFirstLine(), |
michael@0 | 1087 | "Nested first-line frames? BOGUS"); |
michael@0 | 1088 | aReflowState.mLineLayout->SetInFirstLine(true); |
michael@0 | 1089 | rv = ReflowFrames(aPresContext, aReflowState, irs, aMetrics, aStatus); |
michael@0 | 1090 | aReflowState.mLineLayout->SetInFirstLine(false); |
michael@0 | 1091 | |
michael@0 | 1092 | ReflowAbsoluteFrames(aPresContext, aMetrics, aReflowState, aStatus); |
michael@0 | 1093 | |
michael@0 | 1094 | // Note: the line layout code will properly compute our overflow state for us |
michael@0 | 1095 | |
michael@0 | 1096 | return rv; |
michael@0 | 1097 | } |
michael@0 | 1098 | |
michael@0 | 1099 | /* virtual */ void |
michael@0 | 1100 | nsFirstLineFrame::PullOverflowsFromPrevInFlow() |
michael@0 | 1101 | { |
michael@0 | 1102 | nsFirstLineFrame* prevInFlow = static_cast<nsFirstLineFrame*>(GetPrevInFlow()); |
michael@0 | 1103 | if (prevInFlow) { |
michael@0 | 1104 | nsPresContext* presContext = PresContext(); |
michael@0 | 1105 | AutoFrameListPtr prevOverflowFrames(presContext, |
michael@0 | 1106 | prevInFlow->StealOverflowFrames()); |
michael@0 | 1107 | if (prevOverflowFrames) { |
michael@0 | 1108 | // Assume that our prev-in-flow has the same line container that we do. |
michael@0 | 1109 | const nsFrameList::Slice& newFrames = |
michael@0 | 1110 | mFrames.InsertFrames(this, nullptr, *prevOverflowFrames); |
michael@0 | 1111 | ReparentChildListStyle(presContext, newFrames, this); |
michael@0 | 1112 | } |
michael@0 | 1113 | } |
michael@0 | 1114 | } |
michael@0 | 1115 | |
michael@0 | 1116 | /* virtual */ bool |
michael@0 | 1117 | nsFirstLineFrame::DrainSelfOverflowList() |
michael@0 | 1118 | { |
michael@0 | 1119 | AutoFrameListPtr overflowFrames(PresContext(), StealOverflowFrames()); |
michael@0 | 1120 | if (overflowFrames) { |
michael@0 | 1121 | NS_ASSERTION(mFrames.NotEmpty(), "overflow list w/o frames"); |
michael@0 | 1122 | |
michael@0 | 1123 | bool result = !overflowFrames->IsEmpty(); |
michael@0 | 1124 | const nsFrameList::Slice& newFrames = |
michael@0 | 1125 | mFrames.AppendFrames(nullptr, *overflowFrames); |
michael@0 | 1126 | ReparentChildListStyle(PresContext(), newFrames, this); |
michael@0 | 1127 | return result; |
michael@0 | 1128 | } |
michael@0 | 1129 | return false; |
michael@0 | 1130 | } |