summaryrefslogtreecommitdiffstats
path: root/ui/platform_window/android/platform_window_android.h
blob: 725b97692946930d9b771cefd69b6e72de4c3cd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_PLATFORM_WINDOW_ANDROID_PLATFORM_WINDOW_ANDROID_H_
#define UI_PLATFORM_WINDOW_ANDROID_PLATFORM_WINDOW_ANDROID_H_

#include "base/android/jni_weak_ref.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/sequential_id_generator.h"
#include "ui/platform_window/android/android_window_export.h"
#include "ui/platform_window/android/platform_ime_controller_android.h"
#include "ui/platform_window/platform_window.h"

struct ANativeWindow;

namespace ui {

class ANDROID_WINDOW_EXPORT PlatformWindowAndroid : public PlatformWindow {
 public:
  static bool Register(JNIEnv* env);

  explicit PlatformWindowAndroid(PlatformWindowDelegate* delegate);
  ~PlatformWindowAndroid() override;

  void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
  void SurfaceCreated(JNIEnv* env,
                      const base::android::JavaParamRef<jobject>& obj,
                      const base::android::JavaParamRef<jobject>& jsurface,
                      float device_pixel_ratio);
  void SurfaceDestroyed(JNIEnv* env,
                        const base::android::JavaParamRef<jobject>& obj);
  void SurfaceSetSize(JNIEnv* env,
                      const base::android::JavaParamRef<jobject>& obj,
                      jint width,
                      jint height,
                      jfloat density);
  bool TouchEvent(JNIEnv* env,
                  const base::android::JavaParamRef<jobject>& obj,
                  jlong time_ms,
                  jint masked_action,
                  jint pointer_id,
                  jfloat x,
                  jfloat y,
                  jfloat pressure,
                  jfloat touch_major,
                  jfloat touch_minor,
                  jfloat orientation,
                  jfloat h_wheel,
                  jfloat v_wheel);
  bool KeyEvent(JNIEnv* env,
                const base::android::JavaParamRef<jobject>& obj,
                bool pressed,
                jint key_code,
                jint unicode_character);

 private:
  void ReleaseWindow();

  // Overridden from PlatformWindow:
  void Show() override;
  void Hide() override;
  void Close() override;
  void SetBounds(const gfx::Rect& bounds) override;
  gfx::Rect GetBounds() override;
  void SetTitle(const base::string16& title) override;
  void SetCapture() override;
  void ReleaseCapture() override;
  void ToggleFullscreen() override;
  void Maximize() override;
  void Minimize() override;
  void Restore() override;
  void SetCursor(PlatformCursor cursor) override;
  void MoveCursorTo(const gfx::Point& location) override;
  void ConfineCursorToBounds(const gfx::Rect& bounds) override;
  PlatformImeController* GetPlatformImeController() override;

  PlatformWindowDelegate* delegate_;

  JavaObjectWeakGlobalRef java_platform_window_android_;
  ANativeWindow* window_;
  ui::SequentialIDGenerator id_generator_;

  gfx::Size size_;  // Origin is always (0,0)

  PlatformImeControllerAndroid platform_ime_controller_;

  base::WeakPtrFactory<PlatformWindowAndroid> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(PlatformWindowAndroid);
};

}  // namespace ui

#endif  // UI_PLATFORM_WINDOW_ANDROID_PLATFORM_WINDOW_ANDROID_H_