OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_ |
6 #define CHROME_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <gdk/gdk.h> | 9 #include <gdk/gdk.h> |
10 #include <pango/pango-attributes.h> | 10 #include <pango/pango-attributes.h> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" | |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextInputType.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextInputType.h" |
| 18 #include "ui/base/ime/composition_text.h" |
19 | 19 |
20 namespace gfx { | 20 namespace gfx { |
21 class Rect; | 21 class Rect; |
22 } | 22 } |
23 | 23 |
24 #if !defined(TOOLKIT_VIEWS) | 24 #if !defined(TOOLKIT_VIEWS) |
25 class MenuGtk; | 25 class MenuGtk; |
26 #endif | 26 #endif |
27 class RenderWidgetHostViewGtk; | 27 class RenderWidgetHostViewGtk; |
28 struct NativeWebKeyboardEvent; | 28 struct NativeWebKeyboardEvent; |
(...skipping 28 matching lines...) Expand all Loading... |
57 // Not defined for views because the views context menu doesn't | 57 // Not defined for views because the views context menu doesn't |
58 // implement input methods yet. | 58 // implement input methods yet. |
59 void AppendInputMethodsContextMenu(MenuGtk* menu); | 59 void AppendInputMethodsContextMenu(MenuGtk* menu); |
60 #endif | 60 #endif |
61 | 61 |
62 void CancelComposition(); | 62 void CancelComposition(); |
63 | 63 |
64 void ConfirmComposition(); | 64 void ConfirmComposition(); |
65 | 65 |
66 private: | 66 private: |
67 // For unit tests. | |
68 class GtkIMContextWrapperTest; | |
69 FRIEND_TEST_ALL_PREFIXES(GtkIMContextWrapperTest, ExtractCompositionInfo); | |
70 | |
71 // Check if a text needs commit by forwarding a char event instead of | 67 // Check if a text needs commit by forwarding a char event instead of |
72 // by confirming as a composition text. | 68 // by confirming as a composition text. |
73 bool NeedCommitByForwardingCharEvent() const; | 69 bool NeedCommitByForwardingCharEvent() const; |
74 | 70 |
75 // Check if the input method returned any result, eg. preedit and commit text. | 71 // Check if the input method returned any result, eg. preedit and commit text. |
76 bool HasInputMethodResult() const; | 72 bool HasInputMethodResult() const; |
77 | 73 |
78 void ProcessFilteredKeyPressEvent(NativeWebKeyboardEvent* wke); | 74 void ProcessFilteredKeyPressEvent(NativeWebKeyboardEvent* wke); |
79 void ProcessUnfilteredKeyPressEvent(NativeWebKeyboardEvent* wke); | 75 void ProcessUnfilteredKeyPressEvent(NativeWebKeyboardEvent* wke); |
80 | 76 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 GtkIMContextWrapper* self); | 113 GtkIMContextWrapper* self); |
118 static void HandlePreeditEndThunk(GtkIMContext* context, | 114 static void HandlePreeditEndThunk(GtkIMContext* context, |
119 GtkIMContextWrapper* self); | 115 GtkIMContextWrapper* self); |
120 | 116 |
121 // Signal handlers connecting to |host_view_|'s native view widget. | 117 // Signal handlers connecting to |host_view_|'s native view widget. |
122 static void HandleHostViewRealizeThunk(GtkWidget* widget, | 118 static void HandleHostViewRealizeThunk(GtkWidget* widget, |
123 GtkIMContextWrapper* self); | 119 GtkIMContextWrapper* self); |
124 static void HandleHostViewUnrealizeThunk(GtkWidget* widget, | 120 static void HandleHostViewUnrealizeThunk(GtkWidget* widget, |
125 GtkIMContextWrapper* self); | 121 GtkIMContextWrapper* self); |
126 | 122 |
127 // Extracts composition underlines, selection range and utf-16 text from given | |
128 // utf-8 text, pango attributes and cursor position. | |
129 static void ExtractCompositionInfo( | |
130 const gchar* utf8_text, | |
131 PangoAttrList* attrs, | |
132 int cursor_position, | |
133 string16* utf16_text, | |
134 std::vector<WebKit::WebCompositionUnderline>* underlines, | |
135 int* selection_start, | |
136 int* selection_end); | |
137 | |
138 // The parent object. | 123 // The parent object. |
139 RenderWidgetHostViewGtk* host_view_; | 124 RenderWidgetHostViewGtk* host_view_; |
140 | 125 |
141 // The GtkIMContext object. | 126 // The GtkIMContext object. |
142 // In terms of the DOM event specification Appendix A | 127 // In terms of the DOM event specification Appendix A |
143 // <http://www.w3.org/TR/DOM-Level-3-Events/keyset.html>, | 128 // <http://www.w3.org/TR/DOM-Level-3-Events/keyset.html>, |
144 // GTK uses a GtkIMContext object for the following two purposes: | 129 // GTK uses a GtkIMContext object for the following two purposes: |
145 // 1. Composing Latin characters (A.1.2), and; | 130 // 1. Composing Latin characters (A.1.2), and; |
146 // 2. Composing CJK characters with an IME (A.1.3). | 131 // 2. Composing CJK characters with an IME (A.1.3). |
147 // Many JavaScript pages assume composed Latin characters are dispatched to | 132 // Many JavaScript pages assume composed Latin characters are dispatched to |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 164 |
180 // Whether or not the IME is enabled. | 165 // Whether or not the IME is enabled. |
181 bool is_enabled_; | 166 bool is_enabled_; |
182 | 167 |
183 // Whether or not it's currently running inside key event handler. | 168 // Whether or not it's currently running inside key event handler. |
184 // If it's true, then preedit-changed and commit handler will backup the | 169 // If it's true, then preedit-changed and commit handler will backup the |
185 // preedit or commit text instead of sending them down to webkit. | 170 // preedit or commit text instead of sending them down to webkit. |
186 // key event handler will send them later. | 171 // key event handler will send them later. |
187 bool is_in_key_event_handler_; | 172 bool is_in_key_event_handler_; |
188 | 173 |
189 // Stores a copy of the most recent preedit text retrieved from context_. | 174 // The most recent composition text information retrieved from context_; |
190 string16 preedit_text_; | 175 ui::CompositionText composition_; |
191 | 176 |
192 // Stores the selection range in the stored preedit text. | 177 // Whether or not the composition has been changed since last key event. |
193 int preedit_selection_start_; | 178 bool is_composition_changed_; |
194 int preedit_selection_end_; | |
195 | |
196 // Stores composition underlines computed from the pango attributes of the | |
197 // most recent preedit text. | |
198 std::vector<WebKit::WebCompositionUnderline> preedit_underlines_; | |
199 | |
200 // Whether or not the preedit has been changed since last key event. | |
201 bool is_preedit_changed_; | |
202 | 179 |
203 // Stores a copy of the most recent commit text received by commit signal | 180 // Stores a copy of the most recent commit text received by commit signal |
204 // handler. | 181 // handler. |
205 string16 commit_text_; | 182 string16 commit_text_; |
206 | 183 |
207 // If it's true then the next "commit" signal will be suppressed. | 184 // If it's true then the next "commit" signal will be suppressed. |
208 // It's only used to workaround http://crbug.com/50485. | 185 // It's only used to workaround http://crbug.com/50485. |
209 // TODO(suzhe): Remove it after input methods get fixed. | 186 // TODO(suzhe): Remove it after input methods get fixed. |
210 bool suppress_next_commit_; | 187 bool suppress_next_commit_; |
211 | 188 |
212 // Information of the last key event, for working around | 189 // Information of the last key event, for working around |
213 // http://crosbug.com/6582 | 190 // http://crosbug.com/6582 |
214 int last_key_code_; | 191 int last_key_code_; |
215 bool last_key_was_up_; | 192 bool last_key_was_up_; |
216 bool last_key_filtered_no_result_; | 193 bool last_key_filtered_no_result_; |
217 | 194 |
218 DISALLOW_COPY_AND_ASSIGN(GtkIMContextWrapper); | 195 DISALLOW_COPY_AND_ASSIGN(GtkIMContextWrapper); |
219 }; | 196 }; |
220 | 197 |
221 #endif // CHROME_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_ | 198 #endif // CHROME_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_ |
OLD | NEW |