Line data Source code
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 "nsIDOMHTMLInputElement.h"
20 : #include "nsILoginManager.h"
21 : #include "nsIMutationObserver.h"
22 : #include "nsTArray.h"
23 : #include "nsCycleCollectionParticipant.h"
24 :
25 : // X.h defines KeyPress
26 : #ifdef KeyPress
27 : #undef KeyPress
28 : #endif
29 :
30 : class nsFormHistory;
31 : class nsINode;
32 : class nsPIDOMWindowOuter;
33 :
34 : class nsFormFillController final : public nsIFormFillController,
35 : public nsIAutoCompleteInput,
36 : public nsIAutoCompleteSearch,
37 : public nsIDOMEventListener,
38 : public nsIFormAutoCompleteObserver,
39 : public nsIMutationObserver
40 : {
41 : public:
42 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
43 : NS_DECL_NSIFORMFILLCONTROLLER
44 : NS_DECL_NSIAUTOCOMPLETESEARCH
45 : NS_DECL_NSIAUTOCOMPLETEINPUT
46 : NS_DECL_NSIFORMAUTOCOMPLETEOBSERVER
47 : NS_DECL_NSIDOMEVENTLISTENER
48 : NS_DECL_NSIMUTATIONOBSERVER
49 :
50 63 : NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsFormFillController, nsIFormFillController)
51 :
52 : nsresult Focus(nsIDOMEvent* aEvent);
53 : nsresult KeyPress(nsIDOMEvent* aKeyEvent);
54 : nsresult MouseDown(nsIDOMEvent* aMouseEvent);
55 :
56 : nsFormFillController();
57 :
58 : protected:
59 : virtual ~nsFormFillController();
60 :
61 : void AddWindowListeners(nsPIDOMWindowOuter* aWindow);
62 : void RemoveWindowListeners(nsPIDOMWindowOuter* aWindow);
63 :
64 : void AddKeyListener(nsINode* aInput);
65 : void RemoveKeyListener();
66 :
67 : void StartControllingInput(nsIDOMHTMLInputElement *aInput);
68 : void StopControllingInput();
69 : /**
70 : * Checks that aElement is a type of element we want to fill, then calls
71 : * StartControllingInput on it.
72 : */
73 : void MaybeStartControllingInput(nsIDOMHTMLInputElement* aElement);
74 :
75 : nsresult PerformInputListAutoComplete(const nsAString& aSearch,
76 : nsIAutoCompleteResult** aResult);
77 :
78 : void RevalidateDataList();
79 : bool RowMatch(nsFormHistory *aHistory, uint32_t aIndex, const nsAString &aInputName, const nsAString &aInputValue);
80 :
81 : inline nsIDocShell *GetDocShellForInput(nsIDOMHTMLInputElement *aInput);
82 : inline nsPIDOMWindowOuter *GetWindowForDocShell(nsIDocShell *aDocShell);
83 : inline int32_t GetIndexOfDocShell(nsIDocShell *aDocShell);
84 :
85 : void MaybeRemoveMutationObserver(nsINode* aNode);
86 :
87 : void RemoveForDocument(nsIDocument* aDoc);
88 : bool IsEventTrusted(nsIDOMEvent *aEvent);
89 :
90 : bool IsTextControl(nsINode* aNode);
91 :
92 : // members //////////////////////////////////////////
93 :
94 : nsCOMPtr<nsIAutoCompleteController> mController;
95 : nsCOMPtr<nsILoginManager> mLoginManager;
96 : nsIDOMHTMLInputElement* mFocusedInput;
97 : nsINode* mFocusedInputNode;
98 :
99 : // mListNode is a <datalist> element which, is set, has the form fill controller
100 : // as a mutation observer for it.
101 : nsINode* mListNode;
102 : nsCOMPtr<nsIAutoCompletePopup> mFocusedPopup;
103 :
104 : nsTArray<nsCOMPtr<nsIDocShell> > mDocShells;
105 : nsTArray<nsCOMPtr<nsIAutoCompletePopup> > mPopups;
106 :
107 : // The observer passed to StartSearch. It will be notified when the search is
108 : // complete or the data from a datalist changes.
109 : nsCOMPtr<nsIAutoCompleteObserver> mLastListener;
110 :
111 : // This is cleared by StopSearch().
112 : nsCOMPtr<nsIFormAutoComplete> mLastFormAutoComplete;
113 : nsString mLastSearchString;
114 :
115 : nsDataHashtable<nsPtrHashKey<const nsINode>, bool> mPwmgrInputs;
116 : nsDataHashtable<nsPtrHashKey<const nsINode>, bool> mAutofillInputs;
117 :
118 : uint16_t mFocusAfterRightClickThreshold;
119 : uint32_t mTimeout;
120 : uint32_t mMinResultsForPopup;
121 : uint32_t mMaxRows;
122 : mozilla::TimeStamp mLastRightClickTimeStamp;
123 : bool mDisableAutoComplete;
124 : bool mCompleteDefaultIndex;
125 : bool mCompleteSelectedIndex;
126 : bool mForceComplete;
127 : bool mSuppressOnInput;
128 : };
129 :
130 : #endif // __nsFormFillController__
|