toolkit/components/autocomplete/nsAutoCompleteController.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/autocomplete/nsAutoCompleteController.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,153 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef __nsAutoCompleteController__
     1.9 +#define __nsAutoCompleteController__
    1.10 +
    1.11 +#include "nsIAutoCompleteController.h"
    1.12 +
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsIAutoCompleteInput.h"
    1.15 +#include "nsIAutoCompletePopup.h"
    1.16 +#include "nsIAutoCompleteResult.h"
    1.17 +#include "nsIAutoCompleteSearch.h"
    1.18 +#include "nsString.h"
    1.19 +#include "nsITreeView.h"
    1.20 +#include "nsITreeSelection.h"
    1.21 +#include "nsITimer.h"
    1.22 +#include "nsTArray.h"
    1.23 +#include "nsCOMArray.h"
    1.24 +#include "nsCycleCollectionParticipant.h"
    1.25 +
    1.26 +class nsAutoCompleteController : public nsIAutoCompleteController,
    1.27 +                                 public nsIAutoCompleteObserver,
    1.28 +                                 public nsITimerCallback,
    1.29 +                                 public nsITreeView
    1.30 +{
    1.31 +public:
    1.32 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.33 +  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsAutoCompleteController,
    1.34 +                                           nsIAutoCompleteController)
    1.35 +  NS_DECL_NSIAUTOCOMPLETECONTROLLER
    1.36 +  NS_DECL_NSIAUTOCOMPLETEOBSERVER
    1.37 +  NS_DECL_NSITREEVIEW
    1.38 +  NS_DECL_NSITIMERCALLBACK
    1.39 +   
    1.40 +  nsAutoCompleteController();
    1.41 +  virtual ~nsAutoCompleteController();
    1.42 +  
    1.43 +protected:
    1.44 +  nsresult OpenPopup();
    1.45 +  nsresult ClosePopup();
    1.46 +
    1.47 +  nsresult StartSearch(uint16_t aSearchType);
    1.48 +
    1.49 +  nsresult BeforeSearches();
    1.50 +  nsresult StartSearches();
    1.51 +  void AfterSearches();
    1.52 +  nsresult ClearSearchTimer();
    1.53 +
    1.54 +  nsresult ProcessResult(int32_t aSearchIndex, nsIAutoCompleteResult *aResult);
    1.55 +  nsresult PostSearchCleanup();
    1.56 +
    1.57 +  nsresult EnterMatch(bool aIsPopupSelection);
    1.58 +  nsresult RevertTextValue();
    1.59 +
    1.60 +  nsresult CompleteDefaultIndex(int32_t aResultIndex);
    1.61 +  nsresult CompleteValue(nsString &aValue);
    1.62 +
    1.63 +  nsresult GetResultAt(int32_t aIndex, nsIAutoCompleteResult** aResult,
    1.64 +                       int32_t* aRowIndex);
    1.65 +  nsresult GetResultValueAt(int32_t aIndex, bool aGetFinalValue,
    1.66 +                            nsAString & _retval);
    1.67 +  nsresult GetResultLabelAt(int32_t aIndex, nsAString & _retval);
    1.68 +private:
    1.69 +  nsresult GetResultValueLabelAt(int32_t aIndex, bool aGetFinalValue,
    1.70 +                                 bool aGetValue, nsAString & _retval);
    1.71 +protected:
    1.72 +
    1.73 +  /**
    1.74 +   * Gets and validates the defaultComplete result and the relative
    1.75 +   * defaultIndex value.
    1.76 +   *
    1.77 +   * @param aResultIndex
    1.78 +   *        Index of the defaultComplete result to be used.  Pass -1 to search
    1.79 +   *        for the first result providing a valid defaultIndex.
    1.80 +   * @param _result
    1.81 +   *        The found result.
    1.82 +   * @param _defaultIndex
    1.83 +   *        The defaultIndex relative to _result.
    1.84 +   */
    1.85 +  nsresult GetDefaultCompleteResult(int32_t aResultIndex,
    1.86 +                                    nsIAutoCompleteResult** _result,
    1.87 +                                    int32_t* _defaultIndex);
    1.88 +
    1.89 +  /**
    1.90 +   * Gets the defaultComplete value to be suggested to the user.
    1.91 +   *
    1.92 +   * @param aResultIndex
    1.93 +   *        Index of the defaultComplete result to be used.
    1.94 +   * @param aPreserveCasing
    1.95 +   *        Whether user casing should be preserved.
    1.96 +   * @param _retval
    1.97 +   *        The value to be completed.
    1.98 +   */
    1.99 +  nsresult GetDefaultCompleteValue(int32_t aResultIndex, bool aPreserveCasing,
   1.100 +                                   nsAString &_retval);
   1.101 +
   1.102 +  /**
   1.103 +   * Gets the defaultComplete value to be used when the user confirms the
   1.104 +   * current match.
   1.105 +   * The value is returned only if it case-insensitively matches the current
   1.106 +   * input text, otherwise the method returns NS_ERROR_FAILURE.
   1.107 +   * This happens because we don't want to replace text if the user backspaces
   1.108 +   * just before Enter.
   1.109 +   *
   1.110 +   * @param _retval
   1.111 +   *        The value to be completed.
   1.112 +   */
   1.113 +  nsresult GetFinalDefaultCompleteValue(nsAString &_retval);
   1.114 +
   1.115 +  nsresult ClearResults();
   1.116 +  
   1.117 +  nsresult RowIndexToSearch(int32_t aRowIndex,
   1.118 +                            int32_t *aSearchIndex, int32_t *aItemIndex);
   1.119 +
   1.120 +  // members //////////////////////////////////////////
   1.121 +  
   1.122 +  nsCOMPtr<nsIAutoCompleteInput> mInput;
   1.123 +
   1.124 +  nsCOMArray<nsIAutoCompleteSearch> mSearches;
   1.125 +  nsCOMArray<nsIAutoCompleteResult> mResults;
   1.126 +  // Caches the match counts for the current ongoing results to allow
   1.127 +  // incremental results to keep the rowcount up to date.
   1.128 +  nsTArray<uint32_t> mMatchCounts;
   1.129 +  // Temporarily keeps the results alive while invoking startSearch() for each
   1.130 +  // search.  This is needed to allow the searches to reuse the previous result,
   1.131 +  // since otherwise the first search clears mResults.
   1.132 +  nsCOMArray<nsIAutoCompleteResult> mResultCache;
   1.133 +
   1.134 +  nsCOMPtr<nsITimer> mTimer;
   1.135 +  nsCOMPtr<nsITreeSelection> mSelection;
   1.136 +  nsCOMPtr<nsITreeBoxObject> mTree;
   1.137 +
   1.138 +  nsString mSearchString;
   1.139 +  bool mDefaultIndexCompleted;
   1.140 +  bool mBackspaced;
   1.141 +  bool mPopupClosedByCompositionStart;
   1.142 +  enum CompositionState {
   1.143 +    eCompositionState_None,
   1.144 +    eCompositionState_Composing,
   1.145 +    eCompositionState_Committing
   1.146 +  };
   1.147 +  CompositionState mCompositionState;
   1.148 +  uint16_t mSearchStatus;
   1.149 +  uint32_t mRowCount;
   1.150 +  uint32_t mSearchesOngoing;
   1.151 +  uint32_t mSearchesFailed;
   1.152 +  bool mFirstSearchResult;
   1.153 +  uint32_t mImmediateSearchesCount;
   1.154 +};
   1.155 +
   1.156 +#endif /* __nsAutoCompleteController__ */

mercurial