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", "dragstart", "dragleave", "drop", "resize",
68 "scroll", "overflow", "underflow", "overflowchanged",
69 "DOMSubtreeModified", "DOMNodeInserted", "DOMNodeRemoved",
70 "DOMNodeRemovedFromDocument", "DOMNodeInsertedIntoDocument",
71 "DOMAttrModified", "DOMCharacterDataModified",
72 "DOMActivate", "DOMFocusIn", "DOMFocusOut",
73 "pageshow", "pagehide", "DOMMouseScroll", "MozMousePixelScroll",
74 "offline", "online", "copy", "cut", "paste",
76 "SVGLoad", "SVGUnload", "SVGAbort", "SVGError", "SVGResize", "SVGScroll",
80 "loadstart", "progress", "loadedmetadata", "loadedfirstframe",
81 "emptied", "stalled", "play", "pause",
82 "waiting", "seeking", "seeked", "timeupdate", "ended", "dataunavailable",
83 "canshowcurrentframe", "canplay", "canplaythrough", "ratechange",
84 "durationchange", "volumechange",
88 "MozMagnifyGestureStart",
89 "MozMagnifyGestureUpdate",
91 "MozRotateGestureStart",
92 "MozRotateGestureUpdate",
96 static char *sPopupAllowedEvents
;
99 nsDOMEvent::nsDOMEvent(nsPresContext
* aPresContext
, nsEvent
* aEvent
)
101 mPresContext
= aPresContext
;
102 mPrivateDataDuplicated
= PR_FALSE
;
106 mEventIsInternal
= PR_FALSE
;
109 mEventIsInternal
= PR_TRUE
;
111 A derived class might want to allocate its own type of aEvent
112 (derived from nsEvent). To do this, it should take care to pass
113 a non-NULL aEvent to this ctor, e.g.:
115 nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
116 : nsDOMEvent(..., aEvent ? aEvent : new nsFooEvent())
118 Then, to override the mEventIsInternal assignments done by the
119 base ctor, it should do this in its own ctor:
121 nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
126 mEventIsInternal = PR_FALSE;
129 mEventIsInternal = PR_TRUE;
134 mEvent
= new nsEvent(PR_FALSE
, 0);
135 mEvent
->time
= PR_Now();
138 // Get the explicit original target (if it's anonymous make it null)
140 mExplicitOriginalTarget
= GetTargetFromFrame();
141 mTmpRealOriginalTarget
= mExplicitOriginalTarget
;
142 nsCOMPtr
<nsIContent
> content
= do_QueryInterface(mExplicitOriginalTarget
);
143 if (content
&& content
->IsInAnonymousSubtree()) {
144 mExplicitOriginalTarget
= nsnull
;
149 nsDOMEvent::~nsDOMEvent()
151 NS_ASSERT_OWNINGTHREAD(nsDOMEvent
);
153 if (mEventIsInternal
&& mEvent
) {
158 NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMEvent
)
160 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMEvent
)
161 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIDOMEvent
)
162 NS_INTERFACE_MAP_ENTRY(nsIDOMEvent
)
163 NS_INTERFACE_MAP_ENTRY(nsIDOMNSEvent
)
164 NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMEvent
)
165 NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Event
)
168 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMEvent
)
169 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMEvent
)
171 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMEvent
)
172 if (tmp
->mEventIsInternal
) {
173 tmp
->mEvent
->target
= nsnull
;
174 tmp
->mEvent
->currentTarget
= nsnull
;
175 tmp
->mEvent
->originalTarget
= nsnull
;
176 switch (tmp
->mEvent
->eventStructType
) {
178 case NS_MOUSE_SCROLL_EVENT
:
179 static_cast<nsMouseEvent_base
*>(tmp
->mEvent
)->relatedTarget
= nsnull
;
182 static_cast<nsDragEvent
*>(tmp
->mEvent
)->dataTransfer
= nsnull
;
184 case NS_XUL_COMMAND_EVENT
:
185 static_cast<nsXULCommandEvent
*>(tmp
->mEvent
)->sourceEvent
= nsnull
;
187 case NS_MUTATION_EVENT
:
188 static_cast<nsMutationEvent
*>(tmp
->mEvent
)->mRelatedNode
= nsnull
;
194 NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPresContext
);
195 NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTmpRealOriginalTarget
)
196 NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mExplicitOriginalTarget
)
197 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
199 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMEvent
)
200 if (tmp
->mEventIsInternal
) {
201 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEvent
->target
)
202 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEvent
->currentTarget
)
203 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEvent
->originalTarget
)
204 switch (tmp
->mEvent
->eventStructType
) {
206 case NS_MOUSE_SCROLL_EVENT
:
207 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb
, "mEvent->relatedTarget");
209 static_cast<nsMouseEvent_base
*>(tmp
->mEvent
)->relatedTarget
);
212 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb
, "mEvent->dataTransfer");
214 static_cast<nsDragEvent
*>(tmp
->mEvent
)->dataTransfer
);
216 case NS_XUL_COMMAND_EVENT
:
217 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb
, "mEvent->sourceEvent");
219 static_cast<nsXULCommandEvent
*>(tmp
->mEvent
)->sourceEvent
);
221 case NS_MUTATION_EVENT
:
222 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb
, "mEvent->mRelatedNode");
224 static_cast<nsMutationEvent
*>(tmp
->mEvent
)->mRelatedNode
);
230 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPresContext
)
231 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTmpRealOriginalTarget
)
232 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mExplicitOriginalTarget
)
233 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
235 // nsIDOMEventInterface
236 NS_METHOD
nsDOMEvent::GetType(nsAString
& aType
)
238 const char* name
= GetEventName(mEvent
->message
);
241 CopyASCIItoUTF16(name
, aType
);
243 } else if (mEvent
->message
== NS_USER_DEFINED_EVENT
&& mEvent
->userType
) {
245 mEvent
->userType
->ToString(name
);
246 aType
= Substring(name
, 2, name
.Length() - 2); // Remove "on"
250 return NS_ERROR_FAILURE
;
254 GetDOMEventTarget(nsISupports
* aTarget
,
255 nsIDOMEventTarget
** aDOMTarget
)
257 nsCOMPtr
<nsPIDOMEventTarget
> piTarget
= do_QueryInterface(aTarget
);
258 nsISupports
* realTarget
=
259 piTarget
? piTarget
->GetTargetForDOMEvent() : aTarget
;
261 return CallQueryInterface(realTarget
, aDOMTarget
);
264 *aDOMTarget
= nsnull
;
269 nsDOMEvent::GetTarget(nsIDOMEventTarget
** aTarget
)
271 return GetDOMEventTarget(mEvent
->target
, aTarget
);
275 nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget
** aCurrentTarget
)
277 return GetDOMEventTarget(mEvent
->currentTarget
, aCurrentTarget
);
281 // Get the actual event target node (may have been retargeted for mouse events)
283 already_AddRefed
<nsIDOMEventTarget
>
284 nsDOMEvent::GetTargetFromFrame()
286 if (!mPresContext
) { return nsnull
; }
288 // Get the target frame (have to get the ESM first)
289 nsIFrame
* targetFrame
= nsnull
;
290 mPresContext
->EventStateManager()->GetEventTarget(&targetFrame
);
291 if (!targetFrame
) { return nsnull
; }
293 // get the real content
294 nsCOMPtr
<nsIContent
> realEventContent
;
295 targetFrame
->GetContentForEvent(mPresContext
, mEvent
, getter_AddRefs(realEventContent
));
296 if (!realEventContent
) { return nsnull
; }
298 // Finally, we have the real content. QI it and return.
299 nsIDOMEventTarget
* target
= nsnull
;
300 CallQueryInterface(realEventContent
, &target
);
305 nsDOMEvent::GetExplicitOriginalTarget(nsIDOMEventTarget
** aRealEventTarget
)
307 if (mExplicitOriginalTarget
) {
308 *aRealEventTarget
= mExplicitOriginalTarget
;
309 NS_ADDREF(*aRealEventTarget
);
313 return GetTarget(aRealEventTarget
);
317 nsDOMEvent::GetTmpRealOriginalTarget(nsIDOMEventTarget
** aRealEventTarget
)
319 if (mTmpRealOriginalTarget
) {
320 *aRealEventTarget
= mTmpRealOriginalTarget
;
321 NS_ADDREF(*aRealEventTarget
);
325 return GetOriginalTarget(aRealEventTarget
);
329 nsDOMEvent::GetOriginalTarget(nsIDOMEventTarget
** aOriginalTarget
)
331 if (mEvent
->originalTarget
) {
332 return GetDOMEventTarget(mEvent
->originalTarget
, aOriginalTarget
);
335 return GetTarget(aOriginalTarget
);
338 NS_IMETHODIMP_(PRBool
)
339 nsDOMEvent::HasOriginalTarget()
341 return !!mEvent
->originalTarget
;
345 nsDOMEvent::SetTrusted(PRBool aTrusted
)
348 mEvent
->flags
|= NS_EVENT_FLAG_TRUSTED
;
350 mEvent
->flags
&= ~NS_EVENT_FLAG_TRUSTED
;
357 nsDOMEvent::GetEventPhase(PRUint16
* aEventPhase
)
359 // Note, remember to check that this works also
360 // if or when Bug 235441 is fixed.
361 if (mEvent
->currentTarget
== mEvent
->target
||
362 ((mEvent
->flags
& NS_EVENT_FLAG_CAPTURE
) &&
363 (mEvent
->flags
& NS_EVENT_FLAG_BUBBLE
))) {
364 *aEventPhase
= nsIDOMEvent::AT_TARGET
;
365 } else if (mEvent
->flags
& NS_EVENT_FLAG_CAPTURE
) {
366 *aEventPhase
= nsIDOMEvent::CAPTURING_PHASE
;
367 } else if (mEvent
->flags
& NS_EVENT_FLAG_BUBBLE
) {
368 *aEventPhase
= nsIDOMEvent::BUBBLING_PHASE
;
376 nsDOMEvent::GetBubbles(PRBool
* aBubbles
)
378 *aBubbles
= !(mEvent
->flags
& NS_EVENT_FLAG_CANT_BUBBLE
);
383 nsDOMEvent::GetCancelable(PRBool
* aCancelable
)
385 *aCancelable
= !(mEvent
->flags
& NS_EVENT_FLAG_CANT_CANCEL
);
390 nsDOMEvent::GetTimeStamp(PRUint64
* aTimeStamp
)
392 LL_UI2L(*aTimeStamp
, mEvent
->time
);
397 nsDOMEvent::StopPropagation()
399 mEvent
->flags
|= NS_EVENT_FLAG_STOP_DISPATCH
;
404 ReportUseOfDeprecatedMethod(nsEvent
* aEvent
, nsIDOMEvent
* aDOMEvent
,
405 const char* aWarning
)
407 nsCOMPtr
<nsIDocument
> doc
;
408 nsCOMPtr
<nsINode
> node
= do_QueryInterface(aEvent
->currentTarget
);
410 doc
= node
->GetOwnerDoc();
412 nsCOMPtr
<nsPIDOMWindow
> window
= do_QueryInterface(aEvent
->currentTarget
);
414 doc
= do_QueryInterface(window
->GetExtantDocument());
419 aDOMEvent
->GetType(type
);
420 const PRUnichar
*strings
[] = { type
.get() };
421 nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES
,
423 strings
, NS_ARRAY_LENGTH(strings
),
424 doc
? doc
->GetDocumentURI() : nsnull
,
426 nsIScriptError::warningFlag
,
431 nsDOMEvent::PreventBubble()
433 ReportUseOfDeprecatedMethod(mEvent
, this, "UseOfPreventBubbleWarning");
438 nsDOMEvent::PreventCapture()
440 ReportUseOfDeprecatedMethod(mEvent
, this, "UseOfPreventCaptureWarning");
445 nsDOMEvent::GetIsTrusted(PRBool
*aIsTrusted
)
447 *aIsTrusted
= NS_IS_TRUSTED_EVENT(mEvent
);
453 nsDOMEvent::PreventDefault()
455 if (!(mEvent
->flags
& NS_EVENT_FLAG_CANT_CANCEL
)) {
456 mEvent
->flags
|= NS_EVENT_FLAG_NO_DEFAULT
;
462 nsDOMEvent::SetEventType(const nsAString
& aEventTypeArg
)
464 nsCOMPtr
<nsIAtom
> atom
= do_GetAtom(NS_LITERAL_STRING("on") + aEventTypeArg
);
465 mEvent
->message
= NS_USER_DEFINED_EVENT
;
467 if (mEvent
->eventStructType
== NS_MOUSE_EVENT
) {
468 if (atom
== nsGkAtoms::onmousedown
)
469 mEvent
->message
= NS_MOUSE_BUTTON_DOWN
;
470 else if (atom
== nsGkAtoms::onmouseup
)
471 mEvent
->message
= NS_MOUSE_BUTTON_UP
;
472 else if (atom
== nsGkAtoms::onclick
)
473 mEvent
->message
= NS_MOUSE_CLICK
;
474 else if (atom
== nsGkAtoms::ondblclick
)
475 mEvent
->message
= NS_MOUSE_DOUBLECLICK
;
476 else if (atom
== nsGkAtoms::onmouseover
)
477 mEvent
->message
= NS_MOUSE_ENTER_SYNTH
;
478 else if (atom
== nsGkAtoms::onmouseout
)
479 mEvent
->message
= NS_MOUSE_EXIT_SYNTH
;
480 else if (atom
== nsGkAtoms::onmousemove
)
481 mEvent
->message
= NS_MOUSE_MOVE
;
482 else if (atom
== nsGkAtoms::oncontextmenu
)
483 mEvent
->message
= NS_CONTEXTMENU
;
484 } else if (mEvent
->eventStructType
== NS_MOUSE_SCROLL_EVENT
) {
485 if (atom
== nsGkAtoms::onDOMMouseScroll
)
486 mEvent
->message
= NS_MOUSE_SCROLL
;
487 else if (atom
== nsGkAtoms::onMozMousePixelScroll
)
488 mEvent
->message
= NS_MOUSE_PIXEL_SCROLL
;
489 } else if (mEvent
->eventStructType
== NS_DRAG_EVENT
) {
490 if (atom
== nsGkAtoms::ondragstart
)
491 mEvent
->message
= NS_DRAGDROP_START
;
492 else if (atom
== nsGkAtoms::ondraggesture
)
493 mEvent
->message
= NS_DRAGDROP_GESTURE
;
494 else if (atom
== nsGkAtoms::ondragenter
)
495 mEvent
->message
= NS_DRAGDROP_ENTER
;
496 else if (atom
== nsGkAtoms::ondragover
)
497 mEvent
->message
= NS_DRAGDROP_OVER_SYNTH
;
498 else if (atom
== nsGkAtoms::ondragleave
)
499 mEvent
->message
= NS_DRAGDROP_LEAVE_SYNTH
;
500 else if (atom
== nsGkAtoms::ondragexit
)
501 mEvent
->message
= NS_DRAGDROP_EXIT
;
502 else if (atom
== nsGkAtoms::ondrag
)
503 mEvent
->message
= NS_DRAGDROP_DRAG
;
504 else if (atom
== nsGkAtoms::ondrop
)
505 mEvent
->message
= NS_DRAGDROP_DROP
;
506 else if (atom
== nsGkAtoms::ondragdrop
)
507 mEvent
->message
= NS_DRAGDROP_DRAGDROP
;
508 else if (atom
== nsGkAtoms::ondragend
)
509 mEvent
->message
= NS_DRAGDROP_END
;
510 } else if (mEvent
->eventStructType
== NS_KEY_EVENT
) {
511 if (atom
== nsGkAtoms::onkeydown
)
512 mEvent
->message
= NS_KEY_DOWN
;
513 else if (atom
== nsGkAtoms::onkeyup
)
514 mEvent
->message
= NS_KEY_UP
;
515 else if (atom
== nsGkAtoms::onkeypress
)
516 mEvent
->message
= NS_KEY_PRESS
;
517 } else if (mEvent
->eventStructType
== NS_COMPOSITION_EVENT
) {
518 if (atom
== nsGkAtoms::oncompositionstart
)
519 mEvent
->message
= NS_COMPOSITION_START
;
520 else if (atom
== nsGkAtoms::oncompositionend
)
521 mEvent
->message
= NS_COMPOSITION_END
;
522 } else if (mEvent
->eventStructType
== NS_EVENT
) {
523 if (atom
== nsGkAtoms::onfocus
)
524 mEvent
->message
= NS_FOCUS_CONTENT
;
525 else if (atom
== nsGkAtoms::onblur
)
526 mEvent
->message
= NS_BLUR_CONTENT
;
527 else if (atom
== nsGkAtoms::onsubmit
)
528 mEvent
->message
= NS_FORM_SUBMIT
;
529 else if (atom
== nsGkAtoms::onreset
)
530 mEvent
->message
= NS_FORM_RESET
;
531 else if (atom
== nsGkAtoms::onchange
)
532 mEvent
->message
= NS_FORM_CHANGE
;
533 else if (atom
== nsGkAtoms::onselect
)
534 mEvent
->message
= NS_FORM_SELECTED
;
535 else if (atom
== nsGkAtoms::onload
)
536 mEvent
->message
= NS_LOAD
;
537 else if (atom
== nsGkAtoms::onunload
)
538 mEvent
->message
= NS_PAGE_UNLOAD
;
539 else if (atom
== nsGkAtoms::onabort
)
540 mEvent
->message
= NS_IMAGE_ABORT
;
541 else if (atom
== nsGkAtoms::onerror
)
542 mEvent
->message
= NS_LOAD_ERROR
;
543 else if (atom
== nsGkAtoms::onoffline
)
544 mEvent
->message
= NS_OFFLINE
;
545 else if (atom
== nsGkAtoms::ononline
)
546 mEvent
->message
= NS_ONLINE
;
547 else if (atom
== nsGkAtoms::oncopy
)
548 mEvent
->message
= NS_COPY
;
549 else if (atom
== nsGkAtoms::oncut
)
550 mEvent
->message
= NS_CUT
;
551 else if (atom
== nsGkAtoms::onpaste
)
552 mEvent
->message
= NS_PASTE
;
553 } else if (mEvent
->eventStructType
== NS_MUTATION_EVENT
) {
554 if (atom
== nsGkAtoms::onDOMAttrModified
)
555 mEvent
->message
= NS_MUTATION_ATTRMODIFIED
;
556 else if (atom
== nsGkAtoms::onDOMCharacterDataModified
)
557 mEvent
->message
= NS_MUTATION_CHARACTERDATAMODIFIED
;
558 else if (atom
== nsGkAtoms::onDOMNodeInserted
)
559 mEvent
->message
= NS_MUTATION_NODEINSERTED
;
560 else if (atom
== nsGkAtoms::onDOMNodeRemoved
)
561 mEvent
->message
= NS_MUTATION_NODEREMOVED
;
562 else if (atom
== nsGkAtoms::onDOMNodeInsertedIntoDocument
)
563 mEvent
->message
= NS_MUTATION_NODEINSERTEDINTODOCUMENT
;
564 else if (atom
== nsGkAtoms::onDOMNodeRemovedFromDocument
)
565 mEvent
->message
= NS_MUTATION_NODEREMOVEDFROMDOCUMENT
;
566 else if (atom
== nsGkAtoms::onDOMSubtreeModified
)
567 mEvent
->message
= NS_MUTATION_SUBTREEMODIFIED
;
568 } else if (mEvent
->eventStructType
== NS_UI_EVENT
) {
569 if (atom
== nsGkAtoms::onDOMActivate
)
570 mEvent
->message
= NS_UI_ACTIVATE
;
571 else if (atom
== nsGkAtoms::onDOMFocusIn
)
572 mEvent
->message
= NS_UI_FOCUSIN
;
573 else if (atom
== nsGkAtoms::onDOMFocusOut
)
574 mEvent
->message
= NS_UI_FOCUSOUT
;
575 else if (atom
== nsGkAtoms::oninput
)
576 mEvent
->message
= NS_FORM_INPUT
;
577 } else if (mEvent
->eventStructType
== NS_PAGETRANSITION_EVENT
) {
578 if (atom
== nsGkAtoms::onpageshow
)
579 mEvent
->message
= NS_PAGE_SHOW
;
580 else if (atom
== nsGkAtoms::onpagehide
)
581 mEvent
->message
= NS_PAGE_HIDE
;
582 } else if (mEvent
->eventStructType
== NS_XUL_COMMAND_EVENT
) {
583 if (atom
== nsGkAtoms::oncommand
)
584 mEvent
->message
= NS_XUL_COMMAND
;
587 else if (mEvent
->eventStructType
== NS_SVG_EVENT
) {
588 if (atom
== nsGkAtoms::onSVGLoad
)
589 mEvent
->message
= NS_SVG_LOAD
;
590 else if (atom
== nsGkAtoms::onSVGUnload
)
591 mEvent
->message
= NS_SVG_UNLOAD
;
592 else if (atom
== nsGkAtoms::onSVGAbort
)
593 mEvent
->message
= NS_SVG_ABORT
;
594 else if (atom
== nsGkAtoms::onSVGError
)
595 mEvent
->message
= NS_SVG_ERROR
;
596 else if (atom
== nsGkAtoms::onSVGResize
)
597 mEvent
->message
= NS_SVG_RESIZE
;
598 else if (atom
== nsGkAtoms::onSVGScroll
)
599 mEvent
->message
= NS_SVG_SCROLL
;
600 } else if (mEvent
->eventStructType
== NS_SVGZOOM_EVENT
) {
601 if (atom
== nsGkAtoms::onSVGZoom
)
602 mEvent
->message
= NS_SVG_ZOOM
;
607 else if (mEvent
->eventStructType
== NS_MEDIA_EVENT
) {
608 if (atom
== nsGkAtoms::onloadstart
)
609 mEvent
->message
= NS_LOADSTART
;
610 else if (atom
== nsGkAtoms::onprogress
)
611 mEvent
->message
= NS_PROGRESS
;
612 else if (atom
== nsGkAtoms::onloadedmetadata
)
613 mEvent
->message
= NS_LOADEDMETADATA
;
614 else if (atom
== nsGkAtoms::onloadedfirstframe
)
615 mEvent
->message
= NS_LOADEDFIRSTFRAME
;
616 else if (atom
== nsGkAtoms::onemptied
)
617 mEvent
->message
= NS_EMPTIED
;
618 else if (atom
== nsGkAtoms::onstalled
)
619 mEvent
->message
= NS_STALLED
;
620 else if (atom
== nsGkAtoms::onplay
)
621 mEvent
->message
= NS_PLAY
;
622 else if (atom
== nsGkAtoms::onpause
)
623 mEvent
->message
= NS_PAUSE
;
624 else if (atom
== nsGkAtoms::onwaiting
)
625 mEvent
->message
= NS_WAITING
;
626 else if (atom
== nsGkAtoms::onwaiting
)
627 mEvent
->message
= NS_SEEKING
;
628 else if (atom
== nsGkAtoms::onseeking
)
629 mEvent
->message
= NS_SEEKED
;
630 else if (atom
== nsGkAtoms::onseeked
)
631 mEvent
->message
= NS_TIMEUPDATE
;
632 else if (atom
== nsGkAtoms::onended
)
633 mEvent
->message
= NS_ENDED
;
634 else if (atom
== nsGkAtoms::ondataunavailable
)
635 mEvent
->message
= NS_DATAUNAVAILABLE
;
636 else if (atom
== nsGkAtoms::oncanshowcurrentframe
)
637 mEvent
->message
= NS_CANSHOWCURRENTFRAME
;
638 else if (atom
== nsGkAtoms::oncanplay
)
639 mEvent
->message
= NS_CANPLAY
;
640 else if (atom
== nsGkAtoms::oncanplaythrough
)
641 mEvent
->message
= NS_CANPLAYTHROUGH
;
642 else if (atom
== nsGkAtoms::onratechange
)
643 mEvent
->message
= NS_RATECHANGE
;
644 else if (atom
== nsGkAtoms::ondurationchange
)
645 mEvent
->message
= NS_DURATIONCHANGE
;
646 else if (atom
== nsGkAtoms::onvolumechange
)
647 mEvent
->message
= NS_VOLUMECHANGE
;
648 else if (atom
== nsGkAtoms::onload
)
649 mEvent
->message
= NS_LOAD
;
650 else if (atom
== nsGkAtoms::onabort
)
651 mEvent
->message
= NS_MEDIA_ABORT
;
652 else if (atom
== nsGkAtoms::onerror
)
653 mEvent
->message
= NS_MEDIA_ERROR
;
656 else if (mEvent
->eventStructType
== NS_NOTIFYPAINT_EVENT
) {
657 if (atom
== nsGkAtoms::onMozAfterPaint
)
658 mEvent
->message
= NS_AFTERPAINT
;
660 else if (mEvent
->eventStructType
== NS_SIMPLE_GESTURE_EVENT
) {
661 if (atom
== nsGkAtoms::onMozSwipeGesture
)
662 mEvent
->message
= NS_SIMPLE_GESTURE_SWIPE
;
663 else if (atom
== nsGkAtoms::onMozMagnifyGestureStart
)
664 mEvent
->message
= NS_SIMPLE_GESTURE_MAGNIFY_START
;
665 else if (atom
== nsGkAtoms::onMozMagnifyGestureUpdate
)
666 mEvent
->message
= NS_SIMPLE_GESTURE_MAGNIFY_UPDATE
;
667 else if (atom
== nsGkAtoms::onMozMagnifyGesture
)
668 mEvent
->message
= NS_SIMPLE_GESTURE_MAGNIFY
;
669 else if (atom
== nsGkAtoms::onMozRotateGestureStart
)
670 mEvent
->message
= NS_SIMPLE_GESTURE_ROTATE_START
;
671 else if (atom
== nsGkAtoms::onMozRotateGestureUpdate
)
672 mEvent
->message
= NS_SIMPLE_GESTURE_ROTATE_UPDATE
;
673 else if (atom
== nsGkAtoms::onMozRotateGesture
)
674 mEvent
->message
= NS_SIMPLE_GESTURE_ROTATE
;
677 if (mEvent
->message
== NS_USER_DEFINED_EVENT
)
678 mEvent
->userType
= atom
;
684 nsDOMEvent::InitEvent(const nsAString
& aEventTypeArg
, PRBool aCanBubbleArg
, PRBool aCancelableArg
)
686 // Make sure this event isn't already being dispatched.
687 NS_ENSURE_TRUE(!NS_IS_EVENT_IN_DISPATCH(mEvent
), NS_ERROR_INVALID_ARG
);
689 if (NS_IS_TRUSTED_EVENT(mEvent
)) {
690 // Ensure the caller is permitted to dispatch trusted DOM events.
692 PRBool enabled
= PR_FALSE
;
693 nsContentUtils::GetSecurityManager()->
694 IsCapabilityEnabled("UniversalBrowserWrite", &enabled
);
697 SetTrusted(PR_FALSE
);
701 NS_ENSURE_SUCCESS(SetEventType(aEventTypeArg
), NS_ERROR_FAILURE
);
704 mEvent
->flags
&= ~NS_EVENT_FLAG_CANT_BUBBLE
;
706 mEvent
->flags
|= NS_EVENT_FLAG_CANT_BUBBLE
;
709 if (aCancelableArg
) {
710 mEvent
->flags
&= ~NS_EVENT_FLAG_CANT_CANCEL
;
712 mEvent
->flags
|= NS_EVENT_FLAG_CANT_CANCEL
;
715 // Clearing the old targets, so that the event is targeted correctly when
716 // re-dispatching it.
717 mEvent
->target
= nsnull
;
718 mEvent
->originalTarget
= nsnull
;
723 NS_METHOD
nsDOMEvent::DuplicatePrivateData()
725 // FIXME! Simplify this method and make it somehow easily extendable,
728 NS_ASSERTION(mEvent
, "No nsEvent for nsDOMEvent duplication!");
729 if (mEventIsInternal
) {
733 nsEvent
* newEvent
= nsnull
;
734 PRUint32 msg
= mEvent
->message
;
735 PRBool isInputEvent
= PR_FALSE
;
737 switch (mEvent
->eventStructType
) {
740 newEvent
= new nsEvent(PR_FALSE
, msg
);
745 // Not copying widget, it is a weak reference.
746 newEvent
= new nsGUIEvent(PR_FALSE
, msg
, nsnull
);
751 nsSizeEvent
* sizeEvent
= new nsSizeEvent(PR_FALSE
, msg
, nsnull
);
752 NS_ENSURE_TRUE(sizeEvent
, NS_ERROR_OUT_OF_MEMORY
);
753 sizeEvent
->mWinWidth
= static_cast<nsSizeEvent
*>(mEvent
)->mWinWidth
;
754 sizeEvent
->mWinHeight
= static_cast<nsSizeEvent
*>(mEvent
)->mWinHeight
;
755 newEvent
= sizeEvent
;
758 case NS_SIZEMODE_EVENT
:
760 newEvent
= new nsSizeModeEvent(PR_FALSE
, msg
, nsnull
);
761 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
762 static_cast<nsSizeModeEvent
*>(newEvent
)->mSizeMode
=
763 static_cast<nsSizeModeEvent
*>(mEvent
)->mSizeMode
;
766 case NS_ZLEVEL_EVENT
:
768 nsZLevelEvent
* zLevelEvent
= new nsZLevelEvent(PR_FALSE
, msg
, nsnull
);
769 NS_ENSURE_TRUE(zLevelEvent
, NS_ERROR_OUT_OF_MEMORY
);
770 nsZLevelEvent
* oldZLevelEvent
= static_cast<nsZLevelEvent
*>(mEvent
);
771 zLevelEvent
->mPlacement
= oldZLevelEvent
->mPlacement
;
772 zLevelEvent
->mImmediate
= oldZLevelEvent
->mImmediate
;
773 zLevelEvent
->mAdjusted
= oldZLevelEvent
->mAdjusted
;
774 newEvent
= zLevelEvent
;
779 newEvent
= new nsPaintEvent(PR_FALSE
, msg
, nsnull
);
782 case NS_SCROLLBAR_EVENT
:
784 newEvent
= new nsScrollbarEvent(PR_FALSE
, msg
, nsnull
);
785 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
786 static_cast<nsScrollbarEvent
*>(newEvent
)->position
=
787 static_cast<nsScrollbarEvent
*>(mEvent
)->position
;
792 newEvent
= new nsInputEvent(PR_FALSE
, msg
, nsnull
);
793 isInputEvent
= PR_TRUE
;
798 nsKeyEvent
* keyEvent
= new nsKeyEvent(PR_FALSE
, msg
, nsnull
);
799 NS_ENSURE_TRUE(keyEvent
, NS_ERROR_OUT_OF_MEMORY
);
800 nsKeyEvent
* oldKeyEvent
= static_cast<nsKeyEvent
*>(mEvent
);
801 isInputEvent
= PR_TRUE
;
802 keyEvent
->keyCode
= oldKeyEvent
->keyCode
;
803 keyEvent
->charCode
= oldKeyEvent
->charCode
;
804 keyEvent
->isChar
= oldKeyEvent
->isChar
;
810 nsMouseEvent
* oldMouseEvent
= static_cast<nsMouseEvent
*>(mEvent
);
811 nsMouseEvent
* mouseEvent
=
812 new nsMouseEvent(PR_FALSE
, msg
, nsnull
, oldMouseEvent
->reason
);
813 NS_ENSURE_TRUE(mouseEvent
, NS_ERROR_OUT_OF_MEMORY
);
814 isInputEvent
= PR_TRUE
;
815 mouseEvent
->clickCount
= oldMouseEvent
->clickCount
;
816 mouseEvent
->acceptActivation
= oldMouseEvent
->acceptActivation
;
817 mouseEvent
->context
= oldMouseEvent
->context
;
818 mouseEvent
->relatedTarget
= oldMouseEvent
->relatedTarget
;
819 mouseEvent
->button
= oldMouseEvent
->button
;
820 newEvent
= mouseEvent
;
825 nsDragEvent
* oldDragEvent
= static_cast<nsDragEvent
*>(mEvent
);
826 nsDragEvent
* dragEvent
=
827 new nsDragEvent(PR_FALSE
, msg
, nsnull
);
828 NS_ENSURE_TRUE(dragEvent
, NS_ERROR_OUT_OF_MEMORY
);
829 isInputEvent
= PR_TRUE
;
830 dragEvent
->dataTransfer
= oldDragEvent
->dataTransfer
;
831 dragEvent
->clickCount
= oldDragEvent
->clickCount
;
832 dragEvent
->acceptActivation
= oldDragEvent
->acceptActivation
;
833 dragEvent
->relatedTarget
= oldDragEvent
->relatedTarget
;
834 dragEvent
->button
= oldDragEvent
->button
;
835 newEvent
= dragEvent
;
840 newEvent
= new nsMenuEvent(PR_FALSE
, msg
, nsnull
);
841 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
842 static_cast<nsMenuEvent
*>(newEvent
)->mCommand
=
843 static_cast<nsMenuEvent
*>(mEvent
)->mCommand
;
846 case NS_SCRIPT_ERROR_EVENT
:
848 newEvent
= new nsScriptErrorEvent(PR_FALSE
, msg
);
849 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
850 static_cast<nsScriptErrorEvent
*>(newEvent
)->lineNr
=
851 static_cast<nsScriptErrorEvent
*>(mEvent
)->lineNr
;
856 newEvent
= new nsTextEvent(PR_FALSE
, msg
, nsnull
);
857 isInputEvent
= PR_TRUE
;
860 case NS_COMPOSITION_EVENT
:
862 newEvent
= new nsCompositionEvent(PR_FALSE
, msg
, nsnull
);
863 isInputEvent
= PR_TRUE
;
866 case NS_MOUSE_SCROLL_EVENT
:
868 nsMouseScrollEvent
* mouseScrollEvent
=
869 new nsMouseScrollEvent(PR_FALSE
, msg
, nsnull
);
870 NS_ENSURE_TRUE(mouseScrollEvent
, NS_ERROR_OUT_OF_MEMORY
);
871 isInputEvent
= PR_TRUE
;
872 nsMouseScrollEvent
* oldMouseScrollEvent
=
873 static_cast<nsMouseScrollEvent
*>(mEvent
);
874 mouseScrollEvent
->scrollFlags
= oldMouseScrollEvent
->scrollFlags
;
875 mouseScrollEvent
->delta
= oldMouseScrollEvent
->delta
;
876 mouseScrollEvent
->relatedTarget
= oldMouseScrollEvent
->relatedTarget
;
877 mouseScrollEvent
->button
= oldMouseScrollEvent
->button
;
878 newEvent
= mouseScrollEvent
;
881 case NS_SCROLLPORT_EVENT
:
883 newEvent
= new nsScrollPortEvent(PR_FALSE
, msg
, nsnull
);
884 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
885 static_cast<nsScrollPortEvent
*>(newEvent
)->orient
=
886 static_cast<nsScrollPortEvent
*>(mEvent
)->orient
;
889 case NS_MUTATION_EVENT
:
891 nsMutationEvent
* mutationEvent
= new nsMutationEvent(PR_FALSE
, msg
);
892 NS_ENSURE_TRUE(mutationEvent
, NS_ERROR_OUT_OF_MEMORY
);
893 nsMutationEvent
* oldMutationEvent
=
894 static_cast<nsMutationEvent
*>(mEvent
);
895 mutationEvent
->mRelatedNode
= oldMutationEvent
->mRelatedNode
;
896 mutationEvent
->mAttrName
= oldMutationEvent
->mAttrName
;
897 mutationEvent
->mPrevAttrValue
= oldMutationEvent
->mPrevAttrValue
;
898 mutationEvent
->mNewAttrValue
= oldMutationEvent
->mNewAttrValue
;
899 mutationEvent
->mAttrChange
= oldMutationEvent
->mAttrChange
;
900 newEvent
= mutationEvent
;
903 case NS_ACCESSIBLE_EVENT
:
905 newEvent
= new nsAccessibleEvent(PR_FALSE
, msg
, nsnull
);
906 isInputEvent
= PR_TRUE
;
911 newEvent
= new nsFormEvent(PR_FALSE
, msg
);
916 newEvent
= new nsFocusEvent(PR_FALSE
, msg
, nsnull
);
917 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
918 static_cast<nsFocusEvent
*>(newEvent
)->isMozWindowTakingFocus
=
919 static_cast<nsFocusEvent
*>(mEvent
)->isMozWindowTakingFocus
;
924 newEvent
= new nsInputEvent(PR_FALSE
, msg
, nsnull
);
925 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
926 isInputEvent
= PR_TRUE
;
927 newEvent
->eventStructType
= NS_POPUP_EVENT
;
930 case NS_COMMAND_EVENT
:
932 newEvent
= new nsCommandEvent(PR_FALSE
, mEvent
->userType
,
933 static_cast<nsCommandEvent
*>(mEvent
)->command
, nsnull
);
934 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
937 case NS_POPUPBLOCKED_EVENT
:
939 NS_WARNING("nsPopupBlockedEvent should never be an external event!");
940 newEvent
= new nsPopupBlockedEvent(PR_FALSE
, msg
);
943 case NS_BEFORE_PAGE_UNLOAD_EVENT
:
945 newEvent
= new nsBeforePageUnloadEvent(PR_FALSE
, msg
);
946 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
947 static_cast<nsBeforePageUnloadEvent
*>(newEvent
)->text
=
948 static_cast<nsBeforePageUnloadEvent
*>(mEvent
)->text
;
953 newEvent
= new nsUIEvent(PR_FALSE
, msg
,
954 static_cast<nsUIEvent
*>(mEvent
)->detail
);
957 case NS_PAGETRANSITION_EVENT
:
960 new nsPageTransitionEvent(PR_FALSE
, msg
,
961 ((nsPageTransitionEvent
*) mEvent
)->persisted
);
967 newEvent
= new nsEvent(PR_FALSE
, msg
);
968 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
969 newEvent
->eventStructType
= NS_SVG_EVENT
;
972 case NS_SVGZOOM_EVENT
:
974 newEvent
= new nsGUIEvent(PR_FALSE
, msg
, nsnull
);
975 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
976 newEvent
->eventStructType
= NS_SVGZOOM_EVENT
;
980 case NS_XUL_COMMAND_EVENT
:
982 newEvent
= new nsXULCommandEvent(PR_FALSE
, msg
, nsnull
);
983 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
984 isInputEvent
= PR_TRUE
;
985 newEvent
->eventStructType
= NS_XUL_COMMAND_EVENT
;
986 static_cast<nsXULCommandEvent
*>(newEvent
)->sourceEvent
=
987 static_cast<nsXULCommandEvent
*>(mEvent
)->sourceEvent
;
990 case NS_NOTIFYPAINT_EVENT
:
992 nsNotifyPaintEvent
* event
= static_cast<nsNotifyPaintEvent
*>(mEvent
);
994 new nsNotifyPaintEvent(PR_FALSE
, msg
,
995 event
->sameDocRegion
, event
->crossDocRegion
);
998 case NS_SIMPLE_GESTURE_EVENT
:
1000 nsSimpleGestureEvent
* oldSimpleGestureEvent
= static_cast<nsSimpleGestureEvent
*>(mEvent
);
1001 nsSimpleGestureEvent
* simpleGestureEvent
=
1002 new nsSimpleGestureEvent(PR_FALSE
, msg
, nsnull
, 0, 0.0);
1003 NS_ENSURE_TRUE(simpleGestureEvent
, NS_ERROR_OUT_OF_MEMORY
);
1004 isInputEvent
= PR_TRUE
;
1005 simpleGestureEvent
->direction
= oldSimpleGestureEvent
->direction
;
1006 simpleGestureEvent
->delta
= oldSimpleGestureEvent
->delta
;
1007 simpleGestureEvent
->isAlt
= oldSimpleGestureEvent
->isAlt
;
1008 simpleGestureEvent
->isControl
= oldSimpleGestureEvent
->isControl
;
1009 simpleGestureEvent
->isShift
= oldSimpleGestureEvent
->isShift
;
1010 simpleGestureEvent
->isMeta
= oldSimpleGestureEvent
->isMeta
;
1011 newEvent
= simpleGestureEvent
;
1016 NS_WARNING("Unknown event type!!!");
1017 return NS_ERROR_FAILURE
;
1021 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
1024 nsInputEvent
* oldInputEvent
= static_cast<nsInputEvent
*>(mEvent
);
1025 nsInputEvent
* newInputEvent
= static_cast<nsInputEvent
*>(newEvent
);
1026 newInputEvent
->isShift
= oldInputEvent
->isShift
;
1027 newInputEvent
->isControl
= oldInputEvent
->isControl
;
1028 newInputEvent
->isAlt
= oldInputEvent
->isAlt
;
1029 newInputEvent
->isMeta
= oldInputEvent
->isMeta
;
1032 newEvent
->target
= mEvent
->target
;
1033 newEvent
->currentTarget
= mEvent
->currentTarget
;
1034 newEvent
->originalTarget
= mEvent
->originalTarget
;
1035 newEvent
->flags
= mEvent
->flags
;
1036 newEvent
->time
= mEvent
->time
;
1037 newEvent
->refPoint
= mEvent
->refPoint
;
1038 newEvent
->userType
= mEvent
->userType
;
1041 mPresContext
= nsnull
;
1042 mEventIsInternal
= PR_TRUE
;
1043 mPrivateDataDuplicated
= PR_TRUE
;
1048 NS_METHOD
nsDOMEvent::SetTarget(nsIDOMEventTarget
* aTarget
)
1052 nsCOMPtr
<nsPIDOMWindow
> win
= do_QueryInterface(aTarget
);
1054 NS_ASSERTION(!win
|| !win
->IsInnerWindow(),
1055 "Uh, inner window set as event target!");
1059 mEvent
->target
= aTarget
;
1063 NS_METHOD
nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget
* aCurrentTarget
)
1067 nsCOMPtr
<nsPIDOMWindow
> win
= do_QueryInterface(aCurrentTarget
);
1069 NS_ASSERTION(!win
|| !win
->IsInnerWindow(),
1070 "Uh, inner window set as event target!");
1074 mEvent
->currentTarget
= aCurrentTarget
;
1078 NS_METHOD
nsDOMEvent::SetOriginalTarget(nsIDOMEventTarget
* aOriginalTarget
)
1082 nsCOMPtr
<nsPIDOMWindow
> win
= do_QueryInterface(aOriginalTarget
);
1084 NS_ASSERTION(!win
|| !win
->IsInnerWindow(),
1085 "Uh, inner window set as event target!");
1089 mEvent
->originalTarget
= aOriginalTarget
;
1093 NS_IMETHODIMP_(PRBool
)
1094 nsDOMEvent::IsDispatchStopped()
1096 return !!(mEvent
->flags
& NS_EVENT_FLAG_STOP_DISPATCH
);
1099 NS_IMETHODIMP_(nsEvent
*)
1100 nsDOMEvent::GetInternalNSEvent()
1105 // return true if eventName is contained within events, delimited by
1108 PopupAllowedForEvent(const char *eventName
)
1110 if (!sPopupAllowedEvents
) {
1111 nsDOMEvent::PopupAllowedEventsChanged();
1113 if (!sPopupAllowedEvents
) {
1118 nsDependentCString
events(sPopupAllowedEvents
);
1120 nsAFlatCString::const_iterator start
, end
;
1121 nsAFlatCString::const_iterator
startiter(events
.BeginReading(start
));
1122 events
.EndReading(end
);
1124 while (startiter
!= end
) {
1125 nsAFlatCString::const_iterator
enditer(end
);
1127 if (!FindInReadable(nsDependentCString(eventName
), startiter
, enditer
))
1130 // the match is surrounded by spaces, or at a string boundary
1131 if ((startiter
== start
|| *--startiter
== ' ') &&
1132 (enditer
== end
|| *enditer
== ' ')) {
1136 // Move on and see if there are other matches. (The delimitation
1137 // requirement makes it pointless to begin the next search before
1138 // the end of the invalid match just found.)
1139 startiter
= enditer
;
1147 nsDOMEvent::GetEventPopupControlState(nsEvent
*aEvent
)
1149 // generally if an event handler is running, new windows are disallowed.
1150 // check for exceptions:
1151 PopupControlState abuse
= openAbused
;
1153 switch(aEvent
->eventStructType
) {
1155 // For these following events only allow popups if they're
1156 // triggered while handling user input. See
1157 // nsPresShell::HandleEventInternal() for details.
1158 if (nsEventStateManager::IsHandlingUserInput()) {
1159 switch(aEvent
->message
) {
1160 case NS_FORM_SELECTED
:
1161 if (::PopupAllowedForEvent("select"))
1162 abuse
= openControlled
;
1164 case NS_FORM_CHANGE
:
1165 if (::PopupAllowedForEvent("change"))
1166 abuse
= openControlled
;
1172 // For this following event only allow popups if it's triggered
1173 // while handling user input. See
1174 // nsPresShell::HandleEventInternal() for details.
1175 if (nsEventStateManager::IsHandlingUserInput()) {
1176 switch(aEvent
->message
) {
1177 case NS_FORM_INPUT
:
1178 if (::PopupAllowedForEvent("input"))
1179 abuse
= openControlled
;
1184 case NS_INPUT_EVENT
:
1185 // For this following event only allow popups if it's triggered
1186 // while handling user input. See
1187 // nsPresShell::HandleEventInternal() for details.
1188 if (nsEventStateManager::IsHandlingUserInput()) {
1189 switch(aEvent
->message
) {
1190 case NS_FORM_CHANGE
:
1191 if (::PopupAllowedForEvent("change"))
1192 abuse
= openControlled
;
1198 if (NS_IS_TRUSTED_EVENT(aEvent
)) {
1199 PRUint32 key
= static_cast<nsKeyEvent
*>(aEvent
)->keyCode
;
1200 switch(aEvent
->message
) {
1202 // return key on focused button. see note at NS_MOUSE_CLICK.
1203 if (key
== nsIDOMKeyEvent::DOM_VK_RETURN
)
1204 abuse
= openAllowed
;
1205 else if (::PopupAllowedForEvent("keypress"))
1206 abuse
= openControlled
;
1209 // space key on focused button. see note at NS_MOUSE_CLICK.
1210 if (key
== nsIDOMKeyEvent::DOM_VK_SPACE
)
1211 abuse
= openAllowed
;
1212 else if (::PopupAllowedForEvent("keyup"))
1213 abuse
= openControlled
;
1216 if (::PopupAllowedForEvent("keydown"))
1217 abuse
= openControlled
;
1222 case NS_MOUSE_EVENT
:
1223 if (NS_IS_TRUSTED_EVENT(aEvent
) &&
1224 static_cast<nsMouseEvent
*>(aEvent
)->button
== nsMouseEvent::eLeftButton
) {
1225 switch(aEvent
->message
) {
1226 case NS_MOUSE_BUTTON_UP
:
1227 if (::PopupAllowedForEvent("mouseup"))
1228 abuse
= openControlled
;
1230 case NS_MOUSE_BUTTON_DOWN
:
1231 if (::PopupAllowedForEvent("mousedown"))
1232 abuse
= openControlled
;
1234 case NS_MOUSE_CLICK
:
1235 /* Click events get special treatment because of their
1236 historical status as a more legitimate event handler. If
1237 click popups are enabled in the prefs, clear the popup
1238 status completely. */
1239 if (::PopupAllowedForEvent("click"))
1240 abuse
= openAllowed
;
1242 case NS_MOUSE_DOUBLECLICK
:
1243 if (::PopupAllowedForEvent("dblclick"))
1244 abuse
= openControlled
;
1249 case NS_SCRIPT_ERROR_EVENT
:
1250 switch(aEvent
->message
) {
1251 case NS_LOAD_ERROR
:
1252 // Any error event will allow popups, if enabled in the pref.
1253 if (::PopupAllowedForEvent("error"))
1254 abuse
= openControlled
;
1258 case NS_FORM_EVENT
:
1259 // For these following events only allow popups if they're
1260 // triggered while handling user input. See
1261 // nsPresShell::HandleEventInternal() for details.
1262 if (nsEventStateManager::IsHandlingUserInput()) {
1263 switch(aEvent
->message
) {
1264 case NS_FORM_SUBMIT
:
1265 if (::PopupAllowedForEvent("submit"))
1266 abuse
= openControlled
;
1268 case NS_FORM_RESET
:
1269 if (::PopupAllowedForEvent("reset"))
1270 abuse
= openControlled
;
1275 case NS_XUL_COMMAND_EVENT
:
1276 if (nsEventStateManager::IsHandlingUserInput()) {
1277 abuse
= openControlled
;
1286 nsDOMEvent::PopupAllowedEventsChanged()
1288 if (sPopupAllowedEvents
) {
1289 nsMemory::Free(sPopupAllowedEvents
);
1292 nsAdoptingCString str
=
1293 nsContentUtils::GetCharPref("dom.popup_allowed_events");
1295 // We'll want to do this even if str is empty to avoid looking up
1296 // this pref all the time if it's not set.
1297 sPopupAllowedEvents
= ToNewCString(str
);
1302 nsDOMEvent::Shutdown()
1304 if (sPopupAllowedEvents
) {
1305 nsMemory::Free(sPopupAllowedEvents
);
1309 // To be called ONLY by nsDOMEvent::GetType (which has the additional
1310 // logic for handling user-defined events).
1312 const char* nsDOMEvent::GetEventName(PRUint32 aEventType
)
1314 switch(aEventType
) {
1315 case NS_MOUSE_BUTTON_DOWN
:
1316 return sEventNames
[eDOMEvents_mousedown
];
1317 case NS_MOUSE_BUTTON_UP
:
1318 return sEventNames
[eDOMEvents_mouseup
];
1319 case NS_MOUSE_CLICK
:
1320 return sEventNames
[eDOMEvents_click
];
1321 case NS_MOUSE_DOUBLECLICK
:
1322 return sEventNames
[eDOMEvents_dblclick
];
1323 case NS_MOUSE_ENTER_SYNTH
:
1324 return sEventNames
[eDOMEvents_mouseover
];
1325 case NS_MOUSE_EXIT_SYNTH
:
1326 return sEventNames
[eDOMEvents_mouseout
];
1328 return sEventNames
[eDOMEvents_mousemove
];
1330 return sEventNames
[eDOMEvents_keyup
];
1332 return sEventNames
[eDOMEvents_keydown
];
1334 return sEventNames
[eDOMEvents_keypress
];
1335 case NS_COMPOSITION_START
:
1336 return sEventNames
[eDOMEvents_compositionstart
];
1337 case NS_COMPOSITION_END
:
1338 return sEventNames
[eDOMEvents_compositionend
];
1339 case NS_FOCUS_CONTENT
:
1340 return sEventNames
[eDOMEvents_focus
];
1341 case NS_BLUR_CONTENT
:
1342 return sEventNames
[eDOMEvents_blur
];
1344 return sEventNames
[eDOMEvents_close
];
1346 return sEventNames
[eDOMEvents_load
];
1347 case NS_BEFORE_PAGE_UNLOAD
:
1348 return sEventNames
[eDOMEvents_beforeunload
];
1349 case NS_PAGE_UNLOAD
:
1350 return sEventNames
[eDOMEvents_unload
];
1351 case NS_IMAGE_ABORT
:
1352 return sEventNames
[eDOMEvents_abort
];
1354 return sEventNames
[eDOMEvents_error
];
1355 case NS_FORM_SUBMIT
:
1356 return sEventNames
[eDOMEvents_submit
];
1358 return sEventNames
[eDOMEvents_reset
];
1359 case NS_FORM_CHANGE
:
1360 return sEventNames
[eDOMEvents_change
];
1361 case NS_FORM_SELECTED
:
1362 return sEventNames
[eDOMEvents_select
];
1364 return sEventNames
[eDOMEvents_input
];
1366 return sEventNames
[eDOMEvents_paint
];
1367 case NS_RESIZE_EVENT
:
1368 return sEventNames
[eDOMEvents_resize
];
1369 case NS_SCROLL_EVENT
:
1370 return sEventNames
[eDOMEvents_scroll
];
1372 return sEventNames
[eDOMEvents_text
];
1373 case NS_XUL_POPUP_SHOWING
:
1374 return sEventNames
[eDOMEvents_popupShowing
];
1375 case NS_XUL_POPUP_SHOWN
:
1376 return sEventNames
[eDOMEvents_popupShown
];
1377 case NS_XUL_POPUP_HIDING
:
1378 return sEventNames
[eDOMEvents_popupHiding
];
1379 case NS_XUL_POPUP_HIDDEN
:
1380 return sEventNames
[eDOMEvents_popupHidden
];
1381 case NS_XUL_COMMAND
:
1382 return sEventNames
[eDOMEvents_command
];
1383 case NS_XUL_BROADCAST
:
1384 return sEventNames
[eDOMEvents_broadcast
];
1385 case NS_XUL_COMMAND_UPDATE
:
1386 return sEventNames
[eDOMEvents_commandupdate
];
1387 case NS_DRAGDROP_ENTER
:
1388 return sEventNames
[eDOMEvents_dragenter
];
1389 case NS_DRAGDROP_OVER_SYNTH
:
1390 return sEventNames
[eDOMEvents_dragover
];
1391 case NS_DRAGDROP_EXIT_SYNTH
:
1392 return sEventNames
[eDOMEvents_dragexit
];
1393 case NS_DRAGDROP_DRAGDROP
:
1394 return sEventNames
[eDOMEvents_dragdrop
];
1395 case NS_DRAGDROP_GESTURE
:
1396 return sEventNames
[eDOMEvents_draggesture
];
1397 case NS_DRAGDROP_DRAG
:
1398 return sEventNames
[eDOMEvents_drag
];
1399 case NS_DRAGDROP_END
:
1400 return sEventNames
[eDOMEvents_dragend
];
1401 case NS_DRAGDROP_START
:
1402 return sEventNames
[eDOMEvents_dragstart
];
1403 case NS_DRAGDROP_LEAVE_SYNTH
:
1404 return sEventNames
[eDOMEvents_dragleave
];
1405 case NS_DRAGDROP_DROP
:
1406 return sEventNames
[eDOMEvents_drop
];
1407 case NS_SCROLLPORT_OVERFLOW
:
1408 return sEventNames
[eDOMEvents_overflow
];
1409 case NS_SCROLLPORT_UNDERFLOW
:
1410 return sEventNames
[eDOMEvents_underflow
];
1411 case NS_SCROLLPORT_OVERFLOWCHANGED
:
1412 return sEventNames
[eDOMEvents_overflowchanged
];
1413 case NS_MUTATION_SUBTREEMODIFIED
:
1414 return sEventNames
[eDOMEvents_subtreemodified
];
1415 case NS_MUTATION_NODEINSERTED
:
1416 return sEventNames
[eDOMEvents_nodeinserted
];
1417 case NS_MUTATION_NODEREMOVED
:
1418 return sEventNames
[eDOMEvents_noderemoved
];
1419 case NS_MUTATION_NODEREMOVEDFROMDOCUMENT
:
1420 return sEventNames
[eDOMEvents_noderemovedfromdocument
];
1421 case NS_MUTATION_NODEINSERTEDINTODOCUMENT
:
1422 return sEventNames
[eDOMEvents_nodeinsertedintodocument
];
1423 case NS_MUTATION_ATTRMODIFIED
:
1424 return sEventNames
[eDOMEvents_attrmodified
];
1425 case NS_MUTATION_CHARACTERDATAMODIFIED
:
1426 return sEventNames
[eDOMEvents_characterdatamodified
];
1427 case NS_CONTEXTMENU
:
1428 return sEventNames
[eDOMEvents_contextmenu
];
1429 case NS_UI_ACTIVATE
:
1430 return sEventNames
[eDOMEvents_DOMActivate
];
1432 return sEventNames
[eDOMEvents_DOMFocusIn
];
1433 case NS_UI_FOCUSOUT
:
1434 return sEventNames
[eDOMEvents_DOMFocusOut
];
1436 return sEventNames
[eDOMEvents_pageshow
];
1438 return sEventNames
[eDOMEvents_pagehide
];
1439 case NS_MOUSE_SCROLL
:
1440 return sEventNames
[eDOMEvents_DOMMouseScroll
];
1441 case NS_MOUSE_PIXEL_SCROLL
:
1442 return sEventNames
[eDOMEvents_MozMousePixelScroll
];
1444 return sEventNames
[eDOMEvents_offline
];
1446 return sEventNames
[eDOMEvents_online
];
1448 return sEventNames
[eDOMEvents_copy
];
1450 return sEventNames
[eDOMEvents_cut
];
1452 return sEventNames
[eDOMEvents_paste
];
1455 return sEventNames
[eDOMEvents_SVGLoad
];
1457 return sEventNames
[eDOMEvents_SVGUnload
];
1459 return sEventNames
[eDOMEvents_SVGAbort
];
1461 return sEventNames
[eDOMEvents_SVGError
];
1463 return sEventNames
[eDOMEvents_SVGResize
];
1465 return sEventNames
[eDOMEvents_SVGScroll
];
1467 return sEventNames
[eDOMEvents_SVGZoom
];
1471 return sEventNames
[eDOMEvents_loadstart
];
1473 return sEventNames
[eDOMEvents_progress
];
1474 case NS_LOADEDMETADATA
:
1475 return sEventNames
[eDOMEvents_loadedmetadata
];
1476 case NS_LOADEDFIRSTFRAME
:
1477 return sEventNames
[eDOMEvents_loadedfirstframe
];
1479 return sEventNames
[eDOMEvents_emptied
];
1481 return sEventNames
[eDOMEvents_stalled
];
1483 return sEventNames
[eDOMEvents_play
];
1485 return sEventNames
[eDOMEvents_pause
];
1487 return sEventNames
[eDOMEvents_waiting
];
1489 return sEventNames
[eDOMEvents_seeking
];
1491 return sEventNames
[eDOMEvents_seeked
];
1493 return sEventNames
[eDOMEvents_timeupdate
];
1495 return sEventNames
[eDOMEvents_ended
];
1496 case NS_DATAUNAVAILABLE
:
1497 return sEventNames
[eDOMEvents_dataunavailable
];
1498 case NS_CANSHOWCURRENTFRAME
:
1499 return sEventNames
[eDOMEvents_canshowcurrentframe
];
1501 return sEventNames
[eDOMEvents_canplay
];
1502 case NS_CANPLAYTHROUGH
:
1503 return sEventNames
[eDOMEvents_canplaythrough
];
1505 return sEventNames
[eDOMEvents_ratechange
];
1506 case NS_DURATIONCHANGE
:
1507 return sEventNames
[eDOMEvents_durationchange
];
1508 case NS_VOLUMECHANGE
:
1509 return sEventNames
[eDOMEvents_volumechange
];
1512 return sEventNames
[eDOMEvents_afterpaint
];
1513 case NS_SIMPLE_GESTURE_SWIPE
:
1514 return sEventNames
[eDOMEvents_MozSwipeGesture
];
1515 case NS_SIMPLE_GESTURE_MAGNIFY_START
:
1516 return sEventNames
[eDOMEvents_MozMagnifyGestureStart
];
1517 case NS_SIMPLE_GESTURE_MAGNIFY_UPDATE
:
1518 return sEventNames
[eDOMEvents_MozMagnifyGestureUpdate
];
1519 case NS_SIMPLE_GESTURE_MAGNIFY
:
1520 return sEventNames
[eDOMEvents_MozMagnifyGesture
];
1521 case NS_SIMPLE_GESTURE_ROTATE_START
:
1522 return sEventNames
[eDOMEvents_MozRotateGestureStart
];
1523 case NS_SIMPLE_GESTURE_ROTATE_UPDATE
:
1524 return sEventNames
[eDOMEvents_MozRotateGestureUpdate
];
1525 case NS_SIMPLE_GESTURE_ROTATE
:
1526 return sEventNames
[eDOMEvents_MozRotateGesture
];
1530 // XXXldb We can hit this case for nsEvent objects that we didn't
1531 // create and that are not user defined events since this function and
1532 // SetEventType are incomplete. (But fixing that requires fixing the
1533 // arrays in nsEventListenerManager too, since the events for which
1534 // this is a problem generally *are* created by nsDOMEvent.)
1538 nsresult
NS_NewDOMEvent(nsIDOMEvent
** aInstancePtrResult
,
1539 nsPresContext
* aPresContext
,
1542 nsDOMEvent
* it
= new nsDOMEvent(aPresContext
, aEvent
);
1544 return NS_ERROR_OUT_OF_MEMORY
;
1547 return CallQueryInterface(it
, aInstancePtrResult
);