Bug 866436 - Cleanup the implementation of UIEvent.which; r=smaug
authorMs2ger <ms2ger@gmail.com>
Sun, 05 May 2013 09:03:16 +0200
changeset 130844 581b86706691
parent 130843 c5dcc0f29ab8
child 130845 c34dd4b67355
push id24635
push userMs2ger@gmail.com
push date2013-05-05 07:05 +0000
treeherdermozilla-central@c8e47b184aba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs866436
milestone23.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 866436 - Cleanup the implementation of UIEvent.which; r=smaug
content/events/src/nsDOMKeyboardEvent.cpp
content/events/src/nsDOMKeyboardEvent.h
content/events/src/nsDOMMouseEvent.cpp
content/events/src/nsDOMMouseEvent.h
content/events/src/nsDOMUIEvent.cpp
content/events/src/nsDOMUIEvent.h
--- a/content/events/src/nsDOMKeyboardEvent.cpp
+++ b/content/events/src/nsDOMKeyboardEvent.cpp
@@ -129,25 +129,16 @@ nsDOMKeyboardEvent::KeyCode()
   case NS_KEY_UP:
   case NS_KEY_PRESS:
   case NS_KEY_DOWN:
     return static_cast<nsKeyEvent*>(mEvent)->keyCode;
   }
   return 0;
 }
 
-/* virtual */
-nsresult
-nsDOMKeyboardEvent::Which(uint32_t* aWhich)
-{
-  NS_ENSURE_ARG_POINTER(aWhich);
-  *aWhich = Which();
-  return NS_OK;
-}
-
 uint32_t
 nsDOMKeyboardEvent::Which()
 {
   switch (mEvent->message) {
     case NS_KEY_UP:
     case NS_KEY_DOWN:
       return KeyCode();
     case NS_KEY_PRESS:
--- a/content/events/src/nsDOMKeyboardEvent.h
+++ b/content/events/src/nsDOMKeyboardEvent.h
@@ -71,16 +71,12 @@ public:
                     bool aShiftKey, bool aMetaKey,
                     uint32_t aKeyCode, uint32_t aCharCode,
                     mozilla::ErrorResult& aRv)
   {
     aRv = InitKeyEvent(aType, aCanBubble, aCancelable, aView,
                        aCtrlKey, aAltKey, aShiftKey,aMetaKey,
                        aKeyCode, aCharCode);
   }
-
-protected:
-  // Specific implementation for a keyboard event.
-  virtual nsresult Which(uint32_t* aWhich);
 };
 
 
 #endif // nsDOMKeyboardEvent_h__
--- a/content/events/src/nsDOMMouseEvent.cpp
+++ b/content/events/src/nsDOMMouseEvent.cpp
@@ -442,27 +442,16 @@ nsDOMMouseEvent::GetModifierState(const 
                                   bool* aState)
 {
   NS_ENSURE_ARG_POINTER(aState);
 
   *aState = GetModifierState(aKey);
   return NS_OK;
 }
 
-/* virtual */
-nsresult
-nsDOMMouseEvent::Which(uint32_t* aWhich)
-{
-  NS_ENSURE_ARG_POINTER(aWhich);
-  uint16_t button;
-  (void) GetButton(&button);
-  *aWhich = button + 1;
-  return NS_OK;
-}
-
 NS_IMETHODIMP
 nsDOMMouseEvent::GetMozPressure(float* aPressure)
 {
   NS_ENSURE_ARG_POINTER(aPressure);
   *aPressure = MozPressure();
   return NS_OK;
 }
 
--- a/content/events/src/nsDOMMouseEvent.h
+++ b/content/events/src/nsDOMMouseEvent.h
@@ -35,19 +35,17 @@ public:
   }
 
   virtual nsresult InitFromCtor(const nsAString& aType,
                                 JSContext* aCx, JS::Value* aVal);
 
   // Web IDL binding methods
   virtual uint32_t Which() MOZ_OVERRIDE
   {
-    uint32_t w = 0;
-    Which(&w);
-    return w;
+    return Button() + 1;
   }
 
   int32_t ScreenX();
   int32_t ScreenY();
   int32_t ClientX();
   int32_t ClientY();
   bool CtrlKey()
   {
@@ -118,19 +116,16 @@ public:
     aRv = InitNSMouseEvent(aType, aCanBubble, aCancelable,
                            aView, aDetail, aScreenX, aScreenY,
                            aClientX, aClientY, aCtrlKey, aAltKey,
                            aShiftKey, aMetaKey, aButton,
                            aRelatedTarget, aPressure, aInputSource);
   }
 
 protected:
-  // Specific implementation for a mouse event.
-  virtual nsresult Which(uint32_t* aWhich);
-
   nsresult InitMouseEvent(const nsAString& aType,
                           bool aCanBubble,
                           bool aCancelable,
                           nsIDOMWindow* aView,
                           int32_t aDetail,
                           int32_t aScreenX,
                           int32_t aScreenY,
                           int32_t aClientX,
--- a/content/events/src/nsDOMUIEvent.cpp
+++ b/content/events/src/nsDOMUIEvent.cpp
@@ -248,17 +248,19 @@ nsDOMUIEvent::GetPageY(int32_t* aPageY)
                                         mClientPoint).y;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMUIEvent::GetWhich(uint32_t* aWhich)
 {
-  return Which(aWhich);
+  NS_ENSURE_ARG_POINTER(aWhich);
+  *aWhich = Which();
+  return NS_OK;
 }
 
 already_AddRefed<nsINode>
 nsDOMUIEvent::GetRangeParent()
 {
   nsIFrame* targetFrame = nullptr;
 
   if (mPresContext) {
--- a/content/events/src/nsDOMUIEvent.h
+++ b/content/events/src/nsDOMUIEvent.h
@@ -130,19 +130,21 @@ public:
   {
     int32_t y;
     GetPageY(&y);
     return y;
   }
 
   virtual uint32_t Which()
   {
-    uint32_t w;
-    GetWhich(&w);
-    return w;
+    MOZ_ASSERT(mEvent->eventStructType != NS_KEY_EVENT,
+               "Key events should override Which()");
+    MOZ_ASSERT(mEvent->eventStructType != NS_MOUSE_EVENT,
+               "Mouse events should override Which()");
+    return 0;
   }
 
   already_AddRefed<nsINode> GetRangeParent();
 
   int32_t RangeOffset()
   {
     int32_t offset;
     GetRangeOffset(&offset);
@@ -163,25 +165,16 @@ public:
 
 protected:
   // Internal helper functions
   nsIntPoint GetClientPoint();
   nsIntPoint GetMovementPoint();
   nsIntPoint GetLayerPoint();
   nsIntPoint GetPagePoint();
 
-  // Allow specializations.
-  virtual nsresult Which(uint32_t* aWhich)
-  {
-    NS_ENSURE_ARG_POINTER(aWhich);
-    // Usually we never reach here, as this is reimplemented for mouse and keyboard events.
-    *aWhich = 0;
-    return NS_OK;
-  }
-
   nsCOMPtr<nsIDOMWindow> mView;
   int32_t mDetail;
   nsIntPoint mClientPoint;
   // Screenpoint is mEvent->refPoint.
   nsIntPoint mLayerPoint;
   nsIntPoint mPagePoint;
   nsIntPoint mMovementPoint;
   bool mIsPointerLocked;