forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnsBlockFrame.cpp
7206 lines (6457 loc) · 255 KB
/
nsBlockFrame.cpp
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
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
// vim:cindent:ts=2:et:sw=2:
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* rendering object for CSS display:block, inline-block, and list-item
* boxes, also used for various anonymous boxes
*/
#include "nsBlockFrame.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Util.h"
#include "nsCOMPtr.h"
#include "nsAbsoluteContainingBlock.h"
#include "nsBlockReflowContext.h"
#include "nsBlockReflowState.h"
#include "nsBulletFrame.h"
#include "nsLineBox.h"
#include "nsLineLayout.h"
#include "nsPlaceholderFrame.h"
#include "nsStyleConsts.h"
#include "nsFrameManager.h"
#include "nsPresContext.h"
#include "nsIPresShell.h"
#include "nsStyleContext.h"
#include "nsHTMLParts.h"
#include "nsGkAtoms.h"
#include "nsGenericHTMLElement.h"
#include "nsAttrValueInlines.h"
#include "prprf.h"
#include "nsFloatManager.h"
#include "prenv.h"
#include "plstr.h"
#include "nsError.h"
#include "nsAutoPtr.h"
#include "nsIScrollableFrame.h"
#include <algorithm>
#ifdef ACCESSIBILITY
#include "nsIDOMHTMLDocument.h"
#endif
#include "nsLayoutUtils.h"
#include "nsDisplayList.h"
#include "nsCSSAnonBoxes.h"
#include "nsCSSFrameConstructor.h"
#include "nsRenderingContext.h"
#include "TextOverflow.h"
#include "nsIFrameInlines.h"
#ifdef IBMBIDI
#include "nsBidiPresUtils.h"
#endif // IBMBIDI
static const int MIN_LINES_NEEDING_CURSOR = 20;
static const PRUnichar kDiscCharacter = 0x2022;
static const PRUnichar kCircleCharacter = 0x25e6;
static const PRUnichar kSquareCharacter = 0x25aa;
#define DISABLE_FLOAT_BREAKING_IN_COLUMNS
using namespace mozilla;
using namespace mozilla::css;
using namespace mozilla::layout;
#ifdef DEBUG
#include "nsBlockDebugFlags.h"
bool nsBlockFrame::gLamePaintMetrics;
bool nsBlockFrame::gLameReflowMetrics;
bool nsBlockFrame::gNoisy;
bool nsBlockFrame::gNoisyDamageRepair;
bool nsBlockFrame::gNoisyIntrinsic;
bool nsBlockFrame::gNoisyReflow;
bool nsBlockFrame::gReallyNoisyReflow;
bool nsBlockFrame::gNoisyFloatManager;
bool nsBlockFrame::gVerifyLines;
bool nsBlockFrame::gDisableResizeOpt;
int32_t nsBlockFrame::gNoiseIndent;
struct BlockDebugFlags {
const char* name;
bool* on;
};
static const BlockDebugFlags gFlags[] = {
{ "reflow", &nsBlockFrame::gNoisyReflow },
{ "really-noisy-reflow", &nsBlockFrame::gReallyNoisyReflow },
{ "intrinsic", &nsBlockFrame::gNoisyIntrinsic },
{ "float-manager", &nsBlockFrame::gNoisyFloatManager },
{ "verify-lines", &nsBlockFrame::gVerifyLines },
{ "damage-repair", &nsBlockFrame::gNoisyDamageRepair },
{ "lame-paint-metrics", &nsBlockFrame::gLamePaintMetrics },
{ "lame-reflow-metrics", &nsBlockFrame::gLameReflowMetrics },
{ "disable-resize-opt", &nsBlockFrame::gDisableResizeOpt },
};
#define NUM_DEBUG_FLAGS (sizeof(gFlags) / sizeof(gFlags[0]))
static void
ShowDebugFlags()
{
printf("Here are the available GECKO_BLOCK_DEBUG_FLAGS:\n");
const BlockDebugFlags* bdf = gFlags;
const BlockDebugFlags* end = gFlags + NUM_DEBUG_FLAGS;
for (; bdf < end; bdf++) {
printf(" %s\n", bdf->name);
}
printf("Note: GECKO_BLOCK_DEBUG_FLAGS is a comma separated list of flag\n");
printf("names (no whitespace)\n");
}
void
nsBlockFrame::InitDebugFlags()
{
static bool firstTime = true;
if (firstTime) {
firstTime = false;
char* flags = PR_GetEnv("GECKO_BLOCK_DEBUG_FLAGS");
if (flags) {
bool error = false;
for (;;) {
char* cm = PL_strchr(flags, ',');
if (cm) *cm = '\0';
bool found = false;
const BlockDebugFlags* bdf = gFlags;
const BlockDebugFlags* end = gFlags + NUM_DEBUG_FLAGS;
for (; bdf < end; bdf++) {
if (PL_strcasecmp(bdf->name, flags) == 0) {
*(bdf->on) = true;
printf("nsBlockFrame: setting %s debug flag on\n", bdf->name);
gNoisy = true;
found = true;
break;
}
}
if (!found) {
error = true;
}
if (!cm) break;
*cm = ',';
flags = cm + 1;
}
if (error) {
ShowDebugFlags();
}
}
}
}
#endif
// add in a sanity check for absurdly deep frame trees. See bug 42138
// can't just use IsFrameTreeTooDeep() because that method has side effects we don't want
#define MAX_DEPTH_FOR_LIST_RENUMBERING 200 // 200 open displayable tags is pretty unrealistic
//----------------------------------------------------------------------
// Debugging support code
#ifdef DEBUG
const char* nsBlockFrame::kReflowCommandType[] = {
"ContentChanged",
"StyleChanged",
"ReflowDirty",
"Timeout",
"UserDefined",
};
#endif
#ifdef REALLY_NOISY_FIRST_LINE
static void
DumpStyleGeneaology(nsIFrame* aFrame, const char* gap)
{
fputs(gap, stdout);
nsFrame::ListTag(stdout, aFrame);
printf(": ");
nsStyleContext* sc = aFrame->StyleContext();
while (nullptr != sc) {
nsStyleContext* psc;
printf("%p ", sc);
psc = sc->GetParent();
sc = psc;
}
printf("\n");
}
#endif
#ifdef REFLOW_STATUS_COVERAGE
static void
RecordReflowStatus(bool aChildIsBlock, nsReflowStatus aFrameReflowStatus)
{
static uint32_t record[2];
// 0: child-is-block
// 1: child-is-inline
int index = 0;
if (!aChildIsBlock) index |= 1;
// Compute new status
uint32_t newS = record[index];
if (NS_INLINE_IS_BREAK(aFrameReflowStatus)) {
if (NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus)) {
newS |= 1;
}
else if (NS_FRAME_IS_NOT_COMPLETE(aFrameReflowStatus)) {
newS |= 2;
}
else {
newS |= 4;
}
}
else if (NS_FRAME_IS_NOT_COMPLETE(aFrameReflowStatus)) {
newS |= 8;
}
else {
newS |= 16;
}
// Log updates to the status that yield different values
if (record[index] != newS) {
record[index] = newS;
printf("record(%d): %02x %02x\n", index, record[0], record[1]);
}
}
#endif
// Destructor function for the overflowLines frame property
static void
DestroyOverflowLines(void* aPropertyValue)
{
NS_ERROR("Overflow lines should never be destroyed by the FramePropertyTable");
}
NS_DECLARE_FRAME_PROPERTY(OverflowLinesProperty, DestroyOverflowLines)
NS_DECLARE_FRAME_PROPERTY_FRAMELIST(OverflowOutOfFlowsProperty)
NS_DECLARE_FRAME_PROPERTY_FRAMELIST(PushedFloatProperty)
NS_DECLARE_FRAME_PROPERTY_FRAMELIST(OutsideBulletProperty)
NS_DECLARE_FRAME_PROPERTY(InsideBulletProperty, nullptr)
//----------------------------------------------------------------------
nsIFrame*
NS_NewBlockFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, uint32_t aFlags)
{
nsBlockFrame* it = new (aPresShell) nsBlockFrame(aContext);
it->SetFlags(aFlags);
return it;
}
NS_IMPL_FRAMEARENA_HELPERS(nsBlockFrame)
nsBlockFrame::~nsBlockFrame()
{
}
void
nsBlockFrame::DestroyFrom(nsIFrame* aDestructRoot)
{
ClearLineCursor();
DestroyAbsoluteFrames(aDestructRoot);
mFloats.DestroyFramesFrom(aDestructRoot);
nsPresContext* presContext = PresContext();
nsIPresShell* shell = presContext->PresShell();
nsLineBox::DeleteLineList(presContext, mLines, aDestructRoot,
&mFrames);
FramePropertyTable* props = presContext->PropertyTable();
if (HasPushedFloats()) {
SafelyDestroyFrameListProp(aDestructRoot, shell, props,
PushedFloatProperty());
RemoveStateBits(NS_BLOCK_HAS_PUSHED_FLOATS);
}
// destroy overflow lines now
FrameLines* overflowLines = RemoveOverflowLines();
if (overflowLines) {
nsLineBox::DeleteLineList(presContext, overflowLines->mLines,
aDestructRoot, &overflowLines->mFrames);
delete overflowLines;
}
if (GetStateBits() & NS_BLOCK_HAS_OVERFLOW_OUT_OF_FLOWS) {
SafelyDestroyFrameListProp(aDestructRoot, shell, props,
OverflowOutOfFlowsProperty());
RemoveStateBits(NS_BLOCK_HAS_OVERFLOW_OUT_OF_FLOWS);
}
if (HasOutsideBullet()) {
SafelyDestroyFrameListProp(aDestructRoot, shell, props,
OutsideBulletProperty());
RemoveStateBits(NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET);
}
nsBlockFrameSuper::DestroyFrom(aDestructRoot);
}
/* virtual */ nsILineIterator*
nsBlockFrame::GetLineIterator()
{
nsLineIterator* it = new nsLineIterator;
if (!it)
return nullptr;
const nsStyleVisibility* visibility = StyleVisibility();
nsresult rv = it->Init(mLines, visibility->mDirection == NS_STYLE_DIRECTION_RTL);
if (NS_FAILED(rv)) {
delete it;
return nullptr;
}
return it;
}
NS_QUERYFRAME_HEAD(nsBlockFrame)
NS_QUERYFRAME_ENTRY(nsBlockFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrameSuper)
nsSplittableType
nsBlockFrame::GetSplittableType() const
{
return NS_FRAME_SPLITTABLE_NON_RECTANGULAR;
}
#ifdef DEBUG
void
nsBlockFrame::List(FILE* out, int32_t aIndent, uint32_t aFlags) const
{
ListGeneric(out, aIndent, aFlags);
fputs("<\n", out);
aIndent++;
// Output the lines
if (!mLines.empty()) {
const_line_iterator line = begin_lines(), line_end = end_lines();
for ( ; line != line_end; ++line) {
line->List(out, aIndent, aFlags);
}
}
// Output the overflow lines.
const FrameLines* overflowLines = GetOverflowLines();
if (overflowLines && !overflowLines->mLines.empty()) {
IndentBy(out, aIndent);
fprintf(out, "Overflow-lines %p/%p <\n", overflowLines, &overflowLines->mFrames);
const_line_iterator line = overflowLines->mLines.begin(),
line_end = overflowLines->mLines.end();
for ( ; line != line_end; ++line) {
line->List(out, aIndent + 1, aFlags);
}
IndentBy(out, aIndent);
fputs(">\n", out);
}
// skip the principal list - we printed the lines above
// skip the overflow list - we printed the overflow lines above
ChildListIterator lists(this);
ChildListIDs skip(kPrincipalList | kOverflowList);
for (; !lists.IsDone(); lists.Next()) {
if (skip.Contains(lists.CurrentID())) {
continue;
}
IndentBy(out, aIndent);
fprintf(out, "%s %p <\n", mozilla::layout::ChildListName(lists.CurrentID()),
&GetChildList(lists.CurrentID()));
nsFrameList::Enumerator childFrames(lists.CurrentList());
for (; !childFrames.AtEnd(); childFrames.Next()) {
nsIFrame* kid = childFrames.get();
kid->List(out, aIndent + 1, aFlags);
}
IndentBy(out, aIndent);
fputs(">\n", out);
}
aIndent--;
IndentBy(out, aIndent);
fputs(">\n", out);
}
NS_IMETHODIMP_(nsFrameState)
nsBlockFrame::GetDebugStateBits() const
{
// We don't want to include our cursor flag in the bits the
// regression tester looks at
return nsBlockFrameSuper::GetDebugStateBits() & ~NS_BLOCK_HAS_LINE_CURSOR;
}
NS_IMETHODIMP
nsBlockFrame::GetFrameName(nsAString& aResult) const
{
return MakeFrameName(NS_LITERAL_STRING("Block"), aResult);
}
#endif
nsIAtom*
nsBlockFrame::GetType() const
{
return nsGkAtoms::blockFrame;
}
void
nsBlockFrame::InvalidateFrame(uint32_t aDisplayItemKey)
{
if (IsSVGText()) {
NS_ASSERTION(GetParent()->GetType() == nsGkAtoms::svgTextFrame2,
"unexpected block frame in SVG text");
GetParent()->InvalidateFrame();
return;
}
nsBlockFrameSuper::InvalidateFrame(aDisplayItemKey);
}
void
nsBlockFrame::InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey)
{
if (IsSVGText()) {
NS_ASSERTION(GetParent()->GetType() == nsGkAtoms::svgTextFrame2,
"unexpected block frame in SVG text");
GetParent()->InvalidateFrame();
return;
}
nsBlockFrameSuper::InvalidateFrameWithRect(aRect, aDisplayItemKey);
}
nscoord
nsBlockFrame::GetBaseline() const
{
nscoord result;
if (nsLayoutUtils::GetLastLineBaseline(this, &result))
return result;
return nsFrame::GetBaseline();
}
nscoord
nsBlockFrame::GetCaretBaseline() const
{
nsRect contentRect = GetContentRect();
nsMargin bp = GetUsedBorderAndPadding();
if (!mLines.empty()) {
const_line_iterator line = begin_lines();
const nsLineBox* firstLine = line;
if (firstLine->GetChildCount()) {
return bp.top + firstLine->mFirstChild->GetCaretBaseline();
}
}
nsRefPtr<nsFontMetrics> fm;
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm), inflation);
return nsLayoutUtils::GetCenteredFontBaseline(fm, nsHTMLReflowState::
CalcLineHeight(StyleContext(), contentRect.height, inflation)) +
bp.top;
}
/////////////////////////////////////////////////////////////////////////////
// Child frame enumeration
const nsFrameList&
nsBlockFrame::GetChildList(ChildListID aListID) const
{
switch (aListID) {
case kPrincipalList:
return mFrames;
case kOverflowList: {
FrameLines* overflowLines = GetOverflowLines();
return overflowLines ? overflowLines->mFrames : nsFrameList::EmptyList();
}
case kFloatList:
return mFloats;
case kOverflowOutOfFlowList: {
const nsFrameList* list = GetOverflowOutOfFlows();
return list ? *list : nsFrameList::EmptyList();
}
case kPushedFloatsList: {
const nsFrameList* list = GetPushedFloats();
return list ? *list : nsFrameList::EmptyList();
}
case kBulletList: {
const nsFrameList* list = GetOutsideBulletList();
return list ? *list : nsFrameList::EmptyList();
}
default:
return nsContainerFrame::GetChildList(aListID);
}
}
void
nsBlockFrame::GetChildLists(nsTArray<ChildList>* aLists) const
{
nsContainerFrame::GetChildLists(aLists);
FrameLines* overflowLines = GetOverflowLines();
if (overflowLines) {
overflowLines->mFrames.AppendIfNonempty(aLists, kOverflowList);
}
const nsFrameList* list = GetOverflowOutOfFlows();
if (list) {
list->AppendIfNonempty(aLists, kOverflowOutOfFlowList);
}
mFloats.AppendIfNonempty(aLists, kFloatList);
list = GetOutsideBulletList();
if (list) {
list->AppendIfNonempty(aLists, kBulletList);
}
list = GetPushedFloats();
if (list) {
list->AppendIfNonempty(aLists, kPushedFloatsList);
}
}
/* virtual */ bool
nsBlockFrame::IsFloatContainingBlock() const
{
return true;
}
static void
ReparentFrame(nsIFrame* aFrame, nsIFrame* aOldParent, nsIFrame* aNewParent)
{
NS_ASSERTION(aOldParent == aFrame->GetParent(),
"Parent not consistent with expectations");
aFrame->SetParent(aNewParent);
// When pushing and pulling frames we need to check for whether any
// views need to be reparented
nsContainerFrame::ReparentFrameView(aFrame->PresContext(), aFrame,
aOldParent, aNewParent);
}
static void
ReparentFrames(nsFrameList& aFrameList, nsIFrame* aOldParent,
nsIFrame* aNewParent)
{
for (nsFrameList::Enumerator e(aFrameList); !e.AtEnd(); e.Next()) {
ReparentFrame(e.get(), aOldParent, aNewParent);
}
}
/**
* Remove the first line from aFromLines and adjust the associated frame list
* aFromFrames accordingly. The removed line is assigned to *aOutLine and
* a frame list with its frames is assigned to *aOutFrames, i.e. the frames
* that were extracted from the head of aFromFrames.
* aFromLines must contain at least one line, the line may be empty.
* @return true if aFromLines becomes empty
*/
static bool
RemoveFirstLine(nsLineList& aFromLines, nsFrameList& aFromFrames,
nsLineBox** aOutLine, nsFrameList* aOutFrames)
{
nsLineList_iterator removedLine = aFromLines.begin();
*aOutLine = removedLine;
nsLineList_iterator next = aFromLines.erase(removedLine);
bool isLastLine = next == aFromLines.end();
nsIFrame* lastFrame = isLastLine ? aFromFrames.LastChild()
: next->mFirstChild->GetPrevSibling();
nsFrameList::FrameLinkEnumerator linkToBreak(aFromFrames, lastFrame);
*aOutFrames = aFromFrames.ExtractHead(linkToBreak);
return isLastLine;
}
//////////////////////////////////////////////////////////////////////
// Reflow methods
/* virtual */ void
nsBlockFrame::MarkIntrinsicWidthsDirty()
{
nsBlockFrame* dirtyBlock = static_cast<nsBlockFrame*>(FirstContinuation());
dirtyBlock->mMinWidth = NS_INTRINSIC_WIDTH_UNKNOWN;
dirtyBlock->mPrefWidth = NS_INTRINSIC_WIDTH_UNKNOWN;
if (!(GetStateBits() & NS_BLOCK_NEEDS_BIDI_RESOLUTION)) {
for (nsIFrame* frame = dirtyBlock; frame;
frame = frame->GetNextContinuation()) {
frame->AddStateBits(NS_BLOCK_NEEDS_BIDI_RESOLUTION);
}
}
nsBlockFrameSuper::MarkIntrinsicWidthsDirty();
}
void
nsBlockFrame::CheckIntrinsicCacheAgainstShrinkWrapState()
{
nsPresContext *presContext = PresContext();
if (!nsLayoutUtils::FontSizeInflationEnabled(presContext)) {
return;
}
bool inflationEnabled =
!presContext->mInflationDisabledForShrinkWrap;
if (inflationEnabled !=
!!(GetStateBits() & NS_BLOCK_FRAME_INTRINSICS_INFLATED)) {
mMinWidth = NS_INTRINSIC_WIDTH_UNKNOWN;
mPrefWidth = NS_INTRINSIC_WIDTH_UNKNOWN;
if (inflationEnabled) {
AddStateBits(NS_BLOCK_FRAME_INTRINSICS_INFLATED);
} else {
RemoveStateBits(NS_BLOCK_FRAME_INTRINSICS_INFLATED);
}
}
}
/* virtual */ nscoord
nsBlockFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
{
nsIFrame* firstInFlow = FirstContinuation();
if (firstInFlow != this)
return firstInFlow->GetMinWidth(aRenderingContext);
DISPLAY_MIN_WIDTH(this, mMinWidth);
CheckIntrinsicCacheAgainstShrinkWrapState();
if (mMinWidth != NS_INTRINSIC_WIDTH_UNKNOWN)
return mMinWidth;
#ifdef DEBUG
if (gNoisyIntrinsic) {
IndentBy(stdout, gNoiseIndent);
ListTag(stdout);
printf(": GetMinWidth\n");
}
AutoNoisyIndenter indenter(gNoisyIntrinsic);
#endif
for (nsBlockFrame* curFrame = this; curFrame;
curFrame = static_cast<nsBlockFrame*>(curFrame->GetNextContinuation())) {
curFrame->LazyMarkLinesDirty();
}
if (GetStateBits() & NS_BLOCK_NEEDS_BIDI_RESOLUTION)
ResolveBidi();
InlineMinWidthData data;
for (nsBlockFrame* curFrame = this; curFrame;
curFrame = static_cast<nsBlockFrame*>(curFrame->GetNextContinuation())) {
for (line_iterator line = curFrame->begin_lines(), line_end = curFrame->end_lines();
line != line_end; ++line)
{
#ifdef DEBUG
if (gNoisyIntrinsic) {
IndentBy(stdout, gNoiseIndent);
printf("line (%s%s)\n",
line->IsBlock() ? "block" : "inline",
line->IsEmpty() ? ", empty" : "");
}
AutoNoisyIndenter lineindent(gNoisyIntrinsic);
#endif
if (line->IsBlock()) {
data.ForceBreak(aRenderingContext);
data.currentLine = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
line->mFirstChild, nsLayoutUtils::MIN_WIDTH);
data.ForceBreak(aRenderingContext);
} else {
if (!curFrame->GetPrevContinuation() &&
line == curFrame->begin_lines()) {
// Only add text-indent if it has no percentages; using a
// percentage basis of 0 unconditionally would give strange
// behavior for calc(10%-3px).
const nsStyleCoord &indent = StyleText()->mTextIndent;
if (indent.ConvertsToLength())
data.currentLine += nsRuleNode::ComputeCoordPercentCalc(indent, 0);
}
// XXX Bug NNNNNN Should probably handle percentage text-indent.
data.line = &line;
data.lineContainer = curFrame;
nsIFrame *kid = line->mFirstChild;
for (int32_t i = 0, i_end = line->GetChildCount(); i != i_end;
++i, kid = kid->GetNextSibling()) {
kid->AddInlineMinWidth(aRenderingContext, &data);
}
}
#ifdef DEBUG
if (gNoisyIntrinsic) {
IndentBy(stdout, gNoiseIndent);
printf("min: [prevLines=%d currentLine=%d]\n",
data.prevLines, data.currentLine);
}
#endif
}
}
data.ForceBreak(aRenderingContext);
mMinWidth = data.prevLines;
return mMinWidth;
}
/* virtual */ nscoord
nsBlockFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
{
nsIFrame* firstInFlow = FirstContinuation();
if (firstInFlow != this)
return firstInFlow->GetPrefWidth(aRenderingContext);
DISPLAY_PREF_WIDTH(this, mPrefWidth);
CheckIntrinsicCacheAgainstShrinkWrapState();
if (mPrefWidth != NS_INTRINSIC_WIDTH_UNKNOWN)
return mPrefWidth;
#ifdef DEBUG
if (gNoisyIntrinsic) {
IndentBy(stdout, gNoiseIndent);
ListTag(stdout);
printf(": GetPrefWidth\n");
}
AutoNoisyIndenter indenter(gNoisyIntrinsic);
#endif
for (nsBlockFrame* curFrame = this; curFrame;
curFrame = static_cast<nsBlockFrame*>(curFrame->GetNextContinuation())) {
curFrame->LazyMarkLinesDirty();
}
if (GetStateBits() & NS_BLOCK_NEEDS_BIDI_RESOLUTION)
ResolveBidi();
InlinePrefWidthData data;
for (nsBlockFrame* curFrame = this; curFrame;
curFrame = static_cast<nsBlockFrame*>(curFrame->GetNextContinuation())) {
for (line_iterator line = curFrame->begin_lines(), line_end = curFrame->end_lines();
line != line_end; ++line)
{
#ifdef DEBUG
if (gNoisyIntrinsic) {
IndentBy(stdout, gNoiseIndent);
printf("line (%s%s)\n",
line->IsBlock() ? "block" : "inline",
line->IsEmpty() ? ", empty" : "");
}
AutoNoisyIndenter lineindent(gNoisyIntrinsic);
#endif
if (line->IsBlock()) {
data.ForceBreak(aRenderingContext);
data.currentLine = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
line->mFirstChild, nsLayoutUtils::PREF_WIDTH);
data.ForceBreak(aRenderingContext);
} else {
if (!curFrame->GetPrevContinuation() &&
line == curFrame->begin_lines()) {
// Only add text-indent if it has no percentages; using a
// percentage basis of 0 unconditionally would give strange
// behavior for calc(10%-3px).
const nsStyleCoord &indent = StyleText()->mTextIndent;
if (indent.ConvertsToLength())
data.currentLine += nsRuleNode::ComputeCoordPercentCalc(indent, 0);
}
// XXX Bug NNNNNN Should probably handle percentage text-indent.
data.line = &line;
data.lineContainer = curFrame;
nsIFrame *kid = line->mFirstChild;
for (int32_t i = 0, i_end = line->GetChildCount(); i != i_end;
++i, kid = kid->GetNextSibling()) {
kid->AddInlinePrefWidth(aRenderingContext, &data);
}
}
#ifdef DEBUG
if (gNoisyIntrinsic) {
IndentBy(stdout, gNoiseIndent);
printf("pref: [prevLines=%d currentLine=%d]\n",
data.prevLines, data.currentLine);
}
#endif
}
}
data.ForceBreak(aRenderingContext);
mPrefWidth = data.prevLines;
return mPrefWidth;
}
nsRect
nsBlockFrame::ComputeTightBounds(gfxContext* aContext) const
{
// be conservative
if (StyleContext()->HasTextDecorationLines()) {
return GetVisualOverflowRect();
}
return ComputeSimpleTightBounds(aContext);
}
static bool
AvailableSpaceShrunk(const nsRect& aOldAvailableSpace,
const nsRect& aNewAvailableSpace)
{
if (aNewAvailableSpace.width == 0) {
// Positions are not significant if the width is zero.
return aOldAvailableSpace.width != 0;
}
NS_ASSERTION(aOldAvailableSpace.x <= aNewAvailableSpace.x &&
aOldAvailableSpace.XMost() >= aNewAvailableSpace.XMost(),
"available space should never grow");
return aOldAvailableSpace.width != aNewAvailableSpace.width;
}
static nsSize
CalculateContainingBlockSizeForAbsolutes(const nsHTMLReflowState& aReflowState,
nsSize aFrameSize)
{
// The issue here is that for a 'height' of 'auto' the reflow state
// code won't know how to calculate the containing block height
// because it's calculated bottom up. So we use our own computed
// size as the dimensions.
nsIFrame* frame = aReflowState.frame;
nsSize cbSize(aFrameSize);
// Containing block is relative to the padding edge
const nsMargin& border =
aReflowState.mComputedBorderPadding - aReflowState.mComputedPadding;
cbSize.width -= border.LeftRight();
cbSize.height -= border.TopBottom();
if (frame->GetParent()->GetContent() == frame->GetContent() &&
frame->GetParent()->GetType() != nsGkAtoms::canvasFrame) {
// We are a wrapped frame for the content (and the wrapper is not the
// canvas frame, whose size is not meaningful here).
// Use the container's dimensions, if they have been precomputed.
// XXX This is a hack! We really should be waiting until the outermost
// frame is fully reflowed and using the resulting dimensions, even
// if they're intrinsic.
// In fact we should be attaching absolute children to the outermost
// frame and not always sticking them in block frames.
// First, find the reflow state for the outermost frame for this
// content.
const nsHTMLReflowState* aLastRS = &aReflowState;
const nsHTMLReflowState* lastButOneRS = &aReflowState;
while (aLastRS->parentReflowState &&
aLastRS->parentReflowState->frame->GetContent() == frame->GetContent()) {
lastButOneRS = aLastRS;
aLastRS = aLastRS->parentReflowState;
}
if (aLastRS != &aReflowState) {
// Scrollbars need to be specifically excluded, if present, because they are outside the
// padding-edge. We need better APIs for getting the various boxes from a frame.
nsIScrollableFrame* scrollFrame = do_QueryFrame(aLastRS->frame);
nsMargin scrollbars(0,0,0,0);
if (scrollFrame) {
scrollbars =
scrollFrame->GetDesiredScrollbarSizes(aLastRS->frame->PresContext(),
aLastRS->rendContext);
if (!lastButOneRS->mFlags.mAssumingHScrollbar) {
scrollbars.top = scrollbars.bottom = 0;
}
if (!lastButOneRS->mFlags.mAssumingVScrollbar) {
scrollbars.left = scrollbars.right = 0;
}
}
// We found a reflow state for the outermost wrapping frame, so use
// its computed metrics if available
if (aLastRS->ComputedWidth() != NS_UNCONSTRAINEDSIZE) {
cbSize.width = std::max(0,
aLastRS->ComputedWidth() + aLastRS->mComputedPadding.LeftRight() - scrollbars.LeftRight());
}
if (aLastRS->ComputedHeight() != NS_UNCONSTRAINEDSIZE) {
cbSize.height = std::max(0,
aLastRS->ComputedHeight() + aLastRS->mComputedPadding.TopBottom() - scrollbars.TopBottom());
}
}
}
return cbSize;
}
NS_IMETHODIMP
nsBlockFrame::Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aMetrics,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
DO_GLOBAL_REFLOW_COUNT("nsBlockFrame");
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
#ifdef DEBUG
if (gNoisyReflow) {
IndentBy(stdout, gNoiseIndent);
ListTag(stdout);
printf(": begin reflow availSize=%d,%d computedSize=%d,%d\n",
aReflowState.availableWidth, aReflowState.availableHeight,
aReflowState.ComputedWidth(), aReflowState.ComputedHeight());
}
AutoNoisyIndenter indent(gNoisy);
PRTime start = 0; // Initialize these variablies to silence the compiler.
int32_t ctc = 0; // We only use these if they are set (gLameReflowMetrics).
if (gLameReflowMetrics) {
start = PR_Now();
ctc = nsLineBox::GetCtorCount();
}
#endif
const nsHTMLReflowState *reflowState = &aReflowState;
nscoord consumedHeight = GetConsumedHeight();
nscoord effectiveComputedHeight = GetEffectiveComputedHeight(aReflowState,
consumedHeight);
Maybe<nsHTMLReflowState> mutableReflowState;
// If we have non-auto height, we're clipping our kids and we fit,
// make sure our kids fit too.
if (aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE &&
aReflowState.ComputedHeight() != NS_AUTOHEIGHT &&
ShouldApplyOverflowClipping(this, aReflowState.mStyleDisplay)) {
nsMargin heightExtras = aReflowState.mComputedBorderPadding;
if (GetSkipSides() & NS_SIDE_TOP) {
heightExtras.top = 0;
} else {
// Bottom margin never causes us to create continuations, so we
// don't need to worry about whether it fits in its entirety.
heightExtras.top += aReflowState.mComputedMargin.top;
}
if (effectiveComputedHeight + heightExtras.TopBottom() <=
aReflowState.availableHeight) {
mutableReflowState.construct(aReflowState);
mutableReflowState.ref().availableHeight = NS_UNCONSTRAINEDSIZE;
reflowState = mutableReflowState.addr();
}
}
// See comment below about oldSize. Use *only* for the
// abs-pos-containing-block-size-change optimization!
nsSize oldSize = GetSize();
// Should we create a float manager?
nsAutoFloatManager autoFloatManager(const_cast<nsHTMLReflowState&>(*reflowState));
// XXXldb If we start storing the float manager in the frame rather
// than keeping it around only during reflow then we should create it
// only when there are actually floats to manage. Otherwise things
// like tables will gain significant bloat.
bool needFloatManager = nsBlockFrame::BlockNeedsFloatManager(this);
if (needFloatManager)
autoFloatManager.CreateFloatManager(aPresContext);
// OK, some lines may be reflowed. Blow away any saved line cursor
// because we may invalidate the nondecreasing
// overflowArea.VisualOverflow().y/yMost invariant, and we may even
// delete the line with the line cursor.
ClearLineCursor();
if (IsFrameTreeTooDeep(*reflowState, aMetrics, aStatus)) {
return NS_OK;
}
bool topMarginRoot, bottomMarginRoot;
IsMarginRoot(&topMarginRoot, &bottomMarginRoot);
// Cache the consumed height in the block reflow state so that we don't have
// to continually recompute it.
nsBlockReflowState state(*reflowState, aPresContext, this,
topMarginRoot, bottomMarginRoot, needFloatManager,
consumedHeight);
#ifdef IBMBIDI
if (GetStateBits() & NS_BLOCK_NEEDS_BIDI_RESOLUTION)
static_cast<nsBlockFrame*>(FirstContinuation())->ResolveBidi();
#endif // IBMBIDI
if (RenumberLists(aPresContext)) {
AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN);
}
nsresult rv = NS_OK;
// ALWAYS drain overflow. We never want to leave the previnflow's
// overflow lines hanging around; block reflow depends on the
// overflow line lists being cleared out between reflow passes.
DrainOverflowLines();
// Handle paginated overflow (see nsContainerFrame.h)
nsOverflowAreas ocBounds;
nsReflowStatus ocStatus = NS_FRAME_COMPLETE;
if (GetPrevInFlow()) {
ReflowOverflowContainerChildren(aPresContext, *reflowState, ocBounds, 0,
ocStatus);
}
// Now that we're done cleaning up our overflow container lists, we can
// give |state| its nsOverflowContinuationTracker.
nsOverflowContinuationTracker tracker(aPresContext, this, false);
state.mOverflowTracker = &tracker;
// Drain & handle pushed floats
DrainPushedFloats(state);
nsOverflowAreas fcBounds;
nsReflowStatus fcStatus = NS_FRAME_COMPLETE;
ReflowPushedFloats(state, fcBounds, fcStatus);
// If we're not dirty (which means we'll mark everything dirty later)
// and our width has changed, mark the lines dirty that we need to
// mark dirty for a resize reflow.
if (!(GetStateBits() & NS_FRAME_IS_DIRTY) && reflowState->mFlags.mHResize) {
PrepareResizeReflow(state);
}
LazyMarkLinesDirty();