OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "sky/shell/ui/input_event_converter.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/time/time.h" |
| 9 #include "sky/engine/public/platform/WebInputEvent.h" |
| 10 |
| 11 namespace sky { |
| 12 namespace { |
| 13 |
| 14 scoped_ptr<blink::WebInputEvent> BuildWebPointerEvent( |
| 15 const InputEventPtr& event, float device_pixel_ratio) { |
| 16 scoped_ptr<blink::WebPointerEvent> web_event(new blink::WebPointerEvent); |
| 17 |
| 18 web_event->timeStampMS = |
| 19 base::TimeDelta::FromInternalValue(event->time_stamp).InMillisecondsF(); |
| 20 |
| 21 switch (event->type) { |
| 22 case EVENT_TYPE_POINTER_DOWN: |
| 23 web_event->type = blink::WebInputEvent::PointerDown; |
| 24 break; |
| 25 case EVENT_TYPE_POINTER_UP: |
| 26 web_event->type = blink::WebInputEvent::PointerUp; |
| 27 break; |
| 28 case EVENT_TYPE_POINTER_MOVE: |
| 29 web_event->type = blink::WebInputEvent::PointerMove; |
| 30 break; |
| 31 case EVENT_TYPE_POINTER_CANCEL: |
| 32 web_event->type = blink::WebInputEvent::PointerCancel; |
| 33 break; |
| 34 default: |
| 35 NOTIMPLEMENTED() << "Received unexpected event: " << event->type; |
| 36 break; |
| 37 } |
| 38 |
| 39 if (event->pointer_data) { |
| 40 if (event->pointer_data->kind == POINTER_KIND_TOUCH) |
| 41 web_event->kind = blink::WebPointerEvent::Touch; |
| 42 web_event->pointer = event->pointer_data->pointer; |
| 43 web_event->x = event->pointer_data->x / device_pixel_ratio; |
| 44 web_event->y = event->pointer_data->y / device_pixel_ratio; |
| 45 } |
| 46 |
| 47 return web_event.Pass(); |
| 48 } |
| 49 |
| 50 } // namespace |
| 51 |
| 52 scoped_ptr<blink::WebInputEvent> ConvertEvent(const InputEventPtr& event, |
| 53 float device_pixel_ratio) { |
| 54 if (event->type == EVENT_TYPE_POINTER_DOWN || |
| 55 event->type == EVENT_TYPE_POINTER_UP || |
| 56 event->type == EVENT_TYPE_POINTER_MOVE || |
| 57 event->type == EVENT_TYPE_POINTER_CANCEL) { |
| 58 return BuildWebPointerEvent(event, device_pixel_ratio); |
| 59 } |
| 60 |
| 61 return scoped_ptr<blink::WebInputEvent>(); |
| 62 } |
| 63 |
| 64 } // namespace mojo |
OLD | NEW |