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

Side by Side Diff: content/browser/renderer_host/ui_events_helper.cc

Issue 11339037: aura-touch: Refactor some code so that both cros and win-aura can share some code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui_events_helper.h" 5 #include "content/browser/renderer_host/ui_events_helper.h"
6 6
7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
8 #include "ui/base/events/event.h" 8 #include "ui/base/events/event.h"
9 #include "ui/base/events/event_constants.h" 9 #include "ui/base/events/event_constants.h"
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 return ui::ET_TOUCH_MOVED; 46 return ui::ET_TOUCH_MOVED;
47 47
48 case WebKit::WebTouchPoint::StateCancelled: 48 case WebKit::WebTouchPoint::StateCancelled:
49 return ui::ET_TOUCH_CANCELLED; 49 return ui::ET_TOUCH_CANCELLED;
50 50
51 default: 51 default:
52 return ui::ET_UNKNOWN; 52 return ui::ET_UNKNOWN;
53 } 53 }
54 } 54 }
55 55
56 WebKit::WebTouchPoint::State TouchPointStateFromEvent(
57 const ui::TouchEvent* event) {
58 switch (event->type()) {
59 case ui::ET_TOUCH_PRESSED:
60 return WebKit::WebTouchPoint::StatePressed;
61 case ui::ET_TOUCH_RELEASED:
62 return WebKit::WebTouchPoint::StateReleased;
63 case ui::ET_TOUCH_MOVED:
64 return WebKit::WebTouchPoint::StateMoved;
65 case ui::ET_TOUCH_CANCELLED:
66 return WebKit::WebTouchPoint::StateCancelled;
67 default:
68 return WebKit::WebTouchPoint::StateUndefined;
69 }
70 }
71
72 WebKit::WebInputEvent::Type TouchEventTypeFromEvent(
73 const ui::TouchEvent* event) {
74 switch (event->type()) {
75 case ui::ET_TOUCH_PRESSED:
76 return WebKit::WebInputEvent::TouchStart;
77 case ui::ET_TOUCH_RELEASED:
78 return WebKit::WebInputEvent::TouchEnd;
79 case ui::ET_TOUCH_MOVED:
80 return WebKit::WebInputEvent::TouchMove;
81 case ui::ET_TOUCH_CANCELLED:
82 return WebKit::WebInputEvent::TouchCancel;
83 default:
84 return WebKit::WebInputEvent::Undefined;
85 }
86 }
87
56 } // namespace 88 } // namespace
57 89
58 namespace content { 90 namespace content {
59 91
60 bool MakeUITouchEventsFromWebTouchEvents(const WebKit::WebTouchEvent& touch, 92 bool MakeUITouchEventsFromWebTouchEvents(const WebKit::WebTouchEvent& touch,
61 ScopedVector<ui::TouchEvent>* list) { 93 ScopedVector<ui::TouchEvent>* list) {
62 ui::EventType type = ui::ET_UNKNOWN; 94 ui::EventType type = ui::ET_UNKNOWN;
63 switch (touch.type) { 95 switch (touch.type) {
64 case WebKit::WebInputEvent::TouchStart: 96 case WebKit::WebInputEvent::TouchStart:
65 type = ui::ET_TOUCH_PRESSED; 97 type = ui::ET_TOUCH_PRESSED;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 timestamp, 133 timestamp,
102 point.radiusX, 134 point.radiusX,
103 point.radiusY, 135 point.radiusY,
104 point.rotationAngle, 136 point.rotationAngle,
105 point.force); 137 point.force);
106 list->push_back(uievent); 138 list->push_back(uievent);
107 } 139 }
108 return true; 140 return true;
109 } 141 }
110 142
143 int EventFlagsToWebEventModifiers(int flags) {
144 int modifiers = 0;
145 if (flags & ui::EF_SHIFT_DOWN)
146 modifiers |= WebKit::WebInputEvent::ShiftKey;
147 if (flags & ui::EF_CONTROL_DOWN)
148 modifiers |= WebKit::WebInputEvent::ControlKey;
149 if (flags & ui::EF_ALT_DOWN)
150 modifiers |= WebKit::WebInputEvent::AltKey;
151 // TODO(beng): MetaKey/META_MASK
152 if (flags & ui::EF_LEFT_MOUSE_BUTTON)
153 modifiers |= WebKit::WebInputEvent::LeftButtonDown;
154 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON)
155 modifiers |= WebKit::WebInputEvent::MiddleButtonDown;
156 if (flags & ui::EF_RIGHT_MOUSE_BUTTON)
157 modifiers |= WebKit::WebInputEvent::RightButtonDown;
158 if (flags & ui::EF_CAPS_LOCK_DOWN)
159 modifiers |= WebKit::WebInputEvent::CapsLockOn;
160 return modifiers;
161 }
162
163 WebKit::WebTouchPoint* UpdateWebTouchEventFromUIEvent(
164 ui::TouchEvent* event,
165 WebKit::WebTouchEvent* web_event) {
166 WebKit::WebTouchPoint* point = NULL;
167 switch (event->type()) {
168 case ui::ET_TOUCH_PRESSED:
169 // Add a new touch point.
170 if (web_event->touchesLength < WebKit::WebTouchEvent::touchesLengthCap) {
171 point = &web_event->touches[web_event->touchesLength++];
172 point->id = event->touch_id();
173 }
174 break;
175 case ui::ET_TOUCH_RELEASED:
176 case ui::ET_TOUCH_CANCELLED:
177 case ui::ET_TOUCH_MOVED: {
178 // The touch point should have been added to the event from an earlier
179 // _PRESSED event. So find that.
180 // At the moment, only a maximum of 4 touch-points are allowed. So a
181 // simple loop should be sufficient.
182 for (unsigned i = 0; i < web_event->touchesLength; ++i) {
183 point = web_event->touches + i;
184 if (point->id == event->touch_id())
185 break;
186 point = NULL;
187 }
188 break;
189 }
190 default:
191 DLOG(WARNING) << "Unknown touch event " << event->type();
192 break;
193 }
194
195 if (!point)
196 return NULL;
197
198 // The spec requires the radii values to be positive (and 1 when unknown).
199 point->radiusX = std::max(1.f, event->radius_x());
200 point->radiusY = std::max(1.f, event->radius_y());
201 point->rotationAngle = event->rotation_angle();
202 point->force = event->force();
203
204 // Update the location and state of the point.
205 point->state = TouchPointStateFromEvent(event);
206 if (point->state == WebKit::WebTouchPoint::StateMoved) {
207 // It is possible for badly written touch drivers to emit Move events even
208 // when the touch location hasn't changed. In such cases, consume the event
209 // and pretend nothing happened.
210 if (point->position.x == event->x() && point->position.y == event->y())
211 return NULL;
212 }
213 point->position.x = event->x();
214 point->position.y = event->y();
215
216 const gfx::Point root_point = event->root_location();
217 point->screenPosition.x = root_point.x();
218 point->screenPosition.y = root_point.y();
219
220 // Mark the rest of the points as stationary.
221 for (unsigned i = 0; i < web_event->touchesLength; ++i) {
222 WebKit::WebTouchPoint* iter = web_event->touches + i;
223 if (iter != point)
224 iter->state = WebKit::WebTouchPoint::StateStationary;
225 }
226
227 // Update the type of the touch event.
228 web_event->type = TouchEventTypeFromEvent(event);
229 web_event->timeStampSeconds = event->time_stamp().InSecondsF();
230 web_event->modifiers = EventFlagsToWebEventModifiers(event->flags());
231
232 return point;
233 }
234
111 } // namespace content 235 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/ui_events_helper.h ('k') | content/browser/renderer_host/web_input_event_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698