popup_touch_handle_drawable.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// found in the LICENSE file. 45f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "content/browser/android/popup_touch_handle_drawable.h" 65f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 75f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "jni/PopupTouchHandleDrawable_jni.h" 85f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace content { 105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)PopupTouchHandleDrawable::PopupTouchHandleDrawable( 125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::android::ScopedJavaLocalRef<jobject> drawable, 135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) float dpi_scale) 145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) : dpi_scale_(dpi_scale), drawable_(drawable) { 155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DCHECK(drawable.obj()); 165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)PopupTouchHandleDrawable::~PopupTouchHandleDrawable() { 195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void PopupTouchHandleDrawable::SetEnabled(bool enabled) { 225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (enabled) 245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_PopupTouchHandleDrawable_show(env, drawable_.obj()); 255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) else 265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_PopupTouchHandleDrawable_hide(env, drawable_.obj()); 275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void PopupTouchHandleDrawable::SetOrientation( 305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) TouchHandleOrientation orientation) { 315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) jobject obj = drawable_.obj(); 335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) switch (orientation) { 345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) case TOUCH_HANDLE_LEFT: 355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_PopupTouchHandleDrawable_setLeftOrientation(env, obj); 365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) break; 375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) case TOUCH_HANDLE_RIGHT: 395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_PopupTouchHandleDrawable_setRightOrientation(env, obj); 405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) break; 415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) case TOUCH_HANDLE_CENTER: 435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_PopupTouchHandleDrawable_setCenterOrientation(env, obj); 445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) break; 455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) case TOUCH_HANDLE_ORIENTATION_UNDEFINED: 475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) NOTREACHED() << "Invalid touch handle orientation."; 485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) }; 495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void PopupTouchHandleDrawable::SetAlpha(float alpha) { 525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_PopupTouchHandleDrawable_setOpacity(env, drawable_.obj(), alpha); 545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void PopupTouchHandleDrawable::SetFocus(const gfx::PointF& position) { 575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const gfx::PointF position_pix = gfx::ScalePoint(position, dpi_scale_); 585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_PopupTouchHandleDrawable_setFocus( 605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) env, drawable_.obj(), position_pix.x(), position_pix.y()); 615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void PopupTouchHandleDrawable::SetVisible(bool visible) { 645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Java_PopupTouchHandleDrawable_setVisible(env, drawable_.obj(), visible); 665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)bool PopupTouchHandleDrawable::IntersectsWith(const gfx::RectF& rect) const { 695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const gfx::RectF rect_pix = gfx::ScaleRect(rect, dpi_scale_); 705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) JNIEnv* env = base::android::AttachCurrentThread(); 715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return Java_PopupTouchHandleDrawable_intersectsWith(env, 725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) drawable_.obj(), 735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) rect_pix.x(), 745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) rect_pix.y(), 755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) rect_pix.width(), 765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) rect_pix.height()); 775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// static 805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)bool PopupTouchHandleDrawable::RegisterPopupTouchHandleDrawable(JNIEnv* env) { 815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return RegisterNativesImpl(env); 825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} // namespace content 85