Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the canvas is always the first child of its wrapper #19204

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,10 @@ class PDFPageView {

const hasHCM = !!(pageColors?.background && pageColors?.foreground);
const prevCanvas = this.canvas;

// In HCM, a final filter is applied on the canvas which means that
// before it's applied we've normal colors. Consequently, to avoid to
// have a final flash we just display it once all the drawing is done.
const updateOnFirstShow = !prevCanvas && !hasHCM;
this.canvas = canvas;
this.#originalViewport = viewport;
Expand All @@ -984,7 +988,13 @@ class PDFPageView {
// Don't add the canvas until the first draw callback, or until
// drawing is complete when `!this.renderingQueue`, to prevent black
// flickering.
canvasWrapper.append(canvas);
// In whatever case, the canvas must be the first child.
const { firstChild } = canvasWrapper;
if (firstChild) {
firstChild.before(canvas);
} else {
canvasWrapper.append(canvas);
}
showCanvas = null;
return;
}
Expand All @@ -996,10 +1006,12 @@ class PDFPageView {
prevCanvas.replaceWith(canvas);
prevCanvas.width = prevCanvas.height = 0;
} else {
// In HCM, a final filter is applied on the canvas which means that
// before it's applied we've normal colors. Consequently, to avoid to
// have a final flash we just display it once all the drawing is done.
canvasWrapper.append(canvas);
const { firstChild } = canvasWrapper;
if (firstChild) {
firstChild.before(canvas);
} else {
canvasWrapper.append(canvas);
}
}

showCanvas = null;
Expand Down
Loading