| 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/cpp/bindings/allocation_scope.h" | 10 #include "mojo/public/cpp/bindings/allocation_scope.h" |
| 11 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 11 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 12 #include "mojo/services/gles2/command_buffer_impl.h" | 12 #include "mojo/services/gles2/command_buffer_impl.h" |
| 13 #include "mojo/services/native_viewport/native_viewport.h" | 13 #include "mojo/services/native_viewport/native_viewport.h" |
| 14 #include "mojo/services/native_viewport/native_viewport.mojom.h" | 14 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
| 15 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 15 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 16 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
| 16 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 17 | 18 |
| 18 namespace mojo { | 19 namespace mojo { |
| 19 namespace services { | 20 namespace services { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 bool IsRateLimitedEventType(ui::Event* event) { | 23 bool IsRateLimitedEventType(ui::Event* event) { |
| 23 return event->type() == ui::ET_MOUSE_MOVED || | 24 return event->type() == ui::ET_MOUSE_MOVED || |
| 24 event->type() == ui::ET_MOUSE_DRAGGED || | 25 event->type() == ui::ET_MOUSE_DRAGGED || |
| 25 event->type() == ui::ET_TOUCH_MOVED; | 26 event->type() == ui::ET_TOUCH_MOVED; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 native_viewport_->ReleaseCapture(); | 113 native_viewport_->ReleaseCapture(); |
| 113 break; | 114 break; |
| 114 default: | 115 default: |
| 115 break; | 116 break; |
| 116 } | 117 } |
| 117 | 118 |
| 118 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) | 119 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) |
| 119 return false; | 120 return false; |
| 120 | 121 |
| 121 AllocationScope scope; | 122 AllocationScope scope; |
| 122 | 123 client()->OnEvent(*ui_event, |
| 123 Event::Builder event; | 124 base::Bind(&NativeViewportImpl::AckEvent, |
| 124 event.set_action(ui_event->type()); | 125 base::Unretained(this))); |
| 125 event.set_flags(ui_event->flags()); | |
| 126 event.set_time_stamp(ui_event->time_stamp().ToInternalValue()); | |
| 127 | |
| 128 if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { | |
| 129 ui::LocatedEvent* located_event = | |
| 130 static_cast<ui::LocatedEvent*>(ui_event); | |
| 131 Point::Builder location; | |
| 132 location.set_x(located_event->location().x()); | |
| 133 location.set_y(located_event->location().y()); | |
| 134 event.set_location(location.Finish()); | |
| 135 } | |
| 136 | |
| 137 if (ui_event->IsTouchEvent()) { | |
| 138 ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); | |
| 139 TouchData::Builder touch_data; | |
| 140 touch_data.set_pointer_id(touch_event->touch_id()); | |
| 141 event.set_touch_data(touch_data.Finish()); | |
| 142 } else if (ui_event->IsKeyEvent()) { | |
| 143 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); | |
| 144 KeyData::Builder key_data; | |
| 145 key_data.set_key_code(key_event->key_code()); | |
| 146 key_data.set_is_char(key_event->is_char()); | |
| 147 event.set_key_data(key_data.Finish()); | |
| 148 } | |
| 149 | |
| 150 client()->OnEvent(event.Finish(), | |
| 151 base::Bind(&NativeViewportImpl::AckEvent, | |
| 152 base::Unretained(this))); | |
| 153 waiting_for_event_ack_ = true; | 126 waiting_for_event_ack_ = true; |
| 154 return false; | 127 return false; |
| 155 } | 128 } |
| 156 | 129 |
| 157 virtual void OnAcceleratedWidgetAvailable( | 130 virtual void OnAcceleratedWidgetAvailable( |
| 158 gfx::AcceleratedWidget widget) OVERRIDE { | 131 gfx::AcceleratedWidget widget) OVERRIDE { |
| 159 widget_ = widget; | 132 widget_ = widget; |
| 160 CreateCommandBufferIfNeeded(); | 133 CreateCommandBufferIfNeeded(); |
| 161 } | 134 } |
| 162 | 135 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 187 | 160 |
| 188 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* | 161 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* |
| 189 CreateNativeViewportService( | 162 CreateNativeViewportService( |
| 190 mojo::shell::Context* context, | 163 mojo::shell::Context* context, |
| 191 mojo::ScopedMessagePipeHandle service_provider_handle) { | 164 mojo::ScopedMessagePipeHandle service_provider_handle) { |
| 192 mojo::Application* app = new mojo::Application( | 165 mojo::Application* app = new mojo::Application( |
| 193 service_provider_handle.Pass()); | 166 service_provider_handle.Pass()); |
| 194 app->AddService<mojo::services::NativeViewportImpl>(context); | 167 app->AddService<mojo::services::NativeViewportImpl>(context); |
| 195 return app; | 168 return app; |
| 196 } | 169 } |
| OLD | NEW |