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

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

Powered by Google App Engine
This is Rietveld 408576698