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

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 according to review feedbacks. 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/ime/input_method_base.h"
16 #include "views/view.h"
17
18 namespace views {
19
20 // An InputMethod implementation based on GtkIMContext. Most code are copied
21 // from chrome/browser/renderer_host/gtk_im_context_wrapper.*
22 // It's intended for testing purpose.
23 class InputMethodGtk : public InputMethodBase {
24 public:
25 explicit InputMethodGtk(internal::InputMethodDelegate* delegate);
26 virtual ~InputMethodGtk();
27
28 // Overridden from InputMethod:
29 virtual void Init(Widget* widget) OVERRIDE;
30 virtual void DispatchKeyEvent(const KeyEvent& key) OVERRIDE;
31 virtual void OnTextInputTypeChanged(View* view) OVERRIDE;
32 virtual void OnCaretBoundsChanged(View* view) OVERRIDE;
33 virtual void CancelComposition(View* view) OVERRIDE;
34 virtual std::string GetInputLocale() OVERRIDE;
35 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
36 virtual bool IsActive() OVERRIDE;
37
38 private:
39 // Overridden from InputMethodBase:
40 virtual void FocusedViewWillChange() OVERRIDE;
41 virtual void FocusedViewDidChange() OVERRIDE;
42
43 // Asks the client to confirm current composition text.
44 void ConfirmCompositionText();
45
46 // Resets |context_| and |context_simple_|.
47 void ResetContext();
48
49 // Checks the availability of focused text input client and update focus state
50 // of |context_| and |context_simple_| accordingly.
51 void UpdateContextFocusState();
52
53 // Processes a key event that was already filtered by the input method.
54 // A VKEY_PROCESSKEY may be dispatched to the focused View.
55 void ProcessFilteredKeyPressEvent(const KeyEvent& key);
56
57 // Processes a key event that was not filtered by the input method.
58 void ProcessUnfilteredKeyPressEvent(const KeyEvent& key);
59
60 // Sends input method result caused by the given key event to the focused text
61 // input client.
62 void ProcessInputMethodResult(const KeyEvent& key, bool filtered);
63
64 // Checks if the pending input method result needs inserting into the focused
65 // text input client as a single character.
66 bool NeedInsertChar() const;
67
68 // Checks if there is pending input method result.
69 bool HasInputMethodResult() const;
70
71 // Fabricates a key event with VKEY_PROCESSKEY key code and dispatches it to
72 // the focused View.
73 void SendFakeProcessKeyEvent(bool pressed) const;
74
75 // Synthesize a GdkEventKey based on given key event. The returned GdkEventKey
76 // must be freed with gdk_event_free().
77 GdkEvent* SynthesizeGdkEventKey(const KeyEvent& key) const;
78
79 // Event handlers:
80 CHROMEG_CALLBACK_1(InputMethodGtk, void, OnCommit, GtkIMContext*, gchar*);
81 CHROMEG_CALLBACK_0(InputMethodGtk, void, OnPreeditStart, GtkIMContext*);
82 CHROMEG_CALLBACK_0(InputMethodGtk, void, OnPreeditChanged, GtkIMContext*);
83 CHROMEG_CALLBACK_0(InputMethodGtk, void, OnPreeditEnd, GtkIMContext*);
84
85 CHROMEGTK_CALLBACK_0(InputMethodGtk, void, OnWidgetRealize);
86 CHROMEGTK_CALLBACK_0(InputMethodGtk, void, OnWidgetUnrealize);
87
88 CHROMEGTK_CALLBACK_1(InputMethodGtk, gboolean, OnWidgetFocusIn,
89 GdkEventFocus*);
90 CHROMEGTK_CALLBACK_1(InputMethodGtk, gboolean, OnWidgetFocusOut,
91 GdkEventFocus*);
92
93 GtkIMContext* context_;
94 GtkIMContext* context_simple_;
95
96 ui::CompositionText composition_;
97
98 string16 result_text_;
99
oshima 2011/03/22 22:35:51 // Signal ids for corresponding gtk signals.
James Su 2011/03/22 23:08:47 Done.
100 gulong widget_realize_id_;
101 gulong widget_unrealize_id_;
102 gulong widget_focus_in_id_;
103 gulong widget_focus_out_id_;
104
105 // Indicates if |context_| and |context_simple_| are focused or not.
106 bool context_focused_;
107
108 // Indicates if we are handling a key event.
109 bool handling_key_event_;
110
111 // Indicates if there is an ongoing composition text.
112 bool composing_text_;
113
114 // Indicates if the composition text is changed or deleted.
115 bool composition_changed_;
116
117 // If it's true then all input method result received before the next key
118 // event will be discarded.
119 bool suppress_next_result_;
120
121 DISALLOW_COPY_AND_ASSIGN(InputMethodGtk);
122 };
123
124 } // namespace views
125
126 #endif // VIEWS_IME_INPUT_METHOD_GTK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698