Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsQueryFrame.h
blob63f501ba9872be462df42778afbfbe9577ba52fc
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsQueryFrame_h
6 #define nsQueryFrame_h
8 #include "nscore.h"
9 #include "mozilla/Assertions.h"
10 #include "mozilla/TypeTraits.h"
12 // NOTE: the long lines in this file are intentional to make compiler error
13 // messages more readable.
15 #define NS_DECL_QUERYFRAME_TARGET(classname) \
16 static const nsQueryFrame::FrameIID kFrameIID = nsQueryFrame::classname##_id; \
17 typedef classname Has_NS_DECL_QUERYFRAME_TARGET;
19 #define NS_DECL_QUERYFRAME \
20 virtual void* QueryFrame(FrameIID id);
22 #define NS_QUERYFRAME_HEAD(class) \
23 void* class::QueryFrame(FrameIID id) { switch (id) {
25 #define NS_QUERYFRAME_ENTRY(class) \
26 case class::kFrameIID: { \
27 static_assert(mozilla::IsSame<class, class::Has_NS_DECL_QUERYFRAME_TARGET>::value, \
28 #class " must declare itself as a queryframe target"); \
29 return static_cast<class*>(this); \
32 #define NS_QUERYFRAME_ENTRY_CONDITIONAL(class, condition) \
33 case class::kFrameIID: \
34 if (condition) { \
35 static_assert(mozilla::IsSame<class, class::Has_NS_DECL_QUERYFRAME_TARGET>::value, \
36 #class " must declare itself as a queryframe target"); \
37 return static_cast<class*>(this); \
38 } \
39 break;
41 #define NS_QUERYFRAME_TAIL_INHERITING(class) \
42 default: break; \
43 } \
44 return class::QueryFrame(id); \
47 #define NS_QUERYFRAME_TAIL_INHERITANCE_ROOT \
48 default: break; \
49 } \
50 MOZ_ASSERT(id != GetFrameId(), \
51 "A frame failed to QueryFrame to its *own type*. " \
52 "It may be missing NS_DECL_QUERYFRAME, or a " \
53 "NS_QUERYFRAME_ENTRY() line with its own type name"); \
54 return nullptr; \
57 class nsQueryFrame
59 public:
60 enum FrameIID {
61 #define FRAME_ID(classname) classname##_id,
62 #include "nsFrameIdList.h"
63 #undef FRAME_ID
65 // The PresArena implementation uses this bit to distinguish objects
66 // allocated by size from objects allocated by type ID (that is, frames
67 // using AllocateByFrameID, and other objects using AllocateByObjectID).
68 // It should not collide with any frame ID (above) or Object ID (in
69 // nsPresArena.h). It is not 0x80000000 to avoid the question of
70 // whether enumeration constants are signed.
71 NON_FRAME_MARKER = 0x20000000
74 virtual void* QueryFrame(FrameIID id) = 0;
77 class do_QueryFrame
79 public:
80 explicit do_QueryFrame(nsQueryFrame *s) : mRawPtr(s) { }
82 // The return and argument types here are arbitrarily selected so no
83 // corresponding member function exists.
84 typedef void (do_QueryFrame::* MatchNullptr)(double, float);
85 // Implicit constructor for nullptr, trick borrowed from already_AddRefed.
86 MOZ_IMPLICIT do_QueryFrame(MatchNullptr aRawPtr) : mRawPtr(nullptr) {}
88 template<class Dest>
89 operator Dest*() {
90 static_assert(mozilla::IsSame<Dest, typename Dest::Has_NS_DECL_QUERYFRAME_TARGET>::value,
91 "Dest must declare itself as a queryframe target");
92 if (!mRawPtr)
93 return nullptr;
95 return reinterpret_cast<Dest*>(mRawPtr->QueryFrame(Dest::kFrameIID));
98 private:
99 nsQueryFrame *mRawPtr;
102 #endif // nsQueryFrame_h