| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_BASE_IME_CHARACTER_COMPOSER_H_ | 5 #ifndef UI_BASE_IME_CHARACTER_COMPOSER_H_ |
| 6 #define UI_BASE_IME_CHARACTER_COMPOSER_H_ | 6 #define UI_BASE_IME_CHARACTER_COMPOSER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "ui/base/ui_export.h" | 11 #include "ui/base/ui_export.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 // A class to recognize compose and dead key sequence. | 15 // A class to recognize compose and dead key sequence. |
| 16 // Outputs composed character. | 16 // Outputs composed character. |
| 17 // | |
| 18 // TODO(hashimoto): support unicode character composition starting with | |
| 19 // Ctrl-Shift-U. http://crosbug.com/15925 | |
| 20 class UI_EXPORT CharacterComposer { | 17 class UI_EXPORT CharacterComposer { |
| 21 public: | 18 public: |
| 22 CharacterComposer(); | 19 CharacterComposer(); |
| 23 ~CharacterComposer(); | 20 ~CharacterComposer(); |
| 24 | 21 |
| 25 void Reset(); | 22 void Reset(); |
| 26 | 23 |
| 27 // Filters keypress. | 24 // Filters keypress. |
| 28 // Returns true if the keypress is recognized as a part of composition | 25 // Returns true if the keypress is recognized as a part of composition |
| 29 // sequence. | 26 // sequence. |
| 30 // |keyval| must be a GDK_KEY_* constants. | 27 // |keyval| must be a GDK_KEY_* constant. |
| 28 // |keycode| must be a X key code. |
| 31 // |flags| must be a combination of ui::EF_* flags. | 29 // |flags| must be a combination of ui::EF_* flags. |
| 32 // | 30 // |
| 33 // composed_character() returns non empty string when there is a character | 31 // composed_character() returns non empty string when there is a character |
| 34 // composed after this method returns true. | 32 // composed after this method returns true. |
| 35 // preedit_string() returns non empty string when there is a preedit string | 33 // preedit_string() returns non empty string when there is a preedit string |
| 36 // after this method returns true. | 34 // after this method returns true. |
| 37 // Return values of composed_character() and preedit_string() are empty after | 35 // Return values of composed_character() and preedit_string() are empty after |
| 38 // this method returns false. | 36 // this method returns false. |
| 39 bool FilterKeyPress(unsigned int keyval, unsigned int flags); | 37 bool FilterKeyPress(unsigned int keyval, unsigned int keycode, int flags); |
| 40 | 38 |
| 41 // Returns a string consisting of composed character. | 39 // Returns a string consisting of composed character. |
| 42 // Empty string is returned when there is no composition result. | 40 // Empty string is returned when there is no composition result. |
| 43 const string16& composed_character() const { return composed_character_; } | 41 const string16& composed_character() const { return composed_character_; } |
| 44 | 42 |
| 45 // Returns the preedit string. | 43 // Returns the preedit string. |
| 46 const string16& preedit_string() const { return preedit_string_; } | 44 const string16& preedit_string() const { return preedit_string_; } |
| 47 | 45 |
| 48 private: | 46 private: |
| 49 // An enum to describe composition mode. | 47 // An enum to describe composition mode. |
| 50 enum CompositionMode { | 48 enum CompositionMode { |
| 51 // This is the initial state. | 49 // This is the initial state. |
| 52 // Composite a character with dead-keys and compose-key. | 50 // Composite a character with dead-keys and compose-key. |
| 53 KEY_SEQUENCE_MODE, | 51 KEY_SEQUENCE_MODE, |
| 54 // Composite a character with a hexadecimal unicode sequence. | 52 // Composite a character with a hexadecimal unicode sequence. |
| 55 HEX_MODE, | 53 HEX_MODE, |
| 56 }; | 54 }; |
| 57 | 55 |
| 58 // Filters keypress in key sequence mode. | 56 // Filters keypress in key sequence mode. |
| 59 bool FilterKeyPressSequenceMode(unsigned int keyval, unsigned int flags); | 57 bool FilterKeyPressSequenceMode(unsigned int keyval, unsigned int keycode, |
| 58 int flags); |
| 60 | 59 |
| 61 // Filters keypress in hexadecimal mode. | 60 // Filters keypress in hexadecimal mode. |
| 62 bool FilterKeyPressHexMode(unsigned int keyval, unsigned int flags); | 61 bool FilterKeyPressHexMode(unsigned int keyval, unsigned int keycode, |
| 62 int flags); |
| 63 | 63 |
| 64 // Commit a character composed from hexadecimal uncode sequence | 64 // Commit a character composed from hexadecimal uncode sequence |
| 65 void CommitHex(); | 65 void CommitHex(); |
| 66 | 66 |
| 67 // Updates preedit string in hexadecimal mode. | 67 // Updates preedit string in hexadecimal mode. |
| 68 void UpdatePreeditStringHexMode(); | 68 void UpdatePreeditStringHexMode(); |
| 69 | 69 |
| 70 // Remembers keypresses previously filtered. | 70 // Remembers keypresses previously filtered. |
| 71 std::vector<unsigned int> compose_buffer_; | 71 std::vector<unsigned int> compose_buffer_; |
| 72 | 72 |
| 73 // A string representing the composed character. | 73 // A string representing the composed character. |
| 74 string16 composed_character_; | 74 string16 composed_character_; |
| 75 | 75 |
| 76 // Preedit string. | 76 // Preedit string. |
| 77 string16 preedit_string_; | 77 string16 preedit_string_; |
| 78 | 78 |
| 79 // Composition mode which this instance is in. | 79 // Composition mode which this instance is in. |
| 80 CompositionMode composition_mode_; | 80 CompositionMode composition_mode_; |
| 81 | 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(CharacterComposer); | 82 DISALLOW_COPY_AND_ASSIGN(CharacterComposer); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 } // namespace ui | 85 } // namespace ui |
| 86 | 86 |
| 87 #endif // UI_BASE_IME_CHARACTER_COMPOSER_H_ | 87 #endif // UI_BASE_IME_CHARACTER_COMPOSER_H_ |
| OLD | NEW |