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/bind.h" | 6 #include "base/bind.h" |
7 #include "mojo/examples/keyboard/keyboard.mojom.h" | 7 #include "mojo/examples/keyboard/keyboard.mojom.h" |
8 #include "mojo/examples/window_manager/debug_panel.h" | 8 #include "mojo/examples/window_manager/debug_panel.h" |
9 #include "mojo/examples/window_manager/window_manager.mojom.h" | 9 #include "mojo/examples/window_manager/window_manager.mojom.h" |
10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
11 #include "mojo/public/cpp/application/application_delegate.h" | 11 #include "mojo/public/cpp/application/application_delegate.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
14 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 14 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
15 #include "mojo/services/public/cpp/view_manager/node.h" | 15 #include "mojo/services/public/cpp/view_manager/node.h" |
16 #include "mojo/services/public/cpp/view_manager/node_observer.h" | 16 #include "mojo/services/public/cpp/view_manager/node_observer.h" |
17 #include "mojo/services/public/cpp/view_manager/view.h" | 17 #include "mojo/services/public/cpp/view_manager/view.h" |
18 #include "mojo/services/public/cpp/view_manager/view_event_dispatcher.h" | 18 #include "mojo/services/public/cpp/view_manager/view_event_dispatcher.h" |
19 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 19 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
21 #include "mojo/services/public/cpp/view_manager/view_observer.h" | |
22 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" | 21 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" |
23 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" | 22 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" |
24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 23 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
25 #include "mojo/views/views_init.h" | 24 #include "mojo/views/views_init.h" |
26 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
27 #include "ui/events/event_constants.h" | 26 #include "ui/events/event_constants.h" |
28 | 27 |
29 #if defined CreateWindow | 28 #if defined CreateWindow |
30 #undef CreateWindow | 29 #undef CreateWindow |
31 #endif | 30 #endif |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 181 |
183 Node* root_; | 182 Node* root_; |
184 ViewManager* view_manager_; | 183 ViewManager* view_manager_; |
185 Id content_node_id_; | 184 Id content_node_id_; |
186 | 185 |
187 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); | 186 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
188 }; | 187 }; |
189 | 188 |
190 class WindowManager : public ApplicationDelegate, | 189 class WindowManager : public ApplicationDelegate, |
191 public DebugPanel::Delegate, | 190 public DebugPanel::Delegate, |
192 public ViewObserver, | |
193 public ViewManagerDelegate, | 191 public ViewManagerDelegate, |
194 public ViewEventDispatcher { | 192 public ViewEventDispatcher { |
195 public: | 193 public: |
196 WindowManager() | 194 WindowManager() |
197 : launcher_ui_(NULL), | 195 : launcher_ui_(NULL), |
198 view_manager_(NULL), | 196 view_manager_(NULL), |
199 app_(NULL) { | 197 app_(NULL) { |
200 } | 198 } |
201 | 199 |
202 virtual ~WindowManager() {} | 200 virtual ~WindowManager() {} |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 ViewManager::ConfigureIncomingConnection(connection, this); | 271 ViewManager::ConfigureIncomingConnection(connection, this); |
274 return true; | 272 return true; |
275 } | 273 } |
276 | 274 |
277 // Overridden from ViewManagerDelegate: | 275 // Overridden from ViewManagerDelegate: |
278 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { | 276 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
279 DCHECK(!view_manager_); | 277 DCHECK(!view_manager_); |
280 view_manager_ = view_manager; | 278 view_manager_ = view_manager; |
281 view_manager_->SetEventDispatcher(this); | 279 view_manager_->SetEventDispatcher(this); |
282 | 280 |
283 Node* node = Node::Create(view_manager); | 281 Node* node = Node::Create(view_manager_); |
284 root->AddChild(node); | 282 root->AddChild(node); |
285 node->SetBounds(gfx::Rect(root->bounds().size())); | 283 node->SetBounds(gfx::Rect(root->bounds().size())); |
286 content_node_id_ = node->id(); | 284 content_node_id_ = node->id(); |
287 | 285 |
288 root_layout_manager_.reset( | 286 root_layout_manager_.reset( |
289 new RootLayoutManager(view_manager, root, content_node_id_)); | 287 new RootLayoutManager(view_manager_, root, content_node_id_)); |
290 root->AddObserver(root_layout_manager_.get()); | 288 root->AddObserver(root_layout_manager_.get()); |
291 | 289 |
292 View* view = View::Create(view_manager); | 290 View* view = View::Create(view_manager_); |
293 node->SetActiveView(view); | 291 node->SetActiveView(view); |
294 view->SetColor(SK_ColorBLUE); | 292 view->SetColor(SK_ColorBLUE); |
295 view->AddObserver(this); | |
296 | 293 |
297 CreateLauncherUI(); | 294 CreateLauncherUI(); |
298 CreateControlPanel(node); | 295 CreateControlPanel(node); |
299 } | 296 } |
| 297 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { |
| 298 DCHECK_EQ(view_manager_, view_manager); |
| 299 view_manager_ = NULL; |
| 300 base::MessageLoop::current()->Quit(); |
| 301 } |
300 | 302 |
301 // Overridden from ViewEventDispatcher: | 303 // Overridden from ViewEventDispatcher: |
302 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { | 304 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { |
303 // TODO(beng): More sophisticated focus handling than this is required! | 305 // TODO(beng): More sophisticated focus handling than this is required! |
304 if (event->action == ui::ET_MOUSE_PRESSED && | 306 if (event->action == ui::ET_MOUSE_PRESSED && |
305 !IsDescendantOfKeyboard(target)) { | 307 !IsDescendantOfKeyboard(target)) { |
306 target->node()->SetFocus(); | 308 target->node()->SetFocus(); |
307 } | 309 } |
308 view_manager_->DispatchEvent(target, event.Pass()); | 310 view_manager_->DispatchEvent(target, event.Pass()); |
309 } | 311 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 } | 468 } |
467 | 469 |
468 } // namespace examples | 470 } // namespace examples |
469 | 471 |
470 // static | 472 // static |
471 ApplicationDelegate* ApplicationDelegate::Create() { | 473 ApplicationDelegate* ApplicationDelegate::Create() { |
472 return new examples::WindowManager; | 474 return new examples::WindowManager; |
473 } | 475 } |
474 | 476 |
475 } // namespace mojo | 477 } // namespace mojo |
OLD | NEW |