mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 574663 - Mark scroll events that are sent by touchpad momentum scrolling after the finger has left the touchpad with a kIsMomentum flag and prevent these events from changing the zoom factor. r=josh, r=smaug
This commit is contained in:
parent
3dc6725ddf
commit
a1a5075923
@ -2944,15 +2944,18 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (aEvent->message == NS_MOUSE_PIXEL_SCROLL) {
|
if (aEvent->message == NS_MOUSE_PIXEL_SCROLL) {
|
||||||
if (action == MOUSE_SCROLL_N_LINES) {
|
if (action == MOUSE_SCROLL_N_LINES ||
|
||||||
|
(msEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum)) {
|
||||||
action = MOUSE_SCROLL_PIXELS;
|
action = MOUSE_SCROLL_PIXELS;
|
||||||
} else {
|
} else {
|
||||||
// Do not scroll pixels when zooming
|
// Do not scroll pixels when zooming
|
||||||
action = -1;
|
action = -1;
|
||||||
}
|
}
|
||||||
} else if (msEvent->scrollFlags & nsMouseScrollEvent::kHasPixels) {
|
} else if (msEvent->scrollFlags & nsMouseScrollEvent::kHasPixels) {
|
||||||
if (action == MOUSE_SCROLL_N_LINES) {
|
if (action == MOUSE_SCROLL_N_LINES ||
|
||||||
// We shouldn't scroll lines when a pixel scroll event will follow.
|
(msEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum)) {
|
||||||
|
// Don't scroll lines when a pixel scroll event will follow.
|
||||||
|
// Also, don't do history scrolling or zooming for momentum scrolls.
|
||||||
action = -1;
|
action = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ _TEST_FILES = \
|
|||||||
test_bug547996-1.html \
|
test_bug547996-1.html \
|
||||||
test_bug547996-2.xhtml \
|
test_bug547996-2.xhtml \
|
||||||
test_bug556493.html \
|
test_bug556493.html \
|
||||||
|
test_bug574663.html \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
_CHROME_FILES = \
|
_CHROME_FILES = \
|
||||||
|
135
content/events/test/test_bug574663.html
Normal file
135
content/events/test/test_bug574663.html
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=574663
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<title>Test for Bug 574663</title>
|
||||||
|
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||||
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=574663">Mozilla Bug 574663</a>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<pre id="test">
|
||||||
|
<script type="application/javascript;version=1.7">
|
||||||
|
|
||||||
|
/** Test for Bug 574663 **/
|
||||||
|
|
||||||
|
// This test depends on general.smoothScroll being off.
|
||||||
|
|
||||||
|
function sendTouchpadScrollMotion(scrollbox, direction, ctrl, momentum) {
|
||||||
|
var win = scrollbox.ownerDocument.defaultView;
|
||||||
|
let event = {
|
||||||
|
'type': "DOMMouseScroll",
|
||||||
|
'axis': "vertical",
|
||||||
|
'delta': direction,
|
||||||
|
'hasPixels': true,
|
||||||
|
'ctrlKey': ctrl,
|
||||||
|
'isMomentum': momentum,
|
||||||
|
};
|
||||||
|
// first a line scroll
|
||||||
|
synthesizeMouseScroll(scrollbox, 10, 10, event, win);
|
||||||
|
// then 5 pixel scrolls
|
||||||
|
event.delta *= 3;
|
||||||
|
event.type = "MozMousePixelScroll";
|
||||||
|
event.hasPixels = false;
|
||||||
|
for (let i = 0; i < 5; ++i) {
|
||||||
|
synthesizeMouseScroll(scrollbox, 10, 10, event, win);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
var win = open('data:text/html,<!DOCTYPE html>\n' +
|
||||||
|
'<div id="scrollbox" style="height: 100px; overflow: auto;">' +
|
||||||
|
' <div style="height: 1000px;"></div>' +
|
||||||
|
'</div>', '_blank');
|
||||||
|
SimpleTest.waitForFocus(function () {
|
||||||
|
var scrollbox = win.document.getElementById("scrollbox");
|
||||||
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
let winUtils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||||
|
let outstandingTests = [
|
||||||
|
[false, false],
|
||||||
|
[false, true],
|
||||||
|
[true, false],
|
||||||
|
[true, true],
|
||||||
|
];
|
||||||
|
function nextTest() {
|
||||||
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
if (!outstandingTests.length) {
|
||||||
|
win.close();
|
||||||
|
clearPrefs();
|
||||||
|
SimpleTest.finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let [ctrlKey, isMomentum] = outstandingTests.shift();
|
||||||
|
let scrollTopBefore = scrollbox.scrollTop;
|
||||||
|
let zoomFactorBefore = winUtils.screenPixelsPerCSSPixel;
|
||||||
|
sendTouchpadScrollMotion(scrollbox, 1, ctrlKey, isMomentum);
|
||||||
|
|
||||||
|
SimpleTest.executeSoon(function () {
|
||||||
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
if (!ctrlKey) {
|
||||||
|
let postfix = isMomentum ? ", even after releasing the touchpad" : "";
|
||||||
|
// Normal scroll: scroll
|
||||||
|
is(winUtils.screenPixelsPerCSSPixel, zoomFactorBefore, "Normal scrolling shouldn't change zoom" + postfix);
|
||||||
|
isnot(scrollbox.scrollTop, scrollTopBefore, "Normal scrolling should scroll" + postfix);
|
||||||
|
} else {
|
||||||
|
if (!isMomentum) {
|
||||||
|
isnot(winUtils.screenPixelsPerCSSPixel, zoomFactorBefore, "Ctrl-scrolling should zoom while the user is touching the touchpad");
|
||||||
|
is(scrollbox.scrollTop, scrollTopBefore, "Ctrl-scrolling shouldn't scroll while the user is touching the touchpad");
|
||||||
|
} else {
|
||||||
|
is(winUtils.screenPixelsPerCSSPixel, zoomFactorBefore, "Momentum scrolling shouldn't zoom, even when pressing Ctrl");
|
||||||
|
isnot(scrollbox.scrollTop, scrollTopBefore, "Momentum scrolling should scroll, even when pressing Ctrl");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Revert the effect.
|
||||||
|
sendTouchpadScrollMotion(scrollbox, -1, ctrlKey, isMomentum);
|
||||||
|
SimpleTest.executeSoon(nextTest);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
nextTest();
|
||||||
|
}, win);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initPrefs()
|
||||||
|
{
|
||||||
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].
|
||||||
|
getService(Components.interfaces.nsIPrefBranch2);
|
||||||
|
// Disables the app level scroll acceleration
|
||||||
|
prefSvc.setIntPref("mousewheel.acceleration.start", -1);
|
||||||
|
prefSvc.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearPrefs()
|
||||||
|
{
|
||||||
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].
|
||||||
|
getService(Components.interfaces.nsIPrefBranch2);
|
||||||
|
|
||||||
|
if (prefSvc.prefHasUserValue("mousewheel.acceleration.start"))
|
||||||
|
prefSvc.clearUserPref("mousewheel.acceleration.start");
|
||||||
|
if (prefSvc.prefHasUserValue("mousewheel.system_scroll_override_on_root_content.enabled"))
|
||||||
|
prefSvc.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload = function () {
|
||||||
|
initPrefs();
|
||||||
|
SimpleTest.executeSoon(runTest);
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -249,6 +249,8 @@ function synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
|
|||||||
*
|
*
|
||||||
* 'hasPixels' specifies whether kHasPixels should be set in the scrollFlags.
|
* 'hasPixels' specifies whether kHasPixels should be set in the scrollFlags.
|
||||||
*
|
*
|
||||||
|
* 'isMomentum' specifies whether kIsMomentum should be set in the scrollFlags.
|
||||||
|
*
|
||||||
* aWindow is optional, and defaults to the current window object.
|
* aWindow is optional, and defaults to the current window object.
|
||||||
*/
|
*/
|
||||||
function synthesizeMouseScroll(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
|
function synthesizeMouseScroll(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
|
||||||
@ -265,6 +267,7 @@ function synthesizeMouseScroll(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
|
|||||||
const kIsVertical = 0x02;
|
const kIsVertical = 0x02;
|
||||||
const kIsHorizontal = 0x04;
|
const kIsHorizontal = 0x04;
|
||||||
const kHasPixels = 0x08;
|
const kHasPixels = 0x08;
|
||||||
|
const kIsMomentum = 0x40;
|
||||||
|
|
||||||
var button = aEvent.button || 0;
|
var button = aEvent.button || 0;
|
||||||
var modifiers = _parseModifiers(aEvent);
|
var modifiers = _parseModifiers(aEvent);
|
||||||
@ -280,6 +283,9 @@ function synthesizeMouseScroll(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
|
|||||||
if (aEvent.hasPixels) {
|
if (aEvent.hasPixels) {
|
||||||
scrollFlags |= kHasPixels;
|
scrollFlags |= kHasPixels;
|
||||||
}
|
}
|
||||||
|
if (aEvent.isMomentum) {
|
||||||
|
scrollFlags |= kIsMomentum;
|
||||||
|
}
|
||||||
utils.sendMouseScrollEvent(type, left + aOffsetX, top + aOffsetY, button,
|
utils.sendMouseScrollEvent(type, left + aOffsetX, top + aOffsetY, button,
|
||||||
scrollFlags, aEvent.delta, modifiers);
|
scrollFlags, aEvent.delta, modifiers);
|
||||||
}
|
}
|
||||||
|
@ -1096,8 +1096,11 @@ public:
|
|||||||
// will compute the appropriate height/width based on
|
// will compute the appropriate height/width based on
|
||||||
// view lineHeight and generate line scroll events
|
// view lineHeight and generate line scroll events
|
||||||
// as needed.
|
// as needed.
|
||||||
kNoDefer = 1 << 5 // For scrollable views, indicates scroll should not
|
kNoDefer = 1 << 5, // For scrollable views, indicates scroll should not
|
||||||
// occur asynchronously.
|
// occur asynchronously.
|
||||||
|
kIsMomentum = 1 << 6 // Marks scroll events that aren't controlled by the
|
||||||
|
// user but fire automatically as the result of a
|
||||||
|
// "momentum" scroll.
|
||||||
};
|
};
|
||||||
|
|
||||||
nsMouseScrollEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w)
|
nsMouseScrollEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w)
|
||||||
|
@ -110,6 +110,12 @@ extern "C" long TSMProcessRawKeyEvent(EventRef carbonEvent);
|
|||||||
- (CGFloat)deviceDeltaY;
|
- (CGFloat)deviceDeltaY;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
// Undocumented scrollPhase flag that lets us discern between real scrolls and
|
||||||
|
// automatically firing momentum scroll events.
|
||||||
|
@interface NSEvent (ScrollPhase)
|
||||||
|
- (long long)_scrollPhase;
|
||||||
|
@end
|
||||||
|
|
||||||
@interface ChildView : NSView<
|
@interface ChildView : NSView<
|
||||||
#ifdef ACCESSIBILITY
|
#ifdef ACCESSIBILITY
|
||||||
mozAccessible,
|
mozAccessible,
|
||||||
|
@ -3663,6 +3663,9 @@ NSEvent* gLastDragMouseDownEvent = nil;
|
|||||||
// No sense in firing off a Gecko event.
|
// No sense in firing off a Gecko event.
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
BOOL isMomentumScroll = [theEvent respondsToSelector:@selector(_scrollPhase)] &&
|
||||||
|
[theEvent _scrollPhase] != 0;
|
||||||
|
|
||||||
if (scrollDelta != 0) {
|
if (scrollDelta != 0) {
|
||||||
// Send the line scroll event.
|
// Send the line scroll event.
|
||||||
nsMouseScrollEvent geckoEvent(PR_TRUE, NS_MOUSE_SCROLL, nsnull);
|
nsMouseScrollEvent geckoEvent(PR_TRUE, NS_MOUSE_SCROLL, nsnull);
|
||||||
@ -3672,6 +3675,9 @@ NSEvent* gLastDragMouseDownEvent = nil;
|
|||||||
if (hasPixels)
|
if (hasPixels)
|
||||||
geckoEvent.scrollFlags |= nsMouseScrollEvent::kHasPixels;
|
geckoEvent.scrollFlags |= nsMouseScrollEvent::kHasPixels;
|
||||||
|
|
||||||
|
if (isMomentumScroll)
|
||||||
|
geckoEvent.scrollFlags |= nsMouseScrollEvent::kIsMomentum;
|
||||||
|
|
||||||
// Gecko only understands how to scroll by an integer value. Using floor
|
// Gecko only understands how to scroll by an integer value. Using floor
|
||||||
// and ceil is better than truncating the fraction, especially when
|
// and ceil is better than truncating the fraction, especially when
|
||||||
// |delta| < 1.
|
// |delta| < 1.
|
||||||
@ -3757,6 +3763,8 @@ NSEvent* gLastDragMouseDownEvent = nil;
|
|||||||
nsMouseScrollEvent geckoEvent(PR_TRUE, NS_MOUSE_PIXEL_SCROLL, nsnull);
|
nsMouseScrollEvent geckoEvent(PR_TRUE, NS_MOUSE_PIXEL_SCROLL, nsnull);
|
||||||
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
||||||
geckoEvent.scrollFlags |= inAxis;
|
geckoEvent.scrollFlags |= inAxis;
|
||||||
|
if (isMomentumScroll)
|
||||||
|
geckoEvent.scrollFlags |= nsMouseScrollEvent::kIsMomentum;
|
||||||
geckoEvent.delta = NSToIntRound(scrollDeltaPixels);
|
geckoEvent.delta = NSToIntRound(scrollDeltaPixels);
|
||||||
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
||||||
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
||||||
|
Loading…
Reference in New Issue
Block a user