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/view.h" | 17 #include "mojo/services/public/cpp/view_manager/view.h" |
17 #include "mojo/services/public/cpp/view_manager/view_event_dispatcher.h" | 18 #include "mojo/services/public/cpp/view_manager/view_event_dispatcher.h" |
18 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 19 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 20 #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/view_observer.h" |
21 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" | 22 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" |
22 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" | 23 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" |
23 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
24 #include "mojo/views/views_init.h" | 25 #include "mojo/views/views_init.h" |
25 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 150 |
150 KeyboardServicePtr keyboard_service_; | 151 KeyboardServicePtr keyboard_service_; |
151 ViewManager* view_manager_; | 152 ViewManager* view_manager_; |
152 | 153 |
153 // Node the keyboard is attached to. | 154 // Node the keyboard is attached to. |
154 Node* node_; | 155 Node* node_; |
155 | 156 |
156 DISALLOW_COPY_AND_ASSIGN(KeyboardManager); | 157 DISALLOW_COPY_AND_ASSIGN(KeyboardManager); |
157 }; | 158 }; |
158 | 159 |
| 160 class RootLayoutManager : public NodeObserver { |
| 161 public: |
| 162 explicit RootLayoutManager(ViewManager* view_manager, |
| 163 Node* root, |
| 164 Id content_node_id) |
| 165 : root_(root), |
| 166 view_manager_(view_manager), |
| 167 content_node_id_(content_node_id) {} |
| 168 virtual ~RootLayoutManager() {} |
| 169 |
| 170 private: |
| 171 // Overridden from NodeObserver: |
| 172 virtual void OnNodeBoundsChange(Node* node, |
| 173 const gfx::Rect& /*old_bounds*/, |
| 174 const gfx::Rect& new_bounds, |
| 175 DispositionChangePhase phase) OVERRIDE { |
| 176 if (phase != NodeObserver::DISPOSITION_CHANGED) |
| 177 return; |
| 178 DCHECK_EQ(node, root_); |
| 179 Node* content_node = view_manager_->GetNodeById(content_node_id_); |
| 180 content_node->SetBounds(new_bounds); |
| 181 // Force the view's bitmap to be recreated |
| 182 content_node->active_view()->SetColor(SK_ColorBLUE); |
| 183 // TODO(hansmuller): Do Layout |
| 184 } |
| 185 |
| 186 Node* root_; |
| 187 ViewManager* view_manager_; |
| 188 Id content_node_id_; |
| 189 |
| 190 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
| 191 }; |
| 192 |
159 class WindowManager : public ApplicationDelegate, | 193 class WindowManager : public ApplicationDelegate, |
160 public DebugPanel::Delegate, | 194 public DebugPanel::Delegate, |
161 public ViewObserver, | 195 public ViewObserver, |
162 public ViewManagerDelegate, | 196 public ViewManagerDelegate, |
163 public ViewEventDispatcher { | 197 public ViewEventDispatcher { |
164 public: | 198 public: |
165 WindowManager() | 199 WindowManager() |
166 : launcher_ui_(NULL), | 200 : launcher_ui_(NULL), |
167 view_manager_(NULL), | 201 view_manager_(NULL), |
168 app_(NULL) { | 202 app_(NULL) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return true; | 277 return true; |
244 } | 278 } |
245 | 279 |
246 // Overridden from ViewManagerDelegate: | 280 // Overridden from ViewManagerDelegate: |
247 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { | 281 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
248 DCHECK(!view_manager_); | 282 DCHECK(!view_manager_); |
249 view_manager_ = view_manager; | 283 view_manager_ = view_manager; |
250 view_manager_->SetEventDispatcher(this); | 284 view_manager_->SetEventDispatcher(this); |
251 | 285 |
252 Node* node = Node::Create(view_manager); | 286 Node* node = Node::Create(view_manager); |
253 view_manager->GetRoots().front()->AddChild(node); | 287 root->AddChild(node); |
254 node->SetBounds(gfx::Rect(800, 600)); | 288 node->SetBounds(gfx::Rect(root->bounds().size())); |
255 content_node_id_ = node->id(); | 289 content_node_id_ = node->id(); |
256 | 290 |
| 291 root_layout_manager_.reset( |
| 292 new RootLayoutManager(view_manager, root, content_node_id_)); |
| 293 root->AddObserver(root_layout_manager_.get()); |
| 294 |
257 View* view = View::Create(view_manager); | 295 View* view = View::Create(view_manager); |
258 node->SetActiveView(view); | 296 node->SetActiveView(view); |
259 view->SetColor(SK_ColorBLUE); | 297 view->SetColor(SK_ColorBLUE); |
260 view->AddObserver(this); | 298 view->AddObserver(this); |
261 | 299 |
262 CreateLauncherUI(); | 300 CreateLauncherUI(); |
263 CreateControlPanel(node); | 301 CreateControlPanel(node); |
264 } | 302 } |
265 | 303 |
266 // Overridden from ViewEventDispatcher: | 304 // Overridden from ViewEventDispatcher: |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 426 |
389 debug_panel_ = new DebugPanel(this, node); | 427 debug_panel_ = new DebugPanel(this, node); |
390 } | 428 } |
391 | 429 |
392 scoped_ptr<ViewsInit> views_init_; | 430 scoped_ptr<ViewsInit> views_init_; |
393 DebugPanel* debug_panel_; | 431 DebugPanel* debug_panel_; |
394 launcher::LauncherPtr launcher_; | 432 launcher::LauncherPtr launcher_; |
395 Node* launcher_ui_; | 433 Node* launcher_ui_; |
396 std::vector<Node*> windows_; | 434 std::vector<Node*> windows_; |
397 ViewManager* view_manager_; | 435 ViewManager* view_manager_; |
| 436 scoped_ptr<RootLayoutManager> root_layout_manager_; |
398 | 437 |
399 // Id of the node most content is added to. The keyboard is NOT added here. | 438 // Id of the node most content is added to. The keyboard is NOT added here. |
400 Id content_node_id_; | 439 Id content_node_id_; |
401 | 440 |
402 scoped_ptr<KeyboardManager> keyboard_manager_; | 441 scoped_ptr<KeyboardManager> keyboard_manager_; |
403 ApplicationImpl* app_; | 442 ApplicationImpl* app_; |
404 | 443 |
405 DISALLOW_COPY_AND_ASSIGN(WindowManager); | 444 DISALLOW_COPY_AND_ASSIGN(WindowManager); |
406 }; | 445 }; |
407 | 446 |
(...skipping 22 matching lines...) Expand all Loading... |
430 } | 469 } |
431 | 470 |
432 } // namespace examples | 471 } // namespace examples |
433 | 472 |
434 // static | 473 // static |
435 ApplicationDelegate* ApplicationDelegate::Create() { | 474 ApplicationDelegate* ApplicationDelegate::Create() { |
436 return new examples::WindowManager; | 475 return new examples::WindowManager; |
437 } | 476 } |
438 | 477 |
439 } // namespace mojo | 478 } // namespace mojo |
OLD | NEW |