2012-05-21 15:12:37 +04: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 22:20:59 +03:00
|
|
|
|
|
|
|
#ifndef nsQueryFrame_h
|
|
|
|
#define nsQueryFrame_h
|
|
|
|
|
|
|
|
#include "nscore.h"
|
2013-04-04 03:35:07 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/TypeTraits.h"
|
|
|
|
|
|
|
|
// NOTE: the long lines in this file are intentional to make compiler error
|
|
|
|
// messages more readable.
|
2009-01-12 22:20:59 +03:00
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
#define NS_DECL_QUERYFRAME_TARGET(classname) \
|
2013-04-04 03:35:07 +04:00
|
|
|
static const nsQueryFrame::FrameIID kFrameIID = nsQueryFrame::classname##_id; \
|
|
|
|
typedef classname Has_NS_DECL_QUERYFRAME_TARGET;
|
2009-01-12 22:20:59 +03:00
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
#define NS_DECL_QUERYFRAME \
|
2017-01-18 03:27:02 +03:00
|
|
|
void* QueryFrame(FrameIID id) override;
|
2009-01-12 22:20:59 +03:00
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
#define NS_QUERYFRAME_HEAD(class) \
|
|
|
|
void* class::QueryFrame(FrameIID id) { switch (id) {
|
2009-01-12 22:20:59 +03:00
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
#define NS_QUERYFRAME_ENTRY(class) \
|
2013-04-04 03:35:07 +04:00
|
|
|
case class::kFrameIID: { \
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(mozilla::IsSame<class, class::Has_NS_DECL_QUERYFRAME_TARGET>::value, \
|
|
|
|
#class " must declare itself as a queryframe target"); \
|
2013-04-04 03:35:07 +04:00
|
|
|
return static_cast<class*>(this); \
|
|
|
|
}
|
2009-01-12 22:20:59 +03:00
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
#define NS_QUERYFRAME_ENTRY_CONDITIONAL(class, condition) \
|
|
|
|
case class::kFrameIID: \
|
2013-04-04 03:35:07 +04:00
|
|
|
if (condition) { \
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(mozilla::IsSame<class, class::Has_NS_DECL_QUERYFRAME_TARGET>::value, \
|
|
|
|
#class " must declare itself as a queryframe target"); \
|
2013-04-04 03:35:07 +04:00
|
|
|
return static_cast<class*>(this); \
|
|
|
|
} \
|
2009-09-12 20:49:24 +04:00
|
|
|
break;
|
2009-01-12 22:20:59 +03:00
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
#define NS_QUERYFRAME_TAIL_INHERITING(class) \
|
|
|
|
default: break; \
|
|
|
|
} \
|
|
|
|
return class::QueryFrame(id); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_QUERYFRAME_TAIL_INHERITANCE_ROOT \
|
|
|
|
default: break; \
|
|
|
|
} \
|
2013-04-04 03:35:07 +04:00
|
|
|
MOZ_ASSERT(id != GetFrameId(), \
|
|
|
|
"A frame failed to QueryFrame to its *own type*. " \
|
|
|
|
"It may be missing NS_DECL_QUERYFRAME, or a " \
|
|
|
|
"NS_QUERYFRAME_ENTRY() line with its own type name"); \
|
|
|
|
return nullptr; \
|
2009-09-12 20:49:24 +04:00
|
|
|
}
|
2009-01-12 22:20:59 +03:00
|
|
|
|
|
|
|
class nsQueryFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum FrameIID {
|
2012-06-05 19:10:28 +04:00
|
|
|
#define FRAME_ID(classname) classname##_id,
|
|
|
|
#include "nsFrameIdList.h"
|
|
|
|
#undef FRAME_ID
|
2009-09-16 02:00:04 +04:00
|
|
|
|
2012-05-04 04:14:02 +04: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 22:20:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual void* QueryFrame(FrameIID id) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class do_QueryFrame
|
|
|
|
{
|
|
|
|
public:
|
2014-08-08 03:48:38 +04:00
|
|
|
explicit do_QueryFrame(nsQueryFrame *s) : mRawPtr(s) { }
|
|
|
|
|
|
|
|
// The return and argument types here are arbitrarily selected so no
|
|
|
|
// corresponding member function exists.
|
|
|
|
typedef void (do_QueryFrame::* MatchNullptr)(double, float);
|
|
|
|
// Implicit constructor for nullptr, trick borrowed from already_AddRefed.
|
|
|
|
MOZ_IMPLICIT do_QueryFrame(MatchNullptr aRawPtr) : mRawPtr(nullptr) {}
|
2009-01-12 22:20:59 +03:00
|
|
|
|
|
|
|
template<class Dest>
|
|
|
|
operator Dest*() {
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(mozilla::IsSame<Dest, typename Dest::Has_NS_DECL_QUERYFRAME_TARGET>::value,
|
|
|
|
"Dest must declare itself as a queryframe target");
|
2013-04-01 21:10:37 +04:00
|
|
|
if (!mRawPtr)
|
|
|
|
return nullptr;
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
return reinterpret_cast<Dest*>(mRawPtr->QueryFrame(Dest::kFrameIID));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsQueryFrame *mRawPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsQueryFrame_h
|