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

Side by Side Diff: content/browser/renderer_host/input/synthetic_mouse_driver.cc

Issue 2621353003: Replace mouse actions in pointer event tests with pointerActionSequence (Closed)
Patch Set: mouse test Created 3 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "content/browser/renderer_host/input/synthetic_mouse_driver.h" 5 #include "content/browser/renderer_host/input/synthetic_mouse_driver.h"
6 6
7 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" 7 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
8 8
9 namespace content { 9 namespace content {
10 10
11 SyntheticMouseDriver::SyntheticMouseDriver() {} 11 namespace {
12
13 unsigned GetWebMouseEventModifier(int button) {
14 switch (button) {
15 case 0:
Navid Zolghadr 2017/01/12 18:23:46 Do we ever hit this case? Should we ever have a ca
lanwei 2017/01/13 17:29:30 No, I just list all the case. Now, I will just lis
16 return 0;
17 case 1:
Navid Zolghadr 2017/01/12 18:23:46 Can we just use the same numbers as already existi
lanwei 2017/01/13 17:29:30 Done.
18 return blink::WebMouseEvent::LeftButtonDown;
19 case 2:
20 return blink::WebMouseEvent::MiddleButtonDown;
21 case 3:
22 return blink::WebMouseEvent::RightButtonDown;
23 }
24 NOTREACHED();
25 return 0;
26 }
27
28 blink::WebMouseEvent::Button GetWebMouseEventButton(int button) {
29 switch (button) {
30 case 0:
31 return blink::WebMouseEvent::Button::NoButton;
32 case 1:
33 return blink::WebMouseEvent::Button::Left;
34 case 2:
35 return blink::WebMouseEvent::Button::Middle;
36 case 3:
37 return blink::WebMouseEvent::Button::Right;
38 }
39 NOTREACHED();
40 return blink::WebMouseEvent::Button::NoButton;
41 }
42 }
43
44 SyntheticMouseDriver::SyntheticMouseDriver() : last_modifiers_(0) {}
12 45
13 SyntheticMouseDriver::~SyntheticMouseDriver() {} 46 SyntheticMouseDriver::~SyntheticMouseDriver() {}
14 47
15 void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target, 48 void SyntheticMouseDriver::DispatchEvent(SyntheticGestureTarget* target,
16 const base::TimeTicks& timestamp) { 49 const base::TimeTicks& timestamp) {
17 mouse_event_.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); 50 mouse_event_.setTimeStampSeconds(ConvertTimestampToSeconds(timestamp));
18 target->DispatchInputEventToPlatform(mouse_event_); 51 target->DispatchInputEventToPlatform(mouse_event_);
19 } 52 }
20 53
21 void SyntheticMouseDriver::Press(float x, float y, int index) { 54 void SyntheticMouseDriver::Press(float x, float y, int index, int button) {
22 DCHECK_EQ(index, 0); 55 DCHECK_EQ(index, 0);
56 int modifiers = GetWebMouseEventModifier(button);
23 mouse_event_ = SyntheticWebMouseEventBuilder::Build( 57 mouse_event_ = SyntheticWebMouseEventBuilder::Build(
24 blink::WebInputEvent::MouseDown, x, y, 0); 58 blink::WebInputEvent::MouseDown, x, y, modifiers | last_modifiers_);
25 mouse_event_.clickCount = 1; 59 mouse_event_.clickCount = 1;
60 mouse_event_.button = GetWebMouseEventButton(button);
61 last_modifiers_ = modifiers | last_modifiers_;
26 } 62 }
27 63
28 void SyntheticMouseDriver::Move(float x, float y, int index) { 64 void SyntheticMouseDriver::Move(float x, float y, int index) {
29 DCHECK_EQ(index, 0); 65 DCHECK_EQ(index, 0);
30 blink::WebMouseEvent::Button button = mouse_event_.button; 66 blink::WebMouseEvent::Button button = mouse_event_.button;
31 int click_count = mouse_event_.clickCount; 67 int click_count = mouse_event_.clickCount;
32 mouse_event_ = SyntheticWebMouseEventBuilder::Build( 68 mouse_event_ = SyntheticWebMouseEventBuilder::Build(
33 blink::WebInputEvent::MouseMove, x, y, 0); 69 blink::WebInputEvent::MouseMove, x, y, last_modifiers_);
34 mouse_event_.button = button; 70 mouse_event_.button = button;
35 mouse_event_.clickCount = click_count; 71 mouse_event_.clickCount = click_count;
36 } 72 }
37 73
38 void SyntheticMouseDriver::Release(int index) { 74 void SyntheticMouseDriver::Release(int index, int button) {
39 DCHECK_EQ(index, 0); 75 DCHECK_EQ(index, 0);
40 mouse_event_ = SyntheticWebMouseEventBuilder::Build( 76 mouse_event_ = SyntheticWebMouseEventBuilder::Build(
41 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y, 0); 77 blink::WebInputEvent::MouseUp, mouse_event_.x, mouse_event_.y,
78 last_modifiers_);
42 mouse_event_.clickCount = 1; 79 mouse_event_.clickCount = 1;
80 mouse_event_.button = GetWebMouseEventButton(button);
81 last_modifiers_ = last_modifiers_ & (~GetWebMouseEventModifier(button));
43 } 82 }
44 83
45 bool SyntheticMouseDriver::UserInputCheck( 84 bool SyntheticMouseDriver::UserInputCheck(
46 const SyntheticPointerActionParams& params) const { 85 const SyntheticPointerActionParams& params) const {
47 if (params.index() != 0) 86 if (params.index() != 0)
48 return false; 87 return false;
49 88
50 if (params.pointer_action_type() == 89 if (params.pointer_action_type() ==
51 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) { 90 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) {
52 return false; 91 return false;
53 } 92 }
54 93
55 if (params.pointer_action_type() == 94 if (params.pointer_action_type() ==
56 SyntheticPointerActionParams::PointerActionType::PRESS && 95 SyntheticPointerActionParams::PointerActionType::PRESS) {
57 mouse_event_.clickCount > 0) { 96 int modifiers = GetWebMouseEventModifier(params.button());
58 return false; 97 if (last_modifiers_ & modifiers)
98 return false;
59 } 99 }
60 100
61 if (params.pointer_action_type() == 101 if (params.pointer_action_type() ==
62 SyntheticPointerActionParams::PointerActionType::RELEASE && 102 SyntheticPointerActionParams::PointerActionType::RELEASE &&
63 mouse_event_.clickCount <= 0) { 103 mouse_event_.clickCount <= 0) {
64 return false; 104 return false;
65 } 105 }
66 106
67 return true; 107 return true;
68 } 108 }
69 109
70 } // namespace content 110 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698