Bug 916534 - Find Highlight should work in subframes. r=mikdeboer, a=lsblakk
authorTom Schuster <evilpies@gmail.com>
Tue, 17 Sep 2013 12:54:35 -0400
changeset 160324 0129db608054cd541c4bb1ab0e301dc17a26a1d7
parent 160323 35e3080191c99fca5a660607d2e3d9ad09d8c960
child 160325 59170fb446848fe76b45a6d408c46e3d6d5eb6a3
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikdeboer, lsblakk
bugs916534
milestone26.0a2
Bug 916534 - Find Highlight should work in subframes. r=mikdeboer, a=lsblakk
toolkit/content/widgets/findbar.xml
toolkit/modules/Finder.jsm
--- a/toolkit/content/widgets/findbar.xml
+++ b/toolkit/content/widgets/findbar.xml
@@ -430,38 +430,16 @@
             setTimeout(function(aSelf) {
                          if (aSelf._findMode != aSelf.FIND_NORMAL)
                            aSelf.close();
                        }, this._quickFindTimeoutLength, this);
         ]]></body>
       </method>
 
       <!--
-        - For a given node, walk up it's parent chain, to try and find an
-        - editable node.
-        -
-        - @param aNode the node we want to check
-        - @returns the first node in the parent chain that is editable,
-        -          null if there is no such node
-        -->
-      <method name="_getEditableNode">
-        <parameter name="aNode"/>
-        <body><![CDATA[
-          while (aNode) {
-            if (aNode instanceof Components.interfaces.nsIDOMNSEditableElement) {
-              return aNode.editor ? aNode : null;
-            }
-            aNode = aNode.parentNode;
-          }
-          return null;
-        ]]></body>
-      </method>
-
-
-      <!--
         - Turns highlight on or off.
         - @param aHighlight (boolean)
         -        Whether to turn the highlight on or off
         -->
       <method name="toggleHighlight">
         <parameter name="aHighlight"/>
         <body><![CDATA[
           if (!this._dispatchFindEvent("highlightallchange"))
--- a/toolkit/modules/Finder.jsm
+++ b/toolkit/modules/Finder.jsm
@@ -75,17 +75,21 @@ Finder.prototype = {
 
   findAgain: function (aFindBackwards, aLinksOnly) {
     let result = this._fastFind.findAgain(aFindBackwards, aLinksOnly);
     this._notify(result, aFindBackwards, aLinksOnly);
   },
 
   highlight: function (aHighlight, aWord) {
     this._searchString = aWord;
-    this._highlight(aHighlight, aWord, null);
+    let found = this._highlight(aHighlight, aWord, null);
+    if (found)
+      this._notify(Ci.nsITypeAheadFind.FIND_FOUND, false, false);
+    else
+      this._notify(Ci.nsITypeAheadFind.FIND_NOTFOUND, false, false);
   },
 
   removeSelection: function() {
     let fastFind = this._fastFind;
 
     fastFind.collapseSelection();
     fastFind.setSelectionModeAndRepaint(Ci.nsISelectionController.SELECTION_ON);
 
@@ -173,29 +177,28 @@ Finder.prototype = {
     }
 
     this._previousLink = foundLink;
   },
 
   _highlight: function (aHighlight, aWord, aWindow) {
     let win = aWindow || this._getWindow();
 
-    let result = Ci.nsITypeAheadFind.FIND_NOTFOUND;
+    let found = false;
     for (let i = 0; win.frames && i < win.frames.length; i++) {
       if (this._highlight(aHighlight, aWord, win.frames[i]))
-        result = Ci.nsITypeAheadFind.FIND_FOUND;
+        found = true;
     }
 
     let controller = this._getSelectionController(win);
     let doc = win.document;
     if (!controller || !doc || !doc.documentElement) {
       // Without the selection controller,
       // we are unable to (un)highlight any matches
-      this._notify(result)
-      return;
+      return found;
     }
 
     let body = (doc instanceof Ci.nsIDOMHTMLDocument && doc.body) ?
                doc.body : doc.documentElement;
 
     if (aHighlight) {
       let searchRange = doc.createRange();
       searchRange.selectNodeContents(body);
@@ -214,17 +217,17 @@ Finder.prototype = {
       finder.caseSensitive = this._fastFind.caseSensitive;
 
       while ((retRange = finder.Find(aWord, searchRange,
                                      startPt, endPt))) {
         this._highlightRange(retRange, controller);
         startPt = retRange.cloneRange();
         startPt.collapse(false);
 
-        result = Ci.nsITypeAheadFind.FIND_FOUND;
+        found = true;
       }
     } else {
       // First, attempt to remove highlighting from main document
       let sel = controller.getSelection(Ci.nsISelectionController.SELECTION_FIND);
       sel.removeAllRanges();
 
       // Next, check our editor cache, for editors belonging to this
       // document
@@ -234,20 +237,22 @@ Finder.prototype = {
             sel = this._editors[x].selectionController
                                   .getSelection(Ci.nsISelectionController.SELECTION_FIND);
             sel.removeAllRanges();
             // We don't need to listen to this editor any more
             this._unhookListenersAtIndex(x);
           }
         }
       }
-      return true;
+
+      //Removing the highlighting always succeeds, so return true.
+      found = true;
     }
 
-    this._notify(result);
+    return found;
   },
 
   _highlightRange: function(aRange, aController) {
     let node = aRange.startContainer;
     let controller = aController;
 
     let editableNode = this._getEditableNode(node);
     if (editableNode)
@@ -286,16 +291,24 @@ Finder.prototype = {
                           .QueryInterface(Ci.nsIDocShell);
 
     let controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
                              .getInterface(Ci.nsISelectionDisplay)
                              .QueryInterface(Ci.nsISelectionController);
     return controller;
   },
 
+  /*
+   * For a given node, walk up it's parent chain, to try and find an
+   * editable node.
+   *
+   * @param aNode the node we want to check
+   * @returns the first node in the parent chain that is editable,
+   *          null if there is no such node
+   */
   _getEditableNode: function (aNode) {
     while (aNode) {
       if (aNode instanceof Ci.nsIDOMNSEditableElement)
         return aNode.editor ? aNode : null;
 
       aNode = aNode.parentNode;
     }
     return null;