Commit 848ab674 authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

Support triple click in gpuBenchmarking.PointerActionSequence

When we are using gpuBenchmarking.PointerActionSequence to simulate
three mouse click, it only set the click count to 2, not 3. It should
keep the mouse click count and decide if we should increase the count or
set to 1 when we have a mouse press based on the interval of two mouse
presses and difference between the current mouse positions and the last
one.

Bug: 1119679
Change-Id: If95c4da4aa62ae897204badfe1b1035f5240e0c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2446637Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Commit-Queue: Lan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816626}
parent f4464040
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "content/browser/renderer_host/input/synthetic_mouse_driver.h" #include "content/browser/renderer_host/input/synthetic_mouse_driver.h"
#include "build/build_config.h"
#include "content/browser/renderer_host/input/synthetic_gesture_target.h" #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
#include "third_party/blink/public/common/input/synthetic_web_input_event_builders.h" #include "third_party/blink/public/common/input/synthetic_web_input_event_builders.h"
...@@ -35,16 +36,16 @@ void SyntheticMouseDriver::Press(float x, ...@@ -35,16 +36,16 @@ void SyntheticMouseDriver::Press(float x,
float force, float force,
const base::TimeTicks& timestamp) { const base::TimeTicks& timestamp) {
DCHECK_EQ(index, 0); DCHECK_EQ(index, 0);
blink::WebMouseEvent::Button pressed_button =
SyntheticPointerActionParams::GetWebMouseEventButton(button);
click_count_ = ComputeClickCount(timestamp, pressed_button, x, y);
int modifiers = int modifiers =
SyntheticPointerActionParams::GetWebMouseEventModifier(button); SyntheticPointerActionParams::GetWebMouseEventModifier(button);
mouse_event_ = blink::SyntheticWebMouseEventBuilder::Build( mouse_event_ = blink::SyntheticWebMouseEventBuilder::Build(
blink::WebInputEvent::Type::kMouseDown, x, y, blink::WebInputEvent::Type::kMouseDown, x, y,
modifiers | key_modifiers | last_modifiers_, mouse_event_.pointer_type); modifiers | key_modifiers | last_modifiers_, mouse_event_.pointer_type);
mouse_event_.button = mouse_event_.button = pressed_button;
SyntheticPointerActionParams::GetWebMouseEventButton(button);
last_modifiers_ = modifiers | last_modifiers_; last_modifiers_ = modifiers | last_modifiers_;
bool is_repeated_click = IsRepeatedClickEvent(timestamp, x, y);
click_count_ = is_repeated_click ? 2 : 1;
mouse_event_.click_count = click_count_; mouse_event_.click_count = click_count_;
last_mouse_click_time_ = timestamp; last_mouse_click_time_ = timestamp;
last_x_ = x; last_x_ = x;
...@@ -125,27 +126,38 @@ bool SyntheticMouseDriver::UserInputCheck( ...@@ -125,27 +126,38 @@ bool SyntheticMouseDriver::UserInputCheck(
return true; return true;
} }
bool SyntheticMouseDriver::IsRepeatedClickEvent( int SyntheticMouseDriver::ComputeClickCount(
const base::TimeTicks& timestamp, const base::TimeTicks& timestamp,
blink::WebMouseEvent::Button pressed_button,
float x, float x,
float y) { float y) {
const int kDoubleClickTimeMS = 500; const int kDoubleClickTimeMS = 500;
const int kDoubleClickRange = 4; const int kDoubleClickRange = 4;
if (click_count_ == 0) if (click_count_ == 0)
return false; return 1;
base::TimeDelta time_difference = timestamp - last_mouse_click_time_; base::TimeDelta time_difference = timestamp - last_mouse_click_time_;
if (time_difference.InMilliseconds() > kDoubleClickTimeMS) if (time_difference.InMilliseconds() > kDoubleClickTimeMS)
return false; return 1;
if (std::abs(x - last_x_) > kDoubleClickRange / 2) if (std::abs(x - last_x_) > kDoubleClickRange / 2)
return false; return 1;
if (std::abs(y - last_y_) > kDoubleClickRange / 2) if (std::abs(y - last_y_) > kDoubleClickRange / 2)
return false; return 1;
return true; if (mouse_event_.button != pressed_button)
return 1;
++click_count_;
#if !defined(OS_MAC) && !defined(OS_WIN)
// On Mac and Windows, we keep incresing the click count, but on the other
// platforms, we reset the count to 1 when it is greater than 3.
if (click_count_ > 3)
click_count_ = 1;
#endif
return click_count_;
} }
} // namespace content } // namespace content
...@@ -57,7 +57,10 @@ class CONTENT_EXPORT SyntheticMouseDriver : public SyntheticPointerDriver { ...@@ -57,7 +57,10 @@ class CONTENT_EXPORT SyntheticMouseDriver : public SyntheticPointerDriver {
unsigned last_modifiers_ = 0; unsigned last_modifiers_ = 0;
private: private:
bool IsRepeatedClickEvent(const base::TimeTicks& timestamp, float x, float y); int ComputeClickCount(const base::TimeTicks& timestamp,
blink::WebMouseEvent::Button pressed_button,
float x,
float y);
int click_count_ = 0; int click_count_ = 0;
base::TimeTicks last_mouse_click_time_ = base::TimeTicks::Now(); base::TimeTicks last_mouse_click_time_ = base::TimeTicks::Now();
float last_x_ = 0; float last_x_ = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment