Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / base / ime / input_method_auralinux.h
1 // Copyright 2013 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 UI_BASE_IME_INPUT_METHOD_AURALINUX_H_
6 #define UI_BASE_IME_INPUT_METHOD_AURALINUX_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/base/ime/input_method_base.h"
10 #include "ui/base/ime/linux/linux_input_method_context.h"
11
12 namespace ui {
13
14 // A ui::InputMethod implementation for Aura on Linux platforms. The
15 // implementation details are separated to ui::LinuxInputMethodContext
16 // interface.
17 class UI_BASE_EXPORT InputMethodAuraLinux
18     : public InputMethodBase,
19       public LinuxInputMethodContextDelegate {
20  public:
21   explicit InputMethodAuraLinux(internal::InputMethodDelegate* delegate);
22   ~InputMethodAuraLinux() override;
23
24   // Overriden from InputMethod.
25   void Init(bool focused) override;
26   bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
27                                 NativeEventResult* result) override;
28   bool DispatchKeyEvent(const ui::KeyEvent& event) override;
29   void OnTextInputTypeChanged(const TextInputClient* client) override;
30   void OnCaretBoundsChanged(const TextInputClient* client) override;
31   void CancelComposition(const TextInputClient* client) override;
32   void OnInputLocaleChanged() override;
33   std::string GetInputLocale() override;
34   bool IsActive() override;
35   bool IsCandidatePopupOpen() const override;
36
37   // Overriden from ui::LinuxInputMethodContextDelegate
38   void OnCommit(const base::string16& text) override;
39   void OnPreeditChanged(const CompositionText& composition_text) override;
40   void OnPreeditEnd() override;
41   void OnPreeditStart() override;
42
43  protected:
44   // Overridden from InputMethodBase.
45   void OnDidChangeFocusedClient(TextInputClient* focused_before,
46                                 TextInputClient* focused) override;
47
48  private:
49   // Allows to fire a VKEY_PROCESSKEY key event.
50   void AllowToFireProcessKey(const ui::KeyEvent& event);
51   // Fires a VKEY_PROCESSKEY key event if allowed.
52   void MaybeFireProcessKey();
53   // Stops firing VKEY_PROCESSKEY key events.
54   void StopFiringProcessKey();
55
56   scoped_ptr<LinuxInputMethodContext> input_method_context_;
57
58   // IBus in async mode eagerly consumes all the key events first regardless of
59   // whether the underlying IME consumes the key event or not, and makes
60   // gtk_im_context_filter_keypress() always return true, and later pushes
61   // the key event back to the GDK event queue when it turns out that the
62   // underlying IME doesn't consume the key event.
63   //
64   // Thus we have to defer a decision whether or not to dispatch a
65   // VKEY_PROCESSKEY key event.  Unlike other InputMethod's subclasses,
66   // DispatchKeyEvent() in this class does not directly dispatch a
67   // VKEY_PROCESSKEY event, OnCommit or OnPreedit{Start,Changed,End} dispatch
68   // a VKEY_PROCESSKEY event instead.
69   //
70   // Because of this hack, there could be chances that we accidentally dispatch
71   // VKEY_PROCESSKEY events and other key events in out of order.
72   //
73   // |allowed_to_fire_vkey_process_key_| is used not to dispatch a
74   // VKEY_PROCESSKEY event twice for a single key event.
75   bool allowed_to_fire_vkey_process_key_;
76   int vkey_processkey_flags_;
77
78   DISALLOW_COPY_AND_ASSIGN(InputMethodAuraLinux);
79 };
80
81 }  // namespace ui
82
83 #endif  // UI_BASE_IME_INPUT_METHOD_AURALINUX_H_