| 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 // TODO(hansmuller): this is just a hack to force a redraw |
| 182 content_node->active_view()->SetColor(SK_ColorBLUE); |
| 183 } |
| 184 |
| 185 Node* root_; |
| 186 ViewManager* view_manager_; |
| 187 Id content_node_id_; |
| 188 |
| 189 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
| 190 }; |
| 191 |
| 159 class WindowManager : public ApplicationDelegate, | 192 class WindowManager : public ApplicationDelegate, |
| 160 public DebugPanel::Delegate, | 193 public DebugPanel::Delegate, |
| 161 public ViewObserver, | 194 public ViewObserver, |
| 162 public ViewManagerDelegate, | 195 public ViewManagerDelegate, |
| 163 public ViewEventDispatcher { | 196 public ViewEventDispatcher { |
| 164 public: | 197 public: |
| 165 WindowManager() | 198 WindowManager() |
| 166 : launcher_ui_(NULL), | 199 : launcher_ui_(NULL), |
| 167 view_manager_(NULL), | 200 view_manager_(NULL), |
| 168 app_(NULL) { | 201 app_(NULL) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return true; | 276 return true; |
| 244 } | 277 } |
| 245 | 278 |
| 246 // Overridden from ViewManagerDelegate: | 279 // Overridden from ViewManagerDelegate: |
| 247 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { | 280 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
| 248 DCHECK(!view_manager_); | 281 DCHECK(!view_manager_); |
| 249 view_manager_ = view_manager; | 282 view_manager_ = view_manager; |
| 250 view_manager_->SetEventDispatcher(this); | 283 view_manager_->SetEventDispatcher(this); |
| 251 | 284 |
| 252 Node* node = Node::Create(view_manager); | 285 Node* node = Node::Create(view_manager); |
| 253 view_manager->GetRoots().front()->AddChild(node); | 286 root->AddChild(node); |
| 254 node->SetBounds(gfx::Rect(800, 600)); | 287 node->SetBounds(gfx::Rect(root->bounds().size())); |
| 255 content_node_id_ = node->id(); | 288 content_node_id_ = node->id(); |
| 289 root->AddObserver(new RootLayoutManager(view_manager, root, |
| 290 content_node_id_)); |
| 256 | 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 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 465 } |
| 431 | 466 |
| 432 } // namespace examples | 467 } // namespace examples |
| 433 | 468 |
| 434 // static | 469 // static |
| 435 ApplicationDelegate* ApplicationDelegate::Create() { | 470 ApplicationDelegate* ApplicationDelegate::Create() { |
| 436 return new examples::WindowManager; | 471 return new examples::WindowManager; |
| 437 } | 472 } |
| 438 | 473 |
| 439 } // namespace mojo | 474 } // namespace mojo |
| OLD | NEW |