Permalink
Browse files

Bug 833795 - Use screen relative co-ordinates for gestures; r=drs

  • Loading branch information...
1 parent 800ebf3 commit dea9dd3a6403fd302b472faa5bb6684e772a7361 @kentuckyfriedtakahe kentuckyfriedtakahe committed Mar 21, 2013
View
@@ -637,6 +637,10 @@ TabParent::TryCapture(const nsGUIEvent& aEvent)
{
MOZ_ASSERT(sEventCapturer == this && mEventCaptureDepth > 0);
+ if (mIsDestroyed) {
+ return false;
+ }
+
if (aEvent.eventStructType != NS_TOUCH_EVENT) {
// Only capture of touch events is implemented, for now.
return false;
@@ -657,19 +661,29 @@ TabParent::TryCapture(const nsGUIEvent& aEvent)
return false;
}
- // Adjust the widget coordinates to be relative to our frame.
- nsRefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
+ if (RenderFrameParent* rfp = GetRenderFrame()) {
+ // We need to process screen relative events co-ordinates for gestures to
+ // avoid phantom movement when the frame moves.
+ rfp->NotifyInputEvent(event);
- if (!frameLoader) {
- // No frame anymore?
- sEventCapturer = nullptr;
- return false;
- }
+ // Adjust the widget coordinates to be relative to our frame.
+ nsRefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
+
+ if (!frameLoader) {
+ // No frame anymore?
+ sEventCapturer = nullptr;
+ return false;
+ }
- nsEventStateManager::MapEventCoordinatesForChildProcess(frameLoader, &event);
+ // Remove the frame offset and compensate for zoom.
+ nsEventStateManager::MapEventCoordinatesForChildProcess(frameLoader,
+ &event);
+ rfp->ApplyZoomCompensationToEvent(&event);
+ }
- SendRealTouchEvent(event);
- return true;
+ return (event.message == NS_TOUCH_MOVE) ?
+ PBrowserParent::SendRealTouchMoveEvent(event) :
+ PBrowserParent::SendRealTouchEvent(event);
}
bool
@@ -1381,7 +1395,8 @@ TabParent::MaybeForwardEventToRenderFrame(const nsInputEvent& aEvent,
nsInputEvent* aOutEvent)
{
if (RenderFrameParent* rfp = GetRenderFrame()) {
- rfp->NotifyInputEvent(aEvent, aOutEvent);
+ rfp->NotifyInputEvent(aEvent);
+ rfp->ApplyZoomCompensationToEvent(aOutEvent);
}
}
@@ -225,20 +225,8 @@ WidgetSpaceToCompensatedViewportSpace(const gfx::Point& aPoint,
}
nsEventStatus
-AsyncPanZoomController::ReceiveInputEvent(const nsInputEvent& aEvent,
- nsInputEvent* aOutEvent)
+AsyncPanZoomController::ReceiveMainThreadInputEvent(const nsInputEvent& aEvent)
{
- gfxFloat currentResolution;
- gfx::Point currentScrollOffset, lastScrollOffset;
- {
- MonitorAutoLock monitor(mMonitor);
- currentResolution = CalculateResolution(mFrameMetrics).width;
- currentScrollOffset = gfx::Point(mFrameMetrics.mScrollOffset.x,
- mFrameMetrics.mScrollOffset.y);
- lastScrollOffset = gfx::Point(mLastContentPaintMetrics.mScrollOffset.x,
- mLastContentPaintMetrics.mScrollOffset.y);
- }
-
nsEventStatus status;
switch (aEvent.eventStructType) {
case NS_TOUCH_EVENT: {
@@ -256,9 +244,21 @@ AsyncPanZoomController::ReceiveInputEvent(const nsInputEvent& aEvent,
break;
}
- switch (aEvent.eventStructType) {
+ return status;
+}
+
+void
+AsyncPanZoomController::ApplyZoomCompensationToEvent(nsInputEvent* aEvent)
+{
+ gfxFloat currentResolution;
+ {
+ MonitorAutoLock monitor(mMonitor);
+ currentResolution = CalculateResolution(mFrameMetrics).width;
+ }
+
+ switch (aEvent->eventStructType) {
case NS_TOUCH_EVENT: {
- nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aOutEvent);
+ nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
for (uint32_t i = 0; i < touches.Length(); ++i) {
nsIDOMTouch* touch = touches[i];
@@ -273,14 +273,12 @@ AsyncPanZoomController::ReceiveInputEvent(const nsInputEvent& aEvent,
}
default: {
gfx::Point refPoint = WidgetSpaceToCompensatedViewportSpace(
- gfx::Point(aOutEvent->refPoint.x, aOutEvent->refPoint.y),
+ gfx::Point(aEvent->refPoint.x, aEvent->refPoint.y),
currentResolution);
- aOutEvent->refPoint = nsIntPoint(refPoint.x, refPoint.y);
+ aEvent->refPoint = nsIntPoint(refPoint.x, refPoint.y);
break;
}
}
-
- return status;
}
nsEventStatus AsyncPanZoomController::ReceiveInputEvent(const InputData& aEvent) {
@@ -92,17 +92,22 @@ class AsyncPanZoomController MOZ_FINAL {
nsEventStatus ReceiveInputEvent(const InputData& aEvent);
/**
- * Special handler for nsInputEvents. Also sets |aOutEvent| (which is assumed
- * to be an already-existing instance of an nsInputEvent which may be an
- * nsTouchEvent) to have its touch points in DOM space. This is so that the
- * touches can be passed through the DOM and content can handle them.
+ * Special handler for nsInputEvents. |aEvent| is in screen relative
+ * co-ordinates.
*
- * NOTE: Be careful of invoking the nsInputEvent variant. This can only be
- * called on the main thread. See widget/InputData.h for more information on
- * why we have InputData and nsInputEvent separated.
+ * NOTE: This can only be called on the main thread. See widget/InputData.h
+ * for more information on why we have InputData and nsInputEvent separated.
*/
- nsEventStatus ReceiveInputEvent(const nsInputEvent& aEvent,
- nsInputEvent* aOutEvent);
+ nsEventStatus ReceiveMainThreadInputEvent(const nsInputEvent& aEvent);
+
+ /**
+ * Transform from frame relative co-ordinates to DOM relative co-ordinates.
+ * This method updates |aEvent| (which is assumed to be an already-existing
+ * instance of an nsInputEvent which may be an nsTouchEvent) to have its touch
+ * points in DOM space. This is so that the touches can be passed through the
+ * DOM and content can handle them.
+ */
+ void ApplyZoomCompensationToEvent(nsInputEvent* aEvent);
/**
* Updates the composition bounds, i.e. the dimensions of the final size of
@@ -781,11 +781,18 @@ RenderFrameParent::OwnerContentChanged(nsIContent* aContent)
}
void
-RenderFrameParent::NotifyInputEvent(const nsInputEvent& aEvent,
- nsInputEvent* aOutEvent)
+RenderFrameParent::NotifyInputEvent(const nsInputEvent& aEvent)
{
if (mPanZoomController) {
- mPanZoomController->ReceiveInputEvent(aEvent, aOutEvent);
+ mPanZoomController->ReceiveMainThreadInputEvent(aEvent);
+ }
+}
+
+void
+RenderFrameParent::ApplyZoomCompensationToEvent(nsInputEvent* aEvent)
+{
+ if (mPanZoomController) {
+ mPanZoomController->ApplyZoomCompensationToEvent(aEvent);
}
}
@@ -92,8 +92,9 @@ class RenderFrameParent : public PRenderFrameParent,
void SetBackgroundColor(nscolor aColor) { mBackgroundColor = gfxRGBA(aColor); };
- void NotifyInputEvent(const nsInputEvent& aEvent,
- nsInputEvent* aOutEvent);
+ void NotifyInputEvent(const nsInputEvent& aEvent);
+
+ void ApplyZoomCompensationToEvent(nsInputEvent* aEvent);
void NotifyDimensionsChanged(int width, int height);

0 comments on commit dea9dd3

Please sign in to comment.