home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / communicator / findUtils.js < prev    next >
Text File  |  2003-06-08  |  5KB  |  120 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Netscape Public License
  6.  * Version 1.1 (the "License"); you may not use this file except in
  7.  * compliance with the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/NPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is 
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Simon Fraser <sfraser@netscape.com>
  24.  *   Dean Tessman <dean_tessman@hotmail.com>
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  28.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the NPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the NPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. var gPromptService;
  41. var gFindBundle;
  42.  
  43. // browser is the <browser> element
  44. // rootSearchWindow is the window to constrain the search to (normally window._content)
  45. // startSearchWindow is the frame to start searching (can be, and normally, rootSearchWindow)
  46. function findInPage(browser, rootSearchWindow, startSearchWindow)
  47. {
  48.   var findInst = browser.webBrowserFind;
  49.   // set up the find to search the focussedWindow, bounded by the content window.
  50.   var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
  51.   findInFrames.rootSearchFrame = rootSearchWindow;
  52.   findInFrames.currentSearchFrame = startSearchWindow;
  53.  
  54.   // always search in frames for now. We could add a checkbox to the dialog for this.
  55.   findInst.searchFrames = true;
  56.   
  57.   // is the dialog up already?
  58.   if ("findDialog" in window && window.findDialog)
  59.     window.findDialog.focus();
  60.   else
  61.     window.findDialog = window.openDialog("chrome://global/content/finddialog.xul", "_blank", "chrome,resizable=no,dependent=yes", findInst);
  62. }
  63.  
  64. function findAgainInPage(browser, rootSearchWindow, startSearchWindow, reverse)
  65. {
  66.   if ("findDialog" in window && window.findDialog)
  67.     window.findDialog.focus();
  68.   else
  69.   {
  70.     var findInst = browser.webBrowserFind;
  71.     // set up the find to search the focussedWindow, bounded by the content window.
  72.     var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
  73.     findInFrames.rootSearchFrame = rootSearchWindow;
  74.     findInFrames.currentSearchFrame = startSearchWindow;
  75.  
  76.     // always search in frames for now. We could add a checkbox to the dialog for this.
  77.     findInst.searchFrames = true;
  78.  
  79.     // get the find service, which stores global find state, and init the
  80.     // nsIWebBrowser find with it. We don't assume that there was a previous
  81.     // Find that set this up.
  82.     var findService = Components.classes["@mozilla.org/find/find_service;1"]
  83.                            .getService(Components.interfaces.nsIFindService);
  84.     findInst.searchString  = findService.searchString;
  85.     findInst.matchCase     = findService.matchCase;
  86.     findInst.wrapFind      = findService.wrapFind;
  87.     findInst.entireWord    = findService.entireWord;
  88.     findInst.findBackwards = findService.findBackwards ^ reverse;
  89.  
  90.     var found = false;
  91.     if (findInst.searchString.length == 0) {
  92.       // no previous find text
  93.       findInPage(browser, rootSearchWindow, startSearchWindow);
  94.       return;
  95.     }
  96.  
  97.     found = findInst.findNext();
  98.     if (!found) {
  99.       if (!gPromptService)
  100.         gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService()
  101.                                    .QueryInterface(Components.interfaces.nsIPromptService);                                     
  102.       if (!gFindBundle)
  103.         gFindBundle = document.getElementById("findBundle");
  104.           
  105.       gPromptService.alert(window, gFindBundle.getString("notFoundTitle"), gFindBundle.getString("notFoundWarning"));
  106.     }      
  107.  
  108.     // Reset to normal value, otherwise setting can get changed in find dialog
  109.     findInst.findBackwards = findService.findBackwards; 
  110.   }
  111. }
  112.  
  113. function canFindAgainInPage()
  114. {
  115.     var findService = Components.classes["@mozilla.org/find/find_service;1"]
  116.                            .getService(Components.interfaces.nsIFindService);
  117.     return (findService.searchString.length > 0);
  118. }
  119.  
  120.