| 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 "components/mus/ws/window_manager_state.h" | 5 #include "components/mus/ws/window_manager_state.h" |
| 6 | 6 |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "components/mus/ws/accelerator.h" | 8 #include "components/mus/ws/accelerator.h" |
| 9 #include "components/mus/ws/display_manager.h" | 9 #include "components/mus/ws/display_manager.h" |
| 10 #include "components/mus/ws/platform_display.h" | 10 #include "components/mus/ws/platform_display.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 display_ptr->frame_decoration_values = frame_decoration_values_.Clone(); | 153 display_ptr->frame_decoration_values = frame_decoration_values_.Clone(); |
| 154 return display_ptr; | 154 return display_ptr; |
| 155 } | 155 } |
| 156 | 156 |
| 157 void WindowManagerState::OnWillDestroyTree(WindowTree* tree) { | 157 void WindowManagerState::OnWillDestroyTree(WindowTree* tree) { |
| 158 if (tree_awaiting_input_ack_ != tree) | 158 if (tree_awaiting_input_ack_ != tree) |
| 159 return; | 159 return; |
| 160 // The WindowTree is dying. So it's not going to ack the event. | 160 // The WindowTree is dying. So it's not going to ack the event. |
| 161 // If the dying tree matches the root |tree_| marked as handled so we don't | 161 // If the dying tree matches the root |tree_| marked as handled so we don't |
| 162 // notify it of accelerators. | 162 // notify it of accelerators. |
| 163 OnEventAck(tree_awaiting_input_ack_, tree == tree_); | 163 OnEventAck(tree_awaiting_input_ack_, tree == tree_ |
| 164 ? mojom::EventResult::HANDLED |
| 165 : mojom::EventResult::UNHANDLED); |
| 164 } | 166 } |
| 165 | 167 |
| 166 WindowManagerState::WindowManagerState(Display* display, | 168 WindowManagerState::WindowManagerState(Display* display, |
| 167 PlatformDisplay* platform_display, | 169 PlatformDisplay* platform_display, |
| 168 cc::SurfaceId surface_id, | 170 cc::SurfaceId surface_id, |
| 169 bool is_user_id_valid, | 171 bool is_user_id_valid, |
| 170 const UserId& user_id) | 172 const UserId& user_id) |
| 171 : display_(display), | 173 : display_(display), |
| 172 platform_display_(platform_display), | 174 platform_display_(platform_display), |
| 173 is_user_id_valid_(is_user_id_valid), | 175 is_user_id_valid_(is_user_id_valid), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 event_queue_.back()->event = CoalesceEvents( | 222 event_queue_.back()->event = CoalesceEvents( |
| 221 std::move(event_queue_.back()->event), ui::Event::Clone(event)); | 223 std::move(event_queue_.back()->event), ui::Event::Clone(event)); |
| 222 return; | 224 return; |
| 223 } | 225 } |
| 224 QueueEvent(event, nullptr); | 226 QueueEvent(event, nullptr); |
| 225 return; | 227 return; |
| 226 } | 228 } |
| 227 event_dispatcher_.ProcessEvent(event); | 229 event_dispatcher_.ProcessEvent(event); |
| 228 } | 230 } |
| 229 | 231 |
| 230 void WindowManagerState::OnEventAck(mojom::WindowTree* tree, bool handled) { | 232 void WindowManagerState::OnEventAck(mojom::WindowTree* tree, |
| 233 mojom::EventResult result) { |
| 231 if (tree_awaiting_input_ack_ != tree) { | 234 if (tree_awaiting_input_ack_ != tree) { |
| 232 // TODO(sad): The ack must have arrived after the timeout. We should do | 235 // TODO(sad): The ack must have arrived after the timeout. We should do |
| 233 // something here, and in OnEventAckTimeout(). | 236 // something here, and in OnEventAckTimeout(). |
| 234 return; | 237 return; |
| 235 } | 238 } |
| 236 tree_awaiting_input_ack_ = nullptr; | 239 tree_awaiting_input_ack_ = nullptr; |
| 237 event_ack_timer_.Stop(); | 240 event_ack_timer_.Stop(); |
| 238 | 241 |
| 239 if (!handled && post_target_accelerator_) | 242 if (result == mojom::EventResult::UNHANDLED && post_target_accelerator_) { |
| 240 OnAccelerator(post_target_accelerator_->id(), *event_awaiting_input_ack_); | 243 OnAccelerator(post_target_accelerator_->id(), *event_awaiting_input_ack_); |
| 244 } else if (result == mojom::EventResult::REPOST) { |
| 245 scoped_ptr<ui::Event> event = ui::Event::Clone(*event_awaiting_input_ack_); |
| 246 // The cached event may have had its location transformed to a window |
| 247 // target. Use its original coordinates when reposting so it can be |
| 248 // transformed to other targets. |
| 249 if (event->IsPointerEvent()) { |
| 250 ui::PointerEvent* pointer_event = event->AsPointerEvent(); |
| 251 pointer_event->set_location(pointer_event->root_location()); |
| 252 } |
| 253 event_dispatcher_.ProcessEvent(*event); |
| 254 } |
| 241 | 255 |
| 242 ProcessNextEventFromQueue(); | 256 ProcessNextEventFromQueue(); |
| 243 } | 257 } |
| 244 | 258 |
| 245 WindowServer* WindowManagerState::window_server() { | 259 WindowServer* WindowManagerState::window_server() { |
| 246 return display_->window_server(); | 260 return display_->window_server(); |
| 247 } | 261 } |
| 248 | 262 |
| 249 void WindowManagerState::OnEventAckTimeout() { | 263 void WindowManagerState::OnEventAckTimeout() { |
| 250 // TODO(sad): Figure out what we should do. | 264 // TODO(sad): Figure out what we should do. |
| 251 NOTIMPLEMENTED() << "Event ACK timed out."; | 265 NOTIMPLEMENTED() << "Event ACK timed out."; |
| 252 OnEventAck(tree_awaiting_input_ack_, false); | 266 OnEventAck(tree_awaiting_input_ack_, mojom::EventResult::UNHANDLED); |
| 253 } | 267 } |
| 254 | 268 |
| 255 void WindowManagerState::QueueEvent( | 269 void WindowManagerState::QueueEvent( |
| 256 const ui::Event& event, | 270 const ui::Event& event, |
| 257 scoped_ptr<ProcessedEventTarget> processed_event_target) { | 271 scoped_ptr<ProcessedEventTarget> processed_event_target) { |
| 258 scoped_ptr<QueuedEvent> queued_event(new QueuedEvent); | 272 scoped_ptr<QueuedEvent> queued_event(new QueuedEvent); |
| 259 queued_event->event = ui::Event::Clone(event); | 273 queued_event->event = ui::Event::Clone(event); |
| 260 queued_event->processed_target = std::move(processed_event_target); | 274 queued_event->processed_target = std::move(processed_event_target); |
| 261 event_queue_.push(std::move(queued_event)); | 275 event_queue_.push(std::move(queued_event)); |
| 262 } | 276 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 277 queued_event->processed_target->in_nonclient_area(), | 291 queued_event->processed_target->in_nonclient_area(), |
| 278 *queued_event->event, queued_event->processed_target->accelerator()); | 292 *queued_event->event, queued_event->processed_target->accelerator()); |
| 279 return; | 293 return; |
| 280 } | 294 } |
| 281 } | 295 } |
| 282 } | 296 } |
| 283 | 297 |
| 284 void WindowManagerState::DispatchInputEventToWindowImpl( | 298 void WindowManagerState::DispatchInputEventToWindowImpl( |
| 285 ServerWindow* target, | 299 ServerWindow* target, |
| 286 bool in_nonclient_area, | 300 bool in_nonclient_area, |
| 287 const ui::Event& event, | 301 const ui::Event& transformed_event, |
| 288 base::WeakPtr<Accelerator> accelerator) { | 302 base::WeakPtr<Accelerator> accelerator) { |
| 289 if (target == root_->parent()) | 303 if (target == root_->parent()) |
| 290 target = root_.get(); | 304 target = root_.get(); |
| 291 | 305 |
| 292 if (event.IsMousePointerEvent()) { | 306 if (transformed_event.IsMousePointerEvent()) { |
| 293 DCHECK(event_dispatcher_.mouse_cursor_source_window()); | 307 DCHECK(event_dispatcher_.mouse_cursor_source_window()); |
| 294 display_->UpdateNativeCursor( | 308 display_->UpdateNativeCursor( |
| 295 event_dispatcher_.mouse_cursor_source_window()->cursor()); | 309 event_dispatcher_.mouse_cursor_source_window()->cursor()); |
| 296 } | 310 } |
| 297 | 311 |
| 298 // If the event is in the non-client area the event goes to the owner of | 312 // If the event is in the non-client area the event goes to the owner of |
| 299 // the window. Otherwise if the window is an embed root, forward to the | 313 // the window. Otherwise if the window is an embed root, forward to the |
| 300 // embedded window. | 314 // embedded window. |
| 301 WindowTree* tree = | 315 WindowTree* tree = |
| 302 in_nonclient_area | 316 in_nonclient_area |
| (...skipping 12 matching lines...) Expand all Loading... |
| 315 } | 329 } |
| 316 | 330 |
| 317 // TOOD(sad): Adjust this delay, possibly make this dynamic. | 331 // TOOD(sad): Adjust this delay, possibly make this dynamic. |
| 318 const base::TimeDelta max_delay = base::debug::BeingDebugged() | 332 const base::TimeDelta max_delay = base::debug::BeingDebugged() |
| 319 ? base::TimeDelta::FromDays(1) | 333 ? base::TimeDelta::FromDays(1) |
| 320 : GetDefaultAckTimerDelay(); | 334 : GetDefaultAckTimerDelay(); |
| 321 event_ack_timer_.Start(FROM_HERE, max_delay, this, | 335 event_ack_timer_.Start(FROM_HERE, max_delay, this, |
| 322 &WindowManagerState::OnEventAckTimeout); | 336 &WindowManagerState::OnEventAckTimeout); |
| 323 | 337 |
| 324 tree_awaiting_input_ack_ = tree; | 338 tree_awaiting_input_ack_ = tree; |
| 339 event_awaiting_input_ack_ = ui::Event::Clone(transformed_event); |
| 325 if (accelerator) { | 340 if (accelerator) { |
| 326 event_awaiting_input_ack_ = ui::Event::Clone(event); | |
| 327 post_target_accelerator_ = accelerator; | 341 post_target_accelerator_ = accelerator; |
| 328 } | 342 } |
| 329 tree->DispatchInputEvent(target, event); | 343 tree->DispatchInputEvent(target, transformed_event); |
| 330 } | 344 } |
| 331 | 345 |
| 332 void WindowManagerState::OnAccelerator(uint32_t accelerator_id, | 346 void WindowManagerState::OnAccelerator(uint32_t accelerator_id, |
| 333 const ui::Event& event) { | 347 const ui::Event& event) { |
| 334 DCHECK(IsActive()); | 348 DCHECK(IsActive()); |
| 335 tree_->OnAccelerator(accelerator_id, event); | 349 tree_->OnAccelerator(accelerator_id, event); |
| 336 } | 350 } |
| 337 | 351 |
| 338 void WindowManagerState::SetFocusedWindowFromEventDispatcher( | 352 void WindowManagerState::SetFocusedWindowFromEventDispatcher( |
| 339 ServerWindow* new_focused_window) { | 353 ServerWindow* new_focused_window) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 352 | 366 |
| 353 void WindowManagerState::ReleaseNativeCapture() { | 367 void WindowManagerState::ReleaseNativeCapture() { |
| 354 platform_display_->ReleaseCapture(); | 368 platform_display_->ReleaseCapture(); |
| 355 } | 369 } |
| 356 | 370 |
| 357 void WindowManagerState::OnServerWindowCaptureLost(ServerWindow* window) { | 371 void WindowManagerState::OnServerWindowCaptureLost(ServerWindow* window) { |
| 358 DCHECK(window); | 372 DCHECK(window); |
| 359 window_server()->ProcessLostCapture(window); | 373 window_server()->ProcessLostCapture(window); |
| 360 } | 374 } |
| 361 | 375 |
| 362 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, | 376 void WindowManagerState::DispatchInputEventToWindow( |
| 363 bool in_nonclient_area, | 377 ServerWindow* target, |
| 364 const ui::Event& event, | 378 bool in_nonclient_area, |
| 365 Accelerator* accelerator) { | 379 const ui::Event& transformed_event, |
| 380 Accelerator* accelerator) { |
| 366 DCHECK(IsActive()); | 381 DCHECK(IsActive()); |
| 367 // TODO(sky): this needs to see if another wms has capture and if so forward | 382 // TODO(sky): this needs to see if another wms has capture and if so forward |
| 368 // to it. | 383 // to it. |
| 369 if (event_ack_timer_.IsRunning()) { | 384 if (event_ack_timer_.IsRunning()) { |
| 370 scoped_ptr<ProcessedEventTarget> processed_event_target( | 385 scoped_ptr<ProcessedEventTarget> processed_event_target( |
| 371 new ProcessedEventTarget(target, in_nonclient_area, accelerator)); | 386 new ProcessedEventTarget(target, in_nonclient_area, accelerator)); |
| 372 QueueEvent(event, std::move(processed_event_target)); | 387 QueueEvent(transformed_event, std::move(processed_event_target)); |
| 373 return; | 388 return; |
| 374 } | 389 } |
| 375 | 390 |
| 376 base::WeakPtr<Accelerator> weak_accelerator; | 391 base::WeakPtr<Accelerator> weak_accelerator; |
| 377 if (accelerator) | 392 if (accelerator) |
| 378 weak_accelerator = accelerator->GetWeakPtr(); | 393 weak_accelerator = accelerator->GetWeakPtr(); |
| 379 DispatchInputEventToWindowImpl(target, in_nonclient_area, event, | 394 DispatchInputEventToWindowImpl(target, in_nonclient_area, transformed_event, |
| 380 weak_accelerator); | 395 weak_accelerator); |
| 381 } | 396 } |
| 382 | 397 |
| 383 } // namespace ws | 398 } // namespace ws |
| 384 } // namespace mus | 399 } // namespace mus |
| OLD | NEW |