1 /* vim: set ts=2 sw=2 sts=2 et 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";
10 ChromeUtils.defineESModuleGetters(lazy, {
11 BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
14 export class FindBarChild extends JSWindowActorChild {
20 this.inQuickFind = false;
21 this.inPassThrough = false;
23 ChromeUtils.defineLazyGetter(this, "FindBarContent", () => {
24 const { FindBarContent } = ChromeUtils.importESModule(
25 "resource://gre/modules/FindBarContent.sys.mjs"
28 let findBarContent = new FindBarContent(this);
30 Object.defineProperties(this, {
33 return findBarContent.inQuickFind;
38 return findBarContent.inPassThrough;
43 return findBarContent;
48 if (msg.name == "Findbar:UpdateState") {
49 this.FindBarContent.updateState(msg.data);
54 * Check whether this key event will start the findbar in the parent,
55 * in which case we should pass any further key events to the parent to avoid
57 * @param aEvent the key event to check.
59 eventMatchesFindShortcut(aEvent) {
61 this._findKey = Services.cpmm.sharedData.get("Findbar:Shortcut");
66 for (let k in this._findKey) {
67 if (this._findKey[k] != aEvent[k]) {
75 if (event.type == "keypress") {
76 this.onKeypress(event);
81 if (!this.inPassThrough && this.eventMatchesFindShortcut(event)) {
82 return this.FindBarContent.start(event);
85 // disable FAYT in about:blank to prevent FAYT opening unexpectedly.
86 let location = this.document.location.href;
87 if (location == "about:blank") {
95 event.defaultPrevented ||
96 !lazy.BrowserUtils.mimeTypeIsTextBased(this.document.contentType) ||
97 !lazy.BrowserUtils.canFindInPage(location)
102 if (this.inPassThrough || this.inQuickFind) {
103 return this.FindBarContent.onKeypress(event);
106 if (event.charCode && this.shouldFastFind(event.target)) {
107 let key = String.fromCharCode(event.charCode);
108 if ((key == "/" || key == "'") && FindBarChild.manualFAYT) {
109 return this.FindBarContent.startQuickFind(event);
111 if (key != " " && FindBarChild.findAsYouType) {
112 return this.FindBarContent.startQuickFind(event, true);
119 * Return true if we should FAYT for this node:
122 * The element that is focused
124 shouldFastFind(elt) {
126 let win = elt.ownerGlobal;
127 if (win.HTMLInputElement.isInstance(elt) && elt.mozIsTextField(false)) {
131 if (elt.isContentEditable || win.document.designMode == "on") {
136 win.HTMLTextAreaElement.isInstance(elt) ||
137 win.HTMLSelectElement.isInstance(elt) ||
138 win.HTMLObjectElement.isInstance(elt) ||
139 win.HTMLEmbedElement.isInstance(elt)
145 (win.HTMLIFrameElement.isInstance(elt) && elt.mozbrowser) ||
146 win.XULFrameElement.isInstance(elt)
148 // If we're targeting a mozbrowser iframe or an embedded XULFrameElement
149 // (e.g. about:addons extensions inline options page), do not activate
159 XPCOMUtils.defineLazyPreferenceGetter(
162 "accessibility.typeaheadfind"
164 XPCOMUtils.defineLazyPreferenceGetter(
167 "accessibility.typeaheadfind.manual"