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 OnNodeBoundsChanged(Node* node, |
| 173 const gfx::Rect& /*old_bounds*/, |
| 174 const gfx::Rect& new_bounds) OVERRIDE { |
| 175 DCHECK_EQ(node, root_); |
| 176 Node* content_node = view_manager_->GetNodeById(content_node_id_); |
| 177 content_node->SetBounds(new_bounds); |
| 178 // Force the view's bitmap to be recreated |
| 179 content_node->active_view()->SetColor(SK_ColorBLUE); |
| 180 // TODO(hansmuller): Do Layout |
| 181 } |
| 182 |
| 183 Node* root_; |
| 184 ViewManager* view_manager_; |
| 185 Id content_node_id_; |
| 186 |
| 187 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
| 188 }; |
| 189 |
159 class WindowManager : public ApplicationDelegate, | 190 class WindowManager : public ApplicationDelegate, |
160 public DebugPanel::Delegate, | 191 public DebugPanel::Delegate, |
161 public ViewObserver, | 192 public ViewObserver, |
162 public ViewManagerDelegate, | 193 public ViewManagerDelegate, |
163 public ViewEventDispatcher { | 194 public ViewEventDispatcher { |
164 public: | 195 public: |
165 WindowManager() | 196 WindowManager() |
166 : launcher_ui_(NULL), | 197 : launcher_ui_(NULL), |
167 view_manager_(NULL), | 198 view_manager_(NULL), |
168 app_(NULL) { | 199 app_(NULL) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return true; | 274 return true; |
244 } | 275 } |
245 | 276 |
246 // Overridden from ViewManagerDelegate: | 277 // Overridden from ViewManagerDelegate: |
247 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { | 278 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
248 DCHECK(!view_manager_); | 279 DCHECK(!view_manager_); |
249 view_manager_ = view_manager; | 280 view_manager_ = view_manager; |
250 view_manager_->SetEventDispatcher(this); | 281 view_manager_->SetEventDispatcher(this); |
251 | 282 |
252 Node* node = Node::Create(view_manager); | 283 Node* node = Node::Create(view_manager); |
253 view_manager->GetRoots().front()->AddChild(node); | 284 root->AddChild(node); |
254 node->SetBounds(gfx::Rect(800, 600)); | 285 node->SetBounds(gfx::Rect(root->bounds().size())); |
255 content_node_id_ = node->id(); | 286 content_node_id_ = node->id(); |
256 | 287 |
| 288 root_layout_manager_.reset( |
| 289 new RootLayoutManager(view_manager, root, content_node_id_)); |
| 290 root->AddObserver(root_layout_manager_.get()); |
| 291 |
257 View* view = View::Create(view_manager); | 292 View* view = View::Create(view_manager); |
258 node->SetActiveView(view); | 293 node->SetActiveView(view); |
259 view->SetColor(SK_ColorBLUE); | 294 view->SetColor(SK_ColorBLUE); |
260 view->AddObserver(this); | 295 view->AddObserver(this); |
261 | 296 |
262 CreateLauncherUI(); | 297 CreateLauncherUI(); |
263 CreateControlPanel(node); | 298 CreateControlPanel(node); |
264 } | 299 } |
265 | 300 |
266 // Overridden from ViewEventDispatcher: | 301 // Overridden from ViewEventDispatcher: |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 423 |
389 debug_panel_ = new DebugPanel(this, node); | 424 debug_panel_ = new DebugPanel(this, node); |
390 } | 425 } |
391 | 426 |
392 scoped_ptr<ViewsInit> views_init_; | 427 scoped_ptr<ViewsInit> views_init_; |
393 DebugPanel* debug_panel_; | 428 DebugPanel* debug_panel_; |
394 launcher::LauncherPtr launcher_; | 429 launcher::LauncherPtr launcher_; |
395 Node* launcher_ui_; | 430 Node* launcher_ui_; |
396 std::vector<Node*> windows_; | 431 std::vector<Node*> windows_; |
397 ViewManager* view_manager_; | 432 ViewManager* view_manager_; |
| 433 scoped_ptr<RootLayoutManager> root_layout_manager_; |
398 | 434 |
399 // Id of the node most content is added to. The keyboard is NOT added here. | 435 // Id of the node most content is added to. The keyboard is NOT added here. |
400 Id content_node_id_; | 436 Id content_node_id_; |
401 | 437 |
402 scoped_ptr<KeyboardManager> keyboard_manager_; | 438 scoped_ptr<KeyboardManager> keyboard_manager_; |
403 ApplicationImpl* app_; | 439 ApplicationImpl* app_; |
404 | 440 |
405 DISALLOW_COPY_AND_ASSIGN(WindowManager); | 441 DISALLOW_COPY_AND_ASSIGN(WindowManager); |
406 }; | 442 }; |
407 | 443 |
(...skipping 22 matching lines...) Expand all Loading... |
430 } | 466 } |
431 | 467 |
432 } // namespace examples | 468 } // namespace examples |
433 | 469 |
434 // static | 470 // static |
435 ApplicationDelegate* ApplicationDelegate::Create() { | 471 ApplicationDelegate* ApplicationDelegate::Create() { |
436 return new examples::WindowManager; | 472 return new examples::WindowManager; |
437 } | 473 } |
438 | 474 |
439 } // namespace mojo | 475 } // namespace mojo |
OLD | NEW |