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

Side by Side Diff: components/html_viewer/touch_handler.cc

Issue 1677293002: Bye bye Mandoline (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moar Created 4 years, 10 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
« no previous file with comments | « components/html_viewer/touch_handler.h ('k') | components/html_viewer/web_clipboard_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/html_viewer/touch_handler.h"
6
7 #include "components/mus/public/interfaces/input_events.mojom.h"
8 #include "third_party/WebKit/public/web/WebInputEvent.h"
9 #include "third_party/WebKit/public/web/WebWidget.h"
10 #include "ui/events/base_event_utils.h"
11 #include "ui/events/blink/blink_event_util.h"
12 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
13 #include "ui/events/gesture_detection/motion_event_generic.h"
14
15 namespace html_viewer {
16 namespace {
17
18 // TODO(rjkroege): Gesture recognition currently happens in the html_viewer.
19 // In phase2, it will be relocated to MUS. Update this code at that time.
20 void SetPropertiesFromEvent(const mus::mojom::Event& event,
21 ui::PointerProperties* properties) {
22 if (event.pointer_data) {
23 properties->id = event.pointer_data->pointer_id;
24 if (event.pointer_data->location) {
25 properties->x = event.pointer_data->location->x;
26 properties->y = event.pointer_data->location->y;
27 properties->raw_x = event.pointer_data->location->screen_x;
28 properties->raw_y = event.pointer_data->location->screen_y;
29 }
30 }
31
32 if (event.pointer_data && event.pointer_data->brush_data &&
33 (event.pointer_data->kind == mus::mojom::PointerKind::TOUCH ||
34 event.pointer_data->kind == mus::mojom::PointerKind::PEN)) {
35 properties->pressure = event.pointer_data->brush_data->pressure;
36
37 // TODO(rjkroege): vary orientation for width, height.
38 properties->SetAxesAndOrientation(event.pointer_data->brush_data->width,
39 event.pointer_data->brush_data->height,
40 0.0);
41 } else {
42 if (event.flags & mus::mojom::kEventFlagLeftMouseButton ||
43 event.flags & mus::mojom::kEventFlagMiddleMouseButton ||
44 event.flags & mus::mojom::kEventFlagMiddleMouseButton) {
45 properties->pressure = 0.5;
46 } else {
47 properties->pressure = 0.0;
48 }
49 }
50 // TODO(sky): Add support for tool_type.
51 }
52
53 } // namespace
54
55 TouchHandler::TouchHandler(blink::WebWidget* web_widget)
56 : web_widget_(web_widget),
57 gesture_provider_(ui::GetGestureProviderConfig(
58 ui::GestureProviderConfigType::CURRENT_PLATFORM),
59 this) {
60 }
61
62 TouchHandler::~TouchHandler() {
63 }
64
65 void TouchHandler::OnTouchEvent(const mus::mojom::Event& event) {
66 if (!UpdateMotionEvent(event))
67 return;
68
69 SendMotionEventToGestureProvider();
70
71 PostProcessMotionEvent(event);
72 }
73
74 void TouchHandler::OnGestureEvent(const ui::GestureEventData& gesture) {
75 blink::WebGestureEvent web_gesture =
76 CreateWebGestureEventFromGestureEventData(gesture);
77 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to
78 // stop providing shift meta values to synthetic MotionEvents. This prevents
79 // unintended shift+click interpretation of all accessibility clicks.
80 // See crbug.com/443247.
81 if (web_gesture.type == blink::WebInputEvent::GestureTap &&
82 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) {
83 web_gesture.modifiers = 0;
84 }
85 web_widget_->handleInputEvent(web_gesture);
86 }
87
88 bool TouchHandler::UpdateMotionEvent(const mus::mojom::Event& event) {
89 ui::PointerProperties properties;
90 SetPropertiesFromEvent(event, &properties);
91
92 const base::TimeTicks timestamp(
93 base::TimeTicks::FromInternalValue(event.time_stamp));
94 if (current_motion_event_.get()) {
95 current_motion_event_->set_unique_event_id(ui::GetNextTouchEventId());
96 current_motion_event_->set_event_time(timestamp);
97 }
98
99 switch (event.action) {
100 case mus::mojom::EventType::POINTER_DOWN:
101 if (!current_motion_event_.get()) {
102 current_motion_event_.reset(new ui::MotionEventGeneric(
103 ui::MotionEvent::ACTION_DOWN, timestamp, properties));
104 } else {
105 const int index =
106 current_motion_event_->FindPointerIndexOfId(properties.id);
107 if (index != -1) {
108 DVLOG(1) << "pointer down and pointer already down id="
109 << properties.id;
110 return false;
111 }
112 current_motion_event_->PushPointer(properties);
113 current_motion_event_->set_action(ui::MotionEvent::ACTION_POINTER_DOWN);
114 current_motion_event_->set_action_index(static_cast<int>(index));
115 }
116 return true;
117
118 case mus::mojom::EventType::POINTER_UP: {
119 if (!current_motion_event_.get()) {
120 DVLOG(1) << "pointer up with no event, id=" << properties.id;
121 return false;
122 }
123 const int index =
124 current_motion_event_->FindPointerIndexOfId(properties.id);
125 if (index == -1) {
126 DVLOG(1) << "pointer up and pointer not down id=" << properties.id;
127 return false;
128 }
129 current_motion_event_->pointer(index) = properties;
130 current_motion_event_->set_action(
131 current_motion_event_->GetPointerCount() == 1
132 ? ui::MotionEvent::ACTION_UP
133 : ui::MotionEvent::ACTION_POINTER_UP);
134 current_motion_event_->set_action_index(static_cast<int>(index));
135 return true;
136 }
137
138 case mus::mojom::EventType::POINTER_MOVE: {
139 if (!current_motion_event_.get()) {
140 DVLOG(1) << "pointer move with no event, id=" << properties.id;
141 return false;
142 }
143 const int index =
144 current_motion_event_->FindPointerIndexOfId(properties.id);
145 if (index == -1) {
146 DVLOG(1) << "pointer move and pointer not down id=" << properties.id;
147 return false;
148 }
149 current_motion_event_->pointer(index) = properties;
150 current_motion_event_->set_action(ui::MotionEvent::ACTION_MOVE);
151 current_motion_event_->set_action_index(static_cast<int>(index));
152 return true;
153 }
154
155 case mus::mojom::EventType::POINTER_CANCEL: {
156 if (!current_motion_event_.get()) {
157 DVLOG(1) << "canel with no event, id=" << properties.id;
158 return false;
159 }
160 const int index =
161 current_motion_event_->FindPointerIndexOfId(properties.id);
162 if (index == -1) {
163 DVLOG(1) << "cancel and pointer not down id=" << properties.id;
164 return false;
165 }
166 current_motion_event_->pointer(index) = properties;
167 current_motion_event_->set_action(ui::MotionEvent::ACTION_CANCEL);
168 current_motion_event_->set_action_index(0);
169 return true;
170 }
171
172 default:
173 NOTREACHED();
174 }
175 return false;
176 }
177
178 void TouchHandler::SendMotionEventToGestureProvider() {
179 ui::FilteredGestureProvider::TouchHandlingResult result =
180 gesture_provider_.OnTouchEvent(*current_motion_event_);
181 if (!result.succeeded)
182 return;
183
184 blink::WebTouchEvent web_event = ui::CreateWebTouchEventFromMotionEvent(
185 *current_motion_event_, result.did_generate_scroll);
186 gesture_provider_.OnTouchEventAck(web_event.uniqueTouchEventId,
187 web_widget_->handleInputEvent(web_event) !=
188 blink::WebInputEventResult::NotHandled);
189 }
190
191 void TouchHandler::PostProcessMotionEvent(const mus::mojom::Event& event) {
192 switch (event.action) {
193 case mus::mojom::EventType::POINTER_UP: {
194 if (event.pointer_data) {
195 const int index = current_motion_event_->FindPointerIndexOfId(
196 event.pointer_data->pointer_id);
197 current_motion_event_->RemovePointerAt(index);
198 }
199 if (current_motion_event_->GetPointerCount() == 0)
200 current_motion_event_.reset();
201 break;
202 }
203
204 case mus::mojom::EventType::POINTER_CANCEL:
205 current_motion_event_.reset();
206 break;
207
208 default:
209 break;
210 }
211 }
212
213 } // namespace html_viewer
OLDNEW
« no previous file with comments | « components/html_viewer/touch_handler.h ('k') | components/html_viewer/web_clipboard_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698