| OLD | NEW |
| 1 /* function for finding the absolute bounds of a node */ | 1 /* function for finding the absolute bounds of a node */ |
| 2 function findAbsoluteBounds(node) | 2 function findAbsoluteBounds(node) |
| 3 { | 3 { |
| 4 var bounds = {left: 0, top: 0}; | 4 var bounds = {left: 0, top: 0}; |
| 5 bounds.width = node.clientWidth; | 5 bounds.width = node.clientWidth; |
| 6 bounds.height = node.clientHeight; | 6 bounds.height = node.clientHeight; |
| 7 do { | 7 do { |
| 8 bounds.left += node.offsetLeft; | 8 bounds.left += node.offsetLeft; |
| 9 bounds.top += node.offsetTop; | 9 bounds.top += node.offsetTop; |
| 10 } while (node = node.offsetParent); | 10 } while (node = node.offsetParent); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 function adjustTouchPointContextMenu(touchpoint) | 89 function adjustTouchPointContextMenu(touchpoint) |
| 90 { | 90 { |
| 91 var adjustedPoint = internals.touchPositionAdjustedToBestContextMenuNode(tou
chpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document); | 91 var adjustedPoint = internals.touchPositionAdjustedToBestContextMenuNode(tou
chpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document); |
| 92 return adjustedPoint; | 92 return adjustedPoint; |
| 93 } | 93 } |
| 94 | 94 |
| 95 function touchPoint(x, y, radiusX, radiusY) | 95 function touchPoint(x, y, radiusX, radiusY) |
| 96 { | 96 { |
| 97 if (!radiusY) | 97 if (!radiusY) |
| 98 radiusY = radiusX; | 98 radiusY = radiusX; |
| 99 var touchpoint = new Object(); | 99 |
| 100 touchpoint.left = x - radiusX; | 100 return { |
| 101 touchpoint.top = y - radiusY; | 101 left: x - radiusX, |
| 102 touchpoint.width = radiusX * 2; | 102 top: y - radiusY, |
| 103 touchpoint.height = radiusY * 2; | 103 width: radiusX * 2, |
| 104 return touchpoint; | 104 height: radiusY * 2, |
| 105 get x() { return this.left + this.width/2; }, |
| 106 get y() { return this.top + this.height/2; } |
| 107 }; |
| 105 } | 108 } |
| 106 | 109 |
| 107 function offsetTouchPoint(bounds, relativePosition, touchOffset, touchRadiusX, t
ouchRadiusY) | 110 function offsetTouchPoint(bounds, relativePosition, touchOffset, touchRadiusX, t
ouchRadiusY) |
| 108 { | 111 { |
| 109 if (!touchRadiusY) | 112 if (!touchRadiusY) |
| 110 touchRadiusY = touchRadiusX; | 113 touchRadiusY = touchRadiusX; |
| 111 | 114 |
| 112 var touchpoint = {left : bounds.left, top: bounds.top }; | 115 // Start with the center of the touch at the top-left of the bounds. |
| 116 var touchpoint = touchPoint(bounds.left, bounds.top, touchRadiusX, touchRadi
usY); |
| 113 | 117 |
| 114 // Set center point for touch. | 118 // Adjust the touch point as requested. |
| 115 switch (relativePosition) { | 119 switch (relativePosition) { |
| 116 case 'center': | 120 case 'center': |
| 117 touchpoint.left += bounds.width / 2; | 121 touchpoint.left += bounds.width / 2; |
| 118 touchpoint.top += bounds.height / 2; | 122 touchpoint.top += bounds.height / 2; |
| 119 break; | 123 break; |
| 120 case 'left': | 124 case 'left': |
| 121 touchpoint.left -= touchOffset; | 125 touchpoint.left -= touchOffset; |
| 122 touchpoint.top += bounds.height / 2; | 126 touchpoint.top += bounds.height / 2; |
| 123 break; | 127 break; |
| 124 case 'right': | 128 case 'right': |
| (...skipping 17 matching lines...) Expand all Loading... |
| 142 touchpoint.top += bounds.height + touchOffset; | 146 touchpoint.top += bounds.height + touchOffset; |
| 143 break; | 147 break; |
| 144 case 'top': | 148 case 'top': |
| 145 touchpoint.left += bounds.width / 2; | 149 touchpoint.left += bounds.width / 2; |
| 146 touchpoint.top -= touchOffset; | 150 touchpoint.top -= touchOffset; |
| 147 break; | 151 break; |
| 148 case 'bottom': | 152 case 'bottom': |
| 149 touchpoint.left += bounds.width / 2; | 153 touchpoint.left += bounds.width / 2; |
| 150 touchpoint.top += bounds.height + touchOffset; | 154 touchpoint.top += bounds.height + touchOffset; |
| 151 } | 155 } |
| 152 // Adjust from touch center to top-left corner. | |
| 153 touchpoint.left -= touchRadiusX; | |
| 154 touchpoint.top -= touchRadiusY; | |
| 155 | |
| 156 touchpoint.width = 2 * touchRadiusX; | |
| 157 touchpoint.height = 2 * touchRadiusY; | |
| 158 | 156 |
| 159 return touchpoint; | 157 return touchpoint; |
| 160 } | 158 } |
| OLD | NEW |