1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is Mozilla Communicator client code.
15 : *
16 : * The Initial Developer of the Original Code is
17 : * Netscape Communications Corporation.
18 : * Portions created by the Initial Developer are Copyright (C) 1998
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Joe Hewitt <hewitt@netscape.com> (Original Author)
23 : * Masayuki Nakano <masayuki@d-toybox.com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef __nsAutoCompleteController__
40 : #define __nsAutoCompleteController__
41 :
42 : #include "nsIAutoCompleteController.h"
43 :
44 : #include "nsIAutoCompleteInput.h"
45 : #include "nsIAutoCompletePopup.h"
46 : #include "nsIAutoCompleteResult.h"
47 : #include "nsIAutoCompleteSearch.h"
48 : #include "nsString.h"
49 : #include "nsITreeView.h"
50 : #include "nsITreeSelection.h"
51 : #include "nsITimer.h"
52 : #include "nsTArray.h"
53 : #include "nsCOMArray.h"
54 : #include "nsCycleCollectionParticipant.h"
55 :
56 : class nsAutoCompleteController : public nsIAutoCompleteController,
57 : public nsIAutoCompleteObserver,
58 : public nsITimerCallback,
59 : public nsITreeView
60 : {
61 : public:
62 36 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
63 5864 : NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsAutoCompleteController,
64 : nsIAutoCompleteController)
65 : NS_DECL_NSIAUTOCOMPLETECONTROLLER
66 : NS_DECL_NSIAUTOCOMPLETEOBSERVER
67 : NS_DECL_NSITREEVIEW
68 : NS_DECL_NSITIMERCALLBACK
69 :
70 : nsAutoCompleteController();
71 : virtual ~nsAutoCompleteController();
72 :
73 : protected:
74 : nsresult OpenPopup();
75 : nsresult ClosePopup();
76 :
77 : nsresult StartSearch(PRUint16 aSearchType);
78 :
79 : nsresult BeforeSearches();
80 : nsresult StartSearches();
81 : void AfterSearches();
82 : nsresult ClearSearchTimer();
83 :
84 : nsresult ProcessResult(PRInt32 aSearchIndex, nsIAutoCompleteResult *aResult);
85 : nsresult PostSearchCleanup();
86 :
87 : nsresult EnterMatch(bool aIsPopupSelection);
88 : nsresult RevertTextValue();
89 :
90 : nsresult CompleteDefaultIndex(PRInt32 aResultIndex);
91 : nsresult CompleteValue(nsString &aValue);
92 :
93 : nsresult GetResultAt(PRInt32 aIndex, nsIAutoCompleteResult** aResult,
94 : PRInt32* aRowIndex);
95 : nsresult GetResultValueAt(PRInt32 aIndex, bool aValueOnly,
96 : nsAString & _retval);
97 : nsresult GetResultLabelAt(PRInt32 aIndex, bool aValueOnly,
98 : nsAString & _retval);
99 : private:
100 : nsresult GetResultValueLabelAt(PRInt32 aIndex, bool aValueOnly,
101 : bool aGetValue, nsAString & _retval);
102 : protected:
103 : nsresult GetDefaultCompleteValue(PRInt32 aResultIndex, bool aPreserveCasing,
104 : nsAString &_retval);
105 : nsresult ClearResults();
106 :
107 : nsresult RowIndexToSearch(PRInt32 aRowIndex,
108 : PRInt32 *aSearchIndex, PRInt32 *aItemIndex);
109 :
110 : // members //////////////////////////////////////////
111 :
112 : nsCOMPtr<nsIAutoCompleteInput> mInput;
113 :
114 : nsCOMArray<nsIAutoCompleteSearch> mSearches;
115 : nsCOMArray<nsIAutoCompleteResult> mResults;
116 : // Caches the match counts for the current ongoing results to allow
117 : // incremental results to keep the rowcount up to date.
118 : nsTArray<PRUint32> mMatchCounts;
119 : // Temporarily keeps the results alive while invoking startSearch() for each
120 : // search. This is needed to allow the searches to reuse the previous result,
121 : // since otherwise the first search clears mResults.
122 : nsCOMArray<nsIAutoCompleteResult> mResultCache;
123 :
124 : nsCOMPtr<nsITimer> mTimer;
125 : nsCOMPtr<nsITreeSelection> mSelection;
126 : nsCOMPtr<nsITreeBoxObject> mTree;
127 :
128 : nsString mSearchString;
129 : bool mDefaultIndexCompleted;
130 : bool mBackspaced;
131 : bool mPopupClosedByCompositionStart;
132 : enum CompositionState {
133 : eCompositionState_None,
134 : eCompositionState_Composing,
135 : eCompositionState_Committing
136 : };
137 : CompositionState mCompositionState;
138 : PRUint16 mSearchStatus;
139 : PRUint32 mRowCount;
140 : PRUint32 mSearchesOngoing;
141 : PRUint32 mSearchesFailed;
142 : bool mFirstSearchResult;
143 : PRUint32 mImmediateSearchesCount;
144 : };
145 :
146 : #endif /* __nsAutoCompleteController__ */
|