Adding wrapper class WKBackForwardListItemHolder
[chromium-blink-merge.git] / ui / base / ime / input_method_chromeos.h
blobda1b12ba5ef58ed7cdd3358d1b2e8f7a798e1178
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 bool DispatchKeyEvent(const 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(const 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 bool ProcessFilteredKeyPressEvent(const ui::KeyEvent& event);
78 // Processes a key event that was not filtered by the input method.
79 void ProcessUnfilteredKeyPressEvent(const ui::KeyEvent& event);
81 // Sends input method result caused by the given key event to the focused text
82 // input client.
83 void ProcessInputMethodResult(const 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 void SendFakeProcessKeyEvent(bool pressed) const;
95 // Passes keyevent and executes character composition if necessary. Returns
96 // true if character composer comsumes key event.
97 bool ExecuteCharacterComposer(const ui::KeyEvent& event);
99 // chromeos::IMEInputContextHandlerInterface overrides:
100 void CommitText(const std::string& text) override;
101 void UpdateCompositionText(const chromeos::CompositionText& text,
102 uint32 cursor_pos,
103 bool visible) override;
104 void DeleteSurroundingText(int32 offset, uint32 length) override;
106 // Hides the composition text.
107 void HidePreeditText();
109 // Callback function for IMEEngineHandlerInterface::ProcessKeyEvent.
110 void ProcessKeyEventDone(const ui::KeyEvent* event, bool is_handled);
112 // Returns whether an non-password input field is focused.
113 bool IsNonPasswordInputFieldFocused();
115 // Returns true if an text input field is focused.
116 bool IsInputFieldFocused();
118 // Pending composition text generated by the current pending key event.
119 // It'll be sent to the focused text input client as soon as we receive the
120 // processing result of the pending key event.
121 CompositionText composition_;
123 // Pending result text generated by the current pending key event.
124 // It'll be sent to the focused text input client as soon as we receive the
125 // processing result of the pending key event.
126 base::string16 result_text_;
128 base::string16 previous_surrounding_text_;
129 gfx::Range previous_selection_range_;
131 // Indicates if there is an ongoing composition text.
132 bool composing_text_;
134 // Indicates if the composition text is changed or deleted.
135 bool composition_changed_;
137 // An object to compose a character from a sequence of key presses
138 // including dead key etc.
139 CharacterComposer character_composer_;
141 // Indicates whether currently is handling a physical key event.
142 // This is used in CommitText/UpdateCompositionText/etc.
143 bool handling_key_event_;
145 // Used for making callbacks.
146 base::WeakPtrFactory<InputMethodChromeOS> weak_ptr_factory_;
148 DISALLOW_COPY_AND_ASSIGN(InputMethodChromeOS);
151 } // namespace ui
153 #endif // UI_BASE_IME_INPUT_METHOD_CHROMEOS_H_