Bug 912956 part.7 Create mozilla/ContentEvents.h r=roc
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 24 Sep 2013 19:04:15 +0900
changeset 148784 e4e2588531d623d5ae73018293e5a65295f0cc37
parent 148783 93a96f509d9a1a3cada77f275c6e317e903813cc
child 148785 ab54eba99d340c18571fb34b43b4940b1ceab85f
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersroc
bugs912956
milestone27.0a1
Bug 912956 part.7 Create mozilla/ContentEvents.h r=roc
widget/BasicEvents.h
widget/ContentEvents.h
widget/EventForwards.h
widget/moz.build
widget/nsGUIEvent.h
--- a/widget/BasicEvents.h
+++ b/widget/BasicEvents.h
@@ -42,35 +42,33 @@ enum nsEventStructType
   NS_MOUSE_SCROLL_EVENT,             // WidgetMouseScrollEvent
   NS_WHEEL_EVENT,                    // WidgetWheelEvent
 
   // TouchEvents.h
   NS_GESTURENOTIFY_EVENT,            // WidgetGestureNotifyEvent
   NS_SIMPLE_GESTURE_EVENT,           // WidgetSimpleGestureEvent
   NS_TOUCH_EVENT,                    // WidgetTouchEvent
 
-  // Scroll related events
-  NS_SCROLLPORT_EVENT,               // nsScrollPortEvent
-  NS_SCROLLAREA_EVENT,               // nsScrollAreaEvent
+  // ContentEvents.h
+  NS_SCRIPT_ERROR_EVENT,             // InternalScriptErrorEvent
+  NS_SCROLLPORT_EVENT,               // InternalScrollPortEvent
+  NS_SCROLLAREA_EVENT,               // InternalScrollAreaEvent
+  NS_FORM_EVENT,                     // InternalFormEvent
+  NS_FOCUS_EVENT,                    // InternalFocusEvent
+  NS_CLIPBOARD_EVENT,                // InternalClipboardEvent
+  NS_TRANSITION_EVENT,               // InternalTransitionEvent
+  NS_ANIMATION_EVENT,                // InternalAnimationEvent
 
   // DOM events
-  NS_SCRIPT_ERROR_EVENT,             // nsScriptErrorEvent
   NS_MUTATION_EVENT,                 // nsMutationEvent
-  NS_FORM_EVENT,                     // nsFormEvent
-  NS_FOCUS_EVENT,                    // nsFocusEvent
-  NS_CLIPBOARD_EVENT,                // nsClipboardEvent
 
   // SVG events
   NS_SVGZOOM_EVENT,                  // GUIEvent
   NS_SMIL_TIME_EVENT,                // UIEvent
 
-  // CSS events
-  NS_TRANSITION_EVENT,               // nsTransitionEvent
-  NS_ANIMATION_EVENT,                // nsAnimationEvent
-
   // Command events
   NS_COMMAND_EVENT,                  // nsCommandEvent
   NS_CONTENT_COMMAND_EVENT,          // nsContentCommandEvent
 
   // Plugin event
   NS_PLUGIN_EVENT                    // nsPluginEvent
 };
 
