Index: content/browser/renderer_host/ui_events_helper.cc |
diff --git a/content/browser/renderer_host/ui_events_helper.cc b/content/browser/renderer_host/ui_events_helper.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c6ddf16cb1441cabbff2964fb29ec463d881ffb9 |
--- /dev/null |
+++ b/content/browser/renderer_host/ui_events_helper.cc |
@@ -0,0 +1,80 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/renderer_host/ui_events_helper.h" |
+ |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
+#include "ui/base/events/event.h" |
+#include "ui/base/events/event_constants.h" |
+ |
+namespace { |
+ |
+int WebModifiersToUIFlags(int modifiers) { |
+ int flags = ui::EF_NONE; |
+ |
+ if (modifiers & WebKit::WebInputEvent::ShiftKey) |
+ flags |= ui::EF_SHIFT_DOWN; |
+ if (modifiers & WebKit::WebInputEvent::ControlKey) |
+ flags |= ui::EF_CONTROL_DOWN; |
+ if (modifiers & WebKit::WebInputEvent::AltKey) |
+ flags |= ui::EF_ALT_DOWN; |
+ |
+ if (modifiers & WebKit::WebInputEvent::LeftButtonDown) |
+ flags |= ui::EF_LEFT_MOUSE_BUTTON; |
+ if (modifiers & WebKit::WebInputEvent::RightButtonDown) |
+ flags |= ui::EF_RIGHT_MOUSE_BUTTON; |
+ if (modifiers & WebKit::WebInputEvent::MiddleButtonDown) |
+ flags |= ui::EF_MIDDLE_MOUSE_BUTTON; |
+ |
+ if (modifiers & WebKit::WebInputEvent::CapsLockOn) |
+ flags |= ui::EF_CAPS_LOCK_DOWN; |
+ |
+ return flags; |
+} |
+ |
+} // namespace |
+ |
+namespace content { |
+ |
+bool MakeUITouchEventsFromWebTouchEvents(const WebKit::WebTouchEvent& touch, |
+ ScopedVector<ui::TouchEvent>* list) { |
+ ui::EventType type = ui::ET_UNKNOWN; |
+ switch (touch.type) { |
+ case WebKit::WebInputEvent::TouchStart: |
+ type = ui::ET_TOUCH_PRESSED; |
+ break; |
+ case WebKit::WebInputEvent::TouchEnd: |
+ type = ui::ET_TOUCH_RELEASED; |
+ break; |
+ case WebKit::WebInputEvent::TouchMove: |
+ type = ui::ET_TOUCH_MOVED; |
+ break; |
+ case WebKit::WebInputEvent::TouchCancel: |
+ type = ui::ET_TOUCH_CANCELLED; |
+ break; |
+ default: |
+ NOTREACHED(); |
+ return false; |
+ } |
+ |
+ int flags = WebModifiersToUIFlags(touch.modifiers); |
+ base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( |
+ static_cast<int64>(touch.timeStampSeconds * 1000000)); |
+ for (unsigned i = 0; i < touch.touchesLength; ++i) { |
+ const WebKit::WebTouchPoint& point = touch.touches[i]; |
+ ui::TouchEvent* uievent = new ui::TouchEvent(type, |
+ gfx::Point(point.position.x, point.position.y), |
+ flags, |
+ point.id, |
+ timestamp, |
+ point.radiusX, |
+ point.radiusY, |
+ point.rotationAngle, |
+ point.force); |
+ list->push_back(uievent); |
+ } |
+ return true; |
+} |
+ |
+} // namespace content |