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 "nsBoxFrame.h"
13 #include "nsFlexContainerFrame.h"
14 #include "nsGridContainerFrame.h"
15 #include "nsGfxScrollFrame.h"
17 #include "nsImageFrame.h"
18 #include "nsInlineFrame.h"
19 #include "nsPageFrame.h"
20 #include "nsPlaceholderFrame.h"
21 #include "nsRubyTextFrame.h"
22 #include "nsRubyTextContainerFrame.h"
23 #include "nsTableCellFrame.h"
24 #include "nsTableRowFrame.h"
25 #include "nsTableRowGroupFrame.h"
26 #include "nsTextFrame.h"
27 #include "mozilla/ISVGDisplayableFrame.h"
28 #include "mozilla/SVGContainerFrame.h"
33 nsCString
GetFrameState(nsIFrame
* aFrame
) {
35 AutoTArray
<const char*, 3> groups
;
37 nsFrameState state
= aFrame
->GetStateBits();
39 if (state
== nsFrameState(0)) {
44 # define FRAME_STATE_GROUP_CLASS(name_, class_) \
46 class_* frame = do_QueryFrame(aFrame); \
48 (groups.IsEmpty() || strcmp(groups.LastElement(), #name_))) { \
49 groups.AppendElement(#name_); \
52 # define FRAME_STATE_BIT(group_, value_, name_) \
53 if ((state & NS_FRAME_STATE_BIT(value_)) && groups.Contains(#group_)) { \
54 if (!result.IsEmpty()) { \
55 result.InsertLiteral(" | ", 0); \
57 result.InsertLiteral(#name_, 0); \
58 state = state & ~NS_FRAME_STATE_BIT(value_); \
60 # include "nsFrameStateBits.h"
61 # undef FRAME_STATE_GROUP_CLASS
62 # undef FRAME_STATE_BIT
65 result
.AppendPrintf(" | 0x%0" PRIx64
, static_cast<uint64_t>(state
));
71 void PrintFrameState(nsIFrame
* aFrame
) {
72 printf("%s\n", GetFrameState(aFrame
).get());
75 enum class FrameStateGroupId
{
76 # define FRAME_STATE_GROUP_NAME(name_) name_,
77 # include "nsFrameStateBits.h"
78 # undef FRAME_STATE_GROUP_NAME
83 void DebugVerifyFrameStateBits() {
84 // Build an array of all of the bits used by each group. While
85 // building this we assert that a bit isn't used multiple times within
87 nsFrameState bitsUsedPerGroup
[size_t(FrameStateGroupId::LENGTH
)] = {
90 # define FRAME_STATE_BIT(group_, value_, name_) \
92 auto bit = NS_FRAME_STATE_BIT(value_); \
93 size_t group = size_t(FrameStateGroupId::group_); \
94 MOZ_ASSERT(!(bitsUsedPerGroup[group] & bit), #name_ \
95 " must not use a bit already declared within its group"); \
96 bitsUsedPerGroup[group] |= bit; \
99 # include "nsFrameStateBits.h"
100 # undef FRAME_STATE_BIT
102 // FIXME: Can we somehow check across the groups as well??? In other
103 // words, find the pairs of groups that could be used on the same
104 // frame (Generic paired with everything else, and a few other pairs),
105 // and check that we don't have bits in common between those pairs.
110 } // namespace mozilla