Index: mojo/examples/window_manager/window_manager.cc |
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc |
index 2d3c694af4722373fccaab8793ebc25f8b1fccad..1f748df54080380053d545c2af49e3e5c0a214c9 100644 |
--- a/mojo/examples/window_manager/window_manager.cc |
+++ b/mojo/examples/window_manager/window_manager.cc |
@@ -13,6 +13,7 @@ |
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
#include "mojo/services/public/cpp/view_manager/node.h" |
+#include "mojo/services/public/cpp/view_manager/node_observer.h" |
#include "mojo/services/public/cpp/view_manager/view.h" |
#include "mojo/services/public/cpp/view_manager/view_event_dispatcher.h" |
#include "mojo/services/public/cpp/view_manager/view_manager.h" |
@@ -156,6 +157,38 @@ class KeyboardManager : public KeyboardClient { |
DISALLOW_COPY_AND_ASSIGN(KeyboardManager); |
}; |
+class RootLayoutManager : public NodeObserver { |
+ public: |
+ explicit RootLayoutManager(ViewManager* view_manager, |
Ben Goodger (Google)
2014/07/08 15:41:57
nit: explicit only if there is one param to the ct
|
+ Node* root, |
+ Id content_node_id) |
+ : root_(root), |
+ view_manager_(view_manager), |
+ content_node_id_(content_node_id) {} |
+ virtual ~RootLayoutManager() {} |
+ |
+ private: |
+ // Overridden from NodeObserver |
Ben Goodger (Google)
2014/07/08 15:41:57
nit: trailing :
|
+ virtual void OnNodeBoundsChange(Node* node, |
+ const gfx::Rect& /*old_bounds*/, |
+ const gfx::Rect& new_bounds, |
+ DispositionChangePhase phase) OVERRIDE { |
+ if (phase != NodeObserver::DISPOSITION_CHANGED) |
+ return; |
+ DCHECK_EQ(node, root_); |
+ Node* content_node = view_manager_->GetNodeById(content_node_id_); |
+ content_node->SetBounds(new_bounds); |
+ // TODO(hansmuller): this is just a hack to force a redraw |
Ben Goodger (Google)
2014/07/08 15:41:57
Can you schedule the draw in the service side of S
|
+ content_node->active_view()->SetColor(SK_ColorBLUE); |
+ } |
+ |
+ Node* root_; |
+ ViewManager* view_manager_; |
+ Id content_node_id_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
+}; |
+ |
class WindowManager : public ApplicationDelegate, |
public DebugPanel::Delegate, |
public ViewObserver, |
@@ -250,9 +283,11 @@ class WindowManager : public ApplicationDelegate, |
view_manager_->SetEventDispatcher(this); |
Node* node = Node::Create(view_manager); |
- view_manager->GetRoots().front()->AddChild(node); |
- node->SetBounds(gfx::Rect(800, 600)); |
+ root->AddChild(node); |
+ node->SetBounds(gfx::Rect(root->bounds().size())); |
content_node_id_ = node->id(); |
+ root->AddObserver(new RootLayoutManager(view_manager, root, |
+ content_node_id_)); |
Ben Goodger (Google)
2014/07/08 15:41:57
you're leaking the layout manager. The WindowManag
|
View* view = View::Create(view_manager); |
node->SetActiveView(view); |