autoclick_drag_event_rewriter.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/accessibility/autoclick/autoclick_drag_event_rewriter.h"
  5. namespace ash {
  6. void AutoclickDragEventRewriter::SetEnabled(bool enabled) {
  7. enabled_ = enabled;
  8. }
  9. bool AutoclickDragEventRewriter::IsEnabled() const {
  10. return enabled_;
  11. }
  12. ui::EventDispatchDetails AutoclickDragEventRewriter::RewriteEvent(
  13. const ui::Event& event,
  14. const Continuation continuation) {
  15. // Only rewrite mouse moved events to drag events when enabled.
  16. if (!enabled_)
  17. return SendEvent(continuation, &event);
  18. // On touchpads, a SCROLL_FLING_CANCEL can also indicate the start of a drag.
  19. // If this rewriter is enabled, a SCROLL_FLING_CANCEL should simply be
  20. // ignored.
  21. if (event.type() == ui::ET_SCROLL_FLING_CANCEL)
  22. return DiscardEvent(continuation);
  23. // Only rewrite move events, but any other type should still go through.
  24. if (event.type() != ui::ET_MOUSE_MOVED)
  25. return SendEvent(continuation, &event);
  26. const ui::MouseEvent* mouse_event = event.AsMouseEvent();
  27. // "Press" the left mouse button to make it seem like the user is holding it
  28. // down.
  29. int flags = mouse_event->flags() | ui::EF_LEFT_MOUSE_BUTTON;
  30. ui::MouseEvent rewritten_event(
  31. ui::ET_MOUSE_DRAGGED, mouse_event->location(),
  32. mouse_event->root_location(), mouse_event->time_stamp(), flags,
  33. mouse_event->changed_button_flags(), mouse_event->pointer_details());
  34. return SendEventFinally(continuation, &rewritten_event);
  35. }
  36. } // namespace ash