| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/public/cpp/application/application_delegate.h" | 5 #include "mojo/public/cpp/application/application_delegate.h" |
| 6 #include "mojo/public/cpp/application/service_provider_impl.h" | 6 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 7 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 7 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 8 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 8 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 9 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 9 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" | 10 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" |
| 11 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" |
| 10 #include "mojo/services/window_manager/window_manager_app.h" | 12 #include "mojo/services/window_manager/window_manager_app.h" |
| 11 | 13 |
| 12 namespace examples { | 14 namespace examples { |
| 13 | 15 |
| 14 class SimpleWM : public mojo::ApplicationDelegate, | 16 class SimpleWM : public mojo::ApplicationDelegate, |
| 15 public mojo::ViewManagerDelegate, | 17 public mojo::ViewManagerDelegate, |
| 16 public mojo::WindowManagerDelegate { | 18 public mojo::WindowManagerDelegate, |
| 19 public mojo::ViewObserver { |
| 17 public: | 20 public: |
| 18 SimpleWM() | 21 SimpleWM() |
| 19 : window_manager_app_(new mojo::WindowManagerApp(this, this)), | 22 : window_manager_app_(new mojo::WindowManagerApp(this, this)), |
| 20 view_manager_(NULL), | 23 view_manager_(NULL), |
| 21 root_(NULL), | 24 root_(NULL), |
| 22 window_container_(NULL), | 25 window_container_(NULL), |
| 23 next_window_origin_(10, 10) {} | 26 next_window_origin_(10, 10) {} |
| 24 virtual ~SimpleWM() {} | 27 virtual ~SimpleWM() {} |
| 25 | 28 |
| 26 private: | 29 private: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 mojo::ViewManager* view_manager) MOJO_OVERRIDE { | 55 mojo::ViewManager* view_manager) MOJO_OVERRIDE { |
| 53 view_manager_ = NULL; | 56 view_manager_ = NULL; |
| 54 root_ = NULL; | 57 root_ = NULL; |
| 55 } | 58 } |
| 56 | 59 |
| 57 // Overridden from mojo::WindowManagerDelegate: | 60 // Overridden from mojo::WindowManagerDelegate: |
| 58 virtual void Embed( | 61 virtual void Embed( |
| 59 const mojo::String& url, | 62 const mojo::String& url, |
| 60 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) | 63 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) |
| 61 MOJO_OVERRIDE { | 64 MOJO_OVERRIDE { |
| 65 mojo::View* frame_view = mojo::View::Create(view_manager_); |
| 66 window_container_->AddChild(frame_view); |
| 67 frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400))); |
| 68 frame_view->SetColor(SK_ColorBLUE); |
| 69 frame_view->AddObserver(this); |
| 70 |
| 62 mojo::View* embed_view = mojo::View::Create(view_manager_); | 71 mojo::View* embed_view = mojo::View::Create(view_manager_); |
| 63 embed_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400))); | 72 gfx::Rect client_bounds(frame_view->bounds().size()); |
| 64 window_container_->AddChild(embed_view); | 73 client_bounds.Inset(10, 30, 10, 10); |
| 74 embed_view->SetBounds(client_bounds); |
| 75 frame_view->AddChild(embed_view); |
| 65 | 76 |
| 66 // TODO(beng): We're dropping the |service_provider| passed from the client | 77 // TODO(beng): We're dropping the |service_provider| passed from the client |
| 67 // on the floor here and passing our own. Seems like we should | 78 // on the floor here and passing our own. Seems like we should |
| 68 // be sending both. I'm not yet sure how this sould work for | 79 // be sending both. I'm not yet sure how this sould work for |
| 69 // N levels of proxying. | 80 // N levels of proxying. |
| 70 embed_view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>( | 81 embed_view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>( |
| 71 new mojo::ServiceProviderImpl).Pass()); | 82 new mojo::ServiceProviderImpl).Pass()); |
| 72 next_window_origin_.Offset(50, 50); | 83 next_window_origin_.Offset(50, 50); |
| 73 } | 84 } |
| 74 virtual void DispatchEvent(mojo::EventPtr event) MOJO_OVERRIDE {} | 85 virtual void DispatchEvent(mojo::EventPtr event) MOJO_OVERRIDE {} |
| 75 | 86 |
| 87 // Overridden from mojo::ViewObserver: |
| 88 virtual void OnViewInputEvent(mojo::View* view, |
| 89 const mojo::EventPtr& event) MOJO_OVERRIDE { |
| 90 if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED && |
| 91 event->flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON && |
| 92 view->parent() == window_container_) { |
| 93 CloseWindow(view); |
| 94 } |
| 95 } |
| 96 virtual void OnViewDestroyed(mojo::View* view) MOJO_OVERRIDE { |
| 97 view->RemoveObserver(this); |
| 98 } |
| 99 |
| 100 void CloseWindow(mojo::View* view) { |
| 101 mojo::View* first_child = view->children().front(); |
| 102 first_child->Destroy(); |
| 103 view->Destroy(); |
| 104 next_window_origin_.Offset(-50, -50); |
| 105 } |
| 106 |
| 76 scoped_ptr<mojo::WindowManagerApp> window_manager_app_; | 107 scoped_ptr<mojo::WindowManagerApp> window_manager_app_; |
| 77 | 108 |
| 78 mojo::ViewManager* view_manager_; | 109 mojo::ViewManager* view_manager_; |
| 79 mojo::View* root_; | 110 mojo::View* root_; |
| 80 mojo::View* window_container_; | 111 mojo::View* window_container_; |
| 81 | 112 |
| 82 gfx::Point next_window_origin_; | 113 gfx::Point next_window_origin_; |
| 83 | 114 |
| 84 DISALLOW_COPY_AND_ASSIGN(SimpleWM); | 115 DISALLOW_COPY_AND_ASSIGN(SimpleWM); |
| 85 }; | 116 }; |
| 86 | 117 |
| 87 } // namespace examples | 118 } // namespace examples |
| 88 | 119 |
| 89 namespace mojo { | 120 namespace mojo { |
| 90 | 121 |
| 91 // static | 122 // static |
| 92 ApplicationDelegate* ApplicationDelegate::Create() { | 123 ApplicationDelegate* ApplicationDelegate::Create() { |
| 93 return new examples::SimpleWM; | 124 return new examples::SimpleWM; |
| 94 } | 125 } |
| 95 | 126 |
| 96 } // namespace | 127 } // namespace |
| OLD | NEW |