2000-11-04 11:21:20 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2000-11-04 11:21:20 +03:00
|
|
|
* The Original Code is the Mozilla browser.
|
2004-04-18 01:52:36 +04:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications, Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
2000-11-04 11:21:20 +03:00
|
|
|
* Contributor(s):
|
|
|
|
* David W. Hyatt <hyatt@netscape.com> (Original Author)
|
2004-04-18 01:52:36 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-11-04 11:21:20 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsWindowRoot.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIEventListenerManager.h"
|
|
|
|
#include "nsIPresShell.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2000-11-04 11:21:20 +03:00
|
|
|
#include "nsLayoutCID.h"
|
2001-02-20 00:50:04 +03:00
|
|
|
#include "nsContentCID.h"
|
2000-11-04 11:21:20 +03:00
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
|
|
|
#include "nsIDOMWindowInternal.h"
|
|
|
|
#include "nsFocusController.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsString.h"
|
2006-03-07 20:08:51 +03:00
|
|
|
#include "nsEventDispatcher.h"
|
2007-01-05 01:31:26 +03:00
|
|
|
#include "nsIProgrammingLanguage.h"
|
2009-04-02 01:59:02 +04:00
|
|
|
#include "nsGUIEvent.h"
|
2007-09-21 12:54:36 +04:00
|
|
|
|
2007-09-23 20:10:12 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2007-09-23 18:05:27 +04:00
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID);
|
|
|
|
|
|
|
|
nsWindowRoot::nsWindowRoot(nsIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
mWindow = aWindow;
|
|
|
|
|
|
|
|
// Create and init our focus controller.
|
|
|
|
nsFocusController::Create(getter_AddRefs(mFocusController));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMFocusListener> focusListener(do_QueryInterface(mFocusController));
|
2007-07-08 11:08:04 +04:00
|
|
|
mRefCnt.incr(static_cast<nsIDOMEventTarget*>(this));
|
2000-11-04 11:21:20 +03:00
|
|
|
AddEventListener(NS_LITERAL_STRING("focus"), focusListener, PR_TRUE);
|
|
|
|
AddEventListener(NS_LITERAL_STRING("blur"), focusListener, PR_TRUE);
|
2007-07-08 11:08:04 +04:00
|
|
|
mRefCnt.decr(static_cast<nsIDOMEventTarget*>(this));
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindowRoot::~nsWindowRoot()
|
|
|
|
{
|
2006-01-19 05:43:39 +03:00
|
|
|
if (mListenerManager) {
|
|
|
|
mListenerManager->Disconnect();
|
|
|
|
}
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
2007-02-18 17:38:04 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_2(nsWindowRoot, mListenerManager, mFocusController)
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2007-04-25 20:35:27 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsWindowRoot)
|
2007-05-14 13:11:38 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMEventTarget)
|
2007-02-16 02:04:33 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsPIDOMEventTarget)
|
2005-12-03 10:42:40 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsPIWindowRoot)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOM3EventTarget)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNSEventTarget)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2007-05-15 12:50:33 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsWindowRoot, nsIDOMEventTarget)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsWindowRoot, nsIDOMEventTarget)
|
2000-11-04 11:21:20 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 03:16:18 +03:00
|
|
|
nsWindowRoot::AddEventListener(const nsAString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture)
|
2000-11-04 11:21:20 +03:00
|
|
|
{
|
2002-11-09 03:25:25 +03:00
|
|
|
return AddGroupedEventListener(aType, aListener, aUseCapture, nsnull);
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 03:16:18 +03:00
|
|
|
nsWindowRoot::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture)
|
2000-11-04 11:21:20 +03:00
|
|
|
{
|
2002-11-09 03:25:25 +03:00
|
|
|
return RemoveGroupedEventListener(aType, aListener, aUseCapture, nsnull);
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-09-28 01:43:00 +04:00
|
|
|
nsWindowRoot::DispatchEvent(nsIDOMEvent* aEvt, PRBool *_retval)
|
2000-11-04 11:21:20 +03:00
|
|
|
{
|
2006-03-07 20:08:51 +03:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsresult rv = nsEventDispatcher::DispatchDOMEvent(
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsPIDOMEventTarget*>(this), nsnull, aEvt, nsnull, &status);
|
2006-03-07 20:08:51 +03:00
|
|
|
*_retval = (status != nsEventStatus_eConsumeNoDefault);
|
|
|
|
return rv;
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
2007-02-16 02:04:33 +03:00
|
|
|
nsresult
|
|
|
|
nsWindowRoot::DispatchDOMEvent(nsEvent* aEvent,
|
|
|
|
nsIDOMEvent* aDOMEvent,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
return nsEventDispatcher::DispatchDOMEvent(static_cast<nsPIDOMEventTarget*>(this),
|
2007-02-16 02:04:33 +03:00
|
|
|
aEvent, aDOMEvent,
|
|
|
|
aPresContext, aEventStatus);
|
|
|
|
}
|
|
|
|
|
2002-11-09 03:25:25 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowRoot::AddGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
|
|
|
|
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEventListenerManager> manager;
|
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
if (NS_SUCCEEDED(GetListenerManager(PR_TRUE, getter_AddRefs(manager)))) {
|
2002-11-09 03:25:25 +03:00
|
|
|
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
|
|
|
|
manager->AddEventListenerByType(aListener, aType, flags, aEvtGrp);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowRoot::RemoveGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
|
|
|
|
PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
|
|
|
|
{
|
|
|
|
if (mListenerManager) {
|
|
|
|
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
|
|
|
|
mListenerManager->RemoveEventListenerByType(aListener, aType, flags, aEvtGrp);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowRoot::CanTrigger(const nsAString & type, PRBool *_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowRoot::IsRegisteredHere(const nsAString & type, PRBool *_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2005-04-29 03:48:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowRoot::AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener *aListener,
|
|
|
|
PRBool aUseCapture, PRBool aWantsUntrusted)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEventListenerManager> manager;
|
2006-03-07 20:08:51 +03:00
|
|
|
nsresult rv = GetListenerManager(PR_TRUE, getter_AddRefs(manager));
|
2005-04-29 03:48:28 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
|
|
|
|
|
|
|
|
if (aWantsUntrusted) {
|
|
|
|
flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return manager->AddEventListenerByType(aListener, aType, flags, nsnull);
|
|
|
|
}
|
|
|
|
|
2007-05-14 13:11:38 +04:00
|
|
|
nsresult
|
2000-11-04 11:21:20 +03:00
|
|
|
nsWindowRoot::AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEventListenerManager> manager;
|
2006-03-07 20:08:51 +03:00
|
|
|
GetListenerManager(PR_TRUE, getter_AddRefs(manager));
|
2000-11-04 11:21:20 +03:00
|
|
|
if (manager) {
|
|
|
|
manager->AddEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-05-14 13:11:38 +04:00
|
|
|
nsresult
|
2000-11-04 11:21:20 +03:00
|
|
|
nsWindowRoot::RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEventListenerManager> manager;
|
2006-03-07 20:08:51 +03:00
|
|
|
GetListenerManager(PR_TRUE, getter_AddRefs(manager));
|
2000-11-04 11:21:20 +03:00
|
|
|
if (manager) {
|
2001-01-23 07:32:53 +03:00
|
|
|
manager->RemoveEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
|
2000-11-04 11:21:20 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-05-14 13:11:38 +04:00
|
|
|
nsresult
|
2006-03-07 20:08:51 +03:00
|
|
|
nsWindowRoot::GetListenerManager(PRBool aCreateIfNotFound,
|
|
|
|
nsIEventListenerManager** aResult)
|
2000-11-04 11:21:20 +03:00
|
|
|
{
|
|
|
|
if (!mListenerManager) {
|
2006-03-07 20:08:51 +03:00
|
|
|
if (!aCreateIfNotFound) {
|
|
|
|
*aResult = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-11-04 11:21:20 +03:00
|
|
|
nsresult rv;
|
|
|
|
mListenerManager = do_CreateInstance(kEventListenerManagerCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2005-12-03 10:42:40 +03:00
|
|
|
mListenerManager->SetListenerTarget(
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsPIDOMEventTarget*>(this));
|
2000-11-04 11:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = mListenerManager;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-14 13:11:38 +04:00
|
|
|
nsresult
|
2002-11-09 03:25:25 +03:00
|
|
|
nsWindowRoot::GetSystemEventGroup(nsIDOMEventGroup **aGroup)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEventListenerManager> manager;
|
2006-03-07 20:08:51 +03:00
|
|
|
if (NS_SUCCEEDED(GetListenerManager(PR_TRUE, getter_AddRefs(manager))) &&
|
|
|
|
manager) {
|
2002-11-09 03:25:25 +03:00
|
|
|
return manager->GetSystemEventGroupLM(aGroup);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2005-12-03 10:42:40 +03:00
|
|
|
|
2007-02-16 03:03:57 +03:00
|
|
|
nsresult
|
2007-02-16 02:04:33 +03:00
|
|
|
nsWindowRoot::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
2006-03-07 20:08:51 +03:00
|
|
|
{
|
|
|
|
aVisitor.mCanHandle = PR_TRUE;
|
2006-03-09 21:42:09 +03:00
|
|
|
aVisitor.mForceContentDispatch = PR_TRUE; //FIXME! Bug 329119
|
2006-03-07 20:08:51 +03:00
|
|
|
// To keep mWindow alive
|
|
|
|
aVisitor.mItemData = mWindow;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-16 03:03:57 +03:00
|
|
|
nsresult
|
2007-02-16 02:04:33 +03:00
|
|
|
nsWindowRoot::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
2006-03-07 20:08:51 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowRoot::GetFocusController(nsIFocusController** aResult)
|
|
|
|
{
|
|
|
|
*aResult = mFocusController;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-06 17:47:50 +04:00
|
|
|
nsIDOMWindow*
|
|
|
|
nsWindowRoot::GetWindow()
|
|
|
|
{
|
|
|
|
return mWindow;
|
|
|
|
}
|
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowRoot::GetScriptTypeID(PRUint32 *aScriptType)
|
|
|
|
{
|
|
|
|
NS_ERROR("No default script type here - ask some element");
|
|
|
|
return nsIProgrammingLanguage::UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowRoot::SetScriptTypeID(PRUint32 aScriptType)
|
|
|
|
{
|
|
|
|
NS_ERROR("Can't change default script type for a document");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2000-11-04 11:21:20 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
2007-02-16 02:04:33 +03:00
|
|
|
NS_NewWindowRoot(nsIDOMWindow* aWindow, nsPIDOMEventTarget** aResult)
|
2000-11-04 11:21:20 +03:00
|
|
|
{
|
|
|
|
*aResult = new nsWindowRoot(aWindow);
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|