Merge pull request #10123 from Snuffleupagus/viewer-component-signatures

Attempt to simplify the `PDFFindBar` and `PDFSidebar` constructors
This commit is contained in:
Tim van der Meij 2018-10-02 23:30:26 +02:00 committed by GitHub
commit 1cfb723dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 17 deletions

View File

@ -286,7 +286,7 @@ let PDFViewerApplication = {
this.overlayManager = new OverlayManager(); this.overlayManager = new OverlayManager();
const dispatchToDOM = AppOptions.get('eventBusDispatchToDOM'); const dispatchToDOM = AppOptions.get('eventBusDispatchToDOM');
let eventBus = appConfig.eventBus || getGlobalEventBus(dispatchToDOM); const eventBus = appConfig.eventBus || getGlobalEventBus(dispatchToDOM);
this.eventBus = eventBus; this.eventBus = eventBus;
let pdfRenderingQueue = new PDFRenderingQueue(); let pdfRenderingQueue = new PDFRenderingQueue();
@ -349,10 +349,7 @@ let PDFViewerApplication = {
}); });
pdfLinkService.setHistory(this.pdfHistory); pdfLinkService.setHistory(this.pdfHistory);
// TODO: improve `PDFFindBar` constructor parameter passing this.findBar = new PDFFindBar(appConfig.findBar, eventBus, this.l10n);
let findBarConfig = Object.create(appConfig.findBar);
findBarConfig.eventBus = eventBus;
this.findBar = new PDFFindBar(findBarConfig, this.l10n);
this.pdfDocumentProperties = this.pdfDocumentProperties =
new PDFDocumentProperties(appConfig.documentProperties, new PDFDocumentProperties(appConfig.documentProperties,
@ -399,9 +396,7 @@ let PDFViewerApplication = {
let sidebarConfig = Object.create(appConfig.sidebar); let sidebarConfig = Object.create(appConfig.sidebar);
sidebarConfig.pdfViewer = this.pdfViewer; sidebarConfig.pdfViewer = this.pdfViewer;
sidebarConfig.pdfThumbnailViewer = this.pdfThumbnailViewer; sidebarConfig.pdfThumbnailViewer = this.pdfThumbnailViewer;
sidebarConfig.pdfOutlineViewer = this.pdfOutlineViewer; this.pdfSidebar = new PDFSidebar(sidebarConfig, eventBus, this.l10n);
sidebarConfig.eventBus = eventBus;
this.pdfSidebar = new PDFSidebar(sidebarConfig, this.l10n);
this.pdfSidebar.onToggled = this.forceRendering.bind(this); this.pdfSidebar.onToggled = this.forceRendering.bind(this);
this.pdfSidebarResizer = new PDFSidebarResizer(appConfig.sidebarResizer, this.pdfSidebarResizer = new PDFSidebarResizer(appConfig.sidebarResizer,

View File

@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { getGlobalEventBus, NullL10n } from './ui_utils';
import { FindState } from './pdf_find_controller'; import { FindState } from './pdf_find_controller';
import { NullL10n } from './ui_utils';
const MATCHES_COUNT_LIMIT = 1000; const MATCHES_COUNT_LIMIT = 1000;
@ -25,7 +25,7 @@ const MATCHES_COUNT_LIMIT = 1000;
* is done by PDFFindController. * is done by PDFFindController.
*/ */
class PDFFindBar { class PDFFindBar {
constructor(options, l10n = NullL10n) { constructor(options, eventBus = getGlobalEventBus(), l10n = NullL10n) {
this.opened = false; this.opened = false;
this.bar = options.bar || null; this.bar = options.bar || null;
@ -38,7 +38,7 @@ class PDFFindBar {
this.findResultsCount = options.findResultsCount || null; this.findResultsCount = options.findResultsCount || null;
this.findPreviousButton = options.findPreviousButton || null; this.findPreviousButton = options.findPreviousButton || null;
this.findNextButton = options.findNextButton || null; this.findNextButton = options.findNextButton || null;
this.eventBus = options.eventBus; this.eventBus = eventBus;
this.l10n = l10n; this.l10n = l10n;
// Add event listeners to the DOM elements. // Add event listeners to the DOM elements.

View File

@ -39,6 +39,8 @@ class PDFOutlineViewer {
this.eventBus = eventBus; this.eventBus = eventBus;
this.reset(); this.reset();
eventBus.on('toggleoutlinetree', this.toggleOutlineTree.bind(this));
} }
reset() { reset() {

View File

@ -29,12 +29,10 @@ const SidebarView = {
* @typedef {Object} PDFSidebarOptions * @typedef {Object} PDFSidebarOptions
* @property {PDFViewer} pdfViewer - The document viewer. * @property {PDFViewer} pdfViewer - The document viewer.
* @property {PDFThumbnailViewer} pdfThumbnailViewer - The thumbnail viewer. * @property {PDFThumbnailViewer} pdfThumbnailViewer - The thumbnail viewer.
* @property {PDFOutlineViewer} pdfOutlineViewer - The outline viewer.
* @property {HTMLDivElement} outerContainer - The outer container * @property {HTMLDivElement} outerContainer - The outer container
* (encasing both the viewer and sidebar elements). * (encasing both the viewer and sidebar elements).
* @property {HTMLDivElement} viewerContainer - The viewer container * @property {HTMLDivElement} viewerContainer - The viewer container
* (in which the viewer element is placed). * (in which the viewer element is placed).
* @property {EventBus} eventBus - The application event bus.
* @property {HTMLButtonElement} toggleButton - The button used for * @property {HTMLButtonElement} toggleButton - The button used for
* opening/closing the sidebar. * opening/closing the sidebar.
* @property {HTMLButtonElement} thumbnailButton - The button used to show * @property {HTMLButtonElement} thumbnailButton - The button used to show
@ -56,9 +54,10 @@ const SidebarView = {
class PDFSidebar { class PDFSidebar {
/** /**
* @param {PDFSidebarOptions} options * @param {PDFSidebarOptions} options
* @param {EventBus} eventBus - The application event bus.
* @param {IL10n} l10n - Localization service. * @param {IL10n} l10n - Localization service.
*/ */
constructor(options, l10n = NullL10n) { constructor(options, eventBus, l10n = NullL10n) {
this.isOpen = false; this.isOpen = false;
this.active = SidebarView.THUMBS; this.active = SidebarView.THUMBS;
this.isInitialViewSet = false; this.isInitialViewSet = false;
@ -71,11 +70,9 @@ class PDFSidebar {
this.pdfViewer = options.pdfViewer; this.pdfViewer = options.pdfViewer;
this.pdfThumbnailViewer = options.pdfThumbnailViewer; this.pdfThumbnailViewer = options.pdfThumbnailViewer;
this.pdfOutlineViewer = options.pdfOutlineViewer;
this.outerContainer = options.outerContainer; this.outerContainer = options.outerContainer;
this.viewerContainer = options.viewerContainer; this.viewerContainer = options.viewerContainer;
this.eventBus = options.eventBus;
this.toggleButton = options.toggleButton; this.toggleButton = options.toggleButton;
this.thumbnailButton = options.thumbnailButton; this.thumbnailButton = options.thumbnailButton;
@ -88,6 +85,7 @@ class PDFSidebar {
this.disableNotification = options.disableNotification || false; this.disableNotification = options.disableNotification || false;
this.eventBus = eventBus;
this.l10n = l10n; this.l10n = l10n;
this._addEventListeners(); this._addEventListeners();
@ -397,7 +395,7 @@ class PDFSidebar {
this.switchView(SidebarView.OUTLINE); this.switchView(SidebarView.OUTLINE);
}); });
this.outlineButton.addEventListener('dblclick', () => { this.outlineButton.addEventListener('dblclick', () => {
this.pdfOutlineViewer.toggleOutlineTree(); this.eventBus.dispatch('toggleoutlinetree', { source: this, });
}); });
this.attachmentsButton.addEventListener('click', () => { this.attachmentsButton.addEventListener('click', () => {