Commit 118ff984 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Refactor AdjustInlineBoxPositionForPrimaryDirection to make it symmetric

This patch refactors the function by wrapping certain logic into
IsEndOfDifferentDirection(), so that the remaining function body is
symmetric for left and right edge of |inline_box|.

This allows further refactoring, and also eases implementation of NG
version of bidi adjustment.

Bug: 822575
Change-Id: I40874a50fd07592d42afe6f596bc3481b41b9932
Reviewed-on: https://chromium-review.googlesource.com/997135Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548686}
parent c04354be
......@@ -93,6 +93,15 @@ bool IsStartOfDifferentDirection(const InlineBox* inline_box) {
return prev_box->BidiLevel() > inline_box->BidiLevel();
}
// TODO(editing-dev): This function is almost identical to
// |IsStartOfDifferentDirection|. Try to unify them.
bool IsEndOfDifferentDirection(const InlineBox* inline_box) {
const InlineBox* const next_box = inline_box->NextLeafChild();
if (!next_box)
return true;
return next_box->BidiLevel() >= inline_box->BidiLevel();
}
template <typename Strategy>
PositionTemplate<Strategy> DownstreamIgnoringEditingBoundaries(
PositionTemplate<Strategy> position) {
......@@ -119,11 +128,10 @@ InlineBoxPosition AdjustInlineBoxPositionForPrimaryDirection(
InlineBox* inline_box,
int caret_offset) {
if (caret_offset == inline_box->CaretRightmostOffset()) {
InlineBox* const next_box = inline_box->NextLeafChild();
if (!next_box || next_box->BidiLevel() >= inline_box->BidiLevel())
if (IsEndOfDifferentDirection(inline_box))
return InlineBoxPosition(inline_box, caret_offset);
const unsigned level = next_box->BidiLevel();
const unsigned level = inline_box->NextLeafChild()->BidiLevel();
InlineBox* const prev_box =
InlineBoxTraversal::FindLeftBidiRun(*inline_box, level);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment