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"
11 PopupTouchHandleDrawable::PopupTouchHandleDrawable(
12 base::android::ScopedJavaLocalRef
<jobject
> drawable
,
14 : dpi_scale_(dpi_scale
), drawable_(drawable
) {
15 DCHECK(drawable
.obj());
18 PopupTouchHandleDrawable::~PopupTouchHandleDrawable() {
21 void PopupTouchHandleDrawable::SetEnabled(bool enabled
) {
22 JNIEnv
* env
= base::android::AttachCurrentThread();
24 Java_PopupTouchHandleDrawable_show(env
, drawable_
.obj());
26 Java_PopupTouchHandleDrawable_hide(env
, drawable_
.obj());
29 void PopupTouchHandleDrawable::SetOrientation(
30 TouchHandleOrientation orientation
) {
31 JNIEnv
* env
= base::android::AttachCurrentThread();
32 jobject obj
= drawable_
.obj();
33 switch (orientation
) {
34 case TOUCH_HANDLE_LEFT
:
35 Java_PopupTouchHandleDrawable_setLeftOrientation(env
, obj
);
38 case TOUCH_HANDLE_RIGHT
:
39 Java_PopupTouchHandleDrawable_setRightOrientation(env
, obj
);
42 case TOUCH_HANDLE_CENTER
:
43 Java_PopupTouchHandleDrawable_setCenterOrientation(env
, obj
);
46 case TOUCH_HANDLE_ORIENTATION_UNDEFINED
:
47 NOTREACHED() << "Invalid touch handle orientation.";
51 void PopupTouchHandleDrawable::SetAlpha(float alpha
) {
52 JNIEnv
* env
= base::android::AttachCurrentThread();
53 Java_PopupTouchHandleDrawable_setOpacity(env
, drawable_
.obj(), alpha
);
56 void PopupTouchHandleDrawable::SetFocus(const gfx::PointF
& position
) {
57 const gfx::PointF position_pix
= gfx::ScalePoint(position
, dpi_scale_
);
58 JNIEnv
* env
= base::android::AttachCurrentThread();
59 Java_PopupTouchHandleDrawable_setFocus(
60 env
, drawable_
.obj(), position_pix
.x(), position_pix
.y());
63 void PopupTouchHandleDrawable::SetVisible(bool visible
) {
64 JNIEnv
* env
= base::android::AttachCurrentThread();
65 Java_PopupTouchHandleDrawable_setVisible(env
, drawable_
.obj(), visible
);
68 bool PopupTouchHandleDrawable::IntersectsWith(const gfx::RectF
& rect
) const {
69 const gfx::RectF rect_pix
= gfx::ScaleRect(rect
, dpi_scale_
);
70 JNIEnv
* env
= base::android::AttachCurrentThread();
71 return Java_PopupTouchHandleDrawable_intersectsWith(env
,
80 bool PopupTouchHandleDrawable::RegisterPopupTouchHandleDrawable(JNIEnv
* env
) {
81 return RegisterNativesImpl(env
);
84 } // namespace content