Index: content/renderer/gpu/gpu_benchmarking_extension.cc |
diff --git a/content/renderer/gpu/gpu_benchmarking_extension.cc b/content/renderer/gpu/gpu_benchmarking_extension.cc |
index 68221886255898ee802d9565de7841ad6f73cf27..53fe1c16361be59d17441c77178e4d80f91bf616 100644 |
--- a/content/renderer/gpu/gpu_benchmarking_extension.cc |
+++ b/content/renderer/gpu/gpu_benchmarking_extension.cc |
@@ -14,6 +14,7 @@ |
#include "cc/layers/layer.h" |
#include "content/common/input/synthetic_gesture_params.h" |
#include "content/common/input/synthetic_pinch_gesture_params.h" |
+#include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
#include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
#include "content/common/input/synthetic_tap_gesture_params.h" |
#include "content/public/child/v8_value_converter.h" |
@@ -381,6 +382,44 @@ bool BeginSmoothScroll(v8::Isolate* isolate, |
return true; |
} |
+bool BeginSmoothDrag(v8::Isolate* isolate, |
+ int start_x, |
+ int start_y, |
+ int end_x, |
+ int end_y, |
+ v8::Handle<v8::Function> callback, |
+ int gesture_source_type, |
+ int speed_in_pixels_s) { |
+ GpuBenchmarkingContext context; |
+ if (!context.Init(false)) |
+ return false; |
+ scoped_refptr<CallbackAndContext> callback_and_context = |
+ new CallbackAndContext(isolate, callback, |
+ context.web_frame()->mainWorldScriptContext()); |
+ |
+ scoped_ptr<SyntheticSmoothDragGestureParams> gesture_params( |
+ new SyntheticSmoothDragGestureParams); |
+ |
+ // Convert coordinates from CSS pixels to density independent pixels (DIPs). |
+ float page_scale_factor = context.web_view()->pageScaleFactor(); |
+ |
+ gesture_params->start_point.SetPoint(start_x * page_scale_factor, |
+ start_y * page_scale_factor); |
+ gfx::Vector2d distance((end_x - start_x) * page_scale_factor, |
+ (end_y - start_y) * page_scale_factor); |
+ gesture_params->distances.push_back(distance); |
+ gesture_params->speed_in_pixels_s = speed_in_pixels_s * page_scale_factor; |
+ gesture_params->gesture_source_type = |
+ static_cast<SyntheticGestureParams::GestureSourceType>( |
+ gesture_source_type); |
+ |
+ context.render_view_impl()->QueueSyntheticGesture( |
+ gesture_params.Pass(), |
+ base::Bind(&OnSyntheticGestureCompleted, callback_and_context)); |
+ |
+ return true; |
+} |
+ |
} // namespace |
gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin}; |
@@ -425,6 +464,7 @@ gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder( |
.SetMethod("gestureSourceTypeSupported", |
&GpuBenchmarking::GestureSourceTypeSupported) |
.SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy) |
+ .SetMethod("smoothDrag", &GpuBenchmarking::SmoothDrag) |
.SetMethod("swipe", &GpuBenchmarking::Swipe) |
.SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce) |
// TODO(dominikg): Remove once JS interface changes have rolled into |
@@ -529,6 +569,39 @@ bool GpuBenchmarking::SmoothScrollBy(gin::Arguments* args) { |
start_y); |
} |
+bool GpuBenchmarking::SmoothDrag(gin::Arguments* args) { |
+ GpuBenchmarkingContext context; |
+ if (!context.Init(true)) |
+ return false; |
+ |
+ int start_x; |
Sami
2015/02/18 12:01:53
Let's make these coordinates floats too.
ssid
2015/02/18 17:57:35
Done.
|
+ int start_y; |
+ int end_x; |
+ int end_y; |
+ v8::Handle<v8::Function> callback; |
+ int gesture_source_type = 0; // Default input |
+ int speed_in_pixels_s = 800; |
+ |
+ if (!GetArg(args, &start_x) || |
+ !GetArg(args, &start_y) || |
+ !GetArg(args, &end_x) || |
+ !GetArg(args, &end_y) || |
+ !GetOptionalArg(args, &callback) || |
+ !GetOptionalArg(args, &gesture_source_type) || |
+ !GetOptionalArg(args, &speed_in_pixels_s)) { |
+ return false; |
+ } |
+ |
+ return BeginSmoothDrag(args->isolate(), |
+ start_x, |
+ start_y, |
+ end_x, |
+ end_y, |
+ callback, |
+ gesture_source_type, |
+ speed_in_pixels_s); |
+} |
+ |
bool GpuBenchmarking::Swipe(gin::Arguments* args) { |
GpuBenchmarkingContext context; |
if (!context.Init(true)) |