Bug 695014 - nsFormFillController shouldn't watch input elements withouth a list nor autocomplete. f=ehsan, r=bz,zpao,dolske

This commit is contained in:
Mounir Lamouri 2011-11-20 19:02:47 +01:00
parent 8611390781
commit ba0b63566f
4 changed files with 46 additions and 32 deletions

View File

@ -144,6 +144,7 @@ class nsAutoScriptBlockerSuppressNodeRemoved;
struct nsIntMargin; struct nsIntMargin;
class nsPIDOMWindow; class nsPIDOMWindow;
class nsIDocumentLoaderFactory; class nsIDocumentLoaderFactory;
class nsIDOMHTMLInputElement;
namespace mozilla { namespace mozilla {
@ -1847,7 +1848,18 @@ public:
static nsresult Atob(const nsAString& aAsciiString, static nsresult Atob(const nsAString& aAsciiString,
nsAString& aBinaryData); nsAString& aBinaryData);
/**
* Returns whether the input element passed in parameter has the autocomplete
* functionnality enabled. It is taking into account the form owner.
* NOTE: the caller has to make sure autocomplete makes sense for the
* element's type.
*
* @param aInput the input element to check. NOTE: aInput can't be null.
* @return whether the input element has autocomplete enabled.
*/
static bool IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput);
private: private:
static bool InitializeEventTable(); static bool InitializeEventTable();

View File

@ -178,6 +178,7 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
#include "nsICategoryManager.h" #include "nsICategoryManager.h"
#include "nsIViewManager.h" #include "nsIViewManager.h"
#include "nsEventStateManager.h" #include "nsEventStateManager.h"
#include "nsIDOMHTMLInputElement.h"
#ifdef IBMBIDI #ifdef IBMBIDI
#include "nsIBidiKeyboard.h" #include "nsIBidiKeyboard.h"
@ -649,6 +650,27 @@ nsContentUtils::Atob(const nsAString& aAsciiBase64String,
return rv; return rv;
} }
bool
nsContentUtils::IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput)
{
NS_PRECONDITION(aInput, "aInput should not be null!");
nsAutoString autocomplete;
aInput->GetAutocomplete(autocomplete);
if (autocomplete.IsEmpty()) {
nsCOMPtr<nsIDOMHTMLFormElement> form;
aInput->GetForm(getter_AddRefs(form));
if (!form) {
return true;
}
form->GetAutocomplete(autocomplete);
}
return autocomplete.EqualsLiteral("on");
}
/** /**
* Access a cached parser service. Don't addref. We need only one * Access a cached parser service. Don't addref. We need only one
* reference to it and this class has that one. * reference to it and this class has that one.

View File

@ -71,6 +71,7 @@
#include "nsIDOMNSEditableElement.h" #include "nsIDOMNSEditableElement.h"
#include "nsIDOMNSEvent.h" #include "nsIDOMNSEvent.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "nsContentUtils.h"
NS_IMPL_ISUPPORTS5(nsFormFillController, NS_IMPL_ISUPPORTS5(nsFormFillController,
nsIFormFillController, nsIFormFillController,
@ -573,7 +574,8 @@ nsFormFillController::StartSearch(const nsAString &aSearchString, const nsAStrin
getter_AddRefs(result)); getter_AddRefs(result));
} else { } else {
nsCOMPtr<nsIAutoCompleteResult> formHistoryResult; nsCOMPtr<nsIAutoCompleteResult> formHistoryResult;
if (!IsInputAutoCompleteOff()) {
if (mFocusedInput && nsContentUtils::IsAutocompleteEnabled(mFocusedInput)) {
nsCOMPtr <nsIFormAutoComplete> formAutoComplete = nsCOMPtr <nsIFormAutoComplete> formAutoComplete =
do_GetService("@mozilla.org/satchel/form-autocomplete;1", &rv); do_GetService("@mozilla.org/satchel/form-autocomplete;1", &rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -759,8 +761,11 @@ nsFormFillController::Focus(nsIDOMEvent* aEvent)
bool isReadOnly = false; bool isReadOnly = false;
input->GetReadOnly(&isReadOnly); input->GetReadOnly(&isReadOnly);
nsAutoString autocomplete; bool autocomplete = nsContentUtils::IsAutocompleteEnabled(input);
input->GetAttribute(NS_LITERAL_STRING("autocomplete"), autocomplete);
nsCOMPtr<nsIDOMHTMLElement> datalist;
input->GetList(getter_AddRefs(datalist));
bool hasList = datalist != nsnull;
PRInt32 dummy; PRInt32 dummy;
bool isPwmgrInput = false; bool isPwmgrInput = false;
@ -768,39 +773,15 @@ nsFormFillController::Focus(nsIDOMEvent* aEvent)
isPwmgrInput = true; isPwmgrInput = true;
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(input); nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(input);
if (formControl && formControl->IsSingleLineTextControl(true) && if (isPwmgrInput || (formControl &&
!isReadOnly || isPwmgrInput) { formControl->IsSingleLineTextControl(PR_TRUE) &&
(hasList || autocomplete) && !isReadOnly)) {
StartControllingInput(input); StartControllingInput(input);
} }
return NS_OK; return NS_OK;
} }
bool
nsFormFillController::IsInputAutoCompleteOff()
{
bool autoCompleteOff = false;
if (mFocusedInput) {
nsAutoString autocomplete;
mFocusedInput->GetAttribute(NS_LITERAL_STRING("autocomplete"), autocomplete);
// Check the input for autocomplete="off", then the form
if (autocomplete.LowerCaseEqualsLiteral("off")) {
autoCompleteOff = true;
} else {
nsCOMPtr<nsIDOMHTMLFormElement> form;
mFocusedInput->GetForm(getter_AddRefs(form));
if (form)
form->GetAttribute(NS_LITERAL_STRING("autocomplete"), autocomplete);
autoCompleteOff = autocomplete.LowerCaseEqualsLiteral("off");
}
}
return autoCompleteOff;
}
nsresult nsresult
nsFormFillController::KeyPress(nsIDOMEvent* aEvent) nsFormFillController::KeyPress(nsIDOMEvent* aEvent)
{ {

View File

@ -104,7 +104,6 @@ protected:
PRInt32& aEntry, PRInt32& aEntry,
void* aUserData); void* aUserData);
bool IsEventTrusted(nsIDOMEvent *aEvent); bool IsEventTrusted(nsIDOMEvent *aEvent);
bool IsInputAutoCompleteOff();
// members ////////////////////////////////////////// // members //////////////////////////////////////////
nsCOMPtr<nsIAutoCompleteController> mController; nsCOMPtr<nsIAutoCompleteController> mController;