Index: ui/gfx/render_text_harfbuzz.cc |
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc |
index a1aced102e8d93dface016e39cc224fa58edd455..b1387d8414012168698ae4783a2b1a6d832bdd6c 100644 |
--- a/ui/gfx/render_text_harfbuzz.cc |
+++ b/ui/gfx/render_text_harfbuzz.cc |
@@ -651,8 +651,6 @@ SelectionModel RenderTextHarfBuzz::AdjacentCharSelectionModel( |
SelectionModel RenderTextHarfBuzz::AdjacentWordSelectionModel( |
const SelectionModel& selection, |
VisualCursorDirection direction) { |
- // TODO(ckocagil): This implementation currently matches RenderTextWin, but it |
- // should match the native behavior on other platforms. |
if (obscured()) |
return EdgeSelectionModel(direction); |
@@ -662,6 +660,8 @@ SelectionModel RenderTextHarfBuzz::AdjacentWordSelectionModel( |
if (!success) |
return selection; |
+ // Match OS specific word break behavior. |
+#if defined(OS_WIN) |
size_t pos; |
if (direction == CURSOR_RIGHT) { |
pos = std::min(selection.caret_pos() + 1, text().length()); |
@@ -694,6 +694,20 @@ SelectionModel RenderTextHarfBuzz::AdjacentWordSelectionModel( |
} |
} |
return SelectionModel(pos, CURSOR_FORWARD); |
+#else |
+ SelectionModel cur(selection); |
+ for (;;) { |
+ cur = AdjacentCharSelectionModel(cur, direction); |
+ size_t run = GetRunContainingCaret(cur); |
+ if (run == runs_.size()) |
+ break; |
+ const bool is_forward = runs_[run]->is_rtl == (direction == CURSOR_LEFT); |
+ size_t cursor = cur.caret_pos(); |
+ if (is_forward ? iter.IsEndOfWord(cursor) : iter.IsStartOfWord(cursor)) |
+ break; |
+ } |
+ return cur; |
+#endif |
} |
std::vector<Rect> RenderTextHarfBuzz::GetSubstringBounds(const Range& range) { |