michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsISelectionController.h" michael@0: #include "nsIController.h" michael@0: #include "nsIControllers.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsUnicharUtils.h" michael@0: #include "nsIFind.h" michael@0: #include "nsIWebBrowserFind.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsISelection.h" michael@0: #include "nsIDOMRange.h" michael@0: #include "nsIDocShellTreeItem.h" michael@0: #include "nsITypeAheadFind.h" michael@0: #include "nsISound.h" michael@0: michael@0: class nsIPresShell; michael@0: class nsPresContext; michael@0: michael@0: #define TYPEAHEADFIND_NOTFOUND_WAV_URL \ michael@0: "chrome://global/content/notfound.wav" michael@0: michael@0: class nsTypeAheadFind : public nsITypeAheadFind, michael@0: public nsIObserver, michael@0: public nsSupportsWeakReference michael@0: { michael@0: public: michael@0: nsTypeAheadFind(); michael@0: virtual ~nsTypeAheadFind(); michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_NSITYPEAHEADFIND michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTypeAheadFind, nsITypeAheadFind) michael@0: michael@0: protected: michael@0: nsresult PrefsReset(); michael@0: michael@0: void SaveFind(); michael@0: void PlayNotFoundSound(); michael@0: nsresult GetWebBrowserFind(nsIDocShell *aDocShell, michael@0: nsIWebBrowserFind **aWebBrowserFind); michael@0: michael@0: void RangeStartsInsideLink(nsIDOMRange *aRange, nsIPresShell *aPresShell, michael@0: bool *aIsInsideLink, bool *aIsStartingLink); michael@0: michael@0: void GetSelection(nsIPresShell *aPresShell, nsISelectionController **aSelCon, michael@0: nsISelection **aDomSel); michael@0: // *aNewRange may not be collapsed. If you want to collapse it in a michael@0: // particular way, you need to do it yourself. michael@0: bool IsRangeVisible(nsIPresShell *aPresShell, nsPresContext *aPresContext, michael@0: nsIDOMRange *aRange, bool aMustBeVisible, michael@0: bool aGetTopVisibleLeaf, nsIDOMRange **aNewRange, michael@0: bool *aUsesIndependentSelection); michael@0: nsresult FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly, michael@0: bool aIsFirstVisiblePreferred, bool aFindPrev, michael@0: uint16_t* aResult); michael@0: nsresult GetSearchContainers(nsISupports *aContainer, michael@0: nsISelectionController *aSelectionController, michael@0: bool aIsFirstVisiblePreferred, michael@0: bool aFindPrev, nsIPresShell **aPresShell, michael@0: nsPresContext **aPresContext); michael@0: michael@0: // Get the pres shell from mPresShell and return it only if it is still michael@0: // attached to the DOM window. michael@0: NS_HIDDEN_(already_AddRefed) GetPresShell(); michael@0: michael@0: // Current find state michael@0: nsString mTypeAheadBuffer; michael@0: nsCString mNotFoundSoundURL; michael@0: michael@0: // PRBools are used instead of PRPackedBools because the address of the michael@0: // boolean variable is getting passed into a method. michael@0: bool mStartLinksOnlyPref; michael@0: bool mCaretBrowsingOn; michael@0: nsCOMPtr mFoundLink; // Most recent elem found, if a link michael@0: nsCOMPtr mFoundEditable; // Most recent elem found, if editable michael@0: nsCOMPtr mCurrentWindow; michael@0: // mLastFindLength is the character length of the last find string. It is used for michael@0: // disabling the "not found" sound when using backspace or delete michael@0: uint32_t mLastFindLength; michael@0: michael@0: // Sound is played asynchronously on some platforms. michael@0: // If we destroy mSoundInterface before sound has played, it won't play michael@0: nsCOMPtr mSoundInterface; michael@0: bool mIsSoundInitialized; michael@0: michael@0: // where selection was when user started the find michael@0: nsCOMPtr mStartFindRange; michael@0: nsCOMPtr mSearchRange; michael@0: nsCOMPtr mStartPointRange; michael@0: nsCOMPtr mEndPointRange; michael@0: michael@0: // Cached useful interfaces michael@0: nsCOMPtr mFind; michael@0: michael@0: bool mCaseSensitive; michael@0: michael@0: bool EnsureFind() { michael@0: if (mFind) { michael@0: return true; michael@0: } michael@0: michael@0: mFind = do_CreateInstance("@mozilla.org/embedcomp/rangefind;1"); michael@0: if (!mFind) { michael@0: return false; michael@0: } michael@0: michael@0: mFind->SetCaseSensitive(mCaseSensitive); michael@0: mFind->SetWordBreaker(nullptr); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: nsCOMPtr mWebBrowserFind; michael@0: michael@0: // The focused content window that we're listening to and its cached objects michael@0: nsWeakPtr mDocShell; michael@0: nsWeakPtr mPresShell; michael@0: nsWeakPtr mSelectionController; michael@0: // Most recent match's controller michael@0: };