toolkit/components/typeaheadfind/nsTypeAheadFind.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,127 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsCycleCollectionParticipant.h"
    1.10 +#include "nsISelectionController.h"
    1.11 +#include "nsIController.h"
    1.12 +#include "nsIControllers.h"
    1.13 +#include "nsIObserver.h"
    1.14 +#include "nsUnicharUtils.h"
    1.15 +#include "nsIFind.h"
    1.16 +#include "nsIWebBrowserFind.h"
    1.17 +#include "nsWeakReference.h"
    1.18 +#include "nsISelection.h"
    1.19 +#include "nsIDOMRange.h"
    1.20 +#include "nsIDocShellTreeItem.h"
    1.21 +#include "nsITypeAheadFind.h"
    1.22 +#include "nsISound.h"
    1.23 +
    1.24 +class nsIPresShell;
    1.25 +class nsPresContext;
    1.26 +
    1.27 +#define TYPEAHEADFIND_NOTFOUND_WAV_URL \
    1.28 +        "chrome://global/content/notfound.wav"
    1.29 +
    1.30 +class nsTypeAheadFind : public nsITypeAheadFind,
    1.31 +                        public nsIObserver,
    1.32 +                        public nsSupportsWeakReference
    1.33 +{
    1.34 +public:
    1.35 +  nsTypeAheadFind();
    1.36 +  virtual ~nsTypeAheadFind();
    1.37 +
    1.38 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.39 +  NS_DECL_NSITYPEAHEADFIND
    1.40 +  NS_DECL_NSIOBSERVER
    1.41 +
    1.42 +  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTypeAheadFind, nsITypeAheadFind)
    1.43 +
    1.44 +protected:
    1.45 +  nsresult PrefsReset();
    1.46 +
    1.47 +  void SaveFind();
    1.48 +  void PlayNotFoundSound(); 
    1.49 +  nsresult GetWebBrowserFind(nsIDocShell *aDocShell,
    1.50 +                             nsIWebBrowserFind **aWebBrowserFind);
    1.51 +
    1.52 +  void RangeStartsInsideLink(nsIDOMRange *aRange, nsIPresShell *aPresShell, 
    1.53 +                             bool *aIsInsideLink, bool *aIsStartingLink);
    1.54 +
    1.55 +  void GetSelection(nsIPresShell *aPresShell, nsISelectionController **aSelCon, 
    1.56 +                    nsISelection **aDomSel);
    1.57 +  // *aNewRange may not be collapsed.  If you want to collapse it in a
    1.58 +  // particular way, you need to do it yourself.
    1.59 +  bool IsRangeVisible(nsIPresShell *aPresShell, nsPresContext *aPresContext,
    1.60 +                        nsIDOMRange *aRange, bool aMustBeVisible, 
    1.61 +                        bool aGetTopVisibleLeaf, nsIDOMRange **aNewRange,
    1.62 +                        bool *aUsesIndependentSelection);
    1.63 +  nsresult FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly,
    1.64 +                     bool aIsFirstVisiblePreferred, bool aFindPrev,
    1.65 +                     uint16_t* aResult);
    1.66 +  nsresult GetSearchContainers(nsISupports *aContainer,
    1.67 +                               nsISelectionController *aSelectionController,
    1.68 +                               bool aIsFirstVisiblePreferred,
    1.69 +                               bool aFindPrev, nsIPresShell **aPresShell,
    1.70 +                               nsPresContext **aPresContext);
    1.71 +
    1.72 +  // Get the pres shell from mPresShell and return it only if it is still
    1.73 +  // attached to the DOM window.
    1.74 +  NS_HIDDEN_(already_AddRefed<nsIPresShell>) GetPresShell();
    1.75 +
    1.76 +  // Current find state
    1.77 +  nsString mTypeAheadBuffer;
    1.78 +  nsCString mNotFoundSoundURL;
    1.79 +
    1.80 +  // PRBools are used instead of PRPackedBools because the address of the
    1.81 +  // boolean variable is getting passed into a method.
    1.82 +  bool mStartLinksOnlyPref;
    1.83 +  bool mCaretBrowsingOn;
    1.84 +  nsCOMPtr<nsIDOMElement> mFoundLink;     // Most recent elem found, if a link
    1.85 +  nsCOMPtr<nsIDOMElement> mFoundEditable; // Most recent elem found, if editable
    1.86 +  nsCOMPtr<nsIDOMWindow> mCurrentWindow;
    1.87 +  // mLastFindLength is the character length of the last find string.  It is used for
    1.88 +  // disabling the "not found" sound when using backspace or delete
    1.89 +  uint32_t mLastFindLength;
    1.90 +
    1.91 +  // Sound is played asynchronously on some platforms.
    1.92 +  // If we destroy mSoundInterface before sound has played, it won't play
    1.93 +  nsCOMPtr<nsISound> mSoundInterface;
    1.94 +  bool mIsSoundInitialized;
    1.95 +  
    1.96 +  // where selection was when user started the find
    1.97 +  nsCOMPtr<nsIDOMRange> mStartFindRange;
    1.98 +  nsCOMPtr<nsIDOMRange> mSearchRange;
    1.99 +  nsCOMPtr<nsIDOMRange> mStartPointRange;
   1.100 +  nsCOMPtr<nsIDOMRange> mEndPointRange;
   1.101 +
   1.102 +  // Cached useful interfaces
   1.103 +  nsCOMPtr<nsIFind> mFind;
   1.104 +
   1.105 +  bool mCaseSensitive;
   1.106 +
   1.107 +  bool EnsureFind() {
   1.108 +    if (mFind) {
   1.109 +      return true;
   1.110 +    }
   1.111 +
   1.112 +    mFind = do_CreateInstance("@mozilla.org/embedcomp/rangefind;1");
   1.113 +    if (!mFind) {
   1.114 +      return false;
   1.115 +    }
   1.116 +
   1.117 +    mFind->SetCaseSensitive(mCaseSensitive);
   1.118 +    mFind->SetWordBreaker(nullptr);
   1.119 +
   1.120 +    return true;
   1.121 +  }
   1.122 +
   1.123 +  nsCOMPtr<nsIWebBrowserFind> mWebBrowserFind;
   1.124 +
   1.125 +  // The focused content window that we're listening to and its cached objects
   1.126 +  nsWeakPtr mDocShell;
   1.127 +  nsWeakPtr mPresShell;
   1.128 +  nsWeakPtr mSelectionController;
   1.129 +                                          // Most recent match's controller
   1.130 +};

mercurial