OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/renderer_host/ui_events_helper.h" |
| 6 |
| 7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 8 #include "ui/base/events/event.h" |
| 9 #include "ui/base/events/event_constants.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 int WebModifiersToUIFlags(int modifiers) { |
| 14 int flags = ui::EF_NONE; |
| 15 |
| 16 if (modifiers & WebKit::WebInputEvent::ShiftKey) |
| 17 flags |= ui::EF_SHIFT_DOWN; |
| 18 if (modifiers & WebKit::WebInputEvent::ControlKey) |
| 19 flags |= ui::EF_CONTROL_DOWN; |
| 20 if (modifiers & WebKit::WebInputEvent::AltKey) |
| 21 flags |= ui::EF_ALT_DOWN; |
| 22 |
| 23 if (modifiers & WebKit::WebInputEvent::LeftButtonDown) |
| 24 flags |= ui::EF_LEFT_MOUSE_BUTTON; |
| 25 if (modifiers & WebKit::WebInputEvent::RightButtonDown) |
| 26 flags |= ui::EF_RIGHT_MOUSE_BUTTON; |
| 27 if (modifiers & WebKit::WebInputEvent::MiddleButtonDown) |
| 28 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; |
| 29 |
| 30 if (modifiers & WebKit::WebInputEvent::CapsLockOn) |
| 31 flags |= ui::EF_CAPS_LOCK_DOWN; |
| 32 |
| 33 return flags; |
| 34 } |
| 35 |
| 36 } // namespace |
| 37 |
| 38 namespace content { |
| 39 |
| 40 bool MakeUITouchEventsFromWebTouchEvents(const WebKit::WebTouchEvent& touch, |
| 41 ScopedVector<ui::TouchEvent>* list) { |
| 42 ui::EventType type = ui::ET_UNKNOWN; |
| 43 switch (touch.type) { |
| 44 case WebKit::WebInputEvent::TouchStart: |
| 45 type = ui::ET_TOUCH_PRESSED; |
| 46 break; |
| 47 case WebKit::WebInputEvent::TouchEnd: |
| 48 type = ui::ET_TOUCH_RELEASED; |
| 49 break; |
| 50 case WebKit::WebInputEvent::TouchMove: |
| 51 type = ui::ET_TOUCH_MOVED; |
| 52 break; |
| 53 case WebKit::WebInputEvent::TouchCancel: |
| 54 type = ui::ET_TOUCH_CANCELLED; |
| 55 break; |
| 56 default: |
| 57 NOTREACHED(); |
| 58 return false; |
| 59 } |
| 60 |
| 61 int flags = WebModifiersToUIFlags(touch.modifiers); |
| 62 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( |
| 63 static_cast<int64>(touch.timeStampSeconds * 1000000)); |
| 64 for (unsigned i = 0; i < touch.touchesLength; ++i) { |
| 65 const WebKit::WebTouchPoint& point = touch.touches[i]; |
| 66 ui::TouchEvent* uievent = new ui::TouchEvent(type, |
| 67 gfx::Point(point.position.x, point.position.y), |
| 68 flags, |
| 69 point.id, |
| 70 timestamp, |
| 71 point.radiusX, |
| 72 point.radiusY, |
| 73 point.rotationAngle, |
| 74 point.force); |
| 75 list->push_back(uievent); |
| 76 } |
| 77 return true; |
| 78 } |
| 79 |
| 80 } // namespace content |
OLD | NEW |