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 "base/strings/stringprintf.h" | |
| 7 #include "mojo/examples/window_manager/window_manager.mojom.h" | 8 #include "mojo/examples/window_manager/window_manager.mojom.h" |
| 8 #include "mojo/public/cpp/application/application.h" | 9 #include "mojo/public/cpp/application/application.h" |
| 10 #include "mojo/services/navigation/navigation.mojom.h" | |
| 9 #include "mojo/services/public/cpp/view_manager/view.h" | 11 #include "mojo/services/public/cpp/view_manager/view.h" |
| 10 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 12 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 11 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 13 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 12 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 14 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 13 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" | 15 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" |
| 14 #include "ui/events/event_constants.h" | 16 #include "ui/events/event_constants.h" |
| 15 | 17 |
| 16 #if defined CreateWindow | 18 #if defined CreateWindow |
| 17 #undef CreateWindow | 19 #undef CreateWindow |
| 18 #endif | 20 #endif |
| 19 | 21 |
| 20 using mojo::view_manager::Id; | 22 using mojo::view_manager::Id; |
| 21 using mojo::view_manager::View; | 23 using mojo::view_manager::View; |
| 22 using mojo::view_manager::ViewManager; | 24 using mojo::view_manager::ViewManager; |
| 23 using mojo::view_manager::ViewManagerDelegate; | 25 using mojo::view_manager::ViewManagerDelegate; |
| 24 using mojo::view_manager::ViewObserver; | 26 using mojo::view_manager::ViewObserver; |
| 25 using mojo::view_manager::ViewTreeNode; | 27 using mojo::view_manager::ViewTreeNode; |
| 26 using mojo::view_manager::ViewTreeNodeObserver; | 28 using mojo::view_manager::ViewTreeNodeObserver; |
| 27 | 29 |
| 28 namespace mojo { | 30 namespace mojo { |
| 29 namespace examples { | 31 namespace examples { |
| 30 | 32 |
| 31 class WindowManager; | 33 class WindowManager; |
| 32 | 34 |
| 35 namespace { | |
| 36 | |
| 37 const SkColor kColors[] = { SK_ColorYELLOW, | |
| 38 SK_ColorRED, | |
| 39 SK_ColorGREEN, | |
| 40 SK_ColorMAGENTA }; | |
| 41 | |
| 42 const char* kEmbeddedAppURL = "mojo:mojo_embedded_app"; | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 33 class WindowManagerConnection : public InterfaceImpl<IWindowManager> { | 46 class WindowManagerConnection : public InterfaceImpl<IWindowManager> { |
| 34 public: | 47 public: |
| 35 explicit WindowManagerConnection(WindowManager* window_manager) | 48 explicit WindowManagerConnection(WindowManager* window_manager) |
| 36 : window_manager_(window_manager) {} | 49 : window_manager_(window_manager) {} |
| 37 virtual ~WindowManagerConnection() {} | 50 virtual ~WindowManagerConnection() {} |
| 38 | 51 |
| 39 private: | 52 private: |
| 40 // Overridden from IWindowManager: | 53 // Overridden from IWindowManager: |
| 41 virtual void CloseWindow(Id node_id) OVERRIDE; | 54 virtual void CloseWindow(Id node_id) OVERRIDE; |
| 42 | 55 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 62 // Overridden from Application: | 75 // Overridden from Application: |
| 63 virtual void Initialize() MOJO_OVERRIDE { | 76 virtual void Initialize() MOJO_OVERRIDE { |
| 64 AddService<WindowManagerConnection>(this); | 77 AddService<WindowManagerConnection>(this); |
| 65 ViewManager::Create(this, this); | 78 ViewManager::Create(this, this); |
| 66 } | 79 } |
| 67 | 80 |
| 68 // Overridden from ViewObserver: | 81 // Overridden from ViewObserver: |
| 69 virtual void OnViewInputEvent(View* view, EventPtr event) OVERRIDE { | 82 virtual void OnViewInputEvent(View* view, EventPtr event) OVERRIDE { |
| 70 if (event->action == ui::ET_MOUSE_RELEASED) { | 83 if (event->action == ui::ET_MOUSE_RELEASED) { |
| 71 if (event->flags & ui::EF_LEFT_MOUSE_BUTTON) | 84 if (event->flags & ui::EF_LEFT_MOUSE_BUTTON) |
| 72 CreateWindow("mojo:mojo_embedded_app"); | 85 CreateWindow("mojo:mojo_embedded_app"); |
|
Ben Goodger (Google)
2014/06/09 20:17:05
nit: mebbe swap this out with your new kEmbeddedAp
Aaron Boodman
2014/06/10 19:41:29
Ugh. Merge fallout. Sorry.
| |
| 73 else if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON) | 86 else if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON) |
| 74 CreateWindow("mojo:mojo_nesting_app"); | 87 CreateWindow("mojo:mojo_nesting_app"); |
| 75 } | 88 } |
| 76 } | 89 } |
| 77 | 90 |
| 78 // Overridden from ViewManagerDelegate: | 91 // Overridden from ViewManagerDelegate: |
| 79 virtual void OnRootAdded(ViewManager* view_manager, | 92 virtual void OnRootAdded(ViewManager* view_manager, |
| 80 ViewTreeNode* root) OVERRIDE { | 93 ViewTreeNode* root) OVERRIDE { |
| 81 DCHECK(!view_manager_); | 94 DCHECK(!view_manager_); |
| 82 view_manager_ = view_manager; | 95 view_manager_ = view_manager; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 99 if (!node->children().empty()) { | 112 if (!node->children().empty()) { |
| 100 gfx::Point position = node->children().back()->bounds().origin(); | 113 gfx::Point position = node->children().back()->bounds().origin(); |
| 101 position.Offset(50, 50); | 114 position.Offset(50, 50); |
| 102 bounds.set_origin(position); | 115 bounds.set_origin(position); |
| 103 } | 116 } |
| 104 | 117 |
| 105 ViewTreeNode* embedded = ViewTreeNode::Create(view_manager_); | 118 ViewTreeNode* embedded = ViewTreeNode::Create(view_manager_); |
| 106 node->AddChild(embedded); | 119 node->AddChild(embedded); |
| 107 embedded->SetBounds(bounds); | 120 embedded->SetBounds(bounds); |
| 108 embedded->Embed(url); | 121 embedded->Embed(url); |
| 122 | |
| 123 if (!view_navigator_.get()) { | |
| 124 // TODO(aa): This means that there can only ever be one instance of every | |
| 125 // app, which seems wrong. Instead, perhaps embedder should get back a | |
| 126 // service provider that allows it to talk to embeddee. | |
| 127 ConnectTo(kEmbeddedAppURL, &view_navigator_); | |
|
Ben Goodger (Google)
2014/06/09 20:17:05
can't you resolve this by having view_navigator_ b
Aaron Boodman
2014/06/10 19:41:29
I wasn't referring to the shared member variable.
| |
| 128 } | |
| 129 | |
| 130 navigation::NavigationDetailsPtr details( | |
| 131 navigation::NavigationDetails::New()); | |
| 132 size_t index = node->children().size() - 1; | |
| 133 details->url = base::StringPrintf( | |
| 134 "%s/%x", kEmbeddedAppURL, kColors[index % arraysize(kColors)]); | |
| 135 view_navigator_->Navigate(embedded->id(), details.Pass()); | |
| 109 } | 136 } |
| 110 | 137 |
| 138 navigation::ViewNavigatorPtr view_navigator_; | |
| 111 ViewManager* view_manager_; | 139 ViewManager* view_manager_; |
| 112 Id parent_node_id_; | 140 Id parent_node_id_; |
| 113 | 141 |
| 114 DISALLOW_COPY_AND_ASSIGN(WindowManager); | 142 DISALLOW_COPY_AND_ASSIGN(WindowManager); |
| 115 }; | 143 }; |
| 116 | 144 |
| 117 void WindowManagerConnection::CloseWindow(Id node_id) { | 145 void WindowManagerConnection::CloseWindow(Id node_id) { |
| 118 window_manager_->CloseWindow(node_id); | 146 window_manager_->CloseWindow(node_id); |
| 119 } | 147 } |
| 120 | 148 |
| 121 } // namespace examples | 149 } // namespace examples |
| 122 | 150 |
| 123 // static | 151 // static |
| 124 Application* Application::Create() { | 152 Application* Application::Create() { |
| 125 return new examples::WindowManager; | 153 return new examples::WindowManager; |
| 126 } | 154 } |
| 127 | 155 |
| 128 } // namespace mojo | 156 } // namespace mojo |
| OLD | NEW |