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 UI_BASE_ANDROID_WINDOW_ANDROID_H_
6#define UI_BASE_ANDROID_WINDOW_ANDROID_H_
7
8#include <jni.h>
9#include <vector>
10#include "base/android/jni_helper.h"
11#include "base/android/scoped_java_ref.h"
12#include "base/observer_list.h"
13#include "ui/base/ui_export.h"
14#include "ui/gfx/vector2d_f.h"
15
16namespace ui {
17
18class WindowAndroidObserver;
19
20// Android implementation of the activity window.
21class UI_EXPORT WindowAndroid {
22 public:
23  WindowAndroid(JNIEnv* env, jobject obj);
24
25  void Destroy(JNIEnv* env, jobject obj);
26
27  base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
28
29  static bool RegisterWindowAndroid(JNIEnv* env);
30
31  // The content offset is used to translate snapshots to the correct part of
32  // the window.
33  void set_content_offset(const gfx::Vector2dF& content_offset) {
34    content_offset_ = content_offset;
35  }
36
37  bool GrabSnapshot(int content_x, int content_y, int width, int height,
38                    std::vector<unsigned char>* png_representation);
39
40  // Compositor callback relay.
41  void OnCompositingDidCommit();
42
43  void AttachCompositor();
44  void DetachCompositor();
45
46  void AddObserver(WindowAndroidObserver* observer);
47  void RemoveObserver(WindowAndroidObserver* observer);
48
49 private:
50  ~WindowAndroid();
51
52  JavaObjectWeakGlobalRef weak_java_window_;
53  gfx::Vector2dF content_offset_;
54
55  ObserverList<WindowAndroidObserver> observer_list_;
56
57  DISALLOW_COPY_AND_ASSIGN(WindowAndroid);
58};
59
60}  // namespace ui
61
62#endif  // UI_BASE_ANDROID_WINDOW_ANDROID_H_
63