author Ting-Yu Lin <>
Sun, 03 May 2015 23:37:00 +0200
changeset 275826 c83422ef7f416ee02249b0cc0d6b8a08f9369461
child 320120 0049e7998c1a820f4a987b851f147803ee3f4ced
permissions -rw-r--r--
Bug 1110039 - Part 2.4 - Add AccessibleCaretEventHub. r=roc See AccessibleCaretEventHub.h for the class description. Both TouchCaret and SelectionCarets have their event handling mechanism, which lead to a lot of code duplication. Now AccessibleCaretEventHub serves as the single entry point for all events and callbacks. We also encountered performance issues in SelectionCarets because many unnecessary events might be dispatched to Gaia driven by the selection changed events. SelectionCarets did not have clear internal states to avoid this. To solve it, AccessibleCaretEventHub implements state classes, and rely on the current states to call the CopyPasteManager's handler only when it's needed. For example, when dragging a caret, we do not interest in NotifySelectionChanged() for updating the carets. Since we've known a caret is being dragging, we can call UpdateCarets() directly. Hence DragCaretState does not override OnSelectionChanged().

// Steps to generate AccessibleCaretEventHubStates.png
// 1. Install Graphviz
// 2. dot -T png -o AccessibleCaretEventHubStates.png
digraph event_hub_states {
  node [style=filled];
  edge [color="gray30", fontcolor="gray20", fontsize=12]

  NoAction [label="NoAction\n(Initial)"color="#96FF2F"];
  NoAction -> PressCaret [label="Press & on a caret"];
  NoAction -> PressNoCaret [label="Press & not on a caret"];
  NoAction -> Scroll [label="Scroll start"];

  PressCaret [color="#84D8FF"];
  PressCaret -> DragCaret [label="Move & distance is large"];
  PressCaret -> NoAction [label="Release (synthesizing a tap)"];

  DragCaret [color="#84D8FF"];
  DragCaret -> DragCaret [label="Move"];
  DragCaret -> NoAction [label="Release"];

  PressNoCaret [color="#E8C516"];
  PressNoCaret -> NoAction [label="Move & distance is large or\nRelease or\nBlur"];
  PressNoCaret -> LongTap [label="Long tap"];
  PressNoCaret -> Scroll [label="Scroll start", constraint=false];

  LongTap [color="#E8C516"]
  LongTap -> NoAction;

  Scroll [color="#FF9022"]
  Scroll -> PostScroll [label="Scroll end"];
  Scroll -> NoAction [label="Blur"];

  PostScroll [color="#FF9022"]
  PostScroll -> Scroll [label="Scroll start"];
  PostScroll -> NoAction [label="Blur or\nWait 300ms"];
  PostScroll -> NoAction [label="Press (forward to NoAction)", constraint=false];