Revise EventRewriter API.


This is a modified reland of ad149d1ecf01a774014cf98611b83b94121c3fac


Since http://crrev.com/556458 there have been two (or three) completely
different ways of ‘returning’ events from an EventRewriter:

- The original output parameter on RewriteEvent(), with the clunky
  NextDispatchEvent() to produce multiple events.

- Calling SendEventToEventSource(source, event), when the replacement
  event must pass through later event rewriters. (This had the problem
  of not tracking the original source.)

- Several EventRewriters do an end run around the rewriter system in
  some cases, e.g. calling WindowEventDispatcher::OnEventFromSource()
  after a timeout, since the original RewriteEvent() interface could
  only produce events in response to incoming events.

This CL replaces all the above cases with a consistent return mechanism,
using Send…() functions. This is inspired by SendEventToEventSource(),
but has the caller provide the output functions explicitly, so that
multiple sources can correctly share an EventRewriter (as Ash does).

This CL contains the EventRewriter/EventSource revision, under
//ui/events, plus conversions of ‘trivial’ rewriters (essentially those
that only used RewriteEvent()). Other rewriters will be converted in
separate CLs for review by their respective OWNERS, because removing
NextDispatchEvent() or asynchronous dispatch generally requires some
logic change.

This CL includes a compatibility shim for the old API, which will be
removed once all rewriters have changed.

How to convert an EventRewriter:

- When the incoming event is accepted unchanged, replace old API uses of
      return EVENT_REWRITE_CONTINUE;
  with new API
      return SendEvent(continuation, &incoming_event);

- When the incoming event is to be discarded, replace old API uses of
      return EVENT_REWRITE_DISCARD;
  with new API
      return DiscardEvent(continuation);

- When the incoming event is to be replaced, replace old API uses of
      *rewritten_event = std::move(new_event);
      return EVENT_REWRITE_REWRITTEN;
  with new API
      return SendEventFinally(continuation, replacement_event);

- When the incoming event is to be replaced, and the replacement event
  should pass through later rewriters, replace old API uses of
      return SendEventToEventSource(source, replacement_event);
  with new API
      return SendEvent(continuation, replacement_event);

- When the incoming event is to be replaced by multiple events, replace
  old API uses of
      *rewritten_event = std::move(new_event_1);
      // record new_event_2 … new_event_N
      return EVENT_REWRITE_DISPATCH_ANOTHER;
  with new API
      details = SendEventFinally(continuation, new_event_1);
      ⋮
      return SendEventFinally(continuation, new_event_N);

... TBRs for files unchanged in this reland:
TBR=afakhry@chromium.org,pkasting@chromium.org,kenrb@chromium.org

Bug: None
Change-Id: Icdbf52dcb79939d0f38b473b719ee089ddbd9c58
Reviewed-on: https://chromium-review.googlesource.com/c/1437697
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Kevin Schoedel <kpschoedel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631851}
14 files changed