Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[embedlite] Deliver touch events to the web content in css pixel. Fix…
…es JB#49810

Signed-off-by: Raine Makelainen <raine.makelainen@jolla.com>
  • Loading branch information
rainemak committed May 8, 2020
1 parent d7679dd commit dabf60d
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 39 deletions.
10 changes: 4 additions & 6 deletions embedding/embedlite/PEmbedLiteView.ipdl
Expand Up @@ -26,7 +26,7 @@ using MultiTouchInput from "InputData.h";
using mozilla::CSSIntPoint from "Units.h";
using struct mozilla::layers::ZoomConstraints from "FrameMetrics.h";
using mozilla::layers::MaybeZoomConstraints from "FrameMetrics.h";
using mozilla::CSSPoint from "Units.h";
using mozilla::LayoutDevicePoint from "Units.h";
using mozilla::Modifiers from "mozilla/EventForwards.h";
using nsEventStatus from "mozilla/EventForwards.h";
using mozilla::layers::TouchBehaviorFlags from "mozilla/layers/APZUtils.h";
Expand Down Expand Up @@ -58,11 +58,9 @@ child:
async HandleScrollEvent(bool isRootScrollFrame, gfxRect contentRect, gfxSize scrollSize);

async UpdateFrame(FrameMetrics frame) compress;
async HandleDoubleTap(CSSPoint aPoint, Modifiers aModifiers, ScrollableLayerGuid aGuid);
async HandleSingleTap(CSSPoint aPoint, Modifiers aModifiers, ScrollableLayerGuid aGuid);
async HandleLongTap(CSSPoint aPoint, ScrollableLayerGuid aGuid, uint64_t aInputBlockId);
// async AcknowledgeScrollUpdate(ViewID aScrollId, uint32_t aScrollGeneration);
// async RequestFlingSnap(ViewID aScrollId, CSSPoint aDestination);
async HandleDoubleTap(LayoutDevicePoint aPoint, Modifiers aModifiers, ScrollableLayerGuid aGuid);
async HandleSingleTap(LayoutDevicePoint aPoint, Modifiers aModifiers, ScrollableLayerGuid aGuid);
async HandleLongTap(LayoutDevicePoint aPoint, ScrollableLayerGuid aGuid, uint64_t aInputBlockId);
async HandleTextEvent(nsString commit, nsString preEdit);
async HandleKeyPressEvent(int domKeyCode, int gmodifiers, int charCode);
async HandleKeyReleaseEvent(int domKeyCode, int gmodifiers, int charCode);
Expand Down
24 changes: 18 additions & 6 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.cpp
Expand Up @@ -865,11 +865,15 @@ EmbedLiteViewBaseChild::InitEvent(WidgetGUIEvent& event, nsIntPoint* aPoint)
}

bool
EmbedLiteViewBaseChild::RecvHandleDoubleTap(const CSSPoint& aPoint,
EmbedLiteViewBaseChild::RecvHandleDoubleTap(const LayoutDevicePoint& aPoint,
const Modifiers &aModifiers,
const ScrollableLayerGuid& aGuid)
{
CSSPoint cssPoint = APZCCallbackHelper::ApplyCallbackTransform(aPoint, aGuid);
bool ok = false;
CSSPoint cssPoint = mHelper->ApplyPointTransform(aPoint, aGuid, &ok);
if (!ok) {
return true;
}

for (unsigned int i = 0; i < mControllerListeners.Length(); i++) {
mControllerListeners[i]->HandleDoubleTap(cssPoint, aModifiers);
Expand All @@ -885,7 +889,7 @@ EmbedLiteViewBaseChild::RecvHandleDoubleTap(const CSSPoint& aPoint,
}

bool
EmbedLiteViewBaseChild::RecvHandleSingleTap(const CSSPoint& aPoint,
EmbedLiteViewBaseChild::RecvHandleSingleTap(const LayoutDevicePoint& aPoint,
const Modifiers &aModifiers,
const ScrollableLayerGuid& aGuid)
{
Expand All @@ -900,7 +904,11 @@ EmbedLiteViewBaseChild::RecvHandleSingleTap(const CSSPoint& aPoint,
mIMEComposing = false;
}

CSSPoint cssPoint = APZCCallbackHelper::ApplyCallbackTransform(aPoint, aGuid);
bool ok = false;
CSSPoint cssPoint = mHelper->ApplyPointTransform(aPoint, aGuid, &ok);
if (!ok) {
return true;
}

for (unsigned int i = 0; i < mControllerListeners.Length(); i++) {
mControllerListeners[i]->HandleSingleTap(cssPoint, aModifiers);
Expand All @@ -923,11 +931,15 @@ EmbedLiteViewBaseChild::RecvHandleSingleTap(const CSSPoint& aPoint,
}

bool
EmbedLiteViewBaseChild::RecvHandleLongTap(const CSSPoint& aPoint,
EmbedLiteViewBaseChild::RecvHandleLongTap(const LayoutDevicePoint& aPoint,
const ScrollableLayerGuid& aGuid,
const uint64_t& aInputBlockId)
{
CSSPoint cssPoint = APZCCallbackHelper::ApplyCallbackTransform(aPoint, aGuid);
bool ok = false;
CSSPoint cssPoint = mHelper->ApplyPointTransform(aPoint, aGuid, &ok);
if (!ok) {
return true;
}

for (unsigned int i = 0; i < mControllerListeners.Length(); i++) {
mControllerListeners[i]->HandleLongTap(cssPoint, 0, aInputBlockId);
Expand Down
6 changes: 3 additions & 3 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.h
Expand Up @@ -157,11 +157,11 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,
const gfxSize& scrollSize) override;

virtual bool RecvUpdateFrame(const mozilla::layers::FrameMetrics& aFrameMetrics) override;
virtual bool RecvHandleDoubleTap(const CSSPoint&, const Modifiers& aModifiers,
virtual bool RecvHandleDoubleTap(const LayoutDevicePoint &, const Modifiers& aModifiers,
const ScrollableLayerGuid& aGuid) override;
virtual bool RecvHandleSingleTap(const CSSPoint&, const Modifiers& aModifiers,
virtual bool RecvHandleSingleTap(const LayoutDevicePoint &, const Modifiers& aModifiers,
const ScrollableLayerGuid& aGuid) override;
virtual bool RecvHandleLongTap(const CSSPoint& aPoint,
virtual bool RecvHandleLongTap(const LayoutDevicePoint &aPoint,
const mozilla::layers::ScrollableLayerGuid& aGuid,
const uint64_t& aInputBlockId) override;
#if 0 // sha1 6afa98a3ea0ba814b77f7aeb162624433e427ccf
Expand Down
39 changes: 19 additions & 20 deletions embedding/embedlite/embedthread/EmbedContentController.cpp
Expand Up @@ -50,16 +50,15 @@ void EmbedContentController::RequestFlingSnap(const FrameMetrics::ViewID &aScrol

void EmbedContentController::HandleTap(TapType aType, const LayoutDevicePoint &aPoint, Modifiers aModifiers, const EmbedContentController::ScrollableLayerGuid &aGuid, uint64_t aInputBlockId)
{
CSSPoint cssPoint(aPoint.x, aPoint.y);
switch (aType) {
case GeckoContentController::TapType::eSingleTap:
HandleSingleTap(cssPoint, aModifiers, aGuid);
HandleSingleTap(aPoint, aModifiers, aGuid);
break;
case GeckoContentController::TapType::eDoubleTap:
HandleDoubleTap(cssPoint, aModifiers, aGuid);
HandleDoubleTap(aPoint, aModifiers, aGuid);
break;
case GeckoContentController::TapType::eLongTap:
HandleLongTap(cssPoint, aModifiers, aGuid, aInputBlockId);
HandleLongTap(aPoint, aModifiers, aGuid, aInputBlockId);
break;
case GeckoContentController::TapType::eSecondTap:
case GeckoContentController::TapType::eLongTapUp:
Expand All @@ -70,14 +69,14 @@ void EmbedContentController::HandleTap(TapType aType, const LayoutDevicePoint &a
}
}

void EmbedContentController::HandleDoubleTap(const CSSPoint& aPoint,
void EmbedContentController::HandleDoubleTap(const LayoutDevicePoint& aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid)
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(NewRunnableMethod<const CSSPoint &, Modifiers, const ScrollableLayerGuid &>(this,
mUILoop->PostTask(NewRunnableMethod<const LayoutDevicePoint &, Modifiers, const ScrollableLayerGuid &>(this,
&EmbedContentController::HandleDoubleTap,
aPoint,
aModifiers,
Expand All @@ -87,37 +86,37 @@ void EmbedContentController::HandleDoubleTap(const CSSPoint& aPoint,
}
}

void EmbedContentController::HandleSingleTap(const CSSPoint& aPoint,
void EmbedContentController::HandleSingleTap(const LayoutDevicePoint& aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid)
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(NewRunnableMethod<const CSSPoint &, Modifiers, const ScrollableLayerGuid &>(this,
&EmbedContentController::HandleSingleTap,
aPoint,
aModifiers,
aGuid));
mUILoop->PostTask(NewRunnableMethod<const LayoutDevicePoint &, Modifiers, const ScrollableLayerGuid &>(this,
&EmbedContentController::HandleSingleTap,
aPoint,
aModifiers,
aGuid));
} else if (mRenderFrame && !GetListener()->HandleSingleTap(convertIntPoint(aPoint))) {
Unused << mRenderFrame->SendHandleSingleTap(aPoint, aModifiers, aGuid);
}
}

void EmbedContentController::HandleLongTap(const CSSPoint& aPoint,
void EmbedContentController::HandleLongTap(const LayoutDevicePoint &aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid,
uint64_t aInputBlockId)
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(NewRunnableMethod<const CSSPoint &, Modifiers, const ScrollableLayerGuid &, uint64_t>(this,
&EmbedContentController::HandleLongTap,
aPoint,
aModifiers,
aGuid,
aInputBlockId));
mUILoop->PostTask(NewRunnableMethod<const LayoutDevicePoint &, Modifiers, const ScrollableLayerGuid &, uint64_t>(this,
&EmbedContentController::HandleLongTap,
aPoint,
aModifiers,
aGuid,
aInputBlockId));
} else if (mRenderFrame && !GetListener()->HandleLongTap(convertIntPoint(aPoint))) {
Unused << mRenderFrame->SendHandleLongTap(aPoint, aGuid, aInputBlockId);
}
Expand Down Expand Up @@ -178,7 +177,7 @@ void EmbedContentController::DoNotifyFlushComplete()
}
}

nsIntPoint EmbedContentController::convertIntPoint(const CSSPoint &aPoint)
nsIntPoint EmbedContentController::convertIntPoint(const LayoutDevicePoint &aPoint)
{
return nsIntPoint((int)nearbyint(aPoint.x), (int)nearbyint(aPoint.y));
}
Expand Down
8 changes: 4 additions & 4 deletions embedding/embedlite/embedthread/EmbedContentController.h
Expand Up @@ -63,9 +63,9 @@ class EmbedContentController : public mozilla::layers::GeckoContentController
private:
EmbedLiteViewListener *GetListener() const;

void HandleDoubleTap(const CSSPoint& aPoint, Modifiers aModifiers, const ScrollableLayerGuid& aGuid);
void HandleSingleTap(const CSSPoint& aPoint, Modifiers aModifiers, const ScrollableLayerGuid& aGuid);
void HandleLongTap(const CSSPoint& aPoint, Modifiers aModifiers, const ScrollableLayerGuid& aGuid, uint64_t aInputBlockId);
void HandleDoubleTap(const LayoutDevicePoint& aPoint, Modifiers aModifiers, const ScrollableLayerGuid& aGuid);
void HandleSingleTap(const LayoutDevicePoint& aPoint, Modifiers aModifiers, const ScrollableLayerGuid& aGuid);
void HandleLongTap(const LayoutDevicePoint& aPoint, Modifiers aModifiers, const ScrollableLayerGuid& aGuid, uint64_t aInputBlockId);

void DoRequestContentRepaint(const FrameMetrics& aFrameMetrics);
void DoSendScrollEvent(const FrameMetrics& aFrameMetrics);
Expand All @@ -75,7 +75,7 @@ class EmbedContentController : public mozilla::layers::GeckoContentController
void DoNotifyAPZStateChange(const mozilla::layers::ScrollableLayerGuid &aGuid, APZStateChange aChange, int aArg);
void DoNotifyFlushComplete();

nsIntPoint convertIntPoint(const CSSPoint &aPoint);
nsIntPoint convertIntPoint(const LayoutDevicePoint &aPoint);

MessageLoop* mUILoop;
EmbedLiteViewBaseParent* mRenderFrame;
Expand Down
29 changes: 29 additions & 0 deletions embedding/embedlite/utils/TabChildHelper.cpp
Expand Up @@ -513,6 +513,35 @@ TabChildHelper::ReportSizeUpdate(const LayoutDeviceIntRect &aRect)
mInnerSize = ViewAs<ScreenPixel>(size, PixelCastJustification::LayoutDeviceIsScreenForTabDims);
}

mozilla::CSSPoint
TabChildHelper::ApplyPointTransform(const LayoutDevicePoint& aPoint,
const mozilla::layers::ScrollableLayerGuid& aGuid,
bool *ok)
{
nsCOMPtr<nsIPresShell> presShell = GetPresContext()->GetPresShell();
if (!presShell) {
if (ok)
*ok = false;

LOGT("Failed to transform layout device point -- no nsIPresShell");
return mozilla::CSSPoint(0.0f, 0.0f);
}

if (!presShell->GetPresContext()) {
if (ok)
*ok = false;

LOGT("Failed to transform layout device point -- no nsPresContext");
return mozilla::CSSPoint(0.0f, 0.0f);
}

if (ok)
*ok = true;

mozilla::CSSToLayoutDeviceScale scale = presShell->GetPresContext()->CSSToDevPixelScale();
return APZCCallbackHelper::ApplyCallbackTransform(aPoint / scale, aGuid);
}

// -- nsITabChild --------------

NS_IMETHODIMP
Expand Down
9 changes: 9 additions & 0 deletions embedding/embedlite/utils/TabChildHelper.h
Expand Up @@ -22,6 +22,11 @@ class nsPresContext;
class nsIDOMWindowUtils;

namespace mozilla {

namespace layers {
struct ScrollableLayerGuid;
}

namespace embedlite {

class EmbedLiteViewChildIface;
Expand Down Expand Up @@ -66,6 +71,10 @@ class TabChildHelper : public mozilla::dom::TabChildBase,

void ReportSizeUpdate(const LayoutDeviceIntRect& aRect);

mozilla::CSSPoint ApplyPointTransform(const LayoutDevicePoint& aPoint,
const mozilla::layers::ScrollableLayerGuid& aGuid,
bool *ok);

protected:
virtual ~TabChildHelper();
nsIWidget* GetWidget(nsPoint* aOffset);
Expand Down

0 comments on commit dabf60d

Please sign in to comment.