X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fmojo%2Fexamples%2Fwm_flow%2Fwm%2Fwm.cc;h=bf4cafc7bafda143846822f1a6eaf2145650155b;hb=3545e9f2671f595d2a2f3ee75ca0393b01e35ef6;hp=023c44b4f400385d7ae7e9891af0daad9c5e0284;hpb=7d210d4c7e9ba36e635eabc5b5780495f8a63292;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/mojo/examples/wm_flow/wm/wm.cc b/src/mojo/examples/wm_flow/wm/wm.cc index 023c44b..bf4cafc 100644 --- a/src/mojo/examples/wm_flow/wm/wm.cc +++ b/src/mojo/examples/wm_flow/wm/wm.cc @@ -2,18 +2,26 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "mojo/application/application_runner_chromium.h" +#include "mojo/examples/wm_flow/wm/frame_controller.h" +#include "mojo/public/c/system/main.h" #include "mojo/public/cpp/application/application_delegate.h" +#include "mojo/public/cpp/application/application_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_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/interfaces/input_events/input_events.mojom.h" #include "mojo/services/window_manager/window_manager_app.h" +#include "mojo/views/views_init.h" namespace examples { class SimpleWM : public mojo::ApplicationDelegate, public mojo::ViewManagerDelegate, - public mojo::WindowManagerDelegate { + public mojo::WindowManagerDelegate, + public mojo::ViewObserver { public: SimpleWM() : window_manager_app_(new mojo::WindowManagerApp(this, this)), @@ -59,20 +67,48 @@ class SimpleWM : public mojo::ApplicationDelegate, const mojo::String& url, mojo::InterfaceRequest service_provider) MOJO_OVERRIDE { - mojo::View* embed_view = mojo::View::Create(view_manager_); - embed_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400))); - window_container_->AddChild(embed_view); + mojo::View* app_view = NULL; + mojo::View* frame_view = CreateTopLevelWindow(&app_view); + window_container_->AddChild(frame_view); // TODO(beng): We're dropping the |service_provider| passed from the client // on the floor here and passing our own. Seems like we should // be sending both. I'm not yet sure how this sould work for // N levels of proxying. - embed_view->Embed(url, scoped_ptr( + app_view->Embed(url, scoped_ptr( new mojo::ServiceProviderImpl).Pass()); - next_window_origin_.Offset(50, 50); } 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); + } + + mojo::View* CreateTopLevelWindow(mojo::View** app_view) { + mojo::View* frame_view = mojo::View::Create(view_manager_); + frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400))); + next_window_origin_.Offset(50, 50); + + new FrameController(frame_view, app_view); + return frame_view; + } + scoped_ptr window_manager_app_; mojo::ViewManager* view_manager_; @@ -86,11 +122,8 @@ class SimpleWM : public mojo::ApplicationDelegate, } // namespace examples -namespace mojo { - -// static -ApplicationDelegate* ApplicationDelegate::Create() { - return new examples::SimpleWM; +MojoResult MojoMain(MojoHandle shell_handle) { + mojo::ViewsInit views_init; + mojo::ApplicationRunnerChromium runner(new examples::SimpleWM); + return runner.Run(shell_handle); } - -} // namespace