| OLD | NEW |
| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 (function() { | 7 (function() { |
| 8 | 8 |
| 9 function TapGestureOptions(opt_options) { | 9 function TapGestureOptions(opt_options) { |
| 10 if (opt_options) { | 10 if (opt_options) { |
| 11 this.element_ = opt_options.element; | 11 this.element_ = opt_options.element; |
| 12 this.left_position_percentage_ = opt_options.left_position_percentage; | 12 this.left_position_percentage_ = opt_options.left_position_percentage; |
| 13 this.top_position_percentage_ = opt_options.top_position_percentage; | 13 this.top_position_percentage_ = opt_options.top_position_percentage; |
| 14 this.duration_ms_ = opt_options.duration_ms; | 14 this.duration_ms_ = opt_options.duration_ms; |
| 15 this.gesture_source_type_ = opt_options.gesture_source_type; | 15 this.gesture_source_type_ = opt_options.gesture_source_type; |
| 16 } else { | 16 } else { |
| 17 this.element_ = document.body; | 17 this.element_ = document.body; |
| 18 this.left_position_percentage_ = 0.5; | 18 this.left_position_percentage_ = 0.5; |
| 19 this.top_position_percentage_ = 0.5; | 19 this.top_position_percentage_ = 0.5; |
| 20 this.duration_ms_ = 50; | 20 this.duration_ms_ = 50; |
| 21 this.gesture_source_type_ = chrome.gpuBenchmarking.DEFAULT_INPUT; | 21 this.gesture_source_type_ = chrome.gpuBenchmarking.DEFAULT_INPUT; |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 function supportedByBrowser() { | 25 function supportedByBrowser() { |
| 26 return !!(window.chrome && | 26 return !!(window.chrome && |
| 27 chrome.gpuBenchmarking && | 27 chrome.gpuBenchmarking && |
| 28 chrome.gpuBenchmarking.tap); | 28 chrome.gpuBenchmarking.tap && |
| 29 chrome.gpuBenchmarking.visualViewportHeight && |
| 30 chrome.gpuBenchmarking.visualViewportWidth); |
| 29 } | 31 } |
| 30 | 32 |
| 31 function TapAction(opt_callback) { | 33 function TapAction(opt_callback) { |
| 32 var self = this; | 34 var self = this; |
| 33 | 35 |
| 34 this.beginMeasuringHook = function() {}; | 36 this.beginMeasuringHook = function() {}; |
| 35 this.endMeasuringHook = function() {}; | 37 this.endMeasuringHook = function() {}; |
| 36 | 38 |
| 37 this.callback_ = opt_callback; | 39 this.callback_ = opt_callback; |
| 38 } | 40 } |
| 39 | 41 |
| 40 TapAction.prototype.start = function(opt_options) { | 42 TapAction.prototype.start = function(opt_options) { |
| 41 this.options_ = new TapGestureOptions(opt_options); | 43 this.options_ = new TapGestureOptions(opt_options); |
| 42 // Assign this.element_ here instead of constructor, because the constructor | 44 // Assign this.element_ here instead of constructor, because the constructor |
| 43 // ensures this method will be called after the document is loaded. | 45 // ensures this method will be called after the document is loaded. |
| 44 this.element_ = this.options_.element_; | 46 this.element_ = this.options_.element_; |
| 45 | 47 |
| 46 this.beginMeasuringHook(); | 48 this.beginMeasuringHook(); |
| 47 | 49 |
| 48 var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_); | 50 var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_); |
| 49 var position_left = | 51 var position_left = |
| 50 rect.left + rect.width * this.options_.left_position_percentage_; | 52 rect.left + rect.width * this.options_.left_position_percentage_; |
| 51 var position_top = | 53 var position_top = |
| 52 rect.top + rect.height * this.options_.top_position_percentage_; | 54 rect.top + rect.height * this.options_.top_position_percentage_; |
| 53 if (position_left < 0 || position_left >= window.innerWidth || | 55 if (position_left < 0 || |
| 54 position_top < 0 || position_top >= window.innerHeight) { | 56 position_left >= __GestureCommon_GetWindowWidth() || |
| 57 position_top < 0 || |
| 58 position_top >= __GestureCommon_GetWindowHeight()) { |
| 55 throw new Error('Tap position is off-screen'); | 59 throw new Error('Tap position is off-screen'); |
| 56 } | 60 } |
| 57 chrome.gpuBenchmarking.tap(position_left, position_top, | 61 chrome.gpuBenchmarking.tap(position_left, position_top, |
| 58 this.onGestureComplete_.bind(this), | 62 this.onGestureComplete_.bind(this), |
| 59 this.options_.duration_ms_, | 63 this.options_.duration_ms_, |
| 60 this.options_.gesture_source_type_); | 64 this.options_.gesture_source_type_); |
| 61 }; | 65 }; |
| 62 | 66 |
| 63 TapAction.prototype.onGestureComplete_ = function() { | 67 TapAction.prototype.onGestureComplete_ = function() { |
| 64 this.endMeasuringHook(); | 68 this.endMeasuringHook(); |
| 65 | 69 |
| 66 // We're done. | 70 // We're done. |
| 67 if (this.callback_) | 71 if (this.callback_) |
| 68 this.callback_(); | 72 this.callback_(); |
| 69 }; | 73 }; |
| 70 | 74 |
| 71 window.__TapAction = TapAction; | 75 window.__TapAction = TapAction; |
| 72 window.__TapAction_SupportedByBrowser = supportedByBrowser; | 76 window.__TapAction_SupportedByBrowser = supportedByBrowser; |
| 73 })(); | 77 })(); |
| OLD | NEW |