Move/refactor the code in the BaseViewer.update method to reduce duplication in the extending classes

Since most of the important rendering code is already (almost) identical between `PDFViewer.update` and `PDFSinglePageViewer.update`, it's possible to further reduce duplication by moving the code into `BaseViewer.update` instead.
This commit is contained in:
Jonas Jenwald 2019-01-18 12:42:32 +01:00
parent cdbc33ba06
commit 343f488daa
3 changed files with 26 additions and 40 deletions

View File

@ -824,8 +824,28 @@ class BaseViewer {
}; };
} }
_updateHelper(visiblePages) {
throw new Error('Not implemented: _updateHelper');
}
update() { update() {
throw new Error('Not implemented: update'); const visible = this._getVisiblePages();
const visiblePages = visible.views, numVisiblePages = visiblePages.length;
if (numVisiblePages === 0) {
return;
}
this._resizeBuffer(numVisiblePages, visiblePages);
this.renderingQueue.renderHighestPriority(visible);
this._updateHelper(visiblePages); // Run any class-specific update code.
this._updateLocation(visible.first);
this.eventBus.dispatch('updateviewarea', {
source: this,
location: this._location,
});
} }
containsElement(element) { containsElement(element) {

View File

@ -111,23 +111,7 @@ class PDFSinglePageViewer extends BaseViewer {
return this._getCurrentVisiblePage(); return this._getCurrentVisiblePage();
} }
update() { _updateHelper(visiblePages) { }
let visible = this._getVisiblePages();
let visiblePages = visible.views, numVisiblePages = visiblePages.length;
if (numVisiblePages === 0) {
return;
}
this._resizeBuffer(numVisiblePages);
this.renderingQueue.renderHighestPriority(visible);
this._updateLocation(visible.first);
this.eventBus.dispatch('updateviewarea', {
source: this,
location: this._location,
});
}
get _isScrollModeHorizontal() { get _isScrollModeHorizontal() {
// The Scroll/Spread modes are never used in `PDFSinglePageViewer`. // The Scroll/Spread modes are never used in `PDFSinglePageViewer`.

View File

@ -45,23 +45,14 @@ class PDFViewer extends BaseViewer {
return this._getCurrentVisiblePage(); return this._getCurrentVisiblePage();
} }
update() { _updateHelper(visiblePages) {
let visible = this._getVisiblePages(); if (this.isInPresentationMode) {
let visiblePages = visible.views, numVisiblePages = visiblePages.length;
if (numVisiblePages === 0) {
return; return;
} }
this._resizeBuffer(numVisiblePages, visiblePages);
this.renderingQueue.renderHighestPriority(visible);
let currentId = this._currentPageNumber; let currentId = this._currentPageNumber;
let stillFullyVisible = false; let stillFullyVisible = false;
for (let i = 0; i < numVisiblePages; ++i) { for (const page of visiblePages) {
let page = visiblePages[i];
if (page.percent < 100) { if (page.percent < 100) {
break; break;
} }
@ -70,21 +61,12 @@ class PDFViewer extends BaseViewer {
break; break;
} }
} }
if (!stillFullyVisible) { if (!stillFullyVisible) {
currentId = visiblePages[0].id; currentId = visiblePages[0].id;
} }
if (!this.isInPresentationMode) {
this._setCurrentPageNumber(currentId); this._setCurrentPageNumber(currentId);
} }
this._updateLocation(visible.first);
this.eventBus.dispatch('updateviewarea', {
source: this,
location: this._location,
});
}
get _isScrollModeHorizontal() { get _isScrollModeHorizontal() {
// Used to ensure that pre-rendering of the next/previous page works // Used to ensure that pre-rendering of the next/previous page works
// correctly, since Scroll/Spread modes are ignored in Presentation Mode. // correctly, since Scroll/Spread modes are ignored in Presentation Mode.