Add remoting and PPAPI tests to GN build
[chromium-blink-merge.git] / content / browser / android / popup_touch_handle_drawable.cc
blobaef23f8fb0f9696f94bcf038d5320cd64fa345c6
1 // Copyright 2014 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.
5 #include "content/browser/android/popup_touch_handle_drawable.h"
7 #include "jni/PopupTouchHandleDrawable_jni.h"
9 namespace content {
11 PopupTouchHandleDrawable::PopupTouchHandleDrawable(
12 base::android::ScopedJavaLocalRef<jobject> drawable,
13 float dpi_scale)
14 : dpi_scale_(dpi_scale), drawable_(drawable) {
15 DCHECK(drawable.obj());
18 PopupTouchHandleDrawable::~PopupTouchHandleDrawable() {
19 // Explicitly disabling ensures that any external references to the Java
20 // object are cleared, allowing it to be GC'ed in a timely fashion.
21 SetEnabled(false);
24 void PopupTouchHandleDrawable::SetEnabled(bool enabled) {
25 JNIEnv* env = base::android::AttachCurrentThread();
26 if (enabled)
27 Java_PopupTouchHandleDrawable_show(env, drawable_.obj());
28 else
29 Java_PopupTouchHandleDrawable_hide(env, drawable_.obj());
32 void PopupTouchHandleDrawable::SetOrientation(
33 ui::TouchHandleOrientation orientation) {
34 JNIEnv* env = base::android::AttachCurrentThread();
35 jobject obj = drawable_.obj();
36 Java_PopupTouchHandleDrawable_setOrientation(env, obj,
37 static_cast<int>(orientation));
40 void PopupTouchHandleDrawable::SetAlpha(float alpha) {
41 JNIEnv* env = base::android::AttachCurrentThread();
42 bool visible = alpha > 0;
43 Java_PopupTouchHandleDrawable_setVisible(env, drawable_.obj(), visible);
46 void PopupTouchHandleDrawable::SetFocus(const gfx::PointF& position) {
47 const gfx::PointF position_pix = gfx::ScalePoint(position, dpi_scale_);
48 JNIEnv* env = base::android::AttachCurrentThread();
49 Java_PopupTouchHandleDrawable_setFocus(
50 env, drawable_.obj(), position_pix.x(), position_pix.y());
53 gfx::RectF PopupTouchHandleDrawable::GetVisibleBounds() const {
54 JNIEnv* env = base::android::AttachCurrentThread();
55 gfx::RectF unscaled_rect(
56 Java_PopupTouchHandleDrawable_getPositionX(env, drawable_.obj()),
57 Java_PopupTouchHandleDrawable_getPositionY(env, drawable_.obj()),
58 Java_PopupTouchHandleDrawable_getVisibleWidth(env, drawable_.obj()),
59 Java_PopupTouchHandleDrawable_getVisibleHeight(env, drawable_.obj()));
60 return gfx::ScaleRect(unscaled_rect, 1.f / dpi_scale_);
63 // static
64 bool PopupTouchHandleDrawable::RegisterPopupTouchHandleDrawable(JNIEnv* env) {
65 return RegisterNativesImpl(env);
68 } // namespace content