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