Bug 602431, part 3: Add a ShadowContainerLayer base class and BasicShadowContainerLayer implementation. sr=roc

This commit is contained in:
Chris Jones 2010-10-13 17:55:45 -05:00
parent 57c58b918e
commit 9d4c7a5e0c
4 changed files with 97 additions and 31 deletions

View File

@ -135,7 +135,17 @@ ToData(Layer* aLayer)
return static_cast<BasicImplData*>(aLayer->ImplData());
}
template<class Container>
static void ContainerInsertAfter(Layer* aChild, Layer* aAfter, Container* aContainer);
template<class Container>
static void ContainerRemoveChild(Layer* aChild, Container* aContainer);
class BasicContainerLayer : public ContainerLayer, BasicImplData {
template<class Container>
friend void ContainerInsertAfter(Layer* aChild, Layer* aAfter, Container* aContainer);
template<class Container>
friend void ContainerRemoveChild(Layer* aChild, Container* aContainer);
public:
BasicContainerLayer(BasicLayerManager* aManager) :
ContainerLayer(aManager, static_cast<BasicImplData*>(this))
@ -150,12 +160,21 @@ public:
"Can only set properties in construction phase");
ContainerLayer::SetVisibleRegion(aRegion);
}
virtual void InsertAfter(Layer* aChild, Layer* aAfter);
virtual void RemoveChild(Layer* aChild);
virtual void InsertAfter(Layer* aChild, Layer* aAfter)
{
NS_ASSERTION(BasicManager()->InConstruction(),
"Can only set properties in construction phase");
ContainerInsertAfter(aChild, aAfter, this);
}
virtual void RemoveChild(Layer* aChild)
{
NS_ASSERTION(BasicManager()->InConstruction(),
"Can only set properties in construction phase");
ContainerRemoveChild(aChild, this);
}
protected:
void RemoveChildInternal(Layer* aChild);
BasicLayerManager* BasicManager()
{
return static_cast<BasicLayerManager*>(mManager);
@ -165,37 +184,36 @@ protected:
BasicContainerLayer::~BasicContainerLayer()
{
while (mFirstChild) {
RemoveChildInternal(mFirstChild);
ContainerRemoveChild(mFirstChild, this);
}
MOZ_COUNT_DTOR(BasicContainerLayer);
}
void
BasicContainerLayer::InsertAfter(Layer* aChild, Layer* aAfter)
template<class Container>
static void
ContainerInsertAfter(Layer* aChild, Layer* aAfter, Container* aContainer)
{
NS_ASSERTION(BasicManager()->InConstruction(),
"Can only set properties in construction phase");
NS_ASSERTION(aChild->Manager() == Manager(),
NS_ASSERTION(aChild->Manager() == aContainer->Manager(),
"Child has wrong manager");
NS_ASSERTION(!aChild->GetParent(),
"aChild already in the tree");
NS_ASSERTION(!aChild->GetNextSibling() && !aChild->GetPrevSibling(),
"aChild already has siblings?");
NS_ASSERTION(!aAfter ||
(aAfter->Manager() == Manager() &&
aAfter->GetParent() == this),
(aAfter->Manager() == aContainer->Manager() &&
aAfter->GetParent() == aContainer),
"aAfter is not our child");
NS_ADDREF(aChild);
aChild->SetParent(this);
aChild->SetParent(aContainer);
if (!aAfter) {
aChild->SetNextSibling(mFirstChild);
if (mFirstChild) {
mFirstChild->SetPrevSibling(aChild);
aChild->SetNextSibling(aContainer->mFirstChild);
if (aContainer->mFirstChild) {
aContainer->mFirstChild->SetPrevSibling(aChild);
}
mFirstChild = aChild;
aContainer->mFirstChild = aChild;
return;
}
@ -208,20 +226,13 @@ BasicContainerLayer::InsertAfter(Layer* aChild, Layer* aAfter)
aAfter->SetNextSibling(aChild);
}
void
BasicContainerLayer::RemoveChild(Layer* aChild)
template<class Container>
static void
ContainerRemoveChild(Layer* aChild, Container* aContainer)
{
NS_ASSERTION(BasicManager()->InConstruction(),
"Can only set properties in construction phase");
RemoveChildInternal(aChild);
}
void
BasicContainerLayer::RemoveChildInternal(Layer* aChild)
{
NS_ASSERTION(aChild->Manager() == Manager(),
NS_ASSERTION(aChild->Manager() == aContainer->Manager(),
"Child has wrong manager");
NS_ASSERTION(aChild->GetParent() == this,
NS_ASSERTION(aChild->GetParent() == aContainer,
"aChild not our child");
Layer* prev = aChild->GetPrevSibling();
@ -229,7 +240,7 @@ BasicContainerLayer::RemoveChildInternal(Layer* aChild)
if (prev) {
prev->SetNextSibling(next);
} else {
mFirstChild = next;
aContainer->mFirstChild = next;
}
if (next) {
next->SetPrevSibling(prev);
@ -1966,6 +1977,32 @@ BasicShadowThebesLayer::Paint(gfxContext* aContext,
mFrontBuffer.DrawTo(this, isOpaqueContent, target, aOpacity);
}
class BasicShadowContainerLayer : public ShadowContainerLayer, BasicImplData {
template<class Container>
friend void ContainerInsertAfter(Layer* aChild, Layer* aAfter, Container* aContainer);
template<class Container>
friend void ContainerRemoveChild(Layer* aChild, Container* aContainer);
public:
BasicShadowContainerLayer(BasicShadowLayerManager* aLayerManager) :
ShadowContainerLayer(aLayerManager, static_cast<BasicImplData*>(this))
{
MOZ_COUNT_CTOR(BasicShadowContainerLayer);
}
virtual ~BasicShadowContainerLayer()
{
while (mFirstChild) {
ContainerRemoveChild(mFirstChild, this);
}
MOZ_COUNT_DTOR(BasicShadowContainerLayer);
}
virtual void InsertAfter(Layer* aChild, Layer* aAfter)
{ ContainerInsertAfter(aChild, aAfter, this); }
virtual void RemoveChild(Layer* aChild)
{ ContainerRemoveChild(aChild, this); }
};
class BasicShadowImageLayer : public ShadowImageLayer, BasicImplData {
public:
@ -2246,6 +2283,14 @@ BasicShadowLayerManager::CreateShadowThebesLayer()
return layer.forget();
}
already_AddRefed<ShadowContainerLayer>
BasicShadowLayerManager::CreateShadowContainerLayer()
{
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
nsRefPtr<ShadowContainerLayer> layer = new BasicShadowContainerLayer(this);
return layer.forget();
}
already_AddRefed<ShadowImageLayer>
BasicShadowLayerManager::CreateShadowImageLayer()
{

View File

@ -151,6 +151,8 @@ public:
virtual already_AddRefed<ColorLayer> CreateColorLayer();
virtual already_AddRefed<ShadowThebesLayer> CreateShadowThebesLayer()
{ return NULL; }
virtual already_AddRefed<ShadowContainerLayer> CreateShadowContainerLayer()
{ return NULL; }
virtual already_AddRefed<ShadowImageLayer> CreateShadowImageLayer()
{ return NULL; }
virtual already_AddRefed<ShadowColorLayer> CreateShadowColorLayer()
@ -245,6 +247,7 @@ public:
virtual already_AddRefed<CanvasLayer> CreateCanvasLayer();
virtual already_AddRefed<ColorLayer> CreateColorLayer();
virtual already_AddRefed<ShadowThebesLayer> CreateShadowThebesLayer();
virtual already_AddRefed<ShadowContainerLayer> CreateShadowContainerLayer();
virtual already_AddRefed<ShadowImageLayer> CreateShadowImageLayer();
virtual already_AddRefed<ShadowColorLayer> CreateShadowColorLayer();
virtual already_AddRefed<ShadowCanvasLayer> CreateShadowCanvasLayer();

View File

@ -58,6 +58,7 @@ class PLayersChild;
class PLayersParent;
class ShadowableLayer;
class ShadowThebesLayer;
class ShadowContainerLayer;
class ShadowImageLayer;
class ShadowColorLayer;
class ShadowCanvasLayer;
@ -341,6 +342,8 @@ public:
/** CONSTRUCTION PHASE ONLY */
virtual already_AddRefed<ShadowThebesLayer> CreateShadowThebesLayer() = 0;
/** CONSTRUCTION PHASE ONLY */
virtual already_AddRefed<ShadowContainerLayer> CreateShadowContainerLayer() = 0;
/** CONSTRUCTION PHASE ONLY */
virtual already_AddRefed<ShadowImageLayer> CreateShadowImageLayer() = 0;
/** CONSTRUCTION PHASE ONLY */
virtual already_AddRefed<ShadowColorLayer> CreateShadowColorLayer() = 0;
@ -522,6 +525,21 @@ protected:
};
class ShadowContainerLayer : public ShadowLayer,
public ContainerLayer
{
public:
virtual ShadowLayer* AsShadowLayer() { return this; }
MOZ_LAYER_DECL_NAME("ShadowContainerLayer", TYPE_SHADOW)
protected:
ShadowContainerLayer(LayerManager* aManager, void* aImplData)
: ContainerLayer(aManager, aImplData)
{}
};
class ShadowCanvasLayer : public ShadowLayer,
public CanvasLayer
{

View File

@ -159,7 +159,7 @@ ShadowLayersParent::RecvUpdate(const nsTArray<Edit>& cset,
case Edit::TOpCreateContainerLayer: {
MOZ_LAYERS_LOG(("[ParentSide] CreateContainerLayer"));
nsRefPtr<ContainerLayer> layer = layer_manager()->CreateContainerLayer();
nsRefPtr<ContainerLayer> layer = layer_manager()->CreateShadowContainerLayer();
AsShadowLayer(edit.get_OpCreateContainerLayer())->Bind(layer);
break;
}