| 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/common/event_matcher_util.h" |
| 8 #include "components/mus/ws/accelerator.h" | 9 #include "components/mus/ws/accelerator.h" |
| 9 #include "components/mus/ws/display_manager.h" | 10 #include "components/mus/ws/display_manager.h" |
| 10 #include "components/mus/ws/platform_display.h" | 11 #include "components/mus/ws/platform_display.h" |
| 11 #include "components/mus/ws/server_window.h" | 12 #include "components/mus/ws/server_window.h" |
| 12 #include "components/mus/ws/user_display_manager.h" | 13 #include "components/mus/ws/user_display_manager.h" |
| 13 #include "components/mus/ws/user_id_tracker.h" | 14 #include "components/mus/ws/user_id_tracker.h" |
| 14 #include "components/mus/ws/window_server.h" | 15 #include "components/mus/ws/window_server.h" |
| 15 #include "components/mus/ws/window_tree.h" | 16 #include "components/mus/ws/window_tree.h" |
| 16 #include "services/shell/public/interfaces/connector.mojom.h" | 17 #include "services/shell/public/interfaces/connector.mojom.h" |
| 17 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
| 18 | 19 |
| 19 namespace mus { | 20 namespace mus { |
| 20 namespace ws { | 21 namespace ws { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 24 // Debug accelerator IDs start far above the highest valid Windows command ID |
| 25 // (0xDFFF) and Chrome's highest IDC command ID. |
| 26 const uint32_t kPrintWindowsDebugAcceleratorId = 1 << 24; |
| 27 |
| 23 base::TimeDelta GetDefaultAckTimerDelay() { | 28 base::TimeDelta GetDefaultAckTimerDelay() { |
| 24 #if defined(NDEBUG) | 29 #if defined(NDEBUG) |
| 25 return base::TimeDelta::FromMilliseconds(100); | 30 return base::TimeDelta::FromMilliseconds(100); |
| 26 #else | 31 #else |
| 27 return base::TimeDelta::FromMilliseconds(1000); | 32 return base::TimeDelta::FromMilliseconds(1000); |
| 28 #endif | 33 #endif |
| 29 } | 34 } |
| 30 | 35 |
| 31 bool EventsCanBeCoalesced(const ui::Event& one, const ui::Event& two) { | 36 bool EventsCanBeCoalesced(const ui::Event& one, const ui::Event& two) { |
| 32 if (one.type() != two.type() || one.flags() != two.flags()) | 37 if (one.type() != two.type() || one.flags() != two.flags()) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 ServerWindow::Properties())); | 183 ServerWindow::Properties())); |
| 179 // Our root is always a child of the Display's root. Do this | 184 // Our root is always a child of the Display's root. Do this |
| 180 // before the WindowTree has been created so that the client doesn't get | 185 // before the WindowTree has been created so that the client doesn't get |
| 181 // notified of the add, bounds change and visibility change. | 186 // notified of the add, bounds change and visibility change. |
| 182 root_->SetBounds(gfx::Rect(display->root_window()->bounds().size())); | 187 root_->SetBounds(gfx::Rect(display->root_window()->bounds().size())); |
| 183 root_->SetVisible(true); | 188 root_->SetVisible(true); |
| 184 display->root_window()->Add(root_.get()); | 189 display->root_window()->Add(root_.get()); |
| 185 | 190 |
| 186 event_dispatcher_.set_root(root_.get()); | 191 event_dispatcher_.set_root(root_.get()); |
| 187 event_dispatcher_.set_surface_id(surface_id); | 192 event_dispatcher_.set_surface_id(surface_id); |
| 193 |
| 194 AddDebugAccelerators(); |
| 188 } | 195 } |
| 189 | 196 |
| 190 bool WindowManagerState::IsActive() const { | 197 bool WindowManagerState::IsActive() const { |
| 191 return display()->GetActiveWindowManagerState() == this; | 198 return display()->GetActiveWindowManagerState() == this; |
| 192 } | 199 } |
| 193 | 200 |
| 194 void WindowManagerState::Activate(const gfx::Point& mouse_location_on_screen) { | 201 void WindowManagerState::Activate(const gfx::Point& mouse_location_on_screen) { |
| 195 root_->SetVisible(true); | 202 root_->SetVisible(true); |
| 196 event_dispatcher_.Reset(); | 203 event_dispatcher_.Reset(); |
| 197 event_dispatcher_.SetMousePointerScreenLocation(mouse_location_on_screen); | 204 event_dispatcher_.SetMousePointerScreenLocation(mouse_location_on_screen); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 event_awaiting_input_ack_ = ui::Event::Clone(event); | 329 event_awaiting_input_ack_ = ui::Event::Clone(event); |
| 323 post_target_accelerator_ = accelerator; | 330 post_target_accelerator_ = accelerator; |
| 324 } | 331 } |
| 325 | 332 |
| 326 // Ignore |tree| because it will receive the event via normal dispatch. | 333 // Ignore |tree| because it will receive the event via normal dispatch. |
| 327 window_server()->SendToEventObservers(event, user_id_, tree); | 334 window_server()->SendToEventObservers(event, user_id_, tree); |
| 328 | 335 |
| 329 tree->DispatchInputEvent(target, event); | 336 tree->DispatchInputEvent(target, event); |
| 330 } | 337 } |
| 331 | 338 |
| 339 void WindowManagerState::AddDebugAccelerators() { |
| 340 // Always register the accelerators, even if they only work in debug, so that |
| 341 // keyboard behavior is the same in release and debug builds. |
| 342 mojom::EventMatcherPtr matcher = CreateKeyMatcher( |
| 343 mus::mojom::KeyboardCode::S, |
| 344 mus::mojom::kEventFlagControlDown | mus::mojom::kEventFlagAltDown |
| 345 | mus::mojom::kEventFlagShiftDown); |
| 346 event_dispatcher_.AddAccelerator(kPrintWindowsDebugAcceleratorId, |
| 347 std::move(matcher)); |
| 348 } |
| 349 |
| 350 bool WindowManagerState::HandleDebugAccelerator(uint32_t accelerator_id) { |
| 351 #if !defined(NDEBUG) |
| 352 if (accelerator_id == kPrintWindowsDebugAcceleratorId) { |
| 353 // Error so it will be collected in system logs. |
| 354 LOG(ERROR) << "ServerWindow hierarchy:\n" |
| 355 << root()->GetDebugWindowHierarchy(); |
| 356 return true; |
| 357 } |
| 358 #endif |
| 359 return false; |
| 360 } |
| 361 |
| 332 //////////////////////////////////////////////////////////////////////////////// | 362 //////////////////////////////////////////////////////////////////////////////// |
| 333 // EventDispatcherDelegate: | 363 // EventDispatcherDelegate: |
| 334 | 364 |
| 335 void WindowManagerState::OnAccelerator(uint32_t accelerator_id, | 365 void WindowManagerState::OnAccelerator(uint32_t accelerator_id, |
| 336 const ui::Event& event) { | 366 const ui::Event& event) { |
| 337 DCHECK(IsActive()); | 367 DCHECK(IsActive()); |
| 368 if (HandleDebugAccelerator(accelerator_id)) |
| 369 return; |
| 338 tree_->OnAccelerator(accelerator_id, event); | 370 tree_->OnAccelerator(accelerator_id, event); |
| 339 } | 371 } |
| 340 | 372 |
| 341 void WindowManagerState::SetFocusedWindowFromEventDispatcher( | 373 void WindowManagerState::SetFocusedWindowFromEventDispatcher( |
| 342 ServerWindow* new_focused_window) { | 374 ServerWindow* new_focused_window) { |
| 343 DCHECK(IsActive()); | 375 DCHECK(IsActive()); |
| 344 display_->SetFocusedWindow(new_focused_window); | 376 display_->SetFocusedWindow(new_focused_window); |
| 345 } | 377 } |
| 346 | 378 |
| 347 ServerWindow* WindowManagerState::GetFocusedWindowForEventDispatcher() { | 379 ServerWindow* WindowManagerState::GetFocusedWindowForEventDispatcher() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 weak_accelerator); | 420 weak_accelerator); |
| 389 } | 421 } |
| 390 | 422 |
| 391 void WindowManagerState::OnEventTargetNotFound(const ui::Event& event) { | 423 void WindowManagerState::OnEventTargetNotFound(const ui::Event& event) { |
| 392 window_server()->SendToEventObservers(event, user_id_, | 424 window_server()->SendToEventObservers(event, user_id_, |
| 393 nullptr /* ignore_tree */); | 425 nullptr /* ignore_tree */); |
| 394 } | 426 } |
| 395 | 427 |
| 396 } // namespace ws | 428 } // namespace ws |
| 397 } // namespace mus | 429 } // namespace mus |
| OLD | NEW |