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

Side by Side Diff: mojo/services/native_viewport/android/mojo_viewport.cc

Issue 63493002: Wires up MotionEvents for mojo_shell_apk on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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/android/mojo_viewport.h" 5 #include "mojo/services/native_viewport/android/mojo_viewport.h"
6 6
7 #include <android/native_window_jni.h> 7 #include <android/native_window_jni.h>
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "jni/MojoViewport_jni.h" 12 #include "jni/MojoViewport_jni.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace services { 15 namespace services {
16 16
17 const int ACTION_DOWN = 0;
Ben Goodger (Google) 2013/11/07 00:20:38 I'm not sure if there's a better way to do this. T
abarth-chromium 2013/11/07 00:29:11 Is there a header we can include to get these cons
18 const int ACTION_HOVER_ENTER = 9;
19 const int ACTION_HOVER_EXIT = 10;
20 const int ACTION_HOVER_MOVE = 7;
21 const int ACTION_MOVE = 2;
22 const int ACTION_UP = 1;
23
24 ui::EventType MotionEventActionToEventType(jint action, jboolean is_touch) {
25 switch (action) {
26 case ACTION_DOWN:
27 return is_touch ? ui::ET_TOUCH_PRESSED : ui::ET_MOUSE_PRESSED;
28 case ACTION_HOVER_ENTER:
29 DCHECK(!is_touch);
30 return ui::ET_MOUSE_ENTERED;
31 case ACTION_HOVER_EXIT:
32 DCHECK(!is_touch);
33 return ui::ET_MOUSE_EXITED;
34 case ACTION_HOVER_MOVE:
35 DCHECK(!is_touch);
36 return ui::ET_MOUSE_MOVED;
37 case ACTION_MOVE:
38 return is_touch ? ui::ET_TOUCH_MOVED : ui::ET_MOUSE_DRAGGED;
39 case ACTION_UP:
40 return is_touch ? ui::ET_TOUCH_RELEASED : ui::ET_MOUSE_RELEASED;
41 default:
42 NOTREACHED();
43 }
44 return ui::ET_UNKNOWN;
45 }
46
47
abarth-chromium 2013/11/07 00:29:11 You've got a blank line here.
17 MojoViewportInit::MojoViewportInit() { 48 MojoViewportInit::MojoViewportInit() {
18 } 49 }
19 50
20 MojoViewportInit::~MojoViewportInit() { 51 MojoViewportInit::~MojoViewportInit() {
21 } 52 }
22 53
23 static jint Init(JNIEnv* env, jclass obj, jint jinit) { 54 static jint Init(JNIEnv* env, jclass obj, jint jinit) {
24 MojoViewportInit* init = reinterpret_cast<MojoViewportInit*>(jinit); 55 MojoViewportInit* init = reinterpret_cast<MojoViewportInit*>(jinit);
25 MojoViewport* viewport = new MojoViewport(init); 56 MojoViewport* viewport = new MojoViewport(init);
26 return reinterpret_cast<jint>(viewport); 57 return reinterpret_cast<jint>(viewport);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 94 }
64 95
65 void MojoViewport::SurfaceSetSize( 96 void MojoViewport::SurfaceSetSize(
66 JNIEnv* env, jobject obj, jint width, jint height) { 97 JNIEnv* env, jobject obj, jint width, jint height) {
67 ui_runner_->PostTask(FROM_HERE, base::Bind( 98 ui_runner_->PostTask(FROM_HERE, base::Bind(
68 &NativeViewportAndroid::OnResized, 99 &NativeViewportAndroid::OnResized,
69 native_viewport_, 100 native_viewport_,
70 gfx::Size(width, height))); 101 gfx::Size(width, height)));
71 } 102 }
72 103
104 bool MojoViewport::MotionEvent(JNIEnv* env, jobject obj,
105 jboolean is_touch,
106 jint pointer_id,
107 jint action,
108 jfloat x, jfloat y,
109 jlong time_ms) {
110 ui_runner_->PostTask(FROM_HERE, base::Bind(
111 &NativeViewportAndroid::OnMotionEvent,
112 native_viewport_,
113 is_touch,
114 pointer_id,
115 MotionEventActionToEventType(action, is_touch),
116 x, y,
117 time_ms));
118 // TODO(beng): This type needs to live on the main thread so we can respond to
119 // this question truthfully.
120 return true;
121 }
122
73 bool MojoViewport::Register(JNIEnv* env) { 123 bool MojoViewport::Register(JNIEnv* env) {
74 return RegisterNativesImpl(env); 124 return RegisterNativesImpl(env);
75 } 125 }
76 126
77 } // namespace services 127 } // namespace services
78 } // namespace mojo 128 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698