Bug 1330561 - Check if a relevant field is already focused when attaching autocomplete. r=MattN

Differential Revision: https://phabricator.services.mozilla.com/D21267

--HG--
extra : rebase_source : 34ff0ae0b4572e80f5b7de1d03ee4646b87ed31b
extra : histedit_source : 4dd3e5a461b492c936aa22627be89242f8bf2a8a
This commit is contained in:
Jared Wein 2019-02-26 15:43:31 -05:00
parent 2d986f3a3a
commit c8923c1b00
2 changed files with 16 additions and 3 deletions

View File

@ -223,6 +223,12 @@ nsFormFillController::AttachToBrowser(nsIDocShell* aDocShell,
nsCOMPtr<nsPIDOMWindowOuter> window = GetWindowForDocShell(aDocShell);
AddWindowListeners(window);
nsFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIContent> focusedContent = fm->GetFocusedElement();
this->HandleFocus(HTMLInputElement::FromNodeOrNull(focusedContent));
}
return NS_OK;
}
@ -943,9 +949,8 @@ void nsFormFillController::MaybeStartControllingInput(
#endif
}
nsresult nsFormFillController::Focus(Event* aEvent) {
nsCOMPtr<nsIContent> input = do_QueryInterface(aEvent->GetComposedTarget());
MaybeStartControllingInput(HTMLInputElement::FromNodeOrNull(input));
nsresult nsFormFillController::HandleFocus(HTMLInputElement* aInput) {
MaybeStartControllingInput(aInput);
// Bail if we didn't start controlling the input.
if (!mFocusedInput) {
@ -981,6 +986,11 @@ nsresult nsFormFillController::Focus(Event* aEvent) {
return NS_OK;
}
nsresult nsFormFillController::Focus(Event* aEvent) {
nsCOMPtr<nsIContent> input = do_QueryInterface(aEvent->GetComposedTarget());
return this->HandleFocus(HTMLInputElement::FromNodeOrNull(input));
}
nsresult nsFormFillController::KeyDown(Event* aEvent) {
NS_ASSERTION(mController, "should have a controller!");
if (!mFocusedInput || !mController) {

View File

@ -73,6 +73,9 @@ class nsFormFillController final : public nsIFormFillController,
void StartControllingInput(mozilla::dom::HTMLInputElement* aInput);
void StopControllingInput();
nsresult HandleFocus(mozilla::dom::HTMLInputElement* aInput);
/**
* Checks that aElement is a type of element we want to fill, then calls
* StartControllingInput on it.