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