toolkit/components/typeaheadfind/nsTypeAheadFind.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsCycleCollectionParticipant.h"
michael@0 7 #include "nsISelectionController.h"
michael@0 8 #include "nsIController.h"
michael@0 9 #include "nsIControllers.h"
michael@0 10 #include "nsIObserver.h"
michael@0 11 #include "nsUnicharUtils.h"
michael@0 12 #include "nsIFind.h"
michael@0 13 #include "nsIWebBrowserFind.h"
michael@0 14 #include "nsWeakReference.h"
michael@0 15 #include "nsISelection.h"
michael@0 16 #include "nsIDOMRange.h"
michael@0 17 #include "nsIDocShellTreeItem.h"
michael@0 18 #include "nsITypeAheadFind.h"
michael@0 19 #include "nsISound.h"
michael@0 20
michael@0 21 class nsIPresShell;
michael@0 22 class nsPresContext;
michael@0 23
michael@0 24 #define TYPEAHEADFIND_NOTFOUND_WAV_URL \
michael@0 25 "chrome://global/content/notfound.wav"
michael@0 26
michael@0 27 class nsTypeAheadFind : public nsITypeAheadFind,
michael@0 28 public nsIObserver,
michael@0 29 public nsSupportsWeakReference
michael@0 30 {
michael@0 31 public:
michael@0 32 nsTypeAheadFind();
michael@0 33 virtual ~nsTypeAheadFind();
michael@0 34
michael@0 35 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 36 NS_DECL_NSITYPEAHEADFIND
michael@0 37 NS_DECL_NSIOBSERVER
michael@0 38
michael@0 39 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTypeAheadFind, nsITypeAheadFind)
michael@0 40
michael@0 41 protected:
michael@0 42 nsresult PrefsReset();
michael@0 43
michael@0 44 void SaveFind();
michael@0 45 void PlayNotFoundSound();
michael@0 46 nsresult GetWebBrowserFind(nsIDocShell *aDocShell,
michael@0 47 nsIWebBrowserFind **aWebBrowserFind);
michael@0 48
michael@0 49 void RangeStartsInsideLink(nsIDOMRange *aRange, nsIPresShell *aPresShell,
michael@0 50 bool *aIsInsideLink, bool *aIsStartingLink);
michael@0 51
michael@0 52 void GetSelection(nsIPresShell *aPresShell, nsISelectionController **aSelCon,
michael@0 53 nsISelection **aDomSel);
michael@0 54 // *aNewRange may not be collapsed. If you want to collapse it in a
michael@0 55 // particular way, you need to do it yourself.
michael@0 56 bool IsRangeVisible(nsIPresShell *aPresShell, nsPresContext *aPresContext,
michael@0 57 nsIDOMRange *aRange, bool aMustBeVisible,
michael@0 58 bool aGetTopVisibleLeaf, nsIDOMRange **aNewRange,
michael@0 59 bool *aUsesIndependentSelection);
michael@0 60 nsresult FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly,
michael@0 61 bool aIsFirstVisiblePreferred, bool aFindPrev,
michael@0 62 uint16_t* aResult);
michael@0 63 nsresult GetSearchContainers(nsISupports *aContainer,
michael@0 64 nsISelectionController *aSelectionController,
michael@0 65 bool aIsFirstVisiblePreferred,
michael@0 66 bool aFindPrev, nsIPresShell **aPresShell,
michael@0 67 nsPresContext **aPresContext);
michael@0 68
michael@0 69 // Get the pres shell from mPresShell and return it only if it is still
michael@0 70 // attached to the DOM window.
michael@0 71 NS_HIDDEN_(already_AddRefed<nsIPresShell>) GetPresShell();
michael@0 72
michael@0 73 // Current find state
michael@0 74 nsString mTypeAheadBuffer;
michael@0 75 nsCString mNotFoundSoundURL;
michael@0 76
michael@0 77 // PRBools are used instead of PRPackedBools because the address of the
michael@0 78 // boolean variable is getting passed into a method.
michael@0 79 bool mStartLinksOnlyPref;
michael@0 80 bool mCaretBrowsingOn;
michael@0 81 nsCOMPtr<nsIDOMElement> mFoundLink; // Most recent elem found, if a link
michael@0 82 nsCOMPtr<nsIDOMElement> mFoundEditable; // Most recent elem found, if editable
michael@0 83 nsCOMPtr<nsIDOMWindow> mCurrentWindow;
michael@0 84 // mLastFindLength is the character length of the last find string. It is used for
michael@0 85 // disabling the "not found" sound when using backspace or delete
michael@0 86 uint32_t mLastFindLength;
michael@0 87
michael@0 88 // Sound is played asynchronously on some platforms.
michael@0 89 // If we destroy mSoundInterface before sound has played, it won't play
michael@0 90 nsCOMPtr<nsISound> mSoundInterface;
michael@0 91 bool mIsSoundInitialized;
michael@0 92
michael@0 93 // where selection was when user started the find
michael@0 94 nsCOMPtr<nsIDOMRange> mStartFindRange;
michael@0 95 nsCOMPtr<nsIDOMRange> mSearchRange;
michael@0 96 nsCOMPtr<nsIDOMRange> mStartPointRange;
michael@0 97 nsCOMPtr<nsIDOMRange> mEndPointRange;
michael@0 98
michael@0 99 // Cached useful interfaces
michael@0 100 nsCOMPtr<nsIFind> mFind;
michael@0 101
michael@0 102 bool mCaseSensitive;
michael@0 103
michael@0 104 bool EnsureFind() {
michael@0 105 if (mFind) {
michael@0 106 return true;
michael@0 107 }
michael@0 108
michael@0 109 mFind = do_CreateInstance("@mozilla.org/embedcomp/rangefind;1");
michael@0 110 if (!mFind) {
michael@0 111 return false;
michael@0 112 }
michael@0 113
michael@0 114 mFind->SetCaseSensitive(mCaseSensitive);
michael@0 115 mFind->SetWordBreaker(nullptr);
michael@0 116
michael@0 117 return true;
michael@0 118 }
michael@0 119
michael@0 120 nsCOMPtr<nsIWebBrowserFind> mWebBrowserFind;
michael@0 121
michael@0 122 // The focused content window that we're listening to and its cached objects
michael@0 123 nsWeakPtr mDocShell;
michael@0 124 nsWeakPtr mPresShell;
michael@0 125 nsWeakPtr mSelectionController;
michael@0 126 // Most recent match's controller
michael@0 127 };

mercurial