Bug 1710317 - Part 2: Add mButton[s] to WidgetTouchEvent r=aklotz,edgar

It's not ideal to have mButton[s] only to pass them to PointerEvent, but it's required anyway.

Differential Revision: https://phabricator.services.mozilla.com/D115509
This commit is contained in:
Kagami Sascha Rosylight 2021-05-31 13:39:18 +00:00
parent cdcf59a339
commit bc3afb6e7f
7 changed files with 40 additions and 10 deletions

View File

@ -533,12 +533,16 @@ void PointerEventHandler::InitPointerEventFromTouch(
MOZ_ASSERT(aPointerEvent);
MOZ_ASSERT(aTouchEvent);
// Use mButton/mButtons only when mButton got a value (from pen input)
int16_t button = aTouchEvent->mMessage == eTouchMove
? MouseButton::eNotPressed
: aTouchEvent->mButton != MouseButton::eNotPressed
? aTouchEvent->mButton
: MouseButton::ePrimary;
int16_t buttons = aTouchEvent->mMessage == eTouchEnd
? MouseButtonsFlag::eNoButtons
: aTouchEvent->mButton != MouseButton::eNotPressed
? aTouchEvent->mButtons
: MouseButtonsFlag::ePrimaryFlag;
aPointerEvent->mIsPrimary = aIsPrimary;

View File

@ -91,14 +91,18 @@ MultiTouchInput::MultiTouchInput(const MultiTouchInput& aOther)
aOther.modifiers),
mType(aOther.mType),
mScreenOffset(aOther.mScreenOffset),
mHandledByAPZ(aOther.mHandledByAPZ) {
mHandledByAPZ(aOther.mHandledByAPZ),
mButton(aOther.mButton),
mButtons(aOther.mButtons) {
mTouches.AppendElements(aOther.mTouches);
}
MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
: InputData(MULTITOUCH_INPUT, aTouchEvent.mTime, aTouchEvent.mTimeStamp,
aTouchEvent.mModifiers),
mHandledByAPZ(aTouchEvent.mFlags.mHandledByAPZ) {
mHandledByAPZ(aTouchEvent.mFlags.mHandledByAPZ),
mButton(aTouchEvent.mButton),
mButtons(aTouchEvent.mButtons) {
MOZ_ASSERT(NS_IsMainThread(),
"Can only copy from WidgetTouchEvent on main thread");
@ -139,7 +143,7 @@ MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
ViewAs<ScreenPixel>(
domTouch->mRefPoint,
PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent),
ScreenSize(radiusX, radiusY), rotationAngle, force);
ScreenSize((float)radiusX, (float)radiusY), rotationAngle, force);
mTouches.AppendElement(data);
}
@ -197,6 +201,8 @@ WidgetTouchEvent MultiTouchInput::ToWidgetEvent(nsIWidget* aWidget,
event.mFocusSequenceNumber = mFocusSequenceNumber;
event.mLayersId = mLayersId;
event.mInputSource = aInputSource;
event.mButton = mButton;
event.mButtons = mButtons;
for (size_t i = 0; i < mTouches.Length(); i++) {
*event.mTouches.AppendElement() = mTouches[i].ToNewDOMTouch();

View File

@ -254,6 +254,10 @@ class MultiTouchInput : public InputData {
// the touch interaction, so we sstore it in the event.
ExternalPoint mScreenOffset;
bool mHandledByAPZ;
// These button fields match to the corresponding fields in
// WidgetMouseEventBase.
int16_t mButton = 0;
int16_t mButtons = 0;
};
class MouseInput : public InputData {

View File

@ -150,13 +150,15 @@ class WidgetTouchEvent : public WidgetInputEvent {
WidgetTouchEvent(const WidgetTouchEvent& aOther)
: WidgetInputEvent(aOther.IsTrusted(), aOther.mMessage, aOther.mWidget,
eTouchEventClass),
mInputSource(aOther.mInputSource) {
eTouchEventClass) {
MOZ_COUNT_CTOR(WidgetTouchEvent);
mModifiers = aOther.mModifiers;
mTime = aOther.mTime;
mTimeStamp = aOther.mTimeStamp;
mTouches.AppendElements(aOther.mTouches);
mInputSource = aOther.mInputSource;
mButton = aOther.mButton;
mButtons = aOther.mButtons;
mFlags.mCancelable = mMessage != eTouchCancel;
mFlags.mHandledByAPZ = aOther.mFlags.mHandledByAPZ;
}
@ -181,6 +183,8 @@ class WidgetTouchEvent : public WidgetInputEvent {
TouchArray mTouches;
uint16_t mInputSource = 5; // MouseEvent_Binding::MOZ_SOURCE_TOUCH
int16_t mButton = eNotPressed;
int16_t mButtons = 0;
void AssignTouchEventData(const WidgetTouchEvent& aEvent, bool aCopyTargets) {
AssignInputEventData(aEvent, aCopyTargets);

View File

@ -336,6 +336,8 @@ struct ParamTraits<mozilla::WidgetTouchEvent> {
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, static_cast<const mozilla::WidgetInputEvent&>(aParam));
WriteParam(aMsg, aParam.mInputSource);
WriteParam(aMsg, aParam.mButton);
WriteParam(aMsg, aParam.mButtons);
// Sigh, Touch bites us again! We want to be able to do
// WriteParam(aMsg, aParam.mTouches);
const paramType::TouchArray& touches = aParam.mTouches;
@ -359,6 +361,8 @@ struct ParamTraits<mozilla::WidgetTouchEvent> {
if (!ReadParam(aMsg, aIter,
static_cast<mozilla::WidgetInputEvent*>(aResult)) ||
!ReadParam(aMsg, aIter, &aResult->mInputSource) ||
!ReadParam(aMsg, aIter, &aResult->mButton) ||
!ReadParam(aMsg, aIter, &aResult->mButtons) ||
!ReadParam(aMsg, aIter, &numTouches)) {
return false;
}
@ -1162,7 +1166,7 @@ struct ParamTraits<mozilla::MultiTouchInput::MultiTouchType>
template <>
struct ParamTraits<mozilla::MultiTouchInput> {
typedef mozilla::MultiTouchInput paramType;
using paramType = mozilla::MultiTouchInput;
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam));
@ -1170,6 +1174,8 @@ struct ParamTraits<mozilla::MultiTouchInput> {
WriteParam(aMsg, aParam.mTouches);
WriteParam(aMsg, aParam.mHandledByAPZ);
WriteParam(aMsg, aParam.mScreenOffset);
WriteParam(aMsg, aParam.mButton);
WriteParam(aMsg, aParam.mButtons);
}
static bool Read(const Message* aMsg, PickleIterator* aIter,
@ -1178,7 +1184,9 @@ struct ParamTraits<mozilla::MultiTouchInput> {
ReadParam(aMsg, aIter, &aResult->mType) &&
ReadParam(aMsg, aIter, &aResult->mTouches) &&
ReadParam(aMsg, aIter, &aResult->mHandledByAPZ) &&
ReadParam(aMsg, aIter, &aResult->mScreenOffset);
ReadParam(aMsg, aIter, &aResult->mScreenOffset) &&
ReadParam(aMsg, aIter, &aResult->mButton) &&
ReadParam(aMsg, aIter, &aResult->mButtons);
}
};

View File

@ -8558,7 +8558,8 @@ bool nsWindow::WidgetTypeSupportsAcceleration() {
}
bool nsWindow::DispatchTouchEventFromWMPointer(
UINT msg, LPARAM aLParam, const WinPointerInfo& aPointerInfo) {
UINT msg, LPARAM aLParam, const WinPointerInfo& aPointerInfo,
mozilla::MouseButton aButton) {
MultiTouchInput::MultiTouchType touchType;
switch (msg) {
case WM_POINTERDOWN:
@ -8597,6 +8598,8 @@ bool nsWindow::DispatchTouchEventFromWMPointer(
touchInput.mTimeStamp =
GetMessageTimeStamp(static_cast<long>(touchInput.mTime));
touchInput.mTouches.AppendElement(touchData);
touchInput.mButton = aButton;
touchInput.mButtons = aPointerInfo.mButtons;
// POINTER_INFO.dwKeyStates can't be used as it only supports Shift and Ctrl
ModifierKeyState modifierKeyState;

View File

@ -516,7 +516,8 @@ class nsWindow final : public nsWindowBase {
bool WithinDraggableRegion(int32_t clientX, int32_t clientY);
bool DispatchTouchEventFromWMPointer(UINT msg, LPARAM aLParam,
const WinPointerInfo& aPointerInfo);
const WinPointerInfo& aPointerInfo,
mozilla::MouseButton aButton);
protected:
#endif // MOZ_XUL