home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / chrome / toolkit.jar / content / global / findUtils.js < prev    next >
Encoding:
JavaScript  |  2005-02-01  |  3.7 KB  |  109 lines

  1. //@line 39 "/c/mozilla/toolkit/content/findUtils.js"
  2. var gPromptService;
  3. var gFindBundle;
  4.  
  5. function nsFindInstData() {}
  6. nsFindInstData.prototype =
  7. {
  8.   // set the next three attributes on your object to override the defaults
  9.   browser : null,
  10.  
  11.   get rootSearchWindow() { return this._root || this.window.content; },
  12.   set rootSearchWindow(val) { this._root = val; },
  13.  
  14.   get currentSearchWindow() {
  15.     if (this._current)
  16.       return this._current;
  17.  
  18.     var focusedWindow = this.window.document.commandDispatcher.focusedWindow;
  19.     if (!focusedWindow || focusedWindow == this.window)
  20.       focusedWindow = this.window.content;
  21.  
  22.     return focusedWindow;
  23.   },
  24.   set currentSearchWindow(val) { this._current = val; },
  25.  
  26.   get webBrowserFind() { return this.browser.webBrowserFind; },
  27.  
  28.   init : function() {
  29.     var findInst = this.webBrowserFind;
  30.     // set up the find to search the focussedWindow, bounded by the content window.
  31.     var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
  32.     findInFrames.rootSearchFrame = this.rootSearchWindow;
  33.     findInFrames.currentSearchFrame = this.currentSearchWindow;
  34.   
  35.     // always search in frames for now. We could add a checkbox to the dialog for this.
  36.     findInst.searchFrames = true;
  37.   },
  38.  
  39.   window : window,
  40.   _root : null,
  41.   _current : null
  42. }
  43.  
  44. // browser is the <browser> element
  45. // rootSearchWindow is the window to constrain the search to (normally window.content)
  46. // currentSearchWindow is the frame to start searching (can be, and normally, rootSearchWindow)
  47. function findInPage(findInstData)
  48. {
  49.   // is the dialog up already?
  50.   if ("findDialog" in window && window.findDialog)
  51.     window.findDialog.focus();
  52.   else
  53.   {
  54.     findInstData.init();
  55.     window.findDialog = window.openDialog("chrome://global/content/finddialog.xul", "_blank", "chrome,resizable=no,dependent=yes", findInstData);
  56.   }
  57. }
  58.  
  59. function findAgainInPage(findInstData, reverse)
  60. {
  61.   if ("findDialog" in window && window.findDialog)
  62.     window.findDialog.focus();
  63.   else
  64.   {
  65.     // get the find service, which stores global find state, and init the
  66.     // nsIWebBrowser find with it. We don't assume that there was a previous
  67.     // Find that set this up.
  68.     var findService = Components.classes["@mozilla.org/find/find_service;1"]
  69.                            .getService(Components.interfaces.nsIFindService);
  70.  
  71.     var searchString = findService.searchString;
  72.     if (searchString.length == 0) {
  73.       // no previous find text
  74.       findInPage(findInstData);
  75.       return;
  76.     }
  77.  
  78.     findInstData.init();
  79.     var findInst = findInstData.webBrowserFind;
  80.     findInst.searchString  = searchString;
  81.     findInst.matchCase     = findService.matchCase;
  82.     findInst.wrapFind      = findService.wrapFind;
  83.     findInst.entireWord    = findService.entireWord;
  84.     findInst.findBackwards = findService.findBackwards ^ reverse;
  85.  
  86.     var found = findInst.findNext();
  87.     if (!found) {
  88.       if (!gPromptService)
  89.         gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService()
  90.                                    .QueryInterface(Components.interfaces.nsIPromptService);                                     
  91.       if (!gFindBundle)
  92.         gFindBundle = document.getElementById("findBundle");
  93.           
  94.       gPromptService.alert(window, gFindBundle.getString("notFoundTitle"), gFindBundle.getString("notFoundWarning"));
  95.     }      
  96.  
  97.     // Reset to normal value, otherwise setting can get changed in find dialog
  98.     findInst.findBackwards = findService.findBackwards; 
  99.   }
  100. }
  101.  
  102. function canFindAgainInPage()
  103. {
  104.     var findService = Components.classes["@mozilla.org/find/find_service;1"]
  105.                            .getService(Components.interfaces.nsIFindService);
  106.     return (findService.searchString.length > 0);
  107. }
  108.  
  109.