Mozart: Add hit testing interfaces.
Define Mojo interfaces for hit testing functionality modeled after
Flutter's hit test traversal process.
Each node can supply a hit test behavior to control how hit testing
should occur within its bounds. The key properties are visibility,
pruning, and a hit rect.
Visibility is one of |INVISIBLE|, |TRANSLUCENT|, and |OPAQUE|.
This property determines whether a node can be hit and its effect
upon subsequent traversals once hit.
Pruning determines whether children of a node will be hit tested
at all. This can be used to suppress hit testing for a subgraph.
And the hit rect is just a finer specification of the hittable region
within a node's bounds. In the future, this will likely expand
to describe more complex regions.
The results of a hit test are described structurally as a tree which
records the event dispatch order for nodes which are hit as well as
the path by which they were reached.
In general, the dispatch order goes from the most specific hit node
outwards which can be significant for certain operations.
BUG=
R=abarth@google.com
Review URL: https://codereview.chromium.org/1748363002 .
diff --git a/mojo/services/gfx/composition/interfaces/nodes.mojom b/mojo/services/gfx/composition/interfaces/nodes.mojom
index 602ec44..31420a9 100644
--- a/mojo/services/gfx/composition/interfaces/nodes.mojom
+++ b/mojo/services/gfx/composition/interfaces/nodes.mojom
@@ -55,6 +55,46 @@
// missing content for an earlier version of that content or for a placeholder
// if not available.
//
+// HIT TESTING
+//
+// Hit testing is the process of determining which nodes within a scene graph
+// should be responsible for handling events which occur within their visual
+// space on the screen.
+//
+// For example, when the user touches objects on a touch screen, the input
+// system asks the compositor to performs a hit test at the contact point to
+// find the nodes which represent the objects the user wants to interact with.
+// The result of the hit test is a list of nodes, in dispatch order, which
+// have asked to participate in handling events related to the contact point.
+//
+// Nodes may be opaque, translucent, or invisible to the hit testing
+// process depending on whether they prevent or allow targets visually
+// behind them from being hit and whether they can actually be hit,
+// as specified by |HitTestBehavior.visibility|.
+//
+// Nodes are added to the hit test result whenever one of their opaque children
+// is hit. This is useful for scrolling containers which may need to intercept
+// certain gestures within the space of their children and therefore need to
+// be added to the hit test result themselves.
+//
+// Nodes can also request to prune hit testing for their children, which
+// prevents their children from being hit.
+//
+// Hit testing proceeds recursively in post-order traversal (the reverse of
+// the drawing order). Intuitively, this means that the most specific
+// (deepest) nodes of the tree are tested before their ancestors.
+//
+// Starting from the root, the compositor transforms the point of interest
+// into the node's coordinate system, rejects the node if the point is
+// outside of the node's clip region, otherwise recursively tests the
+// node's children (those which were selected by the combinator rule)
+// until the first opaque target hit is found, then evaluates the node's
+// |HitTestBehavior| to determine whether the node was hit. Nodes are
+// accumulated into a hit test result in the order in which they were
+// determined to have been hit.
+//
+// See |HitTestBehavior| for more details.
+//
// INSTANCING
//
// The compositor allows nodes to be referenced and reused multiple times
@@ -128,15 +168,13 @@
// If null, the node does not apply any clipping of its own.
mojo.Rect? content_clip;
- // The hit test id to report if anything within the node is hit.
- // Use |kHitIdNone| if the node should not be hit tested.
- //
- // TODO(jeffbrown): This scheme is probably too naive.
- uint32 hit_id = kHitIdNone;
-
// The Combinator to apply when processing the children of this node.
Combinator combinator = Combinator.MERGE;
+ // The hit testing behavior of the node.
+ // If null, the node is considered invisible for hit testing.
+ HitTestBehavior? hit_test_behavior;
+
// The ids of the children of this node.
// It is an error to specify a node id that does not refer to a valid
// node or which creates a cycle in the graph; the compositor will close