2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-01-25 05:07:03 +03:00
|
|
|
#include "nsPageContentFrame.h"
|
2019-04-03 15:40:26 +03:00
|
|
|
|
|
|
|
#include "mozilla/PresShell.h"
|
|
|
|
|
2007-07-26 08:03:29 +04:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2019-05-22 15:01:33 +03:00
|
|
|
#include "nsPageSequenceFrame.h"
|
2002-01-25 05:07:03 +03:00
|
|
|
|
2016-12-01 01:47:45 +03:00
|
|
|
using namespace mozilla;
|
2014-07-24 12:28:46 +04:00
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsPageContentFrame* NS_NewPageContentFrame(PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell)
|
|
|
|
nsPageContentFrame(aStyle, aPresShell->GetPresContext());
|
2002-01-31 17:24:06 +03:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsPageContentFrame)
|
|
|
|
|
2007-07-26 08:03:29 +04:00
|
|
|
void nsPageContentFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2007-07-26 08:03:29 +04:00
|
|
|
nsReflowStatus& aStatus) {
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsPageContentFrame");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
2002-01-25 05:07:03 +03:00
|
|
|
|
2008-09-08 12:13:17 +04:00
|
|
|
if (GetPrevInFlow() && (GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
2007-08-07 20:06:56 +04:00
|
|
|
nsresult rv =
|
|
|
|
aPresContext->PresShell()->FrameConstructor()->ReplicateFixedFrames(
|
|
|
|
this);
|
2014-05-13 04:47:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
2007-07-26 08:03:29 +04:00
|
|
|
}
|
|
|
|
|
2010-08-06 01:59:36 +04:00
|
|
|
// Set our size up front, since some parts of reflow depend on it
|
|
|
|
// being already set. Note that the computed height may be
|
|
|
|
// unconstrained; that's ok. Consumers should watch out for that.
|
2016-07-21 13:36:39 +03:00
|
|
|
nsSize maxSize(aReflowInput.ComputedWidth(), aReflowInput.ComputedHeight());
|
2012-09-01 01:20:56 +04:00
|
|
|
SetSize(maxSize);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2008-09-08 12:13:17 +04:00
|
|
|
// A PageContentFrame must always have one child: the canvas frame.
|
2006-04-01 05:19:28 +04:00
|
|
|
// Resize our frame allowing it only to be as big as we are
|
|
|
|
// XXX Pay attention to the page's border and padding...
|
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
nsIFrame* frame = mFrames.FirstChild();
|
2014-07-24 12:28:46 +04:00
|
|
|
WritingMode wm = frame->GetWritingMode();
|
|
|
|
LogicalSize logicalSize(wm, maxSize);
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput kidReflowInput(aPresContext, aReflowInput, frame, logicalSize);
|
|
|
|
kidReflowInput.SetComputedBSize(logicalSize.BSize(wm));
|
2006-04-01 05:19:28 +04:00
|
|
|
|
2008-02-24 15:19:17 +03:00
|
|
|
// Reflow the page content area
|
2019-08-08 22:48:19 +03:00
|
|
|
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowInput, 0, 0,
|
|
|
|
ReflowChildFlags::Default, aStatus);
|
2008-02-24 15:19:17 +03:00
|
|
|
|
2006-04-01 05:19:28 +04:00
|
|
|
// The document element's background should cover the entire canvas, so
|
|
|
|
// take into account the combined area and any space taken up by
|
|
|
|
// absolutely positioned elements
|
|
|
|
nsMargin padding(0, 0, 0, 0);
|
|
|
|
|
|
|
|
// XXXbz this screws up percentage padding (sets padding to zero
|
|
|
|
// in the percentage padding case)
|
2016-07-21 13:36:39 +03:00
|
|
|
kidReflowInput.mStylePadding->GetPadding(padding);
|
2006-04-01 05:19:28 +04:00
|
|
|
|
2010-10-07 08:25:47 +04:00
|
|
|
// This is for shrink-to-fit, and therefore we want to use the
|
|
|
|
// scrollable overflow, since the purpose of shrink to fit is to
|
|
|
|
// make the content that ought to be reachable (represented by the
|
|
|
|
// scrollable overflow) fit in the page.
|
|
|
|
if (frame->HasOverflowAreas()) {
|
2006-04-01 05:19:28 +04:00
|
|
|
// The background covers the content area and padding area, so check
|
|
|
|
// for children sticking outside the child frame's padding edge
|
2010-10-07 08:25:47 +04:00
|
|
|
nscoord xmost = aDesiredSize.ScrollableOverflow().XMost();
|
2013-12-27 21:59:52 +04:00
|
|
|
if (xmost > aDesiredSize.Width()) {
|
2014-02-04 06:12:13 +04:00
|
|
|
nscoord widthToFit =
|
|
|
|
xmost + padding.right +
|
2016-11-18 13:12:25 +03:00
|
|
|
kidReflowInput.mStyleBorder->GetComputedBorderWidth(eSideRight);
|
2014-02-04 06:12:13 +04:00
|
|
|
float ratio = float(maxSize.width) / widthToFit;
|
|
|
|
NS_ASSERTION(ratio >= 0.0 && ratio < 1.0,
|
|
|
|
"invalid shrink-to-fit ratio");
|
|
|
|
mPD->mShrinkToFitRatio = std::min(mPD->mShrinkToFitRatio, ratio);
|
2002-09-20 01:45:07 +04:00
|
|
|
}
|
2006-04-01 05:19:28 +04:00
|
|
|
}
|
2002-09-20 01:45:07 +04:00
|
|
|
|
2006-04-01 05:19:28 +04:00
|
|
|
// Place and size the child
|
2016-07-21 13:36:39 +03:00
|
|
|
FinishReflowChild(frame, aPresContext, aDesiredSize, &kidReflowInput, 0, 0,
|
2019-08-08 22:48:19 +03:00
|
|
|
ReflowChildFlags::Default);
|
2002-01-25 05:07:03 +03:00
|
|
|
|
2017-02-11 17:38:48 +03:00
|
|
|
NS_ASSERTION(aPresContext->IsDynamic() || !aStatus.IsFullyComplete() ||
|
2006-04-01 05:19:28 +04:00
|
|
|
!frame->GetNextInFlow(),
|
|
|
|
"bad child flow list");
|
|
|
|
}
|
2011-04-30 03:02:33 +04:00
|
|
|
|
|
|
|
// Reflow our fixed frames
|
2017-02-14 12:55:48 +03:00
|
|
|
nsReflowStatus fixedStatus;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowInput, fixedStatus);
|
2017-02-11 17:45:07 +03:00
|
|
|
NS_ASSERTION(fixedStatus.IsComplete(),
|
|
|
|
"fixed frames can be truncated, but not incomplete");
|
2006-04-01 05:19:28 +04:00
|
|
|
|
|
|
|
// Return our desired size
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = aReflowInput.GetWritingMode();
|
|
|
|
aDesiredSize.ISize(wm) = aReflowInput.ComputedISize();
|
|
|
|
if (aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aDesiredSize.BSize(wm) = aReflowInput.ComputedBSize();
|
2002-01-25 05:07:03 +03:00
|
|
|
}
|
2010-08-28 03:15:08 +04:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
|
2002-01-25 05:07:03 +03:00
|
|
|
}
|
|
|
|
|
2017-06-21 18:45:14 +03:00
|
|
|
void nsPageContentFrame::AppendDirectlyOwnedAnonBoxes(
|
|
|
|
nsTArray<OwnedAnonBox>& aResult) {
|
|
|
|
MOZ_ASSERT(mFrames.FirstChild(),
|
|
|
|
"pageContentFrame must have a canvasFrame child");
|
|
|
|
aResult.AppendElement(mFrames.FirstChild());
|
|
|
|
}
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2002-01-25 05:07:03 +03:00
|
|
|
nsresult nsPageContentFrame::GetFrameName(nsAString& aResult) const {
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|