Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: mojo/services/native_viewport/native_viewport_service.cc

Issue 316713002: Wire input events through the ViewManagerClient interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/services/native_viewport/DEPS ('k') | mojo/services/public/cpp/input_events/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/weak_ptr.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/time/time.h" 10 #include "base/time/time.h"
10 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" 11 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
11 #include "mojo/services/gles2/command_buffer_impl.h" 12 #include "mojo/services/gles2/command_buffer_impl.h"
12 #include "mojo/services/native_viewport/native_viewport.h" 13 #include "mojo/services/native_viewport/native_viewport.h"
13 #include "mojo/services/native_viewport/native_viewport.mojom.h" 14 #include "mojo/services/native_viewport/native_viewport.mojom.h"
14 #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"
15 #include "ui/events/event.h" 17 #include "ui/events/event.h"
16 18
17 namespace mojo { 19 namespace mojo {
18 namespace services { 20 namespace services {
19 namespace { 21 namespace {
20 22
21 bool IsRateLimitedEventType(ui::Event* event) { 23 bool IsRateLimitedEventType(ui::Event* event) {
22 return event->type() == ui::ET_MOUSE_MOVED || 24 return event->type() == ui::ET_MOUSE_MOVED ||
23 event->type() == ui::ET_MOUSE_DRAGGED || 25 event->type() == ui::ET_MOUSE_DRAGGED ||
24 event->type() == ui::ET_TOUCH_MOVED; 26 event->type() == ui::ET_TOUCH_MOVED;
25 } 27 }
26 28
27 } 29 }
28 30
29 class NativeViewportImpl 31 class NativeViewportImpl
30 : public InterfaceImpl<mojo::NativeViewport>, 32 : public InterfaceImpl<mojo::NativeViewport>,
31 public NativeViewportDelegate { 33 public NativeViewportDelegate {
32 public: 34 public:
33 NativeViewportImpl(shell::Context* context) 35 NativeViewportImpl(shell::Context* context)
34 : context_(context), 36 : context_(context),
35 widget_(gfx::kNullAcceleratedWidget), 37 widget_(gfx::kNullAcceleratedWidget),
36 waiting_for_event_ack_(false) {} 38 waiting_for_event_ack_(false),
39 weak_factory_(this) {}
37 virtual ~NativeViewportImpl() { 40 virtual ~NativeViewportImpl() {
38 // Destroy the NativeViewport early on as it may call us back during 41 // Destroy the NativeViewport early on as it may call us back during
39 // destruction and we want to be in a known state. 42 // destruction and we want to be in a known state.
40 native_viewport_.reset(); 43 native_viewport_.reset();
41 } 44 }
42 45
43 virtual void Create(RectPtr bounds) OVERRIDE { 46 virtual void Create(RectPtr bounds) OVERRIDE {
44 native_viewport_ = 47 native_viewport_ =
45 services::NativeViewport::Create(context_, this); 48 services::NativeViewport::Create(context_, this);
46 native_viewport_->Init(bounds.To<gfx::Rect>()); 49 native_viewport_->Init(bounds.To<gfx::Rect>());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 case ui::ET_TOUCH_RELEASED: 108 case ui::ET_TOUCH_RELEASED:
106 native_viewport_->ReleaseCapture(); 109 native_viewport_->ReleaseCapture();
107 break; 110 break;
108 default: 111 default:
109 break; 112 break;
110 } 113 }
111 114
112 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) 115 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event))
113 return false; 116 return false;
114 117
115 EventPtr event(Event::New()); 118 client()->OnEvent(
116 event->action = ui_event->type(); 119 TypeConverter<EventPtr, ui::Event>::ConvertFrom(*ui_event),
117 event->flags = ui_event->flags(); 120 base::Bind(&NativeViewportImpl::AckEvent,
118 event->time_stamp = ui_event->time_stamp().ToInternalValue(); 121 weak_factory_.GetWeakPtr()));
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; 122 waiting_for_event_ack_ = true;
143 return false; 123 return false;
144 } 124 }
145 125
146 virtual void OnAcceleratedWidgetAvailable( 126 virtual void OnAcceleratedWidgetAvailable(
147 gfx::AcceleratedWidget widget) OVERRIDE { 127 gfx::AcceleratedWidget widget) OVERRIDE {
148 widget_ = widget; 128 widget_ = widget;
149 CreateCommandBufferIfNeeded(); 129 CreateCommandBufferIfNeeded();
150 } 130 }
151 131
152 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { 132 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE {
153 CreateCommandBufferIfNeeded(); 133 CreateCommandBufferIfNeeded();
154 client()->OnBoundsChanged(Rect::From(bounds)); 134 client()->OnBoundsChanged(Rect::From(bounds));
155 } 135 }
156 136
157 virtual void OnDestroyed() OVERRIDE { 137 virtual void OnDestroyed() OVERRIDE {
158 command_buffer_.reset(); 138 command_buffer_.reset();
159 client()->OnDestroyed(); 139 client()->OnDestroyed();
160 base::MessageLoop::current()->Quit(); 140 base::MessageLoop::current()->Quit();
161 } 141 }
162 142
163 private: 143 private:
164 shell::Context* context_; 144 shell::Context* context_;
165 gfx::AcceleratedWidget widget_; 145 gfx::AcceleratedWidget widget_;
166 scoped_ptr<services::NativeViewport> native_viewport_; 146 scoped_ptr<services::NativeViewport> native_viewport_;
167 InterfaceRequest<CommandBuffer> command_buffer_request_; 147 InterfaceRequest<CommandBuffer> command_buffer_request_;
168 scoped_ptr<CommandBufferImpl> command_buffer_; 148 scoped_ptr<CommandBufferImpl> command_buffer_;
169 bool waiting_for_event_ack_; 149 bool waiting_for_event_ack_;
150 base::WeakPtrFactory<NativeViewportImpl> weak_factory_;
170 }; 151 };
171 152
172 } // namespace services 153 } // namespace services
173 } // namespace mojo 154 } // namespace mojo
174 155
175 156
176 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* 157 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application*
177 CreateNativeViewportService( 158 CreateNativeViewportService(
178 mojo::shell::Context* context, 159 mojo::shell::Context* context,
179 mojo::ScopedMessagePipeHandle service_provider_handle) { 160 mojo::ScopedMessagePipeHandle service_provider_handle) {
180 mojo::Application* app = new mojo::Application( 161 mojo::Application* app = new mojo::Application(
181 service_provider_handle.Pass()); 162 service_provider_handle.Pass());
182 app->AddService<mojo::services::NativeViewportImpl>(context); 163 app->AddService<mojo::services::NativeViewportImpl>(context);
183 return app; 164 return app;
184 } 165 }
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/DEPS ('k') | mojo/services/public/cpp/input_events/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698