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/input.h> | 7 #include <android/input.h> |
8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
9 | 9 |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
11 #include "jni/NativeViewportAndroid_jni.h" | 11 #include "jni/NativeViewportAndroid_jni.h" |
12 #include "mojo/shell/context.h" | 12 #include "mojo/services/native_viewport/native_viewport_context.h" |
13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
14 #include "ui/gfx/point.h" | 14 #include "ui/gfx/point.h" |
15 | 15 |
16 namespace mojo { | 16 namespace mojo { |
17 namespace services { | 17 namespace services { |
18 | 18 |
19 ui::EventType MotionEventActionToEventType(jint action) { | 19 ui::EventType MotionEventActionToEventType(jint action) { |
20 switch (action) { | 20 switch (action) { |
21 case AMOTION_EVENT_ACTION_DOWN: | 21 case AMOTION_EVENT_ACTION_DOWN: |
22 return ui::ET_TOUCH_PRESSED; | 22 return ui::ET_TOUCH_PRESSED; |
23 case AMOTION_EVENT_ACTION_MOVE: | 23 case AMOTION_EVENT_ACTION_MOVE: |
24 return ui::ET_TOUCH_MOVED; | 24 return ui::ET_TOUCH_MOVED; |
25 case AMOTION_EVENT_ACTION_UP: | 25 case AMOTION_EVENT_ACTION_UP: |
26 return ui::ET_TOUCH_RELEASED; | 26 return ui::ET_TOUCH_RELEASED; |
27 default: | 27 default: |
28 NOTREACHED(); | 28 NOTREACHED(); |
29 } | 29 } |
30 return ui::ET_UNKNOWN; | 30 return ui::ET_UNKNOWN; |
31 } | 31 } |
32 | 32 |
33 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
34 // NativeViewportAndroid, public: | 34 // NativeViewportAndroid, public: |
35 | 35 |
36 // static | 36 // static |
37 bool NativeViewportAndroid::Register(JNIEnv* env) { | 37 bool NativeViewportAndroid::Register(JNIEnv* env) { |
38 return RegisterNativesImpl(env); | 38 return RegisterNativesImpl(env); |
39 } | 39 } |
40 | 40 |
41 NativeViewportAndroid::NativeViewportAndroid(shell::Context* context, | 41 NativeViewportAndroid::NativeViewportAndroid(NativeViewportContext* context, |
42 NativeViewportDelegate* delegate) | 42 NativeViewportDelegate* delegate) |
43 : delegate_(delegate), | 43 : delegate_(delegate), |
44 context_(context), | 44 context_(context), |
45 window_(NULL), | 45 window_(NULL), |
46 id_generator_(0), | 46 id_generator_(0), |
47 weak_factory_(this) { | 47 weak_factory_(this) { |
48 } | 48 } |
49 | 49 |
50 NativeViewportAndroid::~NativeViewportAndroid() { | 50 NativeViewportAndroid::~NativeViewportAndroid() { |
51 if (window_) | 51 if (window_) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 id_generator_.ReleaseNumber(pointer_id); | 96 id_generator_.ReleaseNumber(pointer_id); |
97 | 97 |
98 return true; | 98 return true; |
99 } | 99 } |
100 | 100 |
101 //////////////////////////////////////////////////////////////////////////////// | 101 //////////////////////////////////////////////////////////////////////////////// |
102 // NativeViewportAndroid, NativeViewport implementation: | 102 // NativeViewportAndroid, NativeViewport implementation: |
103 | 103 |
104 void NativeViewportAndroid::Init(const gfx::Rect& bounds) { | 104 void NativeViewportAndroid::Init(const gfx::Rect& bounds) { |
105 JNIEnv* env = base::android::AttachCurrentThread(); | 105 JNIEnv* env = base::android::AttachCurrentThread(); |
106 Java_NativeViewportAndroid_createForActivity(env, context_->activity(), | 106 Java_NativeViewportAndroid_createForActivity(env, context_->GetActivity(), |
qsr
2014/07/21 08:20:25
Any reason not to use base::android::GetApplicatio
| |
107 reinterpret_cast<jlong>(this)); | 107 reinterpret_cast<jlong>(this)); |
108 } | 108 } |
109 | 109 |
110 void NativeViewportAndroid::Show() { | 110 void NativeViewportAndroid::Show() { |
111 // Nothing to do. View is created visible. | 111 // Nothing to do. View is created visible. |
112 } | 112 } |
113 | 113 |
114 void NativeViewportAndroid::Hide() { | 114 void NativeViewportAndroid::Hide() { |
115 // Nothing to do. View is always visible. | 115 // Nothing to do. View is always visible. |
116 } | 116 } |
(...skipping 27 matching lines...) Expand all Loading... | |
144 void NativeViewportAndroid::ReleaseWindow() { | 144 void NativeViewportAndroid::ReleaseWindow() { |
145 ANativeWindow_release(window_); | 145 ANativeWindow_release(window_); |
146 window_ = NULL; | 146 window_ = NULL; |
147 } | 147 } |
148 | 148 |
149 //////////////////////////////////////////////////////////////////////////////// | 149 //////////////////////////////////////////////////////////////////////////////// |
150 // NativeViewport, public: | 150 // NativeViewport, public: |
151 | 151 |
152 // static | 152 // static |
153 scoped_ptr<NativeViewport> NativeViewport::Create( | 153 scoped_ptr<NativeViewport> NativeViewport::Create( |
154 shell::Context* context, | 154 NativeViewportContext* context, |
155 NativeViewportDelegate* delegate) { | 155 NativeViewportDelegate* delegate) { |
156 return scoped_ptr<NativeViewport>( | 156 return scoped_ptr<NativeViewport>( |
157 new NativeViewportAndroid(context, delegate)).Pass(); | 157 new NativeViewportAndroid(context, delegate)).Pass(); |
158 } | 158 } |
159 | 159 |
160 } // namespace services | 160 } // namespace services |
161 } // namespace mojo | 161 } // namespace mojo |
OLD | NEW |