Commit bcfefe84 authored by ben@chromium.org's avatar ben@chromium.org

Add some trivial window decorations & window closing back to the demo window manager

R=sky@chromium.org
BUG=

Review URL: https://codereview.chromium.org/478833002

Cr-Commit-Position: refs/heads/master@{#290120}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290120 0039d316-1c4b-4281-b951-d872f2087c98
parent 11ff4675
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "mojo/services/public/cpp/view_manager/view_manager.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_client_factory.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.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/interfaces/view_manager/view_manager.mojom.h" #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
namespace examples { namespace examples {
...@@ -45,21 +46,22 @@ class EmbedderImpl : public mojo::InterfaceImpl<Embedder> { ...@@ -45,21 +46,22 @@ class EmbedderImpl : public mojo::InterfaceImpl<Embedder> {
// connection by connecting to the ViewManagerInit service and asking to be // connection by connecting to the ViewManagerInit service and asking to be
// embed without a view context. // embed without a view context.
class WMFlowApp : public mojo::ApplicationDelegate, class WMFlowApp : public mojo::ApplicationDelegate,
public mojo::ViewManagerDelegate { public mojo::ViewManagerDelegate,
public mojo::ViewObserver {
public: public:
WMFlowApp() WMFlowApp()
: embed_count_(0), : embed_count_(0),
view_manager_client_factory_(this) {} view_manager_client_factory_(this),
app_(NULL) {}
virtual ~WMFlowApp() {} virtual ~WMFlowApp() {}
private: private:
// Overridden from Application: // Overridden from Application:
virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE {
mojo::ServiceProviderPtr sp; app_ = app;
mojo::ViewManagerInitServicePtr init_svc; OpenNewWindow();
app->ConnectToService("mojo:mojo_view_manager", &init_svc); OpenNewWindow();
init_svc->Embed("mojo:mojo_wm_flow_app", sp.Pass(), OpenNewWindow();
base::Bind(&ConnectCallback));
} }
virtual bool ConfigureIncomingConnection( virtual bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) MOJO_OVERRIDE { mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
...@@ -75,11 +77,12 @@ class WMFlowApp : public mojo::ApplicationDelegate, ...@@ -75,11 +77,12 @@ class WMFlowApp : public mojo::ApplicationDelegate,
mojo::View* root, mojo::View* root,
mojo::ServiceProviderImpl* exported_services, mojo::ServiceProviderImpl* exported_services,
scoped_ptr<mojo::ServiceProvider> imported_services) MOJO_OVERRIDE { scoped_ptr<mojo::ServiceProvider> imported_services) MOJO_OVERRIDE {
root->AddObserver(this);
root->SetColor(kColors[embed_count_++ % arraysize(kColors)]); root->SetColor(kColors[embed_count_++ % arraysize(kColors)]);
mojo::View* embed = mojo::View::Create(view_manager); mojo::View* embed = mojo::View::Create(view_manager);
root->AddChild(embed); root->AddChild(embed);
gfx::Rect bounds = root->bounds(); gfx::Rect bounds = gfx::Rect(root->bounds().size());
bounds.Inset(25, 25); bounds.Inset(25, 25);
embed->SetBounds(bounds); embed->SetBounds(bounds);
...@@ -96,14 +99,36 @@ class WMFlowApp : public mojo::ApplicationDelegate, ...@@ -96,14 +99,36 @@ class WMFlowApp : public mojo::ApplicationDelegate,
virtual void OnViewManagerDisconnected( virtual void OnViewManagerDisconnected(
mojo::ViewManager* view_manager) MOJO_OVERRIDE {} mojo::ViewManager* view_manager) MOJO_OVERRIDE {}
// Overridden from mojo::ViewObserver:
virtual void OnViewInputEvent(mojo::View* view,
const mojo::EventPtr& event) MOJO_OVERRIDE {
if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED &&
event->flags & mojo::EVENT_FLAGS_LEFT_MOUSE_BUTTON) {
OpenNewWindow();
}
}
virtual void OnViewDestroyed(mojo::View* view) MOJO_OVERRIDE {
--embed_count_;
view->RemoveObserver(this);
}
void HelloBackAck() { void HelloBackAck() {
printf("HelloBack() ack'ed\n"); printf("HelloBack() ack'ed\n");
} }
void OpenNewWindow() {
mojo::ViewManagerInitServicePtr init_svc;
app_->ConnectToService("mojo:mojo_view_manager", &init_svc);
mojo::ServiceProviderPtr sp;
init_svc->Embed("mojo:mojo_wm_flow_app", sp.Pass(),
base::Bind(&ConnectCallback));
}
int embed_count_; int embed_count_;
mojo::ViewManagerClientFactory view_manager_client_factory_; mojo::ViewManagerClientFactory view_manager_client_factory_;
mojo::InterfaceFactoryImpl<EmbedderImpl> embedder_factory_; mojo::InterfaceFactoryImpl<EmbedderImpl> embedder_factory_;
EmbeddeePtr embeddee_; EmbeddeePtr embeddee_;
mojo::ApplicationImpl* app_;
DISALLOW_COPY_AND_ASSIGN(WMFlowApp); DISALLOW_COPY_AND_ASSIGN(WMFlowApp);
}; };
......
...@@ -6,14 +6,17 @@ ...@@ -6,14 +6,17 @@
#include "mojo/public/cpp/application/service_provider_impl.h" #include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/services/public/cpp/view_manager/view_manager.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_manager_delegate.h"
#include "mojo/services/public/cpp/view_manager/view_observer.h"
#include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
#include "mojo/services/window_manager/window_manager_app.h" #include "mojo/services/window_manager/window_manager_app.h"
namespace examples { namespace examples {
class SimpleWM : public mojo::ApplicationDelegate, class SimpleWM : public mojo::ApplicationDelegate,
public mojo::ViewManagerDelegate, public mojo::ViewManagerDelegate,
public mojo::WindowManagerDelegate { public mojo::WindowManagerDelegate,
public mojo::ViewObserver {
public: public:
SimpleWM() SimpleWM()
: window_manager_app_(new mojo::WindowManagerApp(this, this)), : window_manager_app_(new mojo::WindowManagerApp(this, this)),
...@@ -59,9 +62,17 @@ class SimpleWM : public mojo::ApplicationDelegate, ...@@ -59,9 +62,17 @@ class SimpleWM : public mojo::ApplicationDelegate,
const mojo::String& url, const mojo::String& url,
mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) mojo::InterfaceRequest<mojo::ServiceProvider> service_provider)
MOJO_OVERRIDE { MOJO_OVERRIDE {
mojo::View* frame_view = mojo::View::Create(view_manager_);
window_container_->AddChild(frame_view);
frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400)));
frame_view->SetColor(SK_ColorBLUE);
frame_view->AddObserver(this);
mojo::View* embed_view = mojo::View::Create(view_manager_); mojo::View* embed_view = mojo::View::Create(view_manager_);
embed_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400))); gfx::Rect client_bounds(frame_view->bounds().size());
window_container_->AddChild(embed_view); client_bounds.Inset(10, 30, 10, 10);
embed_view->SetBounds(client_bounds);
frame_view->AddChild(embed_view);
// TODO(beng): We're dropping the |service_provider| passed from the client // TODO(beng): We're dropping the |service_provider| passed from the client
// on the floor here and passing our own. Seems like we should // on the floor here and passing our own. Seems like we should
...@@ -73,6 +84,26 @@ class SimpleWM : public mojo::ApplicationDelegate, ...@@ -73,6 +84,26 @@ class SimpleWM : public mojo::ApplicationDelegate,
} }
virtual void DispatchEvent(mojo::EventPtr event) MOJO_OVERRIDE {} virtual void DispatchEvent(mojo::EventPtr event) MOJO_OVERRIDE {}
// Overridden from mojo::ViewObserver:
virtual void OnViewInputEvent(mojo::View* view,
const mojo::EventPtr& event) MOJO_OVERRIDE {
if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED &&
event->flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON &&
view->parent() == window_container_) {
CloseWindow(view);
}
}
virtual void OnViewDestroyed(mojo::View* view) MOJO_OVERRIDE {
view->RemoveObserver(this);
}
void CloseWindow(mojo::View* view) {
mojo::View* first_child = view->children().front();
first_child->Destroy();
view->Destroy();
next_window_origin_.Offset(-50, -50);
}
scoped_ptr<mojo::WindowManagerApp> window_manager_app_; scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
mojo::ViewManager* view_manager_; mojo::ViewManager* view_manager_;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ui/aura/window_property.h" #include "ui/aura/window_property.h"
#include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment