Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / browser / android / popup_touch_handle_drawable.cc
blobac2f57bffc2d56241483fb2da171861d8a399239
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() {
21 void PopupTouchHandleDrawable::SetEnabled(bool enabled) {
22 JNIEnv* env = base::android::AttachCurrentThread();
23 if (enabled)
24 Java_PopupTouchHandleDrawable_show(env, drawable_.obj());
25 else
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);
36 break;
38 case TOUCH_HANDLE_RIGHT:
39 Java_PopupTouchHandleDrawable_setRightOrientation(env, obj);
40 break;
42 case TOUCH_HANDLE_CENTER:
43 Java_PopupTouchHandleDrawable_setCenterOrientation(env, obj);
44 break;
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,
72 drawable_.obj(),
73 rect_pix.x(),
74 rect_pix.y(),
75 rect_pix.width(),
76 rect_pix.height());
79 // static
80 bool PopupTouchHandleDrawable::RegisterPopupTouchHandleDrawable(JNIEnv* env) {
81 return RegisterNativesImpl(env);
84 } // namespace content