--- a/browser/components/preferences/in-content/findInPage.js
+++ b/browser/components/preferences/in-content/findInPage.js
@@ -1,51 +1,66 @@
/* 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/. */
+Components.utils.import("resource://gre/modules/DeferredTask.jsm");
// paneSearchResults needs init function to initialize the object
var gSearchResultsPane = {
findSelection: null,
-
searchResultsCategory: null,
-
searchInput: null,
-
listSearchBubbles: [],
-
initialSearch: true,
-
trie: null,
+ timer: null,
init() {
let controller = this.getSelectionController();
this.findSelection = controller.getSelection(Ci.nsISelectionController.SELECTION_FIND);
this.searchResultsCategory = document.getElementById("category-search-results");
this.searchInput = document.getElementById("searchInput");
this.searchInput.hidden = !Services.prefs.getBoolPref("browser.preferences.search");
document.getElementById("searchSuggestions").hidden = this.searchInput.hidden;
if (!this.searchInput.hidden) {
this.searchInput.addEventListener("command", this);
this.searchInput.addEventListener("focus", this);
+ this.searchInput.addEventListener("input", this);
+ this.searchInput.addEventListener("keypress", this);
// adding datalist to textbos input element
// let temp = this.searchInput.boxObject.firstChild.childNodes[0];
// temp.setAttribute("list","searchSuggestions");
// temp.setAttribute("autocomplete","off");
}
this.trie = new Trie();
},
handleEvent(event) {
- if (event.type === "command") {
+ if (event.type === "command" ||
+ (event.type === "keypress" && event.keyCode === 13)) {
this.searchFunction(event);
} else if (event.type === "focus") {
this.initializeCategories();
+ } else if (event.type === "input") {
+ console.log("input",event,event.keyCode)
+ let query = event.target.value.trim()
+ console.log("Search Suggestions: ",this.trie.autoComplete(String(query.toLowerCase())));
+ this.searchSuggestions(this.trie.autoComplete(String(query.toLowerCase())));
+ } else if (event.type === "keypress"){
+ if (this.timer != null) {
+ //console.log("cancel");
+ this.timer.disarm();
+ }
+ this.timer = new DeferredTask(function* () {
+ //console.log("searching DeferredTask");
+ gSearchResultsPane.searchFunction(event);
+ }, 600);
+ this.timer.arm();
}
},
/**
* Check that the passed string matches the filter arguments.
*
* @param String str
* to search for filter words in.
@@ -232,16 +247,48 @@ var gSearchResultsPane = {
}
for (let word of listSuggestions){
let option = document.createElementNS('http://www.w3.org/1999/xhtml', 'option');
option.setAttribute("value",word);
option.setAttribute("data-value",word);
//option.setAttribute("xmlns" ,"http://www.w3.org/1999/xhtml");
object.appendChild(option);
}
+ var keyboardEvent = document.createEvent("KeyboardEvent");
+ var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent";
+
+
+ keyboardEvent[initMethod](
+ "keyup", // event type : keydown, keyup, keypress
+ true, // bubbles
+ true, // cancelable
+ window, // viewArg: should be window
+ false, // ctrlKeyArg
+ false, // altKeyArg
+ false, // shiftKeyArg
+ false, // metaKeyArg
+ 40, // keyCodeArg : unsigned long the virtual key code, else 0
+ 0 // charCodeArgs : unsigned long the Unicode character associated with the depressed key, else 0
+ );
+ this.searchInput.focus();
+ this.searchInput.dispatchEvent(keyboardEvent);
+ // //object.focus();
+ // this.searchInput.focus();
+ let DblDelay = new DeferredTask(() => {
+ var event = new MouseEvent('dlbclick', {
+ 'view': window,
+ 'bubbles': true,
+ 'cancelable': true
+ });
+ document.getElementById("browserHomePage").focus();
+ gSearchResultsPane.searchInput.focus();
+ gSearchResultsPane.searchInput.dispatchEvent(event);
+ console.log("click")
+ }, 1000);
+ DblDelay.arm();
},
/**
* Shows or hides content according to search input
*
* @param String event
* to search for filted query in
*/
@@ -252,19 +299,16 @@ var gSearchResultsPane = {
[].forEach.call(document.querySelectorAll('.search-bubble'),function(e){
e.parentNode.removeChild(e);
});
this.listSearchBubbles = [];
let srHeader = document.getElementById("header-searchResults");
if (query) {
- // Provide Search Suggestions
- console.log("Search Suggestions: ",this.trie.autoComplete(String(query.toLowerCase())));
- this.searchSuggestions(this.trie.autoComplete(String(query.toLowerCase())));
// Showing the Search Results Tag
gotoPref("paneSearchResults");
this.searchResultsCategory.hidden = false;
let resultsFound = false;
// Building the range for highlighted areas
@@ -355,25 +399,27 @@ var gSearchResultsPane = {
}
// Access key are presented
let complexTextNodesResult = this.highlightMatches(accessKeyTextNodes, nodeSizes, allNodeText, searchPhrase);
// Searching some elements, such as xul:button, have a 'label' attribute that contains the user-visible text.
if (nodeObject.getAttribute("label")) {
labelResult = this.stringMatchesFilters(nodeObject.getAttribute("label"), searchPhrase);
- if (labelResult){
+ // Making search bubbles
+ if (labelResult && nodeObject.tagName != "checkbox" && nodeObject.tagName != "radio"){
this.listSearchBubbles.push(nodeObject);
}
}
// Searching some elements, such as xul:label, store their user-visible text in a "value" attribute.
if (nodeObject.getAttribute("value")) {
valueResult = this.stringMatchesFilters(nodeObject.getAttribute("value"), searchPhrase);
- if(valueResult){
+ // Making search bubbles
+ if(valueResult && nodeObject.tagName != "checkbox" && nodeObject.tagName != "radio"){
this.listSearchBubbles.push(nodeObject);
}
}
matchesFound = matchesFound || complexTextNodesResult || labelResult || valueResult;
}
for (let i = 0; i < nodeObject.childNodes.length; i++) {