Bug 1352481 - Finding content and highlights in popups. draft
authormanotejmeka <manotejmeka@gmail.com>
Thu, 13 Apr 2017 12:11:10 -0400
changeset 562197 75b5d64697e9f6157e11914f6c301ec0e1def8c4
parent 561777 37ee196ecaf5a964c31738ae066325a3b5892d54
child 624197 d4af801c790c0f22621b1980adee0ae8ca69397b
push id53982
push userbmo:manotejmeka@gmail.com
push dateThu, 13 Apr 2017 16:20:16 +0000
bugs1352481
milestone55.0a1
Bug 1352481 - Finding content and highlights in popups. MozReview-Commit-ID: 1lVnHwGGFrm
browser/components/preferences/in-content/findInPage.js
browser/components/preferences/in-content/subdialogs.js
--- a/browser/components/preferences/in-content/findInPage.js
+++ b/browser/components/preferences/in-content/findInPage.js
@@ -8,16 +8,20 @@
 var gSearchResultsPane = {
   findSelection: null,
   searchResultsCategory: null,
   searchInput: null,
   listSearchBubbles: [],
   initialSearch: true,
   trie: null,
   timer: null,
+  dialogBoxs: {},
+  counterDialog: 0,
+  dialogeInit: true,
+  searchQuery: "",
 
   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");
@@ -89,20 +93,25 @@ var gSearchResultsPane = {
       if (!this.categoriesInitialized) {
         this.categoriesInitialized = true;
         // Each element of gCategoryInits is a name
         for (let [/* name */, category] of gCategoryInits) {
           if (!category.inited) {
             category.init();
           }
         }
+        // Initializing the sub dialogues
+        this.subDialogInit();
+        // Getting contents of subdialog boxes
+        this.openSubDialogBox();
+
         // Initial search to load tries tree
         this.searchFunction("testing search");
-		this.searchInput.value = ""; // Clearning old searches
-		this.searchFunction("");
+        this.searchInput.value = ""; // Clearning old searches
+        this.searchFunction("");
       }
     } else if (event.type === "input") {
       let query = event.target.value.trim().toLowerCase();
       // Adding a class to show the close button
       this.classManipulation(query, "closeButton");
       let overlayClose = document.getElementById("close-button-overlay");
       overlayClose.hidden = false;
       overlayClose.addEventListener("click", this);
@@ -158,16 +167,28 @@ var gSearchResultsPane = {
         parent.classList.remove("search-tooltip-reverse");
       } else {
         child.classList.add("search-tooltip-inner-reverse");
         parent.classList.add("search-tooltip-reverse");
       }
     }
   },
 
