Skip to content

Commit

Permalink
[embedlite] Add EmbedInputData wrapper class for mozilla::InputData. …
Browse files Browse the repository at this point in the history
…JB#49613

This EmbedInputData does not have any gecko header dependencies. Thus,
in can be safely used from embedding side.
  • Loading branch information
rainemak committed Apr 23, 2020
1 parent 4c9383c commit 85a3c8d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 4 deletions.
73 changes: 73 additions & 0 deletions embedding/embedlite/EmbedInputData.h
@@ -0,0 +1,73 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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 mozilla_EmbedLite_EmbedInputData_h__
#define mozilla_EmbedLite_EmbedInputData_h__

#include <vector>

namespace mozilla {

namespace embedlite {

struct TouchPointF
{
TouchPointF(float x, float y)
: x(x)
, y(y)
{}

float x;
float y;
};

// Simplified wrapper for SingleTouchData of the InputData.h
struct TouchData
{
TouchData(int32_t identifier,
TouchPointF touchPoint,
float pressure)
: identifier(identifier)
, touchPoint(touchPoint)
, pressure(pressure)
{}

int32_t identifier;
TouchPointF touchPoint;
float pressure;
};

class EmbedTouchInput
{
public:
// Keep this sync with InputData.h
enum EmbedTouchType
{
MULTITOUCH_START,
MULTITOUCH_MOVE,
MULTITOUCH_END,
MULTITOUCH_CANCEL,

// Used as an upper bound for ContiguousEnumSerializer
MULTITOUCH_SENTINEL,
};

EmbedTouchInput(EmbedTouchType type, uint32_t timeStamp)
: type(type)
, timeStamp(timeStamp)
{}

EmbedTouchType type;
uint32_t timeStamp;

std::vector<TouchData> touches;
};

} // namespace embedlite
} // namespace mozilla

#endif // mozilla_EmbedLite_EmbedInputData_h__
22 changes: 20 additions & 2 deletions embedding/embedlite/EmbedLiteView.cpp
Expand Up @@ -6,6 +6,7 @@
#include "EmbedLog.h"

#include "EmbedLiteView.h"
#include "EmbedInputData.h"
#include "EmbedLiteApp.h"

#include "mozilla/Unused.h"
Expand Down Expand Up @@ -243,11 +244,28 @@ EmbedLiteView::SetDPI(const float& dpi)
}

void
EmbedLiteView::ReceiveInputEvent(const InputData& aEvent)
EmbedLiteView::ReceiveInputEvent(const EmbedTouchInput &aEvent)
{
LOGT();
NS_ENSURE_TRUE(mViewImpl,);
mViewImpl->ReceiveInputEvent(aEvent);

mozilla::MultiTouchInput multiTouchInput(static_cast<mozilla::MultiTouchInput::MultiTouchType>(aEvent.type),
aEvent.timeStamp, TimeStamp(), 0);

for (const mozilla::embedlite::TouchData &touchData : aEvent.touches) {
nsIntPoint point = nsIntPoint(int32_t(floorf(touchData.touchPoint.x)),
int32_t(floorf(touchData.touchPoint.y)));

mozilla::ScreenIntPoint screenPoint = mozilla::ScreenIntPoint::FromUnknownPoint(point);

multiTouchInput.mTouches.AppendElement(mozilla::SingleTouchData(touchData.identifier,
screenPoint,
mozilla::ScreenSize(1, 1),
180.0f,
touchData.pressure));
}

mViewImpl->ReceiveInputEvent(multiTouchInput);
}

void
Expand Down
4 changes: 2 additions & 2 deletions embedding/embedlite/EmbedLiteView.h
Expand Up @@ -14,9 +14,9 @@
class EmbedLiteViewIface;

namespace mozilla {
class InputData;
namespace embedlite {

class EmbedTouchInput;
class EmbedLiteViewThreadParent;
class PEmbedLiteViewParent;
class EmbedLiteView;
Expand Down Expand Up @@ -97,7 +97,7 @@ class EmbedLiteView
virtual void SendKeyPress(int domKeyCode, int gmodifiers, int charCode);
virtual void SendKeyRelease(int domKeyCode, int gmodifiers, int charCode);

virtual void ReceiveInputEvent(const mozilla::InputData& aEvent);
virtual void ReceiveInputEvent(const EmbedTouchInput& aEvent);
virtual void MousePress(int x, int y, int mstime, unsigned int buttons, unsigned int modifiers);
virtual void MouseRelease(int x, int y, int mstime, unsigned int buttons, unsigned int modifiers);
virtual void MouseMove(int x, int y, int mstime, unsigned int buttons, unsigned int modifiers);
Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/moz.build
Expand Up @@ -28,6 +28,7 @@ XPIDL_MODULE = 'embedLite'

EXPORTS.mozilla.embedlite += [
'EmbedInitGlue.h',
'EmbedInputData.h',
'EmbedLiteAPI.h',
'EmbedLiteApp.h',
'EmbedLiteContentController.h',
Expand Down

0 comments on commit 85a3c8d

Please sign in to comment.