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/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
12 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
| 13 #include "mojo/public/cpp/application/interface_factory_with_context.h" |
13 #include "mojo/services/public/cpp/view_manager/node.h" | 14 #include "mojo/services/public/cpp/view_manager/node.h" |
14 #include "mojo/services/public/cpp/view_manager/view.h" | 15 #include "mojo/services/public/cpp/view_manager/view.h" |
15 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
16 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
17 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 19 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
18 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 20 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
19 #include "mojo/views/native_widget_view_manager.h" | 21 #include "mojo/views/native_widget_view_manager.h" |
20 #include "mojo/views/views_init.h" | 22 #include "mojo/views/views_init.h" |
21 #include "ui/events/event.h" | 23 #include "ui/events/event.h" |
22 #include "ui/views/layout/fill_layout.h" | 24 #include "ui/views/layout/fill_layout.h" |
23 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
24 #include "ui/views/widget/widget_delegate.h" | 26 #include "ui/views/widget/widget_delegate.h" |
25 #include "url/gurl.h" | 27 #include "url/gurl.h" |
26 | 28 |
27 using mojo::view_manager::Id; | 29 using mojo::view_manager::Id; |
28 | 30 |
29 namespace mojo { | 31 namespace mojo { |
30 namespace examples { | 32 namespace examples { |
31 | 33 |
32 class Keyboard; | 34 class Keyboard; |
33 | 35 |
34 class KeyboardServiceImpl : public InterfaceImpl<KeyboardService> { | 36 class KeyboardServiceImpl : public InterfaceImpl<KeyboardService> { |
35 public: | 37 public: |
36 KeyboardServiceImpl(ApplicationConnection* connection, Keyboard* keyboard); | 38 explicit KeyboardServiceImpl(Keyboard* keyboard); |
37 virtual ~KeyboardServiceImpl() {} | 39 virtual ~KeyboardServiceImpl() {} |
38 | 40 |
39 // KeyboardService: | 41 // KeyboardService: |
40 virtual void SetTarget(uint32_t node_id) OVERRIDE; | 42 virtual void SetTarget(uint32_t node_id) OVERRIDE; |
41 | 43 |
42 private: | 44 private: |
43 Keyboard* keyboard_; | 45 Keyboard* keyboard_; |
44 | 46 |
45 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); | 47 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); |
46 }; | 48 }; |
47 | 49 |
48 class Keyboard : public ApplicationDelegate, | 50 class Keyboard |
49 public view_manager::ViewManagerDelegate, | 51 : public ApplicationDelegate, |
50 public KeyboardDelegate { | 52 public view_manager::ViewManagerDelegate, |
| 53 public KeyboardDelegate, |
| 54 public InterfaceFactoryWithContext<KeyboardServiceImpl, Keyboard> { |
51 public: | 55 public: |
52 Keyboard() : view_manager_(NULL), keyboard_service_(NULL), target_(0) {} | 56 Keyboard() |
| 57 : InterfaceFactoryWithContext(this), |
| 58 view_manager_(NULL), |
| 59 view_manager_client_factory_(this), |
| 60 keyboard_service_(NULL), |
| 61 target_(0) {} |
53 | 62 |
54 virtual ~Keyboard() { | 63 virtual ~Keyboard() { |
55 } | 64 } |
56 | 65 |
57 void set_target(Id id) { target_ = id; } | 66 void set_target(Id id) { target_ = id; } |
58 | 67 |
59 void set_keyboard_service(KeyboardServiceImpl* keyboard) { | 68 void set_keyboard_service(KeyboardServiceImpl* keyboard) { |
60 keyboard_service_ = keyboard; | 69 keyboard_service_ = keyboard; |
61 } | 70 } |
62 | 71 |
63 private: | 72 private: |
64 // Overridden from ApplicationDelegate: | 73 // Overridden from ApplicationDelegate: |
65 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 74 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
66 MOJO_OVERRIDE { | 75 MOJO_OVERRIDE { |
67 views_init_.reset(new ViewsInit); | 76 views_init_.reset(new ViewsInit); |
68 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); | 77 connection->AddService(&view_manager_client_factory_); |
69 connection->AddService<KeyboardServiceImpl>(this); | 78 connection->AddService(this); |
70 return true; | 79 return true; |
71 } | 80 } |
72 | 81 |
73 void CreateWidget(view_manager::Node* node) { | 82 void CreateWidget(view_manager::Node* node) { |
74 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; | 83 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; |
75 widget_delegate->GetContentsView()->AddChildView(new KeyboardView(this)); | 84 widget_delegate->GetContentsView()->AddChildView(new KeyboardView(this)); |
76 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout); | 85 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout); |
77 | 86 |
78 views::Widget* widget = new views::Widget; | 87 views::Widget* widget = new views::Widget; |
79 views::Widget::InitParams params( | 88 views::Widget::InitParams params( |
(...skipping 24 matching lines...) Expand all Loading... |
104 virtual void OnKeyPressed(int key_code, int event_flags) OVERRIDE { | 113 virtual void OnKeyPressed(int key_code, int event_flags) OVERRIDE { |
105 if (!target_) | 114 if (!target_) |
106 return; | 115 return; |
107 keyboard_service_->client()->OnKeyboardEvent(target_, key_code, | 116 keyboard_service_->client()->OnKeyboardEvent(target_, key_code, |
108 event_flags); | 117 event_flags); |
109 } | 118 } |
110 | 119 |
111 scoped_ptr<ViewsInit> views_init_; | 120 scoped_ptr<ViewsInit> views_init_; |
112 | 121 |
113 view_manager::ViewManager* view_manager_; | 122 view_manager::ViewManager* view_manager_; |
| 123 view_manager::ViewManagerClientFactory view_manager_client_factory_; |
114 | 124 |
115 KeyboardServiceImpl* keyboard_service_; | 125 KeyboardServiceImpl* keyboard_service_; |
116 | 126 |
117 Id target_; | 127 Id target_; |
118 | 128 |
119 DISALLOW_COPY_AND_ASSIGN(Keyboard); | 129 DISALLOW_COPY_AND_ASSIGN(Keyboard); |
120 }; | 130 }; |
121 | 131 |
122 KeyboardServiceImpl::KeyboardServiceImpl(ApplicationConnection* connection, | 132 KeyboardServiceImpl::KeyboardServiceImpl(Keyboard* keyboard) |
123 Keyboard* keyboard) | |
124 : keyboard_(keyboard) { | 133 : keyboard_(keyboard) { |
125 keyboard_->set_keyboard_service(this); | 134 keyboard_->set_keyboard_service(this); |
126 } | 135 } |
127 | 136 |
128 void KeyboardServiceImpl::SetTarget(uint32_t node_id) { | 137 void KeyboardServiceImpl::SetTarget(uint32_t node_id) { |
129 keyboard_->set_target(node_id); | 138 keyboard_->set_target(node_id); |
130 } | 139 } |
131 | 140 |
132 } // namespace examples | 141 } // namespace examples |
133 | 142 |
134 // static | 143 // static |
135 ApplicationDelegate* ApplicationDelegate::Create() { | 144 ApplicationDelegate* ApplicationDelegate::Create() { |
136 return new examples::Keyboard; | 145 return new examples::Keyboard; |
137 } | 146 } |
138 | 147 |
139 } // namespace mojo | 148 } // namespace mojo |
OLD | NEW |