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

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

Issue 2336803003: Make SyntheticPointerAction to flush the pointer action sequence (Closed)
Patch Set: return invaid when index is out bound Created 4 years 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_pointer_action.h" 5 #include "content/browser/renderer_host/input/synthetic_pointer_action.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/WebKit/public/platform/WebInputEvent.h" 8 #include "third_party/WebKit/public/platform/WebInputEvent.h"
9 #include "ui/events/latency_info.h" 9 #include "ui/events/latency_info.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 SyntheticPointerAction::SyntheticPointerAction( 13 SyntheticPointerAction::SyntheticPointerAction(
14 const SyntheticPointerActionParams& params) 14 const SyntheticPointerActionListParams& params)
15 : params_(params) {} 15 : params_(params),
16 16 gesture_source_type_(SyntheticGestureParams::DEFAULT_INPUT),
17 SyntheticPointerAction::SyntheticPointerAction( 17 state_(SETUP),
18 std::vector<SyntheticPointerActionParams>* param_list, 18 count_(0U) {}
19 SyntheticPointerDriver* synthetic_pointer_driver)
20 : param_list_(param_list),
21 synthetic_pointer_driver_(synthetic_pointer_driver) {}
22 19
23 SyntheticPointerAction::~SyntheticPointerAction() {} 20 SyntheticPointerAction::~SyntheticPointerAction() {}
24 21
25 SyntheticGesture::Result SyntheticPointerAction::ForwardInputEvents( 22 SyntheticGesture::Result SyntheticPointerAction::ForwardInputEvents(
26 const base::TimeTicks& timestamp, 23 const base::TimeTicks& timestamp,
27 SyntheticGestureTarget* target) { 24 SyntheticGestureTarget* target) {
28 DCHECK(synthetic_pointer_driver_); 25 if (state_ == SETUP) {
29 return ForwardTouchOrMouseInputEvents(timestamp, target); 26 gesture_source_type_ = params_.gesture_source_type;
27 if (gesture_source_type_ == SyntheticGestureParams::DEFAULT_INPUT)
28 gesture_source_type_ = target->GetDefaultSyntheticGestureSourceType();
29
30 state_ = RUNNING;
31 }
32
33 DCHECK_NE(gesture_source_type_, SyntheticGestureParams::DEFAULT_INPUT);
34
35 if (!synthetic_pointer_driver_) {
36 synthetic_pointer_driver_ =
37 SyntheticPointerDriver::Create(gesture_source_type_);
tdresser 2016/12/13 14:37:43 Should this happen only when the state is SETUP?
lanwei 2016/12/18 17:35:55 Done.
38 }
39
40 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT ||
41 gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) {
42 state_ = ForwardTouchOrMouseInputEvents(timestamp, target);
43 } else {
44 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED;
tdresser 2016/12/13 14:37:43 Could we move this return up by the DCHECK that we
lanwei 2016/12/18 17:35:55 Done.
45 }
46
47 if (state_ == INVALID)
48 return POINTER_ACTION_INPUT_INVALID;
49
50 return (state_ == DONE) ? SyntheticGesture::GESTURE_FINISHED
51 : SyntheticGesture::GESTURE_RUNNING;
30 } 52 }
31 53
32 SyntheticGesture::Result SyntheticPointerAction::ForwardTouchOrMouseInputEvents( 54 SyntheticPointerAction::GestureState
55 SyntheticPointerAction::ForwardTouchOrMouseInputEvents(
33 const base::TimeTicks& timestamp, 56 const base::TimeTicks& timestamp,
34 SyntheticGestureTarget* target) { 57 SyntheticGestureTarget* target) {
35 for (SyntheticPointerActionParams& params : *param_list_) { 58 DCHECK_GE(count_, 0U);
36 if (!synthetic_pointer_driver_->UserInputCheck(params)) 59 DCHECK_LT(count_, params_.params.size());
37 return POINTER_ACTION_INPUT_INVALID; 60 SyntheticPointerActionListParams::ParamList& param_list =
61 params_.params[count_];
62 for (SyntheticPointerActionParams& param : param_list) {
63 if (param.gesture_source_type() == SyntheticGestureParams::DEFAULT_INPUT)
64 param.set_gesture_source_type(gesture_source_type_);
tdresser 2016/12/13 14:37:43 I know we've talked about this before, but I can't
lanwei 2016/12/18 17:35:55 Yes, the reason we have it in both SyntheticPointe
tdresser 2016/12/19 15:11:53 Yeah, let's remove it for now.
38 65
39 switch (params.pointer_action_type()) { 66 if (!synthetic_pointer_driver_->UserInputCheck(param))
40 case SyntheticPointerActionParams::PointerActionType::PRESS: { 67 return INVALID;
41 int index = synthetic_pointer_driver_->Press(params.position().x(), 68
42 params.position().y()); 69 switch (param.pointer_action_type()) {
43 params.set_index(index); 70 case SyntheticPointerActionParams::PointerActionType::PRESS:
71 synthetic_pointer_driver_->Press(param.position().x(),
72 param.position().y(), param.index());
44 break; 73 break;
45 }
46 case SyntheticPointerActionParams::PointerActionType::MOVE: 74 case SyntheticPointerActionParams::PointerActionType::MOVE:
47 synthetic_pointer_driver_->Move(params.position().x(), 75 synthetic_pointer_driver_->Move(param.position().x(),
48 params.position().y(), params.index()); 76 param.position().y(), param.index());
49 break; 77 break;
50 case SyntheticPointerActionParams::PointerActionType::RELEASE: 78 case SyntheticPointerActionParams::PointerActionType::RELEASE:
51 synthetic_pointer_driver_->Release(params.index()); 79 synthetic_pointer_driver_->Release(param.index());
52 // Only reset the index for touch pointers.
53 if (params.gesture_source_type != SyntheticGestureParams::MOUSE_INPUT)
54 params.set_index(-1);
55 break;
56 case SyntheticPointerActionParams::PointerActionType::IDLE:
57 break; 80 break;
58 case SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED: 81 case SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED:
59 return POINTER_ACTION_INPUT_INVALID; 82 return INVALID;
60 case SyntheticPointerActionParams::PointerActionType::FINISH:
61 return GESTURE_FINISHED;
62 } 83 }
63 } 84 }
64 synthetic_pointer_driver_->DispatchEvent(target, timestamp); 85 synthetic_pointer_driver_->DispatchEvent(target, timestamp);
65 return GESTURE_FINISHED; 86 count_++;
87 if (count_ == params_.params.size())
88 return DONE;
89 else
90 return RUNNING;
66 } 91 }
67 92
68 } // namespace content 93 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698