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

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

Issue 2876843002: Simulate interactivity boost for simulated user input events
Patch Set: Created 3 years, 7 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
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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.scroll import ScrollAction 6 from telemetry.internal.actions.scroll import ScrollAction
7 from telemetry.util import js_template 7 from telemetry.util import js_template
8 8
9 9
10 class ScrollToElementAction(page_action.PageAction): 10 class ScrollToElementAction(page_action.PageAction):
(...skipping 27 matching lines...) Expand all
38 self._element_function = element_function 38 self._element_function = element_function
39 self._container_selector = container_selector 39 self._container_selector = container_selector
40 self._container_element_function = container_element_function 40 self._container_element_function = container_element_function
41 self._speed = speed_in_pixels_per_second 41 self._speed = speed_in_pixels_per_second
42 self._distance = None 42 self._distance = None
43 self._direction = None 43 self._direction = None
44 self._scroller = None 44 self._scroller = None
45 assert (self._selector or self._element_function), ( 45 assert (self._selector or self._element_function), (
46 'Must have either selector or element function') 46 'Must have either selector or element function')
47 47
48 def SimulatesUserInput(self):
49 return True
50
48 def WillRunAction(self, tab): 51 def WillRunAction(self, tab):
49 if self._selector: 52 if self._selector:
50 element = js_template.Render( 53 element = js_template.Render(
51 'document.querySelector({{ selector }})', selector=self._selector) 54 'document.querySelector({{ selector }})', selector=self._selector)
52 else: 55 else:
53 element = self._element_function 56 element = self._element_function
54 57
55 self._distance = tab.EvaluateJavaScript(''' 58 self._distance = tab.EvaluateJavaScript('''
56 (function(elem){ 59 (function(elem){
57 var rect = elem.getBoundingClientRect(); 60 var rect = elem.getBoundingClientRect();
(...skipping 18 matching lines...) Expand all
76 selector=self._container_selector, 79 selector=self._container_selector,
77 element_function=self._container_element_function, 80 element_function=self._container_element_function,
78 distance=self._distance, 81 distance=self._distance,
79 speed_in_pixels_per_second=self._speed) 82 speed_in_pixels_per_second=self._speed)
80 83
81 def RunAction(self, tab): 84 def RunAction(self, tab):
82 if self._distance == 0: # Element is already in view. 85 if self._distance == 0: # Element is already in view.
83 return 86 return
84 self._scroller.WillRunAction(tab) 87 self._scroller.WillRunAction(tab)
85 self._scroller.RunAction(tab) 88 self._scroller.RunAction(tab)
OLDNEW
« no previous file with comments | « telemetry/telemetry/internal/actions/scroll_bounce.py ('k') | telemetry/telemetry/internal/actions/swipe.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698