Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: chromeos_input_method.cc

Issue 6880171: Add two libcros interfaces for handwriting: SendHandwritingStrokes and CancelHandwriting. (Closed) Base URL: ssh://gitrw.chromium.org:9222/cros.git@master
Patch Set: style fix; changed the function name following zork's suggestion Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos_input_method.h ('k') | load.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2011 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
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 SendHandwritingStroke(const HandwritingStroke& stroke) {
656 if (stroke.size() < 2) {
657 LOG(WARNING) << "Empty stroke data or a single dot is passed.";
658 return;
659 }
660
661 IBusInputContext* context = GetInputContext(input_context_path_, ibus_);
662 if (!context) {
663 return;
664 }
665
666 const size_t raw_stroke_size = stroke.size() * 2;
667 scoped_array<double> raw_stroke(new double[raw_stroke_size]);
668 for (size_t n = 0; n < stroke.size(); ++n) {
669 raw_stroke[n * 2] = stroke[n].first; // x
670 raw_stroke[n * 2 + 1] = stroke[n].second; // y
671 }
672 ibus_input_context_process_hand_writing_event(
673 context, raw_stroke.get(), raw_stroke_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
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 ChromeOSSendHandwritingStroke(InputMethodStatusConnection* connection,
1218 const HandwritingStroke& stroke) {
1219 g_return_if_fail(connection);
1220 connection->SendHandwritingStroke(stroke);
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
OLDNEW
« no previous file with comments | « chromeos_input_method.h ('k') | load.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698