| 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 22 matching lines...) Expand all Loading... |
| 33 return false; | 33 return false; |
| 34 | 34 |
| 35 // TODO(sad): wheel events can also be merged. | 35 // TODO(sad): wheel events can also be merged. |
| 36 if (one.type() != ui::ET_POINTER_MOVED) | 36 if (one.type() != ui::ET_POINTER_MOVED) |
| 37 return false; | 37 return false; |
| 38 | 38 |
| 39 return one.AsPointerEvent()->pointer_id() == | 39 return one.AsPointerEvent()->pointer_id() == |
| 40 two.AsPointerEvent()->pointer_id(); | 40 two.AsPointerEvent()->pointer_id(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 scoped_ptr<ui::Event> CoalesceEvents(scoped_ptr<ui::Event> first, | 43 std::unique_ptr<ui::Event> CoalesceEvents(std::unique_ptr<ui::Event> first, |
| 44 scoped_ptr<ui::Event> second) { | 44 std::unique_ptr<ui::Event> second) { |
| 45 DCHECK(first->type() == ui::ET_POINTER_MOVED) | 45 DCHECK(first->type() == ui::ET_POINTER_MOVED) |
| 46 << " Non-move events cannot be merged yet."; | 46 << " Non-move events cannot be merged yet."; |
| 47 // For mouse moves, the new event just replaces the old event. | 47 // For mouse moves, the new event just replaces the old event. |
| 48 return second; | 48 return second; |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 class WindowManagerState::ProcessedEventTarget { | 53 class WindowManagerState::ProcessedEventTarget { |
| 54 public: | 54 public: |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 root_->SetVisible(true); | 202 root_->SetVisible(true); |
| 203 event_dispatcher_.Reset(); | 203 event_dispatcher_.Reset(); |
| 204 event_dispatcher_.SetMousePointerScreenLocation(mouse_location_on_screen); | 204 event_dispatcher_.SetMousePointerScreenLocation(mouse_location_on_screen); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void WindowManagerState::Deactivate() { | 207 void WindowManagerState::Deactivate() { |
| 208 root_->SetVisible(false); | 208 root_->SetVisible(false); |
| 209 event_dispatcher_.Reset(); | 209 event_dispatcher_.Reset(); |
| 210 // The tree is no longer active, so no point in dispatching any further | 210 // The tree is no longer active, so no point in dispatching any further |
| 211 // events. | 211 // events. |
| 212 std::queue<scoped_ptr<QueuedEvent>> event_queue; | 212 std::queue<std::unique_ptr<QueuedEvent>> event_queue; |
| 213 event_queue.swap(event_queue_); | 213 event_queue.swap(event_queue_); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void WindowManagerState::ProcessEvent(const ui::Event& event) { | 216 void WindowManagerState::ProcessEvent(const ui::Event& event) { |
| 217 // If this is still waiting for an ack from a previously sent event, then | 217 // If this is still waiting for an ack from a previously sent event, then |
| 218 // queue up the event to be dispatched once the ack is received. | 218 // queue up the event to be dispatched once the ack is received. |
| 219 if (event_ack_timer_.IsRunning()) { | 219 if (event_ack_timer_.IsRunning()) { |
| 220 if (!event_queue_.empty() && !event_queue_.back()->processed_target && | 220 if (!event_queue_.empty() && !event_queue_.back()->processed_target && |
| 221 EventsCanBeCoalesced(*event_queue_.back()->event, event)) { | 221 EventsCanBeCoalesced(*event_queue_.back()->event, event)) { |
| 222 event_queue_.back()->event = CoalesceEvents( | 222 event_queue_.back()->event = CoalesceEvents( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 250 } | 250 } |
| 251 | 251 |
| 252 void WindowManagerState::OnEventAckTimeout() { | 252 void WindowManagerState::OnEventAckTimeout() { |
| 253 // TODO(sad): Figure out what we should do. | 253 // TODO(sad): Figure out what we should do. |
| 254 NOTIMPLEMENTED() << "Event ACK timed out."; | 254 NOTIMPLEMENTED() << "Event ACK timed out."; |
| 255 OnEventAck(tree_awaiting_input_ack_, mojom::EventResult::UNHANDLED); | 255 OnEventAck(tree_awaiting_input_ack_, mojom::EventResult::UNHANDLED); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void WindowManagerState::QueueEvent( | 258 void WindowManagerState::QueueEvent( |
| 259 const ui::Event& event, | 259 const ui::Event& event, |
| 260 scoped_ptr<ProcessedEventTarget> processed_event_target) { | 260 std::unique_ptr<ProcessedEventTarget> processed_event_target) { |
| 261 scoped_ptr<QueuedEvent> queued_event(new QueuedEvent); | 261 std::unique_ptr<QueuedEvent> queued_event(new QueuedEvent); |
| 262 queued_event->event = ui::Event::Clone(event); | 262 queued_event->event = ui::Event::Clone(event); |
| 263 queued_event->processed_target = std::move(processed_event_target); | 263 queued_event->processed_target = std::move(processed_event_target); |
| 264 event_queue_.push(std::move(queued_event)); | 264 event_queue_.push(std::move(queued_event)); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void WindowManagerState::ProcessNextEventFromQueue() { | 267 void WindowManagerState::ProcessNextEventFromQueue() { |
| 268 // Loop through |event_queue_| stopping after dispatching the first valid | 268 // Loop through |event_queue_| stopping after dispatching the first valid |
| 269 // event. | 269 // event. |
| 270 while (!event_queue_.empty()) { | 270 while (!event_queue_.empty()) { |
| 271 scoped_ptr<QueuedEvent> queued_event = std::move(event_queue_.front()); | 271 std::unique_ptr<QueuedEvent> queued_event = std::move(event_queue_.front()); |
| 272 event_queue_.pop(); | 272 event_queue_.pop(); |
| 273 if (!queued_event->processed_target) { | 273 if (!queued_event->processed_target) { |
| 274 event_dispatcher_.ProcessEvent(*queued_event->event); | 274 event_dispatcher_.ProcessEvent(*queued_event->event); |
| 275 return; | 275 return; |
| 276 } | 276 } |
| 277 if (queued_event->processed_target->IsValid()) { | 277 if (queued_event->processed_target->IsValid()) { |
| 278 DispatchInputEventToWindowImpl( | 278 DispatchInputEventToWindowImpl( |
| 279 queued_event->processed_target->window(), | 279 queued_event->processed_target->window(), |
| 280 queued_event->processed_target->in_nonclient_area(), | 280 queued_event->processed_target->in_nonclient_area(), |
| 281 *queued_event->event, queued_event->processed_target->accelerator()); | 281 *queued_event->event, queued_event->processed_target->accelerator()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 363 } |
| 364 | 364 |
| 365 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, | 365 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, |
| 366 bool in_nonclient_area, | 366 bool in_nonclient_area, |
| 367 const ui::Event& event, | 367 const ui::Event& event, |
| 368 Accelerator* accelerator) { | 368 Accelerator* accelerator) { |
| 369 DCHECK(IsActive()); | 369 DCHECK(IsActive()); |
| 370 // TODO(sky): this needs to see if another wms has capture and if so forward | 370 // TODO(sky): this needs to see if another wms has capture and if so forward |
| 371 // to it. | 371 // to it. |
| 372 if (event_ack_timer_.IsRunning()) { | 372 if (event_ack_timer_.IsRunning()) { |
| 373 scoped_ptr<ProcessedEventTarget> processed_event_target( | 373 std::unique_ptr<ProcessedEventTarget> processed_event_target( |
| 374 new ProcessedEventTarget(target, in_nonclient_area, accelerator)); | 374 new ProcessedEventTarget(target, in_nonclient_area, accelerator)); |
| 375 QueueEvent(event, std::move(processed_event_target)); | 375 QueueEvent(event, std::move(processed_event_target)); |
| 376 return; | 376 return; |
| 377 } | 377 } |
| 378 | 378 |
| 379 base::WeakPtr<Accelerator> weak_accelerator; | 379 base::WeakPtr<Accelerator> weak_accelerator; |
| 380 if (accelerator) | 380 if (accelerator) |
| 381 weak_accelerator = accelerator->GetWeakPtr(); | 381 weak_accelerator = accelerator->GetWeakPtr(); |
| 382 DispatchInputEventToWindowImpl(target, in_nonclient_area, event, | 382 DispatchInputEventToWindowImpl(target, in_nonclient_area, event, |
| 383 weak_accelerator); | 383 weak_accelerator); |
| 384 } | 384 } |
| 385 | 385 |
| 386 } // namespace ws | 386 } // namespace ws |
| 387 } // namespace mus | 387 } // namespace mus |
| OLD | NEW |