Chromium Code Reviews| Index: mojo/examples/media_viewer/media_viewer.cc |
| diff --git a/mojo/examples/media_viewer/media_viewer.cc b/mojo/examples/media_viewer/media_viewer.cc |
| index 58cb3ed1e1770c4d194e10a5ad6483466e9e232e..8d9ed4d4dde2c90b160bea369c63333102869297 100644 |
| --- a/mojo/examples/media_viewer/media_viewer.cc |
| +++ b/mojo/examples/media_viewer/media_viewer.cc |
| @@ -14,6 +14,7 @@ |
| #include "mojo/public/cpp/application/application_impl.h" |
| #include "mojo/public/cpp/bindings/interface_impl.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_manager.h" |
| #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| @@ -202,7 +203,8 @@ class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { |
| class MediaViewer : public ApplicationDelegate, |
| public view_manager::ViewManagerDelegate, |
| - public ControlPanel::Delegate { |
| + public ControlPanel::Delegate, |
| + public view_manager::NodeObserver { |
| public: |
| MediaViewer() : app_(NULL), |
| view_manager_(NULL), |
| @@ -270,6 +272,15 @@ class MediaViewer : public ApplicationDelegate, |
| return true; |
| } |
| + void LayoutNodes() { |
| + view_manager::Node* root = content_node_->parent(); |
| + gfx::Rect control_bounds(root->bounds().width(), 28); |
| + control_node_->SetBounds(control_bounds); |
| + gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), |
| + root->bounds().height() - control_bounds.height()); |
| + content_node_->SetBounds(content_bounds); |
| + } |
| + |
| // Overridden from view_manager::ViewManagerDelegate: |
| virtual void OnRootAdded(view_manager::ViewManager* view_manager, |
| view_manager::Node* root) OVERRIDE { |
| @@ -277,17 +288,15 @@ class MediaViewer : public ApplicationDelegate, |
| control_node_ = view_manager::Node::Create(view_manager_); |
| root->AddChild(control_node_); |
| - gfx::Rect control_bounds(root->bounds().width(), 28); |
| - control_node_->SetBounds(control_bounds); |
| - control_node_->SetActiveView(view_manager::View::Create(view_manager_)); |
| - |
| - control_panel_.Initialize(control_node_); |
| content_node_ = view_manager::Node::Create(view_manager_); |
| root->AddChild(content_node_); |
| - gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), |
| - root->bounds().height() - control_bounds.height()); |
| - content_node_->SetBounds(content_bounds); |
| + |
| + control_node_->SetActiveView(view_manager::View::Create(view_manager_)); |
| + control_panel_.Initialize(control_node_); |
| + |
| + LayoutNodes(); |
| + root->AddObserver(this); |
|
sky
2014/07/14 19:15:28
You need to remove the observer when done.
hansmuller
2014/07/14 22:16:42
Done.
|
| if (pending_navigate_request_) { |
| scoped_ptr<PendingNavigateRequest> request( |
| @@ -321,6 +330,13 @@ class MediaViewer : public ApplicationDelegate, |
| } |
| } |
| + // Overridden from view_manager::NodeObserver |
| + virtual void OnNodeBoundsChanged(view_manager::Node* node, |
| + const gfx::Rect&, |
| + const gfx::Rect&) OVERRIDE { |
| + LayoutNodes(); |
| + } |
| + |
| std::string GetHandlerForContentType(const std::string& content_type) { |
| HandlerMap::const_iterator it = handler_map_.find(content_type); |
| return it != handler_map_.end() ? it->second : std::string(); |