OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 #include "chromeos_input_method.h" | 5 #include "chromeos_input_method.h" |
6 | 6 |
7 #include "chromeos_input_method_ui.h" | 7 #include "chromeos_input_method_ui.h" |
8 #include "chromeos_input_method_whitelist.h" | 8 #include "chromeos_input_method_whitelist.h" |
9 #include "chromeos_keyboard_overlay_map.h" | 9 #include "chromeos_keyboard_overlay_map.h" |
10 | 10 |
11 #include <ibus.h> | 11 #include <ibus.h> |
12 | 12 |
13 #include <algorithm> // for std::reverse. | 13 #include <algorithm> // for std::reverse. |
14 #include <cstdio> | 14 #include <cstdio> |
15 #include <cstring> // for std::strcmp. | 15 #include <cstring> // for std::strcmp. |
16 #include <set> | 16 #include <set> |
17 #include <sstream> | 17 #include <sstream> |
18 #include <stack> | 18 #include <stack> |
19 #include <utility> | 19 #include <utility> |
20 | 20 |
21 #include "base/scoped_ptr.h" | |
21 #include "base/singleton.h" | 22 #include "base/singleton.h" |
22 #include "chromeos/string.h" // for chromeos::SplitStringUsing. | 23 #include "chromeos/string.h" // for chromeos::SplitStringUsing. |
23 #include "ibus_input_methods.h" | 24 #include "ibus_input_methods.h" |
24 | 25 |
25 namespace chromeos { | 26 namespace chromeos { |
26 | 27 |
27 // Returns true if |input_method_id| is whitelisted. | 28 // Returns true if |input_method_id| is whitelisted. |
28 bool InputMethodIdIsWhitelisted(const std::string& input_method_id) { | 29 bool InputMethodIdIsWhitelisted(const std::string& input_method_id) { |
29 static std::set<std::string>* g_supported_input_methods = NULL; | 30 static std::set<std::string>* g_supported_input_methods = NULL; |
30 if (!g_supported_input_methods) { | 31 if (!g_supported_input_methods) { |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 // Since |variant| is floating, ibus_config_set_value_async consumes | 645 // Since |variant| is floating, ibus_config_set_value_async consumes |
645 // (takes ownership of) the variable. | 646 // (takes ownership of) the variable. |
646 | 647 |
647 if (is_preload_engines) { | 648 if (is_preload_engines) { |
648 DLOG(INFO) << "SetImeConfig: " << section << "/" << config_name | 649 DLOG(INFO) << "SetImeConfig: " << section << "/" << config_name |
649 << ": " << value.ToString(); | 650 << ": " << value.ToString(); |
650 } | 651 } |
651 return true; | 652 return true; |
652 } | 653 } |
653 | 654 |
655 void SendHandwritingStrokes(const HandwritingStrokes& strokes) { | |
656 if (strokes.size() < 2) { | |
657 LOG(WARNING) << "Empty stroke data or a single dot is passed."; | |
Zachary Kuznia
2011/04/27 09:45:46
I think VLOG is preferred now.
Yusuke Sato
2011/04/27 10:10:33
It seems that VLOG is not supported in the logging
| |
658 return; | |
659 } | |
660 | |
661 IBusInputContext* context = GetInputContext(input_context_path_, ibus_); | |
662 if (!context) { | |
663 return; | |
664 } | |
665 | |
666 const size_t raw_strokes_size = strokes.size() * 2; | |
667 scoped_array<double> raw_strokes(new double[raw_strokes_size]); | |
668 for (size_t n = 0; n < strokes.size(); ++n) { | |
669 raw_strokes[n * 2] = strokes[n].first; // x | |
670 raw_strokes[n * 2 + 1] = strokes[n].second; // y | |
671 } | |
672 ibus_input_context_process_hand_writing_event( | |
673 context, raw_strokes.get(), raw_strokes_size); | |
674 g_object_unref(context); | |
675 } | |
676 | |
677 void CancelHandwriting(int n_strokes) { | |
678 IBusInputContext* context = GetInputContext(input_context_path_, ibus_); | |
679 if (!context) { | |
680 return; | |
681 } | |
682 ibus_input_context_cancel_hand_writing(context, n_strokes); | |
683 g_object_unref(context); | |
684 } | |
685 | |
654 private: | 686 private: |
655 friend struct DefaultSingletonTraits<InputMethodStatusConnection>; | 687 friend struct DefaultSingletonTraits<InputMethodStatusConnection>; |
656 InputMethodStatusConnection() | 688 InputMethodStatusConnection() |
657 : current_input_method_changed_(NULL), | 689 : current_input_method_changed_(NULL), |
658 register_ime_properties_(NULL), | 690 register_ime_properties_(NULL), |
659 update_ime_property_(NULL), | 691 update_ime_property_(NULL), |
660 connection_change_handler_(NULL), | 692 connection_change_handler_(NULL), |
661 language_library_(NULL), | 693 language_library_(NULL), |
662 ibus_(NULL), | 694 ibus_(NULL), |
663 ibus_config_(NULL) { | 695 ibus_config_(NULL) { |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 extern "C" | 1206 extern "C" |
1175 std::string ChromeOSGetKeyboardOverlayId(const std::string& input_method_id) { | 1207 std::string ChromeOSGetKeyboardOverlayId(const std::string& input_method_id) { |
1176 for (size_t i = 0; i < arraysize(kKeyboardOverlayMap); ++i) { | 1208 for (size_t i = 0; i < arraysize(kKeyboardOverlayMap); ++i) { |
1177 if (kKeyboardOverlayMap[i].input_method_id == input_method_id) { | 1209 if (kKeyboardOverlayMap[i].input_method_id == input_method_id) { |
1178 return kKeyboardOverlayMap[i].keyboard_overlay_id; | 1210 return kKeyboardOverlayMap[i].keyboard_overlay_id; |
1179 } | 1211 } |
1180 } | 1212 } |
1181 return ""; | 1213 return ""; |
1182 } | 1214 } |
1183 | 1215 |
1216 extern "C" | |
1217 void ChromeOSSendHandwritingStrokes(InputMethodStatusConnection* connection, | |
1218 const HandwritingStrokes& strokes) { | |
1219 g_return_if_fail(connection); | |
1220 connection->SendHandwritingStrokes(strokes); | |
1221 } | |
1222 | |
1223 extern "C" | |
1224 void ChromeOSCancelHandwriting(InputMethodStatusConnection* connection, | |
1225 int n_strokes) { | |
1226 g_return_if_fail(connection); | |
1227 connection->CancelHandwriting(n_strokes); | |
1228 } | |
1229 | |
1184 } // namespace chromeos | 1230 } // namespace chromeos |
OLD | NEW |