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 "mojo/services/native_viewport/android/mojo_viewport.h" | 8 #include "mojo/services/native_viewport/android/mojo_viewport.h" |
9 #include "mojo/shell/context.h" | 9 #include "mojo/shell/context.h" |
10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
11 #include "ui/gfx/point.h" | 11 #include "ui/gfx/point.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 namespace services { | 14 namespace services { |
15 | 15 |
16 NativeViewportAndroid::NativeViewportAndroid(NativeViewportDelegate* delegate) | 16 NativeViewportAndroid::NativeViewportAndroid(shell::Context* context, |
| 17 NativeViewportDelegate* delegate) |
17 : delegate_(delegate), | 18 : delegate_(delegate), |
| 19 context_(context), |
18 window_(NULL), | 20 window_(NULL), |
19 id_generator_(0), | 21 id_generator_(0), |
20 weak_factory_(this) { | 22 weak_factory_(this) { |
21 } | 23 } |
22 | 24 |
23 NativeViewportAndroid::~NativeViewportAndroid() { | 25 NativeViewportAndroid::~NativeViewportAndroid() { |
24 if (window_) | 26 if (window_) |
25 ReleaseWindow(); | 27 ReleaseWindow(); |
26 } | 28 } |
27 | 29 |
(...skipping 29 matching lines...) Expand all Loading... |
57 | 59 |
58 void NativeViewportAndroid::ReleaseWindow() { | 60 void NativeViewportAndroid::ReleaseWindow() { |
59 ANativeWindow_release(window_); | 61 ANativeWindow_release(window_); |
60 window_ = NULL; | 62 window_ = NULL; |
61 } | 63 } |
62 | 64 |
63 gfx::Size NativeViewportAndroid::GetSize() { | 65 gfx::Size NativeViewportAndroid::GetSize() { |
64 return size_; | 66 return size_; |
65 } | 67 } |
66 | 68 |
| 69 void NativeViewportAndroid::Init() { |
| 70 MojoViewportInit* init = new MojoViewportInit(); |
| 71 init->ui_runner = context_->task_runners()->ui_runner(); |
| 72 init->native_viewport = GetWeakPtr(); |
| 73 |
| 74 context_->task_runners()->java_runner()->PostTask(FROM_HERE, |
| 75 base::Bind(MojoViewport::CreateForActivity, |
| 76 context_->activity(), |
| 77 init)); |
| 78 } |
| 79 |
67 void NativeViewportAndroid::Close() { | 80 void NativeViewportAndroid::Close() { |
68 // TODO(beng): close activity containing MojoView? | 81 // TODO(beng): close activity containing MojoView? |
69 | 82 |
70 // TODO(beng): perform this in response to view destruction. | 83 // TODO(beng): perform this in response to view destruction. |
71 delegate_->OnDestroyed(); | 84 delegate_->OnDestroyed(); |
72 } | 85 } |
73 | 86 |
74 // static | 87 // static |
75 scoped_ptr<NativeViewport> NativeViewport::Create( | 88 scoped_ptr<NativeViewport> NativeViewport::Create( |
76 shell::Context* context, | 89 shell::Context* context, |
77 NativeViewportDelegate* delegate) { | 90 NativeViewportDelegate* delegate) { |
78 scoped_ptr<NativeViewportAndroid> native_viewport( | 91 return scoped_ptr<NativeViewport>( |
79 new NativeViewportAndroid(delegate)); | 92 new NativeViewportAndroid(context, delegate)).Pass(); |
80 | |
81 MojoViewportInit* init = new MojoViewportInit(); | |
82 init->ui_runner = context->task_runners()->ui_runner(); | |
83 init->native_viewport = native_viewport->GetWeakPtr(); | |
84 | |
85 context->task_runners()->java_runner()->PostTask(FROM_HERE, | |
86 base::Bind(MojoViewport::CreateForActivity, | |
87 context->activity(), | |
88 init)); | |
89 | |
90 return scoped_ptr<NativeViewport>(native_viewport.Pass()); | |
91 } | 93 } |
92 | 94 |
93 } // namespace services | 95 } // namespace services |
94 } // namespace mojo | 96 } // namespace mojo |
OLD | NEW |