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

Move InlineFlowBox::CollectLeafBoxesInLogicalOrder to RootInlineBox

The function is called only on RootInlineBox, and makes sense only when
called on an entire line.

Hence, this patch moves it to RootInlineBox to reduce confusion.

Change-Id: I9a2f283de54a3cce0658b11245f24e14b91c5908
Reviewed-on: https://chromium-review.googlesource.com/1220705
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590537}
parent 1da60342
...@@ -1628,63 +1628,6 @@ LayoutUnit InlineFlowBox::ComputeUnderAnnotationAdjustment( ...@@ -1628,63 +1628,6 @@ LayoutUnit InlineFlowBox::ComputeUnderAnnotationAdjustment(
return result; return result;
} }
void InlineFlowBox::CollectLeafBoxesInLogicalOrder(
Vector<InlineBox*>& leaf_boxes_in_logical_order,
CustomInlineBoxRangeReverse custom_reverse_implementation) const {
InlineBox* leaf = FirstLeafChild();
// FIXME: The reordering code is a copy of parts from BidiResolver::
// createBidiRunsForLine, operating directly on InlineBoxes, instead of
// BidiRuns. Investigate on how this code could possibly be shared.
unsigned char min_level = 128;
unsigned char max_level = 0;
// First find highest and lowest levels, and initialize
// leafBoxesInLogicalOrder with the leaf boxes in visual order.
for (; leaf; leaf = leaf->NextLeafChild()) {
min_level = std::min(min_level, leaf->BidiLevel());
max_level = std::max(max_level, leaf->BidiLevel());
leaf_boxes_in_logical_order.push_back(leaf);
}
if (GetLineLayoutItem().StyleRef().RtlOrdering() == EOrder::kVisual)
return;
// Reverse of reordering of the line (L2 according to Bidi spec):
// L2. From the highest level found in the text to the lowest odd level on
// each line, reverse any contiguous sequence of characters that are at that
// level or higher.
// Reversing the reordering of the line is only done up to the lowest odd
// level.
if (!(min_level % 2))
++min_level;
Vector<InlineBox*>::iterator end = leaf_boxes_in_logical_order.end();
while (min_level <= max_level) {
Vector<InlineBox*>::iterator it = leaf_boxes_in_logical_order.begin();
while (it != end) {
while (it != end) {
if ((*it)->BidiLevel() >= min_level)
break;
++it;
}
Vector<InlineBox*>::iterator first = it;
while (it != end) {
if ((*it)->BidiLevel() < min_level)
break;
++it;
}
Vector<InlineBox*>::iterator last = it;
if (custom_reverse_implementation)
(*custom_reverse_implementation)(first, last);
else
std::reverse(first, last);
}
++min_level;
}
}
const char* InlineFlowBox::BoxName() const { const char* InlineFlowBox::BoxName() const {
return "InlineFlowBox"; return "InlineFlowBox";
} }
......
...@@ -105,14 +105,6 @@ class InlineFlowBox : public InlineBox { ...@@ -105,14 +105,6 @@ class InlineFlowBox : public InlineBox {
InlineBox* FirstLeafChild() const; InlineBox* FirstLeafChild() const;
InlineBox* LastLeafChild() const; InlineBox* LastLeafChild() const;
typedef void (*CustomInlineBoxRangeReverse)(
Vector<InlineBox*>::iterator first,
Vector<InlineBox*>::iterator last);
void CollectLeafBoxesInLogicalOrder(
Vector<InlineBox*>&,
CustomInlineBoxRangeReverse custom_reverse_implementation =
nullptr) const;
DISABLE_CFI_PERF DISABLE_CFI_PERF
void SetConstructed() final { void SetConstructed() final {
InlineBox::SetConstructed(); InlineBox::SetConstructed();
......
...@@ -748,6 +748,63 @@ bool RootInlineBox::IncludeLeadingForBox(InlineBox* box) const { ...@@ -748,6 +748,63 @@ bool RootInlineBox::IncludeLeadingForBox(InlineBox* box) const {
(box->GetLineLayoutItem().IsText() && !box->IsText())); (box->GetLineLayoutItem().IsText() && !box->IsText()));
} }
void RootInlineBox::CollectLeafBoxesInLogicalOrder(
Vector<InlineBox*>& leaf_boxes_in_logical_order,
CustomInlineBoxRangeReverse custom_reverse_implementation) const {
InlineBox* leaf = FirstLeafChild();
// FIXME: The reordering code is a copy of parts from BidiResolver::
// createBidiRunsForLine, operating directly on InlineBoxes, instead of
// BidiRuns. Investigate on how this code could possibly be shared.
unsigned char min_level = 128;
unsigned char max_level = 0;
// First find highest and lowest levels, and initialize
// leafBoxesInLogicalOrder with the leaf boxes in visual order.
for (; leaf; leaf = leaf->NextLeafChild()) {
min_level = std::min(min_level, leaf->BidiLevel());
max_level = std::max(max_level, leaf->BidiLevel());
leaf_boxes_in_logical_order.push_back(leaf);
}
if (GetLineLayoutItem().StyleRef().RtlOrdering() == EOrder::kVisual)
return;
// Reverse of reordering of the line (L2 according to Bidi spec):
// L2. From the highest level found in the text to the lowest odd level on
// each line, reverse any contiguous sequence of characters that are at that
// level or higher.
// Reversing the reordering of the line is only done up to the lowest odd
// level.
if (!(min_level % 2))
++min_level;
Vector<InlineBox*>::iterator end = leaf_boxes_in_logical_order.end();
while (min_level <= max_level) {
Vector<InlineBox*>::iterator it = leaf_boxes_in_logical_order.begin();
while (it != end) {
while (it != end) {
if ((*it)->BidiLevel() >= min_level)
break;
++it;
}
Vector<InlineBox*>::iterator first = it;
while (it != end) {
if ((*it)->BidiLevel() < min_level)
break;
++it;
}
Vector<InlineBox*>::iterator last = it;
if (custom_reverse_implementation)
(*custom_reverse_implementation)(first, last);
else
std::reverse(first, last);
}
++min_level;
}
}
const InlineBox* RootInlineBox::GetLogicalStartNonPseudoBox() const { const InlineBox* RootInlineBox::GetLogicalStartNonPseudoBox() const {
Vector<InlineBox*> leaf_boxes_in_logical_order; Vector<InlineBox*> leaf_boxes_in_logical_order;
CollectLeafBoxesInLogicalOrder(leaf_boxes_in_logical_order); CollectLeafBoxesInLogicalOrder(leaf_boxes_in_logical_order);
......
...@@ -204,6 +204,14 @@ class RootInlineBox : public InlineFlowBox { ...@@ -204,6 +204,14 @@ class RootInlineBox : public InlineFlowBox {
return InlineFlowBox::LogicalBottomLayoutOverflow(LineBottom()); return InlineFlowBox::LogicalBottomLayoutOverflow(LineBottom());
} }
typedef void (*CustomInlineBoxRangeReverse)(
Vector<InlineBox*>::iterator first,
Vector<InlineBox*>::iterator last);
void CollectLeafBoxesInLogicalOrder(
Vector<InlineBox*>&,
CustomInlineBoxRangeReverse custom_reverse_implementation =
nullptr) const;
const InlineBox* GetLogicalStartNonPseudoBox() const; const InlineBox* GetLogicalStartNonPseudoBox() const;
const InlineBox* GetLogicalEndNonPseudoBox() const; const InlineBox* GetLogicalEndNonPseudoBox() const;
......
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