obj.error.sdump('D_ERROR',err);
}
}
+ ],
+ 'cmd_find' : [
+ ['command'],
+ function() {
+ var text = window.prompt('Enter text to find:');
+ obj.find(text);
+ }
]
}
}
}
},
+ '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");
<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>
<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>