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

Side by Side Diff: mojo/services/html_viewer/touch_handler.cc

Issue 1099303002: Move html_viewer from mojo/services to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 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
(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 "mojo/services/html_viewer/touch_handler.h"
6
7 #include "third_party/WebKit/public/web/WebInputEvent.h"
8 #include "third_party/WebKit/public/web/WebView.h"
9 #include "third_party/mojo_services/src/input_events/public/interfaces/input_eve nts.mojom.h"
10 #include "ui/events/blink/blink_event_util.h"
11 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
12 #include "ui/events/gesture_detection/motion_event_generic.h"
13
14 namespace html_viewer {
15 namespace {
16
17 void SetPropertiesFromEvent(const mojo::Event& event,
18 ui::PointerProperties* properties) {
19 properties->id = event.pointer_data->pointer_id;
20 properties->x = event.pointer_data->x;
21 properties->y = event.pointer_data->y;
22 properties->raw_x = event.pointer_data->screen_x;
23 properties->raw_y = event.pointer_data->screen_y;
24 properties->pressure = event.pointer_data->pressure;
25 properties->touch_major = event.pointer_data->radius_major;
26 properties->touch_minor = event.pointer_data->radius_minor;
27 properties->orientation = event.pointer_data->orientation;
28 // TODO(sky): Add support for tool_type.
29 }
30
31 } // namespace
32
33 TouchHandler::TouchHandler(blink::WebView* web_view)
34 : web_view_(web_view),
35 gesture_provider_(ui::GetGestureProviderConfig(
36 ui::GestureProviderConfigType::CURRENT_PLATFORM),
37 this) {
38 }
39
40 TouchHandler::~TouchHandler() {
41 }
42
43 void TouchHandler::OnTouchEvent(const mojo::Event& event) {
44 if (!UpdateMotionEvent(event))
45 return;
46
47 SendMotionEventToGestureProvider();
48
49 PostProcessMotionEvent(event);
50 }
51
52 void TouchHandler::OnGestureEvent(const ui::GestureEventData& gesture) {
53 blink::WebGestureEvent web_gesture =
54 CreateWebGestureEventFromGestureEventData(gesture);
55 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to
56 // stop providing shift meta values to synthetic MotionEvents. This prevents
57 // unintended shift+click interpretation of all accessibility clicks.
58 // See crbug.com/443247.
59 if (web_gesture.type == blink::WebInputEvent::GestureTap &&
60 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) {
61 web_gesture.modifiers = 0;
62 }
63 web_view_->handleInputEvent(web_gesture);
64 }
65
66 bool TouchHandler::UpdateMotionEvent(const mojo::Event& event) {
67 ui::PointerProperties properties;
68 SetPropertiesFromEvent(event, &properties);
69
70 const base::TimeTicks timestamp(
71 base::TimeTicks::FromInternalValue(event.time_stamp));
72 if (current_motion_event_.get()) {
73 current_motion_event_->set_id(current_motion_event_->GetId() + 1);
74 current_motion_event_->set_event_time(timestamp);
75 }
76
77 switch (event.action) {
78 case mojo::EVENT_TYPE_POINTER_DOWN:
79 if (!current_motion_event_.get()) {
80 current_motion_event_.reset(new ui::MotionEventGeneric(
81 ui::MotionEvent::ACTION_DOWN, timestamp, properties));
82 } else {
83 const int index =
84 current_motion_event_->FindPointerIndexOfId(properties.id);
85 if (index != -1) {
86 DVLOG(1) << "pointer down and pointer already down id="
87 << properties.id;
88 return false;
89 }
90 current_motion_event_->PushPointer(properties);
91 current_motion_event_->set_action(ui::MotionEvent::ACTION_POINTER_DOWN);
92 current_motion_event_->set_action_index(static_cast<int>(index));
93 }
94 return true;
95
96 case mojo::EVENT_TYPE_POINTER_UP: {
97 if (!current_motion_event_.get()) {
98 DVLOG(1) << "pointer up with no event, id=" << properties.id;
99 return false;
100 }
101 const int index =
102 current_motion_event_->FindPointerIndexOfId(properties.id);
103 if (index == -1) {
104 DVLOG(1) << "pointer up and pointer not down id=" << properties.id;
105 return false;
106 }
107 current_motion_event_->pointer(index) = properties;
108 current_motion_event_->set_action(
109 current_motion_event_->GetPointerCount() == 1
110 ? ui::MotionEvent::ACTION_UP
111 : ui::MotionEvent::ACTION_POINTER_UP);
112 current_motion_event_->set_action_index(static_cast<int>(index));
113 return true;
114 }
115
116 case mojo::EVENT_TYPE_POINTER_MOVE: {
117 if (!current_motion_event_.get()) {
118 DVLOG(1) << "pointer move with no event, id=" << properties.id;
119 return false;
120 }
121 const int index =
122 current_motion_event_->FindPointerIndexOfId(properties.id);
123 if (index == -1) {
124 DVLOG(1) << "pointer move and pointer not down id=" << properties.id;
125 return false;
126 }
127 current_motion_event_->pointer(index) = properties;
128 current_motion_event_->set_action(ui::MotionEvent::ACTION_MOVE);
129 current_motion_event_->set_action_index(static_cast<int>(index));
130 return true;
131 }
132
133 case mojo::EVENT_TYPE_POINTER_CANCEL: {
134 if (!current_motion_event_.get()) {
135 DVLOG(1) << "canel with no event, id=" << properties.id;
136 return false;
137 }
138 const int index =
139 current_motion_event_->FindPointerIndexOfId(properties.id);
140 if (index == -1) {
141 DVLOG(1) << "cancel and pointer not down id=" << properties.id;
142 return false;
143 }
144 current_motion_event_->pointer(index) = properties;
145 current_motion_event_->set_action(ui::MotionEvent::ACTION_CANCEL);
146 current_motion_event_->set_action_index(0);
147 return true;
148 }
149
150 default:
151 NOTREACHED();
152 }
153 return false;
154 }
155
156 void TouchHandler::SendMotionEventToGestureProvider() {
157 ui::FilteredGestureProvider::TouchHandlingResult result =
158 gesture_provider_.OnTouchEvent(*current_motion_event_);
159 if (!result.succeeded)
160 return;
161
162 blink::WebTouchEvent web_event = ui::CreateWebTouchEventFromMotionEvent(
163 *current_motion_event_, result.did_generate_scroll);
164 gesture_provider_.OnSyncTouchEventAck(web_view_->handleInputEvent(web_event));
165 }
166
167 void TouchHandler::PostProcessMotionEvent(const mojo::Event& event) {
168 switch (event.action) {
169 case mojo::EVENT_TYPE_POINTER_UP: {
170 const int index = current_motion_event_->FindPointerIndexOfId(
171 event.pointer_data->pointer_id);
172 current_motion_event_->RemovePointerAt(index);
173 if (current_motion_event_->GetPointerCount() == 0)
174 current_motion_event_.reset();
175 break;
176 }
177
178 case mojo::EVENT_TYPE_POINTER_CANCEL:
179 current_motion_event_.reset();
180 break;
181
182 default:
183 break;
184 }
185 }
186
187 } // namespace html_viewer
OLDNEW
« no previous file with comments | « mojo/services/html_viewer/touch_handler.h ('k') | mojo/services/html_viewer/web_clipboard_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698