Chromium Code Reviews| 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" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 ViewManager* view_manager_; | 152 ViewManager* view_manager_; |
| 153 | 153 |
| 154 // Node the keyboard is attached to. | 154 // Node the keyboard is attached to. |
| 155 Node* node_; | 155 Node* node_; |
| 156 | 156 |
| 157 DISALLOW_COPY_AND_ASSIGN(KeyboardManager); | 157 DISALLOW_COPY_AND_ASSIGN(KeyboardManager); |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 class RootLayoutManager : public NodeObserver { | 160 class RootLayoutManager : public NodeObserver { |
| 161 public: | 161 public: |
| 162 explicit RootLayoutManager(ViewManager* view_manager, | 162 RootLayoutManager(ViewManager* view_manager, Node* root, |
| 163 Node* root, | 163 Id content_node_id, |
| 164 Id content_node_id) | 164 Id launcher_ui_node_id, |
| 165 : root_(root), | 165 Id control_panel_node_id) |
| 166 view_manager_(view_manager), | 166 : root_(root), |
| 167 content_node_id_(content_node_id) {} | 167 view_manager_(view_manager), |
| 168 content_node_id_(content_node_id), | |
| 169 launcher_ui_node_id_(launcher_ui_node_id), | |
| 170 control_panel_node_id_(control_panel_node_id) {} | |
| 168 virtual ~RootLayoutManager() {} | 171 virtual ~RootLayoutManager() {} |
| 169 | 172 |
| 170 private: | 173 private: |
| 171 // Overridden from NodeObserver: | 174 // Overridden from NodeObserver: |
| 172 virtual void OnNodeBoundsChanged(Node* node, | 175 virtual void OnNodeBoundsChanged(Node* node, |
| 173 const gfx::Rect& /*old_bounds*/, | 176 const gfx::Rect& old_bounds, |
| 174 const gfx::Rect& new_bounds) OVERRIDE { | 177 const gfx::Rect& new_bounds) OVERRIDE { |
| 175 DCHECK_EQ(node, root_); | 178 DCHECK_EQ(node, root_); |
| 179 | |
| 176 Node* content_node = view_manager_->GetNodeById(content_node_id_); | 180 Node* content_node = view_manager_->GetNodeById(content_node_id_); |
| 177 content_node->SetBounds(new_bounds); | 181 content_node->SetBounds(new_bounds); |
| 178 // Force the view's bitmap to be recreated | 182 // Force the view's bitmap to be recreated |
| 179 content_node->active_view()->SetColor(SK_ColorBLUE); | 183 content_node->active_view()->SetColor(SK_ColorBLUE); |
| 180 // TODO(hansmuller): Do Layout | 184 |
| 185 Node* launcher_ui_node = | |
| 186 view_manager_->GetNodeById(launcher_ui_node_id_); | |
| 187 gfx::Rect launcher_ui_bounds(launcher_ui_node->bounds()); | |
| 188 launcher_ui_bounds.set_width(launcher_ui_bounds.width() + | |
| 189 new_bounds.width() - old_bounds.width()); | |
| 190 launcher_ui_node->SetBounds(launcher_ui_bounds); | |
| 191 | |
| 192 | |
| 193 Node* control_panel_node = | |
| 194 view_manager_->GetNodeById(control_panel_node_id_); | |
| 195 gfx::Rect control_panel_bounds(control_panel_node->bounds()); | |
| 196 control_panel_bounds.set_x(control_panel_bounds.x() + | |
| 197 new_bounds.width() - old_bounds.width()); | |
| 198 control_panel_node->SetBounds(control_panel_bounds); | |
| 181 } | 199 } |
|
Ben Goodger (Google)
2014/07/11 18:18:23
Looks like you're missing the embedded node(s) (e.
| |
| 182 | 200 |
| 183 Node* root_; | 201 Node* root_; |
| 184 ViewManager* view_manager_; | 202 ViewManager* view_manager_; |
| 185 Id content_node_id_; | 203 Id content_node_id_; |
| 204 Id launcher_ui_node_id_; | |
| 205 Id control_panel_node_id_; | |
| 186 | 206 |
| 187 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); | 207 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
| 188 }; | 208 }; |
| 189 | 209 |
| 190 class WindowManager : public ApplicationDelegate, | 210 class WindowManager : public ApplicationDelegate, |
| 191 public DebugPanel::Delegate, | 211 public DebugPanel::Delegate, |
| 192 public ViewObserver, | 212 public ViewObserver, |
| 193 public ViewManagerDelegate, | 213 public ViewManagerDelegate, |
| 194 public ViewEventDispatcher { | 214 public ViewEventDispatcher { |
| 195 public: | 215 public: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { | 298 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
| 279 DCHECK(!view_manager_); | 299 DCHECK(!view_manager_); |
| 280 view_manager_ = view_manager; | 300 view_manager_ = view_manager; |
| 281 view_manager_->SetEventDispatcher(this); | 301 view_manager_->SetEventDispatcher(this); |
| 282 | 302 |
| 283 Node* node = Node::Create(view_manager); | 303 Node* node = Node::Create(view_manager); |
| 284 root->AddChild(node); | 304 root->AddChild(node); |
| 285 node->SetBounds(gfx::Rect(root->bounds().size())); | 305 node->SetBounds(gfx::Rect(root->bounds().size())); |
| 286 content_node_id_ = node->id(); | 306 content_node_id_ = node->id(); |
| 287 | 307 |
| 288 root_layout_manager_.reset( | |
| 289 new RootLayoutManager(view_manager, root, content_node_id_)); | |
| 290 root->AddObserver(root_layout_manager_.get()); | |
| 291 | |
| 292 View* view = View::Create(view_manager); | 308 View* view = View::Create(view_manager); |
| 293 node->SetActiveView(view); | 309 node->SetActiveView(view); |
| 294 view->SetColor(SK_ColorBLUE); | 310 view->SetColor(SK_ColorBLUE); |
| 295 view->AddObserver(this); | 311 view->AddObserver(this); |
| 296 | 312 |
| 297 CreateLauncherUI(); | 313 Id launcher_ui_id = CreateLauncherUI(); |
| 298 CreateControlPanel(node); | 314 Id control_panel_id = CreateControlPanel(node); |
| 315 | |
| 316 root_layout_manager_.reset( | |
| 317 new RootLayoutManager(view_manager, root, | |
| 318 content_node_id_, | |
| 319 launcher_ui_id, | |
| 320 control_panel_id)); | |
| 321 root->AddObserver(root_layout_manager_.get()); | |
| 299 } | 322 } |
| 300 | 323 |
| 301 // Overridden from ViewEventDispatcher: | 324 // Overridden from ViewEventDispatcher: |
| 302 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { | 325 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { |
| 303 // TODO(beng): More sophisticated focus handling than this is required! | 326 // TODO(beng): More sophisticated focus handling than this is required! |
| 304 if (event->action == ui::ET_MOUSE_PRESSED && | 327 if (event->action == ui::ET_MOUSE_PRESSED && |
| 305 !IsDescendantOfKeyboard(target)) { | 328 !IsDescendantOfKeyboard(target)) { |
| 306 target->node()->SetFocus(); | 329 target->node()->SetFocus(); |
| 307 } | 330 } |
| 308 view_manager_->DispatchEvent(target, event.Pass()); | 331 view_manager_->DispatchEvent(target, event.Pass()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 dest_node = windows_.back(); | 363 dest_node = windows_.back(); |
| 341 } | 364 } |
| 342 | 365 |
| 343 if (dest_node) | 366 if (dest_node) |
| 344 Embed(dest_node, handler_url, nav_details.Pass(), response.Pass()); | 367 Embed(dest_node, handler_url, nav_details.Pass(), response.Pass()); |
| 345 else | 368 else |
| 346 CreateWindow(handler_url, nav_details.Pass(), response.Pass()); | 369 CreateWindow(handler_url, nav_details.Pass(), response.Pass()); |
| 347 } | 370 } |
| 348 | 371 |
| 349 // TODO(beng): proper layout manager!! | 372 // TODO(beng): proper layout manager!! |
| 350 void CreateLauncherUI() { | 373 Id CreateLauncherUI() { |
| 351 navigation::NavigationDetailsPtr nav_details; | 374 navigation::NavigationDetailsPtr nav_details; |
| 352 navigation::ResponseDetailsPtr response; | 375 navigation::ResponseDetailsPtr response; |
| 353 Node* node = view_manager_->GetNodeById(content_node_id_); | 376 Node* node = view_manager_->GetNodeById(content_node_id_); |
| 354 gfx::Rect bounds = node->bounds(); | 377 gfx::Rect bounds = node->bounds(); |
| 355 bounds.Inset(kBorderInset, kBorderInset); | 378 bounds.Inset(kBorderInset, kBorderInset); |
| 356 bounds.set_height(kTextfieldHeight); | 379 bounds.set_height(kTextfieldHeight); |
| 357 launcher_ui_ = CreateChild(content_node_id_, "mojo:mojo_browser", bounds, | 380 launcher_ui_ = CreateChild(content_node_id_, "mojo:mojo_browser", bounds, |
| 358 nav_details.Pass(), response.Pass()); | 381 nav_details.Pass(), response.Pass()); |
| 382 return launcher_ui_->id(); | |
| 359 } | 383 } |
| 360 | 384 |
| 361 void CreateWindow(const std::string& handler_url, | 385 void CreateWindow(const std::string& handler_url, |
| 362 navigation::NavigationDetailsPtr nav_details, | 386 navigation::NavigationDetailsPtr nav_details, |
| 363 navigation::ResponseDetailsPtr response) { | 387 navigation::ResponseDetailsPtr response) { |
| 364 Node* node = view_manager_->GetNodeById(content_node_id_); | 388 Node* node = view_manager_->GetNodeById(content_node_id_); |
| 365 gfx::Rect bounds(kBorderInset, | 389 gfx::Rect bounds(kBorderInset, |
| 366 2 * kBorderInset + kTextfieldHeight, | 390 2 * kBorderInset + kTextfieldHeight, |
| 367 node->bounds().width() - 3 * kBorderInset - | 391 node->bounds().width() - 3 * kBorderInset - |
| 368 kControlPanelWidth, | 392 kControlPanelWidth, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 app_->ConnectToService(app_url, &navigator); | 424 app_->ConnectToService(app_url, &navigator); |
| 401 navigator->Navigate(node->id(), nav_details.Pass(), response.Pass()); | 425 navigator->Navigate(node->id(), nav_details.Pass(), response.Pass()); |
| 402 } | 426 } |
| 403 } | 427 } |
| 404 | 428 |
| 405 bool IsDescendantOfKeyboard(View* target) { | 429 bool IsDescendantOfKeyboard(View* target) { |
| 406 return keyboard_manager_.get() && | 430 return keyboard_manager_.get() && |
| 407 keyboard_manager_->node()->Contains(target->node()); | 431 keyboard_manager_->node()->Contains(target->node()); |
| 408 } | 432 } |
| 409 | 433 |
| 410 void CreateControlPanel(view_manager::Node* root) { | 434 Id CreateControlPanel(view_manager::Node* root) { |
| 411 Node* node = Node::Create(view_manager_); | 435 Node* node = Node::Create(view_manager_); |
| 412 View* view = view_manager::View::Create(view_manager_); | 436 View* view = view_manager::View::Create(view_manager_); |
| 413 root->AddChild(node); | 437 root->AddChild(node); |
| 414 node->SetActiveView(view); | 438 node->SetActiveView(view); |
| 415 | 439 |
| 416 gfx::Rect bounds(root->bounds().width() - kControlPanelWidth - | 440 gfx::Rect bounds(root->bounds().width() - kControlPanelWidth - |
| 417 kBorderInset, | 441 kBorderInset, |
| 418 kBorderInset * 2 + kTextfieldHeight, | 442 kBorderInset * 2 + kTextfieldHeight, |
| 419 kControlPanelWidth, | 443 kControlPanelWidth, |
| 420 root->bounds().height() - kBorderInset * 3 - | 444 root->bounds().height() - kBorderInset * 3 - |
| 421 kTextfieldHeight); | 445 kTextfieldHeight); |
| 422 node->SetBounds(bounds); | 446 node->SetBounds(bounds); |
| 423 | 447 |
| 424 debug_panel_ = new DebugPanel(this, node); | 448 debug_panel_ = new DebugPanel(this, node); |
| 449 return node->id(); | |
| 425 } | 450 } |
| 426 | 451 |
| 427 scoped_ptr<ViewsInit> views_init_; | 452 scoped_ptr<ViewsInit> views_init_; |
| 428 DebugPanel* debug_panel_; | 453 DebugPanel* debug_panel_; |
| 429 launcher::LauncherPtr launcher_; | 454 launcher::LauncherPtr launcher_; |
| 430 Node* launcher_ui_; | 455 Node* launcher_ui_; |
| 431 std::vector<Node*> windows_; | 456 std::vector<Node*> windows_; |
| 432 ViewManager* view_manager_; | 457 ViewManager* view_manager_; |
| 433 scoped_ptr<RootLayoutManager> root_layout_manager_; | 458 scoped_ptr<RootLayoutManager> root_layout_manager_; |
| 434 | 459 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 } | 491 } |
| 467 | 492 |
| 468 } // namespace examples | 493 } // namespace examples |
| 469 | 494 |
| 470 // static | 495 // static |
| 471 ApplicationDelegate* ApplicationDelegate::Create() { | 496 ApplicationDelegate* ApplicationDelegate::Create() { |
| 472 return new examples::WindowManager; | 497 return new examples::WindowManager; |
| 473 } | 498 } |
| 474 | 499 |
| 475 } // namespace mojo | 500 } // namespace mojo |
| OLD | NEW |