File: input_router.h

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (116 lines) | stat: -rw-r--r-- 5,093 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_INPUT_ROUTER_H_
#define CONTENT_BROWSER_RENDERER_HOST_INPUT_INPUT_ROUTER_H_

#include "base/functional/callback_forward.h"
#include "base/task/sequenced_task_runner.h"
#include "cc/input/touch_action.h"
#include "content/browser/renderer_host/input/gesture_event_queue.h"
#include "content/browser/renderer_host/input/passthrough_touch_event_queue.h"
#include "content/common/content_export.h"
#include "content/common/input/event_with_latency_info.h"
#include "content/public/common/input/native_web_keyboard_event.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/mojom/input/input_event_result.mojom-shared.h"
#include "third_party/blink/public/mojom/input/input_handler.mojom.h"
#include "third_party/blink/public/mojom/input/touch_event.mojom.h"

namespace content {

// The InputRouter allows the embedder to customize how input events are
// sent to the renderer, and how responses are dispatched to the browser.
// While the router should respect the relative order in which events are
// received, it is free to customize when those events are dispatched.
class InputRouter {
 public:
  struct CONTENT_EXPORT Config {
    Config();
    GestureEventQueue::Config gesture_config;
    PassthroughTouchEventQueue::Config touch_config;
  };

  virtual ~InputRouter() = default;

  // Note: if the event is processed immediately, the supplied callback is run
  // *synchronously*. If |this| is destroyed while waiting on a result from
  // the renderer, then callbacks are *not* run.
  using MouseEventCallback =
      base::OnceCallback<void(const MouseEventWithLatencyInfo& event,
                              blink::mojom::InputEventResultSource ack_source,
                              blink::mojom::InputEventResultState ack_result)>;
  virtual void SendMouseEvent(const MouseEventWithLatencyInfo& mouse_event,
                              MouseEventCallback event_result_callback) = 0;

  virtual void SendWheelEvent(
      const MouseWheelEventWithLatencyInfo& wheel_event) = 0;

  using KeyboardEventCallback = base::OnceCallback<void(
      const NativeWebKeyboardEventWithLatencyInfo& event,
      blink::mojom::InputEventResultSource ack_source,
      blink::mojom::InputEventResultState ack_result)>;
  virtual void SendKeyboardEvent(
      const NativeWebKeyboardEventWithLatencyInfo& key_event,
      KeyboardEventCallback event_result_callback) = 0;

  virtual void SendGestureEvent(
      const GestureEventWithLatencyInfo& gesture_event) = 0;

  virtual void SendTouchEvent(
      const TouchEventWithLatencyInfo& touch_event) = 0;

  // Notify the router about whether the current page is mobile-optimized (i.e.,
  // the site has a mobile-friendly viewport).
  virtual void NotifySiteIsMobileOptimized(bool is_mobile_optimized) = 0;

  // Whether there are any events pending dispatch to or ack from the renderer.
  virtual bool HasPendingEvents() const = 0;

  // A scale factor to scale the coordinate in WebInputEvent from DIP
  // to viewport.
  virtual void SetDeviceScaleFactor(float device_scale_factor) = 0;

  // Return the currently allowed touch-action.
  virtual absl::optional<cc::TouchAction> AllowedTouchAction() = 0;

  // Return the currently active touch-action.
  virtual absl::optional<cc::TouchAction> ActiveTouchAction() = 0;

  virtual void SetForceEnableZoom(bool enabled) = 0;

  // Create and bind a new host channel.
  virtual mojo::PendingRemote<blink::mojom::WidgetInputHandlerHost> BindNewHost(
      scoped_refptr<base::SequencedTaskRunner> task_runner) = 0;

  // Used to stop an active fling if such exists.
  virtual void StopFling() = 0;

  // In the case when a gesture event is bubbled from a child frame to the main
  // frame, we set the touch action in the main frame Auto even if there is no
  // pending touch start.
  virtual void ForceSetTouchActionAuto() = 0;

  // Called when the renderer notifies a change in whether or not it has touch
  // event handlers registered.
  virtual void OnHasTouchEventConsumers(
      blink::mojom::TouchEventConsumersPtr consumers) = 0;

  // Will resolve the given callback once all prior input has been fully
  // propagated through the system such that subsequent input will be subject
  // to its effects. e.g. Input that follows a scroll gesture that affects
  // OOPIF hit-testing will need to wait until updated CompositorFrames have
  // been submitted to the browser.
  virtual void WaitForInputProcessed(base::OnceClosure callback) = 0;

  // Acks any pending touch events that are waiting for acks from the renderer.
  // Any future acks for those events from the renderer will be ignored.
  virtual void FlushTouchEventQueue() = 0;
};

}  // namespace content

#endif  // CONTENT_BROWSER_RENDERER_HOST_INPUT_INPUT_ROUTER_H_