зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1295010 - Don't move the eyedropper to the out of browser window by keyboard navigation. r=pbro
MozReview-Commit-ID: vBwmSxVNXK --HG-- extra : rebase_source : b74df421630fc46dab6b6cc026bf3e0ae6b4a651 extra : amend_source : 6885024ef00cfa33d73c59dc03c48ebcda9ccbdd extra : histedit_source : c43167f0a7cbe9f4c733b15da726e5150a9529ba
This commit is contained in:
Родитель
4a071f812f
Коммит
f413b9b7dd
|
@ -7,6 +7,11 @@
|
|||
|
||||
const HIGHLIGHTER_TYPE = "EyeDropper";
|
||||
const ID = "eye-dropper-";
|
||||
const TEST_URI = `
|
||||
<style>
|
||||
html{width:100%;height:100%;}
|
||||
</style>
|
||||
<body>eye-dropper test</body>`;
|
||||
|
||||
const MOVE_EVENTS_DATA = [
|
||||
{type: "mouse", x: 200, y: 100, expected: {x: 200, y: 100}},
|
||||
|
@ -19,11 +24,62 @@ const MOVE_EVENTS_DATA = [
|
|||
{type: "keyboard", key: "VK_DOWN", shift: true, expected: {x: 100, y: 211}},
|
||||
{type: "keyboard", key: "VK_UP", expected: {x: 100, y: 210}},
|
||||
{type: "keyboard", key: "VK_UP", shift: true, expected: {x: 100, y: 200}},
|
||||
// Mouse initialization for left and top snapping
|
||||
{type: "mouse", x: 7, y: 7, expected: {x: 7, y: 7}},
|
||||
// Left Snapping
|
||||
{type: "keyboard", key: "VK_LEFT", shift: true, expected: {x: 0, y: 7},
|
||||
desc: "Left Snapping to x=0"},
|
||||
// Top Snapping
|
||||
{type: "keyboard", key: "VK_UP", shift: true, expected: {x: 0, y: 0},
|
||||
desc: "Top Snapping to y=0"},
|
||||
// Mouse initialization for right snapping
|
||||
{
|
||||
type: "mouse",
|
||||
x: (width, height) => width - 5,
|
||||
y: 0,
|
||||
expected: {
|
||||
x: (width, height) => width - 5,
|
||||
y: 0
|
||||
}
|
||||
},
|
||||
// Right snapping
|
||||
{
|
||||
type: "keyboard",
|
||||
key: "VK_RIGHT",
|
||||
shift: true,
|
||||
expected: {
|
||||
x: (width, height) => width,
|
||||
y: 0
|
||||
},
|
||||
desc: "Right snapping to x=max window width available"
|
||||
},
|
||||
// Mouse initialization for bottom snapping
|
||||
{
|
||||
type: "mouse",
|
||||
x: 0,
|
||||
y: (width, height) => height - 5,
|
||||
expected: {
|
||||
x: 0,
|
||||
y: (width, height) => height - 5
|
||||
}
|
||||
},
|
||||
// Bottom snapping
|
||||
{
|
||||
type: "keyboard",
|
||||
key: "VK_DOWN",
|
||||
shift: true,
|
||||
expected: {
|
||||
x: 0,
|
||||
y: (width, height) => height
|
||||
},
|
||||
desc: "Bottom snapping to y=max window height available"
|
||||
},
|
||||
];
|
||||
|
||||
add_task(function* () {
|
||||
let helper = yield openInspectorForURL("data:text/html;charset=utf-8,eye-dropper test")
|
||||
.then(getHighlighterHelperFor(HIGHLIGHTER_TYPE));
|
||||
let helper = yield openInspectorForURL("data:text/html;charset=utf-8,"
|
||||
+ encodeURIComponent(TEST_URI)
|
||||
).then(getHighlighterHelperFor(HIGHLIGHTER_TYPE));
|
||||
helper.prefix = ID;
|
||||
|
||||
yield helper.show("html");
|
||||
|
@ -35,10 +91,23 @@ add_task(function* () {
|
|||
|
||||
function* respondsToMoveEvents(helper) {
|
||||
info("Checking that the eyedropper responds to events from the mouse and keyboard");
|
||||
let {mouse} = helper;
|
||||
let {mouse, testActor} = helper;
|
||||
let {width, height} = yield testActor.getBoundingClientRect("html");
|
||||
|
||||
for (let {type, x, y, key, shift, expected} of MOVE_EVENTS_DATA) {
|
||||
for (let {type, x, y, key, shift, expected, desc} of MOVE_EVENTS_DATA) {
|
||||
x = typeof x === "function" ? x(width, height) : x;
|
||||
y = typeof y === "function" ? y(width, height) : y;
|
||||
expected.x = typeof expected.x === "function" ?
|
||||
expected.x(width, height) : expected.x;
|
||||
expected.y = typeof expected.y === "function" ?
|
||||
expected.y(width, height) : expected.y;
|
||||
|
||||
if (typeof desc === "undefined") {
|
||||
info(`Simulating a ${type} event to move to ${expected.x} ${expected.y}`);
|
||||
} else {
|
||||
info(`Simulating ${type} event: ${desc}`);
|
||||
}
|
||||
|
||||
if (type === "mouse") {
|
||||
yield mouse.move(x, y);
|
||||
} else if (type === "keyboard") {
|
||||
|
|
|
@ -531,7 +531,9 @@ const getHighlighterHelperFor = (type) => Task.async(
|
|||
finalize: function* () {
|
||||
highlightedNode = null;
|
||||
yield highlighter.finalize();
|
||||
}
|
||||
},
|
||||
|
||||
testActor: testActor
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
@ -429,8 +429,10 @@ EyeDropper.prototype = {
|
|||
offsetX *= modifier;
|
||||
|
||||
if (offsetX !== 0 || offsetY !== 0) {
|
||||
this.magnifiedArea.x += offsetX;
|
||||
this.magnifiedArea.y += offsetY;
|
||||
this.magnifiedArea.x = cap(this.magnifiedArea.x + offsetX,
|
||||
0, this.win.innerWidth * this.pageZoom);
|
||||
this.magnifiedArea.y = cap(this.magnifiedArea.y + offsetY, 0,
|
||||
this.win.innerHeight * this.pageZoom);
|
||||
|
||||
this.draw();
|
||||
|
||||
|
@ -526,3 +528,7 @@ function hexString([r, g, b]) {
|
|||
let val = (1 << 24) + (r << 16) + (g << 8) + (b << 0);
|
||||
return "#" + val.toString(16).substr(-6).toUpperCase();
|
||||
}
|
||||
|
||||
function cap(value, min, max) {
|
||||
return Math.max(min, Math.min(value, max));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче