Merge pull request #7035 from Snuffleupagus/issue-7034

Ensure that `PDFFindController_reset` actually resets *all* state (issue 7034)
This commit is contained in:
Tim van der Meij 2016-02-27 13:58:14 +01:00
commit 7cb3c365ca
3 changed files with 48 additions and 44 deletions

View File

@ -83,6 +83,10 @@ var PDFFindBar = (function PDFFindBarClosure() {
} }
PDFFindBar.prototype = { PDFFindBar.prototype = {
reset: function PDFFindBar_reset() {
this.updateUIState();
},
dispatchEvent: function PDFFindBar_dispatchEvent(type, findPrev) { dispatchEvent: function PDFFindBar_dispatchEvent(type, findPrev) {
var event = document.createEvent('CustomEvent'); var event = document.createEvent('CustomEvent');
event.initCustomEvent('find' + type, true, true, { event.initCustomEvent('find' + type, true, true, {

View File

@ -26,12 +26,55 @@ var FindStates = {
var FIND_SCROLL_OFFSET_TOP = -50; var FIND_SCROLL_OFFSET_TOP = -50;
var FIND_SCROLL_OFFSET_LEFT = -400; var FIND_SCROLL_OFFSET_LEFT = -400;
var CHARACTERS_TO_NORMALIZE = {
'\u2018': '\'', // Left single quotation mark
'\u2019': '\'', // Right single quotation mark
'\u201A': '\'', // Single low-9 quotation mark
'\u201B': '\'', // Single high-reversed-9 quotation mark
'\u201C': '"', // Left double quotation mark
'\u201D': '"', // Right double quotation mark
'\u201E': '"', // Double low-9 quotation mark
'\u201F': '"', // Double high-reversed-9 quotation mark
'\u00BC': '1/4', // Vulgar fraction one quarter
'\u00BD': '1/2', // Vulgar fraction one half
'\u00BE': '3/4', // Vulgar fraction three quarters
};
/** /**
* Provides "search" or "find" functionality for the PDF. * Provides "search" or "find" functionality for the PDF.
* This object actually performs the search for a given string. * This object actually performs the search for a given string.
*/ */
var PDFFindController = (function PDFFindControllerClosure() { var PDFFindController = (function PDFFindControllerClosure() {
function PDFFindController(options) { function PDFFindController(options) {
this.pdfViewer = options.pdfViewer || null;
this.integratedFind = options.integratedFind || false;
this.findBar = options.findBar || null;
this.reset();
// Compile the regular expression for text normalization once.
var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
this.normalizationRegex = new RegExp('[' + replace + ']', 'g');
var events = [
'find',
'findagain',
'findhighlightallchange',
'findcasesensitivitychange'
];
this.handleEvent = this.handleEvent.bind(this);
for (var i = 0, len = events.length; i < len; i++) {
window.addEventListener(events[i], this.handleEvent);
}
}
PDFFindController.prototype = {
setFindBar: function PDFFindController_setFindBar(findBar) {
this.findBar = findBar;
},
reset: function PDFFindController_reset() {
this.startedTextExtraction = false; this.startedTextExtraction = false;
this.extractTextPromises = []; this.extractTextPromises = [];
this.pendingFindMatches = Object.create(null); this.pendingFindMatches = Object.create(null);
@ -52,59 +95,15 @@ var PDFFindController = (function PDFFindControllerClosure() {
this.state = null; this.state = null;
this.dirtyMatch = false; this.dirtyMatch = false;
this.findTimeout = null; this.findTimeout = null;
this.pdfViewer = options.pdfViewer || null;
this.integratedFind = options.integratedFind || false;
this.charactersToNormalize = {
'\u2018': '\'', // Left single quotation mark
'\u2019': '\'', // Right single quotation mark
'\u201A': '\'', // Single low-9 quotation mark
'\u201B': '\'', // Single high-reversed-9 quotation mark
'\u201C': '"', // Left double quotation mark
'\u201D': '"', // Right double quotation mark
'\u201E': '"', // Double low-9 quotation mark
'\u201F': '"', // Double high-reversed-9 quotation mark
'\u00BC': '1/4', // Vulgar fraction one quarter
'\u00BD': '1/2', // Vulgar fraction one half
'\u00BE': '3/4', // Vulgar fraction three quarters
};
this.findBar = options.findBar || null;
// Compile the regular expression for text normalization once
var replace = Object.keys(this.charactersToNormalize).join('');
this.normalizationRegex = new RegExp('[' + replace + ']', 'g');
var events = [
'find',
'findagain',
'findhighlightallchange',
'findcasesensitivitychange'
];
this.firstPagePromise = new Promise(function (resolve) { this.firstPagePromise = new Promise(function (resolve) {
this.resolveFirstPage = resolve; this.resolveFirstPage = resolve;
}.bind(this)); }.bind(this));
this.handleEvent = this.handleEvent.bind(this);
for (var i = 0, len = events.length; i < len; i++) {
window.addEventListener(events[i], this.handleEvent);
}
}
PDFFindController.prototype = {
setFindBar: function PDFFindController_setFindBar(findBar) {
this.findBar = findBar;
},
reset: function PDFFindController_reset() {
this.startedTextExtraction = false;
this.extractTextPromises = [];
this.active = false;
}, },
normalize: function PDFFindController_normalize(text) { normalize: function PDFFindController_normalize(text) {
var self = this;
return text.replace(this.normalizationRegex, function (ch) { return text.replace(this.normalizationRegex, function (ch) {
return self.charactersToNormalize[ch]; return CHARACTERS_TO_NORMALIZE[ch];
}); });
}, },

View File

@ -526,6 +526,9 @@ var PDFViewerApplication = {
this.pdfLinkService.setDocument(null, null); this.pdfLinkService.setDocument(null, null);
} }
this.findController.reset();
this.findBar.reset();
if (typeof PDFBug !== 'undefined') { if (typeof PDFBug !== 'undefined') {
PDFBug.cleanup(); PDFBug.cleanup();
} }
@ -804,8 +807,6 @@ var PDFViewerApplication = {
var self = this; var self = this;
scale = scale || UNKNOWN_SCALE; scale = scale || UNKNOWN_SCALE;
this.findController.reset();
this.pdfDocument = pdfDocument; this.pdfDocument = pdfDocument;
this.pdfDocumentProperties.setDocumentAndUrl(pdfDocument, this.url); this.pdfDocumentProperties.setDocumentAndUrl(pdfDocument, this.url);