Bug 1035356 - Make ReceiveInputEvent(InputData...) do in-place modifications of the event to DOM space. r=mstange r=botond

This commit is contained in:
Kartikaya Gupta 2014-07-08 14:55:52 -04:00
Родитель 455c5b1b12
Коммит d2bd117d55
5 изменённых файлов: 76 добавлений и 38 удалений

Просмотреть файл

@ -365,8 +365,16 @@ ApplyTransform(nsIntPoint* aPoint, const gfx3DMatrix& aMatrix)
aPoint->y = NS_lround(result.y);
}
/*static*/ template<class T> void
TransformScreenToGecko(T* aPoint, AsyncPanZoomController* aApzc, APZCTreeManager* aApzcTm)
{
gfx3DMatrix transformToApzc, transformToGecko;
aApzcTm->GetInputTransforms(aApzc, transformToApzc, transformToGecko);
ApplyTransform(aPoint, transformToApzc * transformToGecko);
}
nsEventStatus
APZCTreeManager::ReceiveInputEvent(const InputData& aEvent,
APZCTreeManager::ReceiveInputEvent(InputData& aEvent,
ScrollableLayerGuid* aOutTargetGuid)
{
nsEventStatus result = nsEventStatus_eIgnore;
@ -374,11 +382,11 @@ APZCTreeManager::ReceiveInputEvent(const InputData& aEvent,
gfx3DMatrix transformToGecko;
switch (aEvent.mInputType) {
case MULTITOUCH_INPUT: {
MultiTouchInput touchInput = aEvent.AsMultiTouchInput();
MultiTouchInput& touchInput = aEvent.AsMultiTouchInput();
result = ProcessTouchInput(touchInput, aOutTargetGuid);
break;
} case PANGESTURE_INPUT: {
const PanGestureInput& panInput = aEvent.AsPanGestureInput();
PanGestureInput& panInput = aEvent.AsPanGestureInput();
bool inOverscrolledApzc = false;
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(panInput.mPanStartPoint,
&inOverscrolledApzc);
@ -387,11 +395,19 @@ APZCTreeManager::ReceiveInputEvent(const InputData& aEvent,
panInput.mType == PanGestureInput::PANGESTURE_MOMENTUMSTART) {
BuildOverscrollHandoffChain(apzc);
}
apzc->GetGuid(aOutTargetGuid);
GetInputTransforms(apzc, transformToApzc, transformToGecko);
// When passing the event to the APZC, we need to apply a different
// transform than the one in TransformScreenToGecko, so we need to
// make a copy of the event.
PanGestureInput inputForApzc(panInput);
GetInputTransforms(apzc, transformToApzc, transformToGecko);
ApplyTransform(&(inputForApzc.mPanStartPoint), transformToApzc);
result = apzc->ReceiveInputEvent(inputForApzc);
// Update the out-parameters so they are what the caller expects.
apzc->GetGuid(aOutTargetGuid);
TransformScreenToGecko(&(panInput.mPanStartPoint), apzc, this);
if (panInput.mType == PanGestureInput::PANGESTURE_END ||
panInput.mType == PanGestureInput::PANGESTURE_MOMENTUMEND) {
ClearOverscrollHandoffChain();
@ -399,32 +415,44 @@ APZCTreeManager::ReceiveInputEvent(const InputData& aEvent,
}
break;
} case PINCHGESTURE_INPUT: {
const PinchGestureInput& pinchInput = aEvent.AsPinchGestureInput();
PinchGestureInput& pinchInput = aEvent.AsPinchGestureInput();
bool inOverscrolledApzc = false;
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(pinchInput.mFocusPoint,
&inOverscrolledApzc);
if (apzc) {
apzc->GetGuid(aOutTargetGuid);
GetInputTransforms(apzc, transformToApzc, transformToGecko);
// When passing the event to the APZC, we need to apply a different
// transform than the one in TransformScreenToGecko, so we need to
// make a copy of the event.
PinchGestureInput inputForApzc(pinchInput);
GetInputTransforms(apzc, transformToApzc, transformToGecko);
ApplyTransform(&(inputForApzc.mFocusPoint), transformToApzc);
apzc->ReceiveInputEvent(inputForApzc);
// Update the out-parameters so they are what the caller expects.
apzc->GetGuid(aOutTargetGuid);
TransformScreenToGecko(&(pinchInput.mFocusPoint), apzc, this);
}
result = inOverscrolledApzc ? nsEventStatus_eConsumeNoDefault
: apzc ? nsEventStatus_eConsumeDoDefault
: nsEventStatus_eIgnore;
break;
} case TAPGESTURE_INPUT: {
const TapGestureInput& tapInput = aEvent.AsTapGestureInput();
TapGestureInput& tapInput = aEvent.AsTapGestureInput();
bool inOverscrolledApzc = false;
nsRefPtr<AsyncPanZoomController> apzc = GetTargetAPZC(ScreenPoint(tapInput.mPoint),
&inOverscrolledApzc);
if (apzc) {
apzc->GetGuid(aOutTargetGuid);
GetInputTransforms(apzc, transformToApzc, transformToGecko);
// When passing the event to the APZC, we need to apply a different
// transform than the one in TransformScreenToGecko, so we need to
// make a copy of the event.
TapGestureInput inputForApzc(tapInput);
GetInputTransforms(apzc, transformToApzc, transformToGecko);
ApplyTransform(&(inputForApzc.mPoint), transformToApzc);
apzc->ReceiveInputEvent(inputForApzc);
// Update the out-parameters so they are what the caller expects.
apzc->GetGuid(aOutTargetGuid);
TransformScreenToGecko(&(tapInput.mPoint), apzc, this);
}
result = inOverscrolledApzc ? nsEventStatus_eConsumeNoDefault
: apzc ? nsEventStatus_eConsumeDoDefault

Просмотреть файл

@ -122,11 +122,16 @@ public:
* based on what type of input it is. For example, a PinchGestureEvent will
* cause scaling. This should only be called externally to this class.
*
* @param aEvent input event object, will not be modified
* This function transforms |aEvent| to have its coordinates in DOM space.
* This is so that the event can be passed through the DOM and content can
* handle them. The event may need to be converted to a WidgetInputEvent
* by the caller if it wants to do this.
*
* @param aEvent input event object; is modified in-place
* @param aOutTargetGuid returns the guid of the apzc this event was
* delivered to. May be null.
*/
nsEventStatus ReceiveInputEvent(const InputData& aEvent,
nsEventStatus ReceiveInputEvent(InputData& aEvent,
ScrollableLayerGuid* aOutTargetGuid);
/**

Просмотреть файл

@ -43,6 +43,11 @@ class TapGestureInput;
{ \
NS_ABORT_IF_FALSE(mInputType == enumID, "Invalid cast of InputData."); \
return (const type&) *this; \
} \
type& As##type() \
{ \
NS_ABORT_IF_FALSE(mInputType == enumID, "Invalid cast of InputData."); \
return (type&) *this; \
}
/** Base input data class. Should never be instantiated. */

Просмотреть файл

@ -876,7 +876,7 @@ Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent(JNIEnv* env,
APZCTreeManager *controller = nsWindow::GetAPZCTreeManager();
if (controller) {
AndroidGeckoEvent* wrapper = AndroidGeckoEvent::MakeFromJavaObject(env, event);
const MultiTouchInput& input = wrapper->MakeMultiTouchInput(nsWindow::TopWindow());
MultiTouchInput input = wrapper->MakeMultiTouchInput(nsWindow::TopWindow());
delete wrapper;
if (input.mType >= 0) {
controller->ReceiveInputEvent(input, nullptr);

Просмотреть файл

@ -5206,15 +5206,15 @@ static int32_t RoundUp(double aDouble)
// animations. They are only dispatched on 10.8 or later, and only by
// relatively modern devices.
if (phase == NSEventPhaseMayBegin) {
apzctm->ReceiveInputEvent(PanGestureInput(PanGestureInput::PANGESTURE_MAYSTART,
eventTime, eventTimeStamp, location,
ScreenPoint(0, 0), 0), &guid);
PanGestureInput panInput(PanGestureInput::PANGESTURE_MAYSTART, eventTime,
eventTimeStamp, location, ScreenPoint(0, 0), 0);
apzctm->ReceiveInputEvent(panInput, &guid);
return;
}
if (phase == NSEventPhaseCancelled) {
apzctm->ReceiveInputEvent(PanGestureInput(PanGestureInput::PANGESTURE_CANCELLED,
eventTime, eventTimeStamp, location,
ScreenPoint(0, 0), 0), &guid);
PanGestureInput panInput(PanGestureInput::PANGESTURE_CANCELLED, eventTime,
eventTimeStamp, location, ScreenPoint(0, 0), 0);
apzctm->ReceiveInputEvent(panInput, &guid);
return;
}
@ -5229,36 +5229,36 @@ static int32_t RoundUp(double aDouble)
momentumPhase == NSEventPhaseNone && delta != ScreenPoint(0, 0));
if (phase == NSEventPhaseBegan || isLegacyScroll) {
apzctm->ReceiveInputEvent(PanGestureInput(PanGestureInput::PANGESTURE_START,
eventTime, eventTimeStamp, location,
ScreenPoint(0, 0), 0), &guid);
PanGestureInput panInput(PanGestureInput::PANGESTURE_START, eventTime,
eventTimeStamp, location, ScreenPoint(0, 0), 0);
apzctm->ReceiveInputEvent(panInput, &guid);
}
if (momentumPhase == NSEventPhaseNone && delta != ScreenPoint(0, 0)) {
apzctm->ReceiveInputEvent(PanGestureInput(PanGestureInput::PANGESTURE_PAN,
eventTime, eventTimeStamp, location,
delta, 0), &guid);
PanGestureInput panInput(PanGestureInput::PANGESTURE_PAN, eventTime,
eventTimeStamp, location, delta, 0);
apzctm->ReceiveInputEvent(panInput, &guid);
}
if (phase == NSEventPhaseEnded || isLegacyScroll) {
apzctm->ReceiveInputEvent(PanGestureInput(PanGestureInput::PANGESTURE_END,
eventTime, eventTimeStamp, location,
ScreenPoint(0, 0), 0), &guid);
PanGestureInput panInput(PanGestureInput::PANGESTURE_END, eventTime,
eventTimeStamp, location, ScreenPoint(0, 0), 0);
apzctm->ReceiveInputEvent(panInput, &guid);
}
// Any device that can dispatch momentum events supports all three momentum phases.
if (momentumPhase == NSEventPhaseBegan) {
apzctm->ReceiveInputEvent(PanGestureInput(PanGestureInput::PANGESTURE_MOMENTUMSTART,
eventTime, eventTimeStamp, location,
ScreenPoint(0, 0), 0), &guid);
PanGestureInput panInput(PanGestureInput::PANGESTURE_MOMENTUMSTART, eventTime,
eventTimeStamp, location, ScreenPoint(0, 0), 0);
apzctm->ReceiveInputEvent(panInput, &guid);
}
if (momentumPhase == NSEventPhaseChanged && delta != ScreenPoint(0, 0)) {
apzctm->ReceiveInputEvent(PanGestureInput(PanGestureInput::PANGESTURE_MOMENTUMPAN,
eventTime, eventTimeStamp, location,
delta, 0), &guid);
PanGestureInput panInput(PanGestureInput::PANGESTURE_MOMENTUMPAN, eventTime,
eventTimeStamp, location, delta, 0);
apzctm->ReceiveInputEvent(panInput, &guid);
}
if (momentumPhase == NSEventPhaseEnded) {
apzctm->ReceiveInputEvent(PanGestureInput(PanGestureInput::PANGESTURE_MOMENTUMEND,
eventTime, eventTimeStamp, location,
ScreenPoint(0, 0), 0), &guid);
PanGestureInput panInput(PanGestureInput::PANGESTURE_MOMENTUMEND, eventTime,
eventTimeStamp, location, ScreenPoint(0, 0), 0);
apzctm->ReceiveInputEvent(panInput, &guid);
}
}
}