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 "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.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/interface_factory_impl.h" | 12 #include "mojo/public/cpp/application/interface_factory_impl.h" |
13 #include "mojo/services/public/cpp/view_manager/node.h" | 13 #include "mojo/services/public/cpp/view_manager/view.h" |
14 #include "mojo/services/public/cpp/view_manager/node_observer.h" | |
15 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 14 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
16 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | 15 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
18 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 18 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
19 #include "ui/events/event_constants.h" | 19 #include "ui/events/event_constants.h" |
20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
21 | 21 |
22 namespace mojo { | 22 namespace mojo { |
23 namespace examples { | 23 namespace examples { |
24 | 24 |
25 namespace { | 25 namespace { |
26 const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app"; | 26 const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app"; |
27 } | 27 } |
(...skipping 12 matching lines...) Expand all Loading... |
40 | 40 |
41 NestingApp* app_; | 41 NestingApp* app_; |
42 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); | 42 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); |
43 }; | 43 }; |
44 | 44 |
45 // An app that embeds another app. | 45 // An app that embeds another app. |
46 // TODO(davemoore): Is this the right name? | 46 // TODO(davemoore): Is this the right name? |
47 class NestingApp | 47 class NestingApp |
48 : public ApplicationDelegate, | 48 : public ApplicationDelegate, |
49 public ViewManagerDelegate, | 49 public ViewManagerDelegate, |
50 public NodeObserver { | 50 public ViewObserver { |
51 public: | 51 public: |
52 NestingApp() | 52 NestingApp() |
53 : navigator_factory_(this), | 53 : navigator_factory_(this), |
54 view_manager_client_factory_(this), | 54 view_manager_client_factory_(this), |
55 nested_(NULL) {} | 55 nested_(NULL) {} |
56 virtual ~NestingApp() {} | 56 virtual ~NestingApp() {} |
57 | 57 |
58 void set_color(const std::string& color) { color_ = color; } | 58 void set_color(const std::string& color) { color_ = color; } |
59 | 59 |
60 void NavigateChild() { | 60 void NavigateChild() { |
(...skipping 17 matching lines...) Expand all Loading... |
78 // TODO(davemoore): Is this ok? | 78 // TODO(davemoore): Is this ok? |
79 if (!navigator_) { | 79 if (!navigator_) { |
80 connection->ConnectToApplication( | 80 connection->ConnectToApplication( |
81 kEmbeddedAppURL)->ConnectToService(&navigator_); | 81 kEmbeddedAppURL)->ConnectToService(&navigator_); |
82 } | 82 } |
83 return true; | 83 return true; |
84 } | 84 } |
85 | 85 |
86 // Overridden from ViewManagerDelegate: | 86 // Overridden from ViewManagerDelegate: |
87 virtual void OnEmbed(ViewManager* view_manager, | 87 virtual void OnEmbed(ViewManager* view_manager, |
88 Node* root, | 88 View* root, |
89 ServiceProviderImpl* exported_services, | 89 ServiceProviderImpl* exported_services, |
90 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 90 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { |
91 root->AddObserver(this); | 91 root->AddObserver(this); |
92 root->SetColor(SK_ColorCYAN); | 92 root->SetColor(SK_ColorCYAN); |
93 | 93 |
94 nested_ = Node::Create(view_manager); | 94 nested_ = View::Create(view_manager); |
95 root->AddChild(nested_); | 95 root->AddChild(nested_); |
96 nested_->SetBounds(gfx::Rect(20, 20, 50, 50)); | 96 nested_->SetBounds(gfx::Rect(20, 20, 50, 50)); |
97 nested_->Embed(kEmbeddedAppURL); | 97 nested_->Embed(kEmbeddedAppURL); |
98 | 98 |
99 NavigateChild(); | 99 NavigateChild(); |
100 } | 100 } |
101 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { | 101 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { |
102 base::MessageLoop::current()->Quit(); | 102 base::MessageLoop::current()->Quit(); |
103 } | 103 } |
104 | 104 |
105 // Overridden from NodeObserver: | 105 // Overridden from ViewObserver: |
106 virtual void OnNodeDestroyed(Node* node) OVERRIDE { | 106 virtual void OnViewDestroyed(View* view) OVERRIDE { |
107 // TODO(beng): reap views & child nodes. | 107 // TODO(beng): reap views & child Views. |
108 nested_ = NULL; | 108 nested_ = NULL; |
109 } | 109 } |
110 virtual void OnNodeInputEvent(Node* node, const EventPtr& event) OVERRIDE { | 110 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { |
111 if (event->action == EVENT_TYPE_MOUSE_RELEASED) | 111 if (event->action == EVENT_TYPE_MOUSE_RELEASED) |
112 window_manager_->CloseWindow(node->id()); | 112 window_manager_->CloseWindow(view->id()); |
113 } | 113 } |
114 | 114 |
115 InterfaceFactoryImplWithContext<NavigatorImpl, NestingApp> navigator_factory_; | 115 InterfaceFactoryImplWithContext<NavigatorImpl, NestingApp> navigator_factory_; |
116 ViewManagerClientFactory view_manager_client_factory_; | 116 ViewManagerClientFactory view_manager_client_factory_; |
117 | 117 |
118 std::string color_; | 118 std::string color_; |
119 Node* nested_; | 119 View* nested_; |
120 NavigatorPtr navigator_; | 120 NavigatorPtr navigator_; |
121 IWindowManagerPtr window_manager_; | 121 IWindowManagerPtr window_manager_; |
122 | 122 |
123 DISALLOW_COPY_AND_ASSIGN(NestingApp); | 123 DISALLOW_COPY_AND_ASSIGN(NestingApp); |
124 }; | 124 }; |
125 | 125 |
126 void NavigatorImpl::Navigate(uint32 node_id, | 126 void NavigatorImpl::Navigate(uint32 node_id, |
127 NavigationDetailsPtr navigation_details, | 127 NavigationDetailsPtr navigation_details, |
128 ResponseDetailsPtr response_details) { | 128 ResponseDetailsPtr response_details) { |
129 GURL url(navigation_details->request->url.To<std::string>()); | 129 GURL url(navigation_details->request->url.To<std::string>()); |
130 if (!url.is_valid()) { | 130 if (!url.is_valid()) { |
131 LOG(ERROR) << "URL is invalid."; | 131 LOG(ERROR) << "URL is invalid."; |
132 return; | 132 return; |
133 } | 133 } |
134 app_->set_color(url.path().substr(1)); | 134 app_->set_color(url.path().substr(1)); |
135 app_->NavigateChild(); | 135 app_->NavigateChild(); |
136 } | 136 } |
137 | 137 |
138 } // namespace examples | 138 } // namespace examples |
139 | 139 |
140 // static | 140 // static |
141 ApplicationDelegate* ApplicationDelegate::Create() { | 141 ApplicationDelegate* ApplicationDelegate::Create() { |
142 return new examples::NestingApp; | 142 return new examples::NestingApp; |
143 } | 143 } |
144 | 144 |
145 } // namespace mojo | 145 } // namespace mojo |
OLD | NEW |