2013-03-04 13:56:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "DisplayListClipState.h"
|
|
|
|
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2017-02-01 01:07:35 +03:00
|
|
|
void
|
|
|
|
DisplayListClipState::ClearUpToASR(const ActiveScrolledRoot* aASR)
|
|
|
|
{
|
|
|
|
while (mClipChainContentDescendants &&
|
|
|
|
ActiveScrolledRoot::IsAncestor(aASR, mClipChainContentDescendants->mASR)) {
|
|
|
|
mClipChainContentDescendants = mClipChainContentDescendants->mParent;
|
|
|
|
}
|
|
|
|
while (mClipChainContainingBlockDescendants &&
|
|
|
|
ActiveScrolledRoot::IsAncestor(aASR, mClipChainContainingBlockDescendants->mASR)) {
|
|
|
|
mClipChainContainingBlockDescendants = mClipChainContainingBlockDescendants->mParent;
|
|
|
|
}
|
|
|
|
InvalidateCurrentCombinedClipChain(aASR);
|
|
|
|
}
|
|
|
|
|
|
|
|
const DisplayItemClipChain*
|
|
|
|
DisplayListClipState::GetCurrentCombinedClipChain(nsDisplayListBuilder* aBuilder)
|
2013-03-04 13:56:00 +04:00
|
|
|
{
|
2017-02-01 01:07:35 +03:00
|
|
|
if (mCurrentCombinedClipChainIsValid) {
|
|
|
|
return mCurrentCombinedClipChain;
|
2013-03-04 13:56:00 +04:00
|
|
|
}
|
2017-02-01 01:07:35 +03:00
|
|
|
if (!mClipChainContentDescendants && !mClipChainContainingBlockDescendants) {
|
|
|
|
mCurrentCombinedClipChain = nullptr;
|
|
|
|
mCurrentCombinedClipChainIsValid = true;
|
2013-03-04 13:56:00 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-01 01:07:35 +03:00
|
|
|
|
|
|
|
mCurrentCombinedClipChain =
|
|
|
|
aBuilder->CreateClipChainIntersection(mCurrentCombinedClipChain,
|
|
|
|
mClipChainContentDescendants,
|
|
|
|
mClipChainContainingBlockDescendants);
|
|
|
|
mCurrentCombinedClipChainIsValid = true;
|
|
|
|
return mCurrentCombinedClipChain;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ApplyClip(nsDisplayListBuilder* aBuilder,
|
|
|
|
const DisplayItemClipChain*& aClipToModify,
|
|
|
|
const ActiveScrolledRoot* aASR,
|
|
|
|
DisplayItemClipChain& aClipChainOnStack)
|
|
|
|
{
|
|
|
|
aClipChainOnStack.mASR = aASR;
|
|
|
|
if (aClipToModify && aClipToModify->mASR == aASR) {
|
|
|
|
// Intersect with aClipToModify and replace the clip chain item.
|
|
|
|
aClipChainOnStack.mClip.IntersectWith(aClipToModify->mClip);
|
|
|
|
aClipChainOnStack.mParent = aClipToModify->mParent;
|
|
|
|
aClipToModify = &aClipChainOnStack;
|
|
|
|
} else if (!aClipToModify ||
|
|
|
|
ActiveScrolledRoot::IsAncestor(aClipToModify->mASR, aASR)) {
|
|
|
|
// Add a new clip chain item at the bottom.
|
|
|
|
aClipChainOnStack.mParent = aClipToModify;
|
|
|
|
aClipToModify = &aClipChainOnStack;
|
2013-03-04 13:56:00 +04:00
|
|
|
} else {
|
2017-02-01 01:07:35 +03:00
|
|
|
// We need to insert / intersect a DisplayItemClipChain in the middle of the
|
|
|
|
// aClipToModify chain. This is a very rare case.
|
|
|
|
// Find the common ancestor and have the builder create the DisplayItemClipChain
|
|
|
|
// intersection. This will create new DisplayItemClipChain objects for all
|
|
|
|
// descendants of ancestorSC and we will not hold on to a pointer to
|
|
|
|
// aClipChainOnStack.
|
|
|
|
const DisplayItemClipChain* ancestorSC = aClipToModify;
|
|
|
|
while (ancestorSC && ActiveScrolledRoot::IsAncestor(aASR, ancestorSC->mASR)) {
|
|
|
|
ancestorSC = ancestorSC->mParent;
|
|
|
|
}
|
|
|
|
aClipChainOnStack.mParent = nullptr;
|
|
|
|
aClipToModify =
|
|
|
|
aBuilder->CreateClipChainIntersection(ancestorSC, aClipToModify, &aClipChainOnStack);
|
2013-03-04 13:56:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-06 15:08:13 +04:00
|
|
|
void
|
2017-02-01 01:07:35 +03:00
|
|
|
DisplayListClipState::ClipContainingBlockDescendants(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect,
|
2013-03-06 15:08:13 +04:00
|
|
|
const nscoord* aRadii,
|
2017-02-01 01:07:35 +03:00
|
|
|
DisplayItemClipChain& aClipChainOnStack)
|
2013-03-06 15:08:13 +04:00
|
|
|
{
|
|
|
|
if (aRadii) {
|
2017-02-01 01:07:35 +03:00
|
|
|
aClipChainOnStack.mClip.SetTo(aRect, aRadii);
|
2013-03-06 15:08:13 +04:00
|
|
|
} else {
|
2017-02-01 01:07:35 +03:00
|
|
|
aClipChainOnStack.mClip.SetTo(aRect);
|
2013-03-06 15:08:13 +04:00
|
|
|
}
|
2017-02-01 01:07:35 +03:00
|
|
|
const ActiveScrolledRoot* asr = aBuilder->CurrentActiveScrolledRoot();
|
|
|
|
ApplyClip(aBuilder, mClipChainContainingBlockDescendants, asr, aClipChainOnStack);
|
|
|
|
InvalidateCurrentCombinedClipChain(asr);
|
2013-03-06 15:08:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-01 01:07:35 +03:00
|
|
|
DisplayListClipState::ClipContentDescendants(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect,
|
2013-07-26 05:36:05 +04:00
|
|
|
const nscoord* aRadii,
|
2017-02-01 01:07:35 +03:00
|
|
|
DisplayItemClipChain& aClipChainOnStack)
|
2013-03-06 15:08:13 +04:00
|
|
|
{
|
2013-07-26 05:36:05 +04:00
|
|
|
if (aRadii) {
|
2017-02-01 01:07:35 +03:00
|
|
|
aClipChainOnStack.mClip.SetTo(aRect, aRadii);
|
2013-07-26 05:36:05 +04:00
|
|
|
} else {
|
2017-02-01 01:07:35 +03:00
|
|
|
aClipChainOnStack.mClip.SetTo(aRect);
|
2013-03-06 15:08:13 +04:00
|
|
|
}
|
2017-02-01 01:07:35 +03:00
|
|
|
const ActiveScrolledRoot* asr = aBuilder->CurrentActiveScrolledRoot();
|
|
|
|
ApplyClip(aBuilder, mClipChainContentDescendants, asr, aClipChainOnStack);
|
|
|
|
InvalidateCurrentCombinedClipChain(asr);
|
2013-03-06 15:08:13 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:21:06 +04:00
|
|
|
void
|
2017-02-01 01:07:35 +03:00
|
|
|
DisplayListClipState::ClipContentDescendants(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect,
|
2014-07-23 09:21:06 +04:00
|
|
|
const nsRect& aRoundedRect,
|
|
|
|
const nscoord* aRadii,
|
2017-02-01 01:07:35 +03:00
|
|
|
DisplayItemClipChain& aClipChainOnStack)
|
2014-07-23 09:21:06 +04:00
|
|
|
{
|
|
|
|
if (aRadii) {
|
2017-02-01 01:07:35 +03:00
|
|
|
aClipChainOnStack.mClip.SetTo(aRect, aRoundedRect, aRadii);
|
2014-07-23 09:21:06 +04:00
|
|
|
} else {
|
|
|
|
nsRect intersect = aRect.Intersect(aRoundedRect);
|
2017-02-01 01:07:35 +03:00
|
|
|
aClipChainOnStack.mClip.SetTo(intersect);
|
2014-07-23 09:21:06 +04:00
|
|
|
}
|
2017-02-01 01:07:35 +03:00
|
|
|
const ActiveScrolledRoot* asr = aBuilder->CurrentActiveScrolledRoot();
|
|
|
|
ApplyClip(aBuilder, mClipChainContentDescendants, asr, aClipChainOnStack);
|
|
|
|
InvalidateCurrentCombinedClipChain(asr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DisplayListClipState::InvalidateCurrentCombinedClipChain(const ActiveScrolledRoot* aInvalidateUpTo)
|
|
|
|
{
|
|
|
|
mCurrentCombinedClipChainIsValid = false;
|
|
|
|
while (mCurrentCombinedClipChain &&
|
|
|
|
ActiveScrolledRoot::IsAncestor(aInvalidateUpTo, mCurrentCombinedClipChain->mASR)) {
|
|
|
|
mCurrentCombinedClipChain = mCurrentCombinedClipChain->mParent;
|
2014-07-23 09:21:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-06 15:08:13 +04:00
|
|
|
void
|
|
|
|
DisplayListClipState::ClipContainingBlockDescendantsToContentBox(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
2017-02-01 01:07:35 +03:00
|
|
|
DisplayItemClipChain& aClipChainOnStack,
|
2013-03-06 15:08:13 +04:00
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
|
|
|
nscoord radii[8];
|
|
|
|
bool hasBorderRadius = aFrame->GetContentBoxBorderRadii(radii);
|
|
|
|
if (!hasBorderRadius && (aFlags & ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect clipRect = aFrame->GetContentRectRelativeToSelf() +
|
|
|
|
aBuilder->ToReferenceFrame(aFrame);
|
|
|
|
// If we have a border-radius, we have to clip our content to that
|
|
|
|
// radius.
|
2017-02-01 01:07:35 +03:00
|
|
|
ClipContainingBlockDescendants(aBuilder, clipRect, hasBorderRadius ? radii : nullptr,
|
|
|
|
aClipChainOnStack);
|
2015-12-22 18:54:19 +03:00
|
|
|
}
|
|
|
|
|
2013-04-04 15:36:45 +04:00
|
|
|
DisplayListClipState::AutoSaveRestore::AutoSaveRestore(nsDisplayListBuilder* aBuilder)
|
2017-02-01 01:07:35 +03:00
|
|
|
: mBuilder(aBuilder)
|
|
|
|
, mState(aBuilder->ClipState())
|
2013-04-04 15:36:45 +04:00
|
|
|
, mSavedState(aBuilder->ClipState())
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2013-04-04 15:36:45 +04:00
|
|
|
, mClipUsed(false)
|
|
|
|
, mRestored(false)
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2017-02-01 01:07:35 +03:00
|
|
|
{}
|
2013-04-04 15:36:45 +04:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|