Commit 08de81e0 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Improved 'Event propagation' section.

parent 21750c65
...@@ -204,11 +204,16 @@ ...@@ -204,11 +204,16 @@
\def\eventpropagationfigure{ \def\eventpropagationfigure{
\begin{figure}[h!] \begin{figure}[h!]
\center \center
\subfigure[An event is triggered in the white area. The event is first \subfigure[
delegated to the white area from te gray area (2). After gesture An event is triggered in the white area. The event driver
detection, it is propagated back to the gray area (6) \emph{unless} delegates the event to the event area tree (1) and the gray root
propagation has been stopped in the rotation detection component area delegates it to the white area (2). The white area delegates
between (3) and (4).]{ it to drag tracker for gesture detection (3), which may trigger a
gesture in the application (4-5). If propagation has not been
stopped by the drag tracker, the event is propagated to the gray
event area (6) which also detects drag gestures that may be
triggered in the application (7-9).
]{
\begin{tikzpicture}[node distance=5.5em] \begin{tikzpicture}[node distance=5.5em]
\draw node[draw=black, minimum width=190, minimum height=140] (screen) at (0,0) {}; \draw node[draw=black, minimum width=190, minimum height=140] (screen) at (0,0) {};
\draw node[fill=gray!50, draw=black!70, minimum height=100, minimum width=100] (screen) at (-0.1,-0.1) {}; \draw node[fill=gray!50, draw=black!70, minimum height=100, minimum width=100] (screen) at (-0.1,-0.1) {};
...@@ -221,10 +226,10 @@ ...@@ -221,10 +226,10 @@
\draw node[block, below of=gray] (white) {White event area} \draw node[block, below of=gray] (white) {White event area}
edge[linefrom, bend left=15] node[left] {2} (gray) edge[linefrom, bend left=15] node[left] {2} (gray)
edge[lineto, bend right=15] node[right] {6} (gray); edge[lineto, bend right=15] node[right] {6} (gray);
\draw node[block, right of=white, xshift=4em] {rotation detection} \draw node[block, right of=white, xshift=4em] {drag tracker}
edge[linefrom, bend right=15] node[above] {3} (white) edge[linefrom, bend right=15] node[above] {3} (white)
edge[lineto, dotted, bend left=15] node[below] {4} (white); edge[lineto, dotted, bend left=15] node[below] {4} (white);
\draw node[block, right of=gray, xshift=4em] {rotation detection} \draw node[block, right of=gray, xshift=4em] {drag tracker}
edge[linefrom, bend right=15] node[above] {7} (gray) edge[linefrom, bend right=15] node[above] {7} (gray)
edge[lineto, dotted, bend left=15] node[below] {8} (gray); edge[lineto, dotted, bend left=15] node[below] {8} (gray);
\draw node[block, below of=white] {Application} \draw node[block, below of=white] {Application}
...@@ -233,8 +238,14 @@ ...@@ -233,8 +238,14 @@
\end{tikzpicture} \end{tikzpicture}
} }
\quad \quad
\subfigure[An event is triggered in the gray event area, it does not even \subfigure[
reach the white event area.]{ An event is triggered in the gray area, but outside the white area.
The event driver delegates the event to the gray event area (1).
Since the white area does not contain the event, delegation stops
and the event is passed on to the drag tracker of the gray event
area (2). If a gesture is detected (3), the event area triggers the
corresponding handler in the application (4).
]{
\begin{tikzpicture}[node distance=5.5em] \begin{tikzpicture}[node distance=5.5em]
\draw node[draw=black, minimum width=190, minimum height=140] (screen) at (0,0) {}; \draw node[draw=black, minimum width=190, minimum height=140] (screen) at (0,0) {};
\draw node[fill=gray!50, draw=black!70, minimum height=100, minimum width=100] (screen) at (-0.1,-0.1) {}; \draw node[fill=gray!50, draw=black!70, minimum height=100, minimum width=100] (screen) at (-0.1,-0.1) {};
...@@ -245,8 +256,8 @@ ...@@ -245,8 +256,8 @@
\draw node[block, below of=driver] (gray) {Gray event area} \draw node[block, below of=driver] (gray) {Gray event area}
edge[linefrom] node[left] {1} (driver); edge[linefrom] node[left] {1} (driver);
\draw node[block, below of=gray] (white) {White event area}; \draw node[block, below of=gray] (white) {White event area};
\draw node[block, right of=white, xshift=4em] {rotation detection}; \draw node[block, right of=white, xshift=4em] {drag tracker};
\draw node[block, right of=gray, xshift=4em] {rotation detection} \draw node[block, right of=gray, xshift=4em] {drag tracker}
edge[linefrom, bend right=15] node[above] {2} (gray) edge[linefrom, bend right=15] node[above] {2} (gray)
edge[lineto, dotted, bend left=15] node[below] {3} (gray); edge[lineto, dotted, bend left=15] node[below] {3} (gray);
\draw node[block, below of=white] {Application} \draw node[block, below of=white] {Application}
...@@ -254,11 +265,13 @@ ...@@ -254,11 +265,13 @@
\end{tikzpicture} \end{tikzpicture}
} }
\caption{ \caption{
Two nested squares both listen to ``tap'' gestures. The two figures Two nested squares both respond to ``drag'' gestures. When the
both show a touch object triggering an event, represented by a white square is dragged, the gray square stays at its current
black dot. The event is delegated through the event area tree in position. The two figures both show a touch object triggering an
the order indicated by the numbered arrow labels. Dotted arrows event, represented by a black dot. The event is delegated and
represent a flow of gestures, regular arrows represent events. propagated through the event area tree in the order indicated by
the numbered arrow labels. Dotted arrows represent a flow of
gestures, regular arrows represent events.
} }
\label{fig:eventpropagation} \label{fig:eventpropagation}
\end{figure} \end{figure}
......
...@@ -352,9 +352,9 @@ detection for every new gesture-based application. ...@@ -352,9 +352,9 @@ detection for every new gesture-based application.
\label{sec:eventpropagation} \label{sec:eventpropagation}
Another problem occurs when event areas overlap, as shown by figure Another problem occurs when event areas overlap, as shown by figure
\ref{fig:eventpropagation}. When the white square is rotated, the gray \ref{fig:eventpropagation}. When the white square is dragged, the gray
square should keep its current orientation. This means that events that are square should stay at its current position. This means that events that are
used for rotation of the white square, should not be used for rotation of used for dragging of the white square, should not be used for dragging of
the gray square. The use of event areas alone does not provide a solution the gray square. The use of event areas alone does not provide a solution
here, since both the gray and the white event area accept an event that here, since both the gray and the white event area accept an event that
occurs within the white square. occurs within the white square.
...@@ -363,24 +363,24 @@ detection for every new gesture-based application. ...@@ -363,24 +363,24 @@ detection for every new gesture-based application.
there is a common solution (used by GTK \cite{gtkeventpropagation}, among there is a common solution (used by GTK \cite{gtkeventpropagation}, among
others). An event is passed to an ``event handler''. If the handler returns others). An event is passed to an ``event handler''. If the handler returns
\texttt{true}, the event is considered ``handled'' and is not \texttt{true}, the event is considered ``handled'' and is not
``propagated'' to other widgets. ``propagated'' to other widgets. Applied to the example of the draggable
squares, the rotation detection component of the white square should stop
Applied to the example of the rotating squares, the rotation detection the propagation of events to the event area of the gray square.
component of the white square should stop the propagation of events to the
event area of the gray square. This is illustrated in figure
\ref{fig:eventpropagation}.
In the example, rotation of the white square has priority over rotation of In the example, rotation of the white square has priority over rotation of
the gray square because the white area is the widget actually being touched the gray square because the white area is the widget actually being touched
at the screen surface. In general, events should be delegated to event at the screen surface. In general, events should be delegated to event
areas according to the order in which the event areas are positioned over areas according to the order in which the event areas are positioned over
each other. The tree structure in which event areas are arranged, is an each other. The tree structure in which event areas are arranged, is an
ideal tool to determine the order in which an event is delegated. Event ideal tool to determine the order in which an event is delegated. An
areas in deeper layers of the tree are positioned on top of their parent. object touching the screen is essentially touching the deepest event area
An object touching the screen is essentially touching the deepest event in the tree that contains the triggered event, which must be the first to
area in the tree that contains the triggered event. A gesture detection receive the event. When the gesture trackers of the event area are
component can stop the propagation of the event by its corresponding event finished with the event, it is propagated to the siblings and parent in the
area. event area tree. Optionally, a gesture tracker can stop the propagation of
the event by its corresponding event area. Figure
\ref{fig:eventpropagation} demonstrates event propagation in the example of
the draggable squares.
\eventpropagationfigure \eventpropagationfigure
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment