Move additional code/methods into BaseViewer and have the extending classes override/extend methods as necessary

This attempts to provide more "default" methods in the base class, in order to reduce unnecessary duplication and to improve self-documentation of the `BaseViewer` class slightly.
The following changes are made (in no particular order):
 - Have `BaseViewer` implement the `_scrollIntoView` method, and *extend* it as necessary in `PDFViewer`/`PDFSinglePageViewer`.
 - Simply inline the `BaseViewer._resizeBuffer` method, in `BaseViewer.update`, since there's only one call-site at this point.
 - Provide a default implementation of `_isScrollModeHorizontal` in `BaseViewer`, and have `PDFSinglePageViewer` override it.
 - Provide a default implementation of `_getVisiblePages`, and have `PDFViewer` extend it and `PDFSinglePageViewer` override it.
This commit is contained in:
Jonas Jenwald 2019-01-23 09:11:06 +01:00
parent 9128335c4d
commit 06cda4c2e7
3 changed files with 24 additions and 38 deletions

View file

@ -14,7 +14,6 @@
*/
import { BaseViewer } from './base_viewer';
import { scrollIntoView } from './ui_utils';
import { shadow } from 'pdfjs-lib';
class PDFSinglePageViewer extends BaseViewer {
@ -87,7 +86,7 @@ class PDFSinglePageViewer extends BaseViewer {
let previousLocation = this._location;
this._ensurePageViewVisible();
scrollIntoView(pageDiv, pageSpot);
super._scrollIntoView({ pageDiv, pageSpot, pageNumber, });
// Since scrolling is tracked using `requestAnimationFrame`, update the
// scroll direction during the next `this._scrollUpdate` invocation.