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/. */
7 /* constants for frame state bits and a type to store them in a uint64_t */
9 #include "nsFrameState.h"
11 #include "nsBlockFrame.h"
12 #include "nsFlexContainerFrame.h"
13 #include "nsGridContainerFrame.h"
14 #include "nsGfxScrollFrame.h"
16 #include "nsImageFrame.h"
17 #include "nsInlineFrame.h"
18 #include "nsPageFrame.h"
19 #include "nsPlaceholderFrame.h"
20 #include "nsRubyTextFrame.h"
21 #include "nsRubyTextContainerFrame.h"
22 #include "nsTableCellFrame.h"
23 #include "nsTableRowFrame.h"
24 #include "nsTableRowGroupFrame.h"
25 #include "nsTextFrame.h"
26 #include "mozilla/ISVGDisplayableFrame.h"
27 #include "mozilla/SVGContainerFrame.h"
32 nsCString
GetFrameState(nsIFrame
* aFrame
) {
34 AutoTArray
<const char*, 3> groups
;
36 nsFrameState state
= aFrame
->GetStateBits();
38 if (state
== nsFrameState(0)) {
43 # define FRAME_STATE_GROUP_CLASS(name_, class_) \
45 class_* frame = do_QueryFrame(aFrame); \
47 (groups.IsEmpty() || strcmp(groups.LastElement(), #name_))) { \
48 groups.AppendElement(#name_); \
51 # define FRAME_STATE_BIT(group_, value_, name_) \
52 if ((state & NS_FRAME_STATE_BIT(value_)) && groups.Contains(#group_)) { \
53 if (!result.IsEmpty()) { \
54 result.InsertLiteral(" | ", 0); \
56 result.InsertLiteral(#name_, 0); \
57 state = state & ~NS_FRAME_STATE_BIT(value_); \
59 # include "nsFrameStateBits.h"
60 # undef FRAME_STATE_GROUP_CLASS
61 # undef FRAME_STATE_BIT
64 result
.AppendPrintf(" | 0x%0" PRIx64
, static_cast<uint64_t>(state
));
70 void PrintFrameState(nsIFrame
* aFrame
) {
71 printf("%s\n", GetFrameState(aFrame
).get());
74 enum class FrameStateGroupId
{
75 # define FRAME_STATE_GROUP_NAME(name_) name_,
76 # include "nsFrameStateBits.h"
77 # undef FRAME_STATE_GROUP_NAME
82 void DebugVerifyFrameStateBits() {
83 // Build an array of all of the bits used by each group. While
84 // building this we assert that a bit isn't used multiple times within
86 nsFrameState bitsUsedPerGroup
[size_t(FrameStateGroupId::LENGTH
)] = {
89 # define FRAME_STATE_BIT(group_, value_, name_) \
91 auto bit = NS_FRAME_STATE_BIT(value_); \
92 size_t group = size_t(FrameStateGroupId::group_); \
93 MOZ_ASSERT(!(bitsUsedPerGroup[group] & bit), #name_ \
94 " must not use a bit already declared within its group"); \
95 bitsUsedPerGroup[group] |= bit; \
98 # include "nsFrameStateBits.h"
99 # undef FRAME_STATE_BIT
101 // FIXME: Can we somehow check across the groups as well??? In other
102 // words, find the pairs of groups that could be used on the same
103 // frame (Generic paired with everything else, and a few other pairs),
104 // and check that we don't have bits in common between those pairs.
109 } // namespace mozilla