2018-07-30 07:38:21 +03:00
|
|
|
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var EXPORTED_SYMBOLS = ["FindBarChild"];
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
const { XPCOMUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/XPCOMUtils.jsm"
|
|
|
|
);
|
2019-07-05 12:04:56 +03:00
|
|
|
|
2018-07-30 07:38:21 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"BrowserUtils",
|
|
|
|
"resource://gre/modules/BrowserUtils.jsm"
|
|
|
|
);
|
|
|
|
|
2019-09-18 02:29:46 +03:00
|
|
|
class FindBarChild extends JSWindowActorChild {
|
|
|
|
constructor() {
|
|
|
|
super();
|
2018-09-27 00:46:18 +03:00
|
|
|
|
2018-07-30 07:38:21 +03:00
|
|
|
this._findKey = null;
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyProxy(
|
|
|
|
this,
|
|
|
|
"FindBarContent",
|
|
|
|
() => {
|
|
|
|
let tmp = {};
|
|
|
|
ChromeUtils.import("resource://gre/modules/FindBarContent.jsm", tmp);
|
2019-09-18 02:29:46 +03:00
|
|
|
return new tmp.FindBarContent(this);
|
2018-07-30 07:38:21 +03:00
|
|
|
},
|
|
|
|
{ inQuickFind: false, inPassThrough: false }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-18 02:29:46 +03:00
|
|
|
receiveMessage(msg) {
|
|
|
|
if (msg.name == "Findbar:UpdateState") {
|
2019-09-30 18:12:28 +03:00
|
|
|
let { FindBarContent } = this;
|
|
|
|
FindBarContent.updateState(msg.data);
|
2019-09-18 02:29:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 07:38:21 +03:00
|
|
|
/**
|
|
|
|
* Check whether this key event will start the findbar in the parent,
|
|
|
|
* in which case we should pass any further key events to the parent to avoid
|
|
|
|
* them being lost.
|
|
|
|
* @param aEvent the key event to check.
|
|
|
|
*/
|
|
|
|
eventMatchesFindShortcut(aEvent) {
|
|
|
|
if (!this._findKey) {
|
|
|
|
this._findKey = Services.cpmm.sharedData.get("Findbar:Shortcut");
|
|
|
|
if (!this._findKey) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let k in this._findKey) {
|
|
|
|
if (this._findKey[k] != aEvent[k]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEvent(event) {
|
|
|
|
if (event.type == "keypress") {
|
|
|
|
this.onKeypress(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onKeypress(event) {
|
|
|
|
let { FindBarContent } = this;
|
|
|
|
|
|
|
|
if (!FindBarContent.inPassThrough && this.eventMatchesFindShortcut(event)) {
|
|
|
|
return FindBarContent.start(event);
|
|
|
|
}
|
|
|
|
|
2018-10-23 17:29:09 +03:00
|
|
|
// disable FAYT in about:blank to prevent FAYT opening unexpectedly.
|
2019-09-18 02:29:46 +03:00
|
|
|
let location = this.document.location.href;
|
2018-10-23 17:29:09 +03:00
|
|
|
if (location == "about:blank") {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-07-30 07:38:21 +03:00
|
|
|
if (
|
|
|
|
event.ctrlKey ||
|
|
|
|
event.altKey ||
|
|
|
|
event.metaKey ||
|
|
|
|
event.defaultPrevented ||
|
2019-09-18 02:29:46 +03:00
|
|
|
!BrowserUtils.mimeTypeIsTextBased(this.document.contentType) ||
|
2018-10-23 17:29:09 +03:00
|
|
|
!BrowserUtils.canFindInPage(location)
|
|
|
|
) {
|
2018-07-30 07:38:21 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FindBarContent.inPassThrough || FindBarContent.inQuickFind) {
|
|
|
|
return FindBarContent.onKeypress(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.charCode && BrowserUtils.shouldFastFind(event.target)) {
|
|
|
|
let key = String.fromCharCode(event.charCode);
|
2018-07-30 22:25:58 +03:00
|
|
|
if ((key == "/" || key == "'") && FindBarChild.manualFAYT) {
|
2018-07-30 07:38:21 +03:00
|
|
|
return FindBarContent.startQuickFind(event);
|
|
|
|
}
|
2018-07-30 22:25:58 +03:00
|
|
|
if (key != " " && FindBarChild.findAsYouType) {
|
2018-07-30 07:38:21 +03:00
|
|
|
return FindBarContent.startQuickFind(event, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 22:25:58 +03:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(
|
|
|
|
FindBarChild,
|
|
|
|
"findAsYouType",
|
|
|
|
"accessibility.typeaheadfind"
|
|
|
|
);
|
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(
|
|
|
|
FindBarChild,
|
|
|
|
"manualFAYT",
|
|
|
|
"accessibility.typeaheadfind.manual"
|
|
|
|
);
|