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
3 // found in the LICENSE file.
9 function TapGestureOptions(opt_options) {
11 this.element_ = opt_options.element;
12 this.left_position_percentage_ = opt_options.left_position_percentage;
13 this.top_position_percentage_ = opt_options.top_position_percentage;
14 this.duration_ms_ = opt_options.duration_ms;
15 this.gesture_source_type_ = opt_options.gesture_source_type;
17 this.element_ = document.body;
18 this.left_position_percentage_ = 0.5;
19 this.top_position_percentage_ = 0.5;
20 this.duration_ms_ = 0;
21 this.gesture_source_type_ = chrome.gpuBenchmarking.DEFAULT_INPUT;
25 function supportedByBrowser() {
26 return !!(window.chrome &&
27 chrome.gpuBenchmarking &&
28 chrome.gpuBenchmarking.tap);
31 function TapAction(opt_callback) {
34 this.beginMeasuringHook = function() {}
35 this.endMeasuringHook = function() {}
37 this.callback_ = opt_callback;
40 TapAction.prototype.start = function(opt_options) {
41 this.options_ = new TapGestureOptions(opt_options);
42 // Assign this.element_ here instead of constructor, because the constructor
43 // ensures this method will be called after the document is loaded.
44 this.element_ = this.options_.element_;
46 requestAnimationFrame(this.startPass_.bind(this));
49 TapAction.prototype.startPass_ = function() {
50 this.beginMeasuringHook();
52 var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_);
54 rect.left + rect.width * this.options_.left_position_percentage_;
56 rect.top + rect.height * this.options_.top_position_percentage_;
57 chrome.gpuBenchmarking.tap(position_left, position_top,
58 this.onGestureComplete_.bind(this),
59 this.options_.duration_ms_,
60 this.options_.gesture_source_type_);
63 TapAction.prototype.onGestureComplete_ = function() {
64 this.endMeasuringHook();
71 window.__TapAction = TapAction;
72 window.__TapAction_SupportedByBrowser = supportedByBrowser;