home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / comm.jar / content / communicator / findUtils.js < prev    next >
Encoding:
JavaScript  |  2001-06-20  |  4.0 KB  |  96 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Simon Fraser <sfraser@netscape.com>
  22.  */
  23.  
  24. var gPromptService;
  25. var gFindBundle;
  26.  
  27. // browser is the <browser> element
  28. // rootSearchWindow is the window to constrain the search to (normally window._content)
  29. // startSearchWindow is the frame to start searching (can be, and normally, rootSearchWindow)
  30. function findInPage(browser, rootSearchWindow, startSearchWindow)
  31. {
  32.   var findInst = browser.webBrowserFind;
  33.   // set up the find to search the focussedWindow, bounded by the content window.
  34.   var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
  35.   findInFrames.rootSearchFrame = rootSearchWindow;
  36.   findInFrames.currentSearchFrame = startSearchWindow;
  37.  
  38.   // always search in frames for now. We could add a checkbox to the dialog for this.
  39.   findInst.searchFrames = true;
  40.   
  41.   // is the dialog up already?
  42.   if (window.findDialog)
  43.     window.findDialog.focus();
  44.   else
  45.     window.findDialog = window.openDialog("chrome://global/content/finddialog.xul", "_blank", "chrome,resizable=no,dependent=yes", findInst);
  46. }
  47.  
  48. function findAgainInPage(browser, rootSearchWindow, startSearchWindow)
  49. {
  50.   if (window.findDialog)
  51.     window.findDialog.focus();
  52.   else
  53.   {
  54.     var findInst = browser.webBrowserFind;
  55.     // set up the find to search the focussedWindow, bounded by the content window.
  56.     var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
  57.     findInFrames.rootSearchFrame = rootSearchWindow;
  58.     findInFrames.currentSearchFrame = startSearchWindow;
  59.  
  60.     // always search in frames for now. We could add a checkbox to the dialog for this.
  61.     findInst.searchFrames = true;
  62.  
  63.     // get the find service, which stores global find state, and init the
  64.     // nsIWebBrowser find with it. We don't assume that there was a previous
  65.     // Find that set this up.
  66.     var findService = Components.classes["@mozilla.org/find/find_service;1"]
  67.                            .getService(Components.interfaces.nsIFindService);
  68.     findInst.searchString  = findService.searchString;
  69.     findInst.matchCase     = findService.matchCase;
  70.     findInst.wrapFind      = findService.wrapFind;
  71.     findInst.entireWord    = findService.entireWord;
  72.     findInst.findBackwards = findService.findBackwards;
  73.  
  74.     var found = false;
  75.     if (findInst.searchString.length > 0)   // should never happen if command updating works
  76.       found = findInst.findNext();
  77.     if (!found) {
  78.       if (!gPromptService)
  79.         gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService()
  80.                                    .QueryInterface(Components.interfaces.nsIPromptService);                                     
  81.       if (!gFindBundle)
  82.         gFindBundle = document.getElementById("findBundle");
  83.           
  84.       gPromptService.alert(window, gFindBundle.getString("notFoundTitle"), gFindBundle.getString("notFoundWarning"));
  85.     }      
  86.   }
  87. }
  88.  
  89. function canFindAgainInPage()
  90. {
  91.     var findService = Components.classes["@mozilla.org/find/find_service;1"]
  92.                            .getService(Components.interfaces.nsIFindService);
  93.     return (findService.searchString.length > 0);
  94. }
  95.  
  96.