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 3 // found in the LICENSE file. 4 5 #ifndef MOJO_SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_ANDROID_H_ 6 #define MOJO_SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_ANDROID_H_ 7 8 #include "base/android/jni_weak_ref.h" 9 #include "base/android/scoped_java_ref.h" 10 #include "base/memory/weak_ptr.h" 11 #include "mojo/services/native_viewport/native_viewport.h" 12 #include "mojo/services/native_viewport/native_viewport_export.h" 13 #include "ui/events/event_constants.h" 14 #include "ui/gfx/rect.h" 15 #include "ui/gfx/sequential_id_generator.h" 16 #include "ui/gfx/size.h" 17 18 namespace gpu { 19 class GLInProcessContext; 20 } 21 22 struct ANativeWindow; 23 24 namespace mojo { 25 namespace services { 26 27 class MOJO_NATIVE_VIEWPORT_EXPORT NativeViewportAndroid 28 : public NativeViewport { 29 public: 30 static MOJO_NATIVE_VIEWPORT_EXPORT bool Register(JNIEnv* env); 31 32 explicit NativeViewportAndroid(shell::Context* context, 33 NativeViewportDelegate* delegate); 34 virtual ~NativeViewportAndroid(); 35 36 void Destroy(JNIEnv* env, jobject obj); 37 void SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface); 38 void SurfaceDestroyed(JNIEnv* env, jobject obj); 39 void SurfaceSetSize(JNIEnv* env, jobject obj, jint width, jint height); 40 bool TouchEvent(JNIEnv* env, jobject obj, jint pointer_id, jint action, 41 jfloat x, jfloat y, jlong time_ms); 42 43 private: 44 // Overridden from NativeViewport: 45 virtual void Init(const gfx::Rect& bounds) OVERRIDE; 46 virtual void Show() OVERRIDE; 47 virtual void Hide() OVERRIDE; 48 virtual void Close() OVERRIDE; 49 virtual gfx::Size GetSize() OVERRIDE; 50 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; 51 virtual void SetCapture() OVERRIDE; 52 virtual void ReleaseCapture() OVERRIDE; 53 54 void ReleaseWindow(); 55 56 NativeViewportDelegate* delegate_; 57 shell::Context* context_; 58 ANativeWindow* window_; 59 gfx::Rect bounds_; 60 ui::SequentialIDGenerator id_generator_; 61 62 base::WeakPtrFactory<NativeViewportAndroid> weak_factory_; 63 64 DISALLOW_COPY_AND_ASSIGN(NativeViewportAndroid); 65 }; 66 67 68 } // namespace services 69 } // namespace mojo 70 71 #endif // MOJO_SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_ANDROID_H_ 72