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

Side by Side Diff: telemetry/telemetry/internal/actions/pinch.js

Issue 3017493002: Fix coordinate calculations under pinch-zoom
Patch Set: Add comments Created 3 years, 3 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 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 // This file provides the PinchAction object, which zooms into or out of a 5 // This file provides the PinchAction object, which zooms into or out of a
6 // page by a given scale factor: 6 // page by a given scale factor:
7 // 1. var action = new __PinchAction(callback) 7 // 1. var action = new __PinchAction(callback)
8 // 2. action.start(pinch_options) 8 // 2. action.start(pinch_options)
9 'use strict'; 9 'use strict';
10 10
11 (function() { 11 (function() {
12 12
13 function PinchGestureOptions(opt_options) { 13 function PinchGestureOptions(opt_options) {
14 if (opt_options) { 14 if (opt_options) {
15 this.element_ = opt_options.element;
16 this.left_anchor_ratio_ = opt_options.left_anchor_ratio; 15 this.left_anchor_ratio_ = opt_options.left_anchor_ratio;
17 this.top_anchor_ratio_ = opt_options.top_anchor_ratio; 16 this.top_anchor_ratio_ = opt_options.top_anchor_ratio;
18 this.scale_factor_ = opt_options.scale_factor; 17 this.scale_factor_ = opt_options.scale_factor;
19 this.speed_ = opt_options.speed; 18 this.speed_ = opt_options.speed;
20 } else { 19 } else {
21 this.element_ = document.body;
22 this.left_anchor_ratio_ = 0.5; 20 this.left_anchor_ratio_ = 0.5;
23 this.top_anchor_ratio_ = 0.5; 21 this.top_anchor_ratio_ = 0.5;
24 this.scale_factor_ = 2.0; 22 this.scale_factor_ = 2.0;
25 this.speed_ = 800; 23 this.speed_ = 800;
26 } 24 }
27 } 25 }
28 26
29 function supportedByBrowser() { 27 function supportedByBrowser() {
30 return !!(window.chrome && 28 return !!(window.chrome &&
31 chrome.gpuBenchmarking && 29 chrome.gpuBenchmarking &&
(...skipping 15 matching lines...) Expand all
47 45
48 PinchAction.prototype.start = function(opt_options) { 46 PinchAction.prototype.start = function(opt_options) {
49 this.options_ = new PinchGestureOptions(opt_options); 47 this.options_ = new PinchGestureOptions(opt_options);
50 48
51 requestAnimationFrame(this.startPass_.bind(this)); 49 requestAnimationFrame(this.startPass_.bind(this));
52 }; 50 };
53 51
54 PinchAction.prototype.startPass_ = function() { 52 PinchAction.prototype.startPass_ = function() {
55 this.beginMeasuringHook(); 53 this.beginMeasuringHook();
56 54
57 var rect = __GestureCommon_GetBoundingVisibleRect(this.options_.element_); 55 // TODO(bokan): Remove else-block once gpuBenchmarking is changed to take
58 var anchor_left = 56 // all coordinates in viewport space. crbug.com/610021.
59 rect.left + rect.width * this.options_.left_anchor_ratio_; 57 let anchorLeft;
60 var anchor_top = 58 let anchorTop;
61 rect.top + rect.height * this.options_.top_anchor_ratio_; 59 if ('gesturesExpectedInViewportCoordinates' in chrome.gpuBenchmarking) {
60 anchorLeft =
61 __GestureCommon_GetWindowWidth() *
62 this.options_.left_anchor_ratio_;
63 anchorTop =
64 __GestureCommon_GetWindowHeight() *
65 this.options_.top_anchor_ratio_;
66 } else {
67 var rect = __GestureCommon_GetBoundingVisibleRect(document.body);
68 anchorLeft = rect.left + rect.width * this.options_.left_anchor_ratio_;
69 anchorTop = rect.top + rect.height * this.options_.top_anchor_ratio_;
70 }
71
62 chrome.gpuBenchmarking.pinchBy(this.options_.scale_factor_, 72 chrome.gpuBenchmarking.pinchBy(this.options_.scale_factor_,
63 anchor_left, anchor_top, 73 anchorLeft, anchorTop,
64 this.onGestureComplete_.bind(this), 74 this.onGestureComplete_.bind(this),
65 this.options_.speed_); 75 this.options_.speed_);
66 }; 76 };
67 77
68 PinchAction.prototype.onGestureComplete_ = function() { 78 PinchAction.prototype.onGestureComplete_ = function() {
69 this.endMeasuringHook(); 79 this.endMeasuringHook();
70 80
71 if (this.callback_) 81 if (this.callback_)
72 this.callback_(); 82 this.callback_();
73 }; 83 };
74 84
75 window.__PinchAction = PinchAction; 85 window.__PinchAction = PinchAction;
76 window.__PinchAction_SupportedByBrowser = supportedByBrowser; 86 window.__PinchAction_SupportedByBrowser = supportedByBrowser;
77 })(); 87 })();
OLDNEW
« no previous file with comments | « telemetry/telemetry/internal/actions/gesture_common.js ('k') | telemetry/telemetry/internal/actions/pinch.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698