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 "content/public/browser/android/content_view_core.h"
8 #include "jni/PopupTouchHandleDrawable_jni.h"
13 scoped_ptr
<PopupTouchHandleDrawable
> PopupTouchHandleDrawable::Create(
14 ContentViewCore
* content_view_core
) {
15 DCHECK(content_view_core
);
16 base::android::ScopedJavaLocalRef
<jobject
> content_view_core_obj
=
17 content_view_core
->GetJavaObject();
18 if (content_view_core_obj
.is_null())
20 JNIEnv
* env
= base::android::AttachCurrentThread();
21 base::android::ScopedJavaLocalRef
<jobject
> drawable_obj(
22 Java_PopupTouchHandleDrawable_create(env
, content_view_core_obj
.obj()));
23 return scoped_ptr
<PopupTouchHandleDrawable
>(new PopupTouchHandleDrawable(
24 env
, drawable_obj
.obj(), content_view_core
->GetDpiScale()));
27 PopupTouchHandleDrawable::PopupTouchHandleDrawable(JNIEnv
* env
,
30 : java_ref_(env
, obj
), dpi_scale_(dpi_scale
) {
31 DCHECK(!java_ref_
.is_empty());
34 PopupTouchHandleDrawable::~PopupTouchHandleDrawable() {
35 JNIEnv
* env
= base::android::AttachCurrentThread();
36 ScopedJavaLocalRef
<jobject
> obj
= java_ref_
.get(env
);
38 Java_PopupTouchHandleDrawable_destroy(env
, obj
.obj());
41 void PopupTouchHandleDrawable::SetEnabled(bool enabled
) {
42 JNIEnv
* env
= base::android::AttachCurrentThread();
43 ScopedJavaLocalRef
<jobject
> obj
= java_ref_
.get(env
);
47 Java_PopupTouchHandleDrawable_show(env
, obj
.obj());
49 Java_PopupTouchHandleDrawable_hide(env
, obj
.obj());
52 void PopupTouchHandleDrawable::SetOrientation(
53 ui::TouchHandleOrientation orientation
) {
54 JNIEnv
* env
= base::android::AttachCurrentThread();
55 ScopedJavaLocalRef
<jobject
> obj
= java_ref_
.get(env
);
57 Java_PopupTouchHandleDrawable_setOrientation(env
, obj
.obj(),
58 static_cast<int>(orientation
));
62 void PopupTouchHandleDrawable::SetAlpha(float alpha
) {
63 JNIEnv
* env
= base::android::AttachCurrentThread();
64 ScopedJavaLocalRef
<jobject
> obj
= java_ref_
.get(env
);
65 bool visible
= alpha
> 0;
67 Java_PopupTouchHandleDrawable_setVisible(env
, obj
.obj(), visible
);
70 void PopupTouchHandleDrawable::SetFocus(const gfx::PointF
& position
) {
71 const gfx::PointF position_pix
= gfx::ScalePoint(position
, dpi_scale_
);
72 JNIEnv
* env
= base::android::AttachCurrentThread();
73 ScopedJavaLocalRef
<jobject
> obj
= java_ref_
.get(env
);
75 Java_PopupTouchHandleDrawable_setFocus(env
, obj
.obj(), position_pix
.x(),
80 gfx::RectF
PopupTouchHandleDrawable::GetVisibleBounds() const {
81 JNIEnv
* env
= base::android::AttachCurrentThread();
82 ScopedJavaLocalRef
<jobject
> obj
= java_ref_
.get(env
);
85 gfx::RectF
unscaled_rect(
86 Java_PopupTouchHandleDrawable_getPositionX(env
, obj
.obj()),
87 Java_PopupTouchHandleDrawable_getPositionY(env
, obj
.obj()),
88 Java_PopupTouchHandleDrawable_getVisibleWidth(env
, obj
.obj()),
89 Java_PopupTouchHandleDrawable_getVisibleHeight(env
, obj
.obj()));
90 return gfx::ScaleRect(unscaled_rect
, 1.f
/ dpi_scale_
);
94 bool PopupTouchHandleDrawable::RegisterPopupTouchHandleDrawable(JNIEnv
* env
) {
95 return RegisterNativesImpl(env
);
98 } // namespace content