OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/services/native_viewport/native_viewport_service.h" | 5 #include "mojo/services/native_viewport/native_viewport_service.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 10 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
11 #include "mojo/services/gles2/command_buffer_impl.h" | 11 #include "mojo/services/gles2/command_buffer_impl.h" |
12 #include "mojo/services/native_viewport/native_viewport.h" | 12 #include "mojo/services/native_viewport/native_viewport.h" |
13 #include "mojo/services/native_viewport/native_viewport.mojom.h" | 13 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 15 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
15 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
16 | 17 |
17 namespace mojo { | 18 namespace mojo { |
18 namespace services { | 19 namespace services { |
19 namespace { | 20 namespace { |
20 | 21 |
21 bool IsRateLimitedEventType(ui::Event* event) { | 22 bool IsRateLimitedEventType(ui::Event* event) { |
22 return event->type() == ui::ET_MOUSE_MOVED || | 23 return event->type() == ui::ET_MOUSE_MOVED || |
23 event->type() == ui::ET_MOUSE_DRAGGED || | 24 event->type() == ui::ET_MOUSE_DRAGGED || |
24 event->type() == ui::ET_TOUCH_MOVED; | 25 event->type() == ui::ET_TOUCH_MOVED; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 case ui::ET_TOUCH_RELEASED: | 106 case ui::ET_TOUCH_RELEASED: |
106 native_viewport_->ReleaseCapture(); | 107 native_viewport_->ReleaseCapture(); |
107 break; | 108 break; |
108 default: | 109 default: |
109 break; | 110 break; |
110 } | 111 } |
111 | 112 |
112 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) | 113 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) |
113 return false; | 114 return false; |
114 | 115 |
115 EventPtr event(Event::New()); | 116 client()->OnEvent( |
116 event->action = ui_event->type(); | 117 TypeConverter<EventPtr, ui::Event>::ConvertFrom(*ui_event), |
117 event->flags = ui_event->flags(); | 118 base::Bind(&NativeViewportImpl::AckEvent, |
118 event->time_stamp = ui_event->time_stamp().ToInternalValue(); | 119 base::Unretained(this))); |
119 | |
120 if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { | |
121 ui::LocatedEvent* located_event = | |
122 static_cast<ui::LocatedEvent*>(ui_event); | |
123 event->location = Point::New(); | |
124 event->location->x = located_event->location().x(); | |
125 event->location->y = located_event->location().y(); | |
126 } | |
127 | |
128 if (ui_event->IsTouchEvent()) { | |
129 ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); | |
130 event->touch_data = TouchData::New(); | |
131 event->touch_data->pointer_id = touch_event->touch_id(); | |
132 } else if (ui_event->IsKeyEvent()) { | |
133 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); | |
134 event->key_data = KeyData::New(); | |
135 event->key_data->key_code = key_event->key_code(); | |
136 event->key_data->is_char = key_event->is_char(); | |
137 } | |
138 | |
139 client()->OnEvent(event.Pass(), | |
140 base::Bind(&NativeViewportImpl::AckEvent, | |
141 base::Unretained(this))); | |
142 waiting_for_event_ack_ = true; | 120 waiting_for_event_ack_ = true; |
143 return false; | 121 return false; |
144 } | 122 } |
145 | 123 |
146 virtual void OnAcceleratedWidgetAvailable( | 124 virtual void OnAcceleratedWidgetAvailable( |
147 gfx::AcceleratedWidget widget) OVERRIDE { | 125 gfx::AcceleratedWidget widget) OVERRIDE { |
148 widget_ = widget; | 126 widget_ = widget; |
149 CreateCommandBufferIfNeeded(); | 127 CreateCommandBufferIfNeeded(); |
150 } | 128 } |
151 | 129 |
(...skipping 23 matching lines...) Expand all Loading... |
175 | 153 |
176 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* | 154 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* |
177 CreateNativeViewportService( | 155 CreateNativeViewportService( |
178 mojo::shell::Context* context, | 156 mojo::shell::Context* context, |
179 mojo::ScopedMessagePipeHandle service_provider_handle) { | 157 mojo::ScopedMessagePipeHandle service_provider_handle) { |
180 mojo::Application* app = new mojo::Application( | 158 mojo::Application* app = new mojo::Application( |
181 service_provider_handle.Pass()); | 159 service_provider_handle.Pass()); |
182 app->AddService<mojo::services::NativeViewportImpl>(context); | 160 app->AddService<mojo::services::NativeViewportImpl>(context); |
183 return app; | 161 return app; |
184 } | 162 } |
OLD | NEW |