forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nsTableFrame.h
943 lines (767 loc) · 33.7 KB
/
nsTableFrame.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsTableFrame_h__
#define nsTableFrame_h__
#include "nscore.h"
#include "nsContainerFrame.h"
#include "nsStyleCoord.h"
#include "nsStyleConsts.h"
#include "nsITableLayout.h"
#include "nsTableColFrame.h"
#include "nsTableColGroupFrame.h"
#include "nsCellMap.h"
#include "nsGkAtoms.h"
#include "nsDisplayList.h"
class nsTableCellFrame;
class nsTableColFrame;
class nsTableRowGroupFrame;
class nsTableRowFrame;
class nsTableColGroupFrame;
class nsITableLayoutStrategy;
class nsStyleContext;
struct nsTableReflowState;
struct nsStylePosition;
struct BCPropertyData;
static inline bool IS_TABLE_CELL(nsIAtom* frameType) {
return nsGkAtoms::tableCellFrame == frameType ||
nsGkAtoms::bcTableCellFrame == frameType;
}
class nsDisplayTableItem : public nsDisplayItem
{
public:
nsDisplayTableItem(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame) :
nsDisplayItem(aBuilder, aFrame),
mPartHasFixedBackground(false) {}
virtual bool IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilder,
nsIFrame* aFrame);
// With collapsed borders, parts of the collapsed border can extend outside
// the table part frames, so allow this display element to blow out to our
// overflow rect. This is also useful for row frames that have spanning
// cells extending outside them.
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap);
void UpdateForFrameBackground(nsIFrame* aFrame);
private:
bool mPartHasFixedBackground;
};
class nsAutoPushCurrentTableItem
{
public:
nsAutoPushCurrentTableItem() : mBuilder(nsnull) {}
void Push(nsDisplayListBuilder* aBuilder, nsDisplayTableItem* aPushItem)
{
mBuilder = aBuilder;
mOldCurrentItem = aBuilder->GetCurrentTableItem();
aBuilder->SetCurrentTableItem(aPushItem);
#ifdef DEBUG
mPushedItem = aPushItem;
#endif
}
~nsAutoPushCurrentTableItem() {
if (!mBuilder)
return;
#ifdef DEBUG
NS_ASSERTION(mBuilder->GetCurrentTableItem() == mPushedItem,
"Someone messed with the current table item behind our back!");
#endif
mBuilder->SetCurrentTableItem(mOldCurrentItem);
}
private:
nsDisplayListBuilder* mBuilder;
nsDisplayTableItem* mOldCurrentItem;
#ifdef DEBUG
nsDisplayTableItem* mPushedItem;
#endif
};
/* ============================================================================ */
/**
* nsTableFrame maps the inner portion of a table (everything except captions.)
* Used as a pseudo-frame within nsTableOuterFrame, it may also be used
* stand-alone as the top-level frame.
*
* The principal child list contains row group frames. There is also an
* additional child list, kColGroupList, which contains the col group frames.
*/
class nsTableFrame : public nsContainerFrame, public nsITableLayout
{
public:
NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS
/** nsTableOuterFrame has intimate knowledge of the inner table frame */
friend class nsTableOuterFrame;
/** instantiate a new instance of nsTableRowFrame.
* @param aPresShell the pres shell for this frame
*
* @return the frame that was created
*/
friend nsIFrame* NS_NewTableFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
/** sets defaults for table-specific style.
* @see nsIFrame::Init
*/
NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow);
static float GetTwipsToPixels(nsPresContext* aPresContext);
// Return true if aParentReflowState.frame or any of its ancestors within
// the containing table have non-auto height. (e.g. pct or fixed height)
static bool AncestorsHaveStyleHeight(const nsHTMLReflowState& aParentReflowState);
// See if a special height reflow will occur due to having a pct height when
// the pct height basis may not yet be valid.
static void CheckRequestSpecialHeightReflow(const nsHTMLReflowState& aReflowState);
// Notify the frame and its ancestors (up to the containing table) that a special
// height reflow will occur.
static void RequestSpecialHeightReflow(const nsHTMLReflowState& aReflowState);
static void RePositionViews(nsIFrame* aFrame);
static bool PageBreakAfter(nsIFrame* aSourceFrame,
nsIFrame* aNextFrame);
nsPoint GetFirstSectionOrigin(const nsHTMLReflowState& aReflowState) const;
/*
* Notification that aAttribute has changed for content inside a table (cell, row, etc)
*/
void AttributeChangedFor(nsIFrame* aFrame,
nsIContent* aContent,
nsIAtom* aAttribute);
/** @see nsIFrame::DestroyFrom */
virtual void DestroyFrom(nsIFrame* aDestructRoot);
/** @see nsIFrame::DidSetStyleContext */
virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
NS_IMETHOD AppendFrames(ChildListID aListID,
nsFrameList& aFrameList);
NS_IMETHOD InsertFrames(ChildListID aListID,
nsIFrame* aPrevFrame,
nsFrameList& aFrameList);
NS_IMETHOD RemoveFrame(ChildListID aListID,
nsIFrame* aOldFrame);
virtual nsMargin GetUsedBorder() const;
virtual nsMargin GetUsedPadding() const;
virtual nsMargin GetUsedMargin() const;
// Get the offset from the border box to the area where the row groups fit
nsMargin GetChildAreaOffset(const nsHTMLReflowState* aReflowState) const;
/** helper method to find the table parent of any table frame object */
static nsTableFrame* GetTableFrame(nsIFrame* aSourceFrame);
typedef nsresult (* DisplayGenericTablePartTraversal)
(nsDisplayListBuilder* aBuilder, nsFrame* aFrame,
const nsRect& aDirtyRect, const nsDisplayListSet& aLists);
static nsresult GenericTraversal(nsDisplayListBuilder* aBuilder, nsFrame* aFrame,
const nsRect& aDirtyRect, const nsDisplayListSet& aLists);
/**
* Helper method to handle display common to table frames, rowgroup frames
* and row frames. It creates a background display item for handling events
* if necessary, an outline display item if necessary, and displays
* all the the frame's children.
* @param aDisplayItem the display item created for this part, or null
* if this part's border/background painting is delegated to an ancestor
* @param aTraversal a function that gets called to traverse the table
* part's child frames and add their display list items to a
* display list set.
*/
static nsresult DisplayGenericTablePart(nsDisplayListBuilder* aBuilder,
nsFrame* aFrame,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists,
nsDisplayTableItem* aDisplayItem,
DisplayGenericTablePartTraversal aTraversal = GenericTraversal);
// Return the closest sibling of aPriorChildFrame (including aPriroChildFrame)
// of type aChildType.
static nsIFrame* GetFrameAtOrBefore(nsIFrame* aParentFrame,
nsIFrame* aPriorChildFrame,
nsIAtom* aChildType);
bool IsAutoHeight();
/** @return true if aDisplayType represents a rowgroup of any sort
* (header, footer, or body)
*/
bool IsRowGroup(PRInt32 aDisplayType) const;
/** Initialize the table frame with a set of children.
* @see nsIFrame::SetInitialChildList
*/
NS_IMETHOD SetInitialChildList(ChildListID aListID,
nsFrameList& aChildList);
virtual const nsFrameList& GetChildList(ChildListID aListID) const;
virtual void GetChildLists(nsTArray<ChildList>* aLists) const;
NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists);
/**
* Paint the background of the table and its parts (column groups,
* columns, row groups, rows, and cells), and the table border, and all
* internal borders if border-collapse is on.
*/
void PaintTableBorderBackground(nsRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsPoint aPt, PRUint32 aBGPaintFlags);
/** Get the outer half (i.e., the part outside the height and width of
* the table) of the largest segment (?) of border-collapsed border on
* the table on each side, or 0 for non border-collapsed tables.
*/
nsMargin GetOuterBCBorder() const;
/** Same as above, but only if it's included from the border-box width
* of the table.
*/
nsMargin GetIncludedOuterBCBorder() const;
/** Same as above, but only if it's excluded from the border-box width
* of the table. This is the area that leaks out into the margin
* (or potentially past it, if there is no margin).
*/
nsMargin GetExcludedOuterBCBorder() const;
/**
* In quirks mode, the size of the table background is reduced
* by the outer BC border. Compute the reduction needed.
*/
nsMargin GetDeflationForBackground(nsPresContext* aPresContext) const;
/** Get width of table + colgroup + col collapse: elements that
* continue along the length of the whole left side.
* see nsTablePainter about continuous borders
*/
nscoord GetContinuousLeftBCBorderWidth() const;
void SetContinuousLeftBCBorderWidth(nscoord aValue);
friend class nsDelayedCalcBCBorders;
void AddBCDamageArea(const nsIntRect& aValue);
bool BCRecalcNeeded(nsStyleContext* aOldStyleContext,
nsStyleContext* aNewStyleContext);
void PaintBCBorders(nsRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
virtual void MarkIntrinsicWidthsDirty();
// For border-collapse tables, the caller must not add padding and
// border to the results of these functions.
virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext);
virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext);
virtual IntrinsicWidthOffsetData
IntrinsicWidthOffsets(nsRenderingContext* aRenderingContext);
virtual nsSize ComputeSize(nsRenderingContext *aRenderingContext,
nsSize aCBSize, nscoord aAvailableWidth,
nsSize aMargin, nsSize aBorder, nsSize aPadding,
PRUint32 aFlags) MOZ_OVERRIDE;
virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext,
nsSize aCBSize, nscoord aAvailableWidth,
nsSize aMargin, nsSize aBorder,
nsSize aPadding, bool aShrinkWrap);
/**
* A copy of nsFrame::ShrinkWidthToFit that calls a different
* GetPrefWidth, since tables have two different ones.
*/
nscoord TableShrinkWidthToFit(nsRenderingContext *aRenderingContext,
nscoord aWidthInCB);
// XXXldb REWRITE THIS COMMENT!
/** inner tables are reflowed in two steps.
* <pre>
* if mFirstPassValid is false, this is our first time through since content was last changed
* set pass to 1
* do pass 1
* get min/max info for all cells in an infinite space
* do column balancing
* set mFirstPassValid to true
* do pass 2
* use column widths to Reflow cells
* </pre>
*
* @see nsIFrame::Reflow
*/
NS_IMETHOD Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
nsresult ReflowTable(nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nscoord aAvailHeight,
nsIFrame*& aLastChildReflowed,
nsReflowStatus& aStatus);
nsFrameList& GetColGroups();
virtual nsIFrame* GetParentStyleContextFrame() const;
/**
* Get the "type" of the frame
*
* @see nsGkAtoms::tableFrame
*/
virtual nsIAtom* GetType() const;
#ifdef DEBUG
/** @see nsIFrame::GetFrameName */
NS_IMETHOD GetFrameName(nsAString& aResult) const;
#endif
/** return the width of the column at aColIndex */
virtual PRInt32 GetColumnWidth(PRInt32 aColIndex);
/** helper to get the cell spacing X style value */
virtual nscoord GetCellSpacingX();
/** helper to get the cell spacing Y style value */
virtual nscoord GetCellSpacingY();
virtual nscoord GetBaseline() const;
/** return the row span of a cell, taking into account row span magic at the bottom
* of a table. The row span equals the number of rows spanned by aCell starting at
* aStartRowIndex, and can be smaller if aStartRowIndex is greater than the row
* index in which aCell originates.
*
* @param aStartRowIndex the cell
* @param aCell the cell
*
* @return the row span, correcting for row spans that extend beyond the bottom
* of the table.
*/
virtual PRInt32 GetEffectiveRowSpan(PRInt32 aStartRowIndex,
const nsTableCellFrame& aCell) const;
virtual PRInt32 GetEffectiveRowSpan(const nsTableCellFrame& aCell,
nsCellMap* aCellMap = nsnull);
/** return the col span of a cell, taking into account col span magic at the edge
* of a table.
*
* @param aCell the cell
*
* @return the col span, correcting for col spans that extend beyond the edge
* of the table.
*/
virtual PRInt32 GetEffectiveColSpan(const nsTableCellFrame& aCell,
nsCellMap* aCellMap = nsnull) const;
/** indicate whether the row has more than one cell that either originates
* or is spanned from the rows above
*/
bool HasMoreThanOneCell(PRInt32 aRowIndex) const;
/** return the column frame associated with aColIndex
* returns nsnull if the col frame has not yet been allocated, or if
* aColIndex is out of range
*/
nsTableColFrame* GetColFrame(PRInt32 aColIndex) const;
/** Insert a col frame reference into the colframe cache and adapt the cellmap
* @param aColFrame - the column frame
* @param aColIndex - index where the column should be inserted into the
* colframe cache
*/
void InsertCol(nsTableColFrame& aColFrame,
PRInt32 aColIndex);
nsTableColGroupFrame* CreateAnonymousColGroupFrame(nsTableColGroupType aType);
PRInt32 DestroyAnonymousColFrames(PRInt32 aNumFrames);
// Append aNumColsToAdd anonymous col frames of type eColAnonymousCell to our
// last eColGroupAnonymousCell colgroup. If we have no such colgroup, then
// create one.
void AppendAnonymousColFrames(PRInt32 aNumColsToAdd);
// Append aNumColsToAdd anonymous col frames of type aColType to
// aColGroupFrame. If aAddToTable is true, also call AddColsToTable on the
// new cols.
void AppendAnonymousColFrames(nsTableColGroupFrame* aColGroupFrame,
PRInt32 aNumColsToAdd,
nsTableColType aColType,
bool aAddToTable);
void MatchCellMapToColCache(nsTableCellMap* aCellMap);
/** empty the column frame cache */
void ClearColCache();
void DidResizeColumns();
virtual void AppendCell(nsTableCellFrame& aCellFrame,
PRInt32 aRowIndex);
virtual void InsertCells(nsTArray<nsTableCellFrame*>& aCellFrames,
PRInt32 aRowIndex,
PRInt32 aColIndexBefore);
virtual void RemoveCell(nsTableCellFrame* aCellFrame,
PRInt32 aRowIndex);
void AppendRows(nsTableRowGroupFrame* aRowGroupFrame,
PRInt32 aRowIndex,
nsTArray<nsTableRowFrame*>& aRowFrames);
PRInt32 InsertRows(nsTableRowGroupFrame* aRowGroupFrame,
nsTArray<nsTableRowFrame*>& aFrames,
PRInt32 aRowIndex,
bool aConsiderSpans);
virtual void RemoveRows(nsTableRowFrame& aFirstRowFrame,
PRInt32 aNumRowsToRemove,
bool aConsiderSpans);
/** Insert multiple rowgroups into the table cellmap handling
* @param aRowGroups - iterator that iterates over the rowgroups to insert
*/
void InsertRowGroups(const nsFrameList::Slice& aRowGroups);
void InsertColGroups(PRInt32 aStartColIndex,
const nsFrameList::Slice& aColgroups);
virtual void RemoveCol(nsTableColGroupFrame* aColGroupFrame,
PRInt32 aColIndex,
bool aRemoveFromCache,
bool aRemoveFromCellMap);
NS_IMETHOD GetIndexByRowAndColumn(PRInt32 aRow, PRInt32 aColumn, PRInt32 *aIndex);
NS_IMETHOD GetRowAndColumnByIndex(PRInt32 aIndex, PRInt32 *aRow, PRInt32 *aColumn);
bool ColumnHasCellSpacingBefore(PRInt32 aColIndex) const;
bool HasPctCol() const;
void SetHasPctCol(bool aValue);
bool HasCellSpanningPctCol() const;
void SetHasCellSpanningPctCol(bool aValue);
/**
* To be called on a frame by its parent after setting its size/position and
* calling DidReflow (possibly via FinishReflowChild()). This can also be
* used for child frames which are not being reflowed but did have their size
* or position changed.
*
* @param aFrame The frame to invalidate
* @param aOrigRect The original rect of aFrame (before the change).
* @param aOrigVisualOverflow The original overflow rect of aFrame.
* @param aIsFirstReflow True if the size/position change is due to the
* first reflow of aFrame.
*/
static void InvalidateFrame(nsIFrame* aFrame,
const nsRect& aOrigRect,
const nsRect& aOrigVisualOverflow,
bool aIsFirstReflow);
virtual bool UpdateOverflow();
protected:
/** protected constructor.
* @see NewFrame
*/
nsTableFrame(nsStyleContext* aContext);
/** destructor, responsible for mColumnLayoutData */
virtual ~nsTableFrame();
void InitChildReflowState(nsHTMLReflowState& aReflowState);
/** implement abstract method on nsContainerFrame */
virtual PRIntn GetSkipSides() const;
public:
bool IsRowInserted() const;
void SetRowInserted(bool aValue);
protected:
// A helper function to reflow a header or footer with unconstrained height
// to see if it should be made repeatable and also to determine its desired
// height.
nsresult SetupHeaderFooterChild(const nsTableReflowState& aReflowState,
nsTableRowGroupFrame* aFrame,
nscoord* aDesiredHeight);
nsresult ReflowChildren(nsTableReflowState& aReflowState,
nsReflowStatus& aStatus,
nsIFrame*& aLastChildReflowed,
nsOverflowAreas& aOverflowAreas);
// This calls the col group and column reflow methods, which do two things:
// (1) set all the dimensions to 0
// (2) notify the table about colgroups or columns with hidden visibility
void ReflowColGroups(nsRenderingContext* aRenderingContext);
/** return the width of the table taking into account visibility collapse
* on columns and colgroups
* @param aBorderPadding the border and padding of the table
*/
nscoord GetCollapsedWidth(nsMargin aBorderPadding);
/** Adjust the table for visibility.collapse set on rowgroups, rows,
* colgroups and cols
* @param aDesiredSize the metrics of the table
* @param aBorderPadding the border and padding of the table
*/
void AdjustForCollapsingRowsCols(nsHTMLReflowMetrics& aDesiredSize,
nsMargin aBorderPadding);
nsITableLayoutStrategy* LayoutStrategy() const {
return static_cast<nsTableFrame*>(GetFirstInFlow())->
mTableLayoutStrategy;
}
// Helper for InsertFrames.
void HomogenousInsertFrames(ChildListID aListID,
nsIFrame* aPrevFrame,
nsFrameList& aFrameList);
private:
/* Handle a row that got inserted during reflow. aNewHeight is the
new height of the table after reflow. */
void ProcessRowInserted(nscoord aNewHeight);
// WIDTH AND HEIGHT CALCULATION
public:
// calculate the computed height of aFrame including its border and padding given
// its reflow state.
nscoord CalcBorderBoxHeight(const nsHTMLReflowState& aReflowState);
protected:
// update the desired height of this table taking into account the current
// reflow state, the table attributes and the content driven rowgroup heights
// this function can change the overflow area
void CalcDesiredHeight(const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredSize);
// The following is a helper for CalcDesiredHeight
void DistributeHeightToRows(const nsHTMLReflowState& aReflowState,
nscoord aAmount);
void PlaceChild(nsTableReflowState& aReflowState,
nsIFrame* aKidFrame,
nsHTMLReflowMetrics& aKidDesiredSize,
const nsRect& aOriginalKidRect,
const nsRect& aOriginalKidVisualOverflow);
void PlaceRepeatedFooter(nsTableReflowState& aReflowState,
nsTableRowGroupFrame *aTfoot,
nscoord aFooterHeight);
nsIFrame* GetFirstBodyRowGroupFrame();
public:
typedef nsAutoTArray<nsTableRowGroupFrame*, 8> RowGroupArray;
/**
* Push all our child frames from the aRowGroups array, in order, starting
* from the frame at aPushFrom to the end of the array. The frames are put on
* our overflow list or moved directly to our next-in-flow if one exists.
*/
protected:
void PushChildren(const RowGroupArray& aRowGroups, PRInt32 aPushFrom);
public:
// put the children frames in the display order (e.g. thead before tbodies
// before tfoot). This will handle calling GetRowGroupFrame() on the
// children, and not append nulls, so the array is guaranteed to contain
// nsTableRowGroupFrames. If there are multiple theads or tfoots, all but
// the first one are treated as tbodies instead.
void OrderRowGroups(RowGroupArray& aChildren,
nsTableRowGroupFrame** aHead = nsnull,
nsTableRowGroupFrame** aFoot = nsnull) const;
// Return the thead, if any
nsTableRowGroupFrame* GetTHead() const;
// Return the tfoot, if any
nsTableRowGroupFrame* GetTFoot() const;
// Returns true if there are any cells above the row at
// aRowIndex and spanning into the row at aRowIndex, the number of
// effective columns limits the search up to that column
bool RowIsSpannedInto(PRInt32 aRowIndex, PRInt32 aNumEffCols);
// Returns true if there is a cell originating in aRowIndex
// which spans into the next row, the number of effective
// columns limits the search up to that column
bool RowHasSpanningCells(PRInt32 aRowIndex, PRInt32 aNumEffCols);
protected:
bool HaveReflowedColGroups() const;
void SetHaveReflowedColGroups(bool aValue);
public:
bool IsBorderCollapse() const;
bool NeedToCalcBCBorders() const;
void SetNeedToCalcBCBorders(bool aValue);
bool NeedToCollapse() const;
void SetNeedToCollapse(bool aValue);
bool HasZeroColSpans() const;
void SetHasZeroColSpans(bool aValue);
bool NeedColSpanExpansion() const;
void SetNeedColSpanExpansion(bool aValue);
/** The GeometryDirty bit is similar to the NS_FRAME_IS_DIRTY frame
* state bit, which implies that all descendants are dirty. The
* GeometryDirty still implies that all the parts of the table are
* dirty, but resizing optimizations should still apply to the
* contents of the individual cells.
*/
void SetGeometryDirty() { mBits.mGeometryDirty = true; }
void ClearGeometryDirty() { mBits.mGeometryDirty = false; }
bool IsGeometryDirty() const { return mBits.mGeometryDirty; }
/** Get the cell map for this table frame. It is not always mCellMap.
* Only the firstInFlow has a legit cell map
*/
virtual nsTableCellMap* GetCellMap() const;
/** Iterate over the row groups and adjust the row indices of all rows
* whose index is >= aRowIndex.
* @param aRowIndex - start adjusting with this index
* @param aAdjustment - shift the row index by this amount
*/
void AdjustRowIndices(PRInt32 aRowIndex,
PRInt32 aAdjustment);
/** Reset the rowindices of all rows as they might have changed due to
* rowgroup reordering, exclude new row group frames that show in the
* reordering but are not yet inserted into the cellmap
* @param aRowGroupsToExclude - an iterator that will produce the row groups
* to exclude.
*/
void ResetRowIndices(const nsFrameList::Slice& aRowGroupsToExclude);
nsTArray<nsTableColFrame*>& GetColCache();
protected:
void SetBorderCollapse(bool aValue);
BCPropertyData* GetBCProperty(bool aCreateIfNecessary = false) const;
void SetFullBCDamageArea();
void CalcBCBorders();
void ExpandBCDamageArea(nsIntRect& aRect) const;
void SetColumnDimensions(nscoord aHeight,
const nsMargin& aReflowState);
PRInt32 CollectRows(nsIFrame* aFrame,
nsTArray<nsTableRowFrame*>& aCollection);
public: /* ----- Cell Map public methods ----- */
PRInt32 GetStartRowIndex(nsTableRowGroupFrame* aRowGroupFrame);
/** returns the number of rows in this table.
*/
PRInt32 GetRowCount () const
{
return GetCellMap()->GetRowCount();
}
/** returns the number of columns in this table after redundant columns have been removed
*/
PRInt32 GetEffectiveColCount() const;
/* return the col count including dead cols */
PRInt32 GetColCount () const
{
return GetCellMap()->GetColCount();
}
// return the last col index which isn't of type eColAnonymousCell
PRInt32 GetIndexOfLastRealCol();
/** returns true if table-layout:auto */
virtual bool IsAutoLayout();
/*---------------- nsITableLayout methods ------------------------*/
/** Get the cell and associated data for a table cell from the frame's cellmap */
NS_IMETHOD GetCellDataAt(PRInt32 aRowIndex, PRInt32 aColIndex,
nsIDOMElement* &aCell, //out params
PRInt32& aStartRowIndex, PRInt32& aStartColIndex,
PRInt32& aRowSpan, PRInt32& aColSpan,
PRInt32& aActualRowSpan, PRInt32& aActualColSpan,
bool& aIsSelected);
/** Get the number of rows and column for a table from the frame's cellmap
* Some rows may not have enough cells (the number returned is the maximum possible),
* which displays as a ragged-right edge table
*/
NS_IMETHOD GetTableSize(PRInt32& aRowCount, PRInt32& aColCount);
/*------------end of nsITableLayout methods -----------------------*/
public:
#ifdef DEBUG
void Dump(bool aDumpRows,
bool aDumpCols,
bool aDumpCellMap);
#endif
protected:
#ifdef DEBUG
void DumpRowGroup(nsIFrame* aChildFrame);
#endif
// DATA MEMBERS
nsAutoTArray<nsTableColFrame*, 8> mColFrames;
struct TableBits {
PRUint32 mHaveReflowedColGroups:1; // have the col groups gotten their initial reflow
PRUint32 mHasPctCol:1; // does any cell or col have a pct width
PRUint32 mCellSpansPctCol:1; // does any cell span a col with a pct width (or containing a cell with a pct width)
PRUint32 mIsBorderCollapse:1; // border collapsing model vs. separate model
PRUint32 mRowInserted:1;
PRUint32 mNeedToCalcBCBorders:1;
PRUint32 mGeometryDirty:1;
PRUint32 mLeftContBCBorder:8;
PRUint32 mNeedToCollapse:1; // rows, cols that have visibility:collapse need to be collapsed
PRUint32 mHasZeroColSpans:1;
PRUint32 mNeedColSpanExpansion:1;
PRUint32 mResizedColumns:1; // have we resized columns since last reflow?
} mBits;
nsTableCellMap* mCellMap; // maintains the relationships between rows, cols, and cells
nsITableLayoutStrategy* mTableLayoutStrategy;// the layout strategy for this frame
nsFrameList mColGroups; // the list of colgroup frames
};
inline bool nsTableFrame::IsRowGroup(PRInt32 aDisplayType) const
{
return bool((NS_STYLE_DISPLAY_TABLE_HEADER_GROUP == aDisplayType) ||
(NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP == aDisplayType) ||
(NS_STYLE_DISPLAY_TABLE_ROW_GROUP == aDisplayType));
}
inline void nsTableFrame::SetHaveReflowedColGroups(bool aValue)
{
mBits.mHaveReflowedColGroups = aValue;
}
inline bool nsTableFrame::HaveReflowedColGroups() const
{
return (bool)mBits.mHaveReflowedColGroups;
}
inline bool nsTableFrame::HasPctCol() const
{
return (bool)mBits.mHasPctCol;
}
inline void nsTableFrame::SetHasPctCol(bool aValue)
{
mBits.mHasPctCol = (unsigned)aValue;
}
inline bool nsTableFrame::HasCellSpanningPctCol() const
{
return (bool)mBits.mCellSpansPctCol;
}
inline void nsTableFrame::SetHasCellSpanningPctCol(bool aValue)
{
mBits.mCellSpansPctCol = (unsigned)aValue;
}
inline bool nsTableFrame::IsRowInserted() const
{
return (bool)mBits.mRowInserted;
}
inline void nsTableFrame::SetRowInserted(bool aValue)
{
mBits.mRowInserted = (unsigned)aValue;
}
inline void nsTableFrame::SetNeedToCollapse(bool aValue)
{
static_cast<nsTableFrame*>(GetFirstInFlow())->mBits.mNeedToCollapse = (unsigned)aValue;
}
inline bool nsTableFrame::NeedToCollapse() const
{
return (bool) static_cast<nsTableFrame*>(GetFirstInFlow())->mBits.mNeedToCollapse;
}
inline void nsTableFrame::SetHasZeroColSpans(bool aValue)
{
mBits.mHasZeroColSpans = (unsigned)aValue;
}
inline bool nsTableFrame::HasZeroColSpans() const
{
return (bool)mBits.mHasZeroColSpans;
}
inline void nsTableFrame::SetNeedColSpanExpansion(bool aValue)
{
mBits.mNeedColSpanExpansion = (unsigned)aValue;
}
inline bool nsTableFrame::NeedColSpanExpansion() const
{
return (bool)mBits.mNeedColSpanExpansion;
}
inline nsFrameList& nsTableFrame::GetColGroups()
{
return static_cast<nsTableFrame*>(GetFirstInFlow())->mColGroups;
}
inline nsTArray<nsTableColFrame*>& nsTableFrame::GetColCache()
{
return mColFrames;
}
inline bool nsTableFrame::IsBorderCollapse() const
{
return (bool)mBits.mIsBorderCollapse;
}
inline void nsTableFrame::SetBorderCollapse(bool aValue)
{
mBits.mIsBorderCollapse = aValue;
}
inline bool nsTableFrame::NeedToCalcBCBorders() const
{
return (bool)mBits.mNeedToCalcBCBorders;
}
inline void nsTableFrame::SetNeedToCalcBCBorders(bool aValue)
{
mBits.mNeedToCalcBCBorders = (unsigned)aValue;
}
inline nscoord
nsTableFrame::GetContinuousLeftBCBorderWidth() const
{
PRInt32 aPixelsToTwips = nsPresContext::AppUnitsPerCSSPixel();
return BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips, mBits.mLeftContBCBorder);
}
inline void nsTableFrame::SetContinuousLeftBCBorderWidth(nscoord aValue)
{
mBits.mLeftContBCBorder = (unsigned) aValue;
}
class nsTableIterator
{
public:
nsTableIterator(nsIFrame& aSource);
nsTableIterator(nsFrameList& aSource);
nsIFrame* First();
nsIFrame* Next();
bool IsLeftToRight();
PRInt32 Count();
protected:
void Init(nsIFrame* aFirstChild);
bool mLeftToRight;
nsIFrame* mFirstListChild;
nsIFrame* mFirstChild;
nsIFrame* mCurrentChild;
PRInt32 mCount;
};
#define ABORT0() \
{NS_ASSERTION(false, "CellIterator program error"); \
return;}
#define ABORT1(aReturn) \
{NS_ASSERTION(false, "CellIterator program error"); \
return aReturn;}
#endif