Bug 1802238 - Don't allow using mixed page sizes when printing unless layout.css.allow-mixed-page-sizes is set r=dholbert

Differential Revision: https://phabricator.services.mozilla.com/D162920
This commit is contained in:
Emily McDonough 2022-12-06 21:24:29 +00:00
parent b71d7b535b
commit 7b23072da6
3 changed files with 25 additions and 7 deletions

View File

@ -402,6 +402,8 @@ void nsPageContentFrame::AppendDirectlyOwnedAnonBoxes(
} }
void nsPageContentFrame::EnsurePageName() { void nsPageContentFrame::EnsurePageName() {
MOZ_ASSERT(HasAnyStateBits(NS_FRAME_FIRST_REFLOW),
"Should only have been called on first reflow");
if (mPageName) { if (mPageName) {
return; return;
} }

View File

@ -594,18 +594,20 @@ nsPageContentFrame* nsPageFrame::PageContentFrame() const {
} }
nsSize nsPageFrame::ComputePageSize() const { nsSize nsPageFrame::ComputePageSize() const {
const nsPageContentFrame* const pcf = PageContentFrame();
nsSize size = PresContext()->GetPageSize();
// Compute the expected page-size. // Compute the expected page-size.
const nsStylePage* const stylePage = pcf->StylePage(); const nsPageFrame* const frame =
const StylePageSize& pageSize = stylePage->mSize; StaticPrefs::layout_css_allow_mixed_page_sizes()
? this
: static_cast<nsPageFrame*>(FirstContinuation());
const StylePageSize& pageSize = frame->PageContentFrame()->StylePage()->mSize;
if (pageSize.IsSize()) { if (pageSize.IsSize()) {
// Use the specified size // Use the specified size
return nsSize{pageSize.AsSize().width.ToAppUnits(), return nsSize{pageSize.AsSize().width.ToAppUnits(),
pageSize.AsSize().height.ToAppUnits()}; pageSize.AsSize().height.ToAppUnits()};
} }
nsSize size = PresContext()->GetPageSize();
if (pageSize.IsOrientation()) { if (pageSize.IsOrientation()) {
// Ensure the correct orientation is applied. // Ensure the correct orientation is applied.
if (pageSize.AsOrientation() == StylePageSizeOrientation::Portrait) { if (pageSize.AsOrientation() == StylePageSizeOrientation::Portrait) {
@ -631,8 +633,16 @@ float nsPageFrame::ComputePageSizeScale(const nsSize aContentPageSize) const {
// Check for the simplest case first, an auto page-size which requires no // Check for the simplest case first, an auto page-size which requires no
// scaling at all. // scaling at all.
if (PageContentFrame()->StylePage()->mSize.IsAuto()) { {
return 1.0f; const nsPageFrame* const frame =
StaticPrefs::layout_css_allow_mixed_page_sizes()
? this
: static_cast<nsPageFrame*>(FirstContinuation());
const StylePageSize& pageSize =
frame->PageContentFrame()->StylePage()->mSize;
if (pageSize.IsAuto()) {
return 1.0f;
}
} }
// Compute scaling due to a possible mismatch in the paper size we are // Compute scaling due to a possible mismatch in the paper size we are

View File

@ -8524,6 +8524,12 @@
mirror: always mirror: always
rust: true rust: true
# Enables support for different CSS page sizes on each page when printing.
- name: layout.css.allow-mixed-page-sizes
type: RelaxedAtomicBool
value: false
mirror: always
# Dictates whether or not the prefers contrast media query will be # Dictates whether or not the prefers contrast media query will be
# usable. # usable.
# true: prefers-contrast will toggle based on OS and browser settings. # true: prefers-contrast will toggle based on OS and browser settings.