| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 case ui::ET_TOUCH_RELEASED: | 109 case ui::ET_TOUCH_RELEASED: |
| 109 native_viewport_->ReleaseCapture(); | 110 native_viewport_->ReleaseCapture(); |
| 110 break; | 111 break; |
| 111 default: | 112 default: |
| 112 break; | 113 break; |
| 113 } | 114 } |
| 114 | 115 |
| 115 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) | 116 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) |
| 116 return false; | 117 return false; |
| 117 | 118 |
| 118 EventPtr event(Event::New()); | 119 client()->OnEvent( |
| 119 event->action = ui_event->type(); | 120 TypeConverter<EventPtr, ui::Event>::ConvertFrom(*ui_event), |
| 120 event->flags = ui_event->flags(); | 121 base::Bind(&NativeViewportImpl::AckEvent, |
| 121 event->time_stamp = ui_event->time_stamp().ToInternalValue(); | 122 base::Unretained(this))); |
| 122 | |
| 123 if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { | |
| 124 ui::LocatedEvent* located_event = | |
| 125 static_cast<ui::LocatedEvent*>(ui_event); | |
| 126 event->location = Point::New(); | |
| 127 event->location->x = located_event->location().x(); | |
| 128 event->location->y = located_event->location().y(); | |
| 129 } | |
| 130 | |
| 131 if (ui_event->IsTouchEvent()) { | |
| 132 ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); | |
| 133 event->touch_data = TouchData::New(); | |
| 134 event->touch_data->pointer_id = touch_event->touch_id(); | |
| 135 } else if (ui_event->IsKeyEvent()) { | |
| 136 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); | |
| 137 event->key_data = KeyData::New(); | |
| 138 event->key_data->key_code = key_event->key_code(); | |
| 139 event->key_data->is_char = key_event->is_char(); | |
| 140 } | |
| 141 | |
| 142 client()->OnEvent(event.Pass(), | |
| 143 base::Bind(&NativeViewportImpl::AckEvent, | |
| 144 base::Unretained(this))); | |
| 145 waiting_for_event_ack_ = true; | 123 waiting_for_event_ack_ = true; |
| 146 return false; | 124 return false; |
| 147 } | 125 } |
| 148 | 126 |
| 149 virtual void OnAcceleratedWidgetAvailable( | 127 virtual void OnAcceleratedWidgetAvailable( |
| 150 gfx::AcceleratedWidget widget) OVERRIDE { | 128 gfx::AcceleratedWidget widget) OVERRIDE { |
| 151 widget_ = widget; | 129 widget_ = widget; |
| 152 CreateCommandBufferIfNeeded(); | 130 CreateCommandBufferIfNeeded(); |
| 153 } | 131 } |
| 154 | 132 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 178 | 156 |
| 179 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* | 157 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* |
| 180 CreateNativeViewportService( | 158 CreateNativeViewportService( |
| 181 mojo::shell::Context* context, | 159 mojo::shell::Context* context, |
| 182 mojo::ScopedMessagePipeHandle service_provider_handle) { | 160 mojo::ScopedMessagePipeHandle service_provider_handle) { |
| 183 mojo::Application* app = new mojo::Application( | 161 mojo::Application* app = new mojo::Application( |
| 184 service_provider_handle.Pass()); | 162 service_provider_handle.Pass()); |
| 185 app->AddService<mojo::services::NativeViewportImpl>(context); | 163 app->AddService<mojo::services::NativeViewportImpl>(context); |
| 186 return app; | 164 return app; |
| 187 } | 165 } |
| OLD | NEW |