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

Unified Diff: tools/telemetry/telemetry/page/actions/drag.js

Issue 955653003: Adding Maps page to page_sets for telemetry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mousedrag2
Patch Set: Multiple actions on Maps benchmark. Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/page/actions/drag.js
diff --git a/tools/telemetry/telemetry/page/actions/drag.js b/tools/telemetry/telemetry/page/actions/drag.js
new file mode 100644
index 0000000000000000000000000000000000000000..c352d08a1fd140c62640d518b1789038db1503e6
--- /dev/null
+++ b/tools/telemetry/telemetry/page/actions/drag.js
@@ -0,0 +1,81 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file provides the DragAction object, which performs drag on a page
+// using given start and end positions:
+// 1. var action = new __DragAction(callback)
+// 2. action.start(drag_options)
+'use strict';
+
+(function() {
+ function DragGestureOptions(opt_options) {
+ if (opt_options) {
petrcermak 2015/02/25 11:35:48 Is there any reason to make the argument optional
ssid 2015/02/27 11:35:15 you are right, it isn't used.
+ this.element_ = opt_options.element;
+ this.left_start_ratio_ = opt_options.left_start_ratio;
+ this.top_start_ratio_ = opt_options.top_start_ratio;
+ this.left_end_ratio_ = opt_options.left_end_ratio;
+ this.top_end_ratio_ = opt_options.top_end_ratio;
+ this.speed_ = opt_options.speed;
+ this.gesture_source_type_ = opt_options.gesture_source_type;
+ } else {
+ this.element_ = document.body;
+ this.speed_ = 800;
+ this.gesture_source_type_ = chrome.gpuBenchmarking.MOUSE_INPUT;
+ }
+ }
+
+ function supportedByBrowser() {
+ return !!(window.chrome &&
+ chrome.gpuBenchmarking &&
+ chrome.gpuBenchmarking.smoothDrag);
+ }
+
+ // This class performs drag action using given start and end positions,
+ // by a single drag gesture.
+ function DragAction(opt_callback) {
+ var self = this;
petrcermak 2015/02/25 11:35:48 No need for "self" because you don't use it in any
ssid 2015/02/27 11:35:15 Done.
+
+ this.beginMeasuringHook = function() {}
+ this.endMeasuringHook = function() {}
petrcermak 2015/02/25 11:35:48 You don't seem to be really using these hooks anyw
+
+ this.callback_ = opt_callback;
+ }
+
+ DragAction.prototype.start = function(opt_options) {
+ this.options_ = new DragGestureOptions(opt_options);
+ // Assign this.element_ here instead of constructor, because the constructor
petrcermak 2015/02/25 11:35:48 Which constructor? The DragAction constructor cert
+ // ensures this method will be called after the document is loaded.
+ this.element_ = this.options_.element_;
+ requestAnimationFrame(this.startGesture_.bind(this));
+ };
+
+ DragAction.prototype.startGesture_ = function() {
+ this.beginMeasuringHook();
+
+ var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_);
+ var start_left =
+ rect.left + rect.width * this.options_.left_start_ratio_;
+ var start_top =
+ rect.top + rect.height * this.options_.top_start_ratio_;
+ var end_left =
+ rect.left + rect.width * this.options_.left_end_ratio_;
+ var end_top =
+ rect.top + rect.height * this.options_.top_end_ratio_;
+ chrome.gpuBenchmarking.smoothDrag(
+ start_left, start_top, end_left, end_top,
+ this.onGestureComplete_.bind(this), this.options_.gesture_source_type_,
+ this.options_.speed_);
+ };
+
+ DragAction.prototype.onGestureComplete_ = function() {
+ this.endMeasuringHook();
+
+ // We're done.
+ if (this.callback_)
+ this.callback_();
+ };
+
+ window.__DragAction = DragAction;
+ window.__DragAction_SupportedByBrowser = supportedByBrowser;
+})();

Powered by Google App Engine
This is Rietveld 408576698