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

Side by Side Diff: content/browser/android/text_suggestion_host_android.h

Issue 2931443003: Add support for Android spellcheck menu in Chrome/WebViews (Closed)
Patch Set: Respond to latest comments Created 3 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 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 #ifndef CONTENT_BROWSER_ANDROID_TEXT_SUGGESTION_HOST_ANDROID_H_
6 #define CONTENT_BROWSER_ANDROID_TEXT_SUGGESTION_HOST_ANDROID_H_
7
8 #include "content/browser/android/render_widget_host_connector.h"
9 #include "content/browser/renderer_host/input/timeout_monitor.h"
10 #include "third_party/WebKit/public/platform/input_host.mojom.h"
11 #include "third_party/WebKit/public/platform/input_messages.mojom.h"
12
13 namespace content {
14
15 // This class, along with its Java counterpart TextSuggestionHost, is used to
16 // implement the Android text suggestion menu that appears when you tap a
17 // misspelled word. This class creates the Android implementation of
18 // mojom::TextSuggestionHost, which is used to communicate back-and-forth with
19 // Blink side code (these are separate classes due to lifecycle considerations;
20 // this class needs to be constructed from Java code, but Mojo code wants to
21 // take ownership of mojom::TextSuggestionHost).
22 class TextSuggestionHostAndroid : public RenderWidgetHostConnector {
23 public:
24 TextSuggestionHostAndroid(JNIEnv* env,
25 const base::android::JavaParamRef<jobject>& obj,
26 WebContents* web_contents);
27 ~TextSuggestionHostAndroid() override;
28
29 // RenderWidgetHostConnector implementation.
30 void UpdateRenderProcessConnection(
31 RenderWidgetHostViewAndroid* old_rwhva,
32 RenderWidgetHostViewAndroid* new_rhwva) override;
33
34 // Called from the Java text suggestion menu to have Blink apply a spell
35 // check suggestion.
36 void ApplySpellCheckSuggestion(
37 JNIEnv*,
38 const base::android::JavaParamRef<jobject>&,
39 const base::android::JavaParamRef<jstring>& replacement);
40 // Called from the Java text suggestion menu to have Blink delete the
41 // currently highlighted region of text that the open suggestion menu pertains
42 // to.
43 void DeleteActiveSuggestionRange(JNIEnv*,
44 const base::android::JavaParamRef<jobject>&);
45 // Called from the Java text suggestion menu to tell Blink that a word is
46 // being added to the dictionary (so Blink can clear the spell check markers
47 // for that word).
48 void NewWordAddedToDictionary(
49 JNIEnv*,
50 const base::android::JavaParamRef<jobject>&,
51 const base::android::JavaParamRef<jstring>& word);
52 // Called from the Java text suggestion menu to tell Blink that the user
53 // closed the menu without performing one of the available actions, so Blink
54 // can re-show the insertion caret and remove the suggestion range highlight.
55 void SuggestionMenuClosed(JNIEnv*,
56 const base::android::JavaParamRef<jobject>&);
57 // Called from Blink to tell the Java TextSuggestionHost to open the text
58 // suggestion menu.
59 void ShowSpellCheckSuggestionMenu(
60 double caret_x,
61 double caret_y,
62 const std::string& marked_text,
63 const std::vector<blink::mojom::SpellCheckSuggestionPtr>& suggestions);
64
65 // Called by RenderWidgetHostViewAndroid
66 void FocusedNodeChanged();
67
68 // Called by browser-side code in response to an input event to stop the
69 // spell check menu timer and close the suggestion menu (if open).
70 void OnKeyEvent();
71 // Called by Blink when the user taps on a spell check marker and we might
72 // want to show the text suggestion menu after the double-tap timer expires.
73 void StartSpellCheckMenuTimer();
74 // Called by browser-side code in response to an input event to stop the
75 // spell check menu timer.
76 void StopSpellCheckMenuTimer();
77
78 private:
79 RenderFrameHost* GetFocusedFrame();
80 const blink::mojom::TextSuggestionBackendPtr& GetTextSuggestionBackend();
81 // Used by the spell check menu timer to notify Blink that the timer has
82 // expired.
83 void OnSpellCheckMenuTimeout();
84
85 // Current RenderWidgetHostView connected to this instance. Can be null.
86 RenderWidgetHostViewAndroid* rwhva_;
87 JavaObjectWeakGlobalRef java_text_suggestion_host_;
88 blink::mojom::TextSuggestionBackendPtr text_suggestion_backend_;
89 TimeoutMonitor spellcheck_menu_timeout_;
90 };
91
92 bool RegisterTextSuggestionHost(JNIEnv* env);
93
94 } // namespace content
95
96 #endif // CONTENT_BROWSER_ANDROID_TEXT_SUGGESTION_HOST_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698