зеркало из https://github.com/mozilla/pjs.git
Bug 695014 - nsFormFillController shouldn't watch input elements withouth a list nor autocomplete. f=ehsan, r=bz,zpao,dolske
This commit is contained in:
Родитель
236a836e30
Коммит
e2e6d5823c
|
@ -144,6 +144,7 @@ class nsAutoScriptBlockerSuppressNodeRemoved;
|
|||
struct nsIntMargin;
|
||||
class nsPIDOMWindow;
|
||||
class nsIDocumentLoaderFactory;
|
||||
class nsIDOMHTMLInputElement;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -1848,6 +1849,17 @@ public:
|
|||
static nsresult Atob(const nsAString& aAsciiString,
|
||||
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:
|
||||
static bool InitializeEventTable();
|
||||
|
||||
|
|
|
@ -178,6 +178,7 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
|
|||
#include "nsICategoryManager.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsEventStateManager.h"
|
||||
#include "nsIDOMHTMLInputElement.h"
|
||||
|
||||
#ifdef IBMBIDI
|
||||
#include "nsIBidiKeyboard.h"
|
||||
|
@ -649,6 +650,27 @@ nsContentUtils::Atob(const nsAString& aAsciiBase64String,
|
|||
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
|
||||
* reference to it and this class has that one.
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
#include "nsIDOMNSEditableElement.h"
|
||||
#include "nsIDOMNSEvent.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS5(nsFormFillController,
|
||||
nsIFormFillController,
|
||||
|
@ -573,7 +574,8 @@ nsFormFillController::StartSearch(const nsAString &aSearchString, const nsAStrin
|
|||
getter_AddRefs(result));
|
||||
} else {
|
||||
nsCOMPtr<nsIAutoCompleteResult> formHistoryResult;
|
||||
if (!IsInputAutoCompleteOff()) {
|
||||
|
||||
if (mFocusedInput && nsContentUtils::IsAutocompleteEnabled(mFocusedInput)) {
|
||||
nsCOMPtr <nsIFormAutoComplete> formAutoComplete =
|
||||
do_GetService("@mozilla.org/satchel/form-autocomplete;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -759,8 +761,11 @@ nsFormFillController::Focus(nsIDOMEvent* aEvent)
|
|||
bool isReadOnly = false;
|
||||
input->GetReadOnly(&isReadOnly);
|
||||
|
||||
nsAutoString autocomplete;
|
||||
input->GetAttribute(NS_LITERAL_STRING("autocomplete"), autocomplete);
|
||||
bool autocomplete = nsContentUtils::IsAutocompleteEnabled(input);
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLElement> datalist;
|
||||
input->GetList(getter_AddRefs(datalist));
|
||||
bool hasList = datalist != nsnull;
|
||||
|
||||
PRInt32 dummy;
|
||||
bool isPwmgrInput = false;
|
||||
|
@ -768,39 +773,15 @@ nsFormFillController::Focus(nsIDOMEvent* aEvent)
|
|||
isPwmgrInput = true;
|
||||
|
||||
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(input);
|
||||
if (formControl && formControl->IsSingleLineTextControl(true) &&
|
||||
!isReadOnly || isPwmgrInput) {
|
||||
if (isPwmgrInput || (formControl &&
|
||||
formControl->IsSingleLineTextControl(PR_TRUE) &&
|
||||
(hasList || autocomplete) && !isReadOnly)) {
|
||||
StartControllingInput(input);
|
||||
}
|
||||
|
||||
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
|
||||
nsFormFillController::KeyPress(nsIDOMEvent* aEvent)
|
||||
{
|
||||
|
|
|
@ -104,7 +104,6 @@ protected:
|
|||
PRInt32& aEntry,
|
||||
void* aUserData);
|
||||
bool IsEventTrusted(nsIDOMEvent *aEvent);
|
||||
bool IsInputAutoCompleteOff();
|
||||
// members //////////////////////////////////////////
|
||||
|
||||
nsCOMPtr<nsIAutoCompleteController> mController;
|
||||
|
|
Загрузка…
Ссылка в новой задаче