layout/generic/nsPageContentFrame.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 #include "nsPageContentFrame.h"
michael@0 6 #include "nsCSSFrameConstructor.h"
michael@0 7 #include "nsPresContext.h"
michael@0 8 #include "nsGkAtoms.h"
michael@0 9 #include "nsIPresShell.h"
michael@0 10 #include "nsSimplePageSequenceFrame.h"
michael@0 11
michael@0 12 nsIFrame*
michael@0 13 NS_NewPageContentFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
michael@0 14 {
michael@0 15 return new (aPresShell) nsPageContentFrame(aContext);
michael@0 16 }
michael@0 17
michael@0 18 NS_IMPL_FRAMEARENA_HELPERS(nsPageContentFrame)
michael@0 19
michael@0 20 nsresult
michael@0 21 nsPageContentFrame::Reflow(nsPresContext* aPresContext,
michael@0 22 nsHTMLReflowMetrics& aDesiredSize,
michael@0 23 const nsHTMLReflowState& aReflowState,
michael@0 24 nsReflowStatus& aStatus)
michael@0 25 {
michael@0 26 DO_GLOBAL_REFLOW_COUNT("nsPageContentFrame");
michael@0 27 DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
michael@0 28 aStatus = NS_FRAME_COMPLETE; // initialize out parameter
michael@0 29 nsresult rv = NS_OK;
michael@0 30
michael@0 31 if (GetPrevInFlow() && (GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
michael@0 32 nsresult rv = aPresContext->PresShell()->FrameConstructor()
michael@0 33 ->ReplicateFixedFrames(this);
michael@0 34 NS_ENSURE_SUCCESS(rv, rv);
michael@0 35 }
michael@0 36
michael@0 37 // Set our size up front, since some parts of reflow depend on it
michael@0 38 // being already set. Note that the computed height may be
michael@0 39 // unconstrained; that's ok. Consumers should watch out for that.
michael@0 40 nsSize maxSize(aReflowState.ComputedWidth(),
michael@0 41 aReflowState.ComputedHeight());
michael@0 42 SetSize(maxSize);
michael@0 43
michael@0 44 // A PageContentFrame must always have one child: the canvas frame.
michael@0 45 // Resize our frame allowing it only to be as big as we are
michael@0 46 // XXX Pay attention to the page's border and padding...
michael@0 47 if (mFrames.NotEmpty()) {
michael@0 48 nsIFrame* frame = mFrames.FirstChild();
michael@0 49 nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame, maxSize);
michael@0 50 kidReflowState.SetComputedHeight(maxSize.height);
michael@0 51
michael@0 52 // Reflow the page content area
michael@0 53 rv = ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus);
michael@0 54 NS_ENSURE_SUCCESS(rv, rv);
michael@0 55
michael@0 56 // The document element's background should cover the entire canvas, so
michael@0 57 // take into account the combined area and any space taken up by
michael@0 58 // absolutely positioned elements
michael@0 59 nsMargin padding(0,0,0,0);
michael@0 60
michael@0 61 // XXXbz this screws up percentage padding (sets padding to zero
michael@0 62 // in the percentage padding case)
michael@0 63 kidReflowState.mStylePadding->GetPadding(padding);
michael@0 64
michael@0 65 // This is for shrink-to-fit, and therefore we want to use the
michael@0 66 // scrollable overflow, since the purpose of shrink to fit is to
michael@0 67 // make the content that ought to be reachable (represented by the
michael@0 68 // scrollable overflow) fit in the page.
michael@0 69 if (frame->HasOverflowAreas()) {
michael@0 70 // The background covers the content area and padding area, so check
michael@0 71 // for children sticking outside the child frame's padding edge
michael@0 72 nscoord xmost = aDesiredSize.ScrollableOverflow().XMost();
michael@0 73 if (xmost > aDesiredSize.Width()) {
michael@0 74 nscoord widthToFit = xmost + padding.right +
michael@0 75 kidReflowState.mStyleBorder->GetComputedBorderWidth(NS_SIDE_RIGHT);
michael@0 76 float ratio = float(maxSize.width) / widthToFit;
michael@0 77 NS_ASSERTION(ratio >= 0.0 && ratio < 1.0, "invalid shrink-to-fit ratio");
michael@0 78 mPD->mShrinkToFitRatio = std::min(mPD->mShrinkToFitRatio, ratio);
michael@0 79 }
michael@0 80 }
michael@0 81
michael@0 82 // Place and size the child
michael@0 83 FinishReflowChild(frame, aPresContext, aDesiredSize, &kidReflowState, 0, 0, 0);
michael@0 84
michael@0 85 NS_ASSERTION(aPresContext->IsDynamic() || !NS_FRAME_IS_FULLY_COMPLETE(aStatus) ||
michael@0 86 !frame->GetNextInFlow(), "bad child flow list");
michael@0 87 }
michael@0 88
michael@0 89 // Reflow our fixed frames
michael@0 90 nsReflowStatus fixedStatus = NS_FRAME_COMPLETE;
michael@0 91 ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowState, fixedStatus);
michael@0 92 NS_ASSERTION(NS_FRAME_IS_COMPLETE(fixedStatus), "fixed frames can be truncated, but not incomplete");
michael@0 93
michael@0 94 // Return our desired size
michael@0 95 aDesiredSize.Width() = aReflowState.ComputedWidth();
michael@0 96 if (aReflowState.ComputedHeight() != NS_UNCONSTRAINEDSIZE) {
michael@0 97 aDesiredSize.Height() = aReflowState.ComputedHeight();
michael@0 98 }
michael@0 99
michael@0 100 FinishAndStoreOverflow(&aDesiredSize);
michael@0 101
michael@0 102 NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
michael@0 103 return NS_OK;
michael@0 104 }
michael@0 105
michael@0 106 nsIAtom*
michael@0 107 nsPageContentFrame::GetType() const
michael@0 108 {
michael@0 109 return nsGkAtoms::pageContentFrame;
michael@0 110 }
michael@0 111
michael@0 112 #ifdef DEBUG_FRAME_DUMP
michael@0 113 nsresult
michael@0 114 nsPageContentFrame::GetFrameName(nsAString& aResult) const
michael@0 115 {
michael@0 116 return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult);
michael@0 117 }
michael@0 118 #endif

mercurial