nsFrameState.cpp (3930B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* constants for frame state bits and a type to store them in a uint64_t */ 8 9 #include "nsFrameState.h" 10 11 #include "mozilla/ISVGDisplayableFrame.h" 12 #include "mozilla/SVGContainerFrame.h" 13 #include "nsBlockFrame.h" 14 #include "nsFlexContainerFrame.h" 15 #include "nsGridContainerFrame.h" 16 #include "nsIFrame.h" 17 #include "nsImageFrame.h" 18 #include "nsInlineFrame.h" 19 #include "nsPageFrame.h" 20 #include "nsPlaceholderFrame.h" 21 #include "nsRubyTextContainerFrame.h" 22 #include "nsRubyTextFrame.h" 23 #include "nsTableCellFrame.h" 24 #include "nsTableRowFrame.h" 25 #include "nsTableRowGroupFrame.h" 26 #include "nsTextFrame.h" 27 28 namespace mozilla { 29 30 #ifdef DEBUG 31 nsCString GetFrameState(nsIFrame* aFrame) { 32 nsCString result; 33 AutoTArray<const char*, 3> groups; 34 35 nsFrameState state = aFrame->GetStateBits(); 36 37 if (state == nsFrameState(0)) { 38 result.Assign('0'); 39 return result; 40 } 41 42 # define FRAME_STATE_GROUP_CLASS(name_, class_) \ 43 { \ 44 class_* frame = do_QueryFrame(aFrame); \ 45 if (frame && \ 46 (groups.IsEmpty() || strcmp(groups.LastElement(), #name_))) { \ 47 groups.AppendElement(#name_); \ 48 } \ 49 } 50 # define FRAME_STATE_BIT(group_, value_, name_) \ 51 if ((state & NS_FRAME_STATE_BIT(value_)) && groups.Contains(#group_)) { \ 52 if (!result.IsEmpty()) { \ 53 result.InsertLiteral(" | ", 0); \ 54 } \ 55 result.InsertLiteral(#name_, 0); \ 56 state = state & ~NS_FRAME_STATE_BIT(value_); \ 57 } 58 # include "nsFrameStateBits.h" 59 # undef FRAME_STATE_GROUP_CLASS 60 # undef FRAME_STATE_BIT 61 62 if (state) { 63 result.AppendPrintf(" | 0x%0" PRIx64, static_cast<uint64_t>(state)); 64 } 65 66 return result; 67 } 68 69 void PrintFrameState(nsIFrame* aFrame) { 70 printf("%s\n", GetFrameState(aFrame).get()); 71 } 72 73 enum class FrameStateGroupId { 74 # define FRAME_STATE_GROUP_NAME(name_) name_, 75 # include "nsFrameStateBits.h" 76 # undef FRAME_STATE_GROUP_NAME 77 78 LENGTH 79 }; 80 81 void DebugVerifyFrameStateBits() { 82 // Build an array of all of the bits used by each group. While 83 // building this we assert that a bit isn't used multiple times within 84 // the same group. 85 nsFrameState bitsUsedPerGroup[size_t(FrameStateGroupId::LENGTH)] = { 86 nsFrameState(0)}; 87 88 # define FRAME_STATE_BIT(group_, value_, name_) \ 89 { \ 90 auto bit = NS_FRAME_STATE_BIT(value_); \ 91 size_t group = size_t(FrameStateGroupId::group_); \ 92 MOZ_ASSERT(!(bitsUsedPerGroup[group] & bit), #name_ \ 93 " must not use a bit already declared within its group"); \ 94 bitsUsedPerGroup[group] |= bit; \ 95 } 96 97 # include "nsFrameStateBits.h" 98 # undef FRAME_STATE_BIT 99 100 // FIXME: Can we somehow check across the groups as well??? In other 101 // words, find the pairs of groups that could be used on the same 102 // frame (Generic paired with everything else, and a few other pairs), 103 // and check that we don't have bits in common between those pairs. 104 } 105 106 #endif 107 108 } // namespace mozilla