|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef __nsFormFillController__ |
|
7 #define __nsFormFillController__ |
|
8 |
|
9 #include "nsIFormFillController.h" |
|
10 #include "nsIAutoCompleteInput.h" |
|
11 #include "nsIAutoCompleteSearch.h" |
|
12 #include "nsIAutoCompleteController.h" |
|
13 #include "nsIAutoCompletePopup.h" |
|
14 #include "nsIFormAutoComplete.h" |
|
15 #include "nsIDOMEventListener.h" |
|
16 #include "nsCOMPtr.h" |
|
17 #include "nsDataHashtable.h" |
|
18 #include "nsIDocShell.h" |
|
19 #include "nsIDOMWindow.h" |
|
20 #include "nsIDOMHTMLInputElement.h" |
|
21 #include "nsILoginManager.h" |
|
22 #include "nsIMutationObserver.h" |
|
23 #include "nsTArray.h" |
|
24 |
|
25 // X.h defines KeyPress |
|
26 #ifdef KeyPress |
|
27 #undef KeyPress |
|
28 #endif |
|
29 |
|
30 class nsFormHistory; |
|
31 class nsINode; |
|
32 |
|
33 class nsFormFillController : public nsIFormFillController, |
|
34 public nsIAutoCompleteInput, |
|
35 public nsIAutoCompleteSearch, |
|
36 public nsIDOMEventListener, |
|
37 public nsIFormAutoCompleteObserver, |
|
38 public nsIMutationObserver |
|
39 { |
|
40 public: |
|
41 NS_DECL_ISUPPORTS |
|
42 NS_DECL_NSIFORMFILLCONTROLLER |
|
43 NS_DECL_NSIAUTOCOMPLETESEARCH |
|
44 NS_DECL_NSIAUTOCOMPLETEINPUT |
|
45 NS_DECL_NSIFORMAUTOCOMPLETEOBSERVER |
|
46 NS_DECL_NSIDOMEVENTLISTENER |
|
47 NS_DECL_NSIMUTATIONOBSERVER |
|
48 |
|
49 nsresult Focus(nsIDOMEvent* aEvent); |
|
50 nsresult KeyPress(nsIDOMEvent* aKeyEvent); |
|
51 nsresult MouseDown(nsIDOMEvent* aMouseEvent); |
|
52 |
|
53 nsFormFillController(); |
|
54 virtual ~nsFormFillController(); |
|
55 |
|
56 protected: |
|
57 void AddWindowListeners(nsIDOMWindow *aWindow); |
|
58 void RemoveWindowListeners(nsIDOMWindow *aWindow); |
|
59 |
|
60 void AddKeyListener(nsINode* aInput); |
|
61 void RemoveKeyListener(); |
|
62 |
|
63 void StartControllingInput(nsIDOMHTMLInputElement *aInput); |
|
64 void StopControllingInput(); |
|
65 |
|
66 nsresult PerformInputListAutoComplete(nsIAutoCompleteResult* aPreviousResult); |
|
67 |
|
68 void RevalidateDataList(); |
|
69 bool RowMatch(nsFormHistory *aHistory, uint32_t aIndex, const nsAString &aInputName, const nsAString &aInputValue); |
|
70 |
|
71 inline nsIDocShell *GetDocShellForInput(nsIDOMHTMLInputElement *aInput); |
|
72 inline nsIDOMWindow *GetWindowForDocShell(nsIDocShell *aDocShell); |
|
73 inline int32_t GetIndexOfDocShell(nsIDocShell *aDocShell); |
|
74 |
|
75 void MaybeRemoveMutationObserver(nsINode* aNode); |
|
76 |
|
77 static PLDHashOperator RemoveForDocumentEnumerator(const nsINode* aKey, |
|
78 bool& aEntry, |
|
79 void* aUserData); |
|
80 bool IsEventTrusted(nsIDOMEvent *aEvent); |
|
81 // members ////////////////////////////////////////// |
|
82 |
|
83 nsCOMPtr<nsIAutoCompleteController> mController; |
|
84 nsCOMPtr<nsILoginManager> mLoginManager; |
|
85 nsIDOMHTMLInputElement* mFocusedInput; |
|
86 nsINode* mFocusedInputNode; |
|
87 |
|
88 // mListNode is a <datalist> element which, is set, has the form fill controller |
|
89 // as a mutation observer for it. |
|
90 nsINode* mListNode; |
|
91 nsCOMPtr<nsIAutoCompletePopup> mFocusedPopup; |
|
92 |
|
93 nsTArray<nsCOMPtr<nsIDocShell> > mDocShells; |
|
94 nsTArray<nsCOMPtr<nsIAutoCompletePopup> > mPopups; |
|
95 |
|
96 //these are used to dynamically update the autocomplete |
|
97 nsCOMPtr<nsIAutoCompleteResult> mLastSearchResult; |
|
98 |
|
99 // The observer passed to StartSearch. It will be notified when the search is |
|
100 // complete or the data from a datalist changes. |
|
101 nsCOMPtr<nsIAutoCompleteObserver> mLastListener; |
|
102 |
|
103 // This is cleared by StopSearch(). |
|
104 nsCOMPtr<nsIFormAutoComplete> mLastFormAutoComplete; |
|
105 nsString mLastSearchString; |
|
106 |
|
107 nsDataHashtable<nsPtrHashKey<const nsINode>, bool> mPwmgrInputs; |
|
108 |
|
109 uint32_t mTimeout; |
|
110 uint32_t mMinResultsForPopup; |
|
111 uint32_t mMaxRows; |
|
112 bool mDisableAutoComplete; |
|
113 bool mCompleteDefaultIndex; |
|
114 bool mCompleteSelectedIndex; |
|
115 bool mForceComplete; |
|
116 bool mSuppressOnInput; |
|
117 }; |
|
118 |
|
119 #endif // __nsFormFillController__ |