2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-06-07 07:55:55 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* 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/
|
1998-06-07 07:55:55 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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.
|
1998-06-07 07:55:55 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
2004-04-17 21:52:36 +00:00
|
|
|
* Steve Clark (buster@netscape.com)
|
2004-08-20 18:09:19 +00:00
|
|
|
* Ilya Konstantinov (mozilla-code@future.shiny.co.il)
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* 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"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-06-07 07:55:55 +00:00
|
|
|
|
2000-05-05 14:47:37 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-06-07 07:55:55 +00:00
|
|
|
#include "nsDOMEvent.h"
|
2004-09-04 19:28:46 +00:00
|
|
|
#include "nsEventStateManager.h"
|
1998-11-18 05:25:26 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIContent.h"
|
1999-06-16 04:39:51 +00:00
|
|
|
#include "nsIPresShell.h"
|
1999-07-27 20:55:03 +00:00
|
|
|
#include "nsIDocument.h"
|
1999-08-31 01:20:32 +00:00
|
|
|
#include "nsIPrivateCompositionEvent.h"
|
2000-05-16 11:35:12 +00:00
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-05-16 11:35:12 +00:00
|
|
|
#include "prmem.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
2000-11-27 07:55:20 +00:00
|
|
|
#include "nsMutationEvent.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 16:46:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2003-04-16 00:00:50 +00:00
|
|
|
#include "nsIURI.h"
|
1998-07-17 04:52:12 +00:00
|
|
|
|
2004-02-11 06:09:51 +00:00
|
|
|
static const char* const sEventNames[] = {
|
1999-04-12 21:17:07 +00:00
|
|
|
"mousedown", "mouseup", "click", "dblclick", "mouseover",
|
2001-03-23 03:34:15 +00:00
|
|
|
"mouseout", "mousemove", "contextmenu", "keydown", "keyup", "keypress",
|
2004-02-11 06:09:51 +00:00
|
|
|
"focus", "blur", "load", "beforeunload", "unload", "abort", "error",
|
2005-05-04 20:22:32 +00:00
|
|
|
"DOMPageRestore", "submit", "reset", "change", "select", "input", "paint",
|
|
|
|
"text", "compositionstart", "compositionend", "popupshowing", "popupshown",
|
2005-03-05 08:19:05 +00:00
|
|
|
"popuphiding", "popuphidden", "close", "command", "broadcast", "commandupdate",
|
2000-05-17 06:53:58 +00:00
|
|
|
"dragenter", "dragover", "dragexit", "dragdrop", "draggesture", "resize",
|
2000-11-27 07:55:20 +00:00
|
|
|
"scroll","overflow", "underflow", "overflowchanged",
|
|
|
|
"DOMSubtreeModified", "DOMNodeInserted", "DOMNodeRemoved",
|
|
|
|
"DOMNodeRemovedFromDocument", "DOMNodeInsertedIntoDocument",
|
2003-04-16 00:00:50 +00:00
|
|
|
"DOMAttrModified", "DOMCharacterDataModified",
|
2004-04-30 23:55:16 +00:00
|
|
|
"popupBlocked", "DOMActivate", "DOMFocusIn", "DOMFocusOut"
|
1999-09-02 03:51:03 +00:00
|
|
|
};
|
1998-07-17 04:52:12 +00:00
|
|
|
|
2004-09-04 19:28:46 +00:00
|
|
|
static char *sPopupAllowedEvents;
|
|
|
|
|
|
|
|
|
2004-08-20 18:09:19 +00:00
|
|
|
nsDOMEvent::nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent)
|
2001-02-12 06:54:31 +00:00
|
|
|
{
|
1998-07-23 02:55:33 +00:00
|
|
|
mPresContext = aPresContext;
|
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 16:46:42 +00:00
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
if (aEvent) {
|
|
|
|
mEvent = aEvent;
|
2004-08-20 18:09:19 +00:00
|
|
|
mEventIsInternal = PR_FALSE;
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-09-22 00:25:16 +00:00
|
|
|
mEventIsInternal = PR_TRUE;
|
2004-08-20 18:09:19 +00:00
|
|
|
/*
|
|
|
|
A derived class might want to allocate its own type of aEvent
|
|
|
|
(derived from nsEvent). To do this, it should take care to pass
|
|
|
|
a non-NULL aEvent to this ctor, e.g.:
|
|
|
|
|
|
|
|
nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
|
|
|
|
: nsDOMEvent(..., aEvent ? aEvent : new nsFooEvent())
|
|
|
|
|
2004-09-04 19:28:46 +00:00
|
|
|
Then, to override the mEventIsInternal assignments done by the
|
|
|
|
base ctor, it should do this in its own ctor:
|
2004-08-20 18:09:19 +00:00
|
|
|
|
|
|
|
nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
|
|
|
|
...
|
|
|
|
{
|
|
|
|
...
|
|
|
|
if (aEvent) {
|
|
|
|
mEventIsInternal = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mEventIsInternal = PR_TRUE;
|
|
|
|
}
|
|
|
|
...
|
|
|
|
}
|
|
|
|
*/
|
2005-04-28 23:48:28 +00:00
|
|
|
mEvent = new nsEvent(PR_FALSE, 0);
|
2004-08-20 18:09:19 +00:00
|
|
|
mEvent->time = PR_Now();
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
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 16:46:42 +00:00
|
|
|
|
2003-02-22 08:10:46 +00:00
|
|
|
// Get the explicit original target (if it's anonymous make it null)
|
|
|
|
{
|
2003-03-04 01:51:16 +00:00
|
|
|
mExplicitOriginalTarget = GetTargetFromFrame();
|
2003-05-21 00:42:32 +00:00
|
|
|
mTmpRealOriginalTarget = mExplicitOriginalTarget;
|
2003-02-22 08:10:46 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mExplicitOriginalTarget);
|
|
|
|
if (content) {
|
|
|
|
if (content->IsNativeAnonymous()) {
|
|
|
|
mExplicitOriginalTarget = nsnull;
|
|
|
|
}
|
2003-07-28 21:17:26 +00:00
|
|
|
if (content->GetBindingParent()) {
|
2003-02-22 08:10:46 +00:00
|
|
|
mExplicitOriginalTarget = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
2001-02-12 06:54:31 +00:00
|
|
|
nsDOMEvent::~nsDOMEvent()
|
|
|
|
{
|
|
|
|
NS_ASSERT_OWNINGTHREAD(nsDOMEvent);
|
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
if (mEventIsInternal) {
|
2004-08-20 18:09:19 +00:00
|
|
|
delete mEvent->userType;
|
2004-01-12 08:25:18 +00:00
|
|
|
delete mEvent;
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsDOMEvent)
|
|
|
|
NS_IMPL_RELEASE(nsDOMEvent)
|
|
|
|
|
1999-12-21 19:28:15 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMEvent)
|
2004-08-20 18:09:19 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEvent)
|
2001-12-06 06:57:03 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNSEvent)
|
1999-12-21 19:28:15 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMEvent)
|
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 16:46:42 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Event)
|
1999-12-21 19:28:15 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
1998-06-07 07:55:55 +00:00
|
|
|
|
|
|
|
// nsIDOMEventInterface
|
2002-03-23 23:13:20 +00:00
|
|
|
NS_METHOD nsDOMEvent::GetType(nsAString& aType)
|
1998-07-17 04:52:12 +00:00
|
|
|
{
|
2003-12-23 15:41:10 +00:00
|
|
|
const char* name = GetEventName(mEvent->message);
|
1998-07-17 04:52:12 +00:00
|
|
|
|
2003-12-23 15:41:10 +00:00
|
|
|
if (name) {
|
|
|
|
CopyASCIItoUTF16(name, aType);
|
1998-07-17 04:52:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-17 05:52:11 +00:00
|
|
|
else {
|
|
|
|
if (mEvent->message == NS_USER_DEFINED_EVENT && mEvent->userType) {
|
|
|
|
aType.Assign(NS_STATIC_CAST(nsStringKey*, mEvent->userType)->GetString());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
1998-07-17 04:52:12 +00:00
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
NS_METHOD nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget)
|
1998-06-07 07:55:55 +00:00
|
|
|
{
|
1998-11-18 05:25:26 +00:00
|
|
|
if (nsnull != mTarget) {
|
|
|
|
*aTarget = mTarget;
|
2003-03-04 01:51:16 +00:00
|
|
|
NS_ADDREF(*aTarget);
|
1998-11-18 05:25:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-23 02:55:33 +00:00
|
|
|
|
2004-08-20 18:09:19 +00:00
|
|
|
*aTarget = nsnull;
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-08 21:31:05 +00:00
|
|
|
|
2001-01-10 20:21:09 +00:00
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2004-02-27 17:17:37 +00:00
|
|
|
if (mPresContext) {
|
|
|
|
mPresContext->EventStateManager()->
|
|
|
|
GetEventTargetContent(mEvent, getter_AddRefs(targetContent));
|
1998-07-23 02:55:33 +00:00
|
|
|
}
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
if (targetContent) {
|
2003-03-04 01:51:16 +00:00
|
|
|
mTarget = do_QueryInterface(targetContent);
|
2002-12-11 14:24:49 +00:00
|
|
|
if (mTarget) {
|
1998-11-18 05:25:26 +00:00
|
|
|
*aTarget = mTarget;
|
2002-08-13 00:50:50 +00:00
|
|
|
NS_ADDREF(*aTarget);
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
1999-07-27 20:55:03 +00:00
|
|
|
else {
|
|
|
|
//Always want a target. Use document if nothing else.
|
2003-12-21 05:36:36 +00:00
|
|
|
nsIPresShell *presShell;
|
|
|
|
if (mPresContext && (presShell = mPresContext->GetPresShell())) {
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = presShell->GetDocument();
|
|
|
|
if (doc) {
|
2003-03-04 01:51:16 +00:00
|
|
|
mTarget = do_QueryInterface(doc);
|
2002-12-11 14:24:49 +00:00
|
|
|
if (mTarget) {
|
|
|
|
*aTarget = mTarget;
|
|
|
|
NS_ADDREF(*aTarget);
|
|
|
|
}
|
|
|
|
}
|
1999-07-27 20:55:03 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 23:51:04 +00:00
|
|
|
NS_IMETHODIMP
|
2000-05-16 11:35:12 +00:00
|
|
|
nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)
|
1998-07-17 04:52:12 +00:00
|
|
|
{
|
2000-05-17 00:40:22 +00:00
|
|
|
*aCurrentTarget = mCurrentTarget;
|
|
|
|
NS_IF_ADDREF(*aCurrentTarget);
|
1999-03-15 05:39:04 +00:00
|
|
|
return NS_OK;
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 08:10:46 +00:00
|
|
|
//
|
|
|
|
// Get the actual event target node (may have been retargeted for mouse events)
|
|
|
|
//
|
2003-03-04 01:51:16 +00:00
|
|
|
already_AddRefed<nsIDOMEventTarget>
|
|
|
|
nsDOMEvent::GetTargetFromFrame()
|
2003-02-22 08:10:46 +00:00
|
|
|
{
|
2003-03-04 01:51:16 +00:00
|
|
|
if (!mPresContext) { return nsnull; }
|
2003-02-22 08:10:46 +00:00
|
|
|
|
|
|
|
// Get the target frame (have to get the ESM first)
|
|
|
|
nsIFrame* targetFrame = nsnull;
|
2004-02-27 17:17:37 +00:00
|
|
|
mPresContext->EventStateManager()->GetEventTarget(&targetFrame);
|
2003-03-04 01:51:16 +00:00
|
|
|
if (!targetFrame) { return nsnull; }
|
2003-02-22 08:10:46 +00:00
|
|
|
|
|
|
|
// get the real content
|
|
|
|
nsCOMPtr<nsIContent> realEventContent;
|
|
|
|
targetFrame->GetContentForEvent(mPresContext, mEvent, getter_AddRefs(realEventContent));
|
2003-03-04 01:51:16 +00:00
|
|
|
if (!realEventContent) { return nsnull; }
|
2003-02-22 08:10:46 +00:00
|
|
|
|
|
|
|
// Finally, we have the real content. QI it and return.
|
2003-03-04 01:51:16 +00:00
|
|
|
nsIDOMEventTarget* target = nsnull;
|
|
|
|
CallQueryInterface(realEventContent, &target);
|
|
|
|
return target;
|
2003-02-22 08:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetExplicitOriginalTarget(nsIDOMEventTarget** aRealEventTarget)
|
|
|
|
{
|
|
|
|
if (mExplicitOriginalTarget) {
|
|
|
|
*aRealEventTarget = mExplicitOriginalTarget;
|
|
|
|
NS_ADDREF(*aRealEventTarget);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetTarget(aRealEventTarget);
|
|
|
|
}
|
|
|
|
|
2003-05-21 00:42:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetTmpRealOriginalTarget(nsIDOMEventTarget** aRealEventTarget)
|
|
|
|
{
|
|
|
|
if (mTmpRealOriginalTarget) {
|
|
|
|
*aRealEventTarget = mTmpRealOriginalTarget;
|
|
|
|
NS_ADDREF(*aRealEventTarget);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetOriginalTarget(aRealEventTarget);
|
|
|
|
}
|
|
|
|
|
2000-09-07 01:07:29 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget)
|
|
|
|
{
|
2000-09-07 09:20:56 +00:00
|
|
|
if (!mOriginalTarget)
|
|
|
|
return GetTarget(aOriginalTarget);
|
|
|
|
|
2000-09-07 01:07:29 +00:00
|
|
|
*aOriginalTarget = mOriginalTarget;
|
|
|
|
NS_IF_ADDREF(*aOriginalTarget);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-09-07 09:20:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::HasOriginalTarget(PRBool* aResult)
|
|
|
|
{
|
|
|
|
*aResult = (mOriginalTarget != nsnull);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-20 08:40:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::SetTrusted(PRBool aTrusted)
|
|
|
|
{
|
2004-09-04 19:28:46 +00:00
|
|
|
if (aTrusted) {
|
|
|
|
mEvent->internalAppFlags |= NS_APP_EVENT_FLAG_TRUSTED;
|
|
|
|
} else {
|
|
|
|
mEvent->internalAppFlags &= ~NS_APP_EVENT_FLAG_TRUSTED;
|
|
|
|
}
|
|
|
|
|
2001-11-20 08:40:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-18 23:51:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetEventPhase(PRUint16* aEventPhase)
|
1998-07-17 04:52:12 +00:00
|
|
|
{
|
2004-07-16 15:10:02 +00:00
|
|
|
if (mEvent->flags & NS_EVENT_FLAG_CAPTURE) {
|
|
|
|
if (mEvent->flags & NS_EVENT_FLAG_BUBBLE) {
|
2004-08-20 18:09:19 +00:00
|
|
|
*aEventPhase = nsIDOMEvent::AT_TARGET;
|
2004-07-16 15:10:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2004-08-20 18:09:19 +00:00
|
|
|
*aEventPhase = nsIDOMEvent::CAPTURING_PHASE;
|
2004-07-16 15:10:02 +00:00
|
|
|
}
|
1999-07-19 19:54:34 +00:00
|
|
|
}
|
|
|
|
else if (mEvent->flags & NS_EVENT_FLAG_BUBBLE) {
|
2004-08-20 18:09:19 +00:00
|
|
|
*aEventPhase = nsIDOMEvent::BUBBLING_PHASE;
|
1999-07-19 19:54:34 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aEventPhase = 0;
|
|
|
|
}
|
|
|
|
|
1999-05-18 23:51:04 +00:00
|
|
|
return NS_OK;
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
|
|
|
|
1999-11-03 07:11:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetBubbles(PRBool* aBubbles)
|
|
|
|
{
|
2000-09-19 21:47:04 +00:00
|
|
|
*aBubbles = !(mEvent->flags & NS_EVENT_FLAG_CANT_BUBBLE);
|
2000-05-16 11:35:12 +00:00
|
|
|
return NS_OK;
|
1999-11-03 07:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetCancelable(PRBool* aCancelable)
|
|
|
|
{
|
2000-09-19 21:47:04 +00:00
|
|
|
*aCancelable = !(mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL);
|
2000-05-16 11:35:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetTimeStamp(PRUint64* aTimeStamp)
|
|
|
|
{
|
2000-05-17 00:40:22 +00:00
|
|
|
LL_UI2L(*aTimeStamp, mEvent->time);
|
2000-05-16 11:35:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::StopPropagation()
|
|
|
|
{
|
|
|
|
mEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH;
|
|
|
|
return NS_OK;
|
1999-11-03 07:11:45 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 23:51:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::PreventBubble()
|
1998-06-07 07:55:55 +00:00
|
|
|
{
|
1999-07-19 19:54:34 +00:00
|
|
|
if (mEvent->flags & NS_EVENT_FLAG_BUBBLE || mEvent->flags & NS_EVENT_FLAG_INIT) {
|
|
|
|
mEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH;
|
|
|
|
}
|
1999-05-18 23:51:04 +00:00
|
|
|
return NS_OK;
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 23:51:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::PreventCapture()
|
1998-06-07 07:55:55 +00:00
|
|
|
{
|
1999-07-19 19:54:34 +00:00
|
|
|
if (mEvent->flags & NS_EVENT_FLAG_CAPTURE) {
|
|
|
|
mEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH;
|
|
|
|
}
|
1999-05-18 23:51:04 +00:00
|
|
|
return NS_OK;
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
2004-09-02 15:25:39 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetIsTrusted(PRBool *aIsTrusted)
|
|
|
|
{
|
2005-04-28 23:48:28 +00:00
|
|
|
*aIsTrusted = NS_IS_TRUSTED_EVENT(mEvent);
|
2004-09-02 15:25:39 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-18 23:51:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::PreventDefault()
|
1998-06-07 07:55:55 +00:00
|
|
|
{
|
2000-05-16 11:35:12 +00:00
|
|
|
if (!(mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL)) {
|
|
|
|
mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
|
|
|
}
|
1999-05-18 23:51:04 +00:00
|
|
|
return NS_OK;
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
nsresult
|
2002-03-23 23:13:20 +00:00
|
|
|
nsDOMEvent::SetEventType(const nsAString& aEventTypeArg)
|
2000-05-16 11:35:12 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> atom= do_GetAtom(NS_LITERAL_STRING("on") + aEventTypeArg);
|
2004-01-14 01:33:47 +00:00
|
|
|
mEvent->message = NS_USER_DEFINED_EVENT;
|
2000-05-16 11:35:12 +00:00
|
|
|
|
2004-01-12 08:25:18 +00:00
|
|
|
if (mEvent->eventStructType == NS_MOUSE_EVENT) {
|
|
|
|
if (atom == nsLayoutAtoms::onmousedown)
|
|
|
|
mEvent->message = NS_MOUSE_LEFT_BUTTON_DOWN;
|
|
|
|
else if (atom == nsLayoutAtoms::onmouseup)
|
|
|
|
mEvent->message = NS_MOUSE_LEFT_BUTTON_UP;
|
|
|
|
else if (atom == nsLayoutAtoms::onclick)
|
|
|
|
mEvent->message = NS_MOUSE_LEFT_CLICK;
|
|
|
|
else if (atom == nsLayoutAtoms::ondblclick)
|
|
|
|
mEvent->message = NS_MOUSE_LEFT_DOUBLECLICK;
|
|
|
|
else if (atom == nsLayoutAtoms::onmouseover)
|
|
|
|
mEvent->message = NS_MOUSE_ENTER_SYNTH;
|
|
|
|
else if (atom == nsLayoutAtoms::onmouseout)
|
|
|
|
mEvent->message = NS_MOUSE_EXIT_SYNTH;
|
|
|
|
else if (atom == nsLayoutAtoms::onmousemove)
|
|
|
|
mEvent->message = NS_MOUSE_MOVE;
|
|
|
|
else if (atom == nsLayoutAtoms::oncontextmenu)
|
|
|
|
mEvent->message = NS_CONTEXTMENU;
|
|
|
|
} else if (mEvent->eventStructType == NS_KEY_EVENT) {
|
|
|
|
if (atom == nsLayoutAtoms::onkeydown)
|
|
|
|
mEvent->message = NS_KEY_DOWN;
|
|
|
|
else if (atom == nsLayoutAtoms::onkeyup)
|
|
|
|
mEvent->message = NS_KEY_UP;
|
|
|
|
else if (atom == nsLayoutAtoms::onkeypress)
|
|
|
|
mEvent->message = NS_KEY_PRESS;
|
2005-03-05 08:19:05 +00:00
|
|
|
} else if (mEvent->eventStructType == NS_COMPOSITION_EVENT) {
|
|
|
|
if (atom == nsLayoutAtoms::oncompositionstart)
|
|
|
|
mEvent->message = NS_COMPOSITION_START;
|
|
|
|
else if (atom == nsLayoutAtoms::oncompositionend)
|
|
|
|
mEvent->message = NS_COMPOSITION_END;
|
2004-01-12 08:25:18 +00:00
|
|
|
} else if (mEvent->eventStructType == NS_EVENT) {
|
|
|
|
if (atom == nsLayoutAtoms::onfocus)
|
|
|
|
mEvent->message = NS_FOCUS_CONTENT;
|
|
|
|
else if (atom == nsLayoutAtoms::onblur)
|
|
|
|
mEvent->message = NS_BLUR_CONTENT;
|
|
|
|
else if (atom == nsLayoutAtoms::onsubmit)
|
|
|
|
mEvent->message = NS_FORM_SUBMIT;
|
|
|
|
else if (atom == nsLayoutAtoms::onreset)
|
|
|
|
mEvent->message = NS_FORM_RESET;
|
|
|
|
else if (atom == nsLayoutAtoms::onchange)
|
|
|
|
mEvent->message = NS_FORM_CHANGE;
|
|
|
|
else if (atom == nsLayoutAtoms::onselect)
|
|
|
|
mEvent->message = NS_FORM_SELECTED;
|
|
|
|
else if (atom == nsLayoutAtoms::onload)
|
|
|
|
mEvent->message = NS_PAGE_LOAD;
|
|
|
|
else if (atom == nsLayoutAtoms::onunload)
|
|
|
|
mEvent->message = NS_PAGE_UNLOAD;
|
|
|
|
else if (atom == nsLayoutAtoms::onabort)
|
|
|
|
mEvent->message = NS_IMAGE_ABORT;
|
|
|
|
else if (atom == nsLayoutAtoms::onerror)
|
|
|
|
mEvent->message = NS_IMAGE_ERROR;
|
2005-05-04 20:22:32 +00:00
|
|
|
else if (atom == nsLayoutAtoms::onDOMPageRestore)
|
|
|
|
mEvent->message = NS_PAGE_RESTORE;
|
2004-01-12 08:25:18 +00:00
|
|
|
} else if (mEvent->eventStructType == NS_MUTATION_EVENT) {
|
|
|
|
if (atom == nsLayoutAtoms::onDOMAttrModified)
|
|
|
|
mEvent->message = NS_MUTATION_ATTRMODIFIED;
|
|
|
|
else if (atom == nsLayoutAtoms::onDOMCharacterDataModified)
|
|
|
|
mEvent->message = NS_MUTATION_CHARACTERDATAMODIFIED;
|
|
|
|
else if (atom == nsLayoutAtoms::onDOMNodeInserted)
|
|
|
|
mEvent->message = NS_MUTATION_NODEINSERTED;
|
|
|
|
else if (atom == nsLayoutAtoms::onDOMNodeRemoved)
|
|
|
|
mEvent->message = NS_MUTATION_NODEREMOVED;
|
|
|
|
else if (atom == nsLayoutAtoms::onDOMNodeInsertedIntoDocument)
|
|
|
|
mEvent->message = NS_MUTATION_NODEINSERTEDINTODOCUMENT;
|
|
|
|
else if (atom == nsLayoutAtoms::onDOMNodeRemovedFromDocument)
|
|
|
|
mEvent->message = NS_MUTATION_NODEREMOVEDFROMDOCUMENT;
|
|
|
|
else if (atom == nsLayoutAtoms::onDOMSubtreeModified)
|
|
|
|
mEvent->message = NS_MUTATION_SUBTREEMODIFIED;
|
2004-08-20 18:09:19 +00:00
|
|
|
} else if (mEvent->eventStructType == NS_UI_EVENT) {
|
2004-04-30 23:55:16 +00:00
|
|
|
if (atom == nsLayoutAtoms::onDOMActivate)
|
2004-08-20 18:09:19 +00:00
|
|
|
mEvent->message = NS_UI_ACTIVATE;
|
2004-04-30 23:55:16 +00:00
|
|
|
else if (atom == nsLayoutAtoms::onDOMFocusIn)
|
2004-08-20 18:09:19 +00:00
|
|
|
mEvent->message = NS_UI_FOCUSIN;
|
2004-04-30 23:55:16 +00:00
|
|
|
else if (atom == nsLayoutAtoms::onDOMFocusOut)
|
2004-08-20 18:09:19 +00:00
|
|
|
mEvent->message = NS_UI_FOCUSOUT;
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
2004-01-14 01:33:47 +00:00
|
|
|
|
|
|
|
if (mEvent->message == NS_USER_DEFINED_EVENT)
|
2001-09-22 00:25:16 +00:00
|
|
|
mEvent->userType = new nsStringKey(aEventTypeArg);
|
2004-01-14 01:33:47 +00:00
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-03 07:11:45 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:13:20 +00:00
|
|
|
nsDOMEvent::InitEvent(const nsAString& aEventTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg)
|
1999-11-03 07:11:45 +00:00
|
|
|
{
|
2000-05-16 11:35:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(SetEventType(aEventTypeArg), NS_ERROR_FAILURE);
|
|
|
|
mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE;
|
|
|
|
mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL;
|
|
|
|
return NS_OK;
|
1999-11-03 07:11:45 +00:00
|
|
|
}
|
|
|
|
|
1998-07-23 02:55:33 +00:00
|
|
|
NS_METHOD nsDOMEvent::DuplicatePrivateData()
|
1998-06-23 21:53:02 +00:00
|
|
|
{
|
1998-07-23 02:55:33 +00:00
|
|
|
//XXX Write me!
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
//XXX And when you do, make sure to copy over the event target here, too!
|
1998-06-23 21:53:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-17 04:52:12 +00:00
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
NS_METHOD nsDOMEvent::SetTarget(nsIDOMEventTarget* aTarget)
|
1999-05-21 19:27:02 +00:00
|
|
|
{
|
2003-03-04 01:51:16 +00:00
|
|
|
mTarget = aTarget;
|
1999-05-21 19:27:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
NS_METHOD nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget)
|
|
|
|
{
|
2003-03-04 01:51:16 +00:00
|
|
|
mCurrentTarget = aCurrentTarget;
|
2000-05-16 11:35:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-09-07 01:07:29 +00:00
|
|
|
NS_METHOD nsDOMEvent::SetOriginalTarget(nsIDOMEventTarget* aOriginalTarget)
|
|
|
|
{
|
2003-03-04 01:51:16 +00:00
|
|
|
mOriginalTarget = aOriginalTarget;
|
2000-09-07 01:07:29 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-15 22:04:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::IsDispatchStopped(PRBool* aIsDispatchStopped)
|
|
|
|
{
|
|
|
|
if (mEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) {
|
|
|
|
*aIsDispatchStopped = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
*aIsDispatchStopped = PR_FALSE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-20 00:45:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::IsHandled(PRBool* aIsHandled)
|
|
|
|
{
|
|
|
|
if (mEvent->internalAppFlags | NS_APP_EVENT_FLAG_HANDLED) {
|
|
|
|
*aIsHandled = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
*aIsHandled = PR_FALSE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::SetHandled(PRBool aHandled)
|
|
|
|
{
|
2004-09-04 19:28:46 +00:00
|
|
|
if(aHandled)
|
2000-06-20 00:45:47 +00:00
|
|
|
mEvent->internalAppFlags |= NS_APP_EVENT_FLAG_HANDLED;
|
|
|
|
else
|
2004-09-04 19:28:46 +00:00
|
|
|
mEvent->internalAppFlags &= ~NS_APP_EVENT_FLAG_HANDLED;
|
2000-06-20 00:45:47 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-17 05:27:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetInternalNSEvent(nsEvent** aNSEvent)
|
|
|
|
{
|
2003-04-16 00:00:50 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aNSEvent);
|
2000-05-17 05:27:22 +00:00
|
|
|
*aNSEvent = mEvent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-04 19:28:46 +00:00
|
|
|
// return true if eventName is contained within events, delimited by
|
|
|
|
// spaces
|
|
|
|
static PRBool
|
|
|
|
PopupAllowedForEvent(const char *eventName)
|
|
|
|
{
|
|
|
|
if (!sPopupAllowedEvents) {
|
|
|
|
nsDOMEvent::PopupAllowedEventsChanged();
|
|
|
|
|
|
|
|
if (!sPopupAllowedEvents) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentCString events(sPopupAllowedEvents);
|
|
|
|
|
|
|
|
nsAFlatCString::const_iterator start, end;
|
|
|
|
nsAFlatCString::const_iterator startiter(events.BeginReading(start));
|
|
|
|
events.EndReading(end);
|
|
|
|
|
|
|
|
while (startiter != end) {
|
|
|
|
nsAFlatCString::const_iterator enditer(end);
|
|
|
|
|
|
|
|
if (!FindInReadable(nsDependentCString(eventName), startiter, enditer))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// the match is surrounded by spaces, or at a string boundary
|
|
|
|
if ((startiter == start || *--startiter == ' ') &&
|
|
|
|
(enditer == end || *enditer == ' ')) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move on and see if there are other matches. (The delimitation
|
|
|
|
// requirement makes it pointless to begin the next search before
|
|
|
|
// the end of the invalid match just found.)
|
|
|
|
startiter = enditer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
PopupControlState
|
|
|
|
nsDOMEvent::GetEventPopupControlState(nsEvent *aEvent)
|
|
|
|
{
|
|
|
|
// generally if an event handler is running, new windows are disallowed.
|
|
|
|
// check for exceptions:
|
|
|
|
PopupControlState abuse = openAbused;
|
|
|
|
|
|
|
|
switch(aEvent->eventStructType) {
|
|
|
|
case NS_EVENT :
|
|
|
|
// For these following events only allow popups if they're
|
|
|
|
// triggered while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
|
|
|
if (nsEventStateManager::IsHandlingUserInput()) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_SELECTED :
|
|
|
|
if (::PopupAllowedForEvent("select"))
|
|
|
|
abuse = openControlled;
|
2005-03-04 02:01:54 +00:00
|
|
|
break;
|
2004-09-04 19:28:46 +00:00
|
|
|
case NS_FORM_CHANGE :
|
|
|
|
if (::PopupAllowedForEvent("change"))
|
|
|
|
abuse = openControlled;
|
2005-03-04 02:01:54 +00:00
|
|
|
break;
|
2004-09-04 19:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_GUI_EVENT :
|
|
|
|
// For this following event only allow popups if it's triggered
|
|
|
|
// while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
|
|
|
if (nsEventStateManager::IsHandlingUserInput()) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_INPUT :
|
|
|
|
if (::PopupAllowedForEvent("input"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_INPUT_EVENT :
|
|
|
|
// For this following event only allow popups if it's triggered
|
|
|
|
// while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
|
|
|
if (nsEventStateManager::IsHandlingUserInput()) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_CHANGE :
|
|
|
|
if (::PopupAllowedForEvent("change"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_KEY_EVENT :
|
2005-04-28 23:48:28 +00:00
|
|
|
if (NS_IS_TRUSTED_EVENT(aEvent)) {
|
2004-09-04 19:28:46 +00:00
|
|
|
PRUint32 key = NS_STATIC_CAST(nsKeyEvent *, aEvent)->keyCode;
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_KEY_PRESS :
|
|
|
|
// return key on focused button. see note at NS_MOUSE_LEFT_CLICK.
|
|
|
|
if (key == nsIDOMKeyEvent::DOM_VK_RETURN)
|
|
|
|
abuse = openAllowed;
|
|
|
|
else if (::PopupAllowedForEvent("keypress"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
case NS_KEY_UP :
|
|
|
|
// space key on focused button. see note at NS_MOUSE_LEFT_CLICK.
|
|
|
|
if (key == nsIDOMKeyEvent::DOM_VK_SPACE)
|
|
|
|
abuse = openAllowed;
|
|
|
|
else if (::PopupAllowedForEvent("keyup"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
case NS_KEY_DOWN :
|
|
|
|
if (::PopupAllowedForEvent("keydown"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_EVENT :
|
2005-04-28 23:48:28 +00:00
|
|
|
if (NS_IS_TRUSTED_EVENT(aEvent)) {
|
2004-09-04 19:28:46 +00:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP :
|
|
|
|
if (::PopupAllowedForEvent("mouseup"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_DOWN :
|
|
|
|
if (::PopupAllowedForEvent("mousedown"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_LEFT_CLICK :
|
|
|
|
/* Click events get special treatment because of their
|
|
|
|
historical status as a more legitimate event handler. If
|
|
|
|
click popups are enabled in the prefs, clear the popup
|
|
|
|
status completely. */
|
|
|
|
if (::PopupAllowedForEvent("click"))
|
|
|
|
abuse = openAllowed;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_LEFT_DOUBLECLICK :
|
|
|
|
if (::PopupAllowedForEvent("dblclick"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_SCRIPT_ERROR_EVENT :
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_SCRIPT_ERROR :
|
|
|
|
// Any error event will allow popups, if enabled in the pref.
|
|
|
|
if (::PopupAllowedForEvent("error"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_FORM_EVENT :
|
|
|
|
// For these following events only allow popups if they're
|
|
|
|
// triggered while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
|
|
|
if (nsEventStateManager::IsHandlingUserInput()) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_SUBMIT :
|
|
|
|
if (::PopupAllowedForEvent("submit"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
case NS_FORM_RESET :
|
|
|
|
if (::PopupAllowedForEvent("reset"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return abuse;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsDOMEvent::PopupAllowedEventsChanged()
|
|
|
|
{
|
|
|
|
if (sPopupAllowedEvents) {
|
|
|
|
nsMemory::Free(sPopupAllowedEvents);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAdoptingCString str =
|
|
|
|
nsContentUtils::GetCharPref("dom.popup_allowed_events");
|
|
|
|
|
|
|
|
// We'll want to do this even if str is empty to avoid looking up
|
|
|
|
// this pref all the time if it's not set.
|
|
|
|
sPopupAllowedEvents = ToNewCString(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsDOMEvent::Shutdown()
|
|
|
|
{
|
|
|
|
if (sPopupAllowedEvents) {
|
|
|
|
nsMemory::Free(sPopupAllowedEvents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
1998-07-17 04:52:12 +00:00
|
|
|
const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
|
|
|
|
{
|
|
|
|
switch(aEventType) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_DOWN:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_mousedown];
|
1998-07-17 04:52:12 +00:00
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_UP:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_mouseup];
|
1998-07-24 05:06:44 +00:00
|
|
|
case NS_MOUSE_LEFT_CLICK:
|
1998-07-31 22:09:51 +00:00
|
|
|
case NS_MOUSE_MIDDLE_CLICK:
|
1998-07-24 05:06:44 +00:00
|
|
|
case NS_MOUSE_RIGHT_CLICK:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_click];
|
1998-07-17 04:52:12 +00:00
|
|
|
case NS_MOUSE_LEFT_DOUBLECLICK:
|
1998-07-31 22:09:51 +00:00
|
|
|
case NS_MOUSE_MIDDLE_DOUBLECLICK:
|
1998-07-17 04:52:12 +00:00
|
|
|
case NS_MOUSE_RIGHT_DOUBLECLICK:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_dblclick];
|
2000-04-24 04:41:27 +00:00
|
|
|
case NS_MOUSE_ENTER_SYNTH:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_mouseover];
|
2000-04-24 04:41:27 +00:00
|
|
|
case NS_MOUSE_EXIT_SYNTH:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_mouseout];
|
1998-07-17 04:52:12 +00:00
|
|
|
case NS_MOUSE_MOVE:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_mousemove];
|
1998-07-17 04:52:12 +00:00
|
|
|
case NS_KEY_UP:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_keyup];
|
1998-07-17 04:52:12 +00:00
|
|
|
case NS_KEY_DOWN:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_keydown];
|
1998-11-24 07:46:58 +00:00
|
|
|
case NS_KEY_PRESS:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_keypress];
|
2005-03-05 08:19:05 +00:00
|
|
|
case NS_COMPOSITION_START:
|
|
|
|
return sEventNames[eDOMEvents_compositionstart];
|
|
|
|
case NS_COMPOSITION_END:
|
|
|
|
return sEventNames[eDOMEvents_compositionend];
|
1999-03-28 22:22:54 +00:00
|
|
|
case NS_FOCUS_CONTENT:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_focus];
|
1999-03-28 22:22:54 +00:00
|
|
|
case NS_BLUR_CONTENT:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_blur];
|
1999-12-01 22:35:33 +00:00
|
|
|
case NS_XUL_CLOSE:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_close];
|
1998-07-24 05:06:44 +00:00
|
|
|
case NS_PAGE_LOAD:
|
|
|
|
case NS_IMAGE_LOAD:
|
2001-05-19 01:21:57 +00:00
|
|
|
case NS_SCRIPT_LOAD:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_load];
|
|
|
|
case NS_BEFORE_PAGE_UNLOAD:
|
|
|
|
return sEventNames[eDOMEvents_beforeunload];
|
1998-07-24 05:06:44 +00:00
|
|
|
case NS_PAGE_UNLOAD:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_unload];
|
1998-07-24 05:06:44 +00:00
|
|
|
case NS_IMAGE_ABORT:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_abort];
|
1998-07-24 05:06:44 +00:00
|
|
|
case NS_IMAGE_ERROR:
|
2000-04-24 04:41:27 +00:00
|
|
|
case NS_SCRIPT_ERROR:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_error];
|
2005-05-04 20:22:32 +00:00
|
|
|
case NS_PAGE_RESTORE:
|
|
|
|
return sEventNames[eDOMEvents_DOMPageRestore];
|
1998-07-31 22:09:51 +00:00
|
|
|
case NS_FORM_SUBMIT:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_submit];
|
1998-07-31 22:09:51 +00:00
|
|
|
case NS_FORM_RESET:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_reset];
|
1998-11-02 23:05:46 +00:00
|
|
|
case NS_FORM_CHANGE:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_change];
|
2004-06-21 23:35:56 +00:00
|
|
|
case NS_FORM_SELECTED:
|
|
|
|
return sEventNames[eDOMEvents_select];
|
2004-06-21 23:41:30 +00:00
|
|
|
case NS_FORM_INPUT:
|
|
|
|
return sEventNames[eDOMEvents_input];
|
1998-10-06 21:01:59 +00:00
|
|
|
case NS_PAINT:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_paint];
|
2000-05-17 05:27:22 +00:00
|
|
|
case NS_RESIZE_EVENT:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_resize];
|
2000-05-17 06:53:58 +00:00
|
|
|
case NS_SCROLL_EVENT:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_scroll];
|
2004-01-12 08:25:18 +00:00
|
|
|
case NS_TEXT_TEXT:
|
2004-09-04 19:28:46 +00:00
|
|
|
return sEventNames[eDOMEvents_text];
|
2001-08-06 21:49:35 +00:00
|
|
|
case NS_XUL_POPUP_SHOWING:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_popupShowing];
|
2001-08-06 21:49:35 +00:00
|
|
|
case NS_XUL_POPUP_SHOWN:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_popupShown];
|
2001-08-06 21:49:35 +00:00
|
|
|
case NS_XUL_POPUP_HIDING:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_popupHiding];
|
2001-08-06 21:49:35 +00:00
|
|
|
case NS_XUL_POPUP_HIDDEN:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_popupHidden];
|
2001-08-06 21:49:35 +00:00
|
|
|
case NS_XUL_COMMAND:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_command];
|
1999-09-21 23:02:35 +00:00
|
|
|
case NS_XUL_BROADCAST:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_broadcast];
|
1999-09-21 23:02:35 +00:00
|
|
|
case NS_XUL_COMMAND_UPDATE:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_commandupdate];
|
1999-09-02 03:51:03 +00:00
|
|
|
case NS_DRAGDROP_ENTER:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_dragenter];
|
2000-04-24 04:41:27 +00:00
|
|
|
case NS_DRAGDROP_OVER_SYNTH:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_dragover];
|
2000-04-24 04:41:27 +00:00
|
|
|
case NS_DRAGDROP_EXIT_SYNTH:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_dragexit];
|
1999-09-02 03:51:03 +00:00
|
|
|
case NS_DRAGDROP_DROP:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_dragdrop];
|
1999-09-02 03:51:03 +00:00
|
|
|
case NS_DRAGDROP_GESTURE:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_draggesture];
|
2000-06-23 05:15:04 +00:00
|
|
|
case NS_SCROLLPORT_OVERFLOW:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_overflow];
|
2000-06-23 05:15:04 +00:00
|
|
|
case NS_SCROLLPORT_UNDERFLOW:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_underflow];
|
2000-06-28 00:00:18 +00:00
|
|
|
case NS_SCROLLPORT_OVERFLOWCHANGED:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_overflowchanged];
|
2000-11-27 07:55:20 +00:00
|
|
|
case NS_MUTATION_SUBTREEMODIFIED:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_subtreemodified];
|
2000-11-27 07:55:20 +00:00
|
|
|
case NS_MUTATION_NODEINSERTED:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_nodeinserted];
|
2000-11-27 07:55:20 +00:00
|
|
|
case NS_MUTATION_NODEREMOVED:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_noderemoved];
|
2000-11-27 07:55:20 +00:00
|
|
|
case NS_MUTATION_NODEREMOVEDFROMDOCUMENT:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_noderemovedfromdocument];
|
2000-11-27 07:55:20 +00:00
|
|
|
case NS_MUTATION_NODEINSERTEDINTODOCUMENT:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_nodeinsertedintodocument];
|
2000-11-27 07:55:20 +00:00
|
|
|
case NS_MUTATION_ATTRMODIFIED:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_attrmodified];
|
2000-11-27 07:55:20 +00:00
|
|
|
case NS_MUTATION_CHARACTERDATAMODIFIED:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_characterdatamodified];
|
2001-03-30 02:30:17 +00:00
|
|
|
case NS_CONTEXTMENU:
|
2001-05-17 18:37:50 +00:00
|
|
|
case NS_CONTEXTMENU_KEY:
|
2004-02-11 06:09:51 +00:00
|
|
|
return sEventNames[eDOMEvents_contextmenu];
|
2004-08-20 18:09:19 +00:00
|
|
|
case NS_UI_ACTIVATE:
|
2004-04-30 23:55:16 +00:00
|
|
|
return sEventNames[eDOMEvents_DOMActivate];
|
2004-08-20 18:09:19 +00:00
|
|
|
case NS_UI_FOCUSIN:
|
2004-04-30 23:55:16 +00:00
|
|
|
return sEventNames[eDOMEvents_DOMFocusIn];
|
2004-08-20 18:09:19 +00:00
|
|
|
case NS_UI_FOCUSOUT:
|
2004-04-30 23:55:16 +00:00
|
|
|
return sEventNames[eDOMEvents_DOMFocusOut];
|
1998-07-17 04:52:12 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
1998-07-23 02:55:33 +00:00
|
|
|
|
2004-08-20 18:09:19 +00:00
|
|
|
nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsEvent *aEvent)
|
1998-07-23 02:55:33 +00:00
|
|
|
{
|
2004-08-20 18:09:19 +00:00
|
|
|
nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent);
|
1998-07-23 02:55:33 +00:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
|
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
1998-07-23 02:55:33 +00:00
|
|
|
}
|