+  subDialogInit() {
+    // Mighting be missing some just a list of all visibile during inspect element
+    let ids = ["useBookmark","chooseLanguage","advancedFonts","colors"];
+			   // ,"passwordExceptions","showPasswords",
+               // "popupPolicyButton","notificationsPolicyButton","addonExceptions",
+               // "connectionSettings","offlineNotifyExceptions","showUpdateHistory"];
+    for (let id of ids){
+      document.getElementById(id).setAttribute("subDialog","true");
+      gSearchResultsPane.dialogBoxs[id] = "";
+    }
+  },
+
   /**
    * Check that the passed string matches the filter arguments.
    *
    * @param String str
    *    to search for filter words in.
    * @param String filter
    *    is a string containing all of the words to filter on.
    * @returns boolean
@@ -305,16 +326,17 @@ var gSearchResultsPane = {
   /**
    * Shows or hides content according to search input
    *
    * @param String event
    *    to search for filted query in
    */
   searchFunction(query) {
     // let query = event.target.value.trim().toLowerCase();
+    this.searchQuery = query;
     this.findSelection.removeAllRanges();
 
     // Remove all search tooltips that were created
     let searchTooltips = Array.from(document.querySelectorAll(".search-tooltip"));
     for (let searchTooltip of searchTooltips) {
       searchTooltip.parentElement.classList.remove("search-tooltip-parent");
       searchTooltip.removeEventListener("mouseenter", this);
       searchTooltip.remove();
@@ -453,28 +475,44 @@ var gSearchResultsPane = {
           this.listSearchTooltips.push(nodeObject);
         }
       }
 
       if (nodeObject.tagName == "button" && (labelResult || valueResult)){
         nodeObject.setAttribute("highlightable", "true");
       }
 
-      matchesFound = matchesFound || complexTextNodesResult || labelResult || valueResult;
+      let subDialog = false;
+      if (nodeObject.tagName == "button" && nodeObject.getAttribute("subDialog")) {
+        
+        subDialog = this.findInDialogs(nodeObject.getAttribute("id"),searchPhrase);
+        //console.log("ans",nodeObject.getAttribute("id"),subDialog, nodeObject);
+        if (subDialog) {
+          //console.log("in dialog",nodeObject,searchPhrase);
+          this.listSearchTooltips.push(nodeObject);
+        }
+      }
+
+      matchesFound = matchesFound || complexTextNodesResult || labelResult || valueResult || subDialog;
+
     }
 
     for (let i = 0; i < nodeObject.childNodes.length; i++) {
       // Search only if child node is not hidden
       if (!nodeObject.childNodes[i].hidden) {
         let result = this.searchWithinNode(nodeObject.childNodes[i], searchPhrase);
         // Creating tooltips for menulist element
         if (result && nodeObject.tagName == "menulist") {
           this.listSearchTooltips.push(nodeObject);
         }
-        matchesFound = matchesFound || result;
+        let subRes = false;
+        if (nodeObject.childNodes[i].contentDocument) {
+          subRes = this.searchWithinNode(nodeObject.childNodes[i].contentDocument, searchPhrase);
+        }
+        matchesFound = matchesFound || result || subRes;
       }
     }
     return matchesFound;
   },
 
   /**
    * Inserting a div structure infront of the DOM element matched textContent.
    * Then calculation the offsets to position the tooltip in the correct place.
@@ -544,10 +582,111 @@ var gSearchResultsPane = {
     // then splitting it into list of words
     let listOfWords = phrase.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "").removeStopWords().split(" ");
     for (let i = 0; i < listOfWords.length; i++) {
       // Might need a better way to check if it is not just numbers
       if (isNaN(listOfWords[i])) {
         this.trie.insert(listOfWords[i].toLowerCase());
       }
     }
+  },
+
+  getSubDialogContent() {
+    //console.log("getting Sub dialog Contet")
+    let that = gSearchResultsPane;
+      //console.log("ar",arry[1],this.totalSubDialogs,this.counterDialog);
+    console.log("opened: ",Object.keys(that.dialogBoxs).length, that.counterDialog);
+    if (Object.keys(that.dialogBoxs).length > that.counterDialog) {
+      // Opening the dialogue box
+	    //console.log("click",key,that.counterDialog,Object.keys(that.dialogBoxs).length);
+      let dialogObj = document.getElementById("dialogBox");
+      //console.log("db",dialogObj,dialogObj.children.length);
+      let subData = that.leafNodes(dialogObj);
+      that.dialogBoxs[Object.keys(that.dialogBoxs)[that.counterDialog]] = subData;
+      that.addToTries(subData);
+      that.counterDialog += 1;
+    } else {
+      that.dialogeInit = false;
+    }
+    document.getElementById("dialogClose").click();
+    that.openSubDialogBox();
+  },
+
+  openSubDialogBox() {
+    let that = gSearchResultsPane;
+    if (Object.keys(that.dialogBoxs).length > that.counterDialog) {
+      document.getElementById(Object.keys(that.dialogBoxs)[that.counterDialog]).click();
+    }
+  },
+  
+  leafNodes(nodeObject) {
+	let matchesFound = "";
+  let that = gSearchResultsPane;
+	//console.log("fun: ",nodeObject,nodeObject.childNodes.length)
+    if (nodeObject.childElementCount == 0) {
+      let simpleTextNodes = that.textNodeDescendants(nodeObject);
+
+      for (let node of simpleTextNodes) {
+        if (isNaN(node.textContent)) {
+          matchesFound += " " +node.textContent.toLowerCase();
+        }
+      }
+
+      // Collecting data from boxObject
+      
+      let allNodeText = "";
+      let labelResult = false;
+      let valueResult = false;
+      let accessKeyTextNodes = that.textNodeDescendants(nodeObject.boxObject);
+
+      for (let node of accessKeyTextNodes) {
+        allNodeText += node.textContent;
+      }
+
+      // Access key are presented
+      if (isNaN(allNodeText)) {
+        matchesFound += " " + allNodeText;
+      }
+
+      // Searching some elements, such as xul:button, have a "label" attribute that contains the user-visible text.
+      let labelContent = nodeObject.getAttribute("label");
+      if (isNaN(labelContent)) {
+        matchesFound += " " + labelContent.toLowerCase();
+      }
+      // Searching some elements, such as xul:label, store their user-visible text in a "value" attribute.
+      let valueContent = nodeObject.getAttribute("value");
+      if (isNaN(valueContent)) {
+        matchesFound += " " + valueContent.toLowerCase();
+      }
+      
+    }
+
+    for (let i = 0; i < nodeObject.childNodes.length; i++) {
+      //console.log("\tchild:",nodeObject.childNodes[i],nodeObject.childNodes[i].childNodes.length);
+      
+      let result = that.leafNodes(nodeObject.childNodes[i]);
+      //console.log("\tresult",result);
+      if (nodeObject.childNodes[i].contentDocument) {
+        result += that.leafNodes(nodeObject.childNodes[i].contentDocument);
+      }
+      //console.log("\tresult2",result);
+      //console.log("result",result);
+      matchesFound += result;
+    }
+    return matchesFound;
+  },
+
+  findInDialogs(nodeObjectId,searchPhrase) {
+	//console.log(key, gSearchResultsPane.dialogBoxs[key]);
+	let storeData = this.dialogBoxs[nodeObjectId].toLowerCase();
+	if (storeData && storeData.indexOf(searchPhrase) > -1) {
+	  return true;
+	}
+    return false;
+  },
+
+  highlightDialog() {
+    if (this.searchQuery) {
+	  let dialog = document.getElementById("dialogBox");
+	  this.searchWithinNode(dialog, this.searchQuery)
+	}
   }
 }
--- a/browser/components/preferences/in-content/subdialogs.js
+++ b/browser/components/preferences/in-content/subdialogs.js
@@ -1,14 +1,15 @@
 /* - 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/. */
 
 /* import-globals-from ../../../base/content/utilityOverlay.js */
 /* import-globals-from preferences.js */
+/* import-globals-from findInPage.js */
 
 "use strict";
 
 var gSubDialog = {
   _closingCallback: null,
   _closingEvent: null,
   _isClosing: false,
   _frame: null,
@@ -289,16 +290,23 @@ var gSubDialog = {
     this._overlay.style.visibility = "visible";
     this._overlay.style.opacity = ""; // XXX: focus hack continued from _onContentLoaded
 
     if (this._box.getAttribute("resizable") == "true") {
       this._resizeObserver = new MutationObserver(this._onResize);
       this._resizeObserver.observe(this._box, {attributes: true});
     }
 
+    //console.log("open",gSearchResultsPane.dialogeInit);
+    if (gSearchResultsPane.dialogeInit) {
+      gSearchResultsPane.getSubDialogContent();
+    } else {
+      gSearchResultsPane.highlightDialog();
+    }
+
     this._trapFocus();
   },
 
   _onResize(mutations) {
     let frame = gSubDialog._frame;
     // The width and height styles are needed for the initial
     // layout of the frame, but afterward they need to be removed
     // or their presence will restrict the contents of the <browser>