/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Steve Clark (buster@netscape.com) * Ilya Konstantinov (mozilla-code@future.shiny.co.il) * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */#include"base/basictypes.h"/* This must occur *after* base/basictypes.h to avoid typedefs conflicts. */#include"mozilla/Util.h"#include"IPC/IPCMessageUtils.h"#include"nsCOMPtr.h"#include"nsDOMEvent.h"#include"nsEventStateManager.h"#include"nsIFrame.h"#include"nsIContent.h"#include"nsIPresShell.h"#include"nsIDocument.h"#include"nsIInterfaceRequestor.h"#include"nsIInterfaceRequestorUtils.h"#include"prmem.h"#include"nsGkAtoms.h"#include"nsMutationEvent.h"#include"nsContentUtils.h"#include"nsIURI.h"#include"nsIScriptSecurityManager.h"#include"nsIScriptError.h"#include"nsDOMPopStateEvent.h"#include"mozilla/Preferences.h"#include"nsJSUtils.h"#include"DictionaryHelpers.h"#include"nsLayoutUtils.h"#include"nsIScrollableFrame.h"usingnamespacemozilla;staticconstchar*constsEventNames[]={"mousedown","mouseup","click","dblclick","mouseenter","mouseleave","mouseover","mouseout","MozMouseHittest","mousemove","contextmenu","keydown","keyup","keypress","focus","blur","load","popstate","beforescriptexecute","afterscriptexecute","beforeunload","unload","hashchange","readystatechange","abort","error","submit","reset","change","select","input","invalid","text","compositionstart","compositionend","compositionupdate","popupshowing","popupshown","popuphiding","popuphidden","close","command","broadcast","commandupdate","dragenter","dragover","dragexit","dragdrop","draggesture","drag","dragend","dragstart","dragleave","drop","resize","scroll","overflow","underflow","overflowchanged","DOMSubtreeModified","DOMNodeInserted","DOMNodeRemoved","DOMNodeRemovedFromDocument","DOMNodeInsertedIntoDocument","DOMAttrModified","DOMCharacterDataModified","DOMActivate","DOMFocusIn","DOMFocusOut","pageshow","pagehide","DOMMouseScroll","MozMousePixelScroll","offline","online","copy","cut","paste","open","message","show","SVGLoad","SVGUnload","SVGAbort","SVGError","SVGResize","SVGScroll","SVGZoom","beginEvent","endEvent","repeatEvent",#ifdef MOZ_MEDIA"loadstart","progress","suspend","emptied","stalled","play","pause","loadedmetadata","loadeddata","waiting","playing","canplay","canplaythrough","seeking","seeked","timeupdate","ended","ratechange","durationchange","volumechange","MozAudioAvailable",#endif // MOZ_MEDIA"MozAfterPaint","MozBeforeResize","mozfullscreenchange","mozfullscreenerror","mozpointerlockchange","mozpointerlockerror","MozSwipeGesture","MozMagnifyGestureStart","MozMagnifyGestureUpdate","MozMagnifyGesture","MozRotateGestureStart","MozRotateGestureUpdate","MozRotateGesture","MozTapGesture","MozPressTapGesture","MozTouchDown","MozTouchMove","MozTouchUp","touchstart","touchend","touchmove","touchcancel","touchenter","touchleave","MozScrolledAreaChanged","transitionend","animationstart","animationend","animationiteration","devicemotion","deviceorientation"};staticchar*sPopupAllowedEvents;nsDOMEvent::nsDOMEvent(nsPresContext*aPresContext,nsEvent*aEvent){mPrivateDataDuplicated=false;if(aEvent){mEvent=aEvent;mEventIsInternal=false;}else{mEventIsInternal=true;/* A derived class might want to allocate its own type of aEvent (derived from nsEvent). To do this, it should take care to pass a non-NULL aEvent to this ctor, e.g.: nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent) : nsDOMEvent(..., aEvent ? aEvent : new nsFooEvent()) Then, to override the mEventIsInternal assignments done by the base ctor, it should do this in its own ctor: nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent) ... { ... if (aEvent) { mEventIsInternal = false; } else { mEventIsInternal = true; } ... } */mEvent=newnsEvent(false,0);mEvent->time=PR_Now();}InitPresContextData(aPresContext);NS_ASSERTION(mEvent->message!=NS_PAINT,"Trying to create a DOM paint event!");}voidnsDOMEvent::InitPresContextData(nsPresContext*aPresContext){mPresContext=aPresContext;// Get the explicit original target (if it's anonymous make it null){nsCOMPtr<nsIContent>content=GetTargetFromFrame();mExplicitOriginalTarget=do_QueryInterface(content);if(content&&content->IsInAnonymousSubtree()){mExplicitOriginalTarget=nsnull;}}}nsDOMEvent::~nsDOMEvent(){NS_ASSERT_OWNINGTHREAD(nsDOMEvent);if(mEventIsInternal&&mEvent){deletemEvent;}}NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMEvent)DOMCI_DATA(Event,nsDOMEvent)NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMEvent)NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports,nsIDOMEvent)NS_INTERFACE_MAP_ENTRY(nsIDOMEvent)NS_INTERFACE_MAP_ENTRY(nsIDOMNSEvent)NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMEvent)NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Event)NS_INTERFACE_MAP_ENDNS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMEvent)NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMEvent)NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMEvent)if(tmp->mEventIsInternal){tmp->mEvent->target=nsnull;tmp->mEvent->currentTarget=nsnull;tmp->mEvent->originalTarget=nsnull;switch(tmp->mEvent->eventStructType){caseNS_MOUSE_EVENT:caseNS_MOUSE_SCROLL_EVENT:caseNS_SIMPLE_GESTURE_EVENT:caseNS_MOZTOUCH_EVENT:static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget=nsnull;break;caseNS_DRAG_EVENT:static_cast<nsDragEvent*>(tmp->mEvent)->dataTransfer=nsnull;static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget=nsnull;break;caseNS_MUTATION_EVENT:static_cast<nsMutationEvent*>(tmp->mEvent)->mRelatedNode=nsnull;break;default:break;}}NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPresContext);NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mExplicitOriginalTarget);NS_IMPL_CYCLE_COLLECTION_UNLINK_ENDNS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMEvent)if(tmp->mEventIsInternal){NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEvent->target)NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEvent->currentTarget)NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEvent->originalTarget)switch(tmp->mEvent->eventStructType){caseNS_MOUSE_EVENT:caseNS_MOUSE_SCROLL_EVENT:caseNS_SIMPLE_GESTURE_EVENT:caseNS_MOZTOUCH_EVENT:NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,"mEvent->relatedTarget");cb.NoteXPCOMChild(static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget);break;caseNS_DRAG_EVENT:NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,"mEvent->dataTransfer");cb.NoteXPCOMChild(static_cast<nsDragEvent*>(tmp->mEvent)->dataTransfer);NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,"mEvent->relatedTarget");cb.NoteXPCOMChild(static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget);break;caseNS_MUTATION_EVENT:NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,"mEvent->mRelatedNode");cb.NoteXPCOMChild(static_cast<nsMutationEvent*>(tmp->mEvent)->mRelatedNode);break;default:break;}}NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mPresContext.get(),nsPresContext)NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mExplicitOriginalTarget)NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END// nsIDOMEventInterfaceNS_METHODnsDOMEvent::GetType(nsAString&aType){if(!mCachedType.IsEmpty()){aType=mCachedType;returnNS_OK;}constchar*name=GetEventName(mEvent->message);if(name){CopyASCIItoUTF16(name,aType);mCachedType=aType;returnNS_OK;}elseif(mEvent->message==NS_USER_DEFINED_EVENT&&mEvent->userType){aType=Substring(nsDependentAtomString(mEvent->userType),2);// Remove "on"mCachedType=aType;returnNS_OK;}aType.Truncate();returnNS_OK;}staticnsresultGetDOMEventTarget(nsIDOMEventTarget*aTarget,nsIDOMEventTarget**aDOMTarget){nsIDOMEventTarget*realTarget=aTarget?aTarget->GetTargetForDOMEvent():aTarget;NS_IF_ADDREF(*aDOMTarget=realTarget);returnNS_OK;}NS_METHODnsDOMEvent::GetTarget(nsIDOMEventTarget**aTarget){returnGetDOMEventTarget(mEvent->target,aTarget);}NS_IMETHODIMPnsDOMEvent::GetCurrentTarget(nsIDOMEventTarget**aCurrentTarget){returnGetDOMEventTarget(mEvent->currentTarget,aCurrentTarget);}//// Get the actual event target node (may have been retargeted for mouse events)//already_AddRefed<nsIContent>nsDOMEvent::GetTargetFromFrame(){if(!mPresContext){returnnsnull;}// Get the target frame (have to get the ESM first)nsIFrame*targetFrame=mPresContext->EventStateManager()->GetEventTarget();if(!targetFrame){returnnsnull;}// get the real contentnsCOMPtr<nsIContent>realEventContent;targetFrame->GetContentForEvent(mEvent,getter_AddRefs(realEventContent));returnrealEventContent.forget();}NS_IMETHODIMPnsDOMEvent::GetExplicitOriginalTarget(nsIDOMEventTarget**aRealEventTarget){if(mExplicitOriginalTarget){*aRealEventTarget=mExplicitOriginalTarget;NS_ADDREF(*aRealEventTarget);returnNS_OK;}returnGetTarget(aRealEventTarget);}NS_IMETHODIMPnsDOMEvent::GetOriginalTarget(nsIDOMEventTarget**aOriginalTarget){if(mEvent->originalTarget){returnGetDOMEventTarget(mEvent->originalTarget,aOriginalTarget);}returnGetTarget(aOriginalTarget);}NS_IMETHODIMPnsDOMEvent::SetTrusted(boolaTrusted){if(aTrusted){mEvent->flags|=NS_EVENT_FLAG_TRUSTED;}else{mEvent->flags&=~NS_EVENT_FLAG_TRUSTED;}returnNS_OK;}NS_IMETHODIMPnsDOMEvent::Initialize(nsISupports*aOwner,JSContext*aCx,JSObject*aObj,PRUint32aArgc,jsval*aArgv){NS_ENSURE_TRUE(aArgc>=1,NS_ERROR_XPC_NOT_ENOUGH_ARGS);booltrusted=false;nsCOMPtr<nsPIDOMWindow>w=do_QueryInterface(aOwner);if(w){nsCOMPtr<nsIDocument>d=do_QueryInterface(w->GetExtantDocument());if(d){trusted=nsContentUtils::IsChromeDoc(d);nsIPresShell*s=d->GetShell();if(s){InitPresContextData(s->GetPresContext());}}}JSAutoRequestar(aCx);JSString*jsstr=JS_ValueToString(aCx,aArgv[0]);if(!jsstr){returnNS_ERROR_DOM_SYNTAX_ERR;}JS::Anchor<JSString*>deleteProtector(jsstr);nsDependentJSStringtype;NS_ENSURE_STATE(type.init(aCx,jsstr));nsresultrv=InitFromCtor(type,aCx,aArgc>=2?&(aArgv[1]):nsnull);NS_ENSURE_SUCCESS(rv,rv);SetTrusted(trusted);returnNS_OK;}nsresultnsDOMEvent::InitFromCtor(constnsAString&aType,JSContext*aCx,jsval*aVal){mozilla::dom::EventInitd;nsresultrv=d.Init(aCx,aVal);NS_ENSURE_SUCCESS(rv,rv);returnInitEvent(aType,d.bubbles,d.cancelable);}NS_IMETHODIMPnsDOMEvent::GetEventPhase(PRUint16*aEventPhase){// Note, remember to check that this works also// if or when Bug 235441 is fixed.if(mEvent->currentTarget==mEvent->target||((mEvent->flags&NS_EVENT_FLAG_CAPTURE)&&(mEvent->flags&NS_EVENT_FLAG_BUBBLE))){*aEventPhase=nsIDOMEvent::AT_TARGET;}elseif(mEvent->flags&NS_EVENT_FLAG_CAPTURE){*aEventPhase=nsIDOMEvent::CAPTURING_PHASE;}elseif(mEvent->flags&NS_EVENT_FLAG_BUBBLE){*aEventPhase=nsIDOMEvent::BUBBLING_PHASE;}else{*aEventPhase=0;}returnNS_OK;}NS_IMETHODIMPnsDOMEvent::GetBubbles(bool*aBubbles){*aBubbles=!(mEvent->flags&NS_EVENT_FLAG_CANT_BUBBLE);returnNS_OK;}NS_IMETHODIMPnsDOMEvent::GetCancelable(bool*aCancelable){*aCancelable=!(mEvent->flags&NS_EVENT_FLAG_CANT_CANCEL);returnNS_OK;}NS_IMETHODIMPnsDOMEvent::GetTimeStamp(PRUint64*aTimeStamp){*aTimeStamp=mEvent->time;returnNS_OK;}NS_IMETHODIMPnsDOMEvent::StopPropagation(){mEvent->flags|=NS_EVENT_FLAG_STOP_DISPATCH;returnNS_OK;}NS_IMETHODIMPnsDOMEvent::StopImmediatePropagation(){mEvent->flags|=(NS_EVENT_FLAG_STOP_DISPATCH_IMMEDIATELY|NS_EVENT_FLAG_STOP_DISPATCH);returnNS_OK;}staticnsIDocument*GetDocumentForReport(nsEvent*aEvent){nsCOMPtr<nsINode>node=do_QueryInterface(aEvent->currentTarget);if(node)returnnode->OwnerDoc();nsCOMPtr<nsPIDOMWindow>window=do_QueryInterface(aEvent->currentTarget);if(!window)returnnsnull;nsCOMPtr<nsIDocument>doc(do_QueryInterface(window->GetExtantDocument()));returndoc;}staticvoidReportUseOfDeprecatedMethod(nsEvent*aEvent,nsIDOMEvent*aDOMEvent,constchar*aWarning){nsCOMPtr<nsIDocument>doc(GetDocumentForReport(aEvent));nsAutoStringtype;aDOMEvent->GetType(type);constPRUnichar*strings[]={type.get()};nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,"DOM Events",doc,nsContentUtils::eDOM_PROPERTIES,aWarning,strings,ArrayLength(strings));}NS_IMETHODIMPnsDOMEvent::PreventBubble(){ReportUseOfDeprecatedMethod(mEvent,this,"UseOfPreventBubbleWarning");returnNS_OK;}NS_IMETHODIMPnsDOMEvent::PreventCapture(){ReportUseOfDeprecatedMethod(mEvent,this,"UseOfPreventCaptureWarning");returnNS_OK;}NS_IMETHODIMPnsDOMEvent::GetIsTrusted(bool*aIsTrusted){*aIsTrusted=NS_IS_TRUSTED_EVENT(mEvent);returnNS_OK;}NS_IMETHODIMPnsDOMEvent::PreventDefault(){if(!(mEvent->flags&NS_EVENT_FLAG_CANT_CANCEL)){mEvent->flags|=NS_EVENT_FLAG_NO_DEFAULT;// Need to set an extra flag for drag events.if(mEvent->eventStructType==NS_DRAG_EVENT&&NS_IS_TRUSTED_EVENT(mEvent)){nsCOMPtr<nsINode>node=do_QueryInterface(mEvent->currentTarget);if(!node){nsCOMPtr<nsPIDOMWindow>win=do_QueryInterface(mEvent->currentTarget);if(win){node=do_QueryInterface(win->GetExtantDocument());}}if(node&&!nsContentUtils::IsChromeDoc(node->OwnerDoc())){mEvent->flags|=NS_EVENT_FLAG_NO_DEFAULT_CALLED_IN_CONTENT;}}}returnNS_OK;}nsresultnsDOMEvent::SetEventType(constnsAString&aEventTypeArg){mEvent->userType=nsContentUtils::GetEventIdAndAtom(aEventTypeArg,mEvent->eventStructType,&(mEvent->message));returnNS_OK;}NS_IMETHODIMPnsDOMEvent::InitEvent(constnsAString&aEventTypeArg,boolaCanBubbleArg,boolaCancelableArg){// Make sure this event isn't already being dispatched.NS_ENSURE_TRUE(!NS_IS_EVENT_IN_DISPATCH(mEvent),NS_ERROR_INVALID_ARG);if(NS_IS_TRUSTED_EVENT(mEvent)){// Ensure the caller is permitted to dispatch trusted DOM events.boolenabled=false;nsContentUtils::GetSecurityManager()->IsCapabilityEnabled("UniversalXPConnect",&enabled);if(!enabled){SetTrusted(false);}}NS_ENSURE_SUCCESS(SetEventType(aEventTypeArg),NS_ERROR_FAILURE);if(aCanBubbleArg){mEvent->flags&=~NS_EVENT_FLAG_CANT_BUBBLE;}else{mEvent->flags|=NS_EVENT_FLAG_CANT_BUBBLE;}if(aCancelableArg){mEvent->flags&=~NS_EVENT_FLAG_CANT_CANCEL;}else{mEvent->flags|=NS_EVENT_FLAG_CANT_CANCEL;}// Clearing the old targets, so that the event is targeted correctly when// re-dispatching it.mEvent->target=nsnull;mEvent->originalTarget=nsnull;mCachedType=aEventTypeArg;returnNS_OK;}NS_METHODnsDOMEvent::DuplicatePrivateData(){// FIXME! Simplify this method and make it somehow easily extendable,// Bug 329127NS_ASSERTION(mEvent,"No nsEvent for nsDOMEvent duplication!");if(mEventIsInternal){returnNS_OK;}nsEvent*newEvent=nsnull;PRUint32msg=mEvent->message;boolisInputEvent=false;switch(mEvent->eventStructType){caseNS_EVENT:{newEvent=newnsEvent(false,msg);break;}caseNS_GUI_EVENT:{// Not copying widget, it is a weak reference.newEvent=newnsGUIEvent(false,msg,nsnull);break;}caseNS_SIZE_EVENT:{nsSizeEvent*sizeEvent=newnsSizeEvent(false,msg,nsnull);NS_ENSURE_TRUE(sizeEvent,NS_ERROR_OUT_OF_MEMORY);sizeEvent->mWinWidth=static_cast<nsSizeEvent*>(mEvent)->mWinWidth;sizeEvent->mWinHeight=static_cast<nsSizeEvent*>(mEvent)->mWinHeight;newEvent=sizeEvent;break;}caseNS_SIZEMODE_EVENT:{newEvent=newnsSizeModeEvent(false,msg,nsnull);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);static_cast<nsSizeModeEvent*>(newEvent)->mSizeMode=static_cast<nsSizeModeEvent*>(mEvent)->mSizeMode;break;}caseNS_ZLEVEL_EVENT:{nsZLevelEvent*zLevelEvent=newnsZLevelEvent(false,msg,nsnull);NS_ENSURE_TRUE(zLevelEvent,NS_ERROR_OUT_OF_MEMORY);nsZLevelEvent*oldZLevelEvent=static_cast<nsZLevelEvent*>(mEvent);zLevelEvent->mPlacement=oldZLevelEvent->mPlacement;zLevelEvent->mImmediate=oldZLevelEvent->mImmediate;zLevelEvent->mAdjusted=oldZLevelEvent->mAdjusted;newEvent=zLevelEvent;break;}caseNS_SCROLLBAR_EVENT:{newEvent=newnsScrollbarEvent(false,msg,nsnull);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);static_cast<nsScrollbarEvent*>(newEvent)->position=static_cast<nsScrollbarEvent*>(mEvent)->position;break;}caseNS_INPUT_EVENT:{newEvent=newnsInputEvent(false,msg,nsnull);isInputEvent=true;break;}caseNS_KEY_EVENT:{nsKeyEvent*keyEvent=newnsKeyEvent(false,msg,nsnull);NS_ENSURE_TRUE(keyEvent,NS_ERROR_OUT_OF_MEMORY);nsKeyEvent*oldKeyEvent=static_cast<nsKeyEvent*>(mEvent);isInputEvent=true;keyEvent->keyCode=oldKeyEvent->keyCode;keyEvent->charCode=oldKeyEvent->charCode;keyEvent->isChar=oldKeyEvent->isChar;newEvent=keyEvent;break;}caseNS_MOUSE_EVENT:{nsMouseEvent*oldMouseEvent=static_cast<nsMouseEvent*>(mEvent);nsMouseEvent*mouseEvent=newnsMouseEvent(false,msg,nsnull,oldMouseEvent->reason);NS_ENSURE_TRUE(mouseEvent,NS_ERROR_OUT_OF_MEMORY);isInputEvent=true;mouseEvent->clickCount=oldMouseEvent->clickCount;mouseEvent->acceptActivation=oldMouseEvent->acceptActivation;mouseEvent->context=oldMouseEvent->context;mouseEvent->relatedTarget=oldMouseEvent->relatedTarget;mouseEvent->button=oldMouseEvent->button;mouseEvent->buttons=oldMouseEvent->buttons;mouseEvent->pressure=oldMouseEvent->pressure;mouseEvent->inputSource=oldMouseEvent->inputSource;newEvent=mouseEvent;break;}caseNS_DRAG_EVENT:{nsDragEvent*oldDragEvent=static_cast<nsDragEvent*>(mEvent);nsDragEvent*dragEvent=newnsDragEvent(false,msg,nsnull);NS_ENSURE_TRUE(dragEvent,NS_ERROR_OUT_OF_MEMORY);isInputEvent=true;dragEvent->dataTransfer=oldDragEvent->dataTransfer;dragEvent->clickCount=oldDragEvent->clickCount;dragEvent->acceptActivation=oldDragEvent->acceptActivation;dragEvent->relatedTarget=oldDragEvent->relatedTarget;dragEvent->button=oldDragEvent->button;dragEvent->buttons=oldDragEvent->buttons;static_cast<nsMouseEvent*>(dragEvent)->inputSource=static_cast<nsMouseEvent*>(oldDragEvent)->inputSource;newEvent=dragEvent;break;}caseNS_SCRIPT_ERROR_EVENT:{newEvent=newnsScriptErrorEvent(false,msg);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);static_cast<nsScriptErrorEvent*>(newEvent)->lineNr=static_cast<nsScriptErrorEvent*>(mEvent)->lineNr;break;}caseNS_TEXT_EVENT:{newEvent=newnsTextEvent(false,msg,nsnull);isInputEvent=true;break;}caseNS_COMPOSITION_EVENT:{nsCompositionEvent*compositionEvent=newnsCompositionEvent(false,msg,nsnull);nsCompositionEvent*oldCompositionEvent=static_cast<nsCompositionEvent*>(mEvent);compositionEvent->data=oldCompositionEvent->data;newEvent=compositionEvent;break;}caseNS_MOUSE_SCROLL_EVENT:{nsMouseScrollEvent*mouseScrollEvent=newnsMouseScrollEvent(false,msg,nsnull);NS_ENSURE_TRUE(mouseScrollEvent,NS_ERROR_OUT_OF_MEMORY);isInputEvent=true;nsMouseScrollEvent*oldMouseScrollEvent=static_cast<nsMouseScrollEvent*>(mEvent);mouseScrollEvent->scrollFlags=oldMouseScrollEvent->scrollFlags;mouseScrollEvent->delta=oldMouseScrollEvent->delta;mouseScrollEvent->relatedTarget=oldMouseScrollEvent->relatedTarget;mouseScrollEvent->button=oldMouseScrollEvent->button;mouseScrollEvent->buttons=oldMouseScrollEvent->buttons;static_cast<nsMouseEvent_base*>(mouseScrollEvent)->inputSource=static_cast<nsMouseEvent_base*>(oldMouseScrollEvent)->inputSource;newEvent=mouseScrollEvent;break;}caseNS_SCROLLPORT_EVENT:{newEvent=newnsScrollPortEvent(false,msg,nsnull);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);static_cast<nsScrollPortEvent*>(newEvent)->orient=static_cast<nsScrollPortEvent*>(mEvent)->orient;break;}caseNS_SCROLLAREA_EVENT:{nsScrollAreaEvent*newScrollAreaEvent=newnsScrollAreaEvent(false,msg,nsnull);NS_ENSURE_TRUE(newScrollAreaEvent,NS_ERROR_OUT_OF_MEMORY);newScrollAreaEvent->mArea=static_cast<nsScrollAreaEvent*>(mEvent)->mArea;newEvent=newScrollAreaEvent;break;}caseNS_MUTATION_EVENT:{nsMutationEvent*mutationEvent=newnsMutationEvent(false,msg);NS_ENSURE_TRUE(mutationEvent,NS_ERROR_OUT_OF_MEMORY);nsMutationEvent*oldMutationEvent=static_cast<nsMutationEvent*>(mEvent);mutationEvent->mRelatedNode=oldMutationEvent->mRelatedNode;mutationEvent->mAttrName=oldMutationEvent->mAttrName;mutationEvent->mPrevAttrValue=oldMutationEvent->mPrevAttrValue;mutationEvent->mNewAttrValue=oldMutationEvent->mNewAttrValue;mutationEvent->mAttrChange=oldMutationEvent->mAttrChange;newEvent=mutationEvent;break;}#ifdef ACCESSIBILITYcaseNS_ACCESSIBLE_EVENT:{newEvent=newnsAccessibleEvent(false,msg,nsnull);isInputEvent=true;break;}#endifcaseNS_FORM_EVENT:{newEvent=newnsFormEvent(false,msg);break;}caseNS_FOCUS_EVENT:{nsFocusEvent*newFocusEvent=newnsFocusEvent(false,msg);NS_ENSURE_TRUE(newFocusEvent,NS_ERROR_OUT_OF_MEMORY);nsFocusEvent*oldFocusEvent=static_cast<nsFocusEvent*>(mEvent);newFocusEvent->fromRaise=oldFocusEvent->fromRaise;newFocusEvent->isRefocus=oldFocusEvent->isRefocus;newEvent=newFocusEvent;break;}caseNS_POPUP_EVENT:{newEvent=newnsInputEvent(false,msg,nsnull);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);isInputEvent=true;newEvent->eventStructType=NS_POPUP_EVENT;break;}caseNS_COMMAND_EVENT:{newEvent=newnsCommandEvent(false,mEvent->userType,static_cast<nsCommandEvent*>(mEvent)->command,nsnull);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);break;}caseNS_UI_EVENT:{newEvent=newnsUIEvent(false,msg,static_cast<nsUIEvent*>(mEvent)->detail);break;}caseNS_SVG_EVENT:{newEvent=newnsEvent(false,msg);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);newEvent->eventStructType=NS_SVG_EVENT;break;}caseNS_SVGZOOM_EVENT:{newEvent=newnsGUIEvent(false,msg,nsnull);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);newEvent->eventStructType=NS_SVGZOOM_EVENT;break;}caseNS_SMIL_TIME_EVENT:{newEvent=newnsUIEvent(false,msg,0);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);newEvent->eventStructType=NS_SMIL_TIME_EVENT;break;}caseNS_SIMPLE_GESTURE_EVENT:{nsSimpleGestureEvent*oldSimpleGestureEvent=static_cast<nsSimpleGestureEvent*>(mEvent);nsSimpleGestureEvent*simpleGestureEvent=newnsSimpleGestureEvent(false,msg,nsnull,0,0.0);NS_ENSURE_TRUE(simpleGestureEvent,NS_ERROR_OUT_OF_MEMORY);isInputEvent=true;simpleGestureEvent->direction=oldSimpleGestureEvent->direction;simpleGestureEvent->delta=oldSimpleGestureEvent->delta;newEvent=simpleGestureEvent;break;}caseNS_TRANSITION_EVENT:{nsTransitionEvent*oldTransitionEvent=static_cast<nsTransitionEvent*>(mEvent);newEvent=newnsTransitionEvent(false,msg,oldTransitionEvent->propertyName,oldTransitionEvent->elapsedTime);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);break;}caseNS_ANIMATION_EVENT:{nsAnimationEvent*oldAnimationEvent=static_cast<nsAnimationEvent*>(mEvent);newEvent=newnsAnimationEvent(false,msg,oldAnimationEvent->animationName,oldAnimationEvent->elapsedTime);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);break;}caseNS_MOZTOUCH_EVENT:{nsMozTouchEvent*oldMozTouchEvent=static_cast<nsMozTouchEvent*>(mEvent);nsMozTouchEvent*mozTouchEvent=newnsMozTouchEvent(false,msg,nsnull,static_cast<nsMozTouchEvent*>(mEvent)->streamId);NS_ENSURE_TRUE(mozTouchEvent,NS_ERROR_OUT_OF_MEMORY);isInputEvent=true;mozTouchEvent->buttons=oldMozTouchEvent->buttons;newEvent=mozTouchEvent;break;}caseNS_TOUCH_EVENT:{nsTouchEvent*oldTouchEvent=static_cast<nsTouchEvent*>(mEvent);newEvent=newnsTouchEvent(false,oldTouchEvent);NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);isInputEvent=true;break;}default:{NS_WARNING("Unknown event type!!!");returnNS_ERROR_FAILURE;}}NS_ENSURE_TRUE(newEvent,NS_ERROR_OUT_OF_MEMORY);if(isInputEvent){nsInputEvent*oldInputEvent=static_cast<nsInputEvent*>(mEvent);nsInputEvent*newInputEvent=static_cast<nsInputEvent*>(newEvent);newInputEvent->modifiers=oldInputEvent->modifiers;}newEvent->target=mEvent->target;newEvent->currentTarget=mEvent->currentTarget;newEvent->originalTarget=mEvent->originalTarget;newEvent->flags=mEvent->flags;newEvent->time=mEvent->time;newEvent->refPoint=mEvent->refPoint;newEvent->userType=mEvent->userType;mEvent=newEvent;mPresContext=nsnull;mEventIsInternal=true;mPrivateDataDuplicated=true;returnNS_OK;}NS_METHODnsDOMEvent::SetTarget(nsIDOMEventTarget*aTarget){#ifdef DEBUG{nsCOMPtr<nsPIDOMWindow>win=do_QueryInterface(aTarget);NS_ASSERTION(!win||!win->IsInnerWindow(),"Uh, inner window set as event target!");}#endifmEvent->target=do_QueryInterface(aTarget);returnNS_OK;}NS_IMETHODIMP_(bool)nsDOMEvent::IsDispatchStopped(){return!!(mEvent->flags&NS_EVENT_FLAG_STOP_DISPATCH);}NS_IMETHODIMP_(nsEvent*)nsDOMEvent::GetInternalNSEvent(){returnmEvent;}// return true if eventName is contained within events, delimited by// spacesstaticboolPopupAllowedForEvent(constchar*eventName){if(!sPopupAllowedEvents){nsDOMEvent::PopupAllowedEventsChanged();if(!sPopupAllowedEvents){returnfalse;}}nsDependentCStringevents(sPopupAllowedEvents);nsAFlatCString::const_iteratorstart,end;nsAFlatCString::const_iteratorstartiter(events.BeginReading(start));events.EndReading(end);while(startiter!=end){nsAFlatCString::const_iteratorenditer(end);if(!FindInReadable(nsDependentCString(eventName),startiter,enditer))returnfalse;// the match is surrounded by spaces, or at a string boundaryif((startiter==start||*--startiter==' ')&&(enditer==end||*enditer==' ')){returntrue;}// Move on and see if there are other matches. (The delimitation// requirement makes it pointless to begin the next search before// the end of the invalid match just found.)startiter=enditer;}returnfalse;}// staticPopupControlStatensDOMEvent::GetEventPopupControlState(nsEvent*aEvent){// generally if an event handler is running, new windows are disallowed.// check for exceptions:PopupControlStateabuse=openAbused;switch(aEvent->eventStructType){caseNS_EVENT:// For these following events only allow popups if they're// triggered while handling user input. See// nsPresShell::HandleEventInternal() for details.if(nsEventStateManager::IsHandlingUserInput()){switch(aEvent->message){caseNS_FORM_SELECTED:if(::PopupAllowedForEvent("select"))abuse=openControlled;break;caseNS_FORM_CHANGE:if(::PopupAllowedForEvent("change"))abuse=openControlled;break;}}break;caseNS_GUI_EVENT:// For this following event only allow popups if it's triggered// while handling user input. See// nsPresShell::HandleEventInternal() for details.if(nsEventStateManager::IsHandlingUserInput()){switch(aEvent->message){caseNS_FORM_INPUT:if(::PopupAllowedForEvent("input"))abuse=openControlled;break;}}break;caseNS_INPUT_EVENT:// For this following event only allow popups if it's triggered// while handling user input. See// nsPresShell::HandleEventInternal() for details.if(nsEventStateManager::IsHandlingUserInput()){switch(aEvent->message){caseNS_FORM_CHANGE:if(::PopupAllowedForEvent("change"))abuse=openControlled;break;caseNS_XUL_COMMAND:abuse=openControlled;break;}}break;caseNS_KEY_EVENT:if(NS_IS_TRUSTED_EVENT(aEvent)){PRUint32key=static_cast<nsKeyEvent*>(aEvent)->keyCode;switch(aEvent->message){caseNS_KEY_PRESS:// return key on focused button. see note at NS_MOUSE_CLICK.if(key==nsIDOMKeyEvent::DOM_VK_RETURN)abuse=openAllowed;elseif(::PopupAllowedForEvent("keypress"))abuse=openControlled;break;caseNS_KEY_UP:// space key on focused button. see note at NS_MOUSE_CLICK.if(key==nsIDOMKeyEvent::DOM_VK_SPACE)abuse=openAllowed;elseif(::PopupAllowedForEvent("keyup"))abuse=openControlled;break;caseNS_KEY_DOWN:if(::PopupAllowedForEvent("keydown"))abuse=openControlled;break;}}break;caseNS_MOUSE_EVENT:if(NS_IS_TRUSTED_EVENT(aEvent)&&static_cast<nsMouseEvent*>(aEvent)->button==nsMouseEvent::eLeftButton){switch(aEvent->message){caseNS_MOUSE_BUTTON_UP:if(::PopupAllowedForEvent("mouseup"))abuse=openControlled;break;caseNS_MOUSE_BUTTON_DOWN:if(::PopupAllowedForEvent("mousedown"))abuse=openControlled;break;caseNS_MOUSE_CLICK:/* Click events get special treatment because of their historical status as a more legitimate event handler. If click popups are enabled in the prefs, clear the popup status completely. */if(::PopupAllowedForEvent("click"))abuse=openAllowed;break;caseNS_MOUSE_DOUBLECLICK:if(::PopupAllowedForEvent("dblclick"))abuse=openControlled;break;}}break;caseNS_SCRIPT_ERROR_EVENT:switch(aEvent->message){caseNS_LOAD_ERROR:// Any error event will allow popups, if enabled in the pref.if(::PopupAllowedForEvent("error"))abuse=openControlled;break;}break;caseNS_FORM_EVENT:// For these following events only allow popups if they're// triggered while handling user input. See// nsPresShell::HandleEventInternal() for details.if(nsEventStateManager::IsHandlingUserInput()){switch(aEvent->message){caseNS_FORM_SUBMIT:if(::PopupAllowedForEvent("submit"))abuse=openControlled;break;caseNS_FORM_RESET:if(::PopupAllowedForEvent("reset"))abuse=openControlled;break;}}break;}returnabuse;}// staticvoidnsDOMEvent::PopupAllowedEventsChanged(){if(sPopupAllowedEvents){nsMemory::Free(sPopupAllowedEvents);}nsAdoptingCStringstr=Preferences::GetCString("dom.popup_allowed_events");// We'll want to do this even if str is empty to avoid looking up// this pref all the time if it's not set.sPopupAllowedEvents=ToNewCString(str);}// staticvoidnsDOMEvent::Shutdown(){if(sPopupAllowedEvents){nsMemory::Free(sPopupAllowedEvents);}}nsIntPointnsDOMEvent::GetScreenCoords(nsPresContext*aPresContext,nsEvent*aEvent,nsIntPointaPoint){if(nsEventStateManager::sIsPointerLocked){returnnsEventStateManager::sLastScreenPoint;}if(!aEvent||(aEvent->eventStructType!=NS_MOUSE_EVENT&&aEvent->eventStructType!=NS_POPUP_EVENT&&aEvent->eventStructType!=NS_MOUSE_SCROLL_EVENT&&aEvent->eventStructType!=NS_MOZTOUCH_EVENT&&aEvent->eventStructType!=NS_TOUCH_EVENT&&aEvent->eventStructType!=NS_DRAG_EVENT&&aEvent->eventStructType!=NS_SIMPLE_GESTURE_EVENT)){returnnsIntPoint(0,0);}nsGUIEvent*guiEvent=static_cast<nsGUIEvent*>(aEvent);if(!guiEvent->widget){returnaPoint;}nsIntPointoffset=aPoint+guiEvent->widget->WidgetToScreenOffset();nscoordfactor=aPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel();returnnsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x*factor),nsPresContext::AppUnitsToIntCSSPixels(offset.y*factor));}//staticnsIntPointnsDOMEvent::GetPageCoords(nsPresContext*aPresContext,nsEvent*aEvent,nsIntPointaPoint,nsIntPointaDefaultPoint){nsIntPointpagePoint=nsDOMEvent::GetClientCoords(aPresContext,aEvent,aPoint,aDefaultPoint);// If there is some scrolling, add scroll info to client point.if(aPresContext&&aPresContext->GetPresShell()){nsIPresShell*shell=aPresContext->GetPresShell();nsIScrollableFrame*scrollframe=shell->GetRootScrollFrameAsScrollable();if(scrollframe){nsPointpt=scrollframe->GetScrollPosition();pagePoint+=nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),nsPresContext::AppUnitsToIntCSSPixels(pt.y));}}returnpagePoint;}// staticnsIntPointnsDOMEvent::GetClientCoords(nsPresContext*aPresContext,nsEvent*aEvent,nsIntPointaPoint,nsIntPointaDefaultPoint){if(nsEventStateManager::sIsPointerLocked){returnnsEventStateManager::sLastClientPoint;}if(!aEvent||(aEvent->eventStructType!=NS_MOUSE_EVENT&&aEvent->eventStructType!=NS_POPUP_EVENT&&aEvent->eventStructType!=NS_MOUSE_SCROLL_EVENT&&aEvent->eventStructType!=NS_MOZTOUCH_EVENT&&aEvent->eventStructType!=NS_TOUCH_EVENT&&aEvent->eventStructType!=NS_DRAG_EVENT&&aEvent->eventStructType!=NS_SIMPLE_GESTURE_EVENT)||!aPresContext||!((nsGUIEvent*)aEvent)->widget){returnaDefaultPoint;}nsPointpt(0,0);nsIPresShell*shell=aPresContext->GetPresShell();if(!shell){returnnsIntPoint(0,0);}nsIFrame*rootFrame=shell->GetRootFrame();if(rootFrame)pt=nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent,aPoint,rootFrame);returnnsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),nsPresContext::AppUnitsToIntCSSPixels(pt.y));}// To be called ONLY by nsDOMEvent::GetType (which has the additional// logic for handling user-defined events).// staticconstchar*nsDOMEvent::GetEventName(PRUint32aEventType){switch(aEventType){caseNS_MOUSE_BUTTON_DOWN:returnsEventNames[eDOMEvents_mousedown];caseNS_MOUSE_BUTTON_UP:returnsEventNames[eDOMEvents_mouseup];caseNS_MOUSE_CLICK:returnsEventNames[eDOMEvents_click];caseNS_MOUSE_DOUBLECLICK:returnsEventNames[eDOMEvents_dblclick];caseNS_MOUSEENTER:returnsEventNames[eDOMEvents_mouseenter];caseNS_MOUSELEAVE:returnsEventNames[eDOMEvents_mouseleave];caseNS_MOUSE_ENTER_SYNTH:returnsEventNames[eDOMEvents_mouseover];caseNS_MOUSE_EXIT_SYNTH:returnsEventNames[eDOMEvents_mouseout];caseNS_MOUSE_MOZHITTEST:returnsEventNames[eDOMEvents_MozMouseHittest];caseNS_MOUSE_MOVE:returnsEventNames[eDOMEvents_mousemove];caseNS_KEY_UP:returnsEventNames[eDOMEvents_keyup];caseNS_KEY_DOWN:returnsEventNames[eDOMEvents_keydown];caseNS_KEY_PRESS:returnsEventNames[eDOMEvents_keypress];caseNS_COMPOSITION_START:returnsEventNames[eDOMEvents_compositionstart];caseNS_COMPOSITION_UPDATE:returnsEventNames[eDOMEvents_compositionupdate];caseNS_COMPOSITION_END:returnsEventNames[eDOMEvents_compositionend];caseNS_FOCUS_CONTENT:returnsEventNames[eDOMEvents_focus];caseNS_BLUR_CONTENT:returnsEventNames[eDOMEvents_blur];caseNS_XUL_CLOSE:returnsEventNames[eDOMEvents_close];caseNS_LOAD:returnsEventNames[eDOMEvents_load];caseNS_POPSTATE:returnsEventNames[eDOMEvents_popstate];caseNS_BEFORE_SCRIPT_EXECUTE:returnsEventNames[eDOMEvents_beforescriptexecute];caseNS_AFTER_SCRIPT_EXECUTE:returnsEventNames[eDOMEvents_afterscriptexecute];caseNS_BEFORE_PAGE_UNLOAD:returnsEventNames[eDOMEvents_beforeunload];caseNS_PAGE_UNLOAD:returnsEventNames[eDOMEvents_unload];caseNS_HASHCHANGE:returnsEventNames[eDOMEvents_hashchange];caseNS_READYSTATECHANGE:returnsEventNames[eDOMEvents_readystatechange];caseNS_IMAGE_ABORT:returnsEventNames[eDOMEvents_abort];caseNS_LOAD_ERROR:returnsEventNames[eDOMEvents_error];caseNS_FORM_SUBMIT:returnsEventNames[eDOMEvents_submit];caseNS_FORM_RESET:returnsEventNames[eDOMEvents_reset];caseNS_FORM_CHANGE:returnsEventNames[eDOMEvents_change];caseNS_FORM_SELECTED:returnsEventNames[eDOMEvents_select];caseNS_FORM_INPUT:returnsEventNames[eDOMEvents_input];caseNS_FORM_INVALID:returnsEventNames[eDOMEvents_invalid];caseNS_RESIZE_EVENT:returnsEventNames[eDOMEvents_resize];caseNS_SCROLL_EVENT:returnsEventNames[eDOMEvents_scroll];caseNS_TEXT_TEXT:returnsEventNames[eDOMEvents_text];caseNS_XUL_POPUP_SHOWING:returnsEventNames[eDOMEvents_popupShowing];caseNS_XUL_POPUP_SHOWN:returnsEventNames[eDOMEvents_popupShown];caseNS_XUL_POPUP_HIDING:returnsEventNames[eDOMEvents_popupHiding];caseNS_XUL_POPUP_HIDDEN:returnsEventNames[eDOMEvents_popupHidden];caseNS_XUL_COMMAND:returnsEventNames[eDOMEvents_command];caseNS_XUL_BROADCAST:returnsEventNames[eDOMEvents_broadcast];caseNS_XUL_COMMAND_UPDATE:returnsEventNames[eDOMEvents_commandupdate];caseNS_DRAGDROP_ENTER:returnsEventNames[eDOMEvents_dragenter];caseNS_DRAGDROP_OVER_SYNTH:returnsEventNames[eDOMEvents_dragover];caseNS_DRAGDROP_EXIT_SYNTH:returnsEventNames[eDOMEvents_dragexit];caseNS_DRAGDROP_DRAGDROP:returnsEventNames[eDOMEvents_dragdrop];caseNS_DRAGDROP_GESTURE:returnsEventNames[eDOMEvents_draggesture];caseNS_DRAGDROP_DRAG:returnsEventNames[eDOMEvents_drag];caseNS_DRAGDROP_END:returnsEventNames[eDOMEvents_dragend];caseNS_DRAGDROP_START:returnsEventNames[eDOMEvents_dragstart];caseNS_DRAGDROP_LEAVE_SYNTH:returnsEventNames[eDOMEvents_dragleave];caseNS_DRAGDROP_DROP:returnsEventNames[eDOMEvents_drop];caseNS_SCROLLPORT_OVERFLOW:returnsEventNames[eDOMEvents_overflow];caseNS_SCROLLPORT_UNDERFLOW:returnsEventNames[eDOMEvents_underflow];caseNS_SCROLLPORT_OVERFLOWCHANGED:returnsEventNames[eDOMEvents_overflowchanged];caseNS_MUTATION_SUBTREEMODIFIED:returnsEventNames[eDOMEvents_subtreemodified];caseNS_MUTATION_NODEINSERTED:returnsEventNames[eDOMEvents_nodeinserted];caseNS_MUTATION_NODEREMOVED:returnsEventNames[eDOMEvents_noderemoved];caseNS_MUTATION_NODEREMOVEDFROMDOCUMENT:returnsEventNames[eDOMEvents_noderemovedfromdocument];caseNS_MUTATION_NODEINSERTEDINTODOCUMENT:returnsEventNames[eDOMEvents_nodeinsertedintodocument];caseNS_MUTATION_ATTRMODIFIED:returnsEventNames[eDOMEvents_attrmodified];caseNS_MUTATION_CHARACTERDATAMODIFIED:returnsEventNames[eDOMEvents_characterdatamodified];caseNS_CONTEXTMENU:returnsEventNames[eDOMEvents_contextmenu];caseNS_UI_ACTIVATE:returnsEventNames[eDOMEvents_DOMActivate];caseNS_UI_FOCUSIN:returnsEventNames[eDOMEvents_DOMFocusIn];caseNS_UI_FOCUSOUT:returnsEventNames[eDOMEvents_DOMFocusOut];caseNS_PAGE_SHOW:returnsEventNames[eDOMEvents_pageshow];caseNS_PAGE_HIDE:returnsEventNames[eDOMEvents_pagehide];caseNS_MOUSE_SCROLL:returnsEventNames[eDOMEvents_DOMMouseScroll];caseNS_MOUSE_PIXEL_SCROLL:returnsEventNames[eDOMEvents_MozMousePixelScroll];caseNS_OFFLINE:returnsEventNames[eDOMEvents_offline];caseNS_ONLINE:returnsEventNames[eDOMEvents_online];caseNS_COPY:returnsEventNames[eDOMEvents_copy];caseNS_CUT:returnsEventNames[eDOMEvents_cut];caseNS_PASTE:returnsEventNames[eDOMEvents_paste];caseNS_OPEN:returnsEventNames[eDOMEvents_open];caseNS_MESSAGE:returnsEventNames[eDOMEvents_message];caseNS_SHOW_EVENT:returnsEventNames[eDOMEvents_show];caseNS_SVG_LOAD:returnsEventNames[eDOMEvents_SVGLoad];caseNS_SVG_UNLOAD:returnsEventNames[eDOMEvents_SVGUnload];caseNS_SVG_ABORT:returnsEventNames[eDOMEvents_SVGAbort];caseNS_SVG_ERROR:returnsEventNames[eDOMEvents_SVGError];caseNS_SVG_RESIZE:returnsEventNames[eDOMEvents_SVGResize];caseNS_SVG_SCROLL:returnsEventNames[eDOMEvents_SVGScroll];caseNS_SVG_ZOOM:returnsEventNames[eDOMEvents_SVGZoom];caseNS_TOUCH_START:returnsEventNames[eDOMEvents_touchstart];caseNS_TOUCH_MOVE:returnsEventNames[eDOMEvents_touchmove];caseNS_TOUCH_END:returnsEventNames[eDOMEvents_touchend];caseNS_TOUCH_ENTER:returnsEventNames[eDOMEvents_touchenter];caseNS_TOUCH_LEAVE:returnsEventNames[eDOMEvents_touchleave];caseNS_TOUCH_CANCEL:returnsEventNames[eDOMEvents_touchcancel];caseNS_SMIL_BEGIN:returnsEventNames[eDOMEvents_beginEvent];caseNS_SMIL_END:returnsEventNames[eDOMEvents_endEvent];caseNS_SMIL_REPEAT:returnsEventNames[eDOMEvents_repeatEvent];#ifdef MOZ_MEDIAcaseNS_LOADSTART:returnsEventNames[eDOMEvents_loadstart];caseNS_PROGRESS:returnsEventNames[eDOMEvents_progress];caseNS_SUSPEND:returnsEventNames[eDOMEvents_suspend];caseNS_EMPTIED:returnsEventNames[eDOMEvents_emptied];caseNS_STALLED:returnsEventNames[eDOMEvents_stalled];caseNS_PLAY:returnsEventNames[eDOMEvents_play];caseNS_PAUSE:returnsEventNames[eDOMEvents_pause];caseNS_LOADEDMETADATA:returnsEventNames[eDOMEvents_loadedmetadata];caseNS_LOADEDDATA:returnsEventNames[eDOMEvents_loadeddata];caseNS_WAITING:returnsEventNames[eDOMEvents_waiting];caseNS_PLAYING:returnsEventNames[eDOMEvents_playing];caseNS_CANPLAY:returnsEventNames[eDOMEvents_canplay];caseNS_CANPLAYTHROUGH:returnsEventNames[eDOMEvents_canplaythrough];caseNS_SEEKING:returnsEventNames[eDOMEvents_seeking];caseNS_SEEKED:returnsEventNames[eDOMEvents_seeked];caseNS_TIMEUPDATE:returnsEventNames[eDOMEvents_timeupdate];caseNS_ENDED:returnsEventNames[eDOMEvents_ended];caseNS_RATECHANGE:returnsEventNames[eDOMEvents_ratechange];caseNS_DURATIONCHANGE:returnsEventNames[eDOMEvents_durationchange];caseNS_VOLUMECHANGE:returnsEventNames[eDOMEvents_volumechange];caseNS_MOZAUDIOAVAILABLE:returnsEventNames[eDOMEvents_mozaudioavailable];#endifcaseNS_AFTERPAINT:returnsEventNames[eDOMEvents_afterpaint];caseNS_BEFORERESIZE_EVENT:returnsEventNames[eDOMEvents_beforeresize];caseNS_SIMPLE_GESTURE_SWIPE:returnsEventNames[eDOMEvents_MozSwipeGesture];caseNS_SIMPLE_GESTURE_MAGNIFY_START:returnsEventNames[eDOMEvents_MozMagnifyGestureStart];caseNS_SIMPLE_GESTURE_MAGNIFY_UPDATE:returnsEventNames[eDOMEvents_MozMagnifyGestureUpdate];caseNS_SIMPLE_GESTURE_MAGNIFY:returnsEventNames[eDOMEvents_MozMagnifyGesture];caseNS_SIMPLE_GESTURE_ROTATE_START:returnsEventNames[eDOMEvents_MozRotateGestureStart];caseNS_SIMPLE_GESTURE_ROTATE_UPDATE:returnsEventNames[eDOMEvents_MozRotateGestureUpdate];caseNS_SIMPLE_GESTURE_ROTATE:returnsEventNames[eDOMEvents_MozRotateGesture];caseNS_SIMPLE_GESTURE_TAP:returnsEventNames[eDOMEvents_MozTapGesture];caseNS_SIMPLE_GESTURE_PRESSTAP:returnsEventNames[eDOMEvents_MozPressTapGesture];caseNS_MOZTOUCH_DOWN:returnsEventNames[eDOMEvents_MozTouchDown];caseNS_MOZTOUCH_MOVE:returnsEventNames[eDOMEvents_MozTouchMove];caseNS_MOZTOUCH_UP:returnsEventNames[eDOMEvents_MozTouchUp];caseNS_SCROLLEDAREACHANGED:returnsEventNames[eDOMEvents_MozScrolledAreaChanged];caseNS_TRANSITION_END:returnsEventNames[eDOMEvents_transitionend];caseNS_ANIMATION_START:returnsEventNames[eDOMEvents_animationstart];caseNS_ANIMATION_END:returnsEventNames[eDOMEvents_animationend];caseNS_ANIMATION_ITERATION:returnsEventNames[eDOMEvents_animationiteration];caseNS_DEVICE_MOTION:returnsEventNames[eDOMEvents_devicemotion];caseNS_DEVICE_ORIENTATION:returnsEventNames[eDOMEvents_deviceorientation];caseNS_FULLSCREENCHANGE:returnsEventNames[eDOMEvents_mozfullscreenchange];caseNS_FULLSCREENERROR:returnsEventNames[eDOMEvents_mozfullscreenerror];default:break;}// XXXldb We can hit this case for nsEvent objects that we didn't// create and that are not user defined events since this function and// SetEventType are incomplete. (But fixing that requires fixing the// arrays in nsEventListenerManager too, since the events for which// this is a problem generally *are* created by nsDOMEvent.)returnnsnull;}NS_IMETHODIMPnsDOMEvent::GetPreventDefault(bool*aReturn){NS_ENSURE_ARG_POINTER(aReturn);*aReturn=mEvent&&(mEvent->flags&NS_EVENT_FLAG_NO_DEFAULT);returnNS_OK;}NS_IMETHODIMPnsDOMEvent::GetDefaultPrevented(bool*aReturn){returnGetPreventDefault(aReturn);}voidnsDOMEvent::Serialize(IPC::Message*aMsg,boolaSerializeInterfaceType){if(aSerializeInterfaceType){IPC::WriteParam(aMsg,NS_LITERAL_STRING("event"));}nsStringtype;GetType(type);IPC::WriteParam(aMsg,type);boolbubbles=false;GetBubbles(&bubbles);IPC::WriteParam(aMsg,bubbles);boolcancelable=false;GetCancelable(&cancelable);IPC::WriteParam(aMsg,cancelable);booltrusted=false;GetIsTrusted(&trusted);IPC::WriteParam(aMsg,trusted);// No timestamp serialization for now!}boolnsDOMEvent::Deserialize(constIPC::Message*aMsg,void**aIter){nsStringtype;NS_ENSURE_TRUE(IPC::ReadParam(aMsg,aIter,&type),false);boolbubbles=false;NS_ENSURE_TRUE(IPC::ReadParam(aMsg,aIter,&bubbles),false);boolcancelable=false;NS_ENSURE_TRUE(IPC::ReadParam(aMsg,aIter,&cancelable),false);booltrusted=false;NS_ENSURE_TRUE(IPC::ReadParam(aMsg,aIter,&trusted),false);nsresultrv=InitEvent(type,bubbles,cancelable);NS_ENSURE_SUCCESS(rv,false);SetTrusted(trusted);returntrue;}nsresultNS_NewDOMEvent(nsIDOMEvent**aInstancePtrResult,nsPresContext*aPresContext,nsEvent*aEvent){nsDOMEvent*it=newnsDOMEvent(aPresContext,aEvent);if(nsnull==it){returnNS_ERROR_OUT_OF_MEMORY;}returnCallQueryInterface(it,aInstancePtrResult);}