Bug 1288187 - Extract a helper function to manage synthetic touch points for widgets that don't have more specific handling. r?botond
MozReview-Commit-ID: LhJp298kN4m
--- a/widget/gonk/nsWindow.cpp
+++ b/widget/gonk/nsWindow.cpp
@@ -268,63 +268,19 @@ nsWindow::SynthesizeNativeTouchPoint(uin
if (aPointerState == TOUCH_HOVER) {
return NS_ERROR_UNEXPECTED;
}
if (!mSynthesizedTouchInput) {
mSynthesizedTouchInput = MakeUnique<MultiTouchInput>();
}
- ScreenIntPoint pointerScreenPoint = ViewAs<ScreenPixel>(aPoint,
- PixelCastJustification::LayoutDeviceIsScreenForBounds);
-
- // We can't dispatch mSynthesizedTouchInput directly because (a) dispatching
- // it might inadvertently modify it and (b) in the case of touchend or
- // touchcancel events mSynthesizedTouchInput will hold the touches that are
- // still down whereas the input dispatched needs to hold the removed
- // touch(es). We use |inputToDispatch| for this purpose.
- MultiTouchInput inputToDispatch;
- inputToDispatch.mInputType = MULTITOUCH_INPUT;
-
- int32_t index = mSynthesizedTouchInput->IndexOfTouch((int32_t)aPointerId);
- if (aPointerState == TOUCH_CONTACT) {
- if (index >= 0) {
- // found an existing touch point, update it
- SingleTouchData& point = mSynthesizedTouchInput->mTouches[index];
- point.mScreenPoint = pointerScreenPoint;
- point.mRotationAngle = (float)aPointerOrientation;
- point.mForce = (float)aPointerPressure;
- inputToDispatch.mType = MultiTouchInput::MULTITOUCH_MOVE;
- } else {
- // new touch point, add it
- mSynthesizedTouchInput->mTouches.AppendElement(SingleTouchData(
- (int32_t)aPointerId,
- pointerScreenPoint,
- ScreenSize(0, 0),
- (float)aPointerOrientation,
- (float)aPointerPressure));
- inputToDispatch.mType = MultiTouchInput::MULTITOUCH_START;
- }
- inputToDispatch.mTouches = mSynthesizedTouchInput->mTouches;
- } else {
- MOZ_ASSERT(aPointerState == TOUCH_REMOVE || aPointerState == TOUCH_CANCEL);
- // a touch point is being lifted, so remove it from the stored list
- if (index >= 0) {
- mSynthesizedTouchInput->mTouches.RemoveElementAt(index);
- }
- inputToDispatch.mType = (aPointerState == TOUCH_REMOVE
- ? MultiTouchInput::MULTITOUCH_END
- : MultiTouchInput::MULTITOUCH_CANCEL);
- inputToDispatch.mTouches.AppendElement(SingleTouchData(
- (int32_t)aPointerId,
- pointerScreenPoint,
- ScreenSize(0, 0),
- (float)aPointerOrientation,
- (float)aPointerPressure));
- }
+ MultiTouchInput inputToDispatch = UpdateSynthesizedTouchState(
+ mSynthesizedTouchInput.get(), aPointerId, aPointerState,
+ aPoint, aPointerPressure, aPointerOrientation);
// Can't use NewRunnableMethod here because that will pass a const-ref
// argument to DispatchTouchInputViaAPZ whereas that function takes a
// non-const ref. At this callsite we don't care about the mutations that
// the function performs so this is fine. Also we can't pass |this| to the
// task because nsWindow refcounting is not threadsafe. Instead we just use
// the gFocusedWindow static ptr instead the task.
APZThreadUtils::RunOnControllerThread(
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -2063,16 +2063,75 @@ nsIWidget::ClearNativeTouchSequence(nsIO
mLongTapTimer->Cancel();
mLongTapTimer = nullptr;
SynthesizeNativeTouchPoint(mLongTapTouchPoint->mPointerId, TOUCH_CANCEL,
mLongTapTouchPoint->mPosition, 0, 0, nullptr);
mLongTapTouchPoint = nullptr;
return NS_OK;
}
+MultiTouchInput
+nsBaseWidget::UpdateSynthesizedTouchState(MultiTouchInput* aState,
+ uint32_t aPointerId,
+ TouchPointerState aPointerState,
+ LayoutDeviceIntPoint aPoint,
+ double aPointerPressure,
+ uint32_t aPointerOrientation)
+{
+ ScreenIntPoint pointerScreenPoint = ViewAs<ScreenPixel>(aPoint,
+ PixelCastJustification::LayoutDeviceIsScreenForBounds);
+
+ // We can't dispatch *aState directly because (a) dispatching
+ // it might inadvertently modify it and (b) in the case of touchend or
+ // touchcancel events aState will hold the touches that are
+ // still down whereas the input dispatched needs to hold the removed
+ // touch(es). We use |inputToDispatch| for this purpose.
+ MultiTouchInput inputToDispatch;
+ inputToDispatch.mInputType = MULTITOUCH_INPUT;
+
+ int32_t index = aState->IndexOfTouch((int32_t)aPointerId);
+ if (aPointerState == TOUCH_CONTACT) {
+ if (index >= 0) {
+ // found an existing touch point, update it
+ SingleTouchData& point = aState->mTouches[index];
+ point.mScreenPoint = pointerScreenPoint;
+ point.mRotationAngle = (float)aPointerOrientation;
+ point.mForce = (float)aPointerPressure;
+ inputToDispatch.mType = MultiTouchInput::MULTITOUCH_MOVE;
+ } else {
+ // new touch point, add it
+ aState->mTouches.AppendElement(SingleTouchData(
+ (int32_t)aPointerId,
+ pointerScreenPoint,
+ ScreenSize(0, 0),
+ (float)aPointerOrientation,
+ (float)aPointerPressure));
+ inputToDispatch.mType = MultiTouchInput::MULTITOUCH_START;
+ }
+ inputToDispatch.mTouches = aState->mTouches;
+ } else {
+ MOZ_ASSERT(aPointerState == TOUCH_REMOVE || aPointerState == TOUCH_CANCEL);
+ // a touch point is being lifted, so remove it from the stored list
+ if (index >= 0) {
+ aState->mTouches.RemoveElementAt(index);
+ }
+ inputToDispatch.mType = (aPointerState == TOUCH_REMOVE
+ ? MultiTouchInput::MULTITOUCH_END
+ : MultiTouchInput::MULTITOUCH_CANCEL);
+ inputToDispatch.mTouches.AppendElement(SingleTouchData(
+ (int32_t)aPointerId,
+ pointerScreenPoint,
+ ScreenSize(0, 0),
+ (float)aPointerOrientation,
+ (float)aPointerPressure));
+ }
+
+ return inputToDispatch;
+}
+
void
nsBaseWidget::RegisterPluginWindowForRemoteUpdates()
{
#if !defined(XP_WIN) && !defined(MOZ_WIDGET_GTK)
NS_NOTREACHED("nsBaseWidget::RegisterPluginWindowForRemoteUpdates not implemented!");
return;
#else
MOZ_ASSERT(NS_IsMainThread());
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -1,15 +1,16 @@
/* -*- Mode: C++; 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/. */
#ifndef nsBaseWidget_h__
#define nsBaseWidget_h__
+#include "InputData.h"
#include "mozilla/EventForwards.h"
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WidgetUtils.h"
#include "mozilla/layers/APZCCallbackHelper.h"
#include "nsRect.h"
#include "nsIWidget.h"
#include "nsWidgetsCID.h"
@@ -553,16 +554,23 @@ protected:
void EnsureTextEventDispatcher();
// Notify the compositor that a device reset has occurred.
void OnRenderingDeviceReset();
bool UseAPZ();
+ mozilla::MultiTouchInput
+ UpdateSynthesizedTouchState(mozilla::MultiTouchInput* aState,
+ uint32_t aPointerId,
+ TouchPointerState aPointerState,
+ LayoutDeviceIntPoint aPoint,
+ double aPointerPressure,
+ uint32_t aPointerOrientation);
#if defined(XP_WIN)
void UpdateScrollCapture() override;
/**
* To be overridden by derived classes to return a snapshot that can be used
* during scrolling. Returning null means we won't update the container.
* @return an already AddRefed SourceSurface containing the snapshot