Commit fe9bf7bf authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Wrap some traversal logic of SelectionModifierCharacter into a function

This patch introduces LeadingBoxOfEntireSecondaryRun() to wrap some
traversal logic, and also reduce the frequency |box| gets changed.

Change-Id: I8bf6c8170370bfb92e8a44a0620069015f11a07d
Reviewed-on: https://chromium-review.googlesource.com/1026930
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553809}
parent fb429719
...@@ -243,6 +243,23 @@ bool IsAfterAtomicInlineOrLineBreak(const InlineBox& box, int offset) { ...@@ -243,6 +243,23 @@ bool IsAfterAtomicInlineOrLineBreak(const InlineBox& box, int offset) {
return box.GetLineLayoutItem().IsAtomicInlineLevel(); return box.GetLineLayoutItem().IsAtomicInlineLevel();
} }
template <typename Traversal>
const InlineBox* LeadingBoxOfEntireSecondaryRun(const InlineBox* box) {
unsigned char level = box->BidiLevel();
// TODO(xiaochengh): Use another runner variable instead of |box|.
while (true) {
box = Traversal::FindBackwardBoundaryOfEntireBidiRun(*box, level);
if (box->BidiLevel() == level)
break;
level = box->BidiLevel();
box = Traversal::FindForwardBoundaryOfEntireBidiRun(*box, level);
if (box->BidiLevel() == level)
break;
level = box->BidiLevel();
}
return box;
}
template <typename Strategy, typename Traversal> template <typename Strategy, typename Traversal>
static PositionTemplate<Strategy> TraverseInternalAlgorithm( static PositionTemplate<Strategy> TraverseInternalAlgorithm(
const VisiblePositionTemplate<Strategy>& visible_position) { const VisiblePositionTemplate<Strategy>& visible_position) {
...@@ -371,16 +388,7 @@ static PositionTemplate<Strategy> TraverseInternalAlgorithm( ...@@ -371,16 +388,7 @@ static PositionTemplate<Strategy> TraverseInternalAlgorithm(
} }
// Trailing edge of a secondary run. Set to the leading edge of // Trailing edge of a secondary run. Set to the leading edge of
// the entire run. // the entire run.
while (true) { box = LeadingBoxOfEntireSecondaryRun<Traversal>(box);
box = Traversal::FindBackwardBoundaryOfEntireBidiRun(*box, level);
if (box->BidiLevel() == level)
break;
level = box->BidiLevel();
box = Traversal::FindForwardBoundaryOfEntireBidiRun(*box, level);
if (box->BidiLevel() == level)
break;
level = box->BidiLevel();
}
offset = Traversal::CaretMinOffsetOf(primary_direction, *box); offset = Traversal::CaretMinOffsetOf(primary_direction, *box);
break; break;
} }
......
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