Merge pull request #6580 from yurydelendik/pr5051
Find match count (rebase of #5051)
This commit is contained in:
commit
c2e70ea726
@ -32,6 +32,7 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
||||
this.highlightAll = options.highlightAllCheckbox || null;
|
||||
this.caseSensitive = options.caseSensitiveCheckbox || null;
|
||||
this.findMsg = options.findMsg || null;
|
||||
this.findResultsCount = options.findResultsCount || null;
|
||||
this.findStatusIcon = options.findStatusIcon || null;
|
||||
this.findPreviousButton = options.findPreviousButton || null;
|
||||
this.findNextButton = options.findNextButton || null;
|
||||
@ -94,7 +95,8 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
||||
return window.dispatchEvent(event);
|
||||
},
|
||||
|
||||
updateUIState: function PDFFindBar_updateUIState(state, previous) {
|
||||
updateUIState:
|
||||
function PDFFindBar_updateUIState(state, previous, matchCount) {
|
||||
var notFound = false;
|
||||
var findMsg = '';
|
||||
var status = '';
|
||||
@ -131,6 +133,26 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
||||
|
||||
this.findField.setAttribute('data-status', status);
|
||||
this.findMsg.textContent = findMsg;
|
||||
|
||||
this.updateResultsCount(matchCount);
|
||||
},
|
||||
|
||||
updateResultsCount: function(matchCount) {
|
||||
if (!this.findResultsCount) {
|
||||
return; // no UI control is provided
|
||||
}
|
||||
|
||||
// If there are no matches, hide the counter
|
||||
if (!matchCount) {
|
||||
this.findResultsCount.classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the match counter
|
||||
this.findResultsCount.textContent = matchCount.toLocaleString();
|
||||
|
||||
// Show the counter
|
||||
this.findResultsCount.classList.remove('hidden');
|
||||
},
|
||||
|
||||
open: function PDFFindBar_open() {
|
||||
|
@ -39,6 +39,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
||||
this.active = false; // If active, find results will be highlighted.
|
||||
this.pageContents = []; // Stores the text for each page.
|
||||
this.pageMatches = [];
|
||||
this.matchCount = 0;
|
||||
this.selected = { // Currently selected match.
|
||||
pageIdx: -1,
|
||||
matchIdx: -1
|
||||
@ -116,7 +117,8 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
||||
var queryLen = query.length;
|
||||
|
||||
if (queryLen === 0) {
|
||||
return; // Do nothing: the matches should be wiped out already.
|
||||
// Do nothing: the matches should be wiped out already.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!caseSensitive) {
|
||||
@ -139,6 +141,12 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
||||
this.resumePageIdx = null;
|
||||
this.nextPageMatch();
|
||||
}
|
||||
|
||||
// Update the matches count
|
||||
if (matches.length > 0) {
|
||||
this.matchCount += matches.length;
|
||||
this.updateUIResultsCount();
|
||||
}
|
||||
},
|
||||
|
||||
extractText: function PDFFindController_extractText() {
|
||||
@ -230,6 +238,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
||||
this.hadMatch = false;
|
||||
this.resumePageIdx = null;
|
||||
this.pageMatches = [];
|
||||
this.matchCount = 0;
|
||||
var self = this;
|
||||
|
||||
for (var i = 0; i < numPages; i++) {
|
||||
@ -386,6 +395,15 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
||||
}
|
||||
},
|
||||
|
||||
updateUIResultsCount:
|
||||
function PDFFindController_updateUIResultsCount() {
|
||||
if (this.findBar === null) {
|
||||
throw new Error('PDFFindController is not initialized with a ' +
|
||||
'PDFFindBar instance.');
|
||||
}
|
||||
this.findBar.updateResultsCount(this.matchCount);
|
||||
},
|
||||
|
||||
updateUIState: function PDFFindController_updateUIState(state, previous) {
|
||||
if (this.integratedFind) {
|
||||
FirefoxCom.request('updateFindControlState',
|
||||
@ -396,7 +414,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
||||
throw new Error('PDFFindController is not initialized with a ' +
|
||||
'PDFFindBar instance.');
|
||||
}
|
||||
this.findBar.updateUIState(state, previous);
|
||||
this.findBar.updateUIState(state, previous, this.matchCount);
|
||||
}
|
||||
};
|
||||
return PDFFindController;
|
||||
|
@ -477,6 +477,13 @@ html[dir='ltr'] .doorHangerRight:before {
|
||||
margin-right: -9px;
|
||||
}
|
||||
|
||||
#findResultsCount {
|
||||
background-color: hsl(0, 0%, 85%);
|
||||
color: hsl(0, 0%, 32%);
|
||||
text-align: center;
|
||||
padding: 3px 4px;
|
||||
}
|
||||
|
||||
#findMsg {
|
||||
font-style: italic;
|
||||
color: #A6B7D0;
|
||||
|
@ -149,6 +149,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
||||
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
|
||||
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
|
||||
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
|
||||
<span id="findResultsCount" class="toolbarLabel hidden"></span>
|
||||
<span id="findMsg" class="toolbarLabel"></span>
|
||||
</div> <!-- findbar -->
|
||||
|
||||
|
@ -167,6 +167,7 @@ var PDFViewerApplication = {
|
||||
highlightAllCheckbox: document.getElementById('findHighlightAll'),
|
||||
caseSensitiveCheckbox: document.getElementById('findMatchCase'),
|
||||
findMsg: document.getElementById('findMsg'),
|
||||
findResultsCount: document.getElementById('findResultsCount'),
|
||||
findStatusIcon: document.getElementById('findStatusIcon'),
|
||||
findPreviousButton: document.getElementById('findPrevious'),
|
||||
findNextButton: document.getElementById('findNext'),
|
||||
|
Loading…
Reference in New Issue
Block a user