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

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

Issue 2826303003: Let selection events bypass ContentViewCore (Closed)
Patch Set: call Initialize() Created 3 years, 7 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 2017 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/android/selection_popup_controller.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "content/browser/renderer_host/render_widget_host_view_android.h"
11 #include "content/public/browser/web_contents.h"
12 #include "jni/SelectionPopupController_jni.h"
13
14 using base::android::AttachCurrentThread;
15 using base::android::ConvertUTF8ToJavaString;
16 using base::android::JavaParamRef;
17 using base::android::ScopedJavaLocalRef;
18
19 namespace content {
20
21 void Init(JNIEnv* env,
22 const JavaParamRef<jobject>& obj,
23 const JavaParamRef<jobject>& jweb_contents) {
24 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents);
25 DCHECK(web_contents);
26
27 // Owns itself and gets destroyed when |WebContentsDestroyed| is called.
28 (new SelectionPopupController(env, obj, web_contents))->Initialize();
29 }
30
31 bool RegisterSelectionPopupController(JNIEnv* env) {
32 return RegisterNativesImpl(env);
33 }
34
35 SelectionPopupController::SelectionPopupController(
36 JNIEnv* env,
37 const JavaParamRef<jobject>& obj,
38 WebContents* web_contents)
39 : RenderWidgetHostConnector(web_contents) {
40 java_obj_ = JavaObjectWeakGlobalRef(env, obj);
41 }
42
43 void SelectionPopupController::UpdateRenderProcessConnection(
44 RenderWidgetHostViewAndroid* old_rwhva,
45 RenderWidgetHostViewAndroid* new_rwhva) {
46 if (old_rwhva)
47 old_rwhva->set_selection_popup_controller(nullptr);
48 if (new_rwhva)
49 new_rwhva->set_selection_popup_controller(this);
50 }
51
52 void SelectionPopupController::OnSelectionEvent(
53 ui::SelectionEventType event,
54 const gfx::PointF& selection_anchor,
55 const gfx::RectF& selection_rect) {
56 JNIEnv* env = AttachCurrentThread();
57 ScopedJavaLocalRef<jobject> obj = java_obj_.get(env);
58 if (obj.is_null())
59 return;
60
61 Java_SelectionPopupController_onSelectionEvent(
62 env, obj, event, selection_anchor.x(), selection_anchor.y(),
63 selection_rect.x(), selection_rect.y(), selection_rect.right(),
64 selection_rect.bottom());
65 }
66
67 void SelectionPopupController::OnSelectionChanged(const std::string& text) {
68 JNIEnv* env = AttachCurrentThread();
69 ScopedJavaLocalRef<jobject> obj = java_obj_.get(env);
70 if (obj.is_null())
71 return;
72 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text);
73 Java_SelectionPopupController_onSelectionChanged(env, obj, jtext);
74 }
75
76 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/selection_popup_controller.h ('k') | content/browser/renderer_host/render_widget_host_view_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698