зеркало из https://github.com/mozilla/gecko-dev.git
Bug 841192. Part 12: Move RoundedRectIntersectsRect from nsDisplayList.cpp to nsLayoutUtils. r=mattwoodrow
--HG-- extra : rebase_source : aa0ad96c363b70895b068a6d4805f9164cc03b27
This commit is contained in:
Родитель
9c8685b71a
Коммит
8efacba3aa
|
@ -1657,69 +1657,6 @@ nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuil
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// Helper for RoundedRectIntersectsRect.
|
||||
static bool
|
||||
CheckCorner(nscoord aXOffset, nscoord aYOffset,
|
||||
nscoord aXRadius, nscoord aYRadius)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aXOffset > 0 && aYOffset > 0,
|
||||
"must not pass nonpositives to CheckCorner");
|
||||
NS_ABORT_IF_FALSE(aXRadius >= 0 && aYRadius >= 0,
|
||||
"must not pass negatives to CheckCorner");
|
||||
|
||||
// Avoid floating point math unless we're either (1) within the
|
||||
// quarter-ellipse area at the rounded corner or (2) outside the
|
||||
// rounding.
|
||||
if (aXOffset >= aXRadius || aYOffset >= aYRadius)
|
||||
return true;
|
||||
|
||||
// Convert coordinates to a unit circle with (0,0) as the center of
|
||||
// curvature, and see if we're inside the circle or outside.
|
||||
float scaledX = float(aXRadius - aXOffset) / float(aXRadius);
|
||||
float scaledY = float(aYRadius - aYOffset) / float(aYRadius);
|
||||
return scaledX * scaledX + scaledY * scaledY < 1.0f;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return whether any part of aTestRect is inside of the rounded
|
||||
* rectangle formed by aBounds and aRadii (which are indexed by the
|
||||
* NS_CORNER_* constants in nsStyleConsts.h).
|
||||
*
|
||||
* See also RoundedRectContainsRect.
|
||||
*/
|
||||
static bool
|
||||
RoundedRectIntersectsRect(const nsRect& aRoundedRect, nscoord aRadii[8],
|
||||
const nsRect& aTestRect)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aTestRect.Intersects(aRoundedRect),
|
||||
"we should already have tested basic rect intersection");
|
||||
|
||||
// distances from this edge of aRoundedRect to opposite edge of aTestRect,
|
||||
// which we know are positive due to the Intersects check above.
|
||||
nsMargin insets;
|
||||
insets.top = aTestRect.YMost() - aRoundedRect.y;
|
||||
insets.right = aRoundedRect.XMost() - aTestRect.x;
|
||||
insets.bottom = aRoundedRect.YMost() - aTestRect.y;
|
||||
insets.left = aTestRect.XMost() - aRoundedRect.x;
|
||||
|
||||
// Check whether the bottom-right corner of aTestRect is inside the
|
||||
// top left corner of aBounds when rounded by aRadii, etc. If any
|
||||
// corner is not, then fail; otherwise succeed.
|
||||
return CheckCorner(insets.left, insets.top,
|
||||
aRadii[NS_CORNER_TOP_LEFT_X],
|
||||
aRadii[NS_CORNER_TOP_LEFT_Y]) &&
|
||||
CheckCorner(insets.right, insets.top,
|
||||
aRadii[NS_CORNER_TOP_RIGHT_X],
|
||||
aRadii[NS_CORNER_TOP_RIGHT_Y]) &&
|
||||
CheckCorner(insets.right, insets.bottom,
|
||||
aRadii[NS_CORNER_BOTTOM_RIGHT_X],
|
||||
aRadii[NS_CORNER_BOTTOM_RIGHT_Y]) &&
|
||||
CheckCorner(insets.left, insets.bottom,
|
||||
aRadii[NS_CORNER_BOTTOM_LEFT_X],
|
||||
aRadii[NS_CORNER_BOTTOM_LEFT_Y]);
|
||||
}
|
||||
|
||||
// Check that the rounded border of aFrame, added to aToReferenceFrame,
|
||||
// intersects aRect. Assumes that the unrounded border has already
|
||||
// been checked for intersection.
|
||||
|
|
|
@ -1425,6 +1425,62 @@ nsLayoutUtils::RoundedRectIntersectRect(const nsRect& aRoundedRect,
|
|||
return result;
|
||||
}
|
||||
|
||||
// Helper for RoundedRectIntersectsRect.
|
||||
static bool
|
||||
CheckCorner(nscoord aXOffset, nscoord aYOffset,
|
||||
nscoord aXRadius, nscoord aYRadius)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aXOffset > 0 && aYOffset > 0,
|
||||
"must not pass nonpositives to CheckCorner");
|
||||
NS_ABORT_IF_FALSE(aXRadius >= 0 && aYRadius >= 0,
|
||||
"must not pass negatives to CheckCorner");
|
||||
|
||||
// Avoid floating point math unless we're either (1) within the
|
||||
// quarter-ellipse area at the rounded corner or (2) outside the
|
||||
// rounding.
|
||||
if (aXOffset >= aXRadius || aYOffset >= aYRadius)
|
||||
return true;
|
||||
|
||||
// Convert coordinates to a unit circle with (0,0) as the center of
|
||||
// curvature, and see if we're inside the circle or outside.
|
||||
float scaledX = float(aXRadius - aXOffset) / float(aXRadius);
|
||||
float scaledY = float(aYRadius - aYOffset) / float(aYRadius);
|
||||
return scaledX * scaledX + scaledY * scaledY < 1.0f;
|
||||
}
|
||||
|
||||
bool
|
||||
nsLayoutUtils::RoundedRectIntersectsRect(const nsRect& aRoundedRect,
|
||||
const nscoord aRadii[8],
|
||||
const nsRect& aTestRect)
|
||||
{
|
||||
if (!aTestRect.Intersects(aRoundedRect))
|
||||
return false;
|
||||
|
||||
// distances from this edge of aRoundedRect to opposite edge of aTestRect,
|
||||
// which we know are positive due to the Intersects check above.
|
||||
nsMargin insets;
|
||||
insets.top = aTestRect.YMost() - aRoundedRect.y;
|
||||
insets.right = aRoundedRect.XMost() - aTestRect.x;
|
||||
insets.bottom = aRoundedRect.YMost() - aTestRect.y;
|
||||
insets.left = aTestRect.XMost() - aRoundedRect.x;
|
||||
|
||||
// Check whether the bottom-right corner of aTestRect is inside the
|
||||
// top left corner of aBounds when rounded by aRadii, etc. If any
|
||||
// corner is not, then fail; otherwise succeed.
|
||||
return CheckCorner(insets.left, insets.top,
|
||||
aRadii[NS_CORNER_TOP_LEFT_X],
|
||||
aRadii[NS_CORNER_TOP_LEFT_Y]) &&
|
||||
CheckCorner(insets.right, insets.top,
|
||||
aRadii[NS_CORNER_TOP_RIGHT_X],
|
||||
aRadii[NS_CORNER_TOP_RIGHT_Y]) &&
|
||||
CheckCorner(insets.right, insets.bottom,
|
||||
aRadii[NS_CORNER_BOTTOM_RIGHT_X],
|
||||
aRadii[NS_CORNER_BOTTOM_RIGHT_Y]) &&
|
||||
CheckCorner(insets.left, insets.bottom,
|
||||
aRadii[NS_CORNER_BOTTOM_LEFT_X],
|
||||
aRadii[NS_CORNER_BOTTOM_LEFT_Y]);
|
||||
}
|
||||
|
||||
nsRect
|
||||
nsLayoutUtils::MatrixTransformRectOut(const nsRect &aBounds,
|
||||
const gfx3DMatrix &aMatrix, float aFactor)
|
||||
|
|
|
@ -657,6 +657,15 @@ public:
|
|||
const nscoord aRadii[8],
|
||||
const nsRect& aContainedRect);
|
||||
|
||||
/**
|
||||
* Return whether any part of aTestRect is inside of the rounded
|
||||
* rectangle formed by aBounds and aRadii (which are indexed by the
|
||||
* NS_CORNER_* constants in nsStyleConsts.h). This is precise.
|
||||
*/
|
||||
static bool RoundedRectIntersectsRect(const nsRect& aRoundedRect,
|
||||
const nscoord aRadii[8],
|
||||
const nsRect& aTestRect);
|
||||
|
||||
enum {
|
||||
PAINT_IN_TRANSFORM = 0x01,
|
||||
PAINT_SYNC_DECODE_IMAGES = 0x02,
|
||||
|
|
Загрузка…
Ссылка в новой задаче