Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Side by Side Diff: telemetry/telemetry/internal/actions/pinch.py

Issue 3017493002: Fix coordinate calculations under pinch-zoom
Patch Set: Add comments Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « telemetry/telemetry/internal/actions/pinch.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 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 from telemetry.internal.actions import page_action 5 from telemetry.internal.actions import page_action
6 from telemetry.internal.actions import utils 6 from telemetry.internal.actions import utils
7 from telemetry.util import js_template 7 from telemetry.util import js_template
8 8
9 9
10 class PinchAction(page_action.PageAction): 10 class PinchAction(page_action.PageAction):
11 11
12 def __init__(self, 12 def __init__(self,
13 selector=None,
14 text=None,
15 element_function=None,
16 left_anchor_ratio=0.5, 13 left_anchor_ratio=0.5,
17 top_anchor_ratio=0.5, 14 top_anchor_ratio=0.5,
18 scale_factor=None, 15 scale_factor=None,
19 speed_in_pixels_per_second=800, 16 speed_in_pixels_per_second=800,
20 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT): 17 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT):
21 super(PinchAction, self).__init__() 18 super(PinchAction, self).__init__()
22 self._selector = selector
23 self._text = text
24 self._element_function = element_function
25 self._left_anchor_ratio = left_anchor_ratio 19 self._left_anchor_ratio = left_anchor_ratio
26 self._top_anchor_ratio = top_anchor_ratio 20 self._top_anchor_ratio = top_anchor_ratio
27 self._scale_factor = scale_factor 21 self._scale_factor = scale_factor
28 self._speed = speed_in_pixels_per_second 22 self._speed = speed_in_pixels_per_second
29 self._synthetic_gesture_source = ( 23 self._synthetic_gesture_source = (
30 'chrome.gpuBenchmarking.%s_INPUT' % synthetic_gesture_source) 24 'chrome.gpuBenchmarking.%s_INPUT' % synthetic_gesture_source)
31 25
32 if (self._selector is None and self._text is None and
33 self._element_function is None):
34 self._element_function = 'document.body'
35
36 def WillRunAction(self, tab): 26 def WillRunAction(self, tab):
37 utils.InjectJavaScript(tab, 'gesture_common.js') 27 utils.InjectJavaScript(tab, 'gesture_common.js')
38 utils.InjectJavaScript(tab, 'pinch.js') 28 utils.InjectJavaScript(tab, 'pinch.js')
39 29
40 # Fail if browser doesn't support synthetic pinch gestures. 30 # Fail if browser doesn't support synthetic pinch gestures.
41 if not tab.EvaluateJavaScript('window.__PinchAction_SupportedByBrowser()'): 31 if not tab.EvaluateJavaScript('window.__PinchAction_SupportedByBrowser()'):
42 raise page_action.PageActionNotSupported( 32 raise page_action.PageActionNotSupported(
43 'Synthetic pinch not supported for this browser') 33 'Synthetic pinch not supported for this browser')
44 34
45 tab.ExecuteJavaScript(""" 35 tab.ExecuteJavaScript("""
46 window.__pinchActionDone = false; 36 window.__pinchActionDone = false;
47 window.__pinchAction = new __PinchAction(function() { 37 window.__pinchAction = new __PinchAction(function() {
48 window.__pinchActionDone = true; 38 window.__pinchActionDone = true;
49 });""") 39 });""")
50 40
51 @staticmethod 41 @staticmethod
52 def _GetDefaultScaleFactorForPage(tab): 42 def _GetDefaultScaleFactorForPage(tab):
53 current_scale_factor = tab.EvaluateJavaScript( 43 current_scale_factor = tab.EvaluateJavaScript("""
54 'window.outerWidth / window.innerWidth') 44 "visualViewport" in window
45 ? visualViewport.scale
46 : window.outerWidth / window.innerWidth'""")
55 return 3.0 / current_scale_factor 47 return 3.0 / current_scale_factor
56 48
57 def RunAction(self, tab): 49 def RunAction(self, tab):
58 scale_factor = (self._scale_factor if self._scale_factor else 50 scale_factor = (self._scale_factor if self._scale_factor else
59 PinchAction._GetDefaultScaleFactorForPage(tab)) 51 PinchAction._GetDefaultScaleFactorForPage(tab))
60 code = js_template.Render( 52 code = js_template.Render(
61 """ 53 """
62 function(element, info) { 54 window.__pinchAction.start({
63 if (!element) { 55 left_anchor_ratio: {{ left_anchor_ratio }},
64 throw Error('Cannot find element: ' + info); 56 top_anchor_ratio: {{ top_anchor_ratio }},
65 } 57 scale_factor: {{ scale_factor }},
66 window.__pinchAction.start({ 58 speed: {{ speed }}
67 element: element, 59 });""",
68 left_anchor_ratio: {{ left_anchor_ratio }},
69 top_anchor_ratio: {{ top_anchor_ratio }},
70 scale_factor: {{ scale_factor }},
71 speed: {{ speed }}
72 });
73 }""",
74 left_anchor_ratio=self._left_anchor_ratio, 60 left_anchor_ratio=self._left_anchor_ratio,
75 top_anchor_ratio=self._top_anchor_ratio, 61 top_anchor_ratio=self._top_anchor_ratio,
76 scale_factor=scale_factor, 62 scale_factor=scale_factor,
77 speed=self._speed) 63 speed=self._speed)
78 page_action.EvaluateCallbackWithElement( 64 tab.EvaluateJavaScript(code)
79 tab,
80 code,
81 selector=self._selector,
82 text=self._text,
83 element_function=self._element_function)
84 tab.WaitForJavaScriptCondition('window.__pinchActionDone', timeout=60) 65 tab.WaitForJavaScriptCondition('window.__pinchActionDone', timeout=60)
OLDNEW
« no previous file with comments | « telemetry/telemetry/internal/actions/pinch.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698