| 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/services/window_manager/window_manager_app.h" | 5 #include "mojo/services/window_manager/window_manager_app.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "mojo/aura/aura_init.h" |
| 9 #include "mojo/converters/geometry/geometry_type_converters.h" | 10 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 10 #include "mojo/converters/input_events/input_events_type_converters.h" | 11 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 11 #include "mojo/public/cpp/application/application_connection.h" | 12 #include "mojo/public/cpp/application/application_connection.h" |
| 12 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
| 13 #include "mojo/public/interfaces/application/shell.mojom.h" | 14 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 14 #include "mojo/services/public/cpp/view_manager/view.h" | 15 #include "mojo/services/public/cpp/view_manager/view.h" |
| 15 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 16 #include "mojo/services/window_manager/focus_controller.h" | |
| 17 #include "mojo/services/window_manager/focus_rules.h" | |
| 18 #include "mojo/services/window_manager/view_event_dispatcher.h" | |
| 19 #include "mojo/services/window_manager/view_target.h" | |
| 20 #include "mojo/services/window_manager/view_targeter.h" | |
| 21 #include "mojo/services/window_manager/window_manager_delegate.h" | 17 #include "mojo/services/window_manager/window_manager_delegate.h" |
| 18 #include "ui/aura/window.h" |
| 19 #include "ui/aura/window_delegate.h" |
| 20 #include "ui/aura/window_property.h" |
| 22 #include "ui/base/hit_test.h" | 21 #include "ui/base/hit_test.h" |
| 22 #include "ui/wm/core/capture_controller.h" |
| 23 #include "ui/wm/core/focus_controller.h" |
| 24 #include "ui/wm/public/activation_client.h" |
| 25 |
| 26 DECLARE_WINDOW_PROPERTY_TYPE(mojo::View*); |
| 23 | 27 |
| 24 namespace mojo { | 28 namespace mojo { |
| 25 | 29 |
| 30 // The aura::Windows we use to track Views don't render, so we don't actually |
| 31 // need to supply a fully functional WindowDelegate. We do need to provide _a_ |
| 32 // delegate however, otherwise the event dispatcher won't dispatch events to |
| 33 // these windows. (The aura WindowTargeter won't allow a delegate-less window |
| 34 // to be the target of an event, since the window delegate is considered the |
| 35 // "target handler"). |
| 36 class DummyDelegate : public aura::WindowDelegate { |
| 37 public: |
| 38 DummyDelegate() {} |
| 39 ~DummyDelegate() override {} |
| 40 |
| 41 private: |
| 42 // WindowDelegate overrides: |
| 43 gfx::Size GetMinimumSize() const override { return gfx::Size(); } |
| 44 gfx::Size GetMaximumSize() const override { return gfx::Size(); } |
| 45 void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 46 const gfx::Rect& new_bounds) override {} |
| 47 gfx::NativeCursor GetCursor(const gfx::Point& point) override { |
| 48 return gfx::kNullCursor; |
| 49 } |
| 50 int GetNonClientComponent(const gfx::Point& point) const override { |
| 51 return HTCAPTION; |
| 52 } |
| 53 bool ShouldDescendIntoChildForEventHandling( |
| 54 aura::Window* child, |
| 55 const gfx::Point& location) override { |
| 56 return true; |
| 57 } |
| 58 bool CanFocus() override { return true; } |
| 59 void OnCaptureLost() override {} |
| 60 void OnPaint(gfx::Canvas* canvas) override {} |
| 61 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
| 62 void OnWindowDestroying(aura::Window* window) override {} |
| 63 void OnWindowDestroyed(aura::Window* window) override {} |
| 64 void OnWindowTargetVisibilityChanged(bool visible) override {} |
| 65 bool HasHitTestMask() const override { return false; } |
| 66 void GetHitTestMask(gfx::Path* mask) const override {} |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(DummyDelegate); |
| 69 }; |
| 70 |
| 26 namespace { | 71 namespace { |
| 27 | 72 |
| 28 Id GetIdForView(View* view) { | 73 DEFINE_WINDOW_PROPERTY_KEY(View*, kViewKey, NULL); |
| 29 return view ? view->id() : 0; | 74 |
| 75 Id GetIdForWindow(aura::Window* window) { |
| 76 return window ? WindowManagerApp::GetViewForWindow(window)->id() : 0; |
| 30 } | 77 } |
| 31 | 78 |
| 32 } // namespace | 79 } // namespace |
| 33 | 80 |
| 34 class WindowManagerApp::WindowManagerInternalImpl | 81 class WindowManagerApp::WindowManagerInternalImpl |
| 35 : public InterfaceImpl<WindowManagerInternal> { | 82 : public InterfaceImpl<WindowManagerInternal> { |
| 36 public: | 83 public: |
| 37 WindowManagerInternalImpl(WindowManagerApp* app) : app_(app) {} | 84 WindowManagerInternalImpl(WindowManagerApp* app) : app_(app) {} |
| 38 ~WindowManagerInternalImpl() override {} | 85 ~WindowManagerInternalImpl() override {} |
| 39 | 86 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 69 // WindowManagerApp, public: | 116 // WindowManagerApp, public: |
| 70 | 117 |
| 71 WindowManagerApp::WindowManagerApp( | 118 WindowManagerApp::WindowManagerApp( |
| 72 ViewManagerDelegate* view_manager_delegate, | 119 ViewManagerDelegate* view_manager_delegate, |
| 73 WindowManagerDelegate* window_manager_delegate) | 120 WindowManagerDelegate* window_manager_delegate) |
| 74 : shell_(nullptr), | 121 : shell_(nullptr), |
| 75 window_manager_factory_(this), | 122 window_manager_factory_(this), |
| 76 native_viewport_event_dispatcher_factory_(this), | 123 native_viewport_event_dispatcher_factory_(this), |
| 77 wrapped_view_manager_delegate_(view_manager_delegate), | 124 wrapped_view_manager_delegate_(view_manager_delegate), |
| 78 window_manager_delegate_(window_manager_delegate), | 125 window_manager_delegate_(window_manager_delegate), |
| 79 view_manager_(nullptr), | 126 view_manager_(NULL), |
| 80 root_(nullptr) { | 127 root_(NULL), |
| 128 dummy_delegate_(new DummyDelegate) { |
| 81 } | 129 } |
| 82 | 130 |
| 83 WindowManagerApp::~WindowManagerApp() { | 131 WindowManagerApp::~WindowManagerApp() { |
| 84 STLDeleteElements(&connections_); | 132 STLDeleteElements(&connections_); |
| 85 } | 133 } |
| 86 | 134 |
| 87 // static | 135 // static |
| 88 View* WindowManagerApp::GetViewForViewTarget(ViewTarget* target) { | 136 View* WindowManagerApp::GetViewForWindow(aura::Window* window) { |
| 89 return target->view(); | 137 return window->GetProperty(kViewKey); |
| 90 } | 138 } |
| 91 | 139 |
| 92 ViewTarget* WindowManagerApp::GetViewTargetForViewId(Id view) { | 140 aura::Window* WindowManagerApp::GetWindowForViewId(Id view) { |
| 93 ViewIdToViewTargetMap::const_iterator it = | 141 ViewIdToWindowMap::const_iterator it = view_id_to_window_map_.find(view); |
| 94 view_id_to_view_target_map_.find(view); | 142 return it != view_id_to_window_map_.end() ? it->second : NULL; |
| 95 return it != view_id_to_view_target_map_.end() ? it->second : nullptr; | |
| 96 } | 143 } |
| 97 | 144 |
| 98 void WindowManagerApp::AddConnection(WindowManagerImpl* connection) { | 145 void WindowManagerApp::AddConnection(WindowManagerImpl* connection) { |
| 99 DCHECK(connections_.find(connection) == connections_.end()); | 146 DCHECK(connections_.find(connection) == connections_.end()); |
| 100 connections_.insert(connection); | 147 connections_.insert(connection); |
| 101 } | 148 } |
| 102 | 149 |
| 103 void WindowManagerApp::RemoveConnection(WindowManagerImpl* connection) { | 150 void WindowManagerApp::RemoveConnection(WindowManagerImpl* connection) { |
| 104 DCHECK(connections_.find(connection) != connections_.end()); | 151 DCHECK(connections_.find(connection) != connections_.end()); |
| 105 connections_.erase(connection); | 152 connections_.erase(connection); |
| 106 } | 153 } |
| 107 | 154 |
| 108 void WindowManagerApp::SetCapture(Id view) { | 155 void WindowManagerApp::SetCapture(Id view) { |
| 109 // TODO(erg): Capture. Another pile of worms that is mixed in here. | 156 capture_client_->capture_client()->SetCapture(GetWindowForViewId(view)); |
| 110 | |
| 111 // capture_client_->capture_client()->SetCapture(GetWindowForViewId(view)); | |
| 112 | |
| 113 // TODO(beng): notify connected clients that capture has changed, probably | 157 // TODO(beng): notify connected clients that capture has changed, probably |
| 114 // by implementing some capture-client observer. | 158 // by implementing some capture-client observer. |
| 115 } | 159 } |
| 116 | 160 |
| 117 void WindowManagerApp::FocusWindow(Id view_id) { | 161 void WindowManagerApp::FocusWindow(Id view) { |
| 118 View* view = view_manager_->GetViewById(view_id); | 162 aura::Window* window = GetWindowForViewId(view); |
| 119 DCHECK(view); | 163 DCHECK(window); |
| 120 focus_controller_->FocusView(view); | 164 focus_client_->FocusWindow(window); |
| 121 } | 165 } |
| 122 | 166 |
| 123 void WindowManagerApp::ActivateWindow(Id view_id) { | 167 void WindowManagerApp::ActivateWindow(Id view) { |
| 124 View* view = view_manager_->GetViewById(view_id); | 168 aura::Window* window = GetWindowForViewId(view); |
| 125 DCHECK(view); | 169 DCHECK(window); |
| 126 focus_controller_->ActivateView(view); | 170 activation_client_->ActivateWindow(window); |
| 127 } | 171 } |
| 128 | 172 |
| 129 bool WindowManagerApp::IsReady() const { | 173 bool WindowManagerApp::IsReady() const { |
| 130 return view_manager_ && root_; | 174 return view_manager_ && root_; |
| 131 } | 175 } |
| 132 | 176 |
| 133 void WindowManagerApp::InitFocus(scoped_ptr<mojo::FocusRules> rules) { | 177 void WindowManagerApp::InitFocus(wm::FocusRules* rules) { |
| 134 focus_controller_.reset(new mojo::FocusController(rules.Pass())); | 178 wm::FocusController* focus_controller = new wm::FocusController(rules); |
| 135 focus_controller_->AddObserver(this); | 179 activation_client_ = focus_controller; |
| 180 focus_client_.reset(focus_controller); |
| 181 aura::client::SetFocusClient(window_tree_host_->window(), focus_controller); |
| 182 aura::client::SetActivationClient(window_tree_host_->window(), |
| 183 focus_controller); |
| 184 |
| 185 focus_client_->AddObserver(this); |
| 186 activation_client_->AddObserver(this); |
| 136 } | 187 } |
| 137 | 188 |
| 138 void WindowManagerApp::Embed( | 189 void WindowManagerApp::Embed( |
| 139 const String& url, | 190 const String& url, |
| 140 InterfaceRequest<ServiceProvider> service_provider) { | 191 InterfaceRequest<ServiceProvider> service_provider) { |
| 141 if (view_manager_) { | 192 if (view_manager_) { |
| 142 window_manager_delegate_->Embed(url, service_provider.Pass()); | 193 window_manager_delegate_->Embed(url, service_provider.Pass()); |
| 143 return; | 194 return; |
| 144 } | 195 } |
| 145 scoped_ptr<PendingEmbed> pending_embed(new PendingEmbed); | 196 scoped_ptr<PendingEmbed> pending_embed(new PendingEmbed); |
| 146 pending_embed->url = url; | 197 pending_embed->url = url; |
| 147 pending_embed->service_provider = service_provider.Pass(); | 198 pending_embed->service_provider = service_provider.Pass(); |
| 148 pending_embeds_.push_back(pending_embed.release()); | 199 pending_embeds_.push_back(pending_embed.release()); |
| 149 } | 200 } |
| 150 | 201 |
| 151 //////////////////////////////////////////////////////////////////////////////// | 202 //////////////////////////////////////////////////////////////////////////////// |
| 152 // WindowManagerApp, ApplicationDelegate implementation: | 203 // WindowManagerApp, ApplicationDelegate implementation: |
| 153 | 204 |
| 154 void WindowManagerApp::Initialize(ApplicationImpl* impl) { | 205 void WindowManagerApp::Initialize(ApplicationImpl* impl) { |
| 155 shell_ = impl->shell(); | 206 shell_ = impl->shell(); |
| 207 aura_init_.reset(new AuraInit); |
| 156 LaunchViewManager(impl); | 208 LaunchViewManager(impl); |
| 157 } | 209 } |
| 158 | 210 |
| 159 bool WindowManagerApp::ConfigureIncomingConnection( | 211 bool WindowManagerApp::ConfigureIncomingConnection( |
| 160 ApplicationConnection* connection) { | 212 ApplicationConnection* connection) { |
| 161 connection->AddService(&window_manager_factory_); | 213 connection->AddService(&window_manager_factory_); |
| 162 return true; | 214 return true; |
| 163 } | 215 } |
| 164 | 216 |
| 165 //////////////////////////////////////////////////////////////////////////////// | 217 //////////////////////////////////////////////////////////////////////////////// |
| 166 // WindowManagerApp, ViewManagerDelegate implementation: | 218 // WindowManagerApp, ViewManagerDelegate implementation: |
| 167 | 219 |
| 168 void WindowManagerApp::OnEmbed(ViewManager* view_manager, | 220 void WindowManagerApp::OnEmbed(ViewManager* view_manager, |
| 169 View* root, | 221 View* root, |
| 170 ServiceProviderImpl* exported_services, | 222 ServiceProviderImpl* exported_services, |
| 171 scoped_ptr<ServiceProvider> imported_services) { | 223 scoped_ptr<ServiceProvider> imported_services) { |
| 172 DCHECK(!view_manager_ && !root_); | 224 DCHECK(!view_manager_ && !root_); |
| 173 view_manager_ = view_manager; | 225 view_manager_ = view_manager; |
| 174 root_ = root; | 226 root_ = root; |
| 175 | 227 |
| 176 view_event_dispatcher_.reset(new ViewEventDispatcher()); | 228 window_tree_host_.reset(new WindowTreeHostMojo(shell_, root_)); |
| 229 window_tree_host_->window()->SetBounds(root->bounds().To<gfx::Rect>()); |
| 230 window_tree_host_->window()->Show(); |
| 177 | 231 |
| 178 RegisterSubtree(root_, nullptr); | 232 RegisterSubtree(root_, window_tree_host_->window()); |
| 179 | 233 |
| 180 // TODO(erg): Also move the capture client over. | 234 capture_client_.reset( |
| 181 // | 235 new wm::ScopedCaptureClient(window_tree_host_->window())); |
| 182 // capture_client_.reset( | |
| 183 // new wm::ScopedCaptureClient(window_tree_host_->window())); | |
| 184 | 236 |
| 185 if (wrapped_view_manager_delegate_) { | 237 if (wrapped_view_manager_delegate_) { |
| 186 wrapped_view_manager_delegate_->OnEmbed( | 238 wrapped_view_manager_delegate_->OnEmbed( |
| 187 view_manager, root, exported_services, imported_services.Pass()); | 239 view_manager, root, exported_services, imported_services.Pass()); |
| 188 } | 240 } |
| 189 | 241 |
| 190 for (PendingEmbed* pending_embed : pending_embeds_) | 242 for (PendingEmbed* pending_embed : pending_embeds_) |
| 191 Embed(pending_embed->url, pending_embed->service_provider.Pass()); | 243 Embed(pending_embed->url, pending_embed->service_provider.Pass()); |
| 192 pending_embeds_.clear(); | 244 pending_embeds_.clear(); |
| 193 } | 245 } |
| 194 | 246 |
| 195 void WindowManagerApp::OnViewManagerDisconnected( | 247 void WindowManagerApp::OnViewManagerDisconnected( |
| 196 ViewManager* view_manager) { | 248 ViewManager* view_manager) { |
| 197 DCHECK_EQ(view_manager_, view_manager); | 249 DCHECK_EQ(view_manager_, view_manager); |
| 198 if (wrapped_view_manager_delegate_) | 250 if (wrapped_view_manager_delegate_) |
| 199 wrapped_view_manager_delegate_->OnViewManagerDisconnected(view_manager); | 251 wrapped_view_manager_delegate_->OnViewManagerDisconnected(view_manager); |
| 200 view_manager_ = nullptr; | 252 view_manager_ = NULL; |
| 201 base::MessageLoop::current()->Quit(); | 253 base::MessageLoop::current()->Quit(); |
| 202 } | 254 } |
| 203 | 255 |
| 204 //////////////////////////////////////////////////////////////////////////////// | 256 //////////////////////////////////////////////////////////////////////////////// |
| 205 // WindowManagerApp, ViewObserver implementation: | 257 // WindowManagerApp, ViewObserver implementation: |
| 206 | 258 |
| 207 void WindowManagerApp::OnTreeChanged( | 259 void WindowManagerApp::OnTreeChanged( |
| 208 const ViewObserver::TreeChangeParams& params) { | 260 const ViewObserver::TreeChangeParams& params) { |
| 209 if (params.receiver != root_) | 261 if (params.receiver != root_) |
| 210 return; | 262 return; |
| 211 DCHECK(params.old_parent || params.new_parent); | 263 DCHECK(params.old_parent || params.new_parent); |
| 212 if (!params.target) | 264 if (!params.target) |
| 213 return; | 265 return; |
| 214 | 266 |
| 215 if (params.new_parent) { | 267 if (params.new_parent) { |
| 216 if (view_id_to_view_target_map_.find(params.target->id()) == | 268 if (view_id_to_window_map_.find(params.target->id()) == |
| 217 view_id_to_view_target_map_.end()) { | 269 view_id_to_window_map_.end()) { |
| 218 ViewIdToViewTargetMap::const_iterator it = | 270 ViewIdToWindowMap::const_iterator it = |
| 219 view_id_to_view_target_map_.find(params.new_parent->id()); | 271 view_id_to_window_map_.find(params.new_parent->id()); |
| 220 DCHECK(it != view_id_to_view_target_map_.end()); | 272 DCHECK(it != view_id_to_window_map_.end()); |
| 221 RegisterSubtree(params.target, it->second); | 273 RegisterSubtree(params.target, it->second); |
| 222 } | 274 } |
| 223 } else if (params.old_parent) { | 275 } else if (params.old_parent) { |
| 224 UnregisterSubtree(params.target); | 276 UnregisterSubtree(params.target); |
| 225 } | 277 } |
| 226 } | 278 } |
| 227 | 279 |
| 228 void WindowManagerApp::OnViewDestroying(View* view) { | 280 void WindowManagerApp::OnViewDestroying(View* view) { |
| 229 if (view != root_) { | 281 if (view != root_) { |
| 230 Unregister(view); | 282 Unregister(view); |
| 231 return; | 283 return; |
| 232 } | 284 } |
| 233 root_ = nullptr; | 285 aura::Window* window = GetWindowForViewId(view->id()); |
| 234 if (focus_controller_) | 286 window->RemovePreTargetHandler(this); |
| 235 focus_controller_->RemoveObserver(this); | 287 root_ = NULL; |
| 288 STLDeleteValues(&view_id_to_window_map_); |
| 289 if (focus_client_.get()) |
| 290 focus_client_->RemoveObserver(this); |
| 291 if (activation_client_) |
| 292 activation_client_->RemoveObserver(this); |
| 293 window_tree_host_.reset(); |
| 236 } | 294 } |
| 237 | 295 |
| 238 void WindowManagerApp::OnViewBoundsChanged(View* view, | 296 void WindowManagerApp::OnViewBoundsChanged(View* view, |
| 239 const Rect& old_bounds, | 297 const Rect& old_bounds, |
| 240 const Rect& new_bounds) { | 298 const Rect& new_bounds) { |
| 241 // aura::Window* window = GetWindowForViewId(view->id()); | 299 aura::Window* window = GetWindowForViewId(view->id()); |
| 242 // window->SetBounds(new_bounds.To<gfx::Rect>()); | 300 window->SetBounds(new_bounds.To<gfx::Rect>()); |
| 243 } | 301 } |
| 244 | 302 |
| 245 //////////////////////////////////////////////////////////////////////////////// | 303 //////////////////////////////////////////////////////////////////////////////// |
| 246 // WindowManagerApp, ui::EventHandler implementation: | 304 // WindowManagerApp, ui::EventHandler implementation: |
| 247 | 305 |
| 248 void WindowManagerApp::OnEvent(ui::Event* event) { | 306 void WindowManagerApp::OnEvent(ui::Event* event) { |
| 249 if (!window_manager_client_) | 307 if (!window_manager_client_) |
| 250 return; | 308 return; |
| 251 | 309 |
| 252 View* view = GetViewForViewTarget(static_cast<ViewTarget*>(event->target())); | 310 View* view = GetViewForWindow(static_cast<aura::Window*>(event->target())); |
| 253 if (!view) | 311 if (!view) |
| 254 return; | 312 return; |
| 255 | 313 |
| 256 if (focus_controller_) | |
| 257 focus_controller_->OnEvent(event); | |
| 258 | |
| 259 window_manager_client_->DispatchInputEventToView(view->id(), | 314 window_manager_client_->DispatchInputEventToView(view->id(), |
| 260 Event::From(*event)); | 315 Event::From(*event)); |
| 261 } | 316 } |
| 262 | 317 |
| 263 //////////////////////////////////////////////////////////////////////////////// | 318 //////////////////////////////////////////////////////////////////////////////// |
| 264 // WindowManagerApp, mojo::FocusControllerObserver implementation: | 319 // WindowManagerApp, aura::client::FocusChangeObserver implementation: |
| 265 | 320 |
| 266 void WindowManagerApp::OnViewFocused(View* gained_focus, | 321 void WindowManagerApp::OnWindowFocused(aura::Window* gained_focus, |
| 267 View* lost_focus) { | 322 aura::Window* lost_focus) { |
| 268 for (Connections::const_iterator it = connections_.begin(); | 323 for (Connections::const_iterator it = connections_.begin(); |
| 269 it != connections_.end(); ++it) { | 324 it != connections_.end(); ++it) { |
| 270 (*it)->NotifyViewFocused(GetIdForView(gained_focus), | 325 (*it)->NotifyViewFocused(GetIdForWindow(gained_focus), |
| 271 GetIdForView(lost_focus)); | 326 GetIdForWindow(lost_focus)); |
| 272 } | 327 } |
| 273 } | 328 } |
| 274 | 329 |
| 275 void WindowManagerApp::OnViewActivated(View* gained_active, | 330 //////////////////////////////////////////////////////////////////////////////// |
| 276 View* lost_active) { | 331 // WindowManagerApp, aura::client::ActivationChangeObserver implementation: |
| 332 |
| 333 void WindowManagerApp::OnWindowActivated(aura::Window* gained_active, |
| 334 aura::Window* lost_active) { |
| 277 for (Connections::const_iterator it = connections_.begin(); | 335 for (Connections::const_iterator it = connections_.begin(); |
| 278 it != connections_.end(); ++it) { | 336 it != connections_.end(); ++it) { |
| 279 (*it)->NotifyWindowActivated(GetIdForView(gained_active), | 337 (*it)->NotifyWindowActivated(GetIdForWindow(gained_active), |
| 280 GetIdForView(lost_active)); | 338 GetIdForWindow(lost_active)); |
| 281 } | 339 } |
| 282 if (gained_active) | 340 if (gained_active) { |
| 283 gained_active->MoveToFront(); | 341 View* view = GetViewForWindow(gained_active); |
| 342 view->MoveToFront(); |
| 343 } |
| 284 } | 344 } |
| 285 | 345 |
| 286 //////////////////////////////////////////////////////////////////////////////// | 346 //////////////////////////////////////////////////////////////////////////////// |
| 287 // WindowManagerApp, private: | 347 // WindowManagerApp, private: |
| 288 | 348 |
| 289 void WindowManagerApp::RegisterSubtree(View* view, ViewTarget* parent) { | 349 void WindowManagerApp::RegisterSubtree(View* view, aura::Window* parent) { |
| 290 view->AddObserver(this); | 350 view->AddObserver(this); |
| 291 DCHECK(view_id_to_view_target_map_.find(view->id()) == | 351 DCHECK(view_id_to_window_map_.find(view->id()) == |
| 292 view_id_to_view_target_map_.end()); | 352 view_id_to_window_map_.end()); |
| 293 ViewTarget* target = new ViewTarget(this, view); | 353 aura::Window* window = new aura::Window(dummy_delegate_.get()); |
| 354 window->set_id(view->id()); |
| 355 window->SetProperty(kViewKey, view); |
| 294 // All events pass through the root during dispatch, so we only need a handler | 356 // All events pass through the root during dispatch, so we only need a handler |
| 295 // installed there. | 357 // installed there. |
| 296 if (view == root_) { | 358 if (view == root_) |
| 297 target->SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter())); | 359 window->AddPreTargetHandler(this); |
| 298 target->AddPreTargetHandler(this); | 360 parent->AddChild(window); |
| 299 view_event_dispatcher_->SetRootViewTarget(target); | 361 window->SetBounds(view->bounds().To<gfx::Rect>()); |
| 300 } | 362 window->Show(); |
| 301 // TODO(erg): Why is there no matching RemoveChild()? How does that work in | 363 view_id_to_window_map_[view->id()] = window; |
| 302 // the aura version? | |
| 303 view_id_to_view_target_map_[view->id()] = target; | |
| 304 View::Children::const_iterator it = view->children().begin(); | 364 View::Children::const_iterator it = view->children().begin(); |
| 305 for (; it != view->children().end(); ++it) | 365 for (; it != view->children().end(); ++it) |
| 306 RegisterSubtree(*it, target); | 366 RegisterSubtree(*it, window); |
| 307 } | 367 } |
| 308 | 368 |
| 309 void WindowManagerApp::UnregisterSubtree(View* view) { | 369 void WindowManagerApp::UnregisterSubtree(View* view) { |
| 310 for (View* child : view->children()) | 370 for (View* child : view->children()) |
| 311 UnregisterSubtree(child); | 371 UnregisterSubtree(child); |
| 312 Unregister(view); | 372 Unregister(view); |
| 313 } | 373 } |
| 314 | 374 |
| 315 void WindowManagerApp::Unregister(View* view) { | 375 void WindowManagerApp::Unregister(View* view) { |
| 316 ViewIdToViewTargetMap::iterator it = | 376 ViewIdToWindowMap::iterator it = view_id_to_window_map_.find(view->id()); |
| 317 view_id_to_view_target_map_.find(view->id()); | 377 if (it == view_id_to_window_map_.end()) { |
| 318 if (it == view_id_to_view_target_map_.end()) { | |
| 319 // Because we unregister in OnViewDestroying() we can still get a subsequent | 378 // Because we unregister in OnViewDestroying() we can still get a subsequent |
| 320 // OnTreeChanged for the same view. Ignore this one. | 379 // OnTreeChanged for the same view. Ignore this one. |
| 321 return; | 380 return; |
| 322 } | 381 } |
| 323 view->RemoveObserver(this); | 382 view->RemoveObserver(this); |
| 324 DCHECK(it != view_id_to_view_target_map_.end()); | 383 DCHECK(it != view_id_to_window_map_.end()); |
| 325 // Delete before we remove from map as destruction may want to look up view | 384 // Delete before we remove from map as destruction may want to look up view |
| 326 // for window. | 385 // for window. |
| 327 delete it->second; | 386 delete it->second; |
| 328 view_id_to_view_target_map_.erase(it); | 387 view_id_to_window_map_.erase(it); |
| 329 } | 388 } |
| 330 | 389 |
| 331 void WindowManagerApp::SetViewportSize(const gfx::Size& size) { | 390 void WindowManagerApp::SetViewportSize(const gfx::Size& size) { |
| 332 window_manager_client_->SetViewportSize(Size::From(size)); | 391 window_manager_client_->SetViewportSize(Size::From(size)); |
| 333 } | 392 } |
| 334 | 393 |
| 335 void WindowManagerApp::LaunchViewManager(ApplicationImpl* app) { | 394 void WindowManagerApp::LaunchViewManager(ApplicationImpl* app) { |
| 336 // TODO(sky): figure out logic if this connection goes away. | 395 // TODO(sky): figure out logic if this connection goes away. |
| 337 view_manager_client_factory_.reset( | 396 view_manager_client_factory_.reset( |
| 338 new ViewManagerClientFactory(shell_, this)); | 397 new ViewManagerClientFactory(shell_, this)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 353 view_manager_app->ConnectToService(&window_manager_client_); | 412 view_manager_app->ConnectToService(&window_manager_client_); |
| 354 } | 413 } |
| 355 | 414 |
| 356 void WindowManagerApp::Create(ApplicationConnection* connection, | 415 void WindowManagerApp::Create(ApplicationConnection* connection, |
| 357 InterfaceRequest<WindowManagerInternal> request) { | 416 InterfaceRequest<WindowManagerInternal> request) { |
| 358 WindowManagerInternalImpl* impl = new WindowManagerInternalImpl(this); | 417 WindowManagerInternalImpl* impl = new WindowManagerInternalImpl(this); |
| 359 BindToRequest(impl, &request); | 418 BindToRequest(impl, &request); |
| 360 } | 419 } |
| 361 | 420 |
| 362 } // namespace mojo | 421 } // namespace mojo |
| OLD | NEW |