Refactors PDFFindBar and FirefoxCom find events.
This commit is contained in:
		
							parent
							
								
									7fd3db9977
								
							
						
					
					
						commit
						3e6e294fd4
					
				
							
								
								
									
										22
									
								
								web/app.js
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								web/app.js
									
									
									
									
									
								
							@ -248,7 +248,6 @@ var PDFViewerApplication = {
 | 
				
			|||||||
        this.findBar.updateUIState(state, previous, matchCount);
 | 
					        this.findBar.updateUIState(state, previous, matchCount);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }.bind(this);
 | 
					    }.bind(this);
 | 
				
			||||||
    this.findController.listenWindowEvents();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.pdfViewer.setFindController(this.findController);
 | 
					    this.pdfViewer.setFindController(this.findController);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1249,6 +1248,7 @@ var PDFViewerApplication = {
 | 
				
			|||||||
    eventBus.on('pagemode', webViewerPageMode);
 | 
					    eventBus.on('pagemode', webViewerPageMode);
 | 
				
			||||||
    eventBus.on('namedaction', webViewerNamedAction);
 | 
					    eventBus.on('namedaction', webViewerNamedAction);
 | 
				
			||||||
    eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
 | 
					    eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
 | 
				
			||||||
 | 
					    eventBus.on('find', webViewerFind);
 | 
				
			||||||
//#if GENERIC
 | 
					//#if GENERIC
 | 
				
			||||||
    eventBus.on('fileinputchange', webViewerFileInputChange);
 | 
					    eventBus.on('fileinputchange', webViewerFileInputChange);
 | 
				
			||||||
//#endif
 | 
					//#endif
 | 
				
			||||||
@ -1827,6 +1827,15 @@ function webViewerLocalized() {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function webViewerFind(e) {
 | 
				
			||||||
 | 
					  PDFViewerApplication.findController.executeCommand('find' + e.type, {
 | 
				
			||||||
 | 
					    query: e.query,
 | 
				
			||||||
 | 
					    caseSensitive: e.caseSensitive,
 | 
				
			||||||
 | 
					    highlightAll: e.highlightAll,
 | 
				
			||||||
 | 
					    findPrevious: e.findPrevious
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function webViewerScaleChange(e) {
 | 
					function webViewerScaleChange(e) {
 | 
				
			||||||
  var appConfig = PDFViewerApplication.appConfig;
 | 
					  var appConfig = PDFViewerApplication.appConfig;
 | 
				
			||||||
  appConfig.toolbar.zoomOut.disabled = (e.scale === MIN_SCALE);
 | 
					  appConfig.toolbar.zoomOut.disabled = (e.scale === MIN_SCALE);
 | 
				
			||||||
@ -1961,8 +1970,15 @@ window.addEventListener('keydown', function keydown(evt) {
 | 
				
			|||||||
        break;
 | 
					        break;
 | 
				
			||||||
      case 71: // g
 | 
					      case 71: // g
 | 
				
			||||||
        if (!PDFViewerApplication.supportsIntegratedFind) {
 | 
					        if (!PDFViewerApplication.supportsIntegratedFind) {
 | 
				
			||||||
          PDFViewerApplication.eventBus.dispatch('findagain',
 | 
					          var findState = PDFViewerApplication.findController.state;
 | 
				
			||||||
                                                 cmd === 5 || cmd === 12);
 | 
					          if (findState) {
 | 
				
			||||||
 | 
					            PDFViewerApplication.findController.executeCommand('findagain', {
 | 
				
			||||||
 | 
					              query: findState.query,
 | 
				
			||||||
 | 
					              caseSensitive: findState.caseSensitive,
 | 
				
			||||||
 | 
					              highlightAll: findState.highlightAll,
 | 
				
			||||||
 | 
					              findPrevious: cmd === 5 || cmd === 12
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
          handled = true;
 | 
					          handled = true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
				
			|||||||
@ -83,6 +83,9 @@
 | 
				
			|||||||
      e.source.container.dispatchEvent(event);
 | 
					      e.source.container.dispatchEvent(event);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    eventBus.on('find', function (e) {
 | 
					    eventBus.on('find', function (e) {
 | 
				
			||||||
 | 
					      if (e.source === window) {
 | 
				
			||||||
 | 
					        return; // event comes from FirefoxCom, no need to replicate
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      var event = document.createEvent('CustomEvent');
 | 
					      var event = document.createEvent('CustomEvent');
 | 
				
			||||||
      event.initCustomEvent('find' + e.type, true, true, {
 | 
					      event.initCustomEvent('find' + e.type, true, true, {
 | 
				
			||||||
        query: e.query,
 | 
					        query: e.query,
 | 
				
			||||||
 | 
				
			|||||||
@ -148,6 +148,32 @@ Preferences._readFromStorage = function (prefObj) {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(function listenFindEvents() {
 | 
				
			||||||
 | 
					  var events = [
 | 
				
			||||||
 | 
					    'find',
 | 
				
			||||||
 | 
					    'findagain',
 | 
				
			||||||
 | 
					    'findhighlightallchange',
 | 
				
			||||||
 | 
					    'findcasesensitivitychange'
 | 
				
			||||||
 | 
					  ];
 | 
				
			||||||
 | 
					  var handleEvent = function (evt) {
 | 
				
			||||||
 | 
					    if (!PDFViewerApplication.initialized) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    PDFViewerApplication.eventBus.dispatch('find', {
 | 
				
			||||||
 | 
					      source: window,
 | 
				
			||||||
 | 
					      type: evt.type.substring('find'.length),
 | 
				
			||||||
 | 
					      query: evt.detail.query,
 | 
				
			||||||
 | 
					      caseSensitive: !!evt.detail.caseSensitive,
 | 
				
			||||||
 | 
					      highlightAll: !!evt.detail.highlightAll,
 | 
				
			||||||
 | 
					      findPrevious: !!evt.detail.findPrevious
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }.bind(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (var i = 0, len = events.length; i < len; i++) {
 | 
				
			||||||
 | 
					    window.addEventListener(events[i], handleEvent);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					})();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function FirefoxComDataRangeTransport(length, initialData) {
 | 
					function FirefoxComDataRangeTransport(length, initialData) {
 | 
				
			||||||
  pdfjsLib.PDFDataRangeTransport.call(this, length, initialData);
 | 
					  pdfjsLib.PDFDataRangeTransport.call(this, length, initialData);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -71,22 +71,6 @@ var PDFFindController = (function PDFFindControllerClosure() {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PDFFindController.prototype = {
 | 
					  PDFFindController.prototype = {
 | 
				
			||||||
    listenWindowEvents: function PDFFindController_listenWindowEvents() {
 | 
					 | 
				
			||||||
      var events = [
 | 
					 | 
				
			||||||
        'find',
 | 
					 | 
				
			||||||
        'findagain',
 | 
					 | 
				
			||||||
        'findhighlightallchange',
 | 
					 | 
				
			||||||
        'findcasesensitivitychange'
 | 
					 | 
				
			||||||
      ];
 | 
					 | 
				
			||||||
      var handleEvent = function (e) {
 | 
					 | 
				
			||||||
        this.executeCommand(e.type, e.detail);
 | 
					 | 
				
			||||||
      }.bind(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      for (var i = 0, len = events.length; i < len; i++) {
 | 
					 | 
				
			||||||
        window.addEventListener(events[i], handleEvent);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    reset: function PDFFindController_reset() {
 | 
					    reset: function PDFFindController_reset() {
 | 
				
			||||||
      this.startedTextExtraction = false;
 | 
					      this.startedTextExtraction = false;
 | 
				
			||||||
      this.extractTextPromises = [];
 | 
					      this.extractTextPromises = [];
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user