Bug 1265342 Part 2a: Move interval binary search method into ShapeInfo. r=dholbert

MozReview-Commit-ID: BxJxIU0RVAo

--HG--
extra : rebase_source : c822c3fd56fe8fc11aeb7aab10afa440a2a53931
This commit is contained in:
Brad Werth 2018-04-11 14:05:06 -07:00
Родитель ab7e20d492
Коммит 405f362460
1 изменённых файлов: 37 добавлений и 27 удалений

Просмотреть файл

@ -617,6 +617,16 @@ protected:
static UniquePtr<nscoord[]> ConvertToFloatLogical(
const nscoord aRadii[8],
WritingMode aWM);
// Some ShapeInfo subclasses may define their float areas in intervals.
// Each interval is a rectangle that is one device pixel deep in the block
// axis. The values are stored as block edges in the y coordinates,
// and inline edges as the x coordinates. Interval arrays should be sorted
// on increasing y values. This function uses a binary search to find the
// first interval that contains aTargetY. If no such interval exists, this
// function returns aIntervals.Length().
static size_t MinIntervalIndexContainingY(const nsTArray<nsRect>& aIntervals,
const nscoord aTargetY);
};
/////////////////////////////////////////////////////////////////////////////
@ -989,7 +999,6 @@ public:
void Translate(nscoord aLineLeft, nscoord aBlockStart) override;
private:
size_t MinIntervalIndexContainingY(const nscoord aTargetY) const;
nscoord LineEdge(const nscoord aBStart,
const nscoord aBEnd,
bool aLeft) const;
@ -1110,31 +1119,6 @@ nsFloatManager::ImageShapeInfo::ImageShapeInfo(
}
}
size_t
nsFloatManager::ImageShapeInfo::MinIntervalIndexContainingY(
const nscoord aTargetY) const
{
// Perform a binary search to find the minimum index of an interval
// that contains aTargetY. If no such interval exists, return a value
// equal to the number of intervals.
size_t startIdx = 0;
size_t endIdx = mIntervals.Length();
while (startIdx < endIdx) {
size_t midIdx = startIdx + (endIdx - startIdx) / 2;
if (mIntervals[midIdx].ContainsY(aTargetY)) {
return midIdx;
}
nscoord midY = mIntervals[midIdx].Y();
if (midY < aTargetY) {
startIdx = midIdx + 1;
} else {
endIdx = midIdx;
}
}
return endIdx;
}
nscoord
nsFloatManager::ImageShapeInfo::LineEdge(const nscoord aBStart,
const nscoord aBEnd,
@ -1154,7 +1138,7 @@ nsFloatManager::ImageShapeInfo::LineEdge(const nscoord aBStart,
nscoord lineEdge = aLeft ? nscoord_MAX : nscoord_MIN;
size_t intervalCount = mIntervals.Length();
for (size_t i = MinIntervalIndexContainingY(aBStart);
for (size_t i = MinIntervalIndexContainingY(mIntervals, aBStart);
i < intervalCount; ++i) {
// We can always get the bCoord from the intervals' mLineLeft,
// since the y() coordinate is duplicated in both points in the
@ -1715,6 +1699,32 @@ nsFloatManager::ShapeInfo::ConvertToFloatLogical(
logicalPoint.B(aWM));
}
/* static */ size_t
nsFloatManager::ShapeInfo::MinIntervalIndexContainingY(
const nsTArray<nsRect>& aIntervals,
const nscoord aTargetY)
{
// Perform a binary search to find the minimum index of an interval
// that contains aTargetY. If no such interval exists, return a value
// equal to the number of intervals.
size_t startIdx = 0;
size_t endIdx = aIntervals.Length();
while (startIdx < endIdx) {
size_t midIdx = startIdx + (endIdx - startIdx) / 2;
if (aIntervals[midIdx].ContainsY(aTargetY)) {
return midIdx;
}
nscoord midY = aIntervals[midIdx].Y();
if (midY < aTargetY) {
startIdx = midIdx + 1;
} else {
endIdx = midIdx;
}
}
return endIdx;
}
/* static */ UniquePtr<nscoord[]>
nsFloatManager::ShapeInfo::ConvertToFloatLogical(const nscoord aRadii[8],
WritingMode aWM)