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", "offline", "online",
74 "copy", "cut", "paste"
77 "SVGLoad", "SVGUnload", "SVGAbort", "SVGError", "SVGResize", "SVGScroll",
82 "loadstart", "progress", "loadedmetadata", "loadedfirstframe",
83 "emptied", "stalled", "play", "pause",
84 "waiting", "seeking", "seeked", "timeupdate", "ended", "dataunavailable",
85 "canshowcurrentframe", "canplay", "canplaythrough", "ratechange",
86 "durationchange", "volumechange"
90 static char *sPopupAllowedEvents
;
93 nsDOMEvent::nsDOMEvent(nsPresContext
* aPresContext
, nsEvent
* aEvent
)
95 mPresContext
= aPresContext
;
96 mPrivateDataDuplicated
= PR_FALSE
;
100 mEventIsInternal
= PR_FALSE
;
103 mEventIsInternal
= PR_TRUE
;
105 A derived class might want to allocate its own type of aEvent
106 (derived from nsEvent). To do this, it should take care to pass
107 a non-NULL aEvent to this ctor, e.g.:
109 nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
110 : nsDOMEvent(..., aEvent ? aEvent : new nsFooEvent())
112 Then, to override the mEventIsInternal assignments done by the
113 base ctor, it should do this in its own ctor:
115 nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
120 mEventIsInternal = PR_FALSE;
123 mEventIsInternal = PR_TRUE;
128 mEvent
= new nsEvent(PR_FALSE
, 0);
129 mEvent
->time
= PR_Now();
132 // Get the explicit original target (if it's anonymous make it null)
134 mExplicitOriginalTarget
= GetTargetFromFrame();
135 mTmpRealOriginalTarget
= mExplicitOriginalTarget
;
136 nsCOMPtr
<nsIContent
> content
= do_QueryInterface(mExplicitOriginalTarget
);
137 if (content
&& content
->IsInAnonymousSubtree()) {
138 mExplicitOriginalTarget
= nsnull
;
143 nsDOMEvent::~nsDOMEvent()
145 NS_ASSERT_OWNINGTHREAD(nsDOMEvent
);
147 if (mEventIsInternal
&& mEvent
) {
152 NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMEvent
)
154 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMEvent
)
155 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIDOMEvent
)
156 NS_INTERFACE_MAP_ENTRY(nsIDOMEvent
)
157 NS_INTERFACE_MAP_ENTRY(nsIDOMNSEvent
)
158 NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMEvent
)
159 NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Event
)
162 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMEvent
)
163 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMEvent
)
165 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMEvent
)
166 if (tmp
->mEventIsInternal
) {
167 tmp
->mEvent
->target
= nsnull
;
168 tmp
->mEvent
->currentTarget
= nsnull
;
169 tmp
->mEvent
->originalTarget
= nsnull
;
170 switch (tmp
->mEvent
->eventStructType
) {
172 case NS_MOUSE_SCROLL_EVENT
:
173 static_cast<nsMouseEvent_base
*>(tmp
->mEvent
)->relatedTarget
= nsnull
;
176 static_cast<nsDragEvent
*>(tmp
->mEvent
)->dataTransfer
= nsnull
;
178 case NS_XUL_COMMAND_EVENT
:
179 static_cast<nsXULCommandEvent
*>(tmp
->mEvent
)->sourceEvent
= nsnull
;
181 case NS_MUTATION_EVENT
:
182 static_cast<nsMutationEvent
*>(tmp
->mEvent
)->mRelatedNode
= nsnull
;
188 NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPresContext
);
189 NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTmpRealOriginalTarget
)
190 NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mExplicitOriginalTarget
)
191 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
193 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMEvent
)
194 if (tmp
->mEventIsInternal
) {
195 cb
.NoteXPCOMChild(tmp
->mEvent
->target
);
196 cb
.NoteXPCOMChild(tmp
->mEvent
->currentTarget
);
197 cb
.NoteXPCOMChild(tmp
->mEvent
->originalTarget
);
198 switch (tmp
->mEvent
->eventStructType
) {
200 case NS_MOUSE_SCROLL_EVENT
:
202 static_cast<nsMouseEvent_base
*>(tmp
->mEvent
)->relatedTarget
);
206 static_cast<nsDragEvent
*>(tmp
->mEvent
)->dataTransfer
);
208 case NS_XUL_COMMAND_EVENT
:
210 static_cast<nsXULCommandEvent
*>(tmp
->mEvent
)->sourceEvent
);
212 case NS_MUTATION_EVENT
:
214 static_cast<nsMutationEvent
*>(tmp
->mEvent
)->mRelatedNode
);
220 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPresContext
)
221 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTmpRealOriginalTarget
)
222 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mExplicitOriginalTarget
)
223 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
225 // nsIDOMEventInterface
226 NS_METHOD
nsDOMEvent::GetType(nsAString
& aType
)
228 const char* name
= GetEventName(mEvent
->message
);
231 CopyASCIItoUTF16(name
, aType
);
233 } else if (mEvent
->message
== NS_USER_DEFINED_EVENT
&& mEvent
->userType
) {
235 mEvent
->userType
->ToString(name
);
236 aType
= Substring(name
, 2, name
.Length() - 2); // Remove "on"
240 return NS_ERROR_FAILURE
;
244 GetDOMEventTarget(nsISupports
* aTarget
,
245 nsIDOMEventTarget
** aDOMTarget
)
247 nsCOMPtr
<nsPIDOMEventTarget
> piTarget
= do_QueryInterface(aTarget
);
248 nsISupports
* realTarget
=
249 piTarget
? piTarget
->GetTargetForDOMEvent() : aTarget
;
251 return CallQueryInterface(realTarget
, aDOMTarget
);
254 *aDOMTarget
= nsnull
;
259 nsDOMEvent::GetTarget(nsIDOMEventTarget
** aTarget
)
261 return GetDOMEventTarget(mEvent
->target
, aTarget
);
265 nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget
** aCurrentTarget
)
267 return GetDOMEventTarget(mEvent
->currentTarget
, aCurrentTarget
);
271 // Get the actual event target node (may have been retargeted for mouse events)
273 already_AddRefed
<nsIDOMEventTarget
>
274 nsDOMEvent::GetTargetFromFrame()
276 if (!mPresContext
) { return nsnull
; }
278 // Get the target frame (have to get the ESM first)
279 nsIFrame
* targetFrame
= nsnull
;
280 mPresContext
->EventStateManager()->GetEventTarget(&targetFrame
);
281 if (!targetFrame
) { return nsnull
; }
283 // get the real content
284 nsCOMPtr
<nsIContent
> realEventContent
;
285 targetFrame
->GetContentForEvent(mPresContext
, mEvent
, getter_AddRefs(realEventContent
));
286 if (!realEventContent
) { return nsnull
; }
288 // Finally, we have the real content. QI it and return.
289 nsIDOMEventTarget
* target
= nsnull
;
290 CallQueryInterface(realEventContent
, &target
);
295 nsDOMEvent::GetExplicitOriginalTarget(nsIDOMEventTarget
** aRealEventTarget
)
297 if (mExplicitOriginalTarget
) {
298 *aRealEventTarget
= mExplicitOriginalTarget
;
299 NS_ADDREF(*aRealEventTarget
);
303 return GetTarget(aRealEventTarget
);
307 nsDOMEvent::GetTmpRealOriginalTarget(nsIDOMEventTarget
** aRealEventTarget
)
309 if (mTmpRealOriginalTarget
) {
310 *aRealEventTarget
= mTmpRealOriginalTarget
;
311 NS_ADDREF(*aRealEventTarget
);
315 return GetOriginalTarget(aRealEventTarget
);
319 nsDOMEvent::GetOriginalTarget(nsIDOMEventTarget
** aOriginalTarget
)
321 if (mEvent
->originalTarget
) {
322 return GetDOMEventTarget(mEvent
->originalTarget
, aOriginalTarget
);
325 return GetTarget(aOriginalTarget
);
329 nsDOMEvent::HasOriginalTarget(PRBool
* aResult
)
331 *aResult
= !!(mEvent
->originalTarget
);
336 nsDOMEvent::SetTrusted(PRBool aTrusted
)
339 mEvent
->flags
|= NS_EVENT_FLAG_TRUSTED
;
341 mEvent
->flags
&= ~NS_EVENT_FLAG_TRUSTED
;
348 nsDOMEvent::GetEventPhase(PRUint16
* aEventPhase
)
350 // Note, remember to check that this works also
351 // if or when Bug 235441 is fixed.
352 if (mEvent
->currentTarget
== mEvent
->target
||
353 ((mEvent
->flags
& NS_EVENT_FLAG_CAPTURE
) &&
354 (mEvent
->flags
& NS_EVENT_FLAG_BUBBLE
))) {
355 *aEventPhase
= nsIDOMEvent::AT_TARGET
;
356 } else if (mEvent
->flags
& NS_EVENT_FLAG_CAPTURE
) {
357 *aEventPhase
= nsIDOMEvent::CAPTURING_PHASE
;
358 } else if (mEvent
->flags
& NS_EVENT_FLAG_BUBBLE
) {
359 *aEventPhase
= nsIDOMEvent::BUBBLING_PHASE
;
367 nsDOMEvent::GetBubbles(PRBool
* aBubbles
)
369 *aBubbles
= !(mEvent
->flags
& NS_EVENT_FLAG_CANT_BUBBLE
);
374 nsDOMEvent::GetCancelable(PRBool
* aCancelable
)
376 *aCancelable
= !(mEvent
->flags
& NS_EVENT_FLAG_CANT_CANCEL
);
381 nsDOMEvent::GetTimeStamp(PRUint64
* aTimeStamp
)
383 LL_UI2L(*aTimeStamp
, mEvent
->time
);
388 nsDOMEvent::StopPropagation()
390 mEvent
->flags
|= NS_EVENT_FLAG_STOP_DISPATCH
;
395 ReportUseOfDeprecatedMethod(nsEvent
* aEvent
, nsIDOMEvent
* aDOMEvent
,
396 const char* aWarning
)
398 nsCOMPtr
<nsIDocument
> doc
;
399 nsCOMPtr
<nsINode
> node
= do_QueryInterface(aEvent
->currentTarget
);
401 doc
= node
->GetOwnerDoc();
403 nsCOMPtr
<nsPIDOMWindow
> window
= do_QueryInterface(aEvent
->currentTarget
);
405 doc
= do_QueryInterface(window
->GetExtantDocument());
410 aDOMEvent
->GetType(type
);
411 const PRUnichar
*strings
[] = { type
.get() };
412 nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES
,
414 strings
, NS_ARRAY_LENGTH(strings
),
415 doc
? doc
->GetDocumentURI() : nsnull
,
417 nsIScriptError::warningFlag
,
422 nsDOMEvent::PreventBubble()
424 ReportUseOfDeprecatedMethod(mEvent
, this, "UseOfPreventBubbleWarning");
429 nsDOMEvent::PreventCapture()
431 ReportUseOfDeprecatedMethod(mEvent
, this, "UseOfPreventCaptureWarning");
436 nsDOMEvent::GetIsTrusted(PRBool
*aIsTrusted
)
438 *aIsTrusted
= NS_IS_TRUSTED_EVENT(mEvent
);
444 nsDOMEvent::PreventDefault()
446 if (!(mEvent
->flags
& NS_EVENT_FLAG_CANT_CANCEL
)) {
447 mEvent
->flags
|= NS_EVENT_FLAG_NO_DEFAULT
;
453 nsDOMEvent::SetEventType(const nsAString
& aEventTypeArg
)
455 nsCOMPtr
<nsIAtom
> atom
= do_GetAtom(NS_LITERAL_STRING("on") + aEventTypeArg
);
456 mEvent
->message
= NS_USER_DEFINED_EVENT
;
458 if (mEvent
->eventStructType
== NS_MOUSE_EVENT
) {
459 if (atom
== nsGkAtoms::onmousedown
)
460 mEvent
->message
= NS_MOUSE_BUTTON_DOWN
;
461 else if (atom
== nsGkAtoms::onmouseup
)
462 mEvent
->message
= NS_MOUSE_BUTTON_UP
;
463 else if (atom
== nsGkAtoms::onclick
)
464 mEvent
->message
= NS_MOUSE_CLICK
;
465 else if (atom
== nsGkAtoms::ondblclick
)
466 mEvent
->message
= NS_MOUSE_DOUBLECLICK
;
467 else if (atom
== nsGkAtoms::onmouseover
)
468 mEvent
->message
= NS_MOUSE_ENTER_SYNTH
;
469 else if (atom
== nsGkAtoms::onmouseout
)
470 mEvent
->message
= NS_MOUSE_EXIT_SYNTH
;
471 else if (atom
== nsGkAtoms::onmousemove
)
472 mEvent
->message
= NS_MOUSE_MOVE
;
473 else if (atom
== nsGkAtoms::oncontextmenu
)
474 mEvent
->message
= NS_CONTEXTMENU
;
475 } else if (mEvent
->eventStructType
== NS_MOUSE_SCROLL_EVENT
) {
476 if (atom
== nsGkAtoms::onDOMMouseScroll
)
477 mEvent
->message
= NS_MOUSE_SCROLL
;
478 } else if (mEvent
->eventStructType
== NS_DRAG_EVENT
) {
479 if (atom
== nsGkAtoms::ondragstart
)
480 mEvent
->message
= NS_DRAGDROP_START
;
481 else if (atom
== nsGkAtoms::ondraggesture
)
482 mEvent
->message
= NS_DRAGDROP_GESTURE
;
483 else if (atom
== nsGkAtoms::ondragenter
)
484 mEvent
->message
= NS_DRAGDROP_ENTER
;
485 else if (atom
== nsGkAtoms::ondragover
)
486 mEvent
->message
= NS_DRAGDROP_OVER_SYNTH
;
487 else if (atom
== nsGkAtoms::ondragleave
)
488 mEvent
->message
= NS_DRAGDROP_LEAVE_SYNTH
;
489 else if (atom
== nsGkAtoms::ondragexit
)
490 mEvent
->message
= NS_DRAGDROP_EXIT
;
491 else if (atom
== nsGkAtoms::ondrag
)
492 mEvent
->message
= NS_DRAGDROP_DRAG
;
493 else if (atom
== nsGkAtoms::ondrop
)
494 mEvent
->message
= NS_DRAGDROP_DROP
;
495 else if (atom
== nsGkAtoms::ondragdrop
)
496 mEvent
->message
= NS_DRAGDROP_DRAGDROP
;
497 else if (atom
== nsGkAtoms::ondragend
)
498 mEvent
->message
= NS_DRAGDROP_END
;
499 } else if (mEvent
->eventStructType
== NS_KEY_EVENT
) {
500 if (atom
== nsGkAtoms::onkeydown
)
501 mEvent
->message
= NS_KEY_DOWN
;
502 else if (atom
== nsGkAtoms::onkeyup
)
503 mEvent
->message
= NS_KEY_UP
;
504 else if (atom
== nsGkAtoms::onkeypress
)
505 mEvent
->message
= NS_KEY_PRESS
;
506 } else if (mEvent
->eventStructType
== NS_COMPOSITION_EVENT
) {
507 if (atom
== nsGkAtoms::oncompositionstart
)
508 mEvent
->message
= NS_COMPOSITION_START
;
509 else if (atom
== nsGkAtoms::oncompositionend
)
510 mEvent
->message
= NS_COMPOSITION_END
;
511 } else if (mEvent
->eventStructType
== NS_EVENT
) {
512 if (atom
== nsGkAtoms::onfocus
)
513 mEvent
->message
= NS_FOCUS_CONTENT
;
514 else if (atom
== nsGkAtoms::onblur
)
515 mEvent
->message
= NS_BLUR_CONTENT
;
516 else if (atom
== nsGkAtoms::onsubmit
)
517 mEvent
->message
= NS_FORM_SUBMIT
;
518 else if (atom
== nsGkAtoms::onreset
)
519 mEvent
->message
= NS_FORM_RESET
;
520 else if (atom
== nsGkAtoms::onchange
)
521 mEvent
->message
= NS_FORM_CHANGE
;
522 else if (atom
== nsGkAtoms::onselect
)
523 mEvent
->message
= NS_FORM_SELECTED
;
524 else if (atom
== nsGkAtoms::onload
)
525 mEvent
->message
= NS_LOAD
;
526 else if (atom
== nsGkAtoms::onunload
)
527 mEvent
->message
= NS_PAGE_UNLOAD
;
528 else if (atom
== nsGkAtoms::onabort
)
529 mEvent
->message
= NS_IMAGE_ABORT
;
530 else if (atom
== nsGkAtoms::onerror
)
531 mEvent
->message
= NS_LOAD_ERROR
;
532 else if (atom
== nsGkAtoms::onoffline
)
533 mEvent
->message
= NS_OFFLINE
;
534 else if (atom
== nsGkAtoms::ononline
)
535 mEvent
->message
= NS_ONLINE
;
536 else if (atom
== nsGkAtoms::oncopy
)
537 mEvent
->message
= NS_COPY
;
538 else if (atom
== nsGkAtoms::oncut
)
539 mEvent
->message
= NS_CUT
;
540 else if (atom
== nsGkAtoms::onpaste
)
541 mEvent
->message
= NS_PASTE
;
542 } else if (mEvent
->eventStructType
== NS_MUTATION_EVENT
) {
543 if (atom
== nsGkAtoms::onDOMAttrModified
)
544 mEvent
->message
= NS_MUTATION_ATTRMODIFIED
;
545 else if (atom
== nsGkAtoms::onDOMCharacterDataModified
)
546 mEvent
->message
= NS_MUTATION_CHARACTERDATAMODIFIED
;
547 else if (atom
== nsGkAtoms::onDOMNodeInserted
)
548 mEvent
->message
= NS_MUTATION_NODEINSERTED
;
549 else if (atom
== nsGkAtoms::onDOMNodeRemoved
)
550 mEvent
->message
= NS_MUTATION_NODEREMOVED
;
551 else if (atom
== nsGkAtoms::onDOMNodeInsertedIntoDocument
)
552 mEvent
->message
= NS_MUTATION_NODEINSERTEDINTODOCUMENT
;
553 else if (atom
== nsGkAtoms::onDOMNodeRemovedFromDocument
)
554 mEvent
->message
= NS_MUTATION_NODEREMOVEDFROMDOCUMENT
;
555 else if (atom
== nsGkAtoms::onDOMSubtreeModified
)
556 mEvent
->message
= NS_MUTATION_SUBTREEMODIFIED
;
557 } else if (mEvent
->eventStructType
== NS_UI_EVENT
) {
558 if (atom
== nsGkAtoms::onDOMActivate
)
559 mEvent
->message
= NS_UI_ACTIVATE
;
560 else if (atom
== nsGkAtoms::onDOMFocusIn
)
561 mEvent
->message
= NS_UI_FOCUSIN
;
562 else if (atom
== nsGkAtoms::onDOMFocusOut
)
563 mEvent
->message
= NS_UI_FOCUSOUT
;
564 else if (atom
== nsGkAtoms::oninput
)
565 mEvent
->message
= NS_FORM_INPUT
;
566 } else if (mEvent
->eventStructType
== NS_PAGETRANSITION_EVENT
) {
567 if (atom
== nsGkAtoms::onpageshow
)
568 mEvent
->message
= NS_PAGE_SHOW
;
569 else if (atom
== nsGkAtoms::onpagehide
)
570 mEvent
->message
= NS_PAGE_HIDE
;
571 } else if (mEvent
->eventStructType
== NS_XUL_COMMAND_EVENT
) {
572 if (atom
== nsGkAtoms::oncommand
)
573 mEvent
->message
= NS_XUL_COMMAND
;
576 else if (mEvent
->eventStructType
== NS_SVG_EVENT
) {
577 if (atom
== nsGkAtoms::onSVGLoad
)
578 mEvent
->message
= NS_SVG_LOAD
;
579 else if (atom
== nsGkAtoms::onSVGUnload
)
580 mEvent
->message
= NS_SVG_UNLOAD
;
581 else if (atom
== nsGkAtoms::onSVGAbort
)
582 mEvent
->message
= NS_SVG_ABORT
;
583 else if (atom
== nsGkAtoms::onSVGError
)
584 mEvent
->message
= NS_SVG_ERROR
;
585 else if (atom
== nsGkAtoms::onSVGResize
)
586 mEvent
->message
= NS_SVG_RESIZE
;
587 else if (atom
== nsGkAtoms::onSVGScroll
)
588 mEvent
->message
= NS_SVG_SCROLL
;
589 } else if (mEvent
->eventStructType
== NS_SVGZOOM_EVENT
) {
590 if (atom
== nsGkAtoms::onSVGZoom
)
591 mEvent
->message
= NS_SVG_ZOOM
;
596 else if (mEvent
->eventStructType
== NS_MEDIA_EVENT
) {
597 if (atom
== nsGkAtoms::onloadstart
)
598 mEvent
->message
= NS_LOADSTART
;
599 else if (atom
== nsGkAtoms::onprogress
)
600 mEvent
->message
= NS_PROGRESS
;
601 else if (atom
== nsGkAtoms::onloadedmetadata
)
602 mEvent
->message
= NS_LOADEDMETADATA
;
603 else if (atom
== nsGkAtoms::onloadedfirstframe
)
604 mEvent
->message
= NS_LOADEDFIRSTFRAME
;
605 else if (atom
== nsGkAtoms::onemptied
)
606 mEvent
->message
= NS_EMPTIED
;
607 else if (atom
== nsGkAtoms::onstalled
)
608 mEvent
->message
= NS_STALLED
;
609 else if (atom
== nsGkAtoms::onplay
)
610 mEvent
->message
= NS_PLAY
;
611 else if (atom
== nsGkAtoms::onpause
)
612 mEvent
->message
= NS_PAUSE
;
613 else if (atom
== nsGkAtoms::onwaiting
)
614 mEvent
->message
= NS_WAITING
;
615 else if (atom
== nsGkAtoms::onwaiting
)
616 mEvent
->message
= NS_SEEKING
;
617 else if (atom
== nsGkAtoms::onseeking
)
618 mEvent
->message
= NS_SEEKED
;
619 else if (atom
== nsGkAtoms::onseeked
)
620 mEvent
->message
= NS_TIMEUPDATE
;
621 else if (atom
== nsGkAtoms::onended
)
622 mEvent
->message
= NS_ENDED
;
623 else if (atom
== nsGkAtoms::ondataunavailable
)
624 mEvent
->message
= NS_DATAUNAVAILABLE
;
625 else if (atom
== nsGkAtoms::oncanshowcurrentframe
)
626 mEvent
->message
= NS_CANSHOWCURRENTFRAME
;
627 else if (atom
== nsGkAtoms::oncanplay
)
628 mEvent
->message
= NS_CANPLAY
;
629 else if (atom
== nsGkAtoms::oncanplaythrough
)
630 mEvent
->message
= NS_CANPLAYTHROUGH
;
631 else if (atom
== nsGkAtoms::onratechange
)
632 mEvent
->message
= NS_RATECHANGE
;
633 else if (atom
== nsGkAtoms::ondurationchange
)
634 mEvent
->message
= NS_DURATIONCHANGE
;
635 else if (atom
== nsGkAtoms::onvolumechange
)
636 mEvent
->message
= NS_VOLUMECHANGE
;
637 else if (atom
== nsGkAtoms::onload
)
638 mEvent
->message
= NS_LOAD
;
639 else if (atom
== nsGkAtoms::onabort
)
640 mEvent
->message
= NS_MEDIA_ABORT
;
641 else if (atom
== nsGkAtoms::onerror
)
642 mEvent
->message
= NS_MEDIA_ERROR
;
645 if (mEvent
->message
== NS_USER_DEFINED_EVENT
)
646 mEvent
->userType
= atom
;
652 nsDOMEvent::InitEvent(const nsAString
& aEventTypeArg
, PRBool aCanBubbleArg
, PRBool aCancelableArg
)
654 // Make sure this event isn't already being dispatched.
655 NS_ENSURE_TRUE(!NS_IS_EVENT_IN_DISPATCH(mEvent
), NS_ERROR_INVALID_ARG
);
657 if (NS_IS_TRUSTED_EVENT(mEvent
)) {
658 // Ensure the caller is permitted to dispatch trusted DOM events.
660 PRBool enabled
= PR_FALSE
;
661 nsContentUtils::GetSecurityManager()->
662 IsCapabilityEnabled("UniversalBrowserWrite", &enabled
);
665 SetTrusted(PR_FALSE
);
669 NS_ENSURE_SUCCESS(SetEventType(aEventTypeArg
), NS_ERROR_FAILURE
);
672 mEvent
->flags
&= ~NS_EVENT_FLAG_CANT_BUBBLE
;
674 mEvent
->flags
|= NS_EVENT_FLAG_CANT_BUBBLE
;
677 if (aCancelableArg
) {
678 mEvent
->flags
&= ~NS_EVENT_FLAG_CANT_CANCEL
;
680 mEvent
->flags
|= NS_EVENT_FLAG_CANT_CANCEL
;
683 // Clearing the old targets, so that the event is targeted correctly when
684 // re-dispatching it.
685 mEvent
->target
= nsnull
;
686 mEvent
->originalTarget
= nsnull
;
691 NS_METHOD
nsDOMEvent::DuplicatePrivateData()
693 // FIXME! Simplify this method and make it somehow easily extendable,
696 NS_ASSERTION(mEvent
, "No nsEvent for nsDOMEvent duplication!");
697 if (mEventIsInternal
) {
701 nsEvent
* newEvent
= nsnull
;
702 PRUint32 msg
= mEvent
->message
;
703 PRBool isInputEvent
= PR_FALSE
;
705 switch (mEvent
->eventStructType
) {
708 newEvent
= new nsEvent(PR_FALSE
, msg
);
713 // Not copying widget, it is a weak reference.
714 newEvent
= new nsGUIEvent(PR_FALSE
, msg
, nsnull
);
719 nsSizeEvent
* sizeEvent
= new nsSizeEvent(PR_FALSE
, msg
, nsnull
);
720 NS_ENSURE_TRUE(sizeEvent
, NS_ERROR_OUT_OF_MEMORY
);
721 sizeEvent
->mWinWidth
= static_cast<nsSizeEvent
*>(mEvent
)->mWinWidth
;
722 sizeEvent
->mWinHeight
= static_cast<nsSizeEvent
*>(mEvent
)->mWinHeight
;
723 newEvent
= sizeEvent
;
726 case NS_SIZEMODE_EVENT
:
728 newEvent
= new nsSizeModeEvent(PR_FALSE
, msg
, nsnull
);
729 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
730 static_cast<nsSizeModeEvent
*>(newEvent
)->mSizeMode
=
731 static_cast<nsSizeModeEvent
*>(mEvent
)->mSizeMode
;
734 case NS_ZLEVEL_EVENT
:
736 nsZLevelEvent
* zLevelEvent
= new nsZLevelEvent(PR_FALSE
, msg
, nsnull
);
737 NS_ENSURE_TRUE(zLevelEvent
, NS_ERROR_OUT_OF_MEMORY
);
738 nsZLevelEvent
* oldZLevelEvent
= static_cast<nsZLevelEvent
*>(mEvent
);
739 zLevelEvent
->mPlacement
= oldZLevelEvent
->mPlacement
;
740 zLevelEvent
->mImmediate
= oldZLevelEvent
->mImmediate
;
741 zLevelEvent
->mAdjusted
= oldZLevelEvent
->mAdjusted
;
742 newEvent
= zLevelEvent
;
747 newEvent
= new nsPaintEvent(PR_FALSE
, msg
, nsnull
);
750 case NS_SCROLLBAR_EVENT
:
752 newEvent
= new nsScrollbarEvent(PR_FALSE
, msg
, nsnull
);
753 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
754 static_cast<nsScrollbarEvent
*>(newEvent
)->position
=
755 static_cast<nsScrollbarEvent
*>(mEvent
)->position
;
760 newEvent
= new nsInputEvent(PR_FALSE
, msg
, nsnull
);
761 isInputEvent
= PR_TRUE
;
766 nsKeyEvent
* keyEvent
= new nsKeyEvent(PR_FALSE
, msg
, nsnull
);
767 NS_ENSURE_TRUE(keyEvent
, NS_ERROR_OUT_OF_MEMORY
);
768 nsKeyEvent
* oldKeyEvent
= static_cast<nsKeyEvent
*>(mEvent
);
769 isInputEvent
= PR_TRUE
;
770 keyEvent
->keyCode
= oldKeyEvent
->keyCode
;
771 keyEvent
->charCode
= oldKeyEvent
->charCode
;
772 keyEvent
->isChar
= oldKeyEvent
->isChar
;
778 nsMouseEvent
* oldMouseEvent
= static_cast<nsMouseEvent
*>(mEvent
);
779 nsMouseEvent
* mouseEvent
=
780 new nsMouseEvent(PR_FALSE
, msg
, nsnull
, oldMouseEvent
->reason
);
781 NS_ENSURE_TRUE(mouseEvent
, NS_ERROR_OUT_OF_MEMORY
);
782 isInputEvent
= PR_TRUE
;
783 mouseEvent
->clickCount
= oldMouseEvent
->clickCount
;
784 mouseEvent
->acceptActivation
= oldMouseEvent
->acceptActivation
;
785 mouseEvent
->context
= oldMouseEvent
->context
;
786 mouseEvent
->relatedTarget
= oldMouseEvent
->relatedTarget
;
787 mouseEvent
->button
= oldMouseEvent
->button
;
788 newEvent
= mouseEvent
;
793 nsDragEvent
* oldDragEvent
= static_cast<nsDragEvent
*>(mEvent
);
794 nsDragEvent
* dragEvent
=
795 new nsDragEvent(PR_FALSE
, msg
, nsnull
);
796 NS_ENSURE_TRUE(dragEvent
, NS_ERROR_OUT_OF_MEMORY
);
797 isInputEvent
= PR_TRUE
;
798 dragEvent
->dataTransfer
= oldDragEvent
->dataTransfer
;
799 dragEvent
->clickCount
= oldDragEvent
->clickCount
;
800 dragEvent
->acceptActivation
= oldDragEvent
->acceptActivation
;
801 dragEvent
->relatedTarget
= oldDragEvent
->relatedTarget
;
802 dragEvent
->button
= oldDragEvent
->button
;
803 newEvent
= dragEvent
;
808 newEvent
= new nsMenuEvent(PR_FALSE
, msg
, nsnull
);
809 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
810 static_cast<nsMenuEvent
*>(newEvent
)->mCommand
=
811 static_cast<nsMenuEvent
*>(mEvent
)->mCommand
;
814 case NS_SCRIPT_ERROR_EVENT
:
816 newEvent
= new nsScriptErrorEvent(PR_FALSE
, msg
);
817 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
818 static_cast<nsScriptErrorEvent
*>(newEvent
)->lineNr
=
819 static_cast<nsScriptErrorEvent
*>(mEvent
)->lineNr
;
824 newEvent
= new nsTextEvent(PR_FALSE
, msg
, nsnull
);
825 isInputEvent
= PR_TRUE
;
828 case NS_COMPOSITION_EVENT
:
830 newEvent
= new nsCompositionEvent(PR_FALSE
, msg
, nsnull
);
831 isInputEvent
= PR_TRUE
;
834 case NS_MOUSE_SCROLL_EVENT
:
836 nsMouseScrollEvent
* mouseScrollEvent
=
837 new nsMouseScrollEvent(PR_FALSE
, msg
, nsnull
);
838 NS_ENSURE_TRUE(mouseScrollEvent
, NS_ERROR_OUT_OF_MEMORY
);
839 isInputEvent
= PR_TRUE
;
840 nsMouseScrollEvent
* oldMouseScrollEvent
=
841 static_cast<nsMouseScrollEvent
*>(mEvent
);
842 mouseScrollEvent
->scrollFlags
= oldMouseScrollEvent
->scrollFlags
;
843 mouseScrollEvent
->delta
= oldMouseScrollEvent
->delta
;
844 mouseScrollEvent
->relatedTarget
= oldMouseScrollEvent
->relatedTarget
;
845 mouseScrollEvent
->button
= oldMouseScrollEvent
->button
;
846 newEvent
= mouseScrollEvent
;
849 case NS_SCROLLPORT_EVENT
:
851 newEvent
= new nsScrollPortEvent(PR_FALSE
, msg
, nsnull
);
852 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
853 static_cast<nsScrollPortEvent
*>(newEvent
)->orient
=
854 static_cast<nsScrollPortEvent
*>(mEvent
)->orient
;
857 case NS_MUTATION_EVENT
:
859 nsMutationEvent
* mutationEvent
= new nsMutationEvent(PR_FALSE
, msg
);
860 NS_ENSURE_TRUE(mutationEvent
, NS_ERROR_OUT_OF_MEMORY
);
861 nsMutationEvent
* oldMutationEvent
=
862 static_cast<nsMutationEvent
*>(mEvent
);
863 mutationEvent
->mRelatedNode
= oldMutationEvent
->mRelatedNode
;
864 mutationEvent
->mAttrName
= oldMutationEvent
->mAttrName
;
865 mutationEvent
->mPrevAttrValue
= oldMutationEvent
->mPrevAttrValue
;
866 mutationEvent
->mNewAttrValue
= oldMutationEvent
->mNewAttrValue
;
867 mutationEvent
->mAttrChange
= oldMutationEvent
->mAttrChange
;
868 newEvent
= mutationEvent
;
871 case NS_ACCESSIBLE_EVENT
:
873 newEvent
= new nsAccessibleEvent(PR_FALSE
, msg
, nsnull
);
874 isInputEvent
= PR_TRUE
;
879 newEvent
= new nsFormEvent(PR_FALSE
, msg
);
884 newEvent
= new nsFocusEvent(PR_FALSE
, msg
, nsnull
);
885 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
886 static_cast<nsFocusEvent
*>(newEvent
)->isMozWindowTakingFocus
=
887 static_cast<nsFocusEvent
*>(mEvent
)->isMozWindowTakingFocus
;
892 newEvent
= new nsInputEvent(PR_FALSE
, msg
, nsnull
);
893 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
894 isInputEvent
= PR_TRUE
;
895 newEvent
->eventStructType
= NS_POPUP_EVENT
;
898 case NS_COMMAND_EVENT
:
900 newEvent
= new nsCommandEvent(PR_FALSE
, mEvent
->userType
,
901 static_cast<nsCommandEvent
*>(mEvent
)->command
, nsnull
);
902 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
905 case NS_POPUPBLOCKED_EVENT
:
907 NS_WARNING("nsPopupBlockedEvent should never be an external event!");
908 newEvent
= new nsPopupBlockedEvent(PR_FALSE
, msg
);
911 case NS_BEFORE_PAGE_UNLOAD_EVENT
:
913 newEvent
= new nsBeforePageUnloadEvent(PR_FALSE
, msg
);
914 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
915 static_cast<nsBeforePageUnloadEvent
*>(newEvent
)->text
=
916 static_cast<nsBeforePageUnloadEvent
*>(mEvent
)->text
;
921 newEvent
= new nsUIEvent(PR_FALSE
, msg
,
922 static_cast<nsUIEvent
*>(mEvent
)->detail
);
925 case NS_PAGETRANSITION_EVENT
:
928 new nsPageTransitionEvent(PR_FALSE
, msg
,
929 ((nsPageTransitionEvent
*) mEvent
)->persisted
);
935 newEvent
= new nsEvent(PR_FALSE
, msg
);
936 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
937 newEvent
->eventStructType
= NS_SVG_EVENT
;
940 case NS_SVGZOOM_EVENT
:
942 newEvent
= new nsGUIEvent(PR_FALSE
, msg
, nsnull
);
943 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
944 newEvent
->eventStructType
= NS_SVGZOOM_EVENT
;
948 case NS_XUL_COMMAND_EVENT
:
950 newEvent
= new nsXULCommandEvent(PR_FALSE
, msg
, nsnull
);
951 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
952 isInputEvent
= PR_TRUE
;
953 newEvent
->eventStructType
= NS_XUL_COMMAND_EVENT
;
954 static_cast<nsXULCommandEvent
*>(newEvent
)->sourceEvent
=
955 static_cast<nsXULCommandEvent
*>(mEvent
)->sourceEvent
;
960 NS_WARNING("Unknown event type!!!");
961 return NS_ERROR_FAILURE
;
965 NS_ENSURE_TRUE(newEvent
, NS_ERROR_OUT_OF_MEMORY
);
968 nsInputEvent
* oldInputEvent
= static_cast<nsInputEvent
*>(mEvent
);
969 nsInputEvent
* newInputEvent
= static_cast<nsInputEvent
*>(newEvent
);
970 newInputEvent
->isShift
= oldInputEvent
->isShift
;
971 newInputEvent
->isControl
= oldInputEvent
->isControl
;
972 newInputEvent
->isAlt
= oldInputEvent
->isAlt
;
973 newInputEvent
->isMeta
= oldInputEvent
->isMeta
;
976 newEvent
->target
= mEvent
->target
;
977 newEvent
->currentTarget
= mEvent
->currentTarget
;
978 newEvent
->originalTarget
= mEvent
->originalTarget
;
979 newEvent
->flags
= mEvent
->flags
;
980 newEvent
->time
= mEvent
->time
;
981 newEvent
->refPoint
= mEvent
->refPoint
;
982 newEvent
->userType
= mEvent
->userType
;
985 mPresContext
= nsnull
;
986 mEventIsInternal
= PR_TRUE
;
987 mPrivateDataDuplicated
= PR_TRUE
;
992 NS_METHOD
nsDOMEvent::SetTarget(nsIDOMEventTarget
* aTarget
)
996 nsCOMPtr
<nsPIDOMWindow
> win
= do_QueryInterface(aTarget
);
998 NS_ASSERTION(!win
|| !win
->IsInnerWindow(),
999 "Uh, inner window set as event target!");
1003 mEvent
->target
= aTarget
;
1007 NS_METHOD
nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget
* aCurrentTarget
)
1011 nsCOMPtr
<nsPIDOMWindow
> win
= do_QueryInterface(aCurrentTarget
);
1013 NS_ASSERTION(!win
|| !win
->IsInnerWindow(),
1014 "Uh, inner window set as event target!");
1018 mEvent
->currentTarget
= aCurrentTarget
;
1022 NS_METHOD
nsDOMEvent::SetOriginalTarget(nsIDOMEventTarget
* aOriginalTarget
)
1026 nsCOMPtr
<nsPIDOMWindow
> win
= do_QueryInterface(aOriginalTarget
);
1028 NS_ASSERTION(!win
|| !win
->IsInnerWindow(),
1029 "Uh, inner window set as event target!");
1033 mEvent
->originalTarget
= aOriginalTarget
;
1038 nsDOMEvent::IsDispatchStopped(PRBool
* aIsDispatchStopped
)
1040 if (mEvent
->flags
& NS_EVENT_FLAG_STOP_DISPATCH
) {
1041 *aIsDispatchStopped
= PR_TRUE
;
1043 *aIsDispatchStopped
= PR_FALSE
;
1049 nsDOMEvent::GetInternalNSEvent(nsEvent
** aNSEvent
)
1051 NS_ENSURE_ARG_POINTER(aNSEvent
);
1056 // return true if eventName is contained within events, delimited by
1059 PopupAllowedForEvent(const char *eventName
)
1061 if (!sPopupAllowedEvents
) {
1062 nsDOMEvent::PopupAllowedEventsChanged();
1064 if (!sPopupAllowedEvents
) {
1069 nsDependentCString
events(sPopupAllowedEvents
);
1071 nsAFlatCString::const_iterator start
, end
;
1072 nsAFlatCString::const_iterator
startiter(events
.BeginReading(start
));
1073 events
.EndReading(end
);
1075 while (startiter
!= end
) {
1076 nsAFlatCString::const_iterator
enditer(end
);
1078 if (!FindInReadable(nsDependentCString(eventName
), startiter
, enditer
))
1081 // the match is surrounded by spaces, or at a string boundary
1082 if ((startiter
== start
|| *--startiter
== ' ') &&
1083 (enditer
== end
|| *enditer
== ' ')) {
1087 // Move on and see if there are other matches. (The delimitation
1088 // requirement makes it pointless to begin the next search before
1089 // the end of the invalid match just found.)
1090 startiter
= enditer
;
1098 nsDOMEvent::GetEventPopupControlState(nsEvent
*aEvent
)
1100 // generally if an event handler is running, new windows are disallowed.
1101 // check for exceptions:
1102 PopupControlState abuse
= openAbused
;
1104 switch(aEvent
->eventStructType
) {
1106 // For these following events only allow popups if they're
1107 // triggered while handling user input. See
1108 // nsPresShell::HandleEventInternal() for details.
1109 if (nsEventStateManager::IsHandlingUserInput()) {
1110 switch(aEvent
->message
) {
1111 case NS_FORM_SELECTED
:
1112 if (::PopupAllowedForEvent("select"))
1113 abuse
= openControlled
;
1115 case NS_FORM_CHANGE
:
1116 if (::PopupAllowedForEvent("change"))
1117 abuse
= openControlled
;
1123 // For this following event only allow popups if it's triggered
1124 // while handling user input. See
1125 // nsPresShell::HandleEventInternal() for details.
1126 if (nsEventStateManager::IsHandlingUserInput()) {
1127 switch(aEvent
->message
) {
1128 case NS_FORM_INPUT
:
1129 if (::PopupAllowedForEvent("input"))
1130 abuse
= openControlled
;
1135 case NS_INPUT_EVENT
:
1136 // For this following event only allow popups if it's triggered
1137 // while handling user input. See
1138 // nsPresShell::HandleEventInternal() for details.
1139 if (nsEventStateManager::IsHandlingUserInput()) {
1140 switch(aEvent
->message
) {
1141 case NS_FORM_CHANGE
:
1142 if (::PopupAllowedForEvent("change"))
1143 abuse
= openControlled
;
1149 if (NS_IS_TRUSTED_EVENT(aEvent
)) {
1150 PRUint32 key
= static_cast<nsKeyEvent
*>(aEvent
)->keyCode
;
1151 switch(aEvent
->message
) {
1153 // return key on focused button. see note at NS_MOUSE_CLICK.
1154 if (key
== nsIDOMKeyEvent::DOM_VK_RETURN
)
1155 abuse
= openAllowed
;
1156 else if (::PopupAllowedForEvent("keypress"))
1157 abuse
= openControlled
;
1160 // space key on focused button. see note at NS_MOUSE_CLICK.
1161 if (key
== nsIDOMKeyEvent::DOM_VK_SPACE
)
1162 abuse
= openAllowed
;
1163 else if (::PopupAllowedForEvent("keyup"))
1164 abuse
= openControlled
;
1167 if (::PopupAllowedForEvent("keydown"))
1168 abuse
= openControlled
;
1173 case NS_MOUSE_EVENT
:
1174 if (NS_IS_TRUSTED_EVENT(aEvent
) &&
1175 static_cast<nsMouseEvent
*>(aEvent
)->button
== nsMouseEvent::eLeftButton
) {
1176 switch(aEvent
->message
) {
1177 case NS_MOUSE_BUTTON_UP
:
1178 if (::PopupAllowedForEvent("mouseup"))
1179 abuse
= openControlled
;
1181 case NS_MOUSE_BUTTON_DOWN
:
1182 if (::PopupAllowedForEvent("mousedown"))
1183 abuse
= openControlled
;
1185 case NS_MOUSE_CLICK
:
1186 /* Click events get special treatment because of their
1187 historical status as a more legitimate event handler. If
1188 click popups are enabled in the prefs, clear the popup
1189 status completely. */
1190 if (::PopupAllowedForEvent("click"))
1191 abuse
= openAllowed
;
1193 case NS_MOUSE_DOUBLECLICK
:
1194 if (::PopupAllowedForEvent("dblclick"))
1195 abuse
= openControlled
;
1200 case NS_SCRIPT_ERROR_EVENT
:
1201 switch(aEvent
->message
) {
1202 case NS_LOAD_ERROR
:
1203 // Any error event will allow popups, if enabled in the pref.
1204 if (::PopupAllowedForEvent("error"))
1205 abuse
= openControlled
;
1209 case NS_FORM_EVENT
:
1210 // For these following events only allow popups if they're
1211 // triggered while handling user input. See
1212 // nsPresShell::HandleEventInternal() for details.
1213 if (nsEventStateManager::IsHandlingUserInput()) {
1214 switch(aEvent
->message
) {
1215 case NS_FORM_SUBMIT
:
1216 if (::PopupAllowedForEvent("submit"))
1217 abuse
= openControlled
;
1219 case NS_FORM_RESET
:
1220 if (::PopupAllowedForEvent("reset"))
1221 abuse
= openControlled
;
1226 case NS_XUL_COMMAND_EVENT
:
1227 if (nsEventStateManager::IsHandlingUserInput()) {
1228 abuse
= openControlled
;
1237 nsDOMEvent::PopupAllowedEventsChanged()
1239 if (sPopupAllowedEvents
) {
1240 nsMemory::Free(sPopupAllowedEvents
);
1243 nsAdoptingCString str
=
1244 nsContentUtils::GetCharPref("dom.popup_allowed_events");
1246 // We'll want to do this even if str is empty to avoid looking up
1247 // this pref all the time if it's not set.
1248 sPopupAllowedEvents
= ToNewCString(str
);
1253 nsDOMEvent::Shutdown()
1255 if (sPopupAllowedEvents
) {
1256 nsMemory::Free(sPopupAllowedEvents
);
1260 // To be called ONLY by nsDOMEvent::GetType (which has the additional
1261 // logic for handling user-defined events).
1263 const char* nsDOMEvent::GetEventName(PRUint32 aEventType
)
1265 switch(aEventType
) {
1266 case NS_MOUSE_BUTTON_DOWN
:
1267 return sEventNames
[eDOMEvents_mousedown
];
1268 case NS_MOUSE_BUTTON_UP
:
1269 return sEventNames
[eDOMEvents_mouseup
];
1270 case NS_MOUSE_CLICK
:
1271 return sEventNames
[eDOMEvents_click
];
1272 case NS_MOUSE_DOUBLECLICK
:
1273 return sEventNames
[eDOMEvents_dblclick
];
1274 case NS_MOUSE_ENTER_SYNTH
:
1275 return sEventNames
[eDOMEvents_mouseover
];
1276 case NS_MOUSE_EXIT_SYNTH
:
1277 return sEventNames
[eDOMEvents_mouseout
];
1279 return sEventNames
[eDOMEvents_mousemove
];
1281 return sEventNames
[eDOMEvents_keyup
];
1283 return sEventNames
[eDOMEvents_keydown
];
1285 return sEventNames
[eDOMEvents_keypress
];
1286 case NS_COMPOSITION_START
:
1287 return sEventNames
[eDOMEvents_compositionstart
];
1288 case NS_COMPOSITION_END
:
1289 return sEventNames
[eDOMEvents_compositionend
];
1290 case NS_FOCUS_CONTENT
:
1291 return sEventNames
[eDOMEvents_focus
];
1292 case NS_BLUR_CONTENT
:
1293 return sEventNames
[eDOMEvents_blur
];
1295 return sEventNames
[eDOMEvents_close
];
1297 return sEventNames
[eDOMEvents_load
];
1298 case NS_BEFORE_PAGE_UNLOAD
:
1299 return sEventNames
[eDOMEvents_beforeunload
];
1300 case NS_PAGE_UNLOAD
:
1301 return sEventNames
[eDOMEvents_unload
];
1302 case NS_IMAGE_ABORT
:
1303 return sEventNames
[eDOMEvents_abort
];
1305 return sEventNames
[eDOMEvents_error
];
1306 case NS_FORM_SUBMIT
:
1307 return sEventNames
[eDOMEvents_submit
];
1309 return sEventNames
[eDOMEvents_reset
];
1310 case NS_FORM_CHANGE
:
1311 return sEventNames
[eDOMEvents_change
];
1312 case NS_FORM_SELECTED
:
1313 return sEventNames
[eDOMEvents_select
];
1315 return sEventNames
[eDOMEvents_input
];
1317 return sEventNames
[eDOMEvents_paint
];
1318 case NS_RESIZE_EVENT
:
1319 return sEventNames
[eDOMEvents_resize
];
1320 case NS_SCROLL_EVENT
:
1321 return sEventNames
[eDOMEvents_scroll
];
1323 return sEventNames
[eDOMEvents_text
];
1324 case NS_XUL_POPUP_SHOWING
:
1325 return sEventNames
[eDOMEvents_popupShowing
];
1326 case NS_XUL_POPUP_SHOWN
:
1327 return sEventNames
[eDOMEvents_popupShown
];
1328 case NS_XUL_POPUP_HIDING
:
1329 return sEventNames
[eDOMEvents_popupHiding
];
1330 case NS_XUL_POPUP_HIDDEN
:
1331 return sEventNames
[eDOMEvents_popupHidden
];
1332 case NS_XUL_COMMAND
:
1333 return sEventNames
[eDOMEvents_command
];
1334 case NS_XUL_BROADCAST
:
1335 return sEventNames
[eDOMEvents_broadcast
];
1336 case NS_XUL_COMMAND_UPDATE
:
1337 return sEventNames
[eDOMEvents_commandupdate
];
1338 case NS_DRAGDROP_ENTER
:
1339 return sEventNames
[eDOMEvents_dragenter
];
1340 case NS_DRAGDROP_OVER_SYNTH
:
1341 return sEventNames
[eDOMEvents_dragover
];
1342 case NS_DRAGDROP_EXIT_SYNTH
:
1343 return sEventNames
[eDOMEvents_dragexit
];
1344 case NS_DRAGDROP_DRAGDROP
:
1345 return sEventNames
[eDOMEvents_dragdrop
];
1346 case NS_DRAGDROP_GESTURE
:
1347 return sEventNames
[eDOMEvents_draggesture
];
1348 case NS_DRAGDROP_DRAG
:
1349 return sEventNames
[eDOMEvents_drag
];
1350 case NS_DRAGDROP_END
:
1351 return sEventNames
[eDOMEvents_dragend
];
1352 case NS_DRAGDROP_START
:
1353 return sEventNames
[eDOMEvents_dragstart
];
1354 case NS_DRAGDROP_LEAVE_SYNTH
:
1355 return sEventNames
[eDOMEvents_dragleave
];
1356 case NS_DRAGDROP_DROP
:
1357 return sEventNames
[eDOMEvents_drop
];
1358 case NS_SCROLLPORT_OVERFLOW
:
1359 return sEventNames
[eDOMEvents_overflow
];
1360 case NS_SCROLLPORT_UNDERFLOW
:
1361 return sEventNames
[eDOMEvents_underflow
];
1362 case NS_SCROLLPORT_OVERFLOWCHANGED
:
1363 return sEventNames
[eDOMEvents_overflowchanged
];
1364 case NS_MUTATION_SUBTREEMODIFIED
:
1365 return sEventNames
[eDOMEvents_subtreemodified
];
1366 case NS_MUTATION_NODEINSERTED
:
1367 return sEventNames
[eDOMEvents_nodeinserted
];
1368 case NS_MUTATION_NODEREMOVED
:
1369 return sEventNames
[eDOMEvents_noderemoved
];
1370 case NS_MUTATION_NODEREMOVEDFROMDOCUMENT
:
1371 return sEventNames
[eDOMEvents_noderemovedfromdocument
];
1372 case NS_MUTATION_NODEINSERTEDINTODOCUMENT
:
1373 return sEventNames
[eDOMEvents_nodeinsertedintodocument
];
1374 case NS_MUTATION_ATTRMODIFIED
:
1375 return sEventNames
[eDOMEvents_attrmodified
];
1376 case NS_MUTATION_CHARACTERDATAMODIFIED
:
1377 return sEventNames
[eDOMEvents_characterdatamodified
];
1378 case NS_CONTEXTMENU
:
1379 return sEventNames
[eDOMEvents_contextmenu
];
1380 case NS_UI_ACTIVATE
:
1381 return sEventNames
[eDOMEvents_DOMActivate
];
1383 return sEventNames
[eDOMEvents_DOMFocusIn
];
1384 case NS_UI_FOCUSOUT
:
1385 return sEventNames
[eDOMEvents_DOMFocusOut
];
1387 return sEventNames
[eDOMEvents_pageshow
];
1389 return sEventNames
[eDOMEvents_pagehide
];
1390 case NS_MOUSE_SCROLL
:
1391 return sEventNames
[eDOMEvents_DOMMouseScroll
];
1393 return sEventNames
[eDOMEvents_offline
];
1395 return sEventNames
[eDOMEvents_online
];
1397 return sEventNames
[eDOMEvents_copy
];
1399 return sEventNames
[eDOMEvents_cut
];
1401 return sEventNames
[eDOMEvents_paste
];
1404 return sEventNames
[eDOMEvents_SVGLoad
];
1406 return sEventNames
[eDOMEvents_SVGUnload
];
1408 return sEventNames
[eDOMEvents_SVGAbort
];
1410 return sEventNames
[eDOMEvents_SVGError
];
1412 return sEventNames
[eDOMEvents_SVGResize
];
1414 return sEventNames
[eDOMEvents_SVGScroll
];
1416 return sEventNames
[eDOMEvents_SVGZoom
];
1420 return sEventNames
[eDOMEvents_loadstart
];
1422 return sEventNames
[eDOMEvents_progress
];
1423 case NS_LOADEDMETADATA
:
1424 return sEventNames
[eDOMEvents_loadedmetadata
];
1425 case NS_LOADEDFIRSTFRAME
:
1426 return sEventNames
[eDOMEvents_loadedfirstframe
];
1428 return sEventNames
[eDOMEvents_emptied
];
1430 return sEventNames
[eDOMEvents_stalled
];
1432 return sEventNames
[eDOMEvents_play
];
1434 return sEventNames
[eDOMEvents_pause
];
1436 return sEventNames
[eDOMEvents_waiting
];
1438 return sEventNames
[eDOMEvents_seeking
];
1440 return sEventNames
[eDOMEvents_seeked
];
1442 return sEventNames
[eDOMEvents_timeupdate
];
1444 return sEventNames
[eDOMEvents_ended
];
1445 case NS_DATAUNAVAILABLE
:
1446 return sEventNames
[eDOMEvents_dataunavailable
];
1447 case NS_CANSHOWCURRENTFRAME
:
1448 return sEventNames
[eDOMEvents_canshowcurrentframe
];
1450 return sEventNames
[eDOMEvents_canplay
];
1451 case NS_CANPLAYTHROUGH
:
1452 return sEventNames
[eDOMEvents_canplaythrough
];
1454 return sEventNames
[eDOMEvents_ratechange
];
1455 case NS_DURATIONCHANGE
:
1456 return sEventNames
[eDOMEvents_durationchange
];
1457 case NS_VOLUMECHANGE
:
1458 return sEventNames
[eDOMEvents_volumechange
];
1463 // XXXldb We can hit this case for nsEvent objects that we didn't
1464 // create and that are not user defined events since this function and
1465 // SetEventType are incomplete. (But fixing that requires fixing the
1466 // arrays in nsEventListenerManager too, since the events for which
1467 // this is a problem generally *are* created by nsDOMEvent.)
1471 nsresult
NS_NewDOMEvent(nsIDOMEvent
** aInstancePtrResult
,
1472 nsPresContext
* aPresContext
,
1475 nsDOMEvent
* it
= new nsDOMEvent(aPresContext
, aEvent
);
1477 return NS_ERROR_OUT_OF_MEMORY
;
1480 return CallQueryInterface(it
, aInstancePtrResult
);