playing around with Find in Page functionality; the recent dojo highlighter commit...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 13 Aug 2010 14:48:01 +0000 (14:48 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 13 Aug 2010 14:48:01 +0000 (14:48 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@17211 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/util/browser.js
Open-ILS/xul/staff_client/chrome/content/util/browser.xul
Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul

index c45652e..ed565f2 100644 (file)
@@ -108,6 +108,13 @@ util.browser.prototype = {
                                     obj.error.sdump('D_ERROR',err);
                                 }
                             }
+                        ],
+                        'cmd_find' : [
+                            ['command'],
+                            function() {
+                                var text = window.prompt('Enter text to find:');
+                                obj.find(text);
+                            }
                         ]
                     }
                 }
@@ -135,6 +142,71 @@ util.browser.prototype = {
         }
     },
 
+    'find' : function(text) {
+        var obj = this;
+        try {
+            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
+            function getBrowser() {
+                return obj.controller.view.browser_browser;
+            }
+
+            function getFocusedSelCtrl() {
+                var ds = getBrowser().docShell;
+                var dsEnum = ds.getDocShellEnumerator(Components.interfaces.nsIDocShellTreeItem.typeContent,
+                                                    Components.interfaces.nsIDocShell.ENUMERATE_FORWARDS);
+                while (dsEnum.hasMoreElements()) {
+                    ds = dsEnum.getNext().QueryInterface(Components.interfaces.nsIDocShell);
+                    if (ds.hasFocus) {
+                        var display = ds.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsISelectionDisplay);
+                        if (!display) return null;
+                        return display.QueryInterface(Components.interfaces.nsISelectionController);
+                    }
+                }
+
+                // One last try
+                return getBrowser().docShell
+                    .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+                    .getInterface(Components.interfaces.nsISelectionDisplay)
+                    .QueryInterface(Components.interfaces.nsISelectionController);
+            }
+
+            function setSelection(range) {
+                try {
+                    var selctrlcomp = Components.interfaces.nsISelectionController;
+                    var selctrl = getFocusedSelCtrl();
+                    var sel = selctrl.getSelection(selctrlcomp.SELECTION_NORMAL);
+                    sel.removeAllRanges();
+                    sel.addRange(range.cloneRange());
+
+                    selctrl.scrollSelectionIntoView(selctrlcomp.SELECTION_NORMAL,
+                        selctrlcomp.SELECTION_FOCUS_REGION,
+                        true);
+                } catch(e) {alert("setSelection: " + e);}
+            }
+
+            var doc = obj.get_content().document;
+            var body = doc.body;
+            var count = body.childNodes.length;
+            var finder = Components.classes["@mozilla.org/embedcomp/rangefind;1"].createInstance()
+                .QueryInterface(Components.interfaces.nsIFind);
+            var searchRange = doc.createRange();
+            var startPt = doc.createRange();
+            var endPt = doc.createRange();
+                searchRange.setStart(body,0);
+                searchRange.setEnd(body, count);
+                startPt.setStart(body, 0);
+                startPt.setEnd(body, 0);
+                endPt.setStart(body, count);
+                endPt.setEnd(body, count);
+            var retRange = finder.Find(text, searchRange, startPt, endPt);
+            alert('retRange = ' + retRange );
+            setSelection(retRange);
+        } catch(E) {
+            alert('Error in browser.js, find(): ' + E);
+        }
+    },
+
     'get_content' : function() {
         try {
             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
index c6fc6e6..6cceebb 100644 (file)
         <command id="cmd_broken" />
         <command id="cmd_print" label="&common.browser.print.label;" accesskey="&common.browser.print.accesskey;" />
         <command id="cmd_debug" />
+        <command id="cmd_find" />
         <command id="cmd_back" label="&common.browser.backward.label;" accesskey="&common.browser.backward.accesskey;" />
         <command id="cmd_reload" label="&common.browser.reload.label;" accesskey="&common.browser.reload.accesskey;" />
         <command id="cmd_forward" label="&common.browser.forward.label;" accesskey="&common.browser.forward.accesskey;" />
             <spacer flex="1"/>
             <label id="debug" value="Debug" disabled="true" command="cmd_debug" onclick="this.doCommand();" />
             <button id="browser_print" command="cmd_print" hidden="true"/>
+            <button id="browser_find" label="Find in Page" command="cmd_find" hidden="false"/>
         </hbox>
         <browser id="browser_browser" flex="1" autoscroll="false" type="content"/>
     </vbox>
index 66508f7..ce1d0e8 100644 (file)
         <command id="cmd_broken" />
         <command id="cmd_print" label="&common.browser.print.label;" accesskey="&common.browser.print.accesskey;" />
         <command id="cmd_debug" />
+        <command id="cmd_find" />
         <command id="cmd_back" label="&common.browser.backward.label;" accesskey="&common.browser.backward.accesskey;" />
         <command id="cmd_reload" label="&common.browser.reload.label;" accesskey="&common.browser.reload.accesskey;" />
         <command id="cmd_forward" label="&common.browser.forward.label;" accesskey="&common.browser.forward.accesskey;" />
             <spacer flex="1"/>
             <label id="debug" value="Debug" disabled="true" command="cmd_debug" onclick="this.doCommand();" />
             <button id="browser_print" command="cmd_print" hidden="true"/>
+            <button id="browser_find" label="Find in Page" command="cmd_find" hidden="false"/>
         </hbox>
         <browser id="browser_browser" flex="1" autoscroll="false" type="content"/>
     </vbox>