Chromium Code Reviews| Index: chromeos_input_method.cc |
| diff --git a/chromeos_input_method.cc b/chromeos_input_method.cc |
| index 132ff0fc14ffd9090350aff1102791fd1fa4338b..009df5bed8fa1ab5f5f0c8b9ec7db52fffa85757 100644 |
| --- a/chromeos_input_method.cc |
| +++ b/chromeos_input_method.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| +// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -18,6 +18,7 @@ |
| #include <stack> |
| #include <utility> |
| +#include "base/scoped_ptr.h" |
| #include "base/singleton.h" |
| #include "chromeos/string.h" // for chromeos::SplitStringUsing. |
| #include "ibus_input_methods.h" |
| @@ -651,6 +652,37 @@ class InputMethodStatusConnection { |
| return true; |
| } |
| + void SendHandwritingStrokes(const HandwritingStrokes& strokes) { |
| + if (strokes.size() < 2) { |
| + LOG(WARNING) << "Empty stroke data or a single dot is passed."; |
| + return; |
| + } |
| + |
| + IBusInputContext* context = GetInputContext(input_context_path_, ibus_); |
| + if (!context) { |
| + return; |
| + } |
| + |
| + const size_t raw_strokes_size = strokes.size() * 2; |
|
Peng
2011/04/27 14:23:11
Maybe we could use ((double*)&strokes[0]) and avoi
Yusuke Sato
2011/05/02 05:22:26
I know it's safe to use the internal buffer of std
Peng
2011/05/02 14:11:47
Yeah. It needs change pair to double or double[2]
|
| + scoped_array<double> raw_strokes(new double[raw_strokes_size]); |
| + for (size_t n = 0; n < strokes.size(); ++n) { |
| + raw_strokes[n * 2] = strokes[n].first; // x |
| + raw_strokes[n * 2 + 1] = strokes[n].second; // y |
| + } |
| + ibus_input_context_process_hand_writing_event( |
| + context, raw_strokes.get(), raw_strokes_size); |
| + g_object_unref(context); |
| + } |
| + |
| + void CancelHandwriting(int n_strokes) { |
| + IBusInputContext* context = GetInputContext(input_context_path_, ibus_); |
| + if (!context) { |
| + return; |
| + } |
| + ibus_input_context_cancel_hand_writing(context, n_strokes); |
| + g_object_unref(context); |
| + } |
| + |
| private: |
| friend struct DefaultSingletonTraits<InputMethodStatusConnection>; |
| InputMethodStatusConnection() |
| @@ -1181,4 +1213,18 @@ std::string ChromeOSGetKeyboardOverlayId(const std::string& input_method_id) { |
| return ""; |
| } |
| +extern "C" |
| +void ChromeOSSendHandwritingStrokes(InputMethodStatusConnection* connection, |
| + const HandwritingStrokes& strokes) { |
| + g_return_if_fail(connection); |
| + connection->SendHandwritingStrokes(strokes); |
| +} |
| + |
| +extern "C" |
| +void ChromeOSCancelHandwriting(InputMethodStatusConnection* connection, |
| + int n_strokes) { |
| + g_return_if_fail(connection); |
| + connection->CancelHandwriting(n_strokes); |
| +} |
| + |
| } // namespace chromeos |