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

This commit is contained in:
Anthony Jones 2013-03-21 15:08:15 +13:00
Родитель 4af4ef25b3
Коммит f9775b58f9
5 изменённых файлов: 70 добавлений и 44 удалений

Просмотреть файл

@ -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;
}
// Remove the frame offset and compensate for zoom.
nsEventStateManager::MapEventCoordinatesForChildProcess(frameLoader,
&event);
rfp->ApplyZoomCompensationToEvent(&event);
}
nsEventStateManager::MapEventCoordinatesForChildProcess(frameLoader, &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 @@ public:
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 @@ public:
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);