forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnsFrame.cpp
10213 lines (9062 loc) · 346 KB
/
nsFrame.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/. */
/* base class of all rendering objects */
#include "nsFrame.h"
#include <stdarg.h>
#include <algorithm>
#include "gfx2DGlue.h"
#include "gfxUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/PathHelpers.h"
#include "mozilla/Snprintf.h"
#include "nsCOMPtr.h"
#include "nsFrameList.h"
#include "nsPlaceholderFrame.h"
#include "nsIContent.h"
#include "nsContentUtils.h"
#include "nsIAtom.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsStyleContext.h"
#include "nsTableOuterFrame.h"
#include "nsView.h"
#include "nsViewManager.h"
#include "nsIScrollableFrame.h"
#include "nsPresContext.h"
#include "nsStyleConsts.h"
#include "nsIPresShell.h"
#include "mozilla/Logging.h"
#include "prprf.h"
#include "nsFrameManager.h"
#include "nsLayoutUtils.h"
#include "RestyleManager.h"
#include "nsIDOMNode.h"
#include "nsISelection.h"
#include "nsISelectionPrivate.h"
#include "nsFrameSelection.h"
#include "nsGkAtoms.h"
#include "nsHtml5Atoms.h"
#include "nsCSSAnonBoxes.h"
#include "nsFrameTraversal.h"
#include "nsRange.h"
#include "nsITextControlFrame.h"
#include "nsNameSpaceManager.h"
#include "nsIPercentBSizeObserver.h"
#include "nsStyleStructInlines.h"
#include "FrameLayerBuilder.h"
#include "nsBidiPresUtils.h"
#include "RubyUtils.h"
// For triple-click pref
#include "imgIContainer.h"
#include "imgIRequest.h"
#include "nsError.h"
#include "nsContainerFrame.h"
#include "nsBoxLayoutState.h"
#include "nsBlockFrame.h"
#include "nsDisplayList.h"
#include "nsSVGIntegrationUtils.h"
#include "nsSVGEffects.h"
#include "nsChangeHint.h"
#include "nsDeckFrame.h"
#include "nsSubDocumentFrame.h"
#include "SVGTextFrame.h"
#include "gfxContext.h"
#include "nsRenderingContext.h"
#include "nsAbsoluteContainingBlock.h"
#include "StickyScrollContainer.h"
#include "nsFontInflationData.h"
#include "gfxASurface.h"
#include "nsRegion.h"
#include "nsIFrameInlines.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/Preferences.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/css/ImageLoader.h"
#include "mozilla/gfx/Tools.h"
#include "nsPrintfCString.h"
#include "ActiveLayerTracker.h"
#include "nsITheme.h"
#include "nsThemeConstants.h"
using namespace mozilla;
using namespace mozilla::css;
using namespace mozilla::dom;
using namespace mozilla::gfx;
using namespace mozilla::layers;
using namespace mozilla::layout;
namespace mozilla {
namespace gfx {
class VRHMDInfo;
}
}
// Struct containing cached metrics for box-wrapped frames.
struct nsBoxLayoutMetrics
{
nsSize mPrefSize;
nsSize mMinSize;
nsSize mMaxSize;
nsSize mBlockMinSize;
nsSize mBlockPrefSize;
nscoord mBlockAscent;
nscoord mFlex;
nscoord mAscent;
nsSize mLastSize;
};
struct nsContentAndOffset
{
nsIContent* mContent;
int32_t mOffset;
};
// Some Misc #defines
#define SELECTION_DEBUG 0
#define FORCE_SELECTION_UPDATE 1
#define CALC_DEBUG 0
// This is faster than nsBidiPresUtils::IsFrameInParagraphDirection,
// because it uses the frame pointer passed in without drilling down to
// the leaf frame.
#define REVERSED_DIRECTION_FRAME(frame) \
(!IS_SAME_DIRECTION(NS_GET_EMBEDDING_LEVEL(frame), NS_GET_BASE_LEVEL(frame)))
#include "nsILineIterator.h"
//non Hack prototypes
#if 0
static void RefreshContentFrames(nsPresContext* aPresContext, nsIContent * aStartContent, nsIContent * aEndContent);
#endif
#include "prenv.h"
NS_DECLARE_FRAME_PROPERTY(BoxMetricsProperty, DeleteValue<nsBoxLayoutMetrics>)
static void
InitBoxMetrics(nsIFrame* aFrame, bool aClear)
{
FrameProperties props = aFrame->Properties();
if (aClear) {
props.Delete(BoxMetricsProperty());
}
nsBoxLayoutMetrics *metrics = new nsBoxLayoutMetrics();
props.Set(BoxMetricsProperty(), metrics);
static_cast<nsFrame*>(aFrame)->nsFrame::MarkIntrinsicISizesDirty();
metrics->mBlockAscent = 0;
metrics->mLastSize.SizeTo(0, 0);
}
static bool
IsBoxWrapped(const nsIFrame* aFrame)
{
return aFrame->GetParent() &&
aFrame->GetParent()->IsBoxFrame() &&
!aFrame->IsBoxFrame();
}
// Formerly the nsIFrameDebug interface
#ifdef DEBUG
static bool gShowFrameBorders = false;
void nsFrame::ShowFrameBorders(bool aEnable)
{
gShowFrameBorders = aEnable;
}
bool nsFrame::GetShowFrameBorders()
{
return gShowFrameBorders;
}
static bool gShowEventTargetFrameBorder = false;
void nsFrame::ShowEventTargetFrameBorder(bool aEnable)
{
gShowEventTargetFrameBorder = aEnable;
}
bool nsFrame::GetShowEventTargetFrameBorder()
{
return gShowEventTargetFrameBorder;
}
/**
* Note: the log module is created during library initialization which
* means that you cannot perform logging before then.
*/
static PRLogModuleInfo* gLogModule;
static PRLogModuleInfo* gStyleVerifyTreeLogModuleInfo;
static uint32_t gStyleVerifyTreeEnable = 0x55;
bool
nsFrame::GetVerifyStyleTreeEnable()
{
if (gStyleVerifyTreeEnable == 0x55) {
if (nullptr == gStyleVerifyTreeLogModuleInfo) {
gStyleVerifyTreeLogModuleInfo = PR_NewLogModule("styleverifytree");
gStyleVerifyTreeEnable = 0 != gStyleVerifyTreeLogModuleInfo->level;
}
}
return gStyleVerifyTreeEnable;
}
void
nsFrame::SetVerifyStyleTreeEnable(bool aEnabled)
{
gStyleVerifyTreeEnable = aEnabled;
}
PRLogModuleInfo*
nsFrame::GetLogModuleInfo()
{
if (nullptr == gLogModule) {
gLogModule = PR_NewLogModule("frame");
}
return gLogModule;
}
#endif
NS_DECLARE_FRAME_PROPERTY(AbsoluteContainingBlockProperty,
DeleteValue<nsAbsoluteContainingBlock>)
bool
nsIFrame::HasAbsolutelyPositionedChildren() const {
return IsAbsoluteContainer() && GetAbsoluteContainingBlock()->HasAbsoluteFrames();
}
nsAbsoluteContainingBlock*
nsIFrame::GetAbsoluteContainingBlock() const {
NS_ASSERTION(IsAbsoluteContainer(), "The frame is not marked as an abspos container correctly");
nsAbsoluteContainingBlock* absCB = static_cast<nsAbsoluteContainingBlock*>
(Properties().Get(AbsoluteContainingBlockProperty()));
NS_ASSERTION(absCB, "The frame is marked as an abspos container but doesn't have the property");
return absCB;
}
void
nsIFrame::MarkAsAbsoluteContainingBlock()
{
MOZ_ASSERT(GetStateBits() & NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN);
NS_ASSERTION(!Properties().Get(AbsoluteContainingBlockProperty()),
"Already has an abs-pos containing block property?");
NS_ASSERTION(!HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN),
"Already has NS_FRAME_HAS_ABSPOS_CHILDREN state bit?");
AddStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN);
Properties().Set(AbsoluteContainingBlockProperty(), new nsAbsoluteContainingBlock(GetAbsoluteListID()));
}
void
nsIFrame::MarkAsNotAbsoluteContainingBlock()
{
NS_ASSERTION(!HasAbsolutelyPositionedChildren(), "Think of the children!");
NS_ASSERTION(Properties().Get(AbsoluteContainingBlockProperty()),
"Should have an abs-pos containing block property");
NS_ASSERTION(HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN),
"Should have NS_FRAME_HAS_ABSPOS_CHILDREN state bit");
MOZ_ASSERT(HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN));
RemoveStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN);
Properties().Delete(AbsoluteContainingBlockProperty());
}
bool
nsIFrame::CheckAndClearPaintedState()
{
bool result = (GetStateBits() & NS_FRAME_PAINTED_THEBES);
RemoveStateBits(NS_FRAME_PAINTED_THEBES);
nsIFrame::ChildListIterator lists(this);
for (; !lists.IsDone(); lists.Next()) {
nsFrameList::Enumerator childFrames(lists.CurrentList());
for (; !childFrames.AtEnd(); childFrames.Next()) {
nsIFrame* child = childFrames.get();
if (child->CheckAndClearPaintedState()) {
result = true;
}
}
}
return result;
}
bool
nsIFrame::IsVisibleConsideringAncestors(uint32_t aFlags) const
{
if (!StyleVisibility()->IsVisible()) {
return false;
}
const nsIFrame* frame = this;
while (frame) {
nsView* view = frame->GetView();
if (view && view->GetVisibility() == nsViewVisibility_kHide)
return false;
nsIFrame* parent = frame->GetParent();
nsDeckFrame* deck = do_QueryFrame(parent);
if (deck) {
if (deck->GetSelectedBox() != frame)
return false;
}
if (parent) {
frame = parent;
} else {
parent = nsLayoutUtils::GetCrossDocParentFrame(frame);
if (!parent)
break;
if ((aFlags & nsIFrame::VISIBILITY_CROSS_CHROME_CONTENT_BOUNDARY) == 0 &&
parent->PresContext()->IsChrome() && !frame->PresContext()->IsChrome()) {
break;
}
if (!parent->StyleVisibility()->IsVisible())
return false;
frame = parent;
}
}
return true;
}
void
nsIFrame::FindCloserFrameForSelection(
nsPoint aPoint,
nsIFrame::FrameWithDistance* aCurrentBestFrame)
{
if (nsLayoutUtils::PointIsCloserToRect(aPoint, mRect,
aCurrentBestFrame->mXDistance,
aCurrentBestFrame->mYDistance)) {
aCurrentBestFrame->mFrame = this;
}
}
void
nsIFrame::ContentStatesChanged(mozilla::EventStates aStates)
{
}
void
NS_MergeReflowStatusInto(nsReflowStatus* aPrimary, nsReflowStatus aSecondary)
{
*aPrimary |= aSecondary &
(NS_FRAME_NOT_COMPLETE | NS_FRAME_OVERFLOW_INCOMPLETE |
NS_FRAME_TRUNCATED | NS_FRAME_REFLOW_NEXTINFLOW);
if (*aPrimary & NS_FRAME_NOT_COMPLETE) {
*aPrimary &= ~NS_FRAME_OVERFLOW_INCOMPLETE;
}
}
void
nsWeakFrame::Init(nsIFrame* aFrame)
{
Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr);
mFrame = aFrame;
if (mFrame) {
nsIPresShell* shell = mFrame->PresContext()->GetPresShell();
NS_WARN_IF_FALSE(shell, "Null PresShell in nsWeakFrame!");
if (shell) {
shell->AddWeakFrame(this);
} else {
mFrame = nullptr;
}
}
}
nsIFrame*
NS_NewEmptyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
{
return new (aPresShell) nsFrame(aContext);
}
nsFrame::nsFrame(nsStyleContext* aContext)
{
MOZ_COUNT_CTOR(nsFrame);
mState = NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY;
mStyleContext = aContext;
mStyleContext->AddRef();
#ifdef DEBUG
mStyleContext->FrameAddRef();
#endif
}
nsFrame::~nsFrame()
{
MOZ_COUNT_DTOR(nsFrame);
NS_IF_RELEASE(mContent);
#ifdef DEBUG
mStyleContext->FrameRelease();
#endif
mStyleContext->Release();
}
NS_IMPL_FRAMEARENA_HELPERS(nsFrame)
// Dummy operator delete. Will never be called, but must be defined
// to satisfy some C++ ABIs.
void
nsFrame::operator delete(void *, size_t)
{
NS_RUNTIMEABORT("nsFrame::operator delete should never be called");
}
NS_QUERYFRAME_HEAD(nsFrame)
NS_QUERYFRAME_ENTRY(nsIFrame)
NS_QUERYFRAME_TAIL_INHERITANCE_ROOT
/////////////////////////////////////////////////////////////////////////////
// nsIFrame
static bool
IsFontSizeInflationContainer(nsIFrame* aFrame,
const nsStyleDisplay* aStyleDisplay)
{
/*
* Font size inflation is built around the idea that we're inflating
* the fonts for a pan-and-zoom UI so that when the user scales up a
* block or other container to fill the width of the device, the fonts
* will be readable. To do this, we need to pick what counts as a
* container.
*
* From a code perspective, the only hard requirement is that frames
* that are line participants
* (nsIFrame::IsFrameOfType(nsIFrame::eLineParticipant)) are never
* containers, since line layout assumes that the inflation is
* consistent within a line.
*
* This is not an imposition, since we obviously want a bunch of text
* (possibly with inline elements) flowing within a block to count the
* block (or higher) as its container.
*
* We also want form controls, including the text in the anonymous
* content inside of them, to match each other and the text next to
* them, so they and their anonymous content should also not be a
* container.
*
* However, because we can't reliably compute sizes across XUL during
* reflow, any XUL frame with a XUL parent is always a container.
*
* There are contexts where it would be nice if some blocks didn't
* count as a container, so that, for example, an indented quotation
* didn't end up with a smaller font size. However, it's hard to
* distinguish these situations where we really do want the indented
* thing to count as a container, so we don't try, and blocks are
* always containers.
*/
// The root frame should always be an inflation container.
if (!aFrame->GetParent()) {
return true;
}
nsIContent *content = aFrame->GetContent();
nsIAtom* frameType = aFrame->GetType();
bool isInline = (aFrame->GetDisplay() == NS_STYLE_DISPLAY_INLINE ||
RubyUtils::IsRubyBox(frameType) ||
(aFrame->IsFloating() &&
frameType == nsGkAtoms::letterFrame) ||
// Given multiple frames for the same node, only the
// outer one should be considered a container.
// (Important, e.g., for nsSelectsAreaFrame.)
(aFrame->GetParent()->GetContent() == content) ||
(content && (content->IsAnyOfHTMLElements(nsGkAtoms::option,
nsGkAtoms::optgroup,
nsGkAtoms::select) ||
content->IsInNativeAnonymousSubtree()))) &&
!(aFrame->IsBoxFrame() && aFrame->GetParent()->IsBoxFrame());
NS_ASSERTION(!aFrame->IsFrameOfType(nsIFrame::eLineParticipant) ||
isInline ||
// br frames and mathml frames report being line
// participants even when their position or display is
// set
aFrame->GetType() == nsGkAtoms::brFrame ||
aFrame->IsFrameOfType(nsIFrame::eMathML),
"line participants must not be containers");
NS_ASSERTION(aFrame->GetType() != nsGkAtoms::bulletFrame || isInline,
"bullets should not be containers");
return !isInline;
}
void
nsFrame::Init(nsIContent* aContent,
nsContainerFrame* aParent,
nsIFrame* aPrevInFlow)
{
NS_PRECONDITION(!mContent, "Double-initing a frame?");
NS_ASSERTION(IsFrameOfType(eDEBUGAllFrames) &&
!IsFrameOfType(eDEBUGNoFrames),
"IsFrameOfType implementation that doesn't call base class");
mContent = aContent;
mParent = aParent;
if (aContent) {
NS_ADDREF(aContent);
}
if (aPrevInFlow) {
// Make sure the general flags bits are the same
nsFrameState state = aPrevInFlow->GetStateBits();
// Make bits that are currently off (see constructor) the same:
mState |= state & (NS_FRAME_INDEPENDENT_SELECTION |
NS_FRAME_PART_OF_IBSPLIT |
NS_FRAME_MAY_BE_TRANSFORMED |
NS_FRAME_MAY_HAVE_GENERATED_CONTENT |
NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN);
} else {
PresContext()->ConstructedFrame();
}
if (GetParent()) {
nsFrameState state = GetParent()->GetStateBits();
// Make bits that are currently off (see constructor) the same:
mState |= state & (NS_FRAME_INDEPENDENT_SELECTION |
NS_FRAME_GENERATED_CONTENT |
NS_FRAME_IS_SVG_TEXT |
NS_FRAME_IN_POPUP |
NS_FRAME_IS_NONDISPLAY);
}
const nsStyleDisplay *disp = StyleDisplay();
if (disp->HasTransform(this)) {
// The frame gets reconstructed if we toggle the -moz-transform
// property, so we can set this bit here and then ignore it.
mState |= NS_FRAME_MAY_BE_TRANSFORMED;
}
if (disp->mPosition == NS_STYLE_POSITION_STICKY &&
!aPrevInFlow &&
!(mState & NS_FRAME_IS_NONDISPLAY) &&
!disp->IsInnerTableStyle()) {
// Note that we only add first continuations, but we really only
// want to add first continuation-or-ib-split-siblings. But since we
// don't yet know if we're a later part of a block-in-inline split,
// we'll just add later members of a block-in-inline split here, and
// then StickyScrollContainer will remove them later.
// We don't currently support relative positioning of inner table
// elements (bug 35168), so exclude them from sticky positioning too.
StickyScrollContainer* ssc =
StickyScrollContainer::GetStickyScrollContainerForFrame(this);
if (ssc) {
ssc->AddFrame(this);
}
}
if (nsLayoutUtils::FontSizeInflationEnabled(PresContext()) || !GetParent()
#ifdef DEBUG
// We have assertions that check inflation invariants even when
// font size inflation is not enabled.
|| true
#endif
) {
if (IsFontSizeInflationContainer(this, disp)) {
AddStateBits(NS_FRAME_FONT_INFLATION_CONTAINER);
if (!GetParent() ||
// I'd use NS_FRAME_OUT_OF_FLOW, but it's not set yet.
disp->IsFloating(this) || disp->IsAbsolutelyPositioned(this)) {
AddStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT);
}
}
NS_ASSERTION(GetParent() ||
(GetStateBits() & NS_FRAME_FONT_INFLATION_CONTAINER),
"root frame should always be a container");
}
if (aContent && aContent->GetProperty(nsGkAtoms::vr_state) != nullptr) {
AddStateBits(NS_FRAME_HAS_VR_CONTENT);
}
DidSetStyleContext(nullptr);
if (::IsBoxWrapped(this))
::InitBoxMetrics(this, false);
}
void
nsFrame::DestroyFrom(nsIFrame* aDestructRoot)
{
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
"destroy called on frame while scripts not blocked");
NS_ASSERTION(!GetNextSibling() && !GetPrevSibling(),
"Frames should be removed before destruction.");
NS_ASSERTION(aDestructRoot, "Must specify destruct root");
MOZ_ASSERT(!HasAbsolutelyPositionedChildren());
nsSVGEffects::InvalidateDirectRenderingObservers(this);
if (StyleDisplay()->mPosition == NS_STYLE_POSITION_STICKY) {
StickyScrollContainer* ssc =
StickyScrollContainer::GetStickyScrollContainerForFrame(this);
if (ssc) {
ssc->RemoveFrame(this);
}
}
// Get the view pointer now before the frame properties disappear
// when we call NotifyDestroyingFrame()
nsView* view = GetView();
nsPresContext* presContext = PresContext();
nsIPresShell *shell = presContext->GetPresShell();
if (mState & NS_FRAME_OUT_OF_FLOW) {
nsPlaceholderFrame* placeholder =
shell->FrameManager()->GetPlaceholderFrameFor(this);
NS_ASSERTION(!placeholder || (aDestructRoot != this),
"Don't call Destroy() on OOFs, call Destroy() on the placeholder.");
NS_ASSERTION(!placeholder ||
nsLayoutUtils::IsProperAncestorFrame(aDestructRoot, placeholder),
"Placeholder relationship should have been torn down already; "
"this might mean we have a stray placeholder in the tree.");
if (placeholder) {
shell->FrameManager()->UnregisterPlaceholderFrame(placeholder);
placeholder->SetOutOfFlowFrame(nullptr);
}
}
// If we have any IB split siblings, clear their references to us.
// (Note: This has to happen before we call shell->NotifyDestroyingFrame,
// because that clears our Properties() table.)
if (mState & NS_FRAME_PART_OF_IBSPLIT) {
// Delete previous sibling's reference to me.
nsIFrame* prevSib = static_cast<nsIFrame*>
(Properties().Get(nsIFrame::IBSplitPrevSibling()));
if (prevSib) {
NS_WARN_IF_FALSE(this ==
prevSib->Properties().Get(nsIFrame::IBSplitSibling()),
"IB sibling chain is inconsistent");
prevSib->Properties().Delete(nsIFrame::IBSplitSibling());
}
// Delete next sibling's reference to me.
nsIFrame* nextSib = static_cast<nsIFrame*>
(Properties().Get(nsIFrame::IBSplitSibling()));
if (nextSib) {
NS_WARN_IF_FALSE(this ==
nextSib->Properties().Get(nsIFrame::IBSplitPrevSibling()),
"IB sibling chain is inconsistent");
nextSib->Properties().Delete(nsIFrame::IBSplitPrevSibling());
}
}
bool isPrimaryFrame = (mContent && mContent->GetPrimaryFrame() == this);
if (isPrimaryFrame) {
// This needs to happen before shell->NotifyDestroyingFrame because
// that clears our Properties() table.
ActiveLayerTracker::TransferActivityToContent(this, mContent);
// Unfortunately, we need to do this for all frames being reframed
// and not only those whose current style involves CSS transitions,
// because what matters is whether the new style (not the old)
// specifies CSS transitions.
RestyleManager::ReframingStyleContexts* rsc =
presContext->RestyleManager()->GetReframingStyleContexts();
if (rsc) {
rsc->Put(mContent, mStyleContext);
}
}
shell->NotifyDestroyingFrame(this);
if (mState & NS_FRAME_EXTERNAL_REFERENCE) {
shell->ClearFrameRefs(this);
}
if (view) {
// Break association between view and frame
view->SetFrame(nullptr);
// Destroy the view
view->Destroy();
}
// Make sure that our deleted frame can't be returned from GetPrimaryFrame()
if (isPrimaryFrame) {
mContent->SetPrimaryFrame(nullptr);
}
// Must retrieve the object ID before calling destructors, so the
// vtable is still valid.
//
// Note to future tweakers: having the method that returns the
// object size call the destructor will not avoid an indirect call;
// the compiler cannot devirtualize the call to the destructor even
// if it's from a method defined in the same class.
nsQueryFrame::FrameIID id = GetFrameId();
this->~nsFrame();
// Now that we're totally cleaned out, we need to add ourselves to
// the presshell's recycler.
shell->FreeFrame(id, this);
}
nsresult
nsFrame::GetOffsets(int32_t &aStart, int32_t &aEnd) const
{
aStart = 0;
aEnd = 0;
return NS_OK;
}
// Subclass hook for style post processing
/* virtual */ void
nsFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
{
if (IsSVGText()) {
SVGTextFrame* svgTextFrame = static_cast<SVGTextFrame*>(
nsLayoutUtils::GetClosestFrameOfType(this, nsGkAtoms::svgTextFrame));
nsIFrame* anonBlock = svgTextFrame->GetFirstPrincipalChild();
// Just as in SVGTextFrame::DidSetStyleContext, we need to ensure that
// any non-display SVGTextFrames get reflowed when a child text frame
// gets new style.
//
// Note that we must check NS_FRAME_FIRST_REFLOW on our SVGTextFrame's
// anonymous block frame rather than our self, since NS_FRAME_FIRST_REFLOW
// may be set on us if we're a new frame that has been inserted after the
// document's first reflow. (In which case this DidSetStyleContext call may
// be happening under frame construction under a Reflow() call.)
if (anonBlock && !(anonBlock->GetStateBits() & NS_FRAME_FIRST_REFLOW) &&
(svgTextFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) &&
!(svgTextFrame->GetStateBits() & NS_STATE_SVG_TEXT_IN_REFLOW)) {
svgTextFrame->ScheduleReflowSVGNonDisplayText();
}
}
ImageLoader* imageLoader = PresContext()->Document()->StyleImageLoader();
// If the old context had a background image image and new context
// does not have the same image, clear the image load notifier
// (which keeps the image loading, if it still is) for the frame.
// We want to do this conservatively because some frames paint their
// backgrounds from some other frame's style data, and we don't want
// to clear those notifiers unless we have to. (They'll be reset
// when we paint, although we could miss a notification in that
// interval.)
const nsStyleBackground *oldBG = aOldStyleContext ?
aOldStyleContext->StyleBackground() :
nullptr;
const nsStyleBackground *newBG = StyleBackground();
if (oldBG) {
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, oldBG) {
// If there is an image in oldBG that's not in newBG, drop it.
if (i >= newBG->mImageCount ||
!oldBG->mLayers[i].mImage.ImageDataEquals(newBG->mLayers[i].mImage)) {
const nsStyleImage& oldImage = oldBG->mLayers[i].mImage;
if (oldImage.GetType() != eStyleImageType_Image) {
continue;
}
imageLoader->DisassociateRequestFromFrame(oldImage.GetImageData(),
this);
}
}
}
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, newBG) {
// If there is an image in newBG that's not in oldBG, add it.
if (!oldBG || i >= oldBG->mImageCount ||
!newBG->mLayers[i].mImage.ImageDataEquals(oldBG->mLayers[i].mImage)) {
const nsStyleImage& newImage = newBG->mLayers[i].mImage;
if (newImage.GetType() != eStyleImageType_Image) {
continue;
}
imageLoader->AssociateRequestToFrame(newImage.GetImageData(), this);
}
}
if (aOldStyleContext) {
// If we detect a change on margin, padding or border, we store the old
// values on the frame itself between now and reflow, so if someone
// calls GetUsed(Margin|Border|Padding)() before the next reflow, we
// can give an accurate answer.
// We don't want to set the property if one already exists.
FrameProperties props = Properties();
nsMargin oldValue(0, 0, 0, 0);
nsMargin newValue(0, 0, 0, 0);
const nsStyleMargin* oldMargin = aOldStyleContext->PeekStyleMargin();
if (oldMargin && oldMargin->GetMargin(oldValue)) {
if ((!StyleMargin()->GetMargin(newValue) || oldValue != newValue) &&
!props.Get(UsedMarginProperty())) {
props.Set(UsedMarginProperty(), new nsMargin(oldValue));
}
}
const nsStylePadding* oldPadding = aOldStyleContext->PeekStylePadding();
if (oldPadding && oldPadding->GetPadding(oldValue)) {
if ((!StylePadding()->GetPadding(newValue) || oldValue != newValue) &&
!props.Get(UsedPaddingProperty())) {
props.Set(UsedPaddingProperty(), new nsMargin(oldValue));
}
}
const nsStyleBorder* oldBorder = aOldStyleContext->PeekStyleBorder();
if (oldBorder) {
oldValue = oldBorder->GetComputedBorder();
newValue = StyleBorder()->GetComputedBorder();
if (oldValue != newValue &&
!props.Get(UsedBorderProperty())) {
props.Set(UsedBorderProperty(), new nsMargin(oldValue));
}
}
}
imgIRequest *oldBorderImage = aOldStyleContext
? aOldStyleContext->StyleBorder()->GetBorderImageRequest()
: nullptr;
imgIRequest *newBorderImage = StyleBorder()->GetBorderImageRequest();
// FIXME (Bug 759996): The following is no longer true.
// For border-images, we can't be as conservative (we need to set the
// new loaders if there has been any change) since the CalcDifference
// call depended on the result of GetComputedBorder() and that result
// depends on whether the image has loaded, start the image load now
// so that we'll get notified when it completes loading and can do a
// restyle. Otherwise, the image might finish loading from the
// network before we start listening to its notifications, and then
// we'll never know that it's finished loading. Likewise, we want to
// do this for freshly-created frames to prevent a similar race if the
// image loads between reflow (which can depend on whether the image
// is loaded) and paint. We also don't really care about any callers
// who try to paint borders with a different style context, because
// they won't have the correct size for the border either.
if (oldBorderImage != newBorderImage) {
// stop and restart the image loading/notification
if (oldBorderImage) {
imageLoader->DisassociateRequestFromFrame(oldBorderImage, this);
}
if (newBorderImage) {
imageLoader->AssociateRequestToFrame(newBorderImage, this);
}
}
// If the page contains markup that overrides text direction, and
// does not contain any characters that would activate the Unicode
// bidi algorithm, we need to call |SetBidiEnabled| on the pres
// context before reflow starts. See bug 115921.
if (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
PresContext()->SetBidiEnabled();
}
}
// MSVC fails with link error "one or more multiply defined symbols found",
// gcc fails with "hidden symbol `nsIFrame::kPrincipalList' isn't defined"
// etc if they are not defined.
#ifndef _MSC_VER
// static nsIFrame constants; initialized in the header file.
const nsIFrame::ChildListID nsIFrame::kPrincipalList;
const nsIFrame::ChildListID nsIFrame::kAbsoluteList;
const nsIFrame::ChildListID nsIFrame::kBulletList;
const nsIFrame::ChildListID nsIFrame::kCaptionList;
const nsIFrame::ChildListID nsIFrame::kColGroupList;
const nsIFrame::ChildListID nsIFrame::kExcessOverflowContainersList;
const nsIFrame::ChildListID nsIFrame::kFixedList;
const nsIFrame::ChildListID nsIFrame::kFloatList;
const nsIFrame::ChildListID nsIFrame::kOverflowContainersList;
const nsIFrame::ChildListID nsIFrame::kOverflowList;
const nsIFrame::ChildListID nsIFrame::kOverflowOutOfFlowList;
const nsIFrame::ChildListID nsIFrame::kPopupList;
const nsIFrame::ChildListID nsIFrame::kPushedFloatsList;
const nsIFrame::ChildListID nsIFrame::kSelectPopupList;
const nsIFrame::ChildListID nsIFrame::kNoReflowPrincipalList;
#endif
/* virtual */ nsMargin
nsIFrame::GetUsedMargin() const
{
nsMargin margin(0, 0, 0, 0);
if (((mState & NS_FRAME_FIRST_REFLOW) &&
!(mState & NS_FRAME_IN_REFLOW)) ||
IsSVGText())
return margin;
nsMargin *m = static_cast<nsMargin*>
(Properties().Get(UsedMarginProperty()));
if (m) {
margin = *m;
} else {
DebugOnly<bool> hasMargin = StyleMargin()->GetMargin(margin);
NS_ASSERTION(hasMargin, "We should have a margin here! (out of memory?)");
}
return margin;
}
/* virtual */ nsMargin
nsIFrame::GetUsedBorder() const
{
nsMargin border(0, 0, 0, 0);
if (((mState & NS_FRAME_FIRST_REFLOW) &&
!(mState & NS_FRAME_IN_REFLOW)) ||
IsSVGText())
return border;
// Theme methods don't use const-ness.
nsIFrame *mutable_this = const_cast<nsIFrame*>(this);
const nsStyleDisplay *disp = StyleDisplay();
if (mutable_this->IsThemed(disp)) {
nsIntMargin result;
nsPresContext *presContext = PresContext();
presContext->GetTheme()->GetWidgetBorder(presContext->DeviceContext(),
mutable_this, disp->mAppearance,
&result);
border.left = presContext->DevPixelsToAppUnits(result.left);
border.top = presContext->DevPixelsToAppUnits(result.top);
border.right = presContext->DevPixelsToAppUnits(result.right);
border.bottom = presContext->DevPixelsToAppUnits(result.bottom);
return border;
}
nsMargin *b = static_cast<nsMargin*>
(Properties().Get(UsedBorderProperty()));
if (b) {
border = *b;
} else {
border = StyleBorder()->GetComputedBorder();
}
return border;
}
/* virtual */ nsMargin
nsIFrame::GetUsedPadding() const
{
nsMargin padding(0, 0, 0, 0);
if (((mState & NS_FRAME_FIRST_REFLOW) &&
!(mState & NS_FRAME_IN_REFLOW)) ||
IsSVGText())
return padding;
// Theme methods don't use const-ness.
nsIFrame *mutable_this = const_cast<nsIFrame*>(this);
const nsStyleDisplay *disp = StyleDisplay();
if (mutable_this->IsThemed(disp)) {
nsPresContext *presContext = PresContext();
nsIntMargin widget;
if (presContext->GetTheme()->GetWidgetPadding(presContext->DeviceContext(),
mutable_this,
disp->mAppearance,
&widget)) {
padding.top = presContext->DevPixelsToAppUnits(widget.top);
padding.right = presContext->DevPixelsToAppUnits(widget.right);
padding.bottom = presContext->DevPixelsToAppUnits(widget.bottom);
padding.left = presContext->DevPixelsToAppUnits(widget.left);
return padding;
}
}
nsMargin *p = static_cast<nsMargin*>
(Properties().Get(UsedPaddingProperty()));
if (p) {
padding = *p;
} else {
DebugOnly<bool> hasPadding = StylePadding()->GetPadding(padding);
NS_ASSERTION(hasPadding, "We should have padding here! (out of memory?)");
}
return padding;
}
nsIFrame::Sides
nsIFrame::GetSkipSides(const nsHTMLReflowState* aReflowState) const
{
if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak ==
NS_STYLE_BOX_DECORATION_BREAK_CLONE)) {
return Sides();
}
// Convert the logical skip sides to physical sides using the frame's
// writing mode
WritingMode writingMode = GetWritingMode();