LCOV - code coverage report
Current view: directory - content/events/src - nsDOMEvent.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 744 155 20.8 %
Date: 2012-06-02 Functions: 53 28 52.8 %

       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
       4                 :  *
       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/
       9                 :  *
      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
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      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.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Steve Clark (buster@netscape.com)
      24                 :  *   Ilya Konstantinov (mozilla-code@future.shiny.co.il)
      25                 :  *
      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.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "base/basictypes.h"
      41                 : 
      42                 : /* This must occur *after* base/basictypes.h to avoid typedefs conflicts. */
      43                 : #include "mozilla/Util.h"
      44                 : 
      45                 : #include "IPC/IPCMessageUtils.h"
      46                 : #include "nsCOMPtr.h"
      47                 : #include "nsDOMEvent.h"
      48                 : #include "nsEventStateManager.h"
      49                 : #include "nsIFrame.h"
      50                 : #include "nsIContent.h"
      51                 : #include "nsIPresShell.h"
      52                 : #include "nsIDocument.h"
      53                 : #include "nsIInterfaceRequestor.h"
      54                 : #include "nsIInterfaceRequestorUtils.h"
      55                 : #include "prmem.h"
      56                 : #include "nsGkAtoms.h"
      57                 : #include "nsMutationEvent.h"
      58                 : #include "nsContentUtils.h"
      59                 : #include "nsIURI.h"
      60                 : #include "nsIScriptSecurityManager.h"
      61                 : #include "nsIScriptError.h"
      62                 : #include "nsDOMPopStateEvent.h"
      63                 : #include "mozilla/Preferences.h"
      64                 : #include "nsJSUtils.h"
      65                 : #include "DictionaryHelpers.h"
      66                 : #include "nsLayoutUtils.h"
      67                 : #include "nsIScrollableFrame.h"
      68                 : 
      69                 : using namespace mozilla;
      70                 : 
      71                 : static const char* const sEventNames[] = {
      72                 :   "mousedown", "mouseup", "click", "dblclick", "mouseenter", "mouseleave", "mouseover",
      73                 :   "mouseout", "MozMouseHittest", "mousemove", "contextmenu", "keydown", "keyup", "keypress",
      74                 :   "focus", "blur", "load", "popstate", "beforescriptexecute",
      75                 :   "afterscriptexecute", "beforeunload", "unload",
      76                 :   "hashchange", "readystatechange", "abort", "error",
      77                 :   "submit", "reset", "change", "select", "input", "invalid", "text",
      78                 :   "compositionstart", "compositionend", "compositionupdate",
      79                 :   "popupshowing", "popupshown",
      80                 :   "popuphiding", "popuphidden", "close", "command", "broadcast", "commandupdate",
      81                 :   "dragenter", "dragover", "dragexit", "dragdrop", "draggesture",
      82                 :   "drag", "dragend", "dragstart", "dragleave", "drop", "resize",
      83                 :   "scroll", "overflow", "underflow", "overflowchanged",
      84                 :   "DOMSubtreeModified", "DOMNodeInserted", "DOMNodeRemoved", 
      85                 :   "DOMNodeRemovedFromDocument", "DOMNodeInsertedIntoDocument",
      86                 :   "DOMAttrModified", "DOMCharacterDataModified",
      87                 :   "DOMActivate", "DOMFocusIn", "DOMFocusOut",
      88                 :   "pageshow", "pagehide", "DOMMouseScroll", "MozMousePixelScroll",
      89                 :   "offline", "online", "copy", "cut", "paste", "open", "message", "show",
      90                 :   "SVGLoad", "SVGUnload", "SVGAbort", "SVGError", "SVGResize", "SVGScroll",
      91                 :   "SVGZoom",
      92                 :   "beginEvent", "endEvent", "repeatEvent",
      93                 : #ifdef MOZ_MEDIA
      94                 :   "loadstart", "progress", "suspend", "emptied", "stalled", "play", "pause",
      95                 :   "loadedmetadata", "loadeddata", "waiting", "playing", "canplay",
      96                 :   "canplaythrough", "seeking", "seeked", "timeupdate", "ended", "ratechange",
      97                 :   "durationchange", "volumechange", "MozAudioAvailable",
      98                 : #endif // MOZ_MEDIA
      99                 :   "MozAfterPaint",
     100                 :   "MozBeforeResize",
     101                 :   "mozfullscreenchange",
     102                 :   "mozfullscreenerror",
     103                 :   "MozSwipeGesture",
     104                 :   "MozMagnifyGestureStart",
     105                 :   "MozMagnifyGestureUpdate",
     106                 :   "MozMagnifyGesture",
     107                 :   "MozRotateGestureStart",
     108                 :   "MozRotateGestureUpdate",
     109                 :   "MozRotateGesture",
     110                 :   "MozTapGesture",
     111                 :   "MozPressTapGesture",
     112                 :   "MozTouchDown",
     113                 :   "MozTouchMove",
     114                 :   "MozTouchUp",
     115                 :   "touchstart",
     116                 :   "touchend",
     117                 :   "touchmove",
     118                 :   "touchcancel",
     119                 :   "touchenter",
     120                 :   "touchleave",
     121                 :   "MozScrolledAreaChanged",
     122                 :   "transitionend",
     123                 :   "animationstart",
     124                 :   "animationend",
     125                 :   "animationiteration",
     126                 :   "devicemotion",
     127                 :   "deviceorientation"
     128                 : };
     129                 : 
     130                 : static char *sPopupAllowedEvents;
     131                 : 
     132                 : 
     133           16413 : nsDOMEvent::nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent)
     134                 : {
     135           16413 :   mPrivateDataDuplicated = false;
     136                 : 
     137           16413 :   if (aEvent) {
     138              46 :     mEvent = aEvent;
     139              46 :     mEventIsInternal = false;
     140                 :   }
     141                 :   else {
     142           16367 :     mEventIsInternal = true;
     143                 :     /*
     144                 :       A derived class might want to allocate its own type of aEvent
     145                 :       (derived from nsEvent). To do this, it should take care to pass
     146                 :       a non-NULL aEvent to this ctor, e.g.:
     147                 :       
     148                 :         nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
     149                 :         : nsDOMEvent(..., aEvent ? aEvent : new nsFooEvent())
     150                 :       
     151                 :       Then, to override the mEventIsInternal assignments done by the
     152                 :       base ctor, it should do this in its own ctor:
     153                 : 
     154                 :         nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
     155                 :         ...
     156                 :         {
     157                 :           ...
     158                 :           if (aEvent) {
     159                 :             mEventIsInternal = false;
     160                 :           }
     161                 :           else {
     162                 :             mEventIsInternal = true;
     163                 :           }
     164                 :           ...
     165                 :         }
     166                 :      */
     167           16367 :     mEvent = new nsEvent(false, 0);
     168           16367 :     mEvent->time = PR_Now();
     169                 :   }
     170                 : 
     171           16413 :   InitPresContextData(aPresContext);
     172                 : 
     173           16413 :   NS_ASSERTION(mEvent->message != NS_PAINT, "Trying to create a DOM paint event!");
     174           16413 : }
     175                 : 
     176                 : void
     177           16413 : nsDOMEvent::InitPresContextData(nsPresContext* aPresContext)
     178                 : {
     179           16413 :   mPresContext = aPresContext;
     180                 :   // Get the explicit original target (if it's anonymous make it null)
     181                 :   {
     182           32826 :     nsCOMPtr<nsIContent> content = GetTargetFromFrame();
     183           16413 :     mExplicitOriginalTarget = do_QueryInterface(content);
     184           16413 :     if (content && content->IsInAnonymousSubtree()) {
     185               0 :       mExplicitOriginalTarget = nsnull;
     186                 :     }
     187                 :   }
     188           16413 : }
     189                 : 
     190           46824 : nsDOMEvent::~nsDOMEvent() 
     191                 : {
     192           16413 :   NS_ASSERT_OWNINGTHREAD(nsDOMEvent);
     193                 : 
     194           16413 :   if (mEventIsInternal && mEvent) {
     195           16367 :     delete mEvent;
     196                 :   }
     197           60822 : }
     198                 : 
     199            1464 : NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMEvent)
     200                 : 
     201                 : DOMCI_DATA(Event, nsDOMEvent)
     202                 : 
     203          194013 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMEvent)
     204          120654 :   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMEvent)
     205          116674 :   NS_INTERFACE_MAP_ENTRY(nsIDOMEvent)
     206           75019 :   NS_INTERFACE_MAP_ENTRY(nsIDOMNSEvent)
     207           60198 :   NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMEvent)
     208           19033 :   NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
     209           19033 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Event)
     210           15663 : NS_INTERFACE_MAP_END
     211                 : 
     212          109375 : NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMEvent)
     213          109375 : NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMEvent)
     214                 : 
     215              11 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMEvent)
     216              11 :   if (tmp->mEventIsInternal) {
     217              11 :     tmp->mEvent->target = nsnull;
     218              11 :     tmp->mEvent->currentTarget = nsnull;
     219              11 :     tmp->mEvent->originalTarget = nsnull;
     220              11 :     switch (tmp->mEvent->eventStructType) {
     221                 :       case NS_MOUSE_EVENT:
     222                 :       case NS_MOUSE_SCROLL_EVENT:
     223                 :       case NS_SIMPLE_GESTURE_EVENT:
     224                 :       case NS_MOZTOUCH_EVENT:
     225               0 :         static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget = nsnull;
     226               0 :         break;
     227                 :       case NS_DRAG_EVENT:
     228               0 :         static_cast<nsDragEvent*>(tmp->mEvent)->dataTransfer = nsnull;
     229               0 :         static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget = nsnull;
     230               0 :         break;
     231                 :       case NS_MUTATION_EVENT:
     232               0 :         static_cast<nsMutationEvent*>(tmp->mEvent)->mRelatedNode = nsnull;
     233               0 :         break;
     234                 :       default:
     235              11 :         break;
     236                 :     }
     237                 :   }
     238              11 :   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPresContext);
     239              11 :   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mExplicitOriginalTarget);
     240              11 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
     241                 : 
     242              34 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMEvent)
     243              34 :   if (tmp->mEventIsInternal) {
     244              34 :     NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEvent->target)
     245              34 :     NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEvent->currentTarget)
     246              34 :     NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEvent->originalTarget)
     247              34 :     switch (tmp->mEvent->eventStructType) {
     248                 :       case NS_MOUSE_EVENT:
     249                 :       case NS_MOUSE_SCROLL_EVENT:
     250                 :       case NS_SIMPLE_GESTURE_EVENT:
     251                 :       case NS_MOZTOUCH_EVENT:
     252               0 :         NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
     253                 :         cb.NoteXPCOMChild(
     254               0 :           static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget);
     255               0 :         break;
     256                 :       case NS_DRAG_EVENT:
     257               0 :         NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->dataTransfer");
     258                 :         cb.NoteXPCOMChild(
     259               0 :           static_cast<nsDragEvent*>(tmp->mEvent)->dataTransfer);
     260               0 :         NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
     261                 :         cb.NoteXPCOMChild(
     262               0 :           static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget);
     263               0 :         break;
     264                 :       case NS_MUTATION_EVENT:
     265               0 :         NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->mRelatedNode");
     266                 :         cb.NoteXPCOMChild(
     267               0 :           static_cast<nsMutationEvent*>(tmp->mEvent)->mRelatedNode);
     268               0 :         break;
     269                 :       default:
     270              34 :         break;
     271                 :     }
     272                 :   }
     273              34 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mPresContext.get(), nsPresContext)
     274              34 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mExplicitOriginalTarget)
     275              34 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
     276                 : 
     277                 : // nsIDOMEventInterface
     278             148 : NS_METHOD nsDOMEvent::GetType(nsAString& aType)
     279                 : {
     280             148 :   if (!mCachedType.IsEmpty()) {
     281             148 :     aType = mCachedType;
     282             148 :     return NS_OK;
     283                 :   }
     284               0 :   const char* name = GetEventName(mEvent->message);
     285                 : 
     286               0 :   if (name) {
     287               0 :     CopyASCIItoUTF16(name, aType);
     288               0 :     mCachedType = aType;
     289               0 :     return NS_OK;
     290               0 :   } else if (mEvent->message == NS_USER_DEFINED_EVENT && mEvent->userType) {
     291               0 :     aType = Substring(nsDependentAtomString(mEvent->userType), 2); // Remove "on"
     292               0 :     mCachedType = aType;
     293               0 :     return NS_OK;
     294                 :   }
     295                 : 
     296               0 :   aType.Truncate();
     297               0 :   return NS_OK;
     298                 : }
     299                 : 
     300                 : static nsresult
     301            7502 : GetDOMEventTarget(nsIDOMEventTarget* aTarget,
     302                 :                   nsIDOMEventTarget** aDOMTarget)
     303                 : {
     304                 :   nsIDOMEventTarget* realTarget =
     305            7502 :     aTarget ? aTarget->GetTargetForDOMEvent() : aTarget;
     306                 : 
     307            7502 :   NS_IF_ADDREF(*aDOMTarget = realTarget);
     308                 : 
     309            7502 :   return NS_OK;
     310                 : }
     311                 : 
     312                 : NS_METHOD
     313            3537 : nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget)
     314                 : {
     315            3537 :   return GetDOMEventTarget(mEvent->target, aTarget);
     316                 : }
     317                 : 
     318                 : NS_IMETHODIMP
     319            3965 : nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)
     320                 : {
     321            3965 :   return GetDOMEventTarget(mEvent->currentTarget, aCurrentTarget);
     322                 : }
     323                 : 
     324                 : //
     325                 : // Get the actual event target node (may have been retargeted for mouse events)
     326                 : //
     327                 : already_AddRefed<nsIContent>
     328           16413 : nsDOMEvent::GetTargetFromFrame()
     329                 : {
     330           16413 :   if (!mPresContext) { return nsnull; }
     331                 : 
     332                 :   // Get the target frame (have to get the ESM first)
     333               0 :   nsIFrame* targetFrame = mPresContext->EventStateManager()->GetEventTarget();
     334               0 :   if (!targetFrame) { return nsnull; }
     335                 : 
     336                 :   // get the real content
     337               0 :   nsCOMPtr<nsIContent> realEventContent;
     338               0 :   targetFrame->GetContentForEvent(mEvent, getter_AddRefs(realEventContent));
     339               0 :   return realEventContent.forget();
     340                 : }
     341                 : 
     342                 : NS_IMETHODIMP
     343               0 : nsDOMEvent::GetExplicitOriginalTarget(nsIDOMEventTarget** aRealEventTarget)
     344                 : {
     345               0 :   if (mExplicitOriginalTarget) {
     346               0 :     *aRealEventTarget = mExplicitOriginalTarget;
     347               0 :     NS_ADDREF(*aRealEventTarget);
     348               0 :     return NS_OK;
     349                 :   }
     350                 : 
     351               0 :   return GetTarget(aRealEventTarget);
     352                 : }
     353                 : 
     354                 : NS_IMETHODIMP
     355               0 : nsDOMEvent::GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget)
     356                 : {
     357               0 :   if (mEvent->originalTarget) {
     358               0 :     return GetDOMEventTarget(mEvent->originalTarget, aOriginalTarget);
     359                 :   }
     360                 : 
     361               0 :   return GetTarget(aOriginalTarget);
     362                 : }
     363                 : 
     364                 : NS_IMETHODIMP
     365           16381 : nsDOMEvent::SetTrusted(bool aTrusted)
     366                 : {
     367           16381 :   if (aTrusted) {
     368           16381 :     mEvent->flags |= NS_EVENT_FLAG_TRUSTED;
     369                 :   } else {
     370               0 :     mEvent->flags &= ~NS_EVENT_FLAG_TRUSTED;
     371                 :   }
     372                 : 
     373           16381 :   return NS_OK;
     374                 : }
     375                 : 
     376                 : NS_IMETHODIMP
     377               0 : nsDOMEvent::Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj,
     378                 :                        PRUint32 aArgc, jsval* aArgv)
     379                 : {
     380               0 :   NS_ENSURE_TRUE(aArgc >= 1, NS_ERROR_XPC_NOT_ENOUGH_ARGS);
     381                 : 
     382               0 :   bool trusted = false;
     383               0 :   nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aOwner);
     384               0 :   if (w) {
     385               0 :     nsCOMPtr<nsIDocument> d = do_QueryInterface(w->GetExtantDocument());
     386               0 :     if (d) {
     387               0 :       trusted = nsContentUtils::IsChromeDoc(d);
     388               0 :       nsIPresShell* s = d->GetShell();
     389               0 :       if (s) {
     390               0 :         InitPresContextData(s->GetPresContext());
     391                 :       }
     392                 :     }
     393                 :   }
     394                 : 
     395               0 :   JSAutoRequest ar(aCx);
     396               0 :   JSString* jsstr = JS_ValueToString(aCx, aArgv[0]);
     397               0 :   if (!jsstr) {
     398               0 :     return NS_ERROR_DOM_SYNTAX_ERR;
     399                 :   }
     400                 : 
     401               0 :   JS::Anchor<JSString*> deleteProtector(jsstr);
     402                 : 
     403               0 :   nsDependentJSString type;
     404               0 :   NS_ENSURE_STATE(type.init(aCx, jsstr));
     405                 : 
     406               0 :   nsresult rv = InitFromCtor(type, aCx, aArgc >= 2 ? &(aArgv[1]) : nsnull);
     407               0 :   NS_ENSURE_SUCCESS(rv, rv);
     408                 : 
     409               0 :   SetTrusted(trusted);
     410               0 :   return NS_OK;
     411                 : }
     412                 : 
     413                 : nsresult
     414               0 : nsDOMEvent::InitFromCtor(const nsAString& aType,
     415                 :                          JSContext* aCx, jsval* aVal)
     416                 : {
     417               0 :   mozilla::dom::EventInit d;
     418               0 :   nsresult rv = d.Init(aCx, aVal);
     419               0 :   NS_ENSURE_SUCCESS(rv, rv);
     420               0 :   return InitEvent(aType, d.bubbles, d.cancelable);
     421                 : }
     422                 : 
     423                 : NS_IMETHODIMP
     424               0 : nsDOMEvent::GetEventPhase(PRUint16* aEventPhase)
     425                 : {
     426                 :   // Note, remember to check that this works also
     427                 :   // if or when Bug 235441 is fixed.
     428               0 :   if (mEvent->currentTarget == mEvent->target ||
     429                 :       ((mEvent->flags & NS_EVENT_FLAG_CAPTURE) &&
     430                 :        (mEvent->flags & NS_EVENT_FLAG_BUBBLE))) {
     431               0 :     *aEventPhase = nsIDOMEvent::AT_TARGET;
     432               0 :   } else if (mEvent->flags & NS_EVENT_FLAG_CAPTURE) {
     433               0 :     *aEventPhase = nsIDOMEvent::CAPTURING_PHASE;
     434               0 :   } else if (mEvent->flags & NS_EVENT_FLAG_BUBBLE) {
     435               0 :     *aEventPhase = nsIDOMEvent::BUBBLING_PHASE;
     436                 :   } else {
     437               0 :     *aEventPhase = 0;
     438                 :   }
     439               0 :   return NS_OK;
     440                 : }
     441                 : 
     442                 : NS_IMETHODIMP
     443               0 : nsDOMEvent::GetBubbles(bool* aBubbles)
     444                 : {
     445               0 :   *aBubbles = !(mEvent->flags & NS_EVENT_FLAG_CANT_BUBBLE);
     446               0 :   return NS_OK;
     447                 : }
     448                 : 
     449                 : NS_IMETHODIMP
     450               0 : nsDOMEvent::GetCancelable(bool* aCancelable)
     451                 : {
     452               0 :   *aCancelable = !(mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL);
     453               0 :   return NS_OK;
     454                 : }
     455                 : 
     456                 : NS_IMETHODIMP
     457               0 : nsDOMEvent::GetTimeStamp(PRUint64* aTimeStamp)
     458                 : {
     459               0 :   *aTimeStamp = mEvent->time;
     460               0 :   return NS_OK;
     461                 : }
     462                 : 
     463                 : NS_IMETHODIMP
     464              10 : nsDOMEvent::StopPropagation()
     465                 : {
     466              10 :   mEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH;
     467              10 :   return NS_OK;
     468                 : }
     469                 : 
     470                 : NS_IMETHODIMP
     471               0 : nsDOMEvent::StopImmediatePropagation()
     472                 : {
     473                 :   mEvent->flags |=
     474               0 :     (NS_EVENT_FLAG_STOP_DISPATCH_IMMEDIATELY | NS_EVENT_FLAG_STOP_DISPATCH);
     475               0 :   return NS_OK;
     476                 : }
     477                 : 
     478               0 : static nsIDocument* GetDocumentForReport(nsEvent* aEvent)
     479                 : {
     480               0 :   nsCOMPtr<nsINode> node = do_QueryInterface(aEvent->currentTarget);
     481               0 :   if (node)
     482               0 :     return node->OwnerDoc();
     483                 : 
     484               0 :   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aEvent->currentTarget);
     485               0 :   if (!window)
     486               0 :     return nsnull;
     487                 : 
     488               0 :   nsCOMPtr<nsIDocument> doc(do_QueryInterface(window->GetExtantDocument()));
     489               0 :   return doc;
     490                 : }
     491                 : 
     492                 : static void
     493               0 : ReportUseOfDeprecatedMethod(nsEvent* aEvent, nsIDOMEvent* aDOMEvent,
     494                 :                             const char* aWarning)
     495                 : {
     496               0 :   nsCOMPtr<nsIDocument> doc(GetDocumentForReport(aEvent));
     497                 : 
     498               0 :   nsAutoString type;
     499               0 :   aDOMEvent->GetType(type);
     500               0 :   const PRUnichar *strings[] = { type.get() };
     501                 :   nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
     502                 :                                   "DOM Events", doc,
     503                 :                                   nsContentUtils::eDOM_PROPERTIES,
     504                 :                                   aWarning,
     505               0 :                                   strings, ArrayLength(strings));
     506               0 : }
     507                 : 
     508                 : NS_IMETHODIMP
     509               0 : nsDOMEvent::PreventBubble()
     510                 : {
     511               0 :   ReportUseOfDeprecatedMethod(mEvent, this, "UseOfPreventBubbleWarning");
     512               0 :   return NS_OK;
     513                 : }
     514                 : 
     515                 : NS_IMETHODIMP
     516               0 : nsDOMEvent::PreventCapture()
     517                 : {
     518               0 :   ReportUseOfDeprecatedMethod(mEvent, this, "UseOfPreventCaptureWarning");
     519               0 :   return NS_OK;
     520                 : }
     521                 : 
     522                 : NS_IMETHODIMP
     523           15343 : nsDOMEvent::GetIsTrusted(bool *aIsTrusted)
     524                 : {
     525           15343 :   *aIsTrusted = NS_IS_TRUSTED_EVENT(mEvent);
     526                 : 
     527           15343 :   return NS_OK;
     528                 : }
     529                 : 
     530                 : NS_IMETHODIMP
     531              32 : nsDOMEvent::PreventDefault()
     532                 : {
     533              32 :   if (!(mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL)) {
     534              32 :     mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT;
     535                 : 
     536                 :     // Need to set an extra flag for drag events.
     537              32 :     if (mEvent->eventStructType == NS_DRAG_EVENT &&
     538                 :         NS_IS_TRUSTED_EVENT(mEvent)) {
     539               0 :       nsCOMPtr<nsINode> node = do_QueryInterface(mEvent->currentTarget);
     540               0 :       if (!node) {
     541               0 :         nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(mEvent->currentTarget);
     542               0 :         if (win) {
     543               0 :           node = do_QueryInterface(win->GetExtantDocument());
     544                 :         }
     545                 :       }
     546               0 :       if (node && !nsContentUtils::IsChromeDoc(node->OwnerDoc())) {
     547               0 :         mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT_CALLED_IN_CONTENT;
     548                 :       }
     549                 :     }
     550                 :   }
     551                 : 
     552              32 :   return NS_OK;
     553                 : }
     554                 : 
     555                 : nsresult
     556           16367 : nsDOMEvent::SetEventType(const nsAString& aEventTypeArg)
     557                 : {
     558                 :   mEvent->userType =
     559                 :     nsContentUtils::GetEventIdAndAtom(aEventTypeArg, mEvent->eventStructType,
     560           16367 :                                       &(mEvent->message));
     561           16367 :   return NS_OK;
     562                 : }
     563                 : 
     564                 : NS_IMETHODIMP
     565           16367 : nsDOMEvent::InitEvent(const nsAString& aEventTypeArg, bool aCanBubbleArg, bool aCancelableArg)
     566                 : {
     567                 :   // Make sure this event isn't already being dispatched.
     568           16367 :   NS_ENSURE_TRUE(!NS_IS_EVENT_IN_DISPATCH(mEvent), NS_ERROR_INVALID_ARG);
     569                 : 
     570           16367 :   if (NS_IS_TRUSTED_EVENT(mEvent)) {
     571                 :     // Ensure the caller is permitted to dispatch trusted DOM events.
     572                 : 
     573            2263 :     bool enabled = false;
     574            2263 :     nsContentUtils::GetSecurityManager()->
     575            2263 :       IsCapabilityEnabled("UniversalXPConnect", &enabled);
     576                 : 
     577            2263 :     if (!enabled) {
     578               0 :       SetTrusted(false);
     579                 :     }
     580                 :   }
     581                 : 
     582           16367 :   NS_ENSURE_SUCCESS(SetEventType(aEventTypeArg), NS_ERROR_FAILURE);
     583                 : 
     584           16367 :   if (aCanBubbleArg) {
     585            2118 :     mEvent->flags &= ~NS_EVENT_FLAG_CANT_BUBBLE;
     586                 :   } else {
     587           14249 :     mEvent->flags |= NS_EVENT_FLAG_CANT_BUBBLE;
     588                 :   }
     589                 : 
     590           16367 :   if (aCancelableArg) {
     591            2108 :     mEvent->flags &= ~NS_EVENT_FLAG_CANT_CANCEL;
     592                 :   } else {
     593           14259 :     mEvent->flags |= NS_EVENT_FLAG_CANT_CANCEL;
     594                 :   }
     595                 : 
     596                 :   // Clearing the old targets, so that the event is targeted correctly when
     597                 :   // re-dispatching it.
     598           16367 :   mEvent->target = nsnull;
     599           16367 :   mEvent->originalTarget = nsnull;
     600           16367 :   mCachedType = aEventTypeArg;
     601           16367 :   return NS_OK;
     602                 : }
     603                 : 
     604              44 : NS_METHOD nsDOMEvent::DuplicatePrivateData()
     605                 : {
     606                 :   // FIXME! Simplify this method and make it somehow easily extendable,
     607                 :   //        Bug 329127
     608                 :   
     609              44 :   NS_ASSERTION(mEvent, "No nsEvent for nsDOMEvent duplication!");
     610              44 :   if (mEventIsInternal) {
     611               0 :     return NS_OK;
     612                 :   }
     613                 : 
     614              44 :   nsEvent* newEvent = nsnull;
     615              44 :   PRUint32 msg = mEvent->message;
     616              44 :   bool isInputEvent = false;
     617                 : 
     618              44 :   switch (mEvent->eventStructType) {
     619                 :     case NS_EVENT:
     620                 :     {
     621               0 :       newEvent = new nsEvent(false, msg);
     622               0 :       break;
     623                 :     }
     624                 :     case NS_GUI_EVENT:
     625                 :     {
     626                 :       // Not copying widget, it is a weak reference.
     627               0 :       newEvent = new nsGUIEvent(false, msg, nsnull);
     628               0 :       break;
     629                 :     }
     630                 :     case NS_SIZE_EVENT:
     631                 :     {
     632               0 :       nsSizeEvent* sizeEvent = new nsSizeEvent(false, msg, nsnull);
     633               0 :       NS_ENSURE_TRUE(sizeEvent, NS_ERROR_OUT_OF_MEMORY);
     634               0 :       sizeEvent->mWinWidth = static_cast<nsSizeEvent*>(mEvent)->mWinWidth;
     635               0 :       sizeEvent->mWinHeight = static_cast<nsSizeEvent*>(mEvent)->mWinHeight;
     636               0 :       newEvent = sizeEvent;
     637               0 :       break;
     638                 :     }
     639                 :     case NS_SIZEMODE_EVENT:
     640                 :     {
     641               0 :       newEvent = new nsSizeModeEvent(false, msg, nsnull);
     642               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     643                 :       static_cast<nsSizeModeEvent*>(newEvent)->mSizeMode =
     644               0 :         static_cast<nsSizeModeEvent*>(mEvent)->mSizeMode;
     645               0 :       break;
     646                 :     }
     647                 :     case NS_ZLEVEL_EVENT:
     648                 :     {
     649               0 :       nsZLevelEvent* zLevelEvent = new nsZLevelEvent(false, msg, nsnull);
     650               0 :       NS_ENSURE_TRUE(zLevelEvent, NS_ERROR_OUT_OF_MEMORY);
     651               0 :       nsZLevelEvent* oldZLevelEvent = static_cast<nsZLevelEvent*>(mEvent);
     652               0 :       zLevelEvent->mPlacement = oldZLevelEvent->mPlacement;
     653               0 :       zLevelEvent->mImmediate = oldZLevelEvent->mImmediate;
     654               0 :       zLevelEvent->mAdjusted = oldZLevelEvent->mAdjusted;
     655               0 :       newEvent = zLevelEvent;
     656               0 :       break;
     657                 :     }
     658                 :     case NS_SCROLLBAR_EVENT:
     659                 :     {
     660               0 :       newEvent = new nsScrollbarEvent(false, msg, nsnull);
     661               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     662                 :       static_cast<nsScrollbarEvent*>(newEvent)->position =
     663               0 :         static_cast<nsScrollbarEvent*>(mEvent)->position;
     664               0 :       break;
     665                 :     }
     666                 :     case NS_INPUT_EVENT:
     667                 :     {
     668               0 :       newEvent = new nsInputEvent(false, msg, nsnull);
     669               0 :       isInputEvent = true;
     670               0 :       break;
     671                 :     }
     672                 :     case NS_KEY_EVENT:
     673                 :     {
     674               0 :       nsKeyEvent* keyEvent = new nsKeyEvent(false, msg, nsnull);
     675               0 :       NS_ENSURE_TRUE(keyEvent, NS_ERROR_OUT_OF_MEMORY);
     676               0 :       nsKeyEvent* oldKeyEvent = static_cast<nsKeyEvent*>(mEvent);
     677               0 :       isInputEvent = true;
     678               0 :       keyEvent->keyCode = oldKeyEvent->keyCode;
     679               0 :       keyEvent->charCode = oldKeyEvent->charCode;
     680               0 :       keyEvent->isChar = oldKeyEvent->isChar;
     681               0 :       newEvent = keyEvent;
     682               0 :       break;
     683                 :     }
     684                 :     case NS_MOUSE_EVENT:
     685                 :     {
     686               0 :       nsMouseEvent* oldMouseEvent = static_cast<nsMouseEvent*>(mEvent);
     687                 :       nsMouseEvent* mouseEvent =
     688               0 :         new nsMouseEvent(false, msg, nsnull, oldMouseEvent->reason);
     689               0 :       NS_ENSURE_TRUE(mouseEvent, NS_ERROR_OUT_OF_MEMORY);
     690               0 :       isInputEvent = true;
     691               0 :       mouseEvent->clickCount = oldMouseEvent->clickCount;
     692               0 :       mouseEvent->acceptActivation = oldMouseEvent->acceptActivation;
     693               0 :       mouseEvent->context = oldMouseEvent->context;
     694               0 :       mouseEvent->relatedTarget = oldMouseEvent->relatedTarget;
     695               0 :       mouseEvent->button = oldMouseEvent->button;
     696               0 :       mouseEvent->pressure = oldMouseEvent->pressure;
     697               0 :       mouseEvent->inputSource = oldMouseEvent->inputSource;
     698               0 :       newEvent = mouseEvent;
     699               0 :       break;
     700                 :     }
     701                 :     case NS_DRAG_EVENT:
     702                 :     {
     703               0 :       nsDragEvent* oldDragEvent = static_cast<nsDragEvent*>(mEvent);
     704                 :       nsDragEvent* dragEvent =
     705               0 :         new nsDragEvent(false, msg, nsnull);
     706               0 :       NS_ENSURE_TRUE(dragEvent, NS_ERROR_OUT_OF_MEMORY);
     707               0 :       isInputEvent = true;
     708               0 :       dragEvent->dataTransfer = oldDragEvent->dataTransfer;
     709               0 :       dragEvent->clickCount = oldDragEvent->clickCount;
     710               0 :       dragEvent->acceptActivation = oldDragEvent->acceptActivation;
     711               0 :       dragEvent->relatedTarget = oldDragEvent->relatedTarget;
     712               0 :       dragEvent->button = oldDragEvent->button;
     713                 :       static_cast<nsMouseEvent*>(dragEvent)->inputSource =
     714               0 :         static_cast<nsMouseEvent*>(oldDragEvent)->inputSource;
     715               0 :       newEvent = dragEvent;
     716               0 :       break;
     717                 :     }
     718                 :     case NS_SCRIPT_ERROR_EVENT:
     719                 :     {
     720               0 :       newEvent = new nsScriptErrorEvent(false, msg);
     721               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     722                 :       static_cast<nsScriptErrorEvent*>(newEvent)->lineNr =
     723               0 :         static_cast<nsScriptErrorEvent*>(mEvent)->lineNr;
     724               0 :       break;
     725                 :     }
     726                 :     case NS_TEXT_EVENT:
     727                 :     {
     728               0 :       newEvent = new nsTextEvent(false, msg, nsnull);
     729               0 :       isInputEvent = true;
     730               0 :       break;
     731                 :     }
     732                 :     case NS_COMPOSITION_EVENT:
     733                 :     {
     734                 :       nsCompositionEvent* compositionEvent =
     735               0 :         new nsCompositionEvent(false, msg, nsnull);
     736                 :       nsCompositionEvent* oldCompositionEvent =
     737               0 :         static_cast<nsCompositionEvent*>(mEvent);
     738               0 :       compositionEvent->data = oldCompositionEvent->data;
     739               0 :       newEvent = compositionEvent;
     740               0 :       break;
     741                 :     }
     742                 :     case NS_MOUSE_SCROLL_EVENT:
     743                 :     {
     744                 :       nsMouseScrollEvent* mouseScrollEvent =
     745               0 :         new nsMouseScrollEvent(false, msg, nsnull);
     746               0 :       NS_ENSURE_TRUE(mouseScrollEvent, NS_ERROR_OUT_OF_MEMORY);
     747               0 :       isInputEvent = true;
     748                 :       nsMouseScrollEvent* oldMouseScrollEvent =
     749               0 :         static_cast<nsMouseScrollEvent*>(mEvent);
     750               0 :       mouseScrollEvent->scrollFlags = oldMouseScrollEvent->scrollFlags;
     751               0 :       mouseScrollEvent->delta = oldMouseScrollEvent->delta;
     752               0 :       mouseScrollEvent->relatedTarget = oldMouseScrollEvent->relatedTarget;
     753               0 :       mouseScrollEvent->button = oldMouseScrollEvent->button;
     754                 :       static_cast<nsMouseEvent_base*>(mouseScrollEvent)->inputSource =
     755               0 :         static_cast<nsMouseEvent_base*>(oldMouseScrollEvent)->inputSource;
     756               0 :       newEvent = mouseScrollEvent;
     757               0 :       break;
     758                 :     }
     759                 :     case NS_SCROLLPORT_EVENT:
     760                 :     {
     761               0 :       newEvent = new nsScrollPortEvent(false, msg, nsnull);
     762               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     763                 :       static_cast<nsScrollPortEvent*>(newEvent)->orient =
     764               0 :         static_cast<nsScrollPortEvent*>(mEvent)->orient;
     765               0 :       break;
     766                 :     }
     767                 :     case NS_SCROLLAREA_EVENT:
     768                 :     {
     769                 :       nsScrollAreaEvent *newScrollAreaEvent = 
     770               0 :         new nsScrollAreaEvent(false, msg, nsnull);
     771               0 :       NS_ENSURE_TRUE(newScrollAreaEvent, NS_ERROR_OUT_OF_MEMORY);
     772                 :       newScrollAreaEvent->mArea =
     773               0 :         static_cast<nsScrollAreaEvent *>(mEvent)->mArea;
     774               0 :       newEvent = newScrollAreaEvent;
     775               0 :       break;
     776                 :     }
     777                 :     case NS_MUTATION_EVENT:
     778                 :     {
     779              44 :       nsMutationEvent* mutationEvent = new nsMutationEvent(false, msg);
     780              44 :       NS_ENSURE_TRUE(mutationEvent, NS_ERROR_OUT_OF_MEMORY);
     781                 :       nsMutationEvent* oldMutationEvent =
     782              44 :         static_cast<nsMutationEvent*>(mEvent);
     783              44 :       mutationEvent->mRelatedNode = oldMutationEvent->mRelatedNode;
     784              44 :       mutationEvent->mAttrName = oldMutationEvent->mAttrName;
     785              44 :       mutationEvent->mPrevAttrValue = oldMutationEvent->mPrevAttrValue;
     786              44 :       mutationEvent->mNewAttrValue = oldMutationEvent->mNewAttrValue;
     787              44 :       mutationEvent->mAttrChange = oldMutationEvent->mAttrChange;
     788              44 :       newEvent = mutationEvent;
     789              44 :       break;
     790                 :     }
     791                 : #ifdef ACCESSIBILITY
     792                 :     case NS_ACCESSIBLE_EVENT:
     793                 :     {
     794               0 :       newEvent = new nsAccessibleEvent(false, msg, nsnull);
     795               0 :       isInputEvent = true;
     796               0 :       break;
     797                 :     }
     798                 : #endif
     799                 :     case NS_FORM_EVENT:
     800                 :     {
     801               0 :       newEvent = new nsFormEvent(false, msg);
     802               0 :       break;
     803                 :     }
     804                 :     case NS_FOCUS_EVENT:
     805                 :     {
     806               0 :       nsFocusEvent* newFocusEvent = new nsFocusEvent(false, msg);
     807               0 :       NS_ENSURE_TRUE(newFocusEvent, NS_ERROR_OUT_OF_MEMORY);
     808               0 :       nsFocusEvent* oldFocusEvent = static_cast<nsFocusEvent*>(mEvent);
     809               0 :       newFocusEvent->fromRaise = oldFocusEvent->fromRaise;
     810               0 :       newFocusEvent->isRefocus = oldFocusEvent->isRefocus;
     811               0 :       newEvent = newFocusEvent;
     812               0 :       break;
     813                 :     }
     814                 : 
     815                 :     case NS_POPUP_EVENT:
     816                 :     {
     817               0 :       newEvent = new nsInputEvent(false, msg, nsnull);
     818               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     819               0 :       isInputEvent = true;
     820               0 :       newEvent->eventStructType = NS_POPUP_EVENT;
     821               0 :       break;
     822                 :     }
     823                 :     case NS_COMMAND_EVENT:
     824                 :     {
     825                 :       newEvent = new nsCommandEvent(false, mEvent->userType,
     826               0 :         static_cast<nsCommandEvent*>(mEvent)->command, nsnull);
     827               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     828               0 :       break;
     829                 :     }
     830                 :     case NS_UI_EVENT:
     831                 :     {
     832                 :       newEvent = new nsUIEvent(false, msg,
     833               0 :                                static_cast<nsUIEvent*>(mEvent)->detail);
     834               0 :       break;
     835                 :     }
     836                 :     case NS_SVG_EVENT:
     837                 :     {
     838               0 :       newEvent = new nsEvent(false, msg);
     839               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     840               0 :       newEvent->eventStructType = NS_SVG_EVENT;
     841               0 :       break;
     842                 :     }
     843                 :     case NS_SVGZOOM_EVENT:
     844                 :     {
     845               0 :       newEvent = new nsGUIEvent(false, msg, nsnull);
     846               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     847               0 :       newEvent->eventStructType = NS_SVGZOOM_EVENT;
     848               0 :       break;
     849                 :     }
     850                 :     case NS_SMIL_TIME_EVENT:
     851                 :     {
     852               0 :       newEvent = new nsUIEvent(false, msg, 0);
     853               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     854               0 :       newEvent->eventStructType = NS_SMIL_TIME_EVENT;
     855               0 :       break;
     856                 :     }
     857                 :     case NS_SIMPLE_GESTURE_EVENT:
     858                 :     {
     859               0 :       nsSimpleGestureEvent* oldSimpleGestureEvent = static_cast<nsSimpleGestureEvent*>(mEvent);
     860                 :       nsSimpleGestureEvent* simpleGestureEvent = 
     861               0 :         new nsSimpleGestureEvent(false, msg, nsnull, 0, 0.0);
     862               0 :       NS_ENSURE_TRUE(simpleGestureEvent, NS_ERROR_OUT_OF_MEMORY);
     863               0 :       isInputEvent = true;
     864               0 :       simpleGestureEvent->direction = oldSimpleGestureEvent->direction;
     865               0 :       simpleGestureEvent->delta = oldSimpleGestureEvent->delta;
     866               0 :       newEvent = simpleGestureEvent;
     867               0 :       break;
     868                 :     }
     869                 :     case NS_TRANSITION_EVENT:
     870                 :     {
     871                 :       nsTransitionEvent* oldTransitionEvent =
     872               0 :         static_cast<nsTransitionEvent*>(mEvent);
     873                 :       newEvent = new nsTransitionEvent(false, msg,
     874                 :                                        oldTransitionEvent->propertyName,
     875               0 :                                        oldTransitionEvent->elapsedTime);
     876               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     877               0 :       break;
     878                 :     }
     879                 :     case NS_ANIMATION_EVENT:
     880                 :     {
     881                 :       nsAnimationEvent* oldAnimationEvent =
     882               0 :         static_cast<nsAnimationEvent*>(mEvent);
     883                 :       newEvent = new nsAnimationEvent(false, msg,
     884                 :                                       oldAnimationEvent->animationName,
     885               0 :                                       oldAnimationEvent->elapsedTime);
     886               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     887               0 :       break;
     888                 :     }
     889                 :     case NS_MOZTOUCH_EVENT:
     890                 :     {
     891                 :       newEvent = new nsMozTouchEvent(false, msg, nsnull,
     892               0 :                                      static_cast<nsMozTouchEvent*>(mEvent)->streamId);
     893               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     894               0 :       isInputEvent = true;
     895               0 :       break;
     896                 :     }
     897                 :     case NS_TOUCH_EVENT:
     898                 :     {
     899               0 :       newEvent = new nsTouchEvent(false, msg, nsnull);
     900               0 :       NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     901               0 :       isInputEvent = true;
     902               0 :       break;
     903                 :     }
     904                 :     default:
     905                 :     {
     906               0 :       NS_WARNING("Unknown event type!!!");
     907               0 :       return NS_ERROR_FAILURE;
     908                 :     }
     909                 :   }
     910                 : 
     911              44 :   NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
     912                 : 
     913              44 :   if (isInputEvent) {
     914               0 :     nsInputEvent* oldInputEvent = static_cast<nsInputEvent*>(mEvent);
     915               0 :     nsInputEvent* newInputEvent = static_cast<nsInputEvent*>(newEvent);
     916               0 :     newInputEvent->isShift = oldInputEvent->isShift;
     917               0 :     newInputEvent->isControl = oldInputEvent->isControl;
     918               0 :     newInputEvent->isAlt = oldInputEvent->isAlt;
     919               0 :     newInputEvent->isMeta = oldInputEvent->isMeta;
     920                 :   }
     921                 : 
     922              44 :   newEvent->target                 = mEvent->target;
     923              44 :   newEvent->currentTarget          = mEvent->currentTarget;
     924              44 :   newEvent->originalTarget         = mEvent->originalTarget;
     925              44 :   newEvent->flags                  = mEvent->flags;
     926              44 :   newEvent->time                   = mEvent->time;
     927              44 :   newEvent->refPoint               = mEvent->refPoint;
     928              44 :   newEvent->userType               = mEvent->userType;
     929                 : 
     930              44 :   mEvent = newEvent;
     931              44 :   mPresContext = nsnull;
     932              44 :   mEventIsInternal = true;
     933              44 :   mPrivateDataDuplicated = true;
     934                 : 
     935              44 :   return NS_OK;
     936                 : }
     937                 : 
     938            6401 : NS_METHOD nsDOMEvent::SetTarget(nsIDOMEventTarget* aTarget)
     939                 : {
     940                 : #ifdef DEBUG
     941                 :   {
     942           12802 :     nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aTarget);
     943                 : 
     944            6401 :     NS_ASSERTION(!win || !win->IsInnerWindow(),
     945                 :                  "Uh, inner window set as event target!");
     946                 :   }
     947                 : #endif
     948                 : 
     949            6401 :   mEvent->target = do_QueryInterface(aTarget);
     950            6401 :   return NS_OK;
     951                 : }
     952                 : 
     953                 : NS_IMETHODIMP_(bool)
     954               0 : nsDOMEvent::IsDispatchStopped()
     955                 : {
     956               0 :   return !!(mEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH);
     957                 : }
     958                 : 
     959                 : NS_IMETHODIMP_(nsEvent*)
     960           34893 : nsDOMEvent::GetInternalNSEvent()
     961                 : {
     962           34893 :   return mEvent;
     963                 : }
     964                 : 
     965                 : // return true if eventName is contained within events, delimited by
     966                 : // spaces
     967                 : static bool
     968               0 : PopupAllowedForEvent(const char *eventName)
     969                 : {
     970               0 :   if (!sPopupAllowedEvents) {
     971               0 :     nsDOMEvent::PopupAllowedEventsChanged();
     972                 : 
     973               0 :     if (!sPopupAllowedEvents) {
     974               0 :       return false;
     975                 :     }
     976                 :   }
     977                 : 
     978               0 :   nsDependentCString events(sPopupAllowedEvents);
     979                 : 
     980               0 :   nsAFlatCString::const_iterator start, end;
     981               0 :   nsAFlatCString::const_iterator startiter(events.BeginReading(start));
     982               0 :   events.EndReading(end);
     983                 : 
     984               0 :   while (startiter != end) {
     985               0 :     nsAFlatCString::const_iterator enditer(end);
     986                 : 
     987               0 :     if (!FindInReadable(nsDependentCString(eventName), startiter, enditer))
     988               0 :       return false;
     989                 : 
     990                 :     // the match is surrounded by spaces, or at a string boundary
     991               0 :     if ((startiter == start || *--startiter == ' ') &&
     992               0 :         (enditer == end || *enditer == ' ')) {
     993               0 :       return true;
     994                 :     }
     995                 : 
     996                 :     // Move on and see if there are other matches. (The delimitation
     997                 :     // requirement makes it pointless to begin the next search before
     998                 :     // the end of the invalid match just found.)
     999               0 :     startiter = enditer;
    1000                 :   }
    1001                 : 
    1002               0 :   return false;
    1003                 : }
    1004                 : 
    1005                 : // static
    1006                 : PopupControlState
    1007            8232 : nsDOMEvent::GetEventPopupControlState(nsEvent *aEvent)
    1008                 : {
    1009                 :   // generally if an event handler is running, new windows are disallowed.
    1010                 :   // check for exceptions:
    1011            8232 :   PopupControlState abuse = openAbused;
    1012                 : 
    1013            8232 :   switch(aEvent->eventStructType) {
    1014                 :   case NS_EVENT :
    1015                 :     // For these following events only allow popups if they're
    1016                 :     // triggered while handling user input. See
    1017                 :     // nsPresShell::HandleEventInternal() for details.
    1018            8226 :     if (nsEventStateManager::IsHandlingUserInput()) {
    1019               0 :       switch(aEvent->message) {
    1020                 :       case NS_FORM_SELECTED :
    1021               0 :         if (::PopupAllowedForEvent("select"))
    1022               0 :           abuse = openControlled;
    1023               0 :         break;
    1024                 :       case NS_FORM_CHANGE :
    1025               0 :         if (::PopupAllowedForEvent("change"))
    1026               0 :           abuse = openControlled;
    1027               0 :         break;
    1028                 :       }
    1029                 :     }
    1030            8226 :     break;
    1031                 :   case NS_GUI_EVENT :
    1032                 :     // For this following event only allow popups if it's triggered
    1033                 :     // while handling user input. See
    1034                 :     // nsPresShell::HandleEventInternal() for details.
    1035               0 :     if (nsEventStateManager::IsHandlingUserInput()) {
    1036               0 :       switch(aEvent->message) {
    1037                 :       case NS_FORM_INPUT :
    1038               0 :         if (::PopupAllowedForEvent("input"))
    1039               0 :           abuse = openControlled;
    1040               0 :         break;
    1041                 :       }
    1042                 :     }
    1043               0 :     break;
    1044                 :   case NS_INPUT_EVENT :
    1045                 :     // For this following event only allow popups if it's triggered
    1046                 :     // while handling user input. See
    1047                 :     // nsPresShell::HandleEventInternal() for details.
    1048               0 :     if (nsEventStateManager::IsHandlingUserInput()) {
    1049               0 :       switch(aEvent->message) {
    1050                 :       case NS_FORM_CHANGE :
    1051               0 :         if (::PopupAllowedForEvent("change"))
    1052               0 :           abuse = openControlled;
    1053               0 :         break;
    1054                 :       case NS_XUL_COMMAND:
    1055               0 :         abuse = openControlled;
    1056               0 :         break;
    1057                 :       }
    1058                 :     }
    1059               0 :     break;
    1060                 :   case NS_KEY_EVENT :
    1061               0 :     if (NS_IS_TRUSTED_EVENT(aEvent)) {
    1062               0 :       PRUint32 key = static_cast<nsKeyEvent *>(aEvent)->keyCode;
    1063               0 :       switch(aEvent->message) {
    1064                 :       case NS_KEY_PRESS :
    1065                 :         // return key on focused button. see note at NS_MOUSE_CLICK.
    1066               0 :         if (key == nsIDOMKeyEvent::DOM_VK_RETURN)
    1067               0 :           abuse = openAllowed;
    1068               0 :         else if (::PopupAllowedForEvent("keypress"))
    1069               0 :           abuse = openControlled;
    1070               0 :         break;
    1071                 :       case NS_KEY_UP :
    1072                 :         // space key on focused button. see note at NS_MOUSE_CLICK.
    1073               0 :         if (key == nsIDOMKeyEvent::DOM_VK_SPACE)
    1074               0 :           abuse = openAllowed;
    1075               0 :         else if (::PopupAllowedForEvent("keyup"))
    1076               0 :           abuse = openControlled;
    1077               0 :         break;
    1078                 :       case NS_KEY_DOWN :
    1079               0 :         if (::PopupAllowedForEvent("keydown"))
    1080               0 :           abuse = openControlled;
    1081               0 :         break;
    1082                 :       }
    1083                 :     }
    1084               0 :     break;
    1085                 :   case NS_MOUSE_EVENT :
    1086               0 :     if (NS_IS_TRUSTED_EVENT(aEvent) &&
    1087                 :         static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) {
    1088               0 :       switch(aEvent->message) {
    1089                 :       case NS_MOUSE_BUTTON_UP :
    1090               0 :         if (::PopupAllowedForEvent("mouseup"))
    1091               0 :           abuse = openControlled;
    1092               0 :         break;
    1093                 :       case NS_MOUSE_BUTTON_DOWN :
    1094               0 :         if (::PopupAllowedForEvent("mousedown"))
    1095               0 :           abuse = openControlled;
    1096               0 :         break;
    1097                 :       case NS_MOUSE_CLICK :
    1098                 :         /* Click events get special treatment because of their
    1099                 :            historical status as a more legitimate event handler. If
    1100                 :            click popups are enabled in the prefs, clear the popup
    1101                 :            status completely. */
    1102               0 :         if (::PopupAllowedForEvent("click"))
    1103               0 :           abuse = openAllowed;
    1104               0 :         break;
    1105                 :       case NS_MOUSE_DOUBLECLICK :
    1106               0 :         if (::PopupAllowedForEvent("dblclick"))
    1107               0 :           abuse = openControlled;
    1108               0 :         break;
    1109                 :       }
    1110                 :     }
    1111               0 :     break;
    1112                 :   case NS_SCRIPT_ERROR_EVENT :
    1113               0 :     switch(aEvent->message) {
    1114                 :     case NS_LOAD_ERROR :
    1115                 :       // Any error event will allow popups, if enabled in the pref.
    1116               0 :       if (::PopupAllowedForEvent("error"))
    1117               0 :         abuse = openControlled;
    1118               0 :       break;
    1119                 :     }
    1120               0 :     break;
    1121                 :   case NS_FORM_EVENT :
    1122                 :     // For these following events only allow popups if they're
    1123                 :     // triggered while handling user input. See
    1124                 :     // nsPresShell::HandleEventInternal() for details.
    1125               0 :     if (nsEventStateManager::IsHandlingUserInput()) {
    1126               0 :       switch(aEvent->message) {
    1127                 :       case NS_FORM_SUBMIT :
    1128               0 :         if (::PopupAllowedForEvent("submit"))
    1129               0 :           abuse = openControlled;
    1130               0 :         break;
    1131                 :       case NS_FORM_RESET :
    1132               0 :         if (::PopupAllowedForEvent("reset"))
    1133               0 :           abuse = openControlled;
    1134               0 :         break;
    1135                 :       }
    1136                 :     }
    1137               0 :     break;
    1138                 :   }
    1139                 : 
    1140            8232 :   return abuse;
    1141                 : }
    1142                 : 
    1143                 : // static
    1144                 : void
    1145               0 : nsDOMEvent::PopupAllowedEventsChanged()
    1146                 : {
    1147               0 :   if (sPopupAllowedEvents) {
    1148               0 :     nsMemory::Free(sPopupAllowedEvents);
    1149                 :   }
    1150                 : 
    1151               0 :   nsAdoptingCString str = Preferences::GetCString("dom.popup_allowed_events");
    1152                 : 
    1153                 :   // We'll want to do this even if str is empty to avoid looking up
    1154                 :   // this pref all the time if it's not set.
    1155               0 :   sPopupAllowedEvents = ToNewCString(str);
    1156               0 : }
    1157                 : 
    1158                 : // static
    1159                 : void
    1160            1403 : nsDOMEvent::Shutdown()
    1161                 : {
    1162            1403 :   if (sPopupAllowedEvents) {
    1163               0 :     nsMemory::Free(sPopupAllowedEvents);
    1164                 :   }
    1165            1403 : }
    1166                 : 
    1167                 : nsIntPoint
    1168               0 : nsDOMEvent::GetScreenCoords(nsPresContext* aPresContext,
    1169                 :                             nsEvent* aEvent,
    1170                 :                             nsIntPoint aPoint)
    1171                 : {
    1172               0 :   if (!aEvent || 
    1173                 :        (aEvent->eventStructType != NS_MOUSE_EVENT &&
    1174                 :         aEvent->eventStructType != NS_POPUP_EVENT &&
    1175                 :         aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
    1176                 :         aEvent->eventStructType != NS_MOZTOUCH_EVENT &&
    1177                 :         aEvent->eventStructType != NS_TOUCH_EVENT &&
    1178                 :         aEvent->eventStructType != NS_DRAG_EVENT &&
    1179                 :         aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT)) {
    1180               0 :     return nsIntPoint(0, 0);
    1181                 :   }
    1182                 : 
    1183               0 :   nsGUIEvent* guiEvent = static_cast<nsGUIEvent*>(aEvent);
    1184               0 :   if (!guiEvent->widget) {
    1185               0 :     return aPoint;
    1186                 :   }
    1187                 : 
    1188               0 :   nsIntPoint offset = aPoint + guiEvent->widget->WidgetToScreenOffset();
    1189               0 :   nscoord factor = aPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel();
    1190                 :   return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
    1191               0 :                     nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));
    1192                 : }
    1193                 : 
    1194                 : //static
    1195                 : nsIntPoint
    1196               0 : nsDOMEvent::GetPageCoords(nsPresContext* aPresContext,
    1197                 :                           nsEvent* aEvent,
    1198                 :                           nsIntPoint aPoint,
    1199                 :                           nsIntPoint aDefaultPoint)
    1200                 : {
    1201                 :   nsIntPoint pagePoint = nsDOMEvent::GetClientCoords(aPresContext,
    1202                 :                                                      aEvent,
    1203                 :                                                      aPoint,
    1204               0 :                                                      aDefaultPoint);
    1205                 : 
    1206                 :   // If there is some scrolling, add scroll info to client point.
    1207               0 :   if (aPresContext && aPresContext->GetPresShell()) {
    1208               0 :     nsIPresShell* shell = aPresContext->GetPresShell();
    1209               0 :     nsIScrollableFrame* scrollframe = shell->GetRootScrollFrameAsScrollable();
    1210               0 :     if (scrollframe) {
    1211               0 :       nsPoint pt = scrollframe->GetScrollPosition();
    1212                 :       pagePoint += nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
    1213               0 :                               nsPresContext::AppUnitsToIntCSSPixels(pt.y));
    1214                 :     }
    1215                 :   }
    1216                 : 
    1217                 :   return pagePoint;
    1218                 : }
    1219                 : 
    1220                 : // static
    1221                 : nsIntPoint
    1222               0 : nsDOMEvent::GetClientCoords(nsPresContext* aPresContext,
    1223                 :                             nsEvent* aEvent,
    1224                 :                             nsIntPoint aPoint,
    1225                 :                             nsIntPoint aDefaultPoint)
    1226                 : {
    1227               0 :   if (!aEvent ||
    1228                 :       (aEvent->eventStructType != NS_MOUSE_EVENT &&
    1229                 :        aEvent->eventStructType != NS_POPUP_EVENT &&
    1230                 :        aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
    1231                 :        aEvent->eventStructType != NS_MOZTOUCH_EVENT &&
    1232                 :        aEvent->eventStructType != NS_TOUCH_EVENT &&
    1233                 :        aEvent->eventStructType != NS_DRAG_EVENT &&
    1234                 :        aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT) ||
    1235                 :       !aPresContext ||
    1236               0 :       !((nsGUIEvent*)aEvent)->widget) {
    1237               0 :     return aDefaultPoint;
    1238                 :   }
    1239                 : 
    1240               0 :   nsPoint pt(0, 0);
    1241               0 :   nsIPresShell* shell = aPresContext->GetPresShell();
    1242               0 :   if (!shell) {
    1243               0 :     return nsIntPoint(0, 0);
    1244                 :   }
    1245               0 :   nsIFrame* rootFrame = shell->GetRootFrame();
    1246               0 :   if (rootFrame)
    1247               0 :     pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, aPoint, rootFrame);
    1248                 : 
    1249                 :   return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
    1250               0 :                     nsPresContext::AppUnitsToIntCSSPixels(pt.y));
    1251                 : }
    1252                 : 
    1253                 : // To be called ONLY by nsDOMEvent::GetType (which has the additional
    1254                 : // logic for handling user-defined events).
    1255                 : // static
    1256               0 : const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
    1257                 : {
    1258               0 :   switch(aEventType) {
    1259                 :   case NS_MOUSE_BUTTON_DOWN:
    1260               0 :     return sEventNames[eDOMEvents_mousedown];
    1261                 :   case NS_MOUSE_BUTTON_UP:
    1262               0 :     return sEventNames[eDOMEvents_mouseup];
    1263                 :   case NS_MOUSE_CLICK:
    1264               0 :     return sEventNames[eDOMEvents_click];
    1265                 :   case NS_MOUSE_DOUBLECLICK:
    1266               0 :     return sEventNames[eDOMEvents_dblclick];
    1267                 :   case NS_MOUSEENTER:
    1268               0 :     return sEventNames[eDOMEvents_mouseenter];
    1269                 :   case NS_MOUSELEAVE:
    1270               0 :     return sEventNames[eDOMEvents_mouseleave];
    1271                 :   case NS_MOUSE_ENTER_SYNTH:
    1272               0 :     return sEventNames[eDOMEvents_mouseover];
    1273                 :   case NS_MOUSE_EXIT_SYNTH:
    1274               0 :     return sEventNames[eDOMEvents_mouseout];
    1275                 :   case NS_MOUSE_MOZHITTEST:
    1276               0 :     return sEventNames[eDOMEvents_MozMouseHittest];
    1277                 :   case NS_MOUSE_MOVE:
    1278               0 :     return sEventNames[eDOMEvents_mousemove];
    1279                 :   case NS_KEY_UP:
    1280               0 :     return sEventNames[eDOMEvents_keyup];
    1281                 :   case NS_KEY_DOWN:
    1282               0 :     return sEventNames[eDOMEvents_keydown];
    1283                 :   case NS_KEY_PRESS:
    1284               0 :     return sEventNames[eDOMEvents_keypress];
    1285                 :   case NS_COMPOSITION_START:
    1286               0 :     return sEventNames[eDOMEvents_compositionstart];
    1287                 :   case NS_COMPOSITION_UPDATE:
    1288               0 :     return sEventNames[eDOMEvents_compositionupdate];
    1289                 :   case NS_COMPOSITION_END:
    1290               0 :     return sEventNames[eDOMEvents_compositionend];
    1291                 :   case NS_FOCUS_CONTENT:
    1292               0 :     return sEventNames[eDOMEvents_focus];
    1293                 :   case NS_BLUR_CONTENT:
    1294               0 :     return sEventNames[eDOMEvents_blur];
    1295                 :   case NS_XUL_CLOSE:
    1296               0 :     return sEventNames[eDOMEvents_close];
    1297                 :   case NS_LOAD:
    1298               0 :     return sEventNames[eDOMEvents_load];
    1299                 :   case NS_POPSTATE:
    1300               0 :     return sEventNames[eDOMEvents_popstate];
    1301                 :   case NS_BEFORE_SCRIPT_EXECUTE:
    1302               0 :     return sEventNames[eDOMEvents_beforescriptexecute];
    1303                 :   case NS_AFTER_SCRIPT_EXECUTE:
    1304               0 :     return sEventNames[eDOMEvents_afterscriptexecute];
    1305                 :   case NS_BEFORE_PAGE_UNLOAD:
    1306               0 :     return sEventNames[eDOMEvents_beforeunload];
    1307                 :   case NS_PAGE_UNLOAD:
    1308               0 :     return sEventNames[eDOMEvents_unload];
    1309                 :   case NS_HASHCHANGE:
    1310               0 :     return sEventNames[eDOMEvents_hashchange];
    1311                 :   case NS_READYSTATECHANGE:
    1312               0 :     return sEventNames[eDOMEvents_readystatechange];
    1313                 :   case NS_IMAGE_ABORT:
    1314               0 :     return sEventNames[eDOMEvents_abort];
    1315                 :   case NS_LOAD_ERROR:
    1316               0 :     return sEventNames[eDOMEvents_error];
    1317                 :   case NS_FORM_SUBMIT:
    1318               0 :     return sEventNames[eDOMEvents_submit];
    1319                 :   case NS_FORM_RESET:
    1320               0 :     return sEventNames[eDOMEvents_reset];
    1321                 :   case NS_FORM_CHANGE:
    1322               0 :     return sEventNames[eDOMEvents_change];
    1323                 :   case NS_FORM_SELECTED:
    1324               0 :     return sEventNames[eDOMEvents_select];
    1325                 :   case NS_FORM_INPUT:
    1326               0 :     return sEventNames[eDOMEvents_input];
    1327                 :   case NS_FORM_INVALID:
    1328               0 :     return sEventNames[eDOMEvents_invalid];
    1329                 :   case NS_RESIZE_EVENT:
    1330               0 :     return sEventNames[eDOMEvents_resize];
    1331                 :   case NS_SCROLL_EVENT:
    1332               0 :     return sEventNames[eDOMEvents_scroll];
    1333                 :   case NS_TEXT_TEXT:
    1334               0 :     return sEventNames[eDOMEvents_text];
    1335                 :   case NS_XUL_POPUP_SHOWING:
    1336               0 :     return sEventNames[eDOMEvents_popupShowing];
    1337                 :   case NS_XUL_POPUP_SHOWN:
    1338               0 :     return sEventNames[eDOMEvents_popupShown];
    1339                 :   case NS_XUL_POPUP_HIDING:
    1340               0 :     return sEventNames[eDOMEvents_popupHiding];
    1341                 :   case NS_XUL_POPUP_HIDDEN:
    1342               0 :     return sEventNames[eDOMEvents_popupHidden];
    1343                 :   case NS_XUL_COMMAND:
    1344               0 :     return sEventNames[eDOMEvents_command];
    1345                 :   case NS_XUL_BROADCAST:
    1346               0 :     return sEventNames[eDOMEvents_broadcast];
    1347                 :   case NS_XUL_COMMAND_UPDATE:
    1348               0 :     return sEventNames[eDOMEvents_commandupdate];
    1349                 :   case NS_DRAGDROP_ENTER:
    1350               0 :     return sEventNames[eDOMEvents_dragenter];
    1351                 :   case NS_DRAGDROP_OVER_SYNTH:
    1352               0 :     return sEventNames[eDOMEvents_dragover];
    1353                 :   case NS_DRAGDROP_EXIT_SYNTH:
    1354               0 :     return sEventNames[eDOMEvents_dragexit];
    1355                 :   case NS_DRAGDROP_DRAGDROP:
    1356               0 :     return sEventNames[eDOMEvents_dragdrop];
    1357                 :   case NS_DRAGDROP_GESTURE:
    1358               0 :     return sEventNames[eDOMEvents_draggesture];
    1359                 :   case NS_DRAGDROP_DRAG:
    1360               0 :     return sEventNames[eDOMEvents_drag];
    1361                 :   case NS_DRAGDROP_END:
    1362               0 :     return sEventNames[eDOMEvents_dragend];
    1363                 :   case NS_DRAGDROP_START:
    1364               0 :     return sEventNames[eDOMEvents_dragstart];
    1365                 :   case NS_DRAGDROP_LEAVE_SYNTH:
    1366               0 :     return sEventNames[eDOMEvents_dragleave];
    1367                 :   case NS_DRAGDROP_DROP:
    1368               0 :     return sEventNames[eDOMEvents_drop];
    1369                 :   case NS_SCROLLPORT_OVERFLOW:
    1370               0 :     return sEventNames[eDOMEvents_overflow];
    1371                 :   case NS_SCROLLPORT_UNDERFLOW:
    1372               0 :     return sEventNames[eDOMEvents_underflow];
    1373                 :   case NS_SCROLLPORT_OVERFLOWCHANGED:
    1374               0 :     return sEventNames[eDOMEvents_overflowchanged];
    1375                 :   case NS_MUTATION_SUBTREEMODIFIED:
    1376               0 :     return sEventNames[eDOMEvents_subtreemodified];
    1377                 :   case NS_MUTATION_NODEINSERTED:
    1378               0 :     return sEventNames[eDOMEvents_nodeinserted];
    1379                 :   case NS_MUTATION_NODEREMOVED:
    1380               0 :     return sEventNames[eDOMEvents_noderemoved];
    1381                 :   case NS_MUTATION_NODEREMOVEDFROMDOCUMENT:
    1382               0 :     return sEventNames[eDOMEvents_noderemovedfromdocument];
    1383                 :   case NS_MUTATION_NODEINSERTEDINTODOCUMENT:
    1384               0 :     return sEventNames[eDOMEvents_nodeinsertedintodocument];
    1385                 :   case NS_MUTATION_ATTRMODIFIED:
    1386               0 :     return sEventNames[eDOMEvents_attrmodified];
    1387                 :   case NS_MUTATION_CHARACTERDATAMODIFIED:
    1388               0 :     return sEventNames[eDOMEvents_characterdatamodified];
    1389                 :   case NS_CONTEXTMENU:
    1390               0 :     return sEventNames[eDOMEvents_contextmenu];
    1391                 :   case NS_UI_ACTIVATE:
    1392               0 :     return sEventNames[eDOMEvents_DOMActivate];
    1393                 :   case NS_UI_FOCUSIN:
    1394               0 :     return sEventNames[eDOMEvents_DOMFocusIn];
    1395                 :   case NS_UI_FOCUSOUT:
    1396               0 :     return sEventNames[eDOMEvents_DOMFocusOut];
    1397                 :   case NS_PAGE_SHOW:
    1398               0 :     return sEventNames[eDOMEvents_pageshow];
    1399                 :   case NS_PAGE_HIDE:
    1400               0 :     return sEventNames[eDOMEvents_pagehide];
    1401                 :   case NS_MOUSE_SCROLL:
    1402               0 :     return sEventNames[eDOMEvents_DOMMouseScroll];
    1403                 :   case NS_MOUSE_PIXEL_SCROLL:
    1404               0 :     return sEventNames[eDOMEvents_MozMousePixelScroll];
    1405                 :   case NS_OFFLINE:
    1406               0 :     return sEventNames[eDOMEvents_offline];
    1407                 :   case NS_ONLINE:
    1408               0 :     return sEventNames[eDOMEvents_online];
    1409                 :   case NS_COPY:
    1410               0 :     return sEventNames[eDOMEvents_copy];
    1411                 :   case NS_CUT:
    1412               0 :     return sEventNames[eDOMEvents_cut];
    1413                 :   case NS_PASTE:
    1414               0 :     return sEventNames[eDOMEvents_paste];
    1415                 :   case NS_OPEN:
    1416               0 :     return sEventNames[eDOMEvents_open];
    1417                 :   case NS_MESSAGE:
    1418               0 :     return sEventNames[eDOMEvents_message];
    1419                 :   case NS_SHOW_EVENT:
    1420               0 :     return sEventNames[eDOMEvents_show];
    1421                 :   case NS_SVG_LOAD:
    1422               0 :     return sEventNames[eDOMEvents_SVGLoad];
    1423                 :   case NS_SVG_UNLOAD:
    1424               0 :     return sEventNames[eDOMEvents_SVGUnload];
    1425                 :   case NS_SVG_ABORT:
    1426               0 :     return sEventNames[eDOMEvents_SVGAbort];
    1427                 :   case NS_SVG_ERROR:
    1428               0 :     return sEventNames[eDOMEvents_SVGError];
    1429                 :   case NS_SVG_RESIZE:
    1430               0 :     return sEventNames[eDOMEvents_SVGResize];
    1431                 :   case NS_SVG_SCROLL:
    1432               0 :     return sEventNames[eDOMEvents_SVGScroll];
    1433                 :   case NS_SVG_ZOOM:
    1434               0 :     return sEventNames[eDOMEvents_SVGZoom];
    1435                 :   case NS_TOUCH_START:
    1436               0 :     return sEventNames[eDOMEvents_touchstart];
    1437                 :   case NS_TOUCH_MOVE:
    1438               0 :     return sEventNames[eDOMEvents_touchmove];
    1439                 :   case NS_TOUCH_END:
    1440               0 :     return sEventNames[eDOMEvents_touchend];
    1441                 :   case NS_TOUCH_ENTER:
    1442               0 :     return sEventNames[eDOMEvents_touchenter];
    1443                 :   case NS_TOUCH_LEAVE:
    1444               0 :     return sEventNames[eDOMEvents_touchleave];
    1445                 :   case NS_TOUCH_CANCEL:
    1446               0 :     return sEventNames[eDOMEvents_touchcancel];
    1447                 :   case NS_SMIL_BEGIN:
    1448               0 :     return sEventNames[eDOMEvents_beginEvent];
    1449                 :   case NS_SMIL_END:
    1450               0 :     return sEventNames[eDOMEvents_endEvent];
    1451                 :   case NS_SMIL_REPEAT:
    1452               0 :     return sEventNames[eDOMEvents_repeatEvent];
    1453                 : #ifdef MOZ_MEDIA
    1454                 :   case NS_LOADSTART:
    1455               0 :     return sEventNames[eDOMEvents_loadstart];
    1456                 :   case NS_PROGRESS:
    1457               0 :     return sEventNames[eDOMEvents_progress];
    1458                 :   case NS_SUSPEND:
    1459               0 :     return sEventNames[eDOMEvents_suspend];
    1460                 :   case NS_EMPTIED:
    1461               0 :     return sEventNames[eDOMEvents_emptied];
    1462                 :   case NS_STALLED:
    1463               0 :     return sEventNames[eDOMEvents_stalled];
    1464                 :   case NS_PLAY:
    1465               0 :     return sEventNames[eDOMEvents_play];
    1466                 :   case NS_PAUSE:
    1467               0 :     return sEventNames[eDOMEvents_pause];
    1468                 :   case NS_LOADEDMETADATA:
    1469               0 :     return sEventNames[eDOMEvents_loadedmetadata];
    1470                 :   case NS_LOADEDDATA:
    1471               0 :     return sEventNames[eDOMEvents_loadeddata];
    1472                 :   case NS_WAITING:
    1473               0 :     return sEventNames[eDOMEvents_waiting];
    1474                 :   case NS_PLAYING:
    1475               0 :     return sEventNames[eDOMEvents_playing];
    1476                 :   case NS_CANPLAY:
    1477               0 :     return sEventNames[eDOMEvents_canplay];
    1478                 :   case NS_CANPLAYTHROUGH:
    1479               0 :     return sEventNames[eDOMEvents_canplaythrough];
    1480                 :   case NS_SEEKING:
    1481               0 :     return sEventNames[eDOMEvents_seeking];
    1482                 :   case NS_SEEKED:
    1483               0 :     return sEventNames[eDOMEvents_seeked];
    1484                 :   case NS_TIMEUPDATE:
    1485               0 :     return sEventNames[eDOMEvents_timeupdate];
    1486                 :   case NS_ENDED:
    1487               0 :     return sEventNames[eDOMEvents_ended];
    1488                 :   case NS_RATECHANGE:
    1489               0 :     return sEventNames[eDOMEvents_ratechange];
    1490                 :   case NS_DURATIONCHANGE:
    1491               0 :     return sEventNames[eDOMEvents_durationchange];
    1492                 :   case NS_VOLUMECHANGE:
    1493               0 :     return sEventNames[eDOMEvents_volumechange];
    1494                 :   case NS_MOZAUDIOAVAILABLE:
    1495               0 :     return sEventNames[eDOMEvents_mozaudioavailable];
    1496                 : #endif
    1497                 :   case NS_AFTERPAINT:
    1498               0 :     return sEventNames[eDOMEvents_afterpaint];
    1499                 :   case NS_BEFORERESIZE_EVENT:
    1500               0 :     return sEventNames[eDOMEvents_beforeresize];
    1501                 :   case NS_SIMPLE_GESTURE_SWIPE:
    1502               0 :     return sEventNames[eDOMEvents_MozSwipeGesture];
    1503                 :   case NS_SIMPLE_GESTURE_MAGNIFY_START:
    1504               0 :     return sEventNames[eDOMEvents_MozMagnifyGestureStart];
    1505                 :   case NS_SIMPLE_GESTURE_MAGNIFY_UPDATE:
    1506               0 :     return sEventNames[eDOMEvents_MozMagnifyGestureUpdate];
    1507                 :   case NS_SIMPLE_GESTURE_MAGNIFY:
    1508               0 :     return sEventNames[eDOMEvents_MozMagnifyGesture];
    1509                 :   case NS_SIMPLE_GESTURE_ROTATE_START:
    1510               0 :     return sEventNames[eDOMEvents_MozRotateGestureStart];
    1511                 :   case NS_SIMPLE_GESTURE_ROTATE_UPDATE:
    1512               0 :     return sEventNames[eDOMEvents_MozRotateGestureUpdate];
    1513                 :   case NS_SIMPLE_GESTURE_ROTATE:
    1514               0 :     return sEventNames[eDOMEvents_MozRotateGesture];
    1515                 :   case NS_SIMPLE_GESTURE_TAP:
    1516               0 :     return sEventNames[eDOMEvents_MozTapGesture];
    1517                 :   case NS_SIMPLE_GESTURE_PRESSTAP:
    1518               0 :     return sEventNames[eDOMEvents_MozPressTapGesture];
    1519                 :   case NS_MOZTOUCH_DOWN:
    1520               0 :     return sEventNames[eDOMEvents_MozTouchDown];
    1521                 :   case NS_MOZTOUCH_MOVE:
    1522               0 :     return sEventNames[eDOMEvents_MozTouchMove];
    1523                 :   case NS_MOZTOUCH_UP:
    1524               0 :     return sEventNames[eDOMEvents_MozTouchUp];
    1525                 :   case NS_SCROLLEDAREACHANGED:
    1526               0 :     return sEventNames[eDOMEvents_MozScrolledAreaChanged];
    1527                 :   case NS_TRANSITION_END:
    1528               0 :     return sEventNames[eDOMEvents_transitionend];
    1529                 :   case NS_ANIMATION_START:
    1530               0 :     return sEventNames[eDOMEvents_animationstart];
    1531                 :   case NS_ANIMATION_END:
    1532               0 :     return sEventNames[eDOMEvents_animationend];
    1533                 :   case NS_ANIMATION_ITERATION:
    1534               0 :     return sEventNames[eDOMEvents_animationiteration];
    1535                 :   case NS_DEVICE_MOTION:
    1536               0 :     return sEventNames[eDOMEvents_devicemotion];
    1537                 :   case NS_DEVICE_ORIENTATION:
    1538               0 :     return sEventNames[eDOMEvents_deviceorientation];
    1539                 :   case NS_FULLSCREENCHANGE:
    1540               0 :     return sEventNames[eDOMEvents_mozfullscreenchange];
    1541                 :   case NS_FULLSCREENERROR:
    1542               0 :     return sEventNames[eDOMEvents_mozfullscreenerror];
    1543                 :   default:
    1544                 :     break;
    1545                 :   }
    1546                 :   // XXXldb We can hit this case for nsEvent objects that we didn't
    1547                 :   // create and that are not user defined events since this function and
    1548                 :   // SetEventType are incomplete.  (But fixing that requires fixing the
    1549                 :   // arrays in nsEventListenerManager too, since the events for which
    1550                 :   // this is a problem generally *are* created by nsDOMEvent.)
    1551               0 :   return nsnull;
    1552                 : }
    1553                 : 
    1554                 : NS_IMETHODIMP
    1555               0 : nsDOMEvent::GetPreventDefault(bool* aReturn)
    1556                 : {
    1557               0 :   NS_ENSURE_ARG_POINTER(aReturn);
    1558               0 :   *aReturn = mEvent && (mEvent->flags & NS_EVENT_FLAG_NO_DEFAULT);
    1559               0 :   return NS_OK;
    1560                 : }
    1561                 : 
    1562                 : NS_IMETHODIMP
    1563               0 : nsDOMEvent::GetDefaultPrevented(bool* aReturn)
    1564                 : {
    1565               0 :   return GetPreventDefault(aReturn);
    1566                 : }
    1567                 : 
    1568                 : void
    1569               0 : nsDOMEvent::Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType)
    1570                 : {
    1571               0 :   if (aSerializeInterfaceType) {
    1572               0 :     IPC::WriteParam(aMsg, NS_LITERAL_STRING("event"));
    1573                 :   }
    1574                 : 
    1575               0 :   nsString type;
    1576               0 :   GetType(type);
    1577               0 :   IPC::WriteParam(aMsg, type);
    1578                 : 
    1579               0 :   bool bubbles = false;
    1580               0 :   GetBubbles(&bubbles);
    1581               0 :   IPC::WriteParam(aMsg, bubbles);
    1582                 : 
    1583               0 :   bool cancelable = false;
    1584               0 :   GetCancelable(&cancelable);
    1585               0 :   IPC::WriteParam(aMsg, cancelable);
    1586                 : 
    1587               0 :   bool trusted = false;
    1588               0 :   GetIsTrusted(&trusted);
    1589               0 :   IPC::WriteParam(aMsg, trusted);
    1590                 : 
    1591                 :   // No timestamp serialization for now!
    1592               0 : }
    1593                 : 
    1594                 : bool
    1595               0 : nsDOMEvent::Deserialize(const IPC::Message* aMsg, void** aIter)
    1596                 : {
    1597               0 :   nsString type;
    1598               0 :   NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &type), false);
    1599                 : 
    1600               0 :   bool bubbles = false;
    1601               0 :   NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &bubbles), false);
    1602                 : 
    1603               0 :   bool cancelable = false;
    1604               0 :   NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &cancelable), false);
    1605                 : 
    1606               0 :   bool trusted = false;
    1607               0 :   NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &trusted), false);
    1608                 : 
    1609               0 :   nsresult rv = InitEvent(type, bubbles, cancelable);
    1610               0 :   NS_ENSURE_SUCCESS(rv, false);
    1611               0 :   SetTrusted(trusted);
    1612                 : 
    1613               0 :   return true;
    1614                 : }
    1615                 : 
    1616                 : 
    1617            9216 : nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult,
    1618                 :                         nsPresContext* aPresContext,
    1619                 :                         nsEvent *aEvent) 
    1620                 : {
    1621            9216 :   nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent);
    1622            9216 :   if (nsnull == it) {
    1623               0 :     return NS_ERROR_OUT_OF_MEMORY;
    1624                 :   }
    1625                 : 
    1626            9216 :   return CallQueryInterface(it, aInstancePtrResult);
    1627            4392 : }

Generated by: LCOV version 1.7