Add ICU message format support
[chromium-blink-merge.git] / ui / base / ime / input_method_chromeos.h
blobd632bf4405a7ccfd7dad59a8ec7c024690bd995d
1 // Copyright 2014 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.
5 #ifndef UI_BASE_IME_INPUT_METHOD_CHROMEOS_H_
6 #define UI_BASE_IME_INPUT_METHOD_CHROMEOS_H_
8 #include <set>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "ui/base/ime/chromeos/character_composer.h"
16 #include "ui/base/ime/chromeos/ime_bridge.h"
17 #include "ui/base/ime/composition_text.h"
18 #include "ui/base/ime/input_method_base.h"
20 namespace ui {
22 // A ui::InputMethod implementation based on IBus.
23 class UI_BASE_IME_EXPORT InputMethodChromeOS
24 : public InputMethodBase,
25 public chromeos::IMEInputContextHandlerInterface {
26 public:
27 explicit InputMethodChromeOS(internal::InputMethodDelegate* delegate);
28 ~InputMethodChromeOS() override;
30 // Overridden from InputMethod:
31 void OnFocus() override;
32 void OnBlur() override;
33 bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
34 NativeEventResult* result) override;
35 void DispatchKeyEvent(ui::KeyEvent* event) override;
36 void OnTextInputTypeChanged(const TextInputClient* client) override;
37 void OnCaretBoundsChanged(const TextInputClient* client) override;
38 void CancelComposition(const TextInputClient* client) override;
39 void OnInputLocaleChanged() override;
40 std::string GetInputLocale() override;
41 bool IsCandidatePopupOpen() const override;
43 protected:
44 // Converts |text| into CompositionText.
45 void ExtractCompositionText(const chromeos::CompositionText& text,
46 uint32 cursor_position,
47 CompositionText* out_composition) const;
49 // Process a key returned from the input method.
50 virtual void ProcessKeyEventPostIME(ui::KeyEvent* event,
51 bool handled);
53 // Resets context and abandon all pending results and key events.
54 void ResetContext();
56 private:
57 class PendingKeyEvent;
59 // Overridden from InputMethodBase:
60 void OnWillChangeFocusedClient(TextInputClient* focused_before,
61 TextInputClient* focused) override;
62 void OnDidChangeFocusedClient(TextInputClient* focused_before,
63 TextInputClient* focused) override;
65 // Asks the client to confirm current composition text.
66 void ConfirmCompositionText();
68 // Checks the availability of focused text input client and update focus
69 // state.
70 void UpdateContextFocusState();
72 // Processes a key event that was already filtered by the input method.
73 // A VKEY_PROCESSKEY may be dispatched to the EventTargets.
74 // It returns the result of whether the event has been stopped propagation
75 // when dispatching post IME.
76 void ProcessFilteredKeyPressEvent(ui::KeyEvent* event);
78 // Processes a key event that was not filtered by the input method.
79 void ProcessUnfilteredKeyPressEvent(ui::KeyEvent* event);
81 // Sends input method result caused by the given key event to the focused text
82 // input client.
83 void ProcessInputMethodResult(ui::KeyEvent* event, bool filtered);
85 // Checks if the pending input method result needs inserting into the focused
86 // text input client as a single character.
87 bool NeedInsertChar() const;
89 // Checks if there is pending input method result.
90 bool HasInputMethodResult() const;
92 // Sends a fake key event for IME composing without physical key events.
93 // Returns true if the faked key event is stopped propagation.
94 bool SendFakeProcessKeyEvent(bool pressed) const;
96 // Passes keyevent and executes character composition if necessary. Returns
97 // true if character composer comsumes key event.
98 bool ExecuteCharacterComposer(const ui::KeyEvent& event);
100 // chromeos::IMEInputContextHandlerInterface overrides:
101 void CommitText(const std::string& text) override;
102 void UpdateCompositionText(const chromeos::CompositionText& text,
103 uint32 cursor_pos,
104 bool visible) override;
105 void DeleteSurroundingText(int32 offset, uint32 length) override;
107 // Hides the composition text.
108 void HidePreeditText();
110 // Callback function for IMEEngineHandlerInterface::ProcessKeyEvent.
111 void ProcessKeyEventDone(ui::KeyEvent* event, bool is_handled);
113 // Returns whether an non-password input field is focused.
114 bool IsNonPasswordInputFieldFocused();
116 // Returns true if an text input field is focused.
117 bool IsInputFieldFocused();
119 // Pending composition text generated by the current pending key event.
120 // It'll be sent to the focused text input client as soon as we receive the
121 // processing result of the pending key event.
122 CompositionText composition_;
124 // Pending result text generated by the current pending key event.
125 // It'll be sent to the focused text input client as soon as we receive the
126 // processing result of the pending key event.
127 base::string16 result_text_;
129 base::string16 previous_surrounding_text_;
130 gfx::Range previous_selection_range_;
132 // Indicates if there is an ongoing composition text.
133 bool composing_text_;
135 // Indicates if the composition text is changed or deleted.
136 bool composition_changed_;
138 // An object to compose a character from a sequence of key presses
139 // including dead key etc.
140 CharacterComposer character_composer_;
142 // Indicates whether currently is handling a physical key event.
143 // This is used in CommitText/UpdateCompositionText/etc.
144 bool handling_key_event_;
146 // Used for making callbacks.
147 base::WeakPtrFactory<InputMethodChromeOS> weak_ptr_factory_;
149 DISALLOW_COPY_AND_ASSIGN(InputMethodChromeOS);
152 } // namespace ui
154 #endif // UI_BASE_IME_INPUT_METHOD_CHROMEOS_H_