Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: content/browser/android/popup_touch_handle_drawable.cc

Issue 481683003: Support for Adaptive Handle Orientation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/android/popup_touch_handle_drawable.h" 5 #include "content/browser/android/popup_touch_handle_drawable.h"
6 6
7 #include "content/public/browser/android/content_view_core.h" 7 #include "content/public/browser/android/content_view_core.h"
8 #include "jni/PopupTouchHandleDrawable_jni.h" 8 #include "jni/PopupTouchHandleDrawable_jni.h"
9 9
10 namespace content { 10 namespace content {
(...skipping 11 matching lines...) Expand all
22 Java_PopupTouchHandleDrawable_create(env, content_view_core_obj.obj())); 22 Java_PopupTouchHandleDrawable_create(env, content_view_core_obj.obj()));
23 return scoped_ptr<PopupTouchHandleDrawable>(new PopupTouchHandleDrawable( 23 return scoped_ptr<PopupTouchHandleDrawable>(new PopupTouchHandleDrawable(
24 env, drawable_obj.obj(), content_view_core->GetDpiScale())); 24 env, drawable_obj.obj(), content_view_core->GetDpiScale()));
25 } 25 }
26 26
27 PopupTouchHandleDrawable::PopupTouchHandleDrawable(JNIEnv* env, 27 PopupTouchHandleDrawable::PopupTouchHandleDrawable(JNIEnv* env,
28 jobject obj, 28 jobject obj,
29 float dpi_scale) 29 float dpi_scale)
30 : java_ref_(env, obj), dpi_scale_(dpi_scale) { 30 : java_ref_(env, obj), dpi_scale_(dpi_scale) {
31 DCHECK(!java_ref_.is_empty()); 31 DCHECK(!java_ref_.is_empty());
32 drawable_horizontal_padding_ratio_ =
33 Java_PopupTouchHandleDrawable_getHandleHorizontalPaddingRatio(env, obj);
32 } 34 }
33 35
34 PopupTouchHandleDrawable::~PopupTouchHandleDrawable() { 36 PopupTouchHandleDrawable::~PopupTouchHandleDrawable() {
35 JNIEnv* env = base::android::AttachCurrentThread(); 37 JNIEnv* env = base::android::AttachCurrentThread();
36 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 38 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
37 if (!obj.is_null()) 39 if (!obj.is_null())
38 Java_PopupTouchHandleDrawable_destroy(env, obj.obj()); 40 Java_PopupTouchHandleDrawable_destroy(env, obj.obj());
39 } 41 }
40 42
41 void PopupTouchHandleDrawable::SetEnabled(bool enabled) { 43 void PopupTouchHandleDrawable::SetEnabled(bool enabled) {
42 JNIEnv* env = base::android::AttachCurrentThread(); 44 JNIEnv* env = base::android::AttachCurrentThread();
43 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 45 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
44 if (obj.is_null()) 46 if (obj.is_null())
45 return; 47 return;
46 if (enabled) 48 if (enabled)
47 Java_PopupTouchHandleDrawable_show(env, obj.obj()); 49 Java_PopupTouchHandleDrawable_show(env, obj.obj());
48 else 50 else
49 Java_PopupTouchHandleDrawable_hide(env, obj.obj()); 51 Java_PopupTouchHandleDrawable_hide(env, obj.obj());
50 } 52 }
51 53
52 void PopupTouchHandleDrawable::SetOrientation( 54 void PopupTouchHandleDrawable::SetOrientation(
53 ui::TouchHandleOrientation orientation) { 55 ui::TouchHandleOrientation orientation,
56 bool mirror_vertical,
57 bool mirror_horizontal) {
54 JNIEnv* env = base::android::AttachCurrentThread(); 58 JNIEnv* env = base::android::AttachCurrentThread();
55 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 59 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
56 if (!obj.is_null()) { 60 if (!obj.is_null()) {
57 Java_PopupTouchHandleDrawable_setOrientation(env, obj.obj(), 61 Java_PopupTouchHandleDrawable_setOrientation(
58 static_cast<int>(orientation)); 62 env, obj.obj(), static_cast<int>(orientation), mirror_vertical,
63 mirror_horizontal);
64 }
65 }
66
67 void PopupTouchHandleDrawable::SetOrigin(const gfx::PointF& origin) {
68 JNIEnv* env = base::android::AttachCurrentThread();
69 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
70 if (!obj.is_null()) {
71 const gfx::PointF origin_pix = gfx::ScalePoint(origin, dpi_scale_);
72 Java_PopupTouchHandleDrawable_setOrigin(env, obj.obj(), origin_pix.x(),
73 origin_pix.y());
59 } 74 }
60 } 75 }
61 76
62 void PopupTouchHandleDrawable::SetAlpha(float alpha) { 77 void PopupTouchHandleDrawable::SetAlpha(float alpha) {
63 JNIEnv* env = base::android::AttachCurrentThread(); 78 JNIEnv* env = base::android::AttachCurrentThread();
64 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 79 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
65 bool visible = alpha > 0; 80 bool visible = alpha > 0;
66 if (!obj.is_null()) 81 if (!obj.is_null())
67 Java_PopupTouchHandleDrawable_setVisible(env, obj.obj(), visible); 82 Java_PopupTouchHandleDrawable_setVisible(env, obj.obj(), visible);
68 } 83 }
69 84
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);
74 if (!obj.is_null()) {
75 Java_PopupTouchHandleDrawable_setFocus(env, obj.obj(), position_pix.x(),
76 position_pix.y());
77 }
78 }
79
80 gfx::RectF PopupTouchHandleDrawable::GetVisibleBounds() const { 85 gfx::RectF PopupTouchHandleDrawable::GetVisibleBounds() const {
81 JNIEnv* env = base::android::AttachCurrentThread(); 86 JNIEnv* env = base::android::AttachCurrentThread();
82 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 87 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
83 if (obj.is_null()) 88 if (obj.is_null())
84 return gfx::RectF(); 89 return gfx::RectF();
85 gfx::RectF unscaled_rect( 90 gfx::RectF unscaled_rect(
86 Java_PopupTouchHandleDrawable_getPositionX(env, obj.obj()), 91 Java_PopupTouchHandleDrawable_getPositionX(env, obj.obj()),
87 Java_PopupTouchHandleDrawable_getPositionY(env, obj.obj()), 92 Java_PopupTouchHandleDrawable_getPositionY(env, obj.obj()),
88 Java_PopupTouchHandleDrawable_getVisibleWidth(env, obj.obj()), 93 Java_PopupTouchHandleDrawable_getVisibleWidth(env, obj.obj()),
89 Java_PopupTouchHandleDrawable_getVisibleHeight(env, obj.obj())); 94 Java_PopupTouchHandleDrawable_getVisibleHeight(env, obj.obj()));
90 return gfx::ScaleRect(unscaled_rect, 1.f / dpi_scale_); 95 return gfx::ScaleRect(unscaled_rect, 1.f / dpi_scale_);
91 } 96 }
92 97
98 float PopupTouchHandleDrawable::GetDrawableHorizontalPaddingRatio() const {
99 return drawable_horizontal_padding_ratio_;
100 }
101
93 // static 102 // static
94 bool PopupTouchHandleDrawable::RegisterPopupTouchHandleDrawable(JNIEnv* env) { 103 bool PopupTouchHandleDrawable::RegisterPopupTouchHandleDrawable(JNIEnv* env) {
95 return RegisterNativesImpl(env); 104 return RegisterNativesImpl(env);
96 } 105 }
97 106
98 } // namespace content 107 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698