| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/ws/window_manager_state.h" | 5 #include "services/ui/ws/window_manager_state.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "services/service_manager/public/interfaces/connector.mojom.h" | 10 #include "services/service_manager/public/interfaces/connector.mojom.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 const ServerWindow* GetEmbedRoot(const ServerWindow* window) { | 60 const ServerWindow* GetEmbedRoot(const ServerWindow* window) { |
| 61 DCHECK(window); | 61 DCHECK(window); |
| 62 const ServerWindow* embed_root = window->parent(); | 62 const ServerWindow* embed_root = window->parent(); |
| 63 while (embed_root && embed_root->id().client_id == window->id().client_id) | 63 while (embed_root && embed_root->id().client_id == window->id().client_id) |
| 64 embed_root = embed_root->parent(); | 64 embed_root = embed_root->parent(); |
| 65 return embed_root; | 65 return embed_root; |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 WindowManagerState::InFlightEventDetails::InFlightEventDetails( |
| 71 WindowTree* tree, |
| 72 int64_t display_id, |
| 73 const Event& event, |
| 74 EventDispatchPhase phase) |
| 75 : tree(tree), |
| 76 display_id(display_id), |
| 77 event(Event::Clone(event)), |
| 78 phase(phase) {} |
| 79 |
| 80 WindowManagerState::InFlightEventDetails::~InFlightEventDetails() {} |
| 81 |
| 70 class WindowManagerState::ProcessedEventTarget { | 82 class WindowManagerState::ProcessedEventTarget { |
| 71 public: | 83 public: |
| 72 ProcessedEventTarget(ServerWindow* window, | 84 ProcessedEventTarget(ServerWindow* window, |
| 73 ClientSpecificId client_id, | 85 ClientSpecificId client_id, |
| 74 Accelerator* accelerator) | 86 Accelerator* accelerator) |
| 75 : client_id_(client_id) { | 87 : client_id_(client_id) { |
| 76 tracker_.Add(window); | 88 tracker_.Add(window); |
| 77 if (accelerator) | 89 if (accelerator) |
| 78 accelerator_ = accelerator->GetWeakPtr(); | 90 accelerator_ = accelerator->GetWeakPtr(); |
| 79 } | 91 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 event_dispatcher_.ReleaseCaptureBlockedByAnyModalWindow(); | 174 event_dispatcher_.ReleaseCaptureBlockedByAnyModalWindow(); |
| 163 } | 175 } |
| 164 | 176 |
| 165 void WindowManagerState::SetDragDropSourceWindow( | 177 void WindowManagerState::SetDragDropSourceWindow( |
| 166 DragSource* drag_source, | 178 DragSource* drag_source, |
| 167 ServerWindow* window, | 179 ServerWindow* window, |
| 168 DragTargetConnection* source_connection, | 180 DragTargetConnection* source_connection, |
| 169 const std::unordered_map<std::string, std::vector<uint8_t>>& drag_data, | 181 const std::unordered_map<std::string, std::vector<uint8_t>>& drag_data, |
| 170 uint32_t drag_operation) { | 182 uint32_t drag_operation) { |
| 171 int32_t drag_pointer = PointerEvent::kMousePointerId; | 183 int32_t drag_pointer = PointerEvent::kMousePointerId; |
| 172 if (event_awaiting_input_ack_ && | 184 if (in_flight_event_details_ && |
| 173 event_awaiting_input_ack_->IsPointerEvent()) { | 185 in_flight_event_details_->event->IsPointerEvent()) { |
| 174 drag_pointer = event_awaiting_input_ack_->AsPointerEvent()->pointer_id(); | 186 drag_pointer = |
| 187 in_flight_event_details_->event->AsPointerEvent()->pointer_id(); |
| 175 } else { | 188 } else { |
| 176 NOTIMPLEMENTED() << "Set drag drop set up during something other than a " | 189 NOTIMPLEMENTED() << "Set drag drop set up during something other than a " |
| 177 << "pointer event; rejecting drag."; | 190 << "pointer event; rejecting drag."; |
| 178 drag_source->OnDragCompleted(false, ui::mojom::kDropEffectNone); | 191 drag_source->OnDragCompleted(false, ui::mojom::kDropEffectNone); |
| 179 return; | 192 return; |
| 180 } | 193 } |
| 181 | 194 |
| 182 event_dispatcher_.SetDragDropSourceWindow(drag_source, window, | 195 event_dispatcher_.SetDragDropSourceWindow(drag_source, window, |
| 183 source_connection, drag_pointer, | 196 source_connection, drag_pointer, |
| 184 drag_data, drag_operation); | 197 drag_data, drag_operation); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 198 event_dispatcher_.AddSystemModalWindow(window); | 211 event_dispatcher_.AddSystemModalWindow(window); |
| 199 } | 212 } |
| 200 | 213 |
| 201 const UserId& WindowManagerState::user_id() const { | 214 const UserId& WindowManagerState::user_id() const { |
| 202 return window_tree_->user_id(); | 215 return window_tree_->user_id(); |
| 203 } | 216 } |
| 204 | 217 |
| 205 void WindowManagerState::OnWillDestroyTree(WindowTree* tree) { | 218 void WindowManagerState::OnWillDestroyTree(WindowTree* tree) { |
| 206 event_dispatcher_.OnWillDestroyDragTargetConnection(tree); | 219 event_dispatcher_.OnWillDestroyDragTargetConnection(tree); |
| 207 | 220 |
| 208 if (tree_awaiting_input_ack_ != tree) | 221 if (!in_flight_event_details_ || in_flight_event_details_->tree != tree) |
| 209 return; | 222 return; |
| 210 | 223 |
| 211 // The WindowTree is dying. So it's not going to ack the event. | 224 // The WindowTree is dying. So it's not going to ack the event. |
| 212 // If the dying tree matches the root |tree_| marked as handled so we don't | 225 // If the dying tree matches the root |tree_| marked as handled so we don't |
| 213 // notify it of accelerators. | 226 // notify it of accelerators. |
| 214 OnEventAck(tree_awaiting_input_ack_, tree == window_tree_ | 227 OnEventAck(in_flight_event_details_->tree, |
| 215 ? mojom::EventResult::HANDLED | 228 tree == window_tree_ ? mojom::EventResult::HANDLED |
| 216 : mojom::EventResult::UNHANDLED); | 229 : mojom::EventResult::UNHANDLED); |
| 217 } | 230 } |
| 218 | 231 |
| 219 ServerWindow* WindowManagerState::GetOrphanedRootWithId(const WindowId& id) { | 232 ServerWindow* WindowManagerState::GetOrphanedRootWithId(const WindowId& id) { |
| 220 for (auto& display_root_ptr : orphaned_window_manager_display_roots_) { | 233 for (auto& display_root_ptr : orphaned_window_manager_display_roots_) { |
| 221 if (display_root_ptr->root()->id() == id) | 234 if (display_root_ptr->root()->id() == id) |
| 222 return display_root_ptr->root(); | 235 return display_root_ptr->root(); |
| 223 } | 236 } |
| 224 return nullptr; | 237 return nullptr; |
| 225 } | 238 } |
| 226 | 239 |
| 227 bool WindowManagerState::IsActive() const { | 240 bool WindowManagerState::IsActive() const { |
| 228 return window_server()->user_id_tracker()->active_id() == user_id(); | 241 return window_server()->user_id_tracker()->active_id() == user_id(); |
| 229 } | 242 } |
| 230 | 243 |
| 231 void WindowManagerState::Activate(const gfx::Point& mouse_location_on_screen) { | 244 void WindowManagerState::Activate(const gfx::Point& mouse_location_on_screen) { |
| 232 SetAllRootWindowsVisible(true); | 245 SetAllRootWindowsVisible(true); |
| 233 event_dispatcher_.Reset(); | 246 event_dispatcher_.Reset(); |
| 234 event_dispatcher_.SetMousePointerScreenLocation(mouse_location_on_screen); | 247 event_dispatcher_.SetMousePointerScreenLocation(mouse_location_on_screen); |
| 235 } | 248 } |
| 236 | 249 |
| 237 void WindowManagerState::Deactivate() { | 250 void WindowManagerState::Deactivate() { |
| 238 SetAllRootWindowsVisible(false); | 251 SetAllRootWindowsVisible(false); |
| 239 event_dispatcher_.Reset(); | 252 event_dispatcher_.Reset(); |
| 240 // The tree is no longer active, so no point in dispatching any further | 253 // The tree is no longer active, so no point in dispatching any further |
| 241 // events. | 254 // events. |
| 242 std::queue<std::unique_ptr<QueuedEvent>> event_queue; | 255 std::queue<std::unique_ptr<QueuedEvent>> event_queue; |
| 243 event_queue.swap(event_queue_); | 256 event_queue.swap(event_queue_); |
| 244 } | 257 } |
| 245 | 258 |
| 246 void WindowManagerState::ProcessEvent(const ui::Event& event) { | 259 void WindowManagerState::ProcessEvent(const ui::Event& event, |
| 260 int64_t display_id) { |
| 247 // If this is still waiting for an ack from a previously sent event, then | 261 // If this is still waiting for an ack from a previously sent event, then |
| 248 // queue up the event to be dispatched once the ack is received. | 262 // queue up the event to be dispatched once the ack is received. |
| 249 if (event_ack_timer_.IsRunning()) { | 263 if (in_flight_event_details_) { |
| 250 if (!event_queue_.empty() && !event_queue_.back()->processed_target && | 264 if (!event_queue_.empty() && !event_queue_.back()->processed_target && |
| 251 EventsCanBeCoalesced(*event_queue_.back()->event, event)) { | 265 EventsCanBeCoalesced(*event_queue_.back()->event, event)) { |
| 252 event_queue_.back()->event = CoalesceEvents( | 266 event_queue_.back()->event = CoalesceEvents( |
| 253 std::move(event_queue_.back()->event), ui::Event::Clone(event)); | 267 std::move(event_queue_.back()->event), ui::Event::Clone(event)); |
| 268 event_queue_.back()->display_id = display_id; |
| 254 return; | 269 return; |
| 255 } | 270 } |
| 256 QueueEvent(event, nullptr); | 271 QueueEvent(event, nullptr, display_id); |
| 257 return; | 272 return; |
| 258 } | 273 } |
| 259 | 274 |
| 260 ProcessEventImpl(event); | 275 ProcessEventImpl(event, display_id); |
| 261 } | 276 } |
| 262 | 277 |
| 263 void WindowManagerState::OnEventAck(mojom::WindowTree* tree, | 278 void WindowManagerState::OnEventAck(mojom::WindowTree* tree, |
| 264 mojom::EventResult result) { | 279 mojom::EventResult result) { |
| 265 if (tree_awaiting_input_ack_ != tree || | 280 if (!in_flight_event_details_ || in_flight_event_details_->tree != tree || |
| 266 event_dispatch_phase_ != EventDispatchPhase::TARGET) { | 281 in_flight_event_details_->phase != EventDispatchPhase::TARGET) { |
| 267 // TODO(sad): The ack must have arrived after the timeout. We should do | 282 // TODO(sad): The ack must have arrived after the timeout. We should do |
| 268 // something here, and in OnEventAckTimeout(). | 283 // something here, and in OnEventAckTimeout(). |
| 269 return; | 284 return; |
| 270 } | 285 } |
| 271 tree_awaiting_input_ack_ = nullptr; | 286 std::unique_ptr<InFlightEventDetails> details = |
| 272 event_ack_timer_.Stop(); | 287 std::move(in_flight_event_details_); |
| 273 | 288 |
| 274 base::WeakPtr<Accelerator> post_target_accelerator = post_target_accelerator_; | 289 base::WeakPtr<Accelerator> post_target_accelerator = post_target_accelerator_; |
| 275 post_target_accelerator_.reset(); | 290 post_target_accelerator_.reset(); |
| 276 std::unique_ptr<ui::Event> event = std::move(event_awaiting_input_ack_); | |
| 277 | 291 |
| 278 if (result == mojom::EventResult::UNHANDLED && post_target_accelerator) { | 292 if (result == mojom::EventResult::UNHANDLED && post_target_accelerator) { |
| 279 OnAccelerator(post_target_accelerator->id(), *event, | 293 OnAccelerator(post_target_accelerator->id(), *details->event, |
| 280 AcceleratorPhase::POST); | 294 AcceleratorPhase::POST); |
| 281 } | 295 } |
| 282 | 296 |
| 283 event_dispatch_phase_ = EventDispatchPhase::NONE; | |
| 284 ProcessNextEventFromQueue(); | 297 ProcessNextEventFromQueue(); |
| 285 } | 298 } |
| 286 | 299 |
| 287 void WindowManagerState::OnAcceleratorAck(mojom::EventResult result) { | 300 void WindowManagerState::OnAcceleratorAck(mojom::EventResult result) { |
| 288 if (event_dispatch_phase_ != EventDispatchPhase::PRE_TARGET_ACCELERATOR) { | 301 if (!in_flight_event_details_ || |
| 302 in_flight_event_details_->phase != |
| 303 EventDispatchPhase::PRE_TARGET_ACCELERATOR) { |
| 289 // TODO(sad): The ack must have arrived after the timeout. We should do | 304 // TODO(sad): The ack must have arrived after the timeout. We should do |
| 290 // something here, and in OnEventAckTimeout(). | 305 // something here, and in OnEventAckTimeout(). |
| 291 return; | 306 return; |
| 292 } | 307 } |
| 293 | 308 |
| 294 tree_awaiting_input_ack_ = nullptr; | 309 std::unique_ptr<InFlightEventDetails> details = |
| 295 event_ack_timer_.Stop(); | 310 std::move(in_flight_event_details_); |
| 296 event_dispatch_phase_ = EventDispatchPhase::NONE; | |
| 297 std::unique_ptr<ui::Event> event = std::move(event_awaiting_input_ack_); | |
| 298 | 311 |
| 299 if (result == mojom::EventResult::UNHANDLED) { | 312 if (result == mojom::EventResult::UNHANDLED) { |
| 313 event_processing_display_id_ = details->display_id; |
| 300 event_dispatcher_.ProcessEvent( | 314 event_dispatcher_.ProcessEvent( |
| 301 *event, EventDispatcher::AcceleratorMatchPhase::POST_ONLY); | 315 *details->event, EventDispatcher::AcceleratorMatchPhase::POST_ONLY); |
| 302 } else { | 316 } else { |
| 303 // We're not going to process the event any further, notify event observers. | 317 // We're not going to process the event any further, notify event observers. |
| 304 // We don't do this first to ensure we don't send an event twice to clients. | 318 // We don't do this first to ensure we don't send an event twice to clients. |
| 305 window_server()->SendToPointerWatchers(*event, user_id(), nullptr, nullptr); | 319 window_server()->SendToPointerWatchers(*details->event, user_id(), nullptr, |
| 320 nullptr, details->display_id); |
| 306 ProcessNextEventFromQueue(); | 321 ProcessNextEventFromQueue(); |
| 307 } | 322 } |
| 308 } | 323 } |
| 309 | 324 |
| 310 const WindowServer* WindowManagerState::window_server() const { | 325 const WindowServer* WindowManagerState::window_server() const { |
| 311 return window_tree_->window_server(); | 326 return window_tree_->window_server(); |
| 312 } | 327 } |
| 313 | 328 |
| 314 WindowServer* WindowManagerState::window_server() { | 329 WindowServer* WindowManagerState::window_server() { |
| 315 return window_tree_->window_server(); | 330 return window_tree_->window_server(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 return display_root_ptr->root(); | 371 return display_root_ptr->root(); |
| 357 } | 372 } |
| 358 NOTREACHED(); | 373 NOTREACHED(); |
| 359 return nullptr; | 374 return nullptr; |
| 360 } | 375 } |
| 361 | 376 |
| 362 void WindowManagerState::OnEventAckTimeout(ClientSpecificId client_id) { | 377 void WindowManagerState::OnEventAckTimeout(ClientSpecificId client_id) { |
| 363 WindowTree* hung_tree = window_server()->GetTreeWithId(client_id); | 378 WindowTree* hung_tree = window_server()->GetTreeWithId(client_id); |
| 364 if (hung_tree && !hung_tree->janky()) | 379 if (hung_tree && !hung_tree->janky()) |
| 365 window_tree_->ClientJankinessChanged(hung_tree); | 380 window_tree_->ClientJankinessChanged(hung_tree); |
| 366 if (event_dispatch_phase_ == EventDispatchPhase::PRE_TARGET_ACCELERATOR) | 381 if (in_flight_event_details_->phase == |
| 382 EventDispatchPhase::PRE_TARGET_ACCELERATOR) { |
| 367 OnAcceleratorAck(mojom::EventResult::UNHANDLED); | 383 OnAcceleratorAck(mojom::EventResult::UNHANDLED); |
| 368 else | 384 } else { |
| 369 OnEventAck(tree_awaiting_input_ack_, mojom::EventResult::UNHANDLED); | 385 OnEventAck( |
| 386 in_flight_event_details_ ? in_flight_event_details_->tree : nullptr, |
| 387 mojom::EventResult::UNHANDLED); |
| 388 } |
| 370 } | 389 } |
| 371 | 390 |
| 372 void WindowManagerState::ProcessEventImpl(const ui::Event& event) { | 391 void WindowManagerState::ProcessEventImpl(const ui::Event& event, |
| 392 int64_t display_id) { |
| 373 // Debug accelerators are always checked and don't interfere with processing. | 393 // Debug accelerators are always checked and don't interfere with processing. |
| 374 ProcessDebugAccelerator(event); | 394 ProcessDebugAccelerator(event); |
| 395 event_processing_display_id_ = display_id; |
| 375 event_dispatcher_.ProcessEvent(event, | 396 event_dispatcher_.ProcessEvent(event, |
| 376 EventDispatcher::AcceleratorMatchPhase::ANY); | 397 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 377 } | 398 } |
| 378 | 399 |
| 379 void WindowManagerState::QueueEvent( | 400 void WindowManagerState::QueueEvent( |
| 380 const ui::Event& event, | 401 const ui::Event& event, |
| 381 std::unique_ptr<ProcessedEventTarget> processed_event_target) { | 402 std::unique_ptr<ProcessedEventTarget> processed_event_target, |
| 403 int64_t display_id) { |
| 382 std::unique_ptr<QueuedEvent> queued_event(new QueuedEvent); | 404 std::unique_ptr<QueuedEvent> queued_event(new QueuedEvent); |
| 383 queued_event->event = ui::Event::Clone(event); | 405 queued_event->event = ui::Event::Clone(event); |
| 384 queued_event->processed_target = std::move(processed_event_target); | 406 queued_event->processed_target = std::move(processed_event_target); |
| 407 queued_event->display_id = display_id; |
| 385 event_queue_.push(std::move(queued_event)); | 408 event_queue_.push(std::move(queued_event)); |
| 386 } | 409 } |
| 387 | 410 |
| 388 void WindowManagerState::ProcessNextEventFromQueue() { | 411 void WindowManagerState::ProcessNextEventFromQueue() { |
| 389 // Loop through |event_queue_| stopping after dispatching the first valid | 412 // Loop through |event_queue_| stopping after dispatching the first valid |
| 390 // event. | 413 // event. |
| 391 while (!event_queue_.empty()) { | 414 while (!event_queue_.empty()) { |
| 392 std::unique_ptr<QueuedEvent> queued_event = std::move(event_queue_.front()); | 415 std::unique_ptr<QueuedEvent> queued_event = std::move(event_queue_.front()); |
| 393 event_queue_.pop(); | 416 event_queue_.pop(); |
| 394 if (!queued_event->processed_target) { | 417 if (!queued_event->processed_target) { |
| 395 ProcessEventImpl(*queued_event->event); | 418 ProcessEventImpl(*queued_event->event, queued_event->display_id); |
| 396 return; | 419 return; |
| 397 } | 420 } |
| 398 if (queued_event->processed_target->IsValid()) { | 421 if (queued_event->processed_target->IsValid()) { |
| 399 DispatchInputEventToWindowImpl( | 422 DispatchInputEventToWindowImpl( |
| 400 queued_event->processed_target->window(), | 423 queued_event->processed_target->window(), |
| 401 queued_event->processed_target->client_id(), *queued_event->event, | 424 queued_event->processed_target->client_id(), *queued_event->event, |
| 402 queued_event->processed_target->accelerator()); | 425 queued_event->processed_target->accelerator()); |
| 403 return; | 426 return; |
| 404 } | 427 } |
| 405 } | 428 } |
| 406 } | 429 } |
| 407 | 430 |
| 408 void WindowManagerState::DispatchInputEventToWindowImpl( | 431 void WindowManagerState::DispatchInputEventToWindowImpl( |
| 409 ServerWindow* target, | 432 ServerWindow* target, |
| 410 ClientSpecificId client_id, | 433 ClientSpecificId client_id, |
| 411 const ui::Event& event, | 434 const ui::Event& event, |
| 412 base::WeakPtr<Accelerator> accelerator) { | 435 base::WeakPtr<Accelerator> accelerator) { |
| 413 if (target && target->parent() == nullptr) | 436 DCHECK(target); |
| 437 if (target->parent() == nullptr) |
| 414 target = GetWindowManagerRoot(target); | 438 target = GetWindowManagerRoot(target); |
| 415 | 439 |
| 416 if (event.IsMousePointerEvent()) { | 440 if (event.IsMousePointerEvent()) { |
| 417 DCHECK(event_dispatcher_.mouse_cursor_source_window()); | 441 DCHECK(event_dispatcher_.mouse_cursor_source_window()); |
| 418 UpdateNativeCursorFromDispatcher(); | 442 UpdateNativeCursorFromDispatcher(); |
| 419 } | 443 } |
| 420 | 444 |
| 421 event_dispatch_phase_ = EventDispatchPhase::TARGET; | |
| 422 | |
| 423 WindowTree* tree = window_server()->GetTreeWithId(client_id); | 445 WindowTree* tree = window_server()->GetTreeWithId(client_id); |
| 424 DCHECK(tree); | 446 DCHECK(tree); |
| 425 ScheduleInputEventTimeout(tree); | 447 ScheduleInputEventTimeout(tree, target, event, EventDispatchPhase::TARGET); |
| 426 | |
| 427 event_awaiting_input_ack_ = ui::Event::Clone(event); | |
| 428 | 448 |
| 429 if (accelerator) | 449 if (accelerator) |
| 430 post_target_accelerator_ = accelerator; | 450 post_target_accelerator_ = accelerator; |
| 431 | 451 |
| 432 // Ignore |tree| because it will receive the event via normal dispatch. | 452 // Ignore |tree| because it will receive the event via normal dispatch. |
| 433 window_server()->SendToPointerWatchers(event, user_id(), target, tree); | 453 window_server()->SendToPointerWatchers(event, user_id(), target, tree, |
| 454 in_flight_event_details_->display_id); |
| 434 | 455 |
| 435 tree->DispatchInputEvent(target, event); | 456 tree->DispatchInputEvent(target, event); |
| 436 } | 457 } |
| 437 | 458 |
| 438 void WindowManagerState::AddDebugAccelerators() { | 459 void WindowManagerState::AddDebugAccelerators() { |
| 439 const DebugAccelerator accelerator = { | 460 const DebugAccelerator accelerator = { |
| 440 DebugAcceleratorType::PRINT_WINDOWS, ui::VKEY_S, | 461 DebugAcceleratorType::PRINT_WINDOWS, ui::VKEY_S, |
| 441 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN}; | 462 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN}; |
| 442 debug_accelerators_.push_back(accelerator); | 463 debug_accelerators_.push_back(accelerator); |
| 443 } | 464 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 462 WindowManagerDisplayRoot* display_root = | 483 WindowManagerDisplayRoot* display_root = |
| 463 display->GetWindowManagerDisplayRootForUser(user_id()); | 484 display->GetWindowManagerDisplayRootForUser(user_id()); |
| 464 if (display_root) { | 485 if (display_root) { |
| 465 LOG(ERROR) << "ServerWindow hierarchy:\n" | 486 LOG(ERROR) << "ServerWindow hierarchy:\n" |
| 466 << display_root->root()->GetDebugWindowHierarchy(); | 487 << display_root->root()->GetDebugWindowHierarchy(); |
| 467 } | 488 } |
| 468 } | 489 } |
| 469 #endif | 490 #endif |
| 470 } | 491 } |
| 471 | 492 |
| 472 void WindowManagerState::ScheduleInputEventTimeout(WindowTree* tree) { | 493 void WindowManagerState::ScheduleInputEventTimeout(WindowTree* tree, |
| 494 ServerWindow* target, |
| 495 const Event& event, |
| 496 EventDispatchPhase phase) { |
| 497 std::unique_ptr<InFlightEventDetails> details = |
| 498 base::MakeUnique<InFlightEventDetails>(tree, event_processing_display_id_, |
| 499 event, phase); |
| 500 |
| 473 // TOOD(sad): Adjust this delay, possibly make this dynamic. | 501 // TOOD(sad): Adjust this delay, possibly make this dynamic. |
| 474 const base::TimeDelta max_delay = base::debug::BeingDebugged() | 502 const base::TimeDelta max_delay = base::debug::BeingDebugged() |
| 475 ? base::TimeDelta::FromDays(1) | 503 ? base::TimeDelta::FromDays(1) |
| 476 : GetDefaultAckTimerDelay(); | 504 : GetDefaultAckTimerDelay(); |
| 477 event_ack_timer_.Start(FROM_HERE, max_delay, | 505 details->timer.Start(FROM_HERE, max_delay, |
| 478 base::Bind(&WindowManagerState::OnEventAckTimeout, | 506 base::Bind(&WindowManagerState::OnEventAckTimeout, |
| 479 weak_factory_.GetWeakPtr(), tree->id())); | 507 weak_factory_.GetWeakPtr(), tree->id())); |
| 480 | 508 in_flight_event_details_ = std::move(details); |
| 481 tree_awaiting_input_ack_ = tree; | |
| 482 } | 509 } |
| 483 | 510 |
| 484 //////////////////////////////////////////////////////////////////////////////// | 511 //////////////////////////////////////////////////////////////////////////////// |
| 485 // EventDispatcherDelegate: | 512 // EventDispatcherDelegate: |
| 486 | 513 |
| 487 void WindowManagerState::OnAccelerator(uint32_t accelerator_id, | 514 void WindowManagerState::OnAccelerator(uint32_t accelerator_id, |
| 488 const ui::Event& event, | 515 const ui::Event& event, |
| 489 AcceleratorPhase phase) { | 516 AcceleratorPhase phase) { |
| 490 DCHECK(IsActive()); | 517 DCHECK(IsActive()); |
| 491 const bool needs_ack = phase == AcceleratorPhase::PRE; | 518 const bool needs_ack = phase == AcceleratorPhase::PRE; |
| 492 if (needs_ack) { | 519 if (needs_ack) { |
| 493 DCHECK_EQ(EventDispatchPhase::NONE, event_dispatch_phase_); | 520 DCHECK(!in_flight_event_details_); |
| 494 event_dispatch_phase_ = EventDispatchPhase::PRE_TARGET_ACCELERATOR; | 521 ScheduleInputEventTimeout(window_tree_, nullptr, event, |
| 495 event_awaiting_input_ack_ = ui::Event::Clone(event); | 522 EventDispatchPhase::PRE_TARGET_ACCELERATOR); |
| 496 ScheduleInputEventTimeout(window_tree_); | |
| 497 } | 523 } |
| 498 window_tree_->OnAccelerator(accelerator_id, event, needs_ack); | 524 window_tree_->OnAccelerator(accelerator_id, event, needs_ack); |
| 499 } | 525 } |
| 500 | 526 |
| 501 void WindowManagerState::SetFocusedWindowFromEventDispatcher( | 527 void WindowManagerState::SetFocusedWindowFromEventDispatcher( |
| 502 ServerWindow* new_focused_window) { | 528 ServerWindow* new_focused_window) { |
| 503 DCHECK(IsActive()); | 529 DCHECK(IsActive()); |
| 504 window_server()->SetFocusedWindow(new_focused_window); | 530 window_server()->SetFocusedWindow(new_focused_window); |
| 505 } | 531 } |
| 506 | 532 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 ->OnMouseCursorLocationChanged(point); | 572 ->OnMouseCursorLocationChanged(point); |
| 547 } | 573 } |
| 548 | 574 |
| 549 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, | 575 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, |
| 550 ClientSpecificId client_id, | 576 ClientSpecificId client_id, |
| 551 const ui::Event& event, | 577 const ui::Event& event, |
| 552 Accelerator* accelerator) { | 578 Accelerator* accelerator) { |
| 553 DCHECK(IsActive()); | 579 DCHECK(IsActive()); |
| 554 // TODO(sky): this needs to see if another wms has capture and if so forward | 580 // TODO(sky): this needs to see if another wms has capture and if so forward |
| 555 // to it. | 581 // to it. |
| 556 if (event_ack_timer_.IsRunning()) { | 582 if (in_flight_event_details_) { |
| 557 std::unique_ptr<ProcessedEventTarget> processed_event_target( | 583 std::unique_ptr<ProcessedEventTarget> processed_event_target( |
| 558 new ProcessedEventTarget(target, client_id, accelerator)); | 584 new ProcessedEventTarget(target, client_id, accelerator)); |
| 559 QueueEvent(event, std::move(processed_event_target)); | 585 QueueEvent(event, std::move(processed_event_target), |
| 586 event_processing_display_id_); |
| 560 return; | 587 return; |
| 561 } | 588 } |
| 562 | 589 |
| 563 base::WeakPtr<Accelerator> weak_accelerator; | 590 base::WeakPtr<Accelerator> weak_accelerator; |
| 564 if (accelerator) | 591 if (accelerator) |
| 565 weak_accelerator = accelerator->GetWeakPtr(); | 592 weak_accelerator = accelerator->GetWeakPtr(); |
| 566 DispatchInputEventToWindowImpl(target, client_id, event, weak_accelerator); | 593 DispatchInputEventToWindowImpl(target, client_id, event, weak_accelerator); |
| 567 } | 594 } |
| 568 | 595 |
| 569 ClientSpecificId WindowManagerState::GetEventTargetClientId( | 596 ClientSpecificId WindowManagerState::GetEventTargetClientId( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 // Translate the location to be relative to the display instead of relative | 645 // Translate the location to be relative to the display instead of relative |
| 619 // to the screen space. | 646 // to the screen space. |
| 620 gfx::Point origin = | 647 gfx::Point origin = |
| 621 target_display_root->display()->platform_display()->GetBounds().origin(); | 648 target_display_root->display()->platform_display()->GetBounds().origin(); |
| 622 *location -= origin.OffsetFromOrigin(); | 649 *location -= origin.OffsetFromOrigin(); |
| 623 return target_display_root->root(); | 650 return target_display_root->root(); |
| 624 } | 651 } |
| 625 | 652 |
| 626 void WindowManagerState::OnEventTargetNotFound(const ui::Event& event) { | 653 void WindowManagerState::OnEventTargetNotFound(const ui::Event& event) { |
| 627 window_server()->SendToPointerWatchers(event, user_id(), nullptr, /* window */ | 654 window_server()->SendToPointerWatchers(event, user_id(), nullptr, /* window */ |
| 628 nullptr /* ignore_tree */); | 655 nullptr /* ignore_tree */, |
| 656 event_processing_display_id_); |
| 629 if (event.IsMousePointerEvent()) | 657 if (event.IsMousePointerEvent()) |
| 630 UpdateNativeCursorFromDispatcher(); | 658 UpdateNativeCursorFromDispatcher(); |
| 631 } | 659 } |
| 632 | 660 |
| 633 void WindowManagerState::OnWindowEmbeddedAppDisconnected(ServerWindow* window) { | 661 void WindowManagerState::OnWindowEmbeddedAppDisconnected(ServerWindow* window) { |
| 634 for (auto iter = orphaned_window_manager_display_roots_.begin(); | 662 for (auto iter = orphaned_window_manager_display_roots_.begin(); |
| 635 iter != orphaned_window_manager_display_roots_.end(); ++iter) { | 663 iter != orphaned_window_manager_display_roots_.end(); ++iter) { |
| 636 if ((*iter)->root() == window) { | 664 if ((*iter)->root() == window) { |
| 637 window->RemoveObserver(this); | 665 window->RemoveObserver(this); |
| 638 orphaned_window_manager_display_roots_.erase(iter); | 666 orphaned_window_manager_display_roots_.erase(iter); |
| 639 return; | 667 return; |
| 640 } | 668 } |
| 641 } | 669 } |
| 642 NOTREACHED(); | 670 NOTREACHED(); |
| 643 } | 671 } |
| 644 | 672 |
| 645 } // namespace ws | 673 } // namespace ws |
| 646 } // namespace ui | 674 } // namespace ui |
| OLD | NEW |