toolkit/components/autocomplete/nsAutoCompleteController.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef __nsAutoCompleteController__
     6 #define __nsAutoCompleteController__
     8 #include "nsIAutoCompleteController.h"
    10 #include "nsCOMPtr.h"
    11 #include "nsIAutoCompleteInput.h"
    12 #include "nsIAutoCompletePopup.h"
    13 #include "nsIAutoCompleteResult.h"
    14 #include "nsIAutoCompleteSearch.h"
    15 #include "nsString.h"
    16 #include "nsITreeView.h"
    17 #include "nsITreeSelection.h"
    18 #include "nsITimer.h"
    19 #include "nsTArray.h"
    20 #include "nsCOMArray.h"
    21 #include "nsCycleCollectionParticipant.h"
    23 class nsAutoCompleteController : public nsIAutoCompleteController,
    24                                  public nsIAutoCompleteObserver,
    25                                  public nsITimerCallback,
    26                                  public nsITreeView
    27 {
    28 public:
    29   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    30   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsAutoCompleteController,
    31                                            nsIAutoCompleteController)
    32   NS_DECL_NSIAUTOCOMPLETECONTROLLER
    33   NS_DECL_NSIAUTOCOMPLETEOBSERVER
    34   NS_DECL_NSITREEVIEW
    35   NS_DECL_NSITIMERCALLBACK
    37   nsAutoCompleteController();
    38   virtual ~nsAutoCompleteController();
    40 protected:
    41   nsresult OpenPopup();
    42   nsresult ClosePopup();
    44   nsresult StartSearch(uint16_t aSearchType);
    46   nsresult BeforeSearches();
    47   nsresult StartSearches();
    48   void AfterSearches();
    49   nsresult ClearSearchTimer();
    51   nsresult ProcessResult(int32_t aSearchIndex, nsIAutoCompleteResult *aResult);
    52   nsresult PostSearchCleanup();
    54   nsresult EnterMatch(bool aIsPopupSelection);
    55   nsresult RevertTextValue();
    57   nsresult CompleteDefaultIndex(int32_t aResultIndex);
    58   nsresult CompleteValue(nsString &aValue);
    60   nsresult GetResultAt(int32_t aIndex, nsIAutoCompleteResult** aResult,
    61                        int32_t* aRowIndex);
    62   nsresult GetResultValueAt(int32_t aIndex, bool aGetFinalValue,
    63                             nsAString & _retval);
    64   nsresult GetResultLabelAt(int32_t aIndex, nsAString & _retval);
    65 private:
    66   nsresult GetResultValueLabelAt(int32_t aIndex, bool aGetFinalValue,
    67                                  bool aGetValue, nsAString & _retval);
    68 protected:
    70   /**
    71    * Gets and validates the defaultComplete result and the relative
    72    * defaultIndex value.
    73    *
    74    * @param aResultIndex
    75    *        Index of the defaultComplete result to be used.  Pass -1 to search
    76    *        for the first result providing a valid defaultIndex.
    77    * @param _result
    78    *        The found result.
    79    * @param _defaultIndex
    80    *        The defaultIndex relative to _result.
    81    */
    82   nsresult GetDefaultCompleteResult(int32_t aResultIndex,
    83                                     nsIAutoCompleteResult** _result,
    84                                     int32_t* _defaultIndex);
    86   /**
    87    * Gets the defaultComplete value to be suggested to the user.
    88    *
    89    * @param aResultIndex
    90    *        Index of the defaultComplete result to be used.
    91    * @param aPreserveCasing
    92    *        Whether user casing should be preserved.
    93    * @param _retval
    94    *        The value to be completed.
    95    */
    96   nsresult GetDefaultCompleteValue(int32_t aResultIndex, bool aPreserveCasing,
    97                                    nsAString &_retval);
    99   /**
   100    * Gets the defaultComplete value to be used when the user confirms the
   101    * current match.
   102    * The value is returned only if it case-insensitively matches the current
   103    * input text, otherwise the method returns NS_ERROR_FAILURE.
   104    * This happens because we don't want to replace text if the user backspaces
   105    * just before Enter.
   106    *
   107    * @param _retval
   108    *        The value to be completed.
   109    */
   110   nsresult GetFinalDefaultCompleteValue(nsAString &_retval);
   112   nsresult ClearResults();
   114   nsresult RowIndexToSearch(int32_t aRowIndex,
   115                             int32_t *aSearchIndex, int32_t *aItemIndex);
   117   // members //////////////////////////////////////////
   119   nsCOMPtr<nsIAutoCompleteInput> mInput;
   121   nsCOMArray<nsIAutoCompleteSearch> mSearches;
   122   nsCOMArray<nsIAutoCompleteResult> mResults;
   123   // Caches the match counts for the current ongoing results to allow
   124   // incremental results to keep the rowcount up to date.
   125   nsTArray<uint32_t> mMatchCounts;
   126   // Temporarily keeps the results alive while invoking startSearch() for each
   127   // search.  This is needed to allow the searches to reuse the previous result,
   128   // since otherwise the first search clears mResults.
   129   nsCOMArray<nsIAutoCompleteResult> mResultCache;
   131   nsCOMPtr<nsITimer> mTimer;
   132   nsCOMPtr<nsITreeSelection> mSelection;
   133   nsCOMPtr<nsITreeBoxObject> mTree;
   135   nsString mSearchString;
   136   bool mDefaultIndexCompleted;
   137   bool mBackspaced;
   138   bool mPopupClosedByCompositionStart;
   139   enum CompositionState {
   140     eCompositionState_None,
   141     eCompositionState_Composing,
   142     eCompositionState_Committing
   143   };
   144   CompositionState mCompositionState;
   145   uint16_t mSearchStatus;
   146   uint32_t mRowCount;
   147   uint32_t mSearchesOngoing;
   148   uint32_t mSearchesFailed;
   149   bool mFirstSearchResult;
   150   uint32_t mImmediateSearchesCount;
   151 };
   153 #endif /* __nsAutoCompleteController__ */

mercurial