Bug 1588311 - Update mousedown targets when native anonymous content is recreated, r=masayuki

Test click handling on input element which has a placeholder.

Differential Revision: https://phabricator.services.mozilla.com/D51877

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Olli Pettay 2019-11-08 19:08:27 +00:00
Родитель 4e6ed37fea
Коммит 422cff01c2
2 изменённых файлов: 83 добавлений и 0 удалений

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

@ -5545,6 +5545,24 @@ void EventStateManager::NativeAnonymousContentRemoved(nsIContent* aContent) {
MOZ_ASSERT(aContent->IsRootOfNativeAnonymousSubtree());
RemoveNodeFromChainIfNeeded(NS_EVENT_STATE_HOVER, aContent, false);
RemoveNodeFromChainIfNeeded(NS_EVENT_STATE_ACTIVE, aContent, false);
if (mLastLeftMouseDownContent &&
nsContentUtils::ContentIsFlattenedTreeDescendantOf(
mLastLeftMouseDownContent, aContent)) {
mLastLeftMouseDownContent = aContent->GetFlattenedTreeParent();
}
if (mLastMiddleMouseDownContent &&
nsContentUtils::ContentIsFlattenedTreeDescendantOf(
mLastMiddleMouseDownContent, aContent)) {
mLastMiddleMouseDownContent = aContent->GetFlattenedTreeParent();
}
if (mLastRightMouseDownContent &&
nsContentUtils::ContentIsFlattenedTreeDescendantOf(
mLastRightMouseDownContent, aContent)) {
mLastRightMouseDownContent = aContent->GetFlattenedTreeParent();
}
}
void EventStateManager::ContentRemoved(Document* aDocument,

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

@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Clicking with primary vs non-primary buttons</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
</head>
<body>
<h1>Clicking on input type=text element when placeholder changes</h1>
<input id="target" onfocus="this.placeholder = ++focusCount;" placeholder="initial">
<input id="other">
<script>
var focusCount = 0;
var target = document.querySelector('#target');
document.addEventListener('contextmenu', event => { event.preventDefault(); });
var test_click = async_test("Test click and auxclick on input element");
// The test is on purpose rather vague, since auxclick handling on
// touchscreens isn't well defined.
// But at least there should be 'click'
var didGetClick = false;
async function testClick(type, mouseButton) {
return new Promise((resolve) => {
target.addEventListener(type, event => {
event.preventDefault();
didGetClick = didGetClick || event.type == "click";
test_click.step(() => {
assert_equals(event.type, type, 'Should have got an event.');
});
}, {once: true});
// Inject mouse click events.
var actions = new test_driver.Actions();
document.getElementById("other").focus();
var bounds = target.getBoundingClientRect();
actions.pointerMove(Math.floor(bounds.width / 5),
Math.floor(bounds.height / 2),
{origin: target})
.pointerDown({button: mouseButton})
.pointerUp({button: mouseButton})
.send()
.then(resolve);
});
}
async function testClicks() {
var buttonType = test_driver.Actions.prototype.ButtonType;
await testClick("click", buttonType.LEFT);
await testClick("auxclick", buttonType.MIDDLE);
await testClick("auxclick", buttonType.RIGHT);
test_click.step(() => {
assert_true(didGetClick, 'Should have got at least "click".');
});
test_click.done();
}
testClicks();
</script>
</body>
</html>