diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 19:01:47 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 19:01:47 +0000 |
commit | d7c088c65013381ad28743eb825683feab994133 (patch) | |
tree | e3cc89476193cd4b90915b3666d38d27911af5fe /mojo/examples/wm_flow | |
parent | 90e3b587f2001eaffbd13e83ab9d18ed778dbc6e (diff) | |
download | chromium_src-d7c088c65013381ad28743eb825683feab994133.zip chromium_src-d7c088c65013381ad28743eb825683feab994133.tar.gz chromium_src-d7c088c65013381ad28743eb825683feab994133.tar.bz2 |
As discussed, a new WM bootstrap flow.
First off, create a new window manager app (wm_flow_wm) which uses the core_window_manager_lib static lib to implement a basic WM.
Second, create a new demo launcher (wm_flow_init) that starts the view manager, embeds wm_flow_wm, and starts an additional app (wm_flow_app).
Thirdly, creates an additional app (wm_flow_app) that also connects to the view manager init service and asks it to embed it somewhere, thus giving it a connection to the view manager (and a top-level window).
I had to change ViewManagerInitService to have some shared state so that it was possible to connect to it > 1 time.
R=sky@chromium.org
BUG=none
Review URL: https://codereview.chromium.org/400113005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285345 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/examples/wm_flow')
-rw-r--r-- | mojo/examples/wm_flow/app/DEPS | 0 | ||||
-rw-r--r-- | mojo/examples/wm_flow/app/app.cc | 77 | ||||
-rw-r--r-- | mojo/examples/wm_flow/init/init.cc | 48 | ||||
-rw-r--r-- | mojo/examples/wm_flow/wm/DEPS | 0 | ||||
-rw-r--r-- | mojo/examples/wm_flow/wm/wm.cc | 89 |
5 files changed, 214 insertions, 0 deletions
diff --git a/mojo/examples/wm_flow/app/DEPS b/mojo/examples/wm_flow/app/DEPS new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/mojo/examples/wm_flow/app/DEPS diff --git a/mojo/examples/wm_flow/app/app.cc b/mojo/examples/wm_flow/app/app.cc new file mode 100644 index 0000000..0d6b83f --- /dev/null +++ b/mojo/examples/wm_flow/app/app.cc @@ -0,0 +1,77 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/bind.h" +#include "mojo/public/cpp/application/application_connection.h" +#include "mojo/public/cpp/application/application_delegate.h" +#include "mojo/public/cpp/application/application_impl.h" +#include "mojo/services/public/cpp/view_manager/node.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_client_factory.h" +#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" +#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" + +namespace examples { +namespace { +void ConnectCallback(bool success) {} + +const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW }; + +} // namespace + +// This app starts its life via Connect() rather than by being embed, so it does +// not start with a connection to the ViewManager service. It has to obtain a +// connection by connecting to the ViewManagerInit service and asking to be +// embed without a node context. +class WMFlowApp : public mojo::ApplicationDelegate, + public mojo::view_manager::ViewManagerDelegate { + public: + WMFlowApp() : embed_count_(0), view_manager_client_factory_(this) {} + virtual ~WMFlowApp() {} + + private: + // Overridden from Application: + virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { + mojo::view_manager::ViewManagerInitServicePtr init_svc; + app->ConnectToService("mojo:mojo_view_manager", &init_svc); + init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback)); + init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback)); + init_svc->Embed("mojo:mojo_wm_flow_app", base::Bind(&ConnectCallback)); + } + virtual bool ConfigureIncomingConnection( + mojo::ApplicationConnection* connection) MOJO_OVERRIDE { + connection->AddService(&view_manager_client_factory_); + return true; + } + + void OnConnect(bool success) {} + + // Overridden from mojo::view_manager::ViewManagerDelegate: + virtual void OnRootAdded(mojo::view_manager::ViewManager* view_manager, + mojo::view_manager::Node* root) MOJO_OVERRIDE { + mojo::view_manager::View* view = + mojo::view_manager::View::Create(view_manager); + root->SetActiveView(view); + view->SetColor(kColors[embed_count_++ % arraysize(kColors)]); + } + virtual void OnViewManagerDisconnected( + mojo::view_manager::ViewManager* view_manager) MOJO_OVERRIDE {} + + int embed_count_; + mojo::view_manager::ViewManagerClientFactory view_manager_client_factory_; + + DISALLOW_COPY_AND_ASSIGN(WMFlowApp); +}; + +} // namespace examples + +namespace mojo { + +// static +ApplicationDelegate* ApplicationDelegate::Create() { + return new examples::WMFlowApp; +} + +} // namespace diff --git a/mojo/examples/wm_flow/init/init.cc b/mojo/examples/wm_flow/init/init.cc new file mode 100644 index 0000000..da54305 --- /dev/null +++ b/mojo/examples/wm_flow/init/init.cc @@ -0,0 +1,48 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/bind.h" +#include "mojo/public/cpp/application/application_delegate.h" +#include "mojo/public/cpp/application/application_impl.h" +#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" + +namespace examples { +namespace { +void ConnectCallback(bool success) {} +} // namespace + +// This application starts the view manager, embeds the window manager and then +// starts another app (wm_flow_app) which also connects to the view manager and +// asks to be embedded without context. +class WMFlowInit : public mojo::ApplicationDelegate { + public: + WMFlowInit() {} + virtual ~WMFlowInit() {} + + private: + // Overridden from Application: + virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { + app->ConnectToService("mojo:mojo_view_manager", &view_manager_init_); + view_manager_init_->Embed("mojo:mojo_wm_flow_wm", + base::Bind(&ConnectCallback)); + app->ConnectToApplication("mojo:mojo_wm_flow_app"); + } + + void OnConnect(bool success) {} + + mojo::view_manager::ViewManagerInitServicePtr view_manager_init_; + + DISALLOW_COPY_AND_ASSIGN(WMFlowInit); +}; + +} // namespace examples + +namespace mojo { + +// static +ApplicationDelegate* ApplicationDelegate::Create() { + return new examples::WMFlowInit; +} + +} // namespace diff --git a/mojo/examples/wm_flow/wm/DEPS b/mojo/examples/wm_flow/wm/DEPS new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/mojo/examples/wm_flow/wm/DEPS diff --git a/mojo/examples/wm_flow/wm/wm.cc b/mojo/examples/wm_flow/wm/wm.cc new file mode 100644 index 0000000..197ad0f --- /dev/null +++ b/mojo/examples/wm_flow/wm/wm.cc @@ -0,0 +1,89 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "mojo/public/cpp/application/application_delegate.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/window_manager_delegate.h" +#include "mojo/services/window_manager/window_manager_app.h" + +namespace examples { + +class SimpleWM : public mojo::ApplicationDelegate, + public mojo::view_manager::ViewManagerDelegate, + public mojo::view_manager::WindowManagerDelegate { + public: + SimpleWM() + : window_manager_app_(new mojo::WindowManagerApp(this)), + view_manager_(NULL), + root_(NULL), + window_container_(NULL), + next_window_origin_(10, 10) {} + virtual ~SimpleWM() {} + + private: + // Overridden from mojo::ApplicationDelegate: + virtual void Initialize(mojo::ApplicationImpl* impl) MOJO_OVERRIDE { + window_manager_app_->Initialize(impl); + } + virtual bool ConfigureIncomingConnection( + mojo::ApplicationConnection* connection) MOJO_OVERRIDE { + window_manager_app_->ConfigureIncomingConnection(connection); + return true; + } + + // Overridden from mojo::view_manager::ViewManagerDelegate: + virtual void OnRootAdded( + mojo::view_manager::ViewManager* view_manager, + mojo::view_manager::Node* root) MOJO_OVERRIDE { + view_manager_ = view_manager; + root_ = root; + view_manager_->SetWindowManagerDelegate(this); + + window_container_ = mojo::view_manager::Node::Create(view_manager_); + window_container_->SetBounds(root_->bounds()); + root_->AddChild(window_container_); + + } + virtual void OnViewManagerDisconnected( + mojo::view_manager::ViewManager* view_manager) MOJO_OVERRIDE { + view_manager_ = NULL; + root_ = NULL; + } + + // Overridden from mojo::view_manager::WindowManagerDelegate: + virtual void Embed(const mojo::String& url) MOJO_OVERRIDE { + mojo::view_manager::Node* embed_node = + mojo::view_manager::Node::Create(view_manager_); + embed_node->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400))); + window_container_->AddChild(embed_node); + embed_node->Embed(url); + next_window_origin_.Offset(50, 50); + } + virtual void DispatchEvent(mojo::view_manager::View* target, + mojo::EventPtr event) MOJO_OVERRIDE { + view_manager_->DispatchEvent(target, event.Pass()); + } + + scoped_ptr<mojo::WindowManagerApp> window_manager_app_; + + mojo::view_manager::ViewManager* view_manager_; + mojo::view_manager::Node* root_; + mojo::view_manager::Node* window_container_; + + gfx::Point next_window_origin_; + + DISALLOW_COPY_AND_ASSIGN(SimpleWM); +}; + +} // namespace examples + +namespace mojo { + +// static +ApplicationDelegate* ApplicationDelegate::Create() { + return new examples::SimpleWM; +} + +} // namespace |