From 405f36246021c2af5f7ce7d26f62938293cd8013 Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Wed, 11 Apr 2018 14:05:06 -0700 Subject: [PATCH] Bug 1265342 Part 2a: Move interval binary search method into ShapeInfo. r=dholbert MozReview-Commit-ID: BxJxIU0RVAo --HG-- extra : rebase_source : c822c3fd56fe8fc11aeb7aab10afa440a2a53931 --- layout/generic/nsFloatManager.cpp | 64 ++++++++++++++++++------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/layout/generic/nsFloatManager.cpp b/layout/generic/nsFloatManager.cpp index 90e142647673..6456403a216e 100644 --- a/layout/generic/nsFloatManager.cpp +++ b/layout/generic/nsFloatManager.cpp @@ -617,6 +617,16 @@ protected: static UniquePtr 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& 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& 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 nsFloatManager::ShapeInfo::ConvertToFloatLogical(const nscoord aRadii[8], WritingMode aWM)