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

Unified Diff: mojo/examples/embedded_app/embedded_app.cc

Issue 311373005: Nesting (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
« no previous file with comments | « no previous file | mojo/examples/nesting_app/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/examples/embedded_app/embedded_app.cc
diff --git a/mojo/examples/embedded_app/embedded_app.cc b/mojo/examples/embedded_app/embedded_app.cc
index ea1460b219dfbaccf5409473b81c7201cbe40544..3f463072b62e098f08e683d8316bb56e46657066 100644
--- a/mojo/examples/embedded_app/embedded_app.cc
+++ b/mojo/examples/embedded_app/embedded_app.cc
@@ -8,6 +8,7 @@
#include "mojo/public/cpp/application/application.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"
#include "mojo/services/public/cpp/view_manager/view_observer.h"
#include "mojo/services/public/cpp/view_manager/view_tree_node.h"
#include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h"
@@ -15,6 +16,7 @@
using mojo::view_manager::View;
using mojo::view_manager::ViewManager;
+using mojo::view_manager::ViewManagerDelegate;
using mojo::view_manager::ViewObserver;
using mojo::view_manager::ViewTreeNode;
using mojo::view_manager::ViewTreeNodeObserver;
@@ -31,21 +33,38 @@ const SkColor kColors[] = { SK_ColorYELLOW,
} // namespace
class EmbeddedApp : public Application,
+ public ViewManagerDelegate,
public ViewObserver,
public ViewTreeNodeObserver {
public:
- EmbeddedApp() : view_manager_(NULL) {}
+ EmbeddedApp() {}
virtual ~EmbeddedApp() {}
private:
// Overridden from Application:
virtual void Initialize() MOJO_OVERRIDE {
- ViewManager::Create(this,
- base::Bind(&EmbeddedApp::OnRootAdded, base::Unretained(this)),
- base::Bind(&EmbeddedApp::OnRootRemoved, base::Unretained(this)));
+ ViewManager::Create(this, this);
ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_);
}
+ // Overridden from ViewManagerDelegate:
+ virtual void OnRootAdded(ViewManager* view_manager,
+ ViewTreeNode* root) OVERRIDE {
+ View* view = View::Create(view_manager);
+ view->AddObserver(this);
+ root->SetActiveView(view);
+ root->AddObserver(this);
+ size_t index = view_manager->roots().size() - 1;
+ view->SetColor(kColors[index % arraysize(kColors)]);
+ }
+ virtual void OnRootRemoved(ViewManager* view_manager,
+ ViewTreeNode* root) OVERRIDE {
+ std::map<ViewTreeNode*, View*>::const_iterator it =
+ views_to_reap_.find(root);
+ if (it != views_to_reap_.end())
+ it->second->Destroy();
+ }
+
// Overridden from ViewObserver:
virtual void OnViewInputEvent(View* view, EventPtr event) OVERRIDE {
if (event->action == ui::ET_MOUSE_RELEASED)
@@ -62,29 +81,7 @@ class EmbeddedApp : public Application,
views_to_reap_[node] = old_view;
}
- void OnRootAdded(ViewManager* view_manager, ViewTreeNode* root) {
- if (!view_manager_)
- view_manager_ = view_manager;
- DCHECK_EQ(view_manager_, view_manager);
-
- View* view = View::Create(view_manager_);
- view->AddObserver(this);
- root->SetActiveView(view);
- root->AddObserver(this);
- size_t index = view_manager_->roots().size() - 1;
- view->SetColor(kColors[index % arraysize(kColors)]);
- }
-
- void OnRootRemoved(ViewManager* view_manager,
- ViewTreeNode* root) {
- std::map<ViewTreeNode*, View*>::const_iterator it =
- views_to_reap_.find(root);
- if (it != views_to_reap_.end())
- it->second->Destroy();
- }
-
IWindowManagerPtr window_manager_;
- ViewManager* view_manager_;
std::map<ViewTreeNode*, View*> views_to_reap_;
DISALLOW_COPY_AND_ASSIGN(EmbeddedApp);
« no previous file with comments | « no previous file | mojo/examples/nesting_app/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698