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

Side by Side Diff: views/ime/input_method_gtk.h

Issue 6688049: New InputMethod api for Views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update. Created 9 years, 9 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 VIEWS_IME_INPUT_METHOD_GTK_H_
6 #define VIEWS_IME_INPUT_METHOD_GTK_H_
7 #pragma once
8
9 #include <gtk/gtk.h>
10 #include <pango/pango-attributes.h>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "ui/base/gtk/gtk_signal.h"
15 #include "views/focus/focus_manager.h"
16 #include "views/ime/input_method.h"
17 #include "views/ime/input_method_delegate.h"
18 #include "views/ime/text_input_client.h"
19 #include "views/view.h"
20
21 namespace views {
22
23 // An InputMethod implementation based on GtkIMContext. Most code are copied
24 // from chrome/browser/renderer_host/gtk_im_context_wrapper.*
25 // It's intended for testing purpose.
26 class InputMethodGtk : public InputMethod,
27 public FocusChangeListener {
28 public:
29 explicit InputMethodGtk(internal::InputMethodDelegate* delegate);
30 virtual ~InputMethodGtk();
31
32 // Overridden from InputMethod:
33 virtual void set_delegate(internal::InputMethodDelegate* delegate) OVERRIDE;
34 virtual void Init(Widget* widget) OVERRIDE;
35 virtual void DispatchKeyEvent(const KeyEvent& key) OVERRIDE;
36 virtual void OnTextInputTypeChanged(View* view) OVERRIDE;
37 virtual void OnCaretBoundsChanged(View* view) OVERRIDE;
38 virtual void CancelComposition(View* view) OVERRIDE;
39 virtual std::string GetInputLocale() OVERRIDE;
40 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
41 virtual bool IsActive() OVERRIDE;
42
43 // Overridden from FocusChangeListener:
44 virtual void FocusWillChange(View* focused_before, View* focused) OVERRIDE;
45
46 private:
47 // Asks the client to confirm current composition text.
48 void ConfirmComposition();
49
50 // Resets |context_| and |context_simple_|.
51 void ResetContext();
52
53 // Checks the availability of focused text input client and update focus state
54 // of |context_| and |context_simple_| accordingly.
55 void UpdateContextFocusState();
56
57 // Processes a key event that was already filtered by the input method.
58 // A VKEY_PROCESSKEY may be dispatched to the focused View.
59 void ProcessFilteredKeyPressEvent(const KeyEvent& key);
60
61 // Processes a key event that was not filtered by the input method.
62 void ProcessUnfilteredKeyPressEvent(const KeyEvent& key);
63
64 // Sends input method result caused by the given key event to the focused text
65 // input client.
66 void ProcessInputMethodResult(const KeyEvent& key, bool filtered);
67
68 // Gets the focused text input client. Returns NULL if there is no focused
69 // View or the focused View doesn't support text input.
70 TextInputClient* GetTextInputClient() const;
71
72 // Gets the text input type of the focused text input client.
73 ui::TextInputType GetTextInputType() const;
74
75 // Checks if the given view is focused. Returns true only if the view and
76 // toplevel widget are both focused.
77 bool IsViewFocused(View* view) const;
78
79 // Checks if the pending input method result needs inserting into the focused
80 // text input client as a single character.
81 bool NeedInsertChar() const;
82
83 // Checks if there is pending input method result.
84 bool HasInputMethodResult() const;
85
86 // Fabricates a key event with VKEY_PROCESSKEY key code and dispatches it to
87 // the focused View.
88 void SendFakeProcessKeyEvent(bool pressed) const;
89
90 // Synthesize a GdkEventKey based on given key event. The returned GdkEventKey
91 // must be freed with gdk_event_free().
92 GdkEvent* SynthesizeGdkEventKey(const KeyEvent& key) const;
93
94 // Convenience method to call delegate_->DispatchKeyEventPostIME().
95 void DispatchKeyEventPostIME(const KeyEvent& key) const;
96
97 // Event handlers:
98 CHROMEG_CALLBACK_1(InputMethodGtk, void, OnCommit, GtkIMContext*, gchar*);
99 CHROMEG_CALLBACK_0(InputMethodGtk, void, OnPreeditStart, GtkIMContext*);
100 CHROMEG_CALLBACK_0(InputMethodGtk, void, OnPreeditChanged, GtkIMContext*);
101 CHROMEG_CALLBACK_0(InputMethodGtk, void, OnPreeditEnd, GtkIMContext*);
102
103 CHROMEGTK_CALLBACK_0(InputMethodGtk, void, OnWidgetRealize);
104 CHROMEGTK_CALLBACK_0(InputMethodGtk, void, OnWidgetUnrealize);
105
106 CHROMEGTK_CALLBACK_1(InputMethodGtk, gboolean, OnWidgetFocusIn,
107 GdkEventFocus*);
108 CHROMEGTK_CALLBACK_1(InputMethodGtk, gboolean, OnWidgetFocusOut,
109 GdkEventFocus*);
110
111 internal::InputMethodDelegate* delegate_;
112 Widget* widget_;
113 View* focused_view_;
114
115 GtkIMContext* context_;
116 GtkIMContext* context_simple_;
117
118 ui::Composition composition_;
119
120 string16 result_text_;
121
122 gulong widget_realize_id_;
123 gulong widget_unrealize_id_;
124 gulong widget_focus_in_id_;
125 gulong widget_focus_out_id_;
126
127 // Indicates if the toplevel widget is focused or not.
128 bool widget_focused_;
129
130 // Indicates if |context_| and |context_simple_| are focused or not.
131 bool context_focused_;
132
133 // Indicates if we are handling a key event.
134 bool handling_key_event_;
135
136 // Indicates if there is an ongoing composition text.
137 bool composing_text_;
138
139 // Indicates if the composition text is changed or deleted.
140 bool composition_changed_;
141
142 // If it's true then all input method result received before the next key
143 // event will be discarded.
144 bool suppress_next_result_;
145 };
146
147 } // namespace views
148
149 #endif // VIEWS_IME_INPUT_METHOD_GTK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698