Bug 452317 - FeedConverter.js: QueryInterface should throw NS_ERROR_NO_INTERFACE...
[wine-gecko.git] / toolkit / components / typeaheadfind / src / nsTypeAheadFind.h
blob0348f9c98e5666f1890d56b33e34fdf7ae9768a1
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
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.
15 * The Original Code is mozilla.org code.
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.
22 * Contributor(s):
23 * Aaron Leventhal (aaronl@netscape.com)
24 * Blake Ross (blake@cs.stanford.edu)
25 * Masayuki Nakano (masayuki@d-toybox.com)
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #include "nsISelectionController.h"
42 #include "nsIController.h"
43 #include "nsIControllers.h"
44 #include "nsIObserver.h"
45 #include "nsUnicharUtils.h"
46 #include "nsIFind.h"
47 #include "nsIWebBrowserFind.h"
48 #include "nsWeakReference.h"
49 #include "nsIPresShell.h"
50 #include "nsPresContext.h"
51 #include "nsISelection.h"
52 #include "nsIDOMRange.h"
53 #include "nsIDocShellTreeItem.h"
54 #include "nsITypeAheadFind.h"
55 #include "nsISound.h"
57 #define TYPEAHEADFIND_NOTFOUND_WAV_URL \
58 "chrome://global/content/notfound.wav"
60 class nsTypeAheadFind : public nsITypeAheadFind,
61 public nsIObserver,
62 public nsSupportsWeakReference
64 public:
65 nsTypeAheadFind();
66 virtual ~nsTypeAheadFind();
68 NS_DECL_ISUPPORTS
69 NS_DECL_NSITYPEAHEADFIND
70 NS_DECL_NSIOBSERVER
72 protected:
73 nsresult PrefsReset();
75 void SaveFind();
76 void PlayNotFoundSound();
77 nsresult GetWebBrowserFind(nsIDocShell *aDocShell,
78 nsIWebBrowserFind **aWebBrowserFind);
80 void RangeStartsInsideLink(nsIDOMRange *aRange, nsIPresShell *aPresShell,
81 PRBool *aIsInsideLink, PRBool *aIsStartingLink);
83 void GetSelection(nsIPresShell *aPresShell, nsISelectionController **aSelCon,
84 nsISelection **aDomSel);
85 PRBool IsRangeVisible(nsIPresShell *aPresShell, nsPresContext *aPresContext,
86 nsIDOMRange *aRange, PRBool aMustBeVisible,
87 PRBool aGetTopVisibleLeaf, nsIDOMRange **aNewRange,
88 PRBool *aUsesIndependentSelection);
89 nsresult FindItNow(nsIPresShell *aPresShell, PRBool aIsLinksOnly,
90 PRBool aIsFirstVisiblePreferred, PRBool aFindPrev,
91 PRUint16* aResult);
92 nsresult GetSearchContainers(nsISupports *aContainer,
93 nsISelectionController *aSelectionController,
94 PRBool aIsFirstVisiblePreferred,
95 PRBool aFindPrev, nsIPresShell **aPresShell,
96 nsPresContext **aPresContext);
98 // Get the pres shell from mPresShell and return it only if it is still
99 // attached to the DOM window.
100 NS_HIDDEN_(already_AddRefed<nsIPresShell>) GetPresShell();
102 // Current find state
103 nsString mTypeAheadBuffer;
104 nsCString mNotFoundSoundURL;
106 // PRBool's are used instead of PRPackedBool's where the address of the
107 // boolean variable is getting passed into a method. For example:
108 // GetBoolPref("accessibility.typeaheadfind.linksonly", &mLinksOnlyPref);
109 PRBool mLinksOnlyPref;
110 PRBool mStartLinksOnlyPref;
111 PRPackedBool mLinksOnly;
112 PRBool mCaretBrowsingOn;
113 nsCOMPtr<nsIDOMElement> mFoundLink; // Most recent elem found, if a link
114 nsCOMPtr<nsIDOMElement> mFoundEditable; // Most recent elem found, if editable
115 nsCOMPtr<nsIDOMWindow> mCurrentWindow;
116 // mLastFindLength is the character length of the last find string. It is used for
117 // disabling the "not found" sound when using backspace or delete
118 PRUint32 mLastFindLength;
120 // Sound is played asynchronously on some platforms.
121 // If we destroy mSoundInterface before sound has played, it won't play
122 nsCOMPtr<nsISound> mSoundInterface;
123 PRBool mIsSoundInitialized;
125 // where selection was when user started the find
126 nsCOMPtr<nsIDOMRange> mStartFindRange;
127 nsCOMPtr<nsIDOMRange> mSearchRange;
128 nsCOMPtr<nsIDOMRange> mStartPointRange;
129 nsCOMPtr<nsIDOMRange> mEndPointRange;
131 // Cached useful interfaces
132 nsCOMPtr<nsIFind> mFind;
133 nsCOMPtr<nsIWebBrowserFind> mWebBrowserFind;
135 // The focused content window that we're listening to and its cached objects
136 nsWeakPtr mDocShell;
137 nsWeakPtr mPresShell;
138 nsWeakPtr mSelectionController;
139 // Most recent match's controller