Bug 855091 - Paris bindings for WheelEvent, r=peterv
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 28 Mar 2013 16:57:33 +0200
changeset 126638 49f0306ffa2f35e0812f9cba74d3aa416ca17e2e
parent 126637 7cd3d772634a6dcf3ec3820731db50ab296b5c24
child 126639 3e2047c6e7235456ab29371fb273b2276e1ec799
push id24492
push userryanvm@gmail.com
push dateSat, 30 Mar 2013 23:31:27 +0000
treeherdermozilla-central@1932c6f78248 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs855091
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 855091 - Paris bindings for WheelEvent, r=peterv
content/events/src/DOMWheelEvent.cpp
content/events/src/DOMWheelEvent.h
dom/bindings/Bindings.conf
dom/webidl/WebIDL.mk
dom/webidl/WheelEvent.webidl
--- a/content/events/src/DOMWheelEvent.cpp
+++ b/content/events/src/DOMWheelEvent.cpp
@@ -27,16 +27,17 @@ DOMWheelEvent::DOMWheelEvent(EventTarget
     mEventIsInternal = false;
   } else {
     mEventIsInternal = true;
     mEvent->time = PR_Now();
     mEvent->refPoint.x = mEvent->refPoint.y = 0;
     static_cast<widget::WheelEvent*>(mEvent)->inputSource =
       nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
   }
