| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/ws/display.h" | 5 #include "components/mus/ws/display.h" |
| 6 | 6 |
| 7 #include "base/debug/debugger.h" | 7 #include "base/debug/debugger.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/mus/common/types.h" | 9 #include "components/mus/common/types.h" |
| 10 #include "components/mus/ws/connection_manager.h" | 10 #include "components/mus/ws/connection_manager.h" |
| 11 #include "components/mus/ws/connection_manager_delegate.h" | 11 #include "components/mus/ws/connection_manager_delegate.h" |
| 12 #include "components/mus/ws/display_binding.h" | 12 #include "components/mus/ws/display_binding.h" |
| 13 #include "components/mus/ws/display_manager.h" | 13 #include "components/mus/ws/display_manager.h" |
| 14 #include "components/mus/ws/focus_controller.h" | 14 #include "components/mus/ws/focus_controller.h" |
| 15 #include "components/mus/ws/platform_display.h" | 15 #include "components/mus/ws/platform_display.h" |
| 16 #include "components/mus/ws/window_manager_factory_service.h" | 16 #include "components/mus/ws/window_manager_factory_service.h" |
| 17 #include "components/mus/ws/window_manager_state.h" | 17 #include "components/mus/ws/window_manager_state.h" |
| 18 #include "components/mus/ws/window_tree.h" | 18 #include "components/mus/ws/window_tree.h" |
| 19 #include "components/mus/ws/window_tree_binding.h" | 19 #include "components/mus/ws/window_tree_binding.h" |
| 20 #include "mojo/common/common_type_converters.h" | 20 #include "mojo/common/common_type_converters.h" |
| 21 #include "mojo/converters/geometry/geometry_type_converters.h" | 21 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 22 #include "mojo/converters/input_events/input_events_type_converters.h" | |
| 23 #include "mojo/shell/public/interfaces/connector.mojom.h" | 22 #include "mojo/shell/public/interfaces/connector.mojom.h" |
| 24 | 23 |
| 25 namespace mus { | 24 namespace mus { |
| 26 namespace ws { | 25 namespace ws { |
| 27 namespace { | |
| 28 | |
| 29 base::TimeDelta GetDefaultAckTimerDelay() { | |
| 30 #if defined(NDEBUG) | |
| 31 return base::TimeDelta::FromMilliseconds(100); | |
| 32 #else | |
| 33 return base::TimeDelta::FromMilliseconds(1000); | |
| 34 #endif | |
| 35 } | |
| 36 | |
| 37 bool EventsCanBeCoalesced(const ui::Event& one, const ui::Event& two) { | |
| 38 if (one.type() != two.type() || one.flags() != two.flags()) | |
| 39 return false; | |
| 40 | |
| 41 // TODO(sad): wheel events can also be merged. | |
| 42 if (one.type() != ui::ET_POINTER_MOVED) | |
| 43 return false; | |
| 44 | |
| 45 return one.AsPointerEvent()->pointer_id() == | |
| 46 two.AsPointerEvent()->pointer_id(); | |
| 47 } | |
| 48 | |
| 49 scoped_ptr<ui::Event> CoalesceEvents(scoped_ptr<ui::Event> first, | |
| 50 scoped_ptr<ui::Event> second) { | |
| 51 DCHECK(first->type() == ui::ET_POINTER_MOVED) | |
| 52 << " Non-move events cannot be merged yet."; | |
| 53 // For mouse moves, the new event just replaces the old event. | |
| 54 return second; | |
| 55 } | |
| 56 | |
| 57 } // namespace | |
| 58 | |
| 59 class Display::ProcessedEventTarget { | |
| 60 public: | |
| 61 ProcessedEventTarget(ServerWindow* window, bool in_nonclient_area) | |
| 62 : in_nonclient_area_(in_nonclient_area) { | |
| 63 tracker_.Add(window); | |
| 64 } | |
| 65 | |
| 66 ~ProcessedEventTarget() {} | |
| 67 | |
| 68 // Return true if the event is still valid. The event becomes invalid if | |
| 69 // the window is destroyed while waiting to dispatch. | |
| 70 bool IsValid() const { return !tracker_.windows().empty(); } | |
| 71 | |
| 72 ServerWindow* window() { | |
| 73 DCHECK(IsValid()); | |
| 74 return tracker_.windows().front(); | |
| 75 } | |
| 76 | |
| 77 bool in_nonclient_area() const { return in_nonclient_area_; } | |
| 78 | |
| 79 private: | |
| 80 ServerWindowTracker tracker_; | |
| 81 const bool in_nonclient_area_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(ProcessedEventTarget); | |
| 84 }; | |
| 85 | |
| 86 Display::QueuedEvent::QueuedEvent() {} | |
| 87 Display::QueuedEvent::~QueuedEvent() {} | |
| 88 | 26 |
| 89 Display::Display(ConnectionManager* connection_manager, | 27 Display::Display(ConnectionManager* connection_manager, |
| 90 mojo::Connector* connector, | 28 mojo::Connector* connector, |
| 91 const scoped_refptr<GpuState>& gpu_state, | 29 const scoped_refptr<GpuState>& gpu_state, |
| 92 const scoped_refptr<SurfacesState>& surfaces_state) | 30 const scoped_refptr<SurfacesState>& surfaces_state) |
| 93 : id_(connection_manager->display_manager()->GetAndAdvanceNextDisplayId()), | 31 : id_(connection_manager->display_manager()->GetAndAdvanceNextDisplayId()), |
| 94 connection_manager_(connection_manager), | 32 connection_manager_(connection_manager), |
| 95 event_dispatcher_(this), | |
| 96 platform_display_( | 33 platform_display_( |
| 97 PlatformDisplay::Create(connector, gpu_state, surfaces_state)), | 34 PlatformDisplay::Create(connector, gpu_state, surfaces_state)), |
| 98 tree_awaiting_input_ack_(nullptr), | |
| 99 last_cursor_(0) { | 35 last_cursor_(0) { |
| 100 platform_display_->Init(this); | 36 platform_display_->Init(this); |
| 101 | 37 |
| 102 connection_manager_->window_manager_factory_registry()->AddObserver(this); | 38 connection_manager_->window_manager_factory_registry()->AddObserver(this); |
| 39 connection_manager_->user_id_tracker()->AddObserver(this); |
| 103 } | 40 } |
| 104 | 41 |
| 105 Display::~Display() { | 42 Display::~Display() { |
| 43 connection_manager_->user_id_tracker()->RemoveObserver(this); |
| 44 |
| 106 connection_manager_->window_manager_factory_registry()->RemoveObserver(this); | 45 connection_manager_->window_manager_factory_registry()->RemoveObserver(this); |
| 107 | 46 |
| 108 DestroyFocusController(); | 47 DestroyFocusController(); |
| 109 for (ServerWindow* window : windows_needing_frame_destruction_) | 48 for (ServerWindow* window : windows_needing_frame_destruction_) |
| 110 window->RemoveObserver(this); | 49 window->RemoveObserver(this); |
| 111 | 50 |
| 112 // Destroy any trees, which triggers destroying the WindowManagerState. Copy | 51 // Destroy any trees, which triggers destroying the WindowManagerState. Copy |
| 113 // off the WindowManagerStates as destruction mutates | 52 // off the WindowManagerStates as destruction mutates |
| 114 // |window_manager_state_map_|. | 53 // |window_manager_state_map_|. |
| 115 std::set<WindowManagerState*> states; | 54 std::set<WindowManagerState*> states; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 ? nullptr | 145 ? nullptr |
| 207 : window_manager_state_map_.begin()->second.get(); | 146 : window_manager_state_map_.begin()->second.get(); |
| 208 } | 147 } |
| 209 | 148 |
| 210 const WindowManagerState* Display::GetWindowManagerStateForUser( | 149 const WindowManagerState* Display::GetWindowManagerStateForUser( |
| 211 const UserId& user_id) const { | 150 const UserId& user_id) const { |
| 212 auto iter = window_manager_state_map_.find(user_id); | 151 auto iter = window_manager_state_map_.find(user_id); |
| 213 return iter == window_manager_state_map_.end() ? nullptr : iter->second.get(); | 152 return iter == window_manager_state_map_.end() ? nullptr : iter->second.get(); |
| 214 } | 153 } |
| 215 | 154 |
| 216 void Display::SetCapture(ServerWindow* window, bool in_nonclient_area) { | |
| 217 ServerWindow* capture_window = event_dispatcher_.capture_window(); | |
| 218 if (capture_window == window) | |
| 219 return; | |
| 220 event_dispatcher_.SetCaptureWindow(window, in_nonclient_area); | |
| 221 } | |
| 222 | |
| 223 mojom::Rotation Display::GetRotation() const { | 155 mojom::Rotation Display::GetRotation() const { |
| 224 return platform_display_->GetRotation(); | 156 return platform_display_->GetRotation(); |
| 225 } | 157 } |
| 226 | 158 |
| 159 const WindowManagerState* Display::GetActiveWindowManagerState() const { |
| 160 return GetWindowManagerStateForUser( |
| 161 connection_manager_->user_id_tracker()->active_id()); |
| 162 } |
| 163 |
| 227 void Display::SetFocusedWindow(ServerWindow* new_focused_window) { | 164 void Display::SetFocusedWindow(ServerWindow* new_focused_window) { |
| 165 // TODO(sky): this is wrong. Focus is global, not per Display. |
| 228 ServerWindow* old_focused_window = focus_controller_->GetFocusedWindow(); | 166 ServerWindow* old_focused_window = focus_controller_->GetFocusedWindow(); |
| 229 if (old_focused_window == new_focused_window) | 167 if (old_focused_window == new_focused_window) |
| 230 return; | 168 return; |
| 231 DCHECK(root_window()->Contains(new_focused_window)); | 169 DCHECK(root_window()->Contains(new_focused_window)); |
| 232 focus_controller_->SetFocusedWindow(new_focused_window); | 170 focus_controller_->SetFocusedWindow(new_focused_window); |
| 233 } | 171 } |
| 234 | 172 |
| 235 ServerWindow* Display::GetFocusedWindow() { | 173 ServerWindow* Display::GetFocusedWindow() { |
| 236 return focus_controller_->GetFocusedWindow(); | 174 return focus_controller_->GetFocusedWindow(); |
| 237 } | 175 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 207 |
| 270 void Display::OnWillDestroyTree(WindowTree* tree) { | 208 void Display::OnWillDestroyTree(WindowTree* tree) { |
| 271 for (auto it = window_manager_state_map_.begin(); | 209 for (auto it = window_manager_state_map_.begin(); |
| 272 it != window_manager_state_map_.end(); ++it) { | 210 it != window_manager_state_map_.end(); ++it) { |
| 273 if (it->second->tree() == tree) { | 211 if (it->second->tree() == tree) { |
| 274 window_manager_state_map_.erase(it); | 212 window_manager_state_map_.erase(it); |
| 275 break; | 213 break; |
| 276 } | 214 } |
| 277 } | 215 } |
| 278 | 216 |
| 279 if (tree_awaiting_input_ack_ != tree) | 217 for (const auto& pair : window_manager_state_map_) |
| 280 return; | 218 pair.second->OnWillDestroyTree(tree); |
| 281 // The WindowTree is dying. So it's not going to ack the event. | 219 } |
| 282 OnEventAck(tree_awaiting_input_ack_); | 220 |
| 221 void Display::UpdateNativeCursor(int32_t cursor_id) { |
| 222 if (cursor_id != last_cursor_) { |
| 223 platform_display_->SetCursorById(cursor_id); |
| 224 last_cursor_ = cursor_id; |
| 225 } |
| 283 } | 226 } |
| 284 | 227 |
| 285 void Display::OnCursorUpdated(ServerWindow* window) { | 228 void Display::OnCursorUpdated(ServerWindow* window) { |
| 286 if (window == event_dispatcher_.mouse_cursor_source_window()) | 229 WindowManagerState* wms = GetActiveWindowManagerState(); |
| 230 if (wms && window == wms->event_dispatcher()->mouse_cursor_source_window()) |
| 287 UpdateNativeCursor(window->cursor()); | 231 UpdateNativeCursor(window->cursor()); |
| 288 } | 232 } |
| 289 | 233 |
| 290 void Display::MaybeChangeCursorOnWindowTreeChange() { | 234 void Display::MaybeChangeCursorOnWindowTreeChange() { |
| 291 event_dispatcher_.UpdateCursorProviderByLastKnownLocation(); | 235 WindowManagerState* wms = GetActiveWindowManagerState(); |
| 236 if (!wms) |
| 237 return; |
| 238 wms->event_dispatcher()->UpdateCursorProviderByLastKnownLocation(); |
| 292 ServerWindow* cursor_source_window = | 239 ServerWindow* cursor_source_window = |
| 293 event_dispatcher_.mouse_cursor_source_window(); | 240 wms->event_dispatcher()->mouse_cursor_source_window(); |
| 294 if (cursor_source_window) | 241 if (cursor_source_window) |
| 295 UpdateNativeCursor(cursor_source_window->cursor()); | 242 UpdateNativeCursor(cursor_source_window->cursor()); |
| 296 } | 243 } |
| 297 | 244 |
| 298 void Display::SetSize(mojo::SizePtr size) { | 245 void Display::SetSize(mojo::SizePtr size) { |
| 299 platform_display_->SetViewportSize(size.To<gfx::Size>()); | 246 platform_display_->SetViewportSize(size.To<gfx::Size>()); |
| 300 } | 247 } |
| 301 | 248 |
| 302 void Display::SetTitle(const mojo::String& title) { | 249 void Display::SetTitle(const mojo::String& title) { |
| 303 platform_display_->SetTitle(title.To<base::string16>()); | 250 platform_display_->SetTitle(title.To<base::string16>()); |
| 304 } | 251 } |
| 305 | 252 |
| 306 void Display::OnEventAck(mojom::WindowTree* tree) { | |
| 307 if (tree_awaiting_input_ack_ != tree) { | |
| 308 // TODO(sad): The ack must have arrived after the timeout. We should do | |
| 309 // something here, and in OnEventAckTimeout(). | |
| 310 return; | |
| 311 } | |
| 312 tree_awaiting_input_ack_ = nullptr; | |
| 313 event_ack_timer_.Stop(); | |
| 314 ProcessNextEventFromQueue(); | |
| 315 } | |
| 316 | |
| 317 void Display::InitWindowManagersIfNecessary() { | 253 void Display::InitWindowManagersIfNecessary() { |
| 318 if (!init_called_ || !root_) | 254 if (!init_called_ || !root_) |
| 319 return; | 255 return; |
| 320 | 256 |
| 321 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); | 257 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); |
| 322 if (binding_) { | 258 if (binding_) { |
| 323 scoped_ptr<WindowManagerState> wms_ptr(new WindowManagerState(this)); | 259 scoped_ptr<WindowManagerState> wms_ptr(new WindowManagerState( |
| 260 this, platform_display_.get(), top_level_surface_id_)); |
| 324 WindowManagerState* wms = wms_ptr.get(); | 261 WindowManagerState* wms = wms_ptr.get(); |
| 325 // For this case we never create additional WindowManagerStates, so any | 262 // For this case we never create additional WindowManagerStates, so any |
| 326 // id works. | 263 // id works. |
| 327 window_manager_state_map_[mojo::shell::mojom::kRootUserID] = | 264 window_manager_state_map_[mojo::shell::mojom::kRootUserID] = |
| 328 std::move(wms_ptr); | 265 std::move(wms_ptr); |
| 329 wms->tree_ = binding_->CreateWindowTree(wms->root()); | 266 wms->tree_ = binding_->CreateWindowTree(wms->root()); |
| 330 } else { | 267 } else { |
| 331 CreateWindowManagerStatesFromRegistry(); | 268 CreateWindowManagerStatesFromRegistry(); |
| 332 } | 269 } |
| 333 } | 270 } |
| 334 | 271 |
| 335 void Display::OnEventAckTimeout() { | |
| 336 // TODO(sad): Figure out what we should do. | |
| 337 NOTIMPLEMENTED() << "Event ACK timed out."; | |
| 338 OnEventAck(tree_awaiting_input_ack_); | |
| 339 } | |
| 340 | |
| 341 void Display::QueueEvent( | |
| 342 const ui::Event& event, | |
| 343 scoped_ptr<ProcessedEventTarget> processed_event_target) { | |
| 344 scoped_ptr<QueuedEvent> queued_event(new QueuedEvent); | |
| 345 queued_event->event = ui::Event::Clone(event); | |
| 346 queued_event->processed_target = std::move(processed_event_target); | |
| 347 event_queue_.push(std::move(queued_event)); | |
| 348 } | |
| 349 | |
| 350 void Display::ProcessNextEventFromQueue() { | |
| 351 // Loop through |event_queue_| stopping after dispatching the first valid | |
| 352 // event. | |
| 353 while (!event_queue_.empty()) { | |
| 354 scoped_ptr<QueuedEvent> queued_event = std::move(event_queue_.front()); | |
| 355 event_queue_.pop(); | |
| 356 if (!queued_event->processed_target) { | |
| 357 event_dispatcher_.ProcessEvent(*queued_event->event); | |
| 358 return; | |
| 359 } | |
| 360 if (queued_event->processed_target->IsValid()) { | |
| 361 DispatchInputEventToWindowImpl( | |
| 362 queued_event->processed_target->window(), | |
| 363 queued_event->processed_target->in_nonclient_area(), | |
| 364 *queued_event->event); | |
| 365 return; | |
| 366 } | |
| 367 } | |
| 368 } | |
| 369 | |
| 370 void Display::DispatchInputEventToWindowImpl(ServerWindow* target, | |
| 371 bool in_nonclient_area, | |
| 372 const ui::Event& event) { | |
| 373 if (target == root_.get()) { | |
| 374 // TODO(sky): use active windowmanager here. | |
| 375 target = GetFirstWindowManagerState()->root(); | |
| 376 } | |
| 377 if (event.IsMousePointerEvent()) { | |
| 378 DCHECK(event_dispatcher_.mouse_cursor_source_window()); | |
| 379 UpdateNativeCursor( | |
| 380 event_dispatcher_.mouse_cursor_source_window()->cursor()); | |
| 381 } | |
| 382 | |
| 383 // If the event is in the non-client area the event goes to the owner of | |
| 384 // the window. Otherwise if the window is an embed root, forward to the | |
| 385 // embedded window. | |
| 386 WindowTree* tree = | |
| 387 in_nonclient_area | |
| 388 ? connection_manager_->GetTreeWithId(target->id().connection_id) | |
| 389 : connection_manager_->GetTreeWithRoot(target); | |
| 390 if (!tree) { | |
| 391 DCHECK(!in_nonclient_area); | |
| 392 tree = connection_manager_->GetTreeWithId(target->id().connection_id); | |
| 393 } | |
| 394 | |
| 395 // TOOD(sad): Adjust this delay, possibly make this dynamic. | |
| 396 const base::TimeDelta max_delay = base::debug::BeingDebugged() | |
| 397 ? base::TimeDelta::FromDays(1) | |
| 398 : GetDefaultAckTimerDelay(); | |
| 399 event_ack_timer_.Start(FROM_HERE, max_delay, this, | |
| 400 &Display::OnEventAckTimeout); | |
| 401 | |
| 402 tree_awaiting_input_ack_ = tree; | |
| 403 tree->DispatchInputEvent(target, mojom::Event::From(event)); | |
| 404 } | |
| 405 | |
| 406 void Display::CreateWindowManagerStatesFromRegistry() { | 272 void Display::CreateWindowManagerStatesFromRegistry() { |
| 407 std::vector<WindowManagerFactoryService*> services = | 273 std::vector<WindowManagerFactoryService*> services = |
| 408 connection_manager_->window_manager_factory_registry()->GetServices(); | 274 connection_manager_->window_manager_factory_registry()->GetServices(); |
| 409 for (WindowManagerFactoryService* service : services) { | 275 for (WindowManagerFactoryService* service : services) { |
| 410 if (service->window_manager_factory()) | 276 if (service->window_manager_factory()) |
| 411 CreateWindowManagerStateFromService(service); | 277 CreateWindowManagerStateFromService(service); |
| 412 } | 278 } |
| 413 } | 279 } |
| 414 | 280 |
| 415 void Display::CreateWindowManagerStateFromService( | 281 void Display::CreateWindowManagerStateFromService( |
| 416 WindowManagerFactoryService* service) { | 282 WindowManagerFactoryService* service) { |
| 417 scoped_ptr<WindowManagerState> wms_ptr( | 283 scoped_ptr<WindowManagerState> wms_ptr( |
| 418 new WindowManagerState(this, service->user_id())); | 284 new WindowManagerState(this, platform_display_.get(), |
| 285 top_level_surface_id_, service->user_id())); |
| 419 WindowManagerState* wms = wms_ptr.get(); | 286 WindowManagerState* wms = wms_ptr.get(); |
| 420 window_manager_state_map_[service->user_id()] = std::move(wms_ptr); | 287 window_manager_state_map_[service->user_id()] = std::move(wms_ptr); |
| 421 wms->tree_ = connection_manager_->CreateTreeForWindowManager( | 288 wms->tree_ = connection_manager_->CreateTreeForWindowManager( |
| 422 this, service->window_manager_factory(), wms->root()); | 289 this, service->window_manager_factory(), wms->root()); |
| 423 } | 290 } |
| 424 | 291 |
| 425 void Display::UpdateNativeCursor(int32_t cursor_id) { | |
| 426 if (cursor_id != last_cursor_) { | |
| 427 platform_display_->SetCursorById(cursor_id); | |
| 428 last_cursor_ = cursor_id; | |
| 429 } | |
| 430 } | |
| 431 | |
| 432 ServerWindow* Display::GetRootWindow() { | 292 ServerWindow* Display::GetRootWindow() { |
| 433 return root_.get(); | 293 return root_.get(); |
| 434 } | 294 } |
| 435 | 295 |
| 436 void Display::OnEvent(const ui::Event& event) { | 296 void Display::OnEvent(const ui::Event& event) { |
| 437 mojom::EventPtr mojo_event(mojom::Event::From(event)); | 297 WindowManagerState* wms = GetActiveWindowManagerState(); |
| 438 // If this is still waiting for an ack from a previously sent event, then | 298 if (wms) |
| 439 // queue up the event to be dispatched once the ack is received. | 299 wms->ProcessEvent(event); |
| 440 if (event_ack_timer_.IsRunning()) { | |
| 441 if (!event_queue_.empty() && !event_queue_.back()->processed_target && | |
| 442 EventsCanBeCoalesced(*event_queue_.back()->event, event)) { | |
| 443 event_queue_.back()->event = CoalesceEvents( | |
| 444 std::move(event_queue_.back()->event), ui::Event::Clone(event)); | |
| 445 return; | |
| 446 } | |
| 447 QueueEvent(event, nullptr); | |
| 448 return; | |
| 449 } | |
| 450 event_dispatcher_.ProcessEvent(event); | |
| 451 } | 300 } |
| 452 | 301 |
| 453 void Display::OnNativeCaptureLost() { | 302 void Display::OnNativeCaptureLost() { |
| 454 SetCapture(nullptr, false); | 303 WindowManagerState* state = GetActiveWindowManagerState(); |
| 304 if (state) |
| 305 state->SetCapture(nullptr, false); |
| 455 } | 306 } |
| 456 | 307 |
| 457 void Display::OnDisplayClosed() { | 308 void Display::OnDisplayClosed() { |
| 458 display_manager()->DestroyDisplay(this); | 309 display_manager()->DestroyDisplay(this); |
| 459 } | 310 } |
| 460 | 311 |
| 461 void Display::OnViewportMetricsChanged( | 312 void Display::OnViewportMetricsChanged( |
| 462 const mojom::ViewportMetrics& old_metrics, | 313 const mojom::ViewportMetrics& old_metrics, |
| 463 const mojom::ViewportMetrics& new_metrics) { | 314 const mojom::ViewportMetrics& new_metrics) { |
| 464 if (!root_) { | 315 if (!root_) { |
| 465 root_.reset(connection_manager_->CreateServerWindow( | 316 root_.reset(connection_manager_->CreateServerWindow( |
| 466 display_manager()->GetAndAdvanceNextRootId(), | 317 display_manager()->GetAndAdvanceNextRootId(), |
| 467 ServerWindow::Properties())); | 318 ServerWindow::Properties())); |
| 468 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); | 319 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); |
| 469 root_->SetVisible(true); | 320 root_->SetVisible(true); |
| 470 focus_controller_.reset(new FocusController(this, root_.get())); | 321 focus_controller_.reset(new FocusController(this, root_.get())); |
| 471 focus_controller_->AddObserver(this); | 322 focus_controller_->AddObserver(this); |
| 472 InitWindowManagersIfNecessary(); | 323 InitWindowManagersIfNecessary(); |
| 473 event_dispatcher_.set_root(root_.get()); | |
| 474 } else { | 324 } else { |
| 475 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); | 325 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); |
| 476 const gfx::Rect wm_bounds(root_->bounds().size()); | 326 const gfx::Rect wm_bounds(root_->bounds().size()); |
| 477 for (auto& pair : window_manager_state_map_) | 327 for (auto& pair : window_manager_state_map_) |
| 478 pair.second->root()->SetBounds(wm_bounds); | 328 pair.second->root()->SetBounds(wm_bounds); |
| 479 } | 329 } |
| 480 // TODO(sky): if bounds changed, then need to update | 330 // TODO(sky): if bounds changed, then need to update |
| 481 // Display/WindowManagerState appropriately (e.g. notify observers). | 331 // Display/WindowManagerState appropriately (e.g. notify observers). |
| 482 connection_manager_->ProcessViewportMetricsChanged(this, old_metrics, | 332 connection_manager_->ProcessViewportMetricsChanged(this, old_metrics, |
| 483 new_metrics); | 333 new_metrics); |
| 484 } | 334 } |
| 485 | 335 |
| 486 void Display::OnTopLevelSurfaceChanged(cc::SurfaceId surface_id) { | 336 void Display::OnTopLevelSurfaceChanged(cc::SurfaceId surface_id) { |
| 487 event_dispatcher_.set_surface_id(surface_id); | 337 DCHECK(!root_); |
| 338 // This should only be called once, and before we've created root_. |
| 339 top_level_surface_id_ = surface_id; |
| 488 } | 340 } |
| 489 | 341 |
| 490 void Display::OnCompositorFrameDrawn() { | 342 void Display::OnCompositorFrameDrawn() { |
| 491 std::set<ServerWindow*> windows; | 343 std::set<ServerWindow*> windows; |
| 492 windows.swap(windows_needing_frame_destruction_); | 344 windows.swap(windows_needing_frame_destruction_); |
| 493 for (ServerWindow* window : windows) { | 345 for (ServerWindow* window : windows) { |
| 494 window->RemoveObserver(this); | 346 window->RemoveObserver(this); |
| 495 window->DestroySurfacesScheduledForDestruction(); | 347 window->DestroySurfacesScheduledForDestruction(); |
| 496 } | 348 } |
| 497 } | 349 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 wms_tree != owning_tree_old && wms_tree != embedded_tree_old && | 439 wms_tree != owning_tree_old && wms_tree != embedded_tree_old && |
| 588 wms_tree != owning_tree_new && wms_tree != embedded_tree_new) { | 440 wms_tree != owning_tree_new && wms_tree != embedded_tree_new) { |
| 589 wms_tree->ProcessFocusChanged(old_focused_window, new_focused_window); | 441 wms_tree->ProcessFocusChanged(old_focused_window, new_focused_window); |
| 590 } | 442 } |
| 591 } | 443 } |
| 592 | 444 |
| 593 UpdateTextInputState(new_focused_window, | 445 UpdateTextInputState(new_focused_window, |
| 594 new_focused_window->text_input_state()); | 446 new_focused_window->text_input_state()); |
| 595 } | 447 } |
| 596 | 448 |
| 597 void Display::OnAccelerator(uint32_t accelerator_id, const ui::Event& event) { | |
| 598 // TODO(sky): accelerators need to be maintained per windowmanager and pushed | |
| 599 // to the eventdispatcher when the active userid changes. | |
| 600 GetFirstWindowManagerState()->tree()->OnAccelerator( | |
| 601 accelerator_id, mojom::Event::From(event)); | |
| 602 } | |
| 603 | |
| 604 void Display::SetFocusedWindowFromEventDispatcher( | |
| 605 ServerWindow* new_focused_window) { | |
| 606 SetFocusedWindow(new_focused_window); | |
| 607 } | |
| 608 | |
| 609 ServerWindow* Display::GetFocusedWindowForEventDispatcher() { | |
| 610 return GetFocusedWindow(); | |
| 611 } | |
| 612 | |
| 613 void Display::SetNativeCapture() { | |
| 614 platform_display_->SetCapture(); | |
| 615 } | |
| 616 | |
| 617 void Display::ReleaseNativeCapture() { | |
| 618 platform_display_->ReleaseCapture(); | |
| 619 } | |
| 620 | |
| 621 void Display::OnServerWindowCaptureLost(ServerWindow* window) { | |
| 622 DCHECK(window); | |
| 623 connection_manager_->ProcessLostCapture(window); | |
| 624 } | |
| 625 | |
| 626 void Display::DispatchInputEventToWindow(ServerWindow* target, | |
| 627 bool in_nonclient_area, | |
| 628 const ui::Event& event) { | |
| 629 if (event_ack_timer_.IsRunning()) { | |
| 630 scoped_ptr<ProcessedEventTarget> processed_event_target( | |
| 631 new ProcessedEventTarget(target, in_nonclient_area)); | |
| 632 QueueEvent(event, std::move(processed_event_target)); | |
| 633 return; | |
| 634 } | |
| 635 | |
| 636 DispatchInputEventToWindowImpl(target, in_nonclient_area, event); | |
| 637 } | |
| 638 | |
| 639 void Display::OnWindowDestroyed(ServerWindow* window) { | 449 void Display::OnWindowDestroyed(ServerWindow* window) { |
| 640 windows_needing_frame_destruction_.erase(window); | 450 windows_needing_frame_destruction_.erase(window); |
| 641 window->RemoveObserver(this); | 451 window->RemoveObserver(this); |
| 642 } | 452 } |
| 643 | 453 |
| 644 void Display::OnActiveUserIdChanged(const UserId& id) { | 454 void Display::OnActiveUserIdChanged(const UserId& previously_active_id, |
| 645 // TODO(sky): this likely needs to cancel any pending events and all that. | 455 const UserId& active_id) { |
| 456 WindowManagerState* previous_wms = |
| 457 GetWindowManagerStateForUser(previously_active_id); |
| 458 const gfx::Point mouse_location_on_screen = |
| 459 previous_wms |
| 460 ? previous_wms->event_dispatcher()->mouse_pointer_last_location() |
| 461 : gfx::Point(); |
| 462 if (previous_wms) |
| 463 previous_wms->event_dispatcher()->Reset(); |
| 464 |
| 465 WindowManagerState* active_wms = GetWindowManagerStateForUser(active_id); |
| 466 if (active_wms) { |
| 467 active_wms->event_dispatcher()->Reset(); |
| 468 active_wms->event_dispatcher()->SetMousePointerScreenLocation( |
| 469 mouse_location_on_screen); |
| 470 } |
| 646 } | 471 } |
| 647 | 472 |
| 648 void Display::OnUserIdAdded(const UserId& id) {} | 473 void Display::OnUserIdAdded(const UserId& id) {} |
| 649 | 474 |
| 650 void Display::OnUserIdRemoved(const UserId& id) { | 475 void Display::OnUserIdRemoved(const UserId& id) { |
| 651 if (binding_) | 476 if (binding_) |
| 652 return; | 477 return; |
| 653 | 478 |
| 654 WindowManagerState* state = GetWindowManagerStateForUser(id); | 479 WindowManagerState* state = GetWindowManagerStateForUser(id); |
| 655 if (!state) | 480 if (!state) |
| 656 return; | 481 return; |
| 657 | 482 |
| 658 // DestroyTree() calls back to OnWillDestroyTree() and the WindowManagerState | 483 // DestroyTree() calls back to OnWillDestroyTree() and the WindowManagerState |
| 659 // is destroyed (and removed). | 484 // is destroyed (and removed). |
| 660 connection_manager_->DestroyTree(state->tree()); | 485 connection_manager_->DestroyTree(state->tree()); |
| 661 DCHECK_EQ(0u, window_manager_state_map_.count(id)); | 486 DCHECK_EQ(0u, window_manager_state_map_.count(id)); |
| 662 } | 487 } |
| 663 | 488 |
| 664 void Display::OnWindowManagerFactorySet(WindowManagerFactoryService* service) { | 489 void Display::OnWindowManagerFactorySet(WindowManagerFactoryService* service) { |
| 665 if (!binding_) | 490 if (!binding_) |
| 666 CreateWindowManagerStateFromService(service); | 491 CreateWindowManagerStateFromService(service); |
| 667 } | 492 } |
| 668 | 493 |
| 669 } // namespace ws | 494 } // namespace ws |
| 670 } // namespace mus | 495 } // namespace mus |
| OLD | NEW |