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: #ifndef __nsAutoCompleteController__ michael@0: #define __nsAutoCompleteController__ michael@0: michael@0: #include "nsIAutoCompleteController.h" michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIAutoCompleteInput.h" michael@0: #include "nsIAutoCompletePopup.h" michael@0: #include "nsIAutoCompleteResult.h" michael@0: #include "nsIAutoCompleteSearch.h" michael@0: #include "nsString.h" michael@0: #include "nsITreeView.h" michael@0: #include "nsITreeSelection.h" michael@0: #include "nsITimer.h" michael@0: #include "nsTArray.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: michael@0: class nsAutoCompleteController : public nsIAutoCompleteController, michael@0: public nsIAutoCompleteObserver, michael@0: public nsITimerCallback, michael@0: public nsITreeView michael@0: { michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsAutoCompleteController, michael@0: nsIAutoCompleteController) michael@0: NS_DECL_NSIAUTOCOMPLETECONTROLLER michael@0: NS_DECL_NSIAUTOCOMPLETEOBSERVER michael@0: NS_DECL_NSITREEVIEW michael@0: NS_DECL_NSITIMERCALLBACK michael@0: michael@0: nsAutoCompleteController(); michael@0: virtual ~nsAutoCompleteController(); michael@0: michael@0: protected: michael@0: nsresult OpenPopup(); michael@0: nsresult ClosePopup(); michael@0: michael@0: nsresult StartSearch(uint16_t aSearchType); michael@0: michael@0: nsresult BeforeSearches(); michael@0: nsresult StartSearches(); michael@0: void AfterSearches(); michael@0: nsresult ClearSearchTimer(); michael@0: michael@0: nsresult ProcessResult(int32_t aSearchIndex, nsIAutoCompleteResult *aResult); michael@0: nsresult PostSearchCleanup(); michael@0: michael@0: nsresult EnterMatch(bool aIsPopupSelection); michael@0: nsresult RevertTextValue(); michael@0: michael@0: nsresult CompleteDefaultIndex(int32_t aResultIndex); michael@0: nsresult CompleteValue(nsString &aValue); michael@0: michael@0: nsresult GetResultAt(int32_t aIndex, nsIAutoCompleteResult** aResult, michael@0: int32_t* aRowIndex); michael@0: nsresult GetResultValueAt(int32_t aIndex, bool aGetFinalValue, michael@0: nsAString & _retval); michael@0: nsresult GetResultLabelAt(int32_t aIndex, nsAString & _retval); michael@0: private: michael@0: nsresult GetResultValueLabelAt(int32_t aIndex, bool aGetFinalValue, michael@0: bool aGetValue, nsAString & _retval); michael@0: protected: michael@0: michael@0: /** michael@0: * Gets and validates the defaultComplete result and the relative michael@0: * defaultIndex value. michael@0: * michael@0: * @param aResultIndex michael@0: * Index of the defaultComplete result to be used. Pass -1 to search michael@0: * for the first result providing a valid defaultIndex. michael@0: * @param _result michael@0: * The found result. michael@0: * @param _defaultIndex michael@0: * The defaultIndex relative to _result. michael@0: */ michael@0: nsresult GetDefaultCompleteResult(int32_t aResultIndex, michael@0: nsIAutoCompleteResult** _result, michael@0: int32_t* _defaultIndex); michael@0: michael@0: /** michael@0: * Gets the defaultComplete value to be suggested to the user. michael@0: * michael@0: * @param aResultIndex michael@0: * Index of the defaultComplete result to be used. michael@0: * @param aPreserveCasing michael@0: * Whether user casing should be preserved. michael@0: * @param _retval michael@0: * The value to be completed. michael@0: */ michael@0: nsresult GetDefaultCompleteValue(int32_t aResultIndex, bool aPreserveCasing, michael@0: nsAString &_retval); michael@0: michael@0: /** michael@0: * Gets the defaultComplete value to be used when the user confirms the michael@0: * current match. michael@0: * The value is returned only if it case-insensitively matches the current michael@0: * input text, otherwise the method returns NS_ERROR_FAILURE. michael@0: * This happens because we don't want to replace text if the user backspaces michael@0: * just before Enter. michael@0: * michael@0: * @param _retval michael@0: * The value to be completed. michael@0: */ michael@0: nsresult GetFinalDefaultCompleteValue(nsAString &_retval); michael@0: michael@0: nsresult ClearResults(); michael@0: michael@0: nsresult RowIndexToSearch(int32_t aRowIndex, michael@0: int32_t *aSearchIndex, int32_t *aItemIndex); michael@0: michael@0: // members ////////////////////////////////////////// michael@0: michael@0: nsCOMPtr mInput; michael@0: michael@0: nsCOMArray mSearches; michael@0: nsCOMArray mResults; michael@0: // Caches the match counts for the current ongoing results to allow michael@0: // incremental results to keep the rowcount up to date. michael@0: nsTArray mMatchCounts; michael@0: // Temporarily keeps the results alive while invoking startSearch() for each michael@0: // search. This is needed to allow the searches to reuse the previous result, michael@0: // since otherwise the first search clears mResults. michael@0: nsCOMArray mResultCache; michael@0: michael@0: nsCOMPtr mTimer; michael@0: nsCOMPtr mSelection; michael@0: nsCOMPtr mTree; michael@0: michael@0: nsString mSearchString; michael@0: bool mDefaultIndexCompleted; michael@0: bool mBackspaced; michael@0: bool mPopupClosedByCompositionStart; michael@0: enum CompositionState { michael@0: eCompositionState_None, michael@0: eCompositionState_Composing, michael@0: eCompositionState_Committing michael@0: }; michael@0: CompositionState mCompositionState; michael@0: uint16_t mSearchStatus; michael@0: uint32_t mRowCount; michael@0: uint32_t mSearchesOngoing; michael@0: uint32_t mSearchesFailed; michael@0: bool mFirstSearchResult; michael@0: uint32_t mImmediateSearchesCount; michael@0: }; michael@0: michael@0: #endif /* __nsAutoCompleteController__ */