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" | |
19 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 20 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" |
21 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" | 21 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" |
22 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" | 22 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" |
23 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 23 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
24 #include "mojo/views/views_init.h" | 24 #include "mojo/views/views_init.h" |
25 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
26 #include "ui/events/event_constants.h" | 26 #include "ui/events/event_constants.h" |
27 #include "ui/gfx/geometry/size_conversions.h" | 27 #include "ui/gfx/geometry/size_conversions.h" |
28 | 28 |
29 #if defined CreateWindow | 29 #if defined CreateWindow |
30 #undef CreateWindow | 30 #undef CreateWindow |
31 #endif | 31 #endif |
32 | 32 |
33 using mojo::view_manager::Id; | 33 using mojo::view_manager::Id; |
34 using mojo::view_manager::Node; | 34 using mojo::view_manager::Node; |
35 using mojo::view_manager::NodeObserver; | 35 using mojo::view_manager::NodeObserver; |
36 using mojo::view_manager::View; | 36 using mojo::view_manager::View; |
37 using mojo::view_manager::ViewEventDispatcher; | |
38 using mojo::view_manager::ViewManager; | 37 using mojo::view_manager::ViewManager; |
39 using mojo::view_manager::ViewManagerDelegate; | 38 using mojo::view_manager::ViewManagerDelegate; |
40 using mojo::view_manager::ViewObserver; | 39 using mojo::view_manager::ViewObserver; |
| 40 using mojo::view_manager::WindowManagerDelegate; |
41 | 41 |
42 namespace mojo { | 42 namespace mojo { |
43 namespace examples { | 43 namespace examples { |
44 | 44 |
45 class WindowManager; | 45 class WindowManager; |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
49 const int kBorderInset = 25; | 49 const int kBorderInset = 25; |
50 const int kControlPanelWidth = 200; | 50 const int kControlPanelWidth = 200; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 const Id content_node_id_; | 245 const Id content_node_id_; |
246 const Id launcher_ui_node_id_; | 246 const Id launcher_ui_node_id_; |
247 const Id control_panel_node_id_; | 247 const Id control_panel_node_id_; |
248 | 248 |
249 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); | 249 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
250 }; | 250 }; |
251 | 251 |
252 class WindowManager : public ApplicationDelegate, | 252 class WindowManager : public ApplicationDelegate, |
253 public DebugPanel::Delegate, | 253 public DebugPanel::Delegate, |
254 public ViewManagerDelegate, | 254 public ViewManagerDelegate, |
255 public ViewEventDispatcher { | 255 public WindowManagerDelegate { |
256 public: | 256 public: |
257 WindowManager() | 257 WindowManager() |
258 : launcher_ui_(NULL), | 258 : launcher_ui_(NULL), |
259 view_manager_(NULL), | 259 view_manager_(NULL), |
260 app_(NULL) { | 260 app_(NULL) { |
261 } | 261 } |
262 | 262 |
263 virtual ~WindowManager() {} | 263 virtual ~WindowManager() {} |
264 | 264 |
265 void CloseWindow(Id node_id) { | 265 void CloseWindow(Id node_id) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 connection->AddService<WindowManagerConnection>(this); | 332 connection->AddService<WindowManagerConnection>(this); |
333 connection->AddService<NavigatorHost>(this); | 333 connection->AddService<NavigatorHost>(this); |
334 ViewManager::ConfigureIncomingConnection(connection, this); | 334 ViewManager::ConfigureIncomingConnection(connection, this); |
335 return true; | 335 return true; |
336 } | 336 } |
337 | 337 |
338 // Overridden from ViewManagerDelegate: | 338 // Overridden from ViewManagerDelegate: |
339 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { | 339 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
340 DCHECK(!view_manager_); | 340 DCHECK(!view_manager_); |
341 view_manager_ = view_manager; | 341 view_manager_ = view_manager; |
342 view_manager_->SetEventDispatcher(this); | 342 view_manager_->SetWindowManagerDelegate(this); |
343 | 343 |
344 Node* node = Node::Create(view_manager_); | 344 Node* node = Node::Create(view_manager_); |
345 root->AddChild(node); | 345 root->AddChild(node); |
346 node->SetBounds(gfx::Rect(root->bounds().size())); | 346 node->SetBounds(gfx::Rect(root->bounds().size())); |
347 content_node_id_ = node->id(); | 347 content_node_id_ = node->id(); |
348 | 348 |
349 View* view = View::Create(view_manager_); | 349 View* view = View::Create(view_manager_); |
350 node->SetActiveView(view); | 350 node->SetActiveView(view); |
351 view->SetColor(SK_ColorBLUE); | 351 view->SetColor(SK_ColorBLUE); |
352 | 352 |
353 Id launcher_ui_id = CreateLauncherUI(); | 353 Id launcher_ui_id = CreateLauncherUI(); |
354 Id control_panel_id = CreateControlPanel(node); | 354 Id control_panel_id = CreateControlPanel(node); |
355 | 355 |
356 root_layout_manager_.reset( | 356 root_layout_manager_.reset( |
357 new RootLayoutManager(view_manager, root, | 357 new RootLayoutManager(view_manager, root, |
358 content_node_id_, | 358 content_node_id_, |
359 launcher_ui_id, | 359 launcher_ui_id, |
360 control_panel_id)); | 360 control_panel_id)); |
361 root->AddObserver(root_layout_manager_.get()); | 361 root->AddObserver(root_layout_manager_.get()); |
362 } | 362 } |
363 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { | 363 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { |
364 DCHECK_EQ(view_manager_, view_manager); | 364 DCHECK_EQ(view_manager_, view_manager); |
365 view_manager_ = NULL; | 365 view_manager_ = NULL; |
366 base::MessageLoop::current()->Quit(); | 366 base::MessageLoop::current()->Quit(); |
367 } | 367 } |
368 | 368 |
369 // Overridden from ViewEventDispatcher: | 369 // Overridden from WindowManagerDelegate: |
| 370 virtual void EmbedRoot(const String& url) OVERRIDE { |
| 371 CreateWindow(url, |
| 372 navigation::NavigationDetailsPtr().Pass(), |
| 373 navigation::ResponseDetailsPtr().Pass()); |
| 374 } |
370 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { | 375 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { |
371 // TODO(beng): More sophisticated focus handling than this is required! | 376 // TODO(beng): More sophisticated focus handling than this is required! |
372 if (event->action == ui::ET_MOUSE_PRESSED && | 377 if (event->action == ui::ET_MOUSE_PRESSED && |
373 !IsDescendantOfKeyboard(target)) { | 378 !IsDescendantOfKeyboard(target)) { |
374 target->node()->SetFocus(); | 379 target->node()->SetFocus(); |
375 } | 380 } |
376 view_manager_->DispatchEvent(target, event.Pass()); | 381 view_manager_->DispatchEvent(target, event.Pass()); |
377 } | 382 } |
378 | 383 |
379 void OnLaunch( | 384 void OnLaunch( |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 } | 541 } |
537 | 542 |
538 } // namespace examples | 543 } // namespace examples |
539 | 544 |
540 // static | 545 // static |
541 ApplicationDelegate* ApplicationDelegate::Create() { | 546 ApplicationDelegate* ApplicationDelegate::Create() { |
542 return new examples::WindowManager; | 547 return new examples::WindowManager; |
543 } | 548 } |
544 | 549 |
545 } // namespace mojo | 550 } // namespace mojo |
OLD | NEW |