1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/satchel/nsFormFillController.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef __nsFormFillController__ 1.10 +#define __nsFormFillController__ 1.11 + 1.12 +#include "nsIFormFillController.h" 1.13 +#include "nsIAutoCompleteInput.h" 1.14 +#include "nsIAutoCompleteSearch.h" 1.15 +#include "nsIAutoCompleteController.h" 1.16 +#include "nsIAutoCompletePopup.h" 1.17 +#include "nsIFormAutoComplete.h" 1.18 +#include "nsIDOMEventListener.h" 1.19 +#include "nsCOMPtr.h" 1.20 +#include "nsDataHashtable.h" 1.21 +#include "nsIDocShell.h" 1.22 +#include "nsIDOMWindow.h" 1.23 +#include "nsIDOMHTMLInputElement.h" 1.24 +#include "nsILoginManager.h" 1.25 +#include "nsIMutationObserver.h" 1.26 +#include "nsTArray.h" 1.27 + 1.28 +// X.h defines KeyPress 1.29 +#ifdef KeyPress 1.30 +#undef KeyPress 1.31 +#endif 1.32 + 1.33 +class nsFormHistory; 1.34 +class nsINode; 1.35 + 1.36 +class nsFormFillController : public nsIFormFillController, 1.37 + public nsIAutoCompleteInput, 1.38 + public nsIAutoCompleteSearch, 1.39 + public nsIDOMEventListener, 1.40 + public nsIFormAutoCompleteObserver, 1.41 + public nsIMutationObserver 1.42 +{ 1.43 +public: 1.44 + NS_DECL_ISUPPORTS 1.45 + NS_DECL_NSIFORMFILLCONTROLLER 1.46 + NS_DECL_NSIAUTOCOMPLETESEARCH 1.47 + NS_DECL_NSIAUTOCOMPLETEINPUT 1.48 + NS_DECL_NSIFORMAUTOCOMPLETEOBSERVER 1.49 + NS_DECL_NSIDOMEVENTLISTENER 1.50 + NS_DECL_NSIMUTATIONOBSERVER 1.51 + 1.52 + nsresult Focus(nsIDOMEvent* aEvent); 1.53 + nsresult KeyPress(nsIDOMEvent* aKeyEvent); 1.54 + nsresult MouseDown(nsIDOMEvent* aMouseEvent); 1.55 + 1.56 + nsFormFillController(); 1.57 + virtual ~nsFormFillController(); 1.58 + 1.59 +protected: 1.60 + void AddWindowListeners(nsIDOMWindow *aWindow); 1.61 + void RemoveWindowListeners(nsIDOMWindow *aWindow); 1.62 + 1.63 + void AddKeyListener(nsINode* aInput); 1.64 + void RemoveKeyListener(); 1.65 + 1.66 + void StartControllingInput(nsIDOMHTMLInputElement *aInput); 1.67 + void StopControllingInput(); 1.68 + 1.69 + nsresult PerformInputListAutoComplete(nsIAutoCompleteResult* aPreviousResult); 1.70 + 1.71 + void RevalidateDataList(); 1.72 + bool RowMatch(nsFormHistory *aHistory, uint32_t aIndex, const nsAString &aInputName, const nsAString &aInputValue); 1.73 + 1.74 + inline nsIDocShell *GetDocShellForInput(nsIDOMHTMLInputElement *aInput); 1.75 + inline nsIDOMWindow *GetWindowForDocShell(nsIDocShell *aDocShell); 1.76 + inline int32_t GetIndexOfDocShell(nsIDocShell *aDocShell); 1.77 + 1.78 + void MaybeRemoveMutationObserver(nsINode* aNode); 1.79 + 1.80 + static PLDHashOperator RemoveForDocumentEnumerator(const nsINode* aKey, 1.81 + bool& aEntry, 1.82 + void* aUserData); 1.83 + bool IsEventTrusted(nsIDOMEvent *aEvent); 1.84 + // members ////////////////////////////////////////// 1.85 + 1.86 + nsCOMPtr<nsIAutoCompleteController> mController; 1.87 + nsCOMPtr<nsILoginManager> mLoginManager; 1.88 + nsIDOMHTMLInputElement* mFocusedInput; 1.89 + nsINode* mFocusedInputNode; 1.90 + 1.91 + // mListNode is a <datalist> element which, is set, has the form fill controller 1.92 + // as a mutation observer for it. 1.93 + nsINode* mListNode; 1.94 + nsCOMPtr<nsIAutoCompletePopup> mFocusedPopup; 1.95 + 1.96 + nsTArray<nsCOMPtr<nsIDocShell> > mDocShells; 1.97 + nsTArray<nsCOMPtr<nsIAutoCompletePopup> > mPopups; 1.98 + 1.99 + //these are used to dynamically update the autocomplete 1.100 + nsCOMPtr<nsIAutoCompleteResult> mLastSearchResult; 1.101 + 1.102 + // The observer passed to StartSearch. It will be notified when the search is 1.103 + // complete or the data from a datalist changes. 1.104 + nsCOMPtr<nsIAutoCompleteObserver> mLastListener; 1.105 + 1.106 + // This is cleared by StopSearch(). 1.107 + nsCOMPtr<nsIFormAutoComplete> mLastFormAutoComplete; 1.108 + nsString mLastSearchString; 1.109 + 1.110 + nsDataHashtable<nsPtrHashKey<const nsINode>, bool> mPwmgrInputs; 1.111 + 1.112 + uint32_t mTimeout; 1.113 + uint32_t mMinResultsForPopup; 1.114 + uint32_t mMaxRows; 1.115 + bool mDisableAutoComplete; 1.116 + bool mCompleteDefaultIndex; 1.117 + bool mCompleteSelectedIndex; 1.118 + bool mForceComplete; 1.119 + bool mSuppressOnInput; 1.120 +}; 1.121 + 1.122 +#endif // __nsFormFillController__