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

Side by Side Diff: chrome/browser/renderer_host/gtk_im_context_wrapper.h

Issue 160577: Cleanup GtkIMContext related code by splitting it into separated source file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/renderer_host/gtk_im_context_wrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 CHROME_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_
6 #define CHROME_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_
7
8 #include <gdk/gdk.h>
9
10 #include "base/basictypes.h"
11 #include "base/string16.h"
12
13 namespace gfx {
14 class Rect;
15 }
16
17 class RenderWidgetHostViewGtk;
18 class NativeWebKeyboardEvent;
19 typedef struct _GtkIMContext GtkIMContext;
20
21 // This class is a convenience wrapper for GtkIMContext.
22 // It creates and manages two GtkIMContext instances, one is GtkIMMulticontext,
23 // for plain text input box, another is GtkIMContextSimple, for password input
24 // box.
25 //
26 // This class is in charge of dispatching key events to these two GtkIMContext
27 // instances and handling signals emitted by them. Key events then will be
28 // forwarded to renderer along with input method results via corresponding host
29 // view.
30 //
31 // This class is used solely by RenderWidgetHostViewGtk.
32 class GtkIMContextWrapper {
33 public:
34 explicit GtkIMContextWrapper(RenderWidgetHostViewGtk* host_view);
35 ~GtkIMContextWrapper();
36
37 // Processes a gdk key event received by |host_view|.
38 void ProcessKeyEvent(GdkEventKey* event);
39
40 // Updates IME status and caret position.
41 void UpdateStatus(int control, const gfx::Rect& caret_rect);
42 void OnFocusIn();
43 void OnFocusOut();
44
45 private:
46 // Check if a text needs commit by forwarding a char event instead of
47 // by confirming as a composition text.
48 bool NeedCommitByForwardingCharEvent();
49
50 void ProcessFilteredKeyPressEvent(NativeWebKeyboardEvent* wke);
51 void ProcessUnfilteredKeyPressEvent(NativeWebKeyboardEvent* wke);
52
53 // Processes result returned from input method after filtering a key event.
54 // |filtered| indicates if the key event was filtered by the input method.
55 void ProcessInputMethodResult(const GdkEventKey* event, bool filtered);
56
57 void CompleteComposition();
58
59 // Real code of "commit" signal handler.
60 void HandleCommit(const string16& text);
61
62 // Real code of "preedit-start" signal handler.
63 void HandlePreeditStart();
64
65 // Real code of "preedit-changed" signal handler.
66 void HandlePreeditChanged(const string16& text, int cursor_position);
67
68 // Real code of "preedit-end" signal handler.
69 void HandlePreeditEnd();
70
71 // Signal handlers of GtkIMContext object.
72 static void HandleCommitThunk(GtkIMContext* context, gchar* text,
73 GtkIMContextWrapper* self);
74 static void HandlePreeditStartThunk(GtkIMContext* context,
75 GtkIMContextWrapper* self);
76 static void HandlePreeditChangedThunk(GtkIMContext* context,
77 GtkIMContextWrapper* self);
78 static void HandlePreeditEndThunk(GtkIMContext* context,
79 GtkIMContextWrapper* self);
80
81 // The parent object.
82 RenderWidgetHostViewGtk* host_view_;
83
84 // The GtkIMContext object.
85 // In terms of the DOM event specification Appendix A
86 // <http://www.w3.org/TR/DOM-Level-3-Events/keyset.html>,
87 // GTK uses a GtkIMContext object for the following two purposes:
88 // 1. Composing Latin characters (A.1.2), and;
89 // 2. Composing CJK characters with an IME (A.1.3).
90 // Many JavaScript pages assume composed Latin characters are dispatched to
91 // their onkeypress() handlers but not dispatched CJK characters composed
92 // with an IME. To emulate this behavior, we should monitor the status of
93 // this GtkIMContext object and prevent sending Char events when a
94 // GtkIMContext object sends a "commit" signal with the CJK characters
95 // composed by an IME.
96 GtkIMContext* context_;
97
98 // A GtkIMContextSimple object, for supporting dead/compose keys when input
99 // method is disabled, eg. in password input box.
100 GtkIMContext* context_simple_;
101
102 // Whether or not this widget is focused.
103 bool is_focused_;
104
105 // Whether or not the above GtkIMContext is composing a text with an IME.
106 // This flag is used in "commit" signal handler of the GtkIMContext object,
107 // which determines how to submit the result text to WebKit according to this
108 // flag.
109 // If this flag is true or there are more than one characters in the result,
110 // then the result text will be committed to WebKit as a confirmed
111 // composition. Otherwise, it'll be forwarded as a key event.
112 //
113 // The GtkIMContext object sends a "preedit_start" before it starts composing
114 // a text and a "preedit_end" signal after it finishes composing it.
115 // "preedit_start" signal is monitored to turn it on.
116 // We don't monitor "preedit_end" signal to turn it off, because an input
117 // method may fire "preedit_end" signal before "commit" signal.
118 // A buggy input method may not fire "preedit_start" and/or "preedit_end"
119 // at all, so this flag will also be set to true when "preedit_changed" signal
120 // is fired with non-empty preedit text.
121 bool is_composing_text_;
122
123 // Whether or not the IME is enabled.
124 // This flag is actually controlled by RenderWidget.
125 // It shall be set to false when an ImeUpdateStatus message with control ==
126 // IME_DISABLE is received, and shall be set to true if control ==
127 // IME_COMPLETE_COMPOSITION or IME_MOVE_WINDOWS.
128 // When this flag is false, keyboard events shall be dispatched directly
129 // instead of sending to context_.
130 bool is_enabled_;
131
132 // Whether or not it's currently running inside key event handler.
133 // If it's true, then preedit-changed and commit handler will backup the
134 // preedit or commit text instead of sending them down to webkit.
135 // key event handler will send them later.
136 bool is_in_key_event_handler_;
137
138 // Stores a copy of the most recent preedit text retrieved from context_.
139 // When an ImeUpdateStatus message with control == IME_COMPLETE_COMPOSITION
140 // is received, this stored preedit text (if not empty) shall be committed,
141 // and context_ shall be reset.
142 string16 preedit_text_;
143
144 // Stores the cursor position in the stored preedit text.
145 int preedit_cursor_position_;
146
147 // Whether or not the preedit has been changed since last key event.
148 bool is_preedit_changed_;
149
150 // Stores a copy of the most recent commit text received by commit signal
151 // handler.
152 string16 commit_text_;
153
154 DISALLOW_COPY_AND_ASSIGN(GtkIMContextWrapper);
155 };
156
157
158 #endif // CHROME_BROWSER_RENDERER_HOST_GTK_IM_CONTEXT_WRAPPER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_host/gtk_im_context_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698