2015-11-25 03:53:46 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-09-28 04:38:20 +04:00
|
|
|
|
|
|
|
#include "nsFormFillController.h"
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2009-06-20 00:19:18 +04:00
|
|
|
#include "nsIFormAutoComplete.h"
|
2010-09-10 09:19:20 +04:00
|
|
|
#include "nsIInputListAutoComplete.h"
|
2006-01-26 22:17:04 +03:00
|
|
|
#include "nsIAutoCompleteSimpleResult.h"
|
2002-09-28 04:38:20 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2003-10-22 10:09:48 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2002-09-28 04:38:20 +04:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
2010-05-12 11:17:07 +04:00
|
|
|
#include "nsIFormControl.h"
|
2004-12-01 01:54:13 +03:00
|
|
|
#include "nsIDocument.h"
|
2002-09-28 04:38:20 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsRect.h"
|
2003-08-09 14:15:31 +04:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
2007-05-16 14:02:45 +04:00
|
|
|
#include "nsILoginManager.h"
|
2004-07-29 12:42:54 +04:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2010-06-10 22:11:40 +04:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
2006-01-25 23:23:24 +03:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2006-08-27 01:42:54 +04:00
|
|
|
#include "nsEmbedCID.h"
|
2007-10-02 20:56:07 +04:00
|
|
|
#include "nsIDOMNSEditableElement.h"
|
2011-11-20 22:02:47 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-10-08 06:21:07 +04:00
|
|
|
#include "nsILoadContext.h"
|
2014-11-22 17:39:05 +03:00
|
|
|
#include "nsIFrame.h"
|
2013-04-20 02:18:33 +04:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2014-09-10 06:45:50 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(nsFormFillController,
|
|
|
|
mController, mLoginManager, mFocusedPopup, mDocShells,
|
2015-05-28 19:55:46 +03:00
|
|
|
mPopups, mLastListener, mLastFormAutoComplete)
|
2014-09-10 06:45:50 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFormFillController)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIFormFillController)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFormFillController)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteInput)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteSearch)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFormAutoCompleteObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFormFillController)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFormFillController)
|
|
|
|
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
|
|
|
|
nsFormFillController::nsFormFillController() :
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocusedInput(nullptr),
|
|
|
|
mFocusedInputNode(nullptr),
|
|
|
|
mListNode(nullptr),
|
2002-09-28 04:38:20 +04:00
|
|
|
mTimeout(50),
|
|
|
|
mMinResultsForPopup(1),
|
2003-07-13 06:27:25 +04:00
|
|
|
mMaxRows(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisableAutoComplete(false),
|
|
|
|
mCompleteDefaultIndex(false),
|
|
|
|
mCompleteSelectedIndex(false),
|
|
|
|
mForceComplete(false),
|
|
|
|
mSuppressOnInput(false)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2006-01-01 02:34:46 +03:00
|
|
|
mController = do_GetService("@mozilla.org/autocomplete/controller;1");
|
2015-01-24 20:37:47 +03:00
|
|
|
MOZ_ASSERT(mController);
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFormFillController::~nsFormFillController()
|
|
|
|
{
|
2012-02-22 16:59:39 +04:00
|
|
|
if (mListNode) {
|
|
|
|
mListNode->RemoveMutationObserver(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mListNode = nullptr;
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
|
|
|
if (mFocusedInputNode) {
|
2012-02-28 03:31:23 +04:00
|
|
|
MaybeRemoveMutationObserver(mFocusedInputNode);
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocusedInputNode = nullptr;
|
|
|
|
mFocusedInput = nullptr;
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
2015-11-25 03:53:46 +03:00
|
|
|
RemoveForDocument(nullptr);
|
2012-02-28 03:31:23 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Remove ourselves as a focus listener from all cached docShells
|
2012-12-11 01:54:32 +04:00
|
|
|
uint32_t count = mDocShells.Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2015-10-27 00:37:32 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = GetWindowForDocShell(mDocShells[i]);
|
|
|
|
RemoveWindowListeners(window);
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:20:16 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIMutationObserver
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
mozilla::dom::Element* aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNameSpaceID,
|
2015-07-25 09:01:19 +03:00
|
|
|
nsIAtom* aAttribute, int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue)
|
2010-09-10 09:20:16 +04:00
|
|
|
{
|
2015-01-24 20:37:47 +03:00
|
|
|
if ((aAttribute == nsGkAtoms::type || aAttribute == nsGkAtoms::readonly ||
|
|
|
|
aAttribute == nsGkAtoms::autocomplete) &&
|
|
|
|
aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> focusedInput(mFocusedInput);
|
|
|
|
// Reset the current state of the controller, unconditionally.
|
|
|
|
StopControllingInput();
|
|
|
|
// Then restart based on the new values. We have to delay this
|
|
|
|
// to avoid ending up in an endless loop due to re-registering our
|
|
|
|
// mutation observer (which would notify us again for *this* event).
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
NS_NewRunnableMethodWithArg<nsCOMPtr<nsIDOMHTMLInputElement>>
|
|
|
|
(this, &nsFormFillController::MaybeStartControllingInput, focusedInput);
|
|
|
|
NS_DispatchToCurrentThread(event);
|
|
|
|
}
|
|
|
|
|
2012-02-22 16:59:39 +04:00
|
|
|
if (mListNode && mListNode->Contains(aElement)) {
|
|
|
|
RevalidateDataList();
|
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndexInContainer)
|
2010-09-10 09:20:16 +04:00
|
|
|
{
|
2012-02-22 16:59:39 +04:00
|
|
|
if (mListNode && mListNode->Contains(aContainer)) {
|
|
|
|
RevalidateDataList();
|
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndexInContainer)
|
2010-09-10 09:20:16 +04:00
|
|
|
{
|
2012-02-22 16:59:39 +04:00
|
|
|
if (mListNode && mListNode->Contains(aContainer)) {
|
|
|
|
RevalidateDataList();
|
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndexInContainer,
|
2010-09-10 09:20:16 +04:00
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
2012-02-22 16:59:39 +04:00
|
|
|
if (mListNode && mListNode->Contains(aContainer)) {
|
|
|
|
RevalidateDataList();
|
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::CharacterDataWillChange(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::AttributeWillChange(nsIDocument* aDocument,
|
|
|
|
mozilla::dom::Element* aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNameSpaceID,
|
2015-07-25 09:05:19 +03:00
|
|
|
nsIAtom* aAttribute, int32_t aModType,
|
|
|
|
const nsAttrValue* aNewValue)
|
2010-09-10 09:20:16 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-24 18:23:32 +03:00
|
|
|
void
|
|
|
|
nsFormFillController::NativeAnonymousChildListChange(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
bool aIsRemove)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:20:16 +04:00
|
|
|
void
|
|
|
|
nsFormFillController::ParentChainChanged(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::NodeWillBeDestroyed(const nsINode* aNode)
|
|
|
|
{
|
2012-02-22 16:59:39 +04:00
|
|
|
mPwmgrInputs.Remove(aNode);
|
|
|
|
if (aNode == mListNode) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mListNode = nullptr;
|
2012-02-22 16:59:39 +04:00
|
|
|
RevalidateDataList();
|
|
|
|
} else if (aNode == mFocusedInputNode) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocusedInputNode = nullptr;
|
|
|
|
mFocusedInput = nullptr;
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
2012-02-28 03:31:23 +04:00
|
|
|
void
|
|
|
|
nsFormFillController::MaybeRemoveMutationObserver(nsINode* aNode)
|
|
|
|
{
|
|
|
|
// Nodes being tracked in mPwmgrInputs will have their observers removed when
|
|
|
|
// they stop being tracked.
|
2015-05-28 19:55:46 +03:00
|
|
|
if (!mPwmgrInputs.Get(aNode)) {
|
2012-02-28 03:31:23 +04:00
|
|
|
aNode->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIFormFillController
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::AttachToBrowser(nsIDocShell *aDocShell, nsIAutoCompletePopup *aPopup)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aDocShell && aPopup, NS_ERROR_ILLEGAL_VALUE);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2012-12-11 01:54:32 +04:00
|
|
|
mDocShells.AppendElement(aDocShell);
|
|
|
|
mPopups.AppendElement(aPopup);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Listen for focus events on the domWindow of the docShell
|
2015-10-27 00:37:32 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = GetWindowForDocShell(aDocShell);
|
|
|
|
AddWindowListeners(window);
|
2002-09-28 04:38:20 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::DetachFromBrowser(nsIDocShell *aDocShell)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = GetIndexOfDocShell(aDocShell);
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_ENSURE_TRUE(index >= 0, NS_ERROR_FAILURE);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Stop listening for focus events on the domWindow of the docShell
|
2015-10-27 00:37:32 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window =
|
2012-12-11 01:54:32 +04:00
|
|
|
GetWindowForDocShell(mDocShells.SafeElementAt(index));
|
2015-10-27 00:37:32 +03:00
|
|
|
RemoveWindowListeners(window);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2012-12-11 01:54:32 +04:00
|
|
|
mDocShells.RemoveElementAt(index);
|
|
|
|
mPopups.RemoveElementAt(index);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-16 14:02:45 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::MarkAsLoginManagerField(nsIDOMHTMLInputElement *aInput)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The Login Manager can supply autocomplete results for username fields,
|
|
|
|
* when a user has multiple logins stored for a site. It uses this
|
|
|
|
* interface to indicate that the form manager shouldn't handle the
|
|
|
|
* autocomplete. The form manager also checks for this tag when saving
|
|
|
|
* form history (so it doesn't save usernames).
|
|
|
|
*/
|
2012-02-22 16:59:39 +04:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aInput);
|
|
|
|
NS_ENSURE_STATE(node);
|
|
|
|
mPwmgrInputs.Put(node, true);
|
|
|
|
node->AddMutationObserverUnlessExists(this);
|
2007-05-16 14:02:45 +04:00
|
|
|
|
2007-10-12 00:23:52 +04:00
|
|
|
if (!mLoginManager)
|
|
|
|
mLoginManager = do_GetService("@mozilla.org/login-manager;1");
|
|
|
|
|
2007-05-16 14:02:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIAutoCompleteInput
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetPopup(nsIAutoCompletePopup **aPopup)
|
|
|
|
{
|
|
|
|
*aPopup = mFocusedPopup;
|
|
|
|
NS_IF_ADDREF(*aPopup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-10-11 11:50:53 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetController(nsIAutoCompleteController **aController)
|
|
|
|
{
|
|
|
|
*aController = mController;
|
|
|
|
NS_IF_ADDREF(*aController);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetPopupOpen(bool *aPopupOpen)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
if (mFocusedPopup)
|
|
|
|
mFocusedPopup->GetPopupOpen(aPopupOpen);
|
2009-10-05 10:46:25 +04:00
|
|
|
else
|
2011-10-17 18:59:28 +04:00
|
|
|
*aPopupOpen = false;
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::SetPopupOpen(bool aPopupOpen)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2004-03-18 04:52:51 +03:00
|
|
|
if (mFocusedPopup) {
|
|
|
|
if (aPopupOpen) {
|
2006-07-18 04:32:24 +04:00
|
|
|
// make sure input field is visible before showing popup (bug 320938)
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mFocusedInput);
|
2006-09-09 01:19:58 +04:00
|
|
|
NS_ENSURE_STATE(content);
|
2006-07-18 04:32:24 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShellForInput(mFocusedInput);
|
2006-08-29 20:11:08 +04:00
|
|
|
NS_ENSURE_STATE(docShell);
|
2012-12-29 05:56:42 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
|
2006-08-29 20:11:08 +04:00
|
|
|
NS_ENSURE_STATE(presShell);
|
2007-03-06 12:53:56 +03:00
|
|
|
presShell->ScrollContentIntoView(content,
|
2012-09-13 06:53:28 +04:00
|
|
|
nsIPresShell::ScrollAxis(
|
|
|
|
nsIPresShell::SCROLL_MINIMUM,
|
|
|
|
nsIPresShell::SCROLL_IF_NOT_VISIBLE),
|
|
|
|
nsIPresShell::ScrollAxis(
|
|
|
|
nsIPresShell::SCROLL_MINIMUM,
|
|
|
|
nsIPresShell::SCROLL_IF_NOT_VISIBLE),
|
2010-10-28 20:01:37 +04:00
|
|
|
nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
|
2009-04-13 12:35:18 +04:00
|
|
|
// mFocusedPopup can be destroyed after ScrollContentIntoView, see bug 420089
|
2013-08-08 00:23:08 +04:00
|
|
|
if (mFocusedPopup) {
|
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mFocusedInput);
|
|
|
|
mFocusedPopup->OpenAutocompletePopup(this, element);
|
|
|
|
}
|
2004-03-18 04:52:51 +03:00
|
|
|
} else
|
|
|
|
mFocusedPopup->ClosePopup();
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
2006-06-19 23:55:33 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetDisableAutoComplete(bool *aDisableAutoComplete)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aDisableAutoComplete = mDisableAutoComplete;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::SetDisableAutoComplete(bool aDisableAutoComplete)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
mDisableAutoComplete = aDisableAutoComplete;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetCompleteDefaultIndex(bool *aCompleteDefaultIndex)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aCompleteDefaultIndex = mCompleteDefaultIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::SetCompleteDefaultIndex(bool aCompleteDefaultIndex)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
mCompleteDefaultIndex = aCompleteDefaultIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-18 15:40:00 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetCompleteSelectedIndex(bool *aCompleteSelectedIndex)
|
2005-02-18 15:40:00 +03:00
|
|
|
{
|
|
|
|
*aCompleteSelectedIndex = mCompleteSelectedIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::SetCompleteSelectedIndex(bool aCompleteSelectedIndex)
|
2005-02-18 15:40:00 +03:00
|
|
|
{
|
|
|
|
mCompleteSelectedIndex = aCompleteSelectedIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetForceComplete(bool *aForceComplete)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aForceComplete = mForceComplete;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsFormFillController::SetForceComplete(bool aForceComplete)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
mForceComplete = aForceComplete;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetMinResultsForPopup(uint32_t *aMinResultsForPopup)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aMinResultsForPopup = mMinResultsForPopup;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsFormFillController::SetMinResultsForPopup(uint32_t aMinResultsForPopup)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
mMinResultsForPopup = aMinResultsForPopup;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-07-13 06:27:25 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetMaxRows(uint32_t *aMaxRows)
|
2003-07-13 06:27:25 +04:00
|
|
|
{
|
|
|
|
*aMaxRows = mMaxRows;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::SetMaxRows(uint32_t aMaxRows)
|
2003-07-13 06:27:25 +04:00
|
|
|
{
|
|
|
|
mMaxRows = aMaxRows;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-11-06 11:43:53 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetShowImageColumn(bool *aShowImageColumn)
|
2007-11-06 11:43:53 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aShowImageColumn = false;
|
2007-11-06 11:43:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsFormFillController::SetShowImageColumn(bool aShowImageColumn)
|
2007-11-06 11:43:53 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 00:19:19 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetShowCommentColumn(bool *aShowCommentColumn)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aShowCommentColumn = false;
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsFormFillController::SetShowCommentColumn(bool aShowCommentColumn)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetTimeout(uint32_t *aTimeout)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aTimeout = mTimeout;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsFormFillController::SetTimeout(uint32_t aTimeout)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
mTimeout = aTimeout;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::SetSearchParam(const nsAString &aSearchParam)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetSearchParam(nsAString &aSearchParam)
|
|
|
|
{
|
2003-04-22 14:27:30 +04:00
|
|
|
if (!mFocusedInput) {
|
|
|
|
NS_WARNING("mFocusedInput is null for some reason! avoiding a crash. should find out why... - ben");
|
2011-08-04 04:52:47 +04:00
|
|
|
return NS_ERROR_FAILURE; // XXX why? fix me.
|
2003-04-22 14:27:30 +04:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
mFocusedInput->GetName(aSearchParam);
|
2013-08-08 00:23:08 +04:00
|
|
|
if (aSearchParam.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(mFocusedInput);
|
|
|
|
element->GetId(aSearchParam);
|
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetSearchCount(uint32_t *aSearchCount)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
*aSearchCount = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetSearchAt(uint32_t index, nsACString & _retval)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2014-05-22 07:48:51 +04:00
|
|
|
_retval.AssignLiteral("form-history");
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetTextValue(nsAString & aTextValue)
|
|
|
|
{
|
2006-09-18 12:23:32 +04:00
|
|
|
if (mFocusedInput) {
|
|
|
|
mFocusedInput->GetValue(aTextValue);
|
|
|
|
} else {
|
|
|
|
aTextValue.Truncate();
|
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::SetTextValue(const nsAString & aTextValue)
|
|
|
|
{
|
2007-10-02 20:56:07 +04:00
|
|
|
nsCOMPtr<nsIDOMNSEditableElement> editable = do_QueryInterface(mFocusedInput);
|
|
|
|
if (editable) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mSuppressOnInput = true;
|
2007-10-02 20:56:07 +04:00
|
|
|
editable->SetUserInput(aTextValue);
|
2011-10-17 18:59:28 +04:00
|
|
|
mSuppressOnInput = false;
|
2006-09-18 12:23:32 +04:00
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetSelectionStart(int32_t *aSelectionStart)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2010-08-05 06:40:18 +04:00
|
|
|
if (mFocusedInput)
|
|
|
|
mFocusedInput->GetSelectionStart(aSelectionStart);
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::GetSelectionEnd(int32_t *aSelectionEnd)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2010-08-05 06:40:18 +04:00
|
|
|
if (mFocusedInput)
|
|
|
|
mFocusedInput->GetSelectionEnd(aSelectionEnd);
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsFormFillController::SelectTextRange(int32_t aStartIndex, int32_t aEndIndex)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2010-08-05 06:40:18 +04:00
|
|
|
if (mFocusedInput)
|
2011-07-28 21:51:22 +04:00
|
|
|
mFocusedInput->SetSelectionRange(aStartIndex, aEndIndex, EmptyString());
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:17:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::OnSearchBegin()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::OnSearchComplete()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::OnTextEntered(bool* aPrevent)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2006-10-09 21:58:11 +04:00
|
|
|
NS_ENSURE_ARG(aPrevent);
|
|
|
|
NS_ENSURE_TRUE(mFocusedInput, NS_OK);
|
2003-08-04 04:57:26 +04:00
|
|
|
// Fire off a DOMAutoComplete event
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
2013-08-08 00:23:08 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mFocusedInput);
|
|
|
|
element->GetOwnerDocument(getter_AddRefs(domDoc));
|
2011-05-23 20:46:36 +04:00
|
|
|
NS_ENSURE_STATE(domDoc);
|
2003-08-04 04:57:26 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
2011-05-23 20:46:36 +04:00
|
|
|
domDoc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
|
2012-06-11 03:44:50 +04:00
|
|
|
NS_ENSURE_STATE(event);
|
2003-08-04 04:57:26 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
event->InitEvent(NS_LITERAL_STRING("DOMAutoComplete"), true, true);
|
2005-04-29 03:48:28 +04:00
|
|
|
|
2006-10-09 21:58:11 +04:00
|
|
|
// XXXjst: We mark this event as a trusted event, it's up to the
|
|
|
|
// callers of this to ensure that it's only called from trusted
|
|
|
|
// code.
|
2012-06-11 03:44:50 +04:00
|
|
|
event->SetTrusted(true);
|
2005-04-29 03:48:28 +04:00
|
|
|
|
2013-04-20 02:18:33 +04:00
|
|
|
nsCOMPtr<EventTarget> targ = do_QueryInterface(mFocusedInput);
|
2003-08-04 04:57:26 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool defaultActionEnabled;
|
2005-03-04 05:01:54 +03:00
|
|
|
targ->DispatchEvent(event, &defaultActionEnabled);
|
2006-10-09 21:58:11 +04:00
|
|
|
*aPrevent = !defaultActionEnabled;
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::OnTextReverted(bool *_retval)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-31 21:55:19 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFormFillController::GetConsumeRollupEvent(bool *aConsumeRollupEvent)
|
2006-05-31 21:55:19 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aConsumeRollupEvent = false;
|
2006-05-31 21:55:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-18 10:40:10 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetInPrivateContext(bool *aInPrivateContext)
|
|
|
|
{
|
|
|
|
if (!mFocusedInput) {
|
|
|
|
*aInPrivateContext = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> inputDoc;
|
2013-08-08 00:23:08 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mFocusedInput);
|
|
|
|
element->GetOwnerDocument(getter_AddRefs(inputDoc));
|
2012-02-18 10:40:10 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(inputDoc);
|
2013-11-15 20:32:12 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = doc->GetDocShell();
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = doc->GetLoadContext();
|
2012-02-18 10:40:10 +04:00
|
|
|
*aInPrivateContext = loadContext && loadContext->UsePrivateBrowsing();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-02 23:53:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::GetNoRollupOnCaretMove(bool *aNoRollupOnCaretMove)
|
|
|
|
{
|
|
|
|
*aNoRollupOnCaretMove = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-16 14:02:45 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIAutoCompleteSearch
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::StartSearch(const nsAString &aSearchString, const nsAString &aSearchParam,
|
|
|
|
nsIAutoCompleteResult *aPreviousResult, nsIAutoCompleteObserver *aListener)
|
|
|
|
{
|
2009-06-20 00:19:18 +04:00
|
|
|
nsresult rv;
|
2006-01-26 22:17:04 +03:00
|
|
|
|
2007-05-16 14:02:45 +04:00
|
|
|
// If the login manager has indicated it's responsible for this field, let it
|
|
|
|
// handle the autocomplete. Otherwise, handle with form history.
|
2015-05-28 19:55:46 +03:00
|
|
|
if (mPwmgrInputs.Get(mFocusedInputNode)) {
|
2007-05-16 14:02:45 +04:00
|
|
|
// XXX aPreviousResult shouldn't ever be a historyResult type, since we're not letting
|
|
|
|
// satchel manage the field?
|
2014-06-28 22:09:45 +04:00
|
|
|
mLastListener = aListener;
|
|
|
|
rv = mLoginManager->AutoCompleteSearchAsync(aSearchString,
|
|
|
|
aPreviousResult,
|
|
|
|
mFocusedInput,
|
|
|
|
this);
|
2013-04-20 02:21:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-16 14:02:45 +04:00
|
|
|
} else {
|
2013-04-20 02:21:30 +04:00
|
|
|
mLastListener = aListener;
|
2011-11-20 22:02:47 +04:00
|
|
|
|
2015-05-28 19:55:46 +03:00
|
|
|
nsCOMPtr<nsIAutoCompleteResult> datalistResult;
|
|
|
|
if (mFocusedInput) {
|
|
|
|
rv = PerformInputListAutoComplete(aSearchString,
|
|
|
|
getter_AddRefs(datalistResult));
|
2010-09-10 09:19:20 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2015-05-28 19:55:46 +03:00
|
|
|
|
|
|
|
nsCOMPtr <nsIFormAutoComplete> formAutoComplete =
|
|
|
|
do_GetService("@mozilla.org/satchel/form-autocomplete;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
formAutoComplete->AutoCompleteSearchAsync(aSearchParam,
|
|
|
|
aSearchString,
|
|
|
|
mFocusedInput,
|
|
|
|
aPreviousResult,
|
|
|
|
datalistResult,
|
|
|
|
this);
|
|
|
|
mLastFormAutoComplete = formAutoComplete;
|
2013-04-20 02:21:30 +04:00
|
|
|
}
|
2010-09-10 09:19:20 +04:00
|
|
|
|
2013-04-20 02:21:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-10 09:20:16 +04:00
|
|
|
|
2013-04-20 02:21:30 +04:00
|
|
|
nsresult
|
2015-05-28 19:55:46 +03:00
|
|
|
nsFormFillController::PerformInputListAutoComplete(const nsAString& aSearch,
|
|
|
|
nsIAutoCompleteResult** aResult)
|
2013-04-20 02:21:30 +04:00
|
|
|
{
|
|
|
|
// If an <input> is focused, check if it has a list="<datalist>" which can
|
|
|
|
// provide the list of suggestions.
|
2009-06-20 00:19:18 +04:00
|
|
|
|
2015-05-28 19:55:46 +03:00
|
|
|
MOZ_ASSERT(!mPwmgrInputs.Get(mFocusedInputNode));
|
2013-04-20 02:21:30 +04:00
|
|
|
nsresult rv;
|
2010-09-10 09:20:16 +04:00
|
|
|
|
2015-05-28 19:55:46 +03:00
|
|
|
nsCOMPtr <nsIInputListAutoComplete> inputListAutoComplete =
|
|
|
|
do_GetService("@mozilla.org/satchel/inputlist-autocomplete;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = inputListAutoComplete->AutoCompleteSearch(aSearch,
|
|
|
|
mFocusedInput,
|
|
|
|
aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-04-20 02:21:30 +04:00
|
|
|
|
2015-05-28 19:55:46 +03:00
|
|
|
if (mFocusedInput) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> list;
|
|
|
|
mFocusedInput->GetList(getter_AddRefs(list));
|
|
|
|
|
|
|
|
// Add a mutation observer to check for changes to the items in the <datalist>
|
|
|
|
// and update the suggestions accordingly.
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(list);
|
|
|
|
if (mListNode != node) {
|
|
|
|
if (mListNode) {
|
|
|
|
mListNode->RemoveMutationObserver(this);
|
|
|
|
mListNode = nullptr;
|
|
|
|
}
|
|
|
|
if (node) {
|
|
|
|
node->AddMutationObserverUnlessExists(this);
|
|
|
|
mListNode = node;
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
}
|
2013-04-20 02:21:30 +04:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-02-11 03:29:40 +03:00
|
|
|
class UpdateSearchResultRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UpdateSearchResultRunnable(nsIAutoCompleteObserver* aObserver,
|
|
|
|
nsIAutoCompleteSearch* aSearch,
|
|
|
|
nsIAutoCompleteResult* aResult)
|
|
|
|
: mObserver(aObserver)
|
|
|
|
, mSearch(aSearch)
|
|
|
|
, mResult(aResult)
|
2015-11-10 22:18:24 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mResult, "Should have a valid result");
|
|
|
|
MOZ_ASSERT(mObserver, "You shouldn't call this runnable with a null observer!");
|
|
|
|
}
|
2011-02-11 03:29:40 +03:00
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
mObserver->OnUpdateSearchResult(mSearch, mResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIAutoCompleteObserver> mObserver;
|
|
|
|
nsCOMPtr<nsIAutoCompleteSearch> mSearch;
|
|
|
|
nsCOMPtr<nsIAutoCompleteResult> mResult;
|
|
|
|
};
|
|
|
|
|
2010-09-10 09:20:16 +04:00
|
|
|
void nsFormFillController::RevalidateDataList()
|
|
|
|
{
|
2012-02-22 16:59:39 +04:00
|
|
|
if (!mLastListener) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-28 19:55:46 +03:00
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2015-05-28 19:55:46 +03:00
|
|
|
nsCOMPtr<nsIAutoCompleteController> controller(do_QueryInterface(mLastListener));
|
|
|
|
if (!controller) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
controller->StartSearch(mLastSearchString);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:20:16 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr <nsIInputListAutoComplete> inputListAutoComplete =
|
|
|
|
do_GetService("@mozilla.org/satchel/inputlist-autocomplete;1", &rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAutoCompleteResult> result;
|
|
|
|
|
2015-05-28 19:55:46 +03:00
|
|
|
rv = inputListAutoComplete->AutoCompleteSearch(mLastSearchString,
|
2010-09-10 09:20:16 +04:00
|
|
|
mFocusedInput,
|
|
|
|
getter_AddRefs(result));
|
2011-02-11 03:29:40 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
new UpdateSearchResultRunnable(mLastListener, this, result);
|
|
|
|
NS_DispatchToCurrentThread(event);
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::StopSearch()
|
|
|
|
{
|
2013-04-20 02:21:30 +04:00
|
|
|
// Make sure to stop and clear this, otherwise the controller will prevent
|
|
|
|
// mLastFormAutoComplete from being deleted.
|
|
|
|
if (mLastFormAutoComplete) {
|
|
|
|
mLastFormAutoComplete->StopAutoCompleteSearch();
|
|
|
|
mLastFormAutoComplete = nullptr;
|
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-20 02:21:30 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIFormAutoCompleteObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::OnSearchCompletion(nsIAutoCompleteResult *aResult)
|
|
|
|
{
|
|
|
|
nsAutoString searchString;
|
2015-05-28 19:55:46 +03:00
|
|
|
aResult->GetSearchString(searchString);
|
|
|
|
|
2013-04-20 02:21:30 +04:00
|
|
|
mLastSearchString = searchString;
|
|
|
|
|
2015-05-28 19:55:46 +03:00
|
|
|
if (mLastListener) {
|
|
|
|
mLastListener->OnSearchResult(this, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2013-04-20 02:21:30 +04:00
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIDOMEventListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFormFillController::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2007-05-16 14:02:45 +04:00
|
|
|
nsAutoString type;
|
|
|
|
aEvent->GetType(type);
|
|
|
|
|
2011-06-28 03:34:56 +04:00
|
|
|
if (type.EqualsLiteral("focus")) {
|
|
|
|
return Focus(aEvent);
|
|
|
|
}
|
|
|
|
if (type.EqualsLiteral("mousedown")) {
|
|
|
|
return MouseDown(aEvent);
|
|
|
|
}
|
|
|
|
if (type.EqualsLiteral("keypress")) {
|
|
|
|
return KeyPress(aEvent);
|
|
|
|
}
|
|
|
|
if (type.EqualsLiteral("input")) {
|
|
|
|
return (!mSuppressOnInput && mController && mFocusedInput) ?
|
|
|
|
mController->HandleText() : NS_OK;
|
|
|
|
}
|
|
|
|
if (type.EqualsLiteral("blur")) {
|
|
|
|
if (mFocusedInput)
|
|
|
|
StopControllingInput();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (type.EqualsLiteral("compositionstart")) {
|
|
|
|
NS_ASSERTION(mController, "should have a controller!");
|
|
|
|
if (mController && mFocusedInput)
|
|
|
|
mController->HandleStartComposition();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (type.EqualsLiteral("compositionend")) {
|
|
|
|
NS_ASSERTION(mController, "should have a controller!");
|
|
|
|
if (mController && mFocusedInput)
|
|
|
|
mController->HandleEndComposition();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (type.EqualsLiteral("contextmenu")) {
|
|
|
|
if (mFocusedPopup)
|
|
|
|
mFocusedPopup->ClosePopup();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-16 14:02:45 +04:00
|
|
|
if (type.EqualsLiteral("pagehide")) {
|
|
|
|
|
2013-04-20 02:18:33 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(
|
|
|
|
aEvent->InternalDOMEvent()->GetTarget());
|
|
|
|
if (!doc)
|
2007-05-16 14:02:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2008-02-27 08:06:13 +03:00
|
|
|
if (mFocusedInput) {
|
2013-04-20 02:18:33 +04:00
|
|
|
if (doc == mFocusedInputNode->OwnerDoc())
|
2008-02-27 08:06:13 +03:00
|
|
|
StopControllingInput();
|
|
|
|
}
|
|
|
|
|
2015-11-25 03:53:46 +03:00
|
|
|
RemoveForDocument(doc);
|
2007-05-16 14:02:45 +04:00
|
|
|
}
|
|
|
|
|
2011-08-04 04:52:47 +04:00
|
|
|
return NS_OK;
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 03:53:46 +03:00
|
|
|
void
|
|
|
|
nsFormFillController::RemoveForDocument(nsIDocument* aDoc)
|
|
|
|
{
|
|
|
|
for (auto iter = mPwmgrInputs.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
const nsINode* key = iter.Key();
|
|
|
|
if (key && (!aDoc || key->OwnerDoc() == aDoc)) {
|
|
|
|
// mFocusedInputNode's observer is tracked separately, so don't remove it
|
|
|
|
// here.
|
|
|
|
if (key != mFocusedInputNode) {
|
|
|
|
const_cast<nsINode*>(key)->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
iter.Remove();
|
2012-02-28 03:31:23 +04:00
|
|
|
}
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
2007-05-16 14:02:45 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
void
|
|
|
|
nsFormFillController::MaybeStartControllingInput(nsIDOMHTMLInputElement* aInput)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2015-01-24 20:37:47 +03:00
|
|
|
nsCOMPtr<nsINode> inputNode = do_QueryInterface(aInput);
|
2012-02-22 16:59:39 +04:00
|
|
|
if (!inputNode)
|
2015-01-24 20:37:47 +03:00
|
|
|
return;
|
2003-04-22 14:27:30 +04:00
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aInput);
|
2013-07-25 03:57:46 +04:00
|
|
|
if (!formControl || !formControl->IsSingleLineTextControl(true))
|
2015-01-24 20:37:47 +03:00
|
|
|
return;
|
2013-07-25 03:57:46 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isReadOnly = false;
|
2015-01-24 20:37:47 +03:00
|
|
|
aInput->GetReadOnly(&isReadOnly);
|
2013-07-25 03:57:45 +04:00
|
|
|
if (isReadOnly)
|
2015-01-24 20:37:47 +03:00
|
|
|
return;
|
2010-09-10 09:19:20 +04:00
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
bool autocomplete = nsContentUtils::IsAutocompleteEnabled(aInput);
|
2011-11-20 22:02:47 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> datalist;
|
2015-01-24 20:37:47 +03:00
|
|
|
aInput->GetList(getter_AddRefs(datalist));
|
2012-07-30 18:20:58 +04:00
|
|
|
bool hasList = datalist != nullptr;
|
2010-09-10 09:19:20 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isPwmgrInput = false;
|
2015-05-28 19:55:46 +03:00
|
|
|
if (mPwmgrInputs.Get(inputNode))
|
2011-10-17 18:59:28 +04:00
|
|
|
isPwmgrInput = true;
|
2010-09-10 09:19:20 +04:00
|
|
|
|
2013-07-25 03:57:46 +04:00
|
|
|
if (isPwmgrInput || hasList || autocomplete) {
|
2015-01-24 20:37:47 +03:00
|
|
|
StartControllingInput(aInput);
|
2010-09-10 09:19:20 +04:00
|
|
|
}
|
2015-01-24 20:37:47 +03:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
nsresult
|
|
|
|
nsFormFillController::Focus(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> input = do_QueryInterface(
|
|
|
|
aEvent->InternalDOMEvent()->GetTarget());
|
|
|
|
MaybeStartControllingInput(input);
|
2010-09-10 09:19:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-05-09 07:34:46 +04:00
|
|
|
|
2011-06-28 03:34:56 +04:00
|
|
|
nsresult
|
2002-09-28 04:38:20 +04:00
|
|
|
nsFormFillController::KeyPress(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2004-07-29 12:42:54 +04:00
|
|
|
NS_ASSERTION(mController, "should have a controller!");
|
|
|
|
if (!mFocusedInput || !mController)
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent);
|
2004-07-29 12:42:54 +04:00
|
|
|
if (!keyEvent)
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-10-22 12:45:54 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cancel = false;
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t k;
|
2003-07-13 06:31:08 +04:00
|
|
|
keyEvent->GetKeyCode(&k);
|
|
|
|
switch (k) {
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DELETE:
|
2006-04-06 02:57:48 +04:00
|
|
|
#ifndef XP_MACOSX
|
2006-02-01 00:16:11 +03:00
|
|
|
mController->HandleDelete(&cancel);
|
|
|
|
break;
|
2006-06-26 10:37:00 +04:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_BACK_SPACE:
|
2009-07-11 11:25:57 +04:00
|
|
|
mController->HandleText();
|
2006-06-26 10:37:00 +04:00
|
|
|
break;
|
2006-04-06 02:57:48 +04:00
|
|
|
#else
|
2006-06-26 10:37:00 +04:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_BACK_SPACE:
|
2006-04-06 02:57:48 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isShift = false;
|
2006-04-06 02:57:48 +04:00
|
|
|
keyEvent->GetShiftKey(&isShift);
|
|
|
|
|
2006-06-26 10:37:00 +04:00
|
|
|
if (isShift)
|
2006-04-06 02:57:48 +04:00
|
|
|
mController->HandleDelete(&cancel);
|
2006-06-26 10:37:00 +04:00
|
|
|
else
|
2009-07-11 11:25:57 +04:00
|
|
|
mController->HandleText();
|
2006-06-26 10:37:00 +04:00
|
|
|
|
|
|
|
break;
|
2006-04-06 02:57:48 +04:00
|
|
|
}
|
|
|
|
#endif
|
2007-12-18 12:16:42 +03:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_PAGE_UP:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_PAGE_DOWN:
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isCtrl, isAlt, isMeta;
|
2007-12-18 12:16:42 +03:00
|
|
|
keyEvent->GetCtrlKey(&isCtrl);
|
|
|
|
keyEvent->GetAltKey(&isAlt);
|
|
|
|
keyEvent->GetMetaKey(&isMeta);
|
|
|
|
if (isCtrl || isAlt || isMeta)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
2003-07-13 06:31:08 +04:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_UP:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DOWN:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_LEFT:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RIGHT:
|
2014-11-22 17:39:05 +03:00
|
|
|
{
|
|
|
|
// Get the writing-mode of the relevant input element,
|
|
|
|
// so that we can remap arrow keys if necessary.
|
|
|
|
mozilla::WritingMode wm;
|
|
|
|
if (mFocusedInputNode && mFocusedInputNode->IsElement()) {
|
|
|
|
mozilla::dom::Element *elem = mFocusedInputNode->AsElement();
|
|
|
|
nsIFrame *frame = elem->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
wm = frame->GetWritingMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wm.IsVertical()) {
|
|
|
|
switch (k) {
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_LEFT:
|
|
|
|
k = wm.IsVerticalLR() ? nsIDOMKeyEvent::DOM_VK_UP
|
|
|
|
: nsIDOMKeyEvent::DOM_VK_DOWN;
|
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RIGHT:
|
|
|
|
k = wm.IsVerticalLR() ? nsIDOMKeyEvent::DOM_VK_DOWN
|
|
|
|
: nsIDOMKeyEvent::DOM_VK_UP;
|
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_UP:
|
|
|
|
k = nsIDOMKeyEvent::DOM_VK_LEFT;
|
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DOWN:
|
|
|
|
k = nsIDOMKeyEvent::DOM_VK_RIGHT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-07 15:59:02 +03:00
|
|
|
mController->HandleKeyNavigation(k, &cancel);
|
2003-07-13 06:31:08 +04:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ESCAPE:
|
|
|
|
mController->HandleEscape(&cancel);
|
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_TAB:
|
|
|
|
mController->HandleTab();
|
2011-10-17 18:59:28 +04:00
|
|
|
cancel = false;
|
2003-07-13 06:31:08 +04:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RETURN:
|
2011-10-17 18:59:28 +04:00
|
|
|
mController->HandleEnter(false, &cancel);
|
2003-07-13 06:31:08 +04:00
|
|
|
break;
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
if (cancel) {
|
|
|
|
aEvent->PreventDefault();
|
2015-03-03 00:59:17 +03:00
|
|
|
// Don't let the page see the RETURN event when the popup is open
|
|
|
|
// (indicated by cancel=true) so sites don't manually submit forms
|
|
|
|
// (e.g. via submit.click()) without the autocompleted value being filled.
|
|
|
|
// Bug 286933 will fix this for other key events.
|
|
|
|
if (k == nsIDOMKeyEvent::DOM_VK_RETURN) {
|
|
|
|
aEvent->StopPropagation();
|
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-28 03:34:56 +04:00
|
|
|
nsresult
|
|
|
|
nsFormFillController::MouseDown(nsIDOMEvent* aEvent)
|
2003-07-13 06:31:08 +04:00
|
|
|
{
|
2011-06-28 03:34:56 +04:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aEvent));
|
2004-07-29 12:42:54 +04:00
|
|
|
if (!mouseEvent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2013-04-20 02:18:33 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> targetInput = do_QueryInterface(
|
|
|
|
aEvent->InternalDOMEvent()->GetTarget());
|
2007-10-02 18:50:51 +04:00
|
|
|
if (!targetInput)
|
|
|
|
return NS_OK;
|
|
|
|
|
2014-02-20 22:38:13 +04:00
|
|
|
int16_t button;
|
2004-07-29 12:42:54 +04:00
|
|
|
mouseEvent->GetButton(&button);
|
|
|
|
if (button != 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isOpen = false;
|
2004-07-29 12:42:54 +04:00
|
|
|
GetPopupOpen(&isOpen);
|
|
|
|
if (isOpen)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAutoCompleteInput> input;
|
|
|
|
mController->GetInput(getter_AddRefs(input));
|
|
|
|
if (!input)
|
2003-07-26 06:55:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2004-07-29 12:42:54 +04:00
|
|
|
nsAutoString value;
|
|
|
|
input->GetTextValue(value);
|
|
|
|
if (value.Length() > 0) {
|
|
|
|
// Show the popup with a filtered result set
|
2005-01-04 22:31:31 +03:00
|
|
|
mController->SetSearchString(EmptyString());
|
2009-07-11 11:25:57 +04:00
|
|
|
mController->HandleText();
|
2004-07-29 12:42:54 +04:00
|
|
|
} else {
|
|
|
|
// Show the popup with the complete result set. Can't use HandleText()
|
|
|
|
// because it doesn't display the popup if the input is blank.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cancel = false;
|
2006-12-07 15:59:02 +03:00
|
|
|
mController->HandleKeyNavigation(nsIDOMKeyEvent::DOM_VK_DOWN, &cancel);
|
2004-07-29 12:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2003-07-13 06:31:08 +04:00
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsFormFillController
|
|
|
|
|
|
|
|
void
|
2015-10-27 00:37:32 +03:00
|
|
|
nsFormFillController::AddWindowListeners(nsPIDOMWindow *aWindow)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
|
|
|
if (!aWindow)
|
|
|
|
return;
|
|
|
|
|
2015-10-27 00:37:32 +03:00
|
|
|
EventTarget* target = aWindow->GetChromeEventHandler();
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2004-07-29 12:42:54 +04:00
|
|
|
if (!target)
|
|
|
|
return;
|
|
|
|
|
2011-06-28 03:34:56 +04:00
|
|
|
target->AddEventListener(NS_LITERAL_STRING("focus"), this,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, false);
|
2011-06-28 03:34:56 +04:00
|
|
|
target->AddEventListener(NS_LITERAL_STRING("blur"), this,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, false);
|
2011-06-28 03:34:56 +04:00
|
|
|
target->AddEventListener(NS_LITERAL_STRING("pagehide"), this,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, false);
|
2011-06-28 03:34:56 +04:00
|
|
|
target->AddEventListener(NS_LITERAL_STRING("mousedown"), this,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, false);
|
2011-06-28 03:34:56 +04:00
|
|
|
target->AddEventListener(NS_LITERAL_STRING("input"), this,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, false);
|
2015-03-03 00:59:17 +03:00
|
|
|
target->AddEventListener(NS_LITERAL_STRING("keypress"), this, true, false);
|
2011-06-28 03:34:56 +04:00
|
|
|
target->AddEventListener(NS_LITERAL_STRING("compositionstart"), this,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, false);
|
2011-06-28 03:34:56 +04:00
|
|
|
target->AddEventListener(NS_LITERAL_STRING("compositionend"), this,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, false);
|
2011-06-28 03:34:56 +04:00
|
|
|
target->AddEventListener(NS_LITERAL_STRING("contextmenu"), this,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, false);
|
2009-09-23 10:23:08 +04:00
|
|
|
|
|
|
|
// Note that any additional listeners added should ensure that they ignore
|
|
|
|
// untrusted events, which might be sent by content that's up to no good.
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-27 00:37:32 +03:00
|
|
|
nsFormFillController::RemoveWindowListeners(nsPIDOMWindow *aWindow)
|
2002-09-28 04:38:20 +04:00
|
|
|
{
|
2002-10-02 23:59:08 +04:00
|
|
|
if (!aWindow)
|
|
|
|
return;
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
StopControllingInput();
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2015-10-27 00:37:32 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
|
2015-11-25 03:53:46 +03:00
|
|
|
RemoveForDocument(doc);
|
2008-02-27 08:06:13 +03:00
|
|
|
|
2015-10-27 00:37:32 +03:00
|
|
|
EventTarget* target = aWindow->GetChromeEventHandler();
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2004-07-29 12:42:54 +04:00
|
|
|
if (!target)
|
|
|
|
return;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("focus"), this, true);
|
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("blur"), this, true);
|
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("pagehide"), this, true);
|
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, true);
|
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("input"), this, true);
|
2015-03-03 00:59:17 +03:00
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("keypress"), this, true);
|
2011-06-28 03:34:56 +04:00
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("compositionstart"), this,
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2011-06-28 03:34:56 +04:00
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("compositionend"), this,
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
|
|
|
target->RemoveEventListener(NS_LITERAL_STRING("contextmenu"), this, true);
|
2007-04-04 23:55:04 +04:00
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::StartControllingInput(nsIDOMHTMLInputElement *aInput)
|
|
|
|
{
|
|
|
|
// Make sure we're not still attached to an input
|
2011-08-04 04:52:47 +04:00
|
|
|
StopControllingInput();
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
if (!mController) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Find the currently focused docShell
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShellForInput(aInput);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = GetIndexOfDocShell(docShell);
|
2002-09-28 04:38:20 +04:00
|
|
|
if (index < 0)
|
|
|
|
return;
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Cache the popup for the focused docShell
|
2012-12-11 01:54:32 +04:00
|
|
|
mFocusedPopup = mPopups.SafeElementAt(index);
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2012-02-22 16:59:39 +04:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aInput);
|
|
|
|
if (!node) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->AddMutationObserverUnlessExists(this);
|
|
|
|
mFocusedInputNode = node;
|
2004-07-29 12:42:54 +04:00
|
|
|
mFocusedInput = aInput;
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2012-02-22 16:59:39 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLElement> list;
|
|
|
|
mFocusedInput->GetList(getter_AddRefs(list));
|
|
|
|
nsCOMPtr<nsINode> listNode = do_QueryInterface(list);
|
|
|
|
if (listNode) {
|
|
|
|
listNode->AddMutationObserverUnlessExists(this);
|
|
|
|
mListNode = listNode;
|
|
|
|
}
|
|
|
|
|
2002-09-28 10:25:03 +04:00
|
|
|
mController->SetInput(this);
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormFillController::StopControllingInput()
|
|
|
|
{
|
2012-02-22 16:59:39 +04:00
|
|
|
if (mListNode) {
|
|
|
|
mListNode->RemoveMutationObserver(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mListNode = nullptr;
|
2010-09-10 09:20:16 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 20:37:47 +03:00
|
|
|
if (mController) {
|
|
|
|
// 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(nullptr);
|
|
|
|
}
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2012-02-22 16:59:39 +04:00
|
|
|
if (mFocusedInputNode) {
|
2012-02-28 03:31:23 +04:00
|
|
|
MaybeRemoveMutationObserver(mFocusedInputNode);
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocusedInputNode = nullptr;
|
|
|
|
mFocusedInput = nullptr;
|
2012-02-22 16:59:39 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mFocusedPopup = nullptr;
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocShell *
|
|
|
|
nsFormFillController::GetDocShellForInput(nsIDOMHTMLInputElement *aInput)
|
|
|
|
{
|
2014-01-10 06:03:47 +04:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aInput);
|
|
|
|
NS_ENSURE_TRUE(node, nullptr);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = node->OwnerDoc()->GetWindow();
|
|
|
|
NS_ENSURE_TRUE(win, nullptr);
|
|
|
|
|
|
|
|
return win->GetDocShell();
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
2015-10-27 00:37:32 +03:00
|
|
|
nsPIDOMWindow *
|
2002-09-28 04:38:20 +04:00
|
|
|
nsFormFillController::GetWindowForDocShell(nsIDocShell *aDocShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
aDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(contentViewer, nullptr);
|
2002-09-28 04:38:20 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
contentViewer->GetDOMDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(doc, nullptr);
|
2002-09-28 04:38:20 +04:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
return doc->GetWindow();
|
2002-09-28 04:38:20 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2002-09-28 04:38:20 +04:00
|
|
|
nsFormFillController::GetIndexOfDocShell(nsIDocShell *aDocShell)
|
|
|
|
{
|
2005-04-12 02:25:09 +04:00
|
|
|
if (!aDocShell)
|
|
|
|
return -1;
|
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
// Loop through our cached docShells looking for the given docShell
|
2012-12-11 01:54:32 +04:00
|
|
|
uint32_t count = mDocShells.Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2012-12-11 01:54:32 +04:00
|
|
|
if (mDocShells[i] == aDocShell)
|
2002-09-28 04:38:20 +04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recursively check the parent docShell of this one
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(aDocShell);
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
treeItem->GetParent(getter_AddRefs(parentItem));
|
|
|
|
if (parentItem) {
|
|
|
|
nsCOMPtr<nsIDocShell> parentShell = do_QueryInterface(parentItem);
|
|
|
|
return GetIndexOfDocShell(parentShell);
|
|
|
|
}
|
2011-08-04 04:52:47 +04:00
|
|
|
|
2002-09-28 04:38:20 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2006-01-25 23:23:24 +03:00
|
|
|
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFormFillController)
|
|
|
|
|
2010-06-10 22:11:40 +04:00
|
|
|
NS_DEFINE_NAMED_CID(NS_FORMFILLCONTROLLER_CID);
|
|
|
|
|
|
|
|
static const mozilla::Module::CIDEntry kSatchelCIDs[] = {
|
2013-10-11 00:38:05 +04:00
|
|
|
{ &kNS_FORMFILLCONTROLLER_CID, false, nullptr, nsFormFillControllerConstructor },
|
|
|
|
{ nullptr }
|
2010-06-10 22:11:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const mozilla::Module::ContractIDEntry kSatchelContracts[] = {
|
|
|
|
{ "@mozilla.org/satchel/form-fill-controller;1", &kNS_FORMFILLCONTROLLER_CID },
|
|
|
|
{ NS_FORMHISTORYAUTOCOMPLETE_CONTRACTID, &kNS_FORMFILLCONTROLLER_CID },
|
2013-10-11 00:38:05 +04:00
|
|
|
{ nullptr }
|
2010-06-10 22:11:40 +04:00
|
|
|
};
|
2006-01-25 23:23:24 +03:00
|
|
|
|
2010-06-10 22:11:40 +04:00
|
|
|
static const mozilla::Module kSatchelModule = {
|
|
|
|
mozilla::Module::kVersion,
|
|
|
|
kSatchelCIDs,
|
|
|
|
kSatchelContracts
|
2006-01-25 23:23:24 +03:00
|
|
|
};
|
|
|
|
|
2010-06-10 22:11:40 +04:00
|
|
|
NSMODULE_DEFN(satchel) = &kSatchelModule;
|