home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / findUtils.js < prev    next >
Text File  |  2002-11-02  |  3KB  |  81 lines

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