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

Unified Diff: services/keyboard/linux/keyboard_service_impl.cc

Issue 1453823005: Implement Linux IME support (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add service name annotation, remove unused member variables Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/keyboard/linux/keyboard_service_impl.h ('k') | services/keyboard/linux/main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/keyboard/linux/keyboard_service_impl.cc
diff --git a/services/keyboard/linux/keyboard_service_impl.cc b/services/keyboard/linux/keyboard_service_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f8b6afc2253cbde1070f18d377e0c7bc7a158870
--- /dev/null
+++ b/services/keyboard/linux/keyboard_service_impl.cc
@@ -0,0 +1,86 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/keyboard/linux/keyboard_service_impl.h"
+
+#include "base/logging.h"
+#include "base/strings/string16.h"
+#include "base/strings/utf_string_conversions.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/connect.h"
+#include "mojo/services/input_events/interfaces/input_key_codes.mojom.h"
+
+namespace keyboard {
+
+LinuxKeyboardServiceImpl::LinuxKeyboardServiceImpl(
+ mojo::InterfaceRequest<keyboard::KeyboardService> request,
+ mojo::InterfaceRequest<NativeViewportEventDispatcher> dispatcher)
+ : event_dispatcher_binding_(this, dispatcher.Pass()),
+ binding_(this, request.Pass()) {
+}
+
+LinuxKeyboardServiceImpl::~LinuxKeyboardServiceImpl() {
+}
+
+void LinuxKeyboardServiceImpl::Show(
+ keyboard::KeyboardClientPtr client,
+ keyboard::KeyboardType type) {
+ client_ = client.Pass();
+}
+
+void LinuxKeyboardServiceImpl::ShowByRequest() {
+}
+
+void LinuxKeyboardServiceImpl::Hide() {
+ client_ = nullptr;
+}
+
+void LinuxKeyboardServiceImpl::SetText(const mojo::String& text) {
+ text_ = text;
+}
+
+void LinuxKeyboardServiceImpl::SetSelection(int32_t start, int32_t end) {
+ // Not applicable for physical keyboards
+}
+
+// |mojo::NativeViewportEventDispatcher| implementation:
+void LinuxKeyboardServiceImpl::OnEvent(
+ mojo::EventPtr event,
+ const OnEventCallback& callback) {
+ if (event->action == mojo::EventType::KEY_PRESSED &&
+ event->key_data->is_char) {
+ if (client_) {
+ switch(event->key_data->windows_key_code) {
+ case mojo::KeyboardCode::BACK: // backspace
+ client_->DeleteSurroundingText(1, 0);
+ break;
+ case mojo::KeyboardCode::DELETE:
+ client_->DeleteSurroundingText(0, 1);
+ break;
+ case mojo::KeyboardCode::HOME:
+ client_->SetSelection(0, 0);
+ break;
+ case mojo::KeyboardCode::END:
+ client_->SetSelection(text_.size()-1, text_.size()-1);
+ break;
+ case mojo::KeyboardCode::TAB:
+ // TODO: Advance focus, in reverse if shifted
+ break;
+ case mojo::KeyboardCode::RETURN:
+ client_->Submit(keyboard::SubmitAction::DONE);
+ break;
+ default:
+ base::string16 character;
+ character.push_back(event->key_data->character);
+ std::string s = base::UTF16ToUTF8(character);
+ text_ += s;
+ client_->CommitText(mojo::String(s), 1);
+ break;
+ }
+ }
+ }
+ callback.Run();
+}
+
+} // namespace keyboard
« no previous file with comments | « services/keyboard/linux/keyboard_service_impl.h ('k') | services/keyboard/linux/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698