Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/external/wpt_automation/fullscreen/auto-click.js |
| diff --git a/third_party/WebKit/LayoutTests/external/wpt_automation/fullscreen/auto-click.js b/third_party/WebKit/LayoutTests/external/wpt_automation/fullscreen/auto-click.js |
| index 2c4723bc2569b9aed72d792792690133a1e27b14..552a5cb3a67d3370617db43539d57751bc32c66d 100644 |
| --- a/third_party/WebKit/LayoutTests/external/wpt_automation/fullscreen/auto-click.js |
| +++ b/third_party/WebKit/LayoutTests/external/wpt_automation/fullscreen/auto-click.js |
| @@ -1,8 +1,25 @@ |
| (function() { |
| +// Gets the offset of an element in coordinates relative to the top-level frame. |
| +function offset(element) { |
| + const rect = element.getBoundingClientRect(); |
| + const iframe = element.ownerDocument.defaultView.frameElement; |
| + if (!iframe) |
| + return { left: rect.left, top: rect.top }; |
|
Mike West
2017/02/24 11:37:16
I must be getting old, but the `{}` for the object
foolip
2017/02/24 15:12:58
Ah, this does look a bit, more {} it is.
|
| + const style = getComputedStyle(iframe); |
|
Mike West
2017/02/24 11:37:16
I don't think you actually use this. Is it just to
foolip
2017/02/24 15:12:58
It's used as style[prop] inside the get function.
|
| + function get(prop) { |
|
Mike West
2017/02/24 11:37:16
Hrm. I don't know if we have a style-guide about n
foolip
2017/02/24 15:12:58
Didn't think of that, done. (I also threw in some
|
| + return +/[\d.]*/.exec(style[prop])[0]; |
| + } |
| + const outerOffset = offset(iframe); |
| + return { |
| + left: outerOffset.left + get('borderLeftWidth') + get('paddingLeft') + rect.left, |
| + top: outerOffset.top + get('borderTopWidth') + get('paddingTop') + rect.top |
| + }; |
| +} |
| + |
| function click(button) { |
| - var rect = button.getBoundingClientRect(); |
| - eventSender.mouseMoveTo(rect.left, rect.top); |
| + var pos = offset(button); |
| + eventSender.mouseMoveTo(Math.ceil(pos.left), Math.ceil(pos.top)); |
| eventSender.mouseDown(); |
| eventSender.mouseUp(); |
| } |
| @@ -28,6 +45,9 @@ for (var button of document.getElementsByTagName('button')) { |
| } |
| for (var iframe of document.getElementsByTagName('iframe')) { |
| observe(iframe.contentDocument); |
| + iframe.addEventListener('load', () => { |
| + observe(iframe.contentDocument); |
| + }); |
| } |
| // Observe future changes. |