Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: mojo/services/public/cpp/view_manager/lib/view_manager_private.cc

Issue 316083002: Add support for multiple roots to the client lib. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/services/public/cpp/view_manager/lib/view_manager_private.cc
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_private.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_private.cc
index e350f3426dfd42481358e7edf35b12b38c697308..c17fed358a2347be48359f45dd202e438b4ed579 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_private.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_private.cc
@@ -4,13 +4,62 @@
#include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
+#include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h"
+#include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h"
+
namespace mojo {
namespace view_manager {
+namespace {
+
+// Responsible for removing a root from the ViewManager when that node is
+// destroyed.
+class RootObserver : public ViewTreeNodeObserver {
+ public:
+ explicit RootObserver(ViewTreeNode* root) : root_(root) {}
+ virtual ~RootObserver() {}
+
+ private:
+ // Overridden from ViewTreeNodeObserver:
+ virtual void OnNodeDestroy(ViewTreeNode* node,
+ DispositionChangePhase phase) OVERRIDE {
+ DCHECK_EQ(node, root_);
+ if (phase != ViewTreeNodeObserver::DISPOSITION_CHANGED)
+ return;
+ ViewManagerPrivate(
+ ViewTreeNodePrivate(root_).view_manager()).RemoveRoot(root_);
sky 2014/06/05 18:18:52 nit: indent 1 more.
+ }
+
+ ViewTreeNode* root_;
+
+ DISALLOW_COPY_AND_ASSIGN(RootObserver);
+};
+
+} // namespace
ViewManagerPrivate::ViewManagerPrivate(ViewManager* manager)
: manager_(manager) {}
ViewManagerPrivate::~ViewManagerPrivate() {}
+void ViewManagerPrivate::AddRoot(ViewTreeNode* root) {
+ // A new root must not already exist as a root or be contained by an existing
+ // hierarchy visible to this view manager.
+ std::vector<ViewTreeNode*>::const_iterator it = manager_->roots().begin();
+ for (; it != manager_->roots().end(); ++it) {
+ if (*it == root || (*it)->Contains(root))
+ return;
+ }
+ manager_->roots_.push_back(root);
+ root->AddObserver(new RootObserver(root));
+ manager_->root_added_callback_.Run(manager_);
+}
+
+void ViewManagerPrivate::RemoveRoot(ViewTreeNode* root) {
+ std::vector<ViewTreeNode*>::iterator it =
+ std::find(manager_->roots_.begin(), manager_->roots_.end(), root);
+ if (it != manager_->roots_.end())
+ manager_->roots_.erase(it);
+}
+
void ViewManagerPrivate::AddNode(TransportNodeId node_id, ViewTreeNode* node) {
DCHECK(!manager_->nodes_[node_id]);
manager_->nodes_[node_id] = node;

Powered by Google App Engine
This is Rietveld 408576698