@@ -869,16 +867,24 @@ public:
 /******************************************************************************
  * mozilla::InternalUIEvent
  *
  * XXX Why this inherits WidgetGUIEvent rather than WidgetEvent?
  ******************************************************************************/
 
 class InternalUIEvent : public WidgetGUIEvent
 {
+protected:
+  InternalUIEvent(bool aIsTrusted, uint32_t aMessage,
+                  nsEventStructType aStructType, int32_t aDetail) :
+    WidgetGUIEvent(aIsTrusted, aMessage, nullptr, aStructType),
+    detail(aDetail)
+  {
+  }
+
 public:
   InternalUIEvent(bool aIsTrusted, uint32_t aMessage, int32_t aDetail) :
     WidgetGUIEvent(aIsTrusted, aMessage, nullptr, NS_UI_EVENT),
     detail(aDetail)
   {
   }
 
   int32_t detail;
new file mode 100644
--- /dev/null
+++ b/widget/ContentEvents.h
@@ -0,0 +1,260 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_ContentEvents_h__
+#define mozilla_ContentEvents_h__
+
+#include <stdint.h>
+
+#include "mozilla/BasicEvents.h"
+#include "mozilla/dom/EventTarget.h"
+#include "nsCOMPtr.h"
+#include "nsIDOMDataTransfer.h"
+#include "nsRect.h"
+#include "nsStringGlue.h"
+
+class nsIContent;
+
+namespace mozilla {
+
+/******************************************************************************
+ * mozilla::InternalScriptErrorEvent
+ ******************************************************************************/
+
+class InternalScriptErrorEvent : public WidgetEvent
+{
+public:
+  InternalScriptErrorEvent(bool aIsTrusted, uint32_t aMessage) :
+    WidgetEvent(aIsTrusted, aMessage, NS_SCRIPT_ERROR_EVENT),
+    lineNr(0), errorMsg(nullptr), fileName(nullptr)
+  {
+  }
+
+  int32_t           lineNr;
+  const PRUnichar*  errorMsg;
+  const PRUnichar*  fileName;
+
+  // XXX Not tested by test_assign_event_data.html
+  void AssignScriptErrorEventData(const InternalScriptErrorEvent& aEvent,
+                                  bool aCopyTargets)
+  {
+    AssignEventData(aEvent, aCopyTargets);
+
+    lineNr = aEvent.lineNr;
+
+    // We don't copy errorMsg and fileName.  If it's necessary, perhaps, this
+    // should duplicate the characters and free them at destructing.
+    errorMsg = nullptr;
+    fileName = nullptr;
+  }
+};
+
+/******************************************************************************
+ * mozilla::InternalScrollPortEvent
+ ******************************************************************************/
+
+class InternalScrollPortEvent : public WidgetGUIEvent
+{
+public:
+  enum orientType
+  {
+    vertical   = 0,
+    horizontal = 1,
+    both       = 2
+  };
+
+  InternalScrollPortEvent(bool aIsTrusted, uint32_t aMessage,
+                          nsIWidget* aWidget) :
+    WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLPORT_EVENT),
+    orient(vertical)
+  {
+  }
+
+  orientType orient;
+
+  void AssignScrollPortEventData(const InternalScrollPortEvent& aEvent,
+                                 bool aCopyTargets)
+  {
+    AssignGUIEventData(aEvent, aCopyTargets);
+
+    orient = aEvent.orient;
+  }
+};
+
+/******************************************************************************
+ * mozilla::InternalScrollPortEvent
+ ******************************************************************************/
+
+class InternalScrollAreaEvent : public WidgetGUIEvent
+{
+public:
+  InternalScrollAreaEvent(bool aIsTrusted, uint32_t aMessage,
+                          nsIWidget* aWidget) :
+    WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLAREA_EVENT)
+  {
+  }
+
+  nsRect mArea;
+
+  void AssignScrollAreaEventData(const InternalScrollAreaEvent& aEvent,
+                                 bool aCopyTargets)
+  {
+    AssignGUIEventData(aEvent, aCopyTargets);
+
+    mArea = aEvent.mArea;
+  }
+};
+
+/******************************************************************************
+ * mozilla::InternalFormEvent
+ *
+ * We hold the originating form control for form submit and reset events.
+ * originator is a weak pointer (does not hold a strong reference).
+ ******************************************************************************/
+
+class InternalFormEvent : public WidgetEvent
+{
+public:
+  InternalFormEvent(bool aIsTrusted, uint32_t aMessage) :
+    WidgetEvent(aIsTrusted, aMessage, NS_FORM_EVENT),
+    originator(nullptr)
+  {
+  }
+
+  nsIContent *originator;
+
+  void AssignFormEventData(const InternalFormEvent& aEvent, bool aCopyTargets)
+  {
+    AssignEventData(aEvent, aCopyTargets);
+
+    // Don't copy originator due to a weak pointer.
+  }
+};
+
+/******************************************************************************
+ * mozilla::InternalClipboardEvent
+ ******************************************************************************/
+
+class InternalClipboardEvent : public WidgetEvent
+{
+public:
+  InternalClipboardEvent(bool aIsTrusted, uint32_t aMessage) :
+    WidgetEvent(aIsTrusted, aMessage, NS_CLIPBOARD_EVENT)
+  {
+  }
+
+  nsCOMPtr<nsIDOMDataTransfer> clipboardData;
+
+  void AssignClipboardEventData(const InternalClipboardEvent& aEvent,
+                                bool aCopyTargets)
+  {
+    AssignEventData(aEvent, aCopyTargets);
+
+    clipboardData = aEvent.clipboardData;
+  }
+};
+
+/******************************************************************************
+ * mozilla::InternalFocusEvent
+ ******************************************************************************/
+
+class InternalFocusEvent : public InternalUIEvent
+{
+public:
+  InternalFocusEvent(bool aIsTrusted, uint32_t aMessage) :
+    InternalUIEvent(aIsTrusted, aMessage, NS_FOCUS_EVENT, 0),
+    fromRaise(false), isRefocus(false)
+  {
+  }
+
+  /// The possible related target
+  nsCOMPtr<dom::EventTarget> relatedTarget;
+
+  bool fromRaise;
+  bool isRefocus;
+
+  void AssignFocusEventData(const InternalFocusEvent& aEvent, bool aCopyTargets)
+  {
+    AssignUIEventData(aEvent, aCopyTargets);
+
+    relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr;
+    fromRaise = aEvent.fromRaise;
+    isRefocus = aEvent.isRefocus;
+  }
+};
+
+/******************************************************************************
+ * mozilla::InternalTransitionEvent
+ ******************************************************************************/
+
+class InternalTransitionEvent : public WidgetEvent
+{
+public:
+  InternalTransitionEvent(bool aIsTrusted, uint32_t aMessage,
+                          const nsAString& aPropertyName, float aElapsedTime,
+                          const nsAString& aPseudoElement) :
+    nsEvent(aIsTrusted, aMessage, NS_TRANSITION_EVENT),
+    propertyName(aPropertyName), elapsedTime(aElapsedTime),
+    pseudoElement(aPseudoElement)
+  {
+  }
+
+  nsString propertyName;
+  float elapsedTime;
+  nsString pseudoElement;
+
+  void AssignTransitionEventData(const InternalTransitionEvent& aEvent,
+                                 bool aCopyTargets)
+  {
+    AssignEventData(aEvent, aCopyTargets);
+
+    // propertyName, elapsedTime and pseudoElement must have been initialized
+    // with the constructor.
+  }
+};
+
+/******************************************************************************
+ * mozilla::InternalAnimationEvent
+ ******************************************************************************/
+
+class InternalAnimationEvent : public WidgetEvent
+{
+public:
+  InternalAnimationEvent(bool aIsTrusted, uint32_t aMessage,
+                         const nsAString& aAnimationName, float aElapsedTime,
+                         const nsAString& aPseudoElement) :
+    WidgetEvent(aIsTrusted, aMessage, NS_ANIMATION_EVENT),
+    animationName(aAnimationName), elapsedTime(aElapsedTime),
+    pseudoElement(aPseudoElement)
+  {
+  }
+
+  nsString animationName;
+  float elapsedTime;
+  nsString pseudoElement;
+
+  void AssignAnimationEventData(const InternalAnimationEvent& aEvent,
+                                bool aCopyTargets)
+  {
+    AssignEventData(aEvent, aCopyTargets);
+
+    // animationName, elapsedTime and pseudoElement must have been initialized
+    // with the constructor.
+  }
+};
+
+} // namespace mozilla
+
+// TODO: Remove following typedefs
+typedef mozilla::InternalScriptErrorEvent nsScriptErrorEvent;
+typedef mozilla::InternalScrollPortEvent  nsScrollPortEvent;
+typedef mozilla::InternalScrollAreaEvent  nsScrollAreaEvent;
+typedef mozilla::InternalFormEvent        nsFormEvent;
+typedef mozilla::InternalClipboardEvent   nsClipboardEvent;
+typedef mozilla::InternalFocusEvent       nsFocusEvent;
+typedef mozilla::InternalTransitionEvent  nsTransitionEvent;
+typedef mozilla::InternalAnimationEvent   nsAnimationEvent;
+
+#endif // mozilla_ContentEvents_h__
--- a/widget/EventForwards.h
+++ b/widget/EventForwards.h
@@ -77,27 +77,27 @@ class WidgetMouseEvent;
 class WidgetDragEvent;
 class WidgetMouseScrollEvent;
 class WidgetWheelEvent;
 
 // TouchEvents.h
 class WidgetGestureNotifyEvent;
 class WidgetSimpleGestureEvent;
 class WidgetTouchEvent;
-} // namespace mozilla
 
 // ContentEvents.h
-class nsScriptErrorEvent;
-class nsScrollPortEvent;
-class nsScrollAreaEvent;
-class nsFormEvent;
-class nsClipboardEvent;
-class nsFocusEvent;
-class nsTransitionEvent;
-class nsAnimationEvent;
+class InternalScriptErrorEvent;
+class InternalScrollPortEvent;
+class InternalScrollAreaEvent;
+class InternalFormEvent;
+class InternalClipboardEvent;
+class InternalFocusEvent;
+class InternalTransitionEvent;
+class InternalAnimationEvent;
+} // namespace mozilla
 
 // MiscEvents.h
 class nsCommandEvent;
 class nsContentCommandEvent;
 class nsPluginEvent;
 
 // content/events/public/nsMutationEvent.h
 class nsMutationEvent;
@@ -123,10 +123,18 @@ typedef mozilla::WidgetMouseScrollEvent 
 
 namespace mozilla {
 typedef WidgetWheelEvent                  WheelEvent;
 }
 
 typedef mozilla::WidgetGestureNotifyEvent nsGestureNotifyEvent;
 typedef mozilla::WidgetSimpleGestureEvent nsSimpleGestureEvent;
 typedef mozilla::WidgetTouchEvent         nsTouchEvent;
+typedef mozilla::InternalScriptErrorEvent nsScriptErrorEvent;
+typedef mozilla::InternalScrollPortEvent  nsScrollPortEvent;
+typedef mozilla::InternalScrollAreaEvent  nsScrollAreaEvent;
+typedef mozilla::InternalFormEvent        nsFormEvent;
+typedef mozilla::InternalClipboardEvent   nsClipboardEvent;
+typedef mozilla::InternalFocusEvent       nsFocusEvent;
+typedef mozilla::InternalTransitionEvent  nsTransitionEvent;
+typedef mozilla::InternalAnimationEvent   nsAnimationEvent;
 
 #endif // mozilla_EventForwards_h__
--- a/widget/moz.build
+++ b/widget/moz.build
@@ -107,16 +107,17 @@ EXPORTS += [
     'nsIWidget.h',
     'nsIWidgetListener.h',
     'nsWidgetInitData.h',
     'nsWidgetsCID.h',
 ]
 
 EXPORTS.mozilla += [
     'BasicEvents.h',
+    'ContentEvents.h',
     'EventForwards.h',
     'LookAndFeel.h',
     'MouseEvents.h',
     'TextEvents.h',
     'TouchEvents.h',
     'WidgetUtils.h',
 ]
 
--- a/widget/nsGUIEvent.h
+++ b/widget/nsGUIEvent.h
@@ -2,108 +2,29 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsGUIEvent_h__
 #define nsGUIEvent_h__
 
 #include "mozilla/BasicEvents.h"
+#include "mozilla/ContentEvents.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 
 #include "nsPoint.h"
 #include "nsRect.h"
-#include "nsIDOMDataTransfer.h"
 #include "nsWeakPtr.h"
 #include "nsITransferable.h"
 
-class nsIContent;
-
 #define NS_EVENT_TYPE_NULL                   0
 #define NS_EVENT_TYPE_ALL                  1 // Not a real event type
 
-/**
- * Script error event
- */
-
-class nsScriptErrorEvent : public nsEvent
-{
-public:
-  nsScriptErrorEvent(bool isTrusted, uint32_t msg)
-    : nsEvent(isTrusted, msg, NS_SCRIPT_ERROR_EVENT),
-      lineNr(0), errorMsg(nullptr), fileName(nullptr)
-  {
-  }
-
-  int32_t           lineNr;
-  const PRUnichar*  errorMsg;
-  const PRUnichar*  fileName;
-
-  // XXX Not tested by test_assign_event_data.html
-  void AssignScriptErrorEventData(const nsScriptErrorEvent& aEvent,
-                                  bool aCopyTargets)
-  {
-    AssignEventData(aEvent, aCopyTargets);
-
-    lineNr = aEvent.lineNr;
-
-    // We don't copy errorMsg and fileName.  If it's necessary, perhaps, this
-    // should duplicate the characters and free them at destructing.
-    errorMsg = nullptr;
-    fileName = nullptr;
-  }
-};
-
-class nsScrollPortEvent : public nsGUIEvent
-{
-public:
-  enum orientType {
-    vertical   = 0,
-    horizontal = 1,
-    both       = 2
-  };
-
-  nsScrollPortEvent(bool isTrusted, uint32_t msg, nsIWidget *w)
-    : nsGUIEvent(isTrusted, msg, w, NS_SCROLLPORT_EVENT),
-      orient(vertical)
-  {
-  }
-
-  orientType orient;
-
-  void AssignScrollPortEventData(const nsScrollPortEvent& aEvent,
-                                 bool aCopyTargets)
-  {
-    AssignGUIEventData(aEvent, aCopyTargets);
-
-    orient = aEvent.orient;
-  }
-};
-
-class nsScrollAreaEvent : public nsGUIEvent
-{
-public:
-  nsScrollAreaEvent(bool isTrusted, uint32_t msg, nsIWidget *w)
-    : nsGUIEvent(isTrusted, msg, w, NS_SCROLLAREA_EVENT)
-  {
-  }
-
-  nsRect mArea;
-
-  void AssignScrollAreaEventData(const nsScrollAreaEvent& aEvent,
-                                 bool aCopyTargets)
-  {
-    AssignGUIEventData(aEvent, aCopyTargets);
-
-    mArea = aEvent.mArea;
-  }
-};
-
 class nsContentCommandEvent : public nsGUIEvent
 {
 public:
   nsContentCommandEvent(bool aIsTrusted, uint32_t aMsg, nsIWidget *aWidget,
                         bool aOnlyEnabledCheck = false) :
     nsGUIEvent(aIsTrusted, aMsg, aWidget, NS_CONTENT_COMMAND_EVENT),
     mOnlyEnabledCheck(bool(aOnlyEnabledCheck)),
     mSucceeded(false), mIsEnabled(false)
@@ -134,42 +55,16 @@ public:
 
   bool mOnlyEnabledCheck;                          // [in]
 
   bool mSucceeded;                                 // [out]
   bool mIsEnabled;                                 // [out]
 };
 
 /**
- * Form event
- * 
- * We hold the originating form control for form submit and reset events.
- * originator is a weak pointer (does not hold a strong reference).
- */
-
-class nsFormEvent : public nsEvent
-{
-public:
-  nsFormEvent(bool isTrusted, uint32_t msg)
-    : nsEvent(isTrusted, msg, NS_FORM_EVENT),
-      originator(nullptr)
-  {
-  }
-
-  nsIContent *originator;
-
-  void AssignFormEventData(const nsFormEvent& aEvent, bool aCopyTargets)
-  {
-    AssignEventData(aEvent, aCopyTargets);
-
-    // Don't copy originator due to a weak pointer.
-  }
-};
-
-/**
  * Command event
  *
  * Custom commands for example from the operating system.
  */
 
 class nsCommandEvent : public nsGUIEvent
 {
 public:
@@ -188,117 +83,16 @@ public:
   {
     AssignGUIEventData(aEvent, aCopyTargets);
 
     // command must have been initialized with the constructor.
   }
 };
 
 /**
- * Clipboard event
- */
-class nsClipboardEvent : public nsEvent
-{
-public:
-  nsClipboardEvent(bool isTrusted, uint32_t msg)
-    : nsEvent(isTrusted, msg, NS_CLIPBOARD_EVENT)
-  {
-  }
-
-  nsCOMPtr<nsIDOMDataTransfer> clipboardData;
-
-  void AssignClipboardEventData(const nsClipboardEvent& aEvent,
-                                bool aCopyTargets)
-  {
-    AssignEventData(aEvent, aCopyTargets);
-
-    clipboardData = aEvent.clipboardData;
-  }
-};
-
-class nsFocusEvent : public nsUIEvent
-{
-public:
-  nsFocusEvent(bool isTrusted, uint32_t msg)
-    : nsUIEvent(isTrusted, msg, 0),
-      fromRaise(false),
-      isRefocus(false)
-  {
-    eventStructType = NS_FOCUS_EVENT;
-  }
-
-  /// The possible related target
-  nsCOMPtr<mozilla::dom::EventTarget> relatedTarget;
-
-  bool fromRaise;
-  bool isRefocus;
-
-  void AssignFocusEventData(const nsFocusEvent& aEvent, bool aCopyTargets)
-  {
-    AssignUIEventData(aEvent, aCopyTargets);
-
-    relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr;
-    fromRaise = aEvent.fromRaise;
-    isRefocus = aEvent.isRefocus;
-  }
-};
-
-class nsTransitionEvent : public nsEvent
-{
-public:
-  nsTransitionEvent(bool isTrusted, uint32_t msg,
-                    const nsAString& propertyNameArg, float elapsedTimeArg,
-                    const nsAString& pseudoElementArg)
-    : nsEvent(isTrusted, msg, NS_TRANSITION_EVENT),
-      propertyName(propertyNameArg), elapsedTime(elapsedTimeArg),
-      pseudoElement(pseudoElementArg)
-  {
-  }
-
-  nsString propertyName;
-  float elapsedTime;
-  nsString pseudoElement;
-
-  void AssignTransitionEventData(const nsTransitionEvent& aEvent,
-                                 bool aCopyTargets)
-  {
-    AssignEventData(aEvent, aCopyTargets);
-
-    // propertyName, elapsedTime and pseudoElement must have been initialized
-    // with the constructor.
-  }
-};
-
-class nsAnimationEvent : public nsEvent
-{
-public:
-  nsAnimationEvent(bool isTrusted, uint32_t msg,
-                   const nsAString &animationNameArg, float elapsedTimeArg,
-                   const nsAString &pseudoElementArg)
-    : nsEvent(isTrusted, msg, NS_ANIMATION_EVENT),
-      animationName(animationNameArg), elapsedTime(elapsedTimeArg),
-      pseudoElement(pseudoElementArg)
-  {
-  }
-
-  nsString animationName;
-  float elapsedTime;
-  nsString pseudoElement;
-
-  void AssignAnimationEventData(const nsAnimationEvent& aEvent,
-                                bool aCopyTargets)
-  {
-    AssignEventData(aEvent, aCopyTargets);
-
-    // animationName, elapsedTime and pseudoElement must have been initialized
-    // with the constructor.
-  }
-};
-
-/**
  * Native event pluginEvent for plugins.
  */
 
 class nsPluginEvent : public nsGUIEvent
 {
 public:
   nsPluginEvent(bool isTrusted, uint32_t msg, nsIWidget *w)
     : nsGUIEvent(isTrusted, msg, w, NS_PLUGIN_EVENT),