Bug 1652278 part 2: Flesh out PrintedSheetFrame implementation so that it serves as the container for nsPageFrame. r=TYLin

This patch:
- Creates an anon-box pseudo-style for PrintedSheetFrame, in part so that it
  can co-opt the styles that we formerly gave to page-frames in ua.css, to draw
  the sheet of paper and the shadow in Print Preview.
- Adjusts nsCSSFrameConstructor to create a PrintedSheetFrame as the parent of
  nsPageFrame (inserting between it and its nsPageSequenceFrame container, in
  the frame tree).
- Fleshes out out a simple BuildDisplayList() implementation for
  PrintedSheetFrame (taking the responsibility for "paper"-drawing from
  nsPageFrame).
- Fleshes out a simple Reflow implementation for PrintedSheetFrame, just
  placing the child page (assuming there's only one for now) at the origin.
- Adjusts nsPageFrame and nsPageSequenceFrame to account for the fact that
  there's another layer between them now.

Note that PrintedSheetFrame needs to implement AppendDirectlyOwnedAnonBoxes()
(just as nsSimplePageSequence and nsPageFrame do), since it owns anonymous
nsPageFrame instances. This implementation only needs to append the first
child, as explained in the code-comment and in
https://bugzilla.mozilla.org/show_bug.cgi?id=1374761#c9 (and of course, for
now, PrintedSheetFrame only has one child at a time anyway.)

Differential Revision: https://phabricator.services.mozilla.com/D83457
This commit is contained in:
Daniel Holbert
2020-08-05 03:28:32 +00:00
parent 42b84e4f10
commit fafdaef2c0
10 changed files with 238 additions and 50 deletions

View File

@@ -29,6 +29,7 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/PresShell.h"
#include "mozilla/PresShellInlines.h"
#include "mozilla/PrintedSheetFrame.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/ServoStyleSetInlines.h"
#include "mozilla/StaticPrefs_layout.h"
@@ -2467,22 +2468,24 @@ void nsCSSFrameConstructor::SetUpDocElementContainingBlock(
ViewportFrame
nsPageSequenceFrame
nsPageFrame
nsPageContentFrame [fixed-cb]
nsCanvasFrame [abs-cb]
root element frame (nsBlockFrame, SVGOuterSVGFrame,
nsTableWrapperFrame, nsPlaceholderFrame)
PrintedSheetFrame
nsPageFrame
nsPageContentFrame [fixed-cb]
nsCanvasFrame [abs-cb]
root element frame (nsBlockFrame, SVGOuterSVGFrame,
nsTableWrapperFrame, nsPlaceholderFrame)
Print-preview presentation, non-XUL
ViewportFrame
nsHTMLScrollFrame
nsPageSequenceFrame
nsPageFrame
nsPageContentFrame [fixed-cb]
nsCanvasFrame [abs-cb]
root element frame (nsBlockFrame, SVGOuterSVGFrame,
nsTableWrapperFrame, nsPlaceholderFrame)
PrintedSheetFrame
nsPageFrame
nsPageContentFrame [fixed-cb]
nsCanvasFrame [abs-cb]
root element frame (nsBlockFrame, SVGOuterSVGFrame,
nsTableWrapperFrame, nsPlaceholderFrame)
Print/print preview of XUL is not supported.
[fixed-cb]: the default containing block for fixed-pos content
@@ -2628,13 +2631,20 @@ void nsCSSFrameConstructor::SetUpDocElementContainingBlock(
}
if (isPaginated) {
// Create the first page
// Set the initial child lists
// Create the first printed sheet frame, as the sole child (for now) of our
// page sequence frame (rootFrame).
auto* printedSheetFrame =
ConstructPrintedSheetFrame(mPresShell, rootFrame, nullptr);
printedSheetFrame->AddStateBits(NS_FRAME_OWNS_ANON_BOXES);
SetInitialSingleChild(rootFrame, printedSheetFrame);
// Create the first page, as the sole child (for now) of the printed sheet
// frame that we just created.
nsContainerFrame* canvasFrame;
nsContainerFrame* pageFrame =
ConstructPageFrame(mPresShell, rootFrame, nullptr, canvasFrame);
ConstructPageFrame(mPresShell, printedSheetFrame, nullptr, canvasFrame);
pageFrame->AddStateBits(NS_FRAME_OWNS_ANON_BOXES);
SetInitialSingleChild(rootFrame, pageFrame);
SetInitialSingleChild(printedSheetFrame, pageFrame);
// The eventual parent of the document element frame.
// XXX should this be set for every new page (in ConstructPageFrame)?
@@ -2671,15 +2681,33 @@ void nsCSSFrameConstructor::ConstructAnonymousContentForCanvas(
aFrameList);
}
PrintedSheetFrame* nsCSSFrameConstructor::ConstructPrintedSheetFrame(
PresShell* aPresShell, nsContainerFrame* aParentFrame,
nsIFrame* aPrevSheetFrame) {
ComputedStyle* parentComputedStyle = aParentFrame->Style();
ServoStyleSet* styleSet = aPresShell->StyleSet();
RefPtr<ComputedStyle> printedSheetPseudoStyle =
styleSet->ResolveInheritingAnonymousBoxStyle(
PseudoStyleType::printedSheet, parentComputedStyle);
auto* printedSheetFrame =
NS_NewPrintedSheetFrame(aPresShell, printedSheetPseudoStyle);
printedSheetFrame->Init(nullptr, aParentFrame, aPrevSheetFrame);
return printedSheetFrame;
}
nsContainerFrame* nsCSSFrameConstructor::ConstructPageFrame(
PresShell* aPresShell, nsContainerFrame* aParentFrame,
nsIFrame* aPrevPageFrame, nsContainerFrame*& aCanvasFrame) {
ComputedStyle* parentComputedStyle = aParentFrame->Style();
ServoStyleSet* styleSet = aPresShell->StyleSet();
RefPtr<ComputedStyle> pagePseudoStyle;
pagePseudoStyle = styleSet->ResolveInheritingAnonymousBoxStyle(
PseudoStyleType::page, parentComputedStyle);
RefPtr<ComputedStyle> pagePseudoStyle =
styleSet->ResolveInheritingAnonymousBoxStyle(PseudoStyleType::page,
parentComputedStyle);
nsContainerFrame* pageFrame = NS_NewPageFrame(aPresShell, pagePseudoStyle);
@@ -7931,8 +7959,10 @@ nsIFrame* nsCSSFrameConstructor::CreateContinuingFrame(
"no support for fragmenting table captions yet");
newFrame = NS_NewColumnSetFrame(mPresShell, computedStyle, nsFrameState(0));
newFrame->Init(content, aParentFrame, aFrame);
} else if (LayoutFrameType::PrintedSheet == frameType) {
newFrame = ConstructPrintedSheetFrame(mPresShell, aParentFrame, aFrame);
} else if (LayoutFrameType::Page == frameType) {
nsContainerFrame* canvasFrame;
nsContainerFrame* canvasFrame; // (unused outparam for ConstructPageFrame)
newFrame =
ConstructPageFrame(mPresShell, aParentFrame, aFrame, canvasFrame);
} else if (LayoutFrameType::TableWrapper == frameType) {