home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 July & August / PCWorld_2005-07-08_cd.bin / komunikace / netscape / nsb-install-8-0.exe / chrome / toolkit.jar / content / global / findUtils.js < prev    next >
Text File  |  2004-12-22  |  4KB  |  132 lines

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