[Mac] Collapse NSCandidateListTouchBarItem if Text is Selected

On Safari, when there is text selected and not just a cursor in text,
the NSCandidateListTouchBarItem collapses.

This change checks if the selection range has a non-zero length, and
if it does, collapses the created NSCandidateListTouchBarItem. The
text suggestions are still accessible by clicking on the collapsed
NSTouchBarItem.

A unit test, CollapsedCandidateListTest, was written to test that
the NSTouchBarItem properly collapses according to the length of the
selection range.

Bug: 717553
Change-Id: I25671450f43b4ba14197f76e431f9212d5494187
Reviewed-on: https://chromium-review.googlesource.com/1144300
Commit-Queue: Tessa Nijssen <tnijssen@google.com>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Sarah Chan <spqchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576975}
2 files changed