1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Steve Clark (buster@netscape.com)
24 * Ilya Konstantinov (mozilla-code@future.shiny.co.il)
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
41 #include "nsDOMEvent.h"
42 #include "nsEventStateManager.h"
44 #include "nsIContent.h"
45 #include "nsIPresShell.h"
46 #include "nsIDocument.h"
47 #include "nsIPrivateCompositionEvent.h"
48 #include "nsIDOMEventTarget.h"
49 #include "nsIInterfaceRequestor.h"
50 #include "nsIInterfaceRequestorUtils.h"
52 #include "nsGkAtoms.h"
53 #include "nsMutationEvent.h"
54 #include "nsContentUtils.h"
56 #include "nsIScriptSecurityManager.h"
57 #include "nsIScriptError.h"
59 static const char* const sEventNames
[] = {
60 "mousedown", "mouseup", "click", "dblclick", "mouseover",
61 "mouseout", "mousemove", "contextmenu", "keydown", "keyup", "keypress",
62 "focus", "blur", "load", "beforeunload", "unload", "abort", "error",
63 "submit", "reset", "change", "select", "input", "paint" ,"text",
64 "compositionstart", "compositionend", "popupshowing", "popupshown",
65 "popuphiding", "popuphidden", "close", "command", "broadcast", "commandupdate",
66 "dragenter", "dragover", "dragexit", "dragdrop", "draggesture",
67 "drag", "dragend", "resize",
68 "scroll", "overflow", "underflow", "overflowchanged",
69 "DOMSubtreeModified", "DOMNodeInserted", "DOMNodeRemoved",
70 "DOMNodeRemovedFromDocument", "DOMNodeInsertedIntoDocument",
71 "DOMAttrModified", "DOMCharacterDataModified",
72 "DOMActivate", "DOMFocusIn", "DOMFocusOut",
73 "pageshow", "pagehide", "DOMMouseScroll", "offline", "online",
74 "copy", "cut", "paste"
77 "SVGLoad", "SVGUnload", "SVGAbort", "SVGError", "SVGResize", "SVGScroll",
82 static char *sPopupAllowedEvents
;
85 nsDOMEvent::nsDOMEvent(nsPresContext
* aPresContext
, nsEvent
* aEvent
)
87 mPresContext
= aPresContext
;
88 mPrivateDataDuplicated
= PR_FALSE
;
92 mEventIsInternal
= PR_FALSE
;
95 mEventIsInternal
= PR_TRUE
;
97 A derived class might want to allocate its own type of aEvent
98 (derived from nsEvent). To do this, it should take care to pass
99 a non-NULL aEvent to this ctor, e.g.:
101 nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
102 : nsDOMEvent(..., aEvent ? aEvent : new nsFooEvent())
104 Then, to override the mEventIsInternal assignments done by the
105 base ctor, it should do this in its own ctor:
107 nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
112 mEventIsInternal = PR_FALSE;
115 mEventIsInternal = PR_TRUE;
120 mEvent
= new nsEvent(PR_FALSE
, 0);
121 mEvent
->time
= PR_Now();
124 // Get the explicit original target (if it's anonymous make it null)
126 mExplicitOriginalTarget
= GetTargetFromFrame();
127 mTmpRealOriginalTarget
= mExplicitOriginalTarget
;
128 nsCOMPtr
<nsIContent
> content
= do_QueryInterface(mExplicitOriginalTarget
);
130 if (content
->IsNativeAnonymous() || content
->GetBindingParent()) {
131 mExplicitOriginalTarget
= nsnull
;
137 nsDOMEvent::~nsDOMEvent()
139 NS_ASSERT_OWNINGTHREAD(nsDOMEvent
);
141 if (mEventIsInternal
&& mEvent
) {
146 NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMEvent
)
148 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMEvent
)
149 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIDOMEvent
)
150 NS_INTERFACE_MAP_ENTRY(nsIDOMEvent
)
151 NS_INTERFACE_MAP_ENTRY(nsIDOMNSEvent
)
152 NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMEvent
)
153 NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Event
)
156 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMEvent
)
157 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMEvent
)
159 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMEvent
)
160 if (tmp
->mEventIsInternal
) {
161 tmp
->mEvent
->target
= nsnull
;
162 tmp
->mEvent
->currentTarget
= nsnull
;
163 tmp
->mEvent
->originalTarget
= nsnull
;
164 switch (tmp
->mEvent
->eventStructType
) {
166 case NS_MOUSE_SCROLL_EVENT
:
167 static_cast<nsMouseEvent_base
*>(tmp
->mEvent
)->relatedTarget
= nsnull
;
169 case NS_XUL_COMMAND_EVENT
:
170 static_cast<nsXULCommandEvent
*>(tmp
->mEvent
)->sourceEvent
= nsnull
;
172 case NS_MUTATION_EVENT
:
173 static_cast<nsMutationEvent
*>(tmp
->mEvent
)->mRelatedNode
= nsnull
;
179 NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPresContext
);
180 NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTmpRealOriginalTarget
)
181 NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mExplicitOriginalTarget
)
182 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
184 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMEvent
)
185 if (tmp
->mEventIsInternal
) {
186 cb
.NoteXPCOMChild(tmp
->mEvent
->target
);
187 cb
.NoteXPCOMChild(tmp
->mEvent
->currentTarget
);
188 cb
.NoteXPCOMChild(tmp
->mEvent
->originalTarget
);
189 switch (tmp
->mEvent
->eventStructType
) {
191 case NS_MOUSE_SCROLL_EVENT
:
193 static_cast<nsMouseEvent_base
*>(tmp
->mEvent
)->relatedTarget
);
195 case NS_XUL_COMMAND_EVENT
:
197 static_cast<nsXULCommandEvent
*>(tmp
->mEvent
)->sourceEvent
);
199 case NS_MUTATION_EVENT
:
201 static_cast<nsMutationEvent
*>(tmp
->mEvent
)->mRelatedNode
);
207 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPresContext
)
208 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTmpRealOriginalTarget
)
209 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mExplicitOriginalTarget
)
210 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
212 // nsIDOMEventInterface
213 NS_METHOD
nsDOMEvent::GetType(nsAString
& aType
)
215 const char* name
= GetEventName(mEvent
->message
);
218 CopyASCIItoUTF16(name
, aType
);
220 } else if (mEvent
->message
== NS_USER_DEFINED_EVENT
&& mEvent
->userType
) {
222 mEvent
->userType
->ToString(name
);
223 aType
= Substring(name
, 2, name
.Length() - 2); // Remove "on"
227 return NS_ERROR_FAILURE
;
231 GetDOMEventTarget(nsISupports
* aTarget
,
232 nsIDOMEventTarget
** aDOMTarget
)
234 nsCOMPtr
<nsPIDOMEventTarget
> piTarget
= do_QueryInterface(aTarget
);
235 nsISupports
* realTarget
=
236 piTarget
? piTarget
->GetTargetForDOMEvent() : aTarget
;
238 return CallQueryInterface(realTarget
, aDOMTarget
);
241 *aDOMTarget
= nsnull
;
246 nsDOMEvent::GetTarget(nsIDOMEventTarget
** aTarget
)
248 return GetDOMEventTarget(mEvent
->target
, aTarget
);
252 nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget
** aCurrentTarget
)
254 return GetDOMEventTarget(mEvent
->currentTarget
, aCurrentTarget
);
258 // Get the actual event target node (may have been retargeted for mouse events)
260 already_AddRefed
<nsIDOMEventTarget
>
261 nsDOMEvent::GetTargetFromFrame()
263 if (!mPresContext
) { return nsnull
; }
265 // Get the target frame (have to get the ESM first)
266 nsIFrame
* targetFrame
= nsnull
;
267 mPresContext
->EventStateManager()->GetEventTarget(&targetFrame
);
268 if (!targetFrame
) { return nsnull
; }
270 // get the real content
271 nsCOMPtr
<nsIContent
> realEventContent
;
272 targetFrame
->GetContentForEvent(mPresContext
, mEvent
, getter_AddRefs(realEventContent
));
273 if (!realEventContent
) { return nsnull
; }
275 // Finally, we have the real content. QI it and return.
276 nsIDOMEventTarget
* target
= nsnull
;
277 CallQueryInterface(realEventContent
, &target
);
282 nsDOMEvent::GetExplicitOriginalTarget(nsIDOMEventTarget
** aRealEventTarget
)
284 if (mExplicitOriginalTarget
) {
285 *aRealEventTarget
= mExplicitOriginalTarget
;
286 NS_ADDREF(*aRealEventTarget
);
290 return GetTarget(aRealEventTarget
);
294 nsDOMEvent::GetTmpRealOriginalTarget(nsIDOMEventTarget
** aRealEventTarget
)
296 if (mTmpRealOriginalTarget
) {
297 *aRealEventTarget
= mTmpRealOriginalTarget
;
298 NS_ADDREF(*aRealEventTarget
);
302 return GetOriginalTarget(aRealEventTarget
);
306 nsDOMEvent::GetOriginalTarget(nsIDOMEventTarget
** aOriginalTarget
)
308 if (mEvent
->originalTarget
) {
309 return GetDOMEventTarget(mEvent
->originalTarget
, aOriginalTarget
);
312 return GetTarget(aOriginalTarget
);
316 nsDOMEvent::HasOriginalTarget(PRBool
* aResult
)
318 *aResult
= !!(mEvent
->originalTarget
);
323 nsDOMEvent::SetTrusted(PRBool aTrusted
)
326 mEvent
->flags
|= NS_EVENT_FLAG_TRUSTED
;
328 mEvent
->flags
&= ~NS_EVENT_FLAG_TRUSTED
;
335 nsDOMEvent::GetEventPhase(PRUint16
* aEventPhase
)
337 // Note, remember to check that this works also
338 // if or when Bug 235441 is fixed.
339 if (mEvent
->currentTarget
== mEvent
->target
||
340 ((mEvent
->flags
& NS_EVENT_FLAG_CAPTURE
) &&
341 (mEvent
->flags
& NS_EVENT_FLAG_BUBBLE
))) {
342 *aEventPhase
= nsIDOMEvent::AT_TARGET
;
343 } else if (mEvent
->flags
& NS_EVENT_FLAG_CAPTURE
) {
344 *aEventPhase
= nsIDOMEvent::CAPTURING_PHASE
;
345 } else if (mEvent
->flags
& NS_EVENT_FLAG_BUBBLE
) {
346 *aEventPhase
= nsIDOMEvent::BUBBLING_PHASE
;
354 nsDOMEvent::GetBubbles(PRBool
* aBubbles
)
356 *aBubbles
= !(mEvent
->flags
& NS_EVENT_FLAG_CANT_BUBBLE
);
361 nsDOMEvent::GetCancelable(PRBool
* aCancelable
)
363 *aCancelable
= !(mEvent
->flags
& NS_EVENT_FLAG_CANT_CANCEL
);
368 nsDOMEvent::GetTimeStamp(PRUint64
* aTimeStamp
)
370 LL_UI2L(*aTimeStamp
, mEvent
->time
);
375 nsDOMEvent::StopPropagation()
377 mEvent
->flags
|= NS_EVENT_FLAG_STOP_DISPATCH
;
382 ReportUseOfDeprecatedMethod(nsEvent
* aEvent
, nsIDOMEvent
* aDOMEvent
,
383 const char* aWarning
)
385 nsCOMPtr
<nsIDocument
> doc
;
386 nsCOMPtr
<nsINode
> node
= do_QueryInterface(aEvent
->currentTarget
);
388 doc
= node
->GetOwnerDoc();
390 nsCOMPtr
<nsPIDOMWindow
> window
= do_QueryInterface(aEvent
->currentTarget
);
392 doc
= do_QueryInterface(window
->GetExtantDocument());
397 aDOMEvent
->GetType(type
);
398 const PRUnichar
*strings
[] = { type
.get() };
399 nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES
,
401 strings
, NS_ARRAY_LENGTH(strings
),
402 doc
? doc
->GetDocumentURI() : nsnull
,
404 nsIScriptError::warningFlag
,
409 nsDOMEvent::PreventBubble()
411 ReportUseOfDeprecatedMethod(mEvent
, this, "UseOfPreventBubbleWarning");
416 nsDOMEvent::PreventCapture()
418 ReportUseOfDeprecatedMethod(mEvent
, this, "UseOfPreventCaptureWarning");
423 nsDOMEvent::GetIsTrusted(PRBool
*aIsTrusted
)
425 *aIsTrusted
= NS_IS_TRUSTED_EVENT(mEvent
);
431 nsDOMEvent::PreventDefault()
433 if (!(mEvent
->flags
& NS_EVENT_FLAG_CANT_CANCEL
)) {
434 mEvent
->flags
|= NS_EVENT_FLAG_NO_DEFAULT
;
440 nsDOMEvent::SetEventType(const nsAString
& aEventTypeArg
)
442 nsCOMPtr
<nsIAtom
> atom
= do_GetAtom(NS_LITERAL_STRING("on") + aEventTypeArg
);
443 mEvent
->message
= NS_USER_DEFINED_EVENT
;
445 if (mEvent
->eventStructType
== NS_MOUSE_EVENT
) {
446 if (atom
== nsGkAtoms::onmousedown
)
447 mEvent
->message
= NS_MOUSE_BUTTON_DOWN
;
448 else if (atom
== nsGkAtoms::onmouseup
)
449 mEvent
->message
= NS_MOUSE_BUTTON_UP
;
450 else if (atom
== nsGkAtoms::onclick
)
451 mEvent
->message
= NS_MOUSE_CLICK
;
452 else if (atom
== nsGkAtoms::ondblclick
)
453 mEvent
->message
= NS_MOUSE_DOUBLECLICK
;
454 else if (atom
== nsGkAtoms::onmouseover
)
455 mEvent
->message
= NS_MOUSE_ENTER_SYNTH
;
456 else if (atom
== nsGkAtoms::onmouseout
)
457 mEvent
->message
= NS_MOUSE_EXIT_SYNTH
;
458 else if (atom
== nsGkAtoms::onmousemove
)
459 mEvent
->message
= NS_MOUSE_MOVE
;
460 else if (atom
== nsGkAtoms::oncontextmenu
)
461 mEvent
->message
= NS_CONTEXTMENU
;
462 } else if (mEvent
->eventStructType
== NS_MOUSE_SCROLL_EVENT
) {
463 if (atom
== nsGkAtoms::onDOMMouseScroll
)
464 mEvent
->message
= NS_MOUSE_SCROLL
;
465 } else if (mEvent
->eventStructType
== NS_KEY_EVENT
) {
466 if (atom
== nsGkAtoms::onkeydown
)
467 mEvent
->message
= NS_KEY_DOWN
;
468 else if (atom
== nsGkAtoms::onkeyup
)
469 mEvent
->message
= NS_KEY_UP
;
470 else if (atom
== nsGkAtoms::onkeypress
)
471 mEvent
->message
= NS_KEY_PRESS
;
472 } else if (mEvent
->eventStructType
== NS_COMPOSITION_EVENT
) {
473 if (atom
== nsGkAtoms::oncompositionstart
)
474 mEvent
->message
= NS_COMPOSITION_START
;
475 else if (atom
== nsGkAtoms::oncompositionend
)
476 mEvent
->message
= NS_COMPOSITION_END
;
477 } else if (mEvent
->eventStructType
== NS_EVENT
) {
478 if (atom
== nsGkAtoms::onfocus
)
479 mEvent
->message
= NS_FOCUS_CONTENT
;
480 else if (atom
== nsGkAtoms::onblur
)
481 mEvent
->message
= NS_BLUR_CONTENT
;
482 else if (atom
== nsGkAtoms::onsubmit
)
483 mEvent
->message
= NS_FORM_SUBMIT
;
484 else if (atom
== nsGkAtoms::onreset
)
485 mEvent
->message
= NS_FORM_RESET
;
486 else if (atom
== nsGkAtoms::onchange
)
487 mEvent
->message
= NS_FORM_CHANGE
;
488 else if (atom
== nsGkAtoms::onselect
)
489 mEvent
->message
= NS_FORM_SELECTED
;
490 else if (atom
== nsGkAtoms::onload
)
491 mEvent
->message
= NS_LOAD
;
492 else if (atom
== nsGkAtoms::onunload
)
493 mEvent
->message
= NS_PAGE_UNLOAD
;
494 else if (atom
== nsGkAtoms::onabort
)
495 mEvent
->message
= NS_IMAGE_ABORT
;
496 else if (atom
== nsGkAtoms::onerror
)
497 mEvent
->message
= NS_LOAD_ERROR
;
498 else if (atom
== nsGkAtoms::onoffline
)
499 mEvent
->message
= NS_OFFLINE
;
500 else if (atom
== nsGkAtoms::ononline
)
501 mEvent
->message
= NS_ONLINE
;
502 else if (atom
== nsGkAtoms::oncopy
)
503 mEvent
->message
= NS_COPY
;
504 else if (atom
== nsGkAtoms::oncut
)
505 mEvent
->message
= NS_CUT
;
506 else if (atom
== nsGkAtoms::onpaste
)
507 mEvent
->message
= NS_PASTE
;
508 } else if (mEvent
->eventStructType
== NS_MUTATION_EVENT
) {
509 if (atom
== nsGkAtoms::onDOMAttrModified
)
510 mEvent
->message
= NS_MUTATION_ATTRMODIFIED
;
511 else if (atom
== nsGkAtoms::onDOMCharacterDataModified
)
512 mEvent
->message
= NS_MUTATION_CHARACTERDATAMODIFIED
;
513 else if (atom
== nsGkAtoms::onDOMNodeInserted
)
514 mEvent
->message
= NS_MUTATION_NODEINSERTED
;
515 else if (atom
== nsGkAtoms::onDOMNodeRemoved
)
516 mEvent
->message
= NS_MUTATION_NODEREMOVED
;
517 else if (atom
== nsGkAtoms::onDOMNodeInsertedIntoDocument
)
518 mEvent
->message
= NS_MUTATION_NODEINSERTEDINTODOCUMENT
;
519 else if (atom
== nsGkAtoms::onDOMNodeRemovedFromDocument
)
520 mEvent
->message
= NS_MUTATION_NODEREMOVEDFROMDOCUMENT
;
521 else if (atom
== nsGkAtoms::onDOMSubtreeModified
)
522 mEvent
->message
= NS_MUTATION_SUBTREEMODIFIED
;
523 } else if (mEvent
->eventStructType
== NS_UI_EVENT
) {
524 if (atom
== nsGkAtoms::onDOMActivate
)
525 mEvent
->message
= NS_UI_ACTIVATE
;
526 else if (atom
== nsGkAtoms::onDOMFocusIn
)
527 mEvent
->message
= NS_UI_FOCUSIN
;
528 else if (atom
== nsGkAtoms::onDOMFocusOut
)
529 mEvent
->message
= NS_UI_FOCUSOUT
;
530 else if (atom
== nsGkAtoms::oninput
)
531 mEvent
->message
= NS_FORM_INPUT
;
532 } else if (mEvent
->eventStructType
== NS_PAGETRANSITION_EVENT
) {
533 if (atom
== nsGkAtoms::onpageshow
)
534 mEvent
->message
= NS_PAGE_SHOW
;
535 else if (atom
== nsGkAtoms::onpagehide
)
536 mEvent
->message
= NS_PAGE_HIDE
;
537 } else if (mEvent
->eventStructType
== NS_XUL_COMMAND_EVENT
) {
538 if (atom
== nsGkAtoms::oncommand
)
539 mEvent
->message
= NS_XUL_COMMAND
;
542 else if (mEvent
->eventStructType
== NS_SVG_EVENT
) {
543 if (atom
== nsGkAtoms::onSVGLoad
)
544 mEvent
->message
= NS_SVG_LOAD
;
545 else if (atom
== nsGkAtoms::onSVGUnload
)
546 mEvent
->message
= NS_SVG_UNLOAD
;
547 else if (atom
== nsGkAtoms::onSVGAbort
)
548 mEvent
->message
= NS_SVG_ABORT
;
549 else if (atom
== nsGkAtoms::onSVGError
)
550 mEvent
->message
= NS_SVG_ERROR
;
551 else if (atom
== nsGkAtoms::onSVGResize
)
552 mEvent
->message
= NS_SVG_RESIZE
;
553 else if (atom
== nsGkAtoms::onSVGScroll
)
554 mEvent
->message
= NS_SVG_SCROLL
;
555 } else if (mEvent
->eventStructType
== NS_SVGZOOM_EVENT
) {
556 if (atom
== nsGkAtoms::onSVGZoom
)
557 mEvent
->message
= NS_SVG_ZOOM
;
561 if (mEvent
->message
== NS_USER_DEFINED_EVENT
)
562 mEvent
->userType
= atom
;
568 nsDOMEvent::InitEvent(const nsAString
& aEventTypeArg
, PRBool aCanBubbleArg
, PRBool aCancelableArg
)
570 // Make sure this event isn't already being dispatched.
571 NS_ENSURE_TRUE(!NS_IS_EVENT_IN_DISPATCH(mEvent
), NS_ERROR_INVALID_ARG
);
573 if (NS_IS_TRUSTED_EVENT(mEvent
)) {
574 // Ensure the caller is permitted to dispatch trusted DOM events.
576 PRBool enabled
= PR_FALSE
;
577 nsContentUtils::GetSecurityManager()->
578 IsCapabilityEnabled("UniversalBrowserWrite", &enabled
);
581 SetTrusted(PR_FALSE
);
585 NS_ENSURE_SUCCESS(SetEventType(aEventTypeArg
), NS_ERROR_FAILURE
);
588 mEvent
->flags
&= ~NS_EVENT_FLAG_CANT_BUBBLE
;
590 mEvent
->flags
|= NS_EVENT_FLAG_CANT_BUBBLE
;
593 if (aCancelableArg
) {
594 mEvent
->flags
&= ~NS_EVENT_FLAG_CANT_CANCEL
;
596 mEvent
->flags
|= NS_EVENT_FLAG_CANT_CANCEL
;
599 // Clearing the old targets, so that the event is targeted correctly when
600 // re-dispatching it.
601 mEvent
->target
= nsnull
;
602 mEvent
->originalTarget
= nsnull
;
607 NS_METHOD
nsDOMEvent::DuplicatePrivateData()
609 // FIXME! Simplify this method and make it somehow easily extendable,
612 NS_ASSERTION(mEvent
, "No nsEvent for nsDOMEvent duplication!");
613 if (mEventIsInternal
) {
617 nsEvent
* newEvent
= nsnull
;
618 PRUint32 msg
= mEvent
->message
;
619 PRBool isInputEvent
= PR_FALSE
;
621 switch (mEvent
->eventStructType
) {
624 newEvent
= new nsEvent(PR_FALSE
, msg
);
629 // Not copying widget, it is a weak reference.
630 newEvent
= new nsGUIEvent(PR_FALSE
, msg
, nsnull
);
635 nsSizeEvent
* sizeEvent
= new nsSizeEvent(PR_FALSE
, msg
, nsnull
);
636 NS_ENSURE_TRUE(sizeEvent
, NS_ERROR_OUT_OF_MEMORY
);
637 sizeEvent
->mWinWidth
= static_cast<nsSizeEvent
*>(mEvent
)->mWinWidth
;
638 sizeEvent
->mWinHeight
= static_cast<nsSizeEvent
*>(mEvent
)->mWinHeight
;
639 newEvent
= sizeEvent
;
642 case NS_SIZEMODE_EVENT
:
644 newEvent
= new nsSizeModeEvent(PR_FALSE
, msg
, nsnull
);
645 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
646 static_cast<nsSizeModeEvent
*>(newEvent
)->mSizeMode
=
647 static_cast<nsSizeModeEvent
*>(mEvent
)->mSizeMode
;
650 case NS_ZLEVEL_EVENT
:
652 nsZLevelEvent
* zLevelEvent
= new nsZLevelEvent(PR_FALSE
, msg
, nsnull
);
653 NS_ENSURE_TRUE(zLevelEvent
, NS_ERROR_OUT_OF_MEMORY
);
654 nsZLevelEvent
* oldZLevelEvent
= static_cast<nsZLevelEvent
*>(mEvent
);
655 zLevelEvent
->mPlacement
= oldZLevelEvent
->mPlacement
;
656 zLevelEvent
->mImmediate
= oldZLevelEvent
->mImmediate
;
657 zLevelEvent
->mAdjusted
= oldZLevelEvent
->mAdjusted
;
658 newEvent
= zLevelEvent
;
663 newEvent
= new nsPaintEvent(PR_FALSE
, msg
, nsnull
);
666 case NS_SCROLLBAR_EVENT
:
668 newEvent
= new nsScrollbarEvent(PR_FALSE
, msg
, nsnull
);
669 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
670 static_cast<nsScrollbarEvent
*>(newEvent
)->position
=
671 static_cast<nsScrollbarEvent
*>(mEvent
)->position
;
676 newEvent
= new nsInputEvent(PR_FALSE
, msg
, nsnull
);
677 isInputEvent
= PR_TRUE
;
682 nsKeyEvent
* keyEvent
= new nsKeyEvent(PR_FALSE
, msg
, nsnull
);
683 NS_ENSURE_TRUE(keyEvent
, NS_ERROR_OUT_OF_MEMORY
);
684 nsKeyEvent
* oldKeyEvent
= static_cast<nsKeyEvent
*>(mEvent
);
685 isInputEvent
= PR_TRUE
;
686 keyEvent
->keyCode
= oldKeyEvent
->keyCode
;
687 keyEvent
->charCode
= oldKeyEvent
->charCode
;
688 keyEvent
->isChar
= oldKeyEvent
->isChar
;
694 nsMouseEvent
* oldMouseEvent
= static_cast<nsMouseEvent
*>(mEvent
);
695 nsMouseEvent
* mouseEvent
=
696 new nsMouseEvent(PR_FALSE
, msg
, nsnull
, oldMouseEvent
->reason
);
697 NS_ENSURE_TRUE(mouseEvent
, NS_ERROR_OUT_OF_MEMORY
);
698 isInputEvent
= PR_TRUE
;
699 mouseEvent
->clickCount
= oldMouseEvent
->clickCount
;
700 mouseEvent
->acceptActivation
= oldMouseEvent
->acceptActivation
;
701 mouseEvent
->context
= oldMouseEvent
->context
;
702 mouseEvent
->relatedTarget
= oldMouseEvent
->relatedTarget
;
703 mouseEvent
->button
= oldMouseEvent
->button
;
704 newEvent
= mouseEvent
;
709 newEvent
= new nsMenuEvent(PR_FALSE
, msg
, nsnull
);
710 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
711 static_cast<nsMenuEvent
*>(newEvent
)->mCommand
=
712 static_cast<nsMenuEvent
*>(mEvent
)->mCommand
;
715 case NS_SCRIPT_ERROR_EVENT
:
717 newEvent
= new nsScriptErrorEvent(PR_FALSE
, msg
);
718 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
719 static_cast<nsScriptErrorEvent
*>(newEvent
)->lineNr
=
720 static_cast<nsScriptErrorEvent
*>(mEvent
)->lineNr
;
725 newEvent
= new nsTextEvent(PR_FALSE
, msg
, nsnull
);
726 isInputEvent
= PR_TRUE
;
729 case NS_COMPOSITION_EVENT
:
731 newEvent
= new nsCompositionEvent(PR_FALSE
, msg
, nsnull
);
732 isInputEvent
= PR_TRUE
;
735 case NS_RECONVERSION_EVENT
:
737 newEvent
= new nsReconversionEvent(PR_FALSE
, msg
, nsnull
);
738 isInputEvent
= PR_TRUE
;
741 case NS_MOUSE_SCROLL_EVENT
:
743 nsMouseScrollEvent
* mouseScrollEvent
=
744 new nsMouseScrollEvent(PR_FALSE
, msg
, nsnull
);
745 NS_ENSURE_TRUE(mouseScrollEvent
, NS_ERROR_OUT_OF_MEMORY
);
746 isInputEvent
= PR_TRUE
;
747 nsMouseScrollEvent
* oldMouseScrollEvent
=
748 static_cast<nsMouseScrollEvent
*>(mEvent
);
749 mouseScrollEvent
->scrollFlags
= oldMouseScrollEvent
->scrollFlags
;
750 mouseScrollEvent
->delta
= oldMouseScrollEvent
->delta
;
751 mouseScrollEvent
->relatedTarget
= oldMouseScrollEvent
->relatedTarget
;
752 mouseScrollEvent
->button
= oldMouseScrollEvent
->button
;
753 newEvent
= mouseScrollEvent
;
756 case NS_SCROLLPORT_EVENT
:
758 newEvent
= new nsScrollPortEvent(PR_FALSE
, msg
, nsnull
);
759 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
760 static_cast<nsScrollPortEvent
*>(newEvent
)->orient
=
761 static_cast<nsScrollPortEvent
*>(mEvent
)->orient
;
764 case NS_MUTATION_EVENT
:
766 nsMutationEvent
* mutationEvent
= new nsMutationEvent(PR_FALSE
, msg
);
767 NS_ENSURE_TRUE(mutationEvent
, NS_ERROR_OUT_OF_MEMORY
);
768 nsMutationEvent
* oldMutationEvent
=
769 static_cast<nsMutationEvent
*>(mEvent
);
770 mutationEvent
->mRelatedNode
= oldMutationEvent
->mRelatedNode
;
771 mutationEvent
->mAttrName
= oldMutationEvent
->mAttrName
;
772 mutationEvent
->mPrevAttrValue
= oldMutationEvent
->mPrevAttrValue
;
773 mutationEvent
->mNewAttrValue
= oldMutationEvent
->mNewAttrValue
;
774 mutationEvent
->mAttrChange
= oldMutationEvent
->mAttrChange
;
775 newEvent
= mutationEvent
;
778 case NS_ACCESSIBLE_EVENT
:
780 newEvent
= new nsAccessibleEvent(PR_FALSE
, msg
, nsnull
);
781 isInputEvent
= PR_TRUE
;
786 newEvent
= new nsFormEvent(PR_FALSE
, msg
);
791 newEvent
= new nsFocusEvent(PR_FALSE
, msg
, nsnull
);
792 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
793 static_cast<nsFocusEvent
*>(newEvent
)->isMozWindowTakingFocus
=
794 static_cast<nsFocusEvent
*>(mEvent
)->isMozWindowTakingFocus
;
799 newEvent
= new nsInputEvent(PR_FALSE
, msg
, nsnull
);
800 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
801 isInputEvent
= PR_TRUE
;
802 newEvent
->eventStructType
= NS_POPUP_EVENT
;
805 case NS_COMMAND_EVENT
:
807 newEvent
= new nsCommandEvent(PR_FALSE
, mEvent
->userType
,
808 static_cast<nsCommandEvent
*>(mEvent
)->command
, nsnull
);
809 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
812 case NS_POPUPBLOCKED_EVENT
:
814 NS_WARNING("nsPopupBlockedEvent should never be an external event!");
815 newEvent
= new nsPopupBlockedEvent(PR_FALSE
, msg
);
818 case NS_BEFORE_PAGE_UNLOAD_EVENT
:
820 newEvent
= new nsBeforePageUnloadEvent(PR_FALSE
, msg
);
821 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
822 static_cast<nsBeforePageUnloadEvent
*>(newEvent
)->text
=
823 static_cast<nsBeforePageUnloadEvent
*>(mEvent
)->text
;
828 newEvent
= new nsUIEvent(PR_FALSE
, msg
,
829 static_cast<nsUIEvent
*>(mEvent
)->detail
);
832 case NS_QUERYCARETRECT_EVENT
:
834 newEvent
= new nsQueryCaretRectEvent(PR_FALSE
, msg
, nsnull
);
835 isInputEvent
= PR_TRUE
;
838 case NS_PAGETRANSITION_EVENT
:
841 new nsPageTransitionEvent(PR_FALSE
, msg
,
842 ((nsPageTransitionEvent
*) mEvent
)->persisted
);
848 newEvent
= new nsEvent(PR_FALSE
, msg
);
849 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
850 newEvent
->eventStructType
= NS_SVG_EVENT
;
853 case NS_SVGZOOM_EVENT
:
855 newEvent
= new nsGUIEvent(PR_FALSE
, msg
, nsnull
);
856 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
857 newEvent
->eventStructType
= NS_SVGZOOM_EVENT
;
861 case NS_XUL_COMMAND_EVENT
:
863 newEvent
= new nsXULCommandEvent(PR_FALSE
, msg
, nsnull
);
864 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
865 isInputEvent
= PR_TRUE
;
866 newEvent
->eventStructType
= NS_XUL_COMMAND_EVENT
;
867 static_cast<nsXULCommandEvent
*>(newEvent
)->sourceEvent
=
868 static_cast<nsXULCommandEvent
*>(mEvent
)->sourceEvent
;
873 NS_WARNING("Unknown event type!!!");
874 return NS_ERROR_FAILURE
;
878 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
881 nsInputEvent
* oldInputEvent
= static_cast<nsInputEvent
*>(mEvent
);
882 nsInputEvent
* newInputEvent
= static_cast<nsInputEvent
*>(newEvent
);
883 newInputEvent
->isShift
= oldInputEvent
->isShift
;
884 newInputEvent
->isControl
= oldInputEvent
->isControl
;
885 newInputEvent
->isAlt
= oldInputEvent
->isAlt
;
886 newInputEvent
->isMeta
= oldInputEvent
->isMeta
;
889 newEvent
->target
= mEvent
->target
;
890 newEvent
->currentTarget
= mEvent
->currentTarget
;
891 newEvent
->originalTarget
= mEvent
->originalTarget
;
892 newEvent
->flags
= mEvent
->flags
;
893 newEvent
->time
= mEvent
->time
;
894 newEvent
->refPoint
= mEvent
->refPoint
;
895 newEvent
->userType
= mEvent
->userType
;
898 mPresContext
= nsnull
;
899 mEventIsInternal
= PR_TRUE
;
900 mPrivateDataDuplicated
= PR_TRUE
;
905 NS_METHOD
nsDOMEvent::SetTarget(nsIDOMEventTarget
* aTarget
)
909 nsCOMPtr
<nsPIDOMWindow
> win
= do_QueryInterface(aTarget
);
911 NS_ASSERTION(!win
|| !win
->IsInnerWindow(),
912 "Uh, inner window set as event target!");
916 mEvent
->target
= aTarget
;
920 NS_METHOD
nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget
* aCurrentTarget
)
924 nsCOMPtr
<nsPIDOMWindow
> win
= do_QueryInterface(aCurrentTarget
);
926 NS_ASSERTION(!win
|| !win
->IsInnerWindow(),
927 "Uh, inner window set as event target!");
931 mEvent
->currentTarget
= aCurrentTarget
;
935 NS_METHOD
nsDOMEvent::SetOriginalTarget(nsIDOMEventTarget
* aOriginalTarget
)
939 nsCOMPtr
<nsPIDOMWindow
> win
= do_QueryInterface(aOriginalTarget
);
941 NS_ASSERTION(!win
|| !win
->IsInnerWindow(),
942 "Uh, inner window set as event target!");
946 mEvent
->originalTarget
= aOriginalTarget
;
951 nsDOMEvent::IsDispatchStopped(PRBool
* aIsDispatchStopped
)
953 if (mEvent
->flags
& NS_EVENT_FLAG_STOP_DISPATCH
) {
954 *aIsDispatchStopped
= PR_TRUE
;
956 *aIsDispatchStopped
= PR_FALSE
;
962 nsDOMEvent::GetInternalNSEvent(nsEvent
** aNSEvent
)
964 NS_ENSURE_ARG_POINTER(aNSEvent
);
969 // return true if eventName is contained within events, delimited by
972 PopupAllowedForEvent(const char *eventName
)
974 if (!sPopupAllowedEvents
) {
975 nsDOMEvent::PopupAllowedEventsChanged();
977 if (!sPopupAllowedEvents
) {
982 nsDependentCString
events(sPopupAllowedEvents
);
984 nsAFlatCString::const_iterator start
, end
;
985 nsAFlatCString::const_iterator
startiter(events
.BeginReading(start
));
986 events
.EndReading(end
);
988 while (startiter
!= end
) {
989 nsAFlatCString::const_iterator
enditer(end
);
991 if (!FindInReadable(nsDependentCString(eventName
), startiter
, enditer
))
994 // the match is surrounded by spaces, or at a string boundary
995 if ((startiter
== start
|| *--startiter
== ' ') &&
996 (enditer
== end
|| *enditer
== ' ')) {
1000 // Move on and see if there are other matches. (The delimitation
1001 // requirement makes it pointless to begin the next search before
1002 // the end of the invalid match just found.)
1003 startiter
= enditer
;
1011 nsDOMEvent::GetEventPopupControlState(nsEvent
*aEvent
)
1013 // generally if an event handler is running, new windows are disallowed.
1014 // check for exceptions:
1015 PopupControlState abuse
= openAbused
;
1017 switch(aEvent
->eventStructType
) {
1019 // For these following events only allow popups if they're
1020 // triggered while handling user input. See
1021 // nsPresShell::HandleEventInternal() for details.
1022 if (nsEventStateManager::IsHandlingUserInput()) {
1023 switch(aEvent
->message
) {
1024 case NS_FORM_SELECTED
:
1025 if (::PopupAllowedForEvent("select"))
1026 abuse
= openControlled
;
1028 case NS_FORM_CHANGE
:
1029 if (::PopupAllowedForEvent("change"))
1030 abuse
= openControlled
;
1036 // For this following event only allow popups if it's triggered
1037 // while handling user input. See
1038 // nsPresShell::HandleEventInternal() for details.
1039 if (nsEventStateManager::IsHandlingUserInput()) {
1040 switch(aEvent
->message
) {
1041 case NS_FORM_INPUT
:
1042 if (::PopupAllowedForEvent("input"))
1043 abuse
= openControlled
;
1048 case NS_INPUT_EVENT
:
1049 // For this following event only allow popups if it's triggered
1050 // while handling user input. See
1051 // nsPresShell::HandleEventInternal() for details.
1052 if (nsEventStateManager::IsHandlingUserInput()) {
1053 switch(aEvent
->message
) {
1054 case NS_FORM_CHANGE
:
1055 if (::PopupAllowedForEvent("change"))
1056 abuse
= openControlled
;
1062 if (NS_IS_TRUSTED_EVENT(aEvent
)) {
1063 PRUint32 key
= static_cast<nsKeyEvent
*>(aEvent
)->keyCode
;
1064 switch(aEvent
->message
) {
1066 // return key on focused button. see note at NS_MOUSE_CLICK.
1067 if (key
== nsIDOMKeyEvent::DOM_VK_RETURN
)
1068 abuse
= openAllowed
;
1069 else if (::PopupAllowedForEvent("keypress"))
1070 abuse
= openControlled
;
1073 // space key on focused button. see note at NS_MOUSE_CLICK.
1074 if (key
== nsIDOMKeyEvent::DOM_VK_SPACE
)
1075 abuse
= openAllowed
;
1076 else if (::PopupAllowedForEvent("keyup"))
1077 abuse
= openControlled
;
1080 if (::PopupAllowedForEvent("keydown"))
1081 abuse
= openControlled
;
1086 case NS_MOUSE_EVENT
:
1087 if (NS_IS_TRUSTED_EVENT(aEvent
) &&
1088 static_cast<nsMouseEvent
*>(aEvent
)->button
== nsMouseEvent::eLeftButton
) {
1089 switch(aEvent
->message
) {
1090 case NS_MOUSE_BUTTON_UP
:
1091 if (::PopupAllowedForEvent("mouseup"))
1092 abuse
= openControlled
;
1094 case NS_MOUSE_BUTTON_DOWN
:
1095 if (::PopupAllowedForEvent("mousedown"))
1096 abuse
= openControlled
;
1098 case NS_MOUSE_CLICK
:
1099 /* Click events get special treatment because of their
1100 historical status as a more legitimate event handler. If
1101 click popups are enabled in the prefs, clear the popup
1102 status completely. */
1103 if (::PopupAllowedForEvent("click"))
1104 abuse
= openAllowed
;
1106 case NS_MOUSE_DOUBLECLICK
:
1107 if (::PopupAllowedForEvent("dblclick"))
1108 abuse
= openControlled
;
1113 case NS_SCRIPT_ERROR_EVENT
:
1114 switch(aEvent
->message
) {
1115 case NS_LOAD_ERROR
:
1116 // Any error event will allow popups, if enabled in the pref.
1117 if (::PopupAllowedForEvent("error"))
1118 abuse
= openControlled
;
1122 case NS_FORM_EVENT
:
1123 // For these following events only allow popups if they're
1124 // triggered while handling user input. See
1125 // nsPresShell::HandleEventInternal() for details.
1126 if (nsEventStateManager::IsHandlingUserInput()) {
1127 switch(aEvent
->message
) {
1128 case NS_FORM_SUBMIT
:
1129 if (::PopupAllowedForEvent("submit"))
1130 abuse
= openControlled
;
1132 case NS_FORM_RESET
:
1133 if (::PopupAllowedForEvent("reset"))
1134 abuse
= openControlled
;
1139 case NS_XUL_COMMAND_EVENT
:
1140 if (nsEventStateManager::IsHandlingUserInput()) {
1141 abuse
= openControlled
;
1150 nsDOMEvent::PopupAllowedEventsChanged()
1152 if (sPopupAllowedEvents
) {
1153 nsMemory::Free(sPopupAllowedEvents
);
1156 nsAdoptingCString str
=
1157 nsContentUtils::GetCharPref("dom.popup_allowed_events");
1159 // We'll want to do this even if str is empty to avoid looking up
1160 // this pref all the time if it's not set.
1161 sPopupAllowedEvents
= ToNewCString(str
);
1166 nsDOMEvent::Shutdown()
1168 if (sPopupAllowedEvents
) {
1169 nsMemory::Free(sPopupAllowedEvents
);
1173 // To be called ONLY by nsDOMEvent::GetType (which has the additional
1174 // logic for handling user-defined events).
1176 const char* nsDOMEvent::GetEventName(PRUint32 aEventType
)
1178 switch(aEventType
) {
1179 case NS_MOUSE_BUTTON_DOWN
:
1180 return sEventNames
[eDOMEvents_mousedown
];
1181 case NS_MOUSE_BUTTON_UP
:
1182 return sEventNames
[eDOMEvents_mouseup
];
1183 case NS_MOUSE_CLICK
:
1184 return sEventNames
[eDOMEvents_click
];
1185 case NS_MOUSE_DOUBLECLICK
:
1186 return sEventNames
[eDOMEvents_dblclick
];
1187 case NS_MOUSE_ENTER_SYNTH
:
1188 return sEventNames
[eDOMEvents_mouseover
];
1189 case NS_MOUSE_EXIT_SYNTH
:
1190 return sEventNames
[eDOMEvents_mouseout
];
1192 return sEventNames
[eDOMEvents_mousemove
];
1194 return sEventNames
[eDOMEvents_keyup
];
1196 return sEventNames
[eDOMEvents_keydown
];
1198 return sEventNames
[eDOMEvents_keypress
];
1199 case NS_COMPOSITION_START
:
1200 return sEventNames
[eDOMEvents_compositionstart
];
1201 case NS_COMPOSITION_END
:
1202 return sEventNames
[eDOMEvents_compositionend
];
1203 case NS_FOCUS_CONTENT
:
1204 return sEventNames
[eDOMEvents_focus
];
1205 case NS_BLUR_CONTENT
:
1206 return sEventNames
[eDOMEvents_blur
];
1208 return sEventNames
[eDOMEvents_close
];
1210 return sEventNames
[eDOMEvents_load
];
1211 case NS_BEFORE_PAGE_UNLOAD
:
1212 return sEventNames
[eDOMEvents_beforeunload
];
1213 case NS_PAGE_UNLOAD
:
1214 return sEventNames
[eDOMEvents_unload
];
1215 case NS_IMAGE_ABORT
:
1216 return sEventNames
[eDOMEvents_abort
];
1218 return sEventNames
[eDOMEvents_error
];
1219 case NS_FORM_SUBMIT
:
1220 return sEventNames
[eDOMEvents_submit
];
1222 return sEventNames
[eDOMEvents_reset
];
1223 case NS_FORM_CHANGE
:
1224 return sEventNames
[eDOMEvents_change
];
1225 case NS_FORM_SELECTED
:
1226 return sEventNames
[eDOMEvents_select
];
1228 return sEventNames
[eDOMEvents_input
];
1230 return sEventNames
[eDOMEvents_paint
];
1231 case NS_RESIZE_EVENT
:
1232 return sEventNames
[eDOMEvents_resize
];
1233 case NS_SCROLL_EVENT
:
1234 return sEventNames
[eDOMEvents_scroll
];
1236 return sEventNames
[eDOMEvents_text
];
1237 case NS_XUL_POPUP_SHOWING
:
1238 return sEventNames
[eDOMEvents_popupShowing
];
1239 case NS_XUL_POPUP_SHOWN
:
1240 return sEventNames
[eDOMEvents_popupShown
];
1241 case NS_XUL_POPUP_HIDING
:
1242 return sEventNames
[eDOMEvents_popupHiding
];
1243 case NS_XUL_POPUP_HIDDEN
:
1244 return sEventNames
[eDOMEvents_popupHidden
];
1245 case NS_XUL_COMMAND
:
1246 return sEventNames
[eDOMEvents_command
];
1247 case NS_XUL_BROADCAST
:
1248 return sEventNames
[eDOMEvents_broadcast
];
1249 case NS_XUL_COMMAND_UPDATE
:
1250 return sEventNames
[eDOMEvents_commandupdate
];
1251 case NS_DRAGDROP_ENTER
:
1252 return sEventNames
[eDOMEvents_dragenter
];
1253 case NS_DRAGDROP_OVER_SYNTH
:
1254 return sEventNames
[eDOMEvents_dragover
];
1255 case NS_DRAGDROP_EXIT_SYNTH
:
1256 return sEventNames
[eDOMEvents_dragexit
];
1257 case NS_DRAGDROP_DROP
:
1258 return sEventNames
[eDOMEvents_dragdrop
];
1259 case NS_DRAGDROP_GESTURE
:
1260 return sEventNames
[eDOMEvents_draggesture
];
1261 case NS_DRAGDROP_DRAG
:
1262 return sEventNames
[eDOMEvents_drag
];
1263 case NS_DRAGDROP_END
:
1264 return sEventNames
[eDOMEvents_dragend
];
1265 case NS_SCROLLPORT_OVERFLOW
:
1266 return sEventNames
[eDOMEvents_overflow
];
1267 case NS_SCROLLPORT_UNDERFLOW
:
1268 return sEventNames
[eDOMEvents_underflow
];
1269 case NS_SCROLLPORT_OVERFLOWCHANGED
:
1270 return sEventNames
[eDOMEvents_overflowchanged
];
1271 case NS_MUTATION_SUBTREEMODIFIED
:
1272 return sEventNames
[eDOMEvents_subtreemodified
];
1273 case NS_MUTATION_NODEINSERTED
:
1274 return sEventNames
[eDOMEvents_nodeinserted
];
1275 case NS_MUTATION_NODEREMOVED
:
1276 return sEventNames
[eDOMEvents_noderemoved
];
1277 case NS_MUTATION_NODEREMOVEDFROMDOCUMENT
:
1278 return sEventNames
[eDOMEvents_noderemovedfromdocument
];
1279 case NS_MUTATION_NODEINSERTEDINTODOCUMENT
:
1280 return sEventNames
[eDOMEvents_nodeinsertedintodocument
];
1281 case NS_MUTATION_ATTRMODIFIED
:
1282 return sEventNames
[eDOMEvents_attrmodified
];
1283 case NS_MUTATION_CHARACTERDATAMODIFIED
:
1284 return sEventNames
[eDOMEvents_characterdatamodified
];
1285 case NS_CONTEXTMENU
:
1286 return sEventNames
[eDOMEvents_contextmenu
];
1287 case NS_UI_ACTIVATE
:
1288 return sEventNames
[eDOMEvents_DOMActivate
];
1290 return sEventNames
[eDOMEvents_DOMFocusIn
];
1291 case NS_UI_FOCUSOUT
:
1292 return sEventNames
[eDOMEvents_DOMFocusOut
];
1294 return sEventNames
[eDOMEvents_pageshow
];
1296 return sEventNames
[eDOMEvents_pagehide
];
1297 case NS_MOUSE_SCROLL
:
1298 return sEventNames
[eDOMEvents_DOMMouseScroll
];
1300 return sEventNames
[eDOMEvents_offline
];
1302 return sEventNames
[eDOMEvents_online
];
1304 return sEventNames
[eDOMEvents_copy
];
1306 return sEventNames
[eDOMEvents_cut
];
1308 return sEventNames
[eDOMEvents_paste
];
1311 return sEventNames
[eDOMEvents_SVGLoad
];
1313 return sEventNames
[eDOMEvents_SVGUnload
];
1315 return sEventNames
[eDOMEvents_SVGAbort
];
1317 return sEventNames
[eDOMEvents_SVGError
];
1319 return sEventNames
[eDOMEvents_SVGResize
];
1321 return sEventNames
[eDOMEvents_SVGScroll
];
1323 return sEventNames
[eDOMEvents_SVGZoom
];
1328 // XXXldb We can hit this case for nsEvent objects that we didn't
1329 // create and that are not user defined events since this function and
1330 // SetEventType are incomplete. (But fixing that requires fixing the
1331 // arrays in nsEventListenerManager too, since the events for which
1332 // this is a problem generally *are* created by nsDOMEvent.)
1336 nsresult
NS_NewDOMEvent(nsIDOMEvent
** aInstancePtrResult
,
1337 nsPresContext
* aPresContext
,
1340 nsDOMEvent
* it
= new nsDOMEvent(aPresContext
, aEvent
);
1342 return NS_ERROR_OUT_OF_MEMORY
;
1345 return CallQueryInterface(it
, aInstancePtrResult
);