Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* constants for frame state bits and a type to store them in a uint64_t */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef nsFrameState_h_ |
michael@0 | 9 | #define nsFrameState_h_ |
michael@0 | 10 | |
michael@0 | 11 | #include <stdint.h> |
michael@0 | 12 | |
michael@0 | 13 | #ifdef DEBUG |
michael@0 | 14 | #include "nsString.h" |
michael@0 | 15 | |
michael@0 | 16 | class nsIFrame; |
michael@0 | 17 | #endif |
michael@0 | 18 | |
michael@0 | 19 | typedef uint64_t nsFrameState_size_t; |
michael@0 | 20 | |
michael@0 | 21 | #define NS_FRAME_STATE_BIT(n_) (nsFrameState(nsFrameState_size_t(1) << (n_))) |
michael@0 | 22 | |
michael@0 | 23 | #if (_MSC_VER == 1600) |
michael@0 | 24 | /* |
michael@0 | 25 | * Visual Studio 2010 has trouble with the sized enum. Although sized enums |
michael@0 | 26 | * are supported, two problems arise: |
michael@0 | 27 | * |
michael@0 | 28 | * 1. Implicit conversions from the enum type to the equivalently sized |
michael@0 | 29 | * integer size are not performed, leading to many compile errors. |
michael@0 | 30 | * 2. Even with explicit casts added to avoid the errors from (1), odd |
michael@0 | 31 | * test failures result, which might well be due to a compiler bug. |
michael@0 | 32 | * |
michael@0 | 33 | * So with VS2010 we use consts for the state bits and forgo the increased |
michael@0 | 34 | * type safety of the enum. (Visual Studio 2012 has no problem with |
michael@0 | 35 | * nsFrameState being a sized enum, however.) |
michael@0 | 36 | */ |
michael@0 | 37 | |
michael@0 | 38 | typedef nsFrameState_size_t nsFrameState; |
michael@0 | 39 | |
michael@0 | 40 | #define FRAME_STATE_BIT(group_, value_, name_) \ |
michael@0 | 41 | const nsFrameState name_ = NS_FRAME_STATE_BIT(value_); |
michael@0 | 42 | #include "nsFrameStateBits.h" |
michael@0 | 43 | #undef FRAME_STATE_BIT |
michael@0 | 44 | |
michael@0 | 45 | #else |
michael@0 | 46 | |
michael@0 | 47 | enum nsFrameState : nsFrameState_size_t { |
michael@0 | 48 | #define FRAME_STATE_BIT(group_, value_, name_) \ |
michael@0 | 49 | name_ = NS_FRAME_STATE_BIT(value_), |
michael@0 | 50 | #include "nsFrameStateBits.h" |
michael@0 | 51 | #undef FRAME_STATE_BIT |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | inline nsFrameState operator|(nsFrameState aLeft, nsFrameState aRight) |
michael@0 | 55 | { |
michael@0 | 56 | return nsFrameState(nsFrameState_size_t(aLeft) | nsFrameState_size_t(aRight)); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | inline nsFrameState operator&(nsFrameState aLeft, nsFrameState aRight) |
michael@0 | 60 | { |
michael@0 | 61 | return nsFrameState(nsFrameState_size_t(aLeft) & nsFrameState_size_t(aRight)); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | inline nsFrameState& operator|=(nsFrameState& aLeft, nsFrameState aRight) |
michael@0 | 65 | { |
michael@0 | 66 | aLeft = aLeft | aRight; |
michael@0 | 67 | return aLeft; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | inline nsFrameState& operator&=(nsFrameState& aLeft, nsFrameState aRight) |
michael@0 | 71 | { |
michael@0 | 72 | aLeft = aLeft & aRight; |
michael@0 | 73 | return aLeft; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | inline nsFrameState operator~(nsFrameState aRight) |
michael@0 | 77 | { |
michael@0 | 78 | return nsFrameState(~nsFrameState_size_t(aRight)); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | inline nsFrameState operator^(nsFrameState aLeft, nsFrameState aRight) |
michael@0 | 82 | { |
michael@0 | 83 | return nsFrameState(nsFrameState_size_t(aLeft) ^ nsFrameState_size_t(aRight)); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | inline nsFrameState& operator^=(nsFrameState& aLeft, nsFrameState aRight) |
michael@0 | 87 | { |
michael@0 | 88 | aLeft = aLeft ^ aRight; |
michael@0 | 89 | return aLeft; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | #endif |
michael@0 | 93 | |
michael@0 | 94 | // Bits 20-31 and 60-63 of the frame state are reserved for implementations. |
michael@0 | 95 | #define NS_FRAME_IMPL_RESERVED nsFrameState(0xF0000000FFF00000) |
michael@0 | 96 | #define NS_FRAME_RESERVED ~NS_FRAME_IMPL_RESERVED |
michael@0 | 97 | |
michael@0 | 98 | namespace mozilla { |
michael@0 | 99 | #ifdef DEBUG |
michael@0 | 100 | nsCString GetFrameState(nsIFrame* aFrame); |
michael@0 | 101 | void PrintFrameState(nsIFrame* aFrame); |
michael@0 | 102 | #endif |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | #endif /* nsFrameState_h_ */ |