Chromium Code Reviews| Index: views/ime/input_method_gtk.h |
| diff --git a/views/ime/input_method_gtk.h b/views/ime/input_method_gtk.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..242245f89b3ff6d36a45371a019a4d3685d54113 |
| --- /dev/null |
| +++ b/views/ime/input_method_gtk.h |
| @@ -0,0 +1,149 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef VIEWS_IME_INPUT_METHOD_GTK_H_ |
| +#define VIEWS_IME_INPUT_METHOD_GTK_H_ |
| +#pragma once |
| + |
| +#include <gtk/gtk.h> |
| +#include <pango/pango-attributes.h> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "ui/base/gtk/gtk_signal.h" |
| +#include "views/focus/focus_manager.h" |
| +#include "views/ime/input_method.h" |
| +#include "views/ime/input_method_delegate.h" |
| +#include "views/ime/text_input_client.h" |
| +#include "views/view.h" |
| + |
| +namespace views { |
| + |
| +// An InputMethod implementation based on GtkIMContext. Most code are copied |
| +// from chrome/browser/renderer_host/gtk_im_context_wrapper.* |
| +// It's intended for testing purpose. |
| +class InputMethodGtk : public InputMethod, |
| + public FocusChangeListener { |
| + public: |
| + explicit InputMethodGtk(internal::InputMethodDelegate* delegate); |
| + virtual ~InputMethodGtk(); |
| + |
| + // Overridden from InputMethod: |
| + virtual void set_delegate(internal::InputMethodDelegate* delegate) OVERRIDE; |
| + virtual void Init(Widget* widget) OVERRIDE; |
| + virtual void DispatchKeyEvent(const KeyEvent& key) OVERRIDE; |
| + virtual void OnTextInputTypeChanged(View* view) OVERRIDE; |
| + virtual void OnCaretBoundsChanged(View* view) OVERRIDE; |
| + virtual void CancelComposition(View* view) OVERRIDE; |
| + virtual std::string GetInputLocale() OVERRIDE; |
| + virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; |
| + virtual bool IsActive() OVERRIDE; |
| + |
| + // Overridden from FocusChangeListener: |
| + virtual void FocusWillChange(View* focused_before, View* focused) OVERRIDE; |
| + |
| + private: |
| + // Asks the client to confirm current composition text. |
|
oshima
2011/03/21 20:30:56
What does this really do? Just curious because thi
James Su
2011/03/21 21:21:16
It'll convert ongoing composition text into final
|
| + void ConfirmComposition(); |
| + |
| + // Resets |context_| and |context_simple_|. |
| + void ResetContext(); |
| + |
| + // Checks the availability of focused text input client and update focus state |
| + // of |context_| and |context_simple_| accordingly. |
| + void UpdateContextFocusState(); |
| + |
| + // Processes a key event that was already filtered by the input method. |
| + // A VKEY_PROCESSKEY may be dispatched to the focused View. |
| + void ProcessFilteredKeyPressEvent(const KeyEvent& key); |
| + |
| + // Processes a key event that was not filtered by the input method. |
| + void ProcessUnfilteredKeyPressEvent(const KeyEvent& key); |
| + |
| + // Sends input method result caused by the given key event to the focused text |
| + // input client. |
| + void ProcessInputMethodResult(const KeyEvent& key, bool filtered); |
| + |
| + // Gets the focused text input client. Returns NULL if there is no focused |
| + // View or the focused View doesn't support text input. |
| + TextInputClient* GetTextInputClient() const; |
| + |
| + // Gets the text input type of the focused text input client. |
| + ui::TextInputType GetTextInputType() const; |
| + |
| + // Checks if the given view is focused. Returns true only if the view and |
| + // toplevel widget are both focused. |
| + bool IsViewFocused(View* view) const; |
| + |
| + // Checks if the pending input method result needs inserting into the focused |
| + // text input client as a single character. |
| + bool NeedInsertChar() const; |
| + |
| + // Sends pending input method result to the focused text input client. |
|
oshima
2011/03/21 20:30:56
Is this comment correct?
James Su
2011/03/21 21:21:16
Done.
|
| + bool HasInputMethodResult() const; |
| + |
| + // Fabricates a key event with VKEY_PROCESSKEY key code and dispatches it to |
| + // the focused View. |
| + void SendFakeProcessKeyEvent(bool pressed) const; |
| + |
| + // Synthesize a GdkEventKey based on given key event. The returned GdkEventKey |
| + // must be freed with gdk_event_free(). |
| + GdkEvent* SynthesizeGdkEventKey(const KeyEvent& key) const; |
| + |
| + // Convenience method to call delegate_->DispatchKeyEventPostIME(). |
| + void DispatchKeyEventPostIME(const KeyEvent& key) const; |
| + |
| + // Event handlers: |
| + CHROMEG_CALLBACK_1(InputMethodGtk, void, OnCommit, GtkIMContext*, gchar*); |
| + CHROMEG_CALLBACK_0(InputMethodGtk, void, OnPreeditStart, GtkIMContext*); |
| + CHROMEG_CALLBACK_0(InputMethodGtk, void, OnPreeditChanged, GtkIMContext*); |
| + CHROMEG_CALLBACK_0(InputMethodGtk, void, OnPreeditEnd, GtkIMContext*); |
| + |
| + CHROMEGTK_CALLBACK_0(InputMethodGtk, void, OnWidgetRealize); |
| + CHROMEGTK_CALLBACK_0(InputMethodGtk, void, OnWidgetUnrealize); |
| + |
| + CHROMEGTK_CALLBACK_1(InputMethodGtk, gboolean, OnWidgetFocusIn, |
| + GdkEventFocus*); |
| + CHROMEGTK_CALLBACK_1(InputMethodGtk, gboolean, OnWidgetFocusOut, |
| + GdkEventFocus*); |
| + |
| + internal::InputMethodDelegate* delegate_; |
| + Widget* widget_; |
| + View* focused_view_; |
| + |
| + GtkIMContext* context_; |
| + GtkIMContext* context_simple_; |
| + |
| + ui::Composition composition_; |
| + |
| + string16 result_text_; |
| + |
| + gulong widget_realize_id_; |
| + gulong widget_unrealize_id_; |
| + gulong widget_focus_in_id_; |
| + gulong widget_focus_out_id_; |
| + |
| + // Indicates if the toplevel widget is focused or not. |
| + bool widget_focused_; |
| + |
| + // Indicates if |context_| and |context_simple_| are focused or not. |
| + bool context_focused_; |
| + |
| + // Indicates if we are handling a key event. |
| + bool handling_key_event_; |
| + |
| + // Indicates if there is an ongoing composition text. |
| + bool composing_text_; |
| + |
| + // Indicates if the composition text is changed or deleted. |
| + bool composition_changed_; |
| + |
| + // If it's true then all input method result received before the next key |
| + // event will be discarded. |
| + bool suppress_next_result_; |
| +}; |
| + |
| +} // namespace views |
| + |
| +#endif // VIEWS_IME_INPUT_METHOD_GTK_H_ |