2013-03-04 01:56:00 -08: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 {
|
|
|
|
|
|
|
|
const DisplayItemClip*
|
|
|
|
DisplayListClipState::GetCurrentCombinedClip(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
if (mCurrentCombinedClip) {
|
|
|
|
return mCurrentCombinedClip;
|
|
|
|
}
|
|
|
|
if (!mClipContentDescendants && !mClipContainingBlockDescendants) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (mClipContentDescendants) {
|
|
|
|
if (mClipContainingBlockDescendants) {
|
2013-05-07 22:16:30 -07:00
|
|
|
DisplayItemClip intersection = *mClipContentDescendants;
|
|
|
|
intersection.IntersectWith(*mClipContainingBlockDescendants);
|
|
|
|
mCurrentCombinedClip = aBuilder->AllocateDisplayItemClip(intersection);
|
|
|
|
} else {
|
|
|
|
mCurrentCombinedClip =
|
|
|
|
aBuilder->AllocateDisplayItemClip(*mClipContentDescendants);
|
2013-03-04 01:56:00 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mCurrentCombinedClip =
|
2013-04-14 22:11:10 -07:00
|
|
|
aBuilder->AllocateDisplayItemClip(*mClipContainingBlockDescendants);
|
2013-03-04 01:56:00 -08:00
|
|
|
}
|
|
|
|
return mCurrentCombinedClip;
|
|
|
|
}
|
|
|
|
|
2013-03-06 03:08:13 -08:00
|
|
|
void
|
|
|
|
DisplayListClipState::ClipContainingBlockDescendants(const nsRect& aRect,
|
|
|
|
const nscoord* aRadii,
|
|
|
|
DisplayItemClip& aClipOnStack)
|
|
|
|
{
|
|
|
|
if (aRadii) {
|
|
|
|
aClipOnStack.SetTo(aRect, aRadii);
|
|
|
|
} else {
|
|
|
|
aClipOnStack.SetTo(aRect);
|
|
|
|
}
|
|
|
|
if (mClipContainingBlockDescendants) {
|
|
|
|
aClipOnStack.IntersectWith(*mClipContainingBlockDescendants);
|
|
|
|
}
|
|
|
|
mClipContainingBlockDescendants = &aClipOnStack;
|
|
|
|
mCurrentCombinedClip = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisplayListClipState::ClipContentDescendants(const nsRect& aRect,
|
2013-07-25 18:36:05 -07:00
|
|
|
const nscoord* aRadii,
|
2013-03-06 03:08:13 -08:00
|
|
|
DisplayItemClip& aClipOnStack)
|
|
|
|
{
|
2013-07-25 18:36:05 -07:00
|
|
|
if (aRadii) {
|
|
|
|
aClipOnStack.SetTo(aRect, aRadii);
|
|
|
|
} else {
|
|
|
|
aClipOnStack.SetTo(aRect);
|
|
|
|
}
|
2013-03-06 03:08:13 -08:00
|
|
|
if (mClipContentDescendants) {
|
|
|
|
aClipOnStack.IntersectWith(*mClipContentDescendants);
|
|
|
|
}
|
|
|
|
mClipContentDescendants = &aClipOnStack;
|
|
|
|
mCurrentCombinedClip = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-22 22:21:06 -07:00
|
|
|
void
|
|
|
|
DisplayListClipState::ClipContentDescendants(const nsRect& aRect,
|
|
|
|
const nsRect& aRoundedRect,
|
|
|
|
const nscoord* aRadii,
|
|
|
|
DisplayItemClip& aClipOnStack)
|
|
|
|
{
|
|
|
|
if (aRadii) {
|
|
|
|
aClipOnStack.SetTo(aRect, aRoundedRect, aRadii);
|
|
|
|
} else {
|
|
|
|
nsRect intersect = aRect.Intersect(aRoundedRect);
|
|
|
|
aClipOnStack.SetTo(intersect);
|
|
|
|
}
|
|
|
|
if (mClipContentDescendants) {
|
|
|
|
aClipOnStack.IntersectWith(*mClipContentDescendants);
|
|
|
|
}
|
|
|
|
mClipContentDescendants = &aClipOnStack;
|
|
|
|
mCurrentCombinedClip = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-03-06 03:08:13 -08:00
|
|
|
void
|
|
|
|
DisplayListClipState::ClipContainingBlockDescendantsToContentBox(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
DisplayItemClip& aClipOnStack,
|
|
|
|
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.
|
|
|
|
ClipContainingBlockDescendants(clipRect, hasBorderRadius ? radii : nullptr,
|
|
|
|
aClipOnStack);
|
|
|
|
}
|
|
|
|
|
2013-04-04 04:36:45 -07:00
|
|
|
DisplayListClipState::AutoSaveRestore::AutoSaveRestore(nsDisplayListBuilder* aBuilder)
|
|
|
|
: mState(aBuilder->ClipState())
|
|
|
|
, mSavedState(aBuilder->ClipState())
|
|
|
|
, mClipUsed(false)
|
|
|
|
, mRestored(false)
|
|
|
|
{}
|
|
|
|
|
2013-03-04 01:56:00 -08:00
|
|
|
}
|