1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/nsPageContentFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +#include "nsPageContentFrame.h" 1.9 +#include "nsCSSFrameConstructor.h" 1.10 +#include "nsPresContext.h" 1.11 +#include "nsGkAtoms.h" 1.12 +#include "nsIPresShell.h" 1.13 +#include "nsSimplePageSequenceFrame.h" 1.14 + 1.15 +nsIFrame* 1.16 +NS_NewPageContentFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) 1.17 +{ 1.18 + return new (aPresShell) nsPageContentFrame(aContext); 1.19 +} 1.20 + 1.21 +NS_IMPL_FRAMEARENA_HELPERS(nsPageContentFrame) 1.22 + 1.23 +nsresult 1.24 +nsPageContentFrame::Reflow(nsPresContext* aPresContext, 1.25 + nsHTMLReflowMetrics& aDesiredSize, 1.26 + const nsHTMLReflowState& aReflowState, 1.27 + nsReflowStatus& aStatus) 1.28 +{ 1.29 + DO_GLOBAL_REFLOW_COUNT("nsPageContentFrame"); 1.30 + DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); 1.31 + aStatus = NS_FRAME_COMPLETE; // initialize out parameter 1.32 + nsresult rv = NS_OK; 1.33 + 1.34 + if (GetPrevInFlow() && (GetStateBits() & NS_FRAME_FIRST_REFLOW)) { 1.35 + nsresult rv = aPresContext->PresShell()->FrameConstructor() 1.36 + ->ReplicateFixedFrames(this); 1.37 + NS_ENSURE_SUCCESS(rv, rv); 1.38 + } 1.39 + 1.40 + // Set our size up front, since some parts of reflow depend on it 1.41 + // being already set. Note that the computed height may be 1.42 + // unconstrained; that's ok. Consumers should watch out for that. 1.43 + nsSize maxSize(aReflowState.ComputedWidth(), 1.44 + aReflowState.ComputedHeight()); 1.45 + SetSize(maxSize); 1.46 + 1.47 + // A PageContentFrame must always have one child: the canvas frame. 1.48 + // Resize our frame allowing it only to be as big as we are 1.49 + // XXX Pay attention to the page's border and padding... 1.50 + if (mFrames.NotEmpty()) { 1.51 + nsIFrame* frame = mFrames.FirstChild(); 1.52 + nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame, maxSize); 1.53 + kidReflowState.SetComputedHeight(maxSize.height); 1.54 + 1.55 + // Reflow the page content area 1.56 + rv = ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus); 1.57 + NS_ENSURE_SUCCESS(rv, rv); 1.58 + 1.59 + // The document element's background should cover the entire canvas, so 1.60 + // take into account the combined area and any space taken up by 1.61 + // absolutely positioned elements 1.62 + nsMargin padding(0,0,0,0); 1.63 + 1.64 + // XXXbz this screws up percentage padding (sets padding to zero 1.65 + // in the percentage padding case) 1.66 + kidReflowState.mStylePadding->GetPadding(padding); 1.67 + 1.68 + // This is for shrink-to-fit, and therefore we want to use the 1.69 + // scrollable overflow, since the purpose of shrink to fit is to 1.70 + // make the content that ought to be reachable (represented by the 1.71 + // scrollable overflow) fit in the page. 1.72 + if (frame->HasOverflowAreas()) { 1.73 + // The background covers the content area and padding area, so check 1.74 + // for children sticking outside the child frame's padding edge 1.75 + nscoord xmost = aDesiredSize.ScrollableOverflow().XMost(); 1.76 + if (xmost > aDesiredSize.Width()) { 1.77 + nscoord widthToFit = xmost + padding.right + 1.78 + kidReflowState.mStyleBorder->GetComputedBorderWidth(NS_SIDE_RIGHT); 1.79 + float ratio = float(maxSize.width) / widthToFit; 1.80 + NS_ASSERTION(ratio >= 0.0 && ratio < 1.0, "invalid shrink-to-fit ratio"); 1.81 + mPD->mShrinkToFitRatio = std::min(mPD->mShrinkToFitRatio, ratio); 1.82 + } 1.83 + } 1.84 + 1.85 + // Place and size the child 1.86 + FinishReflowChild(frame, aPresContext, aDesiredSize, &kidReflowState, 0, 0, 0); 1.87 + 1.88 + NS_ASSERTION(aPresContext->IsDynamic() || !NS_FRAME_IS_FULLY_COMPLETE(aStatus) || 1.89 + !frame->GetNextInFlow(), "bad child flow list"); 1.90 + } 1.91 + 1.92 + // Reflow our fixed frames 1.93 + nsReflowStatus fixedStatus = NS_FRAME_COMPLETE; 1.94 + ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowState, fixedStatus); 1.95 + NS_ASSERTION(NS_FRAME_IS_COMPLETE(fixedStatus), "fixed frames can be truncated, but not incomplete"); 1.96 + 1.97 + // Return our desired size 1.98 + aDesiredSize.Width() = aReflowState.ComputedWidth(); 1.99 + if (aReflowState.ComputedHeight() != NS_UNCONSTRAINEDSIZE) { 1.100 + aDesiredSize.Height() = aReflowState.ComputedHeight(); 1.101 + } 1.102 + 1.103 + FinishAndStoreOverflow(&aDesiredSize); 1.104 + 1.105 + NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); 1.106 + return NS_OK; 1.107 +} 1.108 + 1.109 +nsIAtom* 1.110 +nsPageContentFrame::GetType() const 1.111 +{ 1.112 + return nsGkAtoms::pageContentFrame; 1.113 +} 1.114 + 1.115 +#ifdef DEBUG_FRAME_DUMP 1.116 +nsresult 1.117 +nsPageContentFrame::GetFrameName(nsAString& aResult) const 1.118 +{ 1.119 + return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult); 1.120 +} 1.121 +#endif