| 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_android.h" | 5 #include "mojo/services/native_viewport/native_viewport_android.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 #include "gpu/command_buffer/client/gl_in_process_context.h" | 8 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 10 #include "mojo/services/native_viewport/android/mojo_viewport.h" | 10 #include "mojo/services/native_viewport/android/mojo_viewport.h" |
| 11 #include "mojo/shell/context.h" | 11 #include "mojo/shell/context.h" |
| 12 #include "ui/events/event.h" |
| 13 #include "ui/gfx/point.h" |
| 12 | 14 |
| 13 namespace mojo { | 15 namespace mojo { |
| 14 namespace services { | 16 namespace services { |
| 15 | 17 |
| 16 NativeViewportAndroid::NativeViewportAndroid(NativeViewportDelegate* delegate) | 18 NativeViewportAndroid::NativeViewportAndroid(NativeViewportDelegate* delegate) |
| 17 : delegate_(delegate), | 19 : delegate_(delegate), |
| 18 window_(NULL), | 20 window_(NULL), |
| 21 id_generator_(0), |
| 19 weak_factory_(this) { | 22 weak_factory_(this) { |
| 20 } | 23 } |
| 21 | 24 |
| 22 NativeViewportAndroid::~NativeViewportAndroid() { | 25 NativeViewportAndroid::~NativeViewportAndroid() { |
| 23 if (window_) | 26 if (window_) |
| 24 ReleaseWindow(); | 27 ReleaseWindow(); |
| 25 } | 28 } |
| 26 | 29 |
| 27 void NativeViewportAndroid::OnNativeWindowCreated(ANativeWindow* window) { | 30 void NativeViewportAndroid::OnNativeWindowCreated(ANativeWindow* window) { |
| 28 DCHECK(!window_); | 31 DCHECK(!window_); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 45 void NativeViewportAndroid::OnNativeWindowDestroyed() { | 48 void NativeViewportAndroid::OnNativeWindowDestroyed() { |
| 46 DCHECK(window_); | 49 DCHECK(window_); |
| 47 ReleaseWindow(); | 50 ReleaseWindow(); |
| 48 } | 51 } |
| 49 | 52 |
| 50 void NativeViewportAndroid::OnResized(const gfx::Size& size) { | 53 void NativeViewportAndroid::OnResized(const gfx::Size& size) { |
| 51 size_ = size; | 54 size_ = size; |
| 52 delegate_->OnResized(size); | 55 delegate_->OnResized(size); |
| 53 } | 56 } |
| 54 | 57 |
| 58 void NativeViewportAndroid::OnMotionEvent(bool is_touch, |
| 59 int pointer_id, |
| 60 ui::EventType action, |
| 61 float x, float y, |
| 62 int64 time_ms) { |
| 63 gfx::Point location(static_cast<int>(x), static_cast<int>(y)); |
| 64 if (is_touch) { |
| 65 ui::TouchEvent event(action, location, |
| 66 id_generator_.GetGeneratedID(pointer_id), |
| 67 base::TimeDelta::FromMilliseconds(time_ms)); |
| 68 // TODO(beng): handle multiple touch-points. |
| 69 delegate_->OnEvent(&event); |
| 70 if (action == ui::ET_TOUCH_RELEASED) |
| 71 id_generator_.ReleaseNumber(pointer_id); |
| 72 } else { |
| 73 ui::MouseEvent event(action, location, location, 0); |
| 74 delegate_->OnEvent(&event); |
| 75 } |
| 76 } |
| 77 |
| 55 void NativeViewportAndroid::ReleaseWindow() { | 78 void NativeViewportAndroid::ReleaseWindow() { |
| 56 gl_context_.reset(); | 79 gl_context_.reset(); |
| 57 ANativeWindow_release(window_); | 80 ANativeWindow_release(window_); |
| 58 window_ = NULL; | 81 window_ = NULL; |
| 59 } | 82 } |
| 60 | 83 |
| 61 void NativeViewportAndroid::Close() { | 84 void NativeViewportAndroid::Close() { |
| 62 // TODO(beng): close activity containing MojoView? | 85 // TODO(beng): close activity containing MojoView? |
| 63 | 86 |
| 64 // TODO(beng): perform this in response to view destruction. | 87 // TODO(beng): perform this in response to view destruction. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 79 context->task_runners()->java_runner()->PostTask(FROM_HERE, | 102 context->task_runners()->java_runner()->PostTask(FROM_HERE, |
| 80 base::Bind(MojoViewport::CreateForActivity, | 103 base::Bind(MojoViewport::CreateForActivity, |
| 81 context->activity(), | 104 context->activity(), |
| 82 init)); | 105 init)); |
| 83 | 106 |
| 84 return scoped_ptr<NativeViewport>(native_viewport.Pass()); | 107 return scoped_ptr<NativeViewport>(native_viewport.Pass()); |
| 85 } | 108 } |
| 86 | 109 |
| 87 } // namespace services | 110 } // namespace services |
| 88 } // namespace mojo | 111 } // namespace mojo |
| OLD | NEW |