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/. */
|
|
|
|
|
|
|
|
#ifndef DISPLAYLISTCLIPSTATE_H_
|
|
|
|
#define DISPLAYLISTCLIPSTATE_H_
|
|
|
|
|
|
|
|
#include "DisplayItemClip.h"
|
|
|
|
|
2013-04-04 04:36:45 -07:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2013-03-04 01:56:00 -08:00
|
|
|
class nsIFrame;
|
|
|
|
class nsDisplayListBuilder;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All clip coordinates are in appunits relative to the reference frame
|
|
|
|
* for the display item we're building.
|
|
|
|
*/
|
|
|
|
class DisplayListClipState {
|
|
|
|
public:
|
|
|
|
DisplayListClipState()
|
|
|
|
: mClipContentDescendants(nullptr)
|
|
|
|
, mClipContainingBlockDescendants(nullptr)
|
|
|
|
, mCurrentCombinedClip(nullptr)
|
|
|
|
{}
|
|
|
|
|
2013-03-06 03:08:13 -08:00
|
|
|
/**
|
|
|
|
* Returns intersection of mClipContainingBlockDescendants and
|
|
|
|
* mClipContentDescendants, allocated on aBuilder's arena.
|
|
|
|
*/
|
2013-03-04 01:56:00 -08:00
|
|
|
const DisplayItemClip* GetCurrentCombinedClip(nsDisplayListBuilder* aBuilder);
|
|
|
|
|
2013-03-06 03:08:13 -08:00
|
|
|
const DisplayItemClip* GetClipForContainingBlockDescendants() const
|
2013-03-04 01:56:00 -08:00
|
|
|
{
|
|
|
|
return mClipContainingBlockDescendants;
|
|
|
|
}
|
2013-03-06 03:08:13 -08:00
|
|
|
const DisplayItemClip* GetClipForContentDescendants() const
|
2013-03-04 01:56:00 -08:00
|
|
|
{
|
|
|
|
return mClipContentDescendants;
|
|
|
|
}
|
|
|
|
|
2013-04-04 04:36:45 -07:00
|
|
|
class AutoSaveRestore;
|
|
|
|
friend class AutoSaveRestore;
|
|
|
|
|
|
|
|
class AutoClipContainingBlockDescendantsToContentBox;
|
|
|
|
friend class AutoClipContainingBlockDescendantsToContentBox;
|
|
|
|
|
|
|
|
class AutoClipMultiple;
|
|
|
|
friend class AutoClipMultiple;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT = 0x01
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2013-03-04 01:56:00 -08:00
|
|
|
void SetClipForContainingBlockDescendants(const DisplayItemClip* aClip)
|
|
|
|
{
|
|
|
|
mClipContainingBlockDescendants = aClip;
|
|
|
|
mCurrentCombinedClip = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-03-06 03:08:13 -08:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mClipContentDescendants = nullptr;
|
|
|
|
mClipContainingBlockDescendants = nullptr;
|
|
|
|
mCurrentCombinedClip = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Intersects the given clip rect (with optional aRadii) with the current
|
|
|
|
* mClipContainingBlockDescendants and sets mClipContainingBlockDescendants to
|
|
|
|
* the result, stored in aClipOnStack.
|
|
|
|
*/
|
|
|
|
void ClipContainingBlockDescendants(const nsRect& aRect,
|
|
|
|
const nscoord* aRadii,
|
|
|
|
DisplayItemClip& aClipOnStack);
|
|
|
|
|
|
|
|
void 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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clips containing-block descendants to the frame's content-box,
|
|
|
|
* taking border-radius into account.
|
|
|
|
* If aFlags contains ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT then
|
|
|
|
* we assume display items will not draw outside the content rect, so
|
|
|
|
* clipping is only required if there is a border-radius. This is an
|
|
|
|
* optimization to reduce the amount of clipping required.
|
|
|
|
*/
|
|
|
|
void ClipContainingBlockDescendantsToContentBox(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
DisplayItemClip& aClipOnStack,
|
2013-04-04 04:36:45 -07:00
|
|
|
uint32_t aFlags);
|
2013-03-06 03:08:13 -08:00
|
|
|
|
2013-03-04 01:56:00 -08:00
|
|
|
/**
|
|
|
|
* All content descendants (i.e. following placeholder frames to their
|
|
|
|
* out-of-flows if necessary) should be clipped by mClipContentDescendants.
|
|
|
|
* Null if no clipping applies.
|
|
|
|
*/
|
|
|
|
const DisplayItemClip* mClipContentDescendants;
|
|
|
|
/**
|
2013-03-06 03:08:13 -08:00
|
|
|
* All containing-block descendants (i.e. frame descendants), including
|
|
|
|
* display items for the current frame, should be clipped by
|
|
|
|
* mClipContainingBlockDescendants.
|
2013-03-04 01:56:00 -08:00
|
|
|
* Null if no clipping applies.
|
|
|
|
*/
|
|
|
|
const DisplayItemClip* mClipContainingBlockDescendants;
|
|
|
|
/**
|
|
|
|
* The intersection of mClipContentDescendants and
|
|
|
|
* mClipContainingBlockDescendants.
|
|
|
|
* Allocated in the nsDisplayListBuilder arena. Null if none has been
|
|
|
|
* allocated or both mClipContentDescendants and mClipContainingBlockDescendants
|
|
|
|
* are null.
|
|
|
|
*/
|
|
|
|
const DisplayItemClip* mCurrentCombinedClip;
|
|
|
|
};
|
|
|
|
|
2013-04-04 04:36:45 -07:00
|
|
|
/**
|
|
|
|
* A class to automatically save and restore the current clip state. Also
|
|
|
|
* offers methods for modifying the clip state. Only one modification is allowed
|
|
|
|
* to be in scope at a time using one of these objects; multiple modifications
|
|
|
|
* require nested objects. The interface is written this way to prevent
|
|
|
|
* dangling pointers to DisplayItemClips.
|
|
|
|
*/
|
2013-03-06 03:08:13 -08:00
|
|
|
class DisplayListClipState::AutoSaveRestore {
|
|
|
|
public:
|
2013-04-04 04:36:45 -07:00
|
|
|
AutoSaveRestore(nsDisplayListBuilder* aBuilder);
|
2013-03-06 03:08:13 -08:00
|
|
|
void Restore()
|
|
|
|
{
|
|
|
|
mState = mSavedState;
|
2013-04-04 04:36:45 -07:00
|
|
|
mRestored = true;
|
2013-03-06 03:08:13 -08:00
|
|
|
}
|
|
|
|
~AutoSaveRestore()
|
|
|
|
{
|
|
|
|
mState = mSavedState;
|
|
|
|
}
|
2013-04-04 04:36:45 -07:00
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRestored, "Already restored!");
|
|
|
|
mState.Clear();
|
|
|
|
mClipUsed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Intersects the given clip rect (with optional aRadii) with the current
|
|
|
|
* mClipContainingBlockDescendants and sets mClipContainingBlockDescendants to
|
|
|
|
* the result, stored in aClipOnStack.
|
|
|
|
*/
|
|
|
|
void ClipContainingBlockDescendants(const nsRect& aRect,
|
2013-07-25 18:36:05 -07:00
|
|
|
const nscoord* aRadii = nullptr)
|
2013-04-04 04:36:45 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRestored, "Already restored!");
|
|
|
|
NS_ASSERTION(!mClipUsed, "mClip already used");
|
|
|
|
mClipUsed = true;
|
|
|
|
mState.ClipContainingBlockDescendants(aRect, aRadii, mClip);
|
|
|
|
}
|
|
|
|
|
2013-07-25 18:36:05 -07:00
|
|
|
void ClipContentDescendants(const nsRect& aRect,
|
|
|
|
const nscoord* aRadii = nullptr)
|
2013-04-04 04:36:45 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRestored, "Already restored!");
|
|
|
|
NS_ASSERTION(!mClipUsed, "mClip already used");
|
|
|
|
mClipUsed = true;
|
2013-07-25 18:36:05 -07:00
|
|
|
mState.ClipContentDescendants(aRect, aRadii, mClip);
|
2013-04-04 04:36:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clips containing-block descendants to the frame's content-box,
|
|
|
|
* taking border-radius into account.
|
|
|
|
* If aFlags contains ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT then
|
|
|
|
* we assume display items will not draw outside the content rect, so
|
|
|
|
* clipping is only required if there is a border-radius. This is an
|
|
|
|
* optimization to reduce the amount of clipping required.
|
|
|
|
*/
|
|
|
|
void ClipContainingBlockDescendantsToContentBox(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
uint32_t aFlags = 0)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRestored, "Already restored!");
|
|
|
|
NS_ASSERTION(!mClipUsed, "mClip already used");
|
|
|
|
mClipUsed = true;
|
|
|
|
mState.ClipContainingBlockDescendantsToContentBox(aBuilder, aFrame, mClip, aFlags);
|
|
|
|
}
|
|
|
|
|
2013-03-06 03:08:13 -08:00
|
|
|
protected:
|
|
|
|
DisplayListClipState& mState;
|
|
|
|
DisplayListClipState mSavedState;
|
2013-04-04 04:36:45 -07:00
|
|
|
DisplayItemClip mClip;
|
|
|
|
DebugOnly<bool> mClipUsed;
|
|
|
|
DebugOnly<bool> mRestored;
|
2013-03-06 03:08:13 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
class DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox : public AutoSaveRestore {
|
|
|
|
public:
|
|
|
|
AutoClipContainingBlockDescendantsToContentBox(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
2013-04-04 04:36:45 -07:00
|
|
|
uint32_t aFlags = 0)
|
|
|
|
: AutoSaveRestore(aBuilder)
|
|
|
|
{
|
|
|
|
mClipUsed = true;
|
|
|
|
mState.ClipContainingBlockDescendantsToContentBox(aBuilder, aFrame, mClip, aFlags);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do not use this outside of nsFrame::BuildDisplayListForChild, use
|
|
|
|
* multiple AutoSaveRestores instead. We provide this class just to ensure
|
|
|
|
* BuildDisplayListForChild is as efficient as possible.
|
|
|
|
*/
|
|
|
|
class DisplayListClipState::AutoClipMultiple : public AutoSaveRestore {
|
|
|
|
public:
|
|
|
|
AutoClipMultiple(nsDisplayListBuilder* aBuilder)
|
|
|
|
: AutoSaveRestore(aBuilder)
|
|
|
|
, mExtraClipUsed(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* *aClip must survive longer than this object. Be careful!!!
|
|
|
|
*/
|
|
|
|
void SetClipForContainingBlockDescendants(const DisplayItemClip* aClip)
|
|
|
|
{
|
|
|
|
mState.SetClipForContainingBlockDescendants(aClip);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Intersects the given clip rect (with optional aRadii) with the current
|
|
|
|
* mClipContainingBlockDescendants and sets mClipContainingBlockDescendants to
|
|
|
|
* the result, stored in aClipOnStack.
|
|
|
|
*/
|
|
|
|
void ClipContainingBlockDescendantsExtra(const nsRect& aRect,
|
|
|
|
const nscoord* aRadii)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRestored, "Already restored!");
|
|
|
|
NS_ASSERTION(!mExtraClipUsed, "mExtraClip already used");
|
|
|
|
mExtraClipUsed = true;
|
|
|
|
mState.ClipContainingBlockDescendants(aRect, aRadii, mExtraClip);
|
|
|
|
}
|
|
|
|
|
2013-03-06 03:08:13 -08:00
|
|
|
protected:
|
2013-04-04 04:36:45 -07:00
|
|
|
DisplayItemClip mExtraClip;
|
|
|
|
DebugOnly<bool> mExtraClipUsed;
|
2013-03-06 03:08:13 -08:00
|
|
|
};
|
|
|
|
|
2013-03-04 01:56:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DISPLAYLISTCLIPSTATE_H_ */
|