Merge pull request #2197 from brendandahl/integrated-find
Add support for firefox integrated find.
This commit is contained in:
commit
4a19500a14
@ -55,6 +55,14 @@ if (appInfo.ID === FIREFOX_ID) {
|
||||
isInPrivateBrowsing = function() { return false; };
|
||||
}
|
||||
|
||||
function getChromeWindow(domWindow) {
|
||||
var containingBrowser = domWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell)
|
||||
.chromeEventHandler;
|
||||
return containingBrowser.ownerDocument.defaultView;
|
||||
}
|
||||
|
||||
function getBoolPref(pref, def) {
|
||||
try {
|
||||
return Services.prefs.getBoolPref(pref);
|
||||
@ -334,8 +342,8 @@ ChromeActions.prototype = {
|
||||
pdfBugEnabled: function() {
|
||||
return getBoolPref(PREF_PREFIX + '.pdfBugEnabled', false);
|
||||
},
|
||||
findEnabled: function() {
|
||||
return getBoolPref(PREF_PREFIX + '.findEnabled', false);
|
||||
supportsIntegratedFind: function() {
|
||||
return 'updateControlState' in getChromeWindow(this.domWindow).gFindBar;
|
||||
},
|
||||
fallback: function(url, sendResponse) {
|
||||
var self = this;
|
||||
@ -389,6 +397,20 @@ ChromeActions.prototype = {
|
||||
if (!sentResponse)
|
||||
sendResponse(false);
|
||||
});
|
||||
},
|
||||
updateFindControlState: function(data) {
|
||||
if (!this.supportsIntegratedFind())
|
||||
return;
|
||||
// Verify what we're sending to the findbar.
|
||||
var result = data.result;
|
||||
var findPrevious = data.findPrevious;
|
||||
var findPreviousType = typeof findPrevious;
|
||||
if ((typeof result !== 'number' || result < 0 || result > 3) ||
|
||||
(findPreviousType !== 'undefined' && findPreviousType !== 'boolean')) {
|
||||
return;
|
||||
}
|
||||
getChromeWindow(this.domWindow).gFindBar
|
||||
.updateControlState(result, findPrevious);
|
||||
}
|
||||
};
|
||||
|
||||
@ -429,6 +451,56 @@ RequestListener.prototype.receive = function(event) {
|
||||
}
|
||||
};
|
||||
|
||||
// Forwards events from the eventElement to the contentWindow only if the
|
||||
// content window matches the currently selected browser window.
|
||||
function FindEventManager(eventElement, contentWindow, chromeWindow) {
|
||||
this.types = ['find',
|
||||
'findagain',
|
||||
'findhighlightallchange',
|
||||
'findcasesensitivitychange'];
|
||||
this.chromeWindow = chromeWindow;
|
||||
this.contentWindow = contentWindow;
|
||||
this.eventElement = eventElement;
|
||||
}
|
||||
|
||||
FindEventManager.prototype.bind = function() {
|
||||
this.contentWindow.addEventListener('unload', function unload(e) {
|
||||
this.unbind();
|
||||
this.contentWindow.removeEventListener(e.type, unload);
|
||||
}.bind(this));
|
||||
|
||||
for (var i = 0, ii = this.types.length; i < ii; ++i) {
|
||||
var type = this.types[i];
|
||||
this.eventElement.addEventListener(type, this, true);
|
||||
}
|
||||
};
|
||||
|
||||
FindEventManager.prototype.handleEvent = function(e) {
|
||||
var chromeWindow = this.chromeWindow;
|
||||
var contentWindow = this.contentWindow;
|
||||
// Only forward the events if they are for our dom window.
|
||||
if (chromeWindow.gBrowser.selectedBrowser.contentWindow === contentWindow) {
|
||||
var detail = e.detail;
|
||||
detail.__exposedProps__ = {
|
||||
query: 'r',
|
||||
caseSensitive: 'r',
|
||||
highlightAll: 'r',
|
||||
findPrevious: 'r'
|
||||
};
|
||||
var forward = contentWindow.document.createEvent('CustomEvent');
|
||||
forward.initCustomEvent(e.type, true, true, detail);
|
||||
contentWindow.dispatchEvent(forward);
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
FindEventManager.prototype.unbind = function() {
|
||||
for (var i = 0, ii = this.types.length; i < ii; ++i) {
|
||||
var type = this.types[i];
|
||||
this.eventElement.removeEventListener(type, this, true);
|
||||
}
|
||||
};
|
||||
|
||||
function PdfStreamConverter() {
|
||||
}
|
||||
|
||||
@ -541,6 +613,11 @@ PdfStreamConverter.prototype = {
|
||||
domWindow.addEventListener(PDFJS_EVENT_ID, function(event) {
|
||||
requestListener.receive(event);
|
||||
}, false, true);
|
||||
var chromeWindow = getChromeWindow(domWindow);
|
||||
var findEventManager = new FindEventManager(chromeWindow.gFindBar,
|
||||
domWindow,
|
||||
chromeWindow);
|
||||
findEventManager.bind();
|
||||
}
|
||||
listener.onStopRequest.apply(listener, arguments);
|
||||
}
|
||||
|
@ -117,11 +117,9 @@ limitations under the License.
|
||||
<span data-l10n-id="toggle_slider_label">Toggle Sidebar</span>
|
||||
</button>
|
||||
<div class="toolbarButtonSpacer"></div>
|
||||
<!--#if !MOZCENTRAL-->
|
||||
<button id="viewFind" class="toolbarButton group" title="Find in Document" tabindex="4" data-l10n-id="find">
|
||||
<span data-l10n-id="find_label">Find</span>
|
||||
</button>
|
||||
<!--#endif-->
|
||||
<div class="splitToolbarButton">
|
||||
<button class="toolbarButton pageUp" title="Previous Page" id="previous" tabindex="5" data-l10n-id="previous">
|
||||
<span data-l10n-id="previous_label">Previous</span>
|
||||
|
@ -466,7 +466,11 @@ var PDFFindController = {
|
||||
},
|
||||
|
||||
updateUIState: function(state, previous) {
|
||||
// TODO: Update the firefox find bar or update the html findbar.
|
||||
if (PDFView.supportsIntegratedFind) {
|
||||
FirefoxCom.request('updateFindControlState',
|
||||
{result: state, findPrevious: previous});
|
||||
return;
|
||||
}
|
||||
PDFFindBar.updateUIState(state, previous);
|
||||
}
|
||||
};
|
||||
@ -783,6 +787,19 @@ var PDFView = {
|
||||
return support;
|
||||
},
|
||||
|
||||
get supportsIntegratedFind() {
|
||||
var support = false;
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
//#else
|
||||
// support = FirefoxCom.requestSync('supportsIntegratedFind');
|
||||
//#endif
|
||||
Object.defineProperty(this, 'supportsIntegratedFind', { value: support,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: false });
|
||||
return support;
|
||||
},
|
||||
|
||||
initPassiveLoading: function pdfViewInitPassiveLoading() {
|
||||
if (!PDFView.loadingBar) {
|
||||
PDFView.loadingBar = new ProgressBar('#loadingBar', {});
|
||||
@ -2508,13 +2525,6 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
|
||||
PDFBug.init();
|
||||
}
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
//#else
|
||||
//if (FirefoxCom.requestSync('findEnabled')) {
|
||||
// document.querySelector('#viewFind').classList.remove('hidden');
|
||||
//}
|
||||
//#endif
|
||||
|
||||
if (!PDFView.supportsPrinting) {
|
||||
document.getElementById('print').classList.add('hidden');
|
||||
}
|
||||
@ -2523,6 +2533,10 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
|
||||
document.getElementById('fullscreen').classList.add('hidden');
|
||||
}
|
||||
|
||||
if (PDFView.supportsIntegratedFind) {
|
||||
document.querySelector('#viewFind').classList.add('hidden');
|
||||
}
|
||||
|
||||
// Listen for warnings to trigger the fallback UI. Errors should be caught
|
||||
// and call PDFView.error() so we don't need to listen for those.
|
||||
PDFJS.LogManager.addLogger({
|
||||
@ -2818,12 +2832,12 @@ window.addEventListener('keydown', function keydown(evt) {
|
||||
// control is selected or not.
|
||||
if (cmd == 1 || cmd == 8) { // either CTRL or META key.
|
||||
switch (evt.keyCode) {
|
||||
//#if !MOZCENTRAL
|
||||
case 70:
|
||||
PDFFindBar.toggle();
|
||||
handled = true;
|
||||
if (!PDFView.supportsIntegratedFind) {
|
||||
PDFFindBar.toggle();
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
//#endif
|
||||
case 61: // FF/Mac '='
|
||||
case 107: // FF '+' and '='
|
||||
case 187: // Chrome '+'
|
||||
|
Loading…
x
Reference in New Issue
Block a user