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