Bug 895274 part.75 Rename NS_DRAGDROP_EVENT_START to eDragDropEventFirst, define eDragDropEventLast and correct the type and name of event message in DataTransfer r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 02 Sep 2015 15:08:01 +0900
changeset 289876 38c50d1c496bcb1d3436ea34cfe7863a8e0004de
parent 289875 be746a34f096038983737ea2f143bfc7daec1004
child 289877 76a8bd3c6ea34a2eccadf4a47d0eb6818e66aecc
push id5046
push useratolfsen@mozilla.com
push dateWed, 02 Sep 2015 13:10:30 +0000
reviewerssmaug
bugs895274
milestone43.0a1
Bug 895274 part.75 Rename NS_DRAGDROP_EVENT_START to eDragDropEventFirst, define eDragDropEventLast and correct the type and name of event message in DataTransfer r=smaug
dom/events/DataTransfer.cpp
dom/events/DataTransfer.h
widget/EventMessageList.h
--- a/dom/events/DataTransfer.cpp
+++ b/dom/events/DataTransfer.cpp
@@ -63,83 +63,84 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDataTransfer)
 NS_INTERFACE_MAP_END
 
 // the size of the array
 const char DataTransfer::sEffects[8][9] = {
   "none", "copy", "move", "copyMove", "link", "copyLink", "linkMove", "all"
 };
 
-DataTransfer::DataTransfer(nsISupports* aParent, uint32_t aEventType,
+DataTransfer::DataTransfer(nsISupports* aParent, EventMessage aEventMessage,
                            bool aIsExternal, int32_t aClipboardType)
-  : mParent(aParent),
-    mEventType(aEventType),
-    mDropEffect(nsIDragService::DRAGDROP_ACTION_NONE),
-    mEffectAllowed(nsIDragService::DRAGDROP_ACTION_UNINITIALIZED),
-    mCursorState(false),
-    mReadOnly(true),
-    mIsExternal(aIsExternal),
-    mUserCancelled(false),
-    mIsCrossDomainSubFrameDrop(false),
-    mClipboardType(aClipboardType),
-    mDragImageX(0),
-    mDragImageY(0)
+  : mParent(aParent)
+  , mDropEffect(nsIDragService::DRAGDROP_ACTION_NONE)
+  , mEffectAllowed(nsIDragService::DRAGDROP_ACTION_UNINITIALIZED)
+  , mEventMessage(aEventMessage)
+  , mCursorState(false)
+  , mReadOnly(true)
+  , mIsExternal(aIsExternal)
+  , mUserCancelled(false)
+  , mIsCrossDomainSubFrameDrop(false)
+  , mClipboardType(aClipboardType)
+  , mDragImageX(0)
+  , mDragImageY(0)
 {
   // For these events, we want to be able to add data to the data transfer, so
   // clear the readonly state. Otherwise, the data is already present. For
   // external usage, cache the data from the native clipboard or drag.
-  if (aEventType == NS_CUT ||
-      aEventType == NS_COPY ||
-      aEventType == NS_DRAGDROP_START ||
-      aEventType == NS_DRAGDROP_GESTURE) {
+  if (aEventMessage == NS_CUT ||
+      aEventMessage == NS_COPY ||
+      aEventMessage == NS_DRAGDROP_START ||
+      aEventMessage == NS_DRAGDROP_GESTURE) {
     mReadOnly = false;
   } else if (mIsExternal) {
-    if (aEventType == NS_PASTE) {
+    if (aEventMessage == NS_PASTE) {
       CacheExternalClipboardFormats();
-    } else if (aEventType >= NS_DRAGDROP_EVENT_START && aEventType <= NS_DRAGDROP_LEAVE) {
+    } else if (aEventMessage >= eDragDropEventFirst &&
+               aEventMessage <= eDragDropEventLast) {
       CacheExternalDragFormats();
     }
   }
 }
 
 DataTransfer::DataTransfer(nsISupports* aParent,
-                           uint32_t aEventType,
+                           EventMessage aEventMessage,
                            const uint32_t aEffectAllowed,
                            bool aCursorState,
                            bool aIsExternal,
                            bool aUserCancelled,
                            bool aIsCrossDomainSubFrameDrop,
                            int32_t aClipboardType,
                            nsTArray<nsTArray<TransferItem> >& aItems,
                            Element* aDragImage,
                            uint32_t aDragImageX,
                            uint32_t aDragImageY)
-  : mParent(aParent),
-    mEventType(aEventType),
-    mDropEffect(nsIDragService::DRAGDROP_ACTION_NONE),
-    mEffectAllowed(aEffectAllowed),
-    mCursorState(aCursorState),
-    mReadOnly(true),
-    mIsExternal(aIsExternal),
-    mUserCancelled(aUserCancelled),
-    mIsCrossDomainSubFrameDrop(aIsCrossDomainSubFrameDrop),
-    mClipboardType(aClipboardType),
-    mItems(aItems),
-    mDragImage(aDragImage),
-    mDragImageX(aDragImageX),
-    mDragImageY(aDragImageY)
+  : mParent(aParent)
+  , mDropEffect(nsIDragService::DRAGDROP_ACTION_NONE)
+  , mEffectAllowed(aEffectAllowed)
+  , mEventMessage(aEventMessage)
+  , mCursorState(aCursorState)
+  , mReadOnly(true)
+  , mIsExternal(aIsExternal)
+  , mUserCancelled(aUserCancelled)
+  , mIsCrossDomainSubFrameDrop(aIsCrossDomainSubFrameDrop)
+  , mClipboardType(aClipboardType)
+  , mItems(aItems)
+  , mDragImage(aDragImage)
+  , mDragImageX(aDragImageX)
+  , mDragImageY(aDragImageY)
 {
   MOZ_ASSERT(mParent);
   // The items are copied from aItems into mItems. There is no need to copy
   // the actual data in the items as the data transfer will be read only. The
   // draggesture and dragstart events are the only times when items are
   // modifiable, but those events should have been using the first constructor
   // above.
-  NS_ASSERTION(aEventType != NS_DRAGDROP_GESTURE &&
-               aEventType != NS_DRAGDROP_START,
+  NS_ASSERTION(aEventMessage != NS_DRAGDROP_GESTURE &&
+               aEventMessage != NS_DRAGDROP_START,
                "invalid event type for DataTransfer constructor");
 }
 
 DataTransfer::~DataTransfer()
 {}
 
 // static
 already_AddRefed<DataTransfer>
@@ -263,18 +264,19 @@ DataTransfer::GetMozUserCancelled(bool* 
 {
   *aUserCancelled = MozUserCancelled();
   return NS_OK;
 }
 
 FileList*
 DataTransfer::GetFiles(ErrorResult& aRv)
 {
-  if (mEventType != NS_DRAGDROP_DROP && mEventType != NS_DRAGDROP_DRAGDROP &&
-      mEventType != NS_PASTE) {
+  if (mEventMessage != NS_DRAGDROP_DROP &&
+      mEventMessage != NS_DRAGDROP_DRAGDROP &&
+      mEventMessage != NS_PASTE) {
     return nullptr;
   }
 
   if (!mFiles) {
     mFiles = new FileList(static_cast<nsIDOMDataTransfer*>(this));
 
     uint32_t count = mItems.Length();
 
@@ -536,17 +538,18 @@ DataTransfer::GetMozSourceNode(nsIDOMNod
   return CallQueryInterface(sourceNode, aSourceNode);
 }
 
 already_AddRefed<DOMStringList>
 DataTransfer::MozTypesAt(uint32_t aIndex, ErrorResult& aRv)
 {
   // Only the first item is valid for clipboard events
   if (aIndex > 0 &&
-      (mEventType == NS_CUT || mEventType == NS_COPY || mEventType == NS_PASTE)) {
+      (mEventMessage == NS_CUT || mEventMessage == NS_COPY ||
+       mEventMessage == NS_PASTE)) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return nullptr;
   }
 
   nsRefPtr<DOMStringList> types = new DOMStringList();
   if (aIndex < mItems.Length()) {
     // note that you can retrieve the types regardless of their principal
     nsTArray<TransferItem>& item = mItems[aIndex];
@@ -576,17 +579,18 @@ DataTransfer::MozGetDataAt(const nsAStri
     return NS_OK;
 
   if (aIndex >= mItems.Length()) {
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   // Only the first item is valid for clipboard events
   if (aIndex > 0 &&
-      (mEventType == NS_CUT || mEventType == NS_COPY || mEventType == NS_PASTE)) {
+      (mEventMessage == NS_CUT || mEventMessage == NS_COPY ||
+       mEventMessage == NS_PASTE)) {
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
 
   nsAutoString format;
   GetRealFormat(aFormat, format);
 
   nsTArray<TransferItem>& item = mItems[aIndex];
@@ -594,18 +598,19 @@ DataTransfer::MozGetDataAt(const nsAStri
   // Check if the caller is allowed to access the drag data. Callers with
   // chrome privileges can always read the data. During the
   // drop event, allow retrieving the data except in the case where the
   // source of the drag is in a child frame of the caller. In that case,
   // we only allow access to data of the same principal. During other events,
   // only allow access to the data with the same principal.
   nsIPrincipal* principal = nullptr;
   if (mIsCrossDomainSubFrameDrop ||
-      (mEventType != NS_DRAGDROP_DROP && mEventType != NS_DRAGDROP_DRAGDROP &&
-       mEventType != NS_PASTE &&
+      (mEventMessage != NS_DRAGDROP_DROP &&
+       mEventMessage != NS_DRAGDROP_DRAGDROP &&
+       mEventMessage != NS_PASTE &&
        !nsContentUtils::IsCallerChrome())) {
     principal = nsContentUtils::SubjectPrincipal();
   }
 
   uint32_t count = item.Length();
   for (uint32_t i = 0; i < count; i++) {
     TransferItem& formatitem = item[i];
     if (formatitem.mFormat.Equals(format)) {
@@ -687,17 +692,18 @@ DataTransfer::MozSetDataAt(const nsAStri
   // Specifying an index less than the current length will replace an existing
   // item. Specifying an index equal to the current length will add a new item.
   if (aIndex > mItems.Length()) {
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   // Only the first item is valid for clipboard events
   if (aIndex > 0 &&
-      (mEventType == NS_CUT || mEventType == NS_COPY || mEventType == NS_PASTE)) {
+      (mEventMessage == NS_CUT || mEventMessage == NS_COPY ||
+       mEventMessage == NS_PASTE)) {
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   // don't allow non-chrome to add file data
   // XXX perhaps this should also limit any non-string type as well
   if ((aFormat.EqualsLiteral("application/x-moz-file-promise") ||
        aFormat.EqualsLiteral("application/x-moz-file")) &&
        !nsContentUtils::IsCallerChrome()) {
@@ -732,33 +738,34 @@ DataTransfer::MozClearDataAt(const nsASt
 
   if (aIndex >= mItems.Length()) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return;
   }
 
   // Only the first item is valid for clipboard events
   if (aIndex > 0 &&
-      (mEventType == NS_CUT || mEventType == NS_COPY || mEventType == NS_PASTE)) {
+      (mEventMessage == NS_CUT || mEventMessage == NS_COPY ||
+       mEventMessage == NS_PASTE)) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return;
   }
 
   MozClearDataAtHelper(aFormat, aIndex, aRv);
 }
 
 void
 DataTransfer::MozClearDataAtHelper(const nsAString& aFormat, uint32_t aIndex,
                                    ErrorResult& aRv)
 {
   MOZ_ASSERT(!mReadOnly);
   MOZ_ASSERT(aIndex < mItems.Length());
   MOZ_ASSERT(aIndex == 0 ||
-             (mEventType != NS_CUT && mEventType != NS_COPY &&
-              mEventType != NS_PASTE));
+             (mEventMessage != NS_CUT && mEventMessage != NS_COPY &&
+              mEventMessage != NS_PASTE));
 
   nsAutoString format;
   GetRealFormat(aFormat, format);
 
   nsIPrincipal* principal = nsContentUtils::SubjectPrincipal();
 
   // if the format is empty, clear all formats
   bool clearall = format.IsEmpty();
@@ -933,22 +940,22 @@ DataTransfer::AddElement(nsIDOMElement* 
   NS_ENSURE_TRUE(element, NS_ERROR_INVALID_ARG);
 
   ErrorResult rv;
   AddElement(*element, rv);
   return rv.StealNSResult();
 }
 
 nsresult
-DataTransfer::Clone(nsISupports* aParent, uint32_t aEventType,
+DataTransfer::Clone(nsISupports* aParent, EventMessage aEventMessage,
                     bool aUserCancelled, bool aIsCrossDomainSubFrameDrop,
                     DataTransfer** aNewDataTransfer)
 {
   DataTransfer* newDataTransfer =
-    new DataTransfer(aParent, aEventType, mEffectAllowed, mCursorState,
+    new DataTransfer(aParent, aEventMessage, mEffectAllowed, mCursorState,
                      mIsExternal, aUserCancelled, aIsCrossDomainSubFrameDrop,
                      mClipboardType, mItems, mDragImage, mDragImageX,
                      mDragImageY);
 
   *aNewDataTransfer = newDataTransfer;
   NS_ADDREF(*aNewDataTransfer);
   return NS_OK;
 }
@@ -1247,17 +1254,18 @@ DataTransfer::CacheExternalDragFormats()
       }
     }
   }
 }
 
 void
 DataTransfer::CacheExternalClipboardFormats()
 {
-  NS_ASSERTION(mEventType == NS_PASTE, "caching clipboard data for invalid event");
+  NS_ASSERTION(mEventMessage == NS_PASTE,
+               "caching clipboard data for invalid event");
 
   // Called during the constructor for paste events to cache the formats
   // available on the clipboard. As with CacheExternalDragFormats, the
   // data will only be retrieved when needed.
 
   nsCOMPtr<nsIClipboard> clipboard = do_GetService("@mozilla.org/widget/clipboard;1");
   if (!clipboard || mClipboardType < 0) {
     return;
@@ -1288,17 +1296,17 @@ DataTransfer::FillInExternalData(Transfe
 {
   NS_PRECONDITION(mIsExternal, "Not an external data transfer");
 
   if (aItem.mData) {
     return;
   }
 
   // only drag and paste events should be calling FillInExternalData
-  NS_ASSERTION(mEventType != NS_CUT && mEventType != NS_COPY,
+  NS_ASSERTION(mEventMessage != NS_CUT && mEventMessage != NS_COPY,
                "clipboard event with empty data");
 
     NS_ConvertUTF16toUTF8 utf8format(aItem.mFormat);
     const char* format = utf8format.get();
     if (strcmp(format, "text/plain") == 0)
       format = kUnicodeMime;
     else if (strcmp(format, "text/uri-list") == 0)
       format = kURLDataMime;
@@ -1306,17 +1314,17 @@ DataTransfer::FillInExternalData(Transfe
     nsCOMPtr<nsITransferable> trans =
       do_CreateInstance("@mozilla.org/widget/transferable;1");
     if (!trans)
       return;
 
   trans->Init(nullptr);
   trans->AddDataFlavor(format);
 
-  if (mEventType == NS_PASTE) {
+  if (mEventMessage == NS_PASTE) {
     MOZ_ASSERT(aIndex == 0, "index in clipboard must be 0");
 
     nsCOMPtr<nsIClipboard> clipboard = do_GetService("@mozilla.org/widget/clipboard;1");
     if (!clipboard || mClipboardType < 0) {
       return;
     }
 
     clipboard->GetData(trans, mClipboardType);
--- a/dom/events/DataTransfer.h
+++ b/dom/events/DataTransfer.h
@@ -13,16 +13,17 @@
 #include "nsIPrincipal.h"
 #include "nsIDOMDataTransfer.h"
 #include "nsIDOMElement.h"
 #include "nsIDragService.h"
 #include "nsCycleCollectionParticipant.h"
 
 #include "nsAutoPtr.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/EventForwards.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/Promise.h"
 
 class nsINode;
 class nsITransferable;
 class nsISupportsArray;
 class nsILoadContext;
 
@@ -70,17 +71,17 @@ public:
 protected:
 
   // hide the default constructor
   DataTransfer();
 
   // this constructor is used only by the Clone method to copy the fields as
   // needed to a new data transfer.
   DataTransfer(nsISupports* aParent,
-               uint32_t aEventType,
+               EventMessage aEventMessage,
                const uint32_t aEffectAllowed,
                bool aCursorState,
                bool aIsExternal,
                bool aUserCancelled,
                bool aIsCrossDomainSubFrameDrop,
                int32_t aClipboardType,
                nsTArray<nsTArray<TransferItem> >& aItems,
                Element* aDragImage,
@@ -90,27 +91,25 @@ protected:
   ~DataTransfer();
 
   static const char sEffects[8][9];
 
 public:
 
   // Constructor for DataTransfer.
   //
-  // aEventType is an event constant (such as NS_DRAGDROP_START)
-  //
   // aIsExternal must only be true when used to create a dataTransfer for a
   // paste or a drag that was started without using a data transfer. The
   // latter will occur when an external drag occurs, that is, a drag where the
   // source is another application, or a drag is started by calling the drag
   // service directly. For clipboard operations, aClipboardType indicates
   // which clipboard to use, from nsIClipboard, or -1 for non-clipboard operations,
   // or if access to the system clipboard should not be allowed.
-  DataTransfer(nsISupports* aParent, uint32_t aEventType, bool aIsExternal,
-               int32_t aClipboardType);
+  DataTransfer(nsISupports* aParent, EventMessage aEventMessage,
+               bool aIsExternal, int32_t aClipboardType);
 
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
   nsISupports* GetParentObject()
   {
     return mParent;
   }
 
   void SetParentObject(nsISupports* aNewParent)
@@ -217,18 +216,19 @@ public:
   // returns a weak reference to the drag image
   Element* GetDragImage(int32_t* aX, int32_t* aY)
   {
     *aX = mDragImageX;
     *aY = mDragImageY;
     return mDragImage;
   }
 
-  nsresult Clone(nsISupports* aParent, uint32_t aEventType, bool aUserCancelled,
-                 bool aIsCrossDomainSubFrameDrop, DataTransfer** aResult);
+  nsresult Clone(nsISupports* aParent, EventMessage aEventMessage,
+                 bool aUserCancelled, bool aIsCrossDomainSubFrameDrop,
+                 DataTransfer** aResult);
 
 protected:
 
   // converts some formats used for compatibility in aInFormat into aOutFormat.
   // Text and text/unicode become text/plain, and URL becomes text/uri-list
   void GetRealFormat(const nsAString& aInFormat, nsAString& aOutFormat);
 
   // caches text and uri-list data formats that exist in the drag service or
@@ -249,24 +249,25 @@ protected:
   friend class ContentParent;
   void FillAllExternalData();
 
   void MozClearDataAtHelper(const nsAString& aFormat, uint32_t aIndex,
                             mozilla::ErrorResult& aRv);
 
   nsCOMPtr<nsISupports> mParent;
 
-  // the event type this data transfer is for. This will correspond to an
-  // event->mMessage value.
-  uint32_t mEventType;
 
   // the drop effect and effect allowed
   uint32_t mDropEffect;
   uint32_t mEffectAllowed;
 
+  // the event message this data transfer is for. This will correspond to an
+  // event->mMessage value.
+  EventMessage mEventMessage;
+
   // Indicates the behavior of the cursor during drag operations
   bool mCursorState;
 
   // readonly data transfers may not be modified except the drop effect and
   // effect allowed.
   bool mReadOnly;
 
   // true for drags started without a data transfer, for example, those from
--- a/widget/EventMessageList.h
+++ b/widget/EventMessageList.h
@@ -96,27 +96,28 @@ NS_EVENT_MESSAGE(eFormChange,           
 NS_EVENT_MESSAGE(eFormSelect,           eFormEventFirst + 3)
 NS_EVENT_MESSAGE(eFormInvalid,          eFormEventFirst + 4)
 
 //Need separate focus/blur notifications for non-native widgets
 NS_EVENT_MESSAGE(eFocusEventFirst,      1300)
 NS_EVENT_MESSAGE(eFocus,                eFocusEventFirst)
 NS_EVENT_MESSAGE(eBlur,                 eFocusEventFirst + 1)
 
-NS_EVENT_MESSAGE(NS_DRAGDROP_EVENT_START, 1400)
-NS_EVENT_MESSAGE(NS_DRAGDROP_ENTER,     NS_DRAGDROP_EVENT_START)
-NS_EVENT_MESSAGE(NS_DRAGDROP_OVER,      NS_DRAGDROP_EVENT_START + 1)
-NS_EVENT_MESSAGE(NS_DRAGDROP_EXIT,      NS_DRAGDROP_EVENT_START + 2)
-NS_EVENT_MESSAGE(NS_DRAGDROP_DRAGDROP,  NS_DRAGDROP_EVENT_START + 3)
-NS_EVENT_MESSAGE(NS_DRAGDROP_GESTURE,   NS_DRAGDROP_EVENT_START + 4)
-NS_EVENT_MESSAGE(NS_DRAGDROP_DRAG,      NS_DRAGDROP_EVENT_START + 5)
-NS_EVENT_MESSAGE(NS_DRAGDROP_END,       NS_DRAGDROP_EVENT_START + 6)
-NS_EVENT_MESSAGE(NS_DRAGDROP_START,     NS_DRAGDROP_EVENT_START + 7)
-NS_EVENT_MESSAGE(NS_DRAGDROP_DROP,      NS_DRAGDROP_EVENT_START + 8)
-NS_EVENT_MESSAGE(NS_DRAGDROP_LEAVE,     NS_DRAGDROP_EVENT_START + 9)
+NS_EVENT_MESSAGE(eDragDropEventFirst,   1400)
+NS_EVENT_MESSAGE(NS_DRAGDROP_ENTER,     eDragDropEventFirst)
+NS_EVENT_MESSAGE(NS_DRAGDROP_OVER,      eDragDropEventFirst + 1)
+NS_EVENT_MESSAGE(NS_DRAGDROP_EXIT,      eDragDropEventFirst + 2)
+NS_EVENT_MESSAGE(NS_DRAGDROP_DRAGDROP,  eDragDropEventFirst + 3)
+NS_EVENT_MESSAGE(NS_DRAGDROP_GESTURE,   eDragDropEventFirst + 4)
+NS_EVENT_MESSAGE(NS_DRAGDROP_DRAG,      eDragDropEventFirst + 5)
+NS_EVENT_MESSAGE(NS_DRAGDROP_END,       eDragDropEventFirst + 6)
+NS_EVENT_MESSAGE(NS_DRAGDROP_START,     eDragDropEventFirst + 7)
+NS_EVENT_MESSAGE(NS_DRAGDROP_DROP,      eDragDropEventFirst + 8)
+NS_EVENT_MESSAGE(NS_DRAGDROP_LEAVE,     eDragDropEventFirst + 9)
+NS_EVENT_MESSAGE(eDragDropEventLast,    NS_DRAGDROP_LEAVE)
 
 // Events for popups
 NS_EVENT_MESSAGE(NS_XUL_EVENT_START,    1500)
 NS_EVENT_MESSAGE(NS_XUL_POPUP_SHOWING,  NS_XUL_EVENT_START)
 NS_EVENT_MESSAGE(NS_XUL_POPUP_SHOWN,    NS_XUL_EVENT_START + 1)
 NS_EVENT_MESSAGE(NS_XUL_POPUP_HIDING,   NS_XUL_EVENT_START + 2)
 NS_EVENT_MESSAGE(NS_XUL_POPUP_HIDDEN,   NS_XUL_EVENT_START + 3)
 // NS_XUL_COMMAND used to be here       (NS_XUL_EVENT_START + 4)