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.
8 function SwipeGestureOptions(opt_options) {
10 this.element_ = opt_options.element;
11 this.left_start_ratio_ = opt_options.left_start_ratio;
12 this.top_start_ratio_ = opt_options.top_start_ratio;
13 this.direction_ = opt_options.direction;
14 this.distance_ = opt_options.distance;
15 this.speed_ = opt_options.speed;
17 this.element_ = document.body;
18 this.left_start_ratio_ = 0.5;
19 this.top_start_ratio_ = 0.5;
20 this.direction_ = 'left';
26 function supportedByBrowser() {
27 return !!(window.chrome &&
28 chrome.gpuBenchmarking &&
29 chrome.gpuBenchmarking.swipe &&
30 chrome.gpuBenchmarking.visualViewportHeight &&
31 chrome.gpuBenchmarking.visualViewportWidth);
34 // This class swipes a page for a specified distance.
35 function SwipeAction(opt_callback) {
38 this.beginMeasuringHook = function() {};
39 this.endMeasuringHook = function() {};
41 this.callback_ = opt_callback;
44 SwipeAction.prototype.start = function(opt_options) {
45 this.options_ = new SwipeGestureOptions(opt_options);
46 // Assign this.element_ here instead of constructor, because the constructor
47 // ensures this method will be called after the document is loaded.
48 this.element_ = this.options_.element_;
49 requestAnimationFrame(this.startGesture_.bind(this));
52 SwipeAction.prototype.startGesture_ = function() {
53 this.beginMeasuringHook();
55 var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_);
57 rect.left + rect.width * this.options_.left_start_ratio_;
59 rect.top + rect.height * this.options_.top_start_ratio_;
60 chrome.gpuBenchmarking.swipe(this.options_.direction_,
61 this.options_.distance_,
62 this.onGestureComplete_.bind(this),
63 start_left, start_top,
64 this.options_.speed_);
67 SwipeAction.prototype.onGestureComplete_ = function() {
68 this.endMeasuringHook();
75 window.__SwipeAction = SwipeAction;
76 window.__SwipeAction_SupportedByBrowser = supportedByBrowser;