| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 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. |
| 4 |
| 5 #include "content/browser/renderer_host/select_action_mode.h" |
| 6 |
| 7 #include <jni.h> |
| 8 |
| 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" |
| 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "content/public/common/context_menu_params.h" |
| 13 #include "jni/SelectActionMode_jni.h" |
| 14 #include "ui/display/display.h" |
| 15 #include "ui/display/screen.h" |
| 16 #include "ui/gfx/geometry/rect_f.h" |
| 17 |
| 18 using base::android::AttachCurrentThread; |
| 19 |
| 20 float GetScaleFactor() { |
| 21 return display::Screen::GetScreen() |
| 22 ->GetPrimaryDisplay() |
| 23 .device_scale_factor(); |
| 24 } |
| 25 |
| 26 namespace content { |
| 27 |
| 28 bool RegisterSelectActionMode(JNIEnv* env) { |
| 29 return RegisterNativesImpl(env); |
| 30 } |
| 31 |
| 32 SelectActionMode::SelectActionMode(const content::ContextMenuParams& params) |
| 33 : dpi_scale_(GetScaleFactor()) { |
| 34 |
| 35 jint left = static_cast<jint>(params.selection_start.x() * dpi_scale()); |
| 36 jint top = static_cast<jint>(params.selection_start.y() * dpi_scale()); |
| 37 jint right = static_cast<jint>(params.selection_end.x() * dpi_scale()); |
| 38 jint bottom = static_cast<jint>(params.selection_end.y() * dpi_scale()); |
| 39 jboolean is_empty = static_cast<jboolean>(params.selection_text.empty()); |
| 40 jboolean is_editable = static_cast<jboolean>(params.is_editable); |
| 41 jboolean is_password = static_cast<jboolean>( |
| 42 params.input_field_type == |
| 43 blink::WebContextMenuData::InputFieldTypePassword); |
| 44 |
| 45 JNIEnv* env = AttachCurrentThread(); |
| 46 java_obj_.Reset(env, Java_SelectActionMode_create( |
| 47 env, left, top, right, bottom, is_empty, |
| 48 is_editable, is_password).obj()); |
| 49 DCHECK(!java_obj_.is_null()); |
| 50 } |
| 51 |
| 52 SelectActionMode::~SelectActionMode() { |
| 53 close(); |
| 54 } |
| 55 |
| 56 void SelectActionMode::show() { |
| 57 JNIEnv* env = AttachCurrentThread(); |
| 58 if (!java_obj_.is_null()) |
| 59 Java_SelectActionMode_show(env, java_obj_.obj()); |
| 60 } |
| 61 |
| 62 void SelectActionMode::hide() { |
| 63 JNIEnv* env = AttachCurrentThread(); |
| 64 if (!java_obj_.is_null()) |
| 65 Java_SelectActionMode_hide(env, java_obj_.obj()); |
| 66 } |
| 67 |
| 68 void SelectActionMode::close() { |
| 69 JNIEnv* env = AttachCurrentThread(); |
| 70 if (!java_obj_.is_null()) |
| 71 Java_SelectActionMode_close(env, java_obj_.obj()); |
| 72 } |
| 73 |
| 74 void SelectActionMode::move(const gfx::RectF& selection_rect) { |
| 75 gfx::RectF selection_rect_pix = gfx::ScaleRect(selection_rect, dpi_scale()); |
| 76 JNIEnv* env = AttachCurrentThread(); |
| 77 |
| 78 if (!java_obj_.is_null()) |
| 79 Java_SelectActionMode_move( |
| 80 env, java_obj_.obj(), selection_rect_pix.x(), selection_rect_pix.y(), |
| 81 selection_rect_pix.right(), selection_rect_pix.bottom()); |
| 82 } |
| 83 |
| 84 } // namespace content |
| OLD | NEW |