2018-07-30 00:38:44 +03:00
|
|
|
// vim: set ts=2 sw=2 sts=2 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";
|
|
|
|
|
2018-07-30 07:38:21 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["FindBarContent"];
|
2018-07-30 00:38:44 +03:00
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { XPCOMUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/XPCOMUtils.jsm"
|
|
|
|
);
|
2018-07-30 22:25:58 +03:00
|
|
|
|
2018-07-30 00:38:44 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"Services",
|
|
|
|
"resource://gre/modules/Services.jsm"
|
|
|
|
);
|
|
|
|
|
2019-11-04 16:19:17 +03:00
|
|
|
/* Please keep in sync with toolkit/content/widgets/findbar.js */
|
2018-07-30 00:38:44 +03:00
|
|
|
const FIND_NORMAL = 0;
|
|
|
|
const FIND_TYPEAHEAD = 1;
|
|
|
|
const FIND_LINKS = 2;
|
|
|
|
|
2018-07-30 07:38:21 +03:00
|
|
|
class FindBarContent {
|
2019-09-18 02:29:46 +03:00
|
|
|
constructor(actor) {
|
|
|
|
this.actor = actor;
|
2018-07-30 00:38:44 +03:00
|
|
|
|
|
|
|
this.findMode = 0;
|
|
|
|
this.inQuickFind = false;
|
|
|
|
|
2019-09-18 02:29:46 +03:00
|
|
|
this.addedEventListener = false;
|
2018-07-30 00:38:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
start(event) {
|
|
|
|
this.inPassThrough = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
startQuickFind(event, autostart = false) {
|
2019-09-18 02:29:46 +03:00
|
|
|
if (!this.addedEventListener) {
|
|
|
|
this.addedEventListener = true;
|
|
|
|
Services.els.addSystemEventListener(
|
|
|
|
this.actor.document.defaultView,
|
|
|
|
"mouseup",
|
|
|
|
this,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-30 00:38:44 +03:00
|
|
|
let mode = FIND_TYPEAHEAD;
|
|
|
|
if (
|
|
|
|
event.charCode == "'".charAt(0) ||
|
2018-07-30 22:25:58 +03:00
|
|
|
(autostart && FindBarContent.typeAheadLinksOnly)
|
|
|
|
) {
|
2018-07-30 00:38:44 +03:00
|
|
|
mode = FIND_LINKS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set findMode immediately (without waiting for child->parent->child roundtrip)
|
|
|
|
// to ensure we pass any further keypresses, too.
|
|
|
|
this.findMode = mode;
|
|
|
|
this.passKeyToParent(event);
|
|
|
|
}
|
|
|
|
|
2019-09-30 18:12:28 +03:00
|
|
|
updateState(data) {
|
|
|
|
this.findMode = data.findMode;
|
|
|
|
this.inQuickFind = data.hasQuickFindTimeout;
|
|
|
|
if (data.isOpenAndFocused) {
|
|
|
|
this.inPassThrough = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 00:38:44 +03:00
|
|
|
handleEvent(event) {
|
|
|
|
switch (event.type) {
|
|
|
|
case "keypress":
|
|
|
|
this.onKeypress(event);
|
|
|
|
break;
|
|
|
|
case "mouseup":
|
|
|
|
this.onMouseup(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onKeypress(event) {
|
|
|
|
if (this.inPassThrough) {
|
|
|
|
this.passKeyToParent(event);
|
|
|
|
} else if (
|
|
|
|
this.findMode != FIND_NORMAL &&
|
|
|
|
this.inQuickFind &&
|
|
|
|
event.charCode
|
|
|
|
) {
|
|
|
|
this.passKeyToParent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
passKeyToParent(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
// These are the properties required to dispatch another 'real' event
|
|
|
|
// to the findbar in the parent in _dispatchKeypressEvent in findbar.xml .
|
|
|
|
// If you make changes here, verify that that method can still do its job.
|
|
|
|
const kRequiredProps = [
|
|
|
|
"type",
|
|
|
|
"bubbles",
|
|
|
|
"cancelable",
|
|
|
|
"ctrlKey",
|
|
|
|
"altKey",
|
|
|
|
"shiftKey",
|
|
|
|
"metaKey",
|
|
|
|
"keyCode",
|
|
|
|
"charCode",
|
|
|
|
];
|
|
|
|
let fakeEvent = {};
|
|
|
|
for (let prop of kRequiredProps) {
|
|
|
|
fakeEvent[prop] = event[prop];
|
|
|
|
}
|
2019-09-18 02:29:46 +03:00
|
|
|
this.actor.sendAsyncMessage("Findbar:Keypress", fakeEvent);
|
2018-07-30 00:38:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onMouseup(event) {
|
|
|
|
if (this.findMode != FIND_NORMAL) {
|
2019-09-18 02:29:46 +03:00
|
|
|
this.actor.sendAsyncMessage("Findbar:Mouseup", {});
|
2019-07-05 12:15:43 +03:00
|
|
|
}
|
2018-07-30 00:38:44 +03:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 22:25:58 +03:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(
|
|
|
|
FindBarContent,
|
|
|
|
"typeAheadLinksOnly",
|
|
|
|
"accessibility.typeaheadfind.linksonly"
|
|
|
|
);
|