Back out bug 286933 due to various regressions.
authormozilla.mano@sent.com
Wed, 04 Apr 2007 12:55:04 -0700
changeset 345 1af208af3c64b2823a46eded6eb1f59ee903c70d
parent 344 5e4c256284a028bb15618516295eabed4c488489
child 346 25e959a8520b7a6761788a760ad0682518816136
push idunknown
push userunknown
push dateunknown
bugs286933
milestone1.9a4pre
Back out bug 286933 due to various regressions.
toolkit/components/satchel/src/nsFormFillController.cpp
toolkit/components/satchel/src/nsFormFillController.h
--- a/toolkit/components/satchel/src/nsFormFillController.cpp
+++ b/toolkit/components/satchel/src/nsFormFillController.cpp
@@ -941,20 +941,16 @@ nsFormFillController::AddWindowListeners
 
   target->AddEventListener(NS_LITERAL_STRING("compositionend"),
                            NS_STATIC_CAST(nsIDOMCompositionListener *, this),
                            PR_TRUE);
 
   target->AddEventListener(NS_LITERAL_STRING("contextmenu"),
                            NS_STATIC_CAST(nsIDOMContextMenuListener *, this),
                            PR_TRUE);
-
-  target->AddEventListener(NS_LITERAL_STRING("keypress"),
-                           NS_STATIC_CAST(nsIDOMKeyListener *, this),
-                           PR_TRUE);
 }
 
 void
 nsFormFillController::RemoveWindowListeners(nsIDOMWindow *aWindow)
 {
   if (!aWindow)
     return;
 
@@ -1000,20 +996,42 @@ nsFormFillController::RemoveWindowListen
 
   target->RemoveEventListener(NS_LITERAL_STRING("compositionend"),
                               NS_STATIC_CAST(nsIDOMCompositionListener *, this),
                               PR_TRUE);
 
   target->RemoveEventListener(NS_LITERAL_STRING("contextmenu"),
                               NS_STATIC_CAST(nsIDOMContextMenuListener *, this),
                               PR_TRUE);
+}
 
-  target->RemoveEventListener(NS_LITERAL_STRING("keypress"),
-                              NS_STATIC_CAST(nsIDOMKeyListener *, this),
-                              PR_TRUE);
+void
+nsFormFillController::AddKeyListener(nsIDOMHTMLInputElement *aInput)
+{
+  if (!aInput)
+    return;
+
+    nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(aInput);
+
+    target->AddEventListener(NS_LITERAL_STRING("keypress"),
+                             NS_STATIC_CAST(nsIDOMKeyListener *, this),
+                             PR_TRUE);
+  }
+
+void
+nsFormFillController::RemoveKeyListener()
+{
+  if (!mFocusedInput)
+    return;
+
+    nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mFocusedInput);
+
+    target->RemoveEventListener(NS_LITERAL_STRING("keypress"),
+                                NS_STATIC_CAST(nsIDOMKeyListener *, this),
+                                PR_TRUE);
 }
 
 void
 nsFormFillController::StartControllingInput(nsIDOMHTMLInputElement *aInput)
 {
   // Make sure we're not still attached to an input
   StopControllingInput(); 
 
@@ -1021,25 +1039,28 @@ nsFormFillController::StartControllingIn
   nsCOMPtr<nsIDocShell> docShell = GetDocShellForInput(aInput);
   PRInt32 index = GetIndexOfDocShell(docShell);
   if (index < 0)
     return;
   
   // Cache the popup for the focused docShell
   mPopups->GetElementAt(index, getter_AddRefs(mFocusedPopup));
   
+  AddKeyListener(aInput);
   mFocusedInput = aInput;
 
   // Now we are the autocomplete controller's bitch
   mController->SetInput(this);
 }
 
 void
 nsFormFillController::StopControllingInput()
 {
+  RemoveKeyListener();
+
   // Reset the controller's input, but not if it has been switched
   // to another input already, which might happen if the user switches
   // focus by clicking another autocomplete textbox
   nsCOMPtr<nsIAutoCompleteInput> input;
   mController->GetInput(getter_AddRefs(input));
   if (input == this)
     mController->SetInput(nsnull);
 
--- a/toolkit/components/satchel/src/nsFormFillController.h
+++ b/toolkit/components/satchel/src/nsFormFillController.h
@@ -121,16 +121,19 @@ public:
 
   nsFormFillController();
   virtual ~nsFormFillController();
 
 protected:
   void AddWindowListeners(nsIDOMWindow *aWindow);
   void RemoveWindowListeners(nsIDOMWindow *aWindow);
   
+  void AddKeyListener(nsIDOMHTMLInputElement *aInput);
+  void RemoveKeyListener();
+  
   void StartControllingInput(nsIDOMHTMLInputElement *aInput);
   void StopControllingInput();
   
   PRBool RowMatch(nsFormHistory *aHistory, PRUint32 aIndex, const nsAString &aInputName, const nsAString &aInputValue);
   
   inline nsIDocShell *GetDocShellForInput(nsIDOMHTMLInputElement *aInput);
   inline nsIDOMWindow *GetWindowForDocShell(nsIDocShell *aDocShell);
   inline PRInt32 GetIndexOfDocShell(nsIDocShell *aDocShell);