| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "examples/wm_flow/wm/frame_controller.h" | |
| 6 #include "mojo/application/application_runner_chromium.h" | |
| 7 #include "mojo/public/c/system/main.h" | |
| 8 #include "mojo/public/cpp/application/application_delegate.h" | |
| 9 #include "mojo/public/cpp/application/application_impl.h" | |
| 10 #include "mojo/public/cpp/application/service_provider_impl.h" | |
| 11 #include "mojo/services/input_events/interfaces/input_events.mojom.h" | |
| 12 #include "mojo/services/view_manager/cpp/view_manager.h" | |
| 13 #include "mojo/services/view_manager/cpp/view_manager_delegate.h" | |
| 14 #include "mojo/services/view_manager/cpp/view_observer.h" | |
| 15 #include "services/window_manager/basic_focus_rules.h" | |
| 16 #include "services/window_manager/window_manager_app.h" | |
| 17 #include "services/window_manager/window_manager_delegate.h" | |
| 18 #include "services/window_manager/window_manager_root.h" | |
| 19 #include "url/gurl.h" | |
| 20 | |
| 21 namespace examples { | |
| 22 | |
| 23 // TODO(johngro) : investigate extending mojom with a formal flags type which it | |
| 24 // generates good bindings for, so we don't need to resort to this. | |
| 25 static inline constexpr bool operator &(const mojo::EventFlags& f1, | |
| 26 const mojo::EventFlags& f2) { | |
| 27 return ((static_cast<uint32_t>(f1) & static_cast<uint32_t>(f2)) != 0); | |
| 28 } | |
| 29 | |
| 30 class SimpleWMController : public window_manager::WindowManagerController, | |
| 31 public mojo::ViewObserver { | |
| 32 public: | |
| 33 SimpleWMController(window_manager::WindowManagerRoot* wm_root) | |
| 34 : window_manager_root_(wm_root), | |
| 35 root_(NULL), | |
| 36 window_container_(NULL), | |
| 37 next_window_origin_(10, 10) {} | |
| 38 ~SimpleWMController() override {} | |
| 39 | |
| 40 private: | |
| 41 // Overridden from mojo::ViewManagerDelegate: | |
| 42 void OnEmbed(mojo::View* root, | |
| 43 mojo::InterfaceRequest<mojo::ServiceProvider> services, | |
| 44 mojo::ServiceProviderPtr exposed_services) override { | |
| 45 root_ = root; | |
| 46 | |
| 47 window_container_ = root->view_manager()->CreateView(); | |
| 48 window_container_->SetBounds(root_->bounds()); | |
| 49 root_->AddChild(window_container_); | |
| 50 window_container_->SetVisible(true); | |
| 51 | |
| 52 window_manager_root_->InitFocus(make_scoped_ptr( | |
| 53 new window_manager::BasicFocusRules(window_container_))); | |
| 54 } | |
| 55 void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override { | |
| 56 root_ = NULL; | |
| 57 } | |
| 58 | |
| 59 // Overridden from mojo::WindowManagerDelegate: | |
| 60 void Embed(const mojo::String& url, | |
| 61 mojo::InterfaceRequest<mojo::ServiceProvider> services, | |
| 62 mojo::ServiceProviderPtr exposed_services) override { | |
| 63 DCHECK(root_); | |
| 64 mojo::View* app_view = NULL; | |
| 65 CreateTopLevelWindow(&app_view); | |
| 66 app_view->Embed(url, services.Pass(), exposed_services.Pass()); | |
| 67 } | |
| 68 | |
| 69 // Overridden from mojo::ViewObserver: | |
| 70 void OnViewInputEvent(mojo::View* view, | |
| 71 const mojo::EventPtr& event) override { | |
| 72 if (event->action == mojo::EventType::POINTER_UP && | |
| 73 event->flags & mojo::EventFlags::RIGHT_MOUSE_BUTTON && | |
| 74 view->parent() == window_container_) { | |
| 75 CloseWindow(view); | |
| 76 } | |
| 77 } | |
| 78 void OnViewDestroyed(mojo::View* view) override { | |
| 79 view->RemoveObserver(this); | |
| 80 } | |
| 81 | |
| 82 void CloseWindow(mojo::View* view) { | |
| 83 mojo::View* first_child = view->children().front(); | |
| 84 first_child->Destroy(); | |
| 85 view->Destroy(); | |
| 86 next_window_origin_.Offset(-50, -50); | |
| 87 } | |
| 88 | |
| 89 mojo::View* CreateTopLevelWindow(mojo::View** app_view) { | |
| 90 mojo::View* frame_view = root_->view_manager()->CreateView(); | |
| 91 // Add the View to it's parent before showing so that animations can happen. | |
| 92 window_container_->AddChild(frame_view); | |
| 93 mojo::Rect rect; | |
| 94 rect.x = next_window_origin_.x(); | |
| 95 rect.y = next_window_origin_.y(); | |
| 96 rect.width = rect.height = 400; | |
| 97 frame_view->SetBounds(rect); | |
| 98 next_window_origin_.Offset(50, 50); | |
| 99 | |
| 100 GURL frame_url = url_.Resolve("/examples/wm_flow/wm/window_frame.sky"); | |
| 101 new FrameController(frame_url, frame_view, app_view, window_manager_root_); | |
| 102 return frame_view; | |
| 103 } | |
| 104 | |
| 105 window_manager::WindowManagerRoot* window_manager_root_; | |
| 106 | |
| 107 GURL url_; | |
| 108 mojo::View* root_; | |
| 109 mojo::View* window_container_; | |
| 110 | |
| 111 gfx::Point next_window_origin_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(SimpleWMController); | |
| 114 }; | |
| 115 | |
| 116 class SimpleWM : public mojo::ApplicationDelegate, | |
| 117 public window_manager::WindowManagerControllerFactory { | |
| 118 public: | |
| 119 SimpleWM() | |
| 120 : window_manager_app_(new window_manager::WindowManagerApp(this)) {} | |
| 121 | |
| 122 protected: | |
| 123 ~SimpleWM() override {} | |
| 124 | |
| 125 private: | |
| 126 // Overridden from mojo::ApplicationDelegate: | |
| 127 void Initialize(mojo::ApplicationImpl* impl) override { | |
| 128 // FIXME: Mojo applications don't know their URLs yet: | |
| 129 // https://docs.google.com/a/chromium.org/document/d/1AQ2y6ekzvbdaMF5WrUQmne
yXJnke-MnYYL4Gz1AKDos | |
| 130 url_ = GURL(impl->args()[1]); | |
| 131 window_manager_app_->Initialize(impl); | |
| 132 } | |
| 133 | |
| 134 bool ConfigureIncomingConnection( | |
| 135 mojo::ApplicationConnection* connection) override { | |
| 136 window_manager_app_->ConfigureIncomingConnection(connection); | |
| 137 return true; | |
| 138 } | |
| 139 | |
| 140 scoped_ptr<window_manager::WindowManagerController> | |
| 141 CreateWindowManagerController( | |
| 142 mojo::ApplicationConnection* connection, | |
| 143 window_manager::WindowManagerRoot* wm_root) override { | |
| 144 return scoped_ptr<window_manager::WindowManagerController>( | |
| 145 new SimpleWMController(wm_root)); | |
| 146 } | |
| 147 | |
| 148 scoped_ptr<window_manager::WindowManagerApp> window_manager_app_; | |
| 149 GURL url_; | |
| 150 | |
| 151 DISALLOW_COPY_AND_ASSIGN(SimpleWM); | |
| 152 }; | |
| 153 | |
| 154 } // namespace examples | |
| 155 | |
| 156 MojoResult MojoMain(MojoHandle application_request) { | |
| 157 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM); | |
| 158 return runner.Run(application_request); | |
| 159 } | |
| OLD | NEW |