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

Side by Side Diff: examples/keyboard/keyboard.cc

Issue 840923002: Remove the keyboard from the browser demo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « examples/keyboard/BUILD.gn ('k') | examples/keyboard/keyboard.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 "base/macros.h"
6 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "examples/keyboard/keyboard.mojom.h"
9 #include "examples/keyboard/keyboard_delegate.h"
10 #include "examples/keyboard/keyboard_view.h"
11 #include "mojo/application/application_runner_chromium.h"
12 #include "mojo/public/c/system/main.h"
13 #include "mojo/public/cpp/application/application_connection.h"
14 #include "mojo/public/cpp/application/application_delegate.h"
15 #include "mojo/public/cpp/application/application_impl.h"
16 #include "mojo/public/cpp/application/interface_factory_impl.h"
17 #include "mojo/services/navigation/public/interfaces/navigation.mojom.h"
18 #include "mojo/services/view_manager/public/cpp/view.h"
19 #include "mojo/services/view_manager/public/cpp/view_manager.h"
20 #include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h"
21 #include "mojo/services/view_manager/public/cpp/view_manager_delegate.h"
22 #include "mojo/views/native_widget_view_manager.h"
23 #include "mojo/views/views_init.h"
24 #include "ui/events/event.h"
25 #include "ui/views/layout/fill_layout.h"
26 #include "ui/views/widget/widget.h"
27 #include "ui/views/widget/widget_delegate.h"
28 #include "url/gurl.h"
29
30 namespace mojo {
31 namespace examples {
32
33 class Keyboard;
34
35 class KeyboardServiceImpl : public InterfaceImpl<KeyboardService> {
36 public:
37 explicit KeyboardServiceImpl(Keyboard* keyboard);
38 virtual ~KeyboardServiceImpl() {}
39
40 // KeyboardService:
41 virtual void SetTarget(uint32_t view_id) override;
42
43 private:
44 Keyboard* keyboard_;
45
46 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl);
47 };
48
49 class Keyboard : public ApplicationDelegate,
50 public ViewManagerDelegate,
51 public KeyboardDelegate {
52 public:
53 Keyboard()
54 : shell_(nullptr),
55 keyboard_service_factory_(this),
56 keyboard_service_(NULL),
57 target_(0) {}
58
59 virtual ~Keyboard() {
60 }
61
62 void set_target(Id id) { target_ = id; }
63
64 void set_keyboard_service(KeyboardServiceImpl* keyboard) {
65 keyboard_service_ = keyboard;
66 }
67
68 private:
69 // Overridden from ApplicationDelegate:
70 virtual void Initialize(ApplicationImpl* app) override {
71 shell_ = app->shell();
72 view_manager_client_factory_.reset(
73 new ViewManagerClientFactory(shell_, this));
74 }
75
76 virtual bool ConfigureIncomingConnection(
77 ApplicationConnection* connection) override {
78 views_init_.reset(new ViewsInit);
79 connection->AddService(view_manager_client_factory_.get());
80 connection->AddService(&keyboard_service_factory_);
81 return true;
82 }
83
84 void CreateWidget(View* view) {
85 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
86 widget_delegate->GetContentsView()->AddChildView(new KeyboardView(this));
87 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout);
88
89 views::Widget* widget = new views::Widget;
90 views::Widget::InitParams params(
91 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
92 params.native_widget = new NativeWidgetViewManager(widget, shell_, view);
93 params.delegate = widget_delegate;
94 params.bounds = gfx::Rect(view->bounds().width, view->bounds().height);
95 widget->Init(params);
96 widget->Show();
97 }
98
99 // ViewManagerDelegate:
100 virtual void OnEmbed(View* root,
101 ServiceProviderImpl* exported_services,
102 scoped_ptr<ServiceProvider> imported_services) override {
103 // TODO: deal with OnEmbed() being invoked multiple times.
104 CreateWidget(root);
105 }
106 virtual void OnViewManagerDisconnected(
107 ViewManager* view_manager) override {
108 base::MessageLoop::current()->Quit();
109 }
110
111 // KeyboardDelegate:
112 virtual void OnKeyPressed(int key_code, int event_flags) override {
113 if (!target_)
114 return;
115 keyboard_service_->client()->OnKeyboardEvent(target_, key_code,
116 event_flags);
117 }
118
119 Shell* shell_;
120
121 InterfaceFactoryImplWithContext<KeyboardServiceImpl, Keyboard>
122 keyboard_service_factory_;
123
124 scoped_ptr<ViewsInit> views_init_;
125
126 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
127
128 KeyboardServiceImpl* keyboard_service_;
129
130 Id target_;
131
132 DISALLOW_COPY_AND_ASSIGN(Keyboard);
133 };
134
135 KeyboardServiceImpl::KeyboardServiceImpl(Keyboard* keyboard)
136 : keyboard_(keyboard) {
137 keyboard_->set_keyboard_service(this);
138 }
139
140 void KeyboardServiceImpl::SetTarget(uint32_t view_id) {
141 keyboard_->set_target(view_id);
142 }
143
144 } // namespace examples
145 } // namespace mojo
146
147 MojoResult MojoMain(MojoHandle shell_handle) {
148 mojo::ApplicationRunnerChromium runner(new mojo::examples::Keyboard);
149 return runner.Run(shell_handle);
150 }
OLDNEW
« no previous file with comments | « examples/keyboard/BUILD.gn ('k') | examples/keyboard/keyboard.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698