1 // vim: set ts=2 sw=2 sts=2 tw=80:
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
8 /* Please keep in sync with toolkit/content/widgets/findbar.js */
10 const FIND_TYPEAHEAD = 1;
13 export class FindBarContent {
18 this.inQuickFind = false;
20 this.addedEventListener = false;
24 this.inPassThrough = true;
27 startQuickFind(event, autostart = false) {
28 if (!this.addedEventListener) {
29 this.addedEventListener = true;
30 Services.els.addSystemEventListener(
31 this.actor.document.defaultView,
38 let mode = FIND_TYPEAHEAD;
40 event.charCode == "'".charAt(0) ||
41 (autostart && FindBarContent.typeAheadLinksOnly)
46 // Set findMode immediately (without waiting for child->parent->child roundtrip)
47 // to ensure we pass any further keypresses, too.
49 this.passKeyToParent(event);
53 this.findMode = data.findMode;
54 this.inQuickFind = data.hasQuickFindTimeout;
55 if (data.isOpenAndFocused) {
56 this.inPassThrough = false;
63 this.onKeypress(event);
66 this.onMouseup(event);
72 if (this.inPassThrough) {
73 this.passKeyToParent(event);
75 this.findMode != FIND_NORMAL &&
79 this.passKeyToParent(event);
83 passKeyToParent(event) {
84 event.preventDefault();
85 // These are the properties required to dispatch another 'real' event
86 // to the findbar in the parent in _dispatchKeypressEvent in findbar.xml .
87 // If you make changes here, verify that that method can still do its job.
88 const kRequiredProps = [
100 for (let prop of kRequiredProps) {
101 fakeEvent[prop] = event[prop];
103 this.actor.sendAsyncMessage("Findbar:Keypress", fakeEvent);
107 if (this.findMode != FIND_NORMAL) {
108 this.actor.sendAsyncMessage("Findbar:Mouseup", {});
113 XPCOMUtils.defineLazyPreferenceGetter(
115 "typeAheadLinksOnly",
116 "accessibility.typeaheadfind.linksonly"