Bug 868728 - Cleanup nsDOMUIEvent a bit; r=smaug
authorMs2ger <ms2ger@gmail.com>
Fri, 10 May 2013 09:13:45 +0200
changeset 142325 1102bd83dc9d342a8a94023f2a068c3cb5d24164
parent 142324 a923ac1365feb26020f9bfdd37040eb22c241976
child 142326 e44c0b1eb2e3da774b4f7dc85667d71201276e80
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs868728
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 868728 - Cleanup nsDOMUIEvent a bit; r=smaug
content/events/src/nsDOMUIEvent.cpp
content/events/src/nsDOMUIEvent.h
--- a/content/events/src/nsDOMUIEvent.cpp
+++ b/content/events/src/nsDOMUIEvent.cpp
@@ -219,40 +219,52 @@ nsDOMUIEvent::GetPagePoint()
 
   return pagePoint;
 }
 
 NS_IMETHODIMP
 nsDOMUIEvent::GetPageX(int32_t* aPageX)
 {
   NS_ENSURE_ARG_POINTER(aPageX);
+  *aPageX = PageX();
+  return NS_OK;
+}
+
+int32_t
+nsDOMUIEvent::PageX() const
+{
   if (mPrivateDataDuplicated) {
-    *aPageX = mPagePoint.x;
-  } else {
-    *aPageX = nsDOMEvent::GetPageCoords(mPresContext,
-                                        mEvent,
-                                        mEvent->refPoint,
-                                        mClientPoint).x;
+    return mPagePoint.x;
   }
-  return NS_OK;
+
+  return nsDOMEvent::GetPageCoords(mPresContext,
+                                   mEvent,
+                                   mEvent->refPoint,
+                                   mClientPoint).x;
 }
 
 NS_IMETHODIMP
 nsDOMUIEvent::GetPageY(int32_t* aPageY)
 {
   NS_ENSURE_ARG_POINTER(aPageY);
+  *aPageY = PageY();
+  return NS_OK;
+}
+
+int32_t
+nsDOMUIEvent::PageY() const
+{
   if (mPrivateDataDuplicated) {
-    *aPageY = mPagePoint.y;
-  } else {
-    *aPageY = nsDOMEvent::GetPageCoords(mPresContext,
-                                        mEvent,
-                                        mEvent->refPoint,
-                                        mClientPoint).y;
+    return mPagePoint.y;
   }
-  return NS_OK;
+
+  return nsDOMEvent::GetPageCoords(mPresContext,
+                                   mEvent,
+                                   mEvent->refPoint,
+                                   mClientPoint).y;
 }
 
 NS_IMETHODIMP
 nsDOMUIEvent::GetWhich(uint32_t* aWhich)
 {
   NS_ENSURE_ARG_POINTER(aWhich);
   *aWhich = Which();
   return NS_OK;
@@ -294,30 +306,35 @@ nsDOMUIEvent::GetRangeParent(nsIDOMNode*
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMUIEvent::GetRangeOffset(int32_t* aRangeOffset)
 {
   NS_ENSURE_ARG_POINTER(aRangeOffset);
-  nsIFrame* targetFrame = nullptr;
+  *aRangeOffset = RangeOffset();
+  return NS_OK;
+}
 
-  if (mPresContext) {
-    targetFrame = mPresContext->EventStateManager()->GetEventTarget();
+int32_t
+nsDOMUIEvent::RangeOffset() const
+{
+  if (!mPresContext) {
+    return 0;
   }
 
-  if (targetFrame) {
-    nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent,
-                                                              targetFrame);
-    *aRangeOffset = targetFrame->GetContentOffsetsFromPoint(pt).offset;
-    return NS_OK;
+  nsIFrame* targetFrame = mPresContext->EventStateManager()->GetEventTarget();
+  if (!targetFrame) {
+    return 0;
   }
-  *aRangeOffset = 0;
-  return NS_OK;
+
+  nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent,
+                                                            targetFrame);
+  return targetFrame->GetContentOffsetsFromPoint(pt).offset;
 }
 
 NS_IMETHODIMP
 nsDOMUIEvent::GetCancelBubble(bool* aCancelBubble)
 {
   NS_ENSURE_ARG_POINTER(aCancelBubble);
   *aCancelBubble = CancelBubble();
   return NS_OK;
@@ -326,17 +343,17 @@ nsDOMUIEvent::GetCancelBubble(bool* aCan
 NS_IMETHODIMP
 nsDOMUIEvent::SetCancelBubble(bool aCancelBubble)
 {
   mEvent->mFlags.mPropagationStopped = aCancelBubble;
   return NS_OK;
 }
 
 nsIntPoint
-nsDOMUIEvent::GetLayerPoint()
+nsDOMUIEvent::GetLayerPoint() const
 {
   if (!mEvent ||
       (mEvent->eventStructType != NS_MOUSE_EVENT &&
        mEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
        mEvent->eventStructType != NS_WHEEL_EVENT &&
        mEvent->eventStructType != NS_TOUCH_EVENT &&
        mEvent->eventStructType != NS_DRAG_EVENT &&
        mEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT) ||
@@ -368,28 +385,33 @@ nsDOMUIEvent::GetLayerY(int32_t* aLayerY
   NS_ENSURE_ARG_POINTER(aLayerY);
   *aLayerY = GetLayerPoint().y;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMUIEvent::GetIsChar(bool* aIsChar)
 {
-  switch(mEvent->eventStructType)
+  *aIsChar = IsChar();
+  return NS_OK;
+}
+
+bool
+nsDOMUIEvent::IsChar() const
+{
+  switch (mEvent->eventStructType)
   {
     case NS_KEY_EVENT:
-      *aIsChar = ((nsKeyEvent*)mEvent)->isChar;
-      return NS_OK;
+      return static_cast<nsKeyEvent*>(mEvent)->isChar;
     case NS_TEXT_EVENT:
-      *aIsChar = ((nsTextEvent*)mEvent)->isChar;
-      return NS_OK;
+      return static_cast<nsKeyEvent*>(mEvent)->isChar;
     default:
-      *aIsChar = false;
-      return NS_OK;
+      return false;
   }
+  MOZ_NOT_REACHED("Switch handles all cases.");
 }
 
 NS_IMETHODIMP
 nsDOMUIEvent::DuplicatePrivateData()
 {
   mClientPoint = nsDOMEvent::GetClientCoords(mPresContext,
                                              mEvent,
                                              mEvent->refPoint,
--- a/content/events/src/nsDOMUIEvent.h
+++ b/content/events/src/nsDOMUIEvent.h
@@ -93,86 +93,64 @@ public:
                                                     mozilla::ErrorResult& aRv);
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
   {
     return mozilla::dom::UIEventBinding::Wrap(aCx, aScope, this);
   }
 
-  already_AddRefed<nsIDOMWindow> GetView()
+  nsIDOMWindow* GetView() const
   {
-    nsCOMPtr<nsIDOMWindow> view = mView;
-    return view.forget();
+    return mView;
   }
 
-  int32_t Detail()
+  int32_t Detail() const
   {
     return mDetail;
   }
 
-  int32_t LayerX()
+  int32_t LayerX() const
   {
     return GetLayerPoint().x;
   }
 
-  int32_t LayerY()
+  int32_t LayerY() const
   {
     return GetLayerPoint().y;
   }
 
-  int32_t PageX()
-  {
-    int32_t x;
-    GetPageX(&x);
-    return x;
-  }
-
-  int32_t PageY()
-  {
-    int32_t y;
-    GetPageY(&y);
-    return y;
-  }
+  int32_t PageX() const;
+  int32_t PageY() const;
 
   virtual uint32_t Which()
   {
     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);
-    return offset;
-  }
+  int32_t RangeOffset() const;
 
-  bool CancelBubble()
+  bool CancelBubble() const
   {
     return mEvent->mFlags.mPropagationStopped;
   }
 
-  bool IsChar()
-  {
-    bool isChar;
-    GetIsChar(&isChar);
-    return isChar;
-  }
+  bool IsChar() const;
 
 protected:
   // Internal helper functions
   nsIntPoint GetClientPoint();
   nsIntPoint GetMovementPoint();
-  nsIntPoint GetLayerPoint();
+  nsIntPoint GetLayerPoint() const;
   nsIntPoint GetPagePoint();
 
   nsCOMPtr<nsIDOMWindow> mView;
   int32_t mDetail;
   nsIntPoint mClientPoint;
   // Screenpoint is mEvent->refPoint.
   nsIntPoint mLayerPoint;
   nsIntPoint mPagePoint;