2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2013-03-04 13:56:00 +04:00
|
|
|
* 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"
|
2017-01-27 14:57:44 +03:00
|
|
|
#include "DisplayItemClipChain.h"
|
2013-03-04 13:56:00 +04:00
|
|
|
|
2013-04-04 15:36:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2013-03-04 13:56:00 +04:00
|
|
|
class nsIFrame;
|
2015-12-22 18:54:19 +03:00
|
|
|
class nsIScrollableFrame;
|
2013-03-04 13:56:00 +04:00
|
|
|
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()
|
2017-02-01 01:07:35 +03:00
|
|
|
: mClipChainContentDescendants(nullptr)
|
|
|
|
, mClipChainContainingBlockDescendants(nullptr)
|
|
|
|
, mCurrentCombinedClipChain(nullptr)
|
|
|
|
, mCurrentCombinedClipChainIsValid(false)
|
2013-03-04 13:56:00 +04:00
|
|
|
{}
|
|
|
|
|
2013-03-06 15:08:13 +04:00
|
|
|
/**
|
2017-02-01 01:07:35 +03:00
|
|
|
* Returns intersection of mClipChainContainingBlockDescendants and
|
|
|
|
* mClipChainContentDescendants, allocated on aBuilder's arena.
|
2013-03-06 15:08:13 +04:00
|
|
|
*/
|
2017-02-01 01:07:35 +03:00
|
|
|
const DisplayItemClipChain* GetCurrentCombinedClipChain(nsDisplayListBuilder* aBuilder);
|
2013-03-04 13:56:00 +04:00
|
|
|
|
2017-02-01 01:07:35 +03:00
|
|
|
const DisplayItemClipChain* GetClipChainForContainingBlockDescendants() const
|
2013-03-04 13:56:00 +04:00
|
|
|
{
|
2017-02-01 01:07:35 +03:00
|
|
|
return mClipChainContainingBlockDescendants;
|
2013-03-04 13:56:00 +04:00
|
|
|
}
|
2017-02-01 01:07:35 +03:00
|
|
|
const DisplayItemClipChain* GetClipChainForContentDescendants() const
|
2013-03-04 13:56:00 +04:00
|
|
|
{
|
2017-02-01 01:07:35 +03:00
|
|
|
return mClipChainContentDescendants;
|
2013-03-04 13:56:00 +04:00
|
|
|
}
|
|
|
|
|
2017-02-01 01:07:35 +03:00
|
|
|
const ActiveScrolledRoot* GetContentClipASR() const
|
2016-03-05 19:27:54 +03:00
|
|
|
{
|
2017-02-01 01:07:35 +03:00
|
|
|
return mClipChainContentDescendants ? mClipChainContentDescendants->mASR : nullptr;
|
2016-03-05 19:27:54 +03:00
|
|
|
}
|
|
|
|
|
2013-04-04 15:36:45 +04:00
|
|
|
class AutoSaveRestore;
|
|
|
|
|
|
|
|
class AutoClipContainingBlockDescendantsToContentBox;
|
|
|
|
|
|
|
|
class AutoClipMultiple;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT = 0x01
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2015-12-22 18:54:19 +03:00
|
|
|
|
2013-03-06 15:08:13 +04:00
|
|
|
void Clear()
|
|
|
|
{
|
2017-02-01 01:07:35 +03:00
|
|
|
mClipChainContentDescendants = nullptr;
|
|
|
|
mClipChainContainingBlockDescendants = nullptr;
|
|
|
|
mCurrentCombinedClipChain = nullptr;
|
|
|
|
mCurrentCombinedClipChainIsValid = false;
|
2015-12-22 18:54:19 +03:00
|
|
|
}
|
|
|
|
|
2017-02-01 01:07:35 +03:00
|
|
|
void SetClipChainForContainingBlockDescendants(const DisplayItemClipChain* aClipChain)
|
2015-12-22 18:54:19 +03:00
|
|
|
{
|
2017-02-01 01:07:35 +03:00
|
|
|
mClipChainContainingBlockDescendants = aClipChain;
|
|
|
|
InvalidateCurrentCombinedClipChain(aClipChain ? aClipChain->mASR : nullptr);
|
2015-12-22 18:54:19 +03:00
|
|
|
}
|
|
|
|
|
2013-03-06 15:08:13 +04:00
|
|
|
/**
|
|
|
|
* Intersects the given clip rect (with optional aRadii) with the current
|
|
|
|
* mClipContainingBlockDescendants and sets mClipContainingBlockDescendants to
|
|
|
|
* the result, stored in aClipOnStack.
|
|
|
|
*/
|
2017-02-01 01:07:35 +03:00
|
|
|
void 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
|
|
|
|
2017-02-01 01:07:35 +03:00
|
|
|
void 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);
|
|
|
|
void 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);
|
|
|
|
|
|
|
|
void InvalidateCurrentCombinedClipChain(const ActiveScrolledRoot* aInvalidateUpTo);
|
2013-03-06 15:08:13 +04: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,
|
2017-02-01 01:07:35 +03:00
|
|
|
DisplayItemClipChain& aClipChainOnStack,
|
2013-04-04 15:36:45 +04:00
|
|
|
uint32_t aFlags);
|
2013-03-06 15:08:13 +04:00
|
|
|
|
2013-03-04 13:56:00 +04:00
|
|
|
/**
|
|
|
|
* All content descendants (i.e. following placeholder frames to their
|
2017-02-01 01:07:35 +03:00
|
|
|
* out-of-flows if necessary) should be clipped by mClipChainContentDescendants.
|
2013-03-04 13:56:00 +04:00
|
|
|
* Null if no clipping applies.
|
|
|
|
*/
|
2017-02-01 01:07:35 +03:00
|
|
|
const DisplayItemClipChain* mClipChainContentDescendants;
|
2013-03-04 13:56:00 +04:00
|
|
|
/**
|
2013-03-06 15:08:13 +04:00
|
|
|
* All containing-block descendants (i.e. frame descendants), including
|
|
|
|
* display items for the current frame, should be clipped by
|
2017-02-01 01:07:35 +03:00
|
|
|
* mClipChainContainingBlockDescendants.
|
2013-03-04 13:56:00 +04:00
|
|
|
* Null if no clipping applies.
|
|
|
|
*/
|
2017-02-01 01:07:35 +03:00
|
|
|
const DisplayItemClipChain* mClipChainContainingBlockDescendants;
|
2013-03-04 13:56:00 +04:00
|
|
|
/**
|
2017-02-01 01:07:35 +03:00
|
|
|
* The intersection of mClipChainContentDescendants and
|
|
|
|
* mClipChainContainingBlockDescendants.
|
2013-03-04 13:56:00 +04:00
|
|
|
* Allocated in the nsDisplayListBuilder arena. Null if none has been
|
2017-02-01 01:07:35 +03:00
|
|
|
* allocated or both mClipChainContentDescendants and mClipChainContainingBlockDescendants
|
2013-03-04 13:56:00 +04:00
|
|
|
* are null.
|
|
|
|
*/
|
2017-02-01 01:07:35 +03:00
|
|
|
const DisplayItemClipChain* mCurrentCombinedClipChain;
|
|
|
|
bool mCurrentCombinedClipChainIsValid;
|
2013-03-04 13:56:00 +04:00
|
|
|
};
|
|
|
|
|
2013-04-04 15:36:45 +04: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 15:08:13 +04:00
|
|
|
class DisplayListClipState::AutoSaveRestore {
|
|
|
|
public:
|
2014-08-08 03:48:38 +04:00
|
|
|
explicit AutoSaveRestore(nsDisplayListBuilder* aBuilder);
|
2013-03-06 15:08:13 +04:00
|
|
|
void Restore()
|
|
|
|
{
|
|
|
|
mState = mSavedState;
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2013-04-04 15:36:45 +04:00
|
|
|
mRestored = true;
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2013-03-06 15:08:13 +04:00
|
|
|
}
|
|
|
|
~AutoSaveRestore()
|
|
|
|
{
|
2016-03-05 19:27:54 +03:00
|
|
|
Restore();
|
2013-03-06 15:08:13 +04:00
|
|
|
}
|
2013-04-04 15:36:45 +04:00
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRestored, "Already restored!");
|
|
|
|
mState.Clear();
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2013-04-04 15:36:45 +04:00
|
|
|
mClipUsed = false;
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2013-04-04 15:36:45 +04:00
|
|
|
}
|
|
|
|
|
2017-02-01 01:07:35 +03:00
|
|
|
void SetClipChainForContainingBlockDescendants(const DisplayItemClipChain* aClipChain)
|
2015-12-22 18:54:19 +03:00
|
|
|
{
|
2017-02-01 01:07:35 +03:00
|
|
|
mState.SetClipChainForContainingBlockDescendants(aClipChain);
|
2015-12-22 18:54:19 +03:00
|
|
|
}
|
|
|
|
|
2013-04-04 15:36:45 +04:00
|
|
|
/**
|
|
|
|
* 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-26 05:36:05 +04:00
|
|
|
const nscoord* aRadii = nullptr)
|
2013-04-04 15:36:45 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRestored, "Already restored!");
|
|
|
|
NS_ASSERTION(!mClipUsed, "mClip already used");
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2013-04-04 15:36:45 +04:00
|
|
|
mClipUsed = true;
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2017-02-01 01:07:35 +03:00
|
|
|
mState.ClipContainingBlockDescendants(mBuilder, aRect, aRadii, mClipChain);
|
2013-04-04 15:36:45 +04:00
|
|
|
}
|
|
|
|
|
2013-07-26 05:36:05 +04:00
|
|
|
void ClipContentDescendants(const nsRect& aRect,
|
|
|
|
const nscoord* aRadii = nullptr)
|
2013-04-04 15:36:45 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRestored, "Already restored!");
|
|
|
|
NS_ASSERTION(!mClipUsed, "mClip already used");
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2013-04-04 15:36:45 +04:00
|
|
|
mClipUsed = true;
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2017-02-01 01:07:35 +03:00
|
|
|
mState.ClipContentDescendants(mBuilder, aRect, aRadii, mClipChain);
|
2013-04-04 15:36:45 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:21:06 +04:00
|
|
|
void ClipContentDescendants(const nsRect& aRect,
|
|
|
|
const nsRect& aRoundedRect,
|
|
|
|
const nscoord* aRadii = nullptr)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRestored, "Already restored!");
|
|
|
|
NS_ASSERTION(!mClipUsed, "mClip already used");
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2014-07-23 09:21:06 +04:00
|
|
|
mClipUsed = true;
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2017-02-01 01:07:35 +03:00
|
|
|
mState.ClipContentDescendants(mBuilder, aRect, aRoundedRect, aRadii, mClipChain);
|
2014-07-23 09:21:06 +04:00
|
|
|
}
|
|
|
|
|
2013-04-04 15:36:45 +04: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");
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2013-04-04 15:36:45 +04:00
|
|
|
mClipUsed = true;
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2017-02-01 01:07:35 +03:00
|
|
|
mState.ClipContainingBlockDescendantsToContentBox(aBuilder, aFrame, mClipChain, aFlags);
|
2013-04-04 15:36:45 +04:00
|
|
|
}
|
|
|
|
|
2013-03-06 15:08:13 +04:00
|
|
|
protected:
|
2017-02-01 01:07:35 +03:00
|
|
|
nsDisplayListBuilder* mBuilder;
|
2013-03-06 15:08:13 +04:00
|
|
|
DisplayListClipState& mState;
|
|
|
|
DisplayListClipState mSavedState;
|
2017-02-01 01:07:35 +03:00
|
|
|
DisplayItemClipChain mClipChain;
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool mClipUsed;
|
|
|
|
bool mRestored;
|
|
|
|
#endif
|
2013-03-06 15:08:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox : public AutoSaveRestore {
|
|
|
|
public:
|
|
|
|
AutoClipContainingBlockDescendantsToContentBox(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
2013-04-04 15:36:45 +04:00
|
|
|
uint32_t aFlags = 0)
|
|
|
|
: AutoSaveRestore(aBuilder)
|
|
|
|
{
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2013-04-04 15:36:45 +04:00
|
|
|
mClipUsed = true;
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2017-02-01 01:07:35 +03:00
|
|
|
mState.ClipContainingBlockDescendantsToContentBox(aBuilder, aFrame, mClipChain, aFlags);
|
2013-04-04 15:36:45 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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:
|
2014-08-08 03:48:38 +04:00
|
|
|
explicit AutoClipMultiple(nsDisplayListBuilder* aBuilder)
|
2013-04-04 15:36:45 +04:00
|
|
|
: AutoSaveRestore(aBuilder)
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2013-04-04 15:36:45 +04:00
|
|
|
, mExtraClipUsed(false)
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2013-04-04 15:36:45 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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");
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2013-04-04 15:36:45 +04:00
|
|
|
mExtraClipUsed = true;
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2017-02-01 01:07:35 +03:00
|
|
|
mState.ClipContainingBlockDescendants(mBuilder, aRect, aRadii, mExtraClipChain);
|
2013-04-04 15:36:45 +04:00
|
|
|
}
|
|
|
|
|
2013-03-06 15:08:13 +04:00
|
|
|
protected:
|
2017-02-01 01:07:35 +03:00
|
|
|
DisplayItemClipChain mExtraClipChain;
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool mExtraClipUsed;
|
|
|
|
#endif
|
2013-03-06 15:08:13 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2013-03-04 13:56:00 +04:00
|
|
|
|
|
|
|
#endif /* DISPLAYLISTCLIPSTATE_H_ */
|