Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef nsQueryFrame_h |
michael@0 | 6 | #define nsQueryFrame_h |
michael@0 | 7 | |
michael@0 | 8 | #include "nscore.h" |
michael@0 | 9 | #include "mozilla/Assertions.h" |
michael@0 | 10 | #include "mozilla/TypeTraits.h" |
michael@0 | 11 | |
michael@0 | 12 | // NOTE: the long lines in this file are intentional to make compiler error |
michael@0 | 13 | // messages more readable. |
michael@0 | 14 | |
michael@0 | 15 | #define NS_DECL_QUERYFRAME_TARGET(classname) \ |
michael@0 | 16 | static const nsQueryFrame::FrameIID kFrameIID = nsQueryFrame::classname##_id; \ |
michael@0 | 17 | typedef classname Has_NS_DECL_QUERYFRAME_TARGET; |
michael@0 | 18 | |
michael@0 | 19 | #define NS_DECL_QUERYFRAME \ |
michael@0 | 20 | virtual void* QueryFrame(FrameIID id); |
michael@0 | 21 | |
michael@0 | 22 | #define NS_QUERYFRAME_HEAD(class) \ |
michael@0 | 23 | void* class::QueryFrame(FrameIID id) { switch (id) { |
michael@0 | 24 | |
michael@0 | 25 | #define NS_QUERYFRAME_ENTRY(class) \ |
michael@0 | 26 | case class::kFrameIID: { \ |
michael@0 | 27 | static_assert(mozilla::IsSame<class, class::Has_NS_DECL_QUERYFRAME_TARGET>::value, \ |
michael@0 | 28 | #class " must declare itself as a queryframe target"); \ |
michael@0 | 29 | return static_cast<class*>(this); \ |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | #define NS_QUERYFRAME_ENTRY_CONDITIONAL(class, condition) \ |
michael@0 | 33 | case class::kFrameIID: \ |
michael@0 | 34 | if (condition) { \ |
michael@0 | 35 | static_assert(mozilla::IsSame<class, class::Has_NS_DECL_QUERYFRAME_TARGET>::value, \ |
michael@0 | 36 | #class " must declare itself as a queryframe target"); \ |
michael@0 | 37 | return static_cast<class*>(this); \ |
michael@0 | 38 | } \ |
michael@0 | 39 | break; |
michael@0 | 40 | |
michael@0 | 41 | #define NS_QUERYFRAME_TAIL_INHERITING(class) \ |
michael@0 | 42 | default: break; \ |
michael@0 | 43 | } \ |
michael@0 | 44 | return class::QueryFrame(id); \ |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | #define NS_QUERYFRAME_TAIL_INHERITANCE_ROOT \ |
michael@0 | 48 | default: break; \ |
michael@0 | 49 | } \ |
michael@0 | 50 | MOZ_ASSERT(id != GetFrameId(), \ |
michael@0 | 51 | "A frame failed to QueryFrame to its *own type*. " \ |
michael@0 | 52 | "It may be missing NS_DECL_QUERYFRAME, or a " \ |
michael@0 | 53 | "NS_QUERYFRAME_ENTRY() line with its own type name"); \ |
michael@0 | 54 | return nullptr; \ |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | class nsQueryFrame |
michael@0 | 58 | { |
michael@0 | 59 | public: |
michael@0 | 60 | enum FrameIID { |
michael@0 | 61 | #define FRAME_ID(classname) classname##_id, |
michael@0 | 62 | #include "nsFrameIdList.h" |
michael@0 | 63 | #undef FRAME_ID |
michael@0 | 64 | |
michael@0 | 65 | // The PresArena implementation uses this bit to distinguish objects |
michael@0 | 66 | // allocated by size from objects allocated by type ID (that is, frames |
michael@0 | 67 | // using AllocateByFrameID, and other objects using AllocateByObjectID). |
michael@0 | 68 | // It should not collide with any frame ID (above) or Object ID (in |
michael@0 | 69 | // nsPresArena.h). It is not 0x80000000 to avoid the question of |
michael@0 | 70 | // whether enumeration constants are signed. |
michael@0 | 71 | NON_FRAME_MARKER = 0x20000000 |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | virtual void* QueryFrame(FrameIID id) = 0; |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | class do_QueryFrame |
michael@0 | 78 | { |
michael@0 | 79 | public: |
michael@0 | 80 | do_QueryFrame(nsQueryFrame *s) : mRawPtr(s) { } |
michael@0 | 81 | |
michael@0 | 82 | template<class Dest> |
michael@0 | 83 | operator Dest*() { |
michael@0 | 84 | static_assert(mozilla::IsSame<Dest, typename Dest::Has_NS_DECL_QUERYFRAME_TARGET>::value, |
michael@0 | 85 | "Dest must declare itself as a queryframe target"); |
michael@0 | 86 | if (!mRawPtr) |
michael@0 | 87 | return nullptr; |
michael@0 | 88 | |
michael@0 | 89 | return reinterpret_cast<Dest*>(mRawPtr->QueryFrame(Dest::kFrameIID)); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | private: |
michael@0 | 93 | nsQueryFrame *mRawPtr; |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | #endif // nsQueryFrame_h |