Browse Source

Fixes but 960409 and adresses review comments including removal of do-while construct

Karl Denninghoff 11 years ago
parent
commit
1be27e3c81
  1. 50
      web/pdf_find_controller.js

50
web/pdf_find_controller.js

@ -52,8 +52,6 @@ var PDFFindController = {
resumePageIdx: null, resumePageIdx: null,
resumeCallback: null,
state: null, state: null,
dirtyMatch: false, dirtyMatch: false,
@ -126,10 +124,8 @@ var PDFFindController = {
this.pageMatches[pageIndex] = matches; this.pageMatches[pageIndex] = matches;
this.updatePage(pageIndex); this.updatePage(pageIndex);
if (this.resumePageIdx === pageIndex) { if (this.resumePageIdx === pageIndex) {
var callback = this.resumeCallback;
this.resumePageIdx = null; this.resumePageIdx = null;
this.resumeCallback = null; this.nextPageMatch();
callback();
} }
}, },
@ -220,7 +216,6 @@ var PDFFindController = {
this.offset.pageIdx = currentPageIndex; this.offset.pageIdx = currentPageIndex;
this.offset.matchIdx = null; this.offset.matchIdx = null;
this.hadMatch = false; this.hadMatch = false;
this.resumeCallback = null;
this.resumePageIdx = null; this.resumePageIdx = null;
this.pageMatches = []; this.pageMatches = [];
var self = this; var self = this;
@ -247,7 +242,7 @@ var PDFFindController = {
} }
// If we're waiting on a page, we return since we can't do anything else. // If we're waiting on a page, we return since we can't do anything else.
if (this.resumeCallback) { if (this.resumePageIdx) {
return; return;
} }
@ -273,11 +268,7 @@ var PDFFindController = {
this.nextPageMatch(); this.nextPageMatch();
}, },
nextPageMatch: function() { matchesReady: function(matches) {
if (this.resumePageIdx !== null)
console.error('There can only be one pending page.');
var matchesReady = function(matches) {
var offset = this.offset; var offset = this.offset;
var numMatches = matches.length; var numMatches = matches.length;
var previous = this.state.findPrevious; var previous = this.state.findPrevious;
@ -286,6 +277,8 @@ var PDFFindController = {
this.hadMatch = true; this.hadMatch = true;
offset.matchIdx = previous ? numMatches - 1 : 0; offset.matchIdx = previous ? numMatches - 1 : 0;
this.updateMatch(true); this.updateMatch(true);
// matches were found
return true;
} else { } else {
// No matches attempt to search the next page. // No matches attempt to search the next page.
this.advanceOffsetPage(previous); this.advanceOffsetPage(previous);
@ -294,27 +287,32 @@ var PDFFindController = {
if (!this.hadMatch) { if (!this.hadMatch) {
// No point in wrapping there were no matches. // No point in wrapping there were no matches.
this.updateMatch(false); this.updateMatch(false);
return; // while matches were not found, searching for a page
// with matches should nevertheless halt.
return true;
} }
} }
// Search the next page. // matches were not found (and searching is not done)
this.nextPageMatch(); return false;
} }
}.bind(this); },
nextPageMatch: function() {
if (this.resumePageIdx !== null)
console.error('There can only be one pending page.');
// done boolean to remove do-while construct per review of PR 4131
var done = false;
while (!done) {
var pageIdx = this.offset.pageIdx; var pageIdx = this.offset.pageIdx;
var pageMatches = this.pageMatches; var matches = this.pageMatches[pageIdx];
if (!pageMatches[pageIdx]) { if (!matches) {
// The matches aren't ready setup a callback so we can be notified, // The matches don't exist yet for processing by "matchesReady",
// when they are ready. // so set a resume point for when they do exist.
this.resumeCallback = function() {
matchesReady(pageMatches[pageIdx]);
};
this.resumePageIdx = pageIdx; this.resumePageIdx = pageIdx;
return; break;
}
done = this.matchesReady(matches);
} }
// The matches are finished already.
matchesReady(pageMatches[pageIdx]);
}, },
advanceOffsetPage: function(previous) { advanceOffsetPage: function(previous) {

Loading…
Cancel
Save