Bug 1521712 - Pick on mouseup to allow picking scrollbars; r=rcaliman

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Patrick Brosset 2019-01-23 12:17:41 +00:00
parent ed6061c071
commit 8161663a6d
3 changed files with 52 additions and 2 deletions

View File

@ -122,6 +122,8 @@ skip-if = os == 'win' # bug 1413442
[browser_inspector_highlighter-measure_01.js]
[browser_inspector_highlighter-measure_02.js]
[browser_inspector_highlighter-options.js]
[browser_inspector_highlighter-pick-scrollbar.js]
skip-if = os != 'win' # Only test on windows where scrollbars are ... predictable
[browser_inspector_highlighter-preview.js]
[browser_inspector_highlighter-rulers_01.js]
[browser_inspector_highlighter-rulers_02.js]

View File

@ -0,0 +1,48 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// Test that clicking on a scrollbar with the pick enabled does select the element that
// the scrollbar belongs to (see bug 1521712)
const TEST_URL = `data:text/html;charset=utf-8,
<div id="wrapper" style="width:300px;height:300px;overflow:scroll">
<div style="height:1000px;"></div>
</div>`;
const TEST_NODE = "#wrapper";
add_task(async function() {
const { toolbox, inspector } = await openInspectorForURL(TEST_URL);
info("Start picking");
await startPicker(toolbox);
info("Click on a scrollbar in the document and expect the test node to be selected");
const onSelect = inspector.once("inspector-updated");
const scrollbarWidth = await getScrollbarWidth(TEST_NODE);
const width = await getNodeWidth(TEST_NODE);
await BrowserTestUtils.synthesizeMouse(TEST_NODE,
width - scrollbarWidth / 2, 150, {}, gBrowser.selectedBrowser);
await onSelect;
is(inspector.selection.nodeFront.id, "wrapper", "The wrapper element was selected");
});
async function getScrollbarWidth(selector) {
return ContentTask.spawn(gBrowser.selectedBrowser, selector, s => {
const node = content.document.querySelector(s);
return node.offsetWidth - node.clientWidth;
});
}
async function getNodeWidth(selector) {
return ContentTask.spawn(gBrowser.selectedBrowser, selector, s => {
const node = content.document.querySelector(s);
const rect = node.getBoundingClientRect();
return rect.width;
});
}

View File

@ -411,9 +411,9 @@ exports.HighlighterActor = protocol.ActorClassWithSpec(highlighterSpec, {
_startPickerListeners: function() {
const target = this._highlighterEnv.pageListenerTarget;
target.addEventListener("mousemove", this._onHovered, true);
target.addEventListener("click", this._onPick, true);
target.addEventListener("mouseup", this._onPick, true);
target.addEventListener("mousedown", this._preventContentEvent, true);
target.addEventListener("mouseup", this._preventContentEvent, true);
target.addEventListener("click", this._preventContentEvent, true);
target.addEventListener("dblclick", this._preventContentEvent, true);
target.addEventListener("keydown", this._onKey, true);
target.addEventListener("keyup", this._preventContentEvent, true);