+  SetIsDOMBinding();
 }
 
 DOMWheelEvent::~DOMWheelEvent()
 {
   if (mEventIsInternal && mEvent) {
     MOZ_ASSERT(mEvent->eventStructType == NS_WHEEL_EVENT,
                "The mEvent must be WheelEvent");
     delete static_cast<widget::WheelEvent*>(mEvent);
@@ -86,89 +87,121 @@ DOMWheelEvent::InitWheelEvent(const nsAS
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DOMWheelEvent::GetDeltaX(double* aDeltaX)
 {
   NS_ENSURE_ARG_POINTER(aDeltaX);
 
-  *aDeltaX = static_cast<widget::WheelEvent*>(mEvent)->deltaX;
+  *aDeltaX = DeltaX();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DOMWheelEvent::GetDeltaY(double* aDeltaY)
 {
   NS_ENSURE_ARG_POINTER(aDeltaY);
 
-  *aDeltaY = static_cast<widget::WheelEvent*>(mEvent)->deltaY;
+  *aDeltaY = DeltaY();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DOMWheelEvent::GetDeltaZ(double* aDeltaZ)
 {
   NS_ENSURE_ARG_POINTER(aDeltaZ);
 
-  *aDeltaZ = static_cast<widget::WheelEvent*>(mEvent)->deltaZ;
+  *aDeltaZ = DeltaZ();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DOMWheelEvent::GetDeltaMode(uint32_t* aDeltaMode)
 {
   NS_ENSURE_ARG_POINTER(aDeltaMode);
 
-  *aDeltaMode = static_cast<widget::WheelEvent*>(mEvent)->deltaMode;
+  *aDeltaMode = DeltaMode();
   return NS_OK;
 }
 
+static void
+GetModifierList(bool aCtrl, bool aShift, bool aAlt, bool aMeta,
+                nsAString& aModifierList)
+{
+  if (aCtrl) {
+    aModifierList.AppendLiteral(NS_DOM_KEYNAME_CONTROL);
+  }
+  if (aShift) {
+    if (!aModifierList.IsEmpty()) {
+      aModifierList.AppendLiteral(" ");
+    }
+    aModifierList.AppendLiteral(NS_DOM_KEYNAME_SHIFT);
+  }
+  if (aAlt) {
+    if (!aModifierList.IsEmpty()) {
+      aModifierList.AppendLiteral(" ");
+    }
+    aModifierList.AppendLiteral(NS_DOM_KEYNAME_ALT);
+  }
+  if (aMeta) {
+    if (!aModifierList.IsEmpty()) {
+      aModifierList.AppendLiteral(" ");
+    }
+    aModifierList.AppendLiteral(NS_DOM_KEYNAME_META);
+  }
+}
+
 nsresult
 DOMWheelEvent::InitFromCtor(const nsAString& aType,
                             JSContext* aCx, JS::Value* aVal)
 {
   mozilla::idl::WheelEventInit d;
   nsresult rv = d.Init(aCx, aVal);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoString modifierList;
-  if (d.ctrlKey) {
-    modifierList.AppendLiteral(NS_DOM_KEYNAME_CONTROL);
-  }
-  if (d.shiftKey) {
-    if (!modifierList.IsEmpty()) {
-      modifierList.AppendLiteral(" ");
-    }
-    modifierList.AppendLiteral(NS_DOM_KEYNAME_SHIFT);
-  }
-  if (d.altKey) {
-    if (!modifierList.IsEmpty()) {
-      modifierList.AppendLiteral(" ");
-    }
-    modifierList.AppendLiteral(NS_DOM_KEYNAME_ALT);
-  }
-  if (d.metaKey) {
-    if (!modifierList.IsEmpty()) {
-      modifierList.AppendLiteral(" ");
-    }
-    modifierList.AppendLiteral(NS_DOM_KEYNAME_META);
-  }
+  GetModifierList(d.ctrlKey, d.shiftKey, d.altKey, d.metaKey, modifierList);
 
   rv = InitWheelEvent(aType, d.bubbles, d.cancelable,
                       d.view, d.detail, d.screenX, d.screenY,
                       d.clientX, d.clientY, d.button, d.relatedTarget,
                       modifierList, d.deltaX, d.deltaY, d.deltaZ, d.deltaMode);
   NS_ENSURE_SUCCESS(rv, rv);
 
   static_cast<widget::WheelEvent*>(mEvent)->buttons = d.buttons;
 
   return NS_OK;
 }
 
+already_AddRefed<DOMWheelEvent>
+DOMWheelEvent::Constructor(const GlobalObject& aGlobal,
+                           const nsAString& aType,
+                           const WheelEventInit& aParam,
+                           mozilla::ErrorResult& aRv)
+{
+  nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.Get());
+  nsRefPtr<DOMWheelEvent> e = new DOMWheelEvent(t, nullptr, nullptr);
+  bool trusted = e->Init(t);
+  nsAutoString modifierList;
+  GetModifierList(aParam.mCtrlKey, aParam.mShiftKey,
+                  aParam.mAltKey, aParam.mMetaKey,
+                  modifierList);
+  aRv = e->InitWheelEvent(aType, aParam.mBubbles, aParam.mCancelable,
+                          aParam.mView, aParam.mDetail,
+                          aParam.mScreenX, aParam.mScreenY,
+                          aParam.mClientX, aParam.mClientY,
+                          aParam.mButton, aParam.mRelatedTarget,
+                          modifierList, aParam.mDeltaX,
+                          aParam.mDeltaY, aParam.mDeltaZ, aParam.mDeltaMode);
+  static_cast<widget::WheelEvent*>(e->mEvent)->buttons = aParam.mButtons;
+  e->SetTrusted(trusted);
+  return e.forget();
+}
+
 } // namespace dom
 } // namespace mozilla
 
 using namespace mozilla;
 
 nsresult NS_NewDOMWheelEvent(nsIDOMEvent** aInstancePtrResult,
                              mozilla::dom::EventTarget* aOwner,
                              nsPresContext* aPresContext,
--- a/content/events/src/DOMWheelEvent.h
+++ b/content/events/src/DOMWheelEvent.h
@@ -4,16 +4,17 @@
  * 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_dom_DOMWheelEvent_h__
 #define mozilla_dom_DOMWheelEvent_h__
 
 #include "nsIDOMWheelEvent.h"
 #include "nsDOMMouseEvent.h"
+#include "mozilla/dom/WheelEventBinding.h"
 
 namespace mozilla {
 namespace dom {
 
 class DOMWheelEvent : public nsDOMMouseEvent,
                       public nsIDOMWheelEvent
 {
 public:
@@ -27,14 +28,45 @@ public:
   // nsIDOMWheelEvent Interface
   NS_DECL_NSIDOMWHEELEVENT
   
   // Forward to base class
   NS_FORWARD_TO_NSDOMMOUSEEVENT
 
   virtual nsresult InitFromCtor(const nsAString& aType,
                                 JSContext* aCx, JS::Value* aVal);
+
+  static
+  already_AddRefed<DOMWheelEvent> Constructor(const GlobalObject& aGlobal,
+                                              const nsAString& aType,
+                                              const WheelEventInit& aParam,
+                                              mozilla::ErrorResult& aRv);
+
+  virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope)
+  {
+    return mozilla::dom::WheelEventBinding::Wrap(aCx, aScope, this);
+  }
+
+  double DeltaX()
+  {
+    return static_cast<widget::WheelEvent*>(mEvent)->deltaX;
+  }
+
+  double DeltaY()
+  {
+    return static_cast<widget::WheelEvent*>(mEvent)->deltaY;
+  }
+
+  double DeltaZ()
+  {
+    return static_cast<widget::WheelEvent*>(mEvent)->deltaZ;
+  }
+
+  uint32_t DeltaMode()
+  {
+    return static_cast<widget::WheelEvent*>(mEvent)->deltaMode;
+  }
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_DOMWheelEvent_h__
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -1070,16 +1070,21 @@ DOMInterfaces = {
    'wrapperCache': False
 },
 
 'WebSocket': {
     'headerFile': 'WebSocket.h',
     'implicitJSContext': [ 'constructor' ]
 },
 
+'WheelEvent': {
+    'headerFile': 'DOMWheelEvent.h',
+    'nativeType': 'mozilla::dom::DOMWheelEvent',
+},
+
 'XMLHttpRequest': [
 {
     'nativeType': 'nsXMLHttpRequest',
     'implicitJSContext': [ 'constructor', ],
     'resultNotAddRefed': [ 'upload', 'responseXML' ]
 },
 {
     'workers': True,
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -271,16 +271,17 @@ webidl_files = \
   TimeRanges.webidl \
   TransitionEvent.webidl \
   TreeWalker.webidl \
   UIEvent.webidl \
   URL.webidl \
   ValidityState.webidl \
   WebComponents.webidl \
   WebSocket.webidl \
+  WheelEvent.webidl \
   UndoManager.webidl \
   URLUtils.webidl \
   USSDReceivedEvent.webidl \
   XMLDocument.webidl \
   XMLHttpRequest.webidl \
   XMLHttpRequestEventTarget.webidl \
   XMLHttpRequestUpload.webidl \
   XMLSerializer.webidl \
new file mode 100644
--- /dev/null
+++ b/dom/webidl/WheelEvent.webidl
@@ -0,0 +1,33 @@
+/* -*- Mode: IDL; 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/.
+ *
+ * For more information on this interface please see
+ * http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html
+ *
+ * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
+ * liability, trademark and document use rules apply.
+ */
+
+[Constructor(DOMString type, optional WheelEventInit eventInitDict)]
+interface WheelEvent : MouseEvent
+{
+  const unsigned long DOM_DELTA_PIXEL = 0x00;
+  const unsigned long DOM_DELTA_LINE  = 0x01;
+  const unsigned long DOM_DELTA_PAGE  = 0x02;
+
+  readonly attribute double        deltaX;
+  readonly attribute double        deltaY;
+  readonly attribute double        deltaZ;
+  readonly attribute unsigned long deltaMode;
+
+};
+
+dictionary WheelEventInit : MouseEventInit
+{
+  double deltaX = 0;
+  double deltaY = 0;
+  double deltaZ = 0;
+  unsigned long deltaMode = 0;
+};