Bug 716549. Flush on every mousemove, because otherwise we can end up with mouse events (mousemove, mousein, mouseout) dispatched to the wrong elements. r=smaug

This commit is contained in:
Boris Zbarsky 2011-12-23 22:52:26 -05:00
parent 51eafc2c57
commit a539a4b217
4 changed files with 112 additions and 5 deletions

View File

@ -1146,6 +1146,9 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
GenerateDragGesture(aPresContext, (nsMouseEvent*)aEvent);
UpdateCursor(aPresContext, aEvent, mCurrentTarget, aStatus);
GenerateMouseEnterExit((nsGUIEvent*)aEvent);
// Flush pending layout changes, so that later mouse move events
// will go to the right nodes.
FlushPendingEvents(aPresContext);
break;
case NS_DRAGDROP_GESTURE:
if (mClickHoldContextMenu) {

View File

@ -113,6 +113,7 @@ _TEST_FILES = \
test_bug689564.html \
test_bug698929.html \
test_eventctors.html \
test_bug635465.html \
$(NULL)
#bug 585630

View File

@ -0,0 +1,90 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=635465
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 635465</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style type="text/css">
#item {
position: relative;
}
.s-menu-section-submenu {
position: absolute;
display: none;
}
.open .s-menu-section-submenu {
display: block;
}
</style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=635465">Mozilla Bug 635465</a>
<div id="display">
<div class="item" id="item"
onmouseover="showSubmenu(event)" onmouseout="hideSubmenu(event)">
<a href="#" id="firsthover">Hover me</a>
<div class="s-menu-section-submenu" id="menu">
<a href="#" id="secondhover">Now hover me</a>
</div>
</div>
</div>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript;version=1.8">
/** Test for Bug 635465 **/
function showSubmenu(event) {
var item = document.getElementById('item');
var width = item.offsetWidth; // IT WORKS IF YOU REMOVE THIS LINE
item.className='open';
}
function hideSubmenu(event) {
document.getElementById('item').className='';
}
SimpleTest.waitForExplicitFinish();
function executeTests() {
// First flush out layout of firsthover
ok($("firsthover").getBoundingClientRect().height > 0, true,
"Should have a nonzero height before hover");
// Now trigger a mouseover on firsthover
synthesizeMouseAtCenter($("firsthover"), { type: "mousemove" });
ok($("secondhover").getBoundingClientRect().height > 0, true,
"Should have a nonzero height for submenu after hover");
// Now determine where secondhover is hanging out
var rect = $("secondhover").getBoundingClientRect();
synthesizeMouseAtCenter($("secondhover"), { type: "mousemove" });
// And another mouseover one pixel to the right of where the center used to be
synthesizeMouseAtPoint(rect.left + rect.width/2 + 1,
rect.top + rect.height/2,
{ type: "mousemove" });
ok($("secondhover").getBoundingClientRect().height > 0, true,
"Should have a nonzero height for submenu after second hover");
// And check computed display of the menu
is(getComputedStyle($("menu"), "").display, "block", "Should have block display");
SimpleTest.finish();
}
SimpleTest.waitForFocus(executeTests);
</script>
</pre>
</body>
</html>

View File

@ -145,6 +145,24 @@ function _parseModifiers(aEvent)
* aWindow is optional, and defaults to the current window object.
*/
function synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
{
var rect = aTarget.getBoundingClientRect();
synthesizeMouseAtPoint(rect.left + aOffsetX, rect.top + aOffsetY,
aEvent, aWindow);
}
/*
* Synthesize a mouse event at a particular point in aWindow.
*
* aEvent is an object which may contain the properties:
* shiftKey, ctrlKey, altKey, metaKey, accessKey, clickCount, button, type
*
* If the type is specified, an mouse event of that type is fired. Otherwise,
* a mousedown followed by a mouse up is performed.
*
* aWindow is optional, and defaults to the current window object.
*/
function synthesizeMouseAtPoint(left, top, aEvent, aWindow)
{
var utils = _getDOMWindowUtils(aWindow);
@ -153,11 +171,6 @@ function synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
var clickCount = aEvent.clickCount || 1;
var modifiers = _parseModifiers(aEvent);
var rect = aTarget.getBoundingClientRect();
var left = rect.left + aOffsetX;
var top = rect.top + aOffsetY;
if (aEvent.type) {
utils.sendMouseEvent(aEvent.type, left, top, button, clickCount, modifiers);
}