2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2009-01-12 11:20:59 -08:00
|
|
|
|
|
|
|
#ifndef nsQueryFrame_h
|
|
|
|
#define nsQueryFrame_h
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
#define NS_DECL_QUERYFRAME_TARGET(classname) \
|
2009-01-12 11:20:59 -08:00
|
|
|
static const nsQueryFrame::FrameIID kFrameIID = nsQueryFrame::classname##_id;
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
#define NS_DECL_QUERYFRAME \
|
2009-01-12 11:20:59 -08:00
|
|
|
virtual void* QueryFrame(FrameIID id);
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
#define NS_QUERYFRAME_HEAD(class) \
|
|
|
|
void* class::QueryFrame(FrameIID id) { switch (id) {
|
2009-01-12 11:20:59 -08:00
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
#define NS_QUERYFRAME_ENTRY(class) \
|
|
|
|
case class::kFrameIID: return static_cast<class*>(this);
|
2009-01-12 11:20:59 -08:00
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
#define NS_QUERYFRAME_ENTRY_CONDITIONAL(class, condition) \
|
|
|
|
case class::kFrameIID: \
|
|
|
|
if (condition) return static_cast<class*>(this); \
|
|
|
|
break;
|
2009-01-12 11:20:59 -08:00
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
#define NS_QUERYFRAME_TAIL_INHERITING(class) \
|
|
|
|
default: break; \
|
|
|
|
} \
|
|
|
|
return class::QueryFrame(id); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_QUERYFRAME_TAIL_INHERITANCE_ROOT \
|
|
|
|
default: break; \
|
|
|
|
} \
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr; \
|
2009-09-12 09:49:24 -07:00
|
|
|
}
|
2009-01-12 11:20:59 -08:00
|
|
|
|
|
|
|
class nsQueryFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum FrameIID {
|
2012-06-05 08:10:28 -07:00
|
|
|
#define FRAME_ID(classname) classname##_id,
|
|
|
|
#include "nsFrameIdList.h"
|
|
|
|
#undef FRAME_ID
|
2009-09-15 15:00:04 -07:00
|
|
|
|
2012-05-03 17:14:02 -07:00
|
|
|
// The PresArena implementation uses this bit to distinguish objects
|
|
|
|
// allocated by size from objects allocated by type ID (that is, frames
|
|
|
|
// using AllocateByFrameID, and other objects using AllocateByObjectID).
|
|
|
|
// It should not collide with any frame ID (above) or Object ID (in
|
|
|
|
// nsPresArena.h). It is not 0x80000000 to avoid the question of
|
|
|
|
// whether enumeration constants are signed.
|
|
|
|
NON_FRAME_MARKER = 0x20000000
|
2009-01-12 11:20:59 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual void* QueryFrame(FrameIID id) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class do_QueryFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
do_QueryFrame(nsQueryFrame *s) : mRawPtr(s) { }
|
|
|
|
|
|
|
|
template<class Dest>
|
|
|
|
operator Dest*() {
|
|
|
|
if (!mRawPtr)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-01-12 11:20:59 -08:00
|
|
|
|
|
|
|
return reinterpret_cast<Dest*>(mRawPtr->QueryFrame(Dest::kFrameIID));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsQueryFrame *mRawPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsQueryFrame_h
|