Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / layout / generic / nsFrameState.cpp
blob2e5463e2d304ea7458be147a7d2809f79c9adfbe
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"
15 #include "nsIFrame.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"
29 namespace mozilla {
31 #ifdef DEBUG
32 nsCString GetFrameState(nsIFrame* aFrame) {
33 nsCString result;
34 AutoTArray<const char*, 3> groups;
36 nsFrameState state = aFrame->GetStateBits();
38 if (state == nsFrameState(0)) {
39 result.Assign('0');
40 return result;
43 # define FRAME_STATE_GROUP_CLASS(name_, class_) \
44 { \
45 class_* frame = do_QueryFrame(aFrame); \
46 if (frame && \
47 (groups.IsEmpty() || strcmp(groups.LastElement(), #name_))) { \
48 groups.AppendElement(#name_); \
49 } \
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); \
55 } \
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
63 if (state) {
64 result.AppendPrintf(" | 0x%0" PRIx64, static_cast<uint64_t>(state));
67 return result;
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
79 LENGTH
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
85 // the same group.
86 nsFrameState bitsUsedPerGroup[size_t(FrameStateGroupId::LENGTH)] = {
87 nsFrameState(0)};
89 # define FRAME_STATE_BIT(group_, value_, name_) \
90 { \
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.
107 #endif
109 } // namespace mozilla