| 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 package org.chromium.ui; | 5 package org.chromium.ui; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.Context; | |
| 9 import android.view.KeyEvent; | 8 import android.view.KeyEvent; |
| 10 import android.view.MotionEvent; | 9 import android.view.MotionEvent; |
| 11 import android.view.Surface; | 10 import android.view.Surface; |
| 12 import android.view.SurfaceHolder; | 11 import android.view.SurfaceHolder; |
| 13 import android.view.SurfaceView; | 12 import android.view.SurfaceView; |
| 14 import android.view.View; | 13 import android.view.View; |
| 15 import android.view.inputmethod.EditorInfo; | 14 import android.view.inputmethod.EditorInfo; |
| 16 import android.view.inputmethod.InputConnection; | 15 import android.view.inputmethod.InputConnection; |
| 17 | 16 |
| 17 import org.chromium.base.ContextUtils; |
| 18 import org.chromium.base.annotations.CalledByNative; | 18 import org.chromium.base.annotations.CalledByNative; |
| 19 import org.chromium.base.annotations.JNINamespace; | 19 import org.chromium.base.annotations.JNINamespace; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Exposes SurfaceView to native code. | 22 * Exposes SurfaceView to native code. |
| 23 */ | 23 */ |
| 24 @JNINamespace("ui") | 24 @JNINamespace("ui") |
| 25 public class PlatformWindowAndroid extends SurfaceView { | 25 public class PlatformWindowAndroid extends SurfaceView { |
| 26 | 26 |
| 27 private long mNativeMojoViewport; | 27 private long mNativeMojoViewport; |
| 28 private final SurfaceHolder.Callback mSurfaceCallback; | 28 private final SurfaceHolder.Callback mSurfaceCallback; |
| 29 private final PlatformImeControllerAndroid mImeController; | 29 private final PlatformImeControllerAndroid mImeController; |
| 30 | 30 |
| 31 @CalledByNative | 31 @CalledByNative |
| 32 public static PlatformWindowAndroid createForActivity( | 32 public static PlatformWindowAndroid createForActivity( |
| 33 Activity activity, long nativeViewport, long nativeImeController) { | 33 long nativeViewport, long nativeImeController) { |
| 34 PlatformWindowAndroid rv = | 34 PlatformWindowAndroid rv = new PlatformWindowAndroid(nativeViewport, nat
iveImeController); |
| 35 new PlatformWindowAndroid(activity, nativeViewport, nativeImeCon
troller); | 35 ((Activity) ContextUtils.getApplicationContext()).setContentView(rv); |
| 36 activity.setContentView(rv); | |
| 37 return rv; | 36 return rv; |
| 38 } | 37 } |
| 39 | 38 |
| 40 public PlatformWindowAndroid(Context context, long nativeViewport, long nati
veImeController) { | 39 private PlatformWindowAndroid(long nativeViewport, long nativeImeController)
{ |
| 41 super(context); | 40 super(ContextUtils.getApplicationContext()); |
| 42 | 41 |
| 43 setFocusable(true); | 42 setFocusable(true); |
| 44 setFocusableInTouchMode(true); | 43 setFocusableInTouchMode(true); |
| 45 | 44 |
| 46 mNativeMojoViewport = nativeViewport; | 45 mNativeMojoViewport = nativeViewport; |
| 47 assert mNativeMojoViewport != 0; | 46 assert mNativeMojoViewport != 0; |
| 48 | 47 |
| 49 final float density = context.getResources().getDisplayMetrics().density
; | 48 final float density = |
| 49 ContextUtils.getApplicationContext().getResources().getDisplayMe
trics().density; |
| 50 | 50 |
| 51 mSurfaceCallback = new SurfaceHolder.Callback() { | 51 mSurfaceCallback = new SurfaceHolder.Callback() { |
| 52 @Override | 52 @Override |
| 53 public void surfaceChanged(SurfaceHolder holder, int format, int wid
th, int height) { | 53 public void surfaceChanged(SurfaceHolder holder, int format, int wid
th, int height) { |
| 54 assert mNativeMojoViewport != 0; | 54 assert mNativeMojoViewport != 0; |
| 55 nativeSurfaceSetSize(mNativeMojoViewport, width, height, density
); | 55 nativeSurfaceSetSize(mNativeMojoViewport, width, height, density
); |
| 56 } | 56 } |
| 57 | 57 |
| 58 @Override | 58 @Override |
| 59 public void surfaceCreated(SurfaceHolder holder) { | 59 public void surfaceCreated(SurfaceHolder holder) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 private static native void nativeSurfaceSetSize( | 198 private static native void nativeSurfaceSetSize( |
| 199 long nativePlatformWindowAndroid, int width, int height, float densi
ty); | 199 long nativePlatformWindowAndroid, int width, int height, float densi
ty); |
| 200 | 200 |
| 201 private static native boolean nativeTouchEvent(long nativePlatformWindowAndr
oid, long timeMs, | 201 private static native boolean nativeTouchEvent(long nativePlatformWindowAndr
oid, long timeMs, |
| 202 int maskedAction, int pointerId, float x, float y, float pressure, f
loat touchMajor, | 202 int maskedAction, int pointerId, float x, float y, float pressure, f
loat touchMajor, |
| 203 float touchMinor, float orientation, float hWheel, float vWheel); | 203 float touchMinor, float orientation, float hWheel, float vWheel); |
| 204 | 204 |
| 205 private static native boolean nativeKeyEvent( | 205 private static native boolean nativeKeyEvent( |
| 206 long nativePlatformWindowAndroid, boolean pressed, int keyCode, int
unicodeCharacter); | 206 long nativePlatformWindowAndroid, boolean pressed, int keyCode, int
unicodeCharacter); |
| 207 } | 207 } |
| OLD | NEW |