OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "mojo/examples/keyboard/keyboard.mojom.h" | 8 #include "mojo/examples/keyboard/keyboard.mojom.h" |
9 #include "mojo/examples/keyboard/keyboard_delegate.h" | 9 #include "mojo/examples/keyboard/keyboard_delegate.h" |
10 #include "mojo/examples/keyboard/keyboard_view.h" | 10 #include "mojo/examples/keyboard/keyboard_view.h" |
11 #include "mojo/public/c/system/main.h" | 11 #include "mojo/public/c/system/main.h" |
12 #include "mojo/public/cpp/application/application_connection.h" | 12 #include "mojo/public/cpp/application/application_connection.h" |
13 #include "mojo/public/cpp/application/application_delegate.h" | 13 #include "mojo/public/cpp/application/application_delegate.h" |
| 14 #include "mojo/public/cpp/application/application_impl.h" |
14 #include "mojo/public/cpp/application/application_runner_chromium.h" | 15 #include "mojo/public/cpp/application/application_runner_chromium.h" |
15 #include "mojo/public/cpp/application/interface_factory_impl.h" | 16 #include "mojo/public/cpp/application/interface_factory_impl.h" |
16 #include "mojo/services/public/cpp/view_manager/view.h" | 17 #include "mojo/services/public/cpp/view_manager/view.h" |
17 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
18 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | 19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
20 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 21 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
21 #include "mojo/views/native_widget_view_manager.h" | 22 #include "mojo/views/native_widget_view_manager.h" |
22 #include "mojo/views/views_init.h" | 23 #include "mojo/views/views_init.h" |
23 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
(...skipping 21 matching lines...) Expand all Loading... |
45 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); | 46 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); |
46 }; | 47 }; |
47 | 48 |
48 class Keyboard : public ApplicationDelegate, | 49 class Keyboard : public ApplicationDelegate, |
49 public ViewManagerDelegate, | 50 public ViewManagerDelegate, |
50 public KeyboardDelegate { | 51 public KeyboardDelegate { |
51 public: | 52 public: |
52 Keyboard() | 53 Keyboard() |
53 : keyboard_service_factory_(this), | 54 : keyboard_service_factory_(this), |
54 view_manager_(NULL), | 55 view_manager_(NULL), |
55 view_manager_client_factory_(this), | |
56 keyboard_service_(NULL), | 56 keyboard_service_(NULL), |
57 target_(0) {} | 57 target_(0) {} |
58 | 58 |
59 virtual ~Keyboard() { | 59 virtual ~Keyboard() { |
60 } | 60 } |
61 | 61 |
62 void set_target(Id id) { target_ = id; } | 62 void set_target(Id id) { target_ = id; } |
63 | 63 |
64 void set_keyboard_service(KeyboardServiceImpl* keyboard) { | 64 void set_keyboard_service(KeyboardServiceImpl* keyboard) { |
65 keyboard_service_ = keyboard; | 65 keyboard_service_ = keyboard; |
66 } | 66 } |
67 | 67 |
68 private: | 68 private: |
69 // Overridden from ApplicationDelegate: | 69 // Overridden from ApplicationDelegate: |
| 70 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { |
| 71 view_manager_client_factory_.reset( |
| 72 new ViewManagerClientFactory(app->shell(), this)); |
| 73 } |
| 74 |
70 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 75 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
71 MOJO_OVERRIDE { | 76 MOJO_OVERRIDE { |
72 views_init_.reset(new ViewsInit); | 77 views_init_.reset(new ViewsInit); |
73 connection->AddService(&view_manager_client_factory_); | 78 connection->AddService(view_manager_client_factory_.get()); |
74 connection->AddService(&keyboard_service_factory_); | 79 connection->AddService(&keyboard_service_factory_); |
75 return true; | 80 return true; |
76 } | 81 } |
77 | 82 |
78 void CreateWidget(View* view) { | 83 void CreateWidget(View* view) { |
79 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; | 84 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; |
80 widget_delegate->GetContentsView()->AddChildView(new KeyboardView(this)); | 85 widget_delegate->GetContentsView()->AddChildView(new KeyboardView(this)); |
81 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout); | 86 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout); |
82 | 87 |
83 views::Widget* widget = new views::Widget; | 88 views::Widget* widget = new views::Widget; |
(...skipping 29 matching lines...) Expand all Loading... |
113 keyboard_service_->client()->OnKeyboardEvent(target_, key_code, | 118 keyboard_service_->client()->OnKeyboardEvent(target_, key_code, |
114 event_flags); | 119 event_flags); |
115 } | 120 } |
116 | 121 |
117 InterfaceFactoryImplWithContext<KeyboardServiceImpl, Keyboard> | 122 InterfaceFactoryImplWithContext<KeyboardServiceImpl, Keyboard> |
118 keyboard_service_factory_; | 123 keyboard_service_factory_; |
119 | 124 |
120 scoped_ptr<ViewsInit> views_init_; | 125 scoped_ptr<ViewsInit> views_init_; |
121 | 126 |
122 ViewManager* view_manager_; | 127 ViewManager* view_manager_; |
123 ViewManagerClientFactory view_manager_client_factory_; | 128 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
124 | 129 |
125 KeyboardServiceImpl* keyboard_service_; | 130 KeyboardServiceImpl* keyboard_service_; |
126 | 131 |
127 Id target_; | 132 Id target_; |
128 | 133 |
129 DISALLOW_COPY_AND_ASSIGN(Keyboard); | 134 DISALLOW_COPY_AND_ASSIGN(Keyboard); |
130 }; | 135 }; |
131 | 136 |
132 KeyboardServiceImpl::KeyboardServiceImpl(Keyboard* keyboard) | 137 KeyboardServiceImpl::KeyboardServiceImpl(Keyboard* keyboard) |
133 : keyboard_(keyboard) { | 138 : keyboard_(keyboard) { |
134 keyboard_->set_keyboard_service(this); | 139 keyboard_->set_keyboard_service(this); |
135 } | 140 } |
136 | 141 |
137 void KeyboardServiceImpl::SetTarget(uint32_t view_id) { | 142 void KeyboardServiceImpl::SetTarget(uint32_t view_id) { |
138 keyboard_->set_target(view_id); | 143 keyboard_->set_target(view_id); |
139 } | 144 } |
140 | 145 |
141 } // namespace examples | 146 } // namespace examples |
142 } // namespace mojo | 147 } // namespace mojo |
143 | 148 |
144 MojoResult MojoMain(MojoHandle shell_handle) { | 149 MojoResult MojoMain(MojoHandle shell_handle) { |
145 mojo::ApplicationRunnerChromium runner(new mojo::examples::Keyboard); | 150 mojo::ApplicationRunnerChromium runner(new mojo::examples::Keyboard); |
146 return runner.Run(shell_handle); | 151 return runner.Run(shell_handle); |
147 } | 152 } |
OLD | NEW |