1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<!DOCTYPE html>
<html>
<head>
<title>Touch Adjustment : Adjust context-menu to text-node subtargets - bug 94449</title>
<script src="../resources/ahem.js"></script>
<script src="../resources/js-test.js"></script>
<script src="resources/touchadjustment.js"></script>
<style>
#sandbox {
position: absolute;
top: 0px;
left: 0px;
width: 400px;
height: 200px;
}
#sandbox div {
padding: 10px;
font: 20px Ahem;
white-space: pre-wrap;
}
</style>
</head>
<body>
<div id=sandbox>
<!-- The layout of the two words should be: (10,10)x(80,20) and (170,10)x(80,20). -->
<div id=div1><span id=span1>Text text</span></div>
</div>
<p id='description'></p>
<div id='console'></div>
<script>
// Set up shortcut access to elements
var e = {};
['sandbox', 'div1', 'span1'].forEach(function(a) {
e[a] = document.getElementById(a);
});
function testAdjustedTouches()
{
var adjustedPoint;
var word1Bounds = { left: 10, top: 10, width: 80, height: 20 };
var word2Bounds = { left: 170, top: 10, width: 80, height: 20 };
// Set editing-behaviour mac, so context-menu gesture triggers selections.
internals.settings.setEditingBehavior('mac');
// Check the context-menu is adjusted to the individual words.
adjustedPoint = adjustTouchPointContextMenu(touchPoint(5, 5, 20, 10));
shouldBeWithin(adjustedPoint, word1Bounds);
adjustedPoint = adjustTouchPointContextMenu(touchPoint(100, 15, 20, 10));
shouldBeWithin(adjustedPoint, word1Bounds);
adjustedPoint = adjustTouchPointContextMenu(touchPoint(150, 15, 30, 10));
shouldBeWithin(adjustedPoint, word2Bounds);
adjustedPoint = adjustTouchPointContextMenu(touchPoint(260, 35, 20, 10));
shouldBeWithin(adjustedPoint, word2Bounds);
// Set editing-behaviour to win, so context-menu gesture does not trigger selections.
internals.settings.setEditingBehavior('win');
var range = document.createRange();
range.setStart(e.span1.firstChild, 2);
range.setEnd(e.span1.firstChild, 6);
window.getSelection().addRange(range);
var selectionBounds = { left: 50, top: 10, width: 80, height: 20 };
adjustedPoint = adjustTouchPointContextMenu(touchPoint(25, 5, 30, 20));
shouldBeWithin(adjustedPoint, selectionBounds);
adjustedPoint = adjustTouchPointContextMenu(touchPoint(140, 10, 20, 10));
shouldBeWithin(adjustedPoint, selectionBounds);
}
function runTests()
{
if (window.testRunner && window.internals && internals.touchNodeAdjustedToBestContextMenuNode) {
description('Test touch-adjustment to individual words or active selection.');
testAdjustedTouches();
e.sandbox.style.display = 'none';
}
}
runTests();
</script>
</body>
</html>
|