1 // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 Components.utils.import("resource://gre/modules/Services.jsm");
8 Components.utils.import("resource://gre/modules/FormHistory.jsm");
10 var dialog; // Quick access to document/form elements.
11 var gFindInst; // nsIWebBrowserFind that we're going to use
12 var gFindInstData; // use this to update the find inst data
14 function initDialogObject()
16 // Create dialog object and initialize.
18 dialog.findKey = document.getElementById("dialog.findKey");
19 dialog.caseSensitive = document.getElementById("dialog.caseSensitive");
20 dialog.wrap = document.getElementById("dialog.wrap");
21 dialog.find = document.getElementById("btnFind");
22 dialog.up = document.getElementById("radioUp");
23 dialog.down = document.getElementById("radioDown");
24 dialog.rg = dialog.up.radioGroup;
27 // Move dialog to center, if it not been shown before
28 var windowElement = document.getElementById("findDialog");
29 if (!windowElement.hasAttribute("screenX") || !windowElement.hasAttribute("screenY"))
32 moveToAlertPosition();
38 // get the find service, which stores global find state
39 var findService = Components.classes["@mozilla.org/find/find_service;1"]
40 .getService(Components.interfaces.nsIFindService);
42 // Set initial dialog field contents. Use the gFindInst attributes first,
43 // this is necessary for window.find()
44 dialog.findKey.value = gFindInst.searchString ? gFindInst.searchString : findService.searchString;
45 dialog.caseSensitive.checked = gFindInst.matchCase ? gFindInst.matchCase : findService.matchCase;
46 dialog.wrap.checked = gFindInst.wrapFind ? gFindInst.wrapFind : findService.wrapFind;
47 var findBackwards = gFindInst.findBackwards ? gFindInst.findBackwards : findService.findBackwards;
49 dialog.rg.selectedItem = dialog.up;
51 dialog.rg.selectedItem = dialog.down;
54 function saveFindData()
56 // get the find service, which stores global find state
57 var findService = Components.classes["@mozilla.org/find/find_service;1"]
58 .getService(Components.interfaces.nsIFindService);
60 // Set data attributes per user input.
61 findService.searchString = dialog.findKey.value;
62 findService.matchCase = dialog.caseSensitive.checked;
63 findService.wrapFind = dialog.wrap.checked;
64 findService.findBackwards = dialog.up.selected;
71 // get the find instance
72 var arg0 = window.arguments[0];
73 // If the dialog was opened from window.find(),
74 // arg0 will be an instance of nsIWebBrowserFind
75 if (arg0 instanceof Components.interfaces.nsIWebBrowserFind) {
79 gFindInst = gFindInstData.webBrowserFind;
85 if (dialog.findKey.value)
86 dialog.findKey.select();
87 dialog.findKey.focus();
92 window.opener.findDialog = 0;
97 if (gFindInstData && gFindInst != gFindInstData.webBrowserFind) {
99 gFindInst = gFindInstData.webBrowserFind;
102 // Transfer dialog contents to the find service.
106 // set up the find instance
107 gFindInst.searchString = dialog.findKey.value;
108 gFindInst.matchCase = dialog.caseSensitive.checked;
109 gFindInst.wrapFind = dialog.wrap.checked;
110 gFindInst.findBackwards = dialog.up.selected;
113 var result = gFindInst.findNext();
118 dialog.bundle = document.getElementById("findBundle");
119 Services.prompt.alert(window, dialog.bundle.getString("notFoundTitle"),
120 dialog.bundle.getString("notFoundWarning"));
121 dialog.findKey.select();
122 dialog.findKey.focus();
127 function doEnabling()
129 dialog.find.disabled = !dialog.findKey.value;
132 function updateFormHistory()
134 if (window.opener.PrivateBrowsingUtils &&
135 window.opener.PrivateBrowsingUtils.isWindowPrivate(window.opener) ||
136 !dialog.findKey.value)
141 fieldname: "find-dialog",
142 value: dialog.findKey.value
144 handleError: function(aError) {
145 Components.utils.reportError("Saving find to form history failed: " +