Bug 1885580 - Add a MenuGroup component for the menu redesign r=android-reviewers,007
[gecko.git] / layout / tables / nsTableColFrame.cpp
blob8031d4c47ccd54255ca65cc48aa95589cf381136
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsCOMPtr.h"
6 #include "nsTableColFrame.h"
7 #include "nsTableFrame.h"
8 #include "nsContainerFrame.h"
9 #include "nsStyleConsts.h"
10 #include "nsPresContext.h"
11 #include "nsGkAtoms.h"
12 #include "nsCSSRendering.h"
13 #include "nsIContent.h"
14 #include "mozilla/ComputedStyle.h"
15 #include "mozilla/PresShell.h"
16 #include "mozilla/StaticPrefs_layout.h"
18 using namespace mozilla;
20 #define COL_TYPE_BITS \
21 (NS_FRAME_STATE_BIT(28) | NS_FRAME_STATE_BIT(29) | NS_FRAME_STATE_BIT(30) | \
22 NS_FRAME_STATE_BIT(31))
23 #define COL_TYPE_OFFSET 28
25 using namespace mozilla;
27 nsTableColFrame::nsTableColFrame(ComputedStyle* aStyle,
28 nsPresContext* aPresContext)
29 : nsSplittableFrame(aStyle, aPresContext, kClassID),
30 mMinCoord(0),
31 mPrefCoord(0),
32 mSpanMinCoord(0),
33 mSpanPrefCoord(0),
34 mPrefPercent(0.0f),
35 mSpanPrefPercent(0.0f),
36 mFinalISize(0),
37 mColIndex(0),
38 mIStartBorderWidth(0),
39 mIEndBorderWidth(0),
40 mHasSpecifiedCoord(false) {
41 SetColType(eColContent);
42 ResetIntrinsics();
43 ResetSpanIntrinsics();
44 ResetFinalISize();
47 nsTableColFrame::~nsTableColFrame() = default;
49 nsTableColType nsTableColFrame::GetColType() const {
50 return (nsTableColType)((GetStateBits() & COL_TYPE_BITS) >> COL_TYPE_OFFSET);
53 void nsTableColFrame::SetColType(nsTableColType aType) {
54 NS_ASSERTION(aType != eColAnonymousCol ||
55 (GetPrevContinuation() &&
56 GetPrevContinuation()->GetNextContinuation() == this &&
57 GetPrevContinuation()->GetNextSibling() == this),
58 "spanned content cols must be continuations");
59 uint32_t type = aType - eColContent;
60 RemoveStateBits(COL_TYPE_BITS);
61 AddStateBits(nsFrameState(type << COL_TYPE_OFFSET));
64 /* virtual */
65 void nsTableColFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) {
66 nsSplittableFrame::DidSetComputedStyle(aOldComputedStyle);
68 if (!aOldComputedStyle) // avoid this on init
69 return;
71 nsTableFrame* tableFrame = GetTableFrame();
72 if (tableFrame->IsBorderCollapse() &&
73 tableFrame->BCRecalcNeeded(aOldComputedStyle, Style())) {
74 TableArea damageArea(GetColIndex(), 0, 1, tableFrame->GetRowCount());
75 tableFrame->AddBCDamageArea(damageArea);
79 void nsTableColFrame::Reflow(nsPresContext* aPresContext,
80 ReflowOutput& aDesiredSize,
81 const ReflowInput& aReflowInput,
82 nsReflowStatus& aStatus) {
83 MarkInReflow();
84 DO_GLOBAL_REFLOW_COUNT("nsTableColFrame");
85 MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
86 aDesiredSize.ClearSize();
87 const nsStyleVisibility* colVis = StyleVisibility();
88 bool collapseCol = StyleVisibility::Collapse == colVis->mVisible;
89 if (collapseCol) {
90 GetTableFrame()->SetNeedToCollapse(true);
94 void nsTableColFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
95 const nsDisplayListSet& aLists) {
96 // Per https://drafts.csswg.org/css-tables-3/#global-style-overrides:
97 // "All css properties of table-column and table-column-group boxes are
98 // ignored, except when explicitly specified by this specification."
99 // CSS outlines and box-shadows fall into this category, so we skip them
100 // on these boxes.
101 MOZ_ASSERT_UNREACHABLE("Cols don't paint themselves");
104 int32_t nsTableColFrame::GetSpan() { return StyleTable()->mXSpan; }
106 #ifdef DEBUG
107 void nsTableColFrame::Dump(int32_t aIndent) {
108 char* indent = new char[aIndent + 1];
109 if (!indent) return;
110 for (int32_t i = 0; i < aIndent + 1; i++) {
111 indent[i] = ' ';
113 indent[aIndent] = 0;
115 printf("%s**START COL DUMP**\n%s colIndex=%d coltype=", indent, indent,
116 mColIndex);
117 nsTableColType colType = GetColType();
118 switch (colType) {
119 case eColContent:
120 printf(" content ");
121 break;
122 case eColAnonymousCol:
123 printf(" anonymous-column ");
124 break;
125 case eColAnonymousColGroup:
126 printf(" anonymous-colgroup ");
127 break;
128 case eColAnonymousCell:
129 printf(" anonymous-cell ");
130 break;
132 printf("\nm:%d c:%d(%c) p:%f sm:%d sc:%d sp:%f f:%d", int32_t(mMinCoord),
133 int32_t(mPrefCoord), mHasSpecifiedCoord ? 's' : 'u', mPrefPercent,
134 int32_t(mSpanMinCoord), int32_t(mSpanPrefCoord), mSpanPrefPercent,
135 int32_t(GetFinalISize()));
136 printf("\n%s**END COL DUMP** ", indent);
137 delete[] indent;
139 #endif
140 /* ----- global methods ----- */
142 nsTableColFrame* NS_NewTableColFrame(PresShell* aPresShell,
143 ComputedStyle* aStyle) {
144 return new (aPresShell) nsTableColFrame(aStyle, aPresShell->GetPresContext());
147 NS_IMPL_FRAMEARENA_HELPERS(nsTableColFrame)
149 nsTableColFrame* nsTableColFrame::GetNextCol() const {
150 nsIFrame* childFrame = GetNextSibling();
151 while (childFrame) {
152 if (childFrame->IsTableColFrame()) {
153 return (nsTableColFrame*)childFrame;
155 childFrame = childFrame->GetNextSibling();
157 return nullptr;
160 #ifdef DEBUG_FRAME_DUMP
161 nsresult nsTableColFrame::GetFrameName(nsAString& aResult) const {
162 return MakeFrameName(u"TableCol"_ns, aResult);
164 #endif
166 void nsTableColFrame::InvalidateFrame(uint32_t aDisplayItemKey,
167 bool aRebuildDisplayItems) {
168 nsIFrame::InvalidateFrame(aDisplayItemKey, aRebuildDisplayItems);
169 if (GetTableFrame()->IsBorderCollapse()) {
170 const bool rebuild = StaticPrefs::layout_display_list_retain_sc();
171 GetParent()->InvalidateFrameWithRect(InkOverflowRect() + GetPosition(),
172 aDisplayItemKey, rebuild);
176 void nsTableColFrame::InvalidateFrameWithRect(const nsRect& aRect,
177 uint32_t aDisplayItemKey,
178 bool aRebuildDisplayItems) {
179 nsIFrame::InvalidateFrameWithRect(aRect, aDisplayItemKey,
180 aRebuildDisplayItems);
182 // If we have filters applied that would affects our bounds, then
183 // we get an inactive layer created and this is computed
184 // within FrameLayerBuilder
185 GetParent()->InvalidateFrameWithRect(aRect + GetPosition(), aDisplayItemKey,
186 aRebuildDisplayItems);