Chromium Code Reviews| Index: examples/keyboard_client/keyboard_client.cc |
| diff --git a/examples/keyboard_client/keyboard_client.cc b/examples/keyboard_client/keyboard_client.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fa576ae049b580b4d06b8f467d2d5fb5788f949a |
| --- /dev/null |
| +++ b/examples/keyboard_client/keyboard_client.cc |
| @@ -0,0 +1,61 @@ |
| +// 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 "base/logging.h" |
| +#include "mojo/public/c/system/main.h" |
| +#include "mojo/public/cpp/application/application_delegate.h" |
| +#include "mojo/public/cpp/application/application_impl.h" |
| +#include "mojo/public/cpp/application/application_runner.h" |
| +#include "mojo/public/cpp/utility/run_loop.h" |
| +#include "mojo/services/keyboard/public/interfaces/keyboard.mojom.h" |
| + |
| +namespace examples { |
| + |
| +class KeyboardDelegate : public mojo::ApplicationDelegate, |
| + public keyboard::KeyboardClient { |
| + public: |
| + KeyboardDelegate() : binding_(this) {} |
|
jamesr
2015/05/08 23:45:23
whenever you have a type with a vtable (i.e. inher
APW
2015/05/09 00:45:58
Done.
|
| + |
| + // mojo::ApplicationDelegate implementation. |
| + void Initialize(mojo::ApplicationImpl* app) override { |
| + app->ConnectToService("mojo:keyboard_native", &keyboard_); |
| + keyboard_->ShowByRequest(); |
| + keyboard_->Hide(); |
| + |
| + mojo::InterfaceRequest<keyboard::KeyboardClient> request = |
| + mojo::GetProxy(&keyboardClient_); |
|
jamesr
2015/05/08 23:45:23
i think you still want keyboardClient_ to be a loc
APW
2015/05/09 00:45:58
Done.
|
| + binding_.Bind(request.Pass()); |
| + keyboard_->Show(keyboardClient_.Pass()); |
| + } |
| + |
| + // keyboard::KeyboardClient implementation. |
| + void CommitCompletion(keyboard::CompletionDataPtr completion) override {} |
| + |
| + void CommitCorrection(keyboard::CorrectionDataPtr correction) override {} |
| + |
| + void CommitText(const mojo::String& text, |
| + int32_t newCursorPosition) override {} |
|
jamesr
2015/05/08 23:45:23
by convention we use hacker_style_for_names in c++
APW
2015/05/09 00:45:58
Done.
|
| + |
| + void DeleteSurroundingText(int32_t beforeLength, |
| + int32_t afterLength) override {} |
| + |
| + void SetComposingRegion(int32_t start, int32_t end) override {} |
| + |
| + void SetComposingText(const mojo::String& text, |
| + int32_t newCursorPosition) override {} |
| + |
| + void SetSelection(int32_t start, int32_t end) override {} |
| + |
| + private: |
| + mojo::Binding<keyboard::KeyboardClient> binding_; |
| + keyboard::KeyboardServicePtr keyboard_; |
| + keyboard::KeyboardClientPtr keyboardClient_; |
| +}; |
|
jamesr
2015/05/08 23:45:23
add DISALLOW_COPY_AND_ASSIGN(KeyboardDelegate) to
APW
2015/05/09 00:45:58
Done.
|
| + |
| +} // namespace examples |
| + |
| +MojoResult MojoMain(MojoHandle application_request) { |
| + mojo::ApplicationRunner runner(new examples::KeyboardDelegate); |
| + return runner.Run(application_request); |
| +} |