merge mozilla-central to autoland. r=merge a=merge

This commit is contained in:
Sebastian Hengst 2017-10-01 11:38:25 +02:00
Родитель 5afa7795ae 2980334050
Коммит e15ee0dcab
2 изменённых файлов: 91 добавлений и 0 удалений

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

@ -172,6 +172,11 @@ class WidgetRenderingContext;
// Gestures support
//
// mGestureState is used to detect when Cocoa has called both
// magnifyWithEvent and rotateWithEvent within the same
// beginGestureWithEvent and endGestureWithEvent sequence. We
// discard the spurious gesture event so as not to confuse Gecko.
//
// mCumulativeMagnification keeps track of the total amount of
// magnification peformed during a magnify gesture so that we can
// send that value with the final MozMagnifyGesture event.
@ -182,6 +187,7 @@ class WidgetRenderingContext;
enum {
eGestureState_None,
eGestureState_StartGesture,
eGestureState_MagnifyGesture,
eGestureState_RotateGesture
} mGestureState;
float mCumulativeMagnification;
@ -247,6 +253,7 @@ class WidgetRenderingContext;
*/
- (void)swipeWithEvent:(NSEvent *)anEvent;
- (void)beginGestureWithEvent:(NSEvent *)anEvent;
- (void)magnifyWithEvent:(NSEvent *)anEvent;
- (void)smartMagnifyWithEvent:(NSEvent *)anEvent;
- (void)rotateWithEvent:(NSEvent *)anEvent;
- (void)endGestureWithEvent:(NSEvent *)anEvent;

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

@ -4200,6 +4200,77 @@ NSEvent* gLastDragMouseDownEvent = nil;
NS_OBJC_END_TRY_ABORT_BLOCK;
}
// Pinch zoom gesture.
- (void)magnifyWithEvent:(NSEvent *)anEvent
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
if (!anEvent || !mGeckoChild ||
[self beginOrEndGestureForEventPhase:anEvent]) {
return;
}
nsAutoRetainCocoaObject kungFuDeathGrip(self);
float deltaZ = [anEvent deltaZ];
EventMessage msg;
switch (mGestureState) {
case eGestureState_StartGesture:
msg = eMagnifyGestureStart;
mGestureState = eGestureState_MagnifyGesture;
break;
case eGestureState_MagnifyGesture:
msg = eMagnifyGestureUpdate;
break;
case eGestureState_None:
case eGestureState_RotateGesture:
default:
return;
}
// This sends the pinch gesture value as a fake wheel event that has the
// control key pressed so that pages can implement custom pinch gesture
// handling. It may seem strange that this doesn't use a wheel event with
// the deltaZ property set, but this matches Chrome's behavior as described
// at https://code.google.com/p/chromium/issues/detail?id=289887
//
// The intent of the formula below is to produce numbers similar to Chrome's
// implementation of this feature. Chrome implements deltaY using the formula
// "-100 * log(1 + [event magnification])" which is unfortunately incorrect.
// All deltas for a single pinch gesture should sum to 0 if the start and end
// of a pinch gesture end up in the same place. This doesn't happen in Chrome
// because they followed Apple's misleading documentation, which implies that
// "1 + [event magnification]" is the scale factor. The scale factor is
// instead "pow(ratio, [event magnification])" so "[event magnification]" is
// already in log space.
//
// The multiplication by the backing scale factor below counteracts the
// division by the backing scale factor in WheelEvent.
WidgetWheelEvent geckoWheelEvent(true, EventMessage::eWheel, mGeckoChild);
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoWheelEvent];
double backingScale = mGeckoChild->BackingScaleFactor();
geckoWheelEvent.mDeltaY = -100.0 * [anEvent magnification] * backingScale;
geckoWheelEvent.mModifiers |= MODIFIER_CONTROL;
mGeckoChild->DispatchWindowEvent(geckoWheelEvent);
// If the fake wheel event wasn't stopped, then send a normal magnify event.
if (!geckoWheelEvent.mFlags.mDefaultPrevented) {
WidgetSimpleGestureEvent geckoEvent(true, msg, mGeckoChild);
geckoEvent.mDelta = deltaZ;
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
mGeckoChild->DispatchWindowEvent(geckoEvent);
// Keep track of the cumulative magnification for the final "magnify" event.
mCumulativeMagnification += deltaZ;
}
NS_OBJC_END_TRY_ABORT_BLOCK;
}
// Smart zoom gesture, i.e. two-finger double tap on trackpads.
- (void)smartMagnifyWithEvent:(NSEvent *)anEvent
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
@ -4250,6 +4321,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
break;
case eGestureState_None:
case eGestureState_MagnifyGesture:
default:
return;
}
@ -4332,6 +4404,18 @@ NSEvent* gLastDragMouseDownEvent = nil;
nsAutoRetainCocoaObject kungFuDeathGrip(self);
switch (mGestureState) {
case eGestureState_MagnifyGesture:
{
// Setup the "magnify" event.
WidgetSimpleGestureEvent geckoEvent(true, eMagnifyGesture, mGeckoChild);
geckoEvent.mDelta = mCumulativeMagnification;
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
// Send the event.
mGeckoChild->DispatchWindowEvent(geckoEvent);
}
break;
case eGestureState_RotateGesture:
{
// Setup the "rotate" event.