Skip to content

Commit e87b9c5

Browse files
committed
Remove the scrollIntoView function
and rely on the HTMLElement.scrollIntoView function instead.
1 parent 2643125 commit e87b9c5

3 files changed

Lines changed: 23 additions & 52 deletions

File tree

web/pdf_viewer.css

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
--viewer-container-height: 0;
3232
--pdfViewer-padding-bottom: 0;
33-
--page-margin: 1px auto -8px;
34-
--page-border: 9px solid transparent;
33+
--page-margin-top: 10px;
34+
--page-outline: none;
3535
--spreadHorizontalWrapped-margin-LR: -3.5px;
3636
--loading-icon-delay: 400ms;
3737
--focus-ring-color: light-dark(#0060df, #0df);
@@ -42,8 +42,7 @@
4242

4343
@media screen and (forced-colors: active) {
4444
--pdfViewer-padding-bottom: 9px;
45-
--page-margin: 8px auto -1px;
46-
--page-border: 1px solid CanvasText;
45+
--page-outline: 1px solid CanvasText;
4746
--spreadHorizontalWrapped-margin-LR: 3.5px;
4847
--focus-ring-color: CanvasText;
4948
--new-badge-bg: AccentColor;
@@ -142,12 +141,18 @@
142141
direction: ltr;
143142
width: 816px;
144143
height: 1056px;
145-
margin: var(--page-margin);
144+
margin-inline: auto;
145+
margin-block: var(--page-margin-top) 0;
146146
position: relative;
147147
overflow: visible;
148-
border: var(--page-border);
148+
outline: var(--page-outline);
149149
background-clip: content-box;
150150
background-color: var(--page-bg-color, rgb(255 255 255));
151+
scroll-margin-top: calc(0 - var(--page-margin-top));
152+
153+
&:last-child {
154+
margin-block-end: var(--page-margin-top);
155+
}
151156
}
152157

153158
.pdfViewer .dummyPage {

web/pdf_viewer.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import {
5757
PresentationModeState,
5858
removeNullCharacters,
5959
SCROLLBAR_PADDING,
60-
scrollIntoView,
6160
ScrollMode,
6261
SpreadMode,
6362
TextLayerMode,
@@ -1458,7 +1457,18 @@ class PDFViewer {
14581457
pageSpot = { left: 0, top: 0 };
14591458
}
14601459
}
1461-
scrollIntoView(div, pageSpot);
1460+
1461+
div.scrollIntoView({
1462+
behavior: "auto",
1463+
block: "start",
1464+
inline: pageSpot ? "start" : "nearest",
1465+
});
1466+
if (pageSpot?.top) {
1467+
this.container.scrollTop += pageSpot.top;
1468+
}
1469+
if (pageSpot?.left) {
1470+
this.container.scrollLeft += pageSpot.left;
1471+
}
14621472

14631473
// Ensure that the correct *initial* document position is set, when any
14641474
// OpenParameters are used, for documents with non-default Scroll/Spread

web/ui_utils.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -69,49 +69,6 @@ const CursorTool = {
6969
// Used by `PDFViewerApplication`, and by the API unit-tests.
7070
const AutoPrintRegExp = /\bprint\s*\(/;
7171

72-
/**
73-
* Scrolls specified element into view of its parent.
74-
* @param {HTMLElement} element - The element to be visible.
75-
* @param {Object} [spot] - An object with optional top and left properties,
76-
* specifying the offset from the top left edge.
77-
* @param {number} [spot.left]
78-
* @param {number} [spot.top]
79-
*/
80-
function scrollIntoView(element, spot) {
81-
// Assuming offsetParent is available (it's not available when viewer is in
82-
// hidden iframe or object). We have to scroll: if the offsetParent is not set
83-
// producing the error. See also animationStarted.
84-
let parent = element.offsetParent;
85-
if (!parent) {
86-
console.error("offsetParent is not set -- cannot scroll");
87-
return;
88-
}
89-
let offsetY = element.offsetTop + element.clientTop;
90-
let offsetX = element.offsetLeft + element.clientLeft;
91-
while (
92-
parent.clientHeight === parent.scrollHeight &&
93-
parent.clientWidth === parent.scrollWidth
94-
) {
95-
offsetY += parent.offsetTop;
96-
offsetX += parent.offsetLeft;
97-
98-
parent = parent.offsetParent;
99-
if (!parent) {
100-
return; // no need to scroll
101-
}
102-
}
103-
if (spot) {
104-
if (spot.top !== undefined) {
105-
offsetY += spot.top;
106-
}
107-
if (spot.left !== undefined) {
108-
offsetX += spot.left;
109-
parent.scrollLeft = offsetX;
110-
}
111-
}
112-
parent.scrollTop = offsetY;
113-
}
114-
11572
/**
11673
* Helper function to start monitoring the scroll event and converting them into
11774
* PDF.js friendly one: with scroll debounce and scroll direction.
@@ -890,7 +847,6 @@ export {
890847
ProgressBar,
891848
removeNullCharacters,
892849
SCROLLBAR_PADDING,
893-
scrollIntoView,
894850
ScrollMode,
895851
SidebarView,
896852
SpreadMode,

0 commit comments

Comments
 (0)