mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 22:32:51 +00:00
Bug 1678505 - Expose ScrollableDirections and OverscrollDirecitons to GeckoView. r=botond,geckoview-reviewers,agi,aklotz
Differential Revision: https://phabricator.services.mozilla.com/D103420
This commit is contained in:
parent
cc24f3fbe2
commit
58d740803c
@ -91,6 +91,66 @@ public class PanZoomController {
|
||||
@WrapForJNI
|
||||
public static final int INPUT_RESULT_IGNORED = 3;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef(flag = true,
|
||||
value = { SCROLLABLE_FLAG_NONE, SCROLLABLE_FLAG_TOP, SCROLLABLE_FLAG_RIGHT,
|
||||
SCROLLABLE_FLAG_BOTTOM, SCROLLABLE_FLAG_LEFT })
|
||||
/* package */ @interface ScrollableDirections {}
|
||||
/**
|
||||
* Represents which directions can be scrolled in the scroll container where
|
||||
* an input event was handled.
|
||||
* This value is only useful in the case of {@link PanZoomController#INPUT_RESULT_HANDLED}.
|
||||
*/
|
||||
/* The container cannot be scrolled. */
|
||||
@WrapForJNI
|
||||
public static final int SCROLLABLE_FLAG_NONE = 0;
|
||||
/* The container cannot be scrolled to top */
|
||||
@WrapForJNI
|
||||
public static final int SCROLLABLE_FLAG_TOP = 1 << 0;
|
||||
/* The container cannot be scrolled to right */
|
||||
@WrapForJNI
|
||||
public static final int SCROLLABLE_FLAG_RIGHT = 1 << 1;
|
||||
/* The container cannot be scrolled to bottom */
|
||||
@WrapForJNI
|
||||
public static final int SCROLLABLE_FLAG_BOTTOM = 1 << 2;
|
||||
/* The container cannot be scrolled to left */
|
||||
@WrapForJNI
|
||||
public static final int SCROLLABLE_FLAG_LEFT = 1 << 3;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef(flag = true,
|
||||
value = { OVERSCROLL_FLAG_NONE, OVERSCROLL_FLAG_HORIZONTAL, OVERSCROLL_FLAG_VERTICAL })
|
||||
/* package */ @interface OverscrollDirections {}
|
||||
/**
|
||||
* Represents which directions can be over-scrolled in the scroll container where
|
||||
* an input event was handled.
|
||||
* This value is only useful in the case of {@link PanZoomController#INPUT_RESULT_HANDLED}.
|
||||
*/
|
||||
/* the container cannot be over-scrolled. */
|
||||
@WrapForJNI
|
||||
public static final int OVERSCROLL_FLAG_NONE = 0;
|
||||
/* the container can be over-scrolled horizontally. */
|
||||
@WrapForJNI
|
||||
public static final int OVERSCROLL_FLAG_HORIZONTAL = 1 << 0;
|
||||
/* the container can be over-scrolled vertically. */
|
||||
@WrapForJNI
|
||||
public static final int OVERSCROLL_FLAG_VERTICAL = 1 << 1;
|
||||
|
||||
@WrapForJNI
|
||||
public static class InputResultDetail {
|
||||
protected InputResultDetail(final @InputResult int aHandledResult,
|
||||
final @ScrollableDirections int aScrollableDirections,
|
||||
final @OverscrollDirections int aOverscrollDirections) {
|
||||
handledResult = aHandledResult;
|
||||
scrollableDirections = aScrollableDirections;
|
||||
overscrollDirections = aOverscrollDirections;
|
||||
}
|
||||
|
||||
public final @InputResult int handledResult;
|
||||
public final @ScrollableDirections int scrollableDirections;
|
||||
public final @OverscrollDirections int overscrollDirections;
|
||||
}
|
||||
|
||||
private SynthesizedEventState mPointerState;
|
||||
|
||||
private ArrayList<Pair<Integer, MotionEvent>> mQueuedEvents;
|
||||
@ -190,7 +250,7 @@ public class PanZoomController {
|
||||
@WrapForJNI(calledFrom = "ui")
|
||||
private native void handleMotionEvent(
|
||||
MotionEventData eventData, float screenX, float screenY,
|
||||
GeckoResult<Integer> result);
|
||||
GeckoResult<InputResultDetail> result);
|
||||
|
||||
@WrapForJNI(calledFrom = "ui")
|
||||
private native @InputResult int handleScrollEvent(
|
||||
@ -243,11 +303,12 @@ public class PanZoomController {
|
||||
handleMotionEvent(event, null);
|
||||
}
|
||||
|
||||
private void handleMotionEvent(final MotionEvent event, final GeckoResult<Integer> result) {
|
||||
private void handleMotionEvent(final MotionEvent event, final GeckoResult<InputResultDetail> result) {
|
||||
if (!mAttached) {
|
||||
mQueuedEvents.add(new Pair<>(EVENT_SOURCE_MOTION, event));
|
||||
if (result != null) {
|
||||
result.complete(INPUT_RESULT_HANDLED);
|
||||
result.complete(
|
||||
new InputResultDetail(INPUT_RESULT_HANDLED, SCROLLABLE_FLAG_NONE, OVERSCROLL_FLAG_NONE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -258,7 +319,8 @@ public class PanZoomController {
|
||||
mLastDownTime = event.getDownTime();
|
||||
} else if (mLastDownTime != event.getDownTime()) {
|
||||
if (result != null) {
|
||||
result.complete(INPUT_RESULT_UNHANDLED);
|
||||
result.complete(
|
||||
new InputResultDetail(INPUT_RESULT_UNHANDLED, SCROLLABLE_FLAG_NONE, OVERSCROLL_FLAG_NONE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -419,9 +481,9 @@ public class PanZoomController {
|
||||
return GeckoResult.fromValue(handleMouseEvent(event));
|
||||
}
|
||||
|
||||
final GeckoResult<Integer> result = new GeckoResult<>();
|
||||
final GeckoResult<InputResultDetail> result = new GeckoResult<>();
|
||||
handleMotionEvent(event, result);
|
||||
return result;
|
||||
return result.map(detail -> detail.handledResult);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/DataSurfaceHelpers.h"
|
||||
#include "mozilla/gfx/Types.h"
|
||||
#include "mozilla/layers/LayersTypes.h"
|
||||
#include "mozilla/layers/RenderTrace.h"
|
||||
#include "mozilla/widget/AndroidVsync.h"
|
||||
#include <algorithm>
|
||||
@ -457,8 +458,8 @@ class NPZCSupport final
|
||||
return result;
|
||||
}
|
||||
|
||||
static int32_t ConvertAPZHandledResult(APZHandledResult aHandledResult) {
|
||||
switch (aHandledResult.mPlace) {
|
||||
static int32_t ConvertAPZHandledPlace(APZHandledPlace aHandledPlace) {
|
||||
switch (aHandledPlace) {
|
||||
case APZHandledPlace::Unhandled:
|
||||
return INPUT_RESULT_UNHANDLED;
|
||||
case APZHandledPlace::HandledByRoot:
|
||||
@ -473,6 +474,43 @@ class NPZCSupport final
|
||||
return INPUT_RESULT_UNHANDLED;
|
||||
}
|
||||
|
||||
static int32_t ConvertSideBits(SideBits aSideBits) {
|
||||
int32_t ret = java::PanZoomController::SCROLLABLE_FLAG_NONE;
|
||||
if (aSideBits & SideBits::eTop) {
|
||||
ret |= java::PanZoomController::SCROLLABLE_FLAG_TOP;
|
||||
}
|
||||
if (aSideBits & SideBits::eRight) {
|
||||
ret |= java::PanZoomController::SCROLLABLE_FLAG_RIGHT;
|
||||
}
|
||||
if (aSideBits & SideBits::eBottom) {
|
||||
ret |= java::PanZoomController::SCROLLABLE_FLAG_BOTTOM;
|
||||
}
|
||||
if (aSideBits & SideBits::eLeft) {
|
||||
ret |= java::PanZoomController::SCROLLABLE_FLAG_LEFT;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ConvertScrollDirections(
|
||||
layers::ScrollDirections aScrollDirections) {
|
||||
int32_t ret = java::PanZoomController::OVERSCROLL_FLAG_NONE;
|
||||
if (aScrollDirections.contains(layers::HorizontalScrollDirection)) {
|
||||
ret |= java::PanZoomController::OVERSCROLL_FLAG_HORIZONTAL;
|
||||
}
|
||||
if (aScrollDirections.contains(layers::VerticalScrollDirection)) {
|
||||
ret |= java::PanZoomController::OVERSCROLL_FLAG_VERTICAL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static java::PanZoomController::InputResultDetail::LocalRef
|
||||
ConvertAPZHandledResult(const APZHandledResult& aHandledResult) {
|
||||
return java::PanZoomController::InputResultDetail::New(
|
||||
ConvertAPZHandledPlace(aHandledResult.mPlace),
|
||||
ConvertSideBits(aHandledResult.mScrollableDirections),
|
||||
ConvertScrollDirections(aHandledResult.mOverscrollDirections));
|
||||
}
|
||||
|
||||
public:
|
||||
int32_t HandleMouseEvent(int32_t aAction, int64_t aTime, int32_t aMetaState,
|
||||
float aX, float aY, int buttons) {
|
||||
@ -783,8 +821,10 @@ class NPZCSupport final
|
||||
|
||||
if (!controller) {
|
||||
if (aReturnResult) {
|
||||
aReturnResult->Complete(
|
||||
java::sdk::Integer::ValueOf(INPUT_RESULT_UNHANDLED));
|
||||
aReturnResult->Complete(java::PanZoomController::InputResultDetail::New(
|
||||
INPUT_RESULT_UNHANDLED,
|
||||
java::PanZoomController::SCROLLABLE_FLAG_NONE,
|
||||
java::PanZoomController::OVERSCROLL_FLAG_NONE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -793,8 +833,9 @@ class NPZCSupport final
|
||||
controller->InputBridge()->ReceiveInputEvent(aInput);
|
||||
if (result.GetStatus() == nsEventStatus_eConsumeNoDefault) {
|
||||
if (aReturnResult) {
|
||||
aReturnResult->Complete(
|
||||
java::sdk::Integer::ValueOf(INPUT_RESULT_IGNORED));
|
||||
aReturnResult->Complete(java::PanZoomController::InputResultDetail::New(
|
||||
INPUT_RESULT_IGNORED, java::PanZoomController::SCROLLABLE_FLAG_NONE,
|
||||
java::PanZoomController::OVERSCROLL_FLAG_NONE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -817,16 +858,22 @@ class NPZCSupport final
|
||||
switch (result.GetStatus()) {
|
||||
case nsEventStatus_eIgnore:
|
||||
aReturnResult->Complete(
|
||||
java::sdk::Integer::ValueOf(INPUT_RESULT_UNHANDLED));
|
||||
java::PanZoomController::InputResultDetail::New(
|
||||
INPUT_RESULT_UNHANDLED,
|
||||
java::PanZoomController::SCROLLABLE_FLAG_NONE,
|
||||
java::PanZoomController::OVERSCROLL_FLAG_NONE));
|
||||
break;
|
||||
case nsEventStatus_eConsumeDoDefault:
|
||||
aReturnResult->Complete(java::sdk::Integer::ValueOf(
|
||||
ConvertAPZHandledResult(result.GetHandledResult().value())));
|
||||
aReturnResult->Complete(
|
||||
ConvertAPZHandledResult(result.GetHandledResult().value()));
|
||||
break;
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("Unexpected nsEventStatus");
|
||||
aReturnResult->Complete(
|
||||
java::sdk::Integer::ValueOf(INPUT_RESULT_UNHANDLED));
|
||||
java::PanZoomController::InputResultDetail::New(
|
||||
INPUT_RESULT_UNHANDLED,
|
||||
java::PanZoomController::SCROLLABLE_FLAG_NONE,
|
||||
java::PanZoomController::OVERSCROLL_FLAG_NONE));
|
||||
break;
|
||||
}
|
||||
return;
|
||||
@ -836,9 +883,8 @@ class NPZCSupport final
|
||||
controller->AddInputBlockCallback(
|
||||
result.mInputBlockId,
|
||||
[aReturnResult = java::GeckoResult::GlobalRef(aReturnResult)](
|
||||
uint64_t aInputBlockId, APZHandledResult aHandledResult) {
|
||||
aReturnResult->Complete(java::sdk::Integer::ValueOf(
|
||||
ConvertAPZHandledResult(aHandledResult)));
|
||||
uint64_t aInputBlockId, const APZHandledResult& aHandledResult) {
|
||||
aReturnResult->Complete(ConvertAPZHandledResult(aHandledResult));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user