gecko/layout/base/DisplayListClipState.h
2013-03-07 00:08:13 +13:00

149 lines
4.6 KiB
C++

/* -*- 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"
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)
{}
/**
* Returns intersection of mClipContainingBlockDescendants and
* mClipContentDescendants, allocated on aBuilder's arena.
*/
const DisplayItemClip* GetCurrentCombinedClip(nsDisplayListBuilder* aBuilder);
const DisplayItemClip* GetClipForContainingBlockDescendants() const
{
return mClipContainingBlockDescendants;
}
const DisplayItemClip* GetClipForContentDescendants() const
{
return mClipContentDescendants;
}
void SetClipForContainingBlockDescendants(const DisplayItemClip* aClip)
{
mClipContainingBlockDescendants = aClip;
mCurrentCombinedClip = nullptr;
}
void SetClipForContentDescendants(const DisplayItemClip* aClip)
{
mClipContentDescendants = aClip;
mCurrentCombinedClip = nullptr;
}
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,
DisplayItemClip& aClipOnStack);
enum {
ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT = 0x01
};
/**
* 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,
uint32_t aFlags = 0);
class AutoSaveRestore;
friend class AutoSaveRestore;
class AutoClipContainingBlockDescendantsToContentBox;
private:
/**
* 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;
/**
* All containing-block descendants (i.e. frame descendants), including
* display items for the current frame, should be clipped by
* mClipContainingBlockDescendants.
* 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;
};
class DisplayListClipState::AutoSaveRestore {
public:
AutoSaveRestore(DisplayListClipState& aState)
: mState(aState)
, mSavedState(aState)
{}
void Restore()
{
mState = mSavedState;
}
~AutoSaveRestore()
{
mState = mSavedState;
}
protected:
DisplayListClipState& mState;
DisplayListClipState mSavedState;
};
class DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox : public AutoSaveRestore {
public:
AutoClipContainingBlockDescendantsToContentBox(nsDisplayListBuilder* aBuilder,
nsIFrame* aFrame,
uint32_t aFlags = 0);
protected:
DisplayItemClip mClip;
};
}
#endif /* DISPLAYLISTCLIPSTATE_H_ */