Chromium Code Reviews| Index: content/browser/renderer_host/select_action_mode.cc |
| diff --git a/content/browser/renderer_host/select_action_mode.cc b/content/browser/renderer_host/select_action_mode.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2efe195afa407a543933e813296a26453198c017 |
| --- /dev/null |
| +++ b/content/browser/renderer_host/select_action_mode.cc |
| @@ -0,0 +1,81 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/renderer_host/select_action_mode.h" |
| + |
| +#include <jni.h> |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/android/scoped_java_ref.h" |
| +#include "content/public/browser/render_view_host.h" |
|
no sievers
2016/06/23 23:16:41
render_view_host.h is unused
amaralp
2016/06/24 00:45:49
Nice catch.
|
| +#include "content/public/common/context_menu_params.h" |
| +#include "jni/SelectActionMode_jni.h" |
| +#include "ui/display/display.h" |
| +#include "ui/display/screen.h" |
| +#include "ui/gfx/geometry/rect_f.h" |
| + |
| +using base::android::AttachCurrentThread; |
| + |
| +float GetScaleFactor() { |
| + return display::Screen::GetScreen() |
| + ->GetPrimaryDisplay() |
| + .device_scale_factor(); |
| +} |
| + |
| +namespace content { |
| + |
| +bool RegisterSelectActionMode(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +SelectActionMode::SelectActionMode(const content::ContextMenuParams& params) |
| + : dpi_scale_(GetScaleFactor()) { |
| + |
| + jint left = static_cast<jint>(params.selection_start.x() * dpi_scale()); |
| + jint top = static_cast<jint>(params.selection_start.y() * dpi_scale()); |
| + jint right = static_cast<jint>(params.selection_end.x() * dpi_scale()); |
| + jint bottom = static_cast<jint>(params.selection_end.y() * dpi_scale()); |
| + jboolean is_empty = static_cast<jboolean>(params.selection_text.empty()); |
| + jboolean is_editable = static_cast<jboolean>(params.is_editable); |
| + jboolean is_password = static_cast<jboolean>( |
| + params.input_field_type == |
| + blink::WebContextMenuData::InputFieldTypePassword); |
| + |
| + JNIEnv* env = AttachCurrentThread(); |
| + java_obj_.Reset(env, Java_SelectActionMode_create( |
| + env, left, top, right, bottom, is_empty, |
| + is_editable, is_password).obj()); |
| + DCHECK(!java_obj_.is_null()); |
| +} |
| + |
| +void SelectActionMode::show() { |
| + JNIEnv* env = AttachCurrentThread(); |
| + if (!java_obj_.is_null()) |
| + Java_SelectActionMode_show(env, java_obj_.obj()); |
| +} |
| + |
| +void SelectActionMode::hide() { |
| + JNIEnv* env = AttachCurrentThread(); |
| + if (!java_obj_.is_null()) |
| + Java_SelectActionMode_hide(env, java_obj_.obj()); |
| +} |
| + |
| +void SelectActionMode::close() { |
| + JNIEnv* env = AttachCurrentThread(); |
| + if (!java_obj_.is_null()) |
| + Java_SelectActionMode_close(env, java_obj_.obj()); |
| +} |
| + |
| +void SelectActionMode::move(const gfx::RectF& selection_rect) { |
| + gfx::RectF selection_rect_pix = gfx::ScaleRect(selection_rect, dpi_scale()); |
| + JNIEnv* env = AttachCurrentThread(); |
| + |
| + if (!java_obj_.is_null()) |
| + Java_SelectActionMode_move( |
| + env, java_obj_.obj(), selection_rect_pix.x(), selection_rect_pix.y(), |
| + selection_rect_pix.right(), selection_rect_pix.bottom()); |
| +} |
| + |
| +} // namespace content |