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
17 using namespace mozilla;
18
19 #define COL_TYPE_BITS \
20 (NS_FRAME_STATE_BIT(28) | NS_FRAME_STATE_BIT(29) | NS_FRAME_STATE_BIT(30) | \
21 NS_FRAME_STATE_BIT(31))
22 #define COL_TYPE_OFFSET 28
23
24 using namespace mozilla;
25
nsTableColFrame(ComputedStyle * aStyle,nsPresContext * aPresContext)26 nsTableColFrame::nsTableColFrame(ComputedStyle* aStyle,
27 nsPresContext* aPresContext)
28 : nsSplittableFrame(aStyle, aPresContext, kClassID),
29 mMinCoord(0),
30 mPrefCoord(0),
31 mSpanMinCoord(0),
32 mSpanPrefCoord(0),
33 mPrefPercent(0.0f),
34 mSpanPrefPercent(0.0f),
35 mFinalISize(0),
36 mColIndex(0),
37 mIStartBorderWidth(0),
38 mIEndBorderWidth(0),
39 mBStartContBorderWidth(0),
40 mIEndContBorderWidth(0),
41 mBEndContBorderWidth(0),
42 mHasSpecifiedCoord(false) {
43 SetColType(eColContent);
44 ResetIntrinsics();
45 ResetSpanIntrinsics();
46 ResetFinalISize();
47 }
48
49 nsTableColFrame::~nsTableColFrame() = default;
50
GetColType() const51 nsTableColType nsTableColFrame::GetColType() const {
52 return (nsTableColType)((mState & COL_TYPE_BITS) >> COL_TYPE_OFFSET);
53 }
54
SetColType(nsTableColType aType)55 void nsTableColFrame::SetColType(nsTableColType aType) {
56 NS_ASSERTION(aType != eColAnonymousCol ||
57 (GetPrevContinuation() &&
58 GetPrevContinuation()->GetNextContinuation() == this &&
59 GetPrevContinuation()->GetNextSibling() == this),
60 "spanned content cols must be continuations");
61 uint32_t type = aType - eColContent;
62 RemoveStateBits(COL_TYPE_BITS);
63 AddStateBits(nsFrameState(type << COL_TYPE_OFFSET));
64 }
65
66 /* virtual */
DidSetComputedStyle(ComputedStyle * aOldComputedStyle)67 void nsTableColFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) {
68 nsSplittableFrame::DidSetComputedStyle(aOldComputedStyle);
69
70 if (!aOldComputedStyle) // avoid this on init
71 return;
72
73 nsTableFrame* tableFrame = GetTableFrame();
74 if (tableFrame->IsBorderCollapse() &&
75 tableFrame->BCRecalcNeeded(aOldComputedStyle, Style())) {
76 TableArea damageArea(GetColIndex(), 0, 1, tableFrame->GetRowCount());
77 tableFrame->AddBCDamageArea(damageArea);
78 }
79 }
80
SetContinuousBCBorderWidth(LogicalSide aForSide,BCPixelSize aPixelValue)81 void nsTableColFrame::SetContinuousBCBorderWidth(LogicalSide aForSide,
82 BCPixelSize aPixelValue) {
83 switch (aForSide) {
84 case eLogicalSideBStart:
85 mBStartContBorderWidth = aPixelValue;
86 return;
87 case eLogicalSideIEnd:
88 mIEndContBorderWidth = aPixelValue;
89 return;
90 case eLogicalSideBEnd:
91 mBEndContBorderWidth = aPixelValue;
92 return;
93 default:
94 NS_ERROR("invalid side arg");
95 }
96 }
97
Reflow(nsPresContext * aPresContext,ReflowOutput & aDesiredSize,const ReflowInput & aReflowInput,nsReflowStatus & aStatus)98 void nsTableColFrame::Reflow(nsPresContext* aPresContext,
99 ReflowOutput& aDesiredSize,
100 const ReflowInput& aReflowInput,
101 nsReflowStatus& aStatus) {
102 MarkInReflow();
103 DO_GLOBAL_REFLOW_COUNT("nsTableColFrame");
104 DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
105 MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
106 aDesiredSize.ClearSize();
107 const nsStyleVisibility* colVis = StyleVisibility();
108 bool collapseCol = StyleVisibility::Collapse == colVis->mVisible;
109 if (collapseCol) {
110 GetTableFrame()->SetNeedToCollapse(true);
111 }
112 NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
113 }
114
BuildDisplayList(nsDisplayListBuilder * aBuilder,const nsDisplayListSet & aLists)115 void nsTableColFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
116 const nsDisplayListSet& aLists) {
117 // Per https://drafts.csswg.org/css-tables-3/#global-style-overrides:
118 // "All css properties of table-column and table-column-group boxes are
119 // ignored, except when explicitly specified by this specification."
120 // CSS outlines and box-shadows fall into this category, so we skip them
121 // on these boxes.
122 MOZ_ASSERT_UNREACHABLE("Cols don't paint themselves");
123 }
124
GetSpan()125 int32_t nsTableColFrame::GetSpan() { return StyleTable()->mXSpan; }
126
127 #ifdef DEBUG
Dump(int32_t aIndent)128 void nsTableColFrame::Dump(int32_t aIndent) {
129 char* indent = new char[aIndent + 1];
130 if (!indent) return;
131 for (int32_t i = 0; i < aIndent + 1; i++) {
132 indent[i] = ' ';
133 }
134 indent[aIndent] = 0;
135
136 printf("%s**START COL DUMP**\n%s colIndex=%d coltype=", indent, indent,
137 mColIndex);
138 nsTableColType colType = GetColType();
139 switch (colType) {
140 case eColContent:
141 printf(" content ");
142 break;
143 case eColAnonymousCol:
144 printf(" anonymous-column ");
145 break;
146 case eColAnonymousColGroup:
147 printf(" anonymous-colgroup ");
148 break;
149 case eColAnonymousCell:
150 printf(" anonymous-cell ");
151 break;
152 }
153 printf("\nm:%d c:%d(%c) p:%f sm:%d sc:%d sp:%f f:%d", int32_t(mMinCoord),
154 int32_t(mPrefCoord), mHasSpecifiedCoord ? 's' : 'u', mPrefPercent,
155 int32_t(mSpanMinCoord), int32_t(mSpanPrefCoord), mSpanPrefPercent,
156 int32_t(GetFinalISize()));
157 printf("\n%s**END COL DUMP** ", indent);
158 delete[] indent;
159 }
160 #endif
161 /* ----- global methods ----- */
162
NS_NewTableColFrame(PresShell * aPresShell,ComputedStyle * aStyle)163 nsTableColFrame* NS_NewTableColFrame(PresShell* aPresShell,
164 ComputedStyle* aStyle) {
165 return new (aPresShell) nsTableColFrame(aStyle, aPresShell->GetPresContext());
166 }
167
NS_IMPL_FRAMEARENA_HELPERS(nsTableColFrame)168 NS_IMPL_FRAMEARENA_HELPERS(nsTableColFrame)
169
170 nsTableColFrame* nsTableColFrame::GetNextCol() const {
171 nsIFrame* childFrame = GetNextSibling();
172 while (childFrame) {
173 if (childFrame->IsTableColFrame()) {
174 return (nsTableColFrame*)childFrame;
175 }
176 childFrame = childFrame->GetNextSibling();
177 }
178 return nullptr;
179 }
180
181 #ifdef DEBUG_FRAME_DUMP
GetFrameName(nsAString & aResult) const182 nsresult nsTableColFrame::GetFrameName(nsAString& aResult) const {
183 return MakeFrameName(NS_LITERAL_STRING("TableCol"), aResult);
184 }
185 #endif
186
InvalidateFrame(uint32_t aDisplayItemKey,bool aRebuildDisplayItems)187 void nsTableColFrame::InvalidateFrame(uint32_t aDisplayItemKey,
188 bool aRebuildDisplayItems) {
189 nsIFrame::InvalidateFrame(aDisplayItemKey, aRebuildDisplayItems);
190 if (GetTableFrame()->IsBorderCollapse()) {
191 GetParent()->InvalidateFrameWithRect(
192 GetVisualOverflowRect() + GetPosition(), aDisplayItemKey, false);
193 }
194 }
195
InvalidateFrameWithRect(const nsRect & aRect,uint32_t aDisplayItemKey,bool aRebuildDisplayItems)196 void nsTableColFrame::InvalidateFrameWithRect(const nsRect& aRect,
197 uint32_t aDisplayItemKey,
198 bool aRebuildDisplayItems) {
199 nsIFrame::InvalidateFrameWithRect(aRect, aDisplayItemKey,
200 aRebuildDisplayItems);
201
202 // If we have filters applied that would affects our bounds, then
203 // we get an inactive layer created and this is computed
204 // within FrameLayerBuilder
205 GetParent()->InvalidateFrameWithRect(aRect + GetPosition(), aDisplayItemKey,
206 false);
207 }
208