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

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

Issue 404913002: Break dependency of native_viewport_service on mojo::shell::Context (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move call to GetApplicationContext() to native_viewport_android Created 6 years, 5 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
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_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"
13 #include "ui/events/event.h" 12 #include "ui/events/event.h"
14 #include "ui/gfx/point.h" 13 #include "ui/gfx/point.h"
15 14
16 namespace mojo { 15 namespace mojo {
17 namespace services { 16 namespace services {
18 17
19 ui::EventType MotionEventActionToEventType(jint action) { 18 ui::EventType MotionEventActionToEventType(jint action) {
20 switch (action) { 19 switch (action) {
21 case AMOTION_EVENT_ACTION_DOWN: 20 case AMOTION_EVENT_ACTION_DOWN:
22 return ui::ET_TOUCH_PRESSED; 21 return ui::ET_TOUCH_PRESSED;
23 case AMOTION_EVENT_ACTION_MOVE: 22 case AMOTION_EVENT_ACTION_MOVE:
24 return ui::ET_TOUCH_MOVED; 23 return ui::ET_TOUCH_MOVED;
25 case AMOTION_EVENT_ACTION_UP: 24 case AMOTION_EVENT_ACTION_UP:
26 return ui::ET_TOUCH_RELEASED; 25 return ui::ET_TOUCH_RELEASED;
27 default: 26 default:
28 NOTREACHED(); 27 NOTREACHED();
29 } 28 }
30 return ui::ET_UNKNOWN; 29 return ui::ET_UNKNOWN;
31 } 30 }
32 31
33 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
34 // NativeViewportAndroid, public: 33 // NativeViewportAndroid, public:
35 34
36 // static 35 // static
37 bool NativeViewportAndroid::Register(JNIEnv* env) { 36 bool NativeViewportAndroid::Register(JNIEnv* env) {
38 return RegisterNativesImpl(env); 37 return RegisterNativesImpl(env);
39 } 38 }
40 39
41 NativeViewportAndroid::NativeViewportAndroid(shell::Context* context, 40 NativeViewportAndroid::NativeViewportAndroid(NativeViewportDelegate* delegate)
42 NativeViewportDelegate* delegate)
43 : delegate_(delegate), 41 : delegate_(delegate),
44 context_(context),
45 window_(NULL), 42 window_(NULL),
46 id_generator_(0), 43 id_generator_(0),
47 weak_factory_(this) { 44 weak_factory_(this) {
48 } 45 }
49 46
50 NativeViewportAndroid::~NativeViewportAndroid() { 47 NativeViewportAndroid::~NativeViewportAndroid() {
51 if (window_) 48 if (window_)
52 ReleaseWindow(); 49 ReleaseWindow();
53 } 50 }
54 51
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 id_generator_.ReleaseNumber(pointer_id); 93 id_generator_.ReleaseNumber(pointer_id);
97 94
98 return true; 95 return true;
99 } 96 }
100 97
101 //////////////////////////////////////////////////////////////////////////////// 98 ////////////////////////////////////////////////////////////////////////////////
102 // NativeViewportAndroid, NativeViewport implementation: 99 // NativeViewportAndroid, NativeViewport implementation:
103 100
104 void NativeViewportAndroid::Init(const gfx::Rect& bounds) { 101 void NativeViewportAndroid::Init(const gfx::Rect& bounds) {
105 JNIEnv* env = base::android::AttachCurrentThread(); 102 JNIEnv* env = base::android::AttachCurrentThread();
106 Java_NativeViewportAndroid_createForActivity(env, context_->activity(), 103 Java_NativeViewportAndroid_createForActivity(
107 reinterpret_cast<jlong>(this)); 104 env,
105 base::android::GetApplicationContext(),
106 reinterpret_cast<jlong>(this));
108 } 107 }
109 108
110 void NativeViewportAndroid::Show() { 109 void NativeViewportAndroid::Show() {
111 // Nothing to do. View is created visible. 110 // Nothing to do. View is created visible.
112 } 111 }
113 112
114 void NativeViewportAndroid::Hide() { 113 void NativeViewportAndroid::Hide() {
115 // Nothing to do. View is always visible. 114 // Nothing to do. View is always visible.
116 } 115 }
117 116
(...skipping 26 matching lines...) Expand all
144 void NativeViewportAndroid::ReleaseWindow() { 143 void NativeViewportAndroid::ReleaseWindow() {
145 ANativeWindow_release(window_); 144 ANativeWindow_release(window_);
146 window_ = NULL; 145 window_ = NULL;
147 } 146 }
148 147
149 //////////////////////////////////////////////////////////////////////////////// 148 ////////////////////////////////////////////////////////////////////////////////
150 // NativeViewport, public: 149 // NativeViewport, public:
151 150
152 // static 151 // static
153 scoped_ptr<NativeViewport> NativeViewport::Create( 152 scoped_ptr<NativeViewport> NativeViewport::Create(
154 shell::Context* context,
155 NativeViewportDelegate* delegate) { 153 NativeViewportDelegate* delegate) {
156 return scoped_ptr<NativeViewport>( 154 return scoped_ptr<NativeViewport>(new NativeViewportAndroid(delegate)).Pass();
157 new NativeViewportAndroid(context, delegate)).Pass();
158 } 155 }
159 156
160 } // namespace services 157 } // namespace services
161 } // namespace mojo 158 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/native_viewport_android.h ('k') | mojo/services/native_viewport/native_viewport_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698