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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "services/keyboard/linux/keyboard_service_impl.h"
6
7 #include "base/logging.h"
8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/connect.h"
12 #include "mojo/services/input_events/interfaces/input_key_codes.mojom.h"
13
14 namespace keyboard {
15
16 LinuxKeyboardServiceImpl::LinuxKeyboardServiceImpl(
17 mojo::InterfaceRequest<::keyboard::KeyboardService> request,
18 mojo::InterfaceRequest<NativeViewportEventDispatcher> dispatcher)
19 : binding_(this, request.Pass()),
20 event_dispatcher_binding_(this, dispatcher.Pass()) {
21 }
22
23 LinuxKeyboardServiceImpl::~LinuxKeyboardServiceImpl() {
24 }
25
26 void LinuxKeyboardServiceImpl::Show(
27 ::keyboard::KeyboardClientPtr client,
28 ::keyboard::KeyboardType type) {
29 client_ = client.Pass();
30 }
31
32 void LinuxKeyboardServiceImpl::ShowByRequest() {
33 }
34
35 void LinuxKeyboardServiceImpl::Hide() {
36 client_ = nullptr;
37 }
38
39 void LinuxKeyboardServiceImpl::SetText(const mojo::String& text) {
40 text_ = text;
41 }
42
43 void LinuxKeyboardServiceImpl::SetSelection(int32_t start, int32_t end) {
44 // Not applicable for physical keyboards
45 }
46
47 /*
jamesr 2015/11/19 23:47:33 don't check in commented out code
48 void commitCompletion(CompletionData completion);
49 void commitCorrection(CorrectionData correction);
50 void commitText(String text, int newCursorPosition);
51 void deleteSurroundingText(int beforeLength, int afterLength);
52 void setComposingRegion(int start, int end);
53 void setComposingText(String text, int newCursorPosition);
54 void setSelection(int start, int end);
55 void submit(SubmitAction action);
56 */
57
58 // |mojo::NativeViewportEventDispatcher| implementation:
59 void LinuxKeyboardServiceImpl::OnEvent(
60 mojo::EventPtr event,
61 const mojo::Callback<void()>& callback) {
62 if (event->action == mojo::EventType::KEY_PRESSED &&
63 event->key_data->is_char) {
64 if (client_) {
65 switch(event->key_data->windows_key_code) {
66 case mojo::KeyboardCode::BACK: // backspace
67 client_->DeleteSurroundingText(1, 0);
68 break;
69 case mojo::KeyboardCode::DELETE:
70 client_->DeleteSurroundingText(0, 1);
71 break;
72 case mojo::KeyboardCode::HOME:
73 client_->SetSelection(0, 0);
74 break;
75 case mojo::KeyboardCode::END:
76 client_->SetSelection(text_.size()-1, text_.size()-1);
77 break;
78 case mojo::KeyboardCode::TAB: // tab
jamesr 2015/11/19 23:47:33 nit: delete the "// tab" part
79 // TODO: Advance focus, in reverse if shifted
80 break;
81 case mojo::KeyboardCode::RETURN:
82 client_->Submit(::keyboard::SubmitAction::DONE);
jamesr 2015/11/19 23:47:33 omit :: in ::keyboard
83 break;
84 default:
85 base::string16 character;
86 character.push_back(event->key_data->character);
87 std::string s = base::UTF16ToUTF8(character);
jamesr 2015/11/19 23:47:33 there's gotta be a better way to do this, although
88 text_ += s;
89 client_->CommitText(mojo::String(s), 1);
90 break;
91 }
92 }
93 }
94 callback.Run();
95 }
96
97 } // namespace keyboard
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698