| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function getElementRegion(element) { | 5 function getElementRegion(element) { |
| 6 // Check that node type is element. | 6 // Check that node type is element. |
| 7 if (element.nodeType != 1) | 7 if (element.nodeType != 1) |
| 8 throw new Error(element + ' is not an element'); | 8 throw new Error(element + ' is not an element'); |
| 9 | 9 |
| 10 // We try 2 methods to determine element region. Try the first client rect, | 10 // We try 2 methods to determine element region. Try the first client rect, |
| 11 // and then the bounding client rect. | 11 // and then the bounding client rect. |
| 12 // SVG is one case that doesn't have a first client rect. | 12 // SVG is one case that doesn't have a first client rect. |
| 13 var clientRects = element.getClientRects(); | 13 var clientRects = element.getClientRects(); |
| 14 if (clientRects.length == 0) { | 14 |
| 15 // Element area of a map has same first ClientRect and BoundingClientRect |
| 16 // after blink roll at chromium commit position 290738 which includes blink |
| 17 // revision 180610. Thus handle area as a special case. |
| 18 if (clientRects.length == 0 || element.tagName.toLowerCase() == 'area') { |
| 15 var box = element.getBoundingClientRect(); | 19 var box = element.getBoundingClientRect(); |
| 16 if (element.tagName.toLowerCase() == 'area') { | 20 if (element.tagName.toLowerCase() == 'area') { |
| 17 var coords = element.coords.split(','); | 21 var coords = element.coords.split(','); |
| 18 if (element.shape.toLowerCase() == 'rect') { | 22 if (element.shape.toLowerCase() == 'rect') { |
| 19 if (coords.length != 4) | 23 if (coords.length != 4) |
| 20 throw new Error('failed to detect the region of the area'); | 24 throw new Error('failed to detect the region of the area'); |
| 21 var leftX = Number(coords[0]); | 25 var leftX = Number(coords[0]); |
| 22 var topY = Number(coords[1]); | 26 var topY = Number(coords[1]); |
| 23 var rightX = Number(coords[2]); | 27 var rightX = Number(coords[2]); |
| 24 var bottomY = Number(coords[3]); | 28 var bottomY = Number(coords[3]); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 var clientRect = clientRects[0]; | 79 var clientRect = clientRects[0]; |
| 76 var box = element.getBoundingClientRect(); | 80 var box = element.getBoundingClientRect(); |
| 77 return { | 81 return { |
| 78 'left': clientRect.left - box.left, | 82 'left': clientRect.left - box.left, |
| 79 'top': clientRect.top - box.top, | 83 'top': clientRect.top - box.top, |
| 80 'width': clientRect.right - clientRect.left, | 84 'width': clientRect.right - clientRect.left, |
| 81 'height': clientRect.bottom - clientRect.top | 85 'height': clientRect.bottom - clientRect.top |
| 82 }; | 86 }; |
| 83 } | 87 } |
| 84 } | 88 } |
| OLD | NEW |