Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: mojo/examples/window_manager/window_manager.cc

Issue 460863002: Rename Node to View in the View Manager mojom & client lib. Service TBD. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/examples/window_manager/debug_panel.cc ('k') | mojo/examples/wm_flow/app/app.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/public/cpp/application/interface_factory_impl.h" 13 #include "mojo/public/cpp/application/interface_factory_impl.h"
14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" 14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
15 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" 15 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
16 #include "mojo/services/public/cpp/view_manager/node.h" 16 #include "mojo/services/public/cpp/view_manager/view.h"
17 #include "mojo/services/public/cpp/view_manager/node_observer.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager.h" 17 #include "mojo/services/public/cpp/view_manager/view_manager.h"
19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" 18 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.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/view_observer.h"
21 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" 21 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
22 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" 22 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
23 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" 23 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h"
24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" 24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
25 #include "mojo/views/views_init.h" 25 #include "mojo/views/views_init.h"
26 #include "ui/events/event.h" 26 #include "ui/events/event.h"
27 #include "ui/events/event_constants.h" 27 #include "ui/events/event_constants.h"
28 #include "ui/gfx/geometry/size_conversions.h" 28 #include "ui/gfx/geometry/size_conversions.h"
29 29
30 #if defined CreateWindow 30 #if defined CreateWindow
(...skipping 14 matching lines...) Expand all
45 } // namespace 45 } // namespace
46 46
47 class WindowManagerConnection : public InterfaceImpl<IWindowManager> { 47 class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
48 public: 48 public:
49 explicit WindowManagerConnection(WindowManager* window_manager) 49 explicit WindowManagerConnection(WindowManager* window_manager)
50 : window_manager_(window_manager) {} 50 : window_manager_(window_manager) {}
51 virtual ~WindowManagerConnection() {} 51 virtual ~WindowManagerConnection() {}
52 52
53 private: 53 private:
54 // Overridden from IWindowManager: 54 // Overridden from IWindowManager:
55 virtual void CloseWindow(Id node_id) OVERRIDE; 55 virtual void CloseWindow(Id view_id) OVERRIDE;
56 virtual void ShowKeyboard(Id view_id, RectPtr bounds) OVERRIDE; 56 virtual void ShowKeyboard(Id view_id, RectPtr bounds) OVERRIDE;
57 virtual void HideKeyboard(Id view_id) OVERRIDE; 57 virtual void HideKeyboard(Id view_id) OVERRIDE;
58 58
59 WindowManager* window_manager_; 59 WindowManager* window_manager_;
60 60
61 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection); 61 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection);
62 }; 62 };
63 63
64 class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> { 64 class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> {
65 public: 65 public:
66 explicit NavigatorHostImpl(WindowManager* window_manager) 66 explicit NavigatorHostImpl(WindowManager* window_manager)
67 : window_manager_(window_manager) {} 67 : window_manager_(window_manager) {}
68 virtual ~NavigatorHostImpl() { 68 virtual ~NavigatorHostImpl() {
69 } 69 }
70 70
71 private: 71 private:
72 virtual void DidNavigateLocally(uint32 source_node_id, 72 virtual void DidNavigateLocally(uint32 source_view_id,
73 const mojo::String& url) OVERRIDE; 73 const mojo::String& url) OVERRIDE;
74 virtual void RequestNavigate( 74 virtual void RequestNavigate(
75 uint32 source_node_id, 75 uint32 source_view_id,
76 Target target, 76 Target target,
77 NavigationDetailsPtr nav_details) OVERRIDE; 77 NavigationDetailsPtr nav_details) OVERRIDE;
78 WindowManager* window_manager_; 78 WindowManager* window_manager_;
79 79
80 DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl); 80 DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl);
81 }; 81 };
82 82
83 class KeyboardManager : public KeyboardClient, 83 class KeyboardManager : public KeyboardClient,
84 public NodeObserver { 84 public ViewObserver {
85 public: 85 public:
86 KeyboardManager() : view_manager_(NULL), node_(NULL) { 86 KeyboardManager() : view_manager_(NULL), view_(NULL) {
87 } 87 }
88 virtual ~KeyboardManager() { 88 virtual ~KeyboardManager() {
89 if (node_) 89 if (view_)
90 node_->parent()->RemoveObserver(this); 90 view_->parent()->RemoveObserver(this);
91 } 91 }
92 92
93 Node* node() { return node_; } 93 View* view() { return view_; }
94 94
95 void Init(ApplicationImpl* application, 95 void Init(ApplicationImpl* application,
96 ViewManager* view_manager, 96 ViewManager* view_manager,
97 Node* parent, 97 View* parent,
98 const gfx::Rect& bounds) { 98 const gfx::Rect& bounds) {
99 view_manager_ = view_manager; 99 view_manager_ = view_manager;
100 node_ = Node::Create(view_manager); 100 view_ = View::Create(view_manager);
101 node_->SetBounds(bounds); 101 view_->SetBounds(bounds);
102 parent->AddChild(node_); 102 parent->AddChild(view_);
103 node_->Embed("mojo:mojo_keyboard"); 103 view_->Embed("mojo:mojo_keyboard");
104 application->ConnectToService("mojo:mojo_keyboard", &keyboard_service_); 104 application->ConnectToService("mojo:mojo_keyboard", &keyboard_service_);
105 keyboard_service_.set_client(this); 105 keyboard_service_.set_client(this);
106 parent->AddObserver(this); 106 parent->AddObserver(this);
107 } 107 }
108 108
109 void Show(Id view_id, const gfx::Rect& bounds) { 109 void Show(Id view_id, const gfx::Rect& bounds) {
110 keyboard_service_->SetTarget(view_id); 110 keyboard_service_->SetTarget(view_id);
111 node_->SetVisible(true); 111 view_->SetVisible(true);
112 } 112 }
113 113
114 void Hide(Id view_id) { 114 void Hide(Id view_id) {
115 keyboard_service_->SetTarget(0); 115 keyboard_service_->SetTarget(0);
116 node_->SetVisible(false); 116 view_->SetVisible(false);
117 } 117 }
118 118
119 private: 119 private:
120 // KeyboardClient: 120 // KeyboardClient:
121 virtual void OnKeyboardEvent(Id node_id, 121 virtual void OnKeyboardEvent(Id view_id,
122 int32_t code, 122 int32_t code,
123 int32_t flags) OVERRIDE { 123 int32_t flags) OVERRIDE {
124 Node* node = view_manager_->GetNodeById(node_id); 124 View* view = view_manager_->GetViewById(view_id);
125 if (!node) 125 if (!view)
126 return; 126 return;
127 #if defined(OS_WIN) 127 #if defined(OS_WIN)
128 const bool is_char = code != ui::VKEY_BACK && code != ui::VKEY_RETURN; 128 const bool is_char = code != ui::VKEY_BACK && code != ui::VKEY_RETURN;
129 #else 129 #else
130 const bool is_char = false; 130 const bool is_char = false;
131 #endif 131 #endif
132 if (is_char) { 132 if (is_char) {
133 view_manager_->DispatchEvent( 133 view_manager_->DispatchEvent(
134 node, 134 view,
135 Event::From(ui::KeyEvent(ui::ET_KEY_PRESSED, 135 Event::From(ui::KeyEvent(ui::ET_KEY_PRESSED,
136 static_cast<ui::KeyboardCode>(code), 136 static_cast<ui::KeyboardCode>(code),
137 flags))); 137 flags)));
138 } else { 138 } else {
139 view_manager_->DispatchEvent( 139 view_manager_->DispatchEvent(
140 node, 140 view,
141 Event::From(ui::KeyEvent(static_cast<base::char16>(code), 141 Event::From(ui::KeyEvent(static_cast<base::char16>(code),
142 static_cast<ui::KeyboardCode>(code), 142 static_cast<ui::KeyboardCode>(code),
143 flags))); 143 flags)));
144 } 144 }
145 view_manager_->DispatchEvent( 145 view_manager_->DispatchEvent(
146 node, 146 view,
147 Event::From(ui::KeyEvent(ui::ET_KEY_RELEASED, 147 Event::From(ui::KeyEvent(ui::ET_KEY_RELEASED,
148 static_cast<ui::KeyboardCode>(code), 148 static_cast<ui::KeyboardCode>(code),
149 flags))); 149 flags)));
150 } 150 }
151 151
152 // Overridden from NodeObserver: 152 // Overridden from ViewObserver:
153 virtual void OnNodeBoundsChanged(Node* parent, 153 virtual void OnViewBoundsChanged(View* parent,
154 const gfx::Rect& old_bounds, 154 const gfx::Rect& old_bounds,
155 const gfx::Rect& new_bounds) OVERRIDE { 155 const gfx::Rect& new_bounds) OVERRIDE {
156 gfx::Rect keyboard_bounds(node_->bounds()); 156 gfx::Rect keyboard_bounds(view_->bounds());
157 keyboard_bounds.set_y(new_bounds.bottom() - keyboard_bounds.height()); 157 keyboard_bounds.set_y(new_bounds.bottom() - keyboard_bounds.height());
158 keyboard_bounds.set_width(keyboard_bounds.width() + 158 keyboard_bounds.set_width(keyboard_bounds.width() +
159 new_bounds.width() - old_bounds.width()); 159 new_bounds.width() - old_bounds.width());
160 node_->SetBounds(keyboard_bounds); 160 view_->SetBounds(keyboard_bounds);
161 } 161 }
162 virtual void OnNodeDestroyed(Node* parent) OVERRIDE { 162 virtual void OnViewDestroyed(View* parent) OVERRIDE {
163 DCHECK_EQ(parent, node_->parent()); 163 DCHECK_EQ(parent, view_->parent());
164 parent->RemoveObserver(this); 164 parent->RemoveObserver(this);
165 node_ = NULL; 165 view_ = NULL;
166 } 166 }
167 167
168 KeyboardServicePtr keyboard_service_; 168 KeyboardServicePtr keyboard_service_;
169 ViewManager* view_manager_; 169 ViewManager* view_manager_;
170 170
171 // Node the keyboard is attached to. 171 // View the keyboard is attached to.
172 Node* node_; 172 View* view_;
173 173
174 DISALLOW_COPY_AND_ASSIGN(KeyboardManager); 174 DISALLOW_COPY_AND_ASSIGN(KeyboardManager);
175 }; 175 };
176 176
177 class RootLayoutManager : public NodeObserver { 177 class RootLayoutManager : public ViewObserver {
178 public: 178 public:
179 RootLayoutManager(ViewManager* view_manager, 179 RootLayoutManager(ViewManager* view_manager,
180 Node* root, 180 View* root,
181 Id content_node_id, 181 Id content_view_id,
182 Id launcher_ui_node_id, 182 Id launcher_ui_view_id,
183 Id control_panel_node_id) 183 Id control_panel_view_id)
184 : root_(root), 184 : root_(root),
185 view_manager_(view_manager), 185 view_manager_(view_manager),
186 content_node_id_(content_node_id), 186 content_view_id_(content_view_id),
187 launcher_ui_node_id_(launcher_ui_node_id), 187 launcher_ui_view_id_(launcher_ui_view_id),
188 control_panel_node_id_(control_panel_node_id) {} 188 control_panel_view_id_(control_panel_view_id) {}
189 virtual ~RootLayoutManager() { 189 virtual ~RootLayoutManager() {
190 if (root_) 190 if (root_)
191 root_->RemoveObserver(this); 191 root_->RemoveObserver(this);
192 } 192 }
193 193
194 private: 194 private:
195 // Overridden from NodeObserver: 195 // Overridden from ViewObserver:
196 virtual void OnNodeBoundsChanged(Node* node, 196 virtual void OnViewBoundsChanged(View* view,
197 const gfx::Rect& old_bounds, 197 const gfx::Rect& old_bounds,
198 const gfx::Rect& new_bounds) OVERRIDE { 198 const gfx::Rect& new_bounds) OVERRIDE {
199 DCHECK_EQ(node, root_); 199 DCHECK_EQ(view, root_);
200 200
201 Node* content_node = view_manager_->GetNodeById(content_node_id_); 201 View* content_view = view_manager_->GetViewById(content_view_id_);
202 content_node->SetBounds(new_bounds); 202 content_view->SetBounds(new_bounds);
203 // Force the view's bitmap to be recreated 203 // Force the view's bitmap to be recreated
204 content_node->SetColor(SK_ColorBLUE); 204 content_view->SetColor(SK_ColorBLUE);
205 205
206 int delta_width = new_bounds.width() - old_bounds.width(); 206 int delta_width = new_bounds.width() - old_bounds.width();
207 int delta_height = new_bounds.height() - old_bounds.height(); 207 int delta_height = new_bounds.height() - old_bounds.height();
208 208
209 Node* launcher_ui_node = 209 View* launcher_ui_view =
210 view_manager_->GetNodeById(launcher_ui_node_id_); 210 view_manager_->GetViewById(launcher_ui_view_id_);
211 gfx::Rect launcher_ui_bounds(launcher_ui_node->bounds()); 211 gfx::Rect launcher_ui_bounds(launcher_ui_view->bounds());
212 launcher_ui_bounds.set_width(launcher_ui_bounds.width() + delta_width); 212 launcher_ui_bounds.set_width(launcher_ui_bounds.width() + delta_width);
213 launcher_ui_node->SetBounds(launcher_ui_bounds); 213 launcher_ui_view->SetBounds(launcher_ui_bounds);
214 214
215 Node* control_panel_node = 215 View* control_panel_view =
216 view_manager_->GetNodeById(control_panel_node_id_); 216 view_manager_->GetViewById(control_panel_view_id_);
217 gfx::Rect control_panel_bounds(control_panel_node->bounds()); 217 gfx::Rect control_panel_bounds(control_panel_view->bounds());
218 control_panel_bounds.set_x(control_panel_bounds.x() + delta_width); 218 control_panel_bounds.set_x(control_panel_bounds.x() + delta_width);
219 control_panel_node->SetBounds(control_panel_bounds); 219 control_panel_view->SetBounds(control_panel_bounds);
220 220
221 const Node::Children& content_nodes = content_node->children(); 221 const View::Children& content_views = content_view->children();
222 Node::Children::const_iterator iter = content_nodes.begin(); 222 View::Children::const_iterator iter = content_views.begin();
223 for(; iter != content_nodes.end(); ++iter) { 223 for(; iter != content_views.end(); ++iter) {
224 Node* node = *iter; 224 View* view = *iter;
225 if (node->id() == control_panel_node->id() || 225 if (view->id() == control_panel_view->id() ||
226 node->id() == launcher_ui_node->id()) 226 view->id() == launcher_ui_view->id())
227 continue; 227 continue;
228 gfx::Rect node_bounds(node->bounds()); 228 gfx::Rect view_bounds(view->bounds());
229 node_bounds.set_width(node_bounds.width() + delta_width); 229 view_bounds.set_width(view_bounds.width() + delta_width);
230 node_bounds.set_height(node_bounds.height() + delta_height); 230 view_bounds.set_height(view_bounds.height() + delta_height);
231 node->SetBounds(node_bounds); 231 view->SetBounds(view_bounds);
232 } 232 }
233 } 233 }
234 virtual void OnNodeDestroyed(Node* node) OVERRIDE { 234 virtual void OnViewDestroyed(View* view) OVERRIDE {
235 DCHECK_EQ(node, root_); 235 DCHECK_EQ(view, root_);
236 root_->RemoveObserver(this); 236 root_->RemoveObserver(this);
237 root_ = NULL; 237 root_ = NULL;
238 } 238 }
239 239
240 Node* root_; 240 View* root_;
241 ViewManager* view_manager_; 241 ViewManager* view_manager_;
242 const Id content_node_id_; 242 const Id content_view_id_;
243 const Id launcher_ui_node_id_; 243 const Id launcher_ui_view_id_;
244 const Id control_panel_node_id_; 244 const Id control_panel_view_id_;
245 245
246 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); 246 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager);
247 }; 247 };
248 248
249 class WindowManager 249 class WindowManager
250 : public ApplicationDelegate, 250 : public ApplicationDelegate,
251 public DebugPanel::Delegate, 251 public DebugPanel::Delegate,
252 public ViewManagerDelegate, 252 public ViewManagerDelegate,
253 public WindowManagerDelegate { 253 public WindowManagerDelegate {
254 public: 254 public:
255 WindowManager() 255 WindowManager()
256 : window_manager_factory_(this), 256 : window_manager_factory_(this),
257 navigator_host_factory_(this), 257 navigator_host_factory_(this),
258 launcher_ui_(NULL), 258 launcher_ui_(NULL),
259 view_manager_(NULL), 259 view_manager_(NULL),
260 view_manager_client_factory_(this), 260 view_manager_client_factory_(this),
261 app_(NULL) {} 261 app_(NULL) {}
262 262
263 virtual ~WindowManager() {} 263 virtual ~WindowManager() {}
264 264
265 void CloseWindow(Id node_id) { 265 void CloseWindow(Id view_id) {
266 Node* node = view_manager_->GetNodeById(node_id); 266 View* view = view_manager_->GetViewById(view_id);
267 DCHECK(node); 267 DCHECK(view);
268 std::vector<Node*>::iterator iter = 268 std::vector<View*>::iterator iter =
269 std::find(windows_.begin(), windows_.end(), node); 269 std::find(windows_.begin(), windows_.end(), view);
270 DCHECK(iter != windows_.end()); 270 DCHECK(iter != windows_.end());
271 windows_.erase(iter); 271 windows_.erase(iter);
272 node->Destroy(); 272 view->Destroy();
273 } 273 }
274 274
275 void ShowKeyboard(Id view_id, const gfx::Rect& bounds) { 275 void ShowKeyboard(Id view_id, const gfx::Rect& bounds) {
276 // TODO: this needs to validate |view_id|. That is, it shouldn't assume 276 // TODO: this needs to validate |view_id|. That is, it shouldn't assume
277 // |view_id| is valid and it also needs to make sure the client that sent 277 // |view_id| is valid and it also needs to make sure the client that sent
278 // this really owns |view_id|. 278 // this really owns |view_id|.
279 // TODO: honor |bounds|. 279 // TODO: honor |bounds|.
280 if (!keyboard_manager_) { 280 if (!keyboard_manager_) {
281 keyboard_manager_.reset(new KeyboardManager); 281 keyboard_manager_.reset(new KeyboardManager);
282 Node* parent = view_manager_->GetRoots().back(); 282 View* parent = view_manager_->GetRoots().back();
283 int ideal_height = 200; 283 int ideal_height = 200;
284 // TODO(sky): 10 is a bit of a hack here. There is a bug that causes 284 // TODO(sky): 10 is a bit of a hack here. There is a bug that causes
285 // white strips to appear when 0 is used. Figure this out! 285 // white strips to appear when 0 is used. Figure this out!
286 const gfx::Rect keyboard_bounds( 286 const gfx::Rect keyboard_bounds(
287 10, parent->bounds().height() - ideal_height, 287 10, parent->bounds().height() - ideal_height,
288 parent->bounds().width() - 20, ideal_height); 288 parent->bounds().width() - 20, ideal_height);
289 keyboard_manager_->Init(app_, view_manager_, parent, keyboard_bounds); 289 keyboard_manager_->Init(app_, view_manager_, parent, keyboard_bounds);
290 } 290 }
291 keyboard_manager_->Show(view_id, bounds); 291 keyboard_manager_->Show(view_id, bounds);
292 } 292 }
293 293
294 void HideKeyboard(Id view_id) { 294 void HideKeyboard(Id view_id) {
295 // See comment in ShowKeyboard() about validating args. 295 // See comment in ShowKeyboard() about validating args.
296 if (keyboard_manager_) 296 if (keyboard_manager_)
297 keyboard_manager_->Hide(view_id); 297 keyboard_manager_->Hide(view_id);
298 } 298 }
299 299
300 void DidNavigateLocally(uint32 source_node_id, const mojo::String& url) { 300 void DidNavigateLocally(uint32 source_view_id, const mojo::String& url) {
301 LOG(ERROR) << "DidNavigateLocally: source_node_id: " << source_node_id 301 LOG(ERROR) << "DidNavigateLocally: source_view_id: " << source_view_id
302 << " url: " << url.To<std::string>(); 302 << " url: " << url.To<std::string>();
303 } 303 }
304 304
305 // Overridden from DebugPanel::Delegate: 305 // Overridden from DebugPanel::Delegate:
306 virtual void CloseTopWindow() OVERRIDE { 306 virtual void CloseTopWindow() OVERRIDE {
307 if (!windows_.empty()) 307 if (!windows_.empty())
308 CloseWindow(windows_.back()->id()); 308 CloseWindow(windows_.back()->id());
309 } 309 }
310 310
311 virtual void RequestNavigate( 311 virtual void RequestNavigate(
312 uint32 source_node_id, 312 uint32 source_view_id,
313 Target target, 313 Target target,
314 NavigationDetailsPtr nav_details) OVERRIDE { 314 NavigationDetailsPtr nav_details) OVERRIDE {
315 launcher_->Launch(nav_details.Pass(), 315 launcher_->Launch(nav_details.Pass(),
316 base::Bind(&WindowManager::OnLaunch, 316 base::Bind(&WindowManager::OnLaunch,
317 base::Unretained(this), 317 base::Unretained(this),
318 source_node_id, 318 source_view_id,
319 target)); 319 target));
320 } 320 }
321 321
322 private: 322 private:
323 // Overridden from ApplicationDelegate: 323 // Overridden from ApplicationDelegate:
324 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { 324 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
325 app_ = app; 325 app_ = app;
326 app->ConnectToService("mojo:mojo_launcher", &launcher_); 326 app->ConnectToService("mojo:mojo_launcher", &launcher_);
327 views_init_.reset(new ViewsInit); 327 views_init_.reset(new ViewsInit);
328 } 328 }
329 329
330 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 330 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
331 MOJO_OVERRIDE { 331 MOJO_OVERRIDE {
332 connection->AddService(&window_manager_factory_); 332 connection->AddService(&window_manager_factory_);
333 connection->AddService(&navigator_host_factory_); 333 connection->AddService(&navigator_host_factory_);
334 connection->AddService(&view_manager_client_factory_); 334 connection->AddService(&view_manager_client_factory_);
335 return true; 335 return true;
336 } 336 }
337 337
338 // Overridden from ViewManagerDelegate: 338 // Overridden from ViewManagerDelegate:
339 virtual void OnEmbed(ViewManager* view_manager, 339 virtual void OnEmbed(ViewManager* view_manager,
340 Node* root, 340 View* root,
341 ServiceProviderImpl* exported_services, 341 ServiceProviderImpl* exported_services,
342 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { 342 scoped_ptr<ServiceProvider> imported_services) OVERRIDE {
343 DCHECK(!view_manager_); 343 DCHECK(!view_manager_);
344 view_manager_ = view_manager; 344 view_manager_ = view_manager;
345 view_manager_->SetWindowManagerDelegate(this); 345 view_manager_->SetWindowManagerDelegate(this);
346 346
347 Node* node = Node::Create(view_manager_); 347 View* view = View::Create(view_manager_);
348 root->AddChild(node); 348 root->AddChild(view);
349 node->SetBounds(gfx::Rect(root->bounds().size())); 349 view->SetBounds(gfx::Rect(root->bounds().size()));
350 content_node_id_ = node->id(); 350 content_view_id_ = view->id();
351 351
352 root->SetColor(SK_ColorBLUE); 352 root->SetColor(SK_ColorBLUE);
353 353
354 Id launcher_ui_id = CreateLauncherUI(); 354 Id launcher_ui_id = CreateLauncherUI();
355 Id control_panel_id = CreateControlPanel(node); 355 Id control_panel_id = CreateControlPanel(view);
356 356
357 root_layout_manager_.reset( 357 root_layout_manager_.reset(
358 new RootLayoutManager(view_manager, root, 358 new RootLayoutManager(view_manager, root,
359 content_node_id_, 359 content_view_id_,
360 launcher_ui_id, 360 launcher_ui_id,
361 control_panel_id)); 361 control_panel_id));
362 root->AddObserver(root_layout_manager_.get()); 362 root->AddObserver(root_layout_manager_.get());
363 } 363 }
364 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { 364 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {
365 DCHECK_EQ(view_manager_, view_manager); 365 DCHECK_EQ(view_manager_, view_manager);
366 view_manager_ = NULL; 366 view_manager_ = NULL;
367 base::MessageLoop::current()->Quit(); 367 base::MessageLoop::current()->Quit();
368 } 368 }
369 369
370 // Overridden from WindowManagerDelegate: 370 // Overridden from WindowManagerDelegate:
371 virtual void Embed( 371 virtual void Embed(
372 const String& url, 372 const String& url,
373 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { 373 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE {
374 CreateWindow(url, 374 CreateWindow(url,
375 NavigationDetailsPtr().Pass(), 375 NavigationDetailsPtr().Pass(),
376 ResponseDetailsPtr().Pass()); 376 ResponseDetailsPtr().Pass());
377 } 377 }
378 virtual void DispatchEvent(Node* target, EventPtr event) OVERRIDE { 378 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE {
379 // TODO(beng): More sophisticated focus handling than this is required! 379 // TODO(beng): More sophisticated focus handling than this is required!
380 if (event->action == EVENT_TYPE_MOUSE_PRESSED && 380 if (event->action == EVENT_TYPE_MOUSE_PRESSED &&
381 !IsDescendantOfKeyboard(target)) { 381 !IsDescendantOfKeyboard(target)) {
382 target->SetFocus(); 382 target->SetFocus();
383 } 383 }
384 view_manager_->DispatchEvent(target, event.Pass()); 384 view_manager_->DispatchEvent(target, event.Pass());
385 } 385 }
386 386
387 void OnLaunch( 387 void OnLaunch(
388 uint32 source_node_id, 388 uint32 source_view_id,
389 Target requested_target, 389 Target requested_target,
390 const mojo::String& handler_url, 390 const mojo::String& handler_url,
391 const mojo::String& view_url, 391 const mojo::String& view_url,
392 ResponseDetailsPtr response) { 392 ResponseDetailsPtr response) {
393 // TODO(mpcomplete): This seems to be unused in favor of |response|. We 393 // TODO(mpcomplete): This seems to be unused in favor of |response|. We
394 // might need to use it (and fill it in properly, with method, etc) if we 394 // might need to use it (and fill it in properly, with method, etc) if we
395 // need to preserve that information. 395 // need to preserve that information.
396 NavigationDetailsPtr nav_details(NavigationDetails::New()); 396 NavigationDetailsPtr nav_details(NavigationDetails::New());
397 nav_details->request->url = view_url; 397 nav_details->request->url = view_url;
398 398
399 Target target = debug_panel_->navigation_target(); 399 Target target = debug_panel_->navigation_target();
400 if (target == TARGET_DEFAULT) { 400 if (target == TARGET_DEFAULT) {
401 if (requested_target != TARGET_DEFAULT) { 401 if (requested_target != TARGET_DEFAULT) {
402 target = requested_target; 402 target = requested_target;
403 } else { 403 } else {
404 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin 404 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin
405 // are different? 405 // are different?
406 target = TARGET_SOURCE_NODE; 406 target = TARGET_SOURCE_NODE;
407 } 407 }
408 } 408 }
409 409
410 Node* dest_node = NULL; 410 View* dest_view = NULL;
411 if (target == TARGET_SOURCE_NODE) { 411 if (target == TARGET_SOURCE_NODE) {
412 Node* source_node = view_manager_->GetNodeById(source_node_id); 412 View* source_view = view_manager_->GetViewById(source_view_id);
413 bool app_initiated = std::find(windows_.begin(), windows_.end(), 413 bool app_initiated = std::find(windows_.begin(), windows_.end(),
414 source_node) != windows_.end(); 414 source_view) != windows_.end();
415 if (app_initiated) 415 if (app_initiated)
416 dest_node = source_node; 416 dest_view = source_view;
417 else if (!windows_.empty()) 417 else if (!windows_.empty())
418 dest_node = windows_.back(); 418 dest_view = windows_.back();
419 } 419 }
420 420
421 if (dest_node) 421 if (dest_view)
422 Embed(dest_node, handler_url, nav_details.Pass(), response.Pass()); 422 Embed(dest_view, handler_url, nav_details.Pass(), response.Pass());
423 else 423 else
424 CreateWindow(handler_url, nav_details.Pass(), response.Pass()); 424 CreateWindow(handler_url, nav_details.Pass(), response.Pass());
425 } 425 }
426 426
427 // TODO(beng): proper layout manager!! 427 // TODO(beng): proper layout manager!!
428 Id CreateLauncherUI() { 428 Id CreateLauncherUI() {
429 NavigationDetailsPtr nav_details; 429 NavigationDetailsPtr nav_details;
430 ResponseDetailsPtr response; 430 ResponseDetailsPtr response;
431 Node* node = view_manager_->GetNodeById(content_node_id_); 431 View* view = view_manager_->GetViewById(content_view_id_);
432 gfx::Rect bounds = node->bounds(); 432 gfx::Rect bounds = view->bounds();
433 bounds.Inset(kBorderInset, kBorderInset); 433 bounds.Inset(kBorderInset, kBorderInset);
434 bounds.set_height(kTextfieldHeight); 434 bounds.set_height(kTextfieldHeight);
435 launcher_ui_ = CreateChild(content_node_id_, "mojo:mojo_browser", bounds, 435 launcher_ui_ = CreateChild(content_view_id_, "mojo:mojo_browser", bounds,
436 nav_details.Pass(), response.Pass()); 436 nav_details.Pass(), response.Pass());
437 return launcher_ui_->id(); 437 return launcher_ui_->id();
438 } 438 }
439 439
440 void CreateWindow(const std::string& handler_url, 440 void CreateWindow(const std::string& handler_url,
441 NavigationDetailsPtr nav_details, 441 NavigationDetailsPtr nav_details,
442 ResponseDetailsPtr response) { 442 ResponseDetailsPtr response) {
443 Node* node = view_manager_->GetNodeById(content_node_id_); 443 View* view = view_manager_->GetViewById(content_view_id_);
444 gfx::Rect bounds(kBorderInset, 444 gfx::Rect bounds(kBorderInset,
445 2 * kBorderInset + kTextfieldHeight, 445 2 * kBorderInset + kTextfieldHeight,
446 node->bounds().width() - 3 * kBorderInset - 446 view->bounds().width() - 3 * kBorderInset -
447 kControlPanelWidth, 447 kControlPanelWidth,
448 node->bounds().height() - 448 view->bounds().height() -
449 (3 * kBorderInset + kTextfieldHeight)); 449 (3 * kBorderInset + kTextfieldHeight));
450 if (!windows_.empty()) { 450 if (!windows_.empty()) {
451 gfx::Point position = windows_.back()->bounds().origin(); 451 gfx::Point position = windows_.back()->bounds().origin();
452 position.Offset(35, 35); 452 position.Offset(35, 35);
453 bounds.set_origin(position); 453 bounds.set_origin(position);
454 } 454 }
455 windows_.push_back(CreateChild(content_node_id_, handler_url, bounds, 455 windows_.push_back(CreateChild(content_view_id_, handler_url, bounds,
456 nav_details.Pass(), response.Pass())); 456 nav_details.Pass(), response.Pass()));
457 } 457 }
458 458
459 Node* CreateChild(Id parent_id, 459 View* CreateChild(Id parent_id,
460 const std::string& url, 460 const std::string& url,
461 const gfx::Rect& bounds, 461 const gfx::Rect& bounds,
462 NavigationDetailsPtr nav_details, 462 NavigationDetailsPtr nav_details,
463 ResponseDetailsPtr response) { 463 ResponseDetailsPtr response) {
464 Node* node = view_manager_->GetNodeById(parent_id); 464 View* view = view_manager_->GetViewById(parent_id);
465 Node* embedded = Node::Create(view_manager_); 465 View* embedded = View::Create(view_manager_);
466 node->AddChild(embedded); 466 view->AddChild(embedded);
467 embedded->SetBounds(bounds); 467 embedded->SetBounds(bounds);
468 Embed(embedded, url, nav_details.Pass(), response.Pass()); 468 Embed(embedded, url, nav_details.Pass(), response.Pass());
469 embedded->SetFocus(); 469 embedded->SetFocus();
470 return embedded; 470 return embedded;
471 } 471 }
472 472
473 void Embed(Node* node, const std::string& app_url, 473 void Embed(View* view, const std::string& app_url,
474 NavigationDetailsPtr nav_details, 474 NavigationDetailsPtr nav_details,
475 ResponseDetailsPtr response) { 475 ResponseDetailsPtr response) {
476 node->Embed(app_url); 476 view->Embed(app_url);
477 if (nav_details) { 477 if (nav_details) {
478 NavigatorPtr navigator; 478 NavigatorPtr navigator;
479 app_->ConnectToService(app_url, &navigator); 479 app_->ConnectToService(app_url, &navigator);
480 navigator->Navigate(node->id(), nav_details.Pass(), response.Pass()); 480 navigator->Navigate(view->id(), nav_details.Pass(), response.Pass());
481 } 481 }
482 } 482 }
483 483
484 bool IsDescendantOfKeyboard(Node* target) { 484 bool IsDescendantOfKeyboard(View* target) {
485 return keyboard_manager_.get() && 485 return keyboard_manager_.get() &&
486 keyboard_manager_->node()->Contains(target); 486 keyboard_manager_->view()->Contains(target);
487 } 487 }
488 488
489 Id CreateControlPanel(Node* root) { 489 Id CreateControlPanel(View* root) {
490 Node* node = Node::Create(view_manager_); 490 View* view = View::Create(view_manager_);
491 root->AddChild(node); 491 root->AddChild(view);
492 492
493 gfx::Rect bounds(root->bounds().width() - kControlPanelWidth - 493 gfx::Rect bounds(root->bounds().width() - kControlPanelWidth -
494 kBorderInset, 494 kBorderInset,
495 kBorderInset * 2 + kTextfieldHeight, 495 kBorderInset * 2 + kTextfieldHeight,
496 kControlPanelWidth, 496 kControlPanelWidth,
497 root->bounds().height() - kBorderInset * 3 - 497 root->bounds().height() - kBorderInset * 3 -
498 kTextfieldHeight); 498 kTextfieldHeight);
499 node->SetBounds(bounds); 499 view->SetBounds(bounds);
500 500
501 debug_panel_ = new DebugPanel(this, node); 501 debug_panel_ = new DebugPanel(this, view);
502 return node->id(); 502 return view->id();
503 } 503 }
504 504
505 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> 505 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager>
506 window_manager_factory_; 506 window_manager_factory_;
507 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager> 507 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager>
508 navigator_host_factory_; 508 navigator_host_factory_;
509 509
510 scoped_ptr<ViewsInit> views_init_; 510 scoped_ptr<ViewsInit> views_init_;
511 DebugPanel* debug_panel_; 511 DebugPanel* debug_panel_;
512 LauncherPtr launcher_; 512 LauncherPtr launcher_;
513 Node* launcher_ui_; 513 View* launcher_ui_;
514 std::vector<Node*> windows_; 514 std::vector<View*> windows_;
515 ViewManager* view_manager_; 515 ViewManager* view_manager_;
516 ViewManagerClientFactory view_manager_client_factory_; 516 ViewManagerClientFactory view_manager_client_factory_;
517 scoped_ptr<RootLayoutManager> root_layout_manager_; 517 scoped_ptr<RootLayoutManager> root_layout_manager_;
518 518
519 // Id of the node most content is added to. The keyboard is NOT added here. 519 // Id of the view most content is added to. The keyboard is NOT added here.
520 Id content_node_id_; 520 Id content_view_id_;
521 521
522 scoped_ptr<KeyboardManager> keyboard_manager_; 522 scoped_ptr<KeyboardManager> keyboard_manager_;
523 ApplicationImpl* app_; 523 ApplicationImpl* app_;
524 524
525 DISALLOW_COPY_AND_ASSIGN(WindowManager); 525 DISALLOW_COPY_AND_ASSIGN(WindowManager);
526 }; 526 };
527 527
528 void WindowManagerConnection::CloseWindow(Id node_id) { 528 void WindowManagerConnection::CloseWindow(Id view_id) {
529 window_manager_->CloseWindow(node_id); 529 window_manager_->CloseWindow(view_id);
530 } 530 }
531 531
532 void WindowManagerConnection::ShowKeyboard(Id view_id, RectPtr bounds) { 532 void WindowManagerConnection::ShowKeyboard(Id view_id, RectPtr bounds) {
533 window_manager_->ShowKeyboard(view_id, bounds.To<gfx::Rect>()); 533 window_manager_->ShowKeyboard(view_id, bounds.To<gfx::Rect>());
534 } 534 }
535 535
536 void WindowManagerConnection::HideKeyboard(Id node_id) { 536 void WindowManagerConnection::HideKeyboard(Id view_id) {
537 window_manager_->HideKeyboard(node_id); 537 window_manager_->HideKeyboard(view_id);
538 } 538 }
539 539
540 void NavigatorHostImpl::DidNavigateLocally(uint32 source_node_id, 540 void NavigatorHostImpl::DidNavigateLocally(uint32 source_view_id,
541 const mojo::String& url) { 541 const mojo::String& url) {
542 window_manager_->DidNavigateLocally(source_node_id, url); 542 window_manager_->DidNavigateLocally(source_view_id, url);
543 } 543 }
544 544
545 void NavigatorHostImpl::RequestNavigate( 545 void NavigatorHostImpl::RequestNavigate(
546 uint32 source_node_id, 546 uint32 source_view_id,
547 Target target, 547 Target target,
548 NavigationDetailsPtr nav_details) { 548 NavigationDetailsPtr nav_details) {
549 window_manager_->RequestNavigate(source_node_id, target, nav_details.Pass()); 549 window_manager_->RequestNavigate(source_view_id, target, nav_details.Pass());
550 } 550 }
551 551
552 } // namespace examples 552 } // namespace examples
553 553
554 // static 554 // static
555 ApplicationDelegate* ApplicationDelegate::Create() { 555 ApplicationDelegate* ApplicationDelegate::Create() {
556 return new examples::WindowManager; 556 return new examples::WindowManager;
557 } 557 }
558 558
559 } // namespace mojo 559 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/window_manager/debug_panel.cc ('k') | mojo/examples/wm_flow/app/app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698