Commit 477bacfd authored by erikchen@chromium.org's avatar erikchen@chromium.org

Selectively disable rubber banding on mac.

The logic for handling 2-finger swipes should be:
1. If a 2-finger swipe can scroll the content (or iframe), it should do so.
2. If the 2-finger swipe can cause history navigation, it should do so.
3. The 2-finger swipe should rubber-band the content view.

(2) is handled by the embedder, and (1 & 3) by the renderer. Right now, the
renderer is passed an IPC, and it tries to do (1), and then it tries to do (3).
I've added a new IPC so that there are flags that prevent the renderer from
performing (3) under specific circumstances.

There was an existing mechanism to determine whether the renderer should try
(3), but it was fragile, incorrectly used, and insufficient for newer features
in chrome - the user can cancel a history swipe without cancelling the gesture,
at which point rubber-banding should be possible again. I've simplified and
fixed the logic inside ScrollElasticityController.mm to reflect the desired
behavior.

I modified the IPC InputMsg_HandleInputEvent to include 2 additional bools:
can_rubberband_left and can_rubberband_right. Blink will attempt to consume the
event to scroll the content view, and will only attempt to rubberband if bools
allow it too.

This is part 1 of a two-part change. It only includes the IPC change. The
changes to ScrollElasticityController will land after I've updated Chromium to
use the new API.

BUG=321437

Review URL: https://codereview.chromium.org/197213011

git-svn-id: svn://svn.chromium.org/blink/trunk@170102 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d408d51e
......@@ -73,6 +73,8 @@ public:
, m_scrollCount(0)
, m_unacceleratedScrollingDeltaX(0)
, m_unacceleratedScrollingDeltaY(0)
, m_canRubberbandLeft(true)
, m_canRubberbandRight(true)
#endif
{
}
......@@ -94,6 +96,8 @@ public:
, m_scrollCount(0)
, m_unacceleratedScrollingDeltaX(0)
, m_unacceleratedScrollingDeltaY(0)
, m_canRubberbandLeft(true)
, m_canRubberbandRight(true)
#endif
{
}
......@@ -132,6 +136,8 @@ public:
float unacceleratedScrollingDeltaX() const { return m_unacceleratedScrollingDeltaX; }
float unacceleratedScrollingDeltaY() const { return m_unacceleratedScrollingDeltaY; }
bool useLatchedEventNode() const { return m_momentumPhase == PlatformWheelEventPhaseBegan || m_momentumPhase == PlatformWheelEventPhaseChanged; }
bool canRubberbandLeft() const { return m_canRubberbandLeft; }
bool canRubberbandRight() const { return m_canRubberbandRight; }
#else
bool useLatchedEventNode() const { return false; }
#endif
......@@ -152,6 +158,8 @@ protected:
unsigned m_scrollCount;
float m_unacceleratedScrollingDeltaX;
float m_unacceleratedScrollingDeltaY;
bool m_canRubberbandLeft;
bool m_canRubberbandRight;
#endif
};
......
......@@ -52,7 +52,7 @@ struct SameSizeAsWebMouseEvent : public SameSizeAsWebInputEvent {
};
struct SameSizeAsWebMouseWheelEvent : public SameSizeAsWebMouseEvent {
int mousewheelData[10];
int mousewheelData[12];
};
struct SameSizeAsWebGestureEvent : public SameSizeAsWebInputEvent {
......
......@@ -155,6 +155,8 @@ PlatformWheelEventBuilder::PlatformWheelEventBuilder(Widget* widget, const WebMo
m_scrollCount = 0;
m_unacceleratedScrollingDeltaX = e.deltaX;
m_unacceleratedScrollingDeltaY = e.deltaY;
m_canRubberbandLeft = e.canRubberbandLeft;
m_canRubberbandRight = e.canRubberbandRight;
#endif
}
......
......@@ -966,6 +966,11 @@ static WebMouseWheelEvent::Phase momentumPhaseForEvent(NSEvent *event)
}
WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(NSEvent* event, NSView* view)
{
return mouseWheelEvent(event, view, true, true);
}
WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(NSEvent* event, NSView* view, bool canRubberbandLeft, bool canRubberbandRight)
{
WebMouseWheelEvent result;
......@@ -976,6 +981,9 @@ WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(NSEvent* event, NSView*
setWebEventLocationFromEventInView(&result, event, view);
result.canRubberbandLeft = canRubberbandLeft;
result.canRubberbandRight = canRubberbandRight;
// Of Mice and Men
// ---------------
//
......
......@@ -361,6 +361,24 @@ public:
Phase phase;
Phase momentumPhase;
// See comment at the top of the file for why an int is used here.
// Rubberbanding is an OSX visual effect. When a user scrolls the content
// area with a track pad, and the content area is already at its limit in
// the direction being scrolled, the entire content area is allowed to
// scroll slightly off screen, revealing a grey background. When the user
// lets go, the content area snaps back into place. Blink is responsible
// for this rubberbanding effect, but the embedder may wish to disable
// rubber banding in the left or right direction, if the scroll should have
// an alternate effect. The common case is that a scroll in the left or
// right directions causes a back or forwards navigation, respectively.
//
// These flags prevent rubber banding from starting in a given direction,
// but have no effect on an ongoing rubber banding. A rubber banding that
// started in the vertical direction is allowed to continue in the right
// direction, even if canRubberbandRight is 0.
int canRubberbandLeft;
int canRubberbandRight;
WebMouseWheelEvent(unsigned sizeParam = sizeof(WebMouseWheelEvent))
: WebMouseEvent(sizeParam)
, deltaX(0.0f)
......@@ -373,6 +391,8 @@ public:
, hasPreciseScrollingDeltas(false)
, phase(PhaseNone)
, momentumPhase(PhaseNone)
, canRubberbandLeft(true)
, canRubberbandRight(true)
{
}
};
......
......@@ -53,7 +53,9 @@ public:
BLINK_EXPORT static WebKeyboardEvent keyboardEvent(NSEvent*);
BLINK_EXPORT static WebKeyboardEvent keyboardEvent(wchar_t character, int modifiers, double timeStampSeconds);
BLINK_EXPORT static WebMouseEvent mouseEvent(NSEvent*, NSView*);
// TODO(erikchen): Remove this method once chrome has been updated to use the method with 4 parameters.
BLINK_EXPORT static WebMouseWheelEvent mouseWheelEvent(NSEvent*, NSView*);
BLINK_EXPORT static WebMouseWheelEvent mouseWheelEvent(NSEvent*, NSView*, bool canRubberbandLeft, bool canRubberbandRight);
BLINK_EXPORT static WebGestureEvent gestureEvent(NSEvent *, NSView *);
BLINK_EXPORT static bool isSystemKeyEvent(const WebKeyboardEvent&);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment