Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / base / ime / chromeos / character_composer.h
blob7c32d930bd274d843a6832ab2e67e06545e9e343
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.
5 #ifndef UI_BASE_IME_CHROMEOS_CHARACTER_COMPOSER_H_
6 #define UI_BASE_IME_CHROMEOS_CHARACTER_COMPOSER_H_
8 #include <vector>
10 #include "base/strings/string_util.h"
11 #include "ui/base/ime/ui_base_ime_export.h"
13 namespace ui {
14 class KeyEvent;
16 // A class to recognize compose and dead key sequence.
17 // Outputs composed character.
18 class UI_BASE_IME_EXPORT CharacterComposer {
19 public:
20 CharacterComposer();
21 ~CharacterComposer();
23 void Reset();
25 // Filters keypress.
26 // Returns true if the keypress is recognized as a part of composition
27 // sequence.
28 // Fabricated events which don't have the native event, are not supported.
29 bool FilterKeyPress(const ui::KeyEvent& event);
31 // Returns a string consisting of composed character.
32 // Empty string is returned when there is no composition result.
33 const base::string16& composed_character() const {
34 return composed_character_;
37 // Returns the preedit string.
38 const base::string16& preedit_string() const { return preedit_string_; }
40 private:
41 friend class CharacterComposerTest;
43 // An enum to describe composition mode.
44 enum CompositionMode {
45 // This is the initial state.
46 // Composite a character with dead-keys and compose-key.
47 KEY_SEQUENCE_MODE,
48 // Composite a character with a hexadecimal unicode sequence.
49 HEX_MODE,
52 // Filters keypress using IBus defined value.
53 // Returns true if the keypress is recognized as a part of composition
54 // sequence.
55 // |keyval| must be a GDK_KEY_* constant.
56 // |keycode| must be a X key code.
57 // |flags| must be a combination of ui::EF_* flags.
59 // composed_character() returns non empty string when there is a character
60 // composed after this method returns true.
61 // preedit_string() returns non empty string when there is a preedit string
62 // after this method returns true.
63 // Return values of preedit_string() is empty after this method returns false.
64 // composed_character() may have some characters which are consumed in this
65 // composing session.
68 // TODO(nona): Actually a X KeySym is passed to |keyval|, so we should use
69 // XK_* rather than GDK_KEY_*.
70 bool FilterKeyPressInternal(unsigned int keyval, unsigned int keycode,
71 int flags);
73 // Filters keypress in key sequence mode.
74 bool FilterKeyPressSequenceMode(unsigned int keyval, int flags);
76 // Filters keypress in hexadecimal mode.
77 bool FilterKeyPressHexMode(unsigned int keyval, unsigned int keycode,
78 int flags);
80 // Commit a character composed from hexadecimal uncode sequence
81 void CommitHex();
83 // Updates preedit string in hexadecimal mode.
84 void UpdatePreeditStringHexMode();
86 // Remembers keypresses previously filtered.
87 std::vector<unsigned int> compose_buffer_;
89 // A string representing the composed character.
90 base::string16 composed_character_;
92 // Preedit string.
93 base::string16 preedit_string_;
95 // Composition mode which this instance is in.
96 CompositionMode composition_mode_;
98 DISALLOW_COPY_AND_ASSIGN(CharacterComposer);
101 } // namespace ui
103 #endif // UI_BASE_IME_CHROMEOS_CHARACTER_COMPOSER_H_