Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp
Warning:line 8630, column 7
Value stored to 'result' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_layout_generic2.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/generic -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/generic -resource-dir /usr/lib/llvm-18/lib/clang/18 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/layout/generic -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/generic -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/layout/base -I /var/lib/jenkins/workspace/firefox-scan-build/layout/forms -I /var/lib/jenkins/workspace/firefox-scan-build/layout/painting -I /var/lib/jenkins/workspace/firefox-scan-build/layout/style -I /var/lib/jenkins/workspace/firefox-scan-build/layout/tables -I /var/lib/jenkins/workspace/firefox-scan-build/layout/xul -I /var/lib/jenkins/workspace/firefox-scan-build/docshell/base -I /var/lib/jenkins/workspace/firefox-scan-build/dom/base -I /var/lib/jenkins/workspace/firefox-scan-build/dom/html -I /var/lib/jenkins/workspace/firefox-scan-build/dom/xul -I /var/lib/jenkins/workspace/firefox-scan-build/gfx/cairo/cairo/src -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/cloudproviders -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/gtk-3.0/unix-print -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-error=deprecated -Wno-error=deprecated-anon-enum-enum-conversion -Wno-error=deprecated-enum-enum-conversion -Wno-error=deprecated-pragma -Wno-error=deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2023-12-14-042937-14912-1 -x c++ Unified_cpp_layout_generic2.cpp
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7/* base class of all rendering objects */
8
9#include "nsIFrame.h"
10
11#include <stdarg.h>
12#include <algorithm>
13
14#include "gfx2DGlue.h"
15#include "gfxUtils.h"
16#include "mozilla/Attributes.h"
17#include "mozilla/ComputedStyle.h"
18#include "mozilla/DebugOnly.h"
19#include "mozilla/DisplayPortUtils.h"
20#include "mozilla/EventForwards.h"
21#include "mozilla/dom/CSSAnimation.h"
22#include "mozilla/dom/CSSTransition.h"
23#include "mozilla/dom/ContentVisibilityAutoStateChangeEvent.h"
24#include "mozilla/dom/DocumentInlines.h"
25#include "mozilla/dom/AncestorIterator.h"
26#include "mozilla/dom/ElementInlines.h"
27#include "mozilla/dom/ImageTracker.h"
28#include "mozilla/dom/Selection.h"
29#include "mozilla/gfx/2D.h"
30#include "mozilla/gfx/PathHelpers.h"
31#include "mozilla/IntegerRange.h"
32#include "mozilla/intl/BidiEmbeddingLevel.h"
33#include "mozilla/Maybe.h"
34#include "mozilla/PresShell.h"
35#include "mozilla/PresShellInlines.h"
36#include "mozilla/ResultExtensions.h"
37#include "mozilla/Sprintf.h"
38#include "mozilla/StaticAnalysisFunctions.h"
39#include "mozilla/StaticPrefs_layout.h"
40#include "mozilla/StaticPrefs_print.h"
41#include "mozilla/StaticPrefs_ui.h"
42#include "mozilla/SVGMaskFrame.h"
43#include "mozilla/SVGObserverUtils.h"
44#include "mozilla/SVGTextFrame.h"
45#include "mozilla/SVGIntegrationUtils.h"
46#include "mozilla/SVGUtils.h"
47#include "mozilla/TextControlElement.h"
48#include "mozilla/ToString.h"
49#include "mozilla/Try.h"
50#include "mozilla/ViewportUtils.h"
51
52#include "nsCOMPtr.h"
53#include "nsFieldSetFrame.h"
54#include "nsFlexContainerFrame.h"
55#include "nsFocusManager.h"
56#include "nsFrameList.h"
57#include "nsPlaceholderFrame.h"
58#include "nsIBaseWindow.h"
59#include "nsIContent.h"
60#include "nsIContentInlines.h"
61#include "nsContentUtils.h"
62#include "nsCSSFrameConstructor.h"
63#include "nsCSSProps.h"
64#include "nsCSSPseudoElements.h"
65#include "nsCSSRendering.h"
66#include "nsAtom.h"
67#include "nsString.h"
68#include "nsReadableUtils.h"
69#include "nsTableWrapperFrame.h"
70#include "nsView.h"
71#include "nsViewManager.h"
72#include "nsIScrollableFrame.h"
73#include "nsPresContext.h"
74#include "nsPresContextInlines.h"
75#include "nsStyleConsts.h"
76#include "mozilla/Logging.h"
77#include "nsLayoutUtils.h"
78#include "LayoutLogging.h"
79#include "mozilla/RestyleManager.h"
80#include "nsImageFrame.h"
81#include "nsInlineFrame.h"
82#include "nsFrameSelection.h"
83#include "nsGkAtoms.h"
84#include "nsGridContainerFrame.h"
85#include "nsGfxScrollFrame.h"
86#include "nsCSSAnonBoxes.h"
87#include "nsCanvasFrame.h"
88
89#include "nsFieldSetFrame.h"
90#include "nsFrameTraversal.h"
91#include "nsRange.h"
92#include "nsITextControlFrame.h"
93#include "nsNameSpaceManager.h"
94#include "nsIPercentBSizeObserver.h"
95#include "nsStyleStructInlines.h"
96
97#include "nsBidiPresUtils.h"
98#include "RubyUtils.h"
99#include "TextOverflow.h"
100#include "nsAnimationManager.h"
101
102// For triple-click pref
103#include "imgIRequest.h"
104#include "nsError.h"
105#include "nsContainerFrame.h"
106#include "nsBlockFrame.h"
107#include "nsDisplayList.h"
108#include "nsChangeHint.h"
109#include "nsSubDocumentFrame.h"
110#include "RetainedDisplayListBuilder.h"
111
112#include "gfxContext.h"
113#include "nsAbsoluteContainingBlock.h"
114#include "ScrollSnap.h"
115#include "StickyScrollContainer.h"
116#include "nsFontInflationData.h"
117#include "nsRegion.h"
118#include "nsIFrameInlines.h"
119#include "nsStyleChangeList.h"
120#include "nsWindowSizes.h"
121
122#ifdef ACCESSIBILITY1
123# include "nsAccessibilityService.h"
124#endif
125
126#include "mozilla/AsyncEventDispatcher.h"
127#include "mozilla/CSSClipPathInstance.h"
128#include "mozilla/EffectCompositor.h"
129#include "mozilla/EffectSet.h"
130#include "mozilla/EventListenerManager.h"
131#include "mozilla/EventStateManager.h"
132#include "mozilla/Preferences.h"
133#include "mozilla/LookAndFeel.h"
134#include "mozilla/MouseEvents.h"
135#include "mozilla/ServoStyleSet.h"
136#include "mozilla/ServoStyleSetInlines.h"
137#include "mozilla/css/ImageLoader.h"
138#include "mozilla/dom/HTMLBodyElement.h"
139#include "mozilla/dom/SVGPathData.h"
140#include "mozilla/dom/TouchEvent.h"
141#include "mozilla/gfx/Tools.h"
142#include "mozilla/layers/WebRenderUserData.h"
143#include "mozilla/layout/ScrollAnchorContainer.h"
144#include "nsPrintfCString.h"
145#include "ActiveLayerTracker.h"
146
147#include "nsITheme.h"
148
149using namespace mozilla;
150using namespace mozilla::css;
151using namespace mozilla::dom;
152using namespace mozilla::gfx;
153using namespace mozilla::layers;
154using namespace mozilla::layout;
155typedef nsAbsoluteContainingBlock::AbsPosReflowFlags AbsPosReflowFlags;
156using nsStyleTransformMatrix::TransformReferenceBox;
157
158nsIFrame* nsILineIterator::LineInfo::GetLastFrameOnLine() const {
159 if (!mNumFramesOnLine) {
160 return nullptr; // empty line, not illegal
161 }
162 MOZ_ASSERT(mFirstFrameOnLine)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mFirstFrameOnLine)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mFirstFrameOnLine))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("mFirstFrameOnLine"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 162); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mFirstFrameOnLine"
")"); do { *((volatile int*)__null) = 162; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
163 nsIFrame* maybeLastFrame = mFirstFrameOnLine;
164 for ([[maybe_unused]] int32_t i : IntegerRange(mNumFramesOnLine - 1)) {
165 maybeLastFrame = maybeLastFrame->GetNextSibling();
166 if (NS_WARN_IF(!maybeLastFrame)NS_warn_if_impl(!maybeLastFrame, "!maybeLastFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 166)
) {
167 return nullptr;
168 }
169 }
170 return maybeLastFrame;
171}
172
173#ifdef HAVE_64BIT_BUILD1
174static_assert(sizeof(nsIFrame) == 120, "nsIFrame should remain small");
175#else
176static_assert(sizeof(void*) == 4, "Odd build config?");
177// FIXME(emilio): Investigate why win32 and android-arm32 have bigger sizes (80)
178// than Linux32 (76).
179static_assert(sizeof(nsIFrame) <= 80, "nsIFrame should remain small");
180#endif
181
182const mozilla::LayoutFrameType nsIFrame::sLayoutFrameTypes[kFrameClassCount] = {
183#define FRAME_ID(class_, type_, ...) mozilla::LayoutFrameType::type_,
184#define ABSTRACT_FRAME_ID(...)
185#include "mozilla/FrameIdList.h"
186#undef FRAME_ID
187#undef ABSTRACT_FRAME_ID
188};
189
190const nsIFrame::ClassFlags nsIFrame::sLayoutFrameClassFlags[kFrameClassCount] =
191 {
192#define FRAME_ID(class_, type_, flags_, ...) flags_,
193#define ABSTRACT_FRAME_ID(...)
194#include "mozilla/FrameIdList.h"
195#undef FRAME_ID
196#undef ABSTRACT_FRAME_ID
197};
198
199std::ostream& operator<<(std::ostream& aStream, const nsDirection& aDirection) {
200 return aStream << (aDirection == eDirNext ? "eDirNext" : "eDirPrevious");
201}
202
203struct nsContentAndOffset {
204 nsIContent* mContent = nullptr;
205 int32_t mOffset = 0;
206};
207
208// Some Misc #defines
209#define SELECTION_DEBUG0 0
210#define FORCE_SELECTION_UPDATE1 1
211#define CALC_DEBUG0 0
212
213#include "nsILineIterator.h"
214#include "prenv.h"
215
216// Utility function to set a nsRect-valued property table entry on aFrame,
217// reusing the existing storage if the property happens to be already set.
218template <typename T>
219static void SetOrUpdateRectValuedProperty(
220 nsIFrame* aFrame, FrameProperties::Descriptor<T> aProperty,
221 const nsRect& aNewValue) {
222 bool found;
223 nsRect* rectStorage = aFrame->GetProperty(aProperty, &found);
224 if (!found) {
225 rectStorage = new nsRect(aNewValue);
226 aFrame->AddProperty(aProperty, rectStorage);
227 } else {
228 *rectStorage = aNewValue;
229 }
230}
231
232FrameDestroyContext::~FrameDestroyContext() {
233 for (auto& content : mozilla::Reversed(mAnonymousContent)) {
234 mPresShell->NativeAnonymousContentRemoved(content);
235 content->UnbindFromTree();
236 }
237}
238
239// Formerly the nsIFrameDebug interface
240
241std::ostream& operator<<(std::ostream& aStream, const nsReflowStatus& aStatus) {
242 char complete = 'Y';
243 if (aStatus.IsIncomplete()) {
244 complete = 'N';
245 } else if (aStatus.IsOverflowIncomplete()) {
246 complete = 'O';
247 }
248
249 char brk = 'N';
250 if (aStatus.IsInlineBreakBefore()) {
251 brk = 'B';
252 } else if (aStatus.IsInlineBreakAfter()) {
253 brk = 'A';
254 }
255
256 aStream << "["
257 << "Complete=" << complete << ","
258 << "NIF=" << (aStatus.NextInFlowNeedsReflow() ? 'Y' : 'N') << ","
259 << "Break=" << brk << ","
260 << "FirstLetter=" << (aStatus.FirstLetterComplete() ? 'Y' : 'N')
261 << "]";
262 return aStream;
263}
264
265#ifdef DEBUG1
266
267/**
268 * Note: the log module is created during library initialization which
269 * means that you cannot perform logging before then.
270 */
271mozilla::LazyLogModule nsIFrame::sFrameLogModule("frame");
272
273#endif
274
275NS_DECLARE_FRAME_PROPERTY_DELETABLE(AbsoluteContainingBlockProperty,static const mozilla::FramePropertyDescriptor<nsAbsoluteContainingBlock
>* AbsoluteContainingBlockProperty() { static const auto descriptor
= mozilla::FramePropertyDescriptor<nsAbsoluteContainingBlock
>::NewWithDestructor<DeleteValue>(); return &descriptor
; }
276 nsAbsoluteContainingBlock)static const mozilla::FramePropertyDescriptor<nsAbsoluteContainingBlock
>* AbsoluteContainingBlockProperty() { static const auto descriptor
= mozilla::FramePropertyDescriptor<nsAbsoluteContainingBlock
>::NewWithDestructor<DeleteValue>(); return &descriptor
; }
277
278bool nsIFrame::HasAbsolutelyPositionedChildren() const {
279 return IsAbsoluteContainer() &&
280 GetAbsoluteContainingBlock()->HasAbsoluteFrames();
281}
282
283nsAbsoluteContainingBlock* nsIFrame::GetAbsoluteContainingBlock() const {
284 NS_ASSERTION(IsAbsoluteContainer(),do { if (!(IsAbsoluteContainer())) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "The frame is not marked as an abspos container correctly",
"IsAbsoluteContainer()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 285); MOZ_PretendNoReturn(); } } while (0)
285 "The frame is not marked as an abspos container correctly")do { if (!(IsAbsoluteContainer())) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "The frame is not marked as an abspos container correctly",
"IsAbsoluteContainer()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 285); MOZ_PretendNoReturn(); } } while (0)
;
286 nsAbsoluteContainingBlock* absCB =
287 GetProperty(AbsoluteContainingBlockProperty());
288 NS_ASSERTION(absCB,do { if (!(absCB)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "The frame is marked as an abspos container but doesn't have "
"the property", "absCB", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 290); MOZ_PretendNoReturn(); } } while (0)
289 "The frame is marked as an abspos container but doesn't have "do { if (!(absCB)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "The frame is marked as an abspos container but doesn't have "
"the property", "absCB", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 290); MOZ_PretendNoReturn(); } } while (0)
290 "the property")do { if (!(absCB)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "The frame is marked as an abspos container but doesn't have "
"the property", "absCB", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 290); MOZ_PretendNoReturn(); } } while (0)
;
291 return absCB;
292}
293
294void nsIFrame::MarkAsAbsoluteContainingBlock() {
295 MOZ_ASSERT(HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN))>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 295); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)"
")"); do { *((volatile int*)__null) = 295; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
296 NS_ASSERTION(!GetProperty(AbsoluteContainingBlockProperty()),do { if (!(!GetProperty(AbsoluteContainingBlockProperty()))) {
NS_DebugBreak(NS_DEBUG_ASSERTION, "Already has an abs-pos containing block property?"
, "!GetProperty(AbsoluteContainingBlockProperty())", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 297); MOZ_PretendNoReturn(); } } while (0)
297 "Already has an abs-pos containing block property?")do { if (!(!GetProperty(AbsoluteContainingBlockProperty()))) {
NS_DebugBreak(NS_DEBUG_ASSERTION, "Already has an abs-pos containing block property?"
, "!GetProperty(AbsoluteContainingBlockProperty())", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 297); MOZ_PretendNoReturn(); } } while (0)
;
298 NS_ASSERTION(!HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN),do { if (!(!HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN))) {
NS_DebugBreak(NS_DEBUG_ASSERTION, "Already has NS_FRAME_HAS_ABSPOS_CHILDREN state bit?"
, "!HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 299); MOZ_PretendNoReturn(); } } while (0)
299 "Already has NS_FRAME_HAS_ABSPOS_CHILDREN state bit?")do { if (!(!HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN))) {
NS_DebugBreak(NS_DEBUG_ASSERTION, "Already has NS_FRAME_HAS_ABSPOS_CHILDREN state bit?"
, "!HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 299); MOZ_PretendNoReturn(); } } while (0)
;
300 AddStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN);
301 SetProperty(AbsoluteContainingBlockProperty(),
302 new nsAbsoluteContainingBlock(GetAbsoluteListID()));
303}
304
305void nsIFrame::MarkAsNotAbsoluteContainingBlock() {
306 NS_ASSERTION(!HasAbsolutelyPositionedChildren(), "Think of the children!")do { if (!(!HasAbsolutelyPositionedChildren())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Think of the children!", "!HasAbsolutelyPositionedChildren()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 306); MOZ_PretendNoReturn(); } } while (0)
;
307 NS_ASSERTION(GetProperty(AbsoluteContainingBlockProperty()),do { if (!(GetProperty(AbsoluteContainingBlockProperty()))) {
NS_DebugBreak(NS_DEBUG_ASSERTION, "Should have an abs-pos containing block property"
, "GetProperty(AbsoluteContainingBlockProperty())", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 308); MOZ_PretendNoReturn(); } } while (0)
308 "Should have an abs-pos containing block property")do { if (!(GetProperty(AbsoluteContainingBlockProperty()))) {
NS_DebugBreak(NS_DEBUG_ASSERTION, "Should have an abs-pos containing block property"
, "GetProperty(AbsoluteContainingBlockProperty())", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 308); MOZ_PretendNoReturn(); } } while (0)
;
309 NS_ASSERTION(HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN),do { if (!(HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN))) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Should have NS_FRAME_HAS_ABSPOS_CHILDREN state bit"
, "HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 310); MOZ_PretendNoReturn(); } } while (0)
310 "Should have NS_FRAME_HAS_ABSPOS_CHILDREN state bit")do { if (!(HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN))) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Should have NS_FRAME_HAS_ABSPOS_CHILDREN state bit"
, "HasAnyStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 310); MOZ_PretendNoReturn(); } } while (0)
;
311 MOZ_ASSERT(HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN))>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 311); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)"
")"); do { *((volatile int*)__null) = 311; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
312 RemoveStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN);
313 RemoveProperty(AbsoluteContainingBlockProperty());
314}
315
316bool nsIFrame::CheckAndClearPaintedState() {
317 bool result = HasAnyStateBits(NS_FRAME_PAINTED_THEBES);
318 RemoveStateBits(NS_FRAME_PAINTED_THEBES);
319
320 for (const auto& childList : ChildLists()) {
321 for (nsIFrame* child : childList.mList) {
322 if (child->CheckAndClearPaintedState()) {
323 result = true;
324 }
325 }
326 }
327 return result;
328}
329
330bool nsIFrame::CheckAndClearDisplayListState() {
331 bool result = BuiltDisplayList();
332 SetBuiltDisplayList(false);
333
334 for (const auto& childList : ChildLists()) {
335 for (nsIFrame* child : childList.mList) {
336 if (child->CheckAndClearDisplayListState()) {
337 result = true;
338 }
339 }
340 }
341 return result;
342}
343
344bool nsIFrame::IsVisibleConsideringAncestors(uint32_t aFlags) const {
345 if (!StyleVisibility()->IsVisible()) {
346 return false;
347 }
348
349 if (PresShell()->IsUnderHiddenEmbedderElement()) {
350 return false;
351 }
352
353 const nsIFrame* frame = this;
354 while (frame) {
355 nsView* view = frame->GetView();
356 if (view && view->GetVisibility() == ViewVisibility::Hide) {
357 return false;
358 }
359
360 if (frame->StyleUIReset()->mMozSubtreeHiddenOnlyVisually) {
361 return false;
362 }
363
364 // This method is used to determine if a frame is focusable, because it's
365 // called by nsIFrame::IsFocusable. `content-visibility: auto` should not
366 // force this frame to be unfocusable, so we only take into account
367 // `content-visibility: hidden` here.
368 if (this != frame &&
369 frame->HidesContent(IncludeContentVisibility::Hidden)) {
370 return false;
371 }
372
373 if (nsIFrame* parent = frame->GetParent()) {
374 frame = parent;
375 } else {
376 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(frame);
377 if (!parent) break;
378
379 if ((aFlags & nsIFrame::VISIBILITY_CROSS_CHROME_CONTENT_BOUNDARY) == 0 &&
380 parent->PresContext()->IsChrome() &&
381 !frame->PresContext()->IsChrome()) {
382 break;
383 }
384
385 frame = parent;
386 }
387 }
388
389 return true;
390}
391
392void nsIFrame::FindCloserFrameForSelection(
393 const nsPoint& aPoint, FrameWithDistance* aCurrentBestFrame) {
394 if (nsLayoutUtils::PointIsCloserToRect(aPoint, mRect,
395 aCurrentBestFrame->mXDistance,
396 aCurrentBestFrame->mYDistance)) {
397 aCurrentBestFrame->mFrame = this;
398 }
399}
400
401void nsIFrame::ElementStateChanged(mozilla::dom::ElementState aStates) {}
402
403void WeakFrame::Clear(mozilla::PresShell* aPresShell) {
404 if (aPresShell) {
405 aPresShell->RemoveWeakFrame(this);
406 }
407 mFrame = nullptr;
408}
409
410AutoWeakFrame::AutoWeakFrame(const WeakFrame& aOther)
411 : mPrev(nullptr), mFrame(nullptr) {
412 Init(aOther.GetFrame());
413}
414
415void AutoWeakFrame::Clear(mozilla::PresShell* aPresShell) {
416 if (aPresShell) {
417 aPresShell->RemoveAutoWeakFrame(this);
418 }
419 mFrame = nullptr;
420 mPrev = nullptr;
421}
422
423AutoWeakFrame::~AutoWeakFrame() {
424 Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr);
425}
426
427void AutoWeakFrame::Init(nsIFrame* aFrame) {
428 Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr);
429 mFrame = aFrame;
430 if (mFrame) {
431 mozilla::PresShell* presShell = mFrame->PresContext()->GetPresShell();
432 NS_WARNING_ASSERTION(presShell, "Null PresShell in AutoWeakFrame!")do { if (!(presShell)) { NS_DebugBreak(NS_DEBUG_WARNING, "Null PresShell in AutoWeakFrame!"
, "presShell", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 432); } } while (false)
;
433 if (presShell) {
434 presShell->AddAutoWeakFrame(this);
435 } else {
436 mFrame = nullptr;
437 }
438 }
439}
440
441void WeakFrame::Init(nsIFrame* aFrame) {
442 Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr);
443 mFrame = aFrame;
444 if (mFrame) {
445 mozilla::PresShell* presShell = mFrame->PresContext()->GetPresShell();
446 MOZ_ASSERT(presShell, "Null PresShell in WeakFrame!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(presShell)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(presShell))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("presShell" " (" "Null PresShell in WeakFrame!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 446); AnnotateMozCrashReason("MOZ_ASSERT" "(" "presShell" ") ("
"Null PresShell in WeakFrame!" ")"); do { *((volatile int*)__null
) = 446; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
447 if (presShell) {
448 presShell->AddWeakFrame(this);
449 } else {
450 mFrame = nullptr;
451 }
452 }
453}
454
455nsIFrame* NS_NewEmptyFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
456 return new (aPresShell) nsIFrame(aStyle, aPresShell->GetPresContext());
457}
458
459nsIFrame::~nsIFrame() {
460 MOZ_COUNT_DTOR(nsIFrame)do { static_assert(std::is_class_v<nsIFrame>, "Token '"
"nsIFrame" "' is not a class type."); static_assert(!std::is_base_of
<nsISupports, nsIFrame>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "nsIFrame", sizeof
(*this)); } while (0)
;
461
462 MOZ_ASSERT(GetVisibility() != Visibility::ApproximatelyVisible,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(GetVisibility() != Visibility::ApproximatelyVisible)
>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(GetVisibility() != Visibility::ApproximatelyVisible)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("GetVisibility() != Visibility::ApproximatelyVisible"
" (" "Visible nsFrame is being destroyed" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 463); AnnotateMozCrashReason("MOZ_ASSERT" "(" "GetVisibility() != Visibility::ApproximatelyVisible"
") (" "Visible nsFrame is being destroyed" ")"); do { *((volatile
int*)__null) = 463; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
463 "Visible nsFrame is being destroyed")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(GetVisibility() != Visibility::ApproximatelyVisible)
>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(GetVisibility() != Visibility::ApproximatelyVisible)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("GetVisibility() != Visibility::ApproximatelyVisible"
" (" "Visible nsFrame is being destroyed" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 463); AnnotateMozCrashReason("MOZ_ASSERT" "(" "GetVisibility() != Visibility::ApproximatelyVisible"
") (" "Visible nsFrame is being destroyed" ")"); do { *((volatile
int*)__null) = 463; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
464}
465
466NS_IMPL_FRAMEARENA_HELPERS(nsIFrame)void* nsIFrame ::operator new(size_t sz, mozilla::PresShell *
aShell) { return aShell->AllocateFrame(nsQueryFrame::nsIFrame_id
, sz); }
467
468// Dummy operator delete. Will never be called, but must be defined
469// to satisfy some C++ ABIs.
470void nsIFrame::operator delete(void*, size_t) {
471 MOZ_CRASH("nsIFrame::operator delete should never be called")do { do { } while (false); MOZ_ReportCrash("" "nsIFrame::operator delete should never be called"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 471); AnnotateMozCrashReason("MOZ_CRASH(" "nsIFrame::operator delete should never be called"
")"); do { *((volatile int*)__null) = 471; __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
472}
473
474NS_QUERYFRAME_HEAD(nsIFrame)void* nsIFrame ::QueryFrame(FrameIID id) const { switch (id) {
475 NS_QUERYFRAME_ENTRY(nsIFrame)case nsIFrame ::kFrameIID: { static_assert( std::is_same_v<
nsIFrame, nsIFrame ::Has_NS_DECL_QUERYFRAME_TARGET>, "nsIFrame"
" must declare itself as a queryframe target"); return const_cast
<nsIFrame*>(static_cast<const nsIFrame*>(this)); }
476NS_QUERYFRAME_TAIL_INHERITANCE_ROOTdefault: break; } do { static_assert( mozilla::detail::AssertionConditionType
<decltype(id != GetFrameId())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(id != GetFrameId()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("id != GetFrameId()"
" (" "A frame failed to QueryFrame to its *own type*. " "It may be missing NS_DECL_QUERYFRAME, or a "
"NS_QUERYFRAME_ENTRY() line with its own type name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 476); AnnotateMozCrashReason("MOZ_ASSERT" "(" "id != GetFrameId()"
") (" "A frame failed to QueryFrame to its *own type*. " "It may be missing NS_DECL_QUERYFRAME, or a "
"NS_QUERYFRAME_ENTRY() line with its own type name" ")"); do
{ *((volatile int*)__null) = 476; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); return nullptr; }
477
478/////////////////////////////////////////////////////////////////////////////
479// nsIFrame
480
481static bool IsFontSizeInflationContainer(nsIFrame* aFrame,
482 const nsStyleDisplay* aStyleDisplay) {
483 /*
484 * Font size inflation is built around the idea that we're inflating
485 * the fonts for a pan-and-zoom UI so that when the user scales up a
486 * block or other container to fill the width of the device, the fonts
487 * will be readable. To do this, we need to pick what counts as a
488 * container.
489 *
490 * From a code perspective, the only hard requirement is that frames
491 * that are line participants (nsIFrame::IsLineParticipant) are never
492 * containers, since line layout assumes that the inflation is consistent
493 * within a line.
494 *
495 * This is not an imposition, since we obviously want a bunch of text
496 * (possibly with inline elements) flowing within a block to count the
497 * block (or higher) as its container.
498 *
499 * We also want form controls, including the text in the anonymous
500 * content inside of them, to match each other and the text next to
501 * them, so they and their anonymous content should also not be a
502 * container.
503 *
504 * However, because we can't reliably compute sizes across XUL during
505 * reflow, any XUL frame with a XUL parent is always a container.
506 *
507 * There are contexts where it would be nice if some blocks didn't
508 * count as a container, so that, for example, an indented quotation
509 * didn't end up with a smaller font size. However, it's hard to
510 * distinguish these situations where we really do want the indented
511 * thing to count as a container, so we don't try, and blocks are
512 * always containers.
513 */
514
515 // The root frame should always be an inflation container.
516 if (!aFrame->GetParent()) {
517 return true;
518 }
519
520 nsIContent* content = aFrame->GetContent();
521 if (content && content->IsInNativeAnonymousSubtree()) {
522 // Native anonymous content shouldn't be a font inflation root,
523 // except for the canvas custom content container.
524 nsCanvasFrame* canvas = aFrame->PresShell()->GetCanvasFrame();
525 return canvas && canvas->GetCustomContentContainer() == content;
526 }
527
528 LayoutFrameType frameType = aFrame->Type();
529 bool isInline =
530 aFrame->GetDisplay().IsInlineFlow() || RubyUtils::IsRubyBox(frameType) ||
531 (aStyleDisplay->IsFloatingStyle() &&
532 frameType == LayoutFrameType::Letter) ||
533 // Given multiple frames for the same node, only the
534 // outer one should be considered a container.
535 // (Important, e.g., for nsSelectsAreaFrame.)
536 (aFrame->GetParent()->GetContent() == content) ||
537 (content &&
538 // Form controls shouldn't become inflation containers.
539 (content->IsAnyOfHTMLElements(nsGkAtoms::option, nsGkAtoms::optgroup,
540 nsGkAtoms::select, nsGkAtoms::input,
541 nsGkAtoms::button, nsGkAtoms::textarea)));
542 NS_ASSERTION(!aFrame->IsLineParticipant() || isInline ||do { if (!(!aFrame->IsLineParticipant() || isInline || aFrame
->IsBrFrame() || aFrame->IsMathMLFrame())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "line participants must not be containers"
, "!aFrame->IsLineParticipant() || isInline || aFrame->IsBrFrame() || aFrame->IsMathMLFrame()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 547); MOZ_PretendNoReturn(); } } while (0)
543 // br frames and mathml frames report being linedo { if (!(!aFrame->IsLineParticipant() || isInline || aFrame
->IsBrFrame() || aFrame->IsMathMLFrame())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "line participants must not be containers"
, "!aFrame->IsLineParticipant() || isInline || aFrame->IsBrFrame() || aFrame->IsMathMLFrame()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 547); MOZ_PretendNoReturn(); } } while (0)
544 // participants even when their position or display isdo { if (!(!aFrame->IsLineParticipant() || isInline || aFrame
->IsBrFrame() || aFrame->IsMathMLFrame())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "line participants must not be containers"
, "!aFrame->IsLineParticipant() || isInline || aFrame->IsBrFrame() || aFrame->IsMathMLFrame()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 547); MOZ_PretendNoReturn(); } } while (0)
545 // setdo { if (!(!aFrame->IsLineParticipant() || isInline || aFrame
->IsBrFrame() || aFrame->IsMathMLFrame())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "line participants must not be containers"
, "!aFrame->IsLineParticipant() || isInline || aFrame->IsBrFrame() || aFrame->IsMathMLFrame()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 547); MOZ_PretendNoReturn(); } } while (0)
546 aFrame->IsBrFrame() || aFrame->IsMathMLFrame(),do { if (!(!aFrame->IsLineParticipant() || isInline || aFrame
->IsBrFrame() || aFrame->IsMathMLFrame())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "line participants must not be containers"
, "!aFrame->IsLineParticipant() || isInline || aFrame->IsBrFrame() || aFrame->IsMathMLFrame()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 547); MOZ_PretendNoReturn(); } } while (0)
547 "line participants must not be containers")do { if (!(!aFrame->IsLineParticipant() || isInline || aFrame
->IsBrFrame() || aFrame->IsMathMLFrame())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "line participants must not be containers"
, "!aFrame->IsLineParticipant() || isInline || aFrame->IsBrFrame() || aFrame->IsMathMLFrame()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 547); MOZ_PretendNoReturn(); } } while (0)
;
548 return !isInline;
549}
550
551static void MaybeScheduleReflowSVGNonDisplayText(nsIFrame* aFrame) {
552 if (!aFrame->IsInSVGTextSubtree()) {
553 return;
554 }
555
556 // We need to ensure that any non-display SVGTextFrames get reflowed when a
557 // child text frame gets new style. Thus we need to schedule a reflow in
558 // |DidSetComputedStyle|. We also need to call it from |DestroyFrom|,
559 // because otherwise we won't get notified when style changes to
560 // "display:none".
561 SVGTextFrame* svgTextFrame = static_cast<SVGTextFrame*>(
562 nsLayoutUtils::GetClosestFrameOfType(aFrame, LayoutFrameType::SVGText));
563 nsIFrame* anonBlock = svgTextFrame->PrincipalChildList().FirstChild();
564
565 // Note that we must check NS_FRAME_FIRST_REFLOW on our SVGTextFrame's
566 // anonymous block frame rather than our aFrame, since NS_FRAME_FIRST_REFLOW
567 // may be set on us if we're a new frame that has been inserted after the
568 // document's first reflow. (In which case this DidSetComputedStyle call may
569 // be happening under frame construction under a Reflow() call.)
570 if (!anonBlock || anonBlock->HasAnyStateBits(NS_FRAME_FIRST_REFLOW)) {
571 return;
572 }
573
574 if (!svgTextFrame->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY) ||
575 svgTextFrame->HasAnyStateBits(NS_STATE_SVG_TEXT_IN_REFLOW)) {
576 return;
577 }
578
579 svgTextFrame->ScheduleReflowSVGNonDisplayText(
580 IntrinsicDirty::FrameAncestorsAndDescendants);
581}
582
583bool nsIFrame::IsPrimaryFrameOfRootOrBodyElement() const {
584 if (!IsPrimaryFrame()) {
585 return false;
586 }
587 nsIContent* content = GetContent();
588 Document* document = content->OwnerDoc();
589 return content == document->GetRootElement() ||
590 content == document->GetBodyElement();
591}
592
593bool nsIFrame::IsRenderedLegend() const {
594 if (auto* parent = GetParent(); parent && parent->IsFieldSetFrame()) {
595 return static_cast<nsFieldSetFrame*>(parent)->GetLegend() == this;
596 }
597 return false;
598}
599
600void nsIFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
601 nsIFrame* aPrevInFlow) {
602 MOZ_ASSERT(nsQueryFrame::FrameIID(mClass) == GetFrameId())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(nsQueryFrame::FrameIID(mClass) == GetFrameId())>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(nsQueryFrame::FrameIID(mClass) == GetFrameId()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("nsQueryFrame::FrameIID(mClass) == GetFrameId()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 602); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsQueryFrame::FrameIID(mClass) == GetFrameId()"
")"); do { *((volatile int*)__null) = 602; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
603 MOZ_ASSERT(!mContent, "Double-initing a frame?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mContent)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mContent))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!mContent" " (" "Double-initing a frame?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 603); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mContent" ") ("
"Double-initing a frame?" ")"); do { *((volatile int*)__null
) = 603; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
604
605 mContent = aContent;
606 mParent = aParent;
607 MOZ_DIAGNOSTIC_ASSERT(!mParent || PresShell() == mParent->PresShell())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mParent || PresShell() == mParent->PresShell())>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!mParent || PresShell() == mParent->PresShell()))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mParent || PresShell() == mParent->PresShell()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 607); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mParent || PresShell() == mParent->PresShell()"
")"); do { *((volatile int*)__null) = 607; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
608
609 if (aPrevInFlow) {
610 mWritingMode = aPrevInFlow->GetWritingMode();
611
612 // Copy some state bits from prev-in-flow (the bits that should apply
613 // throughout a continuation chain). The bits are sorted according to their
614 // order in nsFrameStateBits.h.
615
616 // clang-format off
617 AddStateBits(aPrevInFlow->GetStateBits() &
618 (NS_FRAME_GENERATED_CONTENT |
619 NS_FRAME_OUT_OF_FLOW |
620 NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN |
621 NS_FRAME_INDEPENDENT_SELECTION |
622 NS_FRAME_PART_OF_IBSPLIT |
623 NS_FRAME_MAY_BE_TRANSFORMED |
624 NS_FRAME_HAS_MULTI_COLUMN_ANCESTOR));
625 // clang-format on
626
627 // Copy other bits in nsIFrame from prev-in-flow.
628 mHasColumnSpanSiblings = aPrevInFlow->HasColumnSpanSiblings();
629 } else {
630 PresContext()->ConstructedFrame();
631 }
632
633 if (GetParent()) {
634 if (MOZ_UNLIKELY(mContent == PresContext()->Document()->GetRootElement() &&(__builtin_expect(!!(mContent == PresContext()->Document()
->GetRootElement() && mContent == GetParent()->
GetContent()), 0))
635 mContent == GetParent()->GetContent())(__builtin_expect(!!(mContent == PresContext()->Document()
->GetRootElement() && mContent == GetParent()->
GetContent()), 0))
) {
636 // Our content is the root element and we have the same content as our
637 // parent. That is, we are the internal anonymous frame of the root
638 // element. Copy the used mWritingMode from our parent because
639 // mDocElementContainingBlock gets its mWritingMode from <body>.
640 mWritingMode = GetParent()->GetWritingMode();
641 }
642
643 // Copy some state bits from our parent (the bits that should apply
644 // recursively throughout a subtree). The bits are sorted according to their
645 // order in nsFrameStateBits.h.
646
647 // clang-format off
648 AddStateBits(GetParent()->GetStateBits() &
649 (NS_FRAME_GENERATED_CONTENT |
650 NS_FRAME_INDEPENDENT_SELECTION |
651 NS_FRAME_IS_SVG_TEXT |
652 NS_FRAME_IN_POPUP |
653 NS_FRAME_IS_NONDISPLAY));
654 // clang-format on
655
656 if (HasAnyStateBits(NS_FRAME_IN_POPUP) && TrackingVisibility()) {
657 // Assume all frames in popups are visible.
658 IncApproximateVisibleCount();
659 }
660 }
661 if (aPrevInFlow) {
662 mMayHaveOpacityAnimation = aPrevInFlow->MayHaveOpacityAnimation();
663 mMayHaveTransformAnimation = aPrevInFlow->MayHaveTransformAnimation();
664 } else if (mContent) {
665 // It's fine to fetch the EffectSet for the style frame here because in the
666 // following code we take care of the case where animations may target
667 // a different frame.
668 EffectSet* effectSet = EffectSet::GetForStyleFrame(this);
669 if (effectSet) {
670 mMayHaveOpacityAnimation = effectSet->MayHaveOpacityAnimation();
671
672 if (effectSet->MayHaveTransformAnimation()) {
673 // If we are the inner table frame for display:table content, then
674 // transform animations should go on our parent frame (the table wrapper
675 // frame).
676 //
677 // We do this when initializing the child frame (table inner frame),
678 // because when initializng the table wrapper frame, we don't yet have
679 // access to its children so we can't tell if we have transform
680 // animations or not.
681 if (SupportsCSSTransforms()) {
682 mMayHaveTransformAnimation = true;
683 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
684 } else if (aParent && nsLayoutUtils::GetStyleFrame(aParent) == this) {
685 MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aParent->SupportsCSSTransforms())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aParent->SupportsCSSTransforms
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aParent->SupportsCSSTransforms()" " (" "Style frames that don't support transforms should have parents"
" that do" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 688); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 688; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
686 aParent->SupportsCSSTransforms(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aParent->SupportsCSSTransforms())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aParent->SupportsCSSTransforms
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aParent->SupportsCSSTransforms()" " (" "Style frames that don't support transforms should have parents"
" that do" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 688); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 688; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
687 "Style frames that don't support transforms should have parents"do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aParent->SupportsCSSTransforms())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aParent->SupportsCSSTransforms
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aParent->SupportsCSSTransforms()" " (" "Style frames that don't support transforms should have parents"
" that do" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 688); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 688; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
688 " that do")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aParent->SupportsCSSTransforms())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aParent->SupportsCSSTransforms
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aParent->SupportsCSSTransforms()" " (" "Style frames that don't support transforms should have parents"
" that do" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 688); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 688; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
689 aParent->mMayHaveTransformAnimation = true;
690 aParent->AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
691 }
692 }
693 }
694 }
695
696 const nsStyleDisplay* disp = StyleDisplay();
697 if (disp->HasTransform(this)) {
698 // If 'transform' dynamically changes, RestyleManager takes care of
699 // updating this bit.
700 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
701 }
702
703 if (nsLayoutUtils::FontSizeInflationEnabled(PresContext()) ||
704 !GetParent()
705#ifdef DEBUG1
706 // We have assertions that check inflation invariants even when
707 // font size inflation is not enabled.
708 || true
709#endif
710 ) {
711 if (IsFontSizeInflationContainer(this, disp)) {
712 AddStateBits(NS_FRAME_FONT_INFLATION_CONTAINER);
713 if (!GetParent() ||
714 // I'd use NS_FRAME_OUT_OF_FLOW, but it's not set yet.
715 disp->IsFloating(this) || disp->IsAbsolutelyPositioned(this) ||
716 GetParent()->IsFlexContainerFrame() ||
717 GetParent()->IsGridContainerFrame()) {
718 AddStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT);
719 }
720 }
721 NS_ASSERTION(do { if (!(GetParent() || HasAnyStateBits(NS_FRAME_FONT_INFLATION_CONTAINER
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "root frame should always be a container"
, "GetParent() || HasAnyStateBits(NS_FRAME_FONT_INFLATION_CONTAINER)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 723); MOZ_PretendNoReturn(); } } while (0)
722 GetParent() || HasAnyStateBits(NS_FRAME_FONT_INFLATION_CONTAINER),do { if (!(GetParent() || HasAnyStateBits(NS_FRAME_FONT_INFLATION_CONTAINER
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "root frame should always be a container"
, "GetParent() || HasAnyStateBits(NS_FRAME_FONT_INFLATION_CONTAINER)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 723); MOZ_PretendNoReturn(); } } while (0)
723 "root frame should always be a container")do { if (!(GetParent() || HasAnyStateBits(NS_FRAME_FONT_INFLATION_CONTAINER
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "root frame should always be a container"
, "GetParent() || HasAnyStateBits(NS_FRAME_FONT_INFLATION_CONTAINER)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 723); MOZ_PretendNoReturn(); } } while (0)
;
724 }
725
726 if (TrackingVisibility() && PresShell()->AssumeAllFramesVisible()) {
727 IncApproximateVisibleCount();
728 }
729
730 DidSetComputedStyle(nullptr);
731
732 // For a newly created frame, we need to update this frame's visibility state.
733 // Usually we update the state when the frame is restyled and has a
734 // VisibilityChange change hint but we don't generate any change hints for
735 // newly created frames.
736 // Note: We don't need to do this for placeholders since placeholders have
737 // different styles so that the styles don't have visibility:hidden even if
738 // the parent has visibility:hidden style. We also don't need to update the
739 // state when creating continuations because its visibility is the same as its
740 // prev-in-flow, and the animation code cares only primary frames.
741 if (!IsPlaceholderFrame() && !aPrevInFlow) {
742 UpdateVisibleDescendantsState();
743 }
744
745 if (!aPrevInFlow && HasAnyStateBits(NS_FRAME_IS_NONDISPLAY)) {
746 // We aren't going to get a reflow, so nothing else will call
747 // InvalidateRenderingObservers, we have to do it here.
748 SVGObserverUtils::InvalidateRenderingObservers(this);
749 }
750}
751
752void nsIFrame::InitPrimaryFrame() {
753 MOZ_ASSERT(IsPrimaryFrame())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsPrimaryFrame())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsPrimaryFrame()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("IsPrimaryFrame()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 753); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsPrimaryFrame()"
")"); do { *((volatile int*)__null) = 753; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
754 const nsStyleDisplay* disp = StyleDisplay();
755
756 if (disp->mContainerType != StyleContainerType::Normal) {
757 PresContext()->RegisterContainerQueryFrame(this);
758 }
759
760 if (StyleDisplay()->ContentVisibility(*this) ==
761 StyleContentVisibility::Auto) {
762 PresShell()->RegisterContentVisibilityAutoFrame(this);
763 } else if (auto* element = Element::FromNodeOrNull(GetContent())) {
764 element->ClearContentRelevancy();
765 }
766
767 // TODO(mrobinson): Once bug 1765615 is fixed, this should be called on
768 // layout changes. In addition, when `content-visibility: auto` is implemented
769 // this should also be called when scrolling or focus causes content to be
770 // skipped or unskipped.
771 UpdateAnimationVisibility();
772
773 HandleLastRememberedSize();
774}
775
776void nsIFrame::Destroy(DestroyContext& aContext) {
777 NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),do { if (!(!nsContentUtils::IsSafeToRunScript())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "destroy called on frame while scripts not blocked"
, "!nsContentUtils::IsSafeToRunScript()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 778); MOZ_PretendNoReturn(); } } while (0)
778 "destroy called on frame while scripts not blocked")do { if (!(!nsContentUtils::IsSafeToRunScript())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "destroy called on frame while scripts not blocked"
, "!nsContentUtils::IsSafeToRunScript()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 778); MOZ_PretendNoReturn(); } } while (0)
;
779 NS_ASSERTION(!GetNextSibling() && !GetPrevSibling(),do { if (!(!GetNextSibling() && !GetPrevSibling())) {
NS_DebugBreak(NS_DEBUG_ASSERTION, "Frames should be removed before destruction."
, "!GetNextSibling() && !GetPrevSibling()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 780); MOZ_PretendNoReturn(); } } while (0)
780 "Frames should be removed before destruction.")do { if (!(!GetNextSibling() && !GetPrevSibling())) {
NS_DebugBreak(NS_DEBUG_ASSERTION, "Frames should be removed before destruction."
, "!GetNextSibling() && !GetPrevSibling()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 780); MOZ_PretendNoReturn(); } } while (0)
;
781 MOZ_ASSERT(!HasAbsolutelyPositionedChildren())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasAbsolutelyPositionedChildren())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!HasAbsolutelyPositionedChildren
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!HasAbsolutelyPositionedChildren()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 781); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAbsolutelyPositionedChildren()"
")"); do { *((volatile int*)__null) = 781; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
782 MOZ_ASSERT(!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT))>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)"
" (" "NS_FRAME_PART_OF_IBSPLIT set on non-nsContainerFrame?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 783); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)"
") (" "NS_FRAME_PART_OF_IBSPLIT set on non-nsContainerFrame?"
")"); do { *((volatile int*)__null) = 783; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
783 "NS_FRAME_PART_OF_IBSPLIT set on non-nsContainerFrame?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT))>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)"
" (" "NS_FRAME_PART_OF_IBSPLIT set on non-nsContainerFrame?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 783); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)"
") (" "NS_FRAME_PART_OF_IBSPLIT set on non-nsContainerFrame?"
")"); do { *((volatile int*)__null) = 783; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
784
785 MaybeScheduleReflowSVGNonDisplayText(this);
786
787 SVGObserverUtils::InvalidateDirectRenderingObservers(this);
788
789 const auto* disp = StyleDisplay();
790 if (disp->mPosition == StylePositionProperty::Sticky) {
791 if (auto* ssc =
792 StickyScrollContainer::GetStickyScrollContainerForFrame(this)) {
793 ssc->RemoveFrame(this);
794 }
795 }
796
797 if (disp->mContainerType != StyleContainerType::Normal) {
798 PresContext()->UnregisterContainerQueryFrame(this);
799 }
800
801 nsPresContext* presContext = PresContext();
802 mozilla::PresShell* presShell = presContext->GetPresShell();
803 if (HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
804 if (nsPlaceholderFrame* placeholder = GetPlaceholderFrame()) {
805 placeholder->SetOutOfFlowFrame(nullptr);
806 }
807 }
808
809 if (IsPrimaryFrame()) {
810 // This needs to happen before we clear our Properties() table.
811 ActiveLayerTracker::TransferActivityToContent(this, mContent);
812 }
813
814 ScrollAnchorContainer* anchor = nullptr;
815 if (IsScrollAnchor(&anchor)) {
816 anchor->InvalidateAnchor();
817 }
818
819 if (HasCSSAnimations() || HasCSSTransitions() ||
820 // It's fine to look up the style frame here since if we're destroying the
821 // frames for display:table content we should be destroying both wrapper
822 // and inner frame.
823 EffectSet::GetForStyleFrame(this)) {
824 // If no new frame for this element is created by the end of the
825 // restyling process, stop animations and transitions for this frame
826 RestyleManager::AnimationsWithDestroyedFrame* adf =
827 presContext->RestyleManager()->GetAnimationsWithDestroyedFrame();
828 // AnimationsWithDestroyedFrame only lives during the restyling process.
829 if (adf) {
830 adf->Put(mContent, mComputedStyle);
831 }
832 }
833
834 // Disable visibility tracking. Note that we have to do this before we clear
835 // frame properties and lose track of whether we were previously visible.
836 // XXX(seth): It'd be ideal to assert that we're already marked nonvisible
837 // here, but it's unfortunately tricky to guarantee in the face of things like
838 // frame reconstruction induced by style changes.
839 DisableVisibilityTracking();
840
841 // Ensure that we're not in the approximately visible list anymore.
842 PresContext()->GetPresShell()->RemoveFrameFromApproximatelyVisibleList(this);
843
844 presShell->NotifyDestroyingFrame(this);
845
846 if (HasAnyStateBits(NS_FRAME_EXTERNAL_REFERENCE)) {
847 presShell->ClearFrameRefs(this);
848 }
849
850 nsView* view = GetView();
851 if (view) {
852 view->SetFrame(nullptr);
853 view->Destroy();
854 }
855
856 // Make sure that our deleted frame can't be returned from GetPrimaryFrame()
857 if (IsPrimaryFrame()) {
858 mContent->SetPrimaryFrame(nullptr);
859
860 // Pass the root of a generated content subtree (e.g. ::after/::before) to
861 // aPostDestroyData to unbind it after frame destruction is done.
862 if (HasAnyStateBits(NS_FRAME_GENERATED_CONTENT) &&
863 mContent->IsRootOfNativeAnonymousSubtree()) {
864 aContext.AddAnonymousContent(mContent.forget());
865 }
866 }
867
868 // Remove all properties attached to the frame, to ensure any property
869 // destructors that need the frame pointer are handled properly.
870 RemoveAllProperties();
871
872 // Must retrieve the object ID before calling destructors, so the
873 // vtable is still valid.
874 //
875 // Note to future tweakers: having the method that returns the
876 // object size call the destructor will not avoid an indirect call;
877 // the compiler cannot devirtualize the call to the destructor even
878 // if it's from a method defined in the same class.
879
880 nsQueryFrame::FrameIID id = GetFrameId();
881 this->~nsIFrame();
882
883#ifdef DEBUG1
884 {
885 nsIFrame* rootFrame = presShell->GetRootFrame();
886 MOZ_ASSERT(rootFrame)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(rootFrame)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(rootFrame))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("rootFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 886); AnnotateMozCrashReason("MOZ_ASSERT" "(" "rootFrame" ")"
); do { *((volatile int*)__null) = 886; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
887 if (this != rootFrame) {
888 auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(rootFrame);
889 auto* data = builder ? builder->Data() : nullptr;
890
891 const bool inData =
892 data && (data->IsModified(this) || data->HasProps(this));
893
894 if (inData) {
895 DL_LOG(LogLevel::Warning, "Frame %p found in retained data", this)do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Warning)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Warning, "Frame %p found in retained data", this)
; } } while (0)
;
896 }
897
898 MOZ_ASSERT(!inData, "Deleted frame in retained data!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!inData)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!inData))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!inData" " (" "Deleted frame in retained data!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 898); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!inData" ") ("
"Deleted frame in retained data!" ")"); do { *((volatile int
*)__null) = 898; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
899 }
900 }
901#endif
902
903 // Now that we're totally cleaned out, we need to add ourselves to
904 // the presshell's recycler.
905 presShell->FreeFrame(id, this);
906}
907
908std::pair<int32_t, int32_t> nsIFrame::GetOffsets() const {
909 return std::make_pair(0, 0);
910}
911
912static void CompareLayers(
913 const nsStyleImageLayers* aFirstLayers,
914 const nsStyleImageLayers* aSecondLayers,
915 const std::function<void(imgRequestProxy* aReq)>& aCallback) {
916 NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, (*aFirstLayers))for (uint32_t i = ((*aFirstLayers)).mImageCount; (i)-- != 0;) {
917 const auto& image = aFirstLayers->mLayers[i].mImage;
918 if (!image.IsImageRequestType() || !image.IsResolved()) {
919 continue;
920 }
921
922 // aCallback is called when the style image in aFirstLayers is thought to
923 // be different with the corresponded one in aSecondLayers
924 if (!aSecondLayers || i >= aSecondLayers->mImageCount ||
925 (!aSecondLayers->mLayers[i].mImage.IsResolved() ||
926 image.GetImageRequest() !=
927 aSecondLayers->mLayers[i].mImage.GetImageRequest())) {
928 if (imgRequestProxy* req = image.GetImageRequest()) {
929 aCallback(req);
930 }
931 }
932 }
933}
934
935static void AddAndRemoveImageAssociations(
936 ImageLoader& aImageLoader, nsIFrame* aFrame,
937 const nsStyleImageLayers* aOldLayers,
938 const nsStyleImageLayers* aNewLayers) {
939 // If the old context had a background-image image, or mask-image image,
940 // and new context does not have the same image, clear the image load
941 // notifier (which keeps the image loading, if it still is) for the frame.
942 // We want to do this conservatively because some frames paint their
943 // backgrounds from some other frame's style data, and we don't want
944 // to clear those notifiers unless we have to. (They'll be reset
945 // when we paint, although we could miss a notification in that
946 // interval.)
947 if (aOldLayers && aFrame->HasImageRequest()) {
948 CompareLayers(aOldLayers, aNewLayers, [&](imgRequestProxy* aReq) {
949 aImageLoader.DisassociateRequestFromFrame(aReq, aFrame);
950 });
951 }
952
953 CompareLayers(aNewLayers, aOldLayers, [&](imgRequestProxy* aReq) {
954 aImageLoader.AssociateRequestToFrame(aReq, aFrame);
955 });
956}
957
958void nsIFrame::AddDisplayItem(nsDisplayItem* aItem) {
959 MOZ_DIAGNOSTIC_ASSERT(!mDisplayItems.Contains(aItem))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mDisplayItems.Contains(aItem))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mDisplayItems.Contains(aItem
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!mDisplayItems.Contains(aItem)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 959); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mDisplayItems.Contains(aItem)"
")"); do { *((volatile int*)__null) = 959; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
960 mDisplayItems.AppendElement(aItem);
961#ifdef ACCESSIBILITY1
962 if (nsAccessibilityService* accService = GetAccService()) {
963 accService->NotifyOfPossibleBoundsChange(PresShell(), mContent);
964 }
965#endif
966}
967
968bool nsIFrame::RemoveDisplayItem(nsDisplayItem* aItem) {
969 return mDisplayItems.RemoveElement(aItem);
970}
971
972bool nsIFrame::HasDisplayItems() { return !mDisplayItems.IsEmpty(); }
973
974bool nsIFrame::HasDisplayItem(nsDisplayItem* aItem) {
975 return mDisplayItems.Contains(aItem);
976}
977
978bool nsIFrame::HasDisplayItem(uint32_t aKey) {
979 for (nsDisplayItem* i : mDisplayItems) {
980 if (i->GetPerFrameKey() == aKey) {
981 return true;
982 }
983 }
984 return false;
985}
986
987template <typename Condition>
988static void DiscardDisplayItems(nsIFrame* aFrame, Condition aCondition) {
989 for (nsDisplayItem* i : aFrame->DisplayItems()) {
990 // Only discard items that are invalidated by this frame, as we're only
991 // guaranteed to rebuild those items. Table background items are created by
992 // the relevant table part, but have the cell frame as the primary frame,
993 // and we don't want to remove them if this is the cell.
994 if (aCondition(i) && i->FrameForInvalidation() == aFrame) {
995 i->SetCantBeReused();
996 }
997 }
998}
999
1000static void DiscardOldItems(nsIFrame* aFrame) {
1001 DiscardDisplayItems(aFrame,
1002 [](nsDisplayItem* aItem) { return aItem->IsOldItem(); });
1003}
1004
1005void nsIFrame::RemoveDisplayItemDataForDeletion() {
1006 // Destroying a WebRenderUserDataTable can cause destruction of other objects
1007 // which can remove frame properties in their destructor. If we delete a frame
1008 // property it runs the destructor of the stored object in the middle of
1009 // updating the frame property table, so if the destruction of that object
1010 // causes another update to the frame property table it would leave the frame
1011 // property table in an inconsistent state. So we remove it from the table and
1012 // then destroy it. (bug 1530657)
1013 WebRenderUserDataTable* userDataTable =
1014 TakeProperty(WebRenderUserDataProperty::Key());
1015 if (userDataTable) {
1016 for (const auto& data : userDataTable->Values()) {
1017 data->RemoveFromTable();
1018 }
1019 delete userDataTable;
1020 }
1021
1022 if (!nsLayoutUtils::AreRetainedDisplayListsEnabled()) {
1023 // Retained display lists are disabled, no need to update
1024 // RetainedDisplayListData.
1025 return;
1026 }
1027
1028 auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(this);
1029 if (!builder) {
1030 MOZ_ASSERT(DisplayItems().IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(DisplayItems().IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(DisplayItems().IsEmpty()))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("DisplayItems().IsEmpty()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1030); AnnotateMozCrashReason("MOZ_ASSERT" "(" "DisplayItems().IsEmpty()"
")"); do { *((volatile int*)__null) = 1030; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1031 MOZ_ASSERT(!IsFrameModified())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!IsFrameModified())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!IsFrameModified()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("!IsFrameModified()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1031); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsFrameModified()"
")"); do { *((volatile int*)__null) = 1031; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1032 return;
1033 }
1034
1035 for (nsDisplayItem* i : DisplayItems()) {
1036 if (i->GetDependentFrame() == this && !i->HasDeletedFrame()) {
1037 i->Frame()->MarkNeedsDisplayItemRebuild();
1038 }
1039 i->RemoveFrame(this);
1040 }
1041
1042 DisplayItems().Clear();
1043
1044 nsAutoString name;
1045#ifdef DEBUG_FRAME_DUMP1
1046 if (DL_LOG_TEST(LogLevel::Debug)(__builtin_expect(!!(mozilla::detail::log_test(GetLoggerByProcess
(), LogLevel::Debug)), 0))
) {
1047 GetFrameName(name);
1048 }
1049#endif
1050 DL_LOGV("Removing display item data for frame %p (%s)", this,do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Verbose)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Verbose, "Removing display item data for frame %p (%s)"
, this, NS_ConvertUTF16toUTF8(name).get()); } } while (0)
1051 NS_ConvertUTF16toUTF8(name).get())do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Verbose)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Verbose, "Removing display item data for frame %p (%s)"
, this, NS_ConvertUTF16toUTF8(name).get()); } } while (0)
;
1052
1053 auto* data = builder->Data();
1054 if (MayHaveWillChangeBudget()) {
1055 // Keep the frame in list, so it can be removed from the will-change budget.
1056 data->Flags(this) = RetainedDisplayListData::FrameFlag::HadWillChange;
1057 } else {
1058 data->Remove(this);
1059 }
1060}
1061
1062void nsIFrame::MarkNeedsDisplayItemRebuild() {
1063 if (!nsLayoutUtils::AreRetainedDisplayListsEnabled() || IsFrameModified() ||
1064 HasAnyStateBits(NS_FRAME_IN_POPUP)) {
1065 // Skip frames that are already marked modified.
1066 return;
1067 }
1068
1069 if (Type() == LayoutFrameType::Placeholder) {
1070 nsIFrame* oof = static_cast<nsPlaceholderFrame*>(this)->GetOutOfFlowFrame();
1071 if (oof) {
1072 oof->MarkNeedsDisplayItemRebuild();
1073 }
1074 // Do not mark placeholder frames modified.
1075 return;
1076 }
1077
1078#ifdef ACCESSIBILITY1
1079 if (nsAccessibilityService* accService = GetAccService()) {
1080 accService->NotifyOfPossibleBoundsChange(PresShell(), mContent);
1081 }
1082#endif
1083
1084 nsIFrame* rootFrame = PresShell()->GetRootFrame();
1085
1086 if (rootFrame->IsFrameModified()) {
1087 // The whole frame tree is modified.
1088 return;
1089 }
1090
1091 auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(this);
1092 if (!builder) {
1093 MOZ_ASSERT(DisplayItems().IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(DisplayItems().IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(DisplayItems().IsEmpty()))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("DisplayItems().IsEmpty()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1093); AnnotateMozCrashReason("MOZ_ASSERT" "(" "DisplayItems().IsEmpty()"
")"); do { *((volatile int*)__null) = 1093; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1094 return;
1095 }
1096
1097 RetainedDisplayListData* data = builder->Data();
1098 MOZ_ASSERT(data)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(data)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(data))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("data", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1098); AnnotateMozCrashReason("MOZ_ASSERT" "(" "data" ")");
do { *((volatile int*)__null) = 1098; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1099
1100 if (data->AtModifiedFrameLimit()) {
1101 // This marks the whole frame tree modified.
1102 // See |RetainedDisplayListBuilder::ShouldBuildPartial()|.
1103 data->AddModifiedFrame(rootFrame);
1104 return;
1105 }
1106
1107 nsAutoString name;
1108#ifdef DEBUG_FRAME_DUMP1
1109 if (DL_LOG_TEST(LogLevel::Debug)(__builtin_expect(!!(mozilla::detail::log_test(GetLoggerByProcess
(), LogLevel::Debug)), 0))
) {
1110 GetFrameName(name);
1111 }
1112#endif
1113
1114 DL_LOGV("RDL - Rebuilding display items for frame %p (%s)", this,do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Verbose)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Verbose, "RDL - Rebuilding display items for frame %p (%s)"
, this, NS_ConvertUTF16toUTF8(name).get()); } } while (0)
1115 NS_ConvertUTF16toUTF8(name).get())do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Verbose)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Verbose, "RDL - Rebuilding display items for frame %p (%s)"
, this, NS_ConvertUTF16toUTF8(name).get()); } } while (0)
;
1116
1117 data->AddModifiedFrame(this);
1118
1119 MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding
) == 0)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding
) == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding) == 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1120); AnnotateMozCrashReason("MOZ_ASSERT" "(" "PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding) == 0"
")"); do { *((volatile int*)__null) = 1120; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1120 PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding) == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding
) == 0)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding
) == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding) == 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1120); AnnotateMozCrashReason("MOZ_ASSERT" "(" "PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding) == 0"
")"); do { *((volatile int*)__null) = 1120; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1121
1122 // Hopefully this is cheap, but we could use a frame state bit to note
1123 // the presence of dependencies to speed it up.
1124 for (nsDisplayItem* i : DisplayItems()) {
1125 if (i->HasDeletedFrame() || i->Frame() == this) {
1126 // Ignore the items with deleted frames, and the items with |this| as
1127 // the primary frame.
1128 continue;
1129 }
1130
1131 if (i->GetDependentFrame() == this) {
1132 // For items with |this| as a dependent frame, mark the primary frame
1133 // for rebuild.
1134 i->Frame()->MarkNeedsDisplayItemRebuild();
1135 }
1136 }
1137}
1138
1139// Subclass hook for style post processing
1140/* virtual */
1141void nsIFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) {
1142#ifdef ACCESSIBILITY1
1143 // Don't notify for reconstructed frames here, since the frame is still being
1144 // constructed at this point and so LocalAccessible::GetFrame() will return
1145 // null. Style changes for reconstructed frames are handled in
1146 // DocAccessible::PruneOrInsertSubtree.
1147 if (aOldComputedStyle) {
1148 if (nsAccessibilityService* accService = GetAccService()) {
1149 accService->NotifyOfComputedStyleChange(PresShell(), mContent);
1150 }
1151 }
1152#endif
1153
1154 MaybeScheduleReflowSVGNonDisplayText(this);
1155
1156 Document* doc = PresContext()->Document();
1157 ImageLoader* loader = doc->StyleImageLoader();
1158 // Continuing text frame doesn't initialize its continuation pointer before
1159 // reaching here for the first time, so we have to exclude text frames. This
1160 // doesn't affect correctness because text can't match selectors.
1161 //
1162 // FIXME(emilio): We should consider fixing that.
1163 //
1164 // TODO(emilio): Can we avoid doing some / all of the image stuff when
1165 // isNonTextFirstContinuation is false? We should consider doing this just for
1166 // primary frames and pseudos, but the first-line reparenting code makes it
1167 // all bad, should get around to bug 1465474 eventually :(
1168 const bool isNonText = !IsTextFrame();
1169 if (isNonText) {
1170 mComputedStyle->StartImageLoads(*doc, aOldComputedStyle);
1171 }
1172
1173 const nsStyleImageLayers* oldLayers =
1174 aOldComputedStyle ? &aOldComputedStyle->StyleBackground()->mImage
1175 : nullptr;
1176 const nsStyleImageLayers* newLayers = &StyleBackground()->mImage;
1177 AddAndRemoveImageAssociations(*loader, this, oldLayers, newLayers);
1178
1179 oldLayers =
1180 aOldComputedStyle ? &aOldComputedStyle->StyleSVGReset()->mMask : nullptr;
1181 newLayers = &StyleSVGReset()->mMask;
1182 AddAndRemoveImageAssociations(*loader, this, oldLayers, newLayers);
1183
1184 const nsStyleDisplay* disp = StyleDisplay();
1185 bool handleStickyChange = false;
1186 if (aOldComputedStyle) {
1187 // Detect style changes that should trigger a scroll anchor adjustment
1188 // suppression.
1189 // https://drafts.csswg.org/css-scroll-anchoring/#suppression-triggers
1190 bool needAnchorSuppression = false;
1191
1192 const nsStyleMargin* oldMargin = aOldComputedStyle->StyleMargin();
1193 if (oldMargin->mMargin != StyleMargin()->mMargin) {
1194 needAnchorSuppression = true;
1195 }
1196
1197 const nsStylePadding* oldPadding = aOldComputedStyle->StylePadding();
1198 if (oldPadding->mPadding != StylePadding()->mPadding) {
1199 SetHasPaddingChange(true);
1200 needAnchorSuppression = true;
1201 }
1202
1203 const nsStyleDisplay* oldDisp = aOldComputedStyle->StyleDisplay();
1204 if (oldDisp->mOverflowAnchor != disp->mOverflowAnchor) {
1205 if (auto* container = ScrollAnchorContainer::FindFor(this)) {
1206 container->InvalidateAnchor();
1207 }
1208 if (nsIScrollableFrame* scrollableFrame = do_QueryFrame(this)) {
1209 scrollableFrame->Anchor()->InvalidateAnchor();
1210 }
1211 }
1212
1213 if (mInScrollAnchorChain) {
1214 const nsStylePosition* pos = StylePosition();
1215 const nsStylePosition* oldPos = aOldComputedStyle->StylePosition();
1216 if (!needAnchorSuppression &&
1217 (oldPos->mOffset != pos->mOffset || oldPos->mWidth != pos->mWidth ||
1218 oldPos->mMinWidth != pos->mMinWidth ||
1219 oldPos->mMaxWidth != pos->mMaxWidth ||
1220 oldPos->mHeight != pos->mHeight ||
1221 oldPos->mMinHeight != pos->mMinHeight ||
1222 oldPos->mMaxHeight != pos->mMaxHeight ||
1223 oldDisp->mPosition != disp->mPosition ||
1224 oldDisp->mTransform != disp->mTransform)) {
1225 needAnchorSuppression = true;
1226 }
1227
1228 if (needAnchorSuppression &&
1229 StaticPrefs::layout_css_scroll_anchoring_suppressions_enabled()) {
1230 ScrollAnchorContainer::FindFor(this)->SuppressAdjustments();
1231 }
1232 }
1233
1234 if (disp->mPosition != oldDisp->mPosition) {
1235 if (!disp->IsRelativelyOrStickyPositionedStyle() &&
1236 oldDisp->IsRelativelyOrStickyPositionedStyle()) {
1237 RemoveProperty(NormalPositionProperty());
1238 }
1239
1240 handleStickyChange = disp->mPosition == StylePositionProperty::Sticky ||
1241 oldDisp->mPosition == StylePositionProperty::Sticky;
1242 }
1243 if (disp->mScrollSnapAlign != oldDisp->mScrollSnapAlign) {
1244 ScrollSnapUtils::PostPendingResnapFor(this);
1245 }
1246 if (aOldComputedStyle->IsRootElementStyle() &&
1247 disp->mScrollSnapType != oldDisp->mScrollSnapType) {
1248 if (nsIScrollableFrame* scrollableFrame =
1249 PresShell()->GetRootScrollFrameAsScrollable()) {
1250 scrollableFrame->PostPendingResnap();
1251 }
1252 }
1253 if (StyleUIReset()->mMozSubtreeHiddenOnlyVisually &&
1254 !aOldComputedStyle->StyleUIReset()->mMozSubtreeHiddenOnlyVisually) {
1255 PresShell::ClearMouseCapture(this);
1256 }
1257 } else { // !aOldComputedStyle
1258 handleStickyChange = disp->mPosition == StylePositionProperty::Sticky;
1259 }
1260
1261 if (handleStickyChange && !HasAnyStateBits(NS_FRAME_IS_NONDISPLAY) &&
1262 !GetPrevInFlow()) {
1263 // Note that we only add first continuations, but we really only
1264 // want to add first continuation-or-ib-split-siblings. But since we don't
1265 // yet know if we're a later part of a block-in-inline split, we'll just
1266 // add later members of a block-in-inline split here, and then
1267 // StickyScrollContainer will remove them later.
1268 if (auto* ssc =
1269 StickyScrollContainer::GetStickyScrollContainerForFrame(this)) {
1270 if (disp->mPosition == StylePositionProperty::Sticky) {
1271 ssc->AddFrame(this);
1272 } else {
1273 ssc->RemoveFrame(this);
1274 }
1275 }
1276 }
1277
1278 imgIRequest* oldBorderImage =
1279 aOldComputedStyle
1280 ? aOldComputedStyle->StyleBorder()->GetBorderImageRequest()
1281 : nullptr;
1282 imgIRequest* newBorderImage = StyleBorder()->GetBorderImageRequest();
1283 // FIXME (Bug 759996): The following is no longer true.
1284 // For border-images, we can't be as conservative (we need to set the
1285 // new loaders if there has been any change) since the CalcDifference
1286 // call depended on the result of GetComputedBorder() and that result
1287 // depends on whether the image has loaded, start the image load now
1288 // so that we'll get notified when it completes loading and can do a
1289 // restyle. Otherwise, the image might finish loading from the
1290 // network before we start listening to its notifications, and then
1291 // we'll never know that it's finished loading. Likewise, we want to
1292 // do this for freshly-created frames to prevent a similar race if the
1293 // image loads between reflow (which can depend on whether the image
1294 // is loaded) and paint. We also don't really care about any callers who try
1295 // to paint borders with a different style, because they won't have the
1296 // correct size for the border either.
1297 if (oldBorderImage != newBorderImage) {
1298 // stop and restart the image loading/notification
1299 if (oldBorderImage && HasImageRequest()) {
1300 loader->DisassociateRequestFromFrame(oldBorderImage, this);
1301 }
1302 if (newBorderImage) {
1303 loader->AssociateRequestToFrame(newBorderImage, this);
1304 }
1305 }
1306
1307 auto GetShapeImageRequest = [](const ComputedStyle* aStyle) -> imgIRequest* {
1308 if (!aStyle) {
1309 return nullptr;
1310 }
1311 auto& shape = aStyle->StyleDisplay()->mShapeOutside;
1312 if (!shape.IsImage()) {
1313 return nullptr;
1314 }
1315 return shape.AsImage().GetImageRequest();
1316 };
1317
1318 imgIRequest* oldShapeImage = GetShapeImageRequest(aOldComputedStyle);
1319 imgIRequest* newShapeImage = GetShapeImageRequest(Style());
1320 if (oldShapeImage != newShapeImage) {
1321 if (oldShapeImage && HasImageRequest()) {
1322 loader->DisassociateRequestFromFrame(oldShapeImage, this);
1323 }
1324 if (newShapeImage) {
1325 loader->AssociateRequestToFrame(
1326 newShapeImage, this,
1327 ImageLoader::Flags::
1328 RequiresReflowOnFirstFrameCompleteAndLoadEventBlocking);
1329 }
1330 }
1331
1332 // SVGObserverUtils::GetEffectProperties() asserts that we only invoke it with
1333 // the first continuation so we need to check that in advance.
1334 const bool isNonTextFirstContinuation = isNonText && !GetPrevContinuation();
1335 if (isNonTextFirstContinuation) {
1336 // Kick off loading of external SVG resources referenced from properties if
1337 // any. This currently includes filter, clip-path, and mask.
1338 SVGObserverUtils::InitiateResourceDocLoads(this);
1339 }
1340
1341 // If the page contains markup that overrides text direction, and
1342 // does not contain any characters that would activate the Unicode
1343 // bidi algorithm, we need to call |SetBidiEnabled| on the pres
1344 // context before reflow starts. See bug 115921.
1345 if (StyleVisibility()->mDirection == StyleDirection::Rtl) {
1346 PresContext()->SetBidiEnabled();
1347 }
1348
1349 // The following part is for caching offset-path:path(). We cache the
1350 // flatten gfx path, so we don't have to rebuild and re-flattern it at
1351 // each cycle if we have animations on offset-* with a fixed offset-path.
1352 const StyleOffsetPath* oldPath =
1353 aOldComputedStyle ? &aOldComputedStyle->StyleDisplay()->mOffsetPath
1354 : nullptr;
1355 const StyleOffsetPath& newPath = StyleDisplay()->mOffsetPath;
1356 if (!oldPath || *oldPath != newPath) {
1357 // FIXME: Bug 1837042. Cache all basic shapes.
1358 if (newPath.IsPath()) {
1359 RefPtr<gfx::PathBuilder> builder = MotionPathUtils::GetPathBuilder();
1360 RefPtr<gfx::Path> path =
1361 MotionPathUtils::BuildSVGPath(newPath.AsSVGPathData(), builder);
1362 if (path) {
1363 // The newPath could be path('') (i.e. empty path), so its gfx path
1364 // could be nullptr, and so we only set property for a non-empty path.
1365 SetProperty(nsIFrame::OffsetPathCache(), path.forget().take());
1366 } else {
1367 // May have an old cached path, so we have to delete it.
1368 RemoveProperty(nsIFrame::OffsetPathCache());
1369 }
1370 } else if (oldPath) {
1371 RemoveProperty(nsIFrame::OffsetPathCache());
1372 }
1373 }
1374
1375 if (IsPrimaryFrame()) {
1376 HandleLastRememberedSize();
1377 }
1378
1379 RemoveStateBits(NS_FRAME_SIMPLE_EVENT_REGIONS | NS_FRAME_SIMPLE_DISPLAYLIST);
1380
1381 mMayHaveRoundedCorners = true;
1382}
1383
1384void nsIFrame::HandleLastRememberedSize() {
1385 MOZ_ASSERT(IsPrimaryFrame())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsPrimaryFrame())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsPrimaryFrame()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("IsPrimaryFrame()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1385); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsPrimaryFrame()"
")"); do { *((volatile int*)__null) = 1385; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1386 // Storing a last remembered size requires contain-intrinsic-size, and using
1387 // a previously stored last remembered size requires content-visibility.
1388 if (!StaticPrefs::layout_css_contain_intrinsic_size_enabled() ||
1389 !StaticPrefs::layout_css_content_visibility_enabled()) {
1390 return;
1391 }
1392 auto* element = Element::FromNodeOrNull(mContent);
1393 if (!element) {
1394 return;
1395 }
1396 const WritingMode wm = GetWritingMode();
1397 const nsStylePosition* stylePos = StylePosition();
1398 bool canRememberBSize = stylePos->ContainIntrinsicBSize(wm).HasAuto();
1399 bool canRememberISize = stylePos->ContainIntrinsicISize(wm).HasAuto();
1400 if (!canRememberBSize) {
1401 element->RemoveLastRememberedBSize();
1402 }
1403 if (!canRememberISize) {
1404 element->RemoveLastRememberedISize();
1405 }
1406 if ((canRememberBSize || canRememberISize) && !HidesContent()) {
1407 bool isNonReplacedInline = IsLineParticipant() && !IsReplaced();
1408 if (!isNonReplacedInline) {
1409 PresContext()->Document()->ObserveForLastRememberedSize(*element);
1410 return;
1411 }
1412 }
1413 PresContext()->Document()->UnobserveForLastRememberedSize(*element);
1414}
1415
1416#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED1
1417void nsIFrame::AssertNewStyleIsSane(ComputedStyle& aNewStyle) {
1418 MOZ_DIAGNOSTIC_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1419 aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1420 // ::first-line continuations are weird, this should probably be fixed viado { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1421 // bug 1465474.do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1422 (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine &&do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1423 aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1424 // ::first-letter continuations are broken, in particular floating ones,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1425 // see bug 1490281. The construction code tries to fix this up after thedo { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1426 // fact, then restyling undoes it...do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1427 (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText &&do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1428 aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1429 (mComputedStyle->GetPseudoType() ==do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1430 PseudoStyleType::firstLetterContinuation &&do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1431 aNewStyle.GetPseudoType() == PseudoStyleType::mozText))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType
() || (mComputedStyle->GetPseudoType() == PseudoStyleType::
firstLine && aNewStyle.GetPseudoType() == PseudoStyleType
::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType
::mozText && aNewStyle.GetPseudoType() == PseudoStyleType
::firstLetterContinuation) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLetterContinuation && aNewStyle
.GetPseudoType() == PseudoStyleType::mozText))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aNewStyle.GetPseudoType() ==
mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType
() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType
() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType
() == PseudoStyleType::mozText && aNewStyle.GetPseudoType
() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle
->GetPseudoType() == PseudoStyleType::firstLetterContinuation
&& aNewStyle.GetPseudoType() == PseudoStyleType::mozText
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1431); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aNewStyle.GetPseudoType() == mComputedStyle->GetPseudoType() || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLine && aNewStyle.GetPseudoType() == PseudoStyleType::mozLineFrame) || (mComputedStyle->GetPseudoType() == PseudoStyleType::mozText && aNewStyle.GetPseudoType() == PseudoStyleType::firstLetterContinuation) || (mComputedStyle->GetPseudoType() == PseudoStyleType::firstLetterContinuation && aNewStyle.GetPseudoType() == PseudoStyleType::mozText)"
")"); do { *((volatile int*)__null) = 1431; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1432}
1433#endif
1434
1435void nsIFrame::ReparentFrameViewTo(nsViewManager* aViewManager,
1436 nsView* aNewParentView) {
1437 if (HasView()) {
1438 if (IsMenuPopupFrame()) {
1439 // This view must be parented by the root view, don't reparent it.
1440 return;
1441 }
1442 nsView* view = GetView();
1443 aViewManager->RemoveChild(view);
1444
1445 // The view will remember the Z-order and other attributes that have been
1446 // set on it.
1447 nsView* insertBefore =
1448 nsLayoutUtils::FindSiblingViewFor(aNewParentView, this);
1449 aViewManager->InsertChild(aNewParentView, view, insertBefore,
1450 insertBefore != nullptr);
1451 } else if (HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW)) {
1452 for (const auto& childList : ChildLists()) {
1453 // Iterate the child frames, and check each child frame to see if it has
1454 // a view
1455 for (nsIFrame* child : childList.mList) {
1456 child->ReparentFrameViewTo(aViewManager, aNewParentView);
1457 }
1458 }
1459 }
1460}
1461
1462void nsIFrame::SyncFrameViewProperties(nsView* aView) {
1463 if (!aView) {
1464 aView = GetView();
1465 if (!aView) {
1466 return;
1467 }
1468 }
1469
1470 nsViewManager* vm = aView->GetViewManager();
1471
1472 // Make sure visibility is correct. This only affects nsSubDocumentFrame.
1473 if (!SupportsVisibilityHidden()) {
1474 // See if the view should be hidden or visible
1475 ComputedStyle* sc = Style();
1476 vm->SetViewVisibility(aView, sc->StyleVisibility()->IsVisible()
1477 ? ViewVisibility::Show
1478 : ViewVisibility::Hide);
1479 }
1480
1481 const auto zIndex = ZIndex();
1482 const bool autoZIndex = !zIndex;
1483 vm->SetViewZIndex(aView, autoZIndex, zIndex.valueOr(0));
1484}
1485
1486void nsIFrame::CreateView() {
1487 MOZ_ASSERT(!HasView())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasView())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!HasView()))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!HasView()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1487); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasView()"
")"); do { *((volatile int*)__null) = 1487; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1488
1489 nsView* parentView = GetParent()->GetClosestView();
1490 MOZ_ASSERT(parentView, "no parent with view")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(parentView)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(parentView))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("parentView" " (" "no parent with view"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1490); AnnotateMozCrashReason("MOZ_ASSERT" "(" "parentView"
") (" "no parent with view" ")"); do { *((volatile int*)__null
) = 1490; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
1491
1492 nsViewManager* viewManager = parentView->GetViewManager();
1493 MOZ_ASSERT(viewManager, "null view manager")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(viewManager)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(viewManager))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("viewManager" " ("
"null view manager" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1493); AnnotateMozCrashReason("MOZ_ASSERT" "(" "viewManager"
") (" "null view manager" ")"); do { *((volatile int*)__null
) = 1493; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
1494
1495 nsView* view = viewManager->CreateView(GetRect(), parentView);
1496 SyncFrameViewProperties(view);
1497
1498 nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(parentView, this);
1499 // we insert this view 'above' the insertBefore view, unless insertBefore is
1500 // null, in which case we want to call with aAbove == false to insert at the
1501 // beginning in document order
1502 viewManager->InsertChild(parentView, view, insertBefore,
1503 insertBefore != nullptr);
1504
1505 // REVIEW: Don't create a widget for fixed-pos elements anymore.
1506 // ComputeRepaintRegionForCopy will calculate the right area to repaint
1507 // when we scroll.
1508 // Reparent views on any child frames (or their descendants) to this
1509 // view. We can just call ReparentFrameViewTo on this frame because
1510 // we know this frame has no view, so it will crawl the children. Also,
1511 // we know that any descendants with views must have 'parentView' as their
1512 // parent view.
1513 ReparentFrameViewTo(viewManager, view);
1514
1515 // Remember our view
1516 SetView(view);
1517
1518 NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { printf_stderr ("nsIFrame::CreateView: frame=%p view=%p"
, this, view); } } while (0)
1519 ("nsIFrame::CreateView: frame=%p view=%p", this, view))do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { printf_stderr ("nsIFrame::CreateView: frame=%p view=%p"
, this, view); } } while (0)
;
1520}
1521
1522/* virtual */
1523nsMargin nsIFrame::GetUsedMargin() const {
1524 nsMargin margin;
1525 if (((mState & NS_FRAME_FIRST_REFLOW) && !(mState & NS_FRAME_IN_REFLOW)) ||
1526 IsInSVGTextSubtree()) {
1527 return margin;
1528 }
1529
1530 if (nsMargin* m = GetProperty(UsedMarginProperty())) {
1531 margin = *m;
1532 } else if (!StyleMargin()->GetMargin(margin)) {
1533 // If we get here, our caller probably shouldn't be calling us...
1534 NS_ERROR(do { NS_DebugBreak(NS_DEBUG_ASSERTION, "Returning bogus 0-sized margin, because this margin "
"depends on layout & isn't cached!", "Error", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1536); MOZ_PretendNoReturn(); } while (0)
1535 "Returning bogus 0-sized margin, because this margin "do { NS_DebugBreak(NS_DEBUG_ASSERTION, "Returning bogus 0-sized margin, because this margin "
"depends on layout & isn't cached!", "Error", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1536); MOZ_PretendNoReturn(); } while (0)
1536 "depends on layout & isn't cached!")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "Returning bogus 0-sized margin, because this margin "
"depends on layout & isn't cached!", "Error", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1536); MOZ_PretendNoReturn(); } while (0)
;
1537 }
1538 return margin;
1539}
1540
1541/* virtual */
1542nsMargin nsIFrame::GetUsedBorder() const {
1543 if (((mState & NS_FRAME_FIRST_REFLOW) && !(mState & NS_FRAME_IN_REFLOW)) ||
1544 IsInSVGTextSubtree()) {
1545 return {};
1546 }
1547
1548 const nsStyleDisplay* disp = StyleDisplay();
1549 if (IsThemed(disp)) {
1550 // Theme methods don't use const-ness.
1551 auto* mutable_this = const_cast<nsIFrame*>(this);
1552 nsPresContext* pc = PresContext();
1553 LayoutDeviceIntMargin widgetBorder = pc->Theme()->GetWidgetBorder(
1554 pc->DeviceContext(), mutable_this, disp->EffectiveAppearance());
1555 return LayoutDevicePixel::ToAppUnits(widgetBorder,
1556 pc->AppUnitsPerDevPixel());
1557 }
1558
1559 return StyleBorder()->GetComputedBorder();
1560}
1561
1562/* virtual */
1563nsMargin nsIFrame::GetUsedPadding() const {
1564 nsMargin padding;
1565 if (((mState & NS_FRAME_FIRST_REFLOW) && !(mState & NS_FRAME_IN_REFLOW)) ||
1566 IsInSVGTextSubtree()) {
1567 return padding;
1568 }
1569
1570 const nsStyleDisplay* disp = StyleDisplay();
1571 if (IsThemed(disp)) {
1572 // Theme methods don't use const-ness.
1573 nsIFrame* mutable_this = const_cast<nsIFrame*>(this);
1574 nsPresContext* pc = PresContext();
1575 LayoutDeviceIntMargin widgetPadding;
1576 if (pc->Theme()->GetWidgetPadding(pc->DeviceContext(), mutable_this,
1577 disp->EffectiveAppearance(),
1578 &widgetPadding)) {
1579 return LayoutDevicePixel::ToAppUnits(widgetPadding,
1580 pc->AppUnitsPerDevPixel());
1581 }
1582 }
1583
1584 if (nsMargin* p = GetProperty(UsedPaddingProperty())) {
1585 padding = *p;
1586 } else if (!StylePadding()->GetPadding(padding)) {
1587 // If we get here, our caller probably shouldn't be calling us...
1588 NS_ERROR(do { NS_DebugBreak(NS_DEBUG_ASSERTION, "Returning bogus 0-sized padding, because this padding "
"depends on layout & isn't cached!", "Error", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1590); MOZ_PretendNoReturn(); } while (0)
1589 "Returning bogus 0-sized padding, because this padding "do { NS_DebugBreak(NS_DEBUG_ASSERTION, "Returning bogus 0-sized padding, because this padding "
"depends on layout & isn't cached!", "Error", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1590); MOZ_PretendNoReturn(); } while (0)
1590 "depends on layout & isn't cached!")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "Returning bogus 0-sized padding, because this padding "
"depends on layout & isn't cached!", "Error", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1590); MOZ_PretendNoReturn(); } while (0)
;
1591 }
1592 return padding;
1593}
1594
1595nsIFrame::Sides nsIFrame::GetSkipSides() const {
1596 if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak ==(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Clone), 0))
1597 StyleBoxDecorationBreak::Clone)(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Clone), 0))
&&
1598 !HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER)) {
1599 return Sides();
1600 }
1601
1602 // Convert the logical skip sides to physical sides using the frame's
1603 // writing mode
1604 WritingMode writingMode = GetWritingMode();
1605 LogicalSides logicalSkip = GetLogicalSkipSides();
1606 Sides skip;
1607
1608 if (logicalSkip.BStart()) {
1609 if (writingMode.IsVertical()) {
1610 skip |= writingMode.IsVerticalLR() ? SideBits::eLeft : SideBits::eRight;
1611 } else {
1612 skip |= SideBits::eTop;
1613 }
1614 }
1615
1616 if (logicalSkip.BEnd()) {
1617 if (writingMode.IsVertical()) {
1618 skip |= writingMode.IsVerticalLR() ? SideBits::eRight : SideBits::eLeft;
1619 } else {
1620 skip |= SideBits::eBottom;
1621 }
1622 }
1623
1624 if (logicalSkip.IStart()) {
1625 if (writingMode.IsVertical()) {
1626 skip |= SideBits::eTop;
1627 } else {
1628 skip |= writingMode.IsBidiLTR() ? SideBits::eLeft : SideBits::eRight;
1629 }
1630 }
1631
1632 if (logicalSkip.IEnd()) {
1633 if (writingMode.IsVertical()) {
1634 skip |= SideBits::eBottom;
1635 } else {
1636 skip |= writingMode.IsBidiLTR() ? SideBits::eRight : SideBits::eLeft;
1637 }
1638 }
1639 return skip;
1640}
1641
1642nsRect nsIFrame::GetPaddingRectRelativeToSelf() const {
1643 nsMargin border = GetUsedBorder().ApplySkipSides(GetSkipSides());
1644 nsRect r(0, 0, mRect.width, mRect.height);
1645 r.Deflate(border);
1646 return r;
1647}
1648
1649nsRect nsIFrame::GetPaddingRect() const {
1650 return GetPaddingRectRelativeToSelf() + GetPosition();
1651}
1652
1653WritingMode nsIFrame::WritingModeForLine(WritingMode aSelfWM,
1654 nsIFrame* aSubFrame) const {
1655 MOZ_ASSERT(aSelfWM == GetWritingMode())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aSelfWM == GetWritingMode())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aSelfWM == GetWritingMode())
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aSelfWM == GetWritingMode()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1655); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aSelfWM == GetWritingMode()"
")"); do { *((volatile int*)__null) = 1655; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1656 WritingMode writingMode = aSelfWM;
1657
1658 if (StyleTextReset()->mUnicodeBidi == StyleUnicodeBidi::Plaintext) {
1659 mozilla::intl::BidiEmbeddingLevel frameLevel =
1660 nsBidiPresUtils::GetFrameBaseLevel(aSubFrame);
1661 writingMode.SetDirectionFromBidiLevel(frameLevel);
1662 }
1663
1664 return writingMode;
1665}
1666
1667nsRect nsIFrame::GetMarginRect() const {
1668 return GetMarginRectRelativeToSelf() + GetPosition();
1669}
1670
1671nsRect nsIFrame::GetMarginRectRelativeToSelf() const {
1672 nsMargin m = GetUsedMargin().ApplySkipSides(GetSkipSides());
1673 nsRect r(0, 0, mRect.width, mRect.height);
1674 r.Inflate(m);
1675 return r;
1676}
1677
1678bool nsIFrame::IsTransformed() const {
1679 if (!HasAnyStateBits(NS_FRAME_MAY_BE_TRANSFORMED)) {
1680 MOZ_ASSERT(!IsCSSTransformed())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!IsCSSTransformed())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!IsCSSTransformed()))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("!IsCSSTransformed()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1680); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsCSSTransformed()"
")"); do { *((volatile int*)__null) = 1680; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1681 MOZ_ASSERT(!IsSVGTransformed())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!IsSVGTransformed())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!IsSVGTransformed()))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("!IsSVGTransformed()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1681); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsSVGTransformed()"
")"); do { *((volatile int*)__null) = 1681; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1682 return false;
1683 }
1684 return IsCSSTransformed() || IsSVGTransformed();
1685}
1686
1687bool nsIFrame::IsCSSTransformed() const {
1688 return HasAnyStateBits(NS_FRAME_MAY_BE_TRANSFORMED) &&
1689 (StyleDisplay()->HasTransform(this) || HasAnimationOfTransform());
1690}
1691
1692bool nsIFrame::HasAnimationOfTransform() const {
1693 return IsPrimaryFrame() &&
1694 nsLayoutUtils::HasAnimationOfTransformAndMotionPath(this) &&
1695 SupportsCSSTransforms();
1696}
1697
1698bool nsIFrame::ChildrenHavePerspective(
1699 const nsStyleDisplay* aStyleDisplay) const {
1700 MOZ_ASSERT(aStyleDisplay == StyleDisplay())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aStyleDisplay == StyleDisplay())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aStyleDisplay == StyleDisplay
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aStyleDisplay == StyleDisplay()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1700); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStyleDisplay == StyleDisplay()"
")"); do { *((volatile int*)__null) = 1700; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1701 return aStyleDisplay->HasPerspective(this);
1702}
1703
1704bool nsIFrame::HasAnimationOfOpacity(EffectSet* aEffectSet) const {
1705 return ((nsLayoutUtils::IsPrimaryStyleFrame(this) ||
1706 nsLayoutUtils::FirstContinuationOrIBSplitSibling(this)
1707 ->IsPrimaryFrame()) &&
1708 nsLayoutUtils::HasAnimationOfPropertySet(
1709 this, nsCSSPropertyIDSet::OpacityProperties(), aEffectSet));
1710}
1711
1712bool nsIFrame::HasOpacityInternal(float aThreshold,
1713 const nsStyleDisplay* aStyleDisplay,
1714 const nsStyleEffects* aStyleEffects,
1715 EffectSet* aEffectSet) const {
1716 MOZ_ASSERT(0.0 <= aThreshold && aThreshold <= 1.0, "Invalid argument")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(0.0 <= aThreshold && aThreshold <= 1.0
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(0.0 <= aThreshold && aThreshold <= 1.0
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"0.0 <= aThreshold && aThreshold <= 1.0" " (" "Invalid argument"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1716); AnnotateMozCrashReason("MOZ_ASSERT" "(" "0.0 <= aThreshold && aThreshold <= 1.0"
") (" "Invalid argument" ")"); do { *((volatile int*)__null)
= 1716; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
1717 if (aStyleEffects->mOpacity < aThreshold ||
1718 aStyleDisplay->mWillChange.bits & StyleWillChangeBits::OPACITY) {
1719 return true;
1720 }
1721
1722 if (!mMayHaveOpacityAnimation) {
1723 return false;
1724 }
1725
1726 return HasAnimationOfOpacity(aEffectSet);
1727}
1728
1729bool nsIFrame::IsSVGTransformed(gfx::Matrix* aOwnTransforms,
1730 gfx::Matrix* aFromParentTransforms) const {
1731 return false;
1732}
1733
1734bool nsIFrame::Extend3DContext(const nsStyleDisplay* aStyleDisplay,
1735 const nsStyleEffects* aStyleEffects,
1736 mozilla::EffectSet* aEffectSetForOpacity) const {
1737 if (!HasAnyStateBits(NS_FRAME_MAY_BE_TRANSFORMED)) {
1738 return false;
1739 }
1740 const nsStyleDisplay* disp = StyleDisplayWithOptionalParam(aStyleDisplay);
1741 if (disp->mTransformStyle != StyleTransformStyle::Preserve3d ||
1742 !SupportsCSSTransforms()) {
1743 return false;
1744 }
1745
1746 // If we're all scroll frame, then all descendants will be clipped, so we
1747 // can't preserve 3d.
1748 if (IsScrollFrame()) {
1749 return false;
1750 }
1751
1752 const nsStyleEffects* effects = StyleEffectsWithOptionalParam(aStyleEffects);
1753 if (HasOpacity(disp, effects, aEffectSetForOpacity)) {
1754 return false;
1755 }
1756
1757 return ShouldApplyOverflowClipping(disp) == PhysicalAxes::None &&
1758 !GetClipPropClipRect(disp, effects, GetSize()) &&
1759 !SVGIntegrationUtils::UsingEffectsForFrame(this) &&
1760 !effects->HasMixBlendMode() &&
1761 disp->mIsolation != StyleIsolation::Isolate;
1762}
1763
1764bool nsIFrame::Combines3DTransformWithAncestors() const {
1765 // Check these first as they are faster then both calls below and are we are
1766 // likely to hit the early return (backface hidden is uncommon and
1767 // GetReferenceFrame is a hot caller of this which only calls this if
1768 // IsCSSTransformed is false).
1769 if (!IsCSSTransformed() && !BackfaceIsHidden()) {
1770 return false;
1771 }
1772 nsIFrame* parent = GetClosestFlattenedTreeAncestorPrimaryFrame();
1773 return parent && parent->Extend3DContext();
1774}
1775
1776bool nsIFrame::In3DContextAndBackfaceIsHidden() const {
1777 // While both tests fail most of the time, test BackfaceIsHidden()
1778 // first since it's likely to fail faster.
1779 return BackfaceIsHidden() && Combines3DTransformWithAncestors();
1780}
1781
1782bool nsIFrame::HasPerspective() const {
1783 if (!IsCSSTransformed()) {
1784 return false;
1785 }
1786 nsIFrame* parent = GetClosestFlattenedTreeAncestorPrimaryFrame();
1787 if (!parent) {
1788 return false;
1789 }
1790 return parent->ChildrenHavePerspective();
1791}
1792
1793nsRect nsIFrame::GetContentRectRelativeToSelf() const {
1794 nsMargin bp = GetUsedBorderAndPadding().ApplySkipSides(GetSkipSides());
1795 nsRect r(0, 0, mRect.width, mRect.height);
1796 r.Deflate(bp);
1797 return r;
1798}
1799
1800nsRect nsIFrame::GetContentRect() const {
1801 return GetContentRectRelativeToSelf() + GetPosition();
1802}
1803
1804bool nsIFrame::ComputeBorderRadii(const BorderRadius& aBorderRadius,
1805 const nsSize& aFrameSize,
1806 const nsSize& aBorderArea, Sides aSkipSides,
1807 nscoord aRadii[8]) {
1808 // Percentages are relative to whichever side they're on.
1809 for (const auto i : mozilla::AllPhysicalHalfCorners()) {
1810 const LengthPercentage& c = aBorderRadius.Get(i);
1811 nscoord axis = HalfCornerIsX(i) ? aFrameSize.width : aFrameSize.height;
1812 aRadii[i] = std::max(0, c.Resolve(axis));
1813 }
1814
1815 if (aSkipSides.Top()) {
1816 aRadii[eCornerTopLeftX] = 0;
1817 aRadii[eCornerTopLeftY] = 0;
1818 aRadii[eCornerTopRightX] = 0;
1819 aRadii[eCornerTopRightY] = 0;
1820 }
1821
1822 if (aSkipSides.Right()) {
1823 aRadii[eCornerTopRightX] = 0;
1824 aRadii[eCornerTopRightY] = 0;
1825 aRadii[eCornerBottomRightX] = 0;
1826 aRadii[eCornerBottomRightY] = 0;
1827 }
1828
1829 if (aSkipSides.Bottom()) {
1830 aRadii[eCornerBottomRightX] = 0;
1831 aRadii[eCornerBottomRightY] = 0;
1832 aRadii[eCornerBottomLeftX] = 0;
1833 aRadii[eCornerBottomLeftY] = 0;
1834 }
1835
1836 if (aSkipSides.Left()) {
1837 aRadii[eCornerBottomLeftX] = 0;
1838 aRadii[eCornerBottomLeftY] = 0;
1839 aRadii[eCornerTopLeftX] = 0;
1840 aRadii[eCornerTopLeftY] = 0;
1841 }
1842
1843 // css3-background specifies this algorithm for reducing
1844 // corner radii when they are too big.
1845 bool haveRadius = false;
1846 double ratio = 1.0f;
1847 for (const auto side : mozilla::AllPhysicalSides()) {
1848 uint32_t hc1 = SideToHalfCorner(side, false, true);
1849 uint32_t hc2 = SideToHalfCorner(side, true, true);
1850 nscoord length =
1851 SideIsVertical(side) ? aBorderArea.height : aBorderArea.width;
1852 nscoord sum = aRadii[hc1] + aRadii[hc2];
1853 if (sum) {
1854 haveRadius = true;
1855 // avoid floating point division in the normal case
1856 if (length < sum) {
1857 ratio = std::min(ratio, double(length) / sum);
1858 }
1859 }
1860 }
1861 if (ratio < 1.0) {
1862 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1863 aRadii[corner] *= ratio;
1864 }
1865 }
1866
1867 return haveRadius;
1868}
1869
1870void nsIFrame::AdjustBorderRadii(nscoord aRadii[8], const nsMargin& aOffsets) {
1871 auto AdjustOffset = [](const uint32_t aRadius, const nscoord aOffset) {
1872 // Implement the cubic formula to adjust offset when aOffset > 0 and
1873 // aRadius / aOffset < 1.
1874 // https://drafts.csswg.org/css-shapes/#valdef-shape-box-margin-box
1875 if (aOffset > 0) {
1876 const double ratio = aRadius / double(aOffset);
1877 if (ratio < 1.0) {
1878 return nscoord(aOffset * (1.0 + std::pow(ratio - 1, 3)));
1879 }
1880 }
1881 return aOffset;
1882 };
1883
1884 for (const auto side : mozilla::AllPhysicalSides()) {
1885 const nscoord offset = aOffsets.Side(side);
1886 const uint32_t hc1 = SideToHalfCorner(side, false, false);
1887 const uint32_t hc2 = SideToHalfCorner(side, true, false);
1888 if (aRadii[hc1] > 0) {
1889 const nscoord offset1 = AdjustOffset(aRadii[hc1], offset);
1890 aRadii[hc1] = std::max(0, aRadii[hc1] + offset1);
1891 }
1892 if (aRadii[hc2] > 0) {
1893 const nscoord offset2 = AdjustOffset(aRadii[hc2], offset);
1894 aRadii[hc2] = std::max(0, aRadii[hc2] + offset2);
1895 }
1896 }
1897}
1898
1899static inline bool RadiiAreDefinitelyZero(const BorderRadius& aBorderRadius) {
1900 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1901 if (!aBorderRadius.Get(corner).IsDefinitelyZero()) {
1902 return false;
1903 }
1904 }
1905 return true;
1906}
1907
1908/* virtual */
1909bool nsIFrame::GetBorderRadii(const nsSize& aFrameSize,
1910 const nsSize& aBorderArea, Sides aSkipSides,
1911 nscoord aRadii[8]) const {
1912 if (!mMayHaveRoundedCorners) {
1913 memset(aRadii, 0, sizeof(nscoord) * 8);
1914 return false;
1915 }
1916
1917 if (IsThemed()) {
1918 // When we're themed, the native theme code draws the border and
1919 // background, and therefore it doesn't make sense to tell other
1920 // code that's interested in border-radius that we have any radii.
1921 //
1922 // In an ideal world, we might have a way for the them to tell us an
1923 // border radius, but since we don't, we're better off assuming
1924 // zero.
1925 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1926 aRadii[corner] = 0;
1927 }
1928 return false;
1929 }
1930
1931 const auto& radii = StyleBorder()->mBorderRadius;
1932 const bool hasRadii =
1933 ComputeBorderRadii(radii, aFrameSize, aBorderArea, aSkipSides, aRadii);
1934 if (!hasRadii) {
1935 // TODO(emilio): Maybe we can just remove this bit and do the
1936 // IsDefinitelyZero check unconditionally. That should still avoid most of
1937 // the work, though maybe not the cache miss of going through the style and
1938 // the border struct.
1939 const_cast<nsIFrame*>(this)->mMayHaveRoundedCorners =
1940 !RadiiAreDefinitelyZero(radii);
1941 }
1942 return hasRadii;
1943}
1944
1945bool nsIFrame::GetBorderRadii(nscoord aRadii[8]) const {
1946 nsSize sz = GetSize();
1947 return GetBorderRadii(sz, sz, GetSkipSides(), aRadii);
1948}
1949
1950bool nsIFrame::GetMarginBoxBorderRadii(nscoord aRadii[8]) const {
1951 return GetBoxBorderRadii(aRadii, GetUsedMargin());
1952}
1953
1954bool nsIFrame::GetPaddingBoxBorderRadii(nscoord aRadii[8]) const {
1955 return GetBoxBorderRadii(aRadii, -GetUsedBorder());
1956}
1957
1958bool nsIFrame::GetContentBoxBorderRadii(nscoord aRadii[8]) const {
1959 return GetBoxBorderRadii(aRadii, -GetUsedBorderAndPadding());
1960}
1961
1962bool nsIFrame::GetBoxBorderRadii(nscoord aRadii[8],
1963 const nsMargin& aOffsets) const {
1964 if (!GetBorderRadii(aRadii)) {
1965 return false;
1966 }
1967 AdjustBorderRadii(aRadii, aOffsets);
1968 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1969 if (aRadii[corner]) {
1970 return true;
1971 }
1972 }
1973 return false;
1974}
1975
1976bool nsIFrame::GetShapeBoxBorderRadii(nscoord aRadii[8]) const {
1977 using Tag = StyleShapeOutside::Tag;
1978 auto& shapeOutside = StyleDisplay()->mShapeOutside;
1979 auto box = StyleShapeBox::MarginBox;
1980 switch (shapeOutside.tag) {
1981 case Tag::Image:
1982 case Tag::None:
1983 return false;
1984 case Tag::Box:
1985 box = shapeOutside.AsBox();
1986 break;
1987 case Tag::Shape:
1988 box = shapeOutside.AsShape()._1;
1989 break;
1990 }
1991
1992 switch (box) {
1993 case StyleShapeBox::ContentBox:
1994 return GetContentBoxBorderRadii(aRadii);
1995 case StyleShapeBox::PaddingBox:
1996 return GetPaddingBoxBorderRadii(aRadii);
1997 case StyleShapeBox::BorderBox:
1998 return GetBorderRadii(aRadii);
1999 case StyleShapeBox::MarginBox:
2000 return GetMarginBoxBorderRadii(aRadii);
2001 default:
2002 MOZ_ASSERT_UNREACHABLE("Unexpected box value")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"Unexpected box value" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2002); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Unexpected box value" ")"); do {
*((volatile int*)__null) = 2002; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
2003 return false;
2004 }
2005}
2006
2007ComputedStyle* nsIFrame::GetAdditionalComputedStyle(int32_t aIndex) const {
2008 MOZ_ASSERT(aIndex >= 0, "invalid index number")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aIndex >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aIndex >= 0))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("aIndex >= 0"
" (" "invalid index number" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2008); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aIndex >= 0"
") (" "invalid index number" ")"); do { *((volatile int*)__null
) = 2008; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
2009 return nullptr;
2010}
2011
2012void nsIFrame::SetAdditionalComputedStyle(int32_t aIndex,
2013 ComputedStyle* aComputedStyle) {
2014 MOZ_ASSERT(aIndex >= 0, "invalid index number")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aIndex >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aIndex >= 0))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("aIndex >= 0"
" (" "invalid index number" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2014); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aIndex >= 0"
") (" "invalid index number" ")"); do { *((volatile int*)__null
) = 2014; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
2015}
2016
2017nscoord nsIFrame::SynthesizeFallbackBaseline(
2018 WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
2019 const auto margin = GetLogicalUsedMargin(aWM);
2020 NS_ASSERTION(!IsSubtreeDirty(), "frame must not be dirty")do { if (!(!IsSubtreeDirty())) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "frame must not be dirty", "!IsSubtreeDirty()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2020); MOZ_PretendNoReturn(); } } while (0)
;
2021 if (aWM.IsCentralBaseline()) {
2022 return (BSize(aWM) + GetLogicalUsedMargin(aWM).BEnd(aWM)) / 2;
2023 }
2024 // Baseline for inverted line content is the top (block-start) margin edge,
2025 // as the frame is in effect "flipped" for alignment purposes.
2026 if (aWM.IsLineInverted()) {
2027 const auto marginStart = margin.BStart(aWM);
2028 return aBaselineGroup == BaselineSharingGroup::First
2029 ? -marginStart
2030 : BSize(aWM) + marginStart;
2031 }
2032 // Otherwise, the bottom margin edge, per CSS2.1's definition of the
2033 // 'baseline' value of 'vertical-align'.
2034 const auto marginEnd = margin.BEnd(aWM);
2035 return aBaselineGroup == BaselineSharingGroup::First ? BSize(aWM) + marginEnd
2036 : -marginEnd;
2037}
2038
2039nscoord nsIFrame::GetLogicalBaseline(WritingMode aWM) const {
2040 return GetLogicalBaseline(aWM, GetDefaultBaselineSharingGroup(),
2041 BaselineExportContext::LineLayout);
2042}
2043
2044nscoord nsIFrame::GetLogicalBaseline(
2045 WritingMode aWM, BaselineSharingGroup aBaselineGroup,
2046 BaselineExportContext aExportContext) const {
2047 const auto result =
2048 GetNaturalBaselineBOffset(aWM, aBaselineGroup, aExportContext)
2049 .valueOrFrom([this, aWM, aBaselineGroup]() {
2050 return SynthesizeFallbackBaseline(aWM, aBaselineGroup);
2051 });
2052 if (aBaselineGroup == BaselineSharingGroup::Last) {
2053 return BSize(aWM) - result;
2054 }
2055 return result;
2056}
2057
2058const nsFrameList& nsIFrame::GetChildList(ChildListID aListID) const {
2059 if (IsAbsoluteContainer() && aListID == GetAbsoluteListID()) {
2060 return GetAbsoluteContainingBlock()->GetChildList();
2061 } else {
2062 return nsFrameList::EmptyList();
2063 }
2064}
2065
2066void nsIFrame::GetChildLists(nsTArray<ChildList>* aLists) const {
2067 if (IsAbsoluteContainer()) {
2068 const nsFrameList& absoluteList =
2069 GetAbsoluteContainingBlock()->GetChildList();
2070 absoluteList.AppendIfNonempty(aLists, GetAbsoluteListID());
2071 }
2072}
2073
2074AutoTArray<nsIFrame::ChildList, 4> nsIFrame::CrossDocChildLists() {
2075 AutoTArray<ChildList, 4> childLists;
2076 nsSubDocumentFrame* subdocumentFrame = do_QueryFrame(this);
2077 if (subdocumentFrame) {
2078 // Descend into the subdocument
2079 nsIFrame* root = subdocumentFrame->GetSubdocumentRootFrame();
2080 if (root) {
2081 childLists.EmplaceBack(
2082 nsFrameList(root, nsLayoutUtils::GetLastSibling(root)),
2083 FrameChildListID::Principal);
2084 }
2085 }
2086
2087 GetChildLists(&childLists);
2088 return childLists;
2089}
2090
2091nsIFrame::CaretBlockAxisMetrics nsIFrame::GetCaretBlockAxisMetrics(
2092 mozilla::WritingMode aWM, const nsFontMetrics& aFM) const {
2093 // Note(dshin): Ultimately, this does something highly similar (But still
2094 // different) to `nsLayoutUtils::GetFirstLinePosition`.
2095 const auto baseline = GetCaretBaseline();
2096 nscoord ascent = 0, descent = 0;
2097 ascent = aFM.MaxAscent();
2098 descent = aFM.MaxDescent();
2099 const nscoord height = ascent + descent;
2100 if (aWM.IsVertical() && aWM.IsLineInverted()) {
2101 return CaretBlockAxisMetrics{.mOffset = baseline - descent,
2102 .mExtent = height};
2103 }
2104 return CaretBlockAxisMetrics{.mOffset = baseline - ascent, .mExtent = height};
2105}
2106
2107const nsAtom* nsIFrame::ComputePageValue() const {
2108 const nsAtom* value = nsGkAtoms::_empty;
2109 const nsIFrame* frame = this;
2110 // Find what CSS page name value this frame's subtree has, if any.
2111 // Starting with this frame, check if a page name other than auto is present,
2112 // and record it if so. Then, if the current frame is a container frame, find
2113 // the first non-placeholder child and repeat.
2114 // This will find the most deeply nested first in-flow child of this frame's
2115 // subtree, and return its page name (with auto resolved if applicable, and
2116 // subtrees with no page-names returning the empty atom rather than null).
2117 do {
2118 if (const nsAtom* maybePageName = frame->GetStylePageName()) {
2119 value = maybePageName;
2120 }
2121 // Get the next frame to read from.
2122 const nsIFrame* firstNonPlaceholderFrame = nullptr;
2123 // If this is a container frame, inspect its in-flow children.
2124 if (const nsContainerFrame* containerFrame = do_QueryFrame(frame)) {
2125 for (const nsIFrame* childFrame : containerFrame->PrincipalChildList()) {
2126 if (!childFrame->IsPlaceholderFrame()) {
2127 firstNonPlaceholderFrame = childFrame;
2128 break;
2129 }
2130 }
2131 }
2132 frame = firstNonPlaceholderFrame;
2133 } while (frame);
2134 return value;
2135}
2136
2137Visibility nsIFrame::GetVisibility() const {
2138 if (!HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)) {
2139 return Visibility::Untracked;
2140 }
2141
2142 bool isSet = false;
2143 uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet);
2144
2145 MOZ_ASSERT(isSet,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2147); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2147; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2146 "Should have a VisibilityStateProperty value "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2147); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2147; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2147 "if NS_FRAME_VISIBILITY_IS_TRACKED is set")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2147); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2147; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2148
2149 return visibleCount > 0 ? Visibility::ApproximatelyVisible
2150 : Visibility::ApproximatelyNonVisible;
2151}
2152
2153void nsIFrame::UpdateVisibilitySynchronously() {
2154 mozilla::PresShell* presShell = PresShell();
2155 if (!presShell) {
2156 return;
2157 }
2158
2159 if (presShell->AssumeAllFramesVisible()) {
2160 presShell->EnsureFrameInApproximatelyVisibleList(this);
2161 return;
2162 }
2163
2164 bool visible = StyleVisibility()->IsVisible();
2165 nsIFrame* f = GetParent();
2166 nsRect rect = GetRectRelativeToSelf();
2167 nsIFrame* rectFrame = this;
2168 while (f && visible) {
2169 nsIScrollableFrame* sf = do_QueryFrame(f);
2170 if (sf) {
2171 nsRect transformedRect =
2172 nsLayoutUtils::TransformFrameRectToAncestor(rectFrame, rect, f);
2173 if (!sf->IsRectNearlyVisible(transformedRect)) {
2174 visible = false;
2175 break;
2176 }
2177
2178 // In this code we're trying to synchronously update *approximate*
2179 // visibility. (In the future we may update precise visibility here as
2180 // well, which is why the method name does not contain 'approximate'.) The
2181 // IsRectNearlyVisible() check above tells us that the rect we're checking
2182 // is approximately visible within the scrollframe, but we still need to
2183 // ensure that, even if it was scrolled into view, it'd be visible when we
2184 // consider the rest of the document. To do that, we move transformedRect
2185 // to be contained in the scrollport as best we can (it might not fit) to
2186 // pretend that it was scrolled into view.
2187 rect = transformedRect.MoveInsideAndClamp(sf->GetScrollPortRect());
2188 rectFrame = f;
2189 }
2190 nsIFrame* parent = f->GetParent();
2191 if (!parent) {
2192 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(f);
2193 if (parent && parent->PresContext()->IsChrome()) {
2194 break;
2195 }
2196 }
2197 f = parent;
2198 }
2199
2200 if (visible) {
2201 presShell->EnsureFrameInApproximatelyVisibleList(this);
2202 } else {
2203 presShell->RemoveFrameFromApproximatelyVisibleList(this);
2204 }
2205}
2206
2207void nsIFrame::EnableVisibilityTracking() {
2208 if (HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)) {
2209 return; // Nothing to do.
2210 }
2211
2212 MOZ_ASSERT(!HasProperty(VisibilityStateProperty()),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasProperty(VisibilityStateProperty()))>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!HasProperty(VisibilityStateProperty())))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!HasProperty(VisibilityStateProperty())"
" (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2214); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasProperty(VisibilityStateProperty())"
") (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")"); do { *((volatile int*)__null) = 2214; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2213 "Shouldn't have a VisibilityStateProperty value "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasProperty(VisibilityStateProperty()))>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!HasProperty(VisibilityStateProperty())))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!HasProperty(VisibilityStateProperty())"
" (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2214); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasProperty(VisibilityStateProperty())"
") (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")"); do { *((volatile int*)__null) = 2214; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2214 "if NS_FRAME_VISIBILITY_IS_TRACKED is not set")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasProperty(VisibilityStateProperty()))>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!HasProperty(VisibilityStateProperty())))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!HasProperty(VisibilityStateProperty())"
" (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2214); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasProperty(VisibilityStateProperty())"
") (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")"); do { *((volatile int*)__null) = 2214; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2215
2216 // Add the state bit so we know to track visibility for this frame, and
2217 // initialize the frame property.
2218 AddStateBits(NS_FRAME_VISIBILITY_IS_TRACKED);
2219 SetProperty(VisibilityStateProperty(), 0);
2220
2221 mozilla::PresShell* presShell = PresShell();
2222 if (!presShell) {
2223 return;
2224 }
2225
2226 // Schedule a visibility update. This method will virtually always be called
2227 // when layout has changed anyway, so it's very unlikely that any additional
2228 // visibility updates will be triggered by this, but this way we guarantee
2229 // that if this frame is currently visible we'll eventually find out.
2230 presShell->ScheduleApproximateFrameVisibilityUpdateSoon();
2231}
2232
2233void nsIFrame::DisableVisibilityTracking() {
2234 if (!HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)) {
2235 return; // Nothing to do.
2236 }
2237
2238 bool isSet = false;
2239 uint32_t visibleCount = TakeProperty(VisibilityStateProperty(), &isSet);
2240
2241 MOZ_ASSERT(isSet,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2243); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2243; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2242 "Should have a VisibilityStateProperty value "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2243); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2243; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2243 "if NS_FRAME_VISIBILITY_IS_TRACKED is set")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2243); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2243; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2244
2245 RemoveStateBits(NS_FRAME_VISIBILITY_IS_TRACKED);
2246
2247 if (visibleCount == 0) {
2248 return; // We were nonvisible.
2249 }
2250
2251 // We were visible, so send an OnVisibilityChange() notification.
2252 OnVisibilityChange(Visibility::ApproximatelyNonVisible);
2253}
2254
2255void nsIFrame::DecApproximateVisibleCount(
2256 const Maybe<OnNonvisible>& aNonvisibleAction
2257 /* = Nothing() */) {
2258 MOZ_ASSERT(HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED))>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2258); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)"
")"); do { *((volatile int*)__null) = 2258; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2259
2260 bool isSet = false;
2261 uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet);
2262
2263 MOZ_ASSERT(isSet,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2265); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2265; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2264 "Should have a VisibilityStateProperty value "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2265); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2265; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2265 "if NS_FRAME_VISIBILITY_IS_TRACKED is set")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2265); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2265; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2266 MOZ_ASSERT(visibleCount > 0,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(visibleCount > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(visibleCount > 0))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("visibleCount > 0"
" (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2268); AnnotateMozCrashReason("MOZ_ASSERT" "(" "visibleCount > 0"
") (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")"); do { *((volatile int*)__null) = 2268; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2267 "Frame is already nonvisible and we're "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(visibleCount > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(visibleCount > 0))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("visibleCount > 0"
" (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2268); AnnotateMozCrashReason("MOZ_ASSERT" "(" "visibleCount > 0"
") (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")"); do { *((volatile int*)__null) = 2268; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2268 "decrementing its visible count?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(visibleCount > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(visibleCount > 0))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("visibleCount > 0"
" (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2268); AnnotateMozCrashReason("MOZ_ASSERT" "(" "visibleCount > 0"
") (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")"); do { *((volatile int*)__null) = 2268; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2269
2270 visibleCount--;
2271 SetProperty(VisibilityStateProperty(), visibleCount);
2272 if (visibleCount > 0) {
2273 return;
2274 }
2275
2276 // We just became nonvisible, so send an OnVisibilityChange() notification.
2277 OnVisibilityChange(Visibility::ApproximatelyNonVisible, aNonvisibleAction);
2278}
2279
2280void nsIFrame::IncApproximateVisibleCount() {
2281 MOZ_ASSERT(HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED))>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2281); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)"
")"); do { *((volatile int*)__null) = 2281; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2282
2283 bool isSet = false;
2284 uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet);
2285
2286 MOZ_ASSERT(isSet,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2288); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2288; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2287 "Should have a VisibilityStateProperty value "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2288); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2288; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2288 "if NS_FRAME_VISIBILITY_IS_TRACKED is set")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(isSet)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(isSet))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("isSet" " (" "Should have a VisibilityStateProperty value "
"if NS_FRAME_VISIBILITY_IS_TRACKED is set" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2288); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2288; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2289
2290 visibleCount++;
2291 SetProperty(VisibilityStateProperty(), visibleCount);
2292 if (visibleCount > 1) {
2293 return;
2294 }
2295
2296 // We just became visible, so send an OnVisibilityChange() notification.
2297 OnVisibilityChange(Visibility::ApproximatelyVisible);
2298}
2299
2300void nsIFrame::OnVisibilityChange(Visibility aNewVisibility,
2301 const Maybe<OnNonvisible>& aNonvisibleAction
2302 /* = Nothing() */) {
2303 // XXX(seth): In bug 1218990 we'll implement visibility tracking for CSS
2304 // images here.
2305}
2306
2307static nsIFrame* GetActiveSelectionFrame(nsPresContext* aPresContext,
2308 nsIFrame* aFrame) {
2309 nsIContent* capturingContent = PresShell::GetCapturingContent();
2310 if (capturingContent) {
2311 nsIFrame* activeFrame = aPresContext->GetPrimaryFrameFor(capturingContent);
2312 return activeFrame ? activeFrame : aFrame;
2313 }
2314
2315 return aFrame;
2316}
2317
2318int16_t nsIFrame::DetermineDisplaySelection() {
2319 int16_t selType = nsISelectionController::SELECTION_OFF;
2320
2321 nsCOMPtr<nsISelectionController> selCon;
2322 nsresult result =
2323 GetSelectionController(PresContext(), getter_AddRefs(selCon));
2324 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) && selCon) {
2325 result = selCon->GetDisplaySelection(&selType);
2326 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) &&
2327 (selType != nsISelectionController::SELECTION_OFF)) {
2328 // Check whether style allows selection.
2329 if (!IsSelectable(nullptr)) {
2330 selType = nsISelectionController::SELECTION_OFF;
2331 }
2332 }
2333 }
2334 return selType;
2335}
2336
2337static Element* FindElementAncestorForMozSelection(nsIContent* aContent) {
2338 NS_ENSURE_TRUE(aContent, nullptr)do { if ((__builtin_expect(!!(!(aContent)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aContent" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2338); return nullptr; } } while (false)
;
2339 while (aContent && aContent->IsInNativeAnonymousSubtree()) {
2340 aContent = aContent->GetClosestNativeAnonymousSubtreeRootParentOrHost();
2341 }
2342 NS_ASSERTION(aContent, "aContent isn't in non-anonymous tree?")do { if (!(aContent)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "aContent isn't in non-anonymous tree?"
, "aContent", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2342); MOZ_PretendNoReturn(); } } while (0)
;
2343 return aContent ? aContent->GetAsElementOrParentElement() : nullptr;
2344}
2345
2346already_AddRefed<ComputedStyle> nsIFrame::ComputeSelectionStyle(
2347 int16_t aSelectionStatus) const {
2348 // Just bail out if not a selection-status that ::selection applies to.
2349 if (aSelectionStatus != nsISelectionController::SELECTION_ON &&
2350 aSelectionStatus != nsISelectionController::SELECTION_DISABLED) {
2351 return nullptr;
2352 }
2353 Element* element = FindElementAncestorForMozSelection(GetContent());
2354 if (!element) {
2355 return nullptr;
2356 }
2357 RefPtr<ComputedStyle> pseudoStyle =
2358 PresContext()->StyleSet()->ProbePseudoElementStyle(
2359 *element, PseudoStyleType::selection, nullptr, Style());
2360 if (!pseudoStyle) {
2361 return nullptr;
2362 }
2363 // When in high-contrast mode, the style system ends up ignoring the color
2364 // declarations, which means that the ::selection style becomes the inherited
2365 // color, and default background. That's no good.
2366 // When force-color-adjust is set to none allow using the color styles,
2367 // as they will not be replaced.
2368 if (PresContext()->ForcingColors() &&
2369 pseudoStyle->StyleText()->mForcedColorAdjust !=
2370 StyleForcedColorAdjust::None) {
2371 return nullptr;
2372 }
2373 return do_AddRef(pseudoStyle);
2374}
2375
2376already_AddRefed<ComputedStyle> nsIFrame::ComputeHighlightSelectionStyle(
2377 nsAtom* aHighlightName) {
2378 Element* element = FindElementAncestorForMozSelection(GetContent());
2379 if (!element) {
2380 return nullptr;
2381 }
2382 return PresContext()->StyleSet()->ProbePseudoElementStyle(
2383 *element, PseudoStyleType::highlight, aHighlightName, Style());
2384}
2385
2386template <typename SizeOrMaxSize>
2387static inline bool IsIntrinsicKeyword(const SizeOrMaxSize& aSize) {
2388 // All keywords other than auto/none/-moz-available depend on intrinsic sizes.
2389 return aSize.IsMaxContent() || aSize.IsMinContent() || aSize.IsFitContent() ||
2390 aSize.IsFitContentFunction();
2391}
2392
2393bool nsIFrame::CanBeDynamicReflowRoot() const {
2394 const auto& display = *StyleDisplay();
2395 if (IsLineParticipant() || display.mDisplay.IsRuby() ||
2396 display.IsInnerTableStyle() ||
2397 display.DisplayInside() == StyleDisplayInside::Table) {
2398 // We have a display type where 'width' and 'height' don't actually set the
2399 // width or height (i.e., the size depends on content).
2400 MOZ_ASSERT(!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT))>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT)))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT)"
" (" "should not have dynamic reflow root bit" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2401); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT)"
") (" "should not have dynamic reflow root bit" ")"); do { *
((volatile int*)__null) = 2401; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
2401 "should not have dynamic reflow root bit")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT))>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT)))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT)"
" (" "should not have dynamic reflow root bit" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2401); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT)"
") (" "should not have dynamic reflow root bit" ")"); do { *
((volatile int*)__null) = 2401; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
2402 return false;
2403 }
2404
2405 // In general, frames that have contain:layout+size can be reflow roots.
2406 // (One exception: table-wrapper frames don't work well as reflow roots,
2407 // because their inner-table ReflowInput init path tries to reuse & deref
2408 // the wrapper's containing block's reflow input, which may be null if we
2409 // initiate reflow from the table-wrapper itself.)
2410 //
2411 // Changes to `contain` force frame reconstructions, so we used to use
2412 // NS_FRAME_REFLOW_ROOT, this bit could be set for the whole lifetime of
2413 // this frame. But after the support of `content-visibility: auto` which
2414 // is with contain layout + size when it's not relevant to user, and only
2415 // with contain layout when it is relevant. The frame does not reconstruct
2416 // when the relevancy changes. So we use NS_FRAME_DYNAMIC_REFLOW_ROOT instead.
2417 //
2418 // We place it above the pref check on purpose, to make sure it works for
2419 // containment even with the pref disabled.
2420 if (display.IsContainLayout() && GetContainSizeAxes().IsBoth()) {
2421 return true;
2422 }
2423
2424 if (!StaticPrefs::layout_dynamic_reflow_roots_enabled()) {
2425 return false;
2426 }
2427
2428 // We can't serve as a dynamic reflow root if our used 'width' and 'height'
2429 // might be influenced by content.
2430 //
2431 // FIXME: For display:block, we should probably optimize inline-size: auto.
2432 // FIXME: Other flex and grid cases?
2433 const auto& pos = *StylePosition();
2434 const auto& width = pos.mWidth;
2435 const auto& height = pos.mHeight;
2436 if (!width.IsLengthPercentage() || width.HasPercent() ||
2437 !height.IsLengthPercentage() || height.HasPercent() ||
2438 IsIntrinsicKeyword(pos.mMinWidth) || IsIntrinsicKeyword(pos.mMaxWidth) ||
2439 IsIntrinsicKeyword(pos.mMinHeight) ||
2440 IsIntrinsicKeyword(pos.mMaxHeight) ||
2441 ((pos.mMinWidth.IsAuto() || pos.mMinHeight.IsAuto()) &&
2442 IsFlexOrGridItem())) {
2443 return false;
2444 }
2445
2446 // If our flex-basis is 'auto', it'll defer to 'width' (or 'height') which
2447 // we've already checked. Otherwise, it preempts them, so we need to
2448 // perform the same "could-this-value-be-influenced-by-content" checks that
2449 // we performed for 'width' and 'height' above.
2450 if (IsFlexItem()) {
2451 const auto& flexBasis = pos.mFlexBasis;
2452 if (!flexBasis.IsAuto()) {
2453 if (!flexBasis.IsSize() || !flexBasis.AsSize().IsLengthPercentage() ||
2454 flexBasis.AsSize().HasPercent()) {
2455 return false;
2456 }
2457 }
2458 }
2459
2460 if (!IsFixedPosContainingBlock()) {
2461 // We can't treat this frame as a reflow root, since dynamic changes
2462 // to absolutely-positioned frames inside of it require that we
2463 // reflow the placeholder before we reflow the absolutely positioned
2464 // frame.
2465 // FIXME: Alternatively, we could sort the reflow roots in
2466 // PresShell::ProcessReflowCommands by depth in the tree, from
2467 // deepest to least deep. However, for performance (FIXME) we
2468 // should really be sorting them in the opposite order!
2469 return false;
2470 }
2471
2472 // If we participate in a container's block reflow context, or margins
2473 // can collapse through us, we can't be a dynamic reflow root.
2474 if (IsBlockFrameOrSubclass() &&
2475 !HasAllStateBits(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT)) {
2476 return false;
2477 }
2478
2479 // Subgrids are never reflow roots, but 'contain:layout/paint' prevents
2480 // creating a subgrid in the first place.
2481 if (pos.mGridTemplateColumns.IsSubgrid() ||
2482 pos.mGridTemplateRows.IsSubgrid()) {
2483 // NOTE: we could check that 'display' of our parent's primary frame is
2484 // '[inline-]grid' here but that's probably not worth it in practice.
2485 if (!display.IsContainLayout() && !display.IsContainPaint()) {
2486 return false;
2487 }
2488 }
2489
2490 // If we are split, we can't be a dynamic reflow root. Our reflow status may
2491 // change after reflow, and our parent is responsible to create or delete our
2492 // next-in-flow.
2493 if (GetPrevContinuation() || GetNextContinuation()) {
2494 return false;
2495 }
2496
2497 return true;
2498}
2499
2500/********************************************************
2501 * Refreshes each content's frame
2502 *********************************************************/
2503
2504void nsIFrame::DisplayOutlineUnconditional(nsDisplayListBuilder* aBuilder,
2505 const nsDisplayListSet& aLists) {
2506 // Per https://drafts.csswg.org/css-tables-3/#global-style-overrides:
2507 // "All css properties of table-column and table-column-group boxes are
2508 // ignored, except when explicitly specified by this specification."
2509 // CSS outlines fall into this category, so we skip them on these boxes.
2510 MOZ_ASSERT(!IsTableColGroupFrame() && !IsTableColFrame())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!IsTableColGroupFrame() && !IsTableColFrame(
))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!IsTableColGroupFrame() && !IsTableColFrame(
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!IsTableColGroupFrame() && !IsTableColFrame()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2510); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsTableColGroupFrame() && !IsTableColFrame()"
")"); do { *((volatile int*)__null) = 2510; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2511 const auto& outline = *StyleOutline();
2512
2513 if (!outline.ShouldPaintOutline()) {
2514 return;
2515 }
2516
2517 // Outlines are painted by the table wrapper frame.
2518 if (IsTableFrame()) {
2519 return;
2520 }
2521
2522 if (HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT) &&
2523 ScrollableOverflowRect().IsEmpty()) {
2524 // Skip parts of IB-splits with an empty overflow rect, see bug 434301.
2525 // We may still want to fix some of the overflow area calculations over in
2526 // that bug.
2527 return;
2528 }
2529
2530 // We don't display outline-style: auto on themed frames that have their own
2531 // focus indicators.
2532 if (outline.mOutlineStyle.IsAuto()) {
2533 auto* disp = StyleDisplay();
2534 if (IsThemed(disp) && PresContext()->Theme()->ThemeDrawsFocusForWidget(
2535 this, disp->EffectiveAppearance())) {
2536 return;
2537 }
2538 }
2539
2540 aLists.Outlines()->AppendNewToTop<nsDisplayOutline>(aBuilder, this);
2541}
2542
2543void nsIFrame::DisplayOutline(nsDisplayListBuilder* aBuilder,
2544 const nsDisplayListSet& aLists) {
2545 if (!IsVisibleForPainting()) return;
2546
2547 DisplayOutlineUnconditional(aBuilder, aLists);
2548}
2549
2550void nsIFrame::DisplayInsetBoxShadowUnconditional(
2551 nsDisplayListBuilder* aBuilder, nsDisplayList* aList) {
2552 // XXXbz should box-shadow for rows/rowgroups/columns/colgroups get painted
2553 // just because we're visible? Or should it depend on the cell visibility
2554 // when we're not the whole table?
2555 const auto* effects = StyleEffects();
2556 if (effects->HasBoxShadowWithInset(true)) {
2557 aList->AppendNewToTop<nsDisplayBoxShadowInner>(aBuilder, this);
2558 }
2559}
2560
2561void nsIFrame::DisplayInsetBoxShadow(nsDisplayListBuilder* aBuilder,
2562 nsDisplayList* aList) {
2563 if (!IsVisibleForPainting()) return;
2564
2565 DisplayInsetBoxShadowUnconditional(aBuilder, aList);
2566}
2567
2568void nsIFrame::DisplayOutsetBoxShadowUnconditional(
2569 nsDisplayListBuilder* aBuilder, nsDisplayList* aList) {
2570 // XXXbz should box-shadow for rows/rowgroups/columns/colgroups get painted
2571 // just because we're visible? Or should it depend on the cell visibility
2572 // when we're not the whole table?
2573 const auto* effects = StyleEffects();
2574 if (effects->HasBoxShadowWithInset(false)) {
2575 aList->AppendNewToTop<nsDisplayBoxShadowOuter>(aBuilder, this);
2576 }
2577}
2578
2579void nsIFrame::DisplayOutsetBoxShadow(nsDisplayListBuilder* aBuilder,
2580 nsDisplayList* aList) {
2581 if (!IsVisibleForPainting()) return;
2582
2583 DisplayOutsetBoxShadowUnconditional(aBuilder, aList);
2584}
2585
2586void nsIFrame::DisplayCaret(nsDisplayListBuilder* aBuilder,
2587 nsDisplayList* aList) {
2588 if (!IsVisibleForPainting()) return;
2589
2590 aList->AppendNewToTop<nsDisplayCaret>(aBuilder, this);
2591}
2592
2593nscolor nsIFrame::GetCaretColorAt(int32_t aOffset) {
2594 return nsLayoutUtils::GetColor(this, &nsStyleUI::mCaretColor);
2595}
2596
2597auto nsIFrame::ComputeShouldPaintBackground() const -> ShouldPaintBackground {
2598 nsPresContext* pc = PresContext();
2599 ShouldPaintBackground settings{pc->GetBackgroundColorDraw(),
2600 pc->GetBackgroundImageDraw()};
2601 if (settings.mColor && settings.mImage) {
2602 return settings;
2603 }
2604
2605 if (StyleVisibility()->mPrintColorAdjust == StylePrintColorAdjust::Exact) {
2606 return {true, true};
2607 }
2608
2609 return settings;
2610}
2611
2612bool nsIFrame::DisplayBackgroundUnconditional(nsDisplayListBuilder* aBuilder,
2613 const nsDisplayListSet& aLists) {
2614 if (aBuilder->IsForEventDelivery() && !aBuilder->HitTestIsForVisibility()) {
2615 // For hit-testing, we generally just need a light-weight data structure
2616 // like nsDisplayEventReceiver. But if the hit-testing is for visibility,
2617 // then we need to know the opaque region in order to determine whether to
2618 // stop or not.
2619 aLists.BorderBackground()->AppendNewToTop<nsDisplayEventReceiver>(aBuilder,
2620 this);
2621 return false;
2622 }
2623
2624 const AppendedBackgroundType result =
2625 nsDisplayBackgroundImage::AppendBackgroundItemsToTop(
2626 aBuilder, this,
2627 GetRectRelativeToSelf() + aBuilder->ToReferenceFrame(this),
2628 aLists.BorderBackground());
2629
2630 if (result == AppendedBackgroundType::None) {
2631 aBuilder->BuildCompositorHitTestInfoIfNeeded(this,
2632 aLists.BorderBackground());
2633 }
2634
2635 return result == AppendedBackgroundType::ThemedBackground;
2636}
2637
2638void nsIFrame::DisplayBorderBackgroundOutline(nsDisplayListBuilder* aBuilder,
2639 const nsDisplayListSet& aLists) {
2640 // The visibility check belongs here since child elements have the
2641 // opportunity to override the visibility property and display even if
2642 // their parent is hidden.
2643 if (!IsVisibleForPainting()) {
2644 return;
2645 }
2646
2647 DisplayOutsetBoxShadowUnconditional(aBuilder, aLists.BorderBackground());
2648
2649 bool bgIsThemed = DisplayBackgroundUnconditional(aBuilder, aLists);
2650 DisplayInsetBoxShadowUnconditional(aBuilder, aLists.BorderBackground());
2651
2652 // If there's a themed background, we should not create a border item.
2653 // It won't be rendered.
2654 // Don't paint borders for tables here, since they paint them in a different
2655 // order.
2656 if (!bgIsThemed && StyleBorder()->HasBorder() && !IsTableFrame()) {
2657 aLists.BorderBackground()->AppendNewToTop<nsDisplayBorder>(aBuilder, this);
2658 }
2659
2660 DisplayOutlineUnconditional(aBuilder, aLists);
2661}
2662
2663inline static bool IsSVGContentWithCSSClip(const nsIFrame* aFrame) {
2664 // The CSS spec says that the 'clip' property only applies to absolutely
2665 // positioned elements, whereas the SVG spec says that it applies to SVG
2666 // elements regardless of the value of the 'position' property. Here we obey
2667 // the CSS spec for outer-<svg> (since that's what we generally do), but
2668 // obey the SVG spec for other SVG elements to which 'clip' applies.
2669 return aFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT) &&
2670 aFrame->GetContent()->IsAnyOfSVGElements(nsGkAtoms::svg,
2671 nsGkAtoms::foreignObject);
2672}
2673
2674Maybe<nsRect> nsIFrame::GetClipPropClipRect(const nsStyleDisplay* aDisp,
2675 const nsStyleEffects* aEffects,
2676 const nsSize& aSize) const {
2677 if (aEffects->mClip.IsAuto() ||
2678 !(aDisp->IsAbsolutelyPositioned(this) || IsSVGContentWithCSSClip(this))) {
2679 return Nothing();
2680 }
2681
2682 auto& clipRect = aEffects->mClip.AsRect();
2683 nsRect rect = clipRect.ToLayoutRect();
2684 if (MOZ_LIKELY(StyleBorder()->mBoxDecorationBreak ==(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Slice), 1))
2685 StyleBoxDecorationBreak::Slice)(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Slice), 1))
) {
2686 // The clip applies to the joined boxes so it's relative the first
2687 // continuation.
2688 nscoord y = 0;
2689 for (nsIFrame* f = GetPrevContinuation(); f; f = f->GetPrevContinuation()) {
2690 y += f->GetRect().height;
2691 }
2692 rect.MoveBy(nsPoint(0, -y));
2693 }
2694
2695 if (clipRect.right.IsAuto()) {
2696 rect.width = aSize.width - rect.x;
2697 }
2698 if (clipRect.bottom.IsAuto()) {
2699 rect.height = aSize.height - rect.y;
2700 }
2701 return Some(rect);
2702}
2703
2704/**
2705 * If the CSS 'overflow' property applies to this frame, and is not
2706 * handled by constructing a dedicated nsHTML/XULScrollFrame, set up clipping
2707 * for that overflow in aBuilder->ClipState() to clip all containing-block
2708 * descendants.
2709 */
2710static void ApplyOverflowClipping(
2711 nsDisplayListBuilder* aBuilder, const nsIFrame* aFrame,
2712 nsIFrame::PhysicalAxes aClipAxes,
2713 DisplayListClipState::AutoClipMultiple& aClipState) {
2714 // Only 'clip' is handled here (and 'hidden' for table frames, and any
2715 // non-'visible' value for blocks in a paginated context).
2716 // We allow 'clip' to apply to any kind of frame. This is required by
2717 // comboboxes which make their display text (an inline frame) have clipping.
2718 MOZ_ASSERT(aClipAxes != nsIFrame::PhysicalAxes::None)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aClipAxes != nsIFrame::PhysicalAxes::None)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(aClipAxes != nsIFrame::PhysicalAxes::None))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("aClipAxes != nsIFrame::PhysicalAxes::None"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2718); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aClipAxes != nsIFrame::PhysicalAxes::None"
")"); do { *((volatile int*)__null) = 2718; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2719 MOZ_ASSERT(aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay()) ==do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay
()) == aClipAxes)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aFrame->ShouldApplyOverflowClipping
(aFrame->StyleDisplay()) == aClipAxes))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay()) == aClipAxes"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2720); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay()) == aClipAxes"
")"); do { *((volatile int*)__null) = 2720; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2720 aClipAxes)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay
()) == aClipAxes)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aFrame->ShouldApplyOverflowClipping
(aFrame->StyleDisplay()) == aClipAxes))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay()) == aClipAxes"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2720); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay()) == aClipAxes"
")"); do { *((volatile int*)__null) = 2720; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2721
2722 nsRect clipRect;
2723 bool haveRadii = false;
2724 nscoord radii[8];
2725 auto* disp = aFrame->StyleDisplay();
2726 // Only deflate the padding if we clip to the content-box in that axis.
2727 auto wm = aFrame->GetWritingMode();
2728 bool cbH = (wm.IsVertical() ? disp->mOverflowClipBoxBlock
2729 : disp->mOverflowClipBoxInline) ==
2730 StyleOverflowClipBox::ContentBox;
2731 bool cbV = (wm.IsVertical() ? disp->mOverflowClipBoxInline
2732 : disp->mOverflowClipBoxBlock) ==
2733 StyleOverflowClipBox::ContentBox;
2734
2735 nsMargin boxMargin = -aFrame->GetUsedPadding();
2736 if (!cbH) {
2737 boxMargin.left = boxMargin.right = nscoord(0);
2738 }
2739 if (!cbV) {
2740 boxMargin.top = boxMargin.bottom = nscoord(0);
2741 }
2742
2743 auto clipMargin = aFrame->OverflowClipMargin(aClipAxes);
2744
2745 boxMargin -= aFrame->GetUsedBorder();
2746 boxMargin += nsMargin(clipMargin.height, clipMargin.width, clipMargin.height,
2747 clipMargin.width);
2748 boxMargin.ApplySkipSides(aFrame->GetSkipSides());
2749
2750 nsRect rect(nsPoint(0, 0), aFrame->GetSize());
2751 rect.Inflate(boxMargin);
2752 if (MOZ_UNLIKELY(!(aClipAxes & nsIFrame::PhysicalAxes::Horizontal))(__builtin_expect(!!(!(aClipAxes & nsIFrame::PhysicalAxes
::Horizontal)), 0))
) {
2753 // NOTE(mats) We shouldn't be clipping at all in this dimension really,
2754 // but clipping in just one axis isn't supported by our GFX APIs so we
2755 // clip to our visual overflow rect instead.
2756 nsRect o = aFrame->InkOverflowRect();
2757 rect.x = o.x;
2758 rect.width = o.width;
2759 }
2760 if (MOZ_UNLIKELY(!(aClipAxes & nsIFrame::PhysicalAxes::Vertical))(__builtin_expect(!!(!(aClipAxes & nsIFrame::PhysicalAxes
::Vertical)), 0))
) {
2761 // See the note above.
2762 nsRect o = aFrame->InkOverflowRect();
2763 rect.y = o.y;
2764 rect.height = o.height;
2765 }
2766 clipRect = rect + aBuilder->ToReferenceFrame(aFrame);
2767 haveRadii = aFrame->GetBoxBorderRadii(radii, boxMargin);
2768 aClipState.ClipContainingBlockDescendantsExtra(clipRect,
2769 haveRadii ? radii : nullptr);
2770}
2771
2772nsSize nsIFrame::OverflowClipMargin(PhysicalAxes aClipAxes) const {
2773 nsSize result;
2774 if (aClipAxes == PhysicalAxes::None) {
2775 return result;
2776 }
2777 const auto& margin = StyleMargin()->mOverflowClipMargin;
2778 if (margin.IsZero()) {
2779 return result;
2780 }
2781 nscoord marginAu = margin.ToAppUnits();
2782 if (aClipAxes & PhysicalAxes::Horizontal) {
2783 result.width = marginAu;
2784 }
2785 if (aClipAxes & PhysicalAxes::Vertical) {
2786 result.height = marginAu;
2787 }
2788 return result;
2789}
2790
2791/**
2792 * Returns whether a display item that gets created with the builder's current
2793 * state will have a scrolled clip, i.e. a clip that is scrolled by a scroll
2794 * frame which does not move the item itself.
2795 */
2796static bool BuilderHasScrolledClip(nsDisplayListBuilder* aBuilder) {
2797 const DisplayItemClipChain* currentClip =
2798 aBuilder->ClipState().GetCurrentCombinedClipChain(aBuilder);
2799 if (!currentClip) {
2800 return false;
2801 }
2802
2803 const ActiveScrolledRoot* currentClipASR = currentClip->mASR;
2804 const ActiveScrolledRoot* currentASR = aBuilder->CurrentActiveScrolledRoot();
2805 return ActiveScrolledRoot::PickDescendant(currentClipASR, currentASR) !=
2806 currentASR;
2807}
2808
2809class AutoSaveRestoreContainsBlendMode {
2810 nsDisplayListBuilder& mBuilder;
2811 bool mSavedContainsBlendMode;
2812
2813 public:
2814 explicit AutoSaveRestoreContainsBlendMode(nsDisplayListBuilder& aBuilder)
2815 : mBuilder(aBuilder),
2816 mSavedContainsBlendMode(aBuilder.ContainsBlendMode()) {}
2817
2818 ~AutoSaveRestoreContainsBlendMode() {
2819 mBuilder.SetContainsBlendMode(mSavedContainsBlendMode);
2820 }
2821};
2822
2823static bool IsFrameOrAncestorApzAware(nsIFrame* aFrame) {
2824 nsIContent* node = aFrame->GetContent();
2825 if (!node) {
2826 return false;
2827 }
2828
2829 do {
2830 if (node->IsNodeApzAware()) {
2831 return true;
2832 }
2833 nsIContent* shadowRoot = node->GetShadowRoot();
2834 if (shadowRoot && shadowRoot->IsNodeApzAware()) {
2835 return true;
2836 }
2837
2838 // Even if the node owning aFrame doesn't have apz-aware event listeners
2839 // itself, its shadow root or display: contents ancestors (which have no
2840 // frames) might, so we need to account for them too.
2841 } while ((node = node->GetFlattenedTreeParent()) && node->IsElement() &&
2842 node->AsElement()->IsDisplayContents());
2843
2844 return false;
2845}
2846
2847static void CheckForApzAwareEventHandlers(nsDisplayListBuilder* aBuilder,
2848 nsIFrame* aFrame) {
2849 if (aBuilder->GetAncestorHasApzAwareEventHandler()) {
2850 return;
2851 }
2852
2853 if (IsFrameOrAncestorApzAware(aFrame)) {
2854 aBuilder->SetAncestorHasApzAwareEventHandler(true);
2855 }
2856}
2857
2858static void UpdateCurrentHitTestInfo(nsDisplayListBuilder* aBuilder,
2859 nsIFrame* aFrame) {
2860 if (!aBuilder->BuildCompositorHitTestInfo()) {
2861 // Compositor hit test info is not used.
2862 return;
2863 }
2864
2865 CheckForApzAwareEventHandlers(aBuilder, aFrame);
2866
2867 const CompositorHitTestInfo info = aFrame->GetCompositorHitTestInfo(aBuilder);
2868 aBuilder->SetCompositorHitTestInfo(info);
2869}
2870
2871/**
2872 * True if aDescendant participates the context aAncestor participating.
2873 */
2874static bool FrameParticipatesIn3DContext(nsIFrame* aAncestor,
2875 nsIFrame* aDescendant) {
2876 MOZ_ASSERT(aAncestor != aDescendant)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aAncestor != aDescendant)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aAncestor != aDescendant))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("aAncestor != aDescendant"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2876); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAncestor != aDescendant"
")"); do { *((volatile int*)__null) = 2876; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2877 MOZ_ASSERT(aAncestor->GetContent() != aDescendant->GetContent())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aAncestor->GetContent() != aDescendant->GetContent
())>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aAncestor->GetContent() != aDescendant->GetContent
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aAncestor->GetContent() != aDescendant->GetContent()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2877); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAncestor->GetContent() != aDescendant->GetContent()"
")"); do { *((volatile int*)__null) = 2877; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2878 MOZ_ASSERT(aAncestor->Extend3DContext())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aAncestor->Extend3DContext())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aAncestor->Extend3DContext
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aAncestor->Extend3DContext()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2878); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAncestor->Extend3DContext()"
")"); do { *((volatile int*)__null) = 2878; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2879
2880 nsIFrame* ancestor = aAncestor->FirstContinuation();
2881 MOZ_ASSERT(ancestor->IsPrimaryFrame())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(ancestor->IsPrimaryFrame())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(ancestor->IsPrimaryFrame(
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("ancestor->IsPrimaryFrame()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2881); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ancestor->IsPrimaryFrame()"
")"); do { *((volatile int*)__null) = 2881; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2882
2883 nsIFrame* frame;
2884 for (frame = aDescendant->GetClosestFlattenedTreeAncestorPrimaryFrame();
2885 frame && ancestor != frame;
2886 frame = frame->GetClosestFlattenedTreeAncestorPrimaryFrame()) {
2887 if (!frame->Extend3DContext()) {
2888 return false;
2889 }
2890 }
2891
2892 MOZ_ASSERT(frame == ancestor)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(frame == ancestor)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(frame == ancestor))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("frame == ancestor"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2892); AnnotateMozCrashReason("MOZ_ASSERT" "(" "frame == ancestor"
")"); do { *((volatile int*)__null) = 2892; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2893 return true;
2894}
2895
2896static bool ItemParticipatesIn3DContext(nsIFrame* aAncestor,
2897 nsDisplayItem* aItem) {
2898 auto type = aItem->GetType();
2899 const bool isContainer = type == DisplayItemType::TYPE_WRAP_LIST ||
2900 type == DisplayItemType::TYPE_CONTAINER;
2901
2902 if (isContainer && aItem->GetChildren()->Length() == 1) {
2903 // If the wraplist has only one child item, use the type of that item.
2904 type = aItem->GetChildren()->GetBottom()->GetType();
2905 }
2906
2907 if (type != DisplayItemType::TYPE_TRANSFORM &&
2908 type != DisplayItemType::TYPE_PERSPECTIVE) {
2909 return false;
2910 }
2911 nsIFrame* transformFrame = aItem->Frame();
2912 if (aAncestor->GetContent() == transformFrame->GetContent()) {
2913 return true;
2914 }
2915 return FrameParticipatesIn3DContext(aAncestor, transformFrame);
2916}
2917
2918static void WrapSeparatorTransform(nsDisplayListBuilder* aBuilder,
2919 nsIFrame* aFrame,
2920 nsDisplayList* aNonParticipants,
2921 nsDisplayList* aParticipants, int aIndex,
2922 nsDisplayItem** aSeparator) {
2923 if (aNonParticipants->IsEmpty()) {
2924 return;
2925 }
2926
2927 nsDisplayTransform* item = MakeDisplayItemWithIndex<nsDisplayTransform>(
2928 aBuilder, aFrame, aIndex, aNonParticipants, aBuilder->GetVisibleRect());
2929
2930 if (*aSeparator == nullptr && item) {
2931 *aSeparator = item;
2932 }
2933
2934 aParticipants->AppendToTop(item);
2935}
2936
2937// Try to compute a clip rect to bound the contents of the mask item
2938// that will be built for |aMaskedFrame|. If we're not able to compute
2939// one, return an empty Maybe.
2940// The returned clip rect, if there is one, is relative to |aMaskedFrame|.
2941static Maybe<nsRect> ComputeClipForMaskItem(
2942 nsDisplayListBuilder* aBuilder, nsIFrame* aMaskedFrame,
2943 const SVGUtils::MaskUsage& aMaskUsage) {
2944 const nsStyleSVGReset* svgReset = aMaskedFrame->StyleSVGReset();
2945
2946 nsPoint offsetToUserSpace =
2947 nsLayoutUtils::ComputeOffsetToUserSpace(aBuilder, aMaskedFrame);
2948 int32_t devPixelRatio = aMaskedFrame->PresContext()->AppUnitsPerDevPixel();
2949 gfxPoint devPixelOffsetToUserSpace =
2950 nsLayoutUtils::PointToGfxPoint(offsetToUserSpace, devPixelRatio);
2951 CSSToLayoutDeviceScale cssToDevScale =
2952 aMaskedFrame->PresContext()->CSSToDevPixelScale();
2953
2954 nsPoint toReferenceFrame;
2955 aBuilder->FindReferenceFrameFor(aMaskedFrame, &toReferenceFrame);
2956
2957 Maybe<gfxRect> combinedClip;
2958 if (aMaskUsage.ShouldApplyBasicShapeOrPath()) {
2959 Maybe<Rect> result =
2960 CSSClipPathInstance::GetBoundingRectForBasicShapeOrPathClip(
2961 aMaskedFrame, svgReset->mClipPath);
2962 if (result) {
2963 combinedClip = Some(ThebesRect(*result));
2964 }
2965 } else if (aMaskUsage.ShouldApplyClipPath()) {
2966 gfxRect result = SVGUtils::GetBBox(
2967 aMaskedFrame,
2968 SVGUtils::eBBoxIncludeClipped | SVGUtils::eBBoxIncludeFill |
2969 SVGUtils::eBBoxIncludeMarkers | SVGUtils::eBBoxIncludeStroke |
2970 SVGUtils::eDoNotClipToBBoxOfContentInsideClipPath);
2971 combinedClip = Some(
2972 ThebesRect((CSSRect::FromUnknownRect(ToRect(result)) * cssToDevScale)
2973 .ToUnknownRect()));
2974 } else {
2975 // The code for this case is adapted from ComputeMaskGeometry().
2976
2977 nsRect borderArea(toReferenceFrame, aMaskedFrame->GetSize());
2978 borderArea -= offsetToUserSpace;
2979
2980 // Use an infinite dirty rect to pass into nsCSSRendering::
2981 // GetImageLayerClip() because we don't have an actual dirty rect to
2982 // pass in. This is fine because the only time GetImageLayerClip() will
2983 // not intersect the incoming dirty rect with something is in the "NoClip"
2984 // case, and we handle that specially.
2985 nsRect dirtyRect(nscoord_MIN(-nscoord((1 << 30) - 1)) / 2, nscoord_MIN(-nscoord((1 << 30) - 1)) / 2, nscoord_MAXnscoord((1 << 30) - 1),
2986 nscoord_MAXnscoord((1 << 30) - 1));
2987
2988 nsIFrame* firstFrame =
2989 nsLayoutUtils::FirstContinuationOrIBSplitSibling(aMaskedFrame);
2990 nsTArray<SVGMaskFrame*> maskFrames;
2991 // XXX check return value?
2992 SVGObserverUtils::GetAndObserveMasks(firstFrame, &maskFrames);
2993
2994 for (uint32_t i = 0; i < maskFrames.Length(); ++i) {
2995 gfxRect clipArea;
2996 if (maskFrames[i]) {
2997 clipArea = maskFrames[i]->GetMaskArea(aMaskedFrame);
2998 clipArea = ThebesRect(
2999 (CSSRect::FromUnknownRect(ToRect(clipArea)) * cssToDevScale)
3000 .ToUnknownRect());
3001 } else {
3002 const auto& layer = svgReset->mMask.mLayers[i];
3003 if (layer.mClip == StyleGeometryBox::NoClip) {
3004 return Nothing();
3005 }
3006
3007 nsCSSRendering::ImageLayerClipState clipState;
3008 nsCSSRendering::GetImageLayerClip(
3009 layer, aMaskedFrame, *aMaskedFrame->StyleBorder(), borderArea,
3010 dirtyRect, false /* aWillPaintBorder */, devPixelRatio, &clipState);
3011 clipArea = clipState.mDirtyRectInDevPx;
3012 }
3013 combinedClip = UnionMaybeRects(combinedClip, Some(clipArea));
3014 }
3015 }
3016 if (combinedClip) {
3017 if (combinedClip->IsEmpty()) {
3018 // *clipForMask might be empty if all mask references are not resolvable
3019 // or the size of them are empty. We still need to create a transparent
3020 // mask before bug 1276834 fixed, so don't clip ctx by an empty rectangle
3021 // for for now.
3022 return Nothing();
3023 }
3024
3025 // Convert to user space.
3026 *combinedClip += devPixelOffsetToUserSpace;
3027
3028 // Round the clip out. In FrameLayerBuilder we round clips to nearest
3029 // pixels, and if we have a really thin clip here, that can cause the
3030 // clip to become empty if we didn't round out here.
3031 // The rounding happens in coordinates that are relative to the reference
3032 // frame, which matches what FrameLayerBuilder does.
3033 combinedClip->RoundOut();
3034
3035 // Convert to app units.
3036 nsRect result =
3037 nsLayoutUtils::RoundGfxRectToAppRect(*combinedClip, devPixelRatio);
3038
3039 // The resulting clip is relative to the reference frame, but the caller
3040 // expects it to be relative to the masked frame, so adjust it.
3041 result -= toReferenceFrame;
3042 return Some(result);
3043 }
3044 return Nothing();
3045}
3046
3047struct AutoCheckBuilder {
3048 explicit AutoCheckBuilder(nsDisplayListBuilder* aBuilder)
3049 : mBuilder(aBuilder) {
3050 aBuilder->Check();
3051 }
3052
3053 ~AutoCheckBuilder() { mBuilder->Check(); }
3054
3055 nsDisplayListBuilder* mBuilder;
3056};
3057
3058/**
3059 * Tries to reuse a top-level stacking context item from the previous paint.
3060 * Returns true if an item was reused, otherwise false.
3061 */
3062bool TryToReuseStackingContextItem(nsDisplayListBuilder* aBuilder,
3063 nsDisplayList* aList, nsIFrame* aFrame) {
3064 if (!aBuilder->IsForPainting() || !aBuilder->IsPartialUpdate() ||
3065 aBuilder->InInvalidSubtree()) {
3066 return false;
3067 }
3068
3069 if (aFrame->IsFrameModified() || aFrame->HasModifiedDescendants()) {
3070 return false;
3071 }
3072
3073 auto& items = aFrame->DisplayItems();
3074 auto* res = std::find_if(
3075 items.begin(), items.end(),
3076 [](nsDisplayItem* aItem) { return aItem->IsPreProcessed(); });
3077
3078 if (res == items.end()) {
3079 return false;
3080 }
3081
3082 nsDisplayItem* container = *res;
3083 MOZ_ASSERT(container->Frame() == aFrame)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(container->Frame() == aFrame)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(container->Frame() == aFrame
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"container->Frame() == aFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3083); AnnotateMozCrashReason("MOZ_ASSERT" "(" "container->Frame() == aFrame"
")"); do { *((volatile int*)__null) = 3083; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3084 DL_LOGD("RDL - Found SC item %p (%s) (frame: %p)", container,do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Debug, "RDL - Found SC item %p (%s) (frame: %p)",
container, container->Name(), container->Frame()); } }
while (0)
3085 container->Name(), container->Frame())do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Debug, "RDL - Found SC item %p (%s) (frame: %p)",
container, container->Name(), container->Frame()); } }
while (0)
;
3086
3087 aList->AppendToTop(container);
3088 aBuilder->ReuseDisplayItem(container);
3089 return true;
3090}
3091
3092void nsIFrame::BuildDisplayListForStackingContext(
3093 nsDisplayListBuilder* aBuilder, nsDisplayList* aList,
3094 bool* aCreatedContainerItem) {
3095#ifdef DEBUG1
3096 DL_LOGV("BuildDisplayListForStackingContext (%p) <", this)do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Verbose)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Verbose, "BuildDisplayListForStackingContext (%p) <"
, this); } } while (0)
;
3097 ScopeExit e(
3098 [this]() { DL_LOGV("> BuildDisplayListForStackingContext (%p)", this)do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Verbose)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Verbose, "> BuildDisplayListForStackingContext (%p)"
, this); } } while (0)
; });
3099#endif
3100
3101 AutoCheckBuilder check(aBuilder);
3102
3103 if (aBuilder->IsReusingStackingContextItems() &&
3104 TryToReuseStackingContextItem(aBuilder, aList, this)) {
3105 if (aCreatedContainerItem) {
3106 *aCreatedContainerItem = true;
3107 }
3108 return;
3109 }
3110
3111 if (HasAnyStateBits(NS_FRAME_TOO_DEEP_IN_FRAME_TREE)) {
3112 return;
3113 }
3114
3115 const auto& style = *Style();
3116 const nsStyleDisplay* disp = style.StyleDisplay();
3117 const nsStyleEffects* effects = style.StyleEffects();
3118 EffectSet* effectSetForOpacity =
3119 EffectSet::GetForFrame(this, nsCSSPropertyIDSet::OpacityProperties());
3120 // We can stop right away if this is a zero-opacity stacking context and
3121 // we're painting, and we're not animating opacity.
3122 bool needHitTestInfo = aBuilder->BuildCompositorHitTestInfo() &&
3123 Style()->PointerEvents() != StylePointerEvents::None;
3124 bool opacityItemForEventsOnly = false;
3125 if (effects->IsTransparent() && aBuilder->IsForPainting() &&
3126 !(disp->mWillChange.bits & StyleWillChangeBits::OPACITY) &&
3127 !nsLayoutUtils::HasAnimationOfPropertySet(
3128 this, nsCSSPropertyIDSet::OpacityProperties(), effectSetForOpacity)) {
3129 if (needHitTestInfo) {
3130 opacityItemForEventsOnly = true;
3131 } else {
3132 return;
3133 }
3134 }
3135
3136 if (aBuilder->IsForPainting() && disp->mWillChange.bits) {
3137 aBuilder->AddToWillChangeBudget(this, GetSize());
3138 }
3139
3140 // For preserves3d, use the dirty rect already installed on the
3141 // builder, since aDirtyRect maybe distorted for transforms along
3142 // the chain.
3143 nsRect visibleRect = aBuilder->GetVisibleRect();
3144 nsRect dirtyRect = aBuilder->GetDirtyRect();
3145
3146 // We build an opacity item if it's not going to be drawn by SVG content.
3147 // We could in principle skip creating an nsDisplayOpacity item if
3148 // nsDisplayOpacity::NeedsActiveLayer returns false and usingSVGEffects is
3149 // true (the nsDisplayFilter/nsDisplayMasksAndClipPaths could handle the
3150 // opacity). Since SVG has perf issues where we sometimes spend a lot of
3151 // time creating display list items that might be helpful. We'd need to
3152 // restore our mechanism to do that (changed in bug 1482403), and we'd
3153 // need to invalidate the frame if the value that would be return from
3154 // NeedsActiveLayer was to change, which we don't currently do.
3155 const bool useOpacity =
3156 HasVisualOpacity(disp, effects, effectSetForOpacity) &&
3157 !SVGUtils::CanOptimizeOpacity(this);
3158
3159 const bool isTransformed = IsTransformed();
3160 const bool hasPerspective = isTransformed && HasPerspective();
3161 const bool extend3DContext =
3162 Extend3DContext(disp, effects, effectSetForOpacity);
3163 const bool combines3DTransformWithAncestors =
3164 (extend3DContext || isTransformed) && Combines3DTransformWithAncestors();
3165
3166 Maybe<nsDisplayListBuilder::AutoPreserves3DContext> autoPreserves3DContext;
3167 if (extend3DContext && !combines3DTransformWithAncestors) {
3168 // Start a new preserves3d context to keep informations on
3169 // nsDisplayListBuilder.
3170 autoPreserves3DContext.emplace(aBuilder);
3171 // Save dirty rect on the builder to avoid being distorted for
3172 // multiple transforms along the chain.
3173 aBuilder->SavePreserves3DRect();
3174
3175 // We rebuild everything within preserve-3d and don't try
3176 // to retain, so override the dirty rect now.
3177 if (aBuilder->IsRetainingDisplayList()) {
3178 dirtyRect = visibleRect;
3179 aBuilder->SetDisablePartialUpdates(true);
3180 }
3181 }
3182
3183 const bool useBlendMode = effects->mMixBlendMode != StyleBlend::Normal;
3184 if (useBlendMode) {
3185 aBuilder->SetContainsBlendMode(true);
3186 }
3187
3188 // reset blend mode so we can keep track if this stacking context needs have
3189 // a nsDisplayBlendContainer. Set the blend mode back when the routine exits
3190 // so we keep track if the parent stacking context needs a container too.
3191 AutoSaveRestoreContainsBlendMode autoRestoreBlendMode(*aBuilder);
3192 aBuilder->SetContainsBlendMode(false);
3193
3194 // NOTE: When changing this condition make sure to tweak nsGfxScrollFrame as
3195 // well.
3196 bool usingBackdropFilter = effects->HasBackdropFilters() &&
3197 IsVisibleForPainting() &&
3198 !style.IsRootElementStyle();
3199
3200 nsRect visibleRectOutsideTransform = visibleRect;
3201 nsDisplayTransform::PrerenderInfo prerenderInfo;
3202 bool inTransform = aBuilder->IsInTransform();
3203 if (isTransformed) {
3204 prerenderInfo = nsDisplayTransform::ShouldPrerenderTransformedContent(
3205 aBuilder, this, &visibleRect);
3206
3207 switch (prerenderInfo.mDecision) {
3208 case nsDisplayTransform::PrerenderDecision::Full:
3209 case nsDisplayTransform::PrerenderDecision::Partial:
3210 dirtyRect = visibleRect;
3211 break;
3212 case nsDisplayTransform::PrerenderDecision::No: {
3213 // If we didn't prerender an animated frame in a preserve-3d context,
3214 // then we want disable async animations for the rest of the preserve-3d
3215 // (especially ancestors).
3216 if ((extend3DContext || combines3DTransformWithAncestors) &&
3217 prerenderInfo.mHasAnimations) {
3218 aBuilder->SavePreserves3DAllowAsyncAnimation(false);
3219 }
3220
3221 const nsRect overflow = InkOverflowRectRelativeToSelf();
3222 if (overflow.IsEmpty() && !extend3DContext) {
3223 return;
3224 }
3225
3226 // If we're in preserve-3d then grab the dirty rect that was given to
3227 // the root and transform using the combined transform.
3228 if (combines3DTransformWithAncestors) {
3229 visibleRect = dirtyRect = aBuilder->GetPreserves3DRect();
3230 }
3231
3232 float appPerDev = PresContext()->AppUnitsPerDevPixel();
3233 auto transform = nsDisplayTransform::GetResultingTransformMatrix(
3234 this, nsPoint(), appPerDev,
3235 nsDisplayTransform::kTransformRectFlags);
3236 nsRect untransformedDirtyRect;
3237 if (nsDisplayTransform::UntransformRect(dirtyRect, overflow, transform,
3238 appPerDev,
3239 &untransformedDirtyRect)) {
3240 dirtyRect = untransformedDirtyRect;
3241 nsDisplayTransform::UntransformRect(visibleRect, overflow, transform,
3242 appPerDev, &visibleRect);
3243 } else {
3244 // This should only happen if the transform is singular, in which case
3245 // nothing is visible anyway
3246 dirtyRect.SetEmpty();
3247 visibleRect.SetEmpty();
3248 }
3249 }
3250 }
3251 inTransform = true;
3252 } else if (IsFixedPosContainingBlock()) {
3253 // Restict the building area to the overflow rect for these frames, since
3254 // RetainedDisplayListBuilder uses it to know if the size of the stacking
3255 // context changed.
3256 visibleRect.IntersectRect(visibleRect, InkOverflowRect());
3257 dirtyRect.IntersectRect(dirtyRect, InkOverflowRect());
3258 }
3259
3260 bool hasOverrideDirtyRect = false;
3261 // If we're doing a partial build, we're not invalid and we're capable
3262 // of having an override building rect (stacking context and fixed pos
3263 // containing block), then we should assume we have one.
3264 // Either we have an explicit one, or nothing in our subtree changed and
3265 // we have an implicit empty rect.
3266 //
3267 // These conditions should match |CanStoreDisplayListBuildingRect()| in
3268 // RetainedDisplayListBuilder.cpp
3269 if (!aBuilder->IsReusingStackingContextItems() &&
3270 aBuilder->IsPartialUpdate() && !aBuilder->InInvalidSubtree() &&
3271 !IsFrameModified() && IsFixedPosContainingBlock() &&
3272 !GetPrevContinuation() && !GetNextContinuation()) {
3273 dirtyRect = nsRect();
3274 if (HasOverrideDirtyRegion()) {
3275 nsDisplayListBuilder::DisplayListBuildingData* data =
3276 GetProperty(nsDisplayListBuilder::DisplayListBuildingRect());
3277 if (data) {
3278 dirtyRect = data->mDirtyRect.Intersect(visibleRect);
3279 hasOverrideDirtyRect = true;
3280 }
3281 }
3282 }
3283
3284 bool usingFilter = effects->HasFilters() && !style.IsRootElementStyle();
3285 SVGUtils::MaskUsage maskUsage = SVGUtils::DetermineMaskUsage(this, false);
3286 bool usingMask = maskUsage.UsingMaskOrClipPath();
3287 bool usingSVGEffects = usingFilter || usingMask;
3288
3289 nsRect visibleRectOutsideSVGEffects = visibleRect;
3290 nsDisplayList hoistedScrollInfoItemsStorage(aBuilder);
3291 if (usingSVGEffects) {
3292 dirtyRect =
3293 SVGIntegrationUtils::GetRequiredSourceForInvalidArea(this, dirtyRect);
3294 visibleRect =
3295 SVGIntegrationUtils::GetRequiredSourceForInvalidArea(this, visibleRect);
3296 aBuilder->EnterSVGEffectsContents(this, &hoistedScrollInfoItemsStorage);
3297 }
3298
3299 bool useStickyPosition = disp->mPosition == StylePositionProperty::Sticky;
3300
3301 bool useFixedPosition =
3302 disp->mPosition == StylePositionProperty::Fixed &&
3303 (DisplayPortUtils::IsFixedPosFrameInDisplayPort(this) ||
3304 BuilderHasScrolledClip(aBuilder));
3305
3306 nsDisplayListBuilder::AutoBuildingDisplayList buildingDisplayList(
3307 aBuilder, this, visibleRect, dirtyRect, isTransformed);
3308
3309 UpdateCurrentHitTestInfo(aBuilder, this);
3310
3311 // Depending on the effects that are applied to this frame, we can create
3312 // multiple container display items and wrap them around our contents.
3313 // This enum lists all the potential container display items, in the order
3314 // outside to inside.
3315 enum class ContainerItemType : uint8_t {
3316 None = 0,
3317 OwnLayerIfNeeded,
3318 BlendMode,
3319 FixedPosition,
3320 OwnLayerForTransformWithRoundedClip,
3321 Perspective,
3322 Transform,
3323 SeparatorTransforms,
3324 Opacity,
3325 Filter,
3326 BlendContainer
3327 };
3328
3329 nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
3330
3331 auto cssClip = GetClipPropClipRect(disp, effects, GetSize());
3332 auto ApplyClipProp = [&](DisplayListClipState::AutoSaveRestore& aClipState) {
3333 if (!cssClip) {
3334 return;
3335 }
3336 nsPoint offset = aBuilder->GetCurrentFrameOffsetToReferenceFrame();
3337 aBuilder->IntersectDirtyRect(*cssClip);
3338 aBuilder->IntersectVisibleRect(*cssClip);
3339 aClipState.ClipContentDescendants(*cssClip + offset);
3340 };
3341
3342 // The CSS clip property is effectively inside the transform, but outside the
3343 // filters. So if we're not transformed we can apply it just here for
3344 // simplicity, instead of on each of the places that handle clipCapturedBy.
3345 DisplayListClipState::AutoSaveRestore untransformedCssClip(aBuilder);
3346 if (!isTransformed) {
3347 ApplyClipProp(untransformedCssClip);
3348 }
3349
3350 // If there is a current clip, then depending on the container items we
3351 // create, different things can happen to it. Some container items simply
3352 // propagate the clip to their children and aren't clipped themselves.
3353 // But other container items, especially those that establish a different
3354 // geometry for their contents (e.g. transforms), capture the clip on
3355 // themselves and unset the clip for their contents. If we create more than
3356 // one of those container items, the clip will be captured on the outermost
3357 // one and the inner container items will be unclipped.
3358 ContainerItemType clipCapturedBy = ContainerItemType::None;
3359 if (useFixedPosition) {
3360 clipCapturedBy = ContainerItemType::FixedPosition;
3361 } else if (isTransformed) {
3362 const DisplayItemClipChain* currentClip =
3363 aBuilder->ClipState().GetCurrentCombinedClipChain(aBuilder);
3364 if ((hasPerspective || extend3DContext) &&
3365 (currentClip && currentClip->HasRoundedCorners())) {
3366 // If we're creating an nsDisplayTransform item that is going to combine
3367 // its transform with its children (preserve-3d or perspective), then we
3368 // can't have an intermediate surface. Mask layers force an intermediate
3369 // surface, so if we're going to need both then create a separate
3370 // wrapping layer for the mask.
3371 clipCapturedBy = ContainerItemType::OwnLayerForTransformWithRoundedClip;
3372 } else if (hasPerspective) {
3373 clipCapturedBy = ContainerItemType::Perspective;
3374 } else {
3375 clipCapturedBy = ContainerItemType::Transform;
3376 }
3377 } else if (usingFilter) {
3378 clipCapturedBy = ContainerItemType::Filter;
3379 }
3380
3381 DisplayListClipState::AutoSaveRestore clipState(aBuilder);
3382 if (clipCapturedBy != ContainerItemType::None) {
3383 clipState.Clear();
3384 }
3385
3386 DisplayListClipState::AutoSaveRestore transformedCssClip(aBuilder);
3387 if (isTransformed) {
3388 // FIXME(emilio, bug 1525159): In the case we have a both a transform _and_
3389 // filters, this clips the input to the filters as well, which is not
3390 // correct (clipping by the `clip` property is supposed to happen after
3391 // applying the filter effects, per [1].
3392 //
3393 // This is not a regression though, since we used to do that anyway before
3394 // bug 1514384, and even without the transform we get it wrong.
3395 //
3396 // [1]: https://drafts.fxtf.org/css-masking/#placement
3397 ApplyClipProp(transformedCssClip);
3398 }
3399
3400 nsDisplayListCollection set(aBuilder);
3401 Maybe<nsRect> clipForMask;
3402 {
3403 DisplayListClipState::AutoSaveRestore nestedClipState(aBuilder);
3404 nsDisplayListBuilder::AutoInTransformSetter inTransformSetter(aBuilder,
3405 inTransform);
3406 nsDisplayListBuilder::AutoEnterFilter filterASRSetter(aBuilder,
3407 usingFilter);
3408 nsDisplayListBuilder::AutoInEventsOnly inEventsSetter(
3409 aBuilder, opacityItemForEventsOnly);
3410
3411 // If we have a mask, compute a clip to bound the masked content.
3412 // This is necessary in case the content moves with an ancestor
3413 // ASR of the mask.
3414 // Don't do this if we also have a filter, because then the clip
3415 // would be applied before the filter, violating
3416 // https://www.w3.org/TR/filter-effects-1/#placement.
3417 // Filters are a containing block for fixed and absolute descendants,
3418 // so the masked content cannot move with an ancestor ASR.
3419 if (usingMask && !usingFilter) {
3420 clipForMask = ComputeClipForMaskItem(aBuilder, this, maskUsage);
3421 if (clipForMask) {
3422 aBuilder->IntersectDirtyRect(*clipForMask);
3423 aBuilder->IntersectVisibleRect(*clipForMask);
3424 nestedClipState.ClipContentDescendants(
3425 *clipForMask + aBuilder->GetCurrentFrameOffsetToReferenceFrame());
3426 }
3427 }
3428
3429 // extend3DContext also guarantees that applyAbsPosClipping and
3430 // usingSVGEffects are false We only modify the preserve-3d rect if we are
3431 // the top of a preserve-3d heirarchy
3432 if (extend3DContext) {
3433 // Mark these first so MarkAbsoluteFramesForDisplayList knows if we are
3434 // going to be forced to descend into frames.
3435 aBuilder->MarkPreserve3DFramesForDisplayList(this);
3436 }
3437
3438 aBuilder->AdjustWindowDraggingRegion(this);
3439
3440 MarkAbsoluteFramesForDisplayList(aBuilder);
3441 aBuilder->Check();
3442 BuildDisplayList(aBuilder, set);
3443 SetBuiltDisplayList(true);
3444 aBuilder->Check();
3445 aBuilder->DisplayCaret(this, set.Outlines());
3446
3447 // Blend modes are a real pain for retained display lists. We build a blend
3448 // container item if the built list contains any blend mode items within
3449 // the current stacking context. This can change without an invalidation
3450 // to the stacking context frame, or the blend mode frame (e.g. by moving
3451 // an intermediate frame).
3452 // When we gain/remove a blend container item, we need to mark this frame
3453 // as invalid and have the full display list for merging to track
3454 // the change correctly.
3455 // It seems really hard to track this in advance, as the bookkeeping
3456 // required to note which stacking contexts have blend descendants
3457 // is complex and likely to be buggy.
3458 // Instead we're doing the sad thing, detecting it afterwards, and just
3459 // repeating display list building if it changed.
3460 // We have to repeat building for the entire display list (or at least
3461 // the outer stacking context), since we need to mark this frame as invalid
3462 // to remove any existing content that isn't wrapped in the blend container,
3463 // and then we need to build content infront/behind the blend container
3464 // to get correct positioning during merging.
3465 if (aBuilder->ContainsBlendMode() && aBuilder->IsRetainingDisplayList()) {
3466 if (aBuilder->IsPartialUpdate()) {
3467 aBuilder->SetPartialBuildFailed(true);
3468 } else {
3469 aBuilder->SetDisablePartialUpdates(true);
3470 }
3471 }
3472 }
3473
3474 if (aBuilder->IsBackgroundOnly()) {
3475 set.BlockBorderBackgrounds()->DeleteAll(aBuilder);
3476 set.Floats()->DeleteAll(aBuilder);
3477 set.Content()->DeleteAll(aBuilder);
3478 set.PositionedDescendants()->DeleteAll(aBuilder);
3479 set.Outlines()->DeleteAll(aBuilder);
3480 }
3481
3482 if (hasOverrideDirtyRect &&
3483 StaticPrefs::layout_display_list_show_rebuild_area()) {
3484 nsDisplaySolidColor* color = MakeDisplayItem<nsDisplaySolidColor>(
3485 aBuilder, this,
3486 dirtyRect + aBuilder->GetCurrentFrameOffsetToReferenceFrame(),
3487 NS_RGBA(255, 0, 0, 64)((nscolor)(((64) << 24) | ((0) << 16) | ((0) <<
8) | (255)))
, false);
3488 if (color) {
3489 color->SetOverrideZIndex(INT32_MAX(2147483647));
3490 set.PositionedDescendants()->AppendToTop(color);
3491 }
3492 }
3493
3494 nsIContent* content = GetContent();
3495 if (!content) {
3496 content = PresContext()->Document()->GetRootElement();
3497 }
3498
3499 nsDisplayList resultList(aBuilder);
3500 set.SerializeWithCorrectZOrder(&resultList, content);
3501
3502 // Get the ASR to use for the container items that we create here.
3503 const ActiveScrolledRoot* containerItemASR = contASRTracker.GetContainerASR();
3504
3505 bool createdContainer = false;
3506
3507 // If adding both a nsDisplayBlendContainer and a nsDisplayBlendMode to the
3508 // same list, the nsDisplayBlendContainer should be added first. This only
3509 // happens when the element creating this stacking context has mix-blend-mode
3510 // and also contains a child which has mix-blend-mode.
3511 // The nsDisplayBlendContainer must be added to the list first, so it does not
3512 // isolate the containing element blending as well.
3513 if (aBuilder->ContainsBlendMode()) {
3514 resultList.AppendToTop(nsDisplayBlendContainer::CreateForMixBlendMode(
3515 aBuilder, this, &resultList, containerItemASR));
3516 createdContainer = true;
3517 }
3518
3519 if (usingBackdropFilter) {
3520 nsRect backdropRect =
3521 GetRectRelativeToSelf() + aBuilder->ToReferenceFrame(this);
3522 resultList.AppendNewToTop<nsDisplayBackdropFilters>(
3523 aBuilder, this, &resultList, backdropRect, this);
3524 createdContainer = true;
3525 }
3526
3527 // If there are any SVG effects, wrap the list up in an SVG effects item
3528 // (which also handles CSS group opacity). Note that we create an SVG effects
3529 // item even if resultList is empty, since a filter can produce graphical
3530 // output even if the element being filtered wouldn't otherwise do so.
3531 if (usingSVGEffects) {
3532 MOZ_ASSERT(usingFilter || usingMask,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(usingFilter || usingMask)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(usingFilter || usingMask))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("usingFilter || usingMask"
" (" "Beside filter & mask/clip-path, what else effect do we have?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3533); AnnotateMozCrashReason("MOZ_ASSERT" "(" "usingFilter || usingMask"
") (" "Beside filter & mask/clip-path, what else effect do we have?"
")"); do { *((volatile int*)__null) = 3533; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
3533 "Beside filter & mask/clip-path, what else effect do we have?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(usingFilter || usingMask)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(usingFilter || usingMask))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("usingFilter || usingMask"
" (" "Beside filter & mask/clip-path, what else effect do we have?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3533); AnnotateMozCrashReason("MOZ_ASSERT" "(" "usingFilter || usingMask"
") (" "Beside filter & mask/clip-path, what else effect do we have?"
")"); do { *((volatile int*)__null) = 3533; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3534
3535 if (clipCapturedBy == ContainerItemType::Filter) {
3536 clipState.Restore();
3537 }
3538 // Revert to the post-filter dirty rect.
3539 aBuilder->SetVisibleRect(visibleRectOutsideSVGEffects);
3540
3541 // Skip all filter effects while generating glyph mask.
3542 if (usingFilter && !aBuilder->IsForGenerateGlyphMask()) {
3543 /* List now emptied, so add the new list to the top. */
3544 resultList.AppendNewToTop<nsDisplayFilters>(aBuilder, this, &resultList,
3545 this, usingBackdropFilter);
3546 createdContainer = true;
3547 }
3548
3549 if (usingMask) {
3550 // The mask should move with aBuilder->CurrentActiveScrolledRoot(), so
3551 // that's the ASR we prefer to use for the mask item. However, we can
3552 // only do this if the mask if clipped with respect to that ASR, because
3553 // an item always needs to have finite bounds with respect to its ASR.
3554 // If we weren't able to compute a clip for the mask, we fall back to
3555 // using containerItemASR, which is the lowest common ancestor clip of
3556 // the mask's contents. That's not entirely correct, but it satisfies
3557 // the base requirement of the ASR system (that items have finite bounds
3558 // wrt. their ASR).
3559 const ActiveScrolledRoot* maskASR =
3560 clipForMask.isSome() ? aBuilder->CurrentActiveScrolledRoot()
3561 : containerItemASR;
3562 /* List now emptied, so add the new list to the top. */
3563 resultList.AppendNewToTop<nsDisplayMasksAndClipPaths>(
3564 aBuilder, this, &resultList, maskASR, usingBackdropFilter);
3565 createdContainer = true;
3566 }
3567
3568 // TODO(miko): We could probably create a wraplist here and avoid creating
3569 // it later in |BuildDisplayListForChild()|.
3570 createdContainer = false;
3571
3572 // Also add the hoisted scroll info items. We need those for APZ scrolling
3573 // because nsDisplayMasksAndClipPaths items can't build active layers.
3574 aBuilder->ExitSVGEffectsContents();
3575 resultList.AppendToTop(&hoistedScrollInfoItemsStorage);
3576 }
3577
3578 // If the list is non-empty and there is CSS group opacity without SVG
3579 // effects, wrap it up in an opacity item.
3580 if (useOpacity) {
3581 const bool needsActiveOpacityLayer =
3582 nsDisplayOpacity::NeedsActiveLayer(aBuilder, this);
3583 resultList.AppendNewToTop<nsDisplayOpacity>(
3584 aBuilder, this, &resultList, containerItemASR, opacityItemForEventsOnly,
3585 needsActiveOpacityLayer, usingBackdropFilter);
3586 createdContainer = true;
3587 }
3588
3589 // If we're going to apply a transformation and don't have preserve-3d set,
3590 // wrap everything in an nsDisplayTransform. If there's nothing in the list,
3591 // don't add anything.
3592 //
3593 // For the preserve-3d case we want to individually wrap every child in the
3594 // list with a separate nsDisplayTransform instead. When the child is already
3595 // an nsDisplayTransform, we can skip this step, as the computed transform
3596 // will already include our own.
3597 //
3598 // We also traverse into sublists created by nsDisplayWrapList, so that we
3599 // find all the correct children.
3600 if (isTransformed && extend3DContext) {
3601 // Install dummy nsDisplayTransform as a leaf containing
3602 // descendants not participating this 3D rendering context.
3603 nsDisplayList nonparticipants(aBuilder);
3604 nsDisplayList participants(aBuilder);
3605 int index = 1;
3606
3607 nsDisplayItem* separator = nullptr;
3608
3609 // TODO: This can be simplified: |participants| is just |resultList|.
3610 for (nsDisplayItem* item : resultList.TakeItems()) {
3611 if (ItemParticipatesIn3DContext(this, item) &&
3612 !item->GetClip().HasClip()) {
3613 // The frame of this item participates the same 3D context.
3614 WrapSeparatorTransform(aBuilder, this, &nonparticipants, &participants,
3615 index++, &separator);
3616
3617 participants.AppendToTop(item);
3618 } else {
3619 // The frame of the item doesn't participate the current
3620 // context, or has no transform.
3621 //
3622 // For items participating but not transformed, they are add
3623 // to nonparticipants to get a separator layer for handling
3624 // clips, if there is, on an intermediate surface.
3625 // \see ContainerLayer::DefaultComputeEffectiveTransforms().
3626 nonparticipants.AppendToTop(item);
3627 }
3628 }
3629 WrapSeparatorTransform(aBuilder, this, &nonparticipants, &participants,
3630 index++, &separator);
3631
3632 if (separator) {
3633 createdContainer = true;
3634 }
3635
3636 resultList.AppendToTop(&participants);
3637 }
3638
3639 if (isTransformed) {
3640 transformedCssClip.Restore();
3641 if (clipCapturedBy == ContainerItemType::Transform) {
3642 // Restore clip state now so nsDisplayTransform is clipped properly.
3643 clipState.Restore();
3644 }
3645 // Revert to the dirtyrect coming in from the parent, without our transform
3646 // taken into account.
3647 aBuilder->SetVisibleRect(visibleRectOutsideTransform);
3648
3649 if (this != aBuilder->RootReferenceFrame()) {
3650 // Revert to the outer reference frame and offset because all display
3651 // items we create from now on are outside the transform.
3652 nsPoint toOuterReferenceFrame;
3653 const nsIFrame* outerReferenceFrame =
3654 aBuilder->FindReferenceFrameFor(GetParent(), &toOuterReferenceFrame);
3655 toOuterReferenceFrame += GetPosition();
3656
3657 buildingDisplayList.SetReferenceFrameAndCurrentOffset(
3658 outerReferenceFrame, toOuterReferenceFrame);
3659 }
3660
3661 // We would like to block async animations for ancestors of ones not
3662 // prerendered in the preserve-3d tree. Now that we've finished processing
3663 // all descendants, update allowAsyncAnimation to take their prerender
3664 // state into account
3665 // FIXME: We don't block async animations for previous siblings because
3666 // their prerender decisions have been made. We may have to figure out a
3667 // better way to rollback their prerender decisions.
3668 // Alternatively we could not block animations for later siblings, and only
3669 // block them for ancestors of a blocked one.
3670 if ((extend3DContext || combines3DTransformWithAncestors) &&
3671 prerenderInfo.CanUseAsyncAnimations() &&
3672 !aBuilder->GetPreserves3DAllowAsyncAnimation()) {
3673 // aBuilder->GetPreserves3DAllowAsyncAnimation() means the inner or
3674 // previous silbing frames are allowed/disallowed for async animations.
3675 prerenderInfo.mDecision = nsDisplayTransform::PrerenderDecision::No;
3676 }
3677
3678 nsDisplayTransform* transformItem = MakeDisplayItem<nsDisplayTransform>(
3679 aBuilder, this, &resultList, visibleRect, prerenderInfo.mDecision);
3680 if (transformItem) {
3681 resultList.AppendToTop(transformItem);
3682 createdContainer = true;
3683 }
3684
3685 if (hasPerspective) {
3686 transformItem->MarkWithAssociatedPerspective();
3687
3688 if (clipCapturedBy == ContainerItemType::Perspective) {
3689 clipState.Restore();
3690 }
3691 resultList.AppendNewToTop<nsDisplayPerspective>(aBuilder, this,
3692 &resultList);
3693 createdContainer = true;
3694 }
3695 }
3696
3697 if (clipCapturedBy ==
3698 ContainerItemType::OwnLayerForTransformWithRoundedClip) {
3699 clipState.Restore();
3700 resultList.AppendNewToTopWithIndex<nsDisplayOwnLayer>(
3701 aBuilder, this,
3702 /* aIndex = */ nsDisplayOwnLayer::OwnLayerForTransformWithRoundedClip,
3703 &resultList, aBuilder->CurrentActiveScrolledRoot(),
3704 nsDisplayOwnLayerFlags::None, ScrollbarData{},
3705 /* aForceActive = */ false, false);
3706 createdContainer = true;
3707 }
3708
3709 // If we have sticky positioning, wrap it in a sticky position item.
3710 if (useFixedPosition) {
3711 if (clipCapturedBy == ContainerItemType::FixedPosition) {
3712 clipState.Restore();
3713 }
3714 // The ASR for the fixed item should be the ASR of our containing block,
3715 // which has been set as the builder's current ASR, unless this frame is
3716 // invisible and we hadn't saved display item data for it. In that case,
3717 // we need to take the containerItemASR since we might have fixed children.
3718 // For WebRender, we want to the know what |containerItemASR| is for the
3719 // case where the fixed-pos item is not a "real" fixed-pos item (e.g. it's
3720 // nested inside a scrolling transform), so we stash that on the display
3721 // item as well.
3722 const ActiveScrolledRoot* fixedASR = ActiveScrolledRoot::PickAncestor(
3723 containerItemASR, aBuilder->CurrentActiveScrolledRoot());
3724 resultList.AppendNewToTop<nsDisplayFixedPosition>(
3725 aBuilder, this, &resultList, fixedASR, containerItemASR);
3726 createdContainer = true;
3727 } else if (useStickyPosition) {
3728 // For position:sticky, the clip needs to be applied both to the sticky
3729 // container item and to the contents. The container item needs the clip
3730 // because a scrolled clip needs to move independently from the sticky
3731 // contents, and the contents need the clip so that they have finite
3732 // clipped bounds with respect to the container item's ASR. The latter is
3733 // a little tricky in the case where the sticky item has both fixed and
3734 // non-fixed descendants, because that means that the sticky container
3735 // item's ASR is the ASR of the fixed descendant.
3736 // For WebRender display list building, though, we still want to know the
3737 // the ASR that the sticky container item would normally have, so we stash
3738 // that on the display item as the "container ASR" (i.e. the normal ASR of
3739 // the container item, excluding the special behaviour induced by fixed
3740 // descendants).
3741 const ActiveScrolledRoot* stickyASR = ActiveScrolledRoot::PickAncestor(
3742 containerItemASR, aBuilder->CurrentActiveScrolledRoot());
3743
3744 auto* stickyItem = MakeDisplayItem<nsDisplayStickyPosition>(
3745 aBuilder, this, &resultList, stickyASR,
3746 aBuilder->CurrentActiveScrolledRoot(),
3747 clipState.IsClippedToDisplayPort());
3748
3749 bool shouldFlatten = true;
3750
3751 StickyScrollContainer* stickyScrollContainer =
3752 StickyScrollContainer::GetStickyScrollContainerForFrame(this);
3753 if (stickyScrollContainer &&
3754 stickyScrollContainer->ScrollFrame()->IsMaybeAsynchronouslyScrolled()) {
3755 shouldFlatten = false;
3756 }
3757
3758 stickyItem->SetShouldFlatten(shouldFlatten);
3759
3760 resultList.AppendToTop(stickyItem);
3761 createdContainer = true;
3762
3763 // If the sticky element is inside a filter, annotate the scroll frame that
3764 // scrolls the filter as having out-of-flow content inside a filter (this
3765 // inhibits paint skipping).
3766 if (aBuilder->GetFilterASR() && aBuilder->GetFilterASR() == stickyASR) {
3767 aBuilder->GetFilterASR()
3768 ->mScrollableFrame->SetHasOutOfFlowContentInsideFilter();
3769 }
3770 }
3771
3772 // If there's blending, wrap up the list in a blend-mode item. Note that
3773 // opacity can be applied before blending as the blend color is not affected
3774 // by foreground opacity (only background alpha).
3775 if (useBlendMode) {
3776 DisplayListClipState::AutoSaveRestore blendModeClipState(aBuilder);
3777 resultList.AppendNewToTop<nsDisplayBlendMode>(aBuilder, this, &resultList,
3778 effects->mMixBlendMode,
3779 containerItemASR, false);
3780 createdContainer = true;
3781 }
3782
3783 if (aBuilder->IsReusingStackingContextItems()) {
3784 if (resultList.IsEmpty()) {
3785 return;
3786 }
3787
3788 nsDisplayItem* container = resultList.GetBottom();
3789 if (resultList.Length() > 1 || container->Frame() != this) {
3790 container = MakeDisplayItem<nsDisplayContainer>(
3791 aBuilder, this, containerItemASR, &resultList);
3792 } else {
3793 MOZ_ASSERT(resultList.Length() == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(resultList.Length() == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(resultList.Length() == 1))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("resultList.Length() == 1"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3793); AnnotateMozCrashReason("MOZ_ASSERT" "(" "resultList.Length() == 1"
")"); do { *((volatile int*)__null) = 3793; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3794 resultList.Clear();
3795 }
3796
3797 // Mark the outermost display item as reusable. These display items and
3798 // their chidren can be reused during the next paint if no ancestor or
3799 // descendant frames have been modified.
3800 if (!container->IsReusedItem()) {
3801 container->SetReusable();
3802 }
3803 aList->AppendToTop(container);
3804 createdContainer = true;
3805 } else {
3806 aList->AppendToTop(&resultList);
3807 }
3808
3809 if (aCreatedContainerItem) {
3810 *aCreatedContainerItem = createdContainer;
3811 }
3812}
3813
3814static nsDisplayItem* WrapInWrapList(nsDisplayListBuilder* aBuilder,
3815 nsIFrame* aFrame, nsDisplayList* aList,
3816 const ActiveScrolledRoot* aContainerASR,
3817 bool aBuiltContainerItem = false) {
3818 nsDisplayItem* item = aList->GetBottom();
3819 if (!item) {
3820 return nullptr;
3821 }
3822
3823 // We need a wrap list if there are multiple items, or if the single
3824 // item has a different frame. This can change in a partial build depending
3825 // on which items we build, so we need to ensure that we don't transition
3826 // to/from a wrap list without invalidating correctly.
3827 bool needsWrapList =
3828 aList->Length() > 1 || item->Frame() != aFrame || item->GetChildren();
3829
3830 // If we have an explicit container item (that can't change without an
3831 // invalidation) or we're doing a full build and don't need a wrap list, then
3832 // we can skip adding one.
3833 if (aBuiltContainerItem || (!aBuilder->IsPartialUpdate() && !needsWrapList)) {
3834 MOZ_ASSERT(aList->Length() == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aList->Length() == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aList->Length() == 1))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aList->Length() == 1"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3834); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aList->Length() == 1"
")"); do { *((volatile int*)__null) = 3834; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3835 aList->Clear();
3836 return item;
3837 }
3838
3839 // If we're doing a partial build and we didn't need a wrap list
3840 // previously then we can try to work from there.
3841 if (aBuilder->IsPartialUpdate() &&
3842 !aFrame->HasDisplayItem(uint32_t(DisplayItemType::TYPE_CONTAINER))) {
3843 // If we now need a wrap list, we must previously have had no display items
3844 // or a single one belonging to this frame. Mark the item itself as
3845 // discarded so that RetainedDisplayListBuilder uses the ones we just built.
3846 // We don't want to mark the frame as modified as that would invalidate
3847 // positioned descendants that might be outside of this list, and might not
3848 // have been rebuilt this time.
3849 if (needsWrapList) {
3850 DiscardOldItems(aFrame);
3851 } else {
3852 MOZ_ASSERT(aList->Length() == 1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aList->Length() == 1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aList->Length() == 1))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aList->Length() == 1"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3852); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aList->Length() == 1"
")"); do { *((volatile int*)__null) = 3852; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3853 aList->Clear();
3854 return item;
3855 }
3856 }
3857
3858 // The last case we could try to handle is when we previously had a wrap list,
3859 // but no longer need it. Unfortunately we can't differentiate this case from
3860 // a partial build where other children exist but we just didn't build them
3861 // this time.
3862 // TODO:RetainedDisplayListBuilder's merge phase has the full list and
3863 // could strip them out.
3864
3865 return MakeDisplayItem<nsDisplayContainer>(aBuilder, aFrame, aContainerASR,
3866 aList);
3867}
3868
3869/**
3870 * Check if a frame should be visited for building display list.
3871 */
3872static bool DescendIntoChild(nsDisplayListBuilder* aBuilder,
3873 const nsIFrame* aChild, const nsRect& aVisible,
3874 const nsRect& aDirty) {
3875 if (aChild->HasAnyStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO)) {
3876 return true;
3877 }
3878
3879 // If the child is a scrollframe that we want to ignore, then we need
3880 // to descend into it because its scrolled child may intersect the dirty
3881 // area even if the scrollframe itself doesn't.
3882 if (aChild == aBuilder->GetIgnoreScrollFrame()) {
3883 return true;
3884 }
3885
3886 // There are cases where the "ignore scroll frame" on the builder is not set
3887 // correctly, and so we additionally want to catch cases where the child is
3888 // a root scrollframe and we are ignoring scrolling on the viewport.
3889 if (aChild == aBuilder->GetPresShellIgnoreScrollFrame()) {
3890 return true;
3891 }
3892
3893 nsRect overflow = aChild->InkOverflowRect();
3894
3895 // On mobile, there may be a dynamic toolbar. The root content document's
3896 // root scroll frame's ink overflow rect does not include the toolbar
3897 // height, but if the toolbar is hidden, we still want to be able to target
3898 // content underneath the toolbar, so expand the overflow rect here to
3899 // allow display list building to descend into the scroll frame.
3900 if (aBuilder->IsForEventDelivery() &&
3901 aChild == aChild->PresShell()->GetRootScrollFrame() &&
3902 aChild->PresContext()->IsRootContentDocumentCrossProcess() &&
3903 aChild->PresContext()->HasDynamicToolbar()) {
3904 overflow.SizeTo(nsLayoutUtils::ExpandHeightForDynamicToolbar(
3905 aChild->PresContext(), overflow.Size()));
3906 }
3907
3908 if (aDirty.Intersects(overflow)) {
3909 return true;
3910 }
3911
3912 if (aChild->ForceDescendIntoIfVisible() && aVisible.Intersects(overflow)) {
3913 return true;
3914 }
3915
3916 if (aChild->IsTablePart()) {
3917 // Relative positioning and transforms can cause table parts to move, but we
3918 // will still paint the backgrounds for their ancestor parts under them at
3919 // their 'normal' position. That means that we must consider the overflow
3920 // rects at both positions.
3921
3922 // We convert the overflow rect into the nsTableFrame's coordinate
3923 // space, applying the normal position offset at each step. Then we
3924 // compare that against the builder's cached dirty rect in table
3925 // coordinate space.
3926 const nsIFrame* f = aChild;
3927 nsRect normalPositionOverflowRelativeToTable = overflow;
3928
3929 while (f->IsTablePart()) {
3930 normalPositionOverflowRelativeToTable += f->GetNormalPosition();
3931 f = f->GetParent();
3932 }
3933
3934 nsDisplayTableBackgroundSet* tableBGs = aBuilder->GetTableBackgroundSet();
3935 if (tableBGs && tableBGs->GetDirtyRect().Intersects(
3936 normalPositionOverflowRelativeToTable)) {
3937 return true;
3938 }
3939 }
3940
3941 return false;
3942}
3943
3944void nsIFrame::BuildDisplayListForSimpleChild(nsDisplayListBuilder* aBuilder,
3945 nsIFrame* aChild,
3946 const nsDisplayListSet& aLists) {
3947 // This is the shortcut for frames been handled along the common
3948 // path, the most common one of THE COMMON CASE mentioned later.
3949 MOZ_ASSERT(aChild->Type() != LayoutFrameType::Placeholder)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aChild->Type() != LayoutFrameType::Placeholder)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aChild->Type() != LayoutFrameType::Placeholder)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("aChild->Type() != LayoutFrameType::Placeholder"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3949); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aChild->Type() != LayoutFrameType::Placeholder"
")"); do { *((volatile int*)__null) = 3949; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3950 MOZ_ASSERT(!aBuilder->GetSelectedFramesOnly() &&do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aBuilder->GetSelectedFramesOnly() && !aBuilder
->GetIncludeAllOutOfFlows())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aBuilder->GetSelectedFramesOnly
() && !aBuilder->GetIncludeAllOutOfFlows()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
" (" "It should be held for painting to window" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3952); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
") (" "It should be held for painting to window" ")"); do { *
((volatile int*)__null) = 3952; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
3951 !aBuilder->GetIncludeAllOutOfFlows(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aBuilder->GetSelectedFramesOnly() && !aBuilder
->GetIncludeAllOutOfFlows())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aBuilder->GetSelectedFramesOnly
() && !aBuilder->GetIncludeAllOutOfFlows()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
" (" "It should be held for painting to window" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3952); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
") (" "It should be held for painting to window" ")"); do { *
((volatile int*)__null) = 3952; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
3952 "It should be held for painting to window")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aBuilder->GetSelectedFramesOnly() && !aBuilder
->GetIncludeAllOutOfFlows())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aBuilder->GetSelectedFramesOnly
() && !aBuilder->GetIncludeAllOutOfFlows()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
" (" "It should be held for painting to window" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3952); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
") (" "It should be held for painting to window" ")"); do { *
((volatile int*)__null) = 3952; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
3953 MOZ_ASSERT(aChild->HasAnyStateBits(NS_FRAME_SIMPLE_DISPLAYLIST))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aChild->HasAnyStateBits(NS_FRAME_SIMPLE_DISPLAYLIST
))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aChild->HasAnyStateBits(NS_FRAME_SIMPLE_DISPLAYLIST
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aChild->HasAnyStateBits(NS_FRAME_SIMPLE_DISPLAYLIST)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 3953); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aChild->HasAnyStateBits(NS_FRAME_SIMPLE_DISPLAYLIST)"
")"); do { *((volatile int*)__null) = 3953; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3954
3955 const nsPoint offset = aChild->GetOffsetTo(this);
3956 const nsRect visible = aBuilder->GetVisibleRect() - offset;
3957 const nsRect dirty = aBuilder->GetDirtyRect() - offset;
3958
3959 if (!DescendIntoChild(aBuilder, aChild, visible, dirty)) {
3960 DL_LOGV("Skipped frame %p", aChild)do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Verbose)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Verbose, "Skipped frame %p", aChild); } } while (
0)
;
3961 return;
3962 }
3963
3964 // Child cannot be transformed since it is not a stacking context.
3965 nsDisplayListBuilder::AutoBuildingDisplayList buildingForChild(
3966 aBuilder, aChild, visible, dirty, false);
3967
3968 UpdateCurrentHitTestInfo(aBuilder, aChild);
3969
3970 aChild->MarkAbsoluteFramesForDisplayList(aBuilder);
3971 aBuilder->AdjustWindowDraggingRegion(aChild);
3972 aBuilder->Check();
3973 aChild->BuildDisplayList(aBuilder, aLists);
3974 aChild->SetBuiltDisplayList(true);
3975 aBuilder->Check();
3976 aBuilder->DisplayCaret(aChild, aLists.Outlines());
3977}
3978
3979static bool ShouldSkipFrame(nsDisplayListBuilder* aBuilder,
3980 const nsIFrame* aFrame) {
3981 // If painting is restricted to just the background of the top level frame,
3982 // then we have nothing to do here.
3983 if (aBuilder->IsBackgroundOnly()) {
3984 return true;
3985 }
3986 if (aBuilder->IsForGenerateGlyphMask() &&
3987 (!aFrame->IsTextFrame() && aFrame->IsLeaf())) {
3988 return true;
3989 }
3990 // The placeholder frame should have the same content as the OOF frame.
3991 if (aBuilder->GetSelectedFramesOnly() &&
3992 (aFrame->IsLeaf() && !aFrame->IsSelected())) {
3993 return true;
3994 }
3995 static const nsFrameState skipFlags =
3996 (NS_FRAME_TOO_DEEP_IN_FRAME_TREE | NS_FRAME_IS_NONDISPLAY);
3997 if (aFrame->HasAnyStateBits(skipFlags)) {
3998 return true;
3999 }
4000 return aFrame->StyleUIReset()->mMozSubtreeHiddenOnlyVisually;
4001}
4002
4003void nsIFrame::BuildDisplayListForChild(nsDisplayListBuilder* aBuilder,
4004 nsIFrame* aChild,
4005 const nsDisplayListSet& aLists,
4006 DisplayChildFlags aFlags) {
4007 AutoCheckBuilder check(aBuilder);
4008#ifdef DEBUG1
4009 DL_LOGV("BuildDisplayListForChild (%p) <", aChild)do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Verbose)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Verbose, "BuildDisplayListForChild (%p) <", aChild
); } } while (0)
;
4010 ScopeExit e(
4011 [aChild]() { DL_LOGV("> BuildDisplayListForChild (%p)", aChild)do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Verbose)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Verbose, "> BuildDisplayListForChild (%p)", aChild
); } } while (0)
; });
4012#endif
4013
4014 if (ShouldSkipFrame(aBuilder, aChild)) {
4015 return;
4016 }
4017
4018 if (HidesContent()) {
4019 return;
4020 }
4021
4022 // If we're generating a display list for printing, include Link items for
4023 // frames that correspond to HTML link elements so that we can have active
4024 // links in saved PDF output. Note that the state of "within a link" is
4025 // set on the display-list builder, such that all descendants of the link
4026 // element will generate display-list links.
4027 // TODO: we should be able to optimize this so as to avoid creating links
4028 // for the same destination that entirely overlap each other, which adds
4029 // nothing useful to the final PDF.
4030 Maybe<nsDisplayListBuilder::Linkifier> linkifier;
4031 if (StaticPrefs::print_save_as_pdf_links_enabled() &&
4032 aBuilder->IsForPrinting()) {
4033 linkifier.emplace(aBuilder, aChild, aLists.Content());
4034 linkifier->MaybeAppendLink(aBuilder, aChild);
4035 }
4036
4037 nsIFrame* child = aChild;
4038 auto* placeholder = child->IsPlaceholderFrame()
4039 ? static_cast<nsPlaceholderFrame*>(child)
4040 : nullptr;
4041 nsIFrame* childOrOutOfFlow =
4042 placeholder ? placeholder->GetOutOfFlowFrame() : child;
4043
4044 nsIFrame* parent = childOrOutOfFlow->GetParent();
4045 const auto* parentDisplay = parent->StyleDisplay();
4046 const auto overflowClipAxes =
4047 parent->ShouldApplyOverflowClipping(parentDisplay);
4048
4049 const bool isPaintingToWindow = aBuilder->IsPaintingToWindow();
4050 const bool doingShortcut =
4051 isPaintingToWindow &&
4052 child->HasAnyStateBits(NS_FRAME_SIMPLE_DISPLAYLIST) &&
4053 // Animations may change the stacking context state.
4054 // ShouldApplyOverflowClipping is affected by the parent style, which does
4055 // not invalidate the NS_FRAME_SIMPLE_DISPLAYLIST bit.
4056 !(overflowClipAxes != PhysicalAxes::None ||
4057 child->MayHaveTransformAnimation() || child->MayHaveOpacityAnimation());
4058
4059 if (aBuilder->IsForPainting()) {
4060 aBuilder->ClearWillChangeBudgetStatus(child);
4061 }
4062
4063 if (StaticPrefs::layout_css_scroll_anchoring_highlight()) {
4064 if (child->FirstContinuation()->IsScrollAnchor()) {
4065 nsRect bounds = child->GetContentRectRelativeToSelf() +
4066 aBuilder->ToReferenceFrame(child);
4067 nsDisplaySolidColor* color = MakeDisplayItem<nsDisplaySolidColor>(
4068 aBuilder, child, bounds, NS_RGBA(255, 0, 255, 64)((nscolor)(((64) << 24) | ((255) << 16) | ((0) <<
8) | (255)))
);
4069 if (color) {
4070 color->SetOverrideZIndex(INT32_MAX(2147483647));
4071 aLists.PositionedDescendants()->AppendToTop(color);
4072 }
4073 }
4074 }
4075
4076 if (doingShortcut) {
4077 BuildDisplayListForSimpleChild(aBuilder, child, aLists);
4078 return;
4079 }
4080
4081 // dirty rect in child-relative coordinates
4082 NS_ASSERTION(aBuilder->GetCurrentFrame() == this, "Wrong coord space!")do { if (!(aBuilder->GetCurrentFrame() == this)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Wrong coord space!", "aBuilder->GetCurrentFrame() == this"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4082); MOZ_PretendNoReturn(); } } while (0)
;
4083 const nsPoint offset = child->GetOffsetTo(this);
4084 nsRect visible = aBuilder->GetVisibleRect() - offset;
4085 nsRect dirty = aBuilder->GetDirtyRect() - offset;
4086
4087 nsDisplayListBuilder::OutOfFlowDisplayData* savedOutOfFlowData = nullptr;
4088 if (placeholder) {
4089 if (placeholder->HasAnyStateBits(PLACEHOLDER_FOR_TOPLAYER)) {
4090 // If the out-of-flow frame is in the top layer, the viewport frame
4091 // will paint it. Skip it here. Note that, only out-of-flow frames
4092 // with this property should be skipped, because non-HTML elements
4093 // may stop their children from being out-of-flow. Those frames
4094 // should still be handled in the normal in-flow path.
4095 return;
4096 }
4097
4098 child = childOrOutOfFlow;
4099 if (aBuilder->IsForPainting()) {
4100 aBuilder->ClearWillChangeBudgetStatus(child);
4101 }
4102
4103 // If 'child' is a pushed float then it's owned by a block that's not an
4104 // ancestor of the placeholder, and it will be painted by that block and
4105 // should not be painted through the placeholder. Also recheck
4106 // NS_FRAME_TOO_DEEP_IN_FRAME_TREE and NS_FRAME_IS_NONDISPLAY.
4107 static const nsFrameState skipFlags =
4108 (NS_FRAME_IS_PUSHED_FLOAT | NS_FRAME_TOO_DEEP_IN_FRAME_TREE |
4109 NS_FRAME_IS_NONDISPLAY);
4110 if (child->HasAnyStateBits(skipFlags) || nsLayoutUtils::IsPopup(child)) {
4111 return;
4112 }
4113
4114 MOZ_ASSERT(child->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(child->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW))>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(child->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("child->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4114); AnnotateMozCrashReason("MOZ_ASSERT" "(" "child->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)"
")"); do { *((volatile int*)__null) = 4114; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4115 savedOutOfFlowData = nsDisplayListBuilder::GetOutOfFlowData(child);
4116
4117 if (aBuilder->GetIncludeAllOutOfFlows()) {
4118 visible = child->InkOverflowRect();
4119 dirty = child->InkOverflowRect();
4120 } else if (savedOutOfFlowData) {
4121 visible =
4122 savedOutOfFlowData->GetVisibleRectForFrame(aBuilder, child, &dirty);
4123 } else {
4124 // The out-of-flow frame did not intersect the dirty area. We may still
4125 // need to traverse into it, since it may contain placeholders we need
4126 // to enter to reach other out-of-flow frames that are visible.
4127 visible.SetEmpty();
4128 dirty.SetEmpty();
4129 }
4130 }
4131
4132 NS_ASSERTION(!child->IsPlaceholderFrame(),do { if (!(!child->IsPlaceholderFrame())) { NS_DebugBreak(
NS_DEBUG_ASSERTION, "Should have dealt with placeholders already"
, "!child->IsPlaceholderFrame()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4133); MOZ_PretendNoReturn(); } } while (0)
4133 "Should have dealt with placeholders already")do { if (!(!child->IsPlaceholderFrame())) { NS_DebugBreak(
NS_DEBUG_ASSERTION, "Should have dealt with placeholders already"
, "!child->IsPlaceholderFrame()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4133); MOZ_PretendNoReturn(); } } while (0)
;
4134
4135 if (!DescendIntoChild(aBuilder, child, visible, dirty)) {
4136 DL_LOGV("Skipped frame %p", child)do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess
(); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, LogLevel::Verbose)), 0))) { mozilla::detail::log_print(moz_real_module
, LogLevel::Verbose, "Skipped frame %p", child); } } while (0
)
;
4137 return;
4138 }
4139
4140 const bool isSVG = child->HasAnyStateBits(NS_FRAME_SVG_LAYOUT);
4141
4142 // This flag is raised if the control flow strays off the common path.
4143 // The common path is the most common one of THE COMMON CASE mentioned later.
4144 bool awayFromCommonPath = !isPaintingToWindow;
4145
4146 // true if this is a real or pseudo stacking context
4147 bool pseudoStackingContext =
4148 aFlags.contains(DisplayChildFlag::ForcePseudoStackingContext);
4149
4150 if (!pseudoStackingContext && !isSVG &&
4151 aFlags.contains(DisplayChildFlag::Inline) &&
4152 !child->IsLineParticipant()) {
4153 // child is a non-inline frame in an inline context, i.e.,
4154 // it acts like inline-block or inline-table. Therefore it is a
4155 // pseudo-stacking-context.
4156 pseudoStackingContext = true;
4157 }
4158
4159 const nsStyleDisplay* ourDisp = StyleDisplay();
4160 // Don't paint our children if the theme object is a leaf.
4161 if (IsThemed(ourDisp) && !PresContext()->Theme()->WidgetIsContainer(
4162 ourDisp->EffectiveAppearance())) {
4163 return;
4164 }
4165
4166 // Since we're now sure that we're adding this frame to the display list
4167 // (which means we're painting it, modulo occlusion), mark it as visible
4168 // within the displayport.
4169 if (isPaintingToWindow && child->TrackingVisibility() &&
4170 child->IsVisibleForPainting()) {
4171 child->PresShell()->EnsureFrameInApproximatelyVisibleList(child);
4172 awayFromCommonPath = true;
4173 }
4174
4175 // Child is composited if it's transformed, partially transparent, or has
4176 // SVG effects or a blend mode..
4177 const nsStyleDisplay* disp = child->StyleDisplay();
4178 const nsStyleEffects* effects = child->StyleEffects();
4179
4180 const bool isPositioned = disp->IsPositionedStyle();
4181 const bool isStackingContext =
4182 aFlags.contains(DisplayChildFlag::ForceStackingContext) ||
4183 child->IsStackingContext(disp, effects);
4184
4185 if (pseudoStackingContext || isStackingContext || isPositioned ||
4186 placeholder || (!isSVG && disp->IsFloating(child)) ||
4187 (isSVG && effects->mClip.IsRect() && IsSVGContentWithCSSClip(child))) {
4188 pseudoStackingContext = true;
4189 awayFromCommonPath = true;
4190 }
4191
4192 NS_ASSERTION(!isStackingContext || pseudoStackingContext,do { if (!(!isStackingContext || pseudoStackingContext)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Stacking contexts must also be pseudo-stacking-contexts"
, "!isStackingContext || pseudoStackingContext", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4193); MOZ_PretendNoReturn(); } } while (0)
4193 "Stacking contexts must also be pseudo-stacking-contexts")do { if (!(!isStackingContext || pseudoStackingContext)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Stacking contexts must also be pseudo-stacking-contexts"
, "!isStackingContext || pseudoStackingContext", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4193); MOZ_PretendNoReturn(); } } while (0)
;
4194
4195 nsDisplayListBuilder::AutoBuildingDisplayList buildingForChild(
4196 aBuilder, child, visible, dirty);
4197
4198 UpdateCurrentHitTestInfo(aBuilder, child);
4199
4200 DisplayListClipState::AutoClipMultiple clipState(aBuilder);
4201 nsDisplayListBuilder::AutoCurrentActiveScrolledRootSetter asrSetter(aBuilder);
4202
4203 if (savedOutOfFlowData) {
4204 aBuilder->SetBuildingInvisibleItems(false);
4205
4206 clipState.SetClipChainForContainingBlockDescendants(
4207 savedOutOfFlowData->mContainingBlockClipChain);
4208 asrSetter.SetCurrentActiveScrolledRoot(
4209 savedOutOfFlowData->mContainingBlockActiveScrolledRoot);
4210 asrSetter.SetCurrentScrollParentId(savedOutOfFlowData->mScrollParentId);
4211 MOZ_ASSERT(awayFromCommonPath,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(awayFromCommonPath)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(awayFromCommonPath))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("awayFromCommonPath"
" (" "It is impossible when savedOutOfFlowData is true" ")",
"/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4212); AnnotateMozCrashReason("MOZ_ASSERT" "(" "awayFromCommonPath"
") (" "It is impossible when savedOutOfFlowData is true" ")"
); do { *((volatile int*)__null) = 4212; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4212 "It is impossible when savedOutOfFlowData is true")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(awayFromCommonPath)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(awayFromCommonPath))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("awayFromCommonPath"
" (" "It is impossible when savedOutOfFlowData is true" ")",
"/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4212); AnnotateMozCrashReason("MOZ_ASSERT" "(" "awayFromCommonPath"
") (" "It is impossible when savedOutOfFlowData is true" ")"
); do { *((volatile int*)__null) = 4212; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4213 } else if (HasAnyStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO) &&
4214 placeholder) {
4215 NS_ASSERTION(visible.IsEmpty(), "should have empty visible rect")do { if (!(visible.IsEmpty())) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "should have empty visible rect", "visible.IsEmpty()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4215); MOZ_PretendNoReturn(); } } while (0)
;
4216 // Every item we build from now until we descent into an out of flow that
4217 // does have saved out of flow data should be invisible. This state gets
4218 // restored when AutoBuildingDisplayList gets out of scope.
4219 aBuilder->SetBuildingInvisibleItems(true);
4220
4221 // If we have nested out-of-flow frames and the outer one isn't visible
4222 // then we won't have stored clip data for it. We can just clear the clip
4223 // instead since we know we won't render anything, and the inner out-of-flow
4224 // frame will setup the correct clip for itself.
4225 clipState.SetClipChainForContainingBlockDescendants(nullptr);
4226 }
4227
4228 // Setup clipping for the parent's overflow:clip,
4229 // or overflow:hidden on elements that don't support scrolling (and therefore
4230 // don't create nsHTML/XULScrollFrame). This clipping needs to not clip
4231 // anything directly rendered by the parent, only the rendering of its
4232 // children.
4233 // Don't use overflowClip to restrict the dirty rect, since some of the
4234 // descendants may not be clipped by it. Even if we end up with unnecessary
4235 // display items, they'll be pruned during ComputeVisibility.
4236 //
4237 // FIXME(emilio): Why can't we handle this more similarly to `clip` (on the
4238 // parent, rather than on the children)? Would ClipContentDescendants do what
4239 // we want?
4240 if (overflowClipAxes != PhysicalAxes::None) {
4241 ApplyOverflowClipping(aBuilder, parent, overflowClipAxes, clipState);
4242 awayFromCommonPath = true;
4243 }
4244
4245 nsDisplayList list(aBuilder);
4246 nsDisplayList extraPositionedDescendants(aBuilder);
4247 const ActiveScrolledRoot* wrapListASR;
4248 bool builtContainerItem = false;
4249 if (isStackingContext) {
4250 // True stacking context.
4251 // For stacking contexts, BuildDisplayListForStackingContext handles
4252 // clipping and MarkAbsoluteFramesForDisplayList.
4253 nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
4254 child->BuildDisplayListForStackingContext(aBuilder, &list,
4255 &builtContainerItem);
4256 wrapListASR = contASRTracker.GetContainerASR();
4257 if (!aBuilder->IsReusingStackingContextItems() &&
4258 aBuilder->GetCaretFrame() == child) {
4259 builtContainerItem = false;
4260 }
4261 } else {
4262 Maybe<nsRect> clipPropClip =
4263 child->GetClipPropClipRect(disp, effects, child->GetSize());
4264 if (clipPropClip) {
4265 aBuilder->IntersectVisibleRect(*clipPropClip);
4266 aBuilder->IntersectDirtyRect(*clipPropClip);
4267 clipState.ClipContentDescendants(*clipPropClip +
4268 aBuilder->ToReferenceFrame(child));
4269 awayFromCommonPath = true;
4270 }
4271
4272 child->MarkAbsoluteFramesForDisplayList(aBuilder);
4273 child->SetBuiltDisplayList(true);
4274
4275 // Some SVG frames might change opacity without invalidating the frame, so
4276 // exclude them from the fast-path.
4277 if (!awayFromCommonPath && !child->IsSVGFrame()) {
4278 // The shortcut is available for the child for next time.
4279 child->AddStateBits(NS_FRAME_SIMPLE_DISPLAYLIST);
4280 }
4281
4282 if (!pseudoStackingContext) {
4283 // THIS IS THE COMMON CASE.
4284 // Not a pseudo or real stacking context. Do the simple thing and
4285 // return early.
4286 aBuilder->AdjustWindowDraggingRegion(child);
4287 aBuilder->Check();
4288 child->BuildDisplayList(aBuilder, aLists);
4289 aBuilder->Check();
4290 aBuilder->DisplayCaret(child, aLists.Outlines());
4291 return;
4292 }
4293
4294 // A pseudo-stacking context (e.g., a positioned element with z-index auto).
4295 // We allow positioned descendants of the child to escape to our parent
4296 // stacking context's positioned descendant list, because they might be
4297 // z-index:non-auto
4298 nsDisplayListCollection pseudoStack(aBuilder);
4299
4300 aBuilder->AdjustWindowDraggingRegion(child);
4301 nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
4302 aBuilder->Check();
4303 child->BuildDisplayList(aBuilder, pseudoStack);
4304 aBuilder->Check();
4305 if (aBuilder->DisplayCaret(child, pseudoStack.Outlines())) {
4306 builtContainerItem = false;
4307 }
4308 wrapListASR = contASRTracker.GetContainerASR();
4309
4310 list.AppendToTop(pseudoStack.BorderBackground());
4311 list.AppendToTop(pseudoStack.BlockBorderBackgrounds());
4312 list.AppendToTop(pseudoStack.Floats());
4313 list.AppendToTop(pseudoStack.Content());
4314 list.AppendToTop(pseudoStack.Outlines());
4315 extraPositionedDescendants.AppendToTop(pseudoStack.PositionedDescendants());
4316 }
4317
4318 buildingForChild.RestoreBuildingInvisibleItemsValue();
4319
4320 if (!list.IsEmpty()) {
4321 if (isPositioned || isStackingContext) {
4322 // Genuine stacking contexts, and positioned pseudo-stacking-contexts,
4323 // go in this level.
4324 nsDisplayItem* item = WrapInWrapList(aBuilder, child, &list, wrapListASR,
4325 builtContainerItem);
4326 if (isSVG) {
4327 aLists.Content()->AppendToTop(item);
4328 } else {
4329 aLists.PositionedDescendants()->AppendToTop(item);
4330 }
4331 } else if (!isSVG && disp->IsFloating(child)) {
4332 aLists.Floats()->AppendToTop(
4333 WrapInWrapList(aBuilder, child, &list, wrapListASR));
4334 } else {
4335 aLists.Content()->AppendToTop(&list);
4336 }
4337 }
4338 // We delay placing the positioned descendants of positioned frames to here,
4339 // because in the absence of z-index this is the correct order for them.
4340 // This doesn't affect correctness because the positioned descendants list
4341 // is sorted by z-order and content in BuildDisplayListForStackingContext,
4342 // but it means that sort routine needs to do less work.
4343 aLists.PositionedDescendants()->AppendToTop(&extraPositionedDescendants);
4344}
4345
4346void nsIFrame::MarkAbsoluteFramesForDisplayList(
4347 nsDisplayListBuilder* aBuilder) {
4348 if (IsAbsoluteContainer()) {
4349 aBuilder->MarkFramesForDisplayList(
4350 this, GetAbsoluteContainingBlock()->GetChildList());
4351 }
4352}
4353
4354nsresult nsIFrame::GetContentForEvent(const WidgetEvent* aEvent,
4355 nsIContent** aContent) {
4356 nsIFrame* f = nsLayoutUtils::GetNonGeneratedAncestor(this);
4357 *aContent = f->GetContent();
4358 NS_IF_ADDREF(*aContent)ns_if_addref(*aContent);
4359 return NS_OK;
4360}
4361
4362void nsIFrame::FireDOMEvent(const nsAString& aDOMEventName,
4363 nsIContent* aContent) {
4364 nsIContent* target = aContent ? aContent : GetContent();
4365
4366 if (target) {
4367 RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
4368 target, aDOMEventName, CanBubble::eYes, ChromeOnlyDispatch::eNo);
4369 DebugOnly<nsresult> rv = asyncDispatcher->PostDOMEvent();
4370 NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncEventDispatcher failed to dispatch")do { if (!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1
))))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "AsyncEventDispatcher failed to dispatch"
, "NS_SUCCEEDED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4370); MOZ_PretendNoReturn(); } } while (0)
;
4371 }
4372}
4373
4374nsresult nsIFrame::HandleEvent(nsPresContext* aPresContext,
4375 WidgetGUIEvent* aEvent,
4376 nsEventStatus* aEventStatus) {
4377 if (aEvent->mMessage == eMouseMove) {
4378 // XXX If the second argument of HandleDrag() is WidgetMouseEvent,
4379 // the implementation becomes simpler.
4380 return HandleDrag(aPresContext, aEvent, aEventStatus);
4381 }
4382
4383 if ((aEvent->mClass == eMouseEventClass &&
4384 aEvent->AsMouseEvent()->mButton == MouseButton::ePrimary) ||
4385 aEvent->mClass == eTouchEventClass) {
4386 if (aEvent->mMessage == eMouseDown || aEvent->mMessage == eTouchStart) {
4387 HandlePress(aPresContext, aEvent, aEventStatus);
4388 } else if (aEvent->mMessage == eMouseUp || aEvent->mMessage == eTouchEnd) {
4389 HandleRelease(aPresContext, aEvent, aEventStatus);
4390 }
4391 return NS_OK;
4392 }
4393
4394 // When secondary buttion is down, we need to move selection to make users
4395 // possible to paste something at click point quickly.
4396 // When middle button is down, we need to just move selection and focus at
4397 // the clicked point. Note that even if middle click paste is not enabled,
4398 // Chrome moves selection at middle mouse button down. So, we should follow
4399 // the behavior for the compatibility.
4400 if (aEvent->mMessage == eMouseDown) {
4401 WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
4402 if (mouseEvent && (mouseEvent->mButton == MouseButton::eSecondary ||
4403 mouseEvent->mButton == MouseButton::eMiddle)) {
4404 if (*aEventStatus == nsEventStatus_eConsumeNoDefault) {
4405 return NS_OK;
4406 }
4407 return MoveCaretToEventPoint(aPresContext, mouseEvent, aEventStatus);
4408 }
4409 }
4410
4411 return NS_OK;
4412}
4413
4414nsresult nsIFrame::GetDataForTableSelection(
4415 const nsFrameSelection* aFrameSelection, mozilla::PresShell* aPresShell,
4416 WidgetMouseEvent* aMouseEvent, nsIContent** aParentContent,
4417 int32_t* aContentOffset, TableSelectionMode* aTarget) {
4418 if (!aFrameSelection || !aPresShell || !aMouseEvent || !aParentContent ||
4419 !aContentOffset || !aTarget)
4420 return NS_ERROR_NULL_POINTER;
4421
4422 *aParentContent = nullptr;
4423 *aContentOffset = 0;
4424 *aTarget = TableSelectionMode::None;
4425
4426 int16_t displaySelection = aPresShell->GetSelectionFlags();
4427
4428 bool selectingTableCells = aFrameSelection->IsInTableSelectionMode();
4429
4430 // DISPLAY_ALL means we're in an editor.
4431 // If already in cell selection mode,
4432 // continue selecting with mouse drag or end on mouse up,
4433 // or when using shift key to extend block of cells
4434 // (Mouse down does normal selection unless Ctrl/Cmd is pressed)
4435 bool doTableSelection =
4436 displaySelection == nsISelectionDisplay::DISPLAY_ALL &&
4437 selectingTableCells &&
4438 (aMouseEvent->mMessage == eMouseMove ||
4439 (aMouseEvent->mMessage == eMouseUp &&
4440 aMouseEvent->mButton == MouseButton::ePrimary) ||
4441 aMouseEvent->IsShift());
4442
4443 if (!doTableSelection) {
4444 // In Browser, special 'table selection' key must be pressed for table
4445 // selection or when just Shift is pressed and we're already in table/cell
4446 // selection mode
4447#ifdef XP_MACOSX
4448 doTableSelection = aMouseEvent->IsMeta() ||
4449 (aMouseEvent->IsShift() && selectingTableCells);
4450#else
4451 doTableSelection = aMouseEvent->IsControl() ||
4452 (aMouseEvent->IsShift() && selectingTableCells);
4453#endif
4454 }
4455 if (!doTableSelection) return NS_OK;
4456
4457 // Get the cell frame or table frame (or parent) of the current content node
4458 nsIFrame* frame = this;
4459 bool foundCell = false;
4460 bool foundTable = false;
4461
4462 // Get the limiting node to stop parent frame search
4463 nsIContent* limiter = aFrameSelection->GetLimiter();
4464
4465 // If our content node is an ancestor of the limiting node,
4466 // we should stop the search right now.
4467 if (limiter && limiter->IsInclusiveDescendantOf(GetContent())) return NS_OK;
4468
4469 // We don't initiate row/col selection from here now,
4470 // but we may in future
4471 // bool selectColumn = false;
4472 // bool selectRow = false;
4473
4474 while (frame) {
4475 // Check for a table cell by querying to a known CellFrame interface
4476 nsITableCellLayout* cellElement = do_QueryFrame(frame);
4477 if (cellElement) {
4478 foundCell = true;
4479 // TODO: If we want to use proximity to top or left border
4480 // for row and column selection, this is the place to do it
4481 break;
4482 } else {
4483 // If not a cell, check for table
4484 // This will happen when starting frame is the table or child of a table,
4485 // such as a row (we were inbetween cells or in table border)
4486 nsTableWrapperFrame* tableFrame = do_QueryFrame(frame);
4487 if (tableFrame) {
4488 foundTable = true;
4489 // TODO: How can we select row when along left table edge
4490 // or select column when along top edge?
4491 break;
4492 } else {
4493 frame = frame->GetParent();
4494 // Stop if we have hit the selection's limiting content node
4495 if (frame && frame->GetContent() == limiter) break;
4496 }
4497 }
4498 }
4499 // We aren't in a cell or table
4500 if (!foundCell && !foundTable) return NS_OK;
4501
4502 nsIContent* tableOrCellContent = frame->GetContent();
4503 if (!tableOrCellContent) return NS_ERROR_FAILURE;
4504
4505 nsCOMPtr<nsIContent> parentContent = tableOrCellContent->GetParent();
4506 if (!parentContent) return NS_ERROR_FAILURE;
4507
4508 const int32_t offset =
4509 parentContent->ComputeIndexOf_Deprecated(tableOrCellContent);
4510 // Not likely?
4511 if (offset < 0) {
4512 return NS_ERROR_FAILURE;
4513 }
4514
4515 // Everything is OK -- set the return values
4516 parentContent.forget(aParentContent);
4517
4518 *aContentOffset = offset;
4519
4520#if 0
4521 if (selectRow)
4522 *aTarget = TableSelectionMode::Row;
4523 else if (selectColumn)
4524 *aTarget = TableSelectionMode::Column;
4525 else
4526#endif
4527 if (foundCell) {
4528 *aTarget = TableSelectionMode::Cell;
4529 } else if (foundTable) {
4530 *aTarget = TableSelectionMode::Table;
4531 }
4532
4533 return NS_OK;
4534}
4535
4536static bool IsEditingHost(const nsIFrame* aFrame) {
4537 nsIContent* content = aFrame->GetContent();
4538 return content && content->IsEditingHost();
4539}
4540
4541static StyleUserSelect UsedUserSelect(const nsIFrame* aFrame) {
4542 if (aFrame->IsGeneratedContentFrame()) {
4543 return StyleUserSelect::None;
4544 }
4545
4546 // Per https://drafts.csswg.org/css-ui-4/#content-selection:
4547 //
4548 // The used value is the same as the computed value, except:
4549 //
4550 // 1 - on editable elements where the used value is always 'contain'
4551 // regardless of the computed value
4552 // 2 - when the computed value is auto, in which case the used value is one
4553 // of the other values...
4554 //
4555 // See https://github.com/w3c/csswg-drafts/issues/3344 to see why we do this
4556 // at used-value time instead of at computed-value time.
4557
4558 if (aFrame->IsTextInputFrame() || IsEditingHost(aFrame)) {
4559 // We don't implement 'contain' itself, but we make 'text' behave as
4560 // 'contain' for contenteditable and <input> / <textarea> elements anyway so
4561 // this is ok.
4562 return StyleUserSelect::Text;
4563 }
4564
4565 auto style = aFrame->Style()->UserSelect();
4566 if (style != StyleUserSelect::Auto) {
4567 return style;
4568 }
4569
4570 auto* parent = nsLayoutUtils::GetParentOrPlaceholderFor(aFrame);
4571 return parent ? UsedUserSelect(parent) : StyleUserSelect::Text;
4572}
4573
4574bool nsIFrame::IsSelectable(StyleUserSelect* aSelectStyle) const {
4575 auto style = UsedUserSelect(this);
4576 if (aSelectStyle) {
4577 *aSelectStyle = style;
4578 }
4579 return style != StyleUserSelect::None;
4580}
4581
4582bool nsIFrame::ShouldHaveLineIfEmpty() const {
4583 if (Style()->IsPseudoOrAnonBox() &&
4584 Style()->GetPseudoType() != PseudoStyleType::scrolledContent) {
4585 return false;
4586 }
4587 return IsEditingHost(this);
4588}
4589
4590/**
4591 * Handles the Mouse Press Event for the frame
4592 */
4593NS_IMETHODIMPnsresult
4594nsIFrame::HandlePress(nsPresContext* aPresContext, WidgetGUIEvent* aEvent,
4595 nsEventStatus* aEventStatus) {
4596 NS_ENSURE_ARG_POINTER(aEventStatus)do { if ((__builtin_expect(!!(!(aEventStatus)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aEventStatus" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4596); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4597 if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
4598 return NS_OK;
4599 }
4600
4601 NS_ENSURE_ARG_POINTER(aEvent)do { if ((__builtin_expect(!!(!(aEvent)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aEvent" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4601); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4602 if (aEvent->mClass == eTouchEventClass) {
4603 return NS_OK;
4604 }
4605
4606 return MoveCaretToEventPoint(aPresContext, aEvent->AsMouseEvent(),
4607 aEventStatus);
4608}
4609
4610nsresult nsIFrame::MoveCaretToEventPoint(nsPresContext* aPresContext,
4611 WidgetMouseEvent* aMouseEvent,
4612 nsEventStatus* aEventStatus) {
4613 MOZ_ASSERT(aPresContext)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPresContext)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aPresContext))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("aPresContext", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4613); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPresContext"
")"); do { *((volatile int*)__null) = 4613; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4614 MOZ_ASSERT(aMouseEvent)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aMouseEvent)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aMouseEvent))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("aMouseEvent", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4614); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aMouseEvent"
")"); do { *((volatile int*)__null) = 4614; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4615 MOZ_ASSERT(aMouseEvent->mMessage == eMouseDown)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aMouseEvent->mMessage == eMouseDown)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(aMouseEvent->mMessage == eMouseDown))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aMouseEvent->mMessage == eMouseDown"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4615); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aMouseEvent->mMessage == eMouseDown"
")"); do { *((volatile int*)__null) = 4615; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4616 MOZ_ASSERT(aEventStatus)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aEventStatus)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aEventStatus))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("aEventStatus", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4616); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aEventStatus"
")"); do { *((volatile int*)__null) = 4616; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4617 MOZ_ASSERT(nsEventStatus_eConsumeNoDefault != *aEventStatus)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(nsEventStatus_eConsumeNoDefault != *aEventStatus)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(nsEventStatus_eConsumeNoDefault != *aEventStatus))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("nsEventStatus_eConsumeNoDefault != *aEventStatus"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4617); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsEventStatus_eConsumeNoDefault != *aEventStatus"
")"); do { *((volatile int*)__null) = 4617; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4618
4619 mozilla::PresShell* presShell = aPresContext->GetPresShell();
4620 if (!presShell) {
4621 return NS_ERROR_FAILURE;
4622 }
4623
4624 // We often get out of sync state issues with mousedown events that
4625 // get interrupted by alerts/dialogs.
4626 // Check with the ESM to see if we should process this one
4627 if (!aPresContext->EventStateManager()->EventStatusOK(aMouseEvent)) {
4628 return NS_OK;
4629 }
4630
4631 const nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
4632 aMouseEvent, RelativeTo{this});
4633
4634 // When not using `alt`, and clicking on a draggable, but non-editable
4635 // element, don't do anything, and let d&d handle the event.
4636 //
4637 // See bug 48876, bug 388659 and bug 55921 for context here.
4638 //
4639 // FIXME(emilio): The .Contains(pt) check looks a bit fishy. When would it be
4640 // false given we're the event target? If it is needed, why not checking the
4641 // actual draggable node rect instead?
4642 if (!aMouseEvent->IsAlt() && GetRectRelativeToSelf().Contains(pt)) {
4643 for (nsIContent* content = mContent; content;
4644 content = content->GetFlattenedTreeParent()) {
4645 if (nsContentUtils::ContentIsDraggable(content) &&
4646 !content->IsEditable()) {
4647 return NS_OK;
4648 }
4649 }
4650 }
4651
4652 // If we are in Navigator and the click is in a draggable node, we don't want
4653 // to start selection because we don't want to interfere with a potential
4654 // drag of said node and steal all its glory.
4655 const bool isEditor =
4656 presShell->GetSelectionFlags() == nsISelectionDisplay::DISPLAY_ALL;
4657
4658 // Don't do something if it's middle button down event.
4659 const bool isPrimaryButtonDown =
4660 aMouseEvent->mButton == MouseButton::ePrimary;
4661
4662 // check whether style allows selection
4663 // if not, don't tell selection the mouse event even occurred.
4664 StyleUserSelect selectStyle;
4665 // check for select: none
4666 if (!IsSelectable(&selectStyle)) {
4667 return NS_OK;
4668 }
4669
4670 if (isPrimaryButtonDown) {
4671 // If the mouse is dragged outside the nearest enclosing scrollable area
4672 // while making a selection, the area will be scrolled. To do this, capture
4673 // the mouse on the nearest scrollable frame. If there isn't a scrollable
4674 // frame, or something else is already capturing the mouse, there's no
4675 // reason to capture.
4676 if (!PresShell::GetCapturingContent()) {
4677 nsIScrollableFrame* scrollFrame =
4678 nsLayoutUtils::GetNearestScrollableFrame(
4679 this, nsLayoutUtils::SCROLLABLE_SAME_DOC |
4680 nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
4681 if (scrollFrame) {
4682 nsIFrame* capturingFrame = do_QueryFrame(scrollFrame);
4683 PresShell::SetCapturingContent(capturingFrame->GetContent(),
4684 CaptureFlags::IgnoreAllowedState);
4685 }
4686 }
4687 }
4688
4689 // XXX This is screwy; it really should use the selection frame, not the
4690 // event frame
4691 const nsFrameSelection* frameselection =
4692 selectStyle == StyleUserSelect::Text ? GetConstFrameSelection()
4693 : presShell->ConstFrameSelection();
4694
4695 if (!frameselection || frameselection->GetDisplaySelection() ==
4696 nsISelectionController::SELECTION_OFF) {
4697 return NS_OK; // nothing to do we cannot affect selection from here
4698 }
4699
4700#ifdef XP_MACOSX
4701 // If Control key is pressed on macOS, it should be treated as right click.
4702 // So, don't change selection.
4703 if (aMouseEvent->IsControl()) {
4704 return NS_OK;
4705 }
4706 const bool control = aMouseEvent->IsMeta();
4707#else
4708 const bool control = aMouseEvent->IsControl();
4709#endif
4710
4711 RefPtr<nsFrameSelection> fc = const_cast<nsFrameSelection*>(frameselection);
4712 if (isPrimaryButtonDown && aMouseEvent->mClickCount > 1) {
4713 // These methods aren't const but can't actually delete anything,
4714 // so no need for AutoWeakFrame.
4715 fc->SetDragState(true);
4716 return HandleMultiplePress(aPresContext, aMouseEvent, aEventStatus,
4717 control);
4718 }
4719
4720 ContentOffsets offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN);
4721
4722 if (!offsets.content) {
4723 return NS_ERROR_FAILURE;
4724 }
4725
4726 if (aMouseEvent->mButton == MouseButton::eSecondary &&
4727 !MovingCaretToEventPointAllowedIfSecondaryButtonEvent(
4728 *frameselection, *aMouseEvent, *offsets.content,
4729 // When we collapse selection in nsFrameSelection::TakeFocus,
4730 // we always collapse selection to the start offset. Therefore,
4731 // we can ignore the end offset here. E.g., when an <img> is clicked,
4732 // set the primary offset to after it, but the the secondary offset
4733 // may be before it, see OffsetsForSingleFrame for the detail.
4734 offsets.StartOffset())) {
4735 return NS_OK;
4736 }
4737
4738 if (aMouseEvent->mMessage == eMouseDown &&
4739 aMouseEvent->mButton == MouseButton::eMiddle &&
4740 !offsets.content->IsEditable()) {
4741 // However, some users don't like the Chrome compatible behavior of
4742 // middle mouse click. They want to keep selection after starting
4743 // autoscroll. However, the selection change is important for middle
4744 // mouse past. Therefore, we should allow users to take the traditional
4745 // behavior back by themselves unless middle click paste is enabled or
4746 // autoscrolling is disabled.
4747 if (!Preferences::GetBool("middlemouse.paste", false) &&
4748 Preferences::GetBool("general.autoScroll", false) &&
4749 Preferences::GetBool("general.autoscroll.prevent_to_collapse_selection_"
4750 "by_middle_mouse_down",
4751 false)) {
4752 return NS_OK;
4753 }
4754 }
4755
4756 if (isPrimaryButtonDown) {
4757 // Let Ctrl/Cmd + left mouse down do table selection instead of drag
4758 // initiation.
4759 nsCOMPtr<nsIContent> parentContent;
4760 int32_t contentOffset;
4761 TableSelectionMode target;
4762 nsresult rv = GetDataForTableSelection(
4763 frameselection, presShell, aMouseEvent, getter_AddRefs(parentContent),
4764 &contentOffset, &target);
4765 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && parentContent) {
4766 fc->SetDragState(true);
4767 return fc->HandleTableSelection(parentContent, contentOffset, target,
4768 aMouseEvent);
4769 }
4770 }
4771
4772 fc->SetDelayedCaretData(0);
4773
4774 if (isPrimaryButtonDown) {
4775 // Check if any part of this frame is selected, and if the user clicked
4776 // inside the selected region, and if it's the left button. If so, we delay
4777 // starting a new selection since the user may be trying to drag the
4778 // selected region to some other app.
4779
4780 if (GetContent() && GetContent()->IsMaybeSelected()) {
4781 bool inSelection = false;
4782 UniquePtr<SelectionDetails> details = frameselection->LookUpSelection(
4783 offsets.content, 0, offsets.EndOffset(), false);
4784
4785 //
4786 // If there are any details, check to see if the user clicked
4787 // within any selected region of the frame.
4788 //
4789
4790 for (SelectionDetails* curDetail = details.get(); curDetail;
4791 curDetail = curDetail->mNext.get()) {
4792 //
4793 // If the user clicked inside a selection, then just
4794 // return without doing anything. We will handle placing
4795 // the caret later on when the mouse is released. We ignore
4796 // the spellcheck, find and url formatting selections.
4797 //
4798 if (curDetail->mSelectionType != SelectionType::eSpellCheck &&
4799 curDetail->mSelectionType != SelectionType::eFind &&
4800 curDetail->mSelectionType != SelectionType::eURLSecondary &&
4801 curDetail->mSelectionType != SelectionType::eURLStrikeout &&
4802 curDetail->mSelectionType != SelectionType::eHighlight &&
4803 curDetail->mStart <= offsets.StartOffset() &&
4804 offsets.EndOffset() <= curDetail->mEnd) {
4805 inSelection = true;
4806 }
4807 }
4808
4809 if (inSelection) {
4810 fc->SetDragState(false);
4811 fc->SetDelayedCaretData(aMouseEvent);
4812 return NS_OK;
4813 }
4814 }
4815
4816 fc->SetDragState(true);
4817 }
4818
4819 // Do not touch any nsFrame members after this point without adding
4820 // weakFrame checks.
4821 const nsFrameSelection::FocusMode focusMode = [&]() {
4822 // If "Shift" and "Ctrl" are both pressed, "Shift" is given precedence. This
4823 // mimics the old behaviour.
4824 if (aMouseEvent->IsShift()) {
4825 // If clicked in a link when focused content is editable, we should
4826 // collapse selection in the link for compatibility with Blink.
4827 if (isEditor) {
4828 for (Element* element : mContent->InclusiveAncestorsOfType<Element>()) {
4829 if (element->IsLink()) {
4830 return nsFrameSelection::FocusMode::kCollapseToNewPoint;
4831 }
4832 }
4833 }
4834 return nsFrameSelection::FocusMode::kExtendSelection;
4835 }
4836
4837 if (isPrimaryButtonDown && control) {
4838 return nsFrameSelection::FocusMode::kMultiRangeSelection;
4839 }
4840
4841 return nsFrameSelection::FocusMode::kCollapseToNewPoint;
4842 }();
4843
4844 nsresult rv = fc->HandleClick(
4845 MOZ_KnownLive(offsets.content)(offsets.content) /* bug 1636889 */, offsets.StartOffset(),
4846 offsets.EndOffset(), focusMode, offsets.associate);
4847 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4848 return rv;
4849 }
4850
4851 // We don't handle mouse button up if it's middle button.
4852 if (isPrimaryButtonDown && offsets.offset != offsets.secondaryOffset) {
4853 fc->MaintainSelection();
4854 }
4855
4856 if (isPrimaryButtonDown && isEditor && !aMouseEvent->IsShift() &&
4857 (offsets.EndOffset() - offsets.StartOffset()) == 1) {
4858 // A single node is selected and we aren't extending an existing selection,
4859 // which means the user clicked directly on an object (either
4860 // `user-select: all` or a non-text node without children). Therefore,
4861 // disable selection extension during mouse moves.
4862 // XXX This is a bit hacky; shouldn't editor be able to deal with this?
4863 fc->SetDragState(false);
4864 }
4865
4866 return NS_OK;
4867}
4868
4869bool nsIFrame::MovingCaretToEventPointAllowedIfSecondaryButtonEvent(
4870 const nsFrameSelection& aFrameSelection,
4871 WidgetMouseEvent& aSecondaryButtonEvent,
4872 const nsIContent& aContentAtEventPoint, int32_t aOffsetAtEventPoint) const {
4873 MOZ_ASSERT(aSecondaryButtonEvent.mButton == MouseButton::eSecondary)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aSecondaryButtonEvent.mButton == MouseButton::eSecondary
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aSecondaryButtonEvent.mButton == MouseButton::eSecondary
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"aSecondaryButtonEvent.mButton == MouseButton::eSecondary", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4873); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aSecondaryButtonEvent.mButton == MouseButton::eSecondary"
")"); do { *((volatile int*)__null) = 4873; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4874
4875 if (NS_WARN_IF(aOffsetAtEventPoint < 0)NS_warn_if_impl(aOffsetAtEventPoint < 0, "aOffsetAtEventPoint < 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4875)
) {
4876 return false;
4877 }
4878
4879 Selection* selection = aFrameSelection.GetSelection(SelectionType::eNormal);
4880 if (selection && !selection->IsCollapsed()) {
4881 // If right click in a selection range, we should not collapse selection.
4882 if (nsContentUtils::IsPointInSelection(
4883 *selection, aContentAtEventPoint,
4884 static_cast<uint32_t>(aOffsetAtEventPoint))) {
4885 return false;
4886 }
4887
4888 if (StaticPrefs::
4889 ui_mouse_right_click_collapse_selection_stop_if_non_collapsed_selection()) {
4890 // If currently selection is limited in an editing host, we should not
4891 // collapse selection if the clicked point is in the ancestor limiter.
4892 // Otherwise, this mouse click moves focus from the editing host to
4893 // different one or blur the editing host. In this case, we need to
4894 // update selection because keeping current selection in the editing
4895 // host looks like it's not blurred.
4896 // FIXME: If the active editing host is the document element, editor
4897 // does not set ancestor limiter properly. Fix it in the editor side.
4898 if (nsIContent* ancestorLimiter = selection->GetAncestorLimiter()) {
4899 MOZ_ASSERT(ancestorLimiter->IsEditable())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(ancestorLimiter->IsEditable())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(ancestorLimiter->IsEditable
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("ancestorLimiter->IsEditable()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4899); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ancestorLimiter->IsEditable()"
")"); do { *((volatile int*)__null) = 4899; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4900 return !aContentAtEventPoint.IsInclusiveDescendantOf(ancestorLimiter);
4901 }
4902 // If currently selection is not limited in an editing host, we should
4903 // collapse selection only when this click moves focus to an editing
4904 // host because we need to update selection in this case.
4905 if (!aContentAtEventPoint.IsEditable()) {
4906 return false;
4907 }
4908 }
4909 }
4910
4911 return !StaticPrefs::
4912 ui_mouse_right_click_collapse_selection_stop_if_non_editable_node() ||
4913 // The user does not want to collapse selection into non-editable
4914 // content by a right button click.
4915 aContentAtEventPoint.IsEditable() ||
4916 // Treat clicking in a text control as always clicked on editable
4917 // content because we want a hack only for clicking in normal text
4918 // nodes which is outside any editing hosts.
4919 aContentAtEventPoint.IsTextControlElement() ||
4920 TextControlElement::FromNodeOrNull(
4921 aContentAtEventPoint.GetClosestNativeAnonymousSubtreeRoot());
4922}
4923
4924nsresult nsIFrame::SelectByTypeAtPoint(nsPresContext* aPresContext,
4925 const nsPoint& aPoint,
4926 nsSelectionAmount aBeginAmountType,
4927 nsSelectionAmount aEndAmountType,
4928 uint32_t aSelectFlags) {
4929 NS_ENSURE_ARG_POINTER(aPresContext)do { if ((__builtin_expect(!!(!(aPresContext)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aPresContext" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4929); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4930
4931 // No point in selecting if selection is turned off
4932 if (DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF) {
4933 return NS_OK;
4934 }
4935
4936 ContentOffsets offsets = GetContentOffsetsFromPoint(aPoint, SKIP_HIDDEN);
4937 if (!offsets.content) {
4938 return NS_ERROR_FAILURE;
4939 }
4940
4941 int32_t offset;
4942 nsIFrame* frame = nsFrameSelection::GetFrameForNodeOffset(
4943 offsets.content, offsets.offset, offsets.associate, &offset);
4944 if (!frame) {
4945 return NS_ERROR_FAILURE;
4946 }
4947 return frame->PeekBackwardAndForward(aBeginAmountType, aEndAmountType, offset,
4948 aBeginAmountType != eSelectWord,
4949 aSelectFlags);
4950}
4951
4952/**
4953 * Multiple Mouse Press -- line or paragraph selection -- for the frame.
4954 * Wouldn't it be nice if this didn't have to be hardwired into Frame code?
4955 */
4956NS_IMETHODIMPnsresult
4957nsIFrame::HandleMultiplePress(nsPresContext* aPresContext,
4958 WidgetGUIEvent* aEvent,
4959 nsEventStatus* aEventStatus, bool aControlHeld) {
4960 NS_ENSURE_ARG_POINTER(aEvent)do { if ((__builtin_expect(!!(!(aEvent)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aEvent" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4960); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4961 NS_ENSURE_ARG_POINTER(aEventStatus)do { if ((__builtin_expect(!!(!(aEventStatus)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aEventStatus" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 4961); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4962
4963 if (nsEventStatus_eConsumeNoDefault == *aEventStatus ||
4964 DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF) {
4965 return NS_OK;
4966 }
4967
4968 // Find out whether we're doing line or paragraph selection.
4969 // If browser.triple_click_selects_paragraph is true, triple-click selects
4970 // paragraph. Otherwise, triple-click selects line, and quadruple-click
4971 // selects paragraph (on platforms that support quadruple-click).
4972 nsSelectionAmount beginAmount, endAmount;
4973 WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
4974 if (!mouseEvent) {
4975 return NS_OK;
4976 }
4977
4978 if (mouseEvent->mClickCount == 4) {
4979 beginAmount = endAmount = eSelectParagraph;
4980 } else if (mouseEvent->mClickCount == 3) {
4981 if (Preferences::GetBool("browser.triple_click_selects_paragraph")) {
4982 beginAmount = endAmount = eSelectParagraph;
4983 } else {
4984 beginAmount = eSelectBeginLine;
4985 endAmount = eSelectEndLine;
4986 }
4987 } else if (mouseEvent->mClickCount == 2) {
4988 // We only want inline frames; PeekBackwardAndForward dislikes blocks
4989 beginAmount = endAmount = eSelectWord;
4990 } else {
4991 return NS_OK;
4992 }
4993
4994 nsPoint relPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(
4995 mouseEvent, RelativeTo{this});
4996 return SelectByTypeAtPoint(aPresContext, relPoint, beginAmount, endAmount,
4997 (aControlHeld ? SELECT_ACCUMULATE : 0));
4998}
4999
5000nsresult nsIFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack,
5001 nsSelectionAmount aAmountForward,
5002 int32_t aStartPos, bool aJumpLines,
5003 uint32_t aSelectFlags) {
5004 nsIFrame* baseFrame = this;
5005 int32_t baseOffset = aStartPos;
5006 nsresult rv;
5007
5008 PeekOffsetOptions peekOffsetOptions{PeekOffsetOption::StopAtScroller};
5009 if (aJumpLines) {
5010 peekOffsetOptions += PeekOffsetOption::JumpLines;
5011 }
5012
5013 if (aAmountBack == eSelectWord) {
5014 // To avoid selecting the previous word when at start of word,
5015 // first move one character forward.
5016 PeekOffsetStruct pos(eSelectCharacter, eDirNext, aStartPos, nsPoint(0, 0),
5017 peekOffsetOptions);
5018 rv = PeekOffset(&pos);
5019 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
5020 baseFrame = pos.mResultFrame;
5021 baseOffset = pos.mContentOffset;
5022 }
5023 }
5024
5025 // Search backward for a boundary.
5026 PeekOffsetStruct startpos(aAmountBack, eDirPrevious, baseOffset,
5027 nsPoint(0, 0), peekOffsetOptions);
5028 rv = baseFrame->PeekOffset(&startpos);
5029 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5030 return rv;
5031 }
5032
5033 // If the backward search stayed within the same frame, search forward from
5034 // that position for the end boundary; but if it crossed out to a sibling or
5035 // ancestor, start from the original position.
5036 if (startpos.mResultFrame == baseFrame) {
5037 baseOffset = startpos.mContentOffset;
5038 } else {
5039 baseFrame = this;
5040 baseOffset = aStartPos;
5041 }
5042
5043 PeekOffsetStruct endpos(aAmountForward, eDirNext, baseOffset, nsPoint(0, 0),
5044 peekOffsetOptions);
5045 rv = baseFrame->PeekOffset(&endpos);
5046 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5047 return rv;
5048 }
5049
5050 // Keep frameSelection alive.
5051 RefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
5052
5053 const nsFrameSelection::FocusMode focusMode =
5054 (aSelectFlags & SELECT_ACCUMULATE)
5055 ? nsFrameSelection::FocusMode::kMultiRangeSelection
5056 : nsFrameSelection::FocusMode::kCollapseToNewPoint;
5057 rv = frameSelection->HandleClick(
5058 MOZ_KnownLive(startpos.mResultContent)(startpos.mResultContent) /* bug 1636889 */,
5059 startpos.mContentOffset, startpos.mContentOffset, focusMode,
5060 CARET_ASSOCIATE_AFTER);
5061 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5062 return rv;
5063 }
5064
5065 rv = frameSelection->HandleClick(
5066 MOZ_KnownLive(endpos.mResultContent)(endpos.mResultContent) /* bug 1636889 */,
5067 endpos.mContentOffset, endpos.mContentOffset,
5068 nsFrameSelection::FocusMode::kExtendSelection, CARET_ASSOCIATE_BEFORE);
5069 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5070 return rv;
5071 }
5072 if (aAmountBack == eSelectWord) {
5073 frameSelection->SetIsDoubleClickSelection(true);
5074 }
5075
5076 // maintain selection
5077 return frameSelection->MaintainSelection(aAmountBack);
5078}
5079
5080NS_IMETHODIMPnsresult nsIFrame::HandleDrag(nsPresContext* aPresContext,
5081 WidgetGUIEvent* aEvent,
5082 nsEventStatus* aEventStatus) {
5083 MOZ_ASSERT(aEvent->mClass == eMouseEventClass,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aEvent->mClass == eMouseEventClass)>::isValid,
"invalid assertion condition"); if ((__builtin_expect(!!(!(!
!(aEvent->mClass == eMouseEventClass))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aEvent->mClass == eMouseEventClass"
" (" "HandleDrag can only handle mouse event" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5084); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aEvent->mClass == eMouseEventClass"
") (" "HandleDrag can only handle mouse event" ")"); do { *(
(volatile int*)__null) = 5084; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
5084 "HandleDrag can only handle mouse event")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aEvent->mClass == eMouseEventClass)>::isValid,
"invalid assertion condition"); if ((__builtin_expect(!!(!(!
!(aEvent->mClass == eMouseEventClass))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aEvent->mClass == eMouseEventClass"
" (" "HandleDrag can only handle mouse event" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5084); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aEvent->mClass == eMouseEventClass"
") (" "HandleDrag can only handle mouse event" ")"); do { *(
(volatile int*)__null) = 5084; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
5085
5086 NS_ENSURE_ARG_POINTER(aEventStatus)do { if ((__builtin_expect(!!(!(aEventStatus)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aEventStatus" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5086); return NS_ERROR_INVALID_POINTER; } } while (false)
;
5087
5088 RefPtr<nsFrameSelection> frameselection = GetFrameSelection();
5089 if (!frameselection) {
5090 return NS_OK;
5091 }
5092
5093 bool mouseDown = frameselection->GetDragState();
5094 if (!mouseDown) {
5095 return NS_OK;
5096 }
5097
5098 nsIFrame* scrollbar =
5099 nsLayoutUtils::GetClosestFrameOfType(this, LayoutFrameType::Scrollbar);
5100 if (!scrollbar) {
5101 // XXX Do we really need to exclude non-selectable content here?
5102 // GetContentOffsetsFromPoint can handle it just fine, although some
5103 // other stuff might not like it.
5104 // NOTE: DetermineDisplaySelection() returns SELECTION_OFF for
5105 // non-selectable frames.
5106 if (DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF) {
5107 return NS_OK;
5108 }
5109 }
5110
5111 frameselection->StopAutoScrollTimer();
5112
5113 // Check if we are dragging in a table cell
5114 nsCOMPtr<nsIContent> parentContent;
5115 int32_t contentOffset;
5116 TableSelectionMode target;
5117 WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
5118 mozilla::PresShell* presShell = aPresContext->PresShell();
5119 nsresult result;
5120 result = GetDataForTableSelection(frameselection, presShell, mouseEvent,
5121 getter_AddRefs(parentContent),
5122 &contentOffset, &target);
5123
5124 AutoWeakFrame weakThis = this;
5125 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) && parentContent) {
5126 result = frameselection->HandleTableSelection(parentContent, contentOffset,
5127 target, mouseEvent);
5128 if (NS_WARN_IF(NS_FAILED(result))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(result
)), 0))), "NS_FAILED(result)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5128)
) {
5129 return result;
5130 }
5131 } else {
5132 nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent,
5133 RelativeTo{this});
5134 frameselection->HandleDrag(this, pt);
5135 }
5136
5137 // The frameselection object notifies selection listeners synchronously above
5138 // which might have killed us.
5139 if (!weakThis.IsAlive()) {
5140 return NS_OK;
5141 }
5142
5143 // get the nearest scrollframe
5144 nsIScrollableFrame* scrollFrame = nsLayoutUtils::GetNearestScrollableFrame(
5145 this, nsLayoutUtils::SCROLLABLE_SAME_DOC |
5146 nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
5147
5148 if (scrollFrame) {
5149 nsIFrame* capturingFrame = scrollFrame->GetScrolledFrame();
5150 if (capturingFrame) {
5151 nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
5152 mouseEvent, RelativeTo{capturingFrame});
5153 frameselection->StartAutoScrollTimer(capturingFrame, pt, 30);
5154 }
5155 }
5156
5157 return NS_OK;
5158}
5159
5160/**
5161 * This static method handles part of the nsIFrame::HandleRelease in a way
5162 * which doesn't rely on the nsFrame object to stay alive.
5163 */
5164MOZ_CAN_RUN_SCRIPT_BOUNDARY static nsresult HandleFrameSelection(
5165 nsFrameSelection* aFrameSelection, nsIFrame::ContentOffsets& aOffsets,
5166 bool aHandleTableSel, int32_t aContentOffsetForTableSel,
5167 TableSelectionMode aTargetForTableSel,
5168 nsIContent* aParentContentForTableSel, WidgetGUIEvent* aEvent,
5169 const nsEventStatus* aEventStatus) {
5170 if (!aFrameSelection) {
5171 return NS_OK;
5172 }
5173
5174 nsresult rv = NS_OK;
5175
5176 if (nsEventStatus_eConsumeNoDefault != *aEventStatus) {
5177 if (!aHandleTableSel) {
5178 if (!aOffsets.content || !aFrameSelection->HasDelayedCaretData()) {
5179 return NS_ERROR_FAILURE;
5180 }
5181
5182 // We are doing this to simulate what we would have done on HandlePress.
5183 // We didn't do it there to give the user an opportunity to drag
5184 // the text, but since they didn't drag, we want to place the
5185 // caret.
5186 // However, we'll use the mouse position from the release, since:
5187 // * it's easier
5188 // * that's the normal click position to use (although really, in
5189 // the normal case, small movements that don't count as a drag
5190 // can do selection)
5191 aFrameSelection->SetDragState(true);
5192
5193 const nsFrameSelection::FocusMode focusMode =
5194 aFrameSelection->IsShiftDownInDelayedCaretData()
5195 ? nsFrameSelection::FocusMode::kExtendSelection
5196 : nsFrameSelection::FocusMode::kCollapseToNewPoint;
5197 rv = aFrameSelection->HandleClick(
5198 MOZ_KnownLive(aOffsets.content)(aOffsets.content) /* bug 1636889 */,
5199 aOffsets.StartOffset(), aOffsets.EndOffset(), focusMode,
5200 aOffsets.associate);
5201 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5202 return rv;
5203 }
5204 } else if (aParentContentForTableSel) {
5205 aFrameSelection->SetDragState(false);
5206 rv = aFrameSelection->HandleTableSelection(
5207 aParentContentForTableSel, aContentOffsetForTableSel,
5208 aTargetForTableSel, aEvent->AsMouseEvent());
5209 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5210 return rv;
5211 }
5212 }
5213 aFrameSelection->SetDelayedCaretData(0);
5214 }
5215
5216 aFrameSelection->SetDragState(false);
5217 aFrameSelection->StopAutoScrollTimer();
5218
5219 return NS_OK;
5220}
5221
5222NS_IMETHODIMPnsresult nsIFrame::HandleRelease(nsPresContext* aPresContext,
5223 WidgetGUIEvent* aEvent,
5224 nsEventStatus* aEventStatus) {
5225 if (aEvent->mClass != eMouseEventClass) {
5226 return NS_OK;
5227 }
5228
5229 nsIFrame* activeFrame = GetActiveSelectionFrame(aPresContext, this);
5230
5231 nsCOMPtr<nsIContent> captureContent = PresShell::GetCapturingContent();
5232
5233 bool selectionOff =
5234 (DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF);
5235
5236 RefPtr<nsFrameSelection> frameselection;
5237 ContentOffsets offsets;
5238 nsCOMPtr<nsIContent> parentContent;
5239 int32_t contentOffsetForTableSel = 0;
5240 TableSelectionMode targetForTableSel = TableSelectionMode::None;
5241 bool handleTableSelection = true;
5242
5243 if (!selectionOff) {
5244 frameselection = GetFrameSelection();
5245 if (nsEventStatus_eConsumeNoDefault != *aEventStatus && frameselection) {
5246 // Check if the frameselection recorded the mouse going down.
5247 // If not, the user must have clicked in a part of the selection.
5248 // Place the caret before continuing!
5249
5250 if (frameselection->MouseDownRecorded()) {
5251 nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
5252 aEvent, RelativeTo{this});
5253 offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN);
5254 handleTableSelection = false;
5255 } else {
5256 GetDataForTableSelection(frameselection, PresShell(),
5257 aEvent->AsMouseEvent(),
5258 getter_AddRefs(parentContent),
5259 &contentOffsetForTableSel, &targetForTableSel);
5260 }
5261 }
5262 }
5263
5264 // We might be capturing in some other document and the event just happened to
5265 // trickle down here. Make sure that document's frame selection is notified.
5266 // Note, this may cause the current nsFrame object to be deleted, bug 336592.
5267 RefPtr<nsFrameSelection> frameSelection;
5268 if (activeFrame != this && activeFrame->DetermineDisplaySelection() !=
5269 nsISelectionController::SELECTION_OFF) {
5270 frameSelection = activeFrame->GetFrameSelection();
5271 }
5272
5273 // Also check the selection of the capturing content which might be in a
5274 // different document.
5275 if (!frameSelection && captureContent) {
5276 if (Document* doc = captureContent->GetComposedDoc()) {
5277 mozilla::PresShell* capturingPresShell = doc->GetPresShell();
5278 if (capturingPresShell &&
5279 capturingPresShell != PresContext()->GetPresShell()) {
5280 frameSelection = capturingPresShell->FrameSelection();
5281 }
5282 }
5283 }
5284
5285 if (frameSelection) {
5286 AutoWeakFrame wf(this);
5287 frameSelection->SetDragState(false);
5288 frameSelection->StopAutoScrollTimer();
5289 if (wf.IsAlive()) {
5290 nsIScrollableFrame* scrollFrame =
5291 nsLayoutUtils::GetNearestScrollableFrame(
5292 this, nsLayoutUtils::SCROLLABLE_SAME_DOC |
5293 nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
5294 if (scrollFrame) {
5295 // Perform any additional scrolling needed to maintain CSS snap point
5296 // requirements when autoscrolling is over.
5297 scrollFrame->ScrollSnap();
5298 }
5299 }
5300 }
5301
5302 // Do not call any methods of the current object after this point!!!
5303 // The object is perhaps dead!
5304
5305 return selectionOff ? NS_OK
5306 : HandleFrameSelection(
5307 frameselection, offsets, handleTableSelection,
5308 contentOffsetForTableSel, targetForTableSel,
5309 parentContent, aEvent, aEventStatus);
5310}
5311
5312struct MOZ_STACK_CLASS FrameContentRange {
5313 FrameContentRange(nsIContent* aContent, int32_t aStart, int32_t aEnd)
5314 : content(aContent), start(aStart), end(aEnd) {}
5315 nsCOMPtr<nsIContent> content;
5316 int32_t start;
5317 int32_t end;
5318};
5319
5320// Retrieve the content offsets of a frame
5321static FrameContentRange GetRangeForFrame(const nsIFrame* aFrame) {
5322 nsIContent* content = aFrame->GetContent();
5323 if (!content) {
5324 NS_WARNING("Frame has no content")NS_DebugBreak(NS_DEBUG_WARNING, "Frame has no content", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5324)
;
5325 return FrameContentRange(nullptr, -1, -1);
5326 }
5327
5328 LayoutFrameType type = aFrame->Type();
5329 if (type == LayoutFrameType::Text) {
5330 auto [offset, offsetEnd] = aFrame->GetOffsets();
5331 return FrameContentRange(content, offset, offsetEnd);
5332 }
5333
5334 if (type == LayoutFrameType::Br) {
5335 nsIContent* parent = content->GetParent();
5336 const int32_t beginOffset = parent->ComputeIndexOf_Deprecated(content);
5337 return FrameContentRange(parent, beginOffset, beginOffset);
5338 }
5339
5340 while (content->IsRootOfNativeAnonymousSubtree()) {
5341 content = content->GetParent();
5342 }
5343
5344 nsIContent* parent = content->GetParent();
5345 if (aFrame->IsBlockOutside() || !parent) {
5346 return FrameContentRange(content, 0, content->GetChildCount());
5347 }
5348
5349 // TODO(emilio): Revise this in presence of Shadow DOM / display: contents,
5350 // it's likely that we don't want to just walk the light tree, and we need to
5351 // change the representation of FrameContentRange.
5352 const int32_t index = parent->ComputeIndexOf_Deprecated(content);
5353 MOZ_ASSERT(index >= 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(index >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(index >= 0))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("index >= 0",
"/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5353); AnnotateMozCrashReason("MOZ_ASSERT" "(" "index >= 0"
")"); do { *((volatile int*)__null) = 5353; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5354 return FrameContentRange(parent, index, index + 1);
5355}
5356
5357// The FrameTarget represents the closest frame to a point that can be selected
5358// The frame is the frame represented, frameEdge says whether one end of the
5359// frame is the result (in which case different handling is needed), and
5360// afterFrame says which end is represented if frameEdge is true
5361struct FrameTarget {
5362 explicit operator bool() const { return !!frame; }
5363
5364 nsIFrame* frame = nullptr;
5365 bool frameEdge = false;
5366 bool afterFrame = false;
5367};
5368
5369// See function implementation for information
5370static FrameTarget GetSelectionClosestFrame(nsIFrame* aFrame,
5371 const nsPoint& aPoint,
5372 uint32_t aFlags);
5373
5374static bool SelfIsSelectable(nsIFrame* aFrame, uint32_t aFlags) {
5375 if ((aFlags & nsIFrame::SKIP_HIDDEN) &&
5376 !aFrame->StyleVisibility()->IsVisible()) {
5377 return false;
5378 }
5379 return !aFrame->IsGeneratedContentFrame() &&
5380 aFrame->Style()->UserSelect() != StyleUserSelect::None;
5381}
5382
5383static bool SelectionDescendToKids(nsIFrame* aFrame) {
5384 // If we are only near (not directly over) then don't traverse
5385 // frames with independent selection (e.g. text and list controls, see bug
5386 // 268497). Note that this prevents any of the users of this method from
5387 // entering form controls.
5388 // XXX We might want some way to allow using the up-arrow to go into a form
5389 // control, but the focus didn't work right anyway; it'd probably be enough
5390 // if the left and right arrows could enter textboxes (which I don't believe
5391 // they can at the moment)
5392 if (aFrame->IsTextInputFrame() || aFrame->IsListControlFrame()) {
5393 MOZ_ASSERT(aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5393); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5393; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5394 return false;
5395 }
5396
5397 // Failure in this assertion means a new type of frame forms the root of an
5398 // NS_FRAME_INDEPENDENT_SELECTION subtree. In such case, the condition above
5399 // should be changed to handle it.
5400 MOZ_ASSERT_IF(do { if (aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
)) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5402); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5402; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
5401 aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION),do { if (aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
)) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5402); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5402; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
5402 aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION))do { if (aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
)) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5402); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5402; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
5403
5404 if (aFrame->IsGeneratedContentFrame()) {
5405 return false;
5406 }
5407
5408 auto style = aFrame->Style()->UserSelect();
5409 return style != StyleUserSelect::All && style != StyleUserSelect::None;
5410}
5411
5412static FrameTarget GetSelectionClosestFrameForChild(nsIFrame* aChild,
5413 const nsPoint& aPoint,
5414 uint32_t aFlags) {
5415 nsIFrame* parent = aChild->GetParent();
5416 if (SelectionDescendToKids(aChild)) {
5417 nsPoint pt = aPoint - aChild->GetOffsetTo(parent);
5418 return GetSelectionClosestFrame(aChild, pt, aFlags);
5419 }
5420 return FrameTarget{aChild, false, false};
5421}
5422
5423// When the cursor needs to be at the beginning of a block, it shouldn't be
5424// before the first child. A click on a block whose first child is a block
5425// should put the cursor in the child. The cursor shouldn't be between the
5426// blocks, because that's not where it's expected.
5427// Note that this method is guaranteed to succeed.
5428static FrameTarget DrillDownToSelectionFrame(nsIFrame* aFrame, bool aEndFrame,
5429 uint32_t aFlags) {
5430 if (SelectionDescendToKids(aFrame)) {
5431 nsIFrame* result = nullptr;
5432 nsIFrame* frame = aFrame->PrincipalChildList().FirstChild();
5433 if (!aEndFrame) {
5434 while (frame && (!SelfIsSelectable(frame, aFlags) || frame->IsEmpty()))
5435 frame = frame->GetNextSibling();
5436 if (frame) result = frame;
5437 } else {
5438 // Because the frame tree is singly linked, to find the last frame,
5439 // we have to iterate through all the frames
5440 // XXX I have a feeling this could be slow for long blocks, although
5441 // I can't find any slowdowns
5442 while (frame) {
5443 if (!frame->IsEmpty() && SelfIsSelectable(frame, aFlags))
5444 result = frame;
5445 frame = frame->GetNextSibling();
5446 }
5447 }
5448 if (result) return DrillDownToSelectionFrame(result, aEndFrame, aFlags);
5449 }
5450 // If the current frame has no targetable children, target the current frame
5451 return FrameTarget{aFrame, true, aEndFrame};
5452}
5453
5454// This method finds the closest valid FrameTarget on a given line; if there is
5455// no valid FrameTarget on the line, it returns a null FrameTarget
5456static FrameTarget GetSelectionClosestFrameForLine(
5457 nsBlockFrame* aParent, nsBlockFrame::LineIterator aLine,
5458 const nsPoint& aPoint, uint32_t aFlags) {
5459 // Account for end of lines (any iterator from the block is valid)
5460 if (aLine == aParent->LinesEnd())
5461 return DrillDownToSelectionFrame(aParent, true, aFlags);
5462 nsIFrame* frame = aLine->mFirstChild;
5463 nsIFrame* closestFromIStart = nullptr;
5464 nsIFrame* closestFromIEnd = nullptr;
5465 nscoord closestIStart = aLine->IStart(), closestIEnd = aLine->IEnd();
5466 WritingMode wm = aLine->mWritingMode;
5467 LogicalPoint pt(wm, aPoint, aLine->mContainerSize);
5468 bool canSkipBr = false;
5469 bool lastFrameWasEditable = false;
5470 for (int32_t n = aLine->GetChildCount(); n;
5471 --n, frame = frame->GetNextSibling()) {
5472 // Skip brFrames. Can only skip if the line contains at least
5473 // one selectable and non-empty frame before. Also, avoid skipping brs if
5474 // the previous thing had a different editableness than us, since then we
5475 // may end up not being able to select after it if the br is the last thing
5476 // on the line.
5477 if (!SelfIsSelectable(frame, aFlags) || frame->IsEmpty() ||
5478 (canSkipBr && frame->IsBrFrame() &&
5479 lastFrameWasEditable == frame->GetContent()->IsEditable())) {
5480 continue;
5481 }
5482 canSkipBr = true;
5483 lastFrameWasEditable =
5484 frame->GetContent() && frame->GetContent()->IsEditable();
5485 LogicalRect frameRect =
5486 LogicalRect(wm, frame->GetRect(), aLine->mContainerSize);
5487 if (pt.I(wm) >= frameRect.IStart(wm)) {
5488 if (pt.I(wm) < frameRect.IEnd(wm)) {
5489 return GetSelectionClosestFrameForChild(frame, aPoint, aFlags);
5490 }
5491 if (frameRect.IEnd(wm) >= closestIStart) {
5492 closestFromIStart = frame;
5493 closestIStart = frameRect.IEnd(wm);
5494 }
5495 } else {
5496 if (frameRect.IStart(wm) <= closestIEnd) {
5497 closestFromIEnd = frame;
5498 closestIEnd = frameRect.IStart(wm);
5499 }
5500 }
5501 }
5502 if (!closestFromIStart && !closestFromIEnd) {
5503 // We should only get here if there are no selectable frames on a line
5504 // XXX Do we need more elaborate handling here?
5505 return FrameTarget();
5506 }
5507 if (closestFromIStart &&
5508 (!closestFromIEnd ||
5509 (abs(pt.I(wm) - closestIStart) <= abs(pt.I(wm) - closestIEnd)))) {
5510 return GetSelectionClosestFrameForChild(closestFromIStart, aPoint, aFlags);
5511 }
5512 return GetSelectionClosestFrameForChild(closestFromIEnd, aPoint, aFlags);
5513}
5514
5515// This method is for the special handling we do for block frames; they're
5516// special because they represent paragraphs and because they are organized
5517// into lines, which have bounds that are not stored elsewhere in the
5518// frame tree. Returns a null FrameTarget for frames which are not
5519// blocks or blocks with no lines except editable one.
5520static FrameTarget GetSelectionClosestFrameForBlock(nsIFrame* aFrame,
5521 const nsPoint& aPoint,
5522 uint32_t aFlags) {
5523 nsBlockFrame* bf = do_QueryFrame(aFrame);
5524 if (!bf) {
5525 return FrameTarget();
5526 }
5527
5528 // This code searches for the correct line
5529 nsBlockFrame::LineIterator end = bf->LinesEnd();
5530 nsBlockFrame::LineIterator curLine = bf->LinesBegin();
5531 nsBlockFrame::LineIterator closestLine = end;
5532
5533 if (curLine != end) {
5534 // Convert aPoint into a LogicalPoint in the writing-mode of this block
5535 WritingMode wm = curLine->mWritingMode;
5536 LogicalPoint pt(wm, aPoint, curLine->mContainerSize);
5537 do {
5538 // Check to see if our point lies within the line's block-direction bounds
5539 nscoord BCoord = pt.B(wm) - curLine->BStart();
5540 nscoord BSize = curLine->BSize();
5541 if (BCoord >= 0 && BCoord < BSize) {
5542 closestLine = curLine;
5543 break; // We found the line; stop looking
5544 }
5545 if (BCoord < 0) break;
5546 ++curLine;
5547 } while (curLine != end);
5548
5549 if (closestLine == end) {
5550 nsBlockFrame::LineIterator prevLine = curLine.prev();
5551 nsBlockFrame::LineIterator nextLine = curLine;
5552 // Avoid empty lines
5553 while (nextLine != end && nextLine->IsEmpty()) ++nextLine;
5554 while (prevLine != end && prevLine->IsEmpty()) --prevLine;
5555
5556 // This hidden pref dictates whether a point above or below all lines
5557 // comes up with a line or the beginning or end of the frame; 0 on
5558 // Windows, 1 on other platforms by default at the writing of this code
5559 int32_t dragOutOfFrame =
5560 Preferences::GetInt("browser.drag_out_of_frame_style");
5561
5562 if (prevLine == end) {
5563 if (dragOutOfFrame == 1 || nextLine == end)
5564 return DrillDownToSelectionFrame(aFrame, false, aFlags);
5565 closestLine = nextLine;
5566 } else if (nextLine == end) {
5567 if (dragOutOfFrame == 1)
5568 return DrillDownToSelectionFrame(aFrame, true, aFlags);
5569 closestLine = prevLine;
5570 } else { // Figure out which line is closer
5571 if (pt.B(wm) - prevLine->BEnd() < nextLine->BStart() - pt.B(wm))
5572 closestLine = prevLine;
5573 else
5574 closestLine = nextLine;
5575 }
5576 }
5577 }
5578
5579 do {
5580 if (auto target =
5581 GetSelectionClosestFrameForLine(bf, closestLine, aPoint, aFlags)) {
5582 return target;
5583 }
5584 ++closestLine;
5585 } while (closestLine != end);
5586
5587 // Fall back to just targeting the last targetable place
5588 return DrillDownToSelectionFrame(aFrame, true, aFlags);
5589}
5590
5591// Use frame edge for grid, flex, table, and non-editable images. Choose the
5592// edge based on the point position past the frame rect. If past the middle,
5593// caret should be at end, otherwise at start. This behavior matches Blink.
5594//
5595// TODO(emilio): Can we use this code path for other replaced elements other
5596// than images? Or even all other frames? We only get there when we didn't find
5597// selectable children... At least one XUL test fails if we make this apply to
5598// XUL labels. Also, editable images need _not_ to use the frame edge, see
5599// below.
5600static bool UseFrameEdge(nsIFrame* aFrame) {
5601 if (aFrame->IsFlexOrGridContainer() || aFrame->IsTableFrame()) {
5602 return true;
5603 }
5604 const nsImageFrame* image = do_QueryFrame(aFrame);
5605 if (image && !aFrame->GetContent()->IsEditable()) {
5606 // Editable images are a special-case because editing relies on clicking on
5607 // an editable image selecting it, for it to show resizers.
5608 return true;
5609 }
5610 return false;
5611}
5612
5613static FrameTarget LastResortFrameTargetForFrame(nsIFrame* aFrame,
5614 const nsPoint& aPoint) {
5615 if (!UseFrameEdge(aFrame)) {
5616 return {aFrame, false, false};
5617 }
5618 const auto& rect = aFrame->GetRectRelativeToSelf();
5619 nscoord reference;
5620 nscoord middle;
5621 if (aFrame->GetWritingMode().IsVertical()) {
5622 reference = aPoint.y;
5623 middle = rect.Height() / 2;
5624 } else {
5625 reference = aPoint.x;
5626 middle = rect.Width() / 2;
5627 }
5628 const bool afterFrame = reference > middle;
5629 return {aFrame, true, afterFrame};
5630}
5631
5632// GetSelectionClosestFrame is the helper function that calculates the closest
5633// frame to the given point.
5634// It doesn't completely account for offset styles, so needs to be used in
5635// restricted environments.
5636// Cannot handle overlapping frames correctly, so it should receive the output
5637// of GetFrameForPoint
5638// Guaranteed to return a valid FrameTarget.
5639// aPoint is relative to aFrame.
5640static FrameTarget GetSelectionClosestFrame(nsIFrame* aFrame,
5641 const nsPoint& aPoint,
5642 uint32_t aFlags) {
5643 // Handle blocks; if the frame isn't a block, the method fails
5644 if (auto target = GetSelectionClosestFrameForBlock(aFrame, aPoint, aFlags)) {
5645 return target;
5646 }
5647
5648 if (nsIFrame* kid = aFrame->PrincipalChildList().FirstChild()) {
5649 // Go through all the child frames to find the closest one
5650 nsIFrame::FrameWithDistance closest = {nullptr, nscoord_MAXnscoord((1 << 30) - 1), nscoord_MAXnscoord((1 << 30) - 1)};
5651 for (; kid; kid = kid->GetNextSibling()) {
5652 if (!SelfIsSelectable(kid, aFlags) || kid->IsEmpty()) continue;
5653
5654 kid->FindCloserFrameForSelection(aPoint, &closest);
5655 }
5656 if (closest.mFrame) {
5657 if (closest.mFrame->IsInSVGTextSubtree())
5658 return FrameTarget{closest.mFrame, false, false};
5659 return GetSelectionClosestFrameForChild(closest.mFrame, aPoint, aFlags);
5660 }
5661 }
5662
5663 return LastResortFrameTargetForFrame(aFrame, aPoint);
5664}
5665
5666static nsIFrame::ContentOffsets OffsetsForSingleFrame(nsIFrame* aFrame,
5667 const nsPoint& aPoint) {
5668 nsIFrame::ContentOffsets offsets;
5669 FrameContentRange range = GetRangeForFrame(aFrame);
5670 offsets.content = range.content;
5671 // If there are continuations (meaning it's not one rectangle), this is the
5672 // best this function can do
5673 if (aFrame->GetNextContinuation() || aFrame->GetPrevContinuation()) {
5674 offsets.offset = range.start;
5675 offsets.secondaryOffset = range.end;
5676 offsets.associate = CARET_ASSOCIATE_AFTER;
5677 return offsets;
5678 }
5679
5680 // Figure out whether the offsets should be over, after, or before the frame
5681 nsRect rect(nsPoint(0, 0), aFrame->GetSize());
5682
5683 bool isBlock = !aFrame->StyleDisplay()->IsInlineFlow();
5684 bool isRtl = (aFrame->StyleVisibility()->mDirection == StyleDirection::Rtl);
5685 if ((isBlock && rect.y < aPoint.y) ||
5686 (!isBlock && ((isRtl && rect.x + rect.width / 2 > aPoint.x) ||
5687 (!isRtl && rect.x + rect.width / 2 < aPoint.x)))) {
5688 offsets.offset = range.end;
5689 if (rect.Contains(aPoint))
5690 offsets.secondaryOffset = range.start;
5691 else
5692 offsets.secondaryOffset = range.end;
5693 } else {
5694 offsets.offset = range.start;
5695 if (rect.Contains(aPoint))
5696 offsets.secondaryOffset = range.end;
5697 else
5698 offsets.secondaryOffset = range.start;
5699 }
5700 offsets.associate = offsets.offset == range.start ? CARET_ASSOCIATE_AFTER
5701 : CARET_ASSOCIATE_BEFORE;
5702 return offsets;
5703}
5704
5705static nsIFrame* AdjustFrameForSelectionStyles(nsIFrame* aFrame) {
5706 nsIFrame* adjustedFrame = aFrame;
5707 for (nsIFrame* frame = aFrame; frame; frame = frame->GetParent()) {
5708 // These are the conditions that make all children not able to handle
5709 // a cursor.
5710 auto userSelect = frame->Style()->UserSelect();
5711 if (userSelect != StyleUserSelect::Auto &&
5712 userSelect != StyleUserSelect::All) {
5713 break;
5714 }
5715 if (userSelect == StyleUserSelect::All ||
5716 frame->IsGeneratedContentFrame()) {
5717 adjustedFrame = frame;
5718 }
5719 }
5720 return adjustedFrame;
5721}
5722
5723nsIFrame::ContentOffsets nsIFrame::GetContentOffsetsFromPoint(
5724 const nsPoint& aPoint, uint32_t aFlags) {
5725 nsIFrame* adjustedFrame;
5726 if (aFlags & IGNORE_SELECTION_STYLE) {
5727 adjustedFrame = this;
5728 } else {
5729 // This section of code deals with special selection styles. Note that
5730 // -moz-all exists, even though it doesn't need to be explicitly handled.
5731 //
5732 // The offset is forced not to end up in generated content; content offsets
5733 // cannot represent content outside of the document's content tree.
5734
5735 adjustedFrame = AdjustFrameForSelectionStyles(this);
5736
5737 // `user-select: all` needs special handling, because clicking on it should
5738 // lead to the whole frame being selected.
5739 if (adjustedFrame->Style()->UserSelect() == StyleUserSelect::All) {
5740 nsPoint adjustedPoint = aPoint + GetOffsetTo(adjustedFrame);
5741 return OffsetsForSingleFrame(adjustedFrame, adjustedPoint);
5742 }
5743
5744 // For other cases, try to find a closest frame starting from the parent of
5745 // the unselectable frame
5746 if (adjustedFrame != this) {
5747 adjustedFrame = adjustedFrame->GetParent();
5748 }
5749 }
5750
5751 nsPoint adjustedPoint = aPoint + GetOffsetTo(adjustedFrame);
5752
5753 FrameTarget closest =
5754 GetSelectionClosestFrame(adjustedFrame, adjustedPoint, aFlags);
5755
5756 // If the correct offset is at one end of a frame, use offset-based
5757 // calculation method
5758 if (closest.frameEdge) {
5759 ContentOffsets offsets;
5760 FrameContentRange range = GetRangeForFrame(closest.frame);
5761 offsets.content = range.content;
5762 if (closest.afterFrame)
5763 offsets.offset = range.end;
5764 else
5765 offsets.offset = range.start;
5766 offsets.secondaryOffset = offsets.offset;
5767 offsets.associate = offsets.offset == range.start ? CARET_ASSOCIATE_AFTER
5768 : CARET_ASSOCIATE_BEFORE;
5769 return offsets;
5770 }
5771
5772 nsPoint pt;
5773 if (closest.frame != this) {
5774 if (closest.frame->IsInSVGTextSubtree()) {
5775 pt = nsLayoutUtils::TransformAncestorPointToFrame(
5776 RelativeTo{closest.frame}, aPoint, RelativeTo{this});
5777 } else {
5778 pt = aPoint - closest.frame->GetOffsetTo(this);
5779 }
5780 } else {
5781 pt = aPoint;
5782 }
5783 return closest.frame->CalcContentOffsetsFromFramePoint(pt);
5784
5785 // XXX should I add some kind of offset standardization?
5786 // consider <b>xxxxx</b><i>zzzzz</i>; should any click between the last
5787 // x and first z put the cursor in the same logical position in addition
5788 // to the same visual position?
5789}
5790
5791nsIFrame::ContentOffsets nsIFrame::CalcContentOffsetsFromFramePoint(
5792 const nsPoint& aPoint) {
5793 return OffsetsForSingleFrame(this, aPoint);
5794}
5795
5796bool nsIFrame::AssociateImage(const StyleImage& aImage) {
5797 imgRequestProxy* req = aImage.GetImageRequest();
5798 if (!req) {
5799 return false;
5800 }
5801
5802 mozilla::css::ImageLoader* loader =
5803 PresContext()->Document()->StyleImageLoader();
5804
5805 loader->AssociateRequestToFrame(req, this);
5806 return true;
5807}
5808
5809void nsIFrame::DisassociateImage(const StyleImage& aImage) {
5810 imgRequestProxy* req = aImage.GetImageRequest();
5811 if (!req) {
5812 return;
5813 }
5814
5815 mozilla::css::ImageLoader* loader =
5816 PresContext()->Document()->StyleImageLoader();
5817
5818 loader->DisassociateRequestFromFrame(req, this);
5819}
5820
5821StyleImageRendering nsIFrame::UsedImageRendering() const {
5822 ComputedStyle* style;
5823 if (IsCanvasFrame()) {
5824 // XXXdholbert Maybe we should use FindCanvasBackground here (instead of
5825 // FindBackground), since we're inside an IsCanvasFrame check? Though then
5826 // we'd also have to copypaste or abstract-away the multi-part root-frame
5827 // lookup that the canvas-flavored API requires.
5828 style = nsCSSRendering::FindBackground(this);
5829 } else {
5830 style = Style();
5831 }
5832 return style->StyleVisibility()->mImageRendering;
5833}
5834
5835// The touch-action CSS property applies to: all elements except: non-replaced
5836// inline elements, table rows, row groups, table columns, and column groups.
5837StyleTouchAction nsIFrame::UsedTouchAction() const {
5838 if (IsLineParticipant()) {
5839 return StyleTouchAction::AUTO;
5840 }
5841 auto& disp = *StyleDisplay();
5842 if (disp.IsInternalTableStyleExceptCell()) {
5843 return StyleTouchAction::AUTO;
5844 }
5845 return disp.mTouchAction;
5846}
5847
5848Maybe<nsIFrame::Cursor> nsIFrame::GetCursor(const nsPoint&) {
5849 StyleCursorKind kind = StyleUI()->Cursor().keyword;
5850 if (kind == StyleCursorKind::Auto) {
5851 // If this is editable, I-beam cursor is better for most elements.
5852 kind = (mContent && mContent->IsEditable()) ? StyleCursorKind::Text
5853 : StyleCursorKind::Default;
5854 }
5855 if (kind == StyleCursorKind::Text && GetWritingMode().IsVertical()) {
5856 // Per CSS UI spec, UA may treat value 'text' as
5857 // 'vertical-text' for vertical text.
5858 kind = StyleCursorKind::VerticalText;
5859 }
5860
5861 return Some(Cursor{kind, AllowCustomCursorImage::Yes});
5862}
5863
5864// Resize and incremental reflow
5865
5866/* virtual */
5867void nsIFrame::MarkIntrinsicISizesDirty() {
5868 // If we're a flex item, clear our flex-item-specific cached measurements
5869 // (which likely depended on our now-stale intrinsic isize).
5870 if (IsFlexItem()) {
5871 nsFlexContainerFrame::MarkCachedFlexMeasurementsDirty(this);
5872 }
5873
5874 if (HasAnyStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT)) {
5875 nsFontInflationData::MarkFontInflationDataTextDirty(this);
5876 }
5877
5878 RemoveProperty(nsGridContainerFrame::CachedBAxisMeasurement::Prop());
5879}
5880
5881void nsIFrame::MarkSubtreeDirty() {
5882 if (HasAnyStateBits(NS_FRAME_IS_DIRTY)) {
5883 return;
5884 }
5885 // Unconditionally mark given frame dirty.
5886 AddStateBits(NS_FRAME_IS_DIRTY);
5887
5888 // Mark all descendants dirty, unless:
5889 // - Already dirty.
5890 // - TableColGroup
5891 // - XULBox
5892 AutoTArray<nsIFrame*, 32> stack;
5893 for (const auto& childLists : ChildLists()) {
5894 for (nsIFrame* kid : childLists.mList) {
5895 stack.AppendElement(kid);
5896 }
5897 }
5898 while (!stack.IsEmpty()) {
5899 nsIFrame* f = stack.PopLastElement();
5900 if (f->HasAnyStateBits(NS_FRAME_IS_DIRTY) || f->IsTableColGroupFrame()) {
5901 continue;
5902 }
5903
5904 f->AddStateBits(NS_FRAME_IS_DIRTY);
5905
5906 for (const auto& childLists : f->ChildLists()) {
5907 for (nsIFrame* kid : childLists.mList) {
5908 stack.AppendElement(kid);
5909 }
5910 }
5911 }
5912}
5913
5914/* virtual */
5915nscoord nsIFrame::GetMinISize(gfxContext* aRenderingContext) {
5916 nscoord result = 0;
5917 DISPLAY_MIN_INLINE_SIZE(this, result)DR_intrinsic_inline_size_cookie dr_cookie(this, "Min", result
)
;
5918 return result;
5919}
5920
5921/* virtual */
5922nscoord nsIFrame::GetPrefISize(gfxContext* aRenderingContext) {
5923 nscoord result = 0;
5924 DISPLAY_PREF_INLINE_SIZE(this, result)DR_intrinsic_inline_size_cookie dr_cookie(this, "Pref", result
)
;
5925 return result;
5926}
5927
5928/* virtual */
5929void nsIFrame::AddInlineMinISize(gfxContext* aRenderingContext,
5930 nsIFrame::InlineMinISizeData* aData) {
5931 nscoord isize = nsLayoutUtils::IntrinsicForContainer(
5932 aRenderingContext, this, IntrinsicISizeType::MinISize);
5933 aData->DefaultAddInlineMinISize(this, isize);
5934}
5935
5936/* virtual */
5937void nsIFrame::AddInlinePrefISize(gfxContext* aRenderingContext,
5938 nsIFrame::InlinePrefISizeData* aData) {
5939 nscoord isize = nsLayoutUtils::IntrinsicForContainer(
5940 aRenderingContext, this, IntrinsicISizeType::PrefISize);
5941 aData->DefaultAddInlinePrefISize(isize);
5942}
5943
5944void nsIFrame::InlineMinISizeData::DefaultAddInlineMinISize(nsIFrame* aFrame,
5945 nscoord aISize,
5946 bool aAllowBreak) {
5947 auto parent = aFrame->GetParent();
5948 MOZ_ASSERT(parent, "Must have a parent if we get here!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(parent)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(parent))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("parent" " (" "Must have a parent if we get here!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5948); AnnotateMozCrashReason("MOZ_ASSERT" "(" "parent" ") ("
"Must have a parent if we get here!" ")"); do { *((volatile int
*)__null) = 5948; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
5949 const bool mayBreak = aAllowBreak && !aFrame->CanContinueTextRun() &&
5950 !parent->Style()->ShouldSuppressLineBreak() &&
5951 parent->StyleText()->WhiteSpaceCanWrap(parent);
5952 if (mayBreak) {
5953 OptionallyBreak();
5954 }
5955 mTrailingWhitespace = 0;
5956 mSkipWhitespace = false;
5957 mCurrentLine += aISize;
5958 mAtStartOfLine = false;
5959 if (mayBreak) {
5960 OptionallyBreak();
5961 }
5962}
5963
5964void nsIFrame::InlinePrefISizeData::DefaultAddInlinePrefISize(nscoord aISize) {
5965 mCurrentLine = NSCoordSaturatingAdd(mCurrentLine, aISize);
5966 mTrailingWhitespace = 0;
5967 mSkipWhitespace = false;
5968 mLineIsEmpty = false;
5969}
5970
5971void nsIFrame::InlineMinISizeData::ForceBreak() {
5972 mCurrentLine -= mTrailingWhitespace;
5973 mPrevLines = std::max(mPrevLines, mCurrentLine);
5974 mCurrentLine = mTrailingWhitespace = 0;
5975
5976 for (uint32_t i = 0, i_end = mFloats.Length(); i != i_end; ++i) {
5977 nscoord float_min = mFloats[i].Width();
5978 if (float_min > mPrevLines) mPrevLines = float_min;
5979 }
5980 mFloats.Clear();
5981 mSkipWhitespace = true;
5982}
5983
5984void nsIFrame::InlineMinISizeData::OptionallyBreak(nscoord aHyphenWidth) {
5985 // If we can fit more content into a smaller width by staying on this
5986 // line (because we're still at a negative offset due to negative
5987 // text-indent or negative margin), don't break. Otherwise, do the
5988 // same as ForceBreak. it doesn't really matter when we accumulate
5989 // floats.
5990 if (mCurrentLine + aHyphenWidth < 0 || mAtStartOfLine) return;
5991 mCurrentLine += aHyphenWidth;
5992 ForceBreak();
5993}
5994
5995void nsIFrame::InlinePrefISizeData::ForceBreak(StyleClear aClearType) {
5996 // If this force break is not clearing any float, we can leave all the
5997 // floats to the next force break.
5998 if (!mFloats.IsEmpty() && aClearType != StyleClear::None) {
5999 // preferred widths accumulated for floats that have already
6000 // been cleared past
6001 nscoord floats_done = 0,
6002 // preferred widths accumulated for floats that have not yet
6003 // been cleared past
6004 floats_cur_left = 0, floats_cur_right = 0;
6005
6006 for (const FloatInfo& floatInfo : mFloats) {
6007 const nsStyleDisplay* floatDisp = floatInfo.Frame()->StyleDisplay();
6008 StyleClear clearType = floatDisp->mClear;
6009 if (clearType == StyleClear::Left || clearType == StyleClear::Right ||
6010 clearType == StyleClear::Both) {
6011 nscoord floats_cur =
6012 NSCoordSaturatingAdd(floats_cur_left, floats_cur_right);
6013 if (floats_cur > floats_done) {
6014 floats_done = floats_cur;
6015 }
6016 if (clearType != StyleClear::Right) {
6017 floats_cur_left = 0;
6018 }
6019 if (clearType != StyleClear::Left) {
6020 floats_cur_right = 0;
6021 }
6022 }
6023
6024 StyleFloat floatStyle = floatDisp->mFloat;
6025 nscoord& floats_cur =
6026 floatStyle == StyleFloat::Left ? floats_cur_left : floats_cur_right;
6027 nscoord floatWidth = floatInfo.Width();
6028 // Negative-width floats don't change the available space so they
6029 // shouldn't change our intrinsic line width either.
6030 floats_cur = NSCoordSaturatingAdd(floats_cur, std::max(0, floatWidth));
6031 }
6032
6033 nscoord floats_cur =
6034 NSCoordSaturatingAdd(floats_cur_left, floats_cur_right);
6035 if (floats_cur > floats_done) floats_done = floats_cur;
6036
6037 mCurrentLine = NSCoordSaturatingAdd(mCurrentLine, floats_done);
6038
6039 if (aClearType == StyleClear::Both) {
6040 mFloats.Clear();
6041 } else {
6042 // If the break type does not clear all floats, it means there may
6043 // be some floats whose isize should contribute to the intrinsic
6044 // isize of the next line. The code here scans the current mFloats
6045 // and keeps floats which are not cleared by this break. Note that
6046 // floats may be cleared directly or indirectly. See below.
6047 nsTArray<FloatInfo> newFloats;
6048 MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aClearType == StyleClear::Left || aClearType == StyleClear
::Right)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aClearType == StyleClear::Left || aClearType == StyleClear
::Right))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aClearType == StyleClear::Left || aClearType == StyleClear::Right"
" (" "Other values should have been handled in other branches"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6050); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aClearType == StyleClear::Left || aClearType == StyleClear::Right"
") (" "Other values should have been handled in other branches"
")"); do { *((volatile int*)__null) = 6050; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6049 aClearType == StyleClear::Left || aClearType == StyleClear::Right,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aClearType == StyleClear::Left || aClearType == StyleClear
::Right)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aClearType == StyleClear::Left || aClearType == StyleClear
::Right))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aClearType == StyleClear::Left || aClearType == StyleClear::Right"
" (" "Other values should have been handled in other branches"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6050); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aClearType == StyleClear::Left || aClearType == StyleClear::Right"
") (" "Other values should have been handled in other branches"
")"); do { *((volatile int*)__null) = 6050; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6050 "Other values should have been handled in other branches")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aClearType == StyleClear::Left || aClearType == StyleClear
::Right)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aClearType == StyleClear::Left || aClearType == StyleClear
::Right))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aClearType == StyleClear::Left || aClearType == StyleClear::Right"
" (" "Other values should have been handled in other branches"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6050); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aClearType == StyleClear::Left || aClearType == StyleClear::Right"
") (" "Other values should have been handled in other branches"
")"); do { *((volatile int*)__null) = 6050; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6051 StyleFloat clearFloatType =
6052 aClearType == StyleClear::Left ? StyleFloat::Left : StyleFloat::Right;
6053 // Iterate the array in reverse so that we can stop when there are
6054 // no longer any floats we need to keep. See below.
6055 for (FloatInfo& floatInfo : Reversed(mFloats)) {
6056 const nsStyleDisplay* floatDisp = floatInfo.Frame()->StyleDisplay();
6057 if (floatDisp->mFloat != clearFloatType) {
6058 newFloats.AppendElement(floatInfo);
6059 } else {
6060 // This is a float on the side that this break directly clears
6061 // which means we're not keeping it in mFloats. However, if
6062 // this float clears floats on the opposite side (via a value
6063 // of either 'both' or one of 'left'/'right'), any remaining
6064 // (earlier) floats on that side would be indirectly cleared
6065 // as well. Thus, we should break out of this loop and stop
6066 // considering earlier floats to be kept in mFloats.
6067 StyleClear clearType = floatDisp->mClear;
6068 if (clearType != aClearType && clearType != StyleClear::None) {
6069 break;
6070 }
6071 }
6072 }
6073 newFloats.Reverse();
6074 mFloats = std::move(newFloats);
6075 }
6076 }
6077
6078 mCurrentLine =
6079 NSCoordSaturatingSubtract(mCurrentLine, mTrailingWhitespace, nscoord_MAXnscoord((1 << 30) - 1));
6080 mPrevLines = std::max(mPrevLines, mCurrentLine);
6081 mCurrentLine = mTrailingWhitespace = 0;
6082 mSkipWhitespace = true;
6083 mLineIsEmpty = true;
6084}
6085
6086static nscoord ResolveMargin(const LengthPercentageOrAuto& aStyle,
6087 nscoord aPercentageBasis) {
6088 if (aStyle.IsAuto()) {
6089 return nscoord(0);
6090 }
6091 return nsLayoutUtils::ResolveToLength<false>(aStyle.AsLengthPercentage(),
6092 aPercentageBasis);
6093}
6094
6095static nscoord ResolvePadding(const LengthPercentage& aStyle,
6096 nscoord aPercentageBasis) {
6097 return nsLayoutUtils::ResolveToLength<true>(aStyle, aPercentageBasis);
6098}
6099
6100static nsIFrame::IntrinsicSizeOffsetData IntrinsicSizeOffsets(
6101 nsIFrame* aFrame, nscoord aPercentageBasis, bool aForISize) {
6102 nsIFrame::IntrinsicSizeOffsetData result;
6103 WritingMode wm = aFrame->GetWritingMode();
6104 const auto& margin = aFrame->StyleMargin()->mMargin;
6105 bool verticalAxis = aForISize == wm.IsVertical();
6106 if (verticalAxis) {
6107 result.margin += ResolveMargin(margin.Get(eSideTop), aPercentageBasis);
6108 result.margin += ResolveMargin(margin.Get(eSideBottom), aPercentageBasis);
6109 } else {
6110 result.margin += ResolveMargin(margin.Get(eSideLeft), aPercentageBasis);
6111 result.margin += ResolveMargin(margin.Get(eSideRight), aPercentageBasis);
6112 }
6113
6114 const auto& padding = aFrame->StylePadding()->mPadding;
6115 if (verticalAxis) {
6116 result.padding += ResolvePadding(padding.Get(eSideTop), aPercentageBasis);
6117 result.padding +=
6118 ResolvePadding(padding.Get(eSideBottom), aPercentageBasis);
6119 } else {
6120 result.padding += ResolvePadding(padding.Get(eSideLeft), aPercentageBasis);
6121 result.padding += ResolvePadding(padding.Get(eSideRight), aPercentageBasis);
6122 }
6123
6124 const nsStyleBorder* styleBorder = aFrame->StyleBorder();
6125 if (verticalAxis) {
6126 result.border += styleBorder->GetComputedBorderWidth(eSideTop);
6127 result.border += styleBorder->GetComputedBorderWidth(eSideBottom);
6128 } else {
6129 result.border += styleBorder->GetComputedBorderWidth(eSideLeft);
6130 result.border += styleBorder->GetComputedBorderWidth(eSideRight);
6131 }
6132
6133 const nsStyleDisplay* disp = aFrame->StyleDisplay();
6134 if (aFrame->IsThemed(disp)) {
6135 nsPresContext* presContext = aFrame->PresContext();
6136
6137 LayoutDeviceIntMargin border = presContext->Theme()->GetWidgetBorder(
6138 presContext->DeviceContext(), aFrame, disp->EffectiveAppearance());
6139 result.border = presContext->DevPixelsToAppUnits(
6140 verticalAxis ? border.TopBottom() : border.LeftRight());
6141
6142 LayoutDeviceIntMargin padding;
6143 if (presContext->Theme()->GetWidgetPadding(
6144 presContext->DeviceContext(), aFrame, disp->EffectiveAppearance(),
6145 &padding)) {
6146 result.padding = presContext->DevPixelsToAppUnits(
6147 verticalAxis ? padding.TopBottom() : padding.LeftRight());
6148 }
6149 }
6150 return result;
6151}
6152
6153/* virtual */ nsIFrame::IntrinsicSizeOffsetData nsIFrame::IntrinsicISizeOffsets(
6154 nscoord aPercentageBasis) {
6155 return IntrinsicSizeOffsets(this, aPercentageBasis, true);
6156}
6157
6158nsIFrame::IntrinsicSizeOffsetData nsIFrame::IntrinsicBSizeOffsets(
6159 nscoord aPercentageBasis) {
6160 return IntrinsicSizeOffsets(this, aPercentageBasis, false);
6161}
6162
6163/* virtual */
6164IntrinsicSize nsIFrame::GetIntrinsicSize() {
6165 return IntrinsicSize(); // default is width/height set to eStyleUnit_None
6166}
6167
6168AspectRatio nsIFrame::GetAspectRatio() const {
6169 // Per spec, 'aspect-ratio' property applies to all elements except inline
6170 // boxes and internal ruby or table boxes.
6171 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio
6172 // For those frame types that don't support aspect-ratio, they must not have
6173 // the natural ratio, so this early return is fine.
6174 if (!SupportsAspectRatio()) {
6175 return AspectRatio();
6176 }
6177
6178 const StyleAspectRatio& aspectRatio = StylePosition()->mAspectRatio;
6179 // If aspect-ratio is zero or infinite, it's a degenerate ratio and behaves
6180 // as auto.
6181 // https://drafts.csswg.org/css-sizing-4/#valdef-aspect-ratio-ratio
6182 if (!aspectRatio.BehavesAsAuto()) {
6183 // Non-auto. Return the preferred aspect ratio from the aspect-ratio style.
6184 return aspectRatio.ratio.AsRatio().ToLayoutRatio(UseBoxSizing::Yes);
6185 }
6186
6187 // The rest of the cases are when aspect-ratio has 'auto'.
6188 if (auto intrinsicRatio = GetIntrinsicRatio()) {
6189 return intrinsicRatio;
6190 }
6191
6192 if (aspectRatio.HasRatio()) {
6193 // If it's a degenerate ratio, this returns 0. Just the same as the auto
6194 // case.
6195 return aspectRatio.ratio.AsRatio().ToLayoutRatio(UseBoxSizing::No);
6196 }
6197
6198 return AspectRatio();
6199}
6200
6201/* virtual */
6202AspectRatio nsIFrame::GetIntrinsicRatio() const { return AspectRatio(); }
6203
6204static bool ShouldApplyAutomaticMinimumOnInlineAxis(
6205 WritingMode aWM, const nsStyleDisplay* aDisplay,
6206 const nsStylePosition* aPosition) {
6207 // Apply the automatic minimum size for aspect ratio:
6208 // Note: The replaced elements shouldn't be here, so we only check the scroll
6209 // container.
6210 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum
6211 return !aDisplay->IsScrollableOverflow() && aPosition->MinISize(aWM).IsAuto();
6212}
6213
6214struct MinMaxSize {
6215 nscoord mMinSize = 0;
6216 nscoord mMaxSize = NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1);
6217
6218 nscoord ClampSizeToMinAndMax(nscoord aSize) const {
6219 return NS_CSS_MINMAX(aSize, mMinSize, mMaxSize);
6220 }
6221};
6222static MinMaxSize ComputeTransferredMinMaxInlineSize(
6223 const WritingMode aWM, const AspectRatio& aAspectRatio,
6224 const MinMaxSize& aMinMaxBSize, const LogicalSize& aBoxSizingAdjustment) {
6225 // Note: the spec mentions that
6226 // 1. This transferred minimum is capped by any definite preferred or maximum
6227 // size in the destination axis.
6228 // 2. This transferred maximum is floored by any definite preferred or minimum
6229 // size in the destination axis
6230 //
6231 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio
6232 //
6233 // The spec requires us to clamp these by the specified size (it calls it the
6234 // preferred size). However, we actually don't need to worry about that,
6235 // because we only use this if the inline size is indefinite.
6236 //
6237 // We do not need to clamp the transferred minimum and maximum as long as we
6238 // always apply the transferred min/max size before the explicit min/max size,
6239 // the result will be identical.
6240
6241 MinMaxSize transferredISize;
6242
6243 if (aMinMaxBSize.mMinSize > 0) {
6244 transferredISize.mMinSize = aAspectRatio.ComputeRatioDependentSize(
6245 LogicalAxis::eLogicalAxisInline, aWM, aMinMaxBSize.mMinSize,
6246 aBoxSizingAdjustment);
6247 }
6248
6249 if (aMinMaxBSize.mMaxSize != NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1)) {
6250 transferredISize.mMaxSize = aAspectRatio.ComputeRatioDependentSize(
6251 LogicalAxis::eLogicalAxisInline, aWM, aMinMaxBSize.mMaxSize,
6252 aBoxSizingAdjustment);
6253 }
6254
6255 // Minimum size wins over maximum size.
6256 transferredISize.mMaxSize =
6257 std::max(transferredISize.mMinSize, transferredISize.mMaxSize);
6258 return transferredISize;
6259}
6260
6261/* virtual */
6262nsIFrame::SizeComputationResult nsIFrame::ComputeSize(
6263 gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
6264 nscoord aAvailableISize, const LogicalSize& aMargin,
6265 const LogicalSize& aBorderPadding, const StyleSizeOverrides& aSizeOverrides,
6266 ComputeSizeFlags aFlags) {
6267 MOZ_ASSERT(!GetIntrinsicRatio(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!GetIntrinsicRatio())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!GetIntrinsicRatio()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!GetIntrinsicRatio()"
" (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6269); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetIntrinsicRatio()"
") (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")"); do { *((volatile int*)__null) = 6269; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6268 "Please override this method and call "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!GetIntrinsicRatio())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!GetIntrinsicRatio()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!GetIntrinsicRatio()"
" (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6269); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetIntrinsicRatio()"
") (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")"); do { *((volatile int*)__null) = 6269; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6269 "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead.")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!GetIntrinsicRatio())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!GetIntrinsicRatio()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!GetIntrinsicRatio()"
" (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6269); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetIntrinsicRatio()"
") (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")"); do { *((volatile int*)__null) = 6269; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6270 LogicalSize result =
6271 ComputeAutoSize(aRenderingContext, aWM, aCBSize, aAvailableISize, aMargin,
6272 aBorderPadding, aSizeOverrides, aFlags);
6273 const nsStylePosition* stylePos = StylePosition();
6274 const nsStyleDisplay* disp = StyleDisplay();
6275 auto aspectRatioUsage = AspectRatioUsage::None;
6276
6277 const auto boxSizingAdjust = stylePos->mBoxSizing == StyleBoxSizing::Border
6278 ? aBorderPadding
6279 : LogicalSize(aWM);
6280 nscoord boxSizingToMarginEdgeISize = aMargin.ISize(aWM) +
6281 aBorderPadding.ISize(aWM) -
6282 boxSizingAdjust.ISize(aWM);
6283
6284 const auto& styleISize = aSizeOverrides.mStyleISize
6285 ? *aSizeOverrides.mStyleISize
6286 : stylePos->ISize(aWM);
6287 const auto& styleBSize = aSizeOverrides.mStyleBSize
6288 ? *aSizeOverrides.mStyleBSize
6289 : stylePos->BSize(aWM);
6290 const auto& aspectRatio = aSizeOverrides.mAspectRatio
6291 ? *aSizeOverrides.mAspectRatio
6292 : GetAspectRatio();
6293
6294 auto parentFrame = GetParent();
6295 auto alignCB = parentFrame;
6296 bool isGridItem = IsGridItem();
6297 if (parentFrame && parentFrame->IsTableWrapperFrame() && IsTableFrame()) {
6298 // An inner table frame is sized as a grid item if its table wrapper is,
6299 // because they actually have the same CB (the wrapper's CB).
6300 // @see ReflowInput::InitCBReflowInput
6301 auto tableWrapper = GetParent();
6302 auto grandParent = tableWrapper->GetParent();
6303 isGridItem = grandParent->IsGridContainerFrame() &&
6304 !tableWrapper->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW);
6305 if (isGridItem) {
6306 // When resolving justify/align-self below, we want to use the grid
6307 // container's justify/align-items value and WritingMode.
6308 alignCB = grandParent;
6309 }
6310 }
6311 const bool isFlexItem =
6312 IsFlexItem() && !parentFrame->HasAnyStateBits(
6313 NS_STATE_FLEX_IS_EMULATING_LEGACY_WEBKIT_BOX);
6314 // This variable only gets set (and used) if isFlexItem is true. It
6315 // indicates which axis (in this frame's own WM) corresponds to its
6316 // flex container's main axis.
6317 LogicalAxis flexMainAxis =
6318 eLogicalAxisInline; // (init to make valgrind happy)
6319 if (isFlexItem) {
6320 flexMainAxis = nsFlexContainerFrame::IsItemInlineAxisMainAxis(this)
6321 ? eLogicalAxisInline
6322 : eLogicalAxisBlock;
6323 }
6324
6325 const bool isOrthogonal = aWM.IsOrthogonalTo(alignCB->GetWritingMode());
6326 const bool isAutoISize = styleISize.IsAuto();
6327 const bool isAutoBSize =
6328 nsLayoutUtils::IsAutoBSize(styleBSize, aCBSize.BSize(aWM));
6329 // Compute inline-axis size
6330 if (!isAutoISize) {
6331 auto iSizeResult = ComputeISizeValue(
6332 aRenderingContext, aWM, aCBSize, boxSizingAdjust,
6333 boxSizingToMarginEdgeISize, styleISize, aSizeOverrides, aFlags);
6334 result.ISize(aWM) = iSizeResult.mISize;
6335 aspectRatioUsage = iSizeResult.mAspectRatioUsage;
6336 } else if (MOZ_UNLIKELY(isGridItem)(__builtin_expect(!!(isGridItem), 0)) && !IsTrueOverflowContainer()) {
6337 // 'auto' inline-size for grid-level box - fill the CB for 'stretch' /
6338 // 'normal' and clamp it to the CB if requested:
6339 bool stretch = false;
6340 bool mayUseAspectRatio = aspectRatio && !isAutoBSize;
6341 if (!aFlags.contains(ComputeSizeFlag::ShrinkWrap) &&
6342 !StyleMargin()->HasInlineAxisAuto(aWM) &&
6343 !alignCB->IsMasonry(isOrthogonal ? eLogicalAxisBlock
6344 : eLogicalAxisInline)) {
6345 auto inlineAxisAlignment =
6346 isOrthogonal ? StylePosition()->UsedAlignSelf(alignCB->Style())._0
6347 : StylePosition()->UsedJustifySelf(alignCB->Style())._0;
6348 stretch = inlineAxisAlignment == StyleAlignFlags::STRETCH ||
6349 (inlineAxisAlignment == StyleAlignFlags::NORMAL &&
6350 !mayUseAspectRatio);
6351 }
6352
6353 // Apply the preferred aspect ratio for alignments other than *stretch* and
6354 // *normal without aspect ratio*.
6355 // The spec says all other values should size the items as fit-content, and
6356 // the intrinsic size should respect the preferred aspect ratio, so we also
6357 // apply aspect ratio for all other values.
6358 // https://drafts.csswg.org/css-grid/#grid-item-sizing
6359 if (!stretch && mayUseAspectRatio) {
6360 // Note: we don't need to handle aspect ratio for inline axis if both
6361 // width/height are auto. The default ratio-dependent axis is block axis
6362 // in this case, so we can simply get the block size from the non-auto
6363 // |styleBSize|.
6364 auto bSize = nsLayoutUtils::ComputeBSizeValue(
6365 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6366 styleBSize.AsLengthPercentage());
6367 result.ISize(aWM) = aspectRatio.ComputeRatioDependentSize(
6368 LogicalAxis::eLogicalAxisInline, aWM, bSize, boxSizingAdjust);
6369 aspectRatioUsage = AspectRatioUsage::ToComputeISize;
6370 }
6371
6372 if (stretch || aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize)) {
6373 auto iSizeToFillCB =
6374 std::max(nscoord(0), aCBSize.ISize(aWM) - aBorderPadding.ISize(aWM) -
6375 aMargin.ISize(aWM));
6376 if (stretch || result.ISize(aWM) > iSizeToFillCB) {
6377 result.ISize(aWM) = iSizeToFillCB;
6378 }
6379 }
6380 } else if (aspectRatio && !isAutoBSize) {
6381 auto bSize = nsLayoutUtils::ComputeBSizeValue(
6382 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6383 styleBSize.AsLengthPercentage());
6384 result.ISize(aWM) = aspectRatio.ComputeRatioDependentSize(
6385 LogicalAxis::eLogicalAxisInline, aWM, bSize, boxSizingAdjust);
6386 aspectRatioUsage = AspectRatioUsage::ToComputeISize;
6387 }
6388
6389 // Calculate and apply transferred min & max size contraints.
6390 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-size-transfers
6391 //
6392 // Note: The basic principle is that sizing constraints transfer through the
6393 // aspect-ratio to the other side to preserve the aspect ratio to the extent
6394 // that they can without violating any sizes specified explicitly on that
6395 // affected axis.
6396 //
6397 // FIXME: The spec words may not be correct, so we may have to update this
6398 // tentative solution once this spec issue gets resolved. Here, we clamp the
6399 // flex base size by the transferred min and max sizes, and don't include
6400 // the transferred min & max sizes into its used min & max sizes. So this
6401 // lets us match other browsers' current behaviors.
6402 // https://github.com/w3c/csswg-drafts/issues/6071
6403 //
6404 // Note: This may make more sense if we clamp the flex base size in
6405 // FlexItem::ResolveFlexBaseSizeFromAspectRatio(). However, the result should
6406 // be identical. FlexItem::ResolveFlexBaseSizeFromAspectRatio() only handles
6407 // the case of the definite cross size, and the definite cross size is clamped
6408 // by the min & max cross sizes below in this function. This means its flex
6409 // base size has been clamped by the transferred min & max size already after
6410 // generating the flex items. So here we make the code more general for both
6411 // definite cross size and indefinite cross size.
6412 const bool isDefiniteISize = styleISize.IsLengthPercentage();
6413 const auto& minBSizeCoord = stylePos->MinBSize(aWM);
6414 const auto& maxBSizeCoord = stylePos->MaxBSize(aWM);
6415 const bool isAutoMinBSize =
6416 nsLayoutUtils::IsAutoBSize(minBSizeCoord, aCBSize.BSize(aWM));
6417 const bool isAutoMaxBSize =
6418 nsLayoutUtils::IsAutoBSize(maxBSizeCoord, aCBSize.BSize(aWM));
6419 if (aspectRatio && !isDefiniteISize) {
6420 const MinMaxSize minMaxBSize{
6421 isAutoMinBSize ? 0
6422 : nsLayoutUtils::ComputeBSizeValue(
6423 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6424 minBSizeCoord.AsLengthPercentage()),
6425 isAutoMaxBSize ? NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1)
6426 : nsLayoutUtils::ComputeBSizeValue(
6427 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6428 maxBSizeCoord.AsLengthPercentage())};
6429 MinMaxSize transferredMinMaxISize = ComputeTransferredMinMaxInlineSize(
6430 aWM, aspectRatio, minMaxBSize, boxSizingAdjust);
6431
6432 result.ISize(aWM) =
6433 transferredMinMaxISize.ClampSizeToMinAndMax(result.ISize(aWM));
6434 }
6435
6436 // Flex items ignore their min & max sizing properties in their
6437 // flex container's main-axis. (Those properties get applied later in
6438 // the flexbox algorithm.)
6439 const bool isFlexItemInlineAxisMainAxis =
6440 isFlexItem && flexMainAxis == eLogicalAxisInline;
6441 const auto& maxISizeCoord = stylePos->MaxISize(aWM);
6442 nscoord maxISize = NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1);
6443 if (!maxISizeCoord.IsNone() && !isFlexItemInlineAxisMainAxis) {
6444 maxISize = ComputeISizeValue(aRenderingContext, aWM, aCBSize,
6445 boxSizingAdjust, boxSizingToMarginEdgeISize,
6446 maxISizeCoord, aSizeOverrides, aFlags)
6447 .mISize;
6448 result.ISize(aWM) = std::min(maxISize, result.ISize(aWM));
6449 }
6450
6451 const auto& minISizeCoord = stylePos->MinISize(aWM);
6452 nscoord minISize;
6453 if (!minISizeCoord.IsAuto() && !isFlexItemInlineAxisMainAxis) {
6454 minISize = ComputeISizeValue(aRenderingContext, aWM, aCBSize,
6455 boxSizingAdjust, boxSizingToMarginEdgeISize,
6456 minISizeCoord, aSizeOverrides, aFlags)
6457 .mISize;
6458 } else if (MOZ_UNLIKELY((__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IApplyAutoMinSize
)), 0))
6459 aFlags.contains(ComputeSizeFlag::IApplyAutoMinSize))(__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IApplyAutoMinSize
)), 0))
) {
6460 // This implements "Implied Minimum Size of Grid Items".
6461 // https://drafts.csswg.org/css-grid/#min-size-auto
6462 minISize = std::min(maxISize, GetMinISize(aRenderingContext));
6463 if (styleISize.IsLengthPercentage()) {
6464 minISize = std::min(minISize, result.ISize(aWM));
6465 } else if (aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize)) {
6466 // "if the grid item spans only grid tracks that have a fixed max track
6467 // sizing function, its automatic minimum size in that dimension is
6468 // further clamped to less than or equal to the size necessary to fit
6469 // its margin box within the resulting grid area (flooring at zero)"
6470 // https://drafts.csswg.org/css-grid/#min-size-auto
6471 auto maxMinISize =
6472 std::max(nscoord(0), aCBSize.ISize(aWM) - aBorderPadding.ISize(aWM) -
6473 aMargin.ISize(aWM));
6474 minISize = std::min(minISize, maxMinISize);
6475 }
6476 } else if (aspectRatioUsage == AspectRatioUsage::ToComputeISize &&
6477 ShouldApplyAutomaticMinimumOnInlineAxis(aWM, disp, stylePos)) {
6478 // This means we successfully applied aspect-ratio and now need to check
6479 // if we need to apply the implied minimum size:
6480 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum
6481 MOZ_ASSERT(!HasReplacedSizing(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasReplacedSizing())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!HasReplacedSizing()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!HasReplacedSizing()"
" (" "aspect-ratio minimums should not apply to replaced elements"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6482); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasReplacedSizing()"
") (" "aspect-ratio minimums should not apply to replaced elements"
")"); do { *((volatile int*)__null) = 6482; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6482 "aspect-ratio minimums should not apply to replaced elements")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasReplacedSizing())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!HasReplacedSizing()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!HasReplacedSizing()"
" (" "aspect-ratio minimums should not apply to replaced elements"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6482); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasReplacedSizing()"
") (" "aspect-ratio minimums should not apply to replaced elements"
")"); do { *((volatile int*)__null) = 6482; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6483 // The inline size computed by aspect-ratio shouldn't less than the content
6484 // size.
6485 minISize = GetMinISize(aRenderingContext);
6486 } else {
6487 // Treat "min-width: auto" as 0.
6488 // NOTE: Technically, "auto" is supposed to behave like "min-content" on
6489 // flex items. However, we don't need to worry about that here, because
6490 // flex items' min-sizes are intentionally ignored until the flex
6491 // container explicitly considers them during space distribution.
6492 minISize = 0;
6493 }
6494 result.ISize(aWM) = std::max(minISize, result.ISize(aWM));
6495
6496 // Compute block-axis size
6497 // (but not if we have auto bsize -- then, we'll just stick with the bsize
6498 // that we already calculated in the initial ComputeAutoSize() call. However,
6499 // if we have a valid preferred aspect ratio, we still have to compute the
6500 // block size because aspect ratio affects the intrinsic content size.)
6501 if (!isAutoBSize) {
6502 result.BSize(aWM) = nsLayoutUtils::ComputeBSizeValue(
6503 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6504 styleBSize.AsLengthPercentage());
6505 } else if (MOZ_UNLIKELY(isGridItem)(__builtin_expect(!!(isGridItem), 0)) && styleBSize.IsAuto() &&
6506 !aFlags.contains(ComputeSizeFlag::IsGridMeasuringReflow) &&
6507 !IsTrueOverflowContainer() &&
6508 !alignCB->IsMasonry(isOrthogonal ? eLogicalAxisInline
6509 : eLogicalAxisBlock)) {
6510 auto cbSize = aCBSize.BSize(aWM);
6511 if (cbSize != NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1)) {
6512 // 'auto' block-size for grid-level box - fill the CB for 'stretch' /
6513 // 'normal' and clamp it to the CB if requested:
6514 bool stretch = false;
6515 bool mayUseAspectRatio =
6516 aspectRatio && result.ISize(aWM) != NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1);
6517 if (!StyleMargin()->HasBlockAxisAuto(aWM)) {
6518 auto blockAxisAlignment =
6519 isOrthogonal ? StylePosition()->UsedJustifySelf(alignCB->Style())._0
6520 : StylePosition()->UsedAlignSelf(alignCB->Style())._0;
6521 stretch = blockAxisAlignment == StyleAlignFlags::STRETCH ||
6522 (blockAxisAlignment == StyleAlignFlags::NORMAL &&
6523 !mayUseAspectRatio);
6524 }
6525
6526 // Apply the preferred aspect ratio for alignments other than *stretch*
6527 // and *normal without aspect ratio*.
6528 // The spec says all other values should size the items as fit-content,
6529 // and the intrinsic size should respect the preferred aspect ratio, so
6530 // we also apply aspect ratio for all other values.
6531 // https://drafts.csswg.org/css-grid/#grid-item-sizing
6532 if (!stretch && mayUseAspectRatio) {
6533 result.BSize(aWM) = aspectRatio.ComputeRatioDependentSize(
6534 LogicalAxis::eLogicalAxisBlock, aWM, result.ISize(aWM),
6535 boxSizingAdjust);
6536 MOZ_ASSERT(aspectRatioUsage == AspectRatioUsage::None)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aspectRatioUsage == AspectRatioUsage::None)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(aspectRatioUsage == AspectRatioUsage::None))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("aspectRatioUsage == AspectRatioUsage::None"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6536); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aspectRatioUsage == AspectRatioUsage::None"
")"); do { *((volatile int*)__null) = 6536; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6537 aspectRatioUsage = AspectRatioUsage::ToComputeBSize;
6538 }
6539
6540 if (stretch || aFlags.contains(ComputeSizeFlag::BClampMarginBoxMinSize)) {
6541 auto bSizeToFillCB =
6542 std::max(nscoord(0),
6543 cbSize - aBorderPadding.BSize(aWM) - aMargin.BSize(aWM));
6544 if (stretch || (result.BSize(aWM) != NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1) &&
6545 result.BSize(aWM) > bSizeToFillCB)) {
6546 result.BSize(aWM) = bSizeToFillCB;
6547 }
6548 }
6549 }
6550 } else if (aspectRatio) {
6551 // If both inline and block dimensions are auto, the block axis is the
6552 // ratio-dependent axis by default.
6553 // If we have a super large inline size, aspect-ratio should still be
6554 // applied (so aspectRatioUsage flag is set as expected). That's why we
6555 // apply aspect-ratio unconditionally for auto block size here.
6556 result.BSize(aWM) = aspectRatio.ComputeRatioDependentSize(
6557 LogicalAxis::eLogicalAxisBlock, aWM, result.ISize(aWM),
6558 boxSizingAdjust);
6559 MOZ_ASSERT(aspectRatioUsage == AspectRatioUsage::None)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aspectRatioUsage == AspectRatioUsage::None)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(aspectRatioUsage == AspectRatioUsage::None))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("aspectRatioUsage == AspectRatioUsage::None"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6559); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aspectRatioUsage == AspectRatioUsage::None"
")"); do { *((volatile int*)__null) = 6559; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6560 aspectRatioUsage = AspectRatioUsage::ToComputeBSize;
6561 }
6562
6563 if (result.BSize(aWM) != NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1)) {
6564 const bool isFlexItemBlockAxisMainAxis =
6565 isFlexItem && flexMainAxis == eLogicalAxisBlock;
6566 if (!isAutoMaxBSize && !isFlexItemBlockAxisMainAxis) {
6567 nscoord maxBSize = nsLayoutUtils::ComputeBSizeValue(
6568 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6569 maxBSizeCoord.AsLengthPercentage());
6570 result.BSize(aWM) = std::min(maxBSize, result.BSize(aWM));
6571 }
6572
6573 if (!isAutoMinBSize && !isFlexItemBlockAxisMainAxis) {
6574 nscoord minBSize = nsLayoutUtils::ComputeBSizeValue(
6575 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6576 minBSizeCoord.AsLengthPercentage());
6577 result.BSize(aWM) = std::max(minBSize, result.BSize(aWM));
6578 }
6579 }
6580
6581 if (IsThemed(disp)) {
6582 nsPresContext* pc = PresContext();
6583 const LayoutDeviceIntSize widget = pc->Theme()->GetMinimumWidgetSize(
6584 pc, this, disp->EffectiveAppearance());
6585
6586 // Convert themed widget's physical dimensions to logical coords
6587 LogicalSize size(aWM, LayoutDeviceIntSize::ToAppUnits(
6588 widget, pc->AppUnitsPerDevPixel()));
6589
6590 // GetMinimumWidgetSize() returns border-box; we need content-box.
6591 size -= aBorderPadding;
6592
6593 if (size.BSize(aWM) > result.BSize(aWM)) {
6594 result.BSize(aWM) = size.BSize(aWM);
6595 }
6596 if (size.ISize(aWM) > result.ISize(aWM)) {
6597 result.ISize(aWM) = size.ISize(aWM);
6598 }
6599 }
6600
6601 result.ISize(aWM) = std::max(0, result.ISize(aWM));
6602 result.BSize(aWM) = std::max(0, result.BSize(aWM));
6603
6604 return {result, aspectRatioUsage};
6605}
6606
6607nsRect nsIFrame::ComputeTightBounds(DrawTarget* aDrawTarget) const {
6608 return InkOverflowRect();
6609}
6610
6611/* virtual */
6612nsresult nsIFrame::GetPrefWidthTightBounds(gfxContext* aContext, nscoord* aX,
6613 nscoord* aXMost) {
6614 return NS_ERROR_NOT_IMPLEMENTED;
6615}
6616
6617/* virtual */
6618LogicalSize nsIFrame::ComputeAutoSize(
6619 gfxContext* aRenderingContext, WritingMode aWM,
6620 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
6621 const mozilla::LogicalSize& aMargin,
6622 const mozilla::LogicalSize& aBorderPadding,
6623 const StyleSizeOverrides& aSizeOverrides, ComputeSizeFlags aFlags) {
6624 // Use basic shrink-wrapping as a default implementation.
6625 LogicalSize result(aWM, 0xdeadbeef, NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1));
6626
6627 // don't bother setting it if the result won't be used
6628 const auto& styleISize = aSizeOverrides.mStyleISize
6629 ? *aSizeOverrides.mStyleISize
6630 : StylePosition()->ISize(aWM);
6631 if (styleISize.IsAuto()) {
6632 nscoord availBased =
6633 aAvailableISize - aMargin.ISize(aWM) - aBorderPadding.ISize(aWM);
6634 result.ISize(aWM) = ShrinkISizeToFit(aRenderingContext, availBased, aFlags);
6635 }
6636 return result;
6637}
6638
6639nscoord nsIFrame::ShrinkISizeToFit(gfxContext* aRenderingContext,
6640 nscoord aISizeInCB,
6641 ComputeSizeFlags aFlags) {
6642 // If we're a container for font size inflation, then shrink
6643 // wrapping inside of us should not apply font size inflation.
6644 AutoMaybeDisableFontInflation an(this);
6645
6646 nscoord result;
6647 nscoord minISize = GetMinISize(aRenderingContext);
6648 if (minISize > aISizeInCB) {
6649 const bool clamp = aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize);
6650 result = MOZ_UNLIKELY(clamp)(__builtin_expect(!!(clamp), 0)) ? aISizeInCB : minISize;
6651 } else {
6652 nscoord prefISize = GetPrefISize(aRenderingContext);
6653 if (prefISize > aISizeInCB) {
6654 result = aISizeInCB;
6655 } else {
6656 result = prefISize;
6657 }
6658 }
6659 return result;
6660}
6661
6662Maybe<nscoord> nsIFrame::ComputeInlineSizeFromAspectRatio(
6663 WritingMode aWM, const LogicalSize& aCBSize,
6664 const LogicalSize& aContentEdgeToBoxSizing,
6665 const StyleSizeOverrides& aSizeOverrides, ComputeSizeFlags aFlags) const {
6666 // FIXME: Bug 1670151: Use GetAspectRatio() to cover replaced elements (and
6667 // then we can drop the check of eSupportsAspectRatio).
6668 const AspectRatio aspectRatio =
6669 aSizeOverrides.mAspectRatio
6670 ? *aSizeOverrides.mAspectRatio
6671 : StylePosition()->mAspectRatio.ToLayoutRatio();
6672 if (!SupportsAspectRatio() || !aspectRatio) {
6673 return Nothing();
6674 }
6675
6676 const StyleSize& styleBSize = aSizeOverrides.mStyleBSize
6677 ? *aSizeOverrides.mStyleBSize
6678 : StylePosition()->BSize(aWM);
6679 if (nsLayoutUtils::IsAutoBSize(styleBSize, aCBSize.BSize(aWM))) {
6680 return Nothing();
6681 }
6682
6683 MOZ_ASSERT(styleBSize.IsLengthPercentage())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(styleBSize.IsLengthPercentage())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(styleBSize.IsLengthPercentage
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("styleBSize.IsLengthPercentage()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6683); AnnotateMozCrashReason("MOZ_ASSERT" "(" "styleBSize.IsLengthPercentage()"
")"); do { *((volatile int*)__null) = 6683; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6684 nscoord bSize = nsLayoutUtils::ComputeBSizeValue(
6685 aCBSize.BSize(aWM), aContentEdgeToBoxSizing.BSize(aWM),
6686 styleBSize.AsLengthPercentage());
6687 return Some(aspectRatio.ComputeRatioDependentSize(
6688 LogicalAxis::eLogicalAxisInline, aWM, bSize, aContentEdgeToBoxSizing));
6689}
6690
6691nsIFrame::ISizeComputationResult nsIFrame::ComputeISizeValue(
6692 gfxContext* aRenderingContext, const WritingMode aWM,
6693 const LogicalSize& aContainingBlockSize,
6694 const LogicalSize& aContentEdgeToBoxSizing, nscoord aBoxSizingToMarginEdge,
6695 ExtremumLength aSize, Maybe<nscoord> aAvailableISizeOverride,
6696 const StyleSizeOverrides& aSizeOverrides, ComputeSizeFlags aFlags) {
6697 // If 'this' is a container for font size inflation, then shrink
6698 // wrapping inside of it should not apply font size inflation.
6699 AutoMaybeDisableFontInflation an(this);
6700 // If we have an aspect-ratio and a definite block size, we resolve the
6701 // min-content and max-content size by the aspect-ratio and the block size.
6702 // https://github.com/w3c/csswg-drafts/issues/5032
6703 Maybe<nscoord> intrinsicSizeFromAspectRatio =
6704 aSize == ExtremumLength::MozAvailable
6705 ? Nothing()
6706 : ComputeInlineSizeFromAspectRatio(aWM, aContainingBlockSize,
6707 aContentEdgeToBoxSizing,
6708 aSizeOverrides, aFlags);
6709 nscoord result;
6710 switch (aSize) {
6711 case ExtremumLength::MaxContent:
6712 result = intrinsicSizeFromAspectRatio ? *intrinsicSizeFromAspectRatio
6713 : GetPrefISize(aRenderingContext);
6714 NS_ASSERTION(result >= 0, "inline-size less than zero")do { if (!(result >= 0)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "inline-size less than zero", "result >= 0", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6714); MOZ_PretendNoReturn(); } } while (0)
;
6715 return {result, intrinsicSizeFromAspectRatio
6716 ? AspectRatioUsage::ToComputeISize
6717 : AspectRatioUsage::None};
6718 case ExtremumLength::MinContent:
6719 result = intrinsicSizeFromAspectRatio ? *intrinsicSizeFromAspectRatio
6720 : GetMinISize(aRenderingContext);
6721 NS_ASSERTION(result >= 0, "inline-size less than zero")do { if (!(result >= 0)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "inline-size less than zero", "result >= 0", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6721); MOZ_PretendNoReturn(); } } while (0)
;
6722 if (MOZ_UNLIKELY((__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
6723 aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize))(__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
) {
6724 auto available =
6725 aContainingBlockSize.ISize(aWM) -
6726 (aBoxSizingToMarginEdge + aContentEdgeToBoxSizing.ISize(aWM));
6727 result = std::min(available, result);
6728 }
6729 return {result, intrinsicSizeFromAspectRatio
6730 ? AspectRatioUsage::ToComputeISize
6731 : AspectRatioUsage::None};
6732 case ExtremumLength::FitContentFunction:
6733 case ExtremumLength::FitContent: {
6734 nscoord pref = NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1);
6735 nscoord min = 0;
6736 if (intrinsicSizeFromAspectRatio) {
6737 // The min-content and max-content size are identical and equal to the
6738 // size computed from the block size and the aspect ratio.
6739 pref = min = *intrinsicSizeFromAspectRatio;
6740 } else {
6741 pref = GetPrefISize(aRenderingContext);
6742 min = GetMinISize(aRenderingContext);
6743 }
6744
6745 nscoord fill = aAvailableISizeOverride
6746 ? *aAvailableISizeOverride
6747 : aContainingBlockSize.ISize(aWM) -
6748 (aBoxSizingToMarginEdge +
6749 aContentEdgeToBoxSizing.ISize(aWM));
6750
6751 if (MOZ_UNLIKELY((__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
6752 aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize))(__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
) {
6753 min = std::min(min, fill);
6754 }
6755 result = std::max(min, std::min(pref, fill));
6756 NS_ASSERTION(result >= 0, "inline-size less than zero")do { if (!(result >= 0)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "inline-size less than zero", "result >= 0", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6756); MOZ_PretendNoReturn(); } } while (0)
;
6757 return {result};
6758 }
6759 case ExtremumLength::MozAvailable:
6760 return {aContainingBlockSize.ISize(aWM) -
6761 (aBoxSizingToMarginEdge + aContentEdgeToBoxSizing.ISize(aWM))};
6762 }
6763 MOZ_ASSERT_UNREACHABLE("Unknown extremum length?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"Unknown extremum length?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6763); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Unknown extremum length?" ")"); do
{ *((volatile int*)__null) = 6763; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
6764 return {};
6765}
6766
6767nscoord nsIFrame::ComputeISizeValue(const WritingMode aWM,
6768 const LogicalSize& aContainingBlockSize,
6769 const LogicalSize& aContentEdgeToBoxSizing,
6770 const LengthPercentage& aSize) {
6771 LAYOUT_WARN_IF_FALSE(do { if ((__builtin_expect(!!(mozilla::detail::log_test(sLayoutLog
, mozilla::LogLevel::Warning)), 0)) && !(aContainingBlockSize
.ISize(aWM) != nscoord((1 << 30) - 1))) { mozilla::detail
::LayoutLogWarning("have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size " "calculation"
, "aContainingBlockSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6775); } } while (0)
6772 aContainingBlockSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE,do { if ((__builtin_expect(!!(mozilla::detail::log_test(sLayoutLog
, mozilla::LogLevel::Warning)), 0)) && !(aContainingBlockSize
.ISize(aWM) != nscoord((1 << 30) - 1))) { mozilla::detail
::LayoutLogWarning("have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size " "calculation"
, "aContainingBlockSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6775); } } while (0)
6773 "have unconstrained inline-size; this should only result from "do { if ((__builtin_expect(!!(mozilla::detail::log_test(sLayoutLog
, mozilla::LogLevel::Warning)), 0)) && !(aContainingBlockSize
.ISize(aWM) != nscoord((1 << 30) - 1))) { mozilla::detail
::LayoutLogWarning("have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size " "calculation"
, "aContainingBlockSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6775); } } while (0)
6774 "very large sizes, not attempts at intrinsic inline-size "do { if ((__builtin_expect(!!(mozilla::detail::log_test(sLayoutLog
, mozilla::LogLevel::Warning)), 0)) && !(aContainingBlockSize
.ISize(aWM) != nscoord((1 << 30) - 1))) { mozilla::detail
::LayoutLogWarning("have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size " "calculation"
, "aContainingBlockSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6775); } } while (0)
6775 "calculation")do { if ((__builtin_expect(!!(mozilla::detail::log_test(sLayoutLog
, mozilla::LogLevel::Warning)), 0)) && !(aContainingBlockSize
.ISize(aWM) != nscoord((1 << 30) - 1))) { mozilla::detail
::LayoutLogWarning("have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size " "calculation"
, "aContainingBlockSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6775); } } while (0)
;
6776 NS_ASSERTION(aContainingBlockSize.ISize(aWM) >= 0,do { if (!(aContainingBlockSize.ISize(aWM) >= 0)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "inline-size less than zero", "aContainingBlockSize.ISize(aWM) >= 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6777); MOZ_PretendNoReturn(); } } while (0)
6777 "inline-size less than zero")do { if (!(aContainingBlockSize.ISize(aWM) >= 0)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "inline-size less than zero", "aContainingBlockSize.ISize(aWM) >= 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6777); MOZ_PretendNoReturn(); } } while (0)
;
6778
6779 nscoord result = aSize.Resolve(aContainingBlockSize.ISize(aWM));
6780 // The result of a calc() expression might be less than 0; we
6781 // should clamp at runtime (below). (Percentages and coords that
6782 // are less than 0 have already been dropped by the parser.)
6783 result -= aContentEdgeToBoxSizing.ISize(aWM);
6784 return std::max(0, result);
6785}
6786
6787void nsIFrame::DidReflow(nsPresContext* aPresContext,
6788 const ReflowInput* aReflowInput) {
6789 NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, ("nsIFrame::DidReflow"))do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("nsIFrame::DidReflow"
); } } while (0)
;
6790
6791 if (IsHiddenByContentVisibilityOfInFlowParentForLayout()) {
6792 RemoveStateBits(NS_FRAME_IN_REFLOW);
6793 return;
6794 }
6795
6796 SVGObserverUtils::InvalidateDirectRenderingObservers(
6797 this, SVGObserverUtils::INVALIDATE_REFLOW);
6798
6799 RemoveStateBits(NS_FRAME_IN_REFLOW | NS_FRAME_FIRST_REFLOW |
6800 NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN);
6801
6802 // Clear bits that were used in ReflowInput::InitResizeFlags (see
6803 // comment there for why we can't clear it there).
6804 SetHasBSizeChange(false);
6805 SetHasPaddingChange(false);
6806
6807 // Notify the percent bsize observer if there is a percent bsize.
6808 // The observer may be able to initiate another reflow with a computed
6809 // bsize. This happens in the case where a table cell has no computed
6810 // bsize but can fabricate one when the cell bsize is known.
6811 if (aReflowInput && aReflowInput->mPercentBSizeObserver && !GetPrevInFlow()) {
6812 const auto& bsize =
6813 aReflowInput->mStylePosition->BSize(aReflowInput->GetWritingMode());
6814 if (bsize.HasPercent()) {
6815 aReflowInput->mPercentBSizeObserver->NotifyPercentBSize(*aReflowInput);
6816 }
6817 }
6818
6819 aPresContext->ReflowedFrame();
6820}
6821
6822void nsIFrame::FinishReflowWithAbsoluteFrames(nsPresContext* aPresContext,
6823 ReflowOutput& aDesiredSize,
6824 const ReflowInput& aReflowInput,
6825 nsReflowStatus& aStatus,
6826 bool aConstrainBSize) {
6827 ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowInput, aStatus,
6828 aConstrainBSize);
6829
6830 FinishAndStoreOverflow(&aDesiredSize, aReflowInput.mStyleDisplay);
6831}
6832
6833void nsIFrame::ReflowAbsoluteFrames(nsPresContext* aPresContext,
6834 ReflowOutput& aDesiredSize,
6835 const ReflowInput& aReflowInput,
6836 nsReflowStatus& aStatus,
6837 bool aConstrainBSize) {
6838 if (HasAbsolutelyPositionedChildren()) {
6839 nsAbsoluteContainingBlock* absoluteContainer = GetAbsoluteContainingBlock();
6840
6841 // Let the absolutely positioned container reflow any absolutely positioned
6842 // child frames that need to be reflowed
6843
6844 // The containing block for the abs pos kids is formed by our padding edge.
6845 nsMargin usedBorder = GetUsedBorder();
6846 nscoord containingBlockWidth =
6847 std::max(0, aDesiredSize.Width() - usedBorder.LeftRight());
6848 nscoord containingBlockHeight =
6849 std::max(0, aDesiredSize.Height() - usedBorder.TopBottom());
6850 nsContainerFrame* container = do_QueryFrame(this);
6851 NS_ASSERTION(container,do { if (!(container)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Abs-pos children only supported on container frames for now"
, "container", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6852); MOZ_PretendNoReturn(); } } while (0)
6852 "Abs-pos children only supported on container frames for now")do { if (!(container)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Abs-pos children only supported on container frames for now"
, "container", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6852); MOZ_PretendNoReturn(); } } while (0)
;
6853
6854 nsRect containingBlock(0, 0, containingBlockWidth, containingBlockHeight);
6855 AbsPosReflowFlags flags =
6856 AbsPosReflowFlags::CBWidthAndHeightChanged; // XXX could be optimized
6857 if (aConstrainBSize) {
6858 flags |= AbsPosReflowFlags::ConstrainHeight;
6859 }
6860 absoluteContainer->Reflow(container, aPresContext, aReflowInput, aStatus,
6861 containingBlock, flags,
6862 &aDesiredSize.mOverflowAreas);
6863 }
6864}
6865
6866/* virtual */
6867bool nsIFrame::CanContinueTextRun() const {
6868 // By default, a frame will *not* allow a text run to be continued
6869 // through it.
6870 return false;
6871}
6872
6873void nsIFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
6874 const ReflowInput& aReflowInput,
6875 nsReflowStatus& aStatus) {
6876 MarkInReflow();
6877 DO_GLOBAL_REFLOW_COUNT("nsFrame")aPresContext->CountReflows(("nsFrame"), (nsIFrame*)this);;
6878 MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aStatus.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aStatus.IsEmpty()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("aStatus.IsEmpty()"
" (" "Caller should pass a fresh reflow status!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6878); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStatus.IsEmpty()"
") (" "Caller should pass a fresh reflow status!" ")"); do {
*((volatile int*)__null) = 6878; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
6879 aDesiredSize.ClearSize();
6880}
6881
6882bool nsIFrame::IsContentDisabled() const {
6883 // FIXME(emilio): Doing this via CSS means callers must ensure the style is up
6884 // to date, and they don't!
6885 if (StyleUI()->UserInput() == StyleUserInput::None) {
6886 return true;
6887 }
6888
6889 auto* element = nsGenericHTMLElement::FromNodeOrNull(GetContent());
6890 return element && element->IsDisabled();
6891}
6892
6893bool nsIFrame::IsContentRelevant() const {
6894 MOZ_ASSERT(StyleDisplay()->ContentVisibility(*this) ==do { static_assert( mozilla::detail::AssertionConditionType<
decltype(StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility
::Auto)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility
::Auto))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6895); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 6895; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6895 StyleContentVisibility::Auto)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility
::Auto)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility
::Auto))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6895); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 6895; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6896
6897 auto* element = Element::FromNodeOrNull(GetContent());
6898 MOZ_ASSERT(element)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(element)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(element))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("element", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6898); AnnotateMozCrashReason("MOZ_ASSERT" "(" "element" ")"
); do { *((volatile int*)__null) = 6898; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6899
6900 Maybe<ContentRelevancy> relevancy = element->GetContentRelevancy();
6901 if (relevancy.isSome()) {
6902 return !relevancy->isEmpty();
6903 }
6904
6905 // If there is no relevancy set, then this frame still has not received had
6906 // the initial visibility callback call. In that case, only rely on whether
6907 // or not it is inside a top layer element which will never change for this
6908 // frame and allows proper rendering of the top layer.
6909 return IsDescendantOfTopLayerElement();
6910}
6911
6912bool nsIFrame::HidesContent(
6913 const EnumSet<IncludeContentVisibility>& aInclude) const {
6914 auto effectiveContentVisibility = StyleDisplay()->ContentVisibility(*this);
6915 if (aInclude.contains(IncludeContentVisibility::Hidden) &&
6916 effectiveContentVisibility == StyleContentVisibility::Hidden) {
6917 return true;
6918 }
6919
6920 if (aInclude.contains(IncludeContentVisibility::Auto) &&
6921 effectiveContentVisibility == StyleContentVisibility::Auto) {
6922 return !IsContentRelevant();
6923 }
6924
6925 return false;
6926}
6927
6928bool nsIFrame::HidesContentForLayout() const {
6929 return HidesContent() && !PresShell()->IsForcingLayoutForHiddenContent(this);
6930}
6931
6932bool nsIFrame::IsHiddenByContentVisibilityOfInFlowParentForLayout() const {
6933 const auto* parent = GetInFlowParent();
6934 // The anonymous children owned by parent are important for properly sizing
6935 // their parents.
6936 return parent && parent->HidesContentForLayout() &&
6937 !(parent->HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES) &&
6938 Style()->IsAnonBox());
6939}
6940
6941nsIFrame* nsIFrame::GetClosestContentVisibilityAncestor(
6942 const EnumSet<IncludeContentVisibility>& aInclude) const {
6943 if (!StaticPrefs::layout_css_content_visibility_enabled()) {
6944 return nullptr;
6945 }
6946
6947 auto* parent = GetInFlowParent();
6948 bool isAnonymousBlock = Style()->IsAnonBox() && parent &&
6949 parent->HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES);
6950 for (nsIFrame* cur = parent; cur; cur = cur->GetInFlowParent()) {
6951 if (!isAnonymousBlock && cur->HidesContent(aInclude)) {
6952 return cur;
6953 }
6954
6955 // Anonymous boxes are not hidden by the content-visibility of their first
6956 // non-anonymous ancestor, but can be hidden by ancestors further up the
6957 // tree.
6958 isAnonymousBlock = false;
6959 }
6960
6961 return nullptr;
6962}
6963
6964bool nsIFrame::IsHiddenByContentVisibilityOnAnyAncestor(
6965 const EnumSet<IncludeContentVisibility>& aInclude) const {
6966 return !!GetClosestContentVisibilityAncestor(aInclude);
6967}
6968
6969bool nsIFrame::HasSelectionInSubtree() {
6970 if (IsSelected()) {
6971 return true;
6972 }
6973
6974 RefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
6975 if (!frameSelection) {
6976 return false;
6977 }
6978
6979 const Selection* selection =
6980 frameSelection->GetSelection(SelectionType::eNormal);
6981 if (!selection) {
6982 return false;
6983 }
6984
6985 for (uint32_t i = 0; i < selection->RangeCount(); i++) {
6986 auto* range = selection->GetRangeAt(i);
6987 MOZ_ASSERT(range)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(range)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(range))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("range", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6987); AnnotateMozCrashReason("MOZ_ASSERT" "(" "range" ")")
; do { *((volatile int*)__null) = 6987; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6988
6989 const auto* commonAncestorNode =
6990 range->GetRegisteredClosestCommonInclusiveAncestor();
6991 if (commonAncestorNode &&
6992 commonAncestorNode->IsInclusiveDescendantOf(GetContent())) {
6993 return true;
6994 }
6995 }
6996
6997 return false;
6998}
6999
7000bool nsIFrame::IsDescendantOfTopLayerElement() const {
7001 if (!GetContent()) {
7002 return false;
7003 }
7004
7005 nsTArray<dom::Element*> topLayer = PresContext()->Document()->GetTopLayer();
7006 for (auto* element : topLayer) {
7007 if (GetContent()->IsInclusiveFlatTreeDescendantOf(element)) {
7008 return true;
7009 }
7010 }
7011
7012 return false;
7013}
7014
7015bool nsIFrame::UpdateIsRelevantContent(
7016 const ContentRelevancy& aRelevancyToUpdate) {
7017 MOZ_ASSERT(StyleDisplay()->ContentVisibility(*this) ==do { static_assert( mozilla::detail::AssertionConditionType<
decltype(StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility
::Auto)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility
::Auto))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7018); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 7018; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
7018 StyleContentVisibility::Auto)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility
::Auto)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility
::Auto))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7018); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 7018; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7019
7020 auto* element = Element::FromNodeOrNull(GetContent());
7021 MOZ_ASSERT(element)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(element)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(element))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("element", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7021); AnnotateMozCrashReason("MOZ_ASSERT" "(" "element" ")"
); do { *((volatile int*)__null) = 7021; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7022
7023 ContentRelevancy newRelevancy;
7024 Maybe<ContentRelevancy> oldRelevancy = element->GetContentRelevancy();
7025 if (oldRelevancy.isSome()) {
7026 newRelevancy = *oldRelevancy;
7027 }
7028
7029 auto setRelevancyValue = [&](ContentRelevancyReason reason, bool value) {
7030 if (value) {
7031 newRelevancy += reason;
7032 } else {
7033 newRelevancy -= reason;
7034 }
7035 };
7036
7037 if (!oldRelevancy ||
7038 aRelevancyToUpdate.contains(ContentRelevancyReason::Visible)) {
7039 Maybe<bool> visible = element->GetVisibleForContentVisibility();
7040 if (visible.isSome()) {
7041 setRelevancyValue(ContentRelevancyReason::Visible, *visible);
7042 }
7043 }
7044
7045 if (!oldRelevancy ||
7046 aRelevancyToUpdate.contains(ContentRelevancyReason::FocusInSubtree)) {
7047 setRelevancyValue(ContentRelevancyReason::FocusInSubtree,
7048 element->State().HasAtLeastOneOfStates(
7049 ElementState::FOCUS_WITHIN | ElementState::FOCUS));
7050 }
7051
7052 if (!oldRelevancy ||
7053 aRelevancyToUpdate.contains(ContentRelevancyReason::Selected)) {
7054 setRelevancyValue(ContentRelevancyReason::Selected,
7055 HasSelectionInSubtree());
7056 }
7057
7058 bool overallRelevancyChanged =
7059 !oldRelevancy || oldRelevancy->isEmpty() != newRelevancy.isEmpty();
7060 if (!oldRelevancy || *oldRelevancy != newRelevancy) {
7061 element->SetContentRelevancy(newRelevancy);
7062 }
7063
7064 if (!overallRelevancyChanged) {
7065 return false;
7066 }
7067
7068 HandleLastRememberedSize();
7069 PresShell()->FrameNeedsReflow(
7070 this, IntrinsicDirty::FrameAncestorsAndDescendants, NS_FRAME_IS_DIRTY);
7071 InvalidateFrame();
7072
7073 ContentVisibilityAutoStateChangeEventInit init;
7074 init.mSkipped = newRelevancy.isEmpty();
7075 RefPtr<ContentVisibilityAutoStateChangeEvent> event =
7076 ContentVisibilityAutoStateChangeEvent::Constructor(
7077 element, u"contentvisibilityautostatechange"_ns, init);
7078
7079 // Per
7080 // https://drafts.csswg.org/css-contain/#content-visibility-auto-state-changed
7081 // "This event is dispatched by posting a task at the time when the state
7082 // change occurs."
7083 RefPtr<AsyncEventDispatcher> asyncDispatcher =
7084 new AsyncEventDispatcher(element, event.forget());
7085 DebugOnly<nsresult> rv = asyncDispatcher->PostDOMEvent();
7086 NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncEventDispatcher failed to dispatch")do { if (!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1
))))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "AsyncEventDispatcher failed to dispatch"
, "NS_SUCCEEDED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7086); MOZ_PretendNoReturn(); } } while (0)
;
7087 return true;
7088}
7089
7090nsresult nsIFrame::CharacterDataChanged(const CharacterDataChangeInfo&) {
7091 MOZ_ASSERT_UNREACHABLE("should only be called for text frames")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"should only be called for text frames" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7091); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should only be called for text frames"
")"); do { *((volatile int*)__null) = 7091; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7092 return NS_OK;
7093}
7094
7095nsresult nsIFrame::AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
7096 int32_t aModType) {
7097 return NS_OK;
7098}
7099
7100// Flow member functions
7101
7102nsIFrame* nsIFrame::GetPrevContinuation() const { return nullptr; }
7103
7104void nsIFrame::SetPrevContinuation(nsIFrame* aPrevContinuation) {
7105 MOZ_ASSERT(false, "not splittable")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "not splittable"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7105); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"not splittable" ")"); do { *((volatile int*)__null) = 7105;
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
7106}
7107
7108nsIFrame* nsIFrame::GetNextContinuation() const { return nullptr; }
7109
7110void nsIFrame::SetNextContinuation(nsIFrame*) {
7111 MOZ_ASSERT(false, "not splittable")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "not splittable"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7111); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"not splittable" ")"); do { *((volatile int*)__null) = 7111;
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
7112}
7113
7114nsIFrame* nsIFrame::GetPrevInFlow() const { return nullptr; }
7115
7116void nsIFrame::SetPrevInFlow(nsIFrame* aPrevInFlow) {
7117 MOZ_ASSERT(false, "not splittable")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "not splittable"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7117); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"not splittable" ")"); do { *((volatile int*)__null) = 7117;
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
7118}
7119
7120nsIFrame* nsIFrame::GetNextInFlow() const { return nullptr; }
7121
7122void nsIFrame::SetNextInFlow(nsIFrame*) { MOZ_ASSERT(false, "not splittable")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "not splittable"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7122); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"not splittable" ")"); do { *((volatile int*)__null) = 7122;
__attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
; }
7123
7124nsIFrame* nsIFrame::GetTailContinuation() {
7125 nsIFrame* frame = this;
7126 while (frame->HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER)) {
7127 frame = frame->GetPrevContinuation();
7128 NS_ASSERTION(frame, "first continuation can't be overflow container")do { if (!(frame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "first continuation can't be overflow container"
, "frame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7128); MOZ_PretendNoReturn(); } } while (0)
;
7129 }
7130 for (nsIFrame* next = frame->GetNextContinuation();
7131 next && !next->HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER);
7132 next = frame->GetNextContinuation()) {
7133 frame = next;
7134 }
7135
7136 MOZ_ASSERT(frame, "illegal state in continuation chain.")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(frame)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(frame))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("frame" " (" "illegal state in continuation chain."
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7136); AnnotateMozCrashReason("MOZ_ASSERT" "(" "frame" ") ("
"illegal state in continuation chain." ")"); do { *((volatile
int*)__null) = 7136; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7137 return frame;
7138}
7139
7140// Associated view object
7141void nsIFrame::SetView(nsView* aView) {
7142 if (aView) {
7143 aView->SetFrame(this);
7144
7145#ifdef DEBUG1
7146 LayoutFrameType frameType = Type();
7147 NS_ASSERTION(frameType == LayoutFrameType::SubDocument ||do { if (!(frameType == LayoutFrameType::SubDocument || frameType
== LayoutFrameType::ListControl || frameType == LayoutFrameType
::Viewport || frameType == LayoutFrameType::MenuPopup)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Only specific frame types can have an nsView"
, "frameType == LayoutFrameType::SubDocument || frameType == LayoutFrameType::ListControl || frameType == LayoutFrameType::Viewport || frameType == LayoutFrameType::MenuPopup"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7151); MOZ_PretendNoReturn(); } } while (0)
7148 frameType == LayoutFrameType::ListControl ||do { if (!(frameType == LayoutFrameType::SubDocument || frameType
== LayoutFrameType::ListControl || frameType == LayoutFrameType
::Viewport || frameType == LayoutFrameType::MenuPopup)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Only specific frame types can have an nsView"
, "frameType == LayoutFrameType::SubDocument || frameType == LayoutFrameType::ListControl || frameType == LayoutFrameType::Viewport || frameType == LayoutFrameType::MenuPopup"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7151); MOZ_PretendNoReturn(); } } while (0)
7149 frameType == LayoutFrameType::Viewport ||do { if (!(frameType == LayoutFrameType::SubDocument || frameType
== LayoutFrameType::ListControl || frameType == LayoutFrameType
::Viewport || frameType == LayoutFrameType::MenuPopup)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Only specific frame types can have an nsView"
, "frameType == LayoutFrameType::SubDocument || frameType == LayoutFrameType::ListControl || frameType == LayoutFrameType::Viewport || frameType == LayoutFrameType::MenuPopup"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7151); MOZ_PretendNoReturn(); } } while (0)
7150 frameType == LayoutFrameType::MenuPopup,do { if (!(frameType == LayoutFrameType::SubDocument || frameType
== LayoutFrameType::ListControl || frameType == LayoutFrameType
::Viewport || frameType == LayoutFrameType::MenuPopup)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Only specific frame types can have an nsView"
, "frameType == LayoutFrameType::SubDocument || frameType == LayoutFrameType::ListControl || frameType == LayoutFrameType::Viewport || frameType == LayoutFrameType::MenuPopup"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7151); MOZ_PretendNoReturn(); } } while (0)
7151 "Only specific frame types can have an nsView")do { if (!(frameType == LayoutFrameType::SubDocument || frameType
== LayoutFrameType::ListControl || frameType == LayoutFrameType
::Viewport || frameType == LayoutFrameType::MenuPopup)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Only specific frame types can have an nsView"
, "frameType == LayoutFrameType::SubDocument || frameType == LayoutFrameType::ListControl || frameType == LayoutFrameType::Viewport || frameType == LayoutFrameType::MenuPopup"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7151); MOZ_PretendNoReturn(); } } while (0)
;
7152#endif
7153
7154 // Store the view on the frame.
7155 SetViewInternal(aView);
7156
7157 // Set the frame state bit that says the frame has a view
7158 AddStateBits(NS_FRAME_HAS_VIEW);
7159
7160 // Let all of the ancestors know they have a descendant with a view.
7161 for (nsIFrame* f = GetParent();
7162 f && !f->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
7163 f = f->GetParent())
7164 f->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
7165 } else {
7166 MOZ_ASSERT_UNREACHABLE("Destroying a view while the frame is alive?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"Destroying a view while the frame is alive?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7166); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Destroying a view while the frame is alive?"
")"); do { *((volatile int*)__null) = 7166; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7167 RemoveStateBits(NS_FRAME_HAS_VIEW);
7168 SetViewInternal(nullptr);
7169 }
7170}
7171
7172// Find the first geometric parent that has a view
7173nsIFrame* nsIFrame::GetAncestorWithView() const {
7174 for (nsIFrame* f = GetParent(); nullptr != f; f = f->GetParent()) {
7175 if (f->HasView()) {
7176 return f;
7177 }
7178 }
7179 return nullptr;
7180}
7181
7182template <nsPoint (nsIFrame::*PositionGetter)() const>
7183static nsPoint OffsetCalculator(const nsIFrame* aThis, const nsIFrame* aOther) {
7184 MOZ_ASSERT(aOther, "Must have frame for destination coordinate system!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aOther)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aOther))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aOther" " (" "Must have frame for destination coordinate system!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7184); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOther" ") ("
"Must have frame for destination coordinate system!" ")"); do
{ *((volatile int*)__null) = 7184; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
7185
7186 NS_ASSERTION(aThis->PresContext() == aOther->PresContext(),do { if (!(aThis->PresContext() == aOther->PresContext(
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "GetOffsetTo called on frames in different documents"
, "aThis->PresContext() == aOther->PresContext()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7187); MOZ_PretendNoReturn(); } } while (0)
7187 "GetOffsetTo called on frames in different documents")do { if (!(aThis->PresContext() == aOther->PresContext(
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "GetOffsetTo called on frames in different documents"
, "aThis->PresContext() == aOther->PresContext()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7187); MOZ_PretendNoReturn(); } } while (0)
;
7188
7189 nsPoint offset(0, 0);
7190 const nsIFrame* f;
7191 for (f = aThis; f != aOther && f; f = f->GetParent()) {
7192 offset += (f->*PositionGetter)();
7193 }
7194
7195 if (f != aOther) {
7196 // Looks like aOther wasn't an ancestor of |this|. So now we have
7197 // the root-frame-relative position of |this| in |offset|. Convert back
7198 // to the coordinates of aOther
7199 while (aOther) {
7200 offset -= (aOther->*PositionGetter)();
7201 aOther = aOther->GetParent();
7202 }
7203 }
7204
7205 return offset;
7206}
7207
7208nsPoint nsIFrame::GetOffsetTo(const nsIFrame* aOther) const {
7209 return OffsetCalculator<&nsIFrame::GetPosition>(this, aOther);
7210}
7211
7212nsPoint nsIFrame::GetOffsetToIgnoringScrolling(const nsIFrame* aOther) const {
7213 return OffsetCalculator<&nsIFrame::GetPositionIgnoringScrolling>(this,
7214 aOther);
7215}
7216
7217nsPoint nsIFrame::GetOffsetToCrossDoc(const nsIFrame* aOther) const {
7218 return GetOffsetToCrossDoc(aOther, PresContext()->AppUnitsPerDevPixel());
7219}
7220
7221nsPoint nsIFrame::GetOffsetToCrossDoc(const nsIFrame* aOther,
7222 const int32_t aAPD) const {
7223 MOZ_ASSERT(aOther, "Must have frame for destination coordinate system!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aOther)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aOther))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aOther" " (" "Must have frame for destination coordinate system!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7223); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOther" ") ("
"Must have frame for destination coordinate system!" ")"); do
{ *((volatile int*)__null) = 7223; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
7224 NS_ASSERTION(PresContext()->GetRootPresContext() ==do { if (!(PresContext()->GetRootPresContext() == aOther->
PresContext()->GetRootPresContext())) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "trying to get the offset between frames in different document "
"hierarchies?", "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7227); MOZ_PretendNoReturn(); } } while (0)
7225 aOther->PresContext()->GetRootPresContext(),do { if (!(PresContext()->GetRootPresContext() == aOther->
PresContext()->GetRootPresContext())) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "trying to get the offset between frames in different document "
"hierarchies?", "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7227); MOZ_PretendNoReturn(); } } while (0)
7226 "trying to get the offset between frames in different document "do { if (!(PresContext()->GetRootPresContext() == aOther->
PresContext()->GetRootPresContext())) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "trying to get the offset between frames in different document "
"hierarchies?", "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7227); MOZ_PretendNoReturn(); } } while (0)
7227 "hierarchies?")do { if (!(PresContext()->GetRootPresContext() == aOther->
PresContext()->GetRootPresContext())) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "trying to get the offset between frames in different document "
"hierarchies?", "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7227); MOZ_PretendNoReturn(); } } while (0)
;
7228 if (PresContext()->GetRootPresContext() !=
7229 aOther->PresContext()->GetRootPresContext()) {
7230 // crash right away, we are almost certainly going to crash anyway.
7231 MOZ_CRASH(do { do { } while (false); MOZ_ReportCrash("" "trying to get the offset between frames in different "
"document hierarchies?", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7233); AnnotateMozCrashReason("MOZ_CRASH(" "trying to get the offset between frames in different "
"document hierarchies?" ")"); do { *((volatile int*)__null) =
7233; __attribute__((nomerge)) ::abort(); } while (false); }
while (false)
7232 "trying to get the offset between frames in different "do { do { } while (false); MOZ_ReportCrash("" "trying to get the offset between frames in different "
"document hierarchies?", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7233); AnnotateMozCrashReason("MOZ_CRASH(" "trying to get the offset between frames in different "
"document hierarchies?" ")"); do { *((volatile int*)__null) =
7233; __attribute__((nomerge)) ::abort(); } while (false); }
while (false)
7233 "document hierarchies?")do { do { } while (false); MOZ_ReportCrash("" "trying to get the offset between frames in different "
"document hierarchies?", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7233); AnnotateMozCrashReason("MOZ_CRASH(" "trying to get the offset between frames in different "
"document hierarchies?" ")"); do { *((volatile int*)__null) =
7233; __attribute__((nomerge)) ::abort(); } while (false); }
while (false)
;
7234 }
7235
7236 const nsIFrame* root = nullptr;
7237 // offset will hold the final offset
7238 // docOffset holds the currently accumulated offset at the current APD, it
7239 // will be converted and added to offset when the current APD changes.
7240 nsPoint offset(0, 0), docOffset(0, 0);
7241 const nsIFrame* f = this;
7242 int32_t currAPD = PresContext()->AppUnitsPerDevPixel();
7243 while (f && f != aOther) {
7244 docOffset += f->GetPosition();
7245 nsIFrame* parent = f->GetParent();
7246 if (parent) {
7247 f = parent;
7248 } else {
7249 nsPoint newOffset(0, 0);
7250 root = f;
7251 f = nsLayoutUtils::GetCrossDocParentFrameInProcess(f, &newOffset);
7252 int32_t newAPD = f ? f->PresContext()->AppUnitsPerDevPixel() : 0;
7253 if (!f || newAPD != currAPD) {
7254 // Convert docOffset to the right APD and add it to offset.
7255 offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD);
7256 docOffset.x = docOffset.y = 0;
7257 }
7258 currAPD = newAPD;
7259 docOffset += newOffset;
7260 }
7261 }
7262 if (f == aOther) {
7263 offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD);
7264 } else {
7265 // Looks like aOther wasn't an ancestor of |this|. So now we have
7266 // the root-document-relative position of |this| in |offset|. Subtract the
7267 // root-document-relative position of |aOther| from |offset|.
7268 // This call won't try to recurse again because root is an ancestor of
7269 // aOther.
7270 nsPoint negOffset = aOther->GetOffsetToCrossDoc(root, aAPD);
7271 offset -= negOffset;
7272 }
7273
7274 return offset;
7275}
7276
7277CSSIntRect nsIFrame::GetScreenRect() const {
7278 return CSSIntRect::FromAppUnitsToNearest(GetScreenRectInAppUnits());
7279}
7280
7281nsRect nsIFrame::GetScreenRectInAppUnits() const {
7282 nsPresContext* presContext = PresContext();
7283 nsIFrame* rootFrame = presContext->PresShell()->GetRootFrame();
7284 nsPoint rootScreenPos(0, 0);
7285 nsPoint rootFrameOffsetInParent(0, 0);
7286 nsIFrame* rootFrameParent = nsLayoutUtils::GetCrossDocParentFrameInProcess(
7287 rootFrame, &rootFrameOffsetInParent);
7288 if (rootFrameParent) {
7289 nsRect parentScreenRectAppUnits =
7290 rootFrameParent->GetScreenRectInAppUnits();
7291 nsPresContext* parentPresContext = rootFrameParent->PresContext();
7292 double parentScale = double(presContext->AppUnitsPerDevPixel()) /
7293 parentPresContext->AppUnitsPerDevPixel();
7294 nsPoint rootPt =
7295 parentScreenRectAppUnits.TopLeft() + rootFrameOffsetInParent;
7296 rootScreenPos.x = NS_round(parentScale * rootPt.x);
7297 rootScreenPos.y = NS_round(parentScale * rootPt.y);
7298 } else {
7299 nsCOMPtr<nsIWidget> rootWidget =
7300 presContext->PresShell()->GetViewManager()->GetRootWidget();
7301 if (rootWidget) {
7302 LayoutDeviceIntPoint rootDevPx = rootWidget->WidgetToScreenOffset();
7303 rootScreenPos.x = presContext->DevPixelsToAppUnits(rootDevPx.x);
7304 rootScreenPos.y = presContext->DevPixelsToAppUnits(rootDevPx.y);
7305 }
7306 }
7307
7308 return nsRect(rootScreenPos + GetOffsetTo(rootFrame), GetSize());
7309}
7310
7311// Returns the offset from this frame to the closest geometric parent that
7312// has a view. Also returns the containing view or null in case of error
7313void nsIFrame::GetOffsetFromView(nsPoint& aOffset, nsView** aView) const {
7314 MOZ_ASSERT(nullptr != aView, "null OUT parameter pointer")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(nullptr != aView)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(nullptr != aView))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("nullptr != aView"
" (" "null OUT parameter pointer" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7314); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nullptr != aView"
") (" "null OUT parameter pointer" ")"); do { *((volatile int
*)__null) = 7314; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7315 nsIFrame* frame = const_cast<nsIFrame*>(this);
7316
7317 *aView = nullptr;
7318 aOffset.MoveTo(0, 0);
7319 do {
7320 aOffset += frame->GetPosition();
7321 frame = frame->GetParent();
7322 } while (frame && !frame->HasView());
7323
7324 if (frame) {
7325 *aView = frame->GetView();
7326 }
7327}
7328
7329nsIWidget* nsIFrame::GetNearestWidget() const {
7330 return GetClosestView()->GetNearestWidget(nullptr);
7331}
7332
7333nsIWidget* nsIFrame::GetNearestWidget(nsPoint& aOffset) const {
7334 nsPoint offsetToView;
7335 nsPoint offsetToWidget;
7336 nsIWidget* widget =
7337 GetClosestView(&offsetToView)->GetNearestWidget(&offsetToWidget);
7338 aOffset = offsetToView + offsetToWidget;
7339 return widget;
7340}
7341
7342Matrix4x4Flagged nsIFrame::GetTransformMatrix(ViewportType aViewportType,
7343 RelativeTo aStopAtAncestor,
7344 nsIFrame** aOutAncestor,
7345 uint32_t aFlags) const {
7346 MOZ_ASSERT(aOutAncestor, "Need a place to put the ancestor!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aOutAncestor)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aOutAncestor))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("aOutAncestor" " ("
"Need a place to put the ancestor!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7346); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOutAncestor"
") (" "Need a place to put the ancestor!" ")"); do { *((volatile
int*)__null) = 7346; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7347
7348 /* If we're transformed, we want to hand back the combination
7349 * transform/translate matrix that will apply our current transform, then
7350 * shift us to our parent.
7351 */
7352 const bool isTransformed = IsTransformed();
7353 const nsIFrame* zoomedContentRoot = nullptr;
7354 if (aStopAtAncestor.mViewportType == ViewportType::Visual) {
7355 zoomedContentRoot = ViewportUtils::IsZoomedContentRoot(this);
7356 if (zoomedContentRoot) {
7357 MOZ_ASSERT(aViewportType != ViewportType::Visual)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aViewportType != ViewportType::Visual)>::isValid,
"invalid assertion condition"); if ((__builtin_expect(!!(!(!
!(aViewportType != ViewportType::Visual))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aViewportType != ViewportType::Visual"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7357); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aViewportType != ViewportType::Visual"
")"); do { *((volatile int*)__null) = 7357; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7358 }
7359 }
7360
7361 if (isTransformed || zoomedContentRoot) {
7362 Matrix4x4 result;
7363 int32_t scaleFactor =
7364 ((aFlags & IN_CSS_UNITS) ? AppUnitsPerCSSPixel()
7365 : PresContext()->AppUnitsPerDevPixel());
7366
7367 /* Compute the delta to the parent, which we need because we are converting
7368 * coordinates to our parent.
7369 */
7370 if (isTransformed) {
7371 NS_ASSERTION(nsLayoutUtils::GetCrossDocParentFrameInProcess(this),do { if (!(nsLayoutUtils::GetCrossDocParentFrameInProcess(this
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Cannot transform the viewport frame!"
, "nsLayoutUtils::GetCrossDocParentFrameInProcess(this)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7372); MOZ_PretendNoReturn(); } } while (0)
7372 "Cannot transform the viewport frame!")do { if (!(nsLayoutUtils::GetCrossDocParentFrameInProcess(this
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Cannot transform the viewport frame!"
, "nsLayoutUtils::GetCrossDocParentFrameInProcess(this)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7372); MOZ_PretendNoReturn(); } } while (0)
;
7373
7374 result = result * nsDisplayTransform::GetResultingTransformMatrix(
7375 this, nsPoint(0, 0), scaleFactor,
7376 nsDisplayTransform::INCLUDE_PERSPECTIVE |
7377 nsDisplayTransform::OFFSET_BY_ORIGIN);
7378 }
7379
7380 // The offset from a zoomed content root to its parent (e.g. from
7381 // a canvas frame to a scroll frame) is in layout coordinates, so
7382 // apply it before applying any layout-to-visual transform.
7383 *aOutAncestor = nsLayoutUtils::GetCrossDocParentFrameInProcess(this);
7384 nsPoint delta = GetOffsetToCrossDoc(*aOutAncestor);
7385 /* Combine the raw transform with a translation to our parent. */
7386 result.PostTranslate(NSAppUnitsToFloatPixels(delta.x, scaleFactor),
7387 NSAppUnitsToFloatPixels(delta.y, scaleFactor), 0.0f);
7388
7389 if (zoomedContentRoot) {
7390 Matrix4x4 layoutToVisual;
7391 ScrollableLayerGuid::ViewID targetScrollId =
7392 nsLayoutUtils::FindOrCreateIDFor(zoomedContentRoot->GetContent());
7393 if (aFlags & nsIFrame::IN_CSS_UNITS) {
7394 layoutToVisual =
7395 ViewportUtils::GetVisualToLayoutTransform(targetScrollId)
7396 .Inverse()
7397 .ToUnknownMatrix();
7398 } else {
7399 layoutToVisual =
7400 ViewportUtils::GetVisualToLayoutTransform<LayoutDevicePixel>(
7401 targetScrollId)
7402 .Inverse()
7403 .ToUnknownMatrix();
7404 }
7405 result = result * layoutToVisual;
7406 }
7407
7408 return result;
7409 }
7410
7411 *aOutAncestor = nsLayoutUtils::GetCrossDocParentFrameInProcess(this);
7412
7413 /* Otherwise, we're not transformed. In that case, we'll walk up the frame
7414 * tree until we either hit the root frame or something that may be
7415 * transformed. We'll then change coordinates into that frame, since we're
7416 * guaranteed that nothing in-between can be transformed. First, however,
7417 * we have to check to see if we have a parent. If not, we'll set the
7418 * outparam to null (indicating that there's nothing left) and will hand back
7419 * the identity matrix.
7420 */
7421 if (!*aOutAncestor) return Matrix4x4();
7422
7423 /* Keep iterating while the frame can't possibly be transformed. */
7424 const nsIFrame* current = this;
7425 auto shouldStopAt = [](const nsIFrame* aCurrent, nsIFrame* aAncestor,
7426 uint32_t aFlags) {
7427 return aAncestor->IsTransformed() || nsLayoutUtils::IsPopup(aAncestor) ||
7428 ViewportUtils::IsZoomedContentRoot(aAncestor) ||
7429 ((aFlags & STOP_AT_STACKING_CONTEXT_AND_DISPLAY_PORT) &&
7430 (aAncestor->IsStackingContext() ||
7431 DisplayPortUtils::FrameHasDisplayPort(aAncestor, aCurrent)));
7432 };
7433 while (*aOutAncestor != aStopAtAncestor.mFrame &&
7434 !shouldStopAt(current, *aOutAncestor, aFlags)) {
7435 /* If no parent, stop iterating. Otherwise, update the ancestor. */
7436 nsIFrame* parent =
7437 nsLayoutUtils::GetCrossDocParentFrameInProcess(*aOutAncestor);
7438 if (!parent) break;
7439
7440 current = *aOutAncestor;
7441 *aOutAncestor = parent;
7442 }
7443
7444 NS_ASSERTION(*aOutAncestor, "Somehow ended up with a null ancestor...?")do { if (!(*aOutAncestor)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "Somehow ended up with a null ancestor...?", "*aOutAncestor"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7444); MOZ_PretendNoReturn(); } } while (0)
;
7445
7446 /* Translate from this frame to our ancestor, if it exists. That's the
7447 * entire transform, so we're done.
7448 */
7449 nsPoint delta = GetOffsetToCrossDoc(*aOutAncestor);
7450 int32_t scaleFactor =
7451 ((aFlags & IN_CSS_UNITS) ? AppUnitsPerCSSPixel()
7452 : PresContext()->AppUnitsPerDevPixel());
7453 return Matrix4x4::Translation(NSAppUnitsToFloatPixels(delta.x, scaleFactor),
7454 NSAppUnitsToFloatPixels(delta.y, scaleFactor),
7455 0.0f);
7456}
7457
7458static void InvalidateRenderingObservers(nsIFrame* aDisplayRoot,
7459 nsIFrame* aFrame,
7460 bool aFrameChanged = true) {
7461 MOZ_ASSERT(aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame
))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7461); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame)"
")"); do { *((volatile int*)__null) = 7461; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7462 SVGObserverUtils::InvalidateDirectRenderingObservers(aFrame);
7463 nsIFrame* parent = aFrame;
7464 while (parent != aDisplayRoot &&
7465 (parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(parent)) &&
7466 !parent->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) {
7467 SVGObserverUtils::InvalidateDirectRenderingObservers(parent);
7468 }
7469
7470 if (!aFrameChanged) {
7471 return;
7472 }
7473
7474 aFrame->MarkNeedsDisplayItemRebuild();
7475}
7476
7477static void SchedulePaintInternal(
7478 nsIFrame* aDisplayRoot, nsIFrame* aFrame,
7479 nsIFrame::PaintType aType = nsIFrame::PAINT_DEFAULT) {
7480 MOZ_ASSERT(aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame
))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7480); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame)"
")"); do { *((volatile int*)__null) = 7480; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7481 nsPresContext* pres = aDisplayRoot->PresContext()->GetRootPresContext();
7482
7483 // No need to schedule a paint for an external document since they aren't
7484 // painted directly.
7485 if (!pres || (pres->Document() && pres->Document()->IsResourceDoc())) {
7486 return;
7487 }
7488 if (!pres->GetContainerWeak()) {
7489 NS_WARNING("Shouldn't call SchedulePaint in a detached pres context")NS_DebugBreak(NS_DEBUG_WARNING, "Shouldn't call SchedulePaint in a detached pres context"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7489)
;
7490 return;
7491 }
7492
7493 pres->PresShell()->ScheduleViewManagerFlush();
7494
7495 if (aType == nsIFrame::PAINT_DEFAULT) {
7496 aDisplayRoot->AddStateBits(NS_FRAME_UPDATE_LAYER_TREE);
7497 }
7498}
7499
7500static void InvalidateFrameInternal(nsIFrame* aFrame, bool aHasDisplayItem,
7501 bool aRebuildDisplayItems) {
7502 if (aHasDisplayItem) {
7503 aFrame->AddStateBits(NS_FRAME_NEEDS_PAINT);
7504 }
7505
7506 if (aRebuildDisplayItems) {
7507 aFrame->MarkNeedsDisplayItemRebuild();
7508 }
7509 SVGObserverUtils::InvalidateDirectRenderingObservers(aFrame);
7510 bool needsSchedulePaint = false;
7511 if (nsLayoutUtils::IsPopup(aFrame)) {
7512 needsSchedulePaint = true;
7513 } else {
7514 nsIFrame* parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(aFrame);
7515 while (parent &&
7516 !parent->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) {
7517 if (aHasDisplayItem && !parent->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY)) {
7518 parent->AddStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT);
7519 }
7520 SVGObserverUtils::InvalidateDirectRenderingObservers(parent);
7521
7522 // If we're inside a popup, then we need to make sure that we
7523 // call schedule paint so that the NS_FRAME_UPDATE_LAYER_TREE
7524 // flag gets added to the popup display root frame.
7525 if (nsLayoutUtils::IsPopup(parent)) {
7526 needsSchedulePaint = true;
7527 break;
7528 }
7529 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(parent);
7530 }
7531 if (!parent) {
7532 needsSchedulePaint = true;
7533 }
7534 }
7535 if (!aHasDisplayItem) {
7536 return;
7537 }
7538 if (needsSchedulePaint) {
7539 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(aFrame);
7540 SchedulePaintInternal(displayRoot, aFrame);
7541 }
7542 if (aFrame->HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) {
7543 aFrame->RemoveProperty(nsIFrame::InvalidationRect());
7544 aFrame->RemoveStateBits(NS_FRAME_HAS_INVALID_RECT);
7545 }
7546}
7547
7548void nsIFrame::InvalidateFrameSubtree(bool aRebuildDisplayItems /* = true */) {
7549 InvalidateFrame(0, aRebuildDisplayItems);
7550
7551 if (HasAnyStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT)) {
7552 return;
7553 }
7554
7555 AddStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT);
7556
7557 for (const auto& childList : CrossDocChildLists()) {
7558 for (nsIFrame* child : childList.mList) {
7559 // Don't explicitly rebuild display items for our descendants,
7560 // since we should be marked and it implicitly includes all
7561 // descendants.
7562 child->InvalidateFrameSubtree(false);
7563 }
7564 }
7565}
7566
7567void nsIFrame::ClearInvalidationStateBits() {
7568 if (HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) {
7569 for (const auto& childList : CrossDocChildLists()) {
7570 for (nsIFrame* child : childList.mList) {
7571 child->ClearInvalidationStateBits();
7572 }
7573 }
7574 }
7575
7576 RemoveStateBits(NS_FRAME_NEEDS_PAINT | NS_FRAME_DESCENDANT_NEEDS_PAINT |
7577 NS_FRAME_ALL_DESCENDANTS_NEED_PAINT);
7578}
7579
7580bool HasRetainedDataFor(const nsIFrame* aFrame, uint32_t aDisplayItemKey) {
7581 if (RefPtr<WebRenderUserData> data =
7582 GetWebRenderUserData<WebRenderFallbackData>(aFrame,
7583 aDisplayItemKey)) {
7584 return true;
7585 }
7586
7587 return false;
7588}
7589
7590void nsIFrame::InvalidateFrame(uint32_t aDisplayItemKey,
7591 bool aRebuildDisplayItems /* = true */) {
7592 bool hasDisplayItem =
7593 !aDisplayItemKey || HasRetainedDataFor(this, aDisplayItemKey);
7594 InvalidateFrameInternal(this, hasDisplayItem, aRebuildDisplayItems);
7595}
7596
7597void nsIFrame::InvalidateFrameWithRect(const nsRect& aRect,
7598 uint32_t aDisplayItemKey,
7599 bool aRebuildDisplayItems /* = true */) {
7600 if (aRect.IsEmpty()) {
7601 return;
7602 }
7603 bool hasDisplayItem =
7604 !aDisplayItemKey || HasRetainedDataFor(this, aDisplayItemKey);
7605 bool alreadyInvalid = false;
7606 if (!HasAnyStateBits(NS_FRAME_NEEDS_PAINT)) {
7607 InvalidateFrameInternal(this, hasDisplayItem, aRebuildDisplayItems);
7608 } else {
7609 alreadyInvalid = true;
7610 }
7611
7612 if (!hasDisplayItem) {
7613 return;
7614 }
7615
7616 nsRect* rect;
7617 if (HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) {
7618 rect = GetProperty(InvalidationRect());
7619 MOZ_ASSERT(rect)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(rect)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(rect))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("rect", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7619); AnnotateMozCrashReason("MOZ_ASSERT" "(" "rect" ")");
do { *((volatile int*)__null) = 7619; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7620 } else {
7621 if (alreadyInvalid) {
7622 return;
7623 }
7624 rect = new nsRect();
7625 AddProperty(InvalidationRect(), rect);
7626 AddStateBits(NS_FRAME_HAS_INVALID_RECT);
7627 }
7628
7629 *rect = rect->Union(aRect);
7630}
7631
7632/*static*/
7633uint8_t nsIFrame::sLayerIsPrerenderedDataKey;
7634
7635bool nsIFrame::IsInvalid(nsRect& aRect) {
7636 if (!HasAnyStateBits(NS_FRAME_NEEDS_PAINT)) {
7637 return false;
7638 }
7639
7640 if (HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) {
7641 nsRect* rect = GetProperty(InvalidationRect());
7642 NS_ASSERTION(do { if (!(rect)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Must have an invalid rect if NS_FRAME_HAS_INVALID_RECT is set!"
, "rect", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7643); MOZ_PretendNoReturn(); } } while (0)
7643 rect, "Must have an invalid rect if NS_FRAME_HAS_INVALID_RECT is set!")do { if (!(rect)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Must have an invalid rect if NS_FRAME_HAS_INVALID_RECT is set!"
, "rect", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7643); MOZ_PretendNoReturn(); } } while (0)
;
7644 aRect = *rect;
7645 } else {
7646 aRect.SetEmpty();
7647 }
7648 return true;
7649}
7650
7651void nsIFrame::SchedulePaint(PaintType aType, bool aFrameChanged) {
7652 if (PresShell()->IsPaintingSuppressed()) {
7653 // We can't have any display items yet, and when we unsuppress we will
7654 // invalidate the root frame.
7655 return;
7656 }
7657 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this);
7658 InvalidateRenderingObservers(displayRoot, this, aFrameChanged);
7659 SchedulePaintInternal(displayRoot, this, aType);
7660}
7661
7662void nsIFrame::SchedulePaintWithoutInvalidatingObservers(PaintType aType) {
7663 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this);
7664 SchedulePaintInternal(displayRoot, this, aType);
7665}
7666
7667void nsIFrame::InvalidateLayer(DisplayItemType aDisplayItemKey,
7668 const nsIntRect* aDamageRect,
7669 const nsRect* aFrameDamageRect,
7670 uint32_t aFlags /* = 0 */) {
7671 NS_ASSERTION(aDisplayItemKey > DisplayItemType::TYPE_ZERO, "Need a key")do { if (!(aDisplayItemKey > DisplayItemType::TYPE_ZERO)) {
NS_DebugBreak(NS_DEBUG_ASSERTION, "Need a key", "aDisplayItemKey > DisplayItemType::TYPE_ZERO"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7671); MOZ_PretendNoReturn(); } } while (0)
;
7672
7673 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this);
7674 InvalidateRenderingObservers(displayRoot, this, false);
7675
7676 // Check if frame supports WebRender's async update
7677 if ((aFlags & UPDATE_IS_ASYNC) &&
7678 WebRenderUserData::SupportsAsyncUpdate(this)) {
7679 // WebRender does not use layer, then return nullptr.
7680 return;
7681 }
7682
7683 if (aFrameDamageRect && aFrameDamageRect->IsEmpty()) {
7684 return;
7685 }
7686
7687 // In the bug 930056, dialer app startup but not shown on the
7688 // screen because sometimes we don't have any retainned data
7689 // for remote type displayitem and thus Repaint event is not
7690 // triggered. So, always invalidate in this case.
7691 DisplayItemType displayItemKey = aDisplayItemKey;
7692 if (aDisplayItemKey == DisplayItemType::TYPE_REMOTE) {
7693 displayItemKey = DisplayItemType::TYPE_ZERO;
7694 }
7695
7696 if (aFrameDamageRect) {
7697 InvalidateFrameWithRect(*aFrameDamageRect,
7698 static_cast<uint32_t>(displayItemKey));
7699 } else {
7700 InvalidateFrame(static_cast<uint32_t>(displayItemKey));
7701 }
7702}
7703
7704static nsRect ComputeEffectsRect(nsIFrame* aFrame, const nsRect& aOverflowRect,
7705 const nsSize& aNewSize) {
7706 nsRect r = aOverflowRect;
7707
7708 if (aFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
7709 // For SVG frames, we only need to account for filters.
7710 // TODO: We could also take account of clipPath and mask to reduce the
7711 // ink overflow, but that's not essential.
7712 if (aFrame->StyleEffects()->HasFilters()) {
7713 SetOrUpdateRectValuedProperty(aFrame, nsIFrame::PreEffectsBBoxProperty(),
7714 r);
7715 r = SVGUtils::GetPostFilterInkOverflowRect(aFrame, aOverflowRect);
7716 }
7717 return r;
7718 }
7719
7720 // box-shadow
7721 r.UnionRect(r, nsLayoutUtils::GetBoxShadowRectForFrame(aFrame, aNewSize));
7722
7723 // border-image-outset.
7724 // We need to include border-image-outset because it can cause the
7725 // border image to be drawn beyond the border box.
7726
7727 // (1) It's important we not check whether there's a border-image
7728 // since the style hint for a change in border image doesn't cause
7729 // reflow, and that's probably more important than optimizing the
7730 // overflow areas for the silly case of border-image-outset without
7731 // border-image
7732 // (2) It's important that we not check whether the border-image
7733 // is actually loaded, since that would require us to reflow when
7734 // the image loads.
7735 const nsStyleBorder* styleBorder = aFrame->StyleBorder();
7736 nsMargin outsetMargin = styleBorder->GetImageOutset();
7737
7738 if (outsetMargin != nsMargin(0, 0, 0, 0)) {
7739 nsRect outsetRect(nsPoint(0, 0), aNewSize);
7740 outsetRect.Inflate(outsetMargin);
7741 r.UnionRect(r, outsetRect);
7742 }
7743
7744 // Note that we don't remove the outlineInnerRect if a frame loses outline
7745 // style. That would require an extra property lookup for every frame,
7746 // or a new frame state bit to track whether a property had been stored,
7747 // or something like that. It's not worth doing that here. At most it's
7748 // only one heap-allocated rect per frame and it will be cleaned up when
7749 // the frame dies.
7750
7751 if (SVGIntegrationUtils::UsingOverflowAffectingEffects(aFrame)) {
7752 SetOrUpdateRectValuedProperty(aFrame, nsIFrame::PreEffectsBBoxProperty(),
7753 r);
7754 r = SVGIntegrationUtils::ComputePostEffectsInkOverflowRect(aFrame, r);
7755 }
7756
7757 return r;
7758}
7759
7760void nsIFrame::SetPosition(const nsPoint& aPt) {
7761 if (mRect.TopLeft() == aPt) {
7762 return;
7763 }
7764 mRect.MoveTo(aPt);
7765 MarkNeedsDisplayItemRebuild();
7766}
7767
7768void nsIFrame::MovePositionBy(const nsPoint& aTranslation) {
7769 nsPoint position = GetNormalPosition() + aTranslation;
7770
7771 const nsMargin* computedOffsets = nullptr;
7772 if (IsRelativelyOrStickyPositioned()) {
7773 computedOffsets = GetProperty(nsIFrame::ComputedOffsetProperty());
7774 }
7775 ReflowInput::ApplyRelativePositioning(
7776 this, computedOffsets ? *computedOffsets : nsMargin(), &position);
7777 SetPosition(position);
7778}
7779
7780nsRect nsIFrame::GetNormalRect() const {
7781 // It might be faster to first check
7782 // StyleDisplay()->IsRelativelyPositionedStyle().
7783 bool hasProperty;
7784 nsPoint normalPosition = GetProperty(NormalPositionProperty(), &hasProperty);
7785 if (hasProperty) {
7786 return nsRect(normalPosition, GetSize());
7787 }
7788 return GetRect();
7789}
7790
7791nsRect nsIFrame::GetBoundingClientRect() {
7792 return nsLayoutUtils::GetAllInFlowRectsUnion(
7793 this, nsLayoutUtils::GetContainingBlockForClientRect(this),
7794 nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
7795}
7796
7797nsPoint nsIFrame::GetPositionIgnoringScrolling() const {
7798 return GetParent() ? GetParent()->GetPositionOfChildIgnoringScrolling(this)
7799 : GetPosition();
7800}
7801
7802nsRect nsIFrame::GetOverflowRect(OverflowType aType) const {
7803 // Note that in some cases the overflow area might not have been
7804 // updated (yet) to reflect any outline set on the frame or the area
7805 // of child frames. That's OK because any reflow that updates these
7806 // areas will invalidate the appropriate area, so any (mis)uses of
7807 // this method will be fixed up.
7808
7809 if (mOverflow.mType == OverflowStorageType::Large) {
7810 // there is an overflow rect, and it's not stored as deltas but as
7811 // a separately-allocated rect
7812 return GetOverflowAreasProperty()->Overflow(aType);
7813 }
7814
7815 if (aType == OverflowType::Ink &&
7816 mOverflow.mType != OverflowStorageType::None) {
7817 return InkOverflowFromDeltas();
7818 }
7819
7820 return GetRectRelativeToSelf();
7821}
7822
7823OverflowAreas nsIFrame::GetOverflowAreas() const {
7824 if (mOverflow.mType == OverflowStorageType::Large) {
7825 // there is an overflow rect, and it's not stored as deltas but as
7826 // a separately-allocated rect
7827 return *GetOverflowAreasProperty();
7828 }
7829
7830 return OverflowAreas(InkOverflowFromDeltas(),
7831 nsRect(nsPoint(0, 0), GetSize()));
7832}
7833
7834OverflowAreas nsIFrame::GetOverflowAreasRelativeToSelf() const {
7835 if (IsTransformed()) {
7836 if (OverflowAreas* preTransformOverflows =
7837 GetProperty(PreTransformOverflowAreasProperty())) {
7838 return *preTransformOverflows;
7839 }
7840 }
7841 return GetOverflowAreas();
7842}
7843
7844OverflowAreas nsIFrame::GetOverflowAreasRelativeToParent() const {
7845 return GetOverflowAreas() + GetPosition();
7846}
7847
7848OverflowAreas nsIFrame::GetActualAndNormalOverflowAreasRelativeToParent()
7849 const {
7850 if (MOZ_LIKELY(!IsRelativelyOrStickyPositioned())(__builtin_expect(!!(!IsRelativelyOrStickyPositioned()), 1))) {
7851 return GetOverflowAreasRelativeToParent();
7852 }
7853
7854 const OverflowAreas overflows = GetOverflowAreas();
7855 OverflowAreas actualAndNormalOverflows = overflows + GetPosition();
7856 actualAndNormalOverflows.UnionWith(overflows + GetNormalPosition());
7857 return actualAndNormalOverflows;
7858}
7859
7860nsRect nsIFrame::ScrollableOverflowRectRelativeToParent() const {
7861 return ScrollableOverflowRect() + GetPosition();
7862}
7863
7864nsRect nsIFrame::InkOverflowRectRelativeToParent() const {
7865 return InkOverflowRect() + GetPosition();
7866}
7867
7868nsRect nsIFrame::ScrollableOverflowRectRelativeToSelf() const {
7869 if (IsTransformed()) {
7870 if (OverflowAreas* preTransformOverflows =
7871 GetProperty(PreTransformOverflowAreasProperty())) {
7872 return preTransformOverflows->ScrollableOverflow();
7873 }
7874 }
7875 return ScrollableOverflowRect();
7876}
7877
7878nsRect nsIFrame::InkOverflowRectRelativeToSelf() const {
7879 if (IsTransformed()) {
7880 if (OverflowAreas* preTransformOverflows =
7881 GetProperty(PreTransformOverflowAreasProperty())) {
7882 return preTransformOverflows->InkOverflow();
7883 }
7884 }
7885 return InkOverflowRect();
7886}
7887
7888nsRect nsIFrame::PreEffectsInkOverflowRect() const {
7889 nsRect* r = GetProperty(nsIFrame::PreEffectsBBoxProperty());
7890 return r ? *r : InkOverflowRectRelativeToSelf();
7891}
7892
7893bool nsIFrame::UpdateOverflow() {
7894 MOZ_ASSERT(FrameMaintainsOverflow(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(FrameMaintainsOverflow())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(FrameMaintainsOverflow()))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("FrameMaintainsOverflow()"
" (" "Non-display SVG do not maintain ink overflow rects" ")"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7895); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Non-display SVG do not maintain ink overflow rects" ")"
); do { *((volatile int*)__null) = 7895; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
7895 "Non-display SVG do not maintain ink overflow rects")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(FrameMaintainsOverflow())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(FrameMaintainsOverflow()))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("FrameMaintainsOverflow()"
" (" "Non-display SVG do not maintain ink overflow rects" ")"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7895); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Non-display SVG do not maintain ink overflow rects" ")"
); do { *((volatile int*)__null) = 7895; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7896
7897 nsRect rect(nsPoint(0, 0), GetSize());
7898 OverflowAreas overflowAreas(rect, rect);
7899
7900 if (!ComputeCustomOverflow(overflowAreas)) {
7901 // If updating overflow wasn't supported by this frame, then it should
7902 // have scheduled any necessary reflows. We can return false to say nothing
7903 // changed, and wait for reflow to correct it.
7904 return false;
7905 }
7906
7907 UnionChildOverflow(overflowAreas);
7908
7909 if (FinishAndStoreOverflow(overflowAreas, GetSize())) {
7910 if (nsView* view = GetView()) {
7911 // Make sure the frame's view is properly sized.
7912 nsViewManager* vm = view->GetViewManager();
7913 vm->ResizeView(view, overflowAreas.InkOverflow(), true);
7914 }
7915
7916 return true;
7917 }
7918
7919 // Frames that combine their 3d transform with their ancestors
7920 // only compute a pre-transform overflow rect, and then contribute
7921 // to the normal overflow rect of the preserve-3d root. Always return
7922 // true here so that we propagate changes up to the root for final
7923 // calculation.
7924 return Combines3DTransformWithAncestors();
7925}
7926
7927/* virtual */
7928bool nsIFrame::ComputeCustomOverflow(OverflowAreas& aOverflowAreas) {
7929 return true;
7930}
7931
7932bool nsIFrame::DoesClipChildrenInBothAxes() const {
7933 nsIScrollableFrame* sf = do_QueryFrame(this);
7934 const nsStyleDisplay* display = StyleDisplay();
7935 return sf || (display->mOverflowX == StyleOverflow::Clip &&
7936 display->mOverflowY == StyleOverflow::Clip);
7937}
7938
7939/* virtual */
7940void nsIFrame::UnionChildOverflow(OverflowAreas& aOverflowAreas) {
7941 if (!DoesClipChildrenInBothAxes()) {
7942 nsLayoutUtils::UnionChildOverflow(this, aOverflowAreas);
7943 }
7944}
7945
7946// Return true if this form control element's preferred size property (but not
7947// percentage max size property) contains a percentage value that should be
7948// resolved against zero when calculating its min-content contribution in the
7949// corresponding axis.
7950//
7951// For proper replaced elements, the percentage value in both their max size
7952// property or preferred size property should be resolved against zero. This is
7953// handled in IsPercentageResolvedAgainstZero().
7954inline static bool FormControlShrinksForPercentSize(const nsIFrame* aFrame) {
7955 if (!aFrame->IsReplaced()) {
7956 // Quick test to reject most frames.
7957 return false;
7958 }
7959
7960 LayoutFrameType fType = aFrame->Type();
7961 if (fType == LayoutFrameType::Meter || fType == LayoutFrameType::Progress ||
7962 fType == LayoutFrameType::Range) {
7963 // progress, meter and range do have this shrinking behavior
7964 // FIXME: Maybe these should be nsIFormControlFrame?
7965 return true;
7966 }
7967
7968 if (!static_cast<nsIFormControlFrame*>(do_QueryFrame(aFrame))) {
7969 // Not a form control. This includes fieldsets, which do not
7970 // shrink.
7971 return false;
7972 }
7973
7974 if (fType == LayoutFrameType::GfxButtonControl ||
7975 fType == LayoutFrameType::HTMLButtonControl) {
7976 // Buttons don't have this shrinking behavior. (Note that color
7977 // inputs do, even though they inherit from button, so we can't use
7978 // do_QueryFrame here.)
7979 return false;
7980 }
7981
7982 return true;
7983}
7984
7985bool nsIFrame::IsPercentageResolvedAgainstZero(
7986 const StyleSize& aStyleSize, const StyleMaxSize& aStyleMaxSize) const {
7987 const bool sizeHasPercent = aStyleSize.HasPercent();
7988 return ((sizeHasPercent || aStyleMaxSize.HasPercent()) &&
7989 HasReplacedSizing()) ||
7990 (sizeHasPercent && FormControlShrinksForPercentSize(this));
7991}
7992
7993// Summary of the Cyclic-Percentage Intrinsic Size Contribution Rules:
7994//
7995// Element Type | Replaced | Non-replaced
7996// Contribution Type | min-content max-content | min-content max-content
7997// ---------------------------------------------------------------------------
7998// min size | zero zero | zero zero
7999// max & preferred size | zero initial | initial initial
8000//
8001// https://drafts.csswg.org/css-sizing-3/#cyclic-percentage-contribution
8002bool nsIFrame::IsPercentageResolvedAgainstZero(const LengthPercentage& aSize,
8003 SizeProperty aProperty) const {
8004 // Early return to avoid calling the virtual function, IsFrameOfType().
8005 if (aProperty == SizeProperty::MinSize) {
8006 return true;
8007 }
8008
8009 const bool hasPercentOnReplaced = aSize.HasPercent() && HasReplacedSizing();
8010 if (aProperty == SizeProperty::MaxSize) {
8011 return hasPercentOnReplaced;
8012 }
8013
8014 MOZ_ASSERT(aProperty == SizeProperty::Size)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aProperty == SizeProperty::Size)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aProperty == SizeProperty::Size
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"aProperty == SizeProperty::Size", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8014); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aProperty == SizeProperty::Size"
")"); do { *((volatile int*)__null) = 8014; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8015 return hasPercentOnReplaced ||
8016 (aSize.HasPercent() && FormControlShrinksForPercentSize(this));
8017}
8018
8019bool nsIFrame::IsBlockWrapper() const {
8020 auto pseudoType = Style()->GetPseudoType();
8021 return pseudoType == PseudoStyleType::mozBlockInsideInlineWrapper ||
8022 pseudoType == PseudoStyleType::buttonContent ||
8023 pseudoType == PseudoStyleType::cellContent ||
8024 pseudoType == PseudoStyleType::columnSpanWrapper;
8025}
8026
8027bool nsIFrame::IsBlockFrameOrSubclass() const {
8028 const nsBlockFrame* thisAsBlock = do_QueryFrame(this);
8029 return !!thisAsBlock;
8030}
8031
8032bool nsIFrame::IsImageFrameOrSubclass() const {
8033 const nsImageFrame* asImage = do_QueryFrame(this);
8034 return !!asImage;
8035}
8036
8037bool nsIFrame::IsSubgrid() const {
8038 return IsGridContainerFrame() &&
8039 static_cast<const nsGridContainerFrame*>(this)->IsSubgrid();
8040}
8041
8042static nsIFrame* GetNearestBlockContainer(nsIFrame* frame) {
8043 while (!frame->IsBlockContainer()) {
8044 frame = frame->GetParent();
8045 NS_ASSERTION(do { if (!(frame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "How come we got to the root frame without seeing a containing block?"
, "frame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8047); MOZ_PretendNoReturn(); } } while (0)
8046 frame,do { if (!(frame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "How come we got to the root frame without seeing a containing block?"
, "frame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8047); MOZ_PretendNoReturn(); } } while (0)
8047 "How come we got to the root frame without seeing a containing block?")do { if (!(frame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "How come we got to the root frame without seeing a containing block?"
, "frame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8047); MOZ_PretendNoReturn(); } } while (0)
;
8048 }
8049 return frame;
8050}
8051
8052bool nsIFrame::IsBlockContainer() const {
8053 // The block wrappers we use to wrap blocks inside inlines aren't
8054 // described in the CSS spec. We need to make them not be containing
8055 // blocks.
8056 // Since the parent of such a block is either a normal block or
8057 // another such pseudo, this shouldn't cause anything bad to happen.
8058 // Also the anonymous blocks inside table cells are not containing blocks.
8059 //
8060 // If we ever start skipping table row groups from being containing blocks,
8061 // you need to remove the StickyScrollContainer hack referencing bug 1421660.
8062 return !IsLineParticipant() && !IsBlockWrapper() && !IsSubgrid() &&
8063 // Table rows are not containing blocks either
8064 !IsTableRowFrame();
8065}
8066
8067nsIFrame* nsIFrame::GetContainingBlock(
8068 uint32_t aFlags, const nsStyleDisplay* aStyleDisplay) const {
8069 MOZ_ASSERT(aStyleDisplay == StyleDisplay())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aStyleDisplay == StyleDisplay())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aStyleDisplay == StyleDisplay
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aStyleDisplay == StyleDisplay()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8069); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStyleDisplay == StyleDisplay()"
")"); do { *((volatile int*)__null) = 8069; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8070
8071 // Keep this in sync with MightBeContainingBlockFor in ReflowInput.cpp.
8072
8073 if (!GetParent()) {
8074 return nullptr;
8075 }
8076 // MathML frames might have absolute positioning style, but they would
8077 // still be in-flow. So we have to check to make sure that the frame
8078 // is really out-of-flow too.
8079 nsIFrame* f;
8080 if (IsAbsolutelyPositioned(aStyleDisplay)) {
8081 f = GetParent(); // the parent is always the containing block
8082 } else {
8083 f = GetNearestBlockContainer(GetParent());
8084 }
8085
8086 if (aFlags & SKIP_SCROLLED_FRAME && f &&
8087 f->Style()->GetPseudoType() == PseudoStyleType::scrolledContent) {
8088 f = f->GetParent();
8089 }
8090 return f;
8091}
8092
8093#ifdef DEBUG_FRAME_DUMP1
8094
8095Maybe<uint32_t> nsIFrame::ContentIndexInContainer(const nsIFrame* aFrame) {
8096 if (nsIContent* content = aFrame->GetContent()) {
8097 return content->ComputeIndexInParentContent();
8098 }
8099 return Nothing();
8100}
8101
8102nsAutoCString nsIFrame::ListTag() const {
8103 nsAutoString tmp;
8104 GetFrameName(tmp);
8105
8106 nsAutoCString tag;
8107 tag += NS_ConvertUTF16toUTF8(tmp);
8108 tag += nsPrintfCString("@%p", static_cast<const void*>(this));
8109 return tag;
8110}
8111
8112std::string nsIFrame::ConvertToString(const LogicalRect& aRect,
8113 const WritingMode aWM, ListFlags aFlags) {
8114 if (aFlags.contains(ListFlag::DisplayInCSSPixels)) {
8115 // Abuse CSSRect to store all LogicalRect's dimensions in CSS pixels.
8116 return ToString(mozilla::CSSRect(CSSPixel::FromAppUnits(aRect.IStart(aWM)),
8117 CSSPixel::FromAppUnits(aRect.BStart(aWM)),
8118 CSSPixel::FromAppUnits(aRect.ISize(aWM)),
8119 CSSPixel::FromAppUnits(aRect.BSize(aWM))));
8120 }
8121 return ToString(aRect);
8122}
8123
8124std::string nsIFrame::ConvertToString(const LogicalSize& aSize,
8125 const WritingMode aWM, ListFlags aFlags) {
8126 if (aFlags.contains(ListFlag::DisplayInCSSPixels)) {
8127 // Abuse CSSSize to store all LogicalSize's dimensions in CSS pixels.
8128 return ToString(CSSSize(CSSPixel::FromAppUnits(aSize.ISize(aWM)),
8129 CSSPixel::FromAppUnits(aSize.BSize(aWM))));
8130 }
8131 return ToString(aSize);
8132}
8133
8134// Debugging
8135void nsIFrame::ListGeneric(nsACString& aTo, const char* aPrefix,
8136 ListFlags aFlags) const {
8137 aTo += aPrefix;
8138 aTo += ListTag();
8139 if (HasView()) {
8140 aTo += nsPrintfCString(" [view=%p]", static_cast<void*>(GetView()));
8141 }
8142 if (GetParent()) {
8143 aTo += nsPrintfCString(" parent=%p", static_cast<void*>(GetParent()));
8144 }
8145 if (GetNextSibling()) {
8146 aTo += nsPrintfCString(" next=%p", static_cast<void*>(GetNextSibling()));
8147 }
8148 if (GetPrevContinuation()) {
8149 bool fluid = GetPrevInFlow() == GetPrevContinuation();
8150 aTo += nsPrintfCString(" prev-%s=%p", fluid ? "in-flow" : "continuation",
8151 static_cast<void*>(GetPrevContinuation()));
8152 }
8153 if (GetNextContinuation()) {
8154 bool fluid = GetNextInFlow() == GetNextContinuation();
8155 aTo += nsPrintfCString(" next-%s=%p", fluid ? "in-flow" : "continuation",
8156 static_cast<void*>(GetNextContinuation()));
8157 }
8158 if (const nsAtom* const autoPageValue =
8159 GetProperty(AutoPageValueProperty())) {
8160 aTo += " AutoPage=";
8161 aTo += nsAtomCString(autoPageValue);
8162 }
8163 if (const nsIFrame::PageValues* const pageValues =
8164 GetProperty(PageValuesProperty())) {
8165 aTo += " PageValues={";
8166 if (pageValues->mStartPageValue) {
8167 aTo += nsAtomCString(pageValues->mStartPageValue);
8168 } else {
8169 aTo += "<null>";
8170 }
8171 aTo += ", ";
8172 if (pageValues->mEndPageValue) {
8173 aTo += nsAtomCString(pageValues->mEndPageValue);
8174 } else {
8175 aTo += "<null>";
8176 }
8177 aTo += "}";
8178 }
8179 void* IBsibling = GetProperty(IBSplitSibling());
8180 if (IBsibling) {
8181 aTo += nsPrintfCString(" IBSplitSibling=%p", IBsibling);
8182 }
8183 void* IBprevsibling = GetProperty(IBSplitPrevSibling());
8184 if (IBprevsibling) {
8185 aTo += nsPrintfCString(" IBSplitPrevSibling=%p", IBprevsibling);
8186 }
8187 if (nsLayoutUtils::FontSizeInflationEnabled(PresContext())) {
8188 if (HasAnyStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT)) {
8189 aTo += nsPrintfCString(" FFR");
8190 if (nsFontInflationData* data =
8191 nsFontInflationData::FindFontInflationDataFor(this)) {
8192 aTo += nsPrintfCString(
8193 ",enabled=%s,UIS=%s", data->InflationEnabled() ? "yes" : "no",
8194 ConvertToString(data->UsableISize(), aFlags).c_str());
8195 }
8196 }
8197 if (HasAnyStateBits(NS_FRAME_FONT_INFLATION_CONTAINER)) {
8198 aTo += nsPrintfCString(" FIC");
8199 }
8200 aTo += nsPrintfCString(" FI=%f", nsLayoutUtils::FontSizeInflationFor(this));
8201 }
8202 aTo += nsPrintfCString(" %s", ConvertToString(mRect, aFlags).c_str());
8203
8204 mozilla::WritingMode wm = GetWritingMode();
8205 if (wm.IsVertical() || wm.IsBidiRTL()) {
8206 aTo +=
8207 nsPrintfCString(" wm=%s logical-size=(%s)", ToString(wm).c_str(),
8208 ConvertToString(GetLogicalSize(), wm, aFlags).c_str());
8209 }
8210
8211 nsIFrame* parent = GetParent();
8212 if (parent) {
8213 WritingMode pWM = parent->GetWritingMode();
8214 if (pWM.IsVertical() || pWM.IsBidiRTL()) {
8215 nsSize containerSize = parent->mRect.Size();
8216 LogicalRect lr(pWM, mRect, containerSize);
8217 aTo += nsPrintfCString(" parent-wm=%s cs=(%s) logical-rect=%s",
8218 ToString(pWM).c_str(),
8219 ConvertToString(containerSize, aFlags).c_str(),
8220 ConvertToString(lr, pWM, aFlags).c_str());
8221 }
8222 }
8223 nsIFrame* f = const_cast<nsIFrame*>(this);
8224 if (f->HasOverflowAreas()) {
8225 nsRect io = f->InkOverflowRect();
8226 if (!io.IsEqualEdges(mRect)) {
8227 aTo += nsPrintfCString(" ink-overflow=%s",
8228 ConvertToString(io, aFlags).c_str());
8229 }
8230 nsRect so = f->ScrollableOverflowRect();
8231 if (!so.IsEqualEdges(mRect)) {
8232 aTo += nsPrintfCString(" scr-overflow=%s",
8233 ConvertToString(so, aFlags).c_str());
8234 }
8235 }
8236 if (OverflowAreas* preTransformOverflows =
8237 f->GetProperty(PreTransformOverflowAreasProperty())) {
8238 nsRect io = preTransformOverflows->InkOverflow();
8239 if (!io.IsEqualEdges(mRect) &&
8240 (!f->HasOverflowAreas() || !io.IsEqualEdges(f->InkOverflowRect()))) {
8241 aTo += nsPrintfCString(" pre-transform-ink-overflow=%s",
8242 ConvertToString(io, aFlags).c_str());
8243 }
8244 nsRect so = preTransformOverflows->ScrollableOverflow();
8245 if (!so.IsEqualEdges(mRect) &&
8246 (!f->HasOverflowAreas() ||
8247 !so.IsEqualEdges(f->ScrollableOverflowRect()))) {
8248 aTo += nsPrintfCString(" pre-transform-scr-overflow=%s",
8249 ConvertToString(so, aFlags).c_str());
8250 }
8251 }
8252 bool hasNormalPosition;
8253 nsPoint normalPosition = GetNormalPosition(&hasNormalPosition);
8254 if (hasNormalPosition) {
8255 aTo += nsPrintfCString(" normal-position=%s",
8256 ConvertToString(normalPosition, aFlags).c_str());
8257 }
8258 if (HasProperty(BidiDataProperty())) {
8259 FrameBidiData bidi = GetBidiData();
8260 aTo += nsPrintfCString(" bidi(%d,%d,%d)", bidi.baseLevel.Value(),
8261 bidi.embeddingLevel.Value(),
8262 bidi.precedingControl.Value());
8263 }
8264 if (IsTransformed()) {
8265 aTo += nsPrintfCString(" transformed");
8266 }
8267 if (ChildrenHavePerspective()) {
8268 aTo += nsPrintfCString(" perspective");
8269 }
8270 if (Extend3DContext()) {
8271 aTo += nsPrintfCString(" extend-3d");
8272 }
8273 if (Combines3DTransformWithAncestors()) {
8274 aTo += nsPrintfCString(" combines-3d-transform-with-ancestors");
8275 }
8276 if (mContent) {
8277 aTo += nsPrintfCString(" [content=%p]", static_cast<void*>(mContent));
8278 }
8279 aTo += nsPrintfCString(" [cs=%p", static_cast<void*>(mComputedStyle));
8280 if (mComputedStyle) {
8281 auto pseudoType = mComputedStyle->GetPseudoType();
8282 aTo += ToString(pseudoType).c_str();
8283 }
8284 aTo += "]";
8285
8286 auto contentVisibility = StyleDisplay()->ContentVisibility(*this);
8287 if (contentVisibility != StyleContentVisibility::Visible) {
8288 aTo += nsPrintfCString(" [content-visibility=");
8289 if (contentVisibility == StyleContentVisibility::Auto) {
8290 aTo += "auto, "_ns;
8291 } else if (contentVisibility == StyleContentVisibility::Hidden) {
8292 aTo += "hiden, "_ns;
8293 }
8294
8295 if (HidesContent()) {
8296 aTo += "HidesContent=hidden"_ns;
8297 } else {
8298 aTo += "HidesContent=visibile"_ns;
8299 }
8300 aTo += "]";
8301 }
8302
8303 if (IsFrameModified()) {
8304 aTo += nsPrintfCString(" modified");
8305 }
8306
8307 if (HasModifiedDescendants()) {
8308 aTo += nsPrintfCString(" has-modified-descendants");
8309 }
8310}
8311
8312void nsIFrame::List(FILE* out, const char* aPrefix, ListFlags aFlags) const {
8313 nsCString str;
8314 ListGeneric(str, aPrefix, aFlags);
8315 fprintf_stderr(out, "%s\n", str.get());
8316}
8317
8318void nsIFrame::ListTextRuns(FILE* out) const {
8319 nsTHashSet<const void*> seen;
8320 ListTextRuns(out, seen);
8321}
8322
8323void nsIFrame::ListTextRuns(FILE* out, nsTHashSet<const void*>& aSeen) const {
8324 for (const auto& childList : ChildLists()) {
8325 for (const nsIFrame* kid : childList.mList) {
8326 kid->ListTextRuns(out, aSeen);
8327 }
8328 }
8329}
8330
8331void nsIFrame::ListMatchedRules(FILE* out, const char* aPrefix) const {
8332 nsTArray<const StyleLockedStyleRule*> rawRuleList;
8333 Servo_ComputedValues_GetStyleRuleList(mComputedStyle, &rawRuleList);
8334 for (const StyleLockedStyleRule* rawRule : rawRuleList) {
8335 nsAutoCString ruleText;
8336 Servo_StyleRule_GetCssText(rawRule, &ruleText);
8337 fprintf_stderr(out, "%s%s\n", aPrefix, ruleText.get());
8338 }
8339}
8340
8341void nsIFrame::ListWithMatchedRules(FILE* out, const char* aPrefix) const {
8342 fprintf_stderr(out, "%s%s\n", aPrefix, ListTag().get());
8343
8344 nsCString rulePrefix;
8345 rulePrefix += aPrefix;
8346 rulePrefix += " ";
8347 ListMatchedRules(out, rulePrefix.get());
8348}
8349
8350nsresult nsIFrame::GetFrameName(nsAString& aResult) const {
8351 return MakeFrameName(u"Frame"_ns, aResult);
8352}
8353
8354nsresult nsIFrame::MakeFrameName(const nsAString& aType,
8355 nsAString& aResult) const {
8356 aResult = aType;
8357 if (mContent && !mContent->IsText()) {
8358 nsAutoString buf;
8359 mContent->NodeInfo()->NameAtom()->ToString(buf);
8360 if (nsAtom* id = mContent->GetID()) {
8361 buf.AppendLiteral(" id=");
8362 buf.Append(nsDependentAtomString(id));
8363 }
8364 if (IsSubDocumentFrame()) {
8365 nsAutoString src;
8366 mContent->AsElement()->GetAttr(nsGkAtoms::src, src);
8367 buf.AppendLiteral(" src=");
8368 buf.Append(src);
8369 }
8370 aResult.Append('(');
8371 aResult.Append(buf);
8372 aResult.Append(')');
8373 }
8374 aResult.Append('(');
8375 Maybe<uint32_t> index = ContentIndexInContainer(this);
8376 if (index.isSome()) {
8377 aResult.AppendInt(*index);
8378 } else {
8379 aResult.AppendInt(-1);
8380 }
8381 aResult.Append(')');
8382 return NS_OK;
8383}
8384
8385void nsIFrame::DumpFrameTree() const {
8386 PresShell()->GetRootFrame()->List(stderrstderr);
8387}
8388
8389void nsIFrame::DumpFrameTreeInCSSPixels() const {
8390 PresShell()->GetRootFrame()->List(stderrstderr, "", ListFlag::DisplayInCSSPixels);
8391}
8392
8393void nsIFrame::DumpFrameTreeLimited() const { List(stderrstderr); }
8394void nsIFrame::DumpFrameTreeLimitedInCSSPixels() const {
8395 List(stderrstderr, "", ListFlag::DisplayInCSSPixels);
8396}
8397
8398#endif
8399
8400bool nsIFrame::IsVisibleForPainting() const {
8401 return StyleVisibility()->IsVisible();
8402}
8403
8404bool nsIFrame::IsVisibleOrCollapsedForPainting() const {
8405 return StyleVisibility()->IsVisibleOrCollapsed();
8406}
8407
8408/* virtual */
8409bool nsIFrame::IsEmpty() {
8410 return IsHiddenByContentVisibilityOfInFlowParentForLayout();
8411}
8412
8413bool nsIFrame::CachedIsEmpty() {
8414 MOZ_ASSERT(!HasAnyStateBits(NS_FRAME_IS_DIRTY) ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout
())>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout()"
" (" "Must only be called on reflowed lines or those hidden by "
"content-visibility." ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8417); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout()"
") (" "Must only be called on reflowed lines or those hidden by "
"content-visibility." ")"); do { *((volatile int*)__null) = 8417
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
8415 IsHiddenByContentVisibilityOfInFlowParentForLayout(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout
())>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout()"
" (" "Must only be called on reflowed lines or those hidden by "
"content-visibility." ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8417); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout()"
") (" "Must only be called on reflowed lines or those hidden by "
"content-visibility." ")"); do { *((volatile int*)__null) = 8417
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
8416 "Must only be called on reflowed lines or those hidden by "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout
())>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout()"
" (" "Must only be called on reflowed lines or those hidden by "
"content-visibility." ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8417); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout()"
") (" "Must only be called on reflowed lines or those hidden by "
"content-visibility." ")"); do { *((volatile int*)__null) = 8417
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
8417 "content-visibility.")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout
())>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout()"
" (" "Must only be called on reflowed lines or those hidden by "
"content-visibility." ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8417); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_IS_DIRTY) || IsHiddenByContentVisibilityOfInFlowParentForLayout()"
") (" "Must only be called on reflowed lines or those hidden by "
"content-visibility." ")"); do { *((volatile int*)__null) = 8417
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
8418 return IsEmpty();
8419}
8420
8421/* virtual */
8422bool nsIFrame::IsSelfEmpty() {
8423 return IsHiddenByContentVisibilityOfInFlowParentForLayout();
8424}
8425
8426nsresult nsIFrame::GetSelectionController(nsPresContext* aPresContext,
8427 nsISelectionController** aSelCon) {
8428 if (!aPresContext || !aSelCon) return NS_ERROR_INVALID_ARG;
8429
8430 nsIFrame* frame = this;
8431 while (frame && frame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)) {
8432 nsITextControlFrame* tcf = do_QueryFrame(frame);
8433 if (tcf) {
8434 return tcf->GetOwnedSelectionController(aSelCon);
8435 }
8436 frame = frame->GetParent();
8437 }
8438
8439 *aSelCon = do_AddRef(aPresContext->PresShell()).take();
8440 return NS_OK;
8441}
8442
8443already_AddRefed<nsFrameSelection> nsIFrame::GetFrameSelection() {
8444 RefPtr<nsFrameSelection> fs =
8445 const_cast<nsFrameSelection*>(GetConstFrameSelection());
8446 return fs.forget();
8447}
8448
8449const nsFrameSelection* nsIFrame::GetConstFrameSelection() const {
8450 nsIFrame* frame = const_cast<nsIFrame*>(this);
8451 while (frame && frame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)) {
8452 nsITextControlFrame* tcf = do_QueryFrame(frame);
8453 if (tcf) {
8454 return tcf->GetOwnedFrameSelection();
8455 }
8456 frame = frame->GetParent();
8457 }
8458
8459 return PresShell()->ConstFrameSelection();
8460}
8461
8462bool nsIFrame::IsFrameSelected() const {
8463 NS_ASSERTION(!GetContent() || GetContent()->IsMaybeSelected(),do { if (!(!GetContent() || GetContent()->IsMaybeSelected(
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "use the public IsSelected() instead"
, "!GetContent() || GetContent()->IsMaybeSelected()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8464); MOZ_PretendNoReturn(); } } while (0)
8464 "use the public IsSelected() instead")do { if (!(!GetContent() || GetContent()->IsMaybeSelected(
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "use the public IsSelected() instead"
, "!GetContent() || GetContent()->IsMaybeSelected()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8464); MOZ_PretendNoReturn(); } } while (0)
;
8465 return GetContent()->IsSelected(0, GetContent()->GetChildCount());
8466}
8467
8468nsresult nsIFrame::GetPointFromOffset(int32_t inOffset, nsPoint* outPoint) {
8469 MOZ_ASSERT(outPoint != nullptr, "Null parameter")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(outPoint != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(outPoint != nullptr))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("outPoint != nullptr"
" (" "Null parameter" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8469); AnnotateMozCrashReason("MOZ_ASSERT" "(" "outPoint != nullptr"
") (" "Null parameter" ")"); do { *((volatile int*)__null) =
8469; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false)
;
8470 nsRect contentRect = GetContentRectRelativeToSelf();
8471 nsPoint pt = contentRect.TopLeft();
8472 if (mContent) {
8473 nsIContent* newContent = mContent->GetParent();
8474 if (newContent) {
8475 const int32_t newOffset = newContent->ComputeIndexOf_Deprecated(mContent);
8476
8477 // Find the direction of the frame from the EmbeddingLevelProperty,
8478 // which is the resolved bidi level set in
8479 // nsBidiPresUtils::ResolveParagraph (odd levels = right-to-left).
8480 // If the embedding level isn't set, just use the CSS direction
8481 // property.
8482 bool hasBidiData;
8483 FrameBidiData bidiData = GetProperty(BidiDataProperty(), &hasBidiData);
8484 bool isRTL = hasBidiData
8485 ? bidiData.embeddingLevel.IsRTL()
8486 : StyleVisibility()->mDirection == StyleDirection::Rtl;
8487 if ((!isRTL && inOffset > newOffset) ||
8488 (isRTL && inOffset <= newOffset)) {
8489 pt = contentRect.TopRight();
8490 }
8491 }
8492 }
8493 *outPoint = pt;
8494 return NS_OK;
8495}
8496
8497nsresult nsIFrame::GetCharacterRectsInRange(int32_t aInOffset, int32_t aLength,
8498 nsTArray<nsRect>& aOutRect) {
8499 /* no text */
8500 return NS_ERROR_FAILURE;
8501}
8502
8503nsresult nsIFrame::GetChildFrameContainingOffset(int32_t inContentOffset,
8504 bool inHint,
8505 int32_t* outFrameContentOffset,
8506 nsIFrame** outChildFrame) {
8507 MOZ_ASSERT(outChildFrame && outFrameContentOffset, "Null parameter")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(outChildFrame && outFrameContentOffset)>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(outChildFrame && outFrameContentOffset))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("outChildFrame && outFrameContentOffset"
" (" "Null parameter" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8507); AnnotateMozCrashReason("MOZ_ASSERT" "(" "outChildFrame && outFrameContentOffset"
") (" "Null parameter" ")"); do { *((volatile int*)__null) =
8507; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false)
;
8508 *outFrameContentOffset = (int32_t)inHint;
8509 // the best frame to reflect any given offset would be a visible frame if
8510 // possible i.e. we are looking for a valid frame to place the blinking caret
8511 nsRect rect = GetRect();
8512 if (!rect.width || !rect.height) {
8513 // if we have a 0 width or height then lets look for another frame that
8514 // possibly has the same content. If we have no frames in flow then just
8515 // let us return 'this' frame
8516 nsIFrame* nextFlow = GetNextInFlow();
8517 if (nextFlow)
8518 return nextFlow->GetChildFrameContainingOffset(
8519 inContentOffset, inHint, outFrameContentOffset, outChildFrame);
8520 }
8521 *outChildFrame = this;
8522 return NS_OK;
8523}
8524
8525//
8526// What I've pieced together about this routine:
8527// Starting with a block frame (from which a line frame can be gotten)
8528// and a line number, drill down and get the first/last selectable
8529// frame on that line, depending on aPos->mDirection.
8530// aOutSideLimit != 0 means ignore aLineStart, instead work from
8531// the end (if > 0) or beginning (if < 0).
8532//
8533static nsresult GetNextPrevLineFromBlockFrame(PeekOffsetStruct* aPos,
8534 nsIFrame* aBlockFrame,
8535 int32_t aLineStart,
8536 int8_t aOutSideLimit) {
8537 MOZ_ASSERT(aPos)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPos)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(aPos))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("aPos", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8537); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPos" ")");
do { *((volatile int*)__null) = 8537; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8538 MOZ_ASSERT(aBlockFrame)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aBlockFrame)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aBlockFrame))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("aBlockFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8538); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aBlockFrame"
")"); do { *((volatile int*)__null) = 8538; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8539
8540 nsPresContext* pc = aBlockFrame->PresContext();
8541
8542 // magic numbers: aLineStart will be -1 for end of block, 0 will be start of
8543 // block.
8544
8545 aPos->mResultFrame = nullptr;
8546 aPos->mResultContent = nullptr;
8547 aPos->mAttach = aPos->mDirection == eDirNext ? CARET_ASSOCIATE_AFTER
8548 : CARET_ASSOCIATE_BEFORE;
8549
8550 AutoAssertNoDomMutations guard;
8551 nsILineIterator* it = aBlockFrame->GetLineIterator();
8552 if (!it) {
8553 return NS_ERROR_FAILURE;
8554 }
8555 int32_t searchingLine = aLineStart;
8556 int32_t countLines = it->GetNumLines();
8557 if (aOutSideLimit > 0) { // start at end
8558 searchingLine = countLines;
8559 } else if (aOutSideLimit < 0) { // start at beginning
8560 searchingLine = -1; //"next" will be 0
8561 } else if ((aPos->mDirection == eDirPrevious && searchingLine == 0) ||
8562 (aPos->mDirection == eDirNext &&
8563 searchingLine >= (countLines - 1))) {
8564 // Not found.
8565 return NS_ERROR_FAILURE;
8566 }
8567 nsIFrame* resultFrame = nullptr;
8568 nsIFrame* farStoppingFrame = nullptr; // we keep searching until we find a
8569 // "this" frame then we go to next line
8570 nsIFrame* nearStoppingFrame = nullptr; // if we are backing up from edge,
8571 // stop here
8572 nsIFrame* firstFrame;
8573 nsIFrame* lastFrame;
8574 bool isBeforeFirstFrame, isAfterLastFrame;
8575 bool found = false;
8576
8577 nsresult result = NS_OK;
8578 while (!found) {
8579 if (aPos->mDirection == eDirPrevious)
8580 searchingLine--;
8581 else
8582 searchingLine++;
8583 if ((aPos->mDirection == eDirPrevious && searchingLine < 0) ||
8584 (aPos->mDirection == eDirNext && searchingLine >= countLines)) {
8585 // we need to jump to new block frame.
8586 return NS_ERROR_FAILURE;
8587 }
8588 auto line = it->GetLine(searchingLine).unwrap();
8589 if (!line.mNumFramesOnLine) {
8590 continue;
8591 }
8592 lastFrame = firstFrame = line.mFirstFrameOnLine;
8593 for (int32_t lineFrameCount = line.mNumFramesOnLine; lineFrameCount > 1;
8594 lineFrameCount--) {
8595 lastFrame = lastFrame->GetNextSibling();
8596 if (!lastFrame) {
8597 NS_ERROR("GetLine promised more frames than could be found")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "GetLine promised more frames than could be found"
, "Error", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8597); MOZ_PretendNoReturn(); } while (0)
;
8598 return NS_ERROR_FAILURE;
8599 }
8600 }
8601 nsIFrame::GetLastLeaf(&lastFrame);
8602
8603 if (aPos->mDirection == eDirNext) {
8604 nearStoppingFrame = firstFrame;
8605 farStoppingFrame = lastFrame;
8606 } else {
8607 nearStoppingFrame = lastFrame;
8608 farStoppingFrame = firstFrame;
8609 }
8610 nsPoint offset;
8611 nsView* view; // used for call of get offset from view
8612 aBlockFrame->GetOffsetFromView(offset, &view);
8613 nsPoint newDesiredPos =
8614 aPos->mDesiredCaretPos -
8615 offset; // get desired position into blockframe coords
8616 result = it->FindFrameAt(searchingLine, newDesiredPos, &resultFrame,
8617 &isBeforeFirstFrame, &isAfterLastFrame);
8618 if (NS_FAILED(result)((bool)(__builtin_expect(!!(NS_FAILED_impl(result)), 0)))) {
8619 continue;
8620 }
8621
8622 if (resultFrame) {
8623 // check to see if this is ANOTHER blockframe inside the other one if so
8624 // then call into its lines
8625 if (resultFrame->CanProvideLineIterator()) {
8626 aPos->mResultFrame = resultFrame;
8627 return NS_OK;
8628 }
8629 // resultFrame is not a block frame
8630 result = NS_ERROR_FAILURE;
Value stored to 'result' is never read
8631
8632 nsCOMPtr<nsIFrameEnumerator> frameTraversal;
8633 result = NS_NewFrameTraversal(
8634 getter_AddRefs(frameTraversal), pc, resultFrame, ePostOrder,
8635 false, // aVisual
8636 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller),
8637 false, // aFollowOOFs
8638 false // aSkipPopupChecks
8639 );
8640 if (NS_FAILED(result)((bool)(__builtin_expect(!!(NS_FAILED_impl(result)), 0)))) {
8641 return result;
8642 }
8643
8644 auto FoundValidFrame = [aPos](const nsIFrame::ContentOffsets& aOffsets,
8645 const nsIFrame* aFrame) {
8646 if (!aOffsets.content) {
8647 return false;
8648 }
8649 if (!aFrame->IsSelectable(nullptr)) {
8650 return false;
8651 }
8652 if (aPos->mOptions.contains(PeekOffsetOption::ForceEditableRegion) &&
8653 !aOffsets.content->IsEditable()) {
8654 return false;
8655 }
8656 return true;
8657 };
8658
8659 nsIFrame* storeOldResultFrame = resultFrame;
8660 while (!found) {
8661 nsPoint point;
8662 nsRect tempRect = resultFrame->GetRect();
8663 nsPoint offset;
8664 nsView* view; // used for call of get offset from view
8665 resultFrame->GetOffsetFromView(offset, &view);
8666 if (!view) {
8667 return NS_ERROR_FAILURE;
8668 }
8669 if (resultFrame->GetWritingMode().IsVertical()) {
8670 point.y = aPos->mDesiredCaretPos.y;
8671 point.x = tempRect.width + offset.x;
8672 } else {
8673 point.y = tempRect.height + offset.y;
8674 point.x = aPos->mDesiredCaretPos.x;
8675 }
8676
8677 if (!resultFrame->HasView()) {
8678 nsView* view;
8679 nsPoint offset;
8680 resultFrame->GetOffsetFromView(offset, &view);
8681 nsIFrame::ContentOffsets offsets =
8682 resultFrame->GetContentOffsetsFromPoint(point - offset);
8683 aPos->mResultContent = offsets.content;
8684 aPos->mContentOffset = offsets.offset;
8685 aPos->mAttach = offsets.associate;
8686 if (FoundValidFrame(offsets, resultFrame)) {
8687 found = true;
8688 break;
8689 }
8690 }
8691
8692 if (aPos->mDirection == eDirPrevious &&
8693 resultFrame == farStoppingFrame) {
8694 break;
8695 }
8696 if (aPos->mDirection == eDirNext && resultFrame == nearStoppingFrame) {
8697 break;
8698 }
8699 // always try previous on THAT line if that fails go the other way
8700 resultFrame = frameTraversal->Traverse(/* aForward = */ false);
8701 if (!resultFrame) {
8702 return NS_ERROR_FAILURE;
8703 }
8704 }
8705
8706 if (!found) {
8707 resultFrame = storeOldResultFrame;
8708
8709 result = NS_NewFrameTraversal(
8710 getter_AddRefs(frameTraversal), pc, resultFrame, eLeaf,
8711 false, // aVisual
8712 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller),
8713 false, // aFollowOOFs
8714 false // aSkipPopupChecks
8715 );
8716 }
8717 while (!found) {
8718 nsPoint point = aPos->mDesiredCaretPos;
8719 nsView* view;
8720 nsPoint offset;
8721 resultFrame->GetOffsetFromView(offset, &view);
8722 nsIFrame::ContentOffsets offsets =
8723 resultFrame->GetContentOffsetsFromPoint(point - offset);
8724 aPos->mResultContent = offsets.content;
8725 aPos->mContentOffset = offsets.offset;
8726 aPos->mAttach = offsets.associate;
8727 if (FoundValidFrame(offsets, resultFrame)) {
8728 found = true;
8729 if (resultFrame == farStoppingFrame)
8730 aPos->mAttach = CARET_ASSOCIATE_BEFORE;
8731 else
8732 aPos->mAttach = CARET_ASSOCIATE_AFTER;
8733 break;
8734 }
8735 if (aPos->mDirection == eDirPrevious &&
8736 (resultFrame == nearStoppingFrame))
8737 break;
8738 if (aPos->mDirection == eDirNext && (resultFrame == farStoppingFrame))
8739 break;
8740 // previous didnt work now we try "next"
8741 nsIFrame* tempFrame = frameTraversal->Traverse(/* aForward = */ true);
8742 if (!tempFrame) break;
8743 resultFrame = tempFrame;
8744 }
8745 aPos->mResultFrame = resultFrame;
8746 } else {
8747 // we need to jump to new block frame.
8748 aPos->mAmount = eSelectLine;
8749 aPos->mStartOffset = 0;
8750 aPos->mAttach = aPos->mDirection == eDirNext ? CARET_ASSOCIATE_BEFORE
8751 : CARET_ASSOCIATE_AFTER;
8752 if (aPos->mDirection == eDirPrevious)
8753 aPos->mStartOffset = -1; // start from end
8754 return aBlockFrame->PeekOffset(aPos);
8755 }
8756 }
8757 return NS_OK;
8758}
8759
8760nsIFrame::CaretPosition nsIFrame::GetExtremeCaretPosition(bool aStart) {
8761 CaretPosition result;
8762
8763 FrameTarget targetFrame = DrillDownToSelectionFrame(this, !aStart, 0);
8764 FrameContentRange range = GetRangeForFrame(targetFrame.frame);
8765 result.mResultContent = range.content;
8766 result.mContentOffset = aStart ? range.start : range.end;
8767 return result;
8768}
8769
8770// If this is a preformatted text frame, see if it ends with a newline
8771static nsContentAndOffset FindLineBreakInText(nsIFrame* aFrame,
8772 nsDirection aDirection) {
8773 nsContentAndOffset result;
8774
8775 if (aFrame->IsGeneratedContentFrame() ||
8776 !aFrame->HasSignificantTerminalNewline()) {
8777 return result;
8778 }
8779
8780 int32_t endOffset = aFrame->GetOffsets().second;
8781 result.mContent = aFrame->GetContent();
8782 result.mOffset = endOffset - (aDirection == eDirPrevious ? 0 : 1);
8783 return result;
8784}
8785
8786// Find the first (or last) descendant of the given frame
8787// which is either a block-level frame or a BRFrame, or some other kind of break
8788// which stops the line.
8789static nsContentAndOffset FindLineBreakingFrame(nsIFrame* aFrame,
8790 nsDirection aDirection) {
8791 nsContentAndOffset result;
8792
8793 if (aFrame->IsGeneratedContentFrame()) {
8794 return result;
8795 }
8796
8797 // Treat form controls as inline leaves
8798 // XXX we really need a way to determine whether a frame is inline-level
8799 if (static_cast<nsIFormControlFrame*>(do_QueryFrame(aFrame))) {
8800 return result;
8801 }
8802
8803 // Check the frame itself
8804 // Fall through block-in-inline split frames because their mContent is
8805 // the content of the inline frames they were created from. The
8806 // first/last child of such frames is the real block frame we're
8807 // looking for.
8808 if ((aFrame->IsBlockOutside() &&
8809 !aFrame->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) ||
8810 aFrame->IsBrFrame()) {
8811 nsIContent* content = aFrame->GetContent();
8812 result.mContent = content->GetParent();
8813 // In some cases (bug 310589, bug 370174) we end up here with a null
8814 // content. This probably shouldn't ever happen, but since it sometimes
8815 // does, we want to avoid crashing here.
8816 NS_ASSERTION(result.mContent, "Unexpected orphan content")do { if (!(result.mContent)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "Unexpected orphan content", "result.mContent", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8816); MOZ_PretendNoReturn(); } } while (0)
;
8817 if (result.mContent) {
8818 result.mOffset = result.mContent->ComputeIndexOf_Deprecated(content) +
8819 (aDirection == eDirPrevious ? 1 : 0);
8820 }
8821 return result;
8822 }
8823
8824 result = FindLineBreakInText(aFrame, aDirection);
8825 if (result.mContent) {
8826 return result;
8827 }
8828
8829 // Iterate over children and call ourselves recursively
8830 if (aDirection == eDirPrevious) {
8831 nsIFrame* child = aFrame->PrincipalChildList().LastChild();
8832 while (child && !result.mContent) {
8833 result = FindLineBreakingFrame(child, aDirection);
8834 child = child->GetPrevSibling();
8835 }
8836 } else { // eDirNext
8837 nsIFrame* child = aFrame->PrincipalChildList().FirstChild();
8838 while (child && !result.mContent) {
8839 result = FindLineBreakingFrame(child, aDirection);
8840 child = child->GetNextSibling();
8841 }
8842 }
8843 return result;
8844}
8845
8846nsresult nsIFrame::PeekOffsetForParagraph(PeekOffsetStruct* aPos) {
8847 nsIFrame* frame = this;
8848 nsContentAndOffset blockFrameOrBR;
8849 blockFrameOrBR.mContent = nullptr;
8850 bool reachedLimit = frame->IsBlockOutside() || IsEditingHost(frame);
8851
8852 auto traverse = [&aPos](nsIFrame* current) {
8853 return aPos->mDirection == eDirPrevious ? current->GetPrevSibling()
8854 : current->GetNextSibling();
8855 };
8856
8857 // Go through containing frames until reaching a block frame.
8858 // In each step, search the previous (or next) siblings for the closest
8859 // "stop frame" (a block frame or a BRFrame).
8860 // If found, set it to be the selection boundary and abort.
8861 while (!reachedLimit) {
8862 nsIFrame* parent = frame->GetParent();
8863 // Treat a frame associated with the root content as if it were a block
8864 // frame.
8865 if (!frame->mContent || !frame->mContent->GetParent()) {
8866 reachedLimit = true;
8867 break;
8868 }
8869
8870 if (aPos->mDirection == eDirNext) {
8871 // Try to find our own line-break before looking at our siblings.
8872 blockFrameOrBR = FindLineBreakInText(frame, eDirNext);
8873 }
8874
8875 nsIFrame* sibling = traverse(frame);
8876 while (sibling && !blockFrameOrBR.mContent) {
8877 blockFrameOrBR = FindLineBreakingFrame(sibling, aPos->mDirection);
8878 sibling = traverse(sibling);
8879 }
8880 if (blockFrameOrBR.mContent) {
8881 aPos->mResultContent = blockFrameOrBR.mContent;
8882 aPos->mContentOffset = blockFrameOrBR.mOffset;
8883 break;
8884 }
8885 frame = parent;
8886 reachedLimit = frame && (frame->IsBlockOutside() || IsEditingHost(frame));
8887 }
8888
8889 if (reachedLimit) { // no "stop frame" found
8890 aPos->mResultContent = frame->GetContent();
8891 if (aPos->mDirection == eDirPrevious) {
8892 aPos->mContentOffset = 0;
8893 } else if (aPos->mResultContent) {
8894 aPos->mContentOffset = aPos->mResultContent->GetChildCount();
8895 }
8896 }
8897 return NS_OK;
8898}
8899
8900// Determine movement direction relative to frame
8901static bool IsMovingInFrameDirection(const nsIFrame* frame,
8902 nsDirection aDirection, bool aVisual) {
8903 bool isReverseDirection =
8904 aVisual && nsBidiPresUtils::IsReversedDirectionFrame(frame);
8905 return aDirection == (isReverseDirection ? eDirPrevious : eDirNext);
8906}
8907
8908// Determines "are we looking for a boundary between whitespace and
8909// non-whitespace (in the direction we're moving in)". It is true when moving
8910// forward and looking for a beginning of a word, or when moving backwards and
8911// looking for an end of a word.
8912static bool ShouldWordSelectionEatSpace(const PeekOffsetStruct& aPos) {
8913 if (aPos.mWordMovementType != eDefaultBehavior) {
8914 // aPos->mWordMovementType possible values:
8915 // eEndWord: eat the space if we're moving backwards
8916 // eStartWord: eat the space if we're moving forwards
8917 return (aPos.mWordMovementType == eEndWord) ==
8918 (aPos.mDirection == eDirPrevious);
8919 }
8920 // Use the hidden preference which is based on operating system
8921 // behavior. This pref only affects whether moving forward by word
8922 // should go to the end of this word or start of the next word. When
8923 // going backwards, the start of the word is always used, on every
8924 // operating system.
8925 return aPos.mDirection == eDirNext &&
8926 StaticPrefs::layout_word_select_eat_space_to_next_word();
8927}
8928
8929enum class OffsetIsAtLineEdge : bool { No, Yes };
8930
8931static void SetPeekResultFromFrame(PeekOffsetStruct& aPos, nsIFrame* aFrame,
8932 int32_t aOffset,
8933 OffsetIsAtLineEdge aAtLineEdge) {
8934 FrameContentRange range = GetRangeForFrame(aFrame);
8935 aPos.mResultFrame = aFrame;
8936 aPos.mResultContent = range.content;
8937 // Output offset is relative to content, not frame
8938 aPos.mContentOffset =
8939 aOffset < 0 ? range.end + aOffset + 1 : range.start + aOffset;
8940 if (aAtLineEdge == OffsetIsAtLineEdge::Yes) {
8941 aPos.mAttach = aPos.mContentOffset == range.start ? CARET_ASSOCIATE_AFTER
8942 : CARET_ASSOCIATE_BEFORE;
8943 }
8944}
8945
8946void nsIFrame::SelectablePeekReport::TransferTo(PeekOffsetStruct& aPos) const {
8947 return SetPeekResultFromFrame(aPos, mFrame, mOffset, OffsetIsAtLineEdge::No);
8948}
8949
8950nsIFrame::SelectablePeekReport::SelectablePeekReport(
8951 const mozilla::GenericErrorResult<nsresult>&& aErr) {
8952 MOZ_ASSERT(NS_FAILED(aErr.operator nsresult()))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(NS_FAILED_impl(aErr.operator
nsresult())), 0))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
NS_FAILED_impl(aErr.operator nsresult())), 0)))))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("((bool)(__builtin_expect(!!(NS_FAILED_impl(aErr.operator nsresult())), 0)))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8952); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(NS_FAILED_impl(aErr.operator nsresult())), 0)))"
")"); do { *((volatile int*)__null) = 8952; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8953 // Return an empty report
8954}
8955
8956nsresult nsIFrame::PeekOffsetForCharacter(PeekOffsetStruct* aPos,
8957 int32_t aOffset) {
8958 SelectablePeekReport current{this, aOffset};
8959
8960 nsIFrame::FrameSearchResult peekSearchState = CONTINUE;
8961
8962 while (peekSearchState != FOUND) {
8963 const bool movingInFrameDirection = IsMovingInFrameDirection(
8964 current.mFrame, aPos->mDirection,
8965 aPos->mOptions.contains(PeekOffsetOption::Visual));
8966
8967 if (current.mJumpedLine) {
8968 // If we jumped lines, it's as if we found a character, but we still need
8969 // to eat non-renderable content on the new line.
8970 peekSearchState = current.PeekOffsetNoAmount(movingInFrameDirection);
8971 } else {
8972 PeekOffsetCharacterOptions options;
8973 options.mRespectClusters = aPos->mAmount == eSelectCluster;
8974 peekSearchState =
8975 current.PeekOffsetCharacter(movingInFrameDirection, options);
8976 }
8977
8978 current.mMovedOverNonSelectableText |=
8979 peekSearchState == CONTINUE_UNSELECTABLE;
8980
8981 if (peekSearchState != FOUND) {
8982 SelectablePeekReport next = current.mFrame->GetFrameFromDirection(*aPos);
8983 if (next.Failed()) {
8984 return NS_ERROR_FAILURE;
8985 }
8986 next.mJumpedLine |= current.mJumpedLine;
8987 next.mMovedOverNonSelectableText |= current.mMovedOverNonSelectableText;
8988 next.mHasSelectableFrame |= current.mHasSelectableFrame;
8989 current = next;
8990 }
8991
8992 // Found frame, but because we moved over non selectable text we want
8993 // the offset to be at the frame edge. Note that if we are extending the
8994 // selection, this doesn't matter.
8995 if (peekSearchState == FOUND && current.mMovedOverNonSelectableText &&
8996 (!aPos->mOptions.contains(PeekOffsetOption::Extend) ||
8997 current.mHasSelectableFrame)) {
8998 auto [start, end] = current.mFrame->GetOffsets();
8999 current.mOffset = aPos->mDirection == eDirNext ? 0 : end - start;
9000 }
9001 }
9002
9003 // Set outputs
9004 current.TransferTo(*aPos);
9005 // If we're dealing with a text frame and moving backward positions us at
9006 // the end of that line, decrease the offset by one to make sure that
9007 // we're placed before the linefeed character on the previous line.
9008 if (current.mOffset < 0 && current.mJumpedLine &&
9009 aPos->mDirection == eDirPrevious &&
9010 current.mFrame->HasSignificantTerminalNewline() &&
9011 !current.mIgnoredBrFrame) {
9012 --aPos->mContentOffset;
9013 }
9014 return NS_OK;
9015}
9016
9017nsresult nsIFrame::PeekOffsetForWord(PeekOffsetStruct* aPos, int32_t aOffset) {
9018 SelectablePeekReport current{this, aOffset};
9019 bool shouldStopAtHardBreak =
9020 aPos->mWordMovementType == eDefaultBehavior &&
9021 StaticPrefs::layout_word_select_eat_space_to_next_word();
9022 bool wordSelectEatSpace = ShouldWordSelectionEatSpace(*aPos);
9023
9024 PeekWordState state;
9025 while (true) {
9026 bool movingInFrameDirection = IsMovingInFrameDirection(
9027 current.mFrame, aPos->mDirection,
9028 aPos->mOptions.contains(PeekOffsetOption::Visual));
9029
9030 FrameSearchResult searchResult = current.mFrame->PeekOffsetWord(
9031 movingInFrameDirection, wordSelectEatSpace,
9032 aPos->mOptions.contains(PeekOffsetOption::IsKeyboardSelect),
9033 &current.mOffset, &state,
9034 !aPos->mOptions.contains(PeekOffsetOption::PreserveSpaces));
9035 if (searchResult == FOUND) {
9036 break;
9037 }
9038
9039 SelectablePeekReport next = [&]() {
9040 PeekOffsetOptions options = aPos->mOptions;
9041 if (state.mSawInlineCharacter) {
9042 // If we've already found a character, we don't want to stop at
9043 // placeholder frame boundary if there is in the word.
9044 options += PeekOffsetOption::StopAtPlaceholder;
9045 }
9046 return current.mFrame->GetFrameFromDirection(aPos->mDirection, options);
9047 }();
9048 if (next.Failed()) {
9049 // If we've crossed the line boundary, check to make sure that we
9050 // have not consumed a trailing newline as whitespace if it's
9051 // significant.
9052 if (next.mJumpedLine && wordSelectEatSpace &&
9053 current.mFrame->HasSignificantTerminalNewline() &&
9054 current.mFrame->StyleText()->mWhiteSpace !=
9055 StyleWhiteSpace::PreLine) {
9056 current.mOffset -= 1;
9057 }
9058 break;
9059 }
9060
9061 if ((next.mJumpedLine || next.mFoundPlaceholder) && !wordSelectEatSpace &&
9062 state.mSawBeforeType) {
9063 // We can't jump lines if we're looking for whitespace following
9064 // non-whitespace, and we already encountered non-whitespace.
9065 break;
9066 }
9067
9068 if (shouldStopAtHardBreak && next.mJumpedHardBreak) {
9069 /**
9070 * Prev, always: Jump and stop right there
9071 * Next, saw inline: just stop
9072 * Next, no inline: Jump and consume whitespaces
9073 */
9074 if (aPos->mDirection == eDirPrevious) {
9075 // Try moving to the previous line if exists
9076 current.TransferTo(*aPos);
9077 current.mFrame->PeekOffsetForCharacter(aPos, current.mOffset);
9078 return NS_OK;
9079 }
9080 if (state.mSawInlineCharacter || current.mJumpedHardBreak) {
9081 if (current.mFrame->HasSignificantTerminalNewline()) {
9082 current.mOffset -= 1;
9083 }
9084 current.TransferTo(*aPos);
9085 return NS_OK;
9086 }
9087 // Mark the state as whitespace and continue
9088 state.Update(false, true);
9089 }
9090
9091 if (next.mJumpedLine) {
9092 state.mContext.Truncate();
9093 }
9094 current = next;
9095 // Jumping a line is equivalent to encountering whitespace
9096 // This affects only when it already met an actual character
9097 if (wordSelectEatSpace && next.mJumpedLine) {
9098 state.SetSawBeforeType();
9099 }
9100 }
9101
9102 // Set outputs
9103 current.TransferTo(*aPos);
9104 return NS_OK;
9105}
9106
9107static nsIFrame* GetFirstSelectableDescendantWithLineIterator(
9108 nsIFrame* aParentFrame, bool aForceEditableRegion) {
9109 auto FoundValidFrame = [aForceEditableRegion](const nsIFrame* aFrame) {
9110 if (!aFrame->IsSelectable(nullptr)) {
9111 return false;
9112 }
9113 if (aForceEditableRegion && !aFrame->GetContent()->IsEditable()) {
9114 return false;
9115 }
9116 return true;
9117 };
9118
9119 for (nsIFrame* child : aParentFrame->PrincipalChildList()) {
9120 // some children may not be selectable, e.g. :before / :after pseudoelements
9121 // content with user-select: none, or contenteditable="false"
9122 // we need to skip them
9123 if (child->CanProvideLineIterator() && FoundValidFrame(child)) {
9124 return child;
9125 }
9126 if (nsIFrame* nested = GetFirstSelectableDescendantWithLineIterator(
9127 child, aForceEditableRegion)) {
9128 return nested;
9129 }
9130 }
9131 return nullptr;
9132}
9133
9134nsresult nsIFrame::PeekOffsetForLine(PeekOffsetStruct* aPos) {
9135 nsIFrame* blockFrame = this;
9136 nsresult result = NS_ERROR_FAILURE;
9137
9138 // outer loop
9139 // moving to a next block when no more blocks are available in a subtree
9140 AutoAssertNoDomMutations guard;
9141 while (NS_FAILED(result)((bool)(__builtin_expect(!!(NS_FAILED_impl(result)), 0)))) {
9142 auto [newBlock, lineFrame] = blockFrame->GetContainingBlockForLine(
9143 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller));
9144 if (!newBlock) {
9145 return NS_ERROR_FAILURE;
9146 }
9147 blockFrame = newBlock;
9148 nsILineIterator* iter = blockFrame->GetLineIterator();
9149 int32_t thisLine = iter->FindLineContaining(lineFrame);
9150 if (NS_WARN_IF(thisLine < 0)NS_warn_if_impl(thisLine < 0, "thisLine < 0", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9150)
) {
9151 return NS_ERROR_FAILURE;
9152 }
9153
9154 int8_t edgeCase = 0; // no edge case. This should look at thisLine
9155
9156 // this part will find a frame or a block frame. If it's a block frame
9157 // it will "drill down" to find a viable frame or it will return an
9158 // error.
9159 nsIFrame* lastFrame = this;
9160
9161 // inner loop - crawling the frames within a specific block subtree
9162 while (true) {
9163 result =
9164 GetNextPrevLineFromBlockFrame(aPos, blockFrame, thisLine, edgeCase);
9165 // we came back to same spot! keep going
9166 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) &&
9167 (!aPos->mResultFrame || aPos->mResultFrame == lastFrame)) {
9168 aPos->mResultFrame = nullptr;
9169 lastFrame = nullptr;
9170 if (aPos->mDirection == eDirPrevious) {
9171 thisLine--;
9172 } else {
9173 thisLine++;
9174 }
9175 continue;
9176 }
9177
9178 if (NS_FAILED(result)((bool)(__builtin_expect(!!(NS_FAILED_impl(result)), 0)))) {
9179 break;
9180 }
9181
9182 lastFrame = aPos->mResultFrame; // set last frame
9183 /* SPECIAL CHECK FOR NAVIGATION INTO TABLES
9184 * when we hit a frame which doesn't have line iterator, we need to
9185 * drill down and find a child with the line iterator to prevent the
9186 * crawling process to prematurely finish. Note that this is only sound if
9187 * we're guaranteed to not have multiple children implementing
9188 * LineIterator.
9189 *
9190 * So far known cases are:
9191 * 1) table wrapper (drill down into table row group)
9192 * 2) table cell (drill down into its only anon child)
9193 */
9194 const bool shouldDrillIntoChildren =
9195 aPos->mResultFrame->IsTableWrapperFrame() ||
9196 aPos->mResultFrame->IsTableCellFrame();
9197
9198 if (shouldDrillIntoChildren) {
9199 nsIFrame* child = GetFirstSelectableDescendantWithLineIterator(
9200 aPos->mResultFrame,
9201 aPos->mOptions.contains(PeekOffsetOption::ForceEditableRegion));
9202 if (child) {
9203 aPos->mResultFrame = child;
9204 }
9205 }
9206
9207 if (!aPos->mResultFrame->CanProvideLineIterator()) {
9208 // no more selectable content at this level
9209 break;
9210 }
9211
9212 if (aPos->mResultFrame == blockFrame) {
9213 // Make sure block element is not the same as the one we had before.
9214 break;
9215 }
9216
9217 // we've struck another block element with selectable content!
9218 if (aPos->mDirection == eDirPrevious) {
9219 edgeCase = 1; // far edge, search from end backwards
9220 } else {
9221 edgeCase = -1; // near edge search from beginning onwards
9222 }
9223 thisLine = 0; // this line means nothing now.
9224 // everything else means something so keep looking "inside" the
9225 // block
9226 blockFrame = aPos->mResultFrame;
9227 }
9228 }
9229 return result;
9230}
9231
9232nsresult nsIFrame::PeekOffsetForLineEdge(PeekOffsetStruct* aPos) {
9233 // Adjusted so that the caret can't get confused when content changes
9234 nsIFrame* frame = AdjustFrameForSelectionStyles(this);
9235 Element* editingHost = frame->GetContent()->GetEditingHost();
9236
9237 auto [blockFrame, lineFrame] = frame->GetContainingBlockForLine(
9238 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller));
9239 if (!blockFrame) {
9240 return NS_ERROR_FAILURE;
9241 }
9242 AutoAssertNoDomMutations guard;
9243 nsILineIterator* it = blockFrame->GetLineIterator();
9244 int32_t thisLine = it->FindLineContaining(lineFrame);
9245 if (thisLine < 0) {
9246 return NS_ERROR_FAILURE;
9247 }
9248
9249 nsIFrame* baseFrame = nullptr;
9250 bool endOfLine = eSelectEndLine == aPos->mAmount;
9251
9252 if (aPos->mOptions.contains(PeekOffsetOption::Visual) &&
9253 PresContext()->BidiEnabled()) {
9254 nsIFrame* firstFrame;
9255 bool isReordered;
9256 nsIFrame* lastFrame;
9257 MOZ_TRY(do { auto mozTryTempResult_ = ::mozilla::ToResult(it->CheckLineOrder
(thisLine, &isReordered, &firstFrame, &lastFrame)
); if ((__builtin_expect(!!(mozTryTempResult_.isErr()), 0))) {
return mozTryTempResult_.propagateErr(); } } while (0)
9258 it->CheckLineOrder(thisLine, &isReordered, &firstFrame, &lastFrame))do { auto mozTryTempResult_ = ::mozilla::ToResult(it->CheckLineOrder
(thisLine, &isReordered, &firstFrame, &lastFrame)
); if ((__builtin_expect(!!(mozTryTempResult_.isErr()), 0))) {
return mozTryTempResult_.propagateErr(); } } while (0)
;
9259 baseFrame = endOfLine ? lastFrame : firstFrame;
9260 } else {
9261 auto line = it->GetLine(thisLine).unwrap();
9262
9263 nsIFrame* frame = line.mFirstFrameOnLine;
9264 bool lastFrameWasEditable = false;
9265 for (int32_t count = line.mNumFramesOnLine; count;
9266 --count, frame = frame->GetNextSibling()) {
9267 if (frame->IsGeneratedContentFrame()) {
9268 continue;
9269 }
9270 // When jumping to the end of the line with the "end" key,
9271 // try to skip over brFrames
9272 if (endOfLine && line.mNumFramesOnLine > 1 && frame->IsBrFrame() &&
9273 lastFrameWasEditable == frame->GetContent()->IsEditable()) {
9274 continue;
9275 }
9276 lastFrameWasEditable =
9277 frame->GetContent() && frame->GetContent()->IsEditable();
9278 baseFrame = frame;
9279 if (!endOfLine) {
9280 break;
9281 }
9282 }
9283 }
9284 if (!baseFrame) {
9285 return NS_ERROR_FAILURE;
9286 }
9287 // Make sure we are not leaving our inline editing host if exists
9288 if (editingHost) {
9289 if (nsIFrame* frame = editingHost->GetPrimaryFrame()) {
9290 if (frame->IsInlineOutside() &&
9291 !editingHost->Contains(baseFrame->GetContent())) {
9292 baseFrame = frame;
9293 if (endOfLine) {
9294 baseFrame = baseFrame->LastContinuation();
9295 }
9296 }
9297 }
9298 }
9299 FrameTarget targetFrame = DrillDownToSelectionFrame(baseFrame, endOfLine, 0);
9300 SetPeekResultFromFrame(*aPos, targetFrame.frame, endOfLine ? -1 : 0,
9301 OffsetIsAtLineEdge::Yes);
9302 if (endOfLine && targetFrame.frame->HasSignificantTerminalNewline()) {
9303 // Do not position the caret after the terminating newline if we're
9304 // trying to move to the end of line (see bug 596506)
9305 --aPos->mContentOffset;
9306 }
9307 if (!aPos->mResultContent) {
9308 return NS_ERROR_FAILURE;
9309 }
9310 return NS_OK;
9311}
9312
9313nsresult nsIFrame::PeekOffset(PeekOffsetStruct* aPos) {
9314 MOZ_ASSERT(aPos)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPos)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(aPos))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("aPos", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9314); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPos" ")");
do { *((volatile int*)__null) = 9314; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9315
9316 if (NS_WARN_IF(HasAnyStateBits(NS_FRAME_IS_DIRTY))NS_warn_if_impl(HasAnyStateBits(NS_FRAME_IS_DIRTY), "HasAnyStateBits(NS_FRAME_IS_DIRTY)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9316)
) {
9317 // FIXME(Bug 1654362): <caption> currently can remain dirty.
9318 return NS_ERROR_UNEXPECTED;
9319 }
9320
9321 // Translate content offset to be relative to frame
9322 int32_t offset = aPos->mStartOffset - GetRangeForFrame(this).start;
9323
9324 switch (aPos->mAmount) {
9325 case eSelectCharacter:
9326 case eSelectCluster:
9327 return PeekOffsetForCharacter(aPos, offset);
9328 case eSelectWordNoSpace:
9329 // eSelectWordNoSpace means that we should not be eating any whitespace
9330 // when moving to the adjacent word. This means that we should set aPos->
9331 // mWordMovementType to eEndWord if we're moving forwards, and to
9332 // eStartWord if we're moving backwards.
9333 if (aPos->mDirection == eDirPrevious) {
9334 aPos->mWordMovementType = eStartWord;
9335 } else {
9336 aPos->mWordMovementType = eEndWord;
9337 }
9338 // Intentionally fall through the eSelectWord case.
9339 [[fallthrough]];
9340 case eSelectWord:
9341 return PeekOffsetForWord(aPos, offset);
9342 case eSelectLine:
9343 return PeekOffsetForLine(aPos);
9344 case eSelectBeginLine:
9345 case eSelectEndLine:
9346 return PeekOffsetForLineEdge(aPos);
9347 case eSelectParagraph:
9348 return PeekOffsetForParagraph(aPos);
9349 default: {
9350 NS_ASSERTION(false, "Invalid amount")do { if (!(false)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Invalid amount"
, "false", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9350); MOZ_PretendNoReturn(); } } while (0)
;
9351 return NS_ERROR_FAILURE;
9352 }
9353 }
9354}
9355
9356nsIFrame::FrameSearchResult nsIFrame::PeekOffsetNoAmount(bool aForward,
9357 int32_t* aOffset) {
9358 NS_ASSERTION(aOffset && *aOffset <= 1, "aOffset out of range")do { if (!(aOffset && *aOffset <= 1)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "aOffset out of range", "aOffset && *aOffset <= 1"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9358); MOZ_PretendNoReturn(); } } while (0)
;
9359 // Sure, we can stop right here.
9360 return FOUND;
9361}
9362
9363nsIFrame::FrameSearchResult nsIFrame::PeekOffsetCharacter(
9364 bool aForward, int32_t* aOffset, PeekOffsetCharacterOptions aOptions) {
9365 NS_ASSERTION(aOffset && *aOffset <= 1, "aOffset out of range")do { if (!(aOffset && *aOffset <= 1)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "aOffset out of range", "aOffset && *aOffset <= 1"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9365); MOZ_PretendNoReturn(); } } while (0)
;
9366 int32_t startOffset = *aOffset;
9367 // A negative offset means "end of frame", which in our case means offset 1.
9368 if (startOffset < 0) startOffset = 1;
9369 if (aForward == (startOffset == 0)) {
9370 // We're before the frame and moving forward, or after it and moving
9371 // backwards: skip to the other side and we're done.
9372 *aOffset = 1 - startOffset;
9373 return FOUND;
9374 }
9375 return CONTINUE;
9376}
9377
9378nsIFrame::FrameSearchResult nsIFrame::PeekOffsetWord(
9379 bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
9380 int32_t* aOffset, PeekWordState* aState, bool /*aTrimSpaces*/) {
9381 NS_ASSERTION(aOffset && *aOffset <= 1, "aOffset out of range")do { if (!(aOffset && *aOffset <= 1)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "aOffset out of range", "aOffset && *aOffset <= 1"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9381); MOZ_PretendNoReturn(); } } while (0)
;
9382 int32_t startOffset = *aOffset;
9383 // This isn't text, so truncate the context
9384 aState->mContext.Truncate();
9385 if (startOffset < 0) startOffset = 1;
9386 if (aForward == (startOffset == 0)) {
9387 // We're before the frame and moving forward, or after it and moving
9388 // backwards. If we're looking for non-whitespace, we found it (without
9389 // skipping this frame).
9390 if (!aState->mAtStart) {
9391 if (aState->mLastCharWasPunctuation) {
9392 // We're not punctuation, so this is a punctuation boundary.
9393 if (BreakWordBetweenPunctuation(aState, aForward, false, false,
9394 aIsKeyboardSelect))
9395 return FOUND;
9396 } else {
9397 // This is not a punctuation boundary.
9398 if (aWordSelectEatSpace && aState->mSawBeforeType) return FOUND;
9399 }
9400 }
9401 // Otherwise skip to the other side and note that we encountered
9402 // non-whitespace.
9403 *aOffset = 1 - startOffset;
9404 aState->Update(false, // not punctuation
9405 false // not whitespace
9406 );
9407 if (!aWordSelectEatSpace) aState->SetSawBeforeType();
9408 }
9409 return CONTINUE;
9410}
9411
9412// static
9413bool nsIFrame::BreakWordBetweenPunctuation(const PeekWordState* aState,
9414 bool aForward, bool aPunctAfter,
9415 bool aWhitespaceAfter,
9416 bool aIsKeyboardSelect) {
9417 NS_ASSERTION(aPunctAfter != aState->mLastCharWasPunctuation,do { if (!(aPunctAfter != aState->mLastCharWasPunctuation)
) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Call this only at punctuation boundaries"
, "aPunctAfter != aState->mLastCharWasPunctuation", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9418); MOZ_PretendNoReturn(); } } while (0)
9418 "Call this only at punctuation boundaries")do { if (!(aPunctAfter != aState->mLastCharWasPunctuation)
) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Call this only at punctuation boundaries"
, "aPunctAfter != aState->mLastCharWasPunctuation", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9418); MOZ_PretendNoReturn(); } } while (0)
;
9419 if (aState->mLastCharWasWhitespace) {
9420 // We always stop between whitespace and punctuation
9421 return true;
9422 }
9423 if (!StaticPrefs::layout_word_select_stop_at_punctuation()) {
9424 // When this pref is false, we never stop at a punctuation boundary unless
9425 // it's followed by whitespace (in the relevant direction).
9426 return aWhitespaceAfter;
9427 }
9428 if (!aIsKeyboardSelect) {
9429 // mouse caret movement (e.g. word selection) always stops at every
9430 // punctuation boundary
9431 return true;
9432 }
9433 bool afterPunct = aForward ? aState->mLastCharWasPunctuation : aPunctAfter;
9434 if (!afterPunct) {
9435 // keyboard caret movement only stops after punctuation (in content order)
9436 return false;
9437 }
9438 // Stop only if we've seen some non-punctuation since the last whitespace;
9439 // don't stop after punctuation that follows whitespace.
9440 return aState->mSeenNonPunctuationSinceWhitespace;
9441}
9442
9443std::pair<nsIFrame*, nsIFrame*> nsIFrame::GetContainingBlockForLine(
9444 bool aLockScroll) const {
9445 const nsIFrame* parentFrame = this;
9446 const nsIFrame* frame;
9447 while (parentFrame) {
9448 frame = parentFrame;
9449 if (frame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
9450 // if we are searching for a frame that is not in flow we will not find
9451 // it. we must instead look for its placeholder
9452 if (frame->HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER)) {
9453 // abspos continuations don't have placeholders, get the fif
9454 frame = frame->FirstInFlow();
9455 }
9456 frame = frame->GetPlaceholderFrame();
9457 if (!frame) {
9458 return std::pair(nullptr, nullptr);
9459 }
9460 }
9461 parentFrame = frame->GetParent();
9462 if (parentFrame) {
9463 if (aLockScroll && parentFrame->IsScrollFrame()) {
9464 return std::pair(nullptr, nullptr);
9465 }
9466 if (parentFrame->CanProvideLineIterator()) {
9467 return std::pair(const_cast<nsIFrame*>(parentFrame),
9468 const_cast<nsIFrame*>(frame));
9469 }
9470 }
9471 }
9472 return std::pair(nullptr, nullptr);
9473}
9474
9475Result<bool, nsresult> nsIFrame::IsVisuallyAtLineEdge(
9476 nsILineIterator* aLineIterator, int32_t aLine, nsDirection aDirection) {
9477 auto line = aLineIterator->GetLine(aLine).unwrap();
9478
9479 const bool lineIsRTL = aLineIterator->IsLineIteratorFlowRTL();
9480
9481 nsIFrame *firstFrame = nullptr, *lastFrame = nullptr;
9482 bool isReordered = false;
9483 MOZ_TRY(aLineIterator->CheckLineOrder(aLine, &isReordered, &firstFrame,do { auto mozTryTempResult_ = ::mozilla::ToResult(aLineIterator
->CheckLineOrder(aLine, &isReordered, &firstFrame,
&lastFrame)); if ((__builtin_expect(!!(mozTryTempResult_
.isErr()), 0))) { return mozTryTempResult_.propagateErr(); } }
while (0)
9484 &lastFrame))do { auto mozTryTempResult_ = ::mozilla::ToResult(aLineIterator
->CheckLineOrder(aLine, &isReordered, &firstFrame,
&lastFrame)); if ((__builtin_expect(!!(mozTryTempResult_
.isErr()), 0))) { return mozTryTempResult_.propagateErr(); } }
while (0)
;
9485 if (!firstFrame || !lastFrame) {
9486 return true; // XXX: Why true? We check whether `this` is at the edge...
9487 }
9488
9489 nsIFrame* leftmostFrame = lineIsRTL ? lastFrame : firstFrame;
9490 nsIFrame* rightmostFrame = lineIsRTL ? firstFrame : lastFrame;
9491 auto FrameIsRTL = [](nsIFrame* aFrame) {
9492 return nsBidiPresUtils::FrameDirection(aFrame) ==
9493 mozilla::intl::BidiDirection::RTL;
9494 };
9495 if (!lineIsRTL == (aDirection == eDirPrevious)) {
9496 nsIFrame* maybeLeftmostFrame = leftmostFrame;
9497 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9498 if (maybeLeftmostFrame == this) {
9499 return true;
9500 }
9501 // If left edge of the line starts with placeholder frames, we can ignore
9502 // them and should keep checking the following frames.
9503 if (!maybeLeftmostFrame->IsPlaceholderFrame()) {
9504 if ((FrameIsRTL(maybeLeftmostFrame) == lineIsRTL) ==
9505 (aDirection == eDirPrevious)) {
9506 nsIFrame::GetFirstLeaf(&maybeLeftmostFrame);
9507 } else {
9508 nsIFrame::GetLastLeaf(&maybeLeftmostFrame);
9509 }
9510 return maybeLeftmostFrame == this;
9511 }
9512 maybeLeftmostFrame = nsBidiPresUtils::GetFrameToRightOf(
9513 maybeLeftmostFrame, line.mFirstFrameOnLine, line.mNumFramesOnLine);
9514 if (!maybeLeftmostFrame) {
9515 return false;
9516 }
9517 }
9518 return false;
9519 }
9520
9521 nsIFrame* maybeRightmostFrame = rightmostFrame;
9522 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9523 if (maybeRightmostFrame == this) {
9524 return true;
9525 }
9526 // If the line ends with placehlder frames, we can ignore them and should
9527 // keep checking the preceding frames.
9528 if (!maybeRightmostFrame->IsPlaceholderFrame()) {
9529 if ((FrameIsRTL(maybeRightmostFrame) == lineIsRTL) ==
9530 (aDirection == eDirPrevious)) {
9531 nsIFrame::GetFirstLeaf(&maybeRightmostFrame);
9532 } else {
9533 nsIFrame::GetLastLeaf(&maybeRightmostFrame);
9534 }
9535 return maybeRightmostFrame == this;
9536 }
9537 maybeRightmostFrame = nsBidiPresUtils::GetFrameToLeftOf(
9538 maybeRightmostFrame, line.mFirstFrameOnLine, line.mNumFramesOnLine);
9539 if (!maybeRightmostFrame) {
9540 return false;
9541 }
9542 }
9543 return false;
9544}
9545
9546Result<bool, nsresult> nsIFrame::IsLogicallyAtLineEdge(
9547 nsILineIterator* aLineIterator, int32_t aLine, nsDirection aDirection) {
9548 auto line = aLineIterator->GetLine(aLine).unwrap();
9549 if (!line.mNumFramesOnLine) {
9550 return false;
9551 }
9552 MOZ_ASSERT(line.mFirstFrameOnLine)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(line.mFirstFrameOnLine)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(line.mFirstFrameOnLine))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("line.mFirstFrameOnLine"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9552); AnnotateMozCrashReason("MOZ_ASSERT" "(" "line.mFirstFrameOnLine"
")"); do { *((volatile int*)__null) = 9552; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9553
9554 if (aDirection == eDirPrevious) {
9555 nsIFrame* maybeFirstFrame = line.mFirstFrameOnLine;
9556 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9557 if (maybeFirstFrame == this) {
9558 return true;
9559 }
9560 // If the line starts with placeholder frames, we can ignore them and
9561 // should keep checking the following frames.
9562 if (!maybeFirstFrame->IsPlaceholderFrame()) {
9563 nsIFrame::GetFirstLeaf(&maybeFirstFrame);
9564 return maybeFirstFrame == this;
9565 }
9566 maybeFirstFrame = maybeFirstFrame->GetNextSibling();
9567 if (!maybeFirstFrame) {
9568 return false;
9569 }
9570 }
9571 return false;
9572 }
9573
9574 // eDirNext
9575 nsIFrame* maybeLastFrame = line.GetLastFrameOnLine();
9576 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9577 if (maybeLastFrame == this) {
9578 return true;
9579 }
9580 // If the line ends with placehlder frames, we can ignore them and should
9581 // keep checking the preceding frames.
9582 if (!maybeLastFrame->IsPlaceholderFrame()) {
9583 nsIFrame::GetLastLeaf(&maybeLastFrame);
9584 return maybeLastFrame == this;
9585 }
9586 maybeLastFrame = maybeLastFrame->GetPrevSibling();
9587 }
9588 return false;
9589}
9590
9591nsIFrame::SelectablePeekReport nsIFrame::GetFrameFromDirection(
9592 nsDirection aDirection, const PeekOffsetOptions& aOptions) {
9593 SelectablePeekReport result;
9594
9595 nsPresContext* presContext = PresContext();
9596 const bool needsVisualTraversal =
9597 aOptions.contains(PeekOffsetOption::Visual) && presContext->BidiEnabled();
9598 const bool followOofs =
9599 !aOptions.contains(PeekOffsetOption::StopAtPlaceholder);
9600 nsCOMPtr<nsIFrameEnumerator> frameTraversal;
9601 MOZ_TRY(NS_NewFrameTraversal(do { auto mozTryTempResult_ = ::mozilla::ToResult(NS_NewFrameTraversal
( getter_AddRefs(frameTraversal), presContext, this, eLeaf, needsVisualTraversal
, aOptions.contains(PeekOffsetOption::StopAtScroller), followOofs
, false )); if ((__builtin_expect(!!(mozTryTempResult_.isErr(
)), 0))) { return mozTryTempResult_.propagateErr(); } } while
(0)
9602 getter_AddRefs(frameTraversal), presContext, this, eLeaf,do { auto mozTryTempResult_ = ::mozilla::ToResult(NS_NewFrameTraversal
( getter_AddRefs(frameTraversal), presContext, this, eLeaf, needsVisualTraversal
, aOptions.contains(PeekOffsetOption::StopAtScroller), followOofs
, false )); if ((__builtin_expect(!!(mozTryTempResult_.isErr(
)), 0))) { return mozTryTempResult_.propagateErr(); } } while
(0)
9603 needsVisualTraversal, aOptions.contains(PeekOffsetOption::StopAtScroller),do { auto mozTryTempResult_ = ::mozilla::ToResult(NS_NewFrameTraversal
( getter_AddRefs(frameTraversal), presContext, this, eLeaf, needsVisualTraversal
, aOptions.contains(PeekOffsetOption::StopAtScroller), followOofs
, false )); if ((__builtin_expect(!!(mozTryTempResult_.isErr(
)), 0))) { return mozTryTempResult_.propagateErr(); } } while
(0)
9604 followOofs,do { auto mozTryTempResult_ = ::mozilla::ToResult(NS_NewFrameTraversal
( getter_AddRefs(frameTraversal), presContext, this, eLeaf, needsVisualTraversal
, aOptions.contains(PeekOffsetOption::StopAtScroller), followOofs
, false )); if ((__builtin_expect(!!(mozTryTempResult_.isErr(
)), 0))) { return mozTryTempResult_.propagateErr(); } } while
(0)
9605 false // aSkipPopupChecksdo { auto mozTryTempResult_ = ::mozilla::ToResult(NS_NewFrameTraversal
( getter_AddRefs(frameTraversal), presContext, this, eLeaf, needsVisualTraversal
, aOptions.contains(PeekOffsetOption::StopAtScroller), followOofs
, false )); if ((__builtin_expect(!!(mozTryTempResult_.isErr(
)), 0))) { return mozTryTempResult_.propagateErr(); } } while
(0)
9606 ))do { auto mozTryTempResult_ = ::mozilla::ToResult(NS_NewFrameTraversal
( getter_AddRefs(frameTraversal), presContext, this, eLeaf, needsVisualTraversal
, aOptions.contains(PeekOffsetOption::StopAtScroller), followOofs
, false )); if ((__builtin_expect(!!(mozTryTempResult_.isErr(
)), 0))) { return mozTryTempResult_.propagateErr(); } } while
(0)
;
9607
9608 // Find the prev/next selectable frame
9609 bool selectable = false;
9610 nsIFrame* traversedFrame = this;
9611 AutoAssertNoDomMutations guard;
9612 const nsIContent* const nativeAnonymousSubtreeContent =
9613 GetClosestNativeAnonymousSubtreeRoot();
9614 while (!selectable) {
9615 auto [blockFrame, lineFrame] = traversedFrame->GetContainingBlockForLine(
9616 aOptions.contains(PeekOffsetOption::StopAtScroller));
9617 if (!blockFrame) {
9618 return result;
9619 }
9620
9621 nsILineIterator* it = blockFrame->GetLineIterator();
9622 int32_t thisLine = it->FindLineContaining(lineFrame);
9623 if (thisLine < 0) {
9624 return result;
9625 }
9626
9627 bool atLineEdge;
9628 MOZ_TRY_VAR(do { auto mozTryVarTempResult_ = (needsVisualTraversal ? traversedFrame
->IsVisuallyAtLineEdge(it, thisLine, aDirection) : traversedFrame
->IsLogicallyAtLineEdge(it, thisLine, aDirection)); if ((__builtin_expect
(!!(mozTryVarTempResult_.isErr()), 0))) { return mozTryVarTempResult_
.propagateErr(); } (atLineEdge) = mozTryVarTempResult_.unwrap
(); } while (0)
9629 atLineEdge,do { auto mozTryVarTempResult_ = (needsVisualTraversal ? traversedFrame
->IsVisuallyAtLineEdge(it, thisLine, aDirection) : traversedFrame
->IsLogicallyAtLineEdge(it, thisLine, aDirection)); if ((__builtin_expect
(!!(mozTryVarTempResult_.isErr()), 0))) { return mozTryVarTempResult_
.propagateErr(); } (atLineEdge) = mozTryVarTempResult_.unwrap
(); } while (0)
9630 needsVisualTraversaldo { auto mozTryVarTempResult_ = (needsVisualTraversal ? traversedFrame
->IsVisuallyAtLineEdge(it, thisLine, aDirection) : traversedFrame
->IsLogicallyAtLineEdge(it, thisLine, aDirection)); if ((__builtin_expect
(!!(mozTryVarTempResult_.isErr()), 0))) { return mozTryVarTempResult_
.propagateErr(); } (atLineEdge) = mozTryVarTempResult_.unwrap
(); } while (0)
9631 ? traversedFrame->IsVisuallyAtLineEdge(it, thisLine, aDirection)do { auto mozTryVarTempResult_ = (needsVisualTraversal ? traversedFrame
->IsVisuallyAtLineEdge(it, thisLine, aDirection) : traversedFrame
->IsLogicallyAtLineEdge(it, thisLine, aDirection)); if ((__builtin_expect
(!!(mozTryVarTempResult_.isErr()), 0))) { return mozTryVarTempResult_
.propagateErr(); } (atLineEdge) = mozTryVarTempResult_.unwrap
(); } while (0)
9632 : traversedFrame->IsLogicallyAtLineEdge(it, thisLine, aDirection))do { auto mozTryVarTempResult_ = (needsVisualTraversal ? traversedFrame
->IsVisuallyAtLineEdge(it, thisLine, aDirection) : traversedFrame
->IsLogicallyAtLineEdge(it, thisLine, aDirection)); if ((__builtin_expect
(!!(mozTryVarTempResult_.isErr()), 0))) { return mozTryVarTempResult_
.propagateErr(); } (atLineEdge) = mozTryVarTempResult_.unwrap
(); } while (0)
;
9633 if (atLineEdge) {
9634 result.mJumpedLine = true;
9635 if (!aOptions.contains(PeekOffsetOption::JumpLines)) {
9636 return result; // we are done. cannot jump lines
9637 }
9638 int32_t lineToCheckWrap =
9639 aDirection == eDirPrevious ? thisLine - 1 : thisLine;
9640 if (lineToCheckWrap < 0 ||
9641 !it->GetLine(lineToCheckWrap).unwrap().mIsWrapped) {
9642 result.mJumpedHardBreak = true;
9643 }
9644 }
9645
9646 traversedFrame = frameTraversal->Traverse(aDirection == eDirNext);
9647 if (!traversedFrame) {
9648 return result;
9649 }
9650
9651 if (aOptions.contains(PeekOffsetOption::StopAtPlaceholder) &&
9652 traversedFrame->IsPlaceholderFrame()) {
9653 // XXX If the placeholder frame does not have meaningful content, the user
9654 // may want to select as a word around the out-of-flow cotent. However,
9655 // non-text frame resets context in nsIFrame::PeekOffsetWord(). Therefore,
9656 // next text frame considers the new word starts from its edge. So, it's
9657 // not enough to implement such behavior with adding a check here whether
9658 // the real frame may change the word with its contents if it were not
9659 // out-of-flow.
9660 result.mFoundPlaceholder = true;
9661 return result;
9662 }
9663
9664 auto IsSelectable =
9665 [aOptions, nativeAnonymousSubtreeContent](const nsIFrame* aFrame) {
9666 if (!aFrame->IsSelectable(nullptr)) {
9667 return false;
9668 }
9669 // If the new frame is in a native anonymous subtree, we should treat
9670 // it as not selectable unless the frame and found frame are in same
9671 // subtree.
9672 if (aFrame->GetClosestNativeAnonymousSubtreeRoot() !=
9673 nativeAnonymousSubtreeContent) {
9674 return false;
9675 }
9676 return !aOptions.contains(PeekOffsetOption::ForceEditableRegion) ||
9677 aFrame->GetContent()->IsEditable();
9678 };
9679
9680 // Skip br frames, but only if we can select something before hitting the
9681 // end of the line or a non-selectable region.
9682 if (atLineEdge && aDirection == eDirPrevious &&
9683 traversedFrame->IsBrFrame()) {
9684 for (nsIFrame* current = traversedFrame->GetPrevSibling(); current;
9685 current = current->GetPrevSibling()) {
9686 if (!current->IsBlockOutside() && IsSelectable(current)) {
9687 if (!current->IsBrFrame()) {
9688 result.mIgnoredBrFrame = true;
9689 }
9690 break;
9691 }
9692 }
9693 if (result.mIgnoredBrFrame) {
9694 continue;
9695 }
9696 }
9697
9698 selectable = IsSelectable(traversedFrame);
9699 if (!selectable) {
9700 if (traversedFrame->IsSelectable(nullptr)) {
9701 result.mHasSelectableFrame = true;
9702 }
9703 result.mMovedOverNonSelectableText = true;
9704 }
9705 } // while (!selectable)
9706
9707 result.mOffset = (aDirection == eDirNext) ? 0 : -1;
9708
9709 if (aOptions.contains(PeekOffsetOption::Visual) &&
9710 nsBidiPresUtils::IsReversedDirectionFrame(traversedFrame)) {
9711 // The new frame is reverse-direction, go to the other end
9712 result.mOffset = -1 - result.mOffset;
9713 }
9714 result.mFrame = traversedFrame;
9715 return result;
9716}
9717
9718nsIFrame::SelectablePeekReport nsIFrame::GetFrameFromDirection(
9719 const PeekOffsetStruct& aPos) {
9720 return GetFrameFromDirection(aPos.mDirection, aPos.mOptions);
9721}
9722
9723nsView* nsIFrame::GetClosestView(nsPoint* aOffset) const {
9724 nsPoint offset(0, 0);
9725 for (const nsIFrame* f = this; f; f = f->GetParent()) {
9726 if (f->HasView()) {
9727 if (aOffset) *aOffset = offset;
9728 return f->GetView();
9729 }
9730 offset += f->GetPosition();
9731 }
9732
9733 MOZ_ASSERT_UNREACHABLE("No view on any parent? How did that happen?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"No view on any parent? How did that happen?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9733); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "No view on any parent? How did that happen?"
")"); do { *((volatile int*)__null) = 9733; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9734 return nullptr;
9735}
9736
9737/* virtual */
9738void nsIFrame::ChildIsDirty(nsIFrame* aChild) {
9739 MOZ_ASSERT_UNREACHABLE(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"should never be called on a frame that doesn't " "inherit from nsContainerFrame"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9741); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should never be called on a frame that doesn't "
"inherit from nsContainerFrame" ")"); do { *((volatile int*)
__null) = 9741; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
9740 "should never be called on a frame that doesn't "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"should never be called on a frame that doesn't " "inherit from nsContainerFrame"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9741); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should never be called on a frame that doesn't "
"inherit from nsContainerFrame" ")"); do { *((volatile int*)
__null) = 9741; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
9741 "inherit from nsContainerFrame")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"should never be called on a frame that doesn't " "inherit from nsContainerFrame"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9741); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should never be called on a frame that doesn't "
"inherit from nsContainerFrame" ")"); do { *((volatile int*)
__null) = 9741; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
9742}
9743
9744#ifdef ACCESSIBILITY1
9745a11y::AccType nsIFrame::AccessibleType() {
9746 if (IsTableCaption() && !GetRect().IsEmpty()) {
9747 return a11y::eHTMLCaptionType;
9748 }
9749 return a11y::eNoType;
9750}
9751#endif
9752
9753bool nsIFrame::ClearOverflowRects() {
9754 if (mOverflow.mType == OverflowStorageType::None) {
9755 return false;
9756 }
9757 if (mOverflow.mType == OverflowStorageType::Large) {
9758 RemoveProperty(OverflowAreasProperty());
9759 }
9760 mOverflow.mType = OverflowStorageType::None;
9761 return true;
9762}
9763
9764bool nsIFrame::SetOverflowAreas(const OverflowAreas& aOverflowAreas) {
9765 if (mOverflow.mType == OverflowStorageType::Large) {
9766 OverflowAreas* overflow = GetOverflowAreasProperty();
9767 bool changed = *overflow != aOverflowAreas;
9768 *overflow = aOverflowAreas;
9769
9770 // Don't bother with converting to the deltas form if we already
9771 // have a property.
9772 return changed;
9773 }
9774
9775 const nsRect& vis = aOverflowAreas.InkOverflow();
9776 uint32_t l = -vis.x, // left edge: positive delta is leftwards
9777 t = -vis.y, // top: positive is upwards
9778 r = vis.XMost() - mRect.width, // right: positive is rightwards
9779 b = vis.YMost() - mRect.height; // bottom: positive is downwards
9780 if (aOverflowAreas.ScrollableOverflow().IsEqualEdges(
9781 nsRect(nsPoint(0, 0), GetSize())) &&
9782 l <= InkOverflowDeltas::kMax && t <= InkOverflowDeltas::kMax &&
9783 r <= InkOverflowDeltas::kMax && b <= InkOverflowDeltas::kMax &&
9784 // we have to check these against zero because we *never* want to
9785 // set a frame as having no overflow in this function. This is
9786 // because FinishAndStoreOverflow calls this function prior to
9787 // SetRect based on whether the overflow areas match aNewSize.
9788 // In the case where the overflow areas exactly match mRect but
9789 // do not match aNewSize, we need to store overflow in a property
9790 // so that our eventual SetRect/SetSize will know that it has to
9791 // reset our overflow areas.
9792 (l | t | r | b) != 0) {
9793 InkOverflowDeltas oldDeltas = mOverflow.mInkOverflowDeltas;
9794 // It's a "small" overflow area so we store the deltas for each edge
9795 // directly in the frame, rather than allocating a separate rect.
9796 // If they're all zero, that's fine; we're setting things to
9797 // no-overflow.
9798 mOverflow.mInkOverflowDeltas.mLeft = l;
9799 mOverflow.mInkOverflowDeltas.mTop = t;
9800 mOverflow.mInkOverflowDeltas.mRight = r;
9801 mOverflow.mInkOverflowDeltas.mBottom = b;
9802 // There was no scrollable overflow before, and there isn't now.
9803 return oldDeltas != mOverflow.mInkOverflowDeltas;
9804 } else {
9805 bool changed =
9806 !aOverflowAreas.ScrollableOverflow().IsEqualEdges(
9807 nsRect(nsPoint(0, 0), GetSize())) ||
9808 !aOverflowAreas.InkOverflow().IsEqualEdges(InkOverflowFromDeltas());
9809
9810 // it's a large overflow area that we need to store as a property
9811 mOverflow.mType = OverflowStorageType::Large;
9812 AddProperty(OverflowAreasProperty(), new OverflowAreas(aOverflowAreas));
9813 return changed;
9814 }
9815}
9816
9817enum class ApplyTransform : bool { No, Yes };
9818
9819/**
9820 * Compute the outline inner rect (so without outline-width and outline-offset)
9821 * of aFrame, maybe iterating over its descendants, in aFrame's coordinate space
9822 * or its post-transform coordinate space (depending on aApplyTransform).
9823 */
9824static nsRect ComputeOutlineInnerRect(
9825 nsIFrame* aFrame, ApplyTransform aApplyTransform, bool& aOutValid,
9826 const nsSize* aSizeOverride = nullptr,
9827 const OverflowAreas* aOverflowOverride = nullptr) {
9828 const nsRect bounds(nsPoint(0, 0),
9829 aSizeOverride ? *aSizeOverride : aFrame->GetSize());
9830
9831 // The SVG container frames besides SVGTextFrame do not maintain
9832 // an accurate mRect. It will make the outline be larger than
9833 // we expect, we need to make them narrow to their children's outline.
9834 // aOutValid is set to false if the returned nsRect is not valid
9835 // and should not be included in the outline rectangle.
9836 aOutValid = !aFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT) ||
9837 !aFrame->IsSVGContainerFrame() || aFrame->IsSVGTextFrame();
9838
9839 nsRect u;
9840
9841 if (!aFrame->FrameMaintainsOverflow()) {
9842 return u;
9843 }
9844
9845 // Start from our border-box, transformed. See comment below about
9846 // transform of children.
9847 bool doTransform =
9848 aApplyTransform == ApplyTransform::Yes && aFrame->IsTransformed();
9849 TransformReferenceBox boundsRefBox(nullptr, bounds);
9850 if (doTransform) {
9851 u = nsDisplayTransform::TransformRect(bounds, aFrame, boundsRefBox);
9852 } else {
9853 u = bounds;
9854 }
9855
9856 if (aOutValid && !StaticPrefs::layout_outline_include_overflow()) {
9857 return u;
9858 }
9859
9860 // Only iterate through the children if the overflow areas suggest
9861 // that we might need to, and if the frame doesn't clip its overflow
9862 // anyway.
9863 if (aOverflowOverride) {
9864 if (!doTransform && bounds.IsEqualEdges(aOverflowOverride->InkOverflow()) &&
9865 bounds.IsEqualEdges(aOverflowOverride->ScrollableOverflow())) {
9866 return u;
9867 }
9868 } else {
9869 if (!doTransform && bounds.IsEqualEdges(aFrame->InkOverflowRect()) &&
9870 bounds.IsEqualEdges(aFrame->ScrollableOverflowRect())) {
9871 return u;
9872 }
9873 }
9874 const nsStyleDisplay* disp = aFrame->StyleDisplay();
9875 LayoutFrameType fType = aFrame->Type();
9876 if (fType == LayoutFrameType::Scroll ||
9877 fType == LayoutFrameType::ListControl ||
9878 fType == LayoutFrameType::SVGOuterSVG) {
9879 return u;
9880 }
9881
9882 auto overflowClipAxes = aFrame->ShouldApplyOverflowClipping(disp);
9883 auto overflowClipMargin = aFrame->OverflowClipMargin(overflowClipAxes);
9884 if (overflowClipAxes == nsIFrame::PhysicalAxes::Both &&
9885 overflowClipMargin == nsSize()) {
9886 return u;
9887 }
9888
9889 const nsStyleEffects* effects = aFrame->StyleEffects();
9890 Maybe<nsRect> clipPropClipRect =
9891 aFrame->GetClipPropClipRect(disp, effects, bounds.Size());
9892
9893 // Iterate over all children except pop-up, absolutely-positioned,
9894 // float, and overflow ones.
9895 const FrameChildListIDs skip = {
9896 FrameChildListID::Popup, FrameChildListID::Absolute,
9897 FrameChildListID::Fixed, FrameChildListID::Float,
9898 FrameChildListID::Overflow};
9899 for (const auto& [list, listID] : aFrame->ChildLists()) {
9900 if (skip.contains(listID)) {
9901 continue;
9902 }
9903
9904 for (nsIFrame* child : list) {
9905 if (child->IsPlaceholderFrame()) {
9906 continue;
9907 }
9908
9909 // Note that passing ApplyTransform::Yes when
9910 // child->Combines3DTransformWithAncestors() returns true is incorrect if
9911 // our aApplyTransform is No... but the opposite would be as well.
9912 // This is because elements within a preserve-3d scene are always
9913 // transformed up to the top of the scene. This means we don't have a
9914 // mechanism for getting a transform up to an intermediate point within
9915 // the scene. We choose to over-transform rather than under-transform
9916 // because this is consistent with other overflow areas.
9917 bool validRect = true;
9918 nsRect childRect =
9919 ComputeOutlineInnerRect(child, ApplyTransform::Yes, validRect) +
9920 child->GetPosition();
9921
9922 if (!validRect) {
9923 continue;
9924 }
9925
9926 if (clipPropClipRect) {
9927 // Intersect with the clip before transforming.
9928 childRect.IntersectRect(childRect, *clipPropClipRect);
9929 }
9930
9931 // Note that we transform each child separately according to
9932 // aFrame's transform, and then union, which gives a different
9933 // (smaller) result from unioning and then transforming the
9934 // union. This doesn't match the way we handle overflow areas
9935 // with 2-D transforms, though it does match the way we handle
9936 // overflow areas in preserve-3d 3-D scenes.
9937 if (doTransform && !child->Combines3DTransformWithAncestors()) {
9938 childRect =
9939 nsDisplayTransform::TransformRect(childRect, aFrame, boundsRefBox);
9940 }
9941
9942 // If a SVGContainer has a non-SVGContainer child, we assign
9943 // its child's outline to this SVGContainer directly.
9944 if (!aOutValid && validRect) {
9945 u = childRect;
9946 aOutValid = true;
9947 } else {
9948 u = u.UnionEdges(childRect);
9949 }
9950 }
9951 }
9952
9953 if (overflowClipAxes != nsIFrame::PhysicalAxes::None) {
9954 OverflowAreas::ApplyOverflowClippingOnRect(u, bounds, overflowClipAxes,
9955 overflowClipMargin);
9956 }
9957 return u;
9958}
9959
9960static void ComputeAndIncludeOutlineArea(nsIFrame* aFrame,
9961 OverflowAreas& aOverflowAreas,
9962 const nsSize& aNewSize) {
9963 const nsStyleOutline* outline = aFrame->StyleOutline();
9964 if (!outline->ShouldPaintOutline()) {
9965 return;
9966 }
9967
9968 // When the outline property is set on a :-moz-block-inside-inline-wrapper
9969 // pseudo-element, it inherited that outline from the inline that was broken
9970 // because it contained a block. In that case, we don't want a really wide
9971 // outline if the block inside the inline is narrow, so union the actual
9972 // contents of the anonymous blocks.
9973 nsIFrame* frameForArea = aFrame;
9974 do {
9975 PseudoStyleType pseudoType = frameForArea->Style()->GetPseudoType();
9976 if (pseudoType != PseudoStyleType::mozBlockInsideInlineWrapper) break;
9977 // If we're done, we really want it and all its later siblings.
9978 frameForArea = frameForArea->PrincipalChildList().FirstChild();
9979 NS_ASSERTION(frameForArea, "anonymous block with no children?")do { if (!(frameForArea)) { NS_DebugBreak(NS_DEBUG_ASSERTION,
"anonymous block with no children?", "frameForArea", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 9979); MOZ_PretendNoReturn(); } } while (0)
;
9980 } while (frameForArea);
9981
9982 // Find the union of the border boxes of all descendants, or in
9983 // the block-in-inline case, all descendants we care about.
9984 //
9985 // Note that the interesting perspective-related cases are taken
9986 // care of by the code that handles those issues for overflow
9987 // calling FinishAndStoreOverflow again, which in turn calls this
9988 // function again. We still need to deal with preserve-3d a bit.
9989 nsRect innerRect;
9990 bool validRect = false;
9991 if (frameForArea == aFrame) {
9992 innerRect = ComputeOutlineInnerRect(aFrame, ApplyTransform::No, validRect,
9993 &aNewSize, &aOverflowAreas);
9994 } else {
9995 for (; frameForArea; frameForArea = frameForArea->GetNextSibling()) {
9996 nsRect r =
9997 ComputeOutlineInnerRect(frameForArea, ApplyTransform::Yes, validRect);
9998
9999 // Adjust for offsets transforms up to aFrame's pre-transform
10000 // (i.e., normal) coordinate space; see comments in
10001 // UnionBorderBoxes for some of the subtlety here.
10002 for (nsIFrame *f = frameForArea, *parent = f->GetParent();
10003 /* see middle of loop */; f = parent, parent = f->GetParent()) {
10004 r += f->GetPosition();
10005 if (parent == aFrame) {
10006 break;
10007 }
10008 if (parent->IsTransformed() && !f->Combines3DTransformWithAncestors()) {
10009 TransformReferenceBox refBox(parent);
10010 r = nsDisplayTransform::TransformRect(r, parent, refBox);
10011 }
10012 }
10013
10014 innerRect.UnionRect(innerRect, r);
10015 }
10016 }
10017
10018 // Keep this code in sync with nsDisplayOutline::GetInnerRect.
10019 if (innerRect == aFrame->GetRectRelativeToSelf()) {
10020 aFrame->RemoveProperty(nsIFrame::OutlineInnerRectProperty());
10021 } else {
10022 SetOrUpdateRectValuedProperty(aFrame, nsIFrame::OutlineInnerRectProperty(),
10023 innerRect);
10024 }
10025
10026 nsRect outerRect(innerRect);
10027 outerRect.Inflate(outline->EffectiveOffsetFor(outerRect));
10028
10029 if (outline->mOutlineStyle.IsAuto()) {
10030 nsPresContext* pc = aFrame->PresContext();
10031
10032 pc->Theme()->GetWidgetOverflow(pc->DeviceContext(), aFrame,
10033 StyleAppearance::FocusOutline, &outerRect);
10034 } else {
10035 const nscoord width = outline->GetOutlineWidth();
10036 outerRect.Inflate(width);
10037 }
10038
10039 nsRect& vo = aOverflowAreas.InkOverflow();
10040 vo = vo.UnionEdges(innerRect.Union(outerRect));
10041}
10042
10043bool nsIFrame::FinishAndStoreOverflow(OverflowAreas& aOverflowAreas,
10044 nsSize aNewSize, nsSize* aOldSize,
10045 const nsStyleDisplay* aStyleDisplay) {
10046 MOZ_ASSERT(FrameMaintainsOverflow(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(FrameMaintainsOverflow())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(FrameMaintainsOverflow()))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("FrameMaintainsOverflow()"
" (" "Don't call - overflow rects not maintained on these SVG frames"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10047); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Don't call - overflow rects not maintained on these SVG frames"
")"); do { *((volatile int*)__null) = 10047; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
10047 "Don't call - overflow rects not maintained on these SVG frames")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(FrameMaintainsOverflow())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(FrameMaintainsOverflow()))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("FrameMaintainsOverflow()"
" (" "Don't call - overflow rects not maintained on these SVG frames"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10047); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Don't call - overflow rects not maintained on these SVG frames"
")"); do { *((volatile int*)__null) = 10047; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10048
10049 const nsStyleDisplay* disp = StyleDisplayWithOptionalParam(aStyleDisplay);
10050 bool hasTransform = IsTransformed();
10051
10052 nsRect bounds(nsPoint(0, 0), aNewSize);
10053 // Store the passed in overflow area if we are a preserve-3d frame or we have
10054 // a transform, and it's not just the frame bounds.
10055 if (hasTransform || Combines3DTransformWithAncestors()) {
10056 if (!aOverflowAreas.InkOverflow().IsEqualEdges(bounds) ||
10057 !aOverflowAreas.ScrollableOverflow().IsEqualEdges(bounds)) {
10058 OverflowAreas* initial = GetProperty(nsIFrame::InitialOverflowProperty());
10059 if (!initial) {
10060 AddProperty(nsIFrame::InitialOverflowProperty(),
10061 new OverflowAreas(aOverflowAreas));
10062 } else if (initial != &aOverflowAreas) {
10063 *initial = aOverflowAreas;
10064 }
10065 } else {
10066 RemoveProperty(nsIFrame::InitialOverflowProperty());
10067 }
10068#ifdef DEBUG1
10069 SetProperty(nsIFrame::DebugInitialOverflowPropertyApplied(), true);
10070#endif
10071 } else {
10072#ifdef DEBUG1
10073 RemoveProperty(nsIFrame::DebugInitialOverflowPropertyApplied());
10074#endif
10075 }
10076
10077 nsSize oldSize = mRect.Size();
10078 bool sizeChanged = ((aOldSize ? *aOldSize : oldSize) != aNewSize);
10079
10080 // Our frame size may not have been computed and set yet, but code under
10081 // functions such as ComputeEffectsRect (which we're about to call) use the
10082 // values that are stored in our frame rect to compute their results. We
10083 // need the results from those functions to be based on the frame size that
10084 // we *will* have, so we temporarily set our frame size here before calling
10085 // those functions.
10086 //
10087 // XXX Someone should document here why we revert the frame size before we
10088 // return rather than just leaving it set.
10089 //
10090 // We pass false here to avoid invalidating display items for this temporary
10091 // change. We sometimes reflow frames multiple times, with the final size
10092 // being the same as the initial. The single call to SetSize after reflow is
10093 // done will take care of invalidating display items if the size has actually
10094 // changed.
10095 SetSize(aNewSize, false);
10096
10097 const auto overflowClipAxes = ShouldApplyOverflowClipping(disp);
10098
10099 if (ChildrenHavePerspective(disp) && sizeChanged) {
10100 RecomputePerspectiveChildrenOverflow(this);
10101
10102 if (overflowClipAxes != PhysicalAxes::Both) {
10103 aOverflowAreas.SetAllTo(bounds);
10104 DebugOnly<bool> ok = ComputeCustomOverflow(aOverflowAreas);
10105
10106 // ComputeCustomOverflow() should not return false, when
10107 // FrameMaintainsOverflow() returns true.
10108 MOZ_ASSERT(ok, "FrameMaintainsOverflow() != ComputeCustomOverflow()")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(ok)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(ok))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("ok" " (" "FrameMaintainsOverflow() != ComputeCustomOverflow()"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10108); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ok" ") (" "FrameMaintainsOverflow() != ComputeCustomOverflow()"
")"); do { *((volatile int*)__null) = 10108; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10109
10110 UnionChildOverflow(aOverflowAreas);
10111 }
10112 }
10113
10114 // This is now called FinishAndStoreOverflow() instead of
10115 // StoreOverflow() because frame-generic ways of adding overflow
10116 // can happen here, e.g. CSS2 outline and native theme.
10117 // If the overflow area width or height is nscoord_MAX, then a
10118 // saturating union may have encounted an overflow, so the overflow may not
10119 // contain the frame border-box. Don't warn in that case.
10120 // Don't warn for SVG either, since SVG doesn't need the overflow area
10121 // to contain the frame bounds.
10122 for (const auto otype : AllOverflowTypes()) {
10123 DebugOnly<nsRect*> r = &aOverflowAreas.Overflow(otype);
10124 NS_ASSERTION(aNewSize.width == 0 || aNewSize.height == 0 ||do { if (!(aNewSize.width == 0 || aNewSize.height == 0 || r->
width == nscoord((1 << 30) - 1) || r->height == nscoord
((1 << 30) - 1) || HasAnyStateBits(NS_FRAME_SVG_LAYOUT)
|| r->Contains(nsRect(nsPoint(0, 0), aNewSize)))) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Computed overflow area must contain frame bounds"
, "aNewSize.width == 0 || aNewSize.height == 0 || r->width == nscoord_MAX || r->height == nscoord_MAX || HasAnyStateBits(NS_FRAME_SVG_LAYOUT) || r->Contains(nsRect(nsPoint(0, 0), aNewSize))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10128); MOZ_PretendNoReturn(); } } while (0)
10125 r->width == nscoord_MAX || r->height == nscoord_MAX ||do { if (!(aNewSize.width == 0 || aNewSize.height == 0 || r->
width == nscoord((1 << 30) - 1) || r->height == nscoord
((1 << 30) - 1) || HasAnyStateBits(NS_FRAME_SVG_LAYOUT)
|| r->Contains(nsRect(nsPoint(0, 0), aNewSize)))) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Computed overflow area must contain frame bounds"
, "aNewSize.width == 0 || aNewSize.height == 0 || r->width == nscoord_MAX || r->height == nscoord_MAX || HasAnyStateBits(NS_FRAME_SVG_LAYOUT) || r->Contains(nsRect(nsPoint(0, 0), aNewSize))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10128); MOZ_PretendNoReturn(); } } while (0)
10126 HasAnyStateBits(NS_FRAME_SVG_LAYOUT) ||do { if (!(aNewSize.width == 0 || aNewSize.height == 0 || r->
width == nscoord((1 << 30) - 1) || r->height == nscoord
((1 << 30) - 1) || HasAnyStateBits(NS_FRAME_SVG_LAYOUT)
|| r->Contains(nsRect(nsPoint(0, 0), aNewSize)))) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Computed overflow area must contain frame bounds"
, "aNewSize.width == 0 || aNewSize.height == 0 || r->width == nscoord_MAX || r->height == nscoord_MAX || HasAnyStateBits(NS_FRAME_SVG_LAYOUT) || r->Contains(nsRect(nsPoint(0, 0), aNewSize))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10128); MOZ_PretendNoReturn(); } } while (0)
10127 r->Contains(nsRect(nsPoint(0, 0), aNewSize)),do { if (!(aNewSize.width == 0 || aNewSize.height == 0 || r->
width == nscoord((1 << 30) - 1) || r->height == nscoord
((1 << 30) - 1) || HasAnyStateBits(NS_FRAME_SVG_LAYOUT)
|| r->Contains(nsRect(nsPoint(0, 0), aNewSize)))) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Computed overflow area must contain frame bounds"
, "aNewSize.width == 0 || aNewSize.height == 0 || r->width == nscoord_MAX || r->height == nscoord_MAX || HasAnyStateBits(NS_FRAME_SVG_LAYOUT) || r->Contains(nsRect(nsPoint(0, 0), aNewSize))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10128); MOZ_PretendNoReturn(); } } while (0)
10128 "Computed overflow area must contain frame bounds")do { if (!(aNewSize.width == 0 || aNewSize.height == 0 || r->
width == nscoord((1 << 30) - 1) || r->height == nscoord
((1 << 30) - 1) || HasAnyStateBits(NS_FRAME_SVG_LAYOUT)
|| r->Contains(nsRect(nsPoint(0, 0), aNewSize)))) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Computed overflow area must contain frame bounds"
, "aNewSize.width == 0 || aNewSize.height == 0 || r->width == nscoord_MAX || r->height == nscoord_MAX || HasAnyStateBits(NS_FRAME_SVG_LAYOUT) || r->Contains(nsRect(nsPoint(0, 0), aNewSize))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10128); MOZ_PretendNoReturn(); } } while (0)
;
10129 }
10130
10131 // Overflow area must always include the frame's top-left and bottom-right,
10132 // even if the frame rect is empty (so we can scroll to those positions).
10133 const bool shouldIncludeBounds = [&] {
10134 if (aNewSize.width == 0 && IsInlineFrame()) {
10135 // Pending a real fix for bug 426879, don't do this for inline frames with
10136 // zero width.
10137 return false;
10138 }
10139 if (HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
10140 // Do not do this for SVG either, since it will usually massively increase
10141 // the area unnecessarily (except for SVG that applies clipping, since
10142 // that's the pre-existing behavior, and breaks pre-rendering otherwise).
10143 // FIXME(bug 1770704): This check most likely wants to be removed or check
10144 // for specific frame types at least.
10145 return overflowClipAxes != PhysicalAxes::None;
10146 }
10147 return true;
10148 }();
10149
10150 if (shouldIncludeBounds) {
10151 for (const auto otype : AllOverflowTypes()) {
10152 nsRect& o = aOverflowAreas.Overflow(otype);
10153 o = o.UnionEdges(bounds);
10154 }
10155 }
10156
10157 // If we clip our children, clear accumulated overflow area in the affected
10158 // dimension(s). The children are actually clipped to the padding-box, but
10159 // since the overflow area should include the entire border-box, just set it
10160 // to the border-box size here.
10161 if (overflowClipAxes != PhysicalAxes::None) {
10162 aOverflowAreas.ApplyClipping(bounds, overflowClipAxes,
10163 OverflowClipMargin(overflowClipAxes));
10164 }
10165
10166 ComputeAndIncludeOutlineArea(this, aOverflowAreas, aNewSize);
10167
10168 // Nothing in here should affect scrollable overflow.
10169 aOverflowAreas.InkOverflow() =
10170 ComputeEffectsRect(this, aOverflowAreas.InkOverflow(), aNewSize);
10171
10172 // Absolute position clipping
10173 const nsStyleEffects* effects = StyleEffects();
10174 Maybe<nsRect> clipPropClipRect = GetClipPropClipRect(disp, effects, aNewSize);
10175 if (clipPropClipRect) {
10176 for (const auto otype : AllOverflowTypes()) {
10177 nsRect& o = aOverflowAreas.Overflow(otype);
10178 o.IntersectRect(o, *clipPropClipRect);
10179 }
10180 }
10181
10182 /* If we're transformed, transform the overflow rect by the current
10183 * transformation. */
10184 if (hasTransform) {
10185 SetProperty(nsIFrame::PreTransformOverflowAreasProperty(),
10186 new OverflowAreas(aOverflowAreas));
10187
10188 if (Combines3DTransformWithAncestors()) {
10189 /* If we're a preserve-3d leaf frame, then our pre-transform overflow
10190 * should be correct. Our post-transform overflow is empty though, because
10191 * we only contribute to the overflow area of the preserve-3d root frame.
10192 * If we're an intermediate frame then the pre-transform overflow should
10193 * contain all our non-preserve-3d children, which is what we want. Again
10194 * we have no post-transform overflow.
10195 */
10196 aOverflowAreas.SetAllTo(nsRect());
10197 } else {
10198 TransformReferenceBox refBox(this);
10199 for (const auto otype : AllOverflowTypes()) {
10200 nsRect& o = aOverflowAreas.Overflow(otype);
10201 o = nsDisplayTransform::TransformRect(o, this, refBox);
10202 }
10203
10204 /* If we're the root of the 3d context, then we want to include the
10205 * overflow areas of all the participants. This won't have happened yet as
10206 * the code above set their overflow area to empty. Manually collect these
10207 * overflow areas now.
10208 */
10209 if (Extend3DContext(disp, effects)) {
10210 ComputePreserve3DChildrenOverflow(aOverflowAreas);
10211 }
10212 }
10213 } else {
10214 RemoveProperty(nsIFrame::PreTransformOverflowAreasProperty());
10215 }
10216
10217 /* Revert the size change in case some caller is depending on this. */
10218 SetSize(oldSize, false);
10219
10220 bool anyOverflowChanged;
10221 if (aOverflowAreas != OverflowAreas(bounds, bounds)) {
10222 anyOverflowChanged = SetOverflowAreas(aOverflowAreas);
10223 } else {
10224 anyOverflowChanged = ClearOverflowRects();
10225 }
10226
10227 if (anyOverflowChanged) {
10228 SVGObserverUtils::InvalidateDirectRenderingObservers(this);
10229 if (nsBlockFrame* block = do_QueryFrame(this)) {
10230 // NOTE(emilio): we need to use BeforeReflow::Yes, because we want to
10231 // invalidate in cases where we _used_ to have an overflow marker and no
10232 // longer do.
10233 if (TextOverflow::CanHaveOverflowMarkers(
10234 block, TextOverflow::BeforeReflow::Yes)) {
10235 DiscardDisplayItems(this, [](nsDisplayItem* aItem) {
10236 return aItem->GetType() == DisplayItemType::TYPE_TEXT_OVERFLOW;
10237 });
10238 SchedulePaint(PAINT_DEFAULT);
10239 }
10240 }
10241 }
10242 return anyOverflowChanged;
10243}
10244
10245void nsIFrame::RecomputePerspectiveChildrenOverflow(
10246 const nsIFrame* aStartFrame) {
10247 for (const auto& childList : ChildLists()) {
10248 for (nsIFrame* child : childList.mList) {
10249 if (!child->FrameMaintainsOverflow()) {
10250 continue; // frame does not maintain overflow rects
10251 }
10252 if (child->HasPerspective()) {
10253 OverflowAreas* overflow =
10254 child->GetProperty(nsIFrame::InitialOverflowProperty());
10255 nsRect bounds(nsPoint(0, 0), child->GetSize());
10256 if (overflow) {
10257 OverflowAreas overflowCopy = *overflow;
10258 child->FinishAndStoreOverflow(overflowCopy, bounds.Size());
10259 } else {
10260 OverflowAreas boundsOverflow;
10261 boundsOverflow.SetAllTo(bounds);
10262 child->FinishAndStoreOverflow(boundsOverflow, bounds.Size());
10263 }
10264 } else if (child->GetContent() == aStartFrame->GetContent() ||
10265 child->GetClosestFlattenedTreeAncestorPrimaryFrame() ==
10266 aStartFrame) {
10267 // If a frame is using perspective, then the size used to compute
10268 // perspective-origin is the size of the frame belonging to its parent
10269 // style. We must find any descendant frames using our size
10270 // (by recursing into frames that have the same containing block)
10271 // to update their overflow rects too.
10272 child->RecomputePerspectiveChildrenOverflow(aStartFrame);
10273 }
10274 }
10275 }
10276}
10277
10278void nsIFrame::ComputePreserve3DChildrenOverflow(
10279 OverflowAreas& aOverflowAreas) {
10280 // Find all descendants that participate in the 3d context, and include their
10281 // overflow. These descendants have an empty overflow, so won't have been
10282 // included in the normal overflow calculation. Any children that don't
10283 // participate have normal overflow, so will have been included already.
10284
10285 nsRect childVisual;
10286 nsRect childScrollable;
10287 for (const auto& childList : ChildLists()) {
10288 for (nsIFrame* child : childList.mList) {
10289 // If this child participates in the 3d context, then take the
10290 // pre-transform region (which contains all descendants that aren't
10291 // participating in the 3d context) and transform it into the 3d context
10292 // root coordinate space.
10293 if (child->Combines3DTransformWithAncestors()) {
10294 OverflowAreas childOverflow = child->GetOverflowAreasRelativeToSelf();
10295 TransformReferenceBox refBox(child);
10296 for (const auto otype : AllOverflowTypes()) {
10297 nsRect& o = childOverflow.Overflow(otype);
10298 o = nsDisplayTransform::TransformRect(o, child, refBox);
10299 }
10300
10301 aOverflowAreas.UnionWith(childOverflow);
10302
10303 // If this child also extends the 3d context, then recurse into it
10304 // looking for more participants.
10305 if (child->Extend3DContext()) {
10306 child->ComputePreserve3DChildrenOverflow(aOverflowAreas);
10307 }
10308 }
10309 }
10310 }
10311}
10312
10313bool nsIFrame::ZIndexApplies() const {
10314 return StyleDisplay()->IsPositionedStyle() || IsFlexOrGridItem() ||
10315 IsMenuPopupFrame();
10316}
10317
10318Maybe<int32_t> nsIFrame::ZIndex() const {
10319 if (!ZIndexApplies()) {
10320 return Nothing();
10321 }
10322 const auto& zIndex = StylePosition()->mZIndex;
10323 if (zIndex.IsAuto()) {
10324 return Nothing();
10325 }
10326 return Some(zIndex.AsInteger());
10327}
10328
10329bool nsIFrame::IsScrollAnchor(ScrollAnchorContainer** aOutContainer) {
10330 if (!mInScrollAnchorChain) {
10331 return false;
10332 }
10333
10334 nsIFrame* f = this;
10335
10336 // FIXME(emilio, bug 1629280): We should find a non-null anchor if we have the
10337 // flag set, but bug 1629280 makes it so that we cannot really assert it /
10338 // make this just a `while (true)`, and uncomment the below assertion.
10339 while (auto* container = ScrollAnchorContainer::FindFor(f)) {
10340 // MOZ_ASSERT(f->IsInScrollAnchorChain());
10341 if (nsIFrame* anchor = container->AnchorNode()) {
10342 if (anchor != this) {
10343 return false;
10344 }
10345 if (aOutContainer) {
10346 *aOutContainer = container;
10347 }
10348 return true;
10349 }
10350
10351 f = container->Frame();
10352 }
10353
10354 return false;
10355}
10356
10357bool nsIFrame::IsInScrollAnchorChain() const { return mInScrollAnchorChain; }
10358
10359void nsIFrame::SetInScrollAnchorChain(bool aInChain) {
10360 mInScrollAnchorChain = aInChain;
10361}
10362
10363uint32_t nsIFrame::GetDepthInFrameTree() const {
10364 uint32_t result = 0;
10365 for (nsContainerFrame* ancestor = GetParent(); ancestor;
10366 ancestor = ancestor->GetParent()) {
10367 result++;
10368 }
10369 return result;
10370}
10371
10372/**
10373 * This function takes a frame that is part of a block-in-inline split,
10374 * and _if_ that frame is an anonymous block created by an ib split it
10375 * returns the block's preceding inline. This is needed because the
10376 * split inline's style is the parent of the anonymous block's style.
10377 *
10378 * If aFrame is not an anonymous block, null is returned.
10379 */
10380static nsIFrame* GetIBSplitSiblingForAnonymousBlock(const nsIFrame* aFrame) {
10381 MOZ_ASSERT(aFrame, "Must have a non-null frame!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aFrame)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aFrame))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aFrame" " (" "Must have a non-null frame!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10381); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame" ") ("
"Must have a non-null frame!" ")"); do { *((volatile int*)__null
) = 10381; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
10382 NS_ASSERTION(aFrame->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT),do { if (!(aFrame->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "GetIBSplitSibling should only be called on ib-split frames"
, "aFrame->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10383); MOZ_PretendNoReturn(); } } while (0)
10383 "GetIBSplitSibling should only be called on ib-split frames")do { if (!(aFrame->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT
))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "GetIBSplitSibling should only be called on ib-split frames"
, "aFrame->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10383); MOZ_PretendNoReturn(); } } while (0)
;
10384
10385 if (aFrame->Style()->GetPseudoType() !=
10386 PseudoStyleType::mozBlockInsideInlineWrapper) {
10387 // it's not an anonymous block
10388 return nullptr;
10389 }
10390
10391 // Find the first continuation of the frame. (Ugh. This ends up
10392 // being O(N^2) when it is called O(N) times.)
10393 aFrame = aFrame->FirstContinuation();
10394
10395 /*
10396 * Now look up the nsGkAtoms::IBSplitPrevSibling
10397 * property.
10398 */
10399 nsIFrame* ibSplitSibling =
10400 aFrame->GetProperty(nsIFrame::IBSplitPrevSibling());
10401 NS_ASSERTION(ibSplitSibling, "Broken frame tree?")do { if (!(ibSplitSibling)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "Broken frame tree?", "ibSplitSibling", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10401); MOZ_PretendNoReturn(); } } while (0)
;
10402 return ibSplitSibling;
10403}
10404
10405/**
10406 * Get the parent, corrected for the mangled frame tree resulting from
10407 * having a block within an inline. The result only differs from the
10408 * result of |GetParent| when |GetParent| returns an anonymous block
10409 * that was created for an element that was 'display: inline' because
10410 * that element contained a block.
10411 *
10412 * Also skip anonymous scrolled-content parents; inherit directly from the
10413 * outer scroll frame.
10414 *
10415 * Also skip NAC parents if the child frame is NAC.
10416 */
10417static nsIFrame* GetCorrectedParent(const nsIFrame* aFrame) {
10418 nsIFrame* parent = aFrame->GetParent();
10419 if (!parent) {
10420 return nullptr;
10421 }
10422
10423 // For a table caption we want the _inner_ table frame (unless it's anonymous)
10424 // as the style parent.
10425 if (aFrame->IsTableCaption()) {
10426 nsIFrame* innerTable = parent->PrincipalChildList().FirstChild();
10427 if (!innerTable->Style()->IsAnonBox()) {
10428 return innerTable;
10429 }
10430 }
10431
10432 // Table wrappers are always anon boxes; if we're in here for an outer
10433 // table, that actually means its the _inner_ table that wants to
10434 // know its parent. So get the pseudo of the inner in that case.
10435 auto pseudo = aFrame->Style()->GetPseudoType();
10436 if (pseudo == PseudoStyleType::tableWrapper) {
10437 pseudo =
10438 aFrame->PrincipalChildList().FirstChild()->Style()->GetPseudoType();
10439 }
10440
10441 // Prevent a NAC pseudo-element from inheriting from its NAC parent, and
10442 // inherit from the NAC generator element instead.
10443 if (pseudo != PseudoStyleType::NotPseudo) {
10444 MOZ_ASSERT(aFrame->GetContent())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aFrame->GetContent())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aFrame->GetContent()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aFrame->GetContent()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10444); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetContent()"
")"); do { *((volatile int*)__null) = 10444; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10445 Element* element = Element::FromNode(aFrame->GetContent());
10446 // Make sure to avoid doing the fixup for non-element-backed pseudos like
10447 // ::first-line and such.
10448 if (element && !element->IsRootOfNativeAnonymousSubtree() &&
10449 element->GetPseudoElementType() == aFrame->Style()->GetPseudoType()) {
10450 while (parent->GetContent() &&
10451 !parent->GetContent()->IsRootOfNativeAnonymousSubtree()) {
10452 parent = parent->GetInFlowParent();
10453 }
10454 parent = parent->GetInFlowParent();
10455 }
10456 }
10457
10458 return nsIFrame::CorrectStyleParentFrame(parent, pseudo);
10459}
10460
10461/* static */
10462nsIFrame* nsIFrame::CorrectStyleParentFrame(nsIFrame* aProspectiveParent,
10463 PseudoStyleType aChildPseudo) {
10464 MOZ_ASSERT(aProspectiveParent, "Must have a prospective parent")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aProspectiveParent)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aProspectiveParent))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("aProspectiveParent"
" (" "Must have a prospective parent" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10464); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aProspectiveParent"
") (" "Must have a prospective parent" ")"); do { *((volatile
int*)__null) = 10464; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
10465
10466 if (aChildPseudo != PseudoStyleType::NotPseudo) {
10467 // Non-inheriting anon boxes have no style parent frame at all.
10468 if (PseudoStyle::IsNonInheritingAnonBox(aChildPseudo)) {
10469 return nullptr;
10470 }
10471
10472 // Other anon boxes are parented to their actual parent already, except
10473 // for non-elements. Those should not be treated as an anon box.
10474 if (PseudoStyle::IsAnonBox(aChildPseudo) &&
10475 !nsCSSAnonBoxes::IsNonElement(aChildPseudo)) {
10476 NS_ASSERTION(aChildPseudo != PseudoStyleType::mozBlockInsideInlineWrapper,do { if (!(aChildPseudo != PseudoStyleType::mozBlockInsideInlineWrapper
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Should have dealt with kids that have "
"NS_FRAME_PART_OF_IBSPLIT elsewhere", "aChildPseudo != PseudoStyleType::mozBlockInsideInlineWrapper"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10478); MOZ_PretendNoReturn(); } } while (0)
10477 "Should have dealt with kids that have "do { if (!(aChildPseudo != PseudoStyleType::mozBlockInsideInlineWrapper
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Should have dealt with kids that have "
"NS_FRAME_PART_OF_IBSPLIT elsewhere", "aChildPseudo != PseudoStyleType::mozBlockInsideInlineWrapper"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10478); MOZ_PretendNoReturn(); } } while (0)
10478 "NS_FRAME_PART_OF_IBSPLIT elsewhere")do { if (!(aChildPseudo != PseudoStyleType::mozBlockInsideInlineWrapper
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Should have dealt with kids that have "
"NS_FRAME_PART_OF_IBSPLIT elsewhere", "aChildPseudo != PseudoStyleType::mozBlockInsideInlineWrapper"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10478); MOZ_PretendNoReturn(); } } while (0)
;
10479 return aProspectiveParent;
10480 }
10481 }
10482
10483 // Otherwise, walk up out of all anon boxes. For placeholder frames, walk out
10484 // of all pseudo-elements as well. Otherwise ReparentComputedStyle could
10485 // cause style data to be out of sync with the frame tree.
10486 nsIFrame* parent = aProspectiveParent;
10487 do {
10488 if (parent->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) {
10489 nsIFrame* sibling = GetIBSplitSiblingForAnonymousBlock(parent);
10490
10491 if (sibling) {
10492 // |parent| was a block in an {ib} split; use the inline as
10493 // |the style parent.
10494 parent = sibling;
10495 }
10496 }
10497
10498 if (!parent->Style()->IsPseudoOrAnonBox()) {
10499 return parent;
10500 }
10501
10502 if (!parent->Style()->IsAnonBox() && aChildPseudo != PseudoStyleType::MAX) {
10503 // nsPlaceholderFrame passes in PseudoStyleType::MAX for
10504 // aChildPseudo (even though that's not a valid pseudo-type) just to
10505 // trigger this behavior of walking up to the nearest non-pseudo
10506 // ancestor.
10507 return parent;
10508 }
10509
10510 parent = parent->GetInFlowParent();
10511 } while (parent);
10512
10513 if (aProspectiveParent->Style()->GetPseudoType() ==
10514 PseudoStyleType::viewportScroll) {
10515 // aProspectiveParent is the scrollframe for a viewport
10516 // and the kids are the anonymous scrollbars
10517 return aProspectiveParent;
10518 }
10519
10520 // We can get here if the root element is absolutely positioned.
10521 // We can't test for this very accurately, but it can only happen
10522 // when the prospective parent is a canvas frame.
10523 NS_ASSERTION(aProspectiveParent->IsCanvasFrame(),do { if (!(aProspectiveParent->IsCanvasFrame())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Should have found a parent before this"
, "aProspectiveParent->IsCanvasFrame()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10524); MOZ_PretendNoReturn(); } } while (0)
10524 "Should have found a parent before this")do { if (!(aProspectiveParent->IsCanvasFrame())) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Should have found a parent before this"
, "aProspectiveParent->IsCanvasFrame()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10524); MOZ_PretendNoReturn(); } } while (0)
;
10525 return nullptr;
10526}
10527
10528ComputedStyle* nsIFrame::DoGetParentComputedStyle(
10529 nsIFrame** aProviderFrame) const {
10530 *aProviderFrame = nullptr;
10531
10532 // Handle display:contents and the root frame, when there's no parent frame
10533 // to inherit from.
10534 if (MOZ_LIKELY(mContent)(__builtin_expect(!!(mContent), 1))) {
10535 Element* parentElement = mContent->GetFlattenedTreeParentElement();
10536 if (MOZ_LIKELY(parentElement)(__builtin_expect(!!(parentElement), 1))) {
10537 auto pseudo = Style()->GetPseudoType();
10538 if (pseudo == PseudoStyleType::NotPseudo || !mContent->IsElement() ||
10539 (!PseudoStyle::IsAnonBox(pseudo) &&
10540 // Ensure that we don't return the display:contents style
10541 // of the parent content for pseudos that have the same content
10542 // as their primary frame (like -moz-list-bullets do):
10543 IsPrimaryFrame()) ||
10544 /* if next is true then it's really a request for the table frame's
10545 parent context, see nsTable[Outer]Frame::GetParentComputedStyle. */
10546 pseudo == PseudoStyleType::tableWrapper) {
10547 // In some edge cases involving display: contents, we may end up here
10548 // for something that's pending to be reframed. In this case we return
10549 // the wrong style from here (because we've already lost track of it!),
10550 // but it's not a big deal as we're going to be reframed anyway.
10551 if (MOZ_LIKELY(parentElement->HasServoData())(__builtin_expect(!!(parentElement->HasServoData()), 1)) &&
10552 Servo_Element_IsDisplayContents(parentElement)) {
10553 RefPtr<ComputedStyle> style =
10554 ServoStyleSet::ResolveServoStyle(*parentElement);
10555 // NOTE(emilio): we return a weak reference because the element also
10556 // holds the style context alive. This is a bit silly (we could've
10557 // returned a weak ref directly), but it's probably not worth
10558 // optimizing, given this function has just one caller which is rare,
10559 // and this path is rare itself.
10560 return style;
10561 }
10562 }
10563 } else {
10564 if (Style()->GetPseudoType() == PseudoStyleType::NotPseudo) {
10565 // We're a frame for the root. We have no style parent.
10566 return nullptr;
10567 }
10568 }
10569 }
10570
10571 if (!HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
10572 /*
10573 * If this frame is an anonymous block created when an inline with a block
10574 * inside it got split, then the parent style is on its preceding inline. We
10575 * can get to it using GetIBSplitSiblingForAnonymousBlock.
10576 */
10577 if (HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) {
10578 nsIFrame* ibSplitSibling = GetIBSplitSiblingForAnonymousBlock(this);
10579 if (ibSplitSibling) {
10580 return (*aProviderFrame = ibSplitSibling)->Style();
10581 }
10582 }
10583
10584 // If this frame is one of the blocks that split an inline, we must
10585 // return the "special" inline parent, i.e., the parent that this
10586 // frame would have if we didn't mangle the frame structure.
10587 *aProviderFrame = GetCorrectedParent(this);
10588 return *aProviderFrame ? (*aProviderFrame)->Style() : nullptr;
10589 }
10590
10591 // We're an out-of-flow frame. For out-of-flow frames, we must
10592 // resolve underneath the placeholder's parent. The placeholder is
10593 // reached from the first-in-flow.
10594 nsPlaceholderFrame* placeholder = FirstInFlow()->GetPlaceholderFrame();
10595 if (!placeholder) {
10596 MOZ_ASSERT_UNREACHABLE("no placeholder frame for out-of-flow frame")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"no placeholder frame for out-of-flow frame" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10596); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "no placeholder frame for out-of-flow frame"
")"); do { *((volatile int*)__null) = 10596; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10597 *aProviderFrame = GetCorrectedParent(this);
10598 return *aProviderFrame ? (*aProviderFrame)->Style() : nullptr;
10599 }
10600 return placeholder->GetParentComputedStyleForOutOfFlow(aProviderFrame);
10601}
10602
10603void nsIFrame::GetLastLeaf(nsIFrame** aFrame) {
10604 if (!aFrame || !*aFrame) return;
10605 nsIFrame* child = *aFrame;
10606 // if we are a block frame then go for the last line of 'this'
10607 while (1) {
10608 child = child->PrincipalChildList().FirstChild();
10609 if (!child) return; // nothing to do
10610 nsIFrame* siblingFrame;
10611 nsIContent* content;
10612 // ignore anonymous elements, e.g. mozTableAdd* mozTableRemove*
10613 // see bug 278197 comment #12 #13 for details
10614 while ((siblingFrame = child->GetNextSibling()) &&
10615 (content = siblingFrame->GetContent()) &&
10616 !content->IsRootOfNativeAnonymousSubtree())
10617 child = siblingFrame;
10618 *aFrame = child;
10619 }
10620}
10621
10622void nsIFrame::GetFirstLeaf(nsIFrame** aFrame) {
10623 if (!aFrame || !*aFrame) return;
10624 nsIFrame* child = *aFrame;
10625 while (1) {
10626 child = child->PrincipalChildList().FirstChild();
10627 if (!child) return; // nothing to do
10628 *aFrame = child;
10629 }
10630}
10631
10632bool nsIFrame::IsFocusableDueToScrollFrame() {
10633 if (!IsScrollFrame()) {
10634 if (nsFieldSetFrame* fieldset = do_QueryFrame(this)) {
10635 // TODO: Do we have similar special-cases like this where we can have
10636 // anonymous scrollable boxes hanging off a primary frame?
10637 if (nsIFrame* inner = fieldset->GetInner()) {
10638 return inner->IsFocusableDueToScrollFrame();
10639 }
10640 }
10641 return false;
10642 }
10643 if (!mContent->IsHTMLElement()) {
10644 return false;
10645 }
10646 if (mContent->IsRootOfNativeAnonymousSubtree()) {
10647 return false;
10648 }
10649 if (!mContent->GetParent()) {
10650 return false;
10651 }
10652 if (mContent->AsElement()->HasAttr(nsGkAtoms::tabindex)) {
10653 return false;
10654 }
10655 // Elements with scrollable view are focusable with script & tabbable
10656 // Otherwise you couldn't scroll them with keyboard, which is an accessibility
10657 // issue (e.g. Section 508 rules) However, we don't make them to be focusable
10658 // with the mouse, because the extra focus outlines are considered
10659 // unnecessarily ugly. When clicked on, the selection position within the
10660 // element will be enough to make them keyboard scrollable.
10661 nsIScrollableFrame* scrollFrame = do_QueryFrame(this);
10662 if (!scrollFrame) {
10663 return false;
10664 }
10665 if (scrollFrame->IsForTextControlWithNoScrollbars()) {
10666 return false;
10667 }
10668 if (scrollFrame->GetScrollStyles().IsHiddenInBothDirections()) {
10669 return false;
10670 }
10671 if (scrollFrame->GetScrollRange().IsEqualEdges(nsRect(0, 0, 0, 0))) {
10672 return false;
10673 }
10674 return true;
10675}
10676
10677Focusable nsIFrame::IsFocusable(bool aWithMouse, bool aCheckVisibility) {
10678 // cannot focus content in print preview mode. Only the root can be focused,
10679 // but that's handled elsewhere.
10680 if (PresContext()->Type() == nsPresContext::eContext_PrintPreview) {
10681 return {};
10682 }
10683
10684 if (!mContent || !mContent->IsElement()) {
10685 return {};
10686 }
10687
10688 if (aCheckVisibility && !IsVisibleConsideringAncestors()) {
10689 return {};
10690 }
10691
10692 const StyleUserFocus uf = StyleUI()->UserFocus();
10693 if (uf == StyleUserFocus::None) {
10694 return {};
10695 }
10696 MOZ_ASSERT(!StyleUI()->IsInert(), "inert implies -moz-user-focus: none")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!StyleUI()->IsInert())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!StyleUI()->IsInert()))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("!StyleUI()->IsInert()"
" (" "inert implies -moz-user-focus: none" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10696); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!StyleUI()->IsInert()"
") (" "inert implies -moz-user-focus: none" ")"); do { *((volatile
int*)__null) = 10696; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
10697
10698 const PseudoStyleType pseudo = Style()->GetPseudoType();
10699 if (pseudo == PseudoStyleType::anonymousItem) {
10700 return {};
10701 }
10702
10703 Focusable focusable;
10704 if (auto* xul = nsXULElement::FromNode(mContent)) {
10705 // As a legacy special-case, -moz-user-focus controls focusability and
10706 // tabability of XUL elements in some circumstances (which default to
10707 // -moz-user-focus: ignore).
10708 auto focusability = xul->GetXULFocusability(aWithMouse);
10709 focusable.mFocusable =
10710 focusability.mForcedFocusable.valueOr(uf == StyleUserFocus::Normal);
10711 if (focusable) {
10712 focusable.mTabIndex = focusability.mForcedTabIndexIfFocusable.valueOr(0);
10713 }
10714 } else {
10715 focusable = mContent->IsFocusableWithoutStyle(aWithMouse);
10716 }
10717
10718 if (focusable) {
10719 return focusable;
10720 }
10721
10722 // If we're focusing with the mouse we never focus scroll areas.
10723 if (!aWithMouse && IsFocusableDueToScrollFrame()) {
10724 return {true, 0};
10725 }
10726
10727 // FIXME(emilio): some callers rely on somewhat broken return values
10728 // (focusable = false, but non-negative tab-index) from
10729 // IsFocusableWithoutStyle (for image maps in particular).
10730 return focusable;
10731}
10732
10733/**
10734 * @return true if this text frame ends with a newline character which is
10735 * treated as preformatted. It should return false if this is not a text frame.
10736 */
10737bool nsIFrame::HasSignificantTerminalNewline() const { return false; }
10738
10739static StyleVerticalAlignKeyword ConvertSVGDominantBaselineToVerticalAlign(
10740 StyleDominantBaseline aDominantBaseline) {
10741 // Most of these are approximate mappings.
10742 switch (aDominantBaseline) {
10743 case StyleDominantBaseline::Hanging:
10744 case StyleDominantBaseline::TextBeforeEdge:
10745 return StyleVerticalAlignKeyword::TextTop;
10746 case StyleDominantBaseline::TextAfterEdge:
10747 case StyleDominantBaseline::Ideographic:
10748 return StyleVerticalAlignKeyword::TextBottom;
10749 case StyleDominantBaseline::Central:
10750 case StyleDominantBaseline::Middle:
10751 case StyleDominantBaseline::Mathematical:
10752 return StyleVerticalAlignKeyword::Middle;
10753 case StyleDominantBaseline::Auto:
10754 case StyleDominantBaseline::Alphabetic:
10755 return StyleVerticalAlignKeyword::Baseline;
10756 default:
10757 MOZ_ASSERT_UNREACHABLE("unexpected aDominantBaseline value")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: "
"unexpected aDominantBaseline value" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10757); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "unexpected aDominantBaseline value"
")"); do { *((volatile int*)__null) = 10757; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10758 return StyleVerticalAlignKeyword::Baseline;
10759 }
10760}
10761
10762Maybe<StyleVerticalAlignKeyword> nsIFrame::VerticalAlignEnum() const {
10763 if (IsInSVGTextSubtree()) {
10764 StyleDominantBaseline dominantBaseline = StyleSVG()->mDominantBaseline;
10765 return Some(ConvertSVGDominantBaselineToVerticalAlign(dominantBaseline));
10766 }
10767
10768 const auto& verticalAlign = StyleDisplay()->mVerticalAlign;
10769 if (verticalAlign.IsKeyword()) {
10770 return Some(verticalAlign.AsKeyword());
10771 }
10772
10773 return Nothing();
10774}
10775
10776void nsIFrame::UpdateStyleOfChildAnonBox(nsIFrame* aChildFrame,
10777 ServoRestyleState& aRestyleState) {
10778#ifdef DEBUG1
10779 nsIFrame* parent = aChildFrame->GetInFlowParent();
10780 if (aChildFrame->IsTableFrame()) {
10781 parent = parent->GetParent();
10782 }
10783 if (parent->IsLineFrame()) {
10784 parent = parent->GetParent();
10785 }
10786 MOZ_ASSERT(nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent) == this,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent
) == this)>::isValid, "invalid assertion condition"); if (
(__builtin_expect(!!(!(!!(nsLayoutUtils::FirstContinuationOrIBSplitSibling
(parent) == this))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent) == this"
" (" "This should only be used for children!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10787); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent) == this"
") (" "This should only be used for children!" ")"); do { *(
(volatile int*)__null) = 10787; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
10787 "This should only be used for children!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent
) == this)>::isValid, "invalid assertion condition"); if (
(__builtin_expect(!!(!(!!(nsLayoutUtils::FirstContinuationOrIBSplitSibling
(parent) == this))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent) == this"
" (" "This should only be used for children!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10787); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent) == this"
") (" "This should only be used for children!" ")"); do { *(
(volatile int*)__null) = 10787; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
10788#endif // DEBUG
10789 MOZ_ASSERT(!GetContent() || !aChildFrame->GetContent() ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!GetContent() || !aChildFrame->GetContent() || aChildFrame
->GetContent() == GetContent())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!GetContent() || !aChildFrame
->GetContent() || aChildFrame->GetContent() == GetContent
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
" (" "What content node is it a frame for?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10791); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
") (" "What content node is it a frame for?" ")"); do { *((volatile
int*)__null) = 10791; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
10790 aChildFrame->GetContent() == GetContent(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!GetContent() || !aChildFrame->GetContent() || aChildFrame
->GetContent() == GetContent())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!GetContent() || !aChildFrame
->GetContent() || aChildFrame->GetContent() == GetContent
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
" (" "What content node is it a frame for?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10791); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
") (" "What content node is it a frame for?" ")"); do { *((volatile
int*)__null) = 10791; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
10791 "What content node is it a frame for?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!GetContent() || !aChildFrame->GetContent() || aChildFrame
->GetContent() == GetContent())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!GetContent() || !aChildFrame
->GetContent() || aChildFrame->GetContent() == GetContent
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
" (" "What content node is it a frame for?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10791); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
") (" "What content node is it a frame for?" ")"); do { *((volatile
int*)__null) = 10791; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
10792 MOZ_ASSERT(!aChildFrame->GetPrevContinuation(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aChildFrame->GetPrevContinuation())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!aChildFrame->GetPrevContinuation()))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!aChildFrame->GetPrevContinuation()"
" (" "Only first continuations should end up here" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10793); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetPrevContinuation()"
") (" "Only first continuations should end up here" ")"); do
{ *((volatile int*)__null) = 10793; __attribute__((nomerge))
::abort(); } while (false); } } while (false)
10793 "Only first continuations should end up here")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aChildFrame->GetPrevContinuation())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!aChildFrame->GetPrevContinuation()))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!aChildFrame->GetPrevContinuation()"
" (" "Only first continuations should end up here" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10793); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetPrevContinuation()"
") (" "Only first continuations should end up here" ")"); do
{ *((volatile int*)__null) = 10793; __attribute__((nomerge))
::abort(); } while (false); } } while (false)
;
10794
10795 // We could force the caller to pass in the pseudo, since some callers know it
10796 // statically... But this API is a bit nicer.
10797 auto pseudo = aChildFrame->Style()->GetPseudoType();
10798 MOZ_ASSERT(PseudoStyle::IsAnonBox(pseudo), "Child is not an anon box?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(PseudoStyle::IsAnonBox(pseudo))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(PseudoStyle::IsAnonBox(pseudo
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("PseudoStyle::IsAnonBox(pseudo)" " (" "Child is not an anon box?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10798); AnnotateMozCrashReason("MOZ_ASSERT" "(" "PseudoStyle::IsAnonBox(pseudo)"
") (" "Child is not an anon box?" ")"); do { *((volatile int
*)__null) = 10798; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
10799 MOZ_ASSERT(!PseudoStyle::IsNonInheritingAnonBox(pseudo),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!PseudoStyle::IsNonInheritingAnonBox(pseudo))>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!PseudoStyle::IsNonInheritingAnonBox(pseudo)))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!PseudoStyle::IsNonInheritingAnonBox(pseudo)"
" (" "Why did the caller bother calling us?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10800); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!PseudoStyle::IsNonInheritingAnonBox(pseudo)"
") (" "Why did the caller bother calling us?" ")"); do { *((
volatile int*)__null) = 10800; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
10800 "Why did the caller bother calling us?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!PseudoStyle::IsNonInheritingAnonBox(pseudo))>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!PseudoStyle::IsNonInheritingAnonBox(pseudo)))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!PseudoStyle::IsNonInheritingAnonBox(pseudo)"
" (" "Why did the caller bother calling us?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10800); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!PseudoStyle::IsNonInheritingAnonBox(pseudo)"
") (" "Why did the caller bother calling us?" ")"); do { *((
volatile int*)__null) = 10800; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
10801
10802 // Anon boxes inherit from their parent; that's us.
10803 RefPtr<ComputedStyle> newContext =
10804 aRestyleState.StyleSet().ResolveInheritingAnonymousBoxStyle(pseudo,
10805 Style());
10806
10807 nsChangeHint childHint =
10808 UpdateStyleOfOwnedChildFrame(aChildFrame, newContext, aRestyleState);
10809
10810 // Now that we've updated the style on aChildFrame, check whether it itself
10811 // has anon boxes to deal with.
10812 ServoRestyleState childrenState(*aChildFrame, aRestyleState, childHint,
10813 ServoRestyleState::Type::InFlow);
10814 aChildFrame->UpdateStyleOfOwnedAnonBoxes(childrenState);
10815
10816 // Assuming anon boxes don't have ::backdrop associated with them... if that
10817 // ever changes, we'd need to handle that here, like we do in
10818 // RestyleManager::ProcessPostTraversal
10819
10820 // We do need to handle block pseudo-elements here, though. Especially list
10821 // bullets.
10822 if (nsBlockFrame* block = do_QueryFrame(aChildFrame)) {
10823 block->UpdatePseudoElementStyles(childrenState);
10824 }
10825}
10826
10827/* static */
10828nsChangeHint nsIFrame::UpdateStyleOfOwnedChildFrame(
10829 nsIFrame* aChildFrame, ComputedStyle* aNewComputedStyle,
10830 ServoRestyleState& aRestyleState,
10831 const Maybe<ComputedStyle*>& aContinuationComputedStyle) {
10832 MOZ_ASSERT(!aChildFrame->GetAdditionalComputedStyle(0),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aChildFrame->GetAdditionalComputedStyle(0))>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!aChildFrame->GetAdditionalComputedStyle(0)))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!aChildFrame->GetAdditionalComputedStyle(0)"
" (" "We don't handle additional styles here" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10833); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetAdditionalComputedStyle(0)"
") (" "We don't handle additional styles here" ")"); do { *(
(volatile int*)__null) = 10833; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
10833 "We don't handle additional styles here")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aChildFrame->GetAdditionalComputedStyle(0))>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!aChildFrame->GetAdditionalComputedStyle(0)))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!aChildFrame->GetAdditionalComputedStyle(0)"
" (" "We don't handle additional styles here" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10833); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetAdditionalComputedStyle(0)"
") (" "We don't handle additional styles here" ")"); do { *(
(volatile int*)__null) = 10833; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
10834
10835 // Figure out whether we have an actual change. It's important that we do
10836 // this, for several reasons:
10837 //
10838 // 1) Even if all the child's changes are due to properties it inherits from
10839 // us, it's possible that no one ever asked us for those style structs and
10840 // hence changes to them aren't reflected in the changes handled at all.
10841 //
10842 // 2) Content can change stylesheets that change the styles of pseudos, and
10843 // extensions can add/remove stylesheets that change the styles of
10844 // anonymous boxes directly.
10845 uint32_t equalStructs; // Not used, actually.
10846 nsChangeHint childHint = aChildFrame->Style()->CalcStyleDifference(
10847 *aNewComputedStyle, &equalStructs);
10848
10849 // If aChildFrame is out of flow, then aRestyleState's "changes handled by the
10850 // parent" doesn't apply to it, because it may have some other parent in the
10851 // frame tree.
10852 if (!aChildFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
10853 childHint = NS_RemoveSubsumedHints(
10854 childHint, aRestyleState.ChangesHandledFor(aChildFrame));
10855 }
10856 if (childHint) {
10857 if (childHint & nsChangeHint_ReconstructFrame) {
10858 // If we generate a reconstruct here, remove any non-reconstruct hints we
10859 // may have already generated for this content.
10860 aRestyleState.ChangeList().PopChangesForContent(
10861 aChildFrame->GetContent());
10862 }
10863 aRestyleState.ChangeList().AppendChange(
10864 aChildFrame, aChildFrame->GetContent(), childHint);
10865 }
10866
10867 aChildFrame->SetComputedStyle(aNewComputedStyle);
10868 ComputedStyle* continuationStyle = aContinuationComputedStyle
10869 ? *aContinuationComputedStyle
10870 : aNewComputedStyle;
10871 for (nsIFrame* kid = aChildFrame->GetNextContinuation(); kid;
10872 kid = kid->GetNextContinuation()) {
10873 MOZ_ASSERT(!kid->GetAdditionalComputedStyle(0))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!kid->GetAdditionalComputedStyle(0))>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!kid->GetAdditionalComputedStyle(0)))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!kid->GetAdditionalComputedStyle(0)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10873); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!kid->GetAdditionalComputedStyle(0)"
")"); do { *((volatile int*)__null) = 10873; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10874 kid->SetComputedStyle(continuationStyle);
10875 }
10876
10877 return childHint;
10878}
10879
10880/* static */
10881void nsIFrame::AddInPopupStateBitToDescendants(nsIFrame* aFrame) {
10882 if (!aFrame->HasAnyStateBits(NS_FRAME_IN_POPUP) &&
10883 aFrame->TrackingVisibility()) {
10884 // Assume all frames in popups are visible.
10885 aFrame->IncApproximateVisibleCount();
10886 }
10887
10888 aFrame->AddStateBits(NS_FRAME_IN_POPUP);
10889
10890 for (const auto& childList : aFrame->CrossDocChildLists()) {
10891 for (nsIFrame* child : childList.mList) {
10892 AddInPopupStateBitToDescendants(child);
10893 }
10894 }
10895}
10896
10897/* static */
10898void nsIFrame::RemoveInPopupStateBitFromDescendants(nsIFrame* aFrame) {
10899 if (!aFrame->HasAnyStateBits(NS_FRAME_IN_POPUP) ||
10900 nsLayoutUtils::IsPopup(aFrame)) {
10901 return;
10902 }
10903
10904 aFrame->RemoveStateBits(NS_FRAME_IN_POPUP);
10905
10906 if (aFrame->TrackingVisibility()) {
10907 // We assume all frames in popups are visible, so this decrement balances
10908 // out the increment in AddInPopupStateBitToDescendants above.
10909 aFrame->DecApproximateVisibleCount();
10910 }
10911 for (const auto& childList : aFrame->CrossDocChildLists()) {
10912 for (nsIFrame* child : childList.mList) {
10913 RemoveInPopupStateBitFromDescendants(child);
10914 }
10915 }
10916}
10917
10918void nsIFrame::SetParent(nsContainerFrame* aParent) {
10919 // If our parent is a wrapper anon box, our new parent should be too. We
10920 // _can_ change parent if our parent is a wrapper anon box, because some
10921 // wrapper anon boxes can have continuations.
10922 MOZ_ASSERT_IF(ParentIsWrapperAnonBox(),do { if (ParentIsWrapperAnonBox()) { do { static_assert( mozilla
::detail::AssertionConditionType<decltype(aParent->Style
()->IsInheritingAnonBox())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aParent->Style()->IsInheritingAnonBox
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aParent->Style()->IsInheritingAnonBox()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10923); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->Style()->IsInheritingAnonBox()"
")"); do { *((volatile int*)__null) = 10923; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false); } } while
(false)
10923 aParent->Style()->IsInheritingAnonBox())do { if (ParentIsWrapperAnonBox()) { do { static_assert( mozilla
::detail::AssertionConditionType<decltype(aParent->Style
()->IsInheritingAnonBox())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aParent->Style()->IsInheritingAnonBox
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aParent->Style()->IsInheritingAnonBox()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10923); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->Style()->IsInheritingAnonBox()"
")"); do { *((volatile int*)__null) = 10923; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false); } } while
(false)
;
10924
10925 // Note that the current mParent may already be destroyed at this point.
10926 mParent = aParent;
10927 MOZ_DIAGNOSTIC_ASSERT(!mParent || PresShell() == mParent->PresShell())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mParent || PresShell() == mParent->PresShell())>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!mParent || PresShell() == mParent->PresShell()))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mParent || PresShell() == mParent->PresShell()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10927); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mParent || PresShell() == mParent->PresShell()"
")"); do { *((volatile int*)__null) = 10927; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10928
10929 if (HasAnyStateBits(NS_FRAME_HAS_VIEW | NS_FRAME_HAS_CHILD_WITH_VIEW)) {
10930 for (nsIFrame* f = aParent;
10931 f && !f->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
10932 f = f->GetParent()) {
10933 f->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
10934 }
10935 }
10936
10937 if (HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)) {
10938 for (nsIFrame* f = aParent; f; f = f->GetParent()) {
10939 if (f->HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)) {
10940 break;
10941 }
10942 f->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE);
10943 }
10944 }
10945
10946 if (HasAnyStateBits(NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE)) {
10947 for (nsIFrame* f = aParent; f; f = f->GetParent()) {
10948 if (f->HasAnyStateBits(
10949 NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE)) {
10950 break;
10951 }
10952 f->AddStateBits(NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE);
10953 }
10954 }
10955
10956 if (HasInvalidFrameInSubtree()) {
10957 for (nsIFrame* f = aParent;
10958 f && !f->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT |
10959 NS_FRAME_IS_NONDISPLAY);
10960 f = nsLayoutUtils::GetCrossDocParentFrameInProcess(f)) {
10961 f->AddStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT);
10962 }
10963 }
10964
10965 if (aParent->HasAnyStateBits(NS_FRAME_IN_POPUP)) {
10966 AddInPopupStateBitToDescendants(this);
10967 } else {
10968 RemoveInPopupStateBitFromDescendants(this);
10969 }
10970
10971 // If our new parent only has invalid children, then we just invalidate
10972 // ourselves too. This is probably faster than clearing the flag all
10973 // the way up the frame tree.
10974 if (aParent->HasAnyStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT)) {
10975 InvalidateFrame();
10976 } else {
10977 SchedulePaint();
10978 }
10979}
10980
10981bool nsIFrame::IsStackingContext(const nsStyleDisplay* aStyleDisplay,
10982 const nsStyleEffects* aStyleEffects) {
10983 // Properties that influence the output of this function should be handled in
10984 // change_bits_for_longhand as well.
10985 if (HasOpacity(aStyleDisplay, aStyleEffects, nullptr)) {
10986 return true;
10987 }
10988 if (IsTransformed()) {
10989 return true;
10990 }
10991 auto willChange = aStyleDisplay->mWillChange.bits;
10992 if (aStyleDisplay->IsContainPaint() || aStyleDisplay->IsContainLayout() ||
10993 willChange & StyleWillChangeBits::CONTAIN) {
10994 if (SupportsContainLayoutAndPaint()) {
10995 return true;
10996 }
10997 }
10998 // strictly speaking, 'perspective' doesn't require visual atomicity,
10999 // but the spec says it acts like the rest of these
11000 if (aStyleDisplay->HasPerspectiveStyle() ||
11001 willChange & StyleWillChangeBits::PERSPECTIVE) {
11002 if (SupportsCSSTransforms()) {
11003 return true;
11004 }
11005 }
11006 if (!StylePosition()->mZIndex.IsAuto() ||
11007 willChange & StyleWillChangeBits::Z_INDEX) {
11008 if (ZIndexApplies()) {
11009 return true;
11010 }
11011 }
11012 return aStyleEffects->mMixBlendMode != StyleBlend::Normal ||
11013 SVGIntegrationUtils::UsingEffectsForFrame(this) ||
11014 aStyleDisplay->IsPositionForcingStackingContext() ||
11015 aStyleDisplay->mIsolation != StyleIsolation::Auto ||
11016 willChange & StyleWillChangeBits::STACKING_CONTEXT_UNCONDITIONAL;
11017}
11018
11019bool nsIFrame::IsStackingContext() {
11020 return IsStackingContext(StyleDisplay(), StyleEffects());
11021}
11022
11023static bool IsFrameScrolledOutOfView(const nsIFrame* aTarget,
11024 const nsRect& aTargetRect,
11025 const nsIFrame* aParent) {
11026 // The ancestor frame we are checking if it clips out aTargetRect relative to
11027 // aTarget.
11028 nsIFrame* clipParent = nullptr;
11029
11030 // find the first scrollable frame or root frame if we are in a fixed pos
11031 // subtree
11032 for (nsIFrame* f = const_cast<nsIFrame*>(aParent); f;
11033 f = nsLayoutUtils::GetCrossDocParentFrameInProcess(f)) {
11034 nsIScrollableFrame* scrollableFrame = do_QueryFrame(f);
11035 if (scrollableFrame) {
11036 clipParent = f;
11037 break;
11038 }
11039 if (f->StyleDisplay()->mPosition == StylePositionProperty::Fixed &&
11040 nsLayoutUtils::IsReallyFixedPos(f)) {
11041 clipParent = f->GetParent();
11042 break;
11043 }
11044 }
11045
11046 if (!clipParent) {
11047 // Even if we couldn't find the nearest scrollable frame, it might mean we
11048 // are in an out-of-process iframe, try to see if |aTarget| frame is
11049 // scrolled out of view in an scrollable frame in a cross-process ancestor
11050 // document.
11051 return nsLayoutUtils::FrameIsScrolledOutOfViewInCrossProcess(aTarget);
11052 }
11053
11054 nsRect clipRect = clipParent->InkOverflowRectRelativeToSelf();
11055 // We consider that the target is scrolled out if the scrollable (or root)
11056 // frame is empty.
11057 if (clipRect.IsEmpty()) {
11058 return true;
11059 }
11060
11061 nsRect transformedRect = nsLayoutUtils::TransformFrameRectToAncestor(
11062 aTarget, aTargetRect, clipParent);
11063
11064 if (transformedRect.IsEmpty()) {
11065 // If the transformed rect is empty it represents a line or a point that we
11066 // should check is outside the the scrollable rect.
11067 if (transformedRect.x > clipRect.XMost() ||
11068 transformedRect.y > clipRect.YMost() ||
11069 clipRect.x > transformedRect.XMost() ||
11070 clipRect.y > transformedRect.YMost()) {
11071 return true;
11072 }
11073 } else if (!transformedRect.Intersects(clipRect)) {
11074 return true;
11075 }
11076
11077 nsIFrame* parent = clipParent->GetParent();
11078 if (!parent) {
11079 return false;
11080 }
11081
11082 return IsFrameScrolledOutOfView(aTarget, aTargetRect, parent);
11083}
11084
11085bool nsIFrame::IsScrolledOutOfView() const {
11086 nsRect rect = InkOverflowRectRelativeToSelf();
11087 return IsFrameScrolledOutOfView(this, rect, this);
11088}
11089
11090gfx::Matrix nsIFrame::ComputeWidgetTransform() const {
11091 const nsStyleUIReset* uiReset = StyleUIReset();
11092 if (uiReset->mMozWindowTransform.IsNone()) {
11093 return gfx::Matrix();
11094 }
11095
11096 TransformReferenceBox refBox(nullptr, nsRect(nsPoint(), GetSize()));
11097
11098 nsPresContext* presContext = PresContext();
11099 int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
11100 gfx::Matrix4x4 matrix = nsStyleTransformMatrix::ReadTransforms(
11101 uiReset->mMozWindowTransform, refBox, float(appUnitsPerDevPixel));
11102
11103 // Apply the -moz-window-transform-origin translation to the matrix.
11104 const StyleTransformOrigin& origin = uiReset->mWindowTransformOrigin;
11105 Point transformOrigin = nsStyleTransformMatrix::Convert2DPosition(
11106 origin.horizontal, origin.vertical, refBox, appUnitsPerDevPixel);
11107 matrix.ChangeBasis(Point3D(transformOrigin.x, transformOrigin.y, 0));
11108
11109 gfx::Matrix result2d;
11110 if (!matrix.CanDraw2D(&result2d)) {
11111 // FIXME: It would be preferable to reject non-2D transforms at parse time.
11112 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "-moz-window-transform does not describe a 2D transform, "
"but only 2d transforms are supported", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11114)
11113 "-moz-window-transform does not describe a 2D transform, "NS_DebugBreak(NS_DEBUG_WARNING, "-moz-window-transform does not describe a 2D transform, "
"but only 2d transforms are supported", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11114)
11114 "but only 2d transforms are supported")NS_DebugBreak(NS_DEBUG_WARNING, "-moz-window-transform does not describe a 2D transform, "
"but only 2d transforms are supported", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11114)
;
11115 return gfx::Matrix();
11116 }
11117
11118 return result2d;
11119}
11120
11121void nsIFrame::DoUpdateStyleOfOwnedAnonBoxes(ServoRestyleState& aRestyleState) {
11122 // As a special case, we check for {ib}-split block frames here, rather
11123 // than have an nsInlineFrame::AppendDirectlyOwnedAnonBoxes implementation
11124 // that returns them.
11125 //
11126 // (If we did handle them in AppendDirectlyOwnedAnonBoxes, we would have to
11127 // return *all* of the in-flow {ib}-split block frames, not just the first
11128 // one. For restyling, we really just need the first in flow, and the other
11129 // user of the AppendOwnedAnonBoxes API, AllChildIterator, doesn't need to
11130 // know about them at all, since these block frames never create NAC. So we
11131 // avoid any unncessary hashtable lookups for the {ib}-split frames by calling
11132 // UpdateStyleOfOwnedAnonBoxesForIBSplit directly here.)
11133 if (IsInlineFrame()) {
11134 if (HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) {
11135 static_cast<nsInlineFrame*>(this)->UpdateStyleOfOwnedAnonBoxesForIBSplit(
11136 aRestyleState);
11137 }
11138 return;
11139 }
11140
11141 AutoTArray<OwnedAnonBox, 4> frames;
11142 AppendDirectlyOwnedAnonBoxes(frames);
11143 for (OwnedAnonBox& box : frames) {
11144 if (box.mUpdateStyleFn) {
11145 box.mUpdateStyleFn(this, box.mAnonBoxFrame, aRestyleState);
11146 } else {
11147 UpdateStyleOfChildAnonBox(box.mAnonBoxFrame, aRestyleState);
11148 }
11149 }
11150}
11151
11152/* virtual */
11153void nsIFrame::AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) {
11154 MOZ_ASSERT(!HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES))>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES)))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11154); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES)"
")"); do { *((volatile int*)__null) = 11154; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11155 MOZ_ASSERT(false, "Why did this get called?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Why did this get called?"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11155); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Why did this get called?" ")"); do { *((volatile int*)__null
) = 11155; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
11156}
11157
11158void nsIFrame::DoAppendOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) {
11159 size_t i = aResult.Length();
11160 AppendDirectlyOwnedAnonBoxes(aResult);
11161
11162 // After appending the directly owned anonymous boxes of this frame to
11163 // aResult above, we need to check each of them to see if they own
11164 // any anonymous boxes themselves. Note that we keep progressing
11165 // through aResult, looking for additional entries in aResult from these
11166 // subsequent AppendDirectlyOwnedAnonBoxes calls. (Thus we can't
11167 // use a ranged for loop here.)
11168
11169 while (i < aResult.Length()) {
11170 nsIFrame* f = aResult[i].mAnonBoxFrame;
11171 if (f->HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES)) {
11172 f->AppendDirectlyOwnedAnonBoxes(aResult);
11173 }
11174 ++i;
11175 }
11176}
11177
11178nsIFrame::CaretPosition::CaretPosition() : mContentOffset(0) {}
11179
11180nsIFrame::CaretPosition::~CaretPosition() = default;
11181
11182bool nsIFrame::HasCSSAnimations() {
11183 auto* collection = AnimationCollection<CSSAnimation>::Get(this);
11184 return collection && !collection->mAnimations.IsEmpty();
11185}
11186
11187bool nsIFrame::HasCSSTransitions() {
11188 auto* collection = AnimationCollection<CSSTransition>::Get(this);
11189 return collection && !collection->mAnimations.IsEmpty();
11190}
11191
11192void nsIFrame::AddSizeOfExcludingThisForTree(nsWindowSizes& aSizes) const {
11193 aSizes.mLayoutFramePropertiesSize +=
11194 mProperties.SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
11195
11196 // We don't do this for Gecko because this stuff is stored in the nsPresArena
11197 // and so measured elsewhere.
11198 if (!aSizes.mState.HaveSeenPtr(mComputedStyle)) {
11199 mComputedStyle->AddSizeOfIncludingThis(aSizes,
11200 &aSizes.mLayoutComputedValuesNonDom);
11201 }
11202
11203 // And our additional styles.
11204 int32_t index = 0;
11205 while (auto* extra = GetAdditionalComputedStyle(index++)) {
11206 if (!aSizes.mState.HaveSeenPtr(extra)) {
11207 extra->AddSizeOfIncludingThis(aSizes,
11208 &aSizes.mLayoutComputedValuesNonDom);
11209 }
11210 }
11211
11212 for (const auto& childList : ChildLists()) {
11213 for (const nsIFrame* f : childList.mList) {
11214 f->AddSizeOfExcludingThisForTree(aSizes);
11215 }
11216 }
11217}
11218
11219nsRect nsIFrame::GetCompositorHitTestArea(nsDisplayListBuilder* aBuilder) {
11220 nsRect area;
11221
11222 nsIScrollableFrame* scrollFrame = nsLayoutUtils::GetScrollableFrameFor(this);
11223 if (scrollFrame) {
11224 // If the frame is content of a scrollframe, then we need to pick up the
11225 // area corresponding to the overflow rect as well. Otherwise the parts of
11226 // the overflow that are not occupied by descendants get skipped and the
11227 // APZ code sends touch events to the content underneath instead.
11228 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1127773#c15.
11229 area = ScrollableOverflowRect();
11230 } else {
11231 area = GetRectRelativeToSelf();
11232 }
11233
11234 if (!area.IsEmpty()) {
11235 return area + aBuilder->ToReferenceFrame(this);
11236 }
11237
11238 return area;
11239}
11240
11241CompositorHitTestInfo nsIFrame::GetCompositorHitTestInfo(
11242 nsDisplayListBuilder* aBuilder) {
11243 CompositorHitTestInfo result = CompositorHitTestInvisibleToHit;
11244
11245 if (aBuilder->IsInsidePointerEventsNoneDoc()) {
11246 // Somewhere up the parent document chain is a subdocument with pointer-
11247 // events:none set on it.
11248 return result;
11249 }
11250 if (!GetParent()) {
11251 MOZ_ASSERT(IsViewportFrame())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsViewportFrame())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsViewportFrame()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("IsViewportFrame()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11251); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsViewportFrame()"
")"); do { *((volatile int*)__null) = 11251; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11252 // Viewport frames are never event targets, other frames, like canvas
11253 // frames, are the event targets for any regions viewport frames may cover.
11254 return result;
11255 }
11256 if (Style()->PointerEvents() == StylePointerEvents::None) {
11257 return result;
11258 }
11259 if (!StyleVisibility()->IsVisible()) {
11260 return result;
11261 }
11262
11263 // Anything that didn't match the above conditions is visible to hit-testing.
11264 result = CompositorHitTestFlags::eVisibleToHitTest;
11265 SVGUtils::MaskUsage maskUsage = SVGUtils::DetermineMaskUsage(this, false);
11266 if (maskUsage.UsingMaskOrClipPath()) {
11267 // If WebRender is enabled, simple clip-paths can be converted into WR
11268 // clips that WR knows how to hit-test against, so we don't need to mark
11269 // it as an irregular area.
11270 if (!maskUsage.IsSimpleClipShape()) {
11271 result += CompositorHitTestFlags::eIrregularArea;
11272 }
11273 }
11274
11275 if (aBuilder->IsBuildingNonLayerizedScrollbar()) {
11276 // Scrollbars may be painted into a layer below the actual layer they will
11277 // scroll, and therefore wheel events may be dispatched to the outer frame
11278 // instead of the intended scrollframe. To address this, we force a d-t-c
11279 // region on scrollbar frames that won't be placed in their own layer. See
11280 // bug 1213324 for details.
11281 result += CompositorHitTestFlags::eInactiveScrollframe;
11282 } else if (aBuilder->GetAncestorHasApzAwareEventHandler()) {
11283 result += CompositorHitTestFlags::eApzAwareListeners;
11284 } else if (IsRangeFrame()) {
11285 // Range frames handle touch events directly without having a touch listener
11286 // so we need to let APZ know that this area cares about events.
11287 result += CompositorHitTestFlags::eApzAwareListeners;
11288 }
11289
11290 if (aBuilder->IsTouchEventPrefEnabledDoc()) {
11291 // Inherit the touch-action flags from the parent, if there is one. We do
11292 // this because of how the touch-action on a frame combines the touch-action
11293 // from ancestor DOM elements. Refer to the documentation in
11294 // TouchActionHelper.cpp for details; this code is meant to be equivalent to
11295 // that code, but woven into the top-down recursive display list building
11296 // process.
11297 CompositorHitTestInfo inheritedTouchAction =
11298 aBuilder->GetCompositorHitTestInfo() & CompositorHitTestTouchActionMask;
11299
11300 nsIFrame* touchActionFrame = this;
11301 if (nsIScrollableFrame* scrollFrame =
11302 nsLayoutUtils::GetScrollableFrameFor(this)) {
11303 ScrollStyles ss = scrollFrame->GetScrollStyles();
11304 if (ss.mVertical != StyleOverflow::Hidden ||
11305 ss.mHorizontal != StyleOverflow::Hidden) {
11306 touchActionFrame = do_QueryFrame(scrollFrame);
11307 // On scrollframes, stop inheriting the pan-x and pan-y flags; instead,
11308 // reset them back to zero to allow panning on the scrollframe unless we
11309 // encounter an element that disables it that's inside the scrollframe.
11310 // This is equivalent to the |considerPanning| variable in
11311 // TouchActionHelper.cpp, but for a top-down traversal.
11312 CompositorHitTestInfo panMask(
11313 CompositorHitTestFlags::eTouchActionPanXDisabled,
11314 CompositorHitTestFlags::eTouchActionPanYDisabled);
11315 inheritedTouchAction -= panMask;
11316 }
11317 }
11318
11319 result += inheritedTouchAction;
11320
11321 const StyleTouchAction touchAction = touchActionFrame->UsedTouchAction();
11322 // The CSS allows the syntax auto | none | [pan-x || pan-y] | manipulation
11323 // so we can eliminate some combinations of things.
11324 if (touchAction == StyleTouchAction::AUTO) {
11325 // nothing to do
11326 } else if (touchAction & StyleTouchAction::MANIPULATION) {
11327 result += CompositorHitTestFlags::eTouchActionAnimatingZoomDisabled;
11328 } else {
11329 // This path handles the cases none | [pan-x || pan-y || pinch-zoom] so
11330 // double-tap is disabled in here.
11331 if (!(touchAction & StyleTouchAction::PINCH_ZOOM)) {
11332 result += CompositorHitTestFlags::eTouchActionPinchZoomDisabled;
11333 }
11334
11335 result += CompositorHitTestFlags::eTouchActionAnimatingZoomDisabled;
11336
11337 if (!(touchAction & StyleTouchAction::PAN_X)) {
11338 result += CompositorHitTestFlags::eTouchActionPanXDisabled;
11339 }
11340 if (!(touchAction & StyleTouchAction::PAN_Y)) {
11341 result += CompositorHitTestFlags::eTouchActionPanYDisabled;
11342 }
11343 if (touchAction & StyleTouchAction::NONE) {
11344 // all the touch-action disabling flags will already have been set above
11345 MOZ_ASSERT(result.contains(CompositorHitTestTouchActionMask))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(result.contains(CompositorHitTestTouchActionMask))>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(result.contains(CompositorHitTestTouchActionMask))))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("result.contains(CompositorHitTestTouchActionMask)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11345); AnnotateMozCrashReason("MOZ_ASSERT" "(" "result.contains(CompositorHitTestTouchActionMask)"
")"); do { *((volatile int*)__null) = 11345; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11346 }
11347 }
11348 }
11349
11350 const Maybe<ScrollDirection> scrollDirection =
11351 aBuilder->GetCurrentScrollbarDirection();
11352 if (scrollDirection.isSome()) {
11353 if (GetContent()->IsXULElement(nsGkAtoms::thumb)) {
11354 const bool thumbGetsLayer = aBuilder->GetCurrentScrollbarTarget() !=
11355 layers::ScrollableLayerGuid::NULL_SCROLL_ID;
11356 if (thumbGetsLayer) {
11357 result += CompositorHitTestFlags::eScrollbarThumb;
11358 } else {
11359 result += CompositorHitTestFlags::eInactiveScrollframe;
11360 }
11361 }
11362
11363 if (*scrollDirection == ScrollDirection::eVertical) {
11364 result += CompositorHitTestFlags::eScrollbarVertical;
11365 }
11366
11367 // includes the ScrollbarFrame, SliderFrame, anything else that
11368 // might be inside the xul:scrollbar
11369 result += CompositorHitTestFlags::eScrollbar;
11370 }
11371
11372 return result;
11373}
11374
11375// Returns true if we can guarantee there is no visible descendants.
11376static bool HasNoVisibleDescendants(const nsIFrame* aFrame) {
11377 for (const auto& childList : aFrame->ChildLists()) {
11378 for (nsIFrame* f : childList.mList) {
11379 if (nsPlaceholderFrame::GetRealFrameFor(f)
11380 ->IsVisibleOrMayHaveVisibleDescendants()) {
11381 return false;
11382 }
11383 }
11384 }
11385 return true;
11386}
11387
11388void nsIFrame::UpdateVisibleDescendantsState() {
11389 if (StyleVisibility()->IsVisible()) {
11390 // Notify invisible ancestors that a visible descendant exists now.
11391 nsIFrame* ancestor;
11392 for (ancestor = GetInFlowParent();
11393 ancestor && !ancestor->StyleVisibility()->IsVisible();
11394 ancestor = ancestor->GetInFlowParent()) {
11395 ancestor->mAllDescendantsAreInvisible = false;
11396 }
11397 } else {
11398 mAllDescendantsAreInvisible = HasNoVisibleDescendants(this);
11399 }
11400}
11401
11402void nsIFrame::UpdateAnimationVisibility() {
11403 auto* animationCollection = AnimationCollection<CSSAnimation>::Get(this);
11404 auto* transitionCollection = AnimationCollection<CSSTransition>::Get(this);
11405
11406 if ((!animationCollection || animationCollection->mAnimations.IsEmpty()) &&
11407 (!transitionCollection || transitionCollection->mAnimations.IsEmpty())) {
11408 return;
11409 }
11410
11411 bool hidden = IsHiddenByContentVisibilityOnAnyAncestor();
11412 if (animationCollection) {
11413 for (auto& animation : animationCollection->mAnimations) {
11414 animation->SetHiddenByContentVisibility(hidden);
11415 }
11416 }
11417
11418 if (transitionCollection) {
11419 for (auto& transition : transitionCollection->mAnimations) {
11420 transition->SetHiddenByContentVisibility(hidden);
11421 }
11422 }
11423}
11424
11425nsIFrame::PhysicalAxes nsIFrame::ShouldApplyOverflowClipping(
11426 const nsStyleDisplay* aDisp) const {
11427 MOZ_ASSERT(aDisp == StyleDisplay(), "Wrong display struct")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aDisp == StyleDisplay())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aDisp == StyleDisplay()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aDisp == StyleDisplay()"
" (" "Wrong display struct" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11427); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDisp == StyleDisplay()"
") (" "Wrong display struct" ")"); do { *((volatile int*)__null
) = 11427; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
11428
11429 // 'contain:paint', which we handle as 'overflow:clip' here. Except for
11430 // scrollframes we don't need contain:paint to add any clipping, because
11431 // the scrollable frame will already clip overflowing content, and because
11432 // 'contain:paint' should prevent all means of escaping that clipping
11433 // (e.g. because it forms a fixed-pos containing block).
11434 if (aDisp->IsContainPaint() && !IsScrollFrame() &&
11435 SupportsContainLayoutAndPaint()) {
11436 return PhysicalAxes::Both;
11437 }
11438
11439 // and overflow:hidden that we should interpret as clip
11440 if (aDisp->mOverflowX == StyleOverflow::Hidden &&
11441 aDisp->mOverflowY == StyleOverflow::Hidden) {
11442 // REVIEW: these are the frame types that set up clipping.
11443 LayoutFrameType type = Type();
11444 switch (type) {
11445 case LayoutFrameType::Table:
11446 case LayoutFrameType::TableCell:
11447 case LayoutFrameType::SVGOuterSVG:
11448 case LayoutFrameType::SVGInnerSVG:
11449 case LayoutFrameType::SVGSymbol:
11450 case LayoutFrameType::SVGForeignObject:
11451 return PhysicalAxes::Both;
11452 default:
11453 if (IsReplacedWithBlock()) {
11454 if (type == mozilla::LayoutFrameType::TextInput) {
11455 // It has an anonymous scroll frame that handles any overflow.
11456 return PhysicalAxes::None;
11457 }
11458 return PhysicalAxes::Both;
11459 }
11460 }
11461 }
11462
11463 // clip overflow:clip, except for nsListControlFrame which is
11464 // an nsHTMLScrollFrame sub-class.
11465 if (MOZ_UNLIKELY((aDisp->mOverflowX == mozilla::StyleOverflow::Clip ||(__builtin_expect(!!((aDisp->mOverflowX == mozilla::StyleOverflow
::Clip || aDisp->mOverflowY == mozilla::StyleOverflow::Clip
) && !IsListControlFrame()), 0))
11466 aDisp->mOverflowY == mozilla::StyleOverflow::Clip) &&(__builtin_expect(!!((aDisp->mOverflowX == mozilla::StyleOverflow
::Clip || aDisp->mOverflowY == mozilla::StyleOverflow::Clip
) && !IsListControlFrame()), 0))
11467 !IsListControlFrame())(__builtin_expect(!!((aDisp->mOverflowX == mozilla::StyleOverflow
::Clip || aDisp->mOverflowY == mozilla::StyleOverflow::Clip
) && !IsListControlFrame()), 0))
) {
11468 // FIXME: we could use GetViewportScrollStylesOverrideElement() here instead
11469 // if that worked correctly in a print context. (see bug 1654667)
11470 const auto* element = Element::FromNodeOrNull(GetContent());
11471 if (!element ||
11472 !PresContext()->ElementWouldPropagateScrollStyles(*element)) {
11473 uint8_t axes = uint8_t(PhysicalAxes::None);
11474 if (aDisp->mOverflowX == mozilla::StyleOverflow::Clip) {
11475 axes |= uint8_t(PhysicalAxes::Horizontal);
11476 }
11477 if (aDisp->mOverflowY == mozilla::StyleOverflow::Clip) {
11478 axes |= uint8_t(PhysicalAxes::Vertical);
11479 }
11480 return PhysicalAxes(axes);
11481 }
11482 }
11483
11484 if (HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
11485 return PhysicalAxes::None;
11486 }
11487
11488 // If we're paginated and a block, and have NS_BLOCK_CLIP_PAGINATED_OVERFLOW
11489 // set, then we want to clip our overflow.
11490 bool clip = HasAnyStateBits(NS_BLOCK_CLIP_PAGINATED_OVERFLOW) &&
11491 PresContext()->IsPaginated() && IsBlockFrame();
11492 return clip ? PhysicalAxes::Both : PhysicalAxes::None;
11493}
11494
11495#ifdef DEBUG1
11496static void GetTagName(nsIFrame* aFrame, nsIContent* aContent, int aResultSize,
11497 char* aResult) {
11498 if (aContent) {
11499 snprintf(aResult, aResultSize, "%s@%p",
11500 nsAtomCString(aContent->NodeInfo()->NameAtom()).get(), aFrame);
11501 } else {
11502 snprintf(aResult, aResultSize, "@%p", aFrame);
11503 }
11504}
11505
11506void nsIFrame::Trace(const char* aMethod, bool aEnter) {
11507 if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)(int(((mozilla::LogModule*)(sFrameLogModule))->Level()) &
(0x1))
) {
11508 char tagbuf[40];
11509 GetTagName(this, mContent, sizeof(tagbuf), tagbuf);
11510 printf_stderr("%s: %s %s", tagbuf, aEnter ? "enter" : "exit", aMethod);
11511 }
11512}
11513
11514void nsIFrame::Trace(const char* aMethod, bool aEnter,
11515 const nsReflowStatus& aStatus) {
11516 if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)(int(((mozilla::LogModule*)(sFrameLogModule))->Level()) &
(0x1))
) {
11517 char tagbuf[40];
11518 GetTagName(this, mContent, sizeof(tagbuf), tagbuf);
11519 printf_stderr("%s: %s %s, status=%scomplete%s", tagbuf,
11520 aEnter ? "enter" : "exit", aMethod,
11521 aStatus.IsIncomplete() ? "not" : "",
11522 (aStatus.NextInFlowNeedsReflow()) ? "+reflow" : "");
11523 }
11524}
11525
11526void nsIFrame::TraceMsg(const char* aFormatString, ...) {
11527 if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)(int(((mozilla::LogModule*)(sFrameLogModule))->Level()) &
(0x1))
) {
11528 // Format arguments into a buffer
11529 char argbuf[200];
11530 va_list ap;
11531 va_start(ap, aFormatString)__builtin_va_start(ap, aFormatString);
11532 VsprintfLiteral(argbuf, aFormatString, ap);
11533 va_end(ap)__builtin_va_end(ap);
11534
11535 char tagbuf[40];
11536 GetTagName(this, mContent, sizeof(tagbuf), tagbuf);
11537 printf_stderr("%s: %s", tagbuf, argbuf);
11538 }
11539}
11540
11541void nsIFrame::VerifyDirtyBitSet(const nsFrameList& aFrameList) {
11542 for (nsIFrame* f : aFrameList) {
11543 NS_ASSERTION(f->HasAnyStateBits(NS_FRAME_IS_DIRTY), "dirty bit not set")do { if (!(f->HasAnyStateBits(NS_FRAME_IS_DIRTY))) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "dirty bit not set", "f->HasAnyStateBits(NS_FRAME_IS_DIRTY)"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11543); MOZ_PretendNoReturn(); } } while (0)
;
11544 }
11545}
11546
11547// Start Display Reflow
11548DR_cookie::DR_cookie(nsPresContext* aPresContext, nsIFrame* aFrame,
11549 const ReflowInput& aReflowInput, ReflowOutput& aMetrics,
11550 nsReflowStatus& aStatus)
11551 : mPresContext(aPresContext),
11552 mFrame(aFrame),
11553 mReflowInput(aReflowInput),
11554 mMetrics(aMetrics),
11555 mStatus(aStatus) {
11556 MOZ_COUNT_CTOR(DR_cookie)do { static_assert(std::is_class_v<DR_cookie>, "Token '"
"DR_cookie" "' is not a class type."); static_assert(!std::is_base_of
<nsISupports, DR_cookie>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogCtor((void*)this, "DR_cookie", sizeof
(*this)); } while (0)
;
11557 mValue = nsIFrame::DisplayReflowEnter(aPresContext, mFrame, mReflowInput);
11558}
11559
11560DR_cookie::~DR_cookie() {
11561 MOZ_COUNT_DTOR(DR_cookie)do { static_assert(std::is_class_v<DR_cookie>, "Token '"
"DR_cookie" "' is not a class type."); static_assert(!std::is_base_of
<nsISupports, DR_cookie>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "DR_cookie", sizeof
(*this)); } while (0)
;
11562 nsIFrame::DisplayReflowExit(mPresContext, mFrame, mMetrics, mStatus, mValue);
11563}
11564
11565DR_layout_cookie::DR_layout_cookie(nsIFrame* aFrame) : mFrame(aFrame) {
11566 MOZ_COUNT_CTOR(DR_layout_cookie)do { static_assert(std::is_class_v<DR_layout_cookie>, "Token '"
"DR_layout_cookie" "' is not a class type."); static_assert(
!std::is_base_of<nsISupports, DR_layout_cookie>::value,
"nsISupports classes don't need to call MOZ_COUNT_CTOR or " "MOZ_COUNT_DTOR"
);; NS_LogCtor((void*)this, "DR_layout_cookie", sizeof(*this)
); } while (0)
;
11567 mValue = nsIFrame::DisplayLayoutEnter(mFrame);
11568}
11569
11570DR_layout_cookie::~DR_layout_cookie() {
11571 MOZ_COUNT_DTOR(DR_layout_cookie)do { static_assert(std::is_class_v<DR_layout_cookie>, "Token '"
"DR_layout_cookie" "' is not a class type."); static_assert(
!std::is_base_of<nsISupports, DR_layout_cookie>::value,
"nsISupports classes don't need to call MOZ_COUNT_CTOR or " "MOZ_COUNT_DTOR"
);; NS_LogDtor((void*)this, "DR_layout_cookie", sizeof(*this)
); } while (0)
;
11572 nsIFrame::DisplayLayoutExit(mFrame, mValue);
11573}
11574
11575DR_intrinsic_inline_size_cookie::DR_intrinsic_inline_size_cookie(
11576 nsIFrame* aFrame, const char* aType, nscoord& aResult)
11577 : mFrame(aFrame), mType(aType), mResult(aResult) {
11578 MOZ_COUNT_CTOR(DR_intrinsic_inline_size_cookie)do { static_assert(std::is_class_v<DR_intrinsic_inline_size_cookie
>, "Token '" "DR_intrinsic_inline_size_cookie" "' is not a class type."
); static_assert(!std::is_base_of<nsISupports, DR_intrinsic_inline_size_cookie
>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogCtor((void*)this, "DR_intrinsic_inline_size_cookie"
, sizeof(*this)); } while (0)
;
11579 mValue = nsIFrame::DisplayIntrinsicISizeEnter(mFrame, mType);
11580}
11581
11582DR_intrinsic_inline_size_cookie::~DR_intrinsic_inline_size_cookie() {
11583 MOZ_COUNT_DTOR(DR_intrinsic_inline_size_cookie)do { static_assert(std::is_class_v<DR_intrinsic_inline_size_cookie
>, "Token '" "DR_intrinsic_inline_size_cookie" "' is not a class type."
); static_assert(!std::is_base_of<nsISupports, DR_intrinsic_inline_size_cookie
>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "DR_intrinsic_inline_size_cookie"
, sizeof(*this)); } while (0)
;
11584 nsIFrame::DisplayIntrinsicISizeExit(mFrame, mType, mResult, mValue);
11585}
11586
11587DR_intrinsic_size_cookie::DR_intrinsic_size_cookie(nsIFrame* aFrame,
11588 const char* aType,
11589 nsSize& aResult)
11590 : mFrame(aFrame), mType(aType), mResult(aResult) {
11591 MOZ_COUNT_CTOR(DR_intrinsic_size_cookie)do { static_assert(std::is_class_v<DR_intrinsic_size_cookie
>, "Token '" "DR_intrinsic_size_cookie" "' is not a class type."
); static_assert(!std::is_base_of<nsISupports, DR_intrinsic_size_cookie
>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogCtor((void*)this, "DR_intrinsic_size_cookie"
, sizeof(*this)); } while (0)
;
11592 mValue = nsIFrame::DisplayIntrinsicSizeEnter(mFrame, mType);
11593}
11594
11595DR_intrinsic_size_cookie::~DR_intrinsic_size_cookie() {
11596 MOZ_COUNT_DTOR(DR_intrinsic_size_cookie)do { static_assert(std::is_class_v<DR_intrinsic_size_cookie
>, "Token '" "DR_intrinsic_size_cookie" "' is not a class type."
); static_assert(!std::is_base_of<nsISupports, DR_intrinsic_size_cookie
>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "DR_intrinsic_size_cookie"
, sizeof(*this)); } while (0)
;
11597 nsIFrame::DisplayIntrinsicSizeExit(mFrame, mType, mResult, mValue);
11598}
11599
11600DR_init_constraints_cookie::DR_init_constraints_cookie(
11601 nsIFrame* aFrame, ReflowInput* aState, nscoord aCBWidth, nscoord aCBHeight,
11602 const mozilla::Maybe<mozilla::LogicalMargin> aBorder,
11603 const mozilla::Maybe<mozilla::LogicalMargin> aPadding)
11604 : mFrame(aFrame), mState(aState) {
11605 MOZ_COUNT_CTOR(DR_init_constraints_cookie)do { static_assert(std::is_class_v<DR_init_constraints_cookie
>, "Token '" "DR_init_constraints_cookie" "' is not a class type."
); static_assert(!std::is_base_of<nsISupports, DR_init_constraints_cookie
>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogCtor((void*)this, "DR_init_constraints_cookie"
, sizeof(*this)); } while (0)
;
11606 nsMargin border;
11607 if (aBorder) {
11608 border = aBorder->GetPhysicalMargin(aFrame->GetWritingMode());
11609 }
11610 nsMargin padding;
11611 if (aPadding) {
11612 padding = aPadding->GetPhysicalMargin(aFrame->GetWritingMode());
11613 }
11614 mValue = ReflowInput::DisplayInitConstraintsEnter(
11615 mFrame, mState, aCBWidth, aCBHeight, aBorder ? &border : nullptr,
11616 aPadding ? &padding : nullptr);
11617}
11618
11619DR_init_constraints_cookie::~DR_init_constraints_cookie() {
11620 MOZ_COUNT_DTOR(DR_init_constraints_cookie)do { static_assert(std::is_class_v<DR_init_constraints_cookie
>, "Token '" "DR_init_constraints_cookie" "' is not a class type."
); static_assert(!std::is_base_of<nsISupports, DR_init_constraints_cookie
>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "DR_init_constraints_cookie"
, sizeof(*this)); } while (0)
;
11621 ReflowInput::DisplayInitConstraintsExit(mFrame, mState, mValue);
11622}
11623
11624DR_init_offsets_cookie::DR_init_offsets_cookie(
11625 nsIFrame* aFrame, SizeComputationInput* aState, nscoord aPercentBasis,
11626 WritingMode aCBWritingMode,
11627 const mozilla::Maybe<mozilla::LogicalMargin> aBorder,
11628 const mozilla::Maybe<mozilla::LogicalMargin> aPadding)
11629 : mFrame(aFrame), mState(aState) {
11630 MOZ_COUNT_CTOR(DR_init_offsets_cookie)do { static_assert(std::is_class_v<DR_init_offsets_cookie>
, "Token '" "DR_init_offsets_cookie" "' is not a class type."
); static_assert(!std::is_base_of<nsISupports, DR_init_offsets_cookie
>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogCtor((void*)this, "DR_init_offsets_cookie"
, sizeof(*this)); } while (0)
;
11631 nsMargin border;
11632 if (aBorder) {
11633 border = aBorder->GetPhysicalMargin(aFrame->GetWritingMode());
11634 }
11635 nsMargin padding;
11636 if (aPadding) {
11637 padding = aPadding->GetPhysicalMargin(aFrame->GetWritingMode());
11638 }
11639 mValue = SizeComputationInput::DisplayInitOffsetsEnter(
11640 mFrame, mState, aPercentBasis, aCBWritingMode,
11641 aBorder ? &border : nullptr, aPadding ? &padding : nullptr);
11642}
11643
11644DR_init_offsets_cookie::~DR_init_offsets_cookie() {
11645 MOZ_COUNT_DTOR(DR_init_offsets_cookie)do { static_assert(std::is_class_v<DR_init_offsets_cookie>
, "Token '" "DR_init_offsets_cookie" "' is not a class type."
); static_assert(!std::is_base_of<nsISupports, DR_init_offsets_cookie
>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "DR_init_offsets_cookie"
, sizeof(*this)); } while (0)
;
11646 SizeComputationInput::DisplayInitOffsetsExit(mFrame, mState, mValue);
11647}
11648
11649struct DR_Rule;
11650
11651struct DR_FrameTypeInfo {
11652 DR_FrameTypeInfo(LayoutFrameType aFrameType, const char* aFrameNameAbbrev,
11653 const char* aFrameName);
11654 ~DR_FrameTypeInfo();
11655
11656 LayoutFrameType mType;
11657 char mNameAbbrev[16];
11658 char mName[32];
11659 nsTArray<DR_Rule*> mRules;
11660
11661 private:
11662 DR_FrameTypeInfo& operator=(const DR_FrameTypeInfo&) = delete;
11663};
11664
11665struct DR_FrameTreeNode;
11666struct DR_Rule;
11667
11668struct DR_State {
11669 DR_State();
11670 ~DR_State();
11671 void Init();
11672 void AddFrameTypeInfo(LayoutFrameType aFrameType,
11673 const char* aFrameNameAbbrev, const char* aFrameName);
11674 DR_FrameTypeInfo* GetFrameTypeInfo(LayoutFrameType aFrameType);
11675 DR_FrameTypeInfo* GetFrameTypeInfo(char* aFrameName);
11676 void InitFrameTypeTable();
11677 DR_FrameTreeNode* CreateTreeNode(nsIFrame* aFrame,
11678 const ReflowInput* aReflowInput);
11679 void FindMatchingRule(DR_FrameTreeNode& aNode);
11680 bool RuleMatches(DR_Rule& aRule, DR_FrameTreeNode& aNode);
11681 bool GetToken(FILE* aFile, char* aBuf, size_t aBufSize);
11682 DR_Rule* ParseRule(FILE* aFile);
11683 void ParseRulesFile();
11684 void AddRule(nsTArray<DR_Rule*>& aRules, DR_Rule& aRule);
11685 bool IsWhiteSpace(int c);
11686 bool GetNumber(char* aBuf, int32_t& aNumber);
11687 void PrettyUC(nscoord aSize, char* aBuf, int aBufSize);
11688 void PrintMargin(const char* tag, const nsMargin* aMargin);
11689 void DisplayFrameTypeInfo(nsIFrame* aFrame, int32_t aIndent);
11690 void DeleteTreeNode(DR_FrameTreeNode& aNode);
11691
11692 bool mInited;
11693 bool mActive;
11694 int32_t mCount;
11695 int32_t mAssert;
11696 int32_t mIndent;
11697 bool mIndentUndisplayedFrames;
11698 bool mDisplayPixelErrors;
11699 nsTArray<DR_Rule*> mWildRules;
11700 nsTArray<DR_FrameTypeInfo> mFrameTypeTable;
11701 // reflow specific state
11702 nsTArray<DR_FrameTreeNode*> mFrameTreeLeaves;
11703};
11704
11705static DR_State* DR_state; // the one and only DR_State
11706
11707struct DR_RulePart {
11708 explicit DR_RulePart(LayoutFrameType aFrameType)
11709 : mFrameType(aFrameType), mNext(0) {}
11710
11711 void Destroy();
11712
11713 LayoutFrameType mFrameType;
11714 DR_RulePart* mNext;
11715};
11716
11717void DR_RulePart::Destroy() {
11718 if (mNext) {
11719 mNext->Destroy();
11720 }
11721 delete this;
11722}
11723
11724struct DR_Rule {
11725 DR_Rule() : mLength(0), mTarget(nullptr), mDisplay(false) {
11726 MOZ_COUNT_CTOR(DR_Rule)do { static_assert(std::is_class_v<DR_Rule>, "Token '" "DR_Rule"
"' is not a class type."); static_assert(!std::is_base_of<
nsISupports, DR_Rule>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogCtor((void*)this, "DR_Rule", sizeof
(*this)); } while (0)
;
11727 }
11728 ~DR_Rule() {
11729 if (mTarget) mTarget->Destroy();
11730 MOZ_COUNT_DTOR(DR_Rule)do { static_assert(std::is_class_v<DR_Rule>, "Token '" "DR_Rule"
"' is not a class type."); static_assert(!std::is_base_of<
nsISupports, DR_Rule>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "DR_Rule", sizeof
(*this)); } while (0)
;
11731 }
11732 void AddPart(LayoutFrameType aFrameType);
11733
11734 uint32_t mLength;
11735 DR_RulePart* mTarget;
11736 bool mDisplay;
11737};
11738
11739void DR_Rule::AddPart(LayoutFrameType aFrameType) {
11740 DR_RulePart* newPart = new DR_RulePart(aFrameType);
11741 newPart->mNext = mTarget;
11742 mTarget = newPart;
11743 mLength++;
11744}
11745
11746DR_FrameTypeInfo::~DR_FrameTypeInfo() {
11747 int32_t numElements;
11748 numElements = mRules.Length();
11749 for (int32_t i = numElements - 1; i >= 0; i--) {
11750 delete mRules.ElementAt(i);
11751 }
11752}
11753
11754DR_FrameTypeInfo::DR_FrameTypeInfo(LayoutFrameType aFrameType,
11755 const char* aFrameNameAbbrev,
11756 const char* aFrameName) {
11757 mType = aFrameType;
11758 PL_strncpyz(mNameAbbrev, aFrameNameAbbrev, sizeof(mNameAbbrev));
11759 PL_strncpyz(mName, aFrameName, sizeof(mName));
11760}
11761
11762struct DR_FrameTreeNode {
11763 DR_FrameTreeNode(nsIFrame* aFrame, DR_FrameTreeNode* aParent)
11764 : mFrame(aFrame), mParent(aParent), mDisplay(0), mIndent(0) {
11765 MOZ_COUNT_CTOR(DR_FrameTreeNode)do { static_assert(std::is_class_v<DR_FrameTreeNode>, "Token '"
"DR_FrameTreeNode" "' is not a class type."); static_assert(
!std::is_base_of<nsISupports, DR_FrameTreeNode>::value,
"nsISupports classes don't need to call MOZ_COUNT_CTOR or " "MOZ_COUNT_DTOR"
);; NS_LogCtor((void*)this, "DR_FrameTreeNode", sizeof(*this)
); } while (0)
;
11766 }
11767
11768 MOZ_COUNTED_DTOR(DR_FrameTreeNode)~DR_FrameTreeNode() { do { static_assert(std::is_class_v<DR_FrameTreeNode
>, "Token '" "DR_FrameTreeNode" "' is not a class type.");
static_assert(!std::is_base_of<nsISupports, DR_FrameTreeNode
>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "DR_FrameTreeNode"
, sizeof(*this)); } while (0); }
11769
11770 nsIFrame* mFrame;
11771 DR_FrameTreeNode* mParent;
11772 bool mDisplay;
11773 uint32_t mIndent;
11774};
11775
11776// DR_State implementation
11777
11778DR_State::DR_State()
11779 : mInited(false),
11780 mActive(false),
11781 mCount(0),
11782 mAssert(-1),
11783 mIndent(0),
11784 mIndentUndisplayedFrames(false),
11785 mDisplayPixelErrors(false) {
11786 MOZ_COUNT_CTOR(DR_State)do { static_assert(std::is_class_v<DR_State>, "Token '"
"DR_State" "' is not a class type."); static_assert(!std::is_base_of
<nsISupports, DR_State>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogCtor((void*)this, "DR_State", sizeof
(*this)); } while (0)
;
11787}
11788
11789void DR_State::Init() {
11790 char* env = PR_GetEnv("GECKO_DISPLAY_REFLOW_ASSERT");
11791 int32_t num;
11792 if (env) {
11793 if (GetNumber(env, num))
11794 mAssert = num;
11795 else
11796 printf("GECKO_DISPLAY_REFLOW_ASSERT - invalid value = %s", env);
11797 }
11798
11799 env = PR_GetEnv("GECKO_DISPLAY_REFLOW_INDENT_START");
11800 if (env) {
11801 if (GetNumber(env, num))
11802 mIndent = num;
11803 else
11804 printf("GECKO_DISPLAY_REFLOW_INDENT_START - invalid value = %s", env);
11805 }
11806
11807 env = PR_GetEnv("GECKO_DISPLAY_REFLOW_INDENT_UNDISPLAYED_FRAMES");
11808 if (env) {
11809 if (GetNumber(env, num))
11810 mIndentUndisplayedFrames = num;
11811 else
11812 printf(
11813 "GECKO_DISPLAY_REFLOW_INDENT_UNDISPLAYED_FRAMES - invalid value = %s",
11814 env);
11815 }
11816
11817 env = PR_GetEnv("GECKO_DISPLAY_REFLOW_FLAG_PIXEL_ERRORS");
11818 if (env) {
11819 if (GetNumber(env, num))
11820 mDisplayPixelErrors = num;
11821 else
11822 printf("GECKO_DISPLAY_REFLOW_FLAG_PIXEL_ERRORS - invalid value = %s",
11823 env);
11824 }
11825
11826 InitFrameTypeTable();
11827 ParseRulesFile();
11828 mInited = true;
11829}
11830
11831DR_State::~DR_State() {
11832 MOZ_COUNT_DTOR(DR_State)do { static_assert(std::is_class_v<DR_State>, "Token '"
"DR_State" "' is not a class type."); static_assert(!std::is_base_of
<nsISupports, DR_State>::value, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "DR_State", sizeof
(*this)); } while (0)
;
11833 int32_t numElements, i;
11834 numElements = mWildRules.Length();
11835 for (i = numElements - 1; i >= 0; i--) {
11836 delete mWildRules.ElementAt(i);
11837 }
11838 numElements = mFrameTreeLeaves.Length();
11839 for (i = numElements - 1; i >= 0; i--) {
11840 delete mFrameTreeLeaves.ElementAt(i);
11841 }
11842}
11843
11844bool DR_State::GetNumber(char* aBuf, int32_t& aNumber) {
11845 if (sscanf(aBuf, "%d", &aNumber) > 0)
11846 return true;
11847 else
11848 return false;
11849}
11850
11851bool DR_State::IsWhiteSpace(int c) {
11852 return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r');
11853}
11854
11855bool DR_State::GetToken(FILE* aFile, char* aBuf, size_t aBufSize) {
11856 bool haveToken = false;
11857 aBuf[0] = 0;
11858 // get the 1st non whitespace char
11859 int c = -1;
11860 for (c = getc(aFile); (c > 0) && IsWhiteSpace(c); c = getc(aFile)) {
11861 }
11862
11863 if (c > 0) {
11864 haveToken = true;
11865 aBuf[0] = c;
11866 // get everything up to the next whitespace char
11867 size_t cX;
11868 for (cX = 1; cX + 1 < aBufSize; cX++) {
11869 c = getc(aFile);
11870 if (c < 0) { // EOF
11871 ungetc(' ', aFile);
11872 break;
11873 } else {
11874 if (IsWhiteSpace(c)) {
11875 break;
11876 } else {
11877 aBuf[cX] = c;
11878 }
11879 }
11880 }
11881 aBuf[cX] = 0;
11882 }
11883 return haveToken;
11884}
11885
11886DR_Rule* DR_State::ParseRule(FILE* aFile) {
11887 char buf[128];
11888 int32_t doDisplay;
11889 DR_Rule* rule = nullptr;
11890 while (GetToken(aFile, buf, sizeof(buf))) {
11891 if (GetNumber(buf, doDisplay)) {
11892 if (rule) {
11893 rule->mDisplay = !!doDisplay;
11894 break;
11895 } else {
11896 printf("unexpected token - %s \n", buf);
11897 }
11898 } else {
11899 if (!rule) {
11900 rule = new DR_Rule;
11901 }
11902 if (strcmp(buf, "*") == 0) {
11903 rule->AddPart(LayoutFrameType::None);
11904 } else {
11905 DR_FrameTypeInfo* info = GetFrameTypeInfo(buf);
11906 if (info) {
11907 rule->AddPart(info->mType);
11908 } else {
11909 printf("invalid frame type - %s \n", buf);
11910 }
11911 }
11912 }
11913 }
11914 return rule;
11915}
11916
11917void DR_State::AddRule(nsTArray<DR_Rule*>& aRules, DR_Rule& aRule) {
11918 int32_t numRules = aRules.Length();
11919 for (int32_t ruleX = 0; ruleX < numRules; ruleX++) {
11920 DR_Rule* rule = aRules.ElementAt(ruleX);
11921 NS_ASSERTION(rule, "program error")do { if (!(rule)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "program error"
, "rule", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11921); MOZ_PretendNoReturn(); } } while (0)
;
11922 if (aRule.mLength > rule->mLength) {
11923 aRules.InsertElementAt(ruleX, &aRule);
11924 return;
11925 }
11926 }
11927 aRules.AppendElement(&aRule);
11928}
11929
11930static Maybe<bool> ShouldLogReflow(const char* processes) {
11931 switch (processes[0]) {
11932 case 'A':
11933 case 'a':
11934 return Some(true);
11935 case 'P':
11936 case 'p':
11937 return Some(XRE_IsParentProcess());
11938 case 'C':
11939 case 'c':
11940 return Some(XRE_IsContentProcess());
11941 default:
11942 return Nothing{};
11943 }
11944}
11945
11946void DR_State::ParseRulesFile() {
11947 char* processes = PR_GetEnv("GECKO_DISPLAY_REFLOW_PROCESSES");
11948 if (processes) {
11949 Maybe<bool> enableLog = ShouldLogReflow(processes);
11950 if (enableLog.isNothing()) {
11951 MOZ_CRASH("GECKO_DISPLAY_REFLOW_PROCESSES: [a]ll [p]arent [c]ontent")do { do { } while (false); MOZ_ReportCrash("" "GECKO_DISPLAY_REFLOW_PROCESSES: [a]ll [p]arent [c]ontent"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11951); AnnotateMozCrashReason("MOZ_CRASH(" "GECKO_DISPLAY_REFLOW_PROCESSES: [a]ll [p]arent [c]ontent"
")"); do { *((volatile int*)__null) = 11951; __attribute__((
nomerge)) ::abort(); } while (false); } while (false)
;
11952 } else if (enableLog.value()) {
11953 DR_Rule* rule = new DR_Rule;
11954 rule->AddPart(LayoutFrameType::None);
11955 rule->mDisplay = true;
11956 AddRule(mWildRules, *rule);
11957 mActive = true;
11958 }
11959 return;
11960 }
11961
11962 char* path = PR_GetEnv("GECKO_DISPLAY_REFLOW_RULES_FILE");
11963 if (path) {
11964 FILE* inFile = fopen(path, "r");
11965 if (!inFile) {
11966 MOZ_CRASH(do { do { } while (false); MOZ_ReportCrash("" "Failed to open the specified rules file; Try `--setpref "
"security.sandbox.content.level=2` if the sandbox is at cause"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11968); AnnotateMozCrashReason("MOZ_CRASH(" "Failed to open the specified rules file; Try `--setpref "
"security.sandbox.content.level=2` if the sandbox is at cause"
")"); do { *((volatile int*)__null) = 11968; __attribute__((
nomerge)) ::abort(); } while (false); } while (false)
11967 "Failed to open the specified rules file; Try `--setpref "do { do { } while (false); MOZ_ReportCrash("" "Failed to open the specified rules file; Try `--setpref "
"security.sandbox.content.level=2` if the sandbox is at cause"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11968); AnnotateMozCrashReason("MOZ_CRASH(" "Failed to open the specified rules file; Try `--setpref "
"security.sandbox.content.level=2` if the sandbox is at cause"
")"); do { *((volatile int*)__null) = 11968; __attribute__((
nomerge)) ::abort(); } while (false); } while (false)
11968 "security.sandbox.content.level=2` if the sandbox is at cause")do { do { } while (false); MOZ_ReportCrash("" "Failed to open the specified rules file; Try `--setpref "
"security.sandbox.content.level=2` if the sandbox is at cause"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11968); AnnotateMozCrashReason("MOZ_CRASH(" "Failed to open the specified rules file; Try `--setpref "
"security.sandbox.content.level=2` if the sandbox is at cause"
")"); do { *((volatile int*)__null) = 11968; __attribute__((
nomerge)) ::abort(); } while (false); } while (false)
;
11969 }
11970 for (DR_Rule* rule = ParseRule(inFile); rule; rule = ParseRule(inFile)) {
11971 if (rule->mTarget) {
11972 LayoutFrameType fType = rule->mTarget->mFrameType;
11973 if (fType != LayoutFrameType::None) {
11974 DR_FrameTypeInfo* info = GetFrameTypeInfo(fType);
11975 AddRule(info->mRules, *rule);
11976 } else {
11977 AddRule(mWildRules, *rule);
11978 }
11979 mActive = true;
11980 }
11981 }
11982
11983 fclose(inFile);
11984 }
11985}
11986
11987void DR_State::AddFrameTypeInfo(LayoutFrameType aFrameType,
11988 const char* aFrameNameAbbrev,
11989 const char* aFrameName) {
11990 mFrameTypeTable.EmplaceBack(aFrameType, aFrameNameAbbrev, aFrameName);
11991}
11992
11993DR_FrameTypeInfo* DR_State::GetFrameTypeInfo(LayoutFrameType aFrameType) {
11994 int32_t numEntries = mFrameTypeTable.Length();
11995 NS_ASSERTION(numEntries != 0, "empty FrameTypeTable")do { if (!(numEntries != 0)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "empty FrameTypeTable", "numEntries != 0", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11995); MOZ_PretendNoReturn(); } } while (0)
;
11996 for (int32_t i = 0; i < numEntries; i++) {
11997 DR_FrameTypeInfo& info = mFrameTypeTable.ElementAt(i);
11998 if (info.mType == aFrameType) {
11999 return &info;
12000 }
12001 }
12002 return &mFrameTypeTable.ElementAt(numEntries -
12003 1); // return unknown frame type
12004}
12005
12006DR_FrameTypeInfo* DR_State::GetFrameTypeInfo(char* aFrameName) {
12007 int32_t numEntries = mFrameTypeTable.Length();
12008 NS_ASSERTION(numEntries != 0, "empty FrameTypeTable")do { if (!(numEntries != 0)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "empty FrameTypeTable", "numEntries != 0", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12008); MOZ_PretendNoReturn(); } } while (0)
;
12009 for (int32_t i = 0; i < numEntries; i++) {
12010 DR_FrameTypeInfo& info = mFrameTypeTable.ElementAt(i);
12011 if ((strcmp(aFrameName, info.mName) == 0) ||
12012 (strcmp(aFrameName, info.mNameAbbrev) == 0)) {
12013 return &info;
12014 }
12015 }
12016 return &mFrameTypeTable.ElementAt(numEntries -
12017 1); // return unknown frame type
12018}
12019
12020void DR_State::InitFrameTypeTable() {
12021 AddFrameTypeInfo(LayoutFrameType::Block, "block", "block");
12022 AddFrameTypeInfo(LayoutFrameType::Br, "br", "br");
12023 AddFrameTypeInfo(LayoutFrameType::ColorControl, "color", "colorControl");
12024 AddFrameTypeInfo(LayoutFrameType::GfxButtonControl, "button",
12025 "gfxButtonControl");
12026 AddFrameTypeInfo(LayoutFrameType::HTMLButtonControl, "HTMLbutton",
12027 "HTMLButtonControl");
12028 AddFrameTypeInfo(LayoutFrameType::HTMLCanvas, "HTMLCanvas", "HTMLCanvas");
12029 AddFrameTypeInfo(LayoutFrameType::SubDocument, "subdoc", "subDocument");
12030 AddFrameTypeInfo(LayoutFrameType::Image, "img", "image");
12031 AddFrameTypeInfo(LayoutFrameType::Inline, "inline", "inline");
12032 AddFrameTypeInfo(LayoutFrameType::Letter, "letter", "letter");
12033 AddFrameTypeInfo(LayoutFrameType::Line, "line", "line");
12034 AddFrameTypeInfo(LayoutFrameType::ListControl, "select", "select");
12035 AddFrameTypeInfo(LayoutFrameType::Page, "page", "page");
12036 AddFrameTypeInfo(LayoutFrameType::Placeholder, "place", "placeholder");
12037 AddFrameTypeInfo(LayoutFrameType::Canvas, "canvas", "canvas");
12038 AddFrameTypeInfo(LayoutFrameType::Scroll, "scroll", "scroll");
12039 AddFrameTypeInfo(LayoutFrameType::TableCell, "cell", "tableCell");
12040 AddFrameTypeInfo(LayoutFrameType::TableCol, "col", "tableCol");
12041 AddFrameTypeInfo(LayoutFrameType::TableColGroup, "colG", "tableColGroup");
12042 AddFrameTypeInfo(LayoutFrameType::Table, "tbl", "table");
12043 AddFrameTypeInfo(LayoutFrameType::TableWrapper, "tblW", "tableWrapper");
12044 AddFrameTypeInfo(LayoutFrameType::TableRowGroup, "rowG", "tableRowGroup");
12045 AddFrameTypeInfo(LayoutFrameType::TableRow, "row", "tableRow");
12046 AddFrameTypeInfo(LayoutFrameType::TextInput, "textCtl", "textInput");
12047 AddFrameTypeInfo(LayoutFrameType::Text, "text", "text");
12048 AddFrameTypeInfo(LayoutFrameType::Viewport, "VP", "viewport");
12049 AddFrameTypeInfo(LayoutFrameType::Slider, "Slider", "Slider");
12050 AddFrameTypeInfo(LayoutFrameType::None, "unknown", "unknown");
12051}
12052
12053void DR_State::DisplayFrameTypeInfo(nsIFrame* aFrame, int32_t aIndent) {
12054 DR_FrameTypeInfo* frameTypeInfo = GetFrameTypeInfo(aFrame->Type());
12055 if (frameTypeInfo) {
12056 for (int32_t i = 0; i < aIndent; i++) {
12057 printf(" ");
12058 }
12059 if (!strcmp(frameTypeInfo->mNameAbbrev, "unknown")) {
12060 if (aFrame) {
12061 nsAutoString name;
12062 aFrame->GetFrameName(name);
12063 printf("%s %p ", NS_LossyConvertUTF16toASCII(name).get(),
12064 (void*)aFrame);
12065 } else {
12066 printf("%s %p ", frameTypeInfo->mNameAbbrev, (void*)aFrame);
12067 }
12068 } else {
12069 printf("%s %p ", frameTypeInfo->mNameAbbrev, (void*)aFrame);
12070 }
12071 }
12072}
12073
12074bool DR_State::RuleMatches(DR_Rule& aRule, DR_FrameTreeNode& aNode) {
12075 NS_ASSERTION(aRule.mTarget, "program error")do { if (!(aRule.mTarget)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "program error", "aRule.mTarget", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12075); MOZ_PretendNoReturn(); } } while (0)
;
12076
12077 DR_RulePart* rulePart;
12078 DR_FrameTreeNode* parentNode;
12079 for (rulePart = aRule.mTarget->mNext, parentNode = aNode.mParent;
12080 rulePart && parentNode;
12081 rulePart = rulePart->mNext, parentNode = parentNode->mParent) {
12082 if (rulePart->mFrameType != LayoutFrameType::None) {
12083 if (parentNode->mFrame) {
12084 if (rulePart->mFrameType != parentNode->mFrame->Type()) {
12085 return false;
12086 }
12087 } else
12088 NS_ASSERTION(false, "program error")do { if (!(false)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "program error"
, "false", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12088); MOZ_PretendNoReturn(); } } while (0)
;
12089 }
12090 // else wild card match
12091 }
12092 return true;
12093}
12094
12095void DR_State::FindMatchingRule(DR_FrameTreeNode& aNode) {
12096 if (!aNode.mFrame) {
12097 NS_ASSERTION(false, "invalid DR_FrameTreeNode \n")do { if (!(false)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "invalid DR_FrameTreeNode \n"
, "false", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12097); MOZ_PretendNoReturn(); } } while (0)
;
12098 return;
12099 }
12100
12101 bool matchingRule = false;
12102
12103 DR_FrameTypeInfo* info = GetFrameTypeInfo(aNode.mFrame->Type());
12104 NS_ASSERTION(info, "program error")do { if (!(info)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "program error"
, "info", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12104); MOZ_PretendNoReturn(); } } while (0)
;
12105 int32_t numRules = info->mRules.Length();
12106 for (int32_t ruleX = 0; ruleX < numRules; ruleX++) {
12107 DR_Rule* rule = info->mRules.ElementAt(ruleX);
12108 if (rule && RuleMatches(*rule, aNode)) {
12109 aNode.mDisplay = rule->mDisplay;
12110 matchingRule = true;
12111 break;
12112 }
12113 }
12114 if (!matchingRule) {
12115 int32_t numWildRules = mWildRules.Length();
12116 for (int32_t ruleX = 0; ruleX < numWildRules; ruleX++) {
12117 DR_Rule* rule = mWildRules.ElementAt(ruleX);
12118 if (rule && RuleMatches(*rule, aNode)) {
12119 aNode.mDisplay = rule->mDisplay;
12120 break;
12121 }
12122 }
12123 }
12124}
12125
12126DR_FrameTreeNode* DR_State::CreateTreeNode(nsIFrame* aFrame,
12127 const ReflowInput* aReflowInput) {
12128 // find the frame of the parent reflow input (usually just the parent of
12129 // aFrame)
12130 nsIFrame* parentFrame;
12131 if (aReflowInput) {
12132 const ReflowInput* parentRI = aReflowInput->mParentReflowInput;
12133 parentFrame = (parentRI) ? parentRI->mFrame : nullptr;
12134 } else {
12135 parentFrame = aFrame->GetParent();
12136 }
12137
12138 // find the parent tree node leaf
12139 DR_FrameTreeNode* parentNode = nullptr;
12140
12141 DR_FrameTreeNode* lastLeaf = nullptr;
12142 if (mFrameTreeLeaves.Length())
12143 lastLeaf = mFrameTreeLeaves.ElementAt(mFrameTreeLeaves.Length() - 1);
12144 if (lastLeaf) {
12145 for (parentNode = lastLeaf;
12146 parentNode && (parentNode->mFrame != parentFrame);
12147 parentNode = parentNode->mParent) {
12148 }
12149 }
12150 DR_FrameTreeNode* newNode = new DR_FrameTreeNode(aFrame, parentNode);
12151 FindMatchingRule(*newNode);
12152
12153 newNode->mIndent = mIndent;
12154 if (newNode->mDisplay || mIndentUndisplayedFrames) {
12155 ++mIndent;
12156 }
12157
12158 if (lastLeaf && (lastLeaf == parentNode)) {
12159 mFrameTreeLeaves.RemoveLastElement();
12160 }
12161 mFrameTreeLeaves.AppendElement(newNode);
12162 mCount++;
12163
12164 return newNode;
12165}
12166
12167void DR_State::PrettyUC(nscoord aSize, char* aBuf, int aBufSize) {
12168 if (NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1) == aSize) {
12169 strcpy(aBuf, "UC");
12170 } else {
12171 if ((nscoord)0xdeadbeefU == aSize) {
12172 strcpy(aBuf, "deadbeef");
12173 } else {
12174 snprintf(aBuf, aBufSize, "%d", aSize);
12175 }
12176 }
12177}
12178
12179void DR_State::PrintMargin(const char* tag, const nsMargin* aMargin) {
12180 if (aMargin) {
12181 char t[16], r[16], b[16], l[16];
12182 PrettyUC(aMargin->top, t, 16);
12183 PrettyUC(aMargin->right, r, 16);
12184 PrettyUC(aMargin->bottom, b, 16);
12185 PrettyUC(aMargin->left, l, 16);
12186 printf(" %s=%s,%s,%s,%s", tag, t, r, b, l);
12187 } else {
12188 // use %p here for consistency with other null-pointer printouts
12189 printf(" %s=%p", tag, (void*)aMargin);
12190 }
12191}
12192
12193void DR_State::DeleteTreeNode(DR_FrameTreeNode& aNode) {
12194 mFrameTreeLeaves.RemoveElement(&aNode);
12195 int32_t numLeaves = mFrameTreeLeaves.Length();
12196 if ((0 == numLeaves) ||
12197 (aNode.mParent != mFrameTreeLeaves.ElementAt(numLeaves - 1))) {
12198 mFrameTreeLeaves.AppendElement(aNode.mParent);
12199 }
12200
12201 if (aNode.mDisplay || mIndentUndisplayedFrames) {
12202 --mIndent;
12203 }
12204 // delete the tree node
12205 delete &aNode;
12206}
12207
12208static void CheckPixelError(nscoord aSize, int32_t aPixelToTwips) {
12209 if (NS_UNCONSTRAINEDSIZEnscoord((1 << 30) - 1) != aSize) {
12210 if ((aSize % aPixelToTwips) > 0) {
12211 printf("VALUE %d is not a whole pixel \n", aSize);
12212 }
12213 }
12214}
12215
12216static void DisplayReflowEnterPrint(nsPresContext* aPresContext,
12217 nsIFrame* aFrame,
12218 const ReflowInput& aReflowInput,
12219 DR_FrameTreeNode& aTreeNode,
12220 bool aChanged) {
12221 if (aTreeNode.mDisplay) {
12222 DR_state->DisplayFrameTypeInfo(aFrame, aTreeNode.mIndent);
12223
12224 char width[16];
12225 char height[16];
12226
12227 DR_state->PrettyUC(aReflowInput.AvailableWidth(), width, 16);
12228 DR_state->PrettyUC(aReflowInput.AvailableHeight(), height, 16);
12229 printf("Reflow a=%s,%s ", width, height);
12230
12231 DR_state->PrettyUC(aReflowInput.ComputedWidth(), width, 16);
12232 DR_state->PrettyUC(aReflowInput.ComputedHeight(), height, 16);
12233 printf("c=%s,%s ", width, height);
12234
12235 if (aFrame->HasAnyStateBits(NS_FRAME_IS_DIRTY)) printf("dirty ");
12236
12237 if (aFrame->HasAnyStateBits(NS_FRAME_HAS_DIRTY_CHILDREN))
12238 printf("dirty-children ");
12239
12240 if (aReflowInput.mFlags.mSpecialBSizeReflow) printf("special-bsize ");
12241
12242 if (aReflowInput.IsHResize()) printf("h-resize ");
12243
12244 if (aReflowInput.IsVResize()) printf("v-resize ");
12245
12246 nsIFrame* inFlow = aFrame->GetPrevInFlow();
12247 if (inFlow) {
12248 printf("pif=%p ", (void*)inFlow);
12249 }
12250 inFlow = aFrame->GetNextInFlow();
12251 if (inFlow) {
12252 printf("nif=%p ", (void*)inFlow);
12253 }
12254 if (aChanged)
12255 printf("CHANGED \n");
12256 else
12257 printf("cnt=%d \n", DR_state->mCount);
12258 if (DR_state->mDisplayPixelErrors) {
12259 int32_t d2a = aPresContext->AppUnitsPerDevPixel();
12260 CheckPixelError(aReflowInput.AvailableWidth(), d2a);
12261 CheckPixelError(aReflowInput.AvailableHeight(), d2a);
12262 CheckPixelError(aReflowInput.ComputedWidth(), d2a);
12263 CheckPixelError(aReflowInput.ComputedHeight(), d2a);
12264 }
12265 }
12266}
12267
12268void* nsIFrame::DisplayReflowEnter(nsPresContext* aPresContext,
12269 nsIFrame* aFrame,
12270 const ReflowInput& aReflowInput) {
12271 if (!DR_state->mInited) DR_state->Init();
12272 if (!DR_state->mActive) return nullptr;
12273
12274 NS_ASSERTION(aFrame, "invalid call")do { if (!(aFrame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "invalid call"
, "aFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12274); MOZ_PretendNoReturn(); } } while (0)
;
12275
12276 DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, &aReflowInput);
12277 if (treeNode) {
12278 DisplayReflowEnterPrint(aPresContext, aFrame, aReflowInput, *treeNode,
12279 false);
12280 }
12281 return treeNode;
12282}
12283
12284void* nsIFrame::DisplayLayoutEnter(nsIFrame* aFrame) {
12285 if (!DR_state->mInited) DR_state->Init();
12286 if (!DR_state->mActive) return nullptr;
12287
12288 NS_ASSERTION(aFrame, "invalid call")do { if (!(aFrame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "invalid call"
, "aFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12288); MOZ_PretendNoReturn(); } } while (0)
;
12289
12290 DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr);
12291 if (treeNode && treeNode->mDisplay) {
12292 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12293 printf("XULLayout\n");
12294 }
12295 return treeNode;
12296}
12297
12298void* nsIFrame::DisplayIntrinsicISizeEnter(nsIFrame* aFrame,
12299 const char* aType) {
12300 if (!DR_state->mInited) DR_state->Init();
12301 if (!DR_state->mActive) return nullptr;
12302
12303 NS_ASSERTION(aFrame, "invalid call")do { if (!(aFrame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "invalid call"
, "aFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12303); MOZ_PretendNoReturn(); } } while (0)
;
12304
12305 DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr);
12306 if (treeNode && treeNode->mDisplay) {
12307 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12308 printf("Get%sISize\n", aType);
12309 }
12310 return treeNode;
12311}
12312
12313void* nsIFrame::DisplayIntrinsicSizeEnter(nsIFrame* aFrame, const char* aType) {
12314 if (!DR_state->mInited) DR_state->Init();
12315 if (!DR_state->mActive) return nullptr;
12316
12317 NS_ASSERTION(aFrame, "invalid call")do { if (!(aFrame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "invalid call"
, "aFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12317); MOZ_PretendNoReturn(); } } while (0)
;
12318
12319 DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr);
12320 if (treeNode && treeNode->mDisplay) {
12321 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12322 printf("Get%sSize\n", aType);
12323 }
12324 return treeNode;
12325}
12326
12327void nsIFrame::DisplayReflowExit(nsPresContext* aPresContext, nsIFrame* aFrame,
12328 ReflowOutput& aMetrics,
12329 const nsReflowStatus& aStatus,
12330 void* aFrameTreeNode) {
12331 if (!DR_state->mActive) return;
12332
12333 NS_ASSERTION(aFrame, "DisplayReflowExit - invalid call")do { if (!(aFrame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "DisplayReflowExit - invalid call"
, "aFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12333); MOZ_PretendNoReturn(); } } while (0)
;
12334 if (!aFrameTreeNode) return;
12335
12336 DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aFrameTreeNode;
12337 if (treeNode->mDisplay) {
12338 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12339
12340 char width[16];
12341 char height[16];
12342 char x[16];
12343 char y[16];
12344 DR_state->PrettyUC(aMetrics.Width(), width, 16);
12345 DR_state->PrettyUC(aMetrics.Height(), height, 16);
12346 printf("Reflow d=%s,%s", width, height);
12347
12348 if (!aStatus.IsEmpty()) {
12349 printf(" status=%s", ToString(aStatus).c_str());
12350 }
12351 if (aFrame->HasOverflowAreas()) {
12352 DR_state->PrettyUC(aMetrics.InkOverflow().x, x, 16);
12353 DR_state->PrettyUC(aMetrics.InkOverflow().y, y, 16);
12354 DR_state->PrettyUC(aMetrics.InkOverflow().width, width, 16);
12355 DR_state->PrettyUC(aMetrics.InkOverflow().height, height, 16);
12356 printf(" vis-o=(%s,%s) %s x %s", x, y, width, height);
12357
12358 nsRect storedOverflow = aFrame->InkOverflowRect();
12359 DR_state->PrettyUC(storedOverflow.x, x, 16);
12360 DR_state->PrettyUC(storedOverflow.y, y, 16);
12361 DR_state->PrettyUC(storedOverflow.width, width, 16);
12362 DR_state->PrettyUC(storedOverflow.height, height, 16);
12363 printf(" vis-sto=(%s,%s) %s x %s", x, y, width, height);
12364
12365 DR_state->PrettyUC(aMetrics.ScrollableOverflow().x, x, 16);
12366 DR_state->PrettyUC(aMetrics.ScrollableOverflow().y, y, 16);
12367 DR_state->PrettyUC(aMetrics.ScrollableOverflow().width, width, 16);
12368 DR_state->PrettyUC(aMetrics.ScrollableOverflow().height, height, 16);
12369 printf(" scr-o=(%s,%s) %s x %s", x, y, width, height);
12370
12371 storedOverflow = aFrame->ScrollableOverflowRect();
12372 DR_state->PrettyUC(storedOverflow.x, x, 16);
12373 DR_state->PrettyUC(storedOverflow.y, y, 16);
12374 DR_state->PrettyUC(storedOverflow.width, width, 16);
12375 DR_state->PrettyUC(storedOverflow.height, height, 16);
12376 printf(" scr-sto=(%s,%s) %s x %s", x, y, width, height);
12377 }
12378 printf("\n");
12379 if (DR_state->mDisplayPixelErrors) {
12380 int32_t d2a = aPresContext->AppUnitsPerDevPixel();
12381 CheckPixelError(aMetrics.Width(), d2a);
12382 CheckPixelError(aMetrics.Height(), d2a);
12383 }
12384 }
12385 DR_state->DeleteTreeNode(*treeNode);
12386}
12387
12388void nsIFrame::DisplayLayoutExit(nsIFrame* aFrame, void* aFrameTreeNode) {
12389 if (!DR_state->mActive) return;
12390
12391 NS_ASSERTION(aFrame, "non-null frame required")do { if (!(aFrame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "non-null frame required"
, "aFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12391); MOZ_PretendNoReturn(); } } while (0)
;
12392 if (!aFrameTreeNode) return;
12393
12394 DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aFrameTreeNode;
12395 if (treeNode->mDisplay) {
12396 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12397 nsRect rect = aFrame->GetRect();
12398 printf("XULLayout=%d,%d,%d,%d\n", rect.x, rect.y, rect.width, rect.height);
12399 }
12400 DR_state->DeleteTreeNode(*treeNode);
12401}
12402
12403void nsIFrame::DisplayIntrinsicISizeExit(nsIFrame* aFrame, const char* aType,
12404 nscoord aResult,
12405 void* aFrameTreeNode) {
12406 if (!DR_state->mActive) return;
12407
12408 NS_ASSERTION(aFrame, "non-null frame required")do { if (!(aFrame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "non-null frame required"
, "aFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12408); MOZ_PretendNoReturn(); } } while (0)
;
12409 if (!aFrameTreeNode) return;
12410
12411 DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aFrameTreeNode;
12412 if (treeNode->mDisplay) {
12413 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12414 char iSize[16];
12415 DR_state->PrettyUC(aResult, iSize, 16);
12416 printf("Get%sISize=%s\n", aType, iSize);
12417 }
12418 DR_state->DeleteTreeNode(*treeNode);
12419}
12420
12421void nsIFrame::DisplayIntrinsicSizeExit(nsIFrame* aFrame, const char* aType,
12422 nsSize aResult, void* aFrameTreeNode) {
12423 if (!DR_state->mActive) return;
12424
12425 NS_ASSERTION(aFrame, "non-null frame required")do { if (!(aFrame)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "non-null frame required"
, "aFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12425); MOZ_PretendNoReturn(); } } while (0)
;
12426 if (!aFrameTreeNode) return;
12427
12428 DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aFrameTreeNode;
12429 if (treeNode->mDisplay) {
12430 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12431
12432 char width[16];
12433 char height[16];
12434 DR_state->PrettyUC(aResult.width, width, 16);
12435 DR_state->PrettyUC(aResult.height, height, 16);
12436 printf("Get%sSize=%s,%s\n", aType, width, height);
12437 }
12438 DR_state->DeleteTreeNode(*treeNode);
12439}
12440
12441/* static */
12442void nsIFrame::DisplayReflowStartup() { DR_state = new DR_State(); }
12443
12444/* static */
12445void nsIFrame::DisplayReflowShutdown() {
12446 delete DR_state;
12447 DR_state = nullptr;
12448}
12449
12450void DR_cookie::Change() const {
12451 DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)mValue;
12452 if (treeNode && treeNode->mDisplay) {
12453 DisplayReflowEnterPrint(mPresContext, mFrame, mReflowInput, *treeNode,
12454 true);
12455 }
12456}
12457
12458/* static */
12459void* ReflowInput::DisplayInitConstraintsEnter(nsIFrame* aFrame,
12460 ReflowInput* aState,
12461 nscoord aContainingBlockWidth,
12462 nscoord aContainingBlockHeight,
12463 const nsMargin* aBorder,
12464 const nsMargin* aPadding) {
12465 MOZ_ASSERT(aFrame, "non-null frame required")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aFrame)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aFrame))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aFrame" " (" "non-null frame required"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12465); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame" ") ("
"non-null frame required" ")"); do { *((volatile int*)__null
) = 12465; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
12466 MOZ_ASSERT(aState, "non-null state required")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aState)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aState))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aState" " (" "non-null state required"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12466); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aState" ") ("
"non-null state required" ")"); do { *((volatile int*)__null
) = 12466; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
12467
12468 if (!DR_state->mInited) DR_state->Init();
12469 if (!DR_state->mActive) return nullptr;
12470
12471 DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, aState);
12472 if (treeNode && treeNode->mDisplay) {
12473 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12474
12475 printf("InitConstraints parent=%p", (void*)aState->mParentReflowInput);
12476
12477 char width[16];
12478 char height[16];
12479
12480 DR_state->PrettyUC(aContainingBlockWidth, width, 16);
12481 DR_state->PrettyUC(aContainingBlockHeight, height, 16);
12482 printf(" cb=%s,%s", width, height);
12483
12484 DR_state->PrettyUC(aState->AvailableWidth(), width, 16);
12485 DR_state->PrettyUC(aState->AvailableHeight(), height, 16);
12486 printf(" as=%s,%s", width, height);
12487
12488 DR_state->PrintMargin("b", aBorder);
12489 DR_state->PrintMargin("p", aPadding);
12490 putchar('\n');
12491 }
12492 return treeNode;
12493}
12494
12495/* static */
12496void ReflowInput::DisplayInitConstraintsExit(nsIFrame* aFrame,
12497 ReflowInput* aState,
12498 void* aValue) {
12499 MOZ_ASSERT(aFrame, "non-null frame required")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aFrame)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aFrame))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aFrame" " (" "non-null frame required"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12499); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame" ") ("
"non-null frame required" ")"); do { *((volatile int*)__null
) = 12499; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
12500 MOZ_ASSERT(aState, "non-null state required")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aState)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aState))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aState" " (" "non-null state required"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12500); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aState" ") ("
"non-null state required" ")"); do { *((volatile int*)__null
) = 12500; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
12501
12502 if (!DR_state->mActive) return;
12503 if (!aValue) return;
12504
12505 DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aValue;
12506 if (treeNode->mDisplay) {
12507 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12508 char cmiw[16], cw[16], cmxw[16], cmih[16], ch[16], cmxh[16];
12509 DR_state->PrettyUC(aState->ComputedMinWidth(), cmiw, 16);
12510 DR_state->PrettyUC(aState->ComputedWidth(), cw, 16);
12511 DR_state->PrettyUC(aState->ComputedMaxWidth(), cmxw, 16);
12512 DR_state->PrettyUC(aState->ComputedMinHeight(), cmih, 16);
12513 DR_state->PrettyUC(aState->ComputedHeight(), ch, 16);
12514 DR_state->PrettyUC(aState->ComputedMaxHeight(), cmxh, 16);
12515 printf("InitConstraints= cw=(%s <= %s <= %s) ch=(%s <= %s <= %s)", cmiw, cw,
12516 cmxw, cmih, ch, cmxh);
12517 const nsMargin m = aState->ComputedPhysicalOffsets();
12518 DR_state->PrintMargin("co", &m);
12519 putchar('\n');
12520 }
12521 DR_state->DeleteTreeNode(*treeNode);
12522}
12523
12524/* static */
12525void* SizeComputationInput::DisplayInitOffsetsEnter(
12526 nsIFrame* aFrame, SizeComputationInput* aState, nscoord aPercentBasis,
12527 WritingMode aCBWritingMode, const nsMargin* aBorder,
12528 const nsMargin* aPadding) {
12529 MOZ_ASSERT(aFrame, "non-null frame required")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aFrame)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aFrame))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aFrame" " (" "non-null frame required"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12529); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame" ") ("
"non-null frame required" ")"); do { *((volatile int*)__null
) = 12529; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
12530 MOZ_ASSERT(aState, "non-null state required")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aState)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aState))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aState" " (" "non-null state required"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12530); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aState" ") ("
"non-null state required" ")"); do { *((volatile int*)__null
) = 12530; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
12531
12532 if (!DR_state->mInited) DR_state->Init();
12533 if (!DR_state->mActive) return nullptr;
12534
12535 // aState is not necessarily a ReflowInput
12536 DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr);
12537 if (treeNode && treeNode->mDisplay) {
12538 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12539
12540 char pctBasisStr[16];
12541 DR_state->PrettyUC(aPercentBasis, pctBasisStr, 16);
12542 printf("InitOffsets pct_basis=%s", pctBasisStr);
12543
12544 DR_state->PrintMargin("b", aBorder);
12545 DR_state->PrintMargin("p", aPadding);
12546 putchar('\n');
12547 }
12548 return treeNode;
12549}
12550
12551/* static */
12552void SizeComputationInput::DisplayInitOffsetsExit(nsIFrame* aFrame,
12553 SizeComputationInput* aState,
12554 void* aValue) {
12555 MOZ_ASSERT(aFrame, "non-null frame required")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aFrame)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aFrame))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aFrame" " (" "non-null frame required"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12555); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame" ") ("
"non-null frame required" ")"); do { *((volatile int*)__null
) = 12555; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
12556 MOZ_ASSERT(aState, "non-null state required")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aState)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(aState))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aState" " (" "non-null state required"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 12556); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aState" ") ("
"non-null state required" ")"); do { *((volatile int*)__null
) = 12556; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
12557
12558 if (!DR_state->mActive) return;
12559 if (!aValue) return;
12560
12561 DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aValue;
12562 if (treeNode->mDisplay) {
12563 DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
12564 printf("InitOffsets=");
12565 const auto m = aState->ComputedPhysicalMargin();
12566 DR_state->PrintMargin("m", &m);
12567 const auto p = aState->ComputedPhysicalPadding();
12568 DR_state->PrintMargin("p", &p);
12569 const auto bp = aState->ComputedPhysicalBorderPadding();
12570 DR_state->PrintMargin("b+p", &bp);
12571 putchar('\n');
12572 }
12573 DR_state->DeleteTreeNode(*treeNode);
12574}
12575
12576// End Display Reflow
12577
12578// Validation of SideIsVertical.
12579# define CASE(side, result) \
12580 static_assert(SideIsVertical(side) == result, "SideIsVertical is wrong")
12581CASE(eSideTop, false);
12582CASE(eSideRight, true);
12583CASE(eSideBottom, false);
12584CASE(eSideLeft, true);
12585# undef CASE
12586
12587// Validation of HalfCornerIsX.
12588# define CASE(corner, result) \
12589 static_assert(HalfCornerIsX(corner) == result, "HalfCornerIsX is wrong")
12590CASE(eCornerTopLeftX, true);
12591CASE(eCornerTopLeftY, false);
12592CASE(eCornerTopRightX, true);
12593CASE(eCornerTopRightY, false);
12594CASE(eCornerBottomRightX, true);
12595CASE(eCornerBottomRightY, false);
12596CASE(eCornerBottomLeftX, true);
12597CASE(eCornerBottomLeftY, false);
12598# undef CASE
12599
12600// Validation of HalfToFullCorner.
12601# define CASE(corner, result) \
12602 static_assert(HalfToFullCorner(corner) == result, \
12603 "HalfToFullCorner is " \
12604 "wrong")
12605CASE(eCornerTopLeftX, eCornerTopLeft);
12606CASE(eCornerTopLeftY, eCornerTopLeft);
12607CASE(eCornerTopRightX, eCornerTopRight);
12608CASE(eCornerTopRightY, eCornerTopRight);
12609CASE(eCornerBottomRightX, eCornerBottomRight);
12610CASE(eCornerBottomRightY, eCornerBottomRight);
12611CASE(eCornerBottomLeftX, eCornerBottomLeft);
12612CASE(eCornerBottomLeftY, eCornerBottomLeft);
12613# undef CASE
12614
12615// Validation of FullToHalfCorner.
12616# define CASE(corner, vert, result) \
12617 static_assert(FullToHalfCorner(corner, vert) == result, \
12618 "FullToHalfCorner is wrong")
12619CASE(eCornerTopLeft, false, eCornerTopLeftX);
12620CASE(eCornerTopLeft, true, eCornerTopLeftY);
12621CASE(eCornerTopRight, false, eCornerTopRightX);
12622CASE(eCornerTopRight, true, eCornerTopRightY);
12623CASE(eCornerBottomRight, false, eCornerBottomRightX);
12624CASE(eCornerBottomRight, true, eCornerBottomRightY);
12625CASE(eCornerBottomLeft, false, eCornerBottomLeftX);
12626CASE(eCornerBottomLeft, true, eCornerBottomLeftY);
12627# undef CASE
12628
12629// Validation of SideToFullCorner.
12630# define CASE(side, second, result) \
12631 static_assert(SideToFullCorner(side, second) == result, \
12632 "SideToFullCorner is wrong")
12633CASE(eSideTop, false, eCornerTopLeft);
12634CASE(eSideTop, true, eCornerTopRight);
12635
12636CASE(eSideRight, false, eCornerTopRight);
12637CASE(eSideRight, true, eCornerBottomRight);
12638
12639CASE(eSideBottom, false, eCornerBottomRight);
12640CASE(eSideBottom, true, eCornerBottomLeft);
12641
12642CASE(eSideLeft, false, eCornerBottomLeft);
12643CASE(eSideLeft, true, eCornerTopLeft);
12644# undef CASE
12645
12646// Validation of SideToHalfCorner.
12647# define CASE(side, second, parallel, result) \
12648 static_assert(SideToHalfCorner(side, second, parallel) == result, \
12649 "SideToHalfCorner is wrong")
12650CASE(eSideTop, false, true, eCornerTopLeftX);
12651CASE(eSideTop, false, false, eCornerTopLeftY);
12652CASE(eSideTop, true, true, eCornerTopRightX);
12653CASE(eSideTop, true, false, eCornerTopRightY);
12654
12655CASE(eSideRight, false, false, eCornerTopRightX);
12656CASE(eSideRight, false, true, eCornerTopRightY);
12657CASE(eSideRight, true, false, eCornerBottomRightX);
12658CASE(eSideRight, true, true, eCornerBottomRightY);
12659
12660CASE(eSideBottom, false, true, eCornerBottomRightX);
12661CASE(eSideBottom, false, false, eCornerBottomRightY);
12662CASE(eSideBottom, true, true, eCornerBottomLeftX);
12663CASE(eSideBottom, true, false, eCornerBottomLeftY);
12664
12665CASE(eSideLeft, false, false, eCornerBottomLeftX);
12666CASE(eSideLeft, false, true, eCornerBottomLeftY);
12667CASE(eSideLeft, true, false, eCornerTopLeftX);
12668CASE(eSideLeft, true, true, eCornerTopLeftY);
12669# undef CASE
12670
12671#endif