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