Bug 1869217. Don't use the @page rules that match the first page as the page defaults. r=emilio

page-rule-specificity-001-print.html is the only test that actually fails prior
to this patch (it already passes in Chrome).

Differential Revision: https://phabricator.services.mozilla.com/D196000
This commit is contained in:
Jonathan Watt 2023-12-11 10:59:18 +00:00
Родитель aac78f7939
Коммит 7dd21bd102
8 изменённых файлов: 131 добавлений и 11 удалений

Просмотреть файл

@ -1384,8 +1384,8 @@ nsresult nsPrintJob::ReflowPrintObject(const UniquePtr<nsPrintObject>& aPO) {
}
}
const ServoStyleSet::FirstPageSizeAndOrientation sizeAndOrientation =
presShell->StyleSet()->GetFirstPageSizeAndOrientation(firstPageName);
const ServoStyleSet::PageSizeAndOrientation sizeAndOrientation =
presShell->StyleSet()->GetDefaultPageSizeAndOrientation();
// XXX Should we enable this for known save-to-PDF pseudo-printers once
// bug 1826301 is fixed?
if (mPrintSettings->GetOutputFormat() ==

Просмотреть файл

@ -662,11 +662,11 @@ StyleSheet* ServoStyleSet::SheetAt(Origin aOrigin, size_t aIndex) const {
Servo_StyleSet_GetSheetAt(mRawData.get(), aOrigin, aIndex));
}
ServoStyleSet::FirstPageSizeAndOrientation
ServoStyleSet::GetFirstPageSizeAndOrientation(const nsAtom* aFirstPageName) {
FirstPageSizeAndOrientation retval;
ServoStyleSet::PageSizeAndOrientation
ServoStyleSet::GetDefaultPageSizeAndOrientation() {
PageSizeAndOrientation retval;
const RefPtr<ComputedStyle> style =
ResolvePageContentStyle(aFirstPageName, StylePagePseudoClassFlags::FIRST);
ResolvePageContentStyle(nullptr, StylePagePseudoClassFlags::NONE);
const StylePageSize& pageSize = style->StylePage()->mSize;
if (pageSize.IsSize()) {

Просмотреть файл

@ -260,12 +260,12 @@ class ServoStyleSet {
size_t SheetCount(Origin) const;
StyleSheet* SheetAt(Origin, size_t aIndex) const;
struct FirstPageSizeAndOrientation {
struct PageSizeAndOrientation {
Maybe<StylePageSizeOrientation> orientation;
Maybe<nsSize> size;
};
// Gets the specified orientation and size used when the first page printed
// has the name |aFirstPageName|, based on the page-size property.
// Gets the default page size and orientation (the size/orientation specified
// by @page rules without a selector list), if any.
//
// If the specified size is just an orientation, then the size will be set to
// nothing and the orientation will be set accordingly.
@ -273,8 +273,7 @@ class ServoStyleSet {
// to nothing.
// Otherwise, the size will and orientation is determined by the specified
// page size.
FirstPageSizeAndOrientation GetFirstPageSizeAndOrientation(
const nsAtom* aFirstPageName);
PageSizeAndOrientation GetDefaultPageSizeAndOrientation();
void AppendAllNonDocumentAuthorSheets(nsTArray<StyleSheet*>& aArray) const;

Просмотреть файл

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>CSS Paged Media: @page without selector provides defaults</title>
<link rel="author" title="Jonathan Watt" href="mailto:jwatt@jwatt.org"/>
<link rel="help" href="https://drafts.csswg.org/css-page/#cascading-and-page-context"/>
<meta name="assert" content="@page with a selector should not apply to non-matched pages">
<link rel="match" href="page-rule-specificity-print-landscape-ref.html"/>
<meta name="reftest-pages" content="2">
<style>
/* WPT Print Reftest default size is 5x3in - this should only change that for the first page */
@page :first {
size: portrait;
}
div:first-of-type {
break-after: page;
}
body {
margin: 0;
}
</style>
<body>
<div>Portrait</div>
<div>Landscape</div>
</body>
</html>

Просмотреть файл

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>CSS Paged Media: @page without selector provides defaults</title>
<link rel="author" title="Jonathan Watt" href="mailto:jwatt@jwatt.org"/>
<link rel="help" href="https://drafts.csswg.org/css-page/#cascading-and-page-context"/>
<meta name="assert" content="@page rule without a selector list should apply to pages not matched by rules with selectors">
<link rel="match" href="page-rule-specificity-print-landscape-ref.html"/>
<meta name="reftest-pages" content="2">
<style>
@page :first {
size: portrait;
}
@page {
size: landscape;
}
div:first-of-type {
break-after: page;
}
body {
margin: 0;
}
</style>
<body>
<div>Portrait</div>
<div>Landscape</div>
</body>
</html>

Просмотреть файл

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>CSS Paged Media: @page without selector provides defaults</title>
<link rel="author" title="Jonathan Watt" href="mailto:jwatt@jwatt.org"/>
<link rel="help" href="https://drafts.csswg.org/css-page/#cascading-and-page-context"/>
<meta name="assert" content="@page rule without a selector list should apply to pages not matched by rules with selectors">
<link rel="match" href="page-rule-specificity-print-portrait-ref.html"/>
<meta name="reftest-pages" content="2">
<style>
@page :first {
size: landscape;
}
@page {
size: portrait;
}
div:first-of-type {
break-after: page;
}
body {
margin: 0;
}
</style>
<body>
<div>Landscape</div>
<div>Portrait</div>
</body>
</html>

Просмотреть файл

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<link rel="author" title="Jonathan Watt" href="mailto:jwatt@jwatt.org"/>
<style>
body {
margin: 0;
}
</style>
<body>
<div>Landscape</div>
</body>
</html>

Просмотреть файл

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<link rel="author" title="Jonathan Watt" href="mailto:jwatt@jwatt.org"/>
<style>
@page :first {
size: portrait;
}
body {
margin: 0;
}
</style>
<body>
<div>Portrait</div>
</body>
</html>