Reland [Mac] Replace Editing Word with Selected Suggestion from Touch Bar

WebContents::Replace() replaces the current text selection with a given
string. Currently, SuggestedTextTouchBarController replaces the
current user selection when a suggestion is chosen from the touch bar.

SuggestedTextTouchBarController now calculates a range that
encompasses the word in which the cursor resides. If the cursor is not
in or at the end of a word, the range representing the editing word
starts at the cursor position and has length 0.

When a suggestion is chosen from the touch bar, the selection within
the textfield is modified to encompass the word currently being
edited (which may be only a cursor position) and then
WebContents::Replace() is called to replace the selection.

A unit test was written to test that
editingWordFromText:cursorPosition: properly calculates the range
encompassing the current editing word for various combinations of word
and non-word characters.

Some parameter types were changed to reduce the number of conversions
from base::string16 to NSString and vice versa. Previously,
WebContentsTextObserver::DidChangeTextSelection() took a base::string16
as a parameter. It would then convert that input to NSString and pass
it to webContentsTextSelectionChanged:range: which would then call
editingWordRangeFromText:cursorPosition: which would then convert the
NSString back to a base::string16.

The call to BreakIterator::Init() was moved out of a DCHECK because
DCHECKs are stripped for release builds and the call to Init() should
not be removed.

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