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

Unified Diff: content/browser/renderer_host/select_action_mode.cc

Issue 2089933002: Context Menu Refactor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing nits Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
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..ad78e13c4e4d9c6bcdff4c6281940414210ac57b
--- /dev/null
+++ b/content/browser/renderer_host/select_action_mode.cc
@@ -0,0 +1,84 @@
+// 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/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());
+}
+
+SelectActionMode::~SelectActionMode() {
+ close();
+}
+
+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

Powered by Google App Engine
This is Rietveld 408576698