Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp
Warning:line 3576, column 7
Value stored to 'createdContainer' 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-19/lib/clang/19 -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 MOZ_SUPPORT_LEAKCHECKING -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/sysprof-6 -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/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../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-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-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 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fno-sized-deallocation -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-2024-09-22-115206-3586786-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/CaretAssociationHint.h"
18#include "mozilla/ComputedStyle.h"
19#include "mozilla/DebugOnly.h"
20#include "mozilla/DisplayPortUtils.h"
21#include "mozilla/EventForwards.h"
22#include "mozilla/FocusModel.h"
23#include "mozilla/dom/CSSAnimation.h"
24#include "mozilla/dom/CSSTransition.h"
25#include "mozilla/dom/ContentVisibilityAutoStateChangeEvent.h"
26#include "mozilla/dom/DocumentInlines.h"
27#include "mozilla/dom/AncestorIterator.h"
28#include "mozilla/dom/ElementInlines.h"
29#include "mozilla/dom/ImageTracker.h"
30#include "mozilla/dom/Selection.h"
31#include "mozilla/gfx/2D.h"
32#include "mozilla/gfx/PathHelpers.h"
33#include "mozilla/IntegerRange.h"
34#include "mozilla/intl/BidiEmbeddingLevel.h"
35#include "mozilla/Maybe.h"
36#include "mozilla/PresShell.h"
37#include "mozilla/PresShellInlines.h"
38#include "mozilla/ResultExtensions.h"
39#include "mozilla/ScrollContainerFrame.h"
40#include "mozilla/SelectionMovementUtils.h"
41#include "mozilla/Sprintf.h"
42#include "mozilla/StaticAnalysisFunctions.h"
43#include "mozilla/StaticPrefs_layout.h"
44#include "mozilla/StaticPrefs_print.h"
45#include "mozilla/StaticPrefs_ui.h"
46#include "mozilla/SVGMaskFrame.h"
47#include "mozilla/SVGObserverUtils.h"
48#include "mozilla/SVGTextFrame.h"
49#include "mozilla/SVGIntegrationUtils.h"
50#include "mozilla/SVGUtils.h"
51#include "mozilla/TextControlElement.h"
52#include "mozilla/ToString.h"
53#include "mozilla/Try.h"
54#include "mozilla/ViewportUtils.h"
55#include "mozilla/WritingModes.h"
56
57#include "nsCOMPtr.h"
58#include "nsFieldSetFrame.h"
59#include "nsFlexContainerFrame.h"
60#include "nsFocusManager.h"
61#include "nsFrameList.h"
62#include "nsTextControlFrame.h"
63#include "nsPlaceholderFrame.h"
64#include "nsIBaseWindow.h"
65#include "nsIContent.h"
66#include "nsIContentInlines.h"
67#include "nsContentUtils.h"
68#include "nsCSSFrameConstructor.h"
69#include "nsCSSProps.h"
70#include "nsCSSPseudoElements.h"
71#include "nsCSSRendering.h"
72#include "nsAtom.h"
73#include "nsString.h"
74#include "nsReadableUtils.h"
75#include "nsTableWrapperFrame.h"
76#include "nsView.h"
77#include "nsViewManager.h"
78#include "nsPresContext.h"
79#include "nsPresContextInlines.h"
80#include "nsStyleConsts.h"
81#include "mozilla/Logging.h"
82#include "nsLayoutUtils.h"
83#include "LayoutLogging.h"
84#include "mozilla/RestyleManager.h"
85#include "nsImageFrame.h"
86#include "nsInlineFrame.h"
87#include "nsFrameSelection.h"
88#include "nsGkAtoms.h"
89#include "nsGridContainerFrame.h"
90#include "nsCSSAnonBoxes.h"
91#include "nsCanvasFrame.h"
92
93#include "nsFieldSetFrame.h"
94#include "nsFrameTraversal.h"
95#include "nsRange.h"
96#include "nsNameSpaceManager.h"
97#include "nsIPercentBSizeObserver.h"
98#include "nsStyleStructInlines.h"
99
100#include "nsBidiPresUtils.h"
101#include "RubyUtils.h"
102#include "TextOverflow.h"
103#include "nsAnimationManager.h"
104
105// For triple-click pref
106#include "imgIRequest.h"
107#include "nsError.h"
108#include "nsContainerFrame.h"
109#include "nsBlockFrame.h"
110#include "nsDisplayList.h"
111#include "nsChangeHint.h"
112#include "nsSubDocumentFrame.h"
113#include "RetainedDisplayListBuilder.h"
114
115#include "gfxContext.h"
116#include "nsAbsoluteContainingBlock.h"
117#include "ScrollSnap.h"
118#include "StickyScrollContainer.h"
119#include "nsFontInflationData.h"
120#include "nsRegion.h"
121#include "nsIFrameInlines.h"
122#include "nsStyleChangeList.h"
123#include "nsWindowSizes.h"
124
125#ifdef ACCESSIBILITY1
126# include "nsAccessibilityService.h"
127#endif
128
129#include "mozilla/AsyncEventDispatcher.h"
130#include "mozilla/CSSClipPathInstance.h"
131#include "mozilla/EffectCompositor.h"
132#include "mozilla/EffectSet.h"
133#include "mozilla/EventListenerManager.h"
134#include "mozilla/EventStateManager.h"
135#include "mozilla/Preferences.h"
136#include "mozilla/LookAndFeel.h"
137#include "mozilla/MouseEvents.h"
138#include "mozilla/ServoStyleSet.h"
139#include "mozilla/ServoStyleSetInlines.h"
140#include "mozilla/css/ImageLoader.h"
141#include "mozilla/dom/HTMLBodyElement.h"
142#include "mozilla/dom/SVGPathData.h"
143#include "mozilla/dom/TouchEvent.h"
144#include "mozilla/gfx/Tools.h"
145#include "mozilla/layers/WebRenderUserData.h"
146#include "mozilla/layout/ScrollAnchorContainer.h"
147#include "nsPrintfCString.h"
148#include "ActiveLayerTracker.h"
149
150#include "nsITheme.h"
151
152using namespace mozilla;
153using namespace mozilla::css;
154using namespace mozilla::dom;
155using namespace mozilla::gfx;
156using namespace mozilla::layers;
157using namespace mozilla::layout;
158typedef nsAbsoluteContainingBlock::AbsPosReflowFlags AbsPosReflowFlags;
159using nsStyleTransformMatrix::TransformReferenceBox;
160
161nsIFrame* nsILineIterator::LineInfo::GetLastFrameOnLine() const {
162 if (!mNumFramesOnLine) {
163 return nullptr; // empty line, not illegal
164 }
165 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"
, 165); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mFirstFrameOnLine"
")"); do { *((volatile int*)__null) = 165; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
166 nsIFrame* maybeLastFrame = mFirstFrameOnLine;
167 for ([[maybe_unused]] int32_t i : IntegerRange(mNumFramesOnLine - 1)) {
168 maybeLastFrame = maybeLastFrame->GetNextSibling();
169 if (NS_WARN_IF(!maybeLastFrame)NS_warn_if_impl(!maybeLastFrame, "!maybeLastFrame", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 169)
) {
170 return nullptr;
171 }
172 }
173 return maybeLastFrame;
174}
175
176#ifdef HAVE_64BIT_BUILD1
177static_assert(sizeof(nsIFrame) == 120, "nsIFrame should remain small");
178#else
179static_assert(sizeof(void*) == 4, "Odd build config?");
180// FIXME(emilio): Investigate why win32 and android-arm32 have bigger sizes (80)
181// than Linux32 (76).
182static_assert(sizeof(nsIFrame) <= 80, "nsIFrame should remain small");
183#endif
184
185const mozilla::LayoutFrameType nsIFrame::sLayoutFrameTypes[kFrameClassCount] = {
186#define FRAME_ID(class_, type_, ...) mozilla::LayoutFrameType::type_,
187#define ABSTRACT_FRAME_ID(...)
188#include "mozilla/FrameIdList.h"
189#undef FRAME_ID
190#undef ABSTRACT_FRAME_ID
191};
192
193const nsIFrame::ClassFlags nsIFrame::sLayoutFrameClassFlags[kFrameClassCount] =
194 {
195#define FRAME_ID(class_, type_, flags_, ...) flags_,
196#define ABSTRACT_FRAME_ID(...)
197#include "mozilla/FrameIdList.h"
198#undef FRAME_ID
199#undef ABSTRACT_FRAME_ID
200};
201
202std::ostream& operator<<(std::ostream& aStream, const nsDirection& aDirection) {
203 return aStream << (aDirection == eDirNext ? "eDirNext" : "eDirPrevious");
204}
205
206struct nsContentAndOffset {
207 nsIContent* mContent = nullptr;
208 int32_t mOffset = 0;
209};
210
211#include "nsILineIterator.h"
212#include "prenv.h"
213
214// Utility function to set a nsRect-valued property table entry on aFrame,
215// reusing the existing storage if the property happens to be already set.
216template <typename T>
217static void SetOrUpdateRectValuedProperty(
218 nsIFrame* aFrame, FrameProperties::Descriptor<T> aProperty,
219 const nsRect& aNewValue) {
220 bool found;
221 nsRect* rectStorage = aFrame->GetProperty(aProperty, &found);
222 if (!found) {
223 rectStorage = new nsRect(aNewValue);
224 aFrame->AddProperty(aProperty, rectStorage);
225 } else {
226 *rectStorage = aNewValue;
227 }
228}
229
230FrameDestroyContext::~FrameDestroyContext() {
231 for (auto& content : mozilla::Reversed(mAnonymousContent)) {
232 mPresShell->NativeAnonymousContentRemoved(content);
233 content->UnbindFromTree();
234 }
235}
236
237// Formerly the nsIFrameDebug interface
238
239std::ostream& operator<<(std::ostream& aStream, const nsReflowStatus& aStatus) {
240 char complete = 'Y';
241 if (aStatus.IsIncomplete()) {
242 complete = 'N';
243 } else if (aStatus.IsOverflowIncomplete()) {
244 complete = 'O';
245 }
246
247 char brk = 'N';
248 if (aStatus.IsInlineBreakBefore()) {
249 brk = 'B';
250 } else if (aStatus.IsInlineBreakAfter()) {
251 brk = 'A';
252 }
253
254 aStream << "["
255 << "Complete=" << complete << ","
256 << "NIF=" << (aStatus.NextInFlowNeedsReflow() ? 'Y' : 'N') << ","
257 << "Break=" << brk << ","
258 << "FirstLetter=" << (aStatus.FirstLetterComplete() ? 'Y' : 'N')
259 << "]";
260 return aStream;
261}
262
263#ifdef DEBUG1
264
265/**
266 * Note: the log module is created during library initialization which
267 * means that you cannot perform logging before then.
268 */
269mozilla::LazyLogModule nsIFrame::sFrameLogModule("frame");
270
271#endif
272
273NS_DECLARE_FRAME_PROPERTY_DELETABLE(AbsoluteContainingBlockProperty,static const mozilla::FramePropertyDescriptor<nsAbsoluteContainingBlock
>* AbsoluteContainingBlockProperty() { static const auto descriptor
= mozilla::FramePropertyDescriptor<nsAbsoluteContainingBlock
>::NewWithDestructor<DeleteValue>(); return &descriptor
; }
274 nsAbsoluteContainingBlock)static const mozilla::FramePropertyDescriptor<nsAbsoluteContainingBlock
>* AbsoluteContainingBlockProperty() { static const auto descriptor
= mozilla::FramePropertyDescriptor<nsAbsoluteContainingBlock
>::NewWithDestructor<DeleteValue>(); return &descriptor
; }
275
276bool nsIFrame::HasAbsolutelyPositionedChildren() const {
277 return IsAbsoluteContainer() &&
278 GetAbsoluteContainingBlock()->HasAbsoluteFrames();
279}
280
281nsAbsoluteContainingBlock* nsIFrame::GetAbsoluteContainingBlock() const {
282 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"
, 283); MOZ_PretendNoReturn(); } } while (0)
283 "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"
, 283); MOZ_PretendNoReturn(); } } while (0)
;
284 nsAbsoluteContainingBlock* absCB =
285 GetProperty(AbsoluteContainingBlockProperty());
286 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"
, 288); MOZ_PretendNoReturn(); } } while (0)
287 "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"
, 288); MOZ_PretendNoReturn(); } } while (0)
288 "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"
, 288); MOZ_PretendNoReturn(); } } while (0)
;
289 return absCB;
290}
291
292void nsIFrame::MarkAsAbsoluteContainingBlock() {
293 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"
, 293); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)"
")"); do { *((volatile int*)__null) = 293; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
294 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"
, 295); MOZ_PretendNoReturn(); } } while (0)
295 "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"
, 295); MOZ_PretendNoReturn(); } } while (0)
;
296 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"
, 297); MOZ_PretendNoReturn(); } } while (0)
297 "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"
, 297); MOZ_PretendNoReturn(); } } while (0)
;
298 AddStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN);
299 SetProperty(AbsoluteContainingBlockProperty(),
300 new nsAbsoluteContainingBlock(GetAbsoluteListID()));
301}
302
303void nsIFrame::MarkAsNotAbsoluteContainingBlock() {
304 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"
, 304); MOZ_PretendNoReturn(); } } while (0)
;
305 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"
, 306); MOZ_PretendNoReturn(); } } while (0)
306 "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"
, 306); MOZ_PretendNoReturn(); } } while (0)
;
307 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"
, 308); MOZ_PretendNoReturn(); } } while (0)
308 "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"
, 308); MOZ_PretendNoReturn(); } } while (0)
;
309 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"
, 309); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)"
")"); do { *((volatile int*)__null) = 309; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
310 RemoveStateBits(NS_FRAME_HAS_ABSPOS_CHILDREN);
311 RemoveProperty(AbsoluteContainingBlockProperty());
312}
313
314bool nsIFrame::CheckAndClearPaintedState() {
315 bool result = HasAnyStateBits(NS_FRAME_PAINTED_THEBES);
316 RemoveStateBits(NS_FRAME_PAINTED_THEBES);
317
318 for (const auto& childList : ChildLists()) {
319 for (nsIFrame* child : childList.mList) {
320 if (child->CheckAndClearPaintedState()) {
321 result = true;
322 }
323 }
324 }
325 return result;
326}
327
328bool nsIFrame::CheckAndClearDisplayListState() {
329 bool result = BuiltDisplayList();
330 SetBuiltDisplayList(false);
331
332 for (const auto& childList : ChildLists()) {
333 for (nsIFrame* child : childList.mList) {
334 if (child->CheckAndClearDisplayListState()) {
335 result = true;
336 }
337 }
338 }
339 return result;
340}
341
342bool nsIFrame::IsVisibleConsideringAncestors(uint32_t aFlags) const {
343 if (!StyleVisibility()->IsVisible()) {
344 return false;
345 }
346
347 if (PresShell()->IsUnderHiddenEmbedderElement()) {
348 return false;
349 }
350
351 const nsIFrame* frame = this;
352 while (frame) {
353 nsView* view = frame->GetView();
354 if (view && view->GetVisibility() == ViewVisibility::Hide) {
355 return false;
356 }
357
358 if (frame->StyleUIReset()->mMozSubtreeHiddenOnlyVisually) {
359 return false;
360 }
361
362 // This method is used to determine if a frame is focusable, because it's
363 // called by nsIFrame::IsFocusable. `content-visibility: auto` should not
364 // force this frame to be unfocusable, so we only take into account
365 // `content-visibility: hidden` here.
366 if (this != frame &&
367 frame->HidesContent(IncludeContentVisibility::Hidden)) {
368 return false;
369 }
370
371 if (nsIFrame* parent = frame->GetParent()) {
372 frame = parent;
373 } else {
374 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(frame);
375 if (!parent) break;
376
377 if ((aFlags & nsIFrame::VISIBILITY_CROSS_CHROME_CONTENT_BOUNDARY) == 0 &&
378 parent->PresContext()->IsChrome() &&
379 !frame->PresContext()->IsChrome()) {
380 break;
381 }
382
383 frame = parent;
384 }
385 }
386
387 return true;
388}
389
390void nsIFrame::FindCloserFrameForSelection(
391 const nsPoint& aPoint, FrameWithDistance* aCurrentBestFrame) {
392 if (nsLayoutUtils::PointIsCloserToRect(aPoint, mRect,
393 aCurrentBestFrame->mXDistance,
394 aCurrentBestFrame->mYDistance)) {
395 aCurrentBestFrame->mFrame = this;
396 }
397}
398
399void nsIFrame::ElementStateChanged(mozilla::dom::ElementState aStates) {}
400
401void WeakFrame::Clear(mozilla::PresShell* aPresShell) {
402 if (aPresShell) {
403 aPresShell->RemoveWeakFrame(this);
404 }
405 mFrame = nullptr;
406}
407
408AutoWeakFrame::AutoWeakFrame(const WeakFrame& aOther)
409 : mPrev(nullptr), mFrame(nullptr) {
410 Init(aOther.GetFrame());
411}
412
413void AutoWeakFrame::Clear(mozilla::PresShell* aPresShell) {
414 if (aPresShell) {
415 aPresShell->RemoveAutoWeakFrame(this);
416 }
417 mFrame = nullptr;
418 mPrev = nullptr;
419}
420
421AutoWeakFrame::~AutoWeakFrame() {
422 Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr);
423}
424
425void AutoWeakFrame::Init(nsIFrame* aFrame) {
426 Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr);
427 mFrame = aFrame;
428 if (mFrame) {
429 mozilla::PresShell* presShell = mFrame->PresContext()->GetPresShell();
430 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"
, 430); } } while (false)
;
431 if (presShell) {
432 presShell->AddAutoWeakFrame(this);
433 } else {
434 mFrame = nullptr;
435 }
436 }
437}
438
439void WeakFrame::Init(nsIFrame* aFrame) {
440 Clear(mFrame ? mFrame->PresContext()->GetPresShell() : nullptr);
441 mFrame = aFrame;
442 if (mFrame) {
443 mozilla::PresShell* presShell = mFrame->PresContext()->GetPresShell();
444 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"
, 444); AnnotateMozCrashReason("MOZ_ASSERT" "(" "presShell" ") ("
"Null PresShell in WeakFrame!" ")"); do { *((volatile int*)__null
) = 444; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
445 if (presShell) {
446 presShell->AddWeakFrame(this);
447 } else {
448 mFrame = nullptr;
449 }
450 }
451}
452
453nsIFrame* NS_NewEmptyFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
454 return new (aPresShell) nsIFrame(aStyle, aPresShell->GetPresContext());
455}
456
457nsIFrame::~nsIFrame() {
458 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)
;
459
460 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"
, 461); AnnotateMozCrashReason("MOZ_ASSERT" "(" "GetVisibility() != Visibility::ApproximatelyVisible"
") (" "Visible nsFrame is being destroyed" ")"); do { *((volatile
int*)__null) = 461; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
461 "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"
, 461); AnnotateMozCrashReason("MOZ_ASSERT" "(" "GetVisibility() != Visibility::ApproximatelyVisible"
") (" "Visible nsFrame is being destroyed" ")"); do { *((volatile
int*)__null) = 461; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
462}
463
464NS_IMPL_FRAMEARENA_HELPERS(nsIFrame)void* nsIFrame ::operator new(size_t sz, mozilla::PresShell *
aShell) { return aShell->AllocateFrame(nsQueryFrame::nsIFrame_id
, sz); }
465
466// Dummy operator delete. Will never be called, but must be defined
467// to satisfy some C++ ABIs.
468void nsIFrame::operator delete(void*, size_t) {
469 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"
, 469); AnnotateMozCrashReason("MOZ_CRASH(" "nsIFrame::operator delete should never be called"
")"); do { *((volatile int*)__null) = 469; __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
470}
471
472NS_QUERYFRAME_HEAD(nsIFrame)void* nsIFrame ::QueryFrame(FrameIID id) const { switch (id) {
473 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)); }
474NS_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"
, 474); 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) = 474; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); return nullptr; }
475
476/////////////////////////////////////////////////////////////////////////////
477// nsIFrame
478
479static bool IsFontSizeInflationContainer(nsIFrame* aFrame,
480 const nsStyleDisplay* aStyleDisplay) {
481 /*
482 * Font size inflation is built around the idea that we're inflating
483 * the fonts for a pan-and-zoom UI so that when the user scales up a
484 * block or other container to fill the width of the device, the fonts
485 * will be readable. To do this, we need to pick what counts as a
486 * container.
487 *
488 * From a code perspective, the only hard requirement is that frames
489 * that are line participants (nsIFrame::IsLineParticipant) are never
490 * containers, since line layout assumes that the inflation is consistent
491 * within a line.
492 *
493 * This is not an imposition, since we obviously want a bunch of text
494 * (possibly with inline elements) flowing within a block to count the
495 * block (or higher) as its container.
496 *
497 * We also want form controls, including the text in the anonymous
498 * content inside of them, to match each other and the text next to
499 * them, so they and their anonymous content should also not be a
500 * container.
501 *
502 * However, because we can't reliably compute sizes across XUL during
503 * reflow, any XUL frame with a XUL parent is always a container.
504 *
505 * There are contexts where it would be nice if some blocks didn't
506 * count as a container, so that, for example, an indented quotation
507 * didn't end up with a smaller font size. However, it's hard to
508 * distinguish these situations where we really do want the indented
509 * thing to count as a container, so we don't try, and blocks are
510 * always containers.
511 */
512
513 // The root frame should always be an inflation container.
514 if (!aFrame->GetParent()) {
515 return true;
516 }
517
518 nsIContent* content = aFrame->GetContent();
519 if (content && content->IsInNativeAnonymousSubtree()) {
520 // Native anonymous content shouldn't be a font inflation root,
521 // except for the canvas custom content container.
522 nsCanvasFrame* canvas = aFrame->PresShell()->GetCanvasFrame();
523 return canvas && canvas->GetCustomContentContainer() == content;
524 }
525
526 LayoutFrameType frameType = aFrame->Type();
527 bool isInline =
528 aFrame->GetDisplay().IsInlineFlow() || RubyUtils::IsRubyBox(frameType) ||
529 (aStyleDisplay->IsFloatingStyle() &&
530 frameType == LayoutFrameType::Letter) ||
531 // Given multiple frames for the same node, only the
532 // outer one should be considered a container.
533 // (Important, e.g., for nsSelectsAreaFrame.)
534 (aFrame->GetParent()->GetContent() == content) ||
535 (content &&
536 // Form controls shouldn't become inflation containers.
537 (content->IsAnyOfHTMLElements(nsGkAtoms::option, nsGkAtoms::optgroup,
538 nsGkAtoms::select, nsGkAtoms::input,
539 nsGkAtoms::button, nsGkAtoms::textarea)));
540 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"
, 545); MOZ_PretendNoReturn(); } } while (0)
541 // 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"
, 545); MOZ_PretendNoReturn(); } } while (0)
542 // 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"
, 545); MOZ_PretendNoReturn(); } } while (0)
543 // 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"
, 545); MOZ_PretendNoReturn(); } } while (0)
544 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"
, 545); MOZ_PretendNoReturn(); } } while (0)
545 "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"
, 545); MOZ_PretendNoReturn(); } } while (0)
;
546 return !isInline;
547}
548
549static void MaybeScheduleReflowSVGNonDisplayText(nsIFrame* aFrame) {
550 if (!aFrame->IsInSVGTextSubtree()) {
551 return;
552 }
553
554 // We need to ensure that any non-display SVGTextFrames get reflowed when a
555 // child text frame gets new style. Thus we need to schedule a reflow in
556 // |DidSetComputedStyle|. We also need to call it from |DestroyFrom|,
557 // because otherwise we won't get notified when style changes to
558 // "display:none".
559 SVGTextFrame* svgTextFrame = static_cast<SVGTextFrame*>(
560 nsLayoutUtils::GetClosestFrameOfType(aFrame, LayoutFrameType::SVGText));
561 nsIFrame* anonBlock = svgTextFrame->PrincipalChildList().FirstChild();
562
563 // Note that we must check NS_FRAME_FIRST_REFLOW on our SVGTextFrame's
564 // anonymous block frame rather than our aFrame, since NS_FRAME_FIRST_REFLOW
565 // may be set on us if we're a new frame that has been inserted after the
566 // document's first reflow. (In which case this DidSetComputedStyle call may
567 // be happening under frame construction under a Reflow() call.)
568 if (!anonBlock || anonBlock->HasAnyStateBits(NS_FRAME_FIRST_REFLOW)) {
569 return;
570 }
571
572 if (!svgTextFrame->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY) ||
573 svgTextFrame->HasAnyStateBits(NS_STATE_SVG_TEXT_IN_REFLOW)) {
574 return;
575 }
576
577 svgTextFrame->ScheduleReflowSVGNonDisplayText(
578 IntrinsicDirty::FrameAncestorsAndDescendants);
579}
580
581bool nsIFrame::ShouldPropagateRepaintsToRoot() const {
582 if (!IsPrimaryFrame()) {
583 // special case for table frames because style images are associated to the
584 // table frame, but the table wrapper frame is the primary frame
585 if (IsTableFrame()) {
586 MOZ_ASSERT(GetParent() && GetParent()->IsTableWrapperFrame())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(GetParent() && GetParent()->IsTableWrapperFrame
())>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(GetParent() && GetParent()->IsTableWrapperFrame
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("GetParent() && GetParent()->IsTableWrapperFrame()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 586); AnnotateMozCrashReason("MOZ_ASSERT" "(" "GetParent() && GetParent()->IsTableWrapperFrame()"
")"); do { *((volatile int*)__null) = 586; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
587 return GetParent()->ShouldPropagateRepaintsToRoot();
588 }
589
590 return false;
591 }
592 nsIContent* content = GetContent();
593 Document* document = content->OwnerDoc();
594 return content == document->GetRootElement() ||
595 content == document->GetBodyElement();
596}
597
598bool nsIFrame::IsRenderedLegend() const {
599 if (auto* parent = GetParent(); parent && parent->IsFieldSetFrame()) {
600 return static_cast<nsFieldSetFrame*>(parent)->GetLegend() == this;
601 }
602 return false;
603}
604
605void nsIFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
606 nsIFrame* aPrevInFlow) {
607 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"
, 607); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsQueryFrame::FrameIID(mClass) == GetFrameId()"
")"); do { *((volatile int*)__null) = 607; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
608 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"
, 608); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mContent" ") ("
"Double-initing a frame?" ")"); do { *((volatile int*)__null
) = 608; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
609
610 mContent = aContent;
611 mParent = aParent;
612 MOZ_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"
, 612); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mParent || PresShell() == mParent->PresShell()"
")"); do { *((volatile int*)__null) = 612; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
613
614 if (aPrevInFlow) {
615 mWritingMode = aPrevInFlow->GetWritingMode();
616
617 // Copy some state bits from prev-in-flow (the bits that should apply
618 // throughout a continuation chain). The bits are sorted according to their
619 // order in nsFrameStateBits.h.
620
621 // clang-format off
622 AddStateBits(aPrevInFlow->GetStateBits() &
623 (NS_FRAME_GENERATED_CONTENT |
624 NS_FRAME_OUT_OF_FLOW |
625 NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN |
626 NS_FRAME_INDEPENDENT_SELECTION |
627 NS_FRAME_PART_OF_IBSPLIT |
628 NS_FRAME_MAY_BE_TRANSFORMED |
629 NS_FRAME_HAS_MULTI_COLUMN_ANCESTOR));
630 // clang-format on
631
632 // Copy other bits in nsIFrame from prev-in-flow.
633 mHasColumnSpanSiblings = aPrevInFlow->HasColumnSpanSiblings();
634 } else {
635 PresContext()->ConstructedFrame();
636 }
637
638 if (GetParent()) {
639 if (MOZ_UNLIKELY(mContent == PresContext()->Document()->GetRootElement() &&(__builtin_expect(!!(mContent == PresContext()->Document()
->GetRootElement() && mContent == GetParent()->
GetContent()), 0))
640 mContent == GetParent()->GetContent())(__builtin_expect(!!(mContent == PresContext()->Document()
->GetRootElement() && mContent == GetParent()->
GetContent()), 0))
) {
641 // Our content is the root element and we have the same content as our
642 // parent. That is, we are the internal anonymous frame of the root
643 // element. Copy the used mWritingMode from our parent because
644 // mDocElementContainingBlock gets its mWritingMode from <body>.
645 mWritingMode = GetParent()->GetWritingMode();
646 }
647
648 // Copy some state bits from our parent (the bits that should apply
649 // recursively throughout a subtree). The bits are sorted according to their
650 // order in nsFrameStateBits.h.
651
652 // clang-format off
653 AddStateBits(GetParent()->GetStateBits() &
654 (NS_FRAME_GENERATED_CONTENT |
655 NS_FRAME_INDEPENDENT_SELECTION |
656 NS_FRAME_IS_SVG_TEXT |
657 NS_FRAME_IN_POPUP |
658 NS_FRAME_IS_NONDISPLAY));
659 // clang-format on
660
661 if (HasAnyStateBits(NS_FRAME_IN_POPUP) && TrackingVisibility()) {
662 // Assume all frames in popups are visible.
663 IncApproximateVisibleCount();
664 }
665 }
666 if (aPrevInFlow) {
667 mMayHaveOpacityAnimation = aPrevInFlow->MayHaveOpacityAnimation();
668 mMayHaveTransformAnimation = aPrevInFlow->MayHaveTransformAnimation();
669 } else if (mContent) {
670 // It's fine to fetch the EffectSet for the style frame here because in the
671 // following code we take care of the case where animations may target
672 // a different frame.
673 EffectSet* effectSet = EffectSet::GetForStyleFrame(this);
674 if (effectSet) {
675 mMayHaveOpacityAnimation = effectSet->MayHaveOpacityAnimation();
676
677 if (effectSet->MayHaveTransformAnimation()) {
678 // If we are the inner table frame for display:table content, then
679 // transform animations should go on our parent frame (the table wrapper
680 // frame).
681 //
682 // We do this when initializing the child frame (table inner frame),
683 // because when initializng the table wrapper frame, we don't yet have
684 // access to its children so we can't tell if we have transform
685 // animations or not.
686 if (SupportsCSSTransforms()) {
687 mMayHaveTransformAnimation = true;
688 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
689 } else if (aParent && nsLayoutUtils::GetStyleFrame(aParent) == this) {
690 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"
, 693); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 693; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
691 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"
, 693); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 693; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
692 "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"
, 693); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 693; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
693 " 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"
, 693); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 693; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
694 aParent->mMayHaveTransformAnimation = true;
695 aParent->AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
696 }
697 }
698 }
699 }
700
701 const nsStyleDisplay* disp = StyleDisplay();
702 if (disp->HasTransform(this)) {
703 // If 'transform' dynamically changes, RestyleManager takes care of
704 // updating this bit.
705 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
706 }
707
708 if (nsLayoutUtils::FontSizeInflationEnabled(PresContext()) ||
709 !GetParent()
710#ifdef DEBUG1
711 // We have assertions that check inflation invariants even when
712 // font size inflation is not enabled.
713 || true
714#endif
715 ) {
716 if (IsFontSizeInflationContainer(this, disp)) {
717 AddStateBits(NS_FRAME_FONT_INFLATION_CONTAINER);
718 if (!GetParent() ||
719 // I'd use NS_FRAME_OUT_OF_FLOW, but it's not set yet.
720 disp->IsFloating(this) || disp->IsAbsolutelyPositioned(this) ||
721 GetParent()->IsFlexContainerFrame() ||
722 GetParent()->IsGridContainerFrame()) {
723 AddStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT);
724 }
725 }
726 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"
, 728); MOZ_PretendNoReturn(); } } while (0)
727 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"
, 728); MOZ_PretendNoReturn(); } } while (0)
728 "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"
, 728); MOZ_PretendNoReturn(); } } while (0)
;
729 }
730
731 if (TrackingVisibility() && PresShell()->AssumeAllFramesVisible()) {
732 IncApproximateVisibleCount();
733 }
734
735 DidSetComputedStyle(nullptr);
736
737 // For a newly created frame, we need to update this frame's visibility state.
738 // Usually we update the state when the frame is restyled and has a
739 // VisibilityChange change hint but we don't generate any change hints for
740 // newly created frames.
741 // Note: We don't need to do this for placeholders since placeholders have
742 // different styles so that the styles don't have visibility:hidden even if
743 // the parent has visibility:hidden style. We also don't need to update the
744 // state when creating continuations because its visibility is the same as its
745 // prev-in-flow, and the animation code cares only primary frames.
746 if (!IsPlaceholderFrame() && !aPrevInFlow) {
747 UpdateVisibleDescendantsState();
748 }
749
750 if (!aPrevInFlow && HasAnyStateBits(NS_FRAME_IS_NONDISPLAY)) {
751 // We aren't going to get a reflow, so nothing else will call
752 // InvalidateRenderingObservers, we have to do it here.
753 SVGObserverUtils::InvalidateRenderingObservers(this);
754 }
755}
756
757void nsIFrame::InitPrimaryFrame() {
758 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"
, 758); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsPrimaryFrame()"
")"); do { *((volatile int*)__null) = 758; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
759 HandlePrimaryFrameStyleChange(nullptr);
760}
761
762void nsIFrame::HandlePrimaryFrameStyleChange(ComputedStyle* aOldStyle) {
763 const nsStyleDisplay* disp = StyleDisplay();
764 const nsStyleDisplay* oldDisp =
765 aOldStyle ? aOldStyle->StyleDisplay() : nullptr;
766
767 const bool wasQueryContainer = oldDisp && oldDisp->IsQueryContainer();
768 const bool isQueryContainer = disp->IsQueryContainer();
769 if (wasQueryContainer != isQueryContainer) {
770 auto* pc = PresContext();
771 if (isQueryContainer) {
772 pc->RegisterContainerQueryFrame(this);
773 } else {
774 pc->UnregisterContainerQueryFrame(this);
775 }
776 }
777
778 const auto cv = disp->ContentVisibility(*this);
779 if (!oldDisp || oldDisp->ContentVisibility(*this) != cv) {
780 if (cv == StyleContentVisibility::Auto) {
781 PresShell()->RegisterContentVisibilityAutoFrame(this);
782 } else {
783 if (auto* element = Element::FromNodeOrNull(GetContent())) {
784 element->ClearContentRelevancy();
785 }
786 PresShell()->UnregisterContentVisibilityAutoFrame(this);
787 }
788 PresContext()->SetNeedsToUpdateHiddenByContentVisibilityForAnimations();
789 }
790
791 HandleLastRememberedSize();
792}
793
794void nsIFrame::Destroy(DestroyContext& aContext) {
795 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"
, 796); MOZ_PretendNoReturn(); } } while (0)
796 "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"
, 796); MOZ_PretendNoReturn(); } } while (0)
;
797 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"
, 798); MOZ_PretendNoReturn(); } } while (0)
798 "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"
, 798); MOZ_PretendNoReturn(); } } while (0)
;
799 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"
, 799); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAbsolutelyPositionedChildren()"
")"); do { *((volatile int*)__null) = 799; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
800 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"
, 801); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)"
") (" "NS_FRAME_PART_OF_IBSPLIT set on non-nsContainerFrame?"
")"); do { *((volatile int*)__null) = 801; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
801 "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"
, 801); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)"
") (" "NS_FRAME_PART_OF_IBSPLIT set on non-nsContainerFrame?"
")"); do { *((volatile int*)__null) = 801; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
802
803 MaybeScheduleReflowSVGNonDisplayText(this);
804
805 SVGObserverUtils::InvalidateDirectRenderingObservers(this);
806
807 const auto* disp = StyleDisplay();
808 if (disp->mPosition == StylePositionProperty::Sticky) {
809 if (auto* ssc =
810 StickyScrollContainer::GetStickyScrollContainerForFrame(this)) {
811 ssc->RemoveFrame(this);
812 }
813 }
814
815 if (HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
816 if (nsPlaceholderFrame* placeholder = GetPlaceholderFrame()) {
817 placeholder->SetOutOfFlowFrame(nullptr);
818 }
819 }
820
821 nsPresContext* pc = PresContext();
822 mozilla::PresShell* ps = pc->GetPresShell();
823 if (IsPrimaryFrame()) {
824 if (disp->IsQueryContainer()) {
825 pc->UnregisterContainerQueryFrame(this);
826 }
827 if (disp->ContentVisibility(*this) == StyleContentVisibility::Auto) {
828 ps->UnregisterContentVisibilityAutoFrame(this);
829 }
830 // This needs to happen before we clear our Properties() table.
831 ActiveLayerTracker::TransferActivityToContent(this, mContent);
832 }
833
834 ScrollAnchorContainer* anchor = nullptr;
835 if (IsScrollAnchor(&anchor)) {
836 anchor->InvalidateAnchor();
837 }
838
839 if (HasCSSAnimations() || HasCSSTransitions() ||
840 // It's fine to look up the style frame here since if we're destroying the
841 // frames for display:table content we should be destroying both wrapper
842 // and inner frame.
843 EffectSet::GetForStyleFrame(this)) {
844 // If no new frame for this element is created by the end of the
845 // restyling process, stop animations and transitions for this frame
846 RestyleManager::AnimationsWithDestroyedFrame* adf =
847 pc->RestyleManager()->GetAnimationsWithDestroyedFrame();
848 // AnimationsWithDestroyedFrame only lives during the restyling process.
849 if (adf) {
850 adf->Put(mContent, mComputedStyle);
851 }
852 }
853
854 // Disable visibility tracking. Note that we have to do this before we clear
855 // frame properties and lose track of whether we were previously visible.
856 // XXX(seth): It'd be ideal to assert that we're already marked nonvisible
857 // here, but it's unfortunately tricky to guarantee in the face of things like
858 // frame reconstruction induced by style changes.
859 DisableVisibilityTracking();
860
861 // Ensure that we're not in the approximately visible list anymore.
862 ps->RemoveFrameFromApproximatelyVisibleList(this);
863
864 ps->NotifyDestroyingFrame(this);
865
866 if (HasAnyStateBits(NS_FRAME_EXTERNAL_REFERENCE)) {
867 ps->ClearFrameRefs(this);
868 }
869
870 nsView* view = GetView();
871 if (view) {
872 view->SetFrame(nullptr);
873 view->Destroy();
874 }
875
876 // Make sure that our deleted frame can't be returned from GetPrimaryFrame()
877 if (IsPrimaryFrame()) {
878 mContent->SetPrimaryFrame(nullptr);
879
880 // Pass the root of a generated content subtree (e.g. ::after/::before) to
881 // aPostDestroyData to unbind it after frame destruction is done.
882 if (HasAnyStateBits(NS_FRAME_GENERATED_CONTENT) &&
883 mContent->IsRootOfNativeAnonymousSubtree()) {
884 aContext.AddAnonymousContent(mContent.forget());
885 }
886 }
887
888 // Remove all properties attached to the frame, to ensure any property
889 // destructors that need the frame pointer are handled properly.
890 RemoveAllProperties();
891
892 // Must retrieve the object ID before calling destructors, so the
893 // vtable is still valid.
894 //
895 // Note to future tweakers: having the method that returns the
896 // object size call the destructor will not avoid an indirect call;
897 // the compiler cannot devirtualize the call to the destructor even
898 // if it's from a method defined in the same class.
899
900 nsQueryFrame::FrameIID id = GetFrameId();
901 this->~nsIFrame();
902
903#ifdef DEBUG1
904 {
905 nsIFrame* rootFrame = ps->GetRootFrame();
906 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"
, 906); AnnotateMozCrashReason("MOZ_ASSERT" "(" "rootFrame" ")"
); do { *((volatile int*)__null) = 906; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
907 if (this != rootFrame) {
908 auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(rootFrame);
909 auto* data = builder ? builder->Data() : nullptr;
910
911 const bool inData =
912 data && (data->IsModified(this) || data->HasProps(this));
913
914 if (inData) {
915 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)
;
916 }
917
918 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"
, 918); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!inData" ") ("
"Deleted frame in retained data!" ")"); do { *((volatile int
*)__null) = 918; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
919 }
920 }
921#endif
922
923 // Now that we're totally cleaned out, we need to add ourselves to
924 // the presshell's recycler.
925 ps->FreeFrame(id, this);
926}
927
928std::pair<int32_t, int32_t> nsIFrame::GetOffsets() const {
929 return std::make_pair(0, 0);
930}
931
932static void CompareLayers(
933 const nsStyleImageLayers* aFirstLayers,
934 const nsStyleImageLayers* aSecondLayers,
935 const std::function<void(imgRequestProxy* aReq)>& aCallback) {
936 NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, (*aFirstLayers))for (uint32_t i = ((*aFirstLayers)).mImageCount; (i)-- != 0;) {
937 const auto& image = aFirstLayers->mLayers[i].mImage;
938 if (!image.IsImageRequestType() || !image.IsResolved()) {
939 continue;
940 }
941
942 // aCallback is called when the style image in aFirstLayers is thought to
943 // be different with the corresponded one in aSecondLayers
944 if (!aSecondLayers || i >= aSecondLayers->mImageCount ||
945 (!aSecondLayers->mLayers[i].mImage.IsResolved() ||
946 image.GetImageRequest() !=
947 aSecondLayers->mLayers[i].mImage.GetImageRequest())) {
948 if (imgRequestProxy* req = image.GetImageRequest()) {
949 aCallback(req);
950 }
951 }
952 }
953}
954
955static void AddAndRemoveImageAssociations(
956 ImageLoader& aImageLoader, nsIFrame* aFrame,
957 const nsStyleImageLayers* aOldLayers,
958 const nsStyleImageLayers* aNewLayers) {
959 // If the old context had a background-image image, or mask-image image,
960 // and new context does not have the same image, clear the image load
961 // notifier (which keeps the image loading, if it still is) for the frame.
962 // We want to do this conservatively because some frames paint their
963 // backgrounds from some other frame's style data, and we don't want
964 // to clear those notifiers unless we have to. (They'll be reset
965 // when we paint, although we could miss a notification in that
966 // interval.)
967 if (aOldLayers && aFrame->HasImageRequest()) {
968 CompareLayers(aOldLayers, aNewLayers, [&](imgRequestProxy* aReq) {
969 aImageLoader.DisassociateRequestFromFrame(aReq, aFrame);
970 });
971 }
972
973 CompareLayers(aNewLayers, aOldLayers, [&](imgRequestProxy* aReq) {
974 aImageLoader.AssociateRequestToFrame(aReq, aFrame);
975 });
976}
977
978void nsIFrame::AddDisplayItem(nsDisplayItem* aItem) {
979 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"
, 979); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mDisplayItems.Contains(aItem)"
")"); do { *((volatile int*)__null) = 979; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
980 mDisplayItems.AppendElement(aItem);
981#ifdef ACCESSIBILITY1
982 if (nsAccessibilityService* accService = GetAccService()) {
983 accService->NotifyOfPossibleBoundsChange(PresShell(), mContent);
984 }
985#endif
986}
987
988bool nsIFrame::RemoveDisplayItem(nsDisplayItem* aItem) {
989 return mDisplayItems.RemoveElement(aItem);
990}
991
992bool nsIFrame::HasDisplayItems() { return !mDisplayItems.IsEmpty(); }
993
994bool nsIFrame::HasDisplayItem(nsDisplayItem* aItem) {
995 return mDisplayItems.Contains(aItem);
996}
997
998bool nsIFrame::HasDisplayItem(uint32_t aKey) {
999 for (nsDisplayItem* i : mDisplayItems) {
1000 if (i->GetPerFrameKey() == aKey) {
1001 return true;
1002 }
1003 }
1004 return false;
1005}
1006
1007template <typename Condition>
1008static void DiscardDisplayItems(nsIFrame* aFrame, Condition aCondition) {
1009 for (nsDisplayItem* i : aFrame->DisplayItems()) {
1010 // Only discard items that are invalidated by this frame, as we're only
1011 // guaranteed to rebuild those items. Table background items are created by
1012 // the relevant table part, but have the cell frame as the primary frame,
1013 // and we don't want to remove them if this is the cell.
1014 if (aCondition(i) && i->FrameForInvalidation() == aFrame) {
1015 i->SetCantBeReused();
1016 }
1017 }
1018}
1019
1020static void DiscardOldItems(nsIFrame* aFrame) {
1021 DiscardDisplayItems(aFrame,
1022 [](nsDisplayItem* aItem) { return aItem->IsOldItem(); });
1023}
1024
1025void nsIFrame::RemoveDisplayItemDataForDeletion() {
1026 // Destroying a WebRenderUserDataTable can cause destruction of other objects
1027 // which can remove frame properties in their destructor. If we delete a frame
1028 // property it runs the destructor of the stored object in the middle of
1029 // updating the frame property table, so if the destruction of that object
1030 // causes another update to the frame property table it would leave the frame
1031 // property table in an inconsistent state. So we remove it from the table and
1032 // then destroy it. (bug 1530657)
1033 WebRenderUserDataTable* userDataTable =
1034 TakeProperty(WebRenderUserDataProperty::Key());
1035 if (userDataTable) {
1036 for (const auto& data : userDataTable->Values()) {
1037 data->RemoveFromTable();
1038 }
1039 delete userDataTable;
1040 }
1041
1042 if (!nsLayoutUtils::AreRetainedDisplayListsEnabled()) {
1043 // Retained display lists are disabled, no need to update
1044 // RetainedDisplayListData.
1045 return;
1046 }
1047
1048 auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(this);
1049 if (!builder) {
1050 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"
, 1050); AnnotateMozCrashReason("MOZ_ASSERT" "(" "DisplayItems().IsEmpty()"
")"); do { *((volatile int*)__null) = 1050; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1051 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"
, 1051); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsFrameModified()"
")"); do { *((volatile int*)__null) = 1051; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1052 return;
1053 }
1054
1055 for (nsDisplayItem* i : DisplayItems()) {
1056 if (i->GetDependentFrame() == this && !i->HasDeletedFrame()) {
1057 i->Frame()->MarkNeedsDisplayItemRebuild();
1058 }
1059 i->RemoveFrame(this);
1060 }
1061
1062 DisplayItems().Clear();
1063
1064 nsAutoString name;
1065#ifdef DEBUG_FRAME_DUMP1
1066 if (DL_LOG_TEST(LogLevel::Debug)(__builtin_expect(!!(mozilla::detail::log_test(GetLoggerByProcess
(), LogLevel::Debug)), 0))
) {
1067 GetFrameName(name);
1068 }
1069#endif
1070 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)
1071 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)
;
1072
1073 auto* data = builder->Data();
1074 if (MayHaveWillChangeBudget()) {
1075 // Keep the frame in list, so it can be removed from the will-change budget.
1076 data->Flags(this) = RetainedDisplayListData::FrameFlag::HadWillChange;
1077 } else {
1078 data->Remove(this);
1079 }
1080}
1081
1082void nsIFrame::MarkNeedsDisplayItemRebuild() {
1083 if (!nsLayoutUtils::AreRetainedDisplayListsEnabled() || IsFrameModified() ||
1084 HasAnyStateBits(NS_FRAME_IN_POPUP)) {
1085 // Skip frames that are already marked modified.
1086 return;
1087 }
1088
1089 if (Type() == LayoutFrameType::Placeholder) {
1090 nsIFrame* oof = static_cast<nsPlaceholderFrame*>(this)->GetOutOfFlowFrame();
1091 if (oof) {
1092 oof->MarkNeedsDisplayItemRebuild();
1093 }
1094 // Do not mark placeholder frames modified.
1095 return;
1096 }
1097
1098#ifdef ACCESSIBILITY1
1099 if (nsAccessibilityService* accService = GetAccService()) {
1100 accService->NotifyOfPossibleBoundsChange(PresShell(), mContent);
1101 }
1102#endif
1103
1104 nsIFrame* rootFrame = PresShell()->GetRootFrame();
1105
1106 if (rootFrame->IsFrameModified()) {
1107 // The whole frame tree is modified.
1108 return;
1109 }
1110
1111 auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(this);
1112 if (!builder) {
1113 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"
, 1113); AnnotateMozCrashReason("MOZ_ASSERT" "(" "DisplayItems().IsEmpty()"
")"); do { *((volatile int*)__null) = 1113; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1114 return;
1115 }
1116
1117 RetainedDisplayListData* data = builder->Data();
1118 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"
, 1118); AnnotateMozCrashReason("MOZ_ASSERT" "(" "data" ")");
do { *((volatile int*)__null) = 1118; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1119
1120 if (data->AtModifiedFrameLimit()) {
1121 // This marks the whole frame tree modified.
1122 // See |RetainedDisplayListBuilder::ShouldBuildPartial()|.
1123 data->AddModifiedFrame(rootFrame);
1124 return;
1125 }
1126
1127 nsAutoString name;
1128#ifdef DEBUG_FRAME_DUMP1
1129 if (DL_LOG_TEST(LogLevel::Debug)(__builtin_expect(!!(mozilla::detail::log_test(GetLoggerByProcess
(), LogLevel::Debug)), 0))
) {
1130 GetFrameName(name);
1131 }
1132#endif
1133
1134 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)
1135 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)
;
1136
1137 data->AddModifiedFrame(this);
1138
1139 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"
, 1140); AnnotateMozCrashReason("MOZ_ASSERT" "(" "PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding) == 0"
")"); do { *((volatile int*)__null) = 1140; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1140 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"
, 1140); AnnotateMozCrashReason("MOZ_ASSERT" "(" "PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding) == 0"
")"); do { *((volatile int*)__null) = 1140; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1141
1142 // Hopefully this is cheap, but we could use a frame state bit to note
1143 // the presence of dependencies to speed it up.
1144 for (nsDisplayItem* i : DisplayItems()) {
1145 if (i->HasDeletedFrame() || i->Frame() == this) {
1146 // Ignore the items with deleted frames, and the items with |this| as
1147 // the primary frame.
1148 continue;
1149 }
1150
1151 if (i->GetDependentFrame() == this) {
1152 // For items with |this| as a dependent frame, mark the primary frame
1153 // for rebuild.
1154 i->Frame()->MarkNeedsDisplayItemRebuild();
1155 }
1156 }
1157}
1158
1159// Subclass hook for style post processing
1160/* virtual */
1161void nsIFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) {
1162#ifdef ACCESSIBILITY1
1163 // Don't notify for reconstructed frames here, since the frame is still being
1164 // constructed at this point and so LocalAccessible::GetFrame() will return
1165 // null. Style changes for reconstructed frames are handled in
1166 // DocAccessible::PruneOrInsertSubtree.
1167 if (aOldComputedStyle) {
1168 if (nsAccessibilityService* accService = GetAccService()) {
1169 accService->NotifyOfComputedStyleChange(PresShell(), mContent);
1170 }
1171 }
1172#endif
1173
1174 MaybeScheduleReflowSVGNonDisplayText(this);
1175
1176 Document* doc = PresContext()->Document();
1177 ImageLoader* loader = doc->StyleImageLoader();
1178 // Continuing text frame doesn't initialize its continuation pointer before
1179 // reaching here for the first time, so we have to exclude text frames. This
1180 // doesn't affect correctness because text can't match selectors.
1181 //
1182 // FIXME(emilio): We should consider fixing that.
1183 //
1184 // TODO(emilio): Can we avoid doing some / all of the image stuff when
1185 // isNonTextFirstContinuation is false? We should consider doing this just for
1186 // primary frames and pseudos, but the first-line reparenting code makes it
1187 // all bad, should get around to bug 1465474 eventually :(
1188 const bool isNonText = !IsTextFrame();
1189 if (isNonText) {
1190 mComputedStyle->StartImageLoads(*doc, aOldComputedStyle);
1191 }
1192
1193 const nsStyleImageLayers* oldLayers =
1194 aOldComputedStyle ? &aOldComputedStyle->StyleBackground()->mImage
1195 : nullptr;
1196 const nsStyleImageLayers* newLayers = &StyleBackground()->mImage;
1197 AddAndRemoveImageAssociations(*loader, this, oldLayers, newLayers);
1198
1199 oldLayers =
1200 aOldComputedStyle ? &aOldComputedStyle->StyleSVGReset()->mMask : nullptr;
1201 newLayers = &StyleSVGReset()->mMask;
1202 AddAndRemoveImageAssociations(*loader, this, oldLayers, newLayers);
1203
1204 const nsStyleDisplay* disp = StyleDisplay();
1205 bool handleStickyChange = false;
1206 if (aOldComputedStyle) {
1207 // Detect style changes that should trigger a scroll anchor adjustment
1208 // suppression.
1209 // https://drafts.csswg.org/css-scroll-anchoring/#suppression-triggers
1210 bool needAnchorSuppression = false;
1211
1212 const nsStyleMargin* oldMargin = aOldComputedStyle->StyleMargin();
1213 if (oldMargin->mMargin != StyleMargin()->mMargin) {
1214 needAnchorSuppression = true;
1215 }
1216
1217 const nsStylePadding* oldPadding = aOldComputedStyle->StylePadding();
1218 if (oldPadding->mPadding != StylePadding()->mPadding) {
1219 SetHasPaddingChange(true);
1220 needAnchorSuppression = true;
1221 }
1222
1223 const nsStyleDisplay* oldDisp = aOldComputedStyle->StyleDisplay();
1224 if (oldDisp->mOverflowAnchor != disp->mOverflowAnchor) {
1225 if (auto* container = ScrollAnchorContainer::FindFor(this)) {
1226 container->InvalidateAnchor();
1227 }
1228 if (ScrollContainerFrame* scrollContainerFrame = do_QueryFrame(this)) {
1229 scrollContainerFrame->Anchor()->InvalidateAnchor();
1230 }
1231 }
1232
1233 if (mInScrollAnchorChain) {
1234 const nsStylePosition* pos = StylePosition();
1235 const nsStylePosition* oldPos = aOldComputedStyle->StylePosition();
1236 if (!needAnchorSuppression &&
1237 (oldPos->mOffset != pos->mOffset || oldPos->mWidth != pos->mWidth ||
1238 oldPos->mMinWidth != pos->mMinWidth ||
1239 oldPos->mMaxWidth != pos->mMaxWidth ||
1240 oldPos->mHeight != pos->mHeight ||
1241 oldPos->mMinHeight != pos->mMinHeight ||
1242 oldPos->mMaxHeight != pos->mMaxHeight ||
1243 oldDisp->mPosition != disp->mPosition ||
1244 oldDisp->mTransform != disp->mTransform)) {
1245 needAnchorSuppression = true;
1246 }
1247
1248 if (needAnchorSuppression &&
1249 StaticPrefs::layout_css_scroll_anchoring_suppressions_enabled()) {
1250 ScrollAnchorContainer::FindFor(this)->SuppressAdjustments();
1251 }
1252 }
1253
1254 if (disp->mPosition != oldDisp->mPosition) {
1255 if (!disp->IsRelativelyOrStickyPositionedStyle() &&
1256 oldDisp->IsRelativelyOrStickyPositionedStyle()) {
1257 RemoveProperty(NormalPositionProperty());
1258 }
1259
1260 handleStickyChange = disp->mPosition == StylePositionProperty::Sticky ||
1261 oldDisp->mPosition == StylePositionProperty::Sticky;
1262 }
1263 if (disp->mScrollSnapAlign != oldDisp->mScrollSnapAlign) {
1264 ScrollSnapUtils::PostPendingResnapFor(this);
1265 }
1266 if (aOldComputedStyle->IsRootElementStyle() &&
1267 disp->mScrollSnapType != oldDisp->mScrollSnapType) {
1268 if (ScrollContainerFrame* sf =
1269 PresShell()->GetRootScrollContainerFrame()) {
1270 sf->PostPendingResnap();
1271 }
1272 }
1273 if (StyleUIReset()->mMozSubtreeHiddenOnlyVisually &&
1274 !aOldComputedStyle->StyleUIReset()->mMozSubtreeHiddenOnlyVisually) {
1275 PresShell::ClearMouseCapture(this);
1276 }
1277 } else { // !aOldComputedStyle
1278 handleStickyChange = disp->mPosition == StylePositionProperty::Sticky;
1279 }
1280
1281 if (handleStickyChange && !HasAnyStateBits(NS_FRAME_IS_NONDISPLAY) &&
1282 !GetPrevInFlow()) {
1283 // Note that we only add first continuations, but we really only
1284 // want to add first continuation-or-ib-split-siblings. But since we don't
1285 // yet know if we're a later part of a block-in-inline split, we'll just
1286 // add later members of a block-in-inline split here, and then
1287 // StickyScrollContainer will remove them later.
1288 if (auto* ssc =
1289 StickyScrollContainer::GetStickyScrollContainerForFrame(this)) {
1290 if (disp->mPosition == StylePositionProperty::Sticky) {
1291 ssc->AddFrame(this);
1292 } else {
1293 ssc->RemoveFrame(this);
1294 }
1295 }
1296 }
1297
1298 imgIRequest* oldBorderImage =
1299 aOldComputedStyle
1300 ? aOldComputedStyle->StyleBorder()->GetBorderImageRequest()
1301 : nullptr;
1302 imgIRequest* newBorderImage = StyleBorder()->GetBorderImageRequest();
1303 // FIXME (Bug 759996): The following is no longer true.
1304 // For border-images, we can't be as conservative (we need to set the
1305 // new loaders if there has been any change) since the CalcDifference
1306 // call depended on the result of GetComputedBorder() and that result
1307 // depends on whether the image has loaded, start the image load now
1308 // so that we'll get notified when it completes loading and can do a
1309 // restyle. Otherwise, the image might finish loading from the
1310 // network before we start listening to its notifications, and then
1311 // we'll never know that it's finished loading. Likewise, we want to
1312 // do this for freshly-created frames to prevent a similar race if the
1313 // image loads between reflow (which can depend on whether the image
1314 // is loaded) and paint. We also don't really care about any callers who try
1315 // to paint borders with a different style, because they won't have the
1316 // correct size for the border either.
1317 if (oldBorderImage != newBorderImage) {
1318 // stop and restart the image loading/notification
1319 if (oldBorderImage && HasImageRequest()) {
1320 loader->DisassociateRequestFromFrame(oldBorderImage, this);
1321 }
1322 if (newBorderImage) {
1323 loader->AssociateRequestToFrame(newBorderImage, this);
1324 }
1325 }
1326
1327 auto GetShapeImageRequest = [](const ComputedStyle* aStyle) -> imgIRequest* {
1328 if (!aStyle) {
1329 return nullptr;
1330 }
1331 auto& shape = aStyle->StyleDisplay()->mShapeOutside;
1332 if (!shape.IsImage()) {
1333 return nullptr;
1334 }
1335 return shape.AsImage().GetImageRequest();
1336 };
1337
1338 imgIRequest* oldShapeImage = GetShapeImageRequest(aOldComputedStyle);
1339 imgIRequest* newShapeImage = GetShapeImageRequest(Style());
1340 if (oldShapeImage != newShapeImage) {
1341 if (oldShapeImage && HasImageRequest()) {
1342 loader->DisassociateRequestFromFrame(oldShapeImage, this);
1343 }
1344 if (newShapeImage) {
1345 loader->AssociateRequestToFrame(
1346 newShapeImage, this,
1347 ImageLoader::Flags::
1348 RequiresReflowOnFirstFrameCompleteAndLoadEventBlocking);
1349 }
1350 }
1351
1352 // SVGObserverUtils::GetEffectProperties() asserts that we only invoke it with
1353 // the first continuation so we need to check that in advance.
1354 const bool isNonTextFirstContinuation = isNonText && !GetPrevContinuation();
1355 if (isNonTextFirstContinuation) {
1356 // Kick off loading of external SVG resources referenced from properties if
1357 // any. This currently includes filter, clip-path, and mask.
1358 SVGObserverUtils::InitiateResourceDocLoads(this);
1359 }
1360
1361 // If the page contains markup that overrides text direction, and
1362 // does not contain any characters that would activate the Unicode
1363 // bidi algorithm, we need to call |SetBidiEnabled| on the pres
1364 // context before reflow starts. See bug 115921.
1365 if (StyleVisibility()->mDirection == StyleDirection::Rtl) {
1366 PresContext()->SetBidiEnabled();
1367 }
1368
1369 // The following part is for caching offset-path:path(). We cache the
1370 // flatten gfx path, so we don't have to rebuild and re-flattern it at
1371 // each cycle if we have animations on offset-* with a fixed offset-path.
1372 const StyleOffsetPath* oldPath =
1373 aOldComputedStyle ? &aOldComputedStyle->StyleDisplay()->mOffsetPath
1374 : nullptr;
1375 const StyleOffsetPath& newPath = StyleDisplay()->mOffsetPath;
1376 if (!oldPath || *oldPath != newPath) {
1377 // FIXME: Bug 1837042. Cache all basic shapes.
1378 if (newPath.IsPath()) {
1379 RefPtr<gfx::PathBuilder> builder = MotionPathUtils::GetPathBuilder();
1380 RefPtr<gfx::Path> path =
1381 MotionPathUtils::BuildSVGPath(newPath.AsSVGPathData(), builder);
1382 if (path) {
1383 // The newPath could be path('') (i.e. empty path), so its gfx path
1384 // could be nullptr, and so we only set property for a non-empty path.
1385 SetProperty(nsIFrame::OffsetPathCache(), path.forget().take());
1386 } else {
1387 // May have an old cached path, so we have to delete it.
1388 RemoveProperty(nsIFrame::OffsetPathCache());
1389 }
1390 } else if (oldPath) {
1391 RemoveProperty(nsIFrame::OffsetPathCache());
1392 }
1393 }
1394
1395 if (IsPrimaryFrame()) {
1396 MOZ_ASSERT(aOldComputedStyle)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aOldComputedStyle)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aOldComputedStyle))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("aOldComputedStyle"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1396); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOldComputedStyle"
")"); do { *((volatile int*)__null) = 1396; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1397 HandlePrimaryFrameStyleChange(aOldComputedStyle);
1398 }
1399
1400 RemoveStateBits(NS_FRAME_SIMPLE_EVENT_REGIONS | NS_FRAME_SIMPLE_DISPLAYLIST);
1401
1402 mMayHaveRoundedCorners = true;
1403}
1404
1405void nsIFrame::HandleLastRememberedSize() {
1406 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"
, 1406); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsPrimaryFrame()"
")"); do { *((volatile int*)__null) = 1406; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1407 // Storing a last remembered size requires contain-intrinsic-size.
1408 if (!StaticPrefs::layout_css_contain_intrinsic_size_enabled()) {
1409 return;
1410 }
1411 auto* element = Element::FromNodeOrNull(mContent);
1412 if (!element) {
1413 return;
1414 }
1415 const WritingMode wm = GetWritingMode();
1416 const nsStylePosition* stylePos = StylePosition();
1417 bool canRememberBSize = stylePos->ContainIntrinsicBSize(wm).HasAuto();
1418 bool canRememberISize = stylePos->ContainIntrinsicISize(wm).HasAuto();
1419 if (!canRememberBSize) {
1420 element->RemoveLastRememberedBSize();
1421 }
1422 if (!canRememberISize) {
1423 element->RemoveLastRememberedISize();
1424 }
1425 if ((canRememberBSize || canRememberISize) && !HidesContent()) {
1426 bool isNonReplacedInline = IsLineParticipant() && !IsReplaced();
1427 if (!isNonReplacedInline) {
1428 PresContext()->Document()->ObserveForLastRememberedSize(*element);
1429 return;
1430 }
1431 }
1432 PresContext()->Document()->UnobserveForLastRememberedSize(*element);
1433}
1434
1435#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED1
1436void nsIFrame::AssertNewStyleIsSane(ComputedStyle& aNewStyle) {
1437 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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1438 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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1439 // ::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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1440 // 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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1441 (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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1442 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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1443 // ::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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1444 // 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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1445 // 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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1446 (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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1447 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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1448 (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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1449 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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1450 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"
, 1450); 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) = 1450; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1451}
1452#endif
1453
1454void nsIFrame::ReparentFrameViewTo(nsViewManager* aViewManager,
1455 nsView* aNewParentView) {
1456 if (HasView()) {
1457 if (IsMenuPopupFrame()) {
1458 // This view must be parented by the root view, don't reparent it.
1459 return;
1460 }
1461 nsView* view = GetView();
1462 aViewManager->RemoveChild(view);
1463
1464 // The view will remember the Z-order and other attributes that have been
1465 // set on it.
1466 nsView* insertBefore =
1467 nsLayoutUtils::FindSiblingViewFor(aNewParentView, this);
1468 aViewManager->InsertChild(aNewParentView, view, insertBefore,
1469 insertBefore != nullptr);
1470 } else if (HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW)) {
1471 for (const auto& childList : ChildLists()) {
1472 // Iterate the child frames, and check each child frame to see if it has
1473 // a view
1474 for (nsIFrame* child : childList.mList) {
1475 child->ReparentFrameViewTo(aViewManager, aNewParentView);
1476 }
1477 }
1478 }
1479}
1480
1481void nsIFrame::SyncFrameViewProperties(nsView* aView) {
1482 if (!aView) {
1483 aView = GetView();
1484 if (!aView) {
1485 return;
1486 }
1487 }
1488
1489 nsViewManager* vm = aView->GetViewManager();
1490
1491 // Make sure visibility is correct. This only affects nsSubDocumentFrame.
1492 if (!SupportsVisibilityHidden()) {
1493 // See if the view should be hidden or visible
1494 ComputedStyle* sc = Style();
1495 vm->SetViewVisibility(aView, sc->StyleVisibility()->IsVisible()
1496 ? ViewVisibility::Show
1497 : ViewVisibility::Hide);
1498 }
1499}
1500
1501void nsIFrame::CreateView() {
1502 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"
, 1502); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasView()"
")"); do { *((volatile int*)__null) = 1502; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1503
1504 nsView* parentView = GetParent()->GetClosestView();
1505 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"
, 1505); AnnotateMozCrashReason("MOZ_ASSERT" "(" "parentView"
") (" "no parent with view" ")"); do { *((volatile int*)__null
) = 1505; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
1506
1507 nsViewManager* viewManager = parentView->GetViewManager();
1508 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"
, 1508); AnnotateMozCrashReason("MOZ_ASSERT" "(" "viewManager"
") (" "null view manager" ")"); do { *((volatile int*)__null
) = 1508; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
1509
1510 nsView* view = viewManager->CreateView(GetRect(), parentView);
1511 SyncFrameViewProperties(view);
1512
1513 nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(parentView, this);
1514 // we insert this view 'above' the insertBefore view, unless insertBefore is
1515 // null, in which case we want to call with aAbove == false to insert at the
1516 // beginning in document order
1517 viewManager->InsertChild(parentView, view, insertBefore,
1518 insertBefore != nullptr);
1519
1520 // REVIEW: Don't create a widget for fixed-pos elements anymore.
1521 // ComputeRepaintRegionForCopy will calculate the right area to repaint
1522 // when we scroll.
1523 // Reparent views on any child frames (or their descendants) to this
1524 // view. We can just call ReparentFrameViewTo on this frame because
1525 // we know this frame has no view, so it will crawl the children. Also,
1526 // we know that any descendants with views must have 'parentView' as their
1527 // parent view.
1528 ReparentFrameViewTo(viewManager, view);
1529
1530 // Remember our view
1531 SetView(view);
1532
1533 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)
1534 ("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)
;
1535}
1536
1537/* virtual */
1538nsMargin nsIFrame::GetUsedMargin() const {
1539 nsMargin margin;
1540 if (((mState & NS_FRAME_FIRST_REFLOW) && !(mState & NS_FRAME_IN_REFLOW)) ||
1541 IsInSVGTextSubtree()) {
1542 return margin;
1543 }
1544
1545 if (nsMargin* m = GetProperty(UsedMarginProperty())) {
1546 margin = *m;
1547 } else if (!StyleMargin()->GetMargin(margin)) {
1548 // If we get here, our caller probably shouldn't be calling us...
1549 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"
, 1551); MOZ_PretendNoReturn(); } while (0)
1550 "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"
, 1551); MOZ_PretendNoReturn(); } while (0)
1551 "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"
, 1551); MOZ_PretendNoReturn(); } while (0)
;
1552 }
1553 return margin;
1554}
1555
1556/* virtual */
1557nsMargin nsIFrame::GetUsedBorder() const {
1558 if (((mState & NS_FRAME_FIRST_REFLOW) && !(mState & NS_FRAME_IN_REFLOW)) ||
1559 IsInSVGTextSubtree()) {
1560 return {};
1561 }
1562
1563 const nsStyleDisplay* disp = StyleDisplay();
1564 if (IsThemed(disp)) {
1565 // Theme methods don't use const-ness.
1566 auto* mutable_this = const_cast<nsIFrame*>(this);
1567 nsPresContext* pc = PresContext();
1568 LayoutDeviceIntMargin widgetBorder = pc->Theme()->GetWidgetBorder(
1569 pc->DeviceContext(), mutable_this, disp->EffectiveAppearance());
1570 return LayoutDevicePixel::ToAppUnits(widgetBorder,
1571 pc->AppUnitsPerDevPixel());
1572 }
1573
1574 return StyleBorder()->GetComputedBorder();
1575}
1576
1577/* virtual */
1578nsMargin nsIFrame::GetUsedPadding() const {
1579 nsMargin padding;
1580 if (((mState & NS_FRAME_FIRST_REFLOW) && !(mState & NS_FRAME_IN_REFLOW)) ||
1581 IsInSVGTextSubtree()) {
1582 return padding;
1583 }
1584
1585 const nsStyleDisplay* disp = StyleDisplay();
1586 if (IsThemed(disp)) {
1587 // Theme methods don't use const-ness.
1588 nsIFrame* mutable_this = const_cast<nsIFrame*>(this);
1589 nsPresContext* pc = PresContext();
1590 LayoutDeviceIntMargin widgetPadding;
1591 if (pc->Theme()->GetWidgetPadding(pc->DeviceContext(), mutable_this,
1592 disp->EffectiveAppearance(),
1593 &widgetPadding)) {
1594 return LayoutDevicePixel::ToAppUnits(widgetPadding,
1595 pc->AppUnitsPerDevPixel());
1596 }
1597 }
1598
1599 if (nsMargin* p = GetProperty(UsedPaddingProperty())) {
1600 padding = *p;
1601 } else if (!StylePadding()->GetPadding(padding)) {
1602 // If we get here, our caller probably shouldn't be calling us...
1603 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"
, 1605); MOZ_PretendNoReturn(); } while (0)
1604 "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"
, 1605); MOZ_PretendNoReturn(); } while (0)
1605 "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"
, 1605); MOZ_PretendNoReturn(); } while (0)
;
1606 }
1607 return padding;
1608}
1609
1610nsIFrame::Sides nsIFrame::GetSkipSides() const {
1611 if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak ==(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Clone), 0))
1612 StyleBoxDecorationBreak::Clone)(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Clone), 0))
&&
1613 !HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER)) {
1614 return Sides();
1615 }
1616
1617 // Convert the logical skip sides to physical sides using the frame's
1618 // writing mode
1619 WritingMode writingMode = GetWritingMode();
1620 LogicalSides logicalSkip = GetLogicalSkipSides();
1621 Sides skip;
1622
1623 if (logicalSkip.BStart()) {
1624 if (writingMode.IsVertical()) {
1625 skip |= writingMode.IsVerticalLR() ? SideBits::eLeft : SideBits::eRight;
1626 } else {
1627 skip |= SideBits::eTop;
1628 }
1629 }
1630
1631 if (logicalSkip.BEnd()) {
1632 if (writingMode.IsVertical()) {
1633 skip |= writingMode.IsVerticalLR() ? SideBits::eRight : SideBits::eLeft;
1634 } else {
1635 skip |= SideBits::eBottom;
1636 }
1637 }
1638
1639 if (logicalSkip.IStart()) {
1640 if (writingMode.IsVertical()) {
1641 skip |= SideBits::eTop;
1642 } else {
1643 skip |= writingMode.IsBidiLTR() ? SideBits::eLeft : SideBits::eRight;
1644 }
1645 }
1646
1647 if (logicalSkip.IEnd()) {
1648 if (writingMode.IsVertical()) {
1649 skip |= SideBits::eBottom;
1650 } else {
1651 skip |= writingMode.IsBidiLTR() ? SideBits::eRight : SideBits::eLeft;
1652 }
1653 }
1654 return skip;
1655}
1656
1657nsRect nsIFrame::GetPaddingRectRelativeToSelf() const {
1658 nsMargin border = GetUsedBorder().ApplySkipSides(GetSkipSides());
1659 nsRect r(0, 0, mRect.width, mRect.height);
1660 r.Deflate(border);
1661 return r;
1662}
1663
1664nsRect nsIFrame::GetPaddingRect() const {
1665 return GetPaddingRectRelativeToSelf() + GetPosition();
1666}
1667
1668WritingMode nsIFrame::WritingModeForLine(WritingMode aSelfWM,
1669 nsIFrame* aSubFrame) const {
1670 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"
, 1670); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aSelfWM == GetWritingMode()"
")"); do { *((volatile int*)__null) = 1670; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1671 WritingMode writingMode = aSelfWM;
1672
1673 if (StyleTextReset()->mUnicodeBidi == StyleUnicodeBidi::Plaintext) {
1674 mozilla::intl::BidiEmbeddingLevel frameLevel =
1675 nsBidiPresUtils::GetFrameBaseLevel(aSubFrame);
1676 writingMode.SetDirectionFromBidiLevel(frameLevel);
1677 }
1678
1679 return writingMode;
1680}
1681
1682nsRect nsIFrame::GetMarginRect() const {
1683 return GetMarginRectRelativeToSelf() + GetPosition();
1684}
1685
1686nsRect nsIFrame::GetMarginRectRelativeToSelf() const {
1687 nsMargin m = GetUsedMargin().ApplySkipSides(GetSkipSides());
1688 nsRect r(0, 0, mRect.width, mRect.height);
1689 r.Inflate(m);
1690 return r;
1691}
1692
1693bool nsIFrame::IsTransformed() const {
1694 if (!HasAnyStateBits(NS_FRAME_MAY_BE_TRANSFORMED)) {
1695 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"
, 1695); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsCSSTransformed()"
")"); do { *((volatile int*)__null) = 1695; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1696 MOZ_ASSERT(!GetParentSVGTransforms())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!GetParentSVGTransforms())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!GetParentSVGTransforms())))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("!GetParentSVGTransforms()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1696); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetParentSVGTransforms()"
")"); do { *((volatile int*)__null) = 1696; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1697 return false;
1698 }
1699 return IsCSSTransformed() || GetParentSVGTransforms();
1700}
1701
1702bool nsIFrame::IsCSSTransformed() const {
1703 return HasAnyStateBits(NS_FRAME_MAY_BE_TRANSFORMED) &&
1704 (StyleDisplay()->HasTransform(this) || HasAnimationOfTransform());
1705}
1706
1707bool nsIFrame::HasAnimationOfTransform() const {
1708 return IsPrimaryFrame() &&
1709 nsLayoutUtils::HasAnimationOfTransformAndMotionPath(this) &&
1710 SupportsCSSTransforms();
1711}
1712
1713bool nsIFrame::ChildrenHavePerspective(
1714 const nsStyleDisplay* aStyleDisplay) const {
1715 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"
, 1715); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStyleDisplay == StyleDisplay()"
")"); do { *((volatile int*)__null) = 1715; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1716 return aStyleDisplay->HasPerspective(this);
1717}
1718
1719bool nsIFrame::HasAnimationOfOpacity(EffectSet* aEffectSet) const {
1720 return ((nsLayoutUtils::IsPrimaryStyleFrame(this) ||
1721 nsLayoutUtils::FirstContinuationOrIBSplitSibling(this)
1722 ->IsPrimaryFrame()) &&
1723 nsLayoutUtils::HasAnimationOfPropertySet(
1724 this, nsCSSPropertyIDSet::OpacityProperties(), aEffectSet));
1725}
1726
1727bool nsIFrame::HasOpacityInternal(float aThreshold,
1728 const nsStyleDisplay* aStyleDisplay,
1729 const nsStyleEffects* aStyleEffects,
1730 EffectSet* aEffectSet) const {
1731 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"
, 1731); AnnotateMozCrashReason("MOZ_ASSERT" "(" "0.0 <= aThreshold && aThreshold <= 1.0"
") (" "Invalid argument" ")"); do { *((volatile int*)__null)
= 1731; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
1732 if (aStyleEffects->mOpacity < aThreshold ||
1733 aStyleDisplay->mWillChange.bits & StyleWillChangeBits::OPACITY) {
1734 return true;
1735 }
1736
1737 if (!mMayHaveOpacityAnimation) {
1738 return false;
1739 }
1740
1741 return HasAnimationOfOpacity(aEffectSet);
1742}
1743
1744bool nsIFrame::DoGetParentSVGTransforms(gfx::Matrix*) const { return false; }
1745
1746bool nsIFrame::Extend3DContext(const nsStyleDisplay* aStyleDisplay,
1747 const nsStyleEffects* aStyleEffects,
1748 mozilla::EffectSet* aEffectSetForOpacity) const {
1749 if (!HasAnyStateBits(NS_FRAME_MAY_BE_TRANSFORMED)) {
1750 return false;
1751 }
1752 const nsStyleDisplay* disp = StyleDisplayWithOptionalParam(aStyleDisplay);
1753 if (disp->mTransformStyle != StyleTransformStyle::Preserve3d ||
1754 !SupportsCSSTransforms()) {
1755 return false;
1756 }
1757
1758 // If we're all scroll frame, then all descendants will be clipped, so we
1759 // can't preserve 3d.
1760 if (IsScrollContainerFrame()) {
1761 return false;
1762 }
1763
1764 const nsStyleEffects* effects = StyleEffectsWithOptionalParam(aStyleEffects);
1765 if (HasOpacity(disp, effects, aEffectSetForOpacity)) {
1766 return false;
1767 }
1768
1769 return ShouldApplyOverflowClipping(disp).isEmpty() &&
1770 !GetClipPropClipRect(disp, effects, GetSize()) &&
1771 !SVGIntegrationUtils::UsingEffectsForFrame(this) &&
1772 !effects->HasMixBlendMode() &&
1773 disp->mIsolation != StyleIsolation::Isolate;
1774}
1775
1776bool nsIFrame::Combines3DTransformWithAncestors() const {
1777 // Check these first as they are faster then both calls below and are we are
1778 // likely to hit the early return (backface hidden is uncommon and
1779 // GetReferenceFrame is a hot caller of this which only calls this if
1780 // IsCSSTransformed is false).
1781 if (!IsCSSTransformed() && !BackfaceIsHidden()) {
1782 return false;
1783 }
1784 nsIFrame* parent = GetClosestFlattenedTreeAncestorPrimaryFrame();
1785 return parent && parent->Extend3DContext();
1786}
1787
1788bool nsIFrame::In3DContextAndBackfaceIsHidden() const {
1789 // While both tests fail most of the time, test BackfaceIsHidden()
1790 // first since it's likely to fail faster.
1791 return BackfaceIsHidden() && Combines3DTransformWithAncestors();
1792}
1793
1794bool nsIFrame::HasPerspective() const {
1795 if (!IsCSSTransformed()) {
1796 return false;
1797 }
1798 nsIFrame* parent = GetClosestFlattenedTreeAncestorPrimaryFrame();
1799 if (!parent) {
1800 return false;
1801 }
1802 return parent->ChildrenHavePerspective();
1803}
1804
1805nsRect nsIFrame::GetContentRectRelativeToSelf() const {
1806 nsMargin bp = GetUsedBorderAndPadding().ApplySkipSides(GetSkipSides());
1807 nsRect r(0, 0, mRect.width, mRect.height);
1808 r.Deflate(bp);
1809 return r;
1810}
1811
1812nsRect nsIFrame::GetContentRect() const {
1813 return GetContentRectRelativeToSelf() + GetPosition();
1814}
1815
1816bool nsIFrame::ComputeBorderRadii(const BorderRadius& aBorderRadius,
1817 const nsSize& aFrameSize,
1818 const nsSize& aBorderArea, Sides aSkipSides,
1819 nscoord aRadii[8]) {
1820 // Percentages are relative to whichever side they're on.
1821 for (const auto i : mozilla::AllPhysicalHalfCorners()) {
1822 const LengthPercentage& c = aBorderRadius.Get(i);
1823 nscoord axis = HalfCornerIsX(i) ? aFrameSize.width : aFrameSize.height;
1824 aRadii[i] = std::max(0, c.Resolve(axis));
1825 }
1826
1827 if (aSkipSides.Top()) {
1828 aRadii[eCornerTopLeftX] = 0;
1829 aRadii[eCornerTopLeftY] = 0;
1830 aRadii[eCornerTopRightX] = 0;
1831 aRadii[eCornerTopRightY] = 0;
1832 }
1833
1834 if (aSkipSides.Right()) {
1835 aRadii[eCornerTopRightX] = 0;
1836 aRadii[eCornerTopRightY] = 0;
1837 aRadii[eCornerBottomRightX] = 0;
1838 aRadii[eCornerBottomRightY] = 0;
1839 }
1840
1841 if (aSkipSides.Bottom()) {
1842 aRadii[eCornerBottomRightX] = 0;
1843 aRadii[eCornerBottomRightY] = 0;
1844 aRadii[eCornerBottomLeftX] = 0;
1845 aRadii[eCornerBottomLeftY] = 0;
1846 }
1847
1848 if (aSkipSides.Left()) {
1849 aRadii[eCornerBottomLeftX] = 0;
1850 aRadii[eCornerBottomLeftY] = 0;
1851 aRadii[eCornerTopLeftX] = 0;
1852 aRadii[eCornerTopLeftY] = 0;
1853 }
1854
1855 // css3-background specifies this algorithm for reducing
1856 // corner radii when they are too big.
1857 bool haveRadius = false;
1858 double ratio = 1.0f;
1859 for (const auto side : mozilla::AllPhysicalSides()) {
1860 uint32_t hc1 = SideToHalfCorner(side, false, true);
1861 uint32_t hc2 = SideToHalfCorner(side, true, true);
1862 nscoord length =
1863 SideIsVertical(side) ? aBorderArea.height : aBorderArea.width;
1864 nscoord sum = aRadii[hc1] + aRadii[hc2];
1865 if (sum) {
1866 haveRadius = true;
1867 // avoid floating point division in the normal case
1868 if (length < sum) {
1869 ratio = std::min(ratio, double(length) / sum);
1870 }
1871 }
1872 }
1873 if (ratio < 1.0) {
1874 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1875 aRadii[corner] *= ratio;
1876 }
1877 }
1878
1879 return haveRadius;
1880}
1881
1882void nsIFrame::AdjustBorderRadii(nscoord aRadii[8], const nsMargin& aOffsets) {
1883 auto AdjustOffset = [](const uint32_t aRadius, const nscoord aOffset) {
1884 // Implement the cubic formula to adjust offset when aOffset > 0 and
1885 // aRadius / aOffset < 1.
1886 // https://drafts.csswg.org/css-shapes/#valdef-shape-box-margin-box
1887 if (aOffset > 0) {
1888 const double ratio = aRadius / double(aOffset);
1889 if (ratio < 1.0) {
1890 return nscoord(aOffset * (1.0 + std::pow(ratio - 1, 3)));
1891 }
1892 }
1893 return aOffset;
1894 };
1895
1896 for (const auto side : mozilla::AllPhysicalSides()) {
1897 const nscoord offset = aOffsets.Side(side);
1898 const uint32_t hc1 = SideToHalfCorner(side, false, false);
1899 const uint32_t hc2 = SideToHalfCorner(side, true, false);
1900 if (aRadii[hc1] > 0) {
1901 const nscoord offset1 = AdjustOffset(aRadii[hc1], offset);
1902 aRadii[hc1] = std::max(0, aRadii[hc1] + offset1);
1903 }
1904 if (aRadii[hc2] > 0) {
1905 const nscoord offset2 = AdjustOffset(aRadii[hc2], offset);
1906 aRadii[hc2] = std::max(0, aRadii[hc2] + offset2);
1907 }
1908 }
1909}
1910
1911static inline bool RadiiAreDefinitelyZero(const BorderRadius& aBorderRadius) {
1912 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1913 if (!aBorderRadius.Get(corner).IsDefinitelyZero()) {
1914 return false;
1915 }
1916 }
1917 return true;
1918}
1919
1920/* virtual */
1921bool nsIFrame::GetBorderRadii(const nsSize& aFrameSize,
1922 const nsSize& aBorderArea, Sides aSkipSides,
1923 nscoord aRadii[8]) const {
1924 if (!mMayHaveRoundedCorners) {
1925 memset(aRadii, 0, sizeof(nscoord) * 8);
1926 return false;
1927 }
1928
1929 if (IsThemed()) {
1930 // When we're themed, the native theme code draws the border and
1931 // background, and therefore it doesn't make sense to tell other
1932 // code that's interested in border-radius that we have any radii.
1933 //
1934 // In an ideal world, we might have a way for the them to tell us an
1935 // border radius, but since we don't, we're better off assuming
1936 // zero.
1937 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1938 aRadii[corner] = 0;
1939 }
1940 return false;
1941 }
1942
1943 const auto& radii = StyleBorder()->mBorderRadius;
1944 const bool hasRadii =
1945 ComputeBorderRadii(radii, aFrameSize, aBorderArea, aSkipSides, aRadii);
1946 if (!hasRadii) {
1947 // TODO(emilio): Maybe we can just remove this bit and do the
1948 // IsDefinitelyZero check unconditionally. That should still avoid most of
1949 // the work, though maybe not the cache miss of going through the style and
1950 // the border struct.
1951 const_cast<nsIFrame*>(this)->mMayHaveRoundedCorners =
1952 !RadiiAreDefinitelyZero(radii);
1953 }
1954 return hasRadii;
1955}
1956
1957bool nsIFrame::GetBorderRadii(nscoord aRadii[8]) const {
1958 nsSize sz = GetSize();
1959 return GetBorderRadii(sz, sz, GetSkipSides(), aRadii);
1960}
1961
1962bool nsIFrame::GetMarginBoxBorderRadii(nscoord aRadii[8]) const {
1963 return GetBoxBorderRadii(aRadii, GetUsedMargin());
1964}
1965
1966bool nsIFrame::GetPaddingBoxBorderRadii(nscoord aRadii[8]) const {
1967 return GetBoxBorderRadii(aRadii, -GetUsedBorder());
1968}
1969
1970bool nsIFrame::GetContentBoxBorderRadii(nscoord aRadii[8]) const {
1971 return GetBoxBorderRadii(aRadii, -GetUsedBorderAndPadding());
1972}
1973
1974bool nsIFrame::GetBoxBorderRadii(nscoord aRadii[8],
1975 const nsMargin& aOffsets) const {
1976 if (!GetBorderRadii(aRadii)) {
1977 return false;
1978 }
1979 AdjustBorderRadii(aRadii, aOffsets);
1980 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1981 if (aRadii[corner]) {
1982 return true;
1983 }
1984 }
1985 return false;
1986}
1987
1988bool nsIFrame::GetShapeBoxBorderRadii(nscoord aRadii[8]) const {
1989 using Tag = StyleShapeOutside::Tag;
1990 auto& shapeOutside = StyleDisplay()->mShapeOutside;
1991 auto box = StyleShapeBox::MarginBox;
1992 switch (shapeOutside.tag) {
1993 case Tag::Image:
1994 case Tag::None:
1995 return false;
1996 case Tag::Box:
1997 box = shapeOutside.AsBox();
1998 break;
1999 case Tag::Shape:
2000 box = shapeOutside.AsShape()._1;
2001 break;
2002 }
2003
2004 switch (box) {
2005 case StyleShapeBox::ContentBox:
2006 return GetContentBoxBorderRadii(aRadii);
2007 case StyleShapeBox::PaddingBox:
2008 return GetPaddingBoxBorderRadii(aRadii);
2009 case StyleShapeBox::BorderBox:
2010 return GetBorderRadii(aRadii);
2011 case StyleShapeBox::MarginBox:
2012 return GetMarginBoxBorderRadii(aRadii);
2013 default:
2014 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"
, 2014); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Unexpected box value" ")"); do {
*((volatile int*)__null) = 2014; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
2015 return false;
2016 }
2017}
2018
2019nscoord nsIFrame::OneEmInAppUnits() const {
2020 return StyleFont()
2021 ->mFont.size.ScaledBy(nsLayoutUtils::FontSizeInflationFor(this))
2022 .ToAppUnits();
2023}
2024
2025ComputedStyle* nsIFrame::GetAdditionalComputedStyle(int32_t aIndex) const {
2026 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"
, 2026); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aIndex >= 0"
") (" "invalid index number" ")"); do { *((volatile int*)__null
) = 2026; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
2027 return nullptr;
2028}
2029
2030void nsIFrame::SetAdditionalComputedStyle(int32_t aIndex,
2031 ComputedStyle* aComputedStyle) {
2032 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"
, 2032); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aIndex >= 0"
") (" "invalid index number" ")"); do { *((volatile int*)__null
) = 2032; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
2033}
2034
2035nscoord nsIFrame::SynthesizeFallbackBaseline(
2036 WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
2037 const auto margin = GetLogicalUsedMargin(aWM);
2038 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"
, 2038); MOZ_PretendNoReturn(); } } while (0)
;
2039 if (aWM.IsCentralBaseline()) {
2040 return (BSize(aWM) + GetLogicalUsedMargin(aWM).BEnd(aWM)) / 2;
2041 }
2042 // Baseline for inverted line content is the top (block-start) margin edge,
2043 // as the frame is in effect "flipped" for alignment purposes.
2044 if (aWM.IsLineInverted()) {
2045 const auto marginStart = margin.BStart(aWM);
2046 return aBaselineGroup == BaselineSharingGroup::First
2047 ? -marginStart
2048 : BSize(aWM) + marginStart;
2049 }
2050 // Otherwise, the bottom margin edge, per CSS2.1's definition of the
2051 // 'baseline' value of 'vertical-align'.
2052 const auto marginEnd = margin.BEnd(aWM);
2053 return aBaselineGroup == BaselineSharingGroup::First ? BSize(aWM) + marginEnd
2054 : -marginEnd;
2055}
2056
2057nscoord nsIFrame::GetLogicalBaseline(WritingMode aWM) const {
2058 return GetLogicalBaseline(aWM, GetDefaultBaselineSharingGroup(),
2059 BaselineExportContext::LineLayout);
2060}
2061
2062nscoord nsIFrame::GetLogicalBaseline(
2063 WritingMode aWM, BaselineSharingGroup aBaselineGroup,
2064 BaselineExportContext aExportContext) const {
2065 const auto result =
2066 GetNaturalBaselineBOffset(aWM, aBaselineGroup, aExportContext)
2067 .valueOrFrom([this, aWM, aBaselineGroup]() {
2068 return SynthesizeFallbackBaseline(aWM, aBaselineGroup);
2069 });
2070 if (aBaselineGroup == BaselineSharingGroup::Last) {
2071 return BSize(aWM) - result;
2072 }
2073 return result;
2074}
2075
2076const nsFrameList& nsIFrame::GetChildList(ChildListID aListID) const {
2077 if (IsAbsoluteContainer() && aListID == GetAbsoluteListID()) {
2078 return GetAbsoluteContainingBlock()->GetChildList();
2079 } else {
2080 return nsFrameList::EmptyList();
2081 }
2082}
2083
2084void nsIFrame::GetChildLists(nsTArray<ChildList>* aLists) const {
2085 if (IsAbsoluteContainer()) {
2086 const nsFrameList& absoluteList =
2087 GetAbsoluteContainingBlock()->GetChildList();
2088 absoluteList.AppendIfNonempty(aLists, GetAbsoluteListID());
2089 }
2090}
2091
2092AutoTArray<nsIFrame::ChildList, 4> nsIFrame::CrossDocChildLists() {
2093 AutoTArray<ChildList, 4> childLists;
2094 nsSubDocumentFrame* subdocumentFrame = do_QueryFrame(this);
2095 if (subdocumentFrame) {
2096 // Descend into the subdocument
2097 nsIFrame* root = subdocumentFrame->GetSubdocumentRootFrame();
2098 if (root) {
2099 childLists.EmplaceBack(
2100 nsFrameList(root, nsLayoutUtils::GetLastSibling(root)),
2101 FrameChildListID::Principal);
2102 }
2103 }
2104
2105 GetChildLists(&childLists);
2106 return childLists;
2107}
2108
2109nsIFrame::CaretBlockAxisMetrics nsIFrame::GetCaretBlockAxisMetrics(
2110 mozilla::WritingMode aWM, const nsFontMetrics& aFM) const {
2111 // Note(dshin): Ultimately, this does something highly similar (But still
2112 // different) to `nsLayoutUtils::GetFirstLinePosition`.
2113 const auto baseline = GetCaretBaseline();
2114 nscoord ascent = 0, descent = 0;
2115 ascent = aFM.MaxAscent();
2116 descent = aFM.MaxDescent();
2117 const nscoord height = ascent + descent;
2118 if (aWM.IsVertical() && aWM.IsLineInverted()) {
2119 return CaretBlockAxisMetrics{.mOffset = baseline - descent,
2120 .mExtent = height};
2121 }
2122 return CaretBlockAxisMetrics{.mOffset = baseline - ascent, .mExtent = height};
2123}
2124
2125const nsAtom* nsIFrame::ComputePageValue(const nsAtom* aAutoValue) const {
2126 const nsAtom* value = aAutoValue ? aAutoValue : nsGkAtoms::_empty;
2127 const nsIFrame* frame = this;
2128 // Find what CSS page name value this frame's subtree has, if any.
2129 // Starting with this frame, check if a page name other than auto is present,
2130 // and record it if so. Then, if the current frame is a container frame, find
2131 // the first non-placeholder child and repeat.
2132 // This will find the most deeply nested first in-flow child of this frame's
2133 // subtree, and return its page name (with auto resolved if applicable, and
2134 // subtrees with no page-names returning the empty atom rather than null).
2135 do {
2136 if (const nsAtom* maybePageName = frame->GetStylePageName()) {
2137 value = maybePageName;
2138 }
2139 // Get the next frame to read from.
2140 const nsIFrame* firstNonPlaceholderFrame = nullptr;
2141 // If this is a container frame, inspect its in-flow children.
2142 if (const nsContainerFrame* containerFrame = do_QueryFrame(frame)) {
2143 for (const nsIFrame* childFrame : containerFrame->PrincipalChildList()) {
2144 if (!childFrame->IsPlaceholderFrame()) {
2145 firstNonPlaceholderFrame = childFrame;
2146 break;
2147 }
2148 }
2149 }
2150 frame = firstNonPlaceholderFrame;
2151 } while (frame);
2152 return value;
2153}
2154
2155Visibility nsIFrame::GetVisibility() const {
2156 if (!HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)) {
2157 return Visibility::Untracked;
2158 }
2159
2160 bool isSet = false;
2161 uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet);
2162
2163 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"
, 2165); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2165; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2164 "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"
, 2165); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2165; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2165 "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"
, 2165); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2165; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2166
2167 return visibleCount > 0 ? Visibility::ApproximatelyVisible
2168 : Visibility::ApproximatelyNonVisible;
2169}
2170
2171void nsIFrame::UpdateVisibilitySynchronously() {
2172 mozilla::PresShell* presShell = PresShell();
2173 if (!presShell) {
2174 return;
2175 }
2176
2177 if (presShell->AssumeAllFramesVisible()) {
2178 presShell->EnsureFrameInApproximatelyVisibleList(this);
2179 return;
2180 }
2181
2182 bool visible = StyleVisibility()->IsVisible();
2183 nsIFrame* f = GetParent();
2184 nsRect rect = GetRectRelativeToSelf();
2185 nsIFrame* rectFrame = this;
2186 while (f && visible) {
2187 if (ScrollContainerFrame* sf = do_QueryFrame(f)) {
2188 nsRect transformedRect =
2189 nsLayoutUtils::TransformFrameRectToAncestor(rectFrame, rect, f);
2190 if (!sf->IsRectNearlyVisible(transformedRect)) {
2191 visible = false;
2192 break;
2193 }
2194
2195 // In this code we're trying to synchronously update *approximate*
2196 // visibility. (In the future we may update precise visibility here as
2197 // well, which is why the method name does not contain 'approximate'.) The
2198 // IsRectNearlyVisible() check above tells us that the rect we're checking
2199 // is approximately visible within the scrollframe, but we still need to
2200 // ensure that, even if it was scrolled into view, it'd be visible when we
2201 // consider the rest of the document. To do that, we move transformedRect
2202 // to be contained in the scrollport as best we can (it might not fit) to
2203 // pretend that it was scrolled into view.
2204 rect = transformedRect.MoveInsideAndClamp(sf->GetScrollPortRect());
2205 rectFrame = f;
2206 }
2207 nsIFrame* parent = f->GetParent();
2208 if (!parent) {
2209 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(f);
2210 if (parent && parent->PresContext()->IsChrome()) {
2211 break;
2212 }
2213 }
2214 f = parent;
2215 }
2216
2217 if (visible) {
2218 presShell->EnsureFrameInApproximatelyVisibleList(this);
2219 } else {
2220 presShell->RemoveFrameFromApproximatelyVisibleList(this);
2221 }
2222}
2223
2224void nsIFrame::EnableVisibilityTracking() {
2225 if (HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)) {
2226 return; // Nothing to do.
2227 }
2228
2229 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"
, 2231); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasProperty(VisibilityStateProperty())"
") (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")"); do { *((volatile int*)__null) = 2231; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2230 "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"
, 2231); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasProperty(VisibilityStateProperty())"
") (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")"); do { *((volatile int*)__null) = 2231; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2231 "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"
, 2231); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasProperty(VisibilityStateProperty())"
") (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")"); do { *((volatile int*)__null) = 2231; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2232
2233 // Add the state bit so we know to track visibility for this frame, and
2234 // initialize the frame property.
2235 AddStateBits(NS_FRAME_VISIBILITY_IS_TRACKED);
2236 SetProperty(VisibilityStateProperty(), 0);
2237
2238 mozilla::PresShell* presShell = PresShell();
2239 if (!presShell) {
2240 return;
2241 }
2242
2243 // Schedule a visibility update. This method will virtually always be called
2244 // when layout has changed anyway, so it's very unlikely that any additional
2245 // visibility updates will be triggered by this, but this way we guarantee
2246 // that if this frame is currently visible we'll eventually find out.
2247 presShell->ScheduleApproximateFrameVisibilityUpdateSoon();
2248}
2249
2250void nsIFrame::DisableVisibilityTracking() {
2251 if (!HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)) {
2252 return; // Nothing to do.
2253 }
2254
2255 bool isSet = false;
2256 uint32_t visibleCount = TakeProperty(VisibilityStateProperty(), &isSet);
2257
2258 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"
, 2260); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2260; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2259 "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"
, 2260); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2260; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2260 "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"
, 2260); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2260; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2261
2262 RemoveStateBits(NS_FRAME_VISIBILITY_IS_TRACKED);
2263
2264 if (visibleCount == 0) {
2265 return; // We were nonvisible.
2266 }
2267
2268 // We were visible, so send an OnVisibilityChange() notification.
2269 OnVisibilityChange(Visibility::ApproximatelyNonVisible);
2270}
2271
2272void nsIFrame::DecApproximateVisibleCount(
2273 const Maybe<OnNonvisible>& aNonvisibleAction
2274 /* = Nothing() */) {
2275 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"
, 2275); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)"
")"); do { *((volatile int*)__null) = 2275; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2276
2277 bool isSet = false;
2278 uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet);
2279
2280 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"
, 2282); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2282; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2281 "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"
, 2282); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2282; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2282 "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"
, 2282); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2282; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2283 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"
, 2285); AnnotateMozCrashReason("MOZ_ASSERT" "(" "visibleCount > 0"
") (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")"); do { *((volatile int*)__null) = 2285; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2284 "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"
, 2285); AnnotateMozCrashReason("MOZ_ASSERT" "(" "visibleCount > 0"
") (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")"); do { *((volatile int*)__null) = 2285; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2285 "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"
, 2285); AnnotateMozCrashReason("MOZ_ASSERT" "(" "visibleCount > 0"
") (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")"); do { *((volatile int*)__null) = 2285; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2286
2287 visibleCount--;
2288 SetProperty(VisibilityStateProperty(), visibleCount);
2289 if (visibleCount > 0) {
2290 return;
2291 }
2292
2293 // We just became nonvisible, so send an OnVisibilityChange() notification.
2294 OnVisibilityChange(Visibility::ApproximatelyNonVisible, aNonvisibleAction);
2295}
2296
2297void nsIFrame::IncApproximateVisibleCount() {
2298 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"
, 2298); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)"
")"); do { *((volatile int*)__null) = 2298; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2299
2300 bool isSet = false;
2301 uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet);
2302
2303 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"
, 2305); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2305; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2304 "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"
, 2305); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2305; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2305 "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"
, 2305); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2305; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2306
2307 visibleCount++;
2308 SetProperty(VisibilityStateProperty(), visibleCount);
2309 if (visibleCount > 1) {
2310 return;
2311 }
2312
2313 // We just became visible, so send an OnVisibilityChange() notification.
2314 OnVisibilityChange(Visibility::ApproximatelyVisible);
2315}
2316
2317void nsIFrame::OnVisibilityChange(Visibility aNewVisibility,
2318 const Maybe<OnNonvisible>& aNonvisibleAction
2319 /* = Nothing() */) {
2320 // XXX(seth): In bug 1218990 we'll implement visibility tracking for CSS
2321 // images here.
2322}
2323
2324static nsIFrame* GetActiveSelectionFrame(nsPresContext* aPresContext,
2325 nsIFrame* aFrame) {
2326 nsIContent* capturingContent = PresShell::GetCapturingContent();
2327 if (capturingContent) {
2328 nsIFrame* activeFrame = aPresContext->GetPrimaryFrameFor(capturingContent);
2329 return activeFrame ? activeFrame : aFrame;
2330 }
2331
2332 return aFrame;
2333}
2334
2335int16_t nsIFrame::DetermineDisplaySelection() {
2336 int16_t selType = nsISelectionController::SELECTION_OFF;
2337
2338 nsCOMPtr<nsISelectionController> selCon;
2339 nsresult result =
2340 GetSelectionController(PresContext(), getter_AddRefs(selCon));
2341 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) && selCon) {
2342 result = selCon->GetDisplaySelection(&selType);
2343 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) &&
2344 (selType != nsISelectionController::SELECTION_OFF)) {
2345 // Check whether style allows selection.
2346 if (!IsSelectable(nullptr)) {
2347 selType = nsISelectionController::SELECTION_OFF;
2348 }
2349 }
2350 }
2351 return selType;
2352}
2353
2354static Element* FindElementAncestorForMozSelection(nsIContent* aContent) {
2355 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"
, 2355); return nullptr; } } while (false)
;
2356 while (aContent && aContent->IsInNativeAnonymousSubtree()) {
2357 aContent = aContent->GetClosestNativeAnonymousSubtreeRootParentOrHost();
2358 }
2359 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"
, 2359); MOZ_PretendNoReturn(); } } while (0)
;
2360 return aContent ? aContent->GetAsElementOrParentElement() : nullptr;
2361}
2362
2363already_AddRefed<ComputedStyle> nsIFrame::ComputeSelectionStyle(
2364 int16_t aSelectionStatus) const {
2365 // Just bail out if not a selection-status that ::selection applies to.
2366 if (aSelectionStatus != nsISelectionController::SELECTION_ON &&
2367 aSelectionStatus != nsISelectionController::SELECTION_DISABLED) {
2368 return nullptr;
2369 }
2370 Element* element = FindElementAncestorForMozSelection(GetContent());
2371 if (!element) {
2372 return nullptr;
2373 }
2374 RefPtr<ComputedStyle> pseudoStyle =
2375 PresContext()->StyleSet()->ProbePseudoElementStyle(
2376 *element, PseudoStyleType::selection, nullptr, Style());
2377 if (!pseudoStyle) {
2378 return nullptr;
2379 }
2380 // When in high-contrast mode, the style system ends up ignoring the color
2381 // declarations, which means that the ::selection style becomes the inherited
2382 // color, and default background. That's no good.
2383 // When force-color-adjust is set to none allow using the color styles,
2384 // as they will not be replaced.
2385 if (PresContext()->ForcingColors() &&
2386 pseudoStyle->StyleText()->mForcedColorAdjust !=
2387 StyleForcedColorAdjust::None) {
2388 return nullptr;
2389 }
2390 return do_AddRef(pseudoStyle);
2391}
2392
2393already_AddRefed<ComputedStyle> nsIFrame::ComputeHighlightSelectionStyle(
2394 nsAtom* aHighlightName) {
2395 Element* element = FindElementAncestorForMozSelection(GetContent());
2396 if (!element) {
2397 return nullptr;
2398 }
2399 return PresContext()->StyleSet()->ProbePseudoElementStyle(
2400 *element, PseudoStyleType::highlight, aHighlightName, Style());
2401}
2402
2403already_AddRefed<ComputedStyle> nsIFrame::ComputeTargetTextStyle() const {
2404 const Element* element = FindElementAncestorForMozSelection(GetContent());
2405 if (!element) {
2406 return nullptr;
2407 }
2408 RefPtr pseudoStyle = PresContext()->StyleSet()->ProbePseudoElementStyle(
2409 *element, PseudoStyleType::targetText, nullptr, Style());
2410 if (!pseudoStyle) {
2411 return nullptr;
2412 }
2413 if (PresContext()->ForcingColors() &&
2414 pseudoStyle->StyleText()->mForcedColorAdjust !=
2415 StyleForcedColorAdjust::None) {
2416 return nullptr;
2417 }
2418 return pseudoStyle.forget();
2419}
2420
2421bool nsIFrame::CanBeDynamicReflowRoot() const {
2422 const auto& display = *StyleDisplay();
2423 if (IsLineParticipant() || display.mDisplay.IsRuby() ||
2424 display.IsInnerTableStyle() ||
2425 display.DisplayInside() == StyleDisplayInside::Table) {
2426 // We have a display type where 'width' and 'height' don't actually set the
2427 // width or height (i.e., the size depends on content).
2428 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"
, 2429); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT)"
") (" "should not have dynamic reflow root bit" ")"); do { *
((volatile int*)__null) = 2429; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
2429 "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"
, 2429); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT)"
") (" "should not have dynamic reflow root bit" ")"); do { *
((volatile int*)__null) = 2429; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
2430 return false;
2431 }
2432
2433 // In general, frames that have contain:layout+size can be reflow roots.
2434 // (One exception: table-wrapper frames don't work well as reflow roots,
2435 // because their inner-table ReflowInput init path tries to reuse & deref
2436 // the wrapper's containing block's reflow input, which may be null if we
2437 // initiate reflow from the table-wrapper itself.)
2438 //
2439 // Changes to `contain` force frame reconstructions, so we used to use
2440 // NS_FRAME_REFLOW_ROOT, this bit could be set for the whole lifetime of
2441 // this frame. But after the support of `content-visibility: auto` which
2442 // is with contain layout + size when it's not relevant to user, and only
2443 // with contain layout when it is relevant. The frame does not reconstruct
2444 // when the relevancy changes. So we use NS_FRAME_DYNAMIC_REFLOW_ROOT instead.
2445 //
2446 // We place it above the pref check on purpose, to make sure it works for
2447 // containment even with the pref disabled.
2448 if (display.IsContainLayout() && GetContainSizeAxes().IsBoth()) {
2449 return true;
2450 }
2451
2452 if (!StaticPrefs::layout_dynamic_reflow_roots_enabled()) {
2453 return false;
2454 }
2455
2456 // We can't serve as a dynamic reflow root if our used 'width' and 'height'
2457 // might be influenced by content.
2458 //
2459 // FIXME: For display:block, we should probably optimize inline-size: auto.
2460 // FIXME: Other flex and grid cases?
2461 const auto& pos = *StylePosition();
2462 const auto& width = pos.mWidth;
2463 const auto& height = pos.mHeight;
2464 if (!width.IsLengthPercentage() || width.HasPercent() ||
2465 !height.IsLengthPercentage() || height.HasPercent() ||
2466 IsIntrinsicKeyword(pos.mMinWidth) || IsIntrinsicKeyword(pos.mMaxWidth) ||
2467 IsIntrinsicKeyword(pos.mMinHeight) ||
2468 IsIntrinsicKeyword(pos.mMaxHeight) ||
2469 ((pos.mMinWidth.IsAuto() || pos.mMinHeight.IsAuto()) &&
2470 IsFlexOrGridItem())) {
2471 return false;
2472 }
2473
2474 // If our flex-basis is 'auto', it'll defer to 'width' (or 'height') which
2475 // we've already checked. Otherwise, it preempts them, so we need to
2476 // perform the same "could-this-value-be-influenced-by-content" checks that
2477 // we performed for 'width' and 'height' above.
2478 if (IsFlexItem()) {
2479 const auto& flexBasis = pos.mFlexBasis;
2480 if (!flexBasis.IsAuto()) {
2481 if (!flexBasis.IsSize() || !flexBasis.AsSize().IsLengthPercentage() ||
2482 flexBasis.AsSize().HasPercent()) {
2483 return false;
2484 }
2485 }
2486 }
2487
2488 if (!IsFixedPosContainingBlock()) {
2489 // We can't treat this frame as a reflow root, since dynamic changes
2490 // to absolutely-positioned frames inside of it require that we
2491 // reflow the placeholder before we reflow the absolutely positioned
2492 // frame.
2493 // FIXME: Alternatively, we could sort the reflow roots in
2494 // PresShell::ProcessReflowCommands by depth in the tree, from
2495 // deepest to least deep. However, for performance (FIXME) we
2496 // should really be sorting them in the opposite order!
2497 return false;
2498 }
2499
2500 // If we participate in a container's block reflow context, or margins
2501 // can collapse through us, we can't be a dynamic reflow root.
2502 if (IsBlockFrameOrSubclass() && !HasAnyStateBits(NS_BLOCK_BFC)) {
2503 return false;
2504 }
2505
2506 // Subgrids are never reflow roots, but 'contain:layout/paint' prevents
2507 // creating a subgrid in the first place.
2508 if (pos.mGridTemplateColumns.IsSubgrid() ||
2509 pos.mGridTemplateRows.IsSubgrid()) {
2510 // NOTE: we could check that 'display' of our parent's primary frame is
2511 // '[inline-]grid' here but that's probably not worth it in practice.
2512 if (!display.IsContainLayout() && !display.IsContainPaint()) {
2513 return false;
2514 }
2515 }
2516
2517 // If we are split, we can't be a dynamic reflow root. Our reflow status may
2518 // change after reflow, and our parent is responsible to create or delete our
2519 // next-in-flow.
2520 if (GetPrevContinuation() || GetNextContinuation()) {
2521 return false;
2522 }
2523
2524 return true;
2525}
2526
2527/********************************************************
2528 * Refreshes each content's frame
2529 *********************************************************/
2530
2531void nsIFrame::DisplayOutlineUnconditional(nsDisplayListBuilder* aBuilder,
2532 const nsDisplayListSet& aLists) {
2533 // Per https://drafts.csswg.org/css-tables-3/#global-style-overrides:
2534 // "All css properties of table-column and table-column-group boxes are
2535 // ignored, except when explicitly specified by this specification."
2536 // CSS outlines fall into this category, so we skip them on these boxes.
2537 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"
, 2537); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsTableColGroupFrame() && !IsTableColFrame()"
")"); do { *((volatile int*)__null) = 2537; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2538 const auto& outline = *StyleOutline();
2539
2540 if (!outline.ShouldPaintOutline()) {
2541 return;
2542 }
2543
2544 // Outlines are painted by the table wrapper frame.
2545 if (IsTableFrame()) {
2546 return;
2547 }
2548
2549 if (HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT) &&
2550 ScrollableOverflowRect().IsEmpty()) {
2551 // Skip parts of IB-splits with an empty overflow rect, see bug 434301.
2552 // We may still want to fix some of the overflow area calculations over in
2553 // that bug.
2554 return;
2555 }
2556
2557 // We don't display outline-style: auto on themed frames that have their own
2558 // focus indicators.
2559 if (outline.mOutlineStyle.IsAuto()) {
2560 auto* disp = StyleDisplay();
2561 if (IsThemed(disp) && PresContext()->Theme()->ThemeDrawsFocusForWidget(
2562 this, disp->EffectiveAppearance())) {
2563 return;
2564 }
2565 }
2566
2567 aLists.Outlines()->AppendNewToTop<nsDisplayOutline>(aBuilder, this);
2568}
2569
2570void nsIFrame::DisplayOutline(nsDisplayListBuilder* aBuilder,
2571 const nsDisplayListSet& aLists) {
2572 if (!IsVisibleForPainting()) return;
2573
2574 DisplayOutlineUnconditional(aBuilder, aLists);
2575}
2576
2577void nsIFrame::DisplayInsetBoxShadowUnconditional(
2578 nsDisplayListBuilder* aBuilder, nsDisplayList* aList) {
2579 // XXXbz should box-shadow for rows/rowgroups/columns/colgroups get painted
2580 // just because we're visible? Or should it depend on the cell visibility
2581 // when we're not the whole table?
2582 const auto* effects = StyleEffects();
2583 if (effects->HasBoxShadowWithInset(true)) {
2584 aList->AppendNewToTop<nsDisplayBoxShadowInner>(aBuilder, this);
2585 }
2586}
2587
2588void nsIFrame::DisplayInsetBoxShadow(nsDisplayListBuilder* aBuilder,
2589 nsDisplayList* aList) {
2590 if (!IsVisibleForPainting()) return;
2591
2592 DisplayInsetBoxShadowUnconditional(aBuilder, aList);
2593}
2594
2595void nsIFrame::DisplayOutsetBoxShadowUnconditional(
2596 nsDisplayListBuilder* aBuilder, nsDisplayList* aList) {
2597 // XXXbz should box-shadow for rows/rowgroups/columns/colgroups get painted
2598 // just because we're visible? Or should it depend on the cell visibility
2599 // when we're not the whole table?
2600 const auto* effects = StyleEffects();
2601 if (effects->HasBoxShadowWithInset(false)) {
2602 aList->AppendNewToTop<nsDisplayBoxShadowOuter>(aBuilder, this);
2603 }
2604}
2605
2606void nsIFrame::DisplayOutsetBoxShadow(nsDisplayListBuilder* aBuilder,
2607 nsDisplayList* aList) {
2608 if (!IsVisibleForPainting()) return;
2609
2610 DisplayOutsetBoxShadowUnconditional(aBuilder, aList);
2611}
2612
2613void nsIFrame::DisplayCaret(nsDisplayListBuilder* aBuilder,
2614 nsDisplayList* aList) {
2615 if (!IsVisibleForPainting()) return;
2616
2617 aList->AppendNewToTop<nsDisplayCaret>(aBuilder, this);
2618}
2619
2620nscolor nsIFrame::GetCaretColorAt(int32_t aOffset) {
2621 return nsLayoutUtils::GetTextColor(this, &nsStyleUI::mCaretColor);
2622}
2623
2624auto nsIFrame::ComputeShouldPaintBackground() const -> ShouldPaintBackground {
2625 nsPresContext* pc = PresContext();
2626 ShouldPaintBackground settings{pc->GetBackgroundColorDraw(),
2627 pc->GetBackgroundImageDraw()};
2628 if (settings.mColor && settings.mImage) {
2629 return settings;
2630 }
2631
2632 if (StyleVisibility()->mPrintColorAdjust == StylePrintColorAdjust::Exact) {
2633 return {true, true};
2634 }
2635
2636 return settings;
2637}
2638
2639bool nsIFrame::DisplayBackgroundUnconditional(nsDisplayListBuilder* aBuilder,
2640 const nsDisplayListSet& aLists) {
2641 if (aBuilder->IsForEventDelivery() && !aBuilder->HitTestIsForVisibility()) {
2642 // For hit-testing, we generally just need a light-weight data structure
2643 // like nsDisplayEventReceiver. But if the hit-testing is for visibility,
2644 // then we need to know the opaque region in order to determine whether to
2645 // stop or not.
2646 aLists.BorderBackground()->AppendNewToTop<nsDisplayEventReceiver>(aBuilder,
2647 this);
2648 return false;
2649 }
2650
2651 const AppendedBackgroundType result =
2652 nsDisplayBackgroundImage::AppendBackgroundItemsToTop(
2653 aBuilder, this,
2654 GetRectRelativeToSelf() + aBuilder->ToReferenceFrame(this),
2655 aLists.BorderBackground());
2656
2657 if (result == AppendedBackgroundType::None) {
2658 aBuilder->BuildCompositorHitTestInfoIfNeeded(this,
2659 aLists.BorderBackground());
2660 }
2661
2662 return result == AppendedBackgroundType::ThemedBackground;
2663}
2664
2665void nsIFrame::DisplayBorderBackgroundOutline(nsDisplayListBuilder* aBuilder,
2666 const nsDisplayListSet& aLists) {
2667 // The visibility check belongs here since child elements have the
2668 // opportunity to override the visibility property and display even if
2669 // their parent is hidden.
2670 if (!IsVisibleForPainting()) {
2671 return;
2672 }
2673
2674 DisplayOutsetBoxShadowUnconditional(aBuilder, aLists.BorderBackground());
2675
2676 bool bgIsThemed = DisplayBackgroundUnconditional(aBuilder, aLists);
2677 DisplayInsetBoxShadowUnconditional(aBuilder, aLists.BorderBackground());
2678
2679 // If there's a themed background, we should not create a border item.
2680 // It won't be rendered.
2681 // Don't paint borders for tables here, since they paint them in a different
2682 // order.
2683 if (!bgIsThemed && StyleBorder()->HasBorder() && !IsTableFrame()) {
2684 aLists.BorderBackground()->AppendNewToTop<nsDisplayBorder>(aBuilder, this);
2685 }
2686
2687 DisplayOutlineUnconditional(aBuilder, aLists);
2688}
2689
2690inline static bool IsSVGContentWithCSSClip(const nsIFrame* aFrame) {
2691 // The CSS spec says that the 'clip' property only applies to absolutely
2692 // positioned elements, whereas the SVG spec says that it applies to SVG
2693 // elements regardless of the value of the 'position' property. Here we obey
2694 // the CSS spec for outer-<svg> (since that's what we generally do), but
2695 // obey the SVG spec for other SVG elements to which 'clip' applies.
2696 return aFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT) &&
2697 aFrame->GetContent()->IsAnyOfSVGElements(nsGkAtoms::svg,
2698 nsGkAtoms::foreignObject);
2699}
2700
2701Maybe<nsRect> nsIFrame::GetClipPropClipRect(const nsStyleDisplay* aDisp,
2702 const nsStyleEffects* aEffects,
2703 const nsSize& aSize) const {
2704 if (aEffects->mClip.IsAuto() ||
2705 !(aDisp->IsAbsolutelyPositioned(this) || IsSVGContentWithCSSClip(this))) {
2706 return Nothing();
2707 }
2708
2709 auto& clipRect = aEffects->mClip.AsRect();
2710 nsRect rect = clipRect.ToLayoutRect();
2711 if (MOZ_LIKELY(StyleBorder()->mBoxDecorationBreak ==(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Slice), 1))
2712 StyleBoxDecorationBreak::Slice)(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Slice), 1))
) {
2713 // The clip applies to the joined boxes so it's relative the first
2714 // continuation.
2715 nscoord y = 0;
2716 for (nsIFrame* f = GetPrevContinuation(); f; f = f->GetPrevContinuation()) {
2717 y += f->GetRect().height;
2718 }
2719 rect.MoveBy(nsPoint(0, -y));
2720 }
2721
2722 if (clipRect.right.IsAuto()) {
2723 rect.width = aSize.width - rect.x;
2724 }
2725 if (clipRect.bottom.IsAuto()) {
2726 rect.height = aSize.height - rect.y;
2727 }
2728 return Some(rect);
2729}
2730
2731/**
2732 * If the CSS 'overflow' property applies to this frame, and is not
2733 * handled by constructing a dedicated nsHTML/XULScrollFrame, set up clipping
2734 * for that overflow in aBuilder->ClipState() to clip all containing-block
2735 * descendants.
2736 */
2737static void ApplyOverflowClipping(
2738 nsDisplayListBuilder* aBuilder, const nsIFrame* aFrame,
2739 PhysicalAxes aClipAxes,
2740 DisplayListClipState::AutoClipMultiple& aClipState) {
2741 // Only 'clip' is handled here (and 'hidden' for table frames, and any
2742 // non-'visible' value for blocks in a paginated context).
2743 // We allow 'clip' to apply to any kind of frame. This is required by
2744 // comboboxes which make their display text (an inline frame) have clipping.
2745 MOZ_ASSERT(!aClipAxes.isEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aClipAxes.isEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aClipAxes.isEmpty()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!aClipAxes.isEmpty()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 2745); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aClipAxes.isEmpty()"
")"); do { *((volatile int*)__null) = 2745; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2746 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"
, 2747); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay()) == aClipAxes"
")"); do { *((volatile int*)__null) = 2747; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2747 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"
, 2747); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay()) == aClipAxes"
")"); do { *((volatile int*)__null) = 2747; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2748
2749 nsRect clipRect;
2750 bool haveRadii = false;
2751 nscoord radii[8];
2752 auto* disp = aFrame->StyleDisplay();
2753 // Only deflate the padding if we clip to the content-box in that axis.
2754 auto wm = aFrame->GetWritingMode();
2755 bool cbH = (wm.IsVertical() ? disp->mOverflowClipBoxBlock
2756 : disp->mOverflowClipBoxInline) ==
2757 StyleOverflowClipBox::ContentBox;
2758 bool cbV = (wm.IsVertical() ? disp->mOverflowClipBoxInline
2759 : disp->mOverflowClipBoxBlock) ==
2760 StyleOverflowClipBox::ContentBox;
2761
2762 nsMargin boxMargin = -aFrame->GetUsedPadding();
2763 if (!cbH) {
2764 boxMargin.left = boxMargin.right = nscoord(0);
2765 }
2766 if (!cbV) {
2767 boxMargin.top = boxMargin.bottom = nscoord(0);
2768 }
2769
2770 auto clipMargin = aFrame->OverflowClipMargin(aClipAxes);
2771
2772 boxMargin -= aFrame->GetUsedBorder();
2773 boxMargin += nsMargin(clipMargin.height, clipMargin.width, clipMargin.height,
2774 clipMargin.width);
2775 boxMargin.ApplySkipSides(aFrame->GetSkipSides());
2776
2777 nsRect rect(nsPoint(0, 0), aFrame->GetSize());
2778 rect.Inflate(boxMargin);
2779 if (MOZ_UNLIKELY(!aClipAxes.contains(PhysicalAxis::Horizontal))(__builtin_expect(!!(!aClipAxes.contains(PhysicalAxis::Horizontal
)), 0))
) {
2780 // NOTE(mats) We shouldn't be clipping at all in this dimension really,
2781 // but clipping in just one axis isn't supported by our GFX APIs so we
2782 // clip to our visual overflow rect instead.
2783 nsRect o = aFrame->InkOverflowRect();
2784 rect.x = o.x;
2785 rect.width = o.width;
2786 }
2787 if (MOZ_UNLIKELY(!aClipAxes.contains(PhysicalAxis::Vertical))(__builtin_expect(!!(!aClipAxes.contains(PhysicalAxis::Vertical
)), 0))
) {
2788 // See the note above.
2789 nsRect o = aFrame->InkOverflowRect();
2790 rect.y = o.y;
2791 rect.height = o.height;
2792 }
2793 clipRect = rect + aBuilder->ToReferenceFrame(aFrame);
2794 haveRadii = aFrame->GetBoxBorderRadii(radii, boxMargin);
2795 aClipState.ClipContainingBlockDescendantsExtra(clipRect,
2796 haveRadii ? radii : nullptr);
2797}
2798
2799nsSize nsIFrame::OverflowClipMargin(PhysicalAxes aClipAxes) const {
2800 nsSize result;
2801 if (aClipAxes.isEmpty()) {
2802 return result;
2803 }
2804 const auto& margin = StyleMargin()->mOverflowClipMargin;
2805 if (margin.IsZero()) {
2806 return result;
2807 }
2808 nscoord marginAu = margin.ToAppUnits();
2809 if (aClipAxes.contains(PhysicalAxis::Horizontal)) {
2810 result.width = marginAu;
2811 }
2812 if (aClipAxes.contains(PhysicalAxis::Vertical)) {
2813 result.height = marginAu;
2814 }
2815 return result;
2816}
2817
2818/**
2819 * Returns whether a display item that gets created with the builder's current
2820 * state will have a scrolled clip, i.e. a clip that is scrolled by a scroll
2821 * frame which does not move the item itself.
2822 */
2823static bool BuilderHasScrolledClip(nsDisplayListBuilder* aBuilder) {
2824 const DisplayItemClipChain* currentClip =
2825 aBuilder->ClipState().GetCurrentCombinedClipChain(aBuilder);
2826 if (!currentClip) {
2827 return false;
2828 }
2829
2830 const ActiveScrolledRoot* currentClipASR = currentClip->mASR;
2831 const ActiveScrolledRoot* currentASR = aBuilder->CurrentActiveScrolledRoot();
2832 return ActiveScrolledRoot::PickDescendant(currentClipASR, currentASR) !=
2833 currentASR;
2834}
2835
2836class AutoSaveRestoreContainsBlendMode {
2837 nsDisplayListBuilder& mBuilder;
2838 bool mSavedContainsBlendMode;
2839
2840 public:
2841 explicit AutoSaveRestoreContainsBlendMode(nsDisplayListBuilder& aBuilder)
2842 : mBuilder(aBuilder),
2843 mSavedContainsBlendMode(aBuilder.ContainsBlendMode()) {}
2844
2845 ~AutoSaveRestoreContainsBlendMode() {
2846 mBuilder.SetContainsBlendMode(mSavedContainsBlendMode);
2847 }
2848};
2849
2850static bool IsFrameOrAncestorApzAware(nsIFrame* aFrame) {
2851 nsIContent* node = aFrame->GetContent();
2852 if (!node) {
2853 return false;
2854 }
2855
2856 do {
2857 if (node->IsNodeApzAware()) {
2858 return true;
2859 }
2860 nsIContent* shadowRoot = node->GetShadowRoot();
2861 if (shadowRoot && shadowRoot->IsNodeApzAware()) {
2862 return true;
2863 }
2864
2865 // Even if the node owning aFrame doesn't have apz-aware event listeners
2866 // itself, its shadow root or display: contents ancestors (which have no
2867 // frames) might, so we need to account for them too.
2868 } while ((node = node->GetFlattenedTreeParent()) && node->IsElement() &&
2869 node->AsElement()->IsDisplayContents());
2870
2871 return false;
2872}
2873
2874static void CheckForApzAwareEventHandlers(nsDisplayListBuilder* aBuilder,
2875 nsIFrame* aFrame) {
2876 if (aBuilder->GetAncestorHasApzAwareEventHandler()) {
2877 return;
2878 }
2879
2880 if (IsFrameOrAncestorApzAware(aFrame)) {
2881 aBuilder->SetAncestorHasApzAwareEventHandler(true);
2882 }
2883}
2884
2885static void UpdateCurrentHitTestInfo(nsDisplayListBuilder* aBuilder,
2886 nsIFrame* aFrame) {
2887 if (!aBuilder->BuildCompositorHitTestInfo()) {
2888 // Compositor hit test info is not used.
2889 return;
2890 }
2891
2892 CheckForApzAwareEventHandlers(aBuilder, aFrame);
2893
2894 const CompositorHitTestInfo info = aFrame->GetCompositorHitTestInfo(aBuilder);
2895 aBuilder->SetCompositorHitTestInfo(info);
2896}
2897
2898/**
2899 * True if aDescendant participates the context aAncestor participating.
2900 */
2901static bool FrameParticipatesIn3DContext(nsIFrame* aAncestor,
2902 nsIFrame* aDescendant) {
2903 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"
, 2903); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAncestor != aDescendant"
")"); do { *((volatile int*)__null) = 2903; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2904 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"
, 2904); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAncestor->GetContent() != aDescendant->GetContent()"
")"); do { *((volatile int*)__null) = 2904; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2905 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"
, 2905); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAncestor->Extend3DContext()"
")"); do { *((volatile int*)__null) = 2905; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2906
2907 nsIFrame* ancestor = aAncestor->FirstContinuation();
2908 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"
, 2908); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ancestor->IsPrimaryFrame()"
")"); do { *((volatile int*)__null) = 2908; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2909
2910 nsIFrame* frame;
2911 for (frame = aDescendant->GetClosestFlattenedTreeAncestorPrimaryFrame();
2912 frame && ancestor != frame;
2913 frame = frame->GetClosestFlattenedTreeAncestorPrimaryFrame()) {
2914 if (!frame->Extend3DContext()) {
2915 return false;
2916 }
2917 }
2918
2919 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"
, 2919); AnnotateMozCrashReason("MOZ_ASSERT" "(" "frame == ancestor"
")"); do { *((volatile int*)__null) = 2919; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2920 return true;
2921}
2922
2923static bool ItemParticipatesIn3DContext(nsIFrame* aAncestor,
2924 nsDisplayItem* aItem) {
2925 auto type = aItem->GetType();
2926 const bool isContainer = type == DisplayItemType::TYPE_WRAP_LIST ||
2927 type == DisplayItemType::TYPE_CONTAINER;
2928
2929 if (isContainer && aItem->GetChildren()->Length() == 1) {
2930 // If the wraplist has only one child item, use the type of that item.
2931 type = aItem->GetChildren()->GetBottom()->GetType();
2932 }
2933
2934 if (type != DisplayItemType::TYPE_TRANSFORM &&
2935 type != DisplayItemType::TYPE_PERSPECTIVE) {
2936 return false;
2937 }
2938 nsIFrame* transformFrame = aItem->Frame();
2939 if (aAncestor->GetContent() == transformFrame->GetContent()) {
2940 return true;
2941 }
2942 return FrameParticipatesIn3DContext(aAncestor, transformFrame);
2943}
2944
2945static void WrapSeparatorTransform(nsDisplayListBuilder* aBuilder,
2946 nsIFrame* aFrame,
2947 nsDisplayList* aNonParticipants,
2948 nsDisplayList* aParticipants, int aIndex,
2949 nsDisplayItem** aSeparator) {
2950 if (aNonParticipants->IsEmpty()) {
2951 return;
2952 }
2953
2954 nsDisplayTransform* item = MakeDisplayItemWithIndex<nsDisplayTransform>(
2955 aBuilder, aFrame, aIndex, aNonParticipants, aBuilder->GetVisibleRect());
2956
2957 if (*aSeparator == nullptr && item) {
2958 *aSeparator = item;
2959 }
2960
2961 aParticipants->AppendToTop(item);
2962}
2963
2964// Try to compute a clip rect to bound the contents of the mask item
2965// that will be built for |aMaskedFrame|. If we're not able to compute
2966// one, return an empty Maybe.
2967// The returned clip rect, if there is one, is relative to |aMaskedFrame|.
2968static Maybe<nsRect> ComputeClipForMaskItem(
2969 nsDisplayListBuilder* aBuilder, nsIFrame* aMaskedFrame,
2970 const SVGUtils::MaskUsage& aMaskUsage) {
2971 const nsStyleSVGReset* svgReset = aMaskedFrame->StyleSVGReset();
2972
2973 nsPoint offsetToUserSpace =
2974 nsLayoutUtils::ComputeOffsetToUserSpace(aBuilder, aMaskedFrame);
2975 int32_t devPixelRatio = aMaskedFrame->PresContext()->AppUnitsPerDevPixel();
2976 gfxPoint devPixelOffsetToUserSpace =
2977 nsLayoutUtils::PointToGfxPoint(offsetToUserSpace, devPixelRatio);
2978 CSSToLayoutDeviceScale cssToDevScale =
2979 aMaskedFrame->PresContext()->CSSToDevPixelScale();
2980
2981 nsPoint toReferenceFrame;
2982 aBuilder->FindReferenceFrameFor(aMaskedFrame, &toReferenceFrame);
2983
2984 Maybe<gfxRect> combinedClip;
2985 if (aMaskUsage.ShouldApplyBasicShapeOrPath()) {
2986 Maybe<Rect> result =
2987 CSSClipPathInstance::GetBoundingRectForBasicShapeOrPathClip(
2988 aMaskedFrame, svgReset->mClipPath);
2989 if (result) {
2990 combinedClip = Some(ThebesRect(*result));
2991 }
2992 } else if (aMaskUsage.ShouldApplyClipPath()) {
2993 gfxRect result = SVGUtils::GetBBox(
2994 aMaskedFrame,
2995 SVGUtils::eBBoxIncludeClipped | SVGUtils::eBBoxIncludeFill |
2996 SVGUtils::eBBoxIncludeMarkers | SVGUtils::eBBoxIncludeStroke |
2997 SVGUtils::eDoNotClipToBBoxOfContentInsideClipPath);
2998 combinedClip = Some(
2999 ThebesRect((CSSRect::FromUnknownRect(ToRect(result)) * cssToDevScale)
3000 .ToUnknownRect()));
3001 } else {
3002 // The code for this case is adapted from ComputeMaskGeometry().
3003
3004 nsRect borderArea(toReferenceFrame, aMaskedFrame->GetSize());
3005 borderArea -= offsetToUserSpace;
3006
3007 // Use an infinite dirty rect to pass into nsCSSRendering::
3008 // GetImageLayerClip() because we don't have an actual dirty rect to
3009 // pass in. This is fine because the only time GetImageLayerClip() will
3010 // not intersect the incoming dirty rect with something is in the "NoClip"
3011 // case, and we handle that specially.
3012 nsRect dirtyRect(nscoord_MIN / 2, nscoord_MIN / 2, nscoord_MAX,
3013 nscoord_MAX);
3014
3015 nsIFrame* firstFrame =
3016 nsLayoutUtils::FirstContinuationOrIBSplitSibling(aMaskedFrame);
3017 nsTArray<SVGMaskFrame*> maskFrames;
3018 // XXX check return value?
3019 SVGObserverUtils::GetAndObserveMasks(firstFrame, &maskFrames);
3020
3021 for (uint32_t i = 0; i < maskFrames.Length(); ++i) {
3022 gfxRect clipArea;
3023 if (maskFrames[i]) {
3024 clipArea = maskFrames[i]->GetMaskArea(aMaskedFrame);
3025 clipArea = ThebesRect(
3026 (CSSRect::FromUnknownRect(ToRect(clipArea)) * cssToDevScale)
3027 .ToUnknownRect());
3028 } else {
3029 const auto& layer = svgReset->mMask.mLayers[i];
3030 if (layer.mClip == StyleGeometryBox::NoClip) {
3031 return Nothing();
3032 }
3033
3034 nsCSSRendering::ImageLayerClipState clipState;
3035 nsCSSRendering::GetImageLayerClip(
3036 layer, aMaskedFrame, *aMaskedFrame->StyleBorder(), borderArea,
3037 dirtyRect, false /* aWillPaintBorder */, devPixelRatio, &clipState);
3038 clipArea = clipState.mDirtyRectInDevPx;
3039 }
3040 combinedClip = UnionMaybeRects(combinedClip, Some(clipArea));
3041 }
3042 }
3043 if (combinedClip) {
3044 if (combinedClip->IsEmpty()) {
3045 // *clipForMask might be empty if all mask references are not resolvable
3046 // or the size of them are empty. We still need to create a transparent
3047 // mask before bug 1276834 fixed, so don't clip ctx by an empty rectangle
3048 // for for now.
3049 return Nothing();
3050 }
3051
3052 // Convert to user space.
3053 *combinedClip += devPixelOffsetToUserSpace;
3054
3055 // Round the clip out. In FrameLayerBuilder we round clips to nearest
3056 // pixels, and if we have a really thin clip here, that can cause the
3057 // clip to become empty if we didn't round out here.
3058 // The rounding happens in coordinates that are relative to the reference
3059 // frame, which matches what FrameLayerBuilder does.
3060 combinedClip->RoundOut();
3061
3062 // Convert to app units.
3063 nsRect result =
3064 nsLayoutUtils::RoundGfxRectToAppRect(*combinedClip, devPixelRatio);
3065
3066 // The resulting clip is relative to the reference frame, but the caller
3067 // expects it to be relative to the masked frame, so adjust it.
3068 result -= toReferenceFrame;
3069 return Some(result);
3070 }
3071 return Nothing();
3072}
3073
3074struct AutoCheckBuilder {
3075 explicit AutoCheckBuilder(nsDisplayListBuilder* aBuilder)
3076 : mBuilder(aBuilder) {
3077 aBuilder->Check();
3078 }
3079
3080 ~AutoCheckBuilder() { mBuilder->Check(); }
3081
3082 nsDisplayListBuilder* mBuilder;
3083};
3084
3085/**
3086 * Tries to reuse a top-level stacking context item from the previous paint.
3087 * Returns true if an item was reused, otherwise false.
3088 */
3089bool TryToReuseStackingContextItem(nsDisplayListBuilder* aBuilder,
3090 nsDisplayList* aList, nsIFrame* aFrame) {
3091 if (!aBuilder->IsForPainting() || !aBuilder->IsPartialUpdate() ||
3092 aBuilder->InInvalidSubtree()) {
3093 return false;
3094 }
3095
3096 if (aFrame->IsFrameModified() || aFrame->HasModifiedDescendants()) {
3097 return false;
3098 }
3099
3100 auto& items = aFrame->DisplayItems();
3101 auto* res = std::find_if(
3102 items.begin(), items.end(),
3103 [](nsDisplayItem* aItem) { return aItem->IsPreProcessed(); });
3104
3105 if (res == items.end()) {
3106 return false;
3107 }
3108
3109 nsDisplayItem* container = *res;
3110 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"
, 3110); AnnotateMozCrashReason("MOZ_ASSERT" "(" "container->Frame() == aFrame"
")"); do { *((volatile int*)__null) = 3110; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3111 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)
3112 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)
;
3113
3114 aList->AppendToTop(container);
3115 aBuilder->ReuseDisplayItem(container);
3116 return true;
3117}
3118
3119void nsIFrame::BuildDisplayListForStackingContext(
3120 nsDisplayListBuilder* aBuilder, nsDisplayList* aList,
3121 bool* aCreatedContainerItem) {
3122#ifdef DEBUG1
3123 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)
;
3124 ScopeExit e(
3125 [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)
; });
3126#endif
3127
3128 AutoCheckBuilder check(aBuilder);
3129
3130 if (aBuilder->IsReusingStackingContextItems() &&
3131 TryToReuseStackingContextItem(aBuilder, aList, this)) {
3132 if (aCreatedContainerItem) {
3133 *aCreatedContainerItem = true;
3134 }
3135 return;
3136 }
3137
3138 if (HasAnyStateBits(NS_FRAME_TOO_DEEP_IN_FRAME_TREE)) {
3139 return;
3140 }
3141
3142 const auto& style = *Style();
3143 const nsStyleDisplay* disp = style.StyleDisplay();
3144 const nsStyleEffects* effects = style.StyleEffects();
3145 EffectSet* effectSetForOpacity =
3146 EffectSet::GetForFrame(this, nsCSSPropertyIDSet::OpacityProperties());
3147 // We can stop right away if this is a zero-opacity stacking context and
3148 // we're painting, and we're not animating opacity.
3149 bool needHitTestInfo = aBuilder->BuildCompositorHitTestInfo() &&
3150 Style()->PointerEvents() != StylePointerEvents::None;
3151 bool opacityItemForEventsOnly = false;
3152 if (effects->IsTransparent() && aBuilder->IsForPainting() &&
3153 !(disp->mWillChange.bits & StyleWillChangeBits::OPACITY) &&
3154 !nsLayoutUtils::HasAnimationOfPropertySet(
3155 this, nsCSSPropertyIDSet::OpacityProperties(), effectSetForOpacity)) {
3156 if (needHitTestInfo) {
3157 opacityItemForEventsOnly = true;
3158 } else {
3159 return;
3160 }
3161 }
3162
3163 if (aBuilder->IsForPainting() && disp->mWillChange.bits) {
3164 aBuilder->AddToWillChangeBudget(this, GetSize());
3165 }
3166
3167 // For preserves3d, use the dirty rect already installed on the
3168 // builder, since aDirtyRect maybe distorted for transforms along
3169 // the chain.
3170 nsRect visibleRect = aBuilder->GetVisibleRect();
3171 nsRect dirtyRect = aBuilder->GetDirtyRect();
3172
3173 // We build an opacity item if it's not going to be drawn by SVG content.
3174 // We could in principle skip creating an nsDisplayOpacity item if
3175 // nsDisplayOpacity::NeedsActiveLayer returns false and usingSVGEffects is
3176 // true (the nsDisplayFilter/nsDisplayMasksAndClipPaths could handle the
3177 // opacity). Since SVG has perf issues where we sometimes spend a lot of
3178 // time creating display list items that might be helpful. We'd need to
3179 // restore our mechanism to do that (changed in bug 1482403), and we'd
3180 // need to invalidate the frame if the value that would be return from
3181 // NeedsActiveLayer was to change, which we don't currently do.
3182 const bool useOpacity =
3183 HasVisualOpacity(disp, effects, effectSetForOpacity) &&
3184 !SVGUtils::CanOptimizeOpacity(this);
3185
3186 const bool isTransformed = IsTransformed();
3187 const bool hasPerspective = isTransformed && HasPerspective();
3188 const bool extend3DContext =
3189 Extend3DContext(disp, effects, effectSetForOpacity);
3190 const bool combines3DTransformWithAncestors =
3191 (extend3DContext || isTransformed) && Combines3DTransformWithAncestors();
3192
3193 Maybe<nsDisplayListBuilder::AutoPreserves3DContext> autoPreserves3DContext;
3194 if (extend3DContext && !combines3DTransformWithAncestors) {
3195 // Start a new preserves3d context to keep informations on
3196 // nsDisplayListBuilder.
3197 autoPreserves3DContext.emplace(aBuilder);
3198 // Save dirty rect on the builder to avoid being distorted for
3199 // multiple transforms along the chain.
3200 aBuilder->SavePreserves3DRect();
3201
3202 // We rebuild everything within preserve-3d and don't try
3203 // to retain, so override the dirty rect now.
3204 if (aBuilder->IsRetainingDisplayList()) {
3205 dirtyRect = visibleRect;
3206 aBuilder->SetDisablePartialUpdates(true);
3207 }
3208 }
3209
3210 const bool useBlendMode = effects->mMixBlendMode != StyleBlend::Normal;
3211 if (useBlendMode) {
3212 aBuilder->SetContainsBlendMode(true);
3213 }
3214
3215 // reset blend mode so we can keep track if this stacking context needs have
3216 // a nsDisplayBlendContainer. Set the blend mode back when the routine exits
3217 // so we keep track if the parent stacking context needs a container too.
3218 AutoSaveRestoreContainsBlendMode autoRestoreBlendMode(*aBuilder);
3219 aBuilder->SetContainsBlendMode(false);
3220
3221 // NOTE: When changing this condition make sure to tweak ScrollContainerFrame
3222 // as well.
3223 bool usingBackdropFilter = effects->HasBackdropFilters() &&
3224 IsVisibleForPainting() &&
3225 !style.IsRootElementStyle();
3226
3227 nsRect visibleRectOutsideTransform = visibleRect;
3228 nsDisplayTransform::PrerenderInfo prerenderInfo;
3229 bool inTransform = aBuilder->IsInTransform();
3230 if (isTransformed) {
3231 prerenderInfo = nsDisplayTransform::ShouldPrerenderTransformedContent(
3232 aBuilder, this, &visibleRect);
3233
3234 switch (prerenderInfo.mDecision) {
3235 case nsDisplayTransform::PrerenderDecision::Full:
3236 case nsDisplayTransform::PrerenderDecision::Partial:
3237 dirtyRect = visibleRect;
3238 break;
3239 case nsDisplayTransform::PrerenderDecision::No: {
3240 // If we didn't prerender an animated frame in a preserve-3d context,
3241 // then we want disable async animations for the rest of the preserve-3d
3242 // (especially ancestors).
3243 if ((extend3DContext || combines3DTransformWithAncestors) &&
3244 prerenderInfo.mHasAnimations) {
3245 aBuilder->SavePreserves3DAllowAsyncAnimation(false);
3246 }
3247
3248 const nsRect overflow = InkOverflowRectRelativeToSelf();
3249 if (overflow.IsEmpty() && !extend3DContext) {
3250 return;
3251 }
3252
3253 // If we're in preserve-3d then grab the dirty rect that was given to
3254 // the root and transform using the combined transform.
3255 if (combines3DTransformWithAncestors) {
3256 visibleRect = dirtyRect = aBuilder->GetPreserves3DRect();
3257 }
3258
3259 float appPerDev = PresContext()->AppUnitsPerDevPixel();
3260 auto transform = nsDisplayTransform::GetResultingTransformMatrix(
3261 this, nsPoint(), appPerDev,
3262 nsDisplayTransform::kTransformRectFlags);
3263 nsRect untransformedDirtyRect;
3264 if (nsDisplayTransform::UntransformRect(dirtyRect, overflow, transform,
3265 appPerDev,
3266 &untransformedDirtyRect)) {
3267 dirtyRect = untransformedDirtyRect;
3268 nsDisplayTransform::UntransformRect(visibleRect, overflow, transform,
3269 appPerDev, &visibleRect);
3270 } else {
3271 // This should only happen if the transform is singular, in which case
3272 // nothing is visible anyway
3273 dirtyRect.SetEmpty();
3274 visibleRect.SetEmpty();
3275 }
3276 }
3277 }
3278 inTransform = true;
3279 } else if (IsFixedPosContainingBlock()) {
3280 // Restict the building area to the overflow rect for these frames, since
3281 // RetainedDisplayListBuilder uses it to know if the size of the stacking
3282 // context changed.
3283 visibleRect.IntersectRect(visibleRect, InkOverflowRect());
3284 dirtyRect.IntersectRect(dirtyRect, InkOverflowRect());
3285 }
3286
3287 bool hasOverrideDirtyRect = false;
3288 // If we're doing a partial build, we're not invalid and we're capable
3289 // of having an override building rect (stacking context and fixed pos
3290 // containing block), then we should assume we have one.
3291 // Either we have an explicit one, or nothing in our subtree changed and
3292 // we have an implicit empty rect.
3293 //
3294 // These conditions should match |CanStoreDisplayListBuildingRect()| in
3295 // RetainedDisplayListBuilder.cpp
3296 if (!aBuilder->IsReusingStackingContextItems() &&
3297 aBuilder->IsPartialUpdate() && !aBuilder->InInvalidSubtree() &&
3298 !IsFrameModified() && IsFixedPosContainingBlock() &&
3299 !GetPrevContinuation() && !GetNextContinuation()) {
3300 dirtyRect = nsRect();
3301 if (HasOverrideDirtyRegion()) {
3302 nsDisplayListBuilder::DisplayListBuildingData* data =
3303 GetProperty(nsDisplayListBuilder::DisplayListBuildingRect());
3304 if (data) {
3305 dirtyRect = data->mDirtyRect.Intersect(visibleRect);
3306 hasOverrideDirtyRect = true;
3307 }
3308 }
3309 }
3310
3311 bool usingFilter = effects->HasFilters() && !style.IsRootElementStyle();
3312 SVGUtils::MaskUsage maskUsage = SVGUtils::DetermineMaskUsage(this, false);
3313 bool usingMask = maskUsage.UsingMaskOrClipPath();
3314 bool usingSVGEffects = usingFilter || usingMask;
3315
3316 nsRect visibleRectOutsideSVGEffects = visibleRect;
3317 nsDisplayList hoistedScrollInfoItemsStorage(aBuilder);
3318 if (usingSVGEffects) {
3319 dirtyRect =
3320 SVGIntegrationUtils::GetRequiredSourceForInvalidArea(this, dirtyRect);
3321 visibleRect =
3322 SVGIntegrationUtils::GetRequiredSourceForInvalidArea(this, visibleRect);
3323 aBuilder->EnterSVGEffectsContents(this, &hoistedScrollInfoItemsStorage);
3324 }
3325
3326 bool useStickyPosition = disp->mPosition == StylePositionProperty::Sticky;
3327
3328 bool useFixedPosition =
3329 disp->mPosition == StylePositionProperty::Fixed &&
3330 (DisplayPortUtils::IsFixedPosFrameInDisplayPort(this) ||
3331 BuilderHasScrolledClip(aBuilder));
3332
3333 nsDisplayListBuilder::AutoBuildingDisplayList buildingDisplayList(
3334 aBuilder, this, visibleRect, dirtyRect, isTransformed);
3335
3336 UpdateCurrentHitTestInfo(aBuilder, this);
3337
3338 // Depending on the effects that are applied to this frame, we can create
3339 // multiple container display items and wrap them around our contents.
3340 // This enum lists all the potential container display items, in the order
3341 // outside to inside.
3342 enum class ContainerItemType : uint8_t {
3343 None = 0,
3344 OwnLayerIfNeeded,
3345 BlendMode,
3346 FixedPosition,
3347 OwnLayerForTransformWithRoundedClip,
3348 Perspective,
3349 Transform,
3350 SeparatorTransforms,
3351 Opacity,
3352 Filter,
3353 BlendContainer
3354 };
3355
3356 nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
3357
3358 auto cssClip = GetClipPropClipRect(disp, effects, GetSize());
3359 auto ApplyClipProp = [&](DisplayListClipState::AutoSaveRestore& aClipState) {
3360 if (!cssClip) {
3361 return;
3362 }
3363 nsPoint offset = aBuilder->GetCurrentFrameOffsetToReferenceFrame();
3364 aBuilder->IntersectDirtyRect(*cssClip);
3365 aBuilder->IntersectVisibleRect(*cssClip);
3366 aClipState.ClipContentDescendants(*cssClip + offset);
3367 };
3368
3369 // The CSS clip property is effectively inside the transform, but outside the
3370 // filters. So if we're not transformed we can apply it just here for
3371 // simplicity, instead of on each of the places that handle clipCapturedBy.
3372 DisplayListClipState::AutoSaveRestore untransformedCssClip(aBuilder);
3373 if (!isTransformed) {
3374 ApplyClipProp(untransformedCssClip);
3375 }
3376
3377 // If there is a current clip, then depending on the container items we
3378 // create, different things can happen to it. Some container items simply
3379 // propagate the clip to their children and aren't clipped themselves.
3380 // But other container items, especially those that establish a different
3381 // geometry for their contents (e.g. transforms), capture the clip on
3382 // themselves and unset the clip for their contents. If we create more than
3383 // one of those container items, the clip will be captured on the outermost
3384 // one and the inner container items will be unclipped.
3385 ContainerItemType clipCapturedBy = ContainerItemType::None;
3386 if (useFixedPosition) {
3387 clipCapturedBy = ContainerItemType::FixedPosition;
3388 } else if (isTransformed) {
3389 const DisplayItemClipChain* currentClip =
3390 aBuilder->ClipState().GetCurrentCombinedClipChain(aBuilder);
3391 if ((hasPerspective || extend3DContext) &&
3392 (currentClip && currentClip->HasRoundedCorners())) {
3393 // If we're creating an nsDisplayTransform item that is going to combine
3394 // its transform with its children (preserve-3d or perspective), then we
3395 // can't have an intermediate surface. Mask layers force an intermediate
3396 // surface, so if we're going to need both then create a separate
3397 // wrapping layer for the mask.
3398 clipCapturedBy = ContainerItemType::OwnLayerForTransformWithRoundedClip;
3399 } else if (hasPerspective) {
3400 clipCapturedBy = ContainerItemType::Perspective;
3401 } else {
3402 clipCapturedBy = ContainerItemType::Transform;
3403 }
3404 } else if (usingFilter) {
3405 clipCapturedBy = ContainerItemType::Filter;
3406 }
3407
3408 DisplayListClipState::AutoSaveRestore clipState(aBuilder);
3409 if (clipCapturedBy != ContainerItemType::None) {
3410 clipState.Clear();
3411 }
3412
3413 DisplayListClipState::AutoSaveRestore transformedCssClip(aBuilder);
3414 if (isTransformed) {
3415 // FIXME(emilio, bug 1525159): In the case we have a both a transform _and_
3416 // filters, this clips the input to the filters as well, which is not
3417 // correct (clipping by the `clip` property is supposed to happen after
3418 // applying the filter effects, per [1].
3419 //
3420 // This is not a regression though, since we used to do that anyway before
3421 // bug 1514384, and even without the transform we get it wrong.
3422 //
3423 // [1]: https://drafts.fxtf.org/css-masking/#placement
3424 ApplyClipProp(transformedCssClip);
3425 }
3426
3427 uint32_t numActiveScrollframesEncounteredBefore =
3428 aBuilder->GetNumActiveScrollframesEncountered();
3429
3430 nsDisplayListCollection set(aBuilder);
3431 Maybe<nsRect> clipForMask;
3432 {
3433 DisplayListClipState::AutoSaveRestore nestedClipState(aBuilder);
3434 nsDisplayListBuilder::AutoInTransformSetter inTransformSetter(aBuilder,
3435 inTransform);
3436 nsDisplayListBuilder::AutoEnterFilter filterASRSetter(aBuilder,
3437 usingFilter);
3438 nsDisplayListBuilder::AutoInEventsOnly inEventsSetter(
3439 aBuilder, opacityItemForEventsOnly);
3440
3441 // If we have a mask, compute a clip to bound the masked content.
3442 // This is necessary in case the content moves with an ancestor
3443 // ASR of the mask.
3444 // Don't do this if we also have a filter, because then the clip
3445 // would be applied before the filter, violating
3446 // https://www.w3.org/TR/filter-effects-1/#placement.
3447 // Filters are a containing block for fixed and absolute descendants,
3448 // so the masked content cannot move with an ancestor ASR.
3449 if (usingMask && !usingFilter) {
3450 clipForMask = ComputeClipForMaskItem(aBuilder, this, maskUsage);
3451 if (clipForMask) {
3452 aBuilder->IntersectDirtyRect(*clipForMask);
3453 aBuilder->IntersectVisibleRect(*clipForMask);
3454 nestedClipState.ClipContentDescendants(
3455 *clipForMask + aBuilder->GetCurrentFrameOffsetToReferenceFrame());
3456 }
3457 }
3458
3459 // extend3DContext also guarantees that applyAbsPosClipping and
3460 // usingSVGEffects are false We only modify the preserve-3d rect if we are
3461 // the top of a preserve-3d heirarchy
3462 if (extend3DContext) {
3463 // Mark these first so MarkAbsoluteFramesForDisplayList knows if we are
3464 // going to be forced to descend into frames.
3465 aBuilder->MarkPreserve3DFramesForDisplayList(this);
3466 }
3467
3468 aBuilder->AdjustWindowDraggingRegion(this);
3469
3470 MarkAbsoluteFramesForDisplayList(aBuilder);
3471 aBuilder->Check();
3472 BuildDisplayList(aBuilder, set);
3473 SetBuiltDisplayList(true);
3474 aBuilder->Check();
3475 aBuilder->DisplayCaret(this, set.Outlines());
3476
3477 // Blend modes are a real pain for retained display lists. We build a blend
3478 // container item if the built list contains any blend mode items within
3479 // the current stacking context. This can change without an invalidation
3480 // to the stacking context frame, or the blend mode frame (e.g. by moving
3481 // an intermediate frame).
3482 // When we gain/remove a blend container item, we need to mark this frame
3483 // as invalid and have the full display list for merging to track
3484 // the change correctly.
3485 // It seems really hard to track this in advance, as the bookkeeping
3486 // required to note which stacking contexts have blend descendants
3487 // is complex and likely to be buggy.
3488 // Instead we're doing the sad thing, detecting it afterwards, and just
3489 // repeating display list building if it changed.
3490 // We have to repeat building for the entire display list (or at least
3491 // the outer stacking context), since we need to mark this frame as invalid
3492 // to remove any existing content that isn't wrapped in the blend container,
3493 // and then we need to build content infront/behind the blend container
3494 // to get correct positioning during merging.
3495 if (aBuilder->ContainsBlendMode() && aBuilder->IsRetainingDisplayList()) {
3496 if (aBuilder->IsPartialUpdate()) {
3497 aBuilder->SetPartialBuildFailed(true);
3498 } else {
3499 aBuilder->SetDisablePartialUpdates(true);
3500 }
3501 }
3502 }
3503
3504 if (aBuilder->IsBackgroundOnly()) {
3505 set.BlockBorderBackgrounds()->DeleteAll(aBuilder);
3506 set.Floats()->DeleteAll(aBuilder);
3507 set.Content()->DeleteAll(aBuilder);
3508 set.PositionedDescendants()->DeleteAll(aBuilder);
3509 set.Outlines()->DeleteAll(aBuilder);
3510 }
3511
3512 if (hasOverrideDirtyRect &&
3513 StaticPrefs::layout_display_list_show_rebuild_area()) {
3514 nsDisplaySolidColor* color = MakeDisplayItem<nsDisplaySolidColor>(
3515 aBuilder, this,
3516 dirtyRect + aBuilder->GetCurrentFrameOffsetToReferenceFrame(),
3517 NS_RGBA(255, 0, 0, 64)((nscolor)(((64) << 24) | ((0) << 16) | ((0) <<
8) | (255)))
, false);
3518 if (color) {
3519 color->SetOverrideZIndex(INT32_MAX(2147483647));
3520 set.PositionedDescendants()->AppendToTop(color);
3521 }
3522 }
3523
3524 nsIContent* content = GetContent();
3525 if (!content) {
3526 content = PresContext()->Document()->GetRootElement();
3527 }
3528
3529 nsDisplayList resultList(aBuilder);
3530 set.SerializeWithCorrectZOrder(&resultList, content);
3531
3532 // Get the ASR to use for the container items that we create here.
3533 const ActiveScrolledRoot* containerItemASR = contASRTracker.GetContainerASR();
3534
3535 bool createdContainer = false;
3536
3537 // If adding both a nsDisplayBlendContainer and a nsDisplayBlendMode to the
3538 // same list, the nsDisplayBlendContainer should be added first. This only
3539 // happens when the element creating this stacking context has mix-blend-mode
3540 // and also contains a child which has mix-blend-mode.
3541 // The nsDisplayBlendContainer must be added to the list first, so it does not
3542 // isolate the containing element blending as well.
3543 if (aBuilder->ContainsBlendMode()) {
3544 resultList.AppendToTop(nsDisplayBlendContainer::CreateForMixBlendMode(
3545 aBuilder, this, &resultList, containerItemASR));
3546 createdContainer = true;
3547 }
3548
3549 if (usingBackdropFilter) {
3550 nsRect backdropRect =
3551 GetRectRelativeToSelf() + aBuilder->ToReferenceFrame(this);
3552 resultList.AppendNewToTop<nsDisplayBackdropFilters>(
3553 aBuilder, this, &resultList, backdropRect, this);
3554 createdContainer = true;
3555 }
3556
3557 // If there are any SVG effects, wrap the list up in an SVG effects item
3558 // (which also handles CSS group opacity). Note that we create an SVG effects
3559 // item even if resultList is empty, since a filter can produce graphical
3560 // output even if the element being filtered wouldn't otherwise do so.
3561 if (usingSVGEffects) {
3562 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"
, 3563); AnnotateMozCrashReason("MOZ_ASSERT" "(" "usingFilter || usingMask"
") (" "Beside filter & mask/clip-path, what else effect do we have?"
")"); do { *((volatile int*)__null) = 3563; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
3563 "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"
, 3563); AnnotateMozCrashReason("MOZ_ASSERT" "(" "usingFilter || usingMask"
") (" "Beside filter & mask/clip-path, what else effect do we have?"
")"); do { *((volatile int*)__null) = 3563; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3564
3565 if (clipCapturedBy == ContainerItemType::Filter) {
3566 clipState.Restore();
3567 }
3568 // Revert to the post-filter dirty rect.
3569 aBuilder->SetVisibleRect(visibleRectOutsideSVGEffects);
3570
3571 // Skip all filter effects while generating glyph mask.
3572 if (usingFilter && !aBuilder->IsForGenerateGlyphMask()) {
3573 /* List now emptied, so add the new list to the top. */
3574 resultList.AppendNewToTop<nsDisplayFilters>(aBuilder, this, &resultList,
3575 this, usingBackdropFilter);
3576 createdContainer = true;
Value stored to 'createdContainer' is never read
3577 }
3578
3579 if (usingMask) {
3580 // The mask should move with aBuilder->CurrentActiveScrolledRoot(), so
3581 // that's the ASR we prefer to use for the mask item. However, we can
3582 // only do this if the mask if clipped with respect to that ASR, because
3583 // an item always needs to have finite bounds with respect to its ASR.
3584 // If we weren't able to compute a clip for the mask, we fall back to
3585 // using containerItemASR, which is the lowest common ancestor clip of
3586 // the mask's contents. That's not entirely correct, but it satisfies
3587 // the base requirement of the ASR system (that items have finite bounds
3588 // wrt. their ASR).
3589 const ActiveScrolledRoot* maskASR =
3590 clipForMask.isSome() ? aBuilder->CurrentActiveScrolledRoot()
3591 : containerItemASR;
3592 /* List now emptied, so add the new list to the top. */
3593 resultList.AppendNewToTop<nsDisplayMasksAndClipPaths>(
3594 aBuilder, this, &resultList, maskASR, usingBackdropFilter);
3595 createdContainer = true;
3596 }
3597
3598 // TODO(miko): We could probably create a wraplist here and avoid creating
3599 // it later in |BuildDisplayListForChild()|.
3600 createdContainer = false;
3601
3602 // Also add the hoisted scroll info items. We need those for APZ scrolling
3603 // because nsDisplayMasksAndClipPaths items can't build active layers.
3604 aBuilder->ExitSVGEffectsContents();
3605 resultList.AppendToTop(&hoistedScrollInfoItemsStorage);
3606 }
3607
3608 // If the list is non-empty and there is CSS group opacity without SVG
3609 // effects, wrap it up in an opacity item.
3610 if (useOpacity) {
3611 const bool needsActiveOpacityLayer =
3612 nsDisplayOpacity::NeedsActiveLayer(aBuilder, this);
3613 resultList.AppendNewToTop<nsDisplayOpacity>(
3614 aBuilder, this, &resultList, containerItemASR, opacityItemForEventsOnly,
3615 needsActiveOpacityLayer, usingBackdropFilter);
3616 createdContainer = true;
3617 }
3618
3619 // If we're going to apply a transformation and don't have preserve-3d set,
3620 // wrap everything in an nsDisplayTransform. If there's nothing in the list,
3621 // don't add anything.
3622 //
3623 // For the preserve-3d case we want to individually wrap every child in the
3624 // list with a separate nsDisplayTransform instead. When the child is already
3625 // an nsDisplayTransform, we can skip this step, as the computed transform
3626 // will already include our own.
3627 //
3628 // We also traverse into sublists created by nsDisplayWrapList, so that we
3629 // find all the correct children.
3630 if (isTransformed && extend3DContext) {
3631 // Install dummy nsDisplayTransform as a leaf containing
3632 // descendants not participating this 3D rendering context.
3633 nsDisplayList nonparticipants(aBuilder);
3634 nsDisplayList participants(aBuilder);
3635 int index = 1;
3636
3637 nsDisplayItem* separator = nullptr;
3638
3639 // TODO: This can be simplified: |participants| is just |resultList|.
3640 for (nsDisplayItem* item : resultList.TakeItems()) {
3641 if (ItemParticipatesIn3DContext(this, item) &&
3642 !item->GetClip().HasClip()) {
3643 // The frame of this item participates the same 3D context.
3644 WrapSeparatorTransform(aBuilder, this, &nonparticipants, &participants,
3645 index++, &separator);
3646
3647 participants.AppendToTop(item);
3648 } else {
3649 // The frame of the item doesn't participate the current
3650 // context, or has no transform.
3651 //
3652 // For items participating but not transformed, they are add
3653 // to nonparticipants to get a separator layer for handling
3654 // clips, if there is, on an intermediate surface.
3655 // \see ContainerLayer::DefaultComputeEffectiveTransforms().
3656 nonparticipants.AppendToTop(item);
3657 }
3658 }
3659 WrapSeparatorTransform(aBuilder, this, &nonparticipants, &participants,
3660 index++, &separator);
3661
3662 if (separator) {
3663 createdContainer = true;
3664 }
3665
3666 resultList.AppendToTop(&participants);
3667 }
3668
3669 if (isTransformed) {
3670 transformedCssClip.Restore();
3671 if (clipCapturedBy == ContainerItemType::Transform) {
3672 // Restore clip state now so nsDisplayTransform is clipped properly.
3673 clipState.Restore();
3674 }
3675 // Revert to the dirtyrect coming in from the parent, without our transform
3676 // taken into account.
3677 aBuilder->SetVisibleRect(visibleRectOutsideTransform);
3678
3679 if (this != aBuilder->RootReferenceFrame()) {
3680 // Revert to the outer reference frame and offset because all display
3681 // items we create from now on are outside the transform.
3682 nsPoint toOuterReferenceFrame;
3683 const nsIFrame* outerReferenceFrame =
3684 aBuilder->FindReferenceFrameFor(GetParent(), &toOuterReferenceFrame);
3685 toOuterReferenceFrame += GetPosition();
3686
3687 buildingDisplayList.SetReferenceFrameAndCurrentOffset(
3688 outerReferenceFrame, toOuterReferenceFrame);
3689 }
3690
3691 // We would like to block async animations for ancestors of ones not
3692 // prerendered in the preserve-3d tree. Now that we've finished processing
3693 // all descendants, update allowAsyncAnimation to take their prerender
3694 // state into account
3695 // FIXME: We don't block async animations for previous siblings because
3696 // their prerender decisions have been made. We may have to figure out a
3697 // better way to rollback their prerender decisions.
3698 // Alternatively we could not block animations for later siblings, and only
3699 // block them for ancestors of a blocked one.
3700 if ((extend3DContext || combines3DTransformWithAncestors) &&
3701 prerenderInfo.CanUseAsyncAnimations() &&
3702 !aBuilder->GetPreserves3DAllowAsyncAnimation()) {
3703 // aBuilder->GetPreserves3DAllowAsyncAnimation() means the inner or
3704 // previous silbing frames are allowed/disallowed for async animations.
3705 prerenderInfo.mDecision = nsDisplayTransform::PrerenderDecision::No;
3706 }
3707
3708 nsDisplayTransform* transformItem = MakeDisplayItem<nsDisplayTransform>(
3709 aBuilder, this, &resultList, visibleRect, prerenderInfo.mDecision,
3710 usingBackdropFilter);
3711 if (transformItem) {
3712 resultList.AppendToTop(transformItem);
3713 createdContainer = true;
3714
3715 if (numActiveScrollframesEncounteredBefore !=
3716 aBuilder->GetNumActiveScrollframesEncountered()) {
3717 transformItem->SetContainsASRs(true);
3718 }
3719
3720 if (hasPerspective) {
3721 transformItem->MarkWithAssociatedPerspective();
3722
3723 if (clipCapturedBy == ContainerItemType::Perspective) {
3724 clipState.Restore();
3725 }
3726 resultList.AppendNewToTop<nsDisplayPerspective>(aBuilder, this,
3727 &resultList);
3728 createdContainer = true;
3729 }
3730 }
3731 }
3732
3733 if (clipCapturedBy ==
3734 ContainerItemType::OwnLayerForTransformWithRoundedClip) {
3735 clipState.Restore();
3736 resultList.AppendNewToTopWithIndex<nsDisplayOwnLayer>(
3737 aBuilder, this,
3738 /* aIndex = */ nsDisplayOwnLayer::OwnLayerForTransformWithRoundedClip,
3739 &resultList, aBuilder->CurrentActiveScrolledRoot(),
3740 nsDisplayOwnLayerFlags::None, ScrollbarData{},
3741 /* aForceActive = */ false, false);
3742 createdContainer = true;
3743 }
3744
3745 // If we have sticky positioning, wrap it in a sticky position item.
3746 if (useFixedPosition) {
3747 if (clipCapturedBy == ContainerItemType::FixedPosition) {
3748 clipState.Restore();
3749 }
3750 // The ASR for the fixed item should be the ASR of our containing block,
3751 // which has been set as the builder's current ASR, unless this frame is
3752 // invisible and we hadn't saved display item data for it. In that case,
3753 // we need to take the containerItemASR since we might have fixed children.
3754 // For WebRender, we want to the know what |containerItemASR| is for the
3755 // case where the fixed-pos item is not a "real" fixed-pos item (e.g. it's
3756 // nested inside a scrolling transform), so we stash that on the display
3757 // item as well.
3758 const ActiveScrolledRoot* fixedASR = ActiveScrolledRoot::PickAncestor(
3759 containerItemASR, aBuilder->CurrentActiveScrolledRoot());
3760 resultList.AppendNewToTop<nsDisplayFixedPosition>(
3761 aBuilder, this, &resultList, fixedASR, containerItemASR);
3762 createdContainer = true;
3763 } else if (useStickyPosition) {
3764 // For position:sticky, the clip needs to be applied both to the sticky
3765 // container item and to the contents. The container item needs the clip
3766 // because a scrolled clip needs to move independently from the sticky
3767 // contents, and the contents need the clip so that they have finite
3768 // clipped bounds with respect to the container item's ASR. The latter is
3769 // a little tricky in the case where the sticky item has both fixed and
3770 // non-fixed descendants, because that means that the sticky container
3771 // item's ASR is the ASR of the fixed descendant.
3772 // For WebRender display list building, though, we still want to know the
3773 // the ASR that the sticky container item would normally have, so we stash
3774 // that on the display item as the "container ASR" (i.e. the normal ASR of
3775 // the container item, excluding the special behaviour induced by fixed
3776 // descendants).
3777 const ActiveScrolledRoot* stickyASR = ActiveScrolledRoot::PickAncestor(
3778 containerItemASR, aBuilder->CurrentActiveScrolledRoot());
3779
3780 auto* stickyItem = MakeDisplayItem<nsDisplayStickyPosition>(
3781 aBuilder, this, &resultList, stickyASR,
3782 aBuilder->CurrentActiveScrolledRoot(),
3783 clipState.IsClippedToDisplayPort());
3784
3785 bool shouldFlatten = true;
3786
3787 StickyScrollContainer* stickyScrollContainer =
3788 StickyScrollContainer::GetStickyScrollContainerForFrame(this);
3789 if (stickyScrollContainer && stickyScrollContainer->ScrollContainer()
3790 ->IsMaybeAsynchronouslyScrolled()) {
3791 shouldFlatten = false;
3792 }
3793
3794 stickyItem->SetShouldFlatten(shouldFlatten);
3795
3796 resultList.AppendToTop(stickyItem);
3797 createdContainer = true;
3798
3799 // If the sticky element is inside a filter, annotate the scroll frame that
3800 // scrolls the filter as having out-of-flow content inside a filter (this
3801 // inhibits paint skipping).
3802 if (aBuilder->GetFilterASR() && aBuilder->GetFilterASR() == stickyASR) {
3803 aBuilder->GetFilterASR()
3804 ->mScrollContainerFrame->SetHasOutOfFlowContentInsideFilter();
3805 }
3806 }
3807
3808 // If there's blending, wrap up the list in a blend-mode item. Note that
3809 // opacity can be applied before blending as the blend color is not affected
3810 // by foreground opacity (only background alpha).
3811 if (useBlendMode) {
3812 DisplayListClipState::AutoSaveRestore blendModeClipState(aBuilder);
3813 resultList.AppendNewToTop<nsDisplayBlendMode>(aBuilder, this, &resultList,
3814 effects->mMixBlendMode,
3815 containerItemASR, false);
3816 createdContainer = true;
3817 }
3818
3819 if (aBuilder->IsReusingStackingContextItems()) {
3820 if (resultList.IsEmpty()) {
3821 return;
3822 }
3823
3824 nsDisplayItem* container = resultList.GetBottom();
3825 if (resultList.Length() > 1 || container->Frame() != this) {
3826 container = MakeDisplayItem<nsDisplayContainer>(
3827 aBuilder, this, containerItemASR, &resultList);
3828 } else {
3829 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"
, 3829); AnnotateMozCrashReason("MOZ_ASSERT" "(" "resultList.Length() == 1"
")"); do { *((volatile int*)__null) = 3829; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3830 resultList.Clear();
3831 }
3832
3833 // Mark the outermost display item as reusable. These display items and
3834 // their chidren can be reused during the next paint if no ancestor or
3835 // descendant frames have been modified.
3836 if (!container->IsReusedItem()) {
3837 container->SetReusable();
3838 }
3839 aList->AppendToTop(container);
3840 createdContainer = true;
3841 } else {
3842 aList->AppendToTop(&resultList);
3843 }
3844
3845 if (aCreatedContainerItem) {
3846 *aCreatedContainerItem = createdContainer;
3847 }
3848}
3849
3850static nsDisplayItem* WrapInWrapList(nsDisplayListBuilder* aBuilder,
3851 nsIFrame* aFrame, nsDisplayList* aList,
3852 const ActiveScrolledRoot* aContainerASR,
3853 bool aBuiltContainerItem = false) {
3854 nsDisplayItem* item = aList->GetBottom();
3855 if (!item) {
3856 return nullptr;
3857 }
3858
3859 // We need a wrap list if there are multiple items, or if the single
3860 // item has a different frame. This can change in a partial build depending
3861 // on which items we build, so we need to ensure that we don't transition
3862 // to/from a wrap list without invalidating correctly.
3863 bool needsWrapList =
3864 aList->Length() > 1 || item->Frame() != aFrame || item->GetChildren();
3865
3866 // If we have an explicit container item (that can't change without an
3867 // invalidation) or we're doing a full build and don't need a wrap list, then
3868 // we can skip adding one.
3869 if (aBuiltContainerItem || (!aBuilder->IsPartialUpdate() && !needsWrapList)) {
3870 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"
, 3870); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aList->Length() == 1"
")"); do { *((volatile int*)__null) = 3870; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3871 aList->Clear();
3872 return item;
3873 }
3874
3875 // If we're doing a partial build and we didn't need a wrap list
3876 // previously then we can try to work from there.
3877 if (aBuilder->IsPartialUpdate() &&
3878 !aFrame->HasDisplayItem(uint32_t(DisplayItemType::TYPE_CONTAINER))) {
3879 // If we now need a wrap list, we must previously have had no display items
3880 // or a single one belonging to this frame. Mark the item itself as
3881 // discarded so that RetainedDisplayListBuilder uses the ones we just built.
3882 // We don't want to mark the frame as modified as that would invalidate
3883 // positioned descendants that might be outside of this list, and might not
3884 // have been rebuilt this time.
3885 if (needsWrapList) {
3886 DiscardOldItems(aFrame);
3887 } else {
3888 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"
, 3888); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aList->Length() == 1"
")"); do { *((volatile int*)__null) = 3888; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3889 aList->Clear();
3890 return item;
3891 }
3892 }
3893
3894 // The last case we could try to handle is when we previously had a wrap list,
3895 // but no longer need it. Unfortunately we can't differentiate this case from
3896 // a partial build where other children exist but we just didn't build them
3897 // this time.
3898 // TODO:RetainedDisplayListBuilder's merge phase has the full list and
3899 // could strip them out.
3900
3901 return MakeDisplayItem<nsDisplayContainer>(aBuilder, aFrame, aContainerASR,
3902 aList);
3903}
3904
3905/**
3906 * Check if a frame should be visited for building display list.
3907 */
3908static bool DescendIntoChild(nsDisplayListBuilder* aBuilder,
3909 const nsIFrame* aChild, const nsRect& aVisible,
3910 const nsRect& aDirty) {
3911 if (aChild->HasAnyStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO)) {
3912 return true;
3913 }
3914
3915 // If the child is a scrollframe that we want to ignore, then we need
3916 // to descend into it because its scrolled child may intersect the dirty
3917 // area even if the scrollframe itself doesn't.
3918 if (aChild == aBuilder->GetIgnoreScrollFrame()) {
3919 return true;
3920 }
3921
3922 // There are cases where the "ignore scroll frame" on the builder is not set
3923 // correctly, and so we additionally want to catch cases where the child is
3924 // a root scrollframe and we are ignoring scrolling on the viewport.
3925 if (aChild == aBuilder->GetPresShellIgnoreScrollFrame()) {
3926 return true;
3927 }
3928
3929 nsRect overflow = aChild->InkOverflowRect();
3930
3931 // On mobile, there may be a dynamic toolbar. The root content document's
3932 // root scroll frame's ink overflow rect does not include the toolbar
3933 // height, but if the toolbar is hidden, we still want to be able to target
3934 // content underneath the toolbar, so expand the overflow rect here to
3935 // allow display list building to descend into the scroll frame.
3936 if (aBuilder->IsForEventDelivery() &&
3937 aChild == aChild->PresShell()->GetRootScrollContainerFrame() &&
3938 aChild->PresContext()->IsRootContentDocumentCrossProcess() &&
3939 aChild->PresContext()->HasDynamicToolbar()) {
3940 overflow.SizeTo(nsLayoutUtils::ExpandHeightForDynamicToolbar(
3941 aChild->PresContext(), overflow.Size()));
3942 }
3943
3944 if (aDirty.Intersects(overflow)) {
3945 return true;
3946 }
3947
3948 if (aChild->ForceDescendIntoIfVisible() && aVisible.Intersects(overflow)) {
3949 return true;
3950 }
3951
3952 if (aChild->IsTablePart()) {
3953 // Relative positioning and transforms can cause table parts to move, but we
3954 // will still paint the backgrounds for their ancestor parts under them at
3955 // their 'normal' position. That means that we must consider the overflow
3956 // rects at both positions.
3957
3958 // We convert the overflow rect into the nsTableFrame's coordinate
3959 // space, applying the normal position offset at each step. Then we
3960 // compare that against the builder's cached dirty rect in table
3961 // coordinate space.
3962 const nsIFrame* f = aChild;
3963 nsRect normalPositionOverflowRelativeToTable = overflow;
3964
3965 while (f->IsTablePart()) {
3966 normalPositionOverflowRelativeToTable += f->GetNormalPosition();
3967 f = f->GetParent();
3968 }
3969
3970 nsDisplayTableBackgroundSet* tableBGs = aBuilder->GetTableBackgroundSet();
3971 if (tableBGs && tableBGs->GetDirtyRect().Intersects(
3972 normalPositionOverflowRelativeToTable)) {
3973 return true;
3974 }
3975 }
3976
3977 return false;
3978}
3979
3980void nsIFrame::BuildDisplayListForSimpleChild(nsDisplayListBuilder* aBuilder,
3981 nsIFrame* aChild,
3982 const nsDisplayListSet& aLists) {
3983 // This is the shortcut for frames been handled along the common
3984 // path, the most common one of THE COMMON CASE mentioned later.
3985 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"
, 3985); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aChild->Type() != LayoutFrameType::Placeholder"
")"); do { *((volatile int*)__null) = 3985; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3986 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"
, 3988); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
") (" "It should be held for painting to window" ")"); do { *
((volatile int*)__null) = 3988; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
3987 !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"
, 3988); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
") (" "It should be held for painting to window" ")"); do { *
((volatile int*)__null) = 3988; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
3988 "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"
, 3988); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
") (" "It should be held for painting to window" ")"); do { *
((volatile int*)__null) = 3988; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
3989 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"
, 3989); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aChild->HasAnyStateBits(NS_FRAME_SIMPLE_DISPLAYLIST)"
")"); do { *((volatile int*)__null) = 3989; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3990
3991 const nsPoint offset = aChild->GetOffsetTo(this);
3992 const nsRect visible = aBuilder->GetVisibleRect() - offset;
3993 const nsRect dirty = aBuilder->GetDirtyRect() - offset;
3994
3995 if (!DescendIntoChild(aBuilder, aChild, visible, dirty)) {
3996 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)
;
3997 return;
3998 }
3999
4000 // Child cannot be transformed since it is not a stacking context.
4001 nsDisplayListBuilder::AutoBuildingDisplayList buildingForChild(
4002 aBuilder, aChild, visible, dirty, false);
4003
4004 UpdateCurrentHitTestInfo(aBuilder, aChild);
4005
4006 aChild->MarkAbsoluteFramesForDisplayList(aBuilder);
4007 aBuilder->AdjustWindowDraggingRegion(aChild);
4008 aBuilder->Check();
4009 aChild->BuildDisplayList(aBuilder, aLists);
4010 aChild->SetBuiltDisplayList(true);
4011 aBuilder->Check();
4012 aBuilder->DisplayCaret(aChild, aLists.Outlines());
4013}
4014
4015static bool ShouldSkipFrame(nsDisplayListBuilder* aBuilder,
4016 const nsIFrame* aFrame) {
4017 // If painting is restricted to just the background of the top level frame,
4018 // then we have nothing to do here.
4019 if (aBuilder->IsBackgroundOnly()) {
4020 return true;
4021 }
4022 if (aBuilder->IsForGenerateGlyphMask() &&
4023 (!aFrame->IsTextFrame() && aFrame->IsLeaf())) {
4024 return true;
4025 }
4026 // The placeholder frame should have the same content as the OOF frame.
4027 if (aBuilder->GetSelectedFramesOnly() &&
4028 (aFrame->IsLeaf() && !aFrame->IsSelected())) {
4029 return true;
4030 }
4031 static const nsFrameState skipFlags =
4032 (NS_FRAME_TOO_DEEP_IN_FRAME_TREE | NS_FRAME_IS_NONDISPLAY);
4033 if (aFrame->HasAnyStateBits(skipFlags)) {
4034 return true;
4035 }
4036 return aFrame->StyleUIReset()->mMozSubtreeHiddenOnlyVisually;
4037}
4038
4039void nsIFrame::BuildDisplayListForChild(nsDisplayListBuilder* aBuilder,
4040 nsIFrame* aChild,
4041 const nsDisplayListSet& aLists,
4042 DisplayChildFlags aFlags) {
4043 AutoCheckBuilder check(aBuilder);
4044#ifdef DEBUG1
4045 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)
;
4046 ScopeExit e(
4047 [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)
; });
4048#endif
4049
4050 if (ShouldSkipFrame(aBuilder, aChild)) {
4051 return;
4052 }
4053
4054 if (HidesContent()) {
4055 return;
4056 }
4057
4058 nsIFrame* child = aChild;
4059 auto* placeholder = child->IsPlaceholderFrame()
4060 ? static_cast<nsPlaceholderFrame*>(child)
4061 : nullptr;
4062 nsIFrame* childOrOutOfFlow =
4063 placeholder ? placeholder->GetOutOfFlowFrame() : child;
4064
4065 // If we're generating a display list for printing, include Link items for
4066 // frames that correspond to HTML link elements so that we can have active
4067 // links in saved PDF output. Note that the state of "within a link" is
4068 // set on the display-list builder, such that all descendants of the link
4069 // element will generate display-list links.
4070 // TODO: we should be able to optimize this so as to avoid creating links
4071 // for the same destination that entirely overlap each other, which adds
4072 // nothing useful to the final PDF.
4073 Maybe<nsDisplayListBuilder::Linkifier> linkifier;
4074 if (StaticPrefs::print_save_as_pdf_links_enabled() &&
4075 aBuilder->IsForPrinting()) {
4076 linkifier.emplace(aBuilder, childOrOutOfFlow, aLists.Content());
4077 linkifier->MaybeAppendLink(aBuilder, childOrOutOfFlow);
4078 }
4079
4080 nsIFrame* parent = childOrOutOfFlow->GetParent();
4081 const auto* parentDisplay = parent->StyleDisplay();
4082 const auto overflowClipAxes =
4083 parent->ShouldApplyOverflowClipping(parentDisplay);
4084
4085 const bool isPaintingToWindow = aBuilder->IsPaintingToWindow();
4086 const bool doingShortcut =
4087 isPaintingToWindow &&
4088 child->HasAnyStateBits(NS_FRAME_SIMPLE_DISPLAYLIST) &&
4089 // Animations may change the stacking context state.
4090 // ShouldApplyOverflowClipping is affected by the parent style, which does
4091 // not invalidate the NS_FRAME_SIMPLE_DISPLAYLIST bit.
4092 !(!overflowClipAxes.isEmpty() || child->MayHaveTransformAnimation() ||
4093 child->MayHaveOpacityAnimation());
4094
4095 if (aBuilder->IsForPainting()) {
4096 aBuilder->ClearWillChangeBudgetStatus(child);
4097 }
4098
4099 if (StaticPrefs::layout_css_scroll_anchoring_highlight()) {
4100 if (child->FirstContinuation()->IsScrollAnchor()) {
4101 nsRect bounds = child->GetContentRectRelativeToSelf() +
4102 aBuilder->ToReferenceFrame(child);
4103 nsDisplaySolidColor* color = MakeDisplayItem<nsDisplaySolidColor>(
4104 aBuilder, child, bounds, NS_RGBA(255, 0, 255, 64)((nscolor)(((64) << 24) | ((255) << 16) | ((0) <<
8) | (255)))
);
4105 if (color) {
4106 color->SetOverrideZIndex(INT32_MAX(2147483647));
4107 aLists.PositionedDescendants()->AppendToTop(color);
4108 }
4109 }
4110 }
4111
4112 if (doingShortcut) {
4113 BuildDisplayListForSimpleChild(aBuilder, child, aLists);
4114 return;
4115 }
4116
4117 // dirty rect in child-relative coordinates
4118 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"
, 4118); MOZ_PretendNoReturn(); } } while (0)
;
4119 const nsPoint offset = child->GetOffsetTo(this);
4120 nsRect visible = aBuilder->GetVisibleRect() - offset;
4121 nsRect dirty = aBuilder->GetDirtyRect() - offset;
4122
4123 nsDisplayListBuilder::OutOfFlowDisplayData* savedOutOfFlowData = nullptr;
4124 if (placeholder) {
4125 if (placeholder->HasAnyStateBits(PLACEHOLDER_FOR_TOPLAYER)) {
4126 // If the out-of-flow frame is in the top layer, the viewport frame
4127 // will paint it. Skip it here. Note that, only out-of-flow frames
4128 // with this property should be skipped, because non-HTML elements
4129 // may stop their children from being out-of-flow. Those frames
4130 // should still be handled in the normal in-flow path.
4131 return;
4132 }
4133
4134 child = childOrOutOfFlow;
4135 if (aBuilder->IsForPainting()) {
4136 aBuilder->ClearWillChangeBudgetStatus(child);
4137 }
4138
4139 // If 'child' is a pushed float then it's owned by a block that's not an
4140 // ancestor of the placeholder, and it will be painted by that block and
4141 // should not be painted through the placeholder. Also recheck
4142 // NS_FRAME_TOO_DEEP_IN_FRAME_TREE and NS_FRAME_IS_NONDISPLAY.
4143 static const nsFrameState skipFlags =
4144 (NS_FRAME_IS_PUSHED_FLOAT | NS_FRAME_TOO_DEEP_IN_FRAME_TREE |
4145 NS_FRAME_IS_NONDISPLAY);
4146 if (child->HasAnyStateBits(skipFlags) || nsLayoutUtils::IsPopup(child)) {
4147 return;
4148 }
4149
4150 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"
, 4150); AnnotateMozCrashReason("MOZ_ASSERT" "(" "child->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)"
")"); do { *((volatile int*)__null) = 4150; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4151 savedOutOfFlowData = nsDisplayListBuilder::GetOutOfFlowData(child);
4152
4153 if (aBuilder->GetIncludeAllOutOfFlows()) {
4154 visible = child->InkOverflowRect();
4155 dirty = child->InkOverflowRect();
4156 } else if (savedOutOfFlowData) {
4157 visible =
4158 savedOutOfFlowData->GetVisibleRectForFrame(aBuilder, child, &dirty);
4159 } else {
4160 // The out-of-flow frame did not intersect the dirty area. We may still
4161 // need to traverse into it, since it may contain placeholders we need
4162 // to enter to reach other out-of-flow frames that are visible.
4163 visible.SetEmpty();
4164 dirty.SetEmpty();
4165 }
4166 }
4167
4168 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"
, 4169); MOZ_PretendNoReturn(); } } while (0)
4169 "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"
, 4169); MOZ_PretendNoReturn(); } } while (0)
;
4170
4171 if (!DescendIntoChild(aBuilder, child, visible, dirty)) {
4172 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
)
;
4173 return;
4174 }
4175
4176 const bool isSVG = child->HasAnyStateBits(NS_FRAME_SVG_LAYOUT);
4177
4178 // This flag is raised if the control flow strays off the common path.
4179 // The common path is the most common one of THE COMMON CASE mentioned later.
4180 bool awayFromCommonPath = !isPaintingToWindow;
4181
4182 // true if this is a real or pseudo stacking context
4183 bool pseudoStackingContext =
4184 aFlags.contains(DisplayChildFlag::ForcePseudoStackingContext);
4185
4186 if (!pseudoStackingContext && !isSVG &&
4187 aFlags.contains(DisplayChildFlag::Inline) &&
4188 !child->IsLineParticipant()) {
4189 // child is a non-inline frame in an inline context, i.e.,
4190 // it acts like inline-block or inline-table. Therefore it is a
4191 // pseudo-stacking-context.
4192 pseudoStackingContext = true;
4193 }
4194
4195 const nsStyleDisplay* ourDisp = StyleDisplay();
4196 // Don't paint our children if the theme object is a leaf.
4197 if (IsThemed(ourDisp) && !PresContext()->Theme()->WidgetIsContainer(
4198 ourDisp->EffectiveAppearance())) {
4199 return;
4200 }
4201
4202 // Since we're now sure that we're adding this frame to the display list
4203 // (which means we're painting it, modulo occlusion), mark it as visible
4204 // within the displayport.
4205 if (isPaintingToWindow && child->TrackingVisibility() &&
4206 child->IsVisibleForPainting()) {
4207 child->PresShell()->EnsureFrameInApproximatelyVisibleList(child);
4208 awayFromCommonPath = true;
4209 }
4210
4211 // Child is composited if it's transformed, partially transparent, or has
4212 // SVG effects or a blend mode..
4213 const nsStyleDisplay* disp = child->StyleDisplay();
4214 const nsStyleEffects* effects = child->StyleEffects();
4215
4216 const bool isPositioned = disp->IsPositionedStyle();
4217 const bool isStackingContext =
4218 aFlags.contains(DisplayChildFlag::ForceStackingContext) ||
4219 child->IsStackingContext(disp, effects);
4220
4221 if (pseudoStackingContext || isStackingContext || isPositioned ||
4222 placeholder || (!isSVG && disp->IsFloating(child)) ||
4223 (isSVG && effects->mClip.IsRect() && IsSVGContentWithCSSClip(child))) {
4224 pseudoStackingContext = true;
4225 awayFromCommonPath = true;
4226 }
4227
4228 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"
, 4229); MOZ_PretendNoReturn(); } } while (0)
4229 "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"
, 4229); MOZ_PretendNoReturn(); } } while (0)
;
4230
4231 nsDisplayListBuilder::AutoBuildingDisplayList buildingForChild(
4232 aBuilder, child, visible, dirty);
4233
4234 UpdateCurrentHitTestInfo(aBuilder, child);
4235
4236 DisplayListClipState::AutoClipMultiple clipState(aBuilder);
4237 nsDisplayListBuilder::AutoCurrentActiveScrolledRootSetter asrSetter(aBuilder);
4238
4239 if (savedOutOfFlowData) {
4240 aBuilder->SetBuildingInvisibleItems(false);
4241
4242 clipState.SetClipChainForContainingBlockDescendants(
4243 savedOutOfFlowData->mContainingBlockClipChain);
4244 asrSetter.SetCurrentActiveScrolledRoot(
4245 savedOutOfFlowData->mContainingBlockActiveScrolledRoot);
4246 asrSetter.SetCurrentScrollParentId(savedOutOfFlowData->mScrollParentId);
4247 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"
, 4248); AnnotateMozCrashReason("MOZ_ASSERT" "(" "awayFromCommonPath"
") (" "It is impossible when savedOutOfFlowData is true" ")"
); do { *((volatile int*)__null) = 4248; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4248 "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"
, 4248); AnnotateMozCrashReason("MOZ_ASSERT" "(" "awayFromCommonPath"
") (" "It is impossible when savedOutOfFlowData is true" ")"
); do { *((volatile int*)__null) = 4248; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4249 } else if (HasAnyStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO) &&
4250 placeholder) {
4251 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"
, 4251); MOZ_PretendNoReturn(); } } while (0)
;
4252 // Every item we build from now until we descent into an out of flow that
4253 // does have saved out of flow data should be invisible. This state gets
4254 // restored when AutoBuildingDisplayList gets out of scope.
4255 aBuilder->SetBuildingInvisibleItems(true);
4256
4257 // If we have nested out-of-flow frames and the outer one isn't visible
4258 // then we won't have stored clip data for it. We can just clear the clip
4259 // instead since we know we won't render anything, and the inner out-of-flow
4260 // frame will setup the correct clip for itself.
4261 clipState.SetClipChainForContainingBlockDescendants(nullptr);
4262 }
4263
4264 // Setup clipping for the parent's overflow:clip,
4265 // or overflow:hidden on elements that don't support scrolling (and therefore
4266 // don't create nsHTML/XULScrollFrame). This clipping needs to not clip
4267 // anything directly rendered by the parent, only the rendering of its
4268 // children.
4269 // Don't use overflowClip to restrict the dirty rect, since some of the
4270 // descendants may not be clipped by it. Even if we end up with unnecessary
4271 // display items, they'll be pruned during ComputeVisibility.
4272 //
4273 // FIXME(emilio): Why can't we handle this more similarly to `clip` (on the
4274 // parent, rather than on the children)? Would ClipContentDescendants do what
4275 // we want?
4276 if (!overflowClipAxes.isEmpty()) {
4277 ApplyOverflowClipping(aBuilder, parent, overflowClipAxes, clipState);
4278 awayFromCommonPath = true;
4279 }
4280
4281 nsDisplayList list(aBuilder);
4282 nsDisplayList extraPositionedDescendants(aBuilder);
4283 const ActiveScrolledRoot* wrapListASR;
4284 bool builtContainerItem = false;
4285 if (isStackingContext) {
4286 // True stacking context.
4287 // For stacking contexts, BuildDisplayListForStackingContext handles
4288 // clipping and MarkAbsoluteFramesForDisplayList.
4289 nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
4290 child->BuildDisplayListForStackingContext(aBuilder, &list,
4291 &builtContainerItem);
4292 wrapListASR = contASRTracker.GetContainerASR();
4293 if (!aBuilder->IsReusingStackingContextItems() &&
4294 aBuilder->GetCaretFrame() == child) {
4295 builtContainerItem = false;
4296 }
4297 } else {
4298 Maybe<nsRect> clipPropClip =
4299 child->GetClipPropClipRect(disp, effects, child->GetSize());
4300 if (clipPropClip) {
4301 aBuilder->IntersectVisibleRect(*clipPropClip);
4302 aBuilder->IntersectDirtyRect(*clipPropClip);
4303 clipState.ClipContentDescendants(*clipPropClip +
4304 aBuilder->ToReferenceFrame(child));
4305 awayFromCommonPath = true;
4306 }
4307
4308 child->MarkAbsoluteFramesForDisplayList(aBuilder);
4309 child->SetBuiltDisplayList(true);
4310
4311 // Some SVG frames might change opacity without invalidating the frame, so
4312 // exclude them from the fast-path.
4313 if (!awayFromCommonPath && !child->IsSVGFrame()) {
4314 // The shortcut is available for the child for next time.
4315 child->AddStateBits(NS_FRAME_SIMPLE_DISPLAYLIST);
4316 }
4317
4318 if (!pseudoStackingContext) {
4319 // THIS IS THE COMMON CASE.
4320 // Not a pseudo or real stacking context. Do the simple thing and
4321 // return early.
4322 aBuilder->AdjustWindowDraggingRegion(child);
4323 aBuilder->Check();
4324 child->BuildDisplayList(aBuilder, aLists);
4325 aBuilder->Check();
4326 aBuilder->DisplayCaret(child, aLists.Outlines());
4327 return;
4328 }
4329
4330 // A pseudo-stacking context (e.g., a positioned element with z-index auto).
4331 // We allow positioned descendants of the child to escape to our parent
4332 // stacking context's positioned descendant list, because they might be
4333 // z-index:non-auto
4334 nsDisplayListCollection pseudoStack(aBuilder);
4335
4336 aBuilder->AdjustWindowDraggingRegion(child);
4337 nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
4338 aBuilder->Check();
4339 child->BuildDisplayList(aBuilder, pseudoStack);
4340 aBuilder->Check();
4341 if (aBuilder->DisplayCaret(child, pseudoStack.Outlines())) {
4342 builtContainerItem = false;
4343 }
4344 wrapListASR = contASRTracker.GetContainerASR();
4345
4346 list.AppendToTop(pseudoStack.BorderBackground());
4347 list.AppendToTop(pseudoStack.BlockBorderBackgrounds());
4348 list.AppendToTop(pseudoStack.Floats());
4349 list.AppendToTop(pseudoStack.Content());
4350 list.AppendToTop(pseudoStack.Outlines());
4351 extraPositionedDescendants.AppendToTop(pseudoStack.PositionedDescendants());
4352 }
4353
4354 buildingForChild.RestoreBuildingInvisibleItemsValue();
4355
4356 if (!list.IsEmpty()) {
4357 if (isPositioned || isStackingContext) {
4358 // Genuine stacking contexts, and positioned pseudo-stacking-contexts,
4359 // go in this level.
4360 nsDisplayItem* item = WrapInWrapList(aBuilder, child, &list, wrapListASR,
4361 builtContainerItem);
4362 if (isSVG) {
4363 aLists.Content()->AppendToTop(item);
4364 } else {
4365 aLists.PositionedDescendants()->AppendToTop(item);
4366 }
4367 } else if (!isSVG && disp->IsFloating(child)) {
4368 aLists.Floats()->AppendToTop(
4369 WrapInWrapList(aBuilder, child, &list, wrapListASR));
4370 } else {
4371 aLists.Content()->AppendToTop(&list);
4372 }
4373 }
4374 // We delay placing the positioned descendants of positioned frames to here,
4375 // because in the absence of z-index this is the correct order for them.
4376 // This doesn't affect correctness because the positioned descendants list
4377 // is sorted by z-order and content in BuildDisplayListForStackingContext,
4378 // but it means that sort routine needs to do less work.
4379 aLists.PositionedDescendants()->AppendToTop(&extraPositionedDescendants);
4380}
4381
4382void nsIFrame::MarkAbsoluteFramesForDisplayList(
4383 nsDisplayListBuilder* aBuilder) {
4384 if (IsAbsoluteContainer()) {
4385 aBuilder->MarkFramesForDisplayList(
4386 this, GetAbsoluteContainingBlock()->GetChildList());
4387 }
4388}
4389
4390nsresult nsIFrame::GetContentForEvent(const WidgetEvent* aEvent,
4391 nsIContent** aContent) {
4392 nsIFrame* f = nsLayoutUtils::GetNonGeneratedAncestor(this);
4393 *aContent = f->GetContent();
4394 NS_IF_ADDREF(*aContent)ns_if_addref(*aContent);
4395 return NS_OK;
4396}
4397
4398void nsIFrame::FireDOMEvent(const nsAString& aDOMEventName,
4399 nsIContent* aContent) {
4400 nsIContent* target = aContent ? aContent : GetContent();
4401
4402 if (target) {
4403 RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
4404 target, aDOMEventName, CanBubble::eYes, ChromeOnlyDispatch::eNo);
4405 DebugOnly<nsresult> rv = asyncDispatcher->PostDOMEvent();
4406 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"
, 4406); MOZ_PretendNoReturn(); } } while (0)
;
4407 }
4408}
4409
4410nsresult nsIFrame::HandleEvent(nsPresContext* aPresContext,
4411 WidgetGUIEvent* aEvent,
4412 nsEventStatus* aEventStatus) {
4413 if (aEvent->mMessage == eMouseMove) {
4414 // XXX If the second argument of HandleDrag() is WidgetMouseEvent,
4415 // the implementation becomes simpler.
4416 return HandleDrag(aPresContext, aEvent, aEventStatus);
4417 }
4418
4419 if ((aEvent->mClass == eMouseEventClass &&
4420 aEvent->AsMouseEvent()->mButton == MouseButton::ePrimary) ||
4421 aEvent->mClass == eTouchEventClass) {
4422 if (aEvent->mMessage == eMouseDown || aEvent->mMessage == eTouchStart) {
4423 HandlePress(aPresContext, aEvent, aEventStatus);
4424 } else if (aEvent->mMessage == eMouseUp || aEvent->mMessage == eTouchEnd) {
4425 HandleRelease(aPresContext, aEvent, aEventStatus);
4426 }
4427 return NS_OK;
4428 }
4429
4430 // When secondary buttion is down, we need to move selection to make users
4431 // possible to paste something at click point quickly.
4432 // When middle button is down, we need to just move selection and focus at
4433 // the clicked point. Note that even if middle click paste is not enabled,
4434 // Chrome moves selection at middle mouse button down. So, we should follow
4435 // the behavior for the compatibility.
4436 if (aEvent->mMessage == eMouseDown) {
4437 WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
4438 if (mouseEvent && (mouseEvent->mButton == MouseButton::eSecondary ||
4439 mouseEvent->mButton == MouseButton::eMiddle)) {
4440 if (*aEventStatus == nsEventStatus_eConsumeNoDefault) {
4441 return NS_OK;
4442 }
4443 return MoveCaretToEventPoint(aPresContext, mouseEvent, aEventStatus);
4444 }
4445 }
4446
4447 return NS_OK;
4448}
4449
4450nsresult nsIFrame::GetDataForTableSelection(
4451 const nsFrameSelection* aFrameSelection, mozilla::PresShell* aPresShell,
4452 WidgetMouseEvent* aMouseEvent, nsIContent** aParentContent,
4453 int32_t* aContentOffset, TableSelectionMode* aTarget) {
4454 if (!aFrameSelection || !aPresShell || !aMouseEvent || !aParentContent ||
4455 !aContentOffset || !aTarget)
4456 return NS_ERROR_NULL_POINTER;
4457
4458 *aParentContent = nullptr;
4459 *aContentOffset = 0;
4460 *aTarget = TableSelectionMode::None;
4461
4462 int16_t displaySelection = aPresShell->GetSelectionFlags();
4463
4464 bool selectingTableCells = aFrameSelection->IsInTableSelectionMode();
4465
4466 // DISPLAY_ALL means we're in an editor.
4467 // If already in cell selection mode,
4468 // continue selecting with mouse drag or end on mouse up,
4469 // or when using shift key to extend block of cells
4470 // (Mouse down does normal selection unless Ctrl/Cmd is pressed)
4471 bool doTableSelection =
4472 displaySelection == nsISelectionDisplay::DISPLAY_ALL &&
4473 selectingTableCells &&
4474 (aMouseEvent->mMessage == eMouseMove ||
4475 (aMouseEvent->mMessage == eMouseUp &&
4476 aMouseEvent->mButton == MouseButton::ePrimary) ||
4477 aMouseEvent->IsShift());
4478
4479 if (!doTableSelection) {
4480 // In Browser, special 'table selection' key must be pressed for table
4481 // selection or when just Shift is pressed and we're already in table/cell
4482 // selection mode
4483#ifdef XP_MACOSX
4484 doTableSelection = aMouseEvent->IsMeta() ||
4485 (aMouseEvent->IsShift() && selectingTableCells);
4486#else
4487 doTableSelection = aMouseEvent->IsControl() ||
4488 (aMouseEvent->IsShift() && selectingTableCells);
4489#endif
4490 }
4491 if (!doTableSelection) return NS_OK;
4492
4493 // Get the cell frame or table frame (or parent) of the current content node
4494 nsIFrame* frame = this;
4495 bool foundCell = false;
4496 bool foundTable = false;
4497
4498 // Get the limiting node to stop parent frame search
4499 nsIContent* limiter = aFrameSelection->GetLimiter();
4500
4501 // If our content node is an ancestor of the limiting node,
4502 // we should stop the search right now.
4503 if (limiter && limiter->IsInclusiveDescendantOf(GetContent())) return NS_OK;
4504
4505 // We don't initiate row/col selection from here now,
4506 // but we may in future
4507 // bool selectColumn = false;
4508 // bool selectRow = false;
4509
4510 while (frame) {
4511 // Check for a table cell by querying to a known CellFrame interface
4512 nsITableCellLayout* cellElement = do_QueryFrame(frame);
4513 if (cellElement) {
4514 foundCell = true;
4515 // TODO: If we want to use proximity to top or left border
4516 // for row and column selection, this is the place to do it
4517 break;
4518 } else {
4519 // If not a cell, check for table
4520 // This will happen when starting frame is the table or child of a table,
4521 // such as a row (we were inbetween cells or in table border)
4522 nsTableWrapperFrame* tableFrame = do_QueryFrame(frame);
4523 if (tableFrame) {
4524 foundTable = true;
4525 // TODO: How can we select row when along left table edge
4526 // or select column when along top edge?
4527 break;
4528 } else {
4529 frame = frame->GetParent();
4530 // Stop if we have hit the selection's limiting content node
4531 if (frame && frame->GetContent() == limiter) break;
4532 }
4533 }
4534 }
4535 // We aren't in a cell or table
4536 if (!foundCell && !foundTable) return NS_OK;
4537
4538 nsIContent* tableOrCellContent = frame->GetContent();
4539 if (!tableOrCellContent) return NS_ERROR_FAILURE;
4540
4541 nsCOMPtr<nsIContent> parentContent = tableOrCellContent->GetParent();
4542 if (!parentContent) return NS_ERROR_FAILURE;
4543
4544 const int32_t offset =
4545 parentContent->ComputeIndexOf_Deprecated(tableOrCellContent);
4546 // Not likely?
4547 if (offset < 0) {
4548 return NS_ERROR_FAILURE;
4549 }
4550
4551 // Everything is OK -- set the return values
4552 parentContent.forget(aParentContent);
4553
4554 *aContentOffset = offset;
4555
4556#if 0
4557 if (selectRow)
4558 *aTarget = TableSelectionMode::Row;
4559 else if (selectColumn)
4560 *aTarget = TableSelectionMode::Column;
4561 else
4562#endif
4563 if (foundCell) {
4564 *aTarget = TableSelectionMode::Cell;
4565 } else if (foundTable) {
4566 *aTarget = TableSelectionMode::Table;
4567 }
4568
4569 return NS_OK;
4570}
4571
4572static bool IsEditingHost(const nsIFrame* aFrame) {
4573 nsIContent* content = aFrame->GetContent();
4574 return content && content->IsEditingHost();
4575}
4576
4577static StyleUserSelect UsedUserSelect(const nsIFrame* aFrame) {
4578 if (aFrame->IsGeneratedContentFrame()) {
4579 return StyleUserSelect::None;
4580 }
4581
4582 // Per https://drafts.csswg.org/css-ui-4/#content-selection:
4583 //
4584 // The used value is the same as the computed value, except:
4585 //
4586 // 1 - on editable elements where the used value is always 'contain'
4587 // regardless of the computed value
4588 // 2 - when the computed value is auto, in which case the used value is one
4589 // of the other values...
4590 //
4591 // See https://github.com/w3c/csswg-drafts/issues/3344 to see why we do this
4592 // at used-value time instead of at computed-value time.
4593
4594 if (aFrame->IsTextInputFrame() || IsEditingHost(aFrame)) {
4595 // We don't implement 'contain' itself, but we make 'text' behave as
4596 // 'contain' for contenteditable and <input> / <textarea> elements anyway so
4597 // this is ok.
4598 return StyleUserSelect::Text;
4599 }
4600
4601 auto style = aFrame->Style()->UserSelect();
4602 if (style != StyleUserSelect::Auto) {
4603 return style;
4604 }
4605
4606 auto* parent = nsLayoutUtils::GetParentOrPlaceholderFor(aFrame);
4607 return parent ? UsedUserSelect(parent) : StyleUserSelect::Text;
4608}
4609
4610bool nsIFrame::IsSelectable(StyleUserSelect* aSelectStyle) const {
4611 auto style = UsedUserSelect(this);
4612 if (aSelectStyle) {
4613 *aSelectStyle = style;
4614 }
4615 return style != StyleUserSelect::None;
4616}
4617
4618bool nsIFrame::ShouldHaveLineIfEmpty() const {
4619 if (Style()->IsPseudoOrAnonBox() &&
4620 Style()->GetPseudoType() != PseudoStyleType::scrolledContent) {
4621 return false;
4622 }
4623 return IsEditingHost(this);
4624}
4625
4626/**
4627 * Handles the Mouse Press Event for the frame
4628 */
4629NS_IMETHODIMPnsresult
4630nsIFrame::HandlePress(nsPresContext* aPresContext, WidgetGUIEvent* aEvent,
4631 nsEventStatus* aEventStatus) {
4632 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"
, 4632); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4633 if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
4634 return NS_OK;
4635 }
4636
4637 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"
, 4637); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4638 if (aEvent->mClass == eTouchEventClass) {
4639 return NS_OK;
4640 }
4641
4642 return MoveCaretToEventPoint(aPresContext, aEvent->AsMouseEvent(),
4643 aEventStatus);
4644}
4645
4646nsresult nsIFrame::MoveCaretToEventPoint(nsPresContext* aPresContext,
4647 WidgetMouseEvent* aMouseEvent,
4648 nsEventStatus* aEventStatus) {
4649 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"
, 4649); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPresContext"
")"); do { *((volatile int*)__null) = 4649; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4650 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"
, 4650); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aMouseEvent"
")"); do { *((volatile int*)__null) = 4650; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4651 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"
, 4651); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aMouseEvent->mMessage == eMouseDown"
")"); do { *((volatile int*)__null) = 4651; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4652 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"
, 4652); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aEventStatus"
")"); do { *((volatile int*)__null) = 4652; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4653 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"
, 4653); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsEventStatus_eConsumeNoDefault != *aEventStatus"
")"); do { *((volatile int*)__null) = 4653; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4654
4655 mozilla::PresShell* presShell = aPresContext->GetPresShell();
4656 if (!presShell) {
4657 return NS_ERROR_FAILURE;
4658 }
4659
4660 // We often get out of sync state issues with mousedown events that
4661 // get interrupted by alerts/dialogs.
4662 // Check with the ESM to see if we should process this one
4663 if (!aPresContext->EventStateManager()->EventStatusOK(aMouseEvent)) {
4664 return NS_OK;
4665 }
4666
4667 const nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
4668 aMouseEvent, RelativeTo{this});
4669
4670 // When not using `alt`, and clicking on a draggable, but non-editable
4671 // element, don't do anything, and let d&d handle the event.
4672 //
4673 // See bug 48876, bug 388659 and bug 55921 for context here.
4674 //
4675 // FIXME(emilio): The .Contains(pt) check looks a bit fishy. When would it be
4676 // false given we're the event target? If it is needed, why not checking the
4677 // actual draggable node rect instead?
4678 if (!aMouseEvent->IsAlt() && GetRectRelativeToSelf().Contains(pt)) {
4679 for (nsIContent* content = mContent; content;
4680 content = content->GetFlattenedTreeParent()) {
4681 if (nsContentUtils::ContentIsDraggable(content) &&
4682 !content->IsEditable()) {
4683 return NS_OK;
4684 }
4685 }
4686 }
4687
4688 // If we are in Navigator and the click is in a draggable node, we don't want
4689 // to start selection because we don't want to interfere with a potential
4690 // drag of said node and steal all its glory.
4691 const bool isEditor =
4692 presShell->GetSelectionFlags() == nsISelectionDisplay::DISPLAY_ALL;
4693
4694 // Don't do something if it's middle button down event.
4695 const bool isPrimaryButtonDown =
4696 aMouseEvent->mButton == MouseButton::ePrimary;
4697
4698 // check whether style allows selection
4699 // if not, don't tell selection the mouse event even occurred.
4700 StyleUserSelect selectStyle;
4701 // check for select: none
4702 if (!IsSelectable(&selectStyle)) {
4703 return NS_OK;
4704 }
4705
4706 if (isPrimaryButtonDown) {
4707 // If the mouse is dragged outside the nearest enclosing scrollable area
4708 // while making a selection, the area will be scrolled. To do this, capture
4709 // the mouse on the nearest scroll container frame. If there isn't a scroll
4710 // container frame, or something else is already capturing the mouse,
4711 // there's no reason to capture.
4712 if (!PresShell::GetCapturingContent()) {
4713 ScrollContainerFrame* scrollContainerFrame =
4714 nsLayoutUtils::GetNearestScrollContainerFrame(
4715 this, nsLayoutUtils::SCROLLABLE_SAME_DOC |
4716 nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
4717 if (scrollContainerFrame) {
4718 nsIFrame* capturingFrame = scrollContainerFrame;
4719 PresShell::SetCapturingContent(capturingFrame->GetContent(),
4720 CaptureFlags::IgnoreAllowedState);
4721 }
4722 }
4723 }
4724
4725 // XXX This is screwy; it really should use the selection frame, not the
4726 // event frame
4727 const nsFrameSelection* frameselection =
4728 selectStyle == StyleUserSelect::Text ? GetConstFrameSelection()
4729 : presShell->ConstFrameSelection();
4730
4731 if (!frameselection || frameselection->GetDisplaySelection() ==
4732 nsISelectionController::SELECTION_OFF) {
4733 return NS_OK; // nothing to do we cannot affect selection from here
4734 }
4735
4736#ifdef XP_MACOSX
4737 // If Control key is pressed on macOS, it should be treated as right click.
4738 // So, don't change selection.
4739 if (aMouseEvent->IsControl()) {
4740 return NS_OK;
4741 }
4742 const bool control = aMouseEvent->IsMeta();
4743#else
4744 const bool control = aMouseEvent->IsControl();
4745#endif
4746
4747 RefPtr<nsFrameSelection> fc = const_cast<nsFrameSelection*>(frameselection);
4748 if (isPrimaryButtonDown && aMouseEvent->mClickCount > 1) {
4749 // These methods aren't const but can't actually delete anything,
4750 // so no need for AutoWeakFrame.
4751 fc->SetDragState(true);
4752 return HandleMultiplePress(aPresContext, aMouseEvent, aEventStatus,
4753 control);
4754 }
4755
4756 ContentOffsets offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN);
4757
4758 if (!offsets.content) {
4759 return NS_ERROR_FAILURE;
4760 }
4761
4762 const bool isSecondaryButton =
4763 aMouseEvent->mButton == MouseButton::eSecondary;
4764 if (isSecondaryButton &&
4765 !MovingCaretToEventPointAllowedIfSecondaryButtonEvent(
4766 *frameselection, *aMouseEvent, *offsets.content,
4767 // When we collapse selection in nsFrameSelection::TakeFocus,
4768 // we always collapse selection to the start offset. Therefore,
4769 // we can ignore the end offset here. E.g., when an <img> is clicked,
4770 // set the primary offset to after it, but the the secondary offset
4771 // may be before it, see OffsetsForSingleFrame for the detail.
4772 offsets.StartOffset())) {
4773 return NS_OK;
4774 }
4775
4776 if (aMouseEvent->mMessage == eMouseDown &&
4777 aMouseEvent->mButton == MouseButton::eMiddle &&
4778 !offsets.content->IsEditable()) {
4779 // However, some users don't like the Chrome compatible behavior of
4780 // middle mouse click. They want to keep selection after starting
4781 // autoscroll. However, the selection change is important for middle
4782 // mouse past. Therefore, we should allow users to take the traditional
4783 // behavior back by themselves unless middle click paste is enabled or
4784 // autoscrolling is disabled.
4785 if (!Preferences::GetBool("middlemouse.paste", false) &&
4786 Preferences::GetBool("general.autoScroll", false) &&
4787 Preferences::GetBool("general.autoscroll.prevent_to_collapse_selection_"
4788 "by_middle_mouse_down",
4789 false)) {
4790 return NS_OK;
4791 }
4792 }
4793
4794 if (isPrimaryButtonDown) {
4795 // Let Ctrl/Cmd + left mouse down do table selection instead of drag
4796 // initiation.
4797 nsCOMPtr<nsIContent> parentContent;
4798 int32_t contentOffset;
4799 TableSelectionMode target;
4800 nsresult rv = GetDataForTableSelection(
4801 frameselection, presShell, aMouseEvent, getter_AddRefs(parentContent),
4802 &contentOffset, &target);
4803 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && parentContent) {
4804 fc->SetDragState(true);
4805 return fc->HandleTableSelection(parentContent, contentOffset, target,
4806 aMouseEvent);
4807 }
4808 }
4809
4810 fc->SetDelayedCaretData(0);
4811
4812 if (isPrimaryButtonDown) {
4813 // Check if any part of this frame is selected, and if the user clicked
4814 // inside the selected region, and if it's the left button. If so, we delay
4815 // starting a new selection since the user may be trying to drag the
4816 // selected region to some other app.
4817
4818 if (GetContent() && GetContent()->IsMaybeSelected()) {
4819 bool inSelection = false;
4820 UniquePtr<SelectionDetails> details = frameselection->LookUpSelection(
4821 offsets.content, 0, offsets.EndOffset(), false);
4822
4823 //
4824 // If there are any details, check to see if the user clicked
4825 // within any selected region of the frame.
4826 //
4827
4828 for (SelectionDetails* curDetail = details.get(); curDetail;
4829 curDetail = curDetail->mNext.get()) {
4830 //
4831 // If the user clicked inside a selection, then just
4832 // return without doing anything. We will handle placing
4833 // the caret later on when the mouse is released. We ignore
4834 // the spellcheck, find and url formatting selections.
4835 //
4836 if (curDetail->mSelectionType != SelectionType::eSpellCheck &&
4837 curDetail->mSelectionType != SelectionType::eFind &&
4838 curDetail->mSelectionType != SelectionType::eURLSecondary &&
4839 curDetail->mSelectionType != SelectionType::eURLStrikeout &&
4840 curDetail->mSelectionType != SelectionType::eHighlight &&
4841 curDetail->mSelectionType != SelectionType::eTargetText &&
4842 curDetail->mStart <= offsets.StartOffset() &&
4843 offsets.EndOffset() <= curDetail->mEnd) {
4844 inSelection = true;
4845 }
4846 }
4847
4848 if (inSelection) {
4849 fc->SetDragState(false);
4850 fc->SetDelayedCaretData(aMouseEvent);
4851 return NS_OK;
4852 }
4853 }
4854
4855 fc->SetDragState(true);
4856 }
4857
4858 // Do not touch any nsFrame members after this point without adding
4859 // weakFrame checks.
4860 const nsFrameSelection::FocusMode focusMode = [&]() {
4861 // If "Shift" and "Ctrl" are both pressed, "Shift" is given precedence. This
4862 // mimics the old behaviour.
4863 const bool isShift =
4864 aMouseEvent->IsShift() &&
4865 // If Shift + secondary button press shoud open context menu without a
4866 // contextmenu event, user wants to open context menu like as a
4867 // secondary button press without Shift key.
4868 !(isSecondaryButton &&
4869 StaticPrefs::dom_event_contextmenu_shift_suppresses_event());
4870 if (isShift) {
4871 // If clicked in a link when focused content is editable, we should
4872 // collapse selection in the link for compatibility with Blink.
4873 if (isEditor) {
4874 for (Element* element : mContent->InclusiveAncestorsOfType<Element>()) {
4875 if (element->IsLink()) {
4876 return nsFrameSelection::FocusMode::kCollapseToNewPoint;
4877 }
4878 }
4879 }
4880 return nsFrameSelection::FocusMode::kExtendSelection;
4881 }
4882
4883 if (isPrimaryButtonDown && control) {
4884 return nsFrameSelection::FocusMode::kMultiRangeSelection;
4885 }
4886
4887 return nsFrameSelection::FocusMode::kCollapseToNewPoint;
4888 }();
4889
4890 nsresult rv = fc->HandleClick(
4891 MOZ_KnownLive(offsets.content)(offsets.content) /* bug 1636889 */, offsets.StartOffset(),
4892 offsets.EndOffset(), focusMode, offsets.associate);
4893 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4894 return rv;
4895 }
4896
4897 // We don't handle mouse button up if it's middle button.
4898 if (isPrimaryButtonDown && offsets.offset != offsets.secondaryOffset) {
4899 fc->MaintainSelection();
4900 }
4901
4902 if (isPrimaryButtonDown && isEditor && !aMouseEvent->IsShift() &&
4903 (offsets.EndOffset() - offsets.StartOffset()) == 1) {
4904 // A single node is selected and we aren't extending an existing selection,
4905 // which means the user clicked directly on an object (either
4906 // `user-select: all` or a non-text node without children). Therefore,
4907 // disable selection extension during mouse moves.
4908 // XXX This is a bit hacky; shouldn't editor be able to deal with this?
4909 fc->SetDragState(false);
4910 }
4911
4912 return NS_OK;
4913}
4914
4915bool nsIFrame::MovingCaretToEventPointAllowedIfSecondaryButtonEvent(
4916 const nsFrameSelection& aFrameSelection,
4917 WidgetMouseEvent& aSecondaryButtonEvent,
4918 const nsIContent& aContentAtEventPoint, int32_t aOffsetAtEventPoint) const {
4919 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"
, 4919); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aSecondaryButtonEvent.mButton == MouseButton::eSecondary"
")"); do { *((volatile int*)__null) = 4919; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4920
4921 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"
, 4921)
) {
4922 return false;
4923 }
4924
4925 const bool contentIsEditable = aContentAtEventPoint.IsEditable();
4926 const TextControlElement* const contentAsTextControl =
4927 TextControlElement::FromNodeOrNull(
4928 aContentAtEventPoint.IsTextControlElement()
4929 ? &aContentAtEventPoint
4930 : aContentAtEventPoint.GetClosestNativeAnonymousSubtreeRoot());
4931 if (Selection* selection =
4932 aFrameSelection.GetSelection(SelectionType::eNormal)) {
4933 const bool selectionIsCollapsed =
4934 selection->AreNormalAndCrossShadowBoundaryRangesCollapsed();
4935 // If right click in a selection range, we should not collapse
4936 // selection.
4937 if (!selectionIsCollapsed && nsContentUtils::IsPointInSelection(
4938 *selection, aContentAtEventPoint,
4939 static_cast<uint32_t>(aOffsetAtEventPoint),
4940 true /* aAllowCrossShadowBoundary */)) {
4941 return false;
4942 }
4943 const bool wantToPreventMoveCaret =
4944 StaticPrefs::
4945 ui_mouse_right_click_move_caret_stop_if_in_focused_editable_node() &&
4946 selectionIsCollapsed && (contentIsEditable || contentAsTextControl);
4947 const bool wantToPreventCollapseSelection =
4948 StaticPrefs::
4949 ui_mouse_right_click_collapse_selection_stop_if_non_collapsed_selection() &&
4950 !selectionIsCollapsed;
4951 if (wantToPreventMoveCaret || wantToPreventCollapseSelection) {
4952 // If currently selection is limited in an editing host, we should not
4953 // collapse selection nor move caret if the clicked point is in the
4954 // ancestor limiter. Otherwise, this mouse click moves focus from the
4955 // editing host to different one or blur the editing host. In this case,
4956 // we need to update selection because keeping current selection in the
4957 // editing host looks like it's not blurred.
4958 // FIXME: If the active editing host is the document element, editor
4959 // does not set ancestor limiter properly. Fix it in the editor side.
4960 if (nsIContent* ancestorLimiter = selection->GetAncestorLimiter()) {
4961 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"
, 4961); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ancestorLimiter->IsEditable()"
")"); do { *((volatile int*)__null) = 4961; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4962 return !aContentAtEventPoint.IsInclusiveDescendantOf(ancestorLimiter);
4963 }
4964 }
4965 // If selection is editable and `stop_if_in_focused_editable_node` pref is
4966 // set to true, user does not want to move caret to right click place if
4967 // clicked in the focused text control element.
4968 if (wantToPreventMoveCaret && contentAsTextControl &&
4969 contentAsTextControl == nsFocusManager::GetFocusedElementStatic()) {
4970 return false;
4971 }
4972 // If currently selection is not limited in an editing host, we should
4973 // collapse selection only when this click moves focus to an editing
4974 // host because we need to update selection in this case.
4975 if (wantToPreventCollapseSelection && !contentIsEditable) {
4976 return false;
4977 }
4978 }
4979
4980 return !StaticPrefs::
4981 ui_mouse_right_click_collapse_selection_stop_if_non_editable_node() ||
4982 // The user does not want to collapse selection into non-editable
4983 // content by a right button click.
4984 contentIsEditable ||
4985 // Treat clicking in a text control as always clicked on editable
4986 // content because we want a hack only for clicking in normal text
4987 // nodes which is outside any editing hosts.
4988 contentAsTextControl;
4989}
4990
4991nsresult nsIFrame::SelectByTypeAtPoint(nsPresContext* aPresContext,
4992 const nsPoint& aPoint,
4993 nsSelectionAmount aBeginAmountType,
4994 nsSelectionAmount aEndAmountType,
4995 uint32_t aSelectFlags) {
4996 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"
, 4996); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4997
4998 // No point in selecting if selection is turned off
4999 if (DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF) {
5000 return NS_OK;
5001 }
5002
5003 ContentOffsets offsets = GetContentOffsetsFromPoint(
5004 aPoint, SKIP_HIDDEN | IGNORE_NATIVE_ANONYMOUS_SUBTREE);
5005 if (!offsets.content) {
5006 return NS_ERROR_FAILURE;
5007 }
5008
5009 uint32_t offset;
5010 nsIFrame* frame = SelectionMovementUtils::GetFrameForNodeOffset(
5011 offsets.content, offsets.offset, offsets.associate, &offset);
5012 if (!frame) {
5013 return NS_ERROR_FAILURE;
5014 }
5015 return frame->PeekBackwardAndForward(
5016 aBeginAmountType, aEndAmountType, static_cast<int32_t>(offset),
5017 aBeginAmountType != eSelectWord, aSelectFlags);
5018}
5019
5020/**
5021 * Multiple Mouse Press -- line or paragraph selection -- for the frame.
5022 * Wouldn't it be nice if this didn't have to be hardwired into Frame code?
5023 */
5024NS_IMETHODIMPnsresult
5025nsIFrame::HandleMultiplePress(nsPresContext* aPresContext,
5026 WidgetGUIEvent* aEvent,
5027 nsEventStatus* aEventStatus, bool aControlHeld) {
5028 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"
, 5028); return NS_ERROR_INVALID_POINTER; } } while (false)
;
5029 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"
, 5029); return NS_ERROR_INVALID_POINTER; } } while (false)
;
5030
5031 if (nsEventStatus_eConsumeNoDefault == *aEventStatus ||
5032 DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF) {
5033 return NS_OK;
5034 }
5035
5036 // Find out whether we're doing line or paragraph selection.
5037 // If browser.triple_click_selects_paragraph is true, triple-click selects
5038 // paragraph. Otherwise, triple-click selects line, and quadruple-click
5039 // selects paragraph (on platforms that support quadruple-click).
5040 nsSelectionAmount beginAmount, endAmount;
5041 WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
5042 if (!mouseEvent) {
5043 return NS_OK;
5044 }
5045
5046 if (mouseEvent->mClickCount == 4) {
5047 beginAmount = endAmount = eSelectParagraph;
5048 } else if (mouseEvent->mClickCount == 3) {
5049 if (Preferences::GetBool("browser.triple_click_selects_paragraph")) {
5050 beginAmount = endAmount = eSelectParagraph;
5051 } else {
5052 beginAmount = eSelectBeginLine;
5053 endAmount = eSelectEndLine;
5054 }
5055 } else if (mouseEvent->mClickCount == 2) {
5056 // We only want inline frames; PeekBackwardAndForward dislikes blocks
5057 beginAmount = endAmount = eSelectWord;
5058 } else {
5059 return NS_OK;
5060 }
5061
5062 nsPoint relPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(
5063 mouseEvent, RelativeTo{this});
5064 return SelectByTypeAtPoint(aPresContext, relPoint, beginAmount, endAmount,
5065 (aControlHeld ? SELECT_ACCUMULATE : 0));
5066}
5067
5068nsresult nsIFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack,
5069 nsSelectionAmount aAmountForward,
5070 int32_t aStartPos, bool aJumpLines,
5071 uint32_t aSelectFlags) {
5072 nsIFrame* baseFrame = this;
5073 int32_t baseOffset = aStartPos;
5074 nsresult rv;
5075
5076 PeekOffsetOptions peekOffsetOptions{PeekOffsetOption::StopAtScroller};
5077 if (aJumpLines) {
5078 peekOffsetOptions += PeekOffsetOption::JumpLines;
5079 }
5080
5081 if (aAmountBack == eSelectWord) {
5082 // To avoid selecting the previous word when at start of word,
5083 // first move one character forward.
5084 PeekOffsetStruct pos(eSelectCharacter, eDirNext, aStartPos, nsPoint(0, 0),
5085 peekOffsetOptions);
5086 rv = PeekOffset(&pos);
5087 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
5088 baseFrame = pos.mResultFrame;
5089 baseOffset = pos.mContentOffset;
5090 }
5091 }
5092
5093 // Search backward for a boundary.
5094 PeekOffsetStruct startpos(aAmountBack, eDirPrevious, baseOffset,
5095 nsPoint(0, 0), peekOffsetOptions);
5096 rv = baseFrame->PeekOffset(&startpos);
5097 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5098 return rv;
5099 }
5100
5101 // If the backward search stayed within the same frame, search forward from
5102 // that position for the end boundary; but if it crossed out to a sibling or
5103 // ancestor, start from the original position.
5104 if (startpos.mResultFrame == baseFrame) {
5105 baseOffset = startpos.mContentOffset;
5106 } else {
5107 baseFrame = this;
5108 baseOffset = aStartPos;
5109 }
5110
5111 PeekOffsetStruct endpos(aAmountForward, eDirNext, baseOffset, nsPoint(0, 0),
5112 peekOffsetOptions);
5113 rv = baseFrame->PeekOffset(&endpos);
5114 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5115 return rv;
5116 }
5117
5118 // Keep frameSelection alive.
5119 RefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
5120
5121 const nsFrameSelection::FocusMode focusMode =
5122 (aSelectFlags & SELECT_ACCUMULATE)
5123 ? nsFrameSelection::FocusMode::kMultiRangeSelection
5124 : nsFrameSelection::FocusMode::kCollapseToNewPoint;
5125 rv = frameSelection->HandleClick(
5126 MOZ_KnownLive(startpos.mResultContent)(startpos.mResultContent) /* bug 1636889 */,
5127 startpos.mContentOffset, startpos.mContentOffset, focusMode,
5128 CaretAssociationHint::After);
5129 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5130 return rv;
5131 }
5132
5133 rv = frameSelection->HandleClick(
5134 MOZ_KnownLive(endpos.mResultContent)(endpos.mResultContent) /* bug 1636889 */,
5135 endpos.mContentOffset, endpos.mContentOffset,
5136 nsFrameSelection::FocusMode::kExtendSelection,
5137 CaretAssociationHint::Before);
5138 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5139 return rv;
5140 }
5141 if (aAmountBack == eSelectWord) {
5142 frameSelection->SetClickSelectionType(ClickSelectionType::Double);
5143 } else if (aAmountBack == eSelectParagraph) {
5144 frameSelection->SetClickSelectionType(ClickSelectionType::Triple);
5145 }
5146
5147 // maintain selection
5148 return frameSelection->MaintainSelection(aAmountBack);
5149}
5150
5151NS_IMETHODIMPnsresult nsIFrame::HandleDrag(nsPresContext* aPresContext,
5152 WidgetGUIEvent* aEvent,
5153 nsEventStatus* aEventStatus) {
5154 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"
, 5155); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aEvent->mClass == eMouseEventClass"
") (" "HandleDrag can only handle mouse event" ")"); do { *(
(volatile int*)__null) = 5155; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
5155 "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"
, 5155); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aEvent->mClass == eMouseEventClass"
") (" "HandleDrag can only handle mouse event" ")"); do { *(
(volatile int*)__null) = 5155; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
5156
5157 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"
, 5157); return NS_ERROR_INVALID_POINTER; } } while (false)
;
5158
5159 RefPtr<nsFrameSelection> frameselection = GetFrameSelection();
5160 if (!frameselection) {
5161 return NS_OK;
5162 }
5163
5164 bool mouseDown = frameselection->GetDragState();
5165 if (!mouseDown) {
5166 return NS_OK;
5167 }
5168
5169 nsIFrame* scrollbar =
5170 nsLayoutUtils::GetClosestFrameOfType(this, LayoutFrameType::Scrollbar);
5171 if (!scrollbar) {
5172 // XXX Do we really need to exclude non-selectable content here?
5173 // GetContentOffsetsFromPoint can handle it just fine, although some
5174 // other stuff might not like it.
5175 // NOTE: DetermineDisplaySelection() returns SELECTION_OFF for
5176 // non-selectable frames.
5177 if (DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF) {
5178 return NS_OK;
5179 }
5180 }
5181
5182 frameselection->StopAutoScrollTimer();
5183
5184 // Check if we are dragging in a table cell
5185 nsCOMPtr<nsIContent> parentContent;
5186 int32_t contentOffset;
5187 TableSelectionMode target;
5188 WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
5189 mozilla::PresShell* presShell = aPresContext->PresShell();
5190 nsresult result;
5191 result = GetDataForTableSelection(frameselection, presShell, mouseEvent,
5192 getter_AddRefs(parentContent),
5193 &contentOffset, &target);
5194
5195 AutoWeakFrame weakThis = this;
5196 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) && parentContent) {
5197 result = frameselection->HandleTableSelection(parentContent, contentOffset,
5198 target, mouseEvent);
5199 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"
, 5199)
) {
5200 return result;
5201 }
5202 } else {
5203 nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent,
5204 RelativeTo{this});
5205 frameselection->HandleDrag(this, pt);
5206 }
5207
5208 // The frameselection object notifies selection listeners synchronously above
5209 // which might have killed us.
5210 if (!weakThis.IsAlive()) {
5211 return NS_OK;
5212 }
5213
5214 // Get the nearest scroll container frame.
5215 ScrollContainerFrame* scrollContainerFrame =
5216 nsLayoutUtils::GetNearestScrollContainerFrame(
5217 this, nsLayoutUtils::SCROLLABLE_SAME_DOC |
5218 nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
5219
5220 if (scrollContainerFrame) {
5221 nsIFrame* capturingFrame = scrollContainerFrame->GetScrolledFrame();
5222 if (capturingFrame) {
5223 nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
5224 mouseEvent, RelativeTo{capturingFrame});
5225 frameselection->StartAutoScrollTimer(capturingFrame, pt, 30);
5226 }
5227 }
5228
5229 return NS_OK;
5230}
5231
5232/**
5233 * This static method handles part of the nsIFrame::HandleRelease in a way
5234 * which doesn't rely on the nsFrame object to stay alive.
5235 */
5236MOZ_CAN_RUN_SCRIPT_BOUNDARY static nsresult HandleFrameSelection(
5237 nsFrameSelection* aFrameSelection, nsIFrame::ContentOffsets& aOffsets,
5238 bool aHandleTableSel, int32_t aContentOffsetForTableSel,
5239 TableSelectionMode aTargetForTableSel,
5240 nsIContent* aParentContentForTableSel, WidgetGUIEvent* aEvent,
5241 const nsEventStatus* aEventStatus) {
5242 if (!aFrameSelection) {
5243 return NS_OK;
5244 }
5245
5246 nsresult rv = NS_OK;
5247
5248 if (nsEventStatus_eConsumeNoDefault != *aEventStatus) {
5249 if (!aHandleTableSel) {
5250 if (!aOffsets.content || !aFrameSelection->HasDelayedCaretData()) {
5251 return NS_ERROR_FAILURE;
5252 }
5253
5254 // We are doing this to simulate what we would have done on HandlePress.
5255 // We didn't do it there to give the user an opportunity to drag
5256 // the text, but since they didn't drag, we want to place the
5257 // caret.
5258 // However, we'll use the mouse position from the release, since:
5259 // * it's easier
5260 // * that's the normal click position to use (although really, in
5261 // the normal case, small movements that don't count as a drag
5262 // can do selection)
5263 aFrameSelection->SetDragState(true);
5264
5265 const nsFrameSelection::FocusMode focusMode =
5266 aFrameSelection->IsShiftDownInDelayedCaretData()
5267 ? nsFrameSelection::FocusMode::kExtendSelection
5268 : nsFrameSelection::FocusMode::kCollapseToNewPoint;
5269 rv = aFrameSelection->HandleClick(
5270 MOZ_KnownLive(aOffsets.content)(aOffsets.content) /* bug 1636889 */,
5271 aOffsets.StartOffset(), aOffsets.EndOffset(), focusMode,
5272 aOffsets.associate);
5273 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5274 return rv;
5275 }
5276 } else if (aParentContentForTableSel) {
5277 aFrameSelection->SetDragState(false);
5278 rv = aFrameSelection->HandleTableSelection(
5279 aParentContentForTableSel, aContentOffsetForTableSel,
5280 aTargetForTableSel, aEvent->AsMouseEvent());
5281 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5282 return rv;
5283 }
5284 }
5285 aFrameSelection->SetDelayedCaretData(0);
5286 }
5287
5288 aFrameSelection->SetDragState(false);
5289 aFrameSelection->StopAutoScrollTimer();
5290
5291 return NS_OK;
5292}
5293
5294NS_IMETHODIMPnsresult nsIFrame::HandleRelease(nsPresContext* aPresContext,
5295 WidgetGUIEvent* aEvent,
5296 nsEventStatus* aEventStatus) {
5297 if (aEvent->mClass != eMouseEventClass) {
5298 return NS_OK;
5299 }
5300
5301 nsIFrame* activeFrame = GetActiveSelectionFrame(aPresContext, this);
5302
5303 nsCOMPtr<nsIContent> captureContent = PresShell::GetCapturingContent();
5304
5305 bool selectionOff =
5306 (DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF);
5307
5308 RefPtr<nsFrameSelection> frameselection;
5309 ContentOffsets offsets;
5310 nsCOMPtr<nsIContent> parentContent;
5311 int32_t contentOffsetForTableSel = 0;
5312 TableSelectionMode targetForTableSel = TableSelectionMode::None;
5313 bool handleTableSelection = true;
5314
5315 if (!selectionOff) {
5316 frameselection = GetFrameSelection();
5317 if (nsEventStatus_eConsumeNoDefault != *aEventStatus && frameselection) {
5318 // Check if the frameselection recorded the mouse going down.
5319 // If not, the user must have clicked in a part of the selection.
5320 // Place the caret before continuing!
5321
5322 if (frameselection->MouseDownRecorded()) {
5323 nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
5324 aEvent, RelativeTo{this});
5325 offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN);
5326 handleTableSelection = false;
5327 } else {
5328 GetDataForTableSelection(frameselection, PresShell(),
5329 aEvent->AsMouseEvent(),
5330 getter_AddRefs(parentContent),
5331 &contentOffsetForTableSel, &targetForTableSel);
5332 }
5333 }
5334 }
5335
5336 // We might be capturing in some other document and the event just happened to
5337 // trickle down here. Make sure that document's frame selection is notified.
5338 // Note, this may cause the current nsFrame object to be deleted, bug 336592.
5339 RefPtr<nsFrameSelection> frameSelection;
5340 if (activeFrame != this && activeFrame->DetermineDisplaySelection() !=
5341 nsISelectionController::SELECTION_OFF) {
5342 frameSelection = activeFrame->GetFrameSelection();
5343 }
5344
5345 // Also check the selection of the capturing content which might be in a
5346 // different document.
5347 if (!frameSelection && captureContent) {
5348 if (Document* doc = captureContent->GetComposedDoc()) {
5349 mozilla::PresShell* capturingPresShell = doc->GetPresShell();
5350 if (capturingPresShell &&
5351 capturingPresShell != PresContext()->GetPresShell()) {
5352 frameSelection = capturingPresShell->FrameSelection();
5353 }
5354 }
5355 }
5356
5357 if (frameSelection) {
5358 AutoWeakFrame wf(this);
5359 frameSelection->SetDragState(false);
5360 frameSelection->StopAutoScrollTimer();
5361 if (wf.IsAlive()) {
5362 ScrollContainerFrame* scrollContainerFrame =
5363 nsLayoutUtils::GetNearestScrollContainerFrame(
5364 this, nsLayoutUtils::SCROLLABLE_SAME_DOC |
5365 nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
5366 if (scrollContainerFrame) {
5367 // Perform any additional scrolling needed to maintain CSS snap point
5368 // requirements when autoscrolling is over.
5369 scrollContainerFrame->ScrollSnap();
5370 }
5371 }
5372 }
5373
5374 // Do not call any methods of the current object after this point!!!
5375 // The object is perhaps dead!
5376
5377 return selectionOff ? NS_OK
5378 : HandleFrameSelection(
5379 frameselection, offsets, handleTableSelection,
5380 contentOffsetForTableSel, targetForTableSel,
5381 parentContent, aEvent, aEventStatus);
5382}
5383
5384struct MOZ_STACK_CLASS FrameContentRange {
5385 FrameContentRange(nsIContent* aContent, int32_t aStart, int32_t aEnd)
5386 : content(aContent), start(aStart), end(aEnd) {}
5387 nsCOMPtr<nsIContent> content;
5388 int32_t start;
5389 int32_t end;
5390};
5391
5392// Retrieve the content offsets of a frame
5393static FrameContentRange GetRangeForFrame(const nsIFrame* aFrame) {
5394 nsIContent* content = aFrame->GetContent();
5395 if (!content) {
5396 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"
, 5396)
;
5397 return FrameContentRange(nullptr, -1, -1);
5398 }
5399
5400 LayoutFrameType type = aFrame->Type();
5401 if (type == LayoutFrameType::Text) {
5402 auto [offset, offsetEnd] = aFrame->GetOffsets();
5403 return FrameContentRange(content, offset, offsetEnd);
5404 }
5405
5406 if (type == LayoutFrameType::Br) {
5407 nsIContent* parent = content->GetParent();
5408 const int32_t beginOffset = parent->ComputeIndexOf_Deprecated(content);
5409 return FrameContentRange(parent, beginOffset, beginOffset);
5410 }
5411
5412 while (content->IsRootOfNativeAnonymousSubtree()) {
5413 content = content->GetParent();
5414 }
5415
5416 MOZ_ASSERT(!content->IsBeingRemoved())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!content->IsBeingRemoved())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!content->IsBeingRemoved(
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!content->IsBeingRemoved()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5416); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!content->IsBeingRemoved()"
")"); do { *((volatile int*)__null) = 5416; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5417 nsIContent* parent = content->GetParent();
5418 if (aFrame->IsBlockOutside() || !parent) {
5419 return FrameContentRange(content, 0, content->GetChildCount());
5420 }
5421
5422 // TODO(emilio): Revise this in presence of Shadow DOM / display: contents,
5423 // it's likely that we don't want to just walk the light tree, and we need to
5424 // change the representation of FrameContentRange.
5425 Maybe<uint32_t> index = parent->ComputeIndexOf(content);
5426 MOZ_ASSERT(index.isSome())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(index.isSome())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(index.isSome()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("index.isSome()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5426); AnnotateMozCrashReason("MOZ_ASSERT" "(" "index.isSome()"
")"); do { *((volatile int*)__null) = 5426; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5427 return FrameContentRange(parent, static_cast<int32_t>(*index),
5428 static_cast<int32_t>(*index + 1));
5429}
5430
5431// The FrameTarget represents the closest frame to a point that can be selected
5432// The frame is the frame represented, frameEdge says whether one end of the
5433// frame is the result (in which case different handling is needed), and
5434// afterFrame says which end is represented if frameEdge is true
5435struct FrameTarget {
5436 explicit operator bool() const { return !!frame; }
5437
5438 nsIFrame* frame = nullptr;
5439 bool frameEdge = false;
5440 bool afterFrame = false;
5441};
5442
5443// See function implementation for information
5444static FrameTarget GetSelectionClosestFrame(nsIFrame* aFrame,
5445 const nsPoint& aPoint,
5446 uint32_t aFlags);
5447
5448static bool SelfIsSelectable(nsIFrame* aFrame, nsIFrame* aParentFrame,
5449 uint32_t aFlags) {
5450 // We should not move selection into a native anonymous subtree when handling
5451 // selection outside it.
5452 if ((aFlags & nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE) &&
5453 aParentFrame->GetClosestNativeAnonymousSubtreeRoot() !=
5454 aFrame->GetClosestNativeAnonymousSubtreeRoot()) {
5455 return false;
5456 }
5457 if ((aFlags & nsIFrame::SKIP_HIDDEN) &&
5458 !aFrame->StyleVisibility()->IsVisible()) {
5459 return false;
5460 }
5461 return !aFrame->IsGeneratedContentFrame() &&
5462 aFrame->Style()->UserSelect() != StyleUserSelect::None;
5463}
5464
5465static bool FrameContentCanHaveParentSelectionRange(nsIFrame* aFrame) {
5466 // If we are only near (not directly over) then don't traverse
5467 // frames with independent selection (e.g. text and list controls, see bug
5468 // 268497). Note that this prevents any of the users of this method from
5469 // entering form controls.
5470 // XXX We might want some way to allow using the up-arrow to go into a form
5471 // control, but the focus didn't work right anyway; it'd probably be enough
5472 // if the left and right arrows could enter textboxes (which I don't believe
5473 // they can at the moment)
5474 if (aFrame->IsTextInputFrame() || aFrame->IsListControlFrame()) {
5475 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"
, 5475); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5475; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5476 return false;
5477 }
5478
5479 // Failure in this assertion means a new type of frame forms the root of an
5480 // NS_FRAME_INDEPENDENT_SELECTION subtree. In such case, the condition above
5481 // should be changed to handle it.
5482 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"
, 5484); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5484; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
5483 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"
, 5484); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5484; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
5484 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"
, 5484); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5484; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
5485
5486 return !aFrame->IsGeneratedContentFrame();
5487}
5488
5489static bool SelectionDescendToKids(nsIFrame* aFrame) {
5490 if (!FrameContentCanHaveParentSelectionRange(aFrame)) {
5491 return false;
5492 }
5493 auto style = aFrame->Style()->UserSelect();
5494 return style != StyleUserSelect::All && style != StyleUserSelect::None;
5495}
5496
5497static FrameTarget GetSelectionClosestFrameForChild(nsIFrame* aChild,
5498 const nsPoint& aPoint,
5499 uint32_t aFlags) {
5500 nsIFrame* parent = aChild->GetParent();
5501 if (SelectionDescendToKids(aChild)) {
5502 nsPoint pt = aPoint - aChild->GetOffsetTo(parent);
5503 return GetSelectionClosestFrame(aChild, pt, aFlags);
5504 }
5505 return FrameTarget{aChild, false, false};
5506}
5507
5508// When the cursor needs to be at the beginning of a block, it shouldn't be
5509// before the first child. A click on a block whose first child is a block
5510// should put the cursor in the child. The cursor shouldn't be between the
5511// blocks, because that's not where it's expected.
5512// Note that this method is guaranteed to succeed.
5513static FrameTarget DrillDownToSelectionFrame(nsIFrame* aFrame, bool aEndFrame,
5514 uint32_t aFlags) {
5515 if (SelectionDescendToKids(aFrame)) {
5516 nsIFrame* result = nullptr;
5517 nsIFrame* frame = aFrame->PrincipalChildList().FirstChild();
5518 if (!aEndFrame) {
5519 while (frame &&
5520 (!SelfIsSelectable(frame, aFrame, aFlags) || frame->IsEmpty())) {
5521 frame = frame->GetNextSibling();
5522 }
5523 if (frame) {
5524 result = frame;
5525 }
5526 } else {
5527 // Because the frame tree is singly linked, to find the last frame,
5528 // we have to iterate through all the frames
5529 // XXX I have a feeling this could be slow for long blocks, although
5530 // I can't find any slowdowns
5531 while (frame) {
5532 if (!frame->IsEmpty() && SelfIsSelectable(frame, aFrame, aFlags)) {
5533 result = frame;
5534 }
5535 frame = frame->GetNextSibling();
5536 }
5537 }
5538 if (result) {
5539 return DrillDownToSelectionFrame(result, aEndFrame, aFlags);
5540 }
5541 }
5542 // If the current frame has no targetable children, target the current frame
5543 return FrameTarget{aFrame, true, aEndFrame};
5544}
5545
5546// This method finds the closest valid FrameTarget on a given line; if there is
5547// no valid FrameTarget on the line, it returns a null FrameTarget
5548static FrameTarget GetSelectionClosestFrameForLine(
5549 nsBlockFrame* aParent, nsBlockFrame::LineIterator aLine,
5550 const nsPoint& aPoint, uint32_t aFlags) {
5551 // Account for end of lines (any iterator from the block is valid)
5552 if (aLine == aParent->LinesEnd()) {
5553 return DrillDownToSelectionFrame(aParent, true, aFlags);
5554 }
5555 nsIFrame* frame = aLine->mFirstChild;
5556 nsIFrame* closestFromIStart = nullptr;
5557 nsIFrame* closestFromIEnd = nullptr;
5558 nscoord closestIStart = aLine->IStart(), closestIEnd = aLine->IEnd();
5559 WritingMode wm = aLine->mWritingMode;
5560 LogicalPoint pt(wm, aPoint, aLine->mContainerSize);
5561 bool canSkipBr = false;
5562 bool lastFrameWasEditable = false;
5563 for (int32_t n = aLine->GetChildCount(); n;
5564 --n, frame = frame->GetNextSibling()) {
5565 // Skip brFrames. Can only skip if the line contains at least
5566 // one selectable and non-empty frame before. Also, avoid skipping brs if
5567 // the previous thing had a different editableness than us, since then we
5568 // may end up not being able to select after it if the br is the last thing
5569 // on the line.
5570 if (!SelfIsSelectable(frame, aParent, aFlags) || frame->IsEmpty() ||
5571 (canSkipBr && frame->IsBrFrame() &&
5572 lastFrameWasEditable == frame->GetContent()->IsEditable())) {
5573 continue;
5574 }
5575 canSkipBr = true;
5576 lastFrameWasEditable =
5577 frame->GetContent() && frame->GetContent()->IsEditable();
5578 LogicalRect frameRect =
5579 LogicalRect(wm, frame->GetRect(), aLine->mContainerSize);
5580 if (pt.I(wm) >= frameRect.IStart(wm)) {
5581 if (pt.I(wm) < frameRect.IEnd(wm)) {
5582 return GetSelectionClosestFrameForChild(frame, aPoint, aFlags);
5583 }
5584 if (frameRect.IEnd(wm) >= closestIStart) {
5585 closestFromIStart = frame;
5586 closestIStart = frameRect.IEnd(wm);
5587 }
5588 } else {
5589 if (frameRect.IStart(wm) <= closestIEnd) {
5590 closestFromIEnd = frame;
5591 closestIEnd = frameRect.IStart(wm);
5592 }
5593 }
5594 }
5595 if (!closestFromIStart && !closestFromIEnd) {
5596 // We should only get here if there are no selectable frames on a line
5597 // XXX Do we need more elaborate handling here?
5598 return FrameTarget();
5599 }
5600 if (closestFromIStart &&
5601 (!closestFromIEnd ||
5602 (abs(pt.I(wm) - closestIStart) <= abs(pt.I(wm) - closestIEnd)))) {
5603 return GetSelectionClosestFrameForChild(closestFromIStart, aPoint, aFlags);
5604 }
5605 return GetSelectionClosestFrameForChild(closestFromIEnd, aPoint, aFlags);
5606}
5607
5608// This method is for the special handling we do for block frames; they're
5609// special because they represent paragraphs and because they are organized
5610// into lines, which have bounds that are not stored elsewhere in the
5611// frame tree. Returns a null FrameTarget for frames which are not
5612// blocks or blocks with no lines except editable one.
5613static FrameTarget GetSelectionClosestFrameForBlock(nsIFrame* aFrame,
5614 const nsPoint& aPoint,
5615 uint32_t aFlags) {
5616 nsBlockFrame* bf = do_QueryFrame(aFrame);
5617 if (!bf) {
5618 return FrameTarget();
5619 }
5620
5621 // This code searches for the correct line
5622 nsBlockFrame::LineIterator end = bf->LinesEnd();
5623 nsBlockFrame::LineIterator curLine = bf->LinesBegin();
5624 nsBlockFrame::LineIterator closestLine = end;
5625
5626 if (curLine != end) {
5627 // Convert aPoint into a LogicalPoint in the writing-mode of this block
5628 WritingMode wm = curLine->mWritingMode;
5629 LogicalPoint pt(wm, aPoint, curLine->mContainerSize);
5630 do {
5631 // Check to see if our point lies within the line's block-direction bounds
5632 nscoord BCoord = pt.B(wm) - curLine->BStart();
5633 nscoord BSize = curLine->BSize();
5634 if (BCoord >= 0 && BCoord < BSize) {
5635 closestLine = curLine;
5636 break; // We found the line; stop looking
5637 }
5638 if (BCoord < 0) break;
5639 ++curLine;
5640 } while (curLine != end);
5641
5642 if (closestLine == end) {
5643 nsBlockFrame::LineIterator prevLine = curLine.prev();
5644 nsBlockFrame::LineIterator nextLine = curLine;
5645 // Avoid empty lines
5646 while (nextLine != end && nextLine->IsEmpty()) ++nextLine;
5647 while (prevLine != end && prevLine->IsEmpty()) --prevLine;
5648
5649 // This hidden pref dictates whether a point above or below all lines
5650 // comes up with a line or the beginning or end of the frame; 0 on
5651 // Windows, 1 on other platforms by default at the writing of this code
5652 int32_t dragOutOfFrame =
5653 Preferences::GetInt("browser.drag_out_of_frame_style");
5654
5655 if (prevLine == end) {
5656 if (dragOutOfFrame == 1 || nextLine == end)
5657 return DrillDownToSelectionFrame(aFrame, false, aFlags);
5658 closestLine = nextLine;
5659 } else if (nextLine == end) {
5660 if (dragOutOfFrame == 1)
5661 return DrillDownToSelectionFrame(aFrame, true, aFlags);
5662 closestLine = prevLine;
5663 } else { // Figure out which line is closer
5664 if (pt.B(wm) - prevLine->BEnd() < nextLine->BStart() - pt.B(wm))
5665 closestLine = prevLine;
5666 else
5667 closestLine = nextLine;
5668 }
5669 }
5670 }
5671
5672 do {
5673 if (auto target =
5674 GetSelectionClosestFrameForLine(bf, closestLine, aPoint, aFlags)) {
5675 return target;
5676 }
5677 ++closestLine;
5678 } while (closestLine != end);
5679
5680 // Fall back to just targeting the last targetable place
5681 return DrillDownToSelectionFrame(aFrame, true, aFlags);
5682}
5683
5684// Use frame edge for grid, flex, table, and non-editable images. Choose the
5685// edge based on the point position past the frame rect. If past the middle,
5686// caret should be at end, otherwise at start. This behavior matches Blink.
5687//
5688// TODO(emilio): Can we use this code path for other replaced elements other
5689// than images? Or even all other frames? We only get there when we didn't find
5690// selectable children... At least one XUL test fails if we make this apply to
5691// XUL labels. Also, editable images need _not_ to use the frame edge, see
5692// below.
5693static bool UseFrameEdge(nsIFrame* aFrame) {
5694 if (aFrame->IsFlexOrGridContainer() || aFrame->IsTableFrame()) {
5695 return true;
5696 }
5697 const nsImageFrame* image = do_QueryFrame(aFrame);
5698 if (image && !aFrame->GetContent()->IsEditable()) {
5699 // Editable images are a special-case because editing relies on clicking on
5700 // an editable image selecting it, for it to show resizers.
5701 return true;
5702 }
5703 return false;
5704}
5705
5706static FrameTarget LastResortFrameTargetForFrame(nsIFrame* aFrame,
5707 const nsPoint& aPoint) {
5708 if (!UseFrameEdge(aFrame)) {
5709 return {aFrame, false, false};
5710 }
5711 const auto& rect = aFrame->GetRectRelativeToSelf();
5712 nscoord reference;
5713 nscoord middle;
5714 if (aFrame->GetWritingMode().IsVertical()) {
5715 reference = aPoint.y;
5716 middle = rect.Height() / 2;
5717 } else {
5718 reference = aPoint.x;
5719 middle = rect.Width() / 2;
5720 }
5721 const bool afterFrame = reference > middle;
5722 return {aFrame, true, afterFrame};
5723}
5724
5725// GetSelectionClosestFrame is the helper function that calculates the closest
5726// frame to the given point.
5727// It doesn't completely account for offset styles, so needs to be used in
5728// restricted environments.
5729// Cannot handle overlapping frames correctly, so it should receive the output
5730// of GetFrameForPoint
5731// Guaranteed to return a valid FrameTarget.
5732// aPoint is relative to aFrame.
5733static FrameTarget GetSelectionClosestFrame(nsIFrame* aFrame,
5734 const nsPoint& aPoint,
5735 uint32_t aFlags) {
5736 // Handle blocks; if the frame isn't a block, the method fails
5737 if (auto target = GetSelectionClosestFrameForBlock(aFrame, aPoint, aFlags)) {
5738 return target;
5739 }
5740
5741 if (aFlags & nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE &&
5742 !FrameContentCanHaveParentSelectionRange(aFrame)) {
5743 return LastResortFrameTargetForFrame(aFrame, aPoint);
5744 }
5745
5746 if (nsIFrame* kid = aFrame->PrincipalChildList().FirstChild()) {
5747 // Go through all the child frames to find the closest one
5748 nsIFrame::FrameWithDistance closest = {nullptr, nscoord_MAX, nscoord_MAX};
5749 for (; kid; kid = kid->GetNextSibling()) {
5750 if (!SelfIsSelectable(kid, aFrame, aFlags) || kid->IsEmpty()) {
5751 continue;
5752 }
5753
5754 kid->FindCloserFrameForSelection(aPoint, &closest);
5755 }
5756 if (closest.mFrame) {
5757 if (closest.mFrame->IsInSVGTextSubtree())
5758 return FrameTarget{closest.mFrame, false, false};
5759 return GetSelectionClosestFrameForChild(closest.mFrame, aPoint, aFlags);
5760 }
5761 }
5762
5763 return LastResortFrameTargetForFrame(aFrame, aPoint);
5764}
5765
5766static nsIFrame::ContentOffsets OffsetsForSingleFrame(nsIFrame* aFrame,
5767 const nsPoint& aPoint) {
5768 nsIFrame::ContentOffsets offsets;
5769 FrameContentRange range = GetRangeForFrame(aFrame);
5770 offsets.content = range.content;
5771 // If there are continuations (meaning it's not one rectangle), this is the
5772 // best this function can do
5773 if (aFrame->GetNextContinuation() || aFrame->GetPrevContinuation()) {
5774 offsets.offset = range.start;
5775 offsets.secondaryOffset = range.end;
5776 offsets.associate = CaretAssociationHint::After;
5777 return offsets;
5778 }
5779
5780 // Figure out whether the offsets should be over, after, or before the frame
5781 nsRect rect(nsPoint(0, 0), aFrame->GetSize());
5782
5783 bool isBlock = !aFrame->StyleDisplay()->IsInlineFlow();
5784 bool isRtl = (aFrame->StyleVisibility()->mDirection == StyleDirection::Rtl);
5785 if ((isBlock && rect.y < aPoint.y) ||
5786 (!isBlock && ((isRtl && rect.x + rect.width / 2 > aPoint.x) ||
5787 (!isRtl && rect.x + rect.width / 2 < aPoint.x)))) {
5788 offsets.offset = range.end;
5789 if (rect.Contains(aPoint))
5790 offsets.secondaryOffset = range.start;
5791 else
5792 offsets.secondaryOffset = range.end;
5793 } else {
5794 offsets.offset = range.start;
5795 if (rect.Contains(aPoint))
5796 offsets.secondaryOffset = range.end;
5797 else
5798 offsets.secondaryOffset = range.start;
5799 }
5800 offsets.associate = offsets.offset == range.start
5801 ? CaretAssociationHint::After
5802 : CaretAssociationHint::Before;
5803 return offsets;
5804}
5805
5806static nsIFrame* AdjustFrameForSelectionStyles(nsIFrame* aFrame) {
5807 nsIFrame* adjustedFrame = aFrame;
5808 for (nsIFrame* frame = aFrame; frame; frame = frame->GetParent()) {
5809 // These are the conditions that make all children not able to handle
5810 // a cursor.
5811 auto userSelect = frame->Style()->UserSelect();
5812 if (userSelect != StyleUserSelect::Auto &&
5813 userSelect != StyleUserSelect::All) {
5814 break;
5815 }
5816 if (userSelect == StyleUserSelect::All ||
5817 frame->IsGeneratedContentFrame()) {
5818 adjustedFrame = frame;
5819 }
5820 }
5821 return adjustedFrame;
5822}
5823
5824nsIFrame::ContentOffsets nsIFrame::GetContentOffsetsFromPoint(
5825 const nsPoint& aPoint, uint32_t aFlags) {
5826 nsIFrame* adjustedFrame;
5827 if (aFlags & IGNORE_SELECTION_STYLE) {
5828 adjustedFrame = this;
5829 } else {
5830 // This section of code deals with special selection styles. Note that
5831 // -moz-all exists, even though it doesn't need to be explicitly handled.
5832 //
5833 // The offset is forced not to end up in generated content; content offsets
5834 // cannot represent content outside of the document's content tree.
5835
5836 adjustedFrame = AdjustFrameForSelectionStyles(this);
5837
5838 // `user-select: all` needs special handling, because clicking on it should
5839 // lead to the whole frame being selected.
5840 if (adjustedFrame->Style()->UserSelect() == StyleUserSelect::All) {
5841 nsPoint adjustedPoint = aPoint + GetOffsetTo(adjustedFrame);
5842 return OffsetsForSingleFrame(adjustedFrame, adjustedPoint);
5843 }
5844
5845 // For other cases, try to find a closest frame starting from the parent of
5846 // the unselectable frame
5847 if (adjustedFrame != this) {
5848 adjustedFrame = adjustedFrame->GetParent();
5849 }
5850 }
5851
5852 nsPoint adjustedPoint = aPoint + GetOffsetTo(adjustedFrame);
5853
5854 FrameTarget closest =
5855 GetSelectionClosestFrame(adjustedFrame, adjustedPoint, aFlags);
5856
5857 // If the correct offset is at one end of a frame, use offset-based
5858 // calculation method
5859 if (closest.frameEdge) {
5860 ContentOffsets offsets;
5861 FrameContentRange range = GetRangeForFrame(closest.frame);
5862 offsets.content = range.content;
5863 if (closest.afterFrame)
5864 offsets.offset = range.end;
5865 else
5866 offsets.offset = range.start;
5867 offsets.secondaryOffset = offsets.offset;
5868 offsets.associate = offsets.offset == range.start
5869 ? CaretAssociationHint::After
5870 : CaretAssociationHint::Before;
5871 return offsets;
5872 }
5873
5874 nsPoint pt;
5875 if (closest.frame != this) {
5876 if (closest.frame->IsInSVGTextSubtree()) {
5877 pt = nsLayoutUtils::TransformAncestorPointToFrame(
5878 RelativeTo{closest.frame}, aPoint, RelativeTo{this});
5879 } else {
5880 pt = aPoint - closest.frame->GetOffsetTo(this);
5881 }
5882 } else {
5883 pt = aPoint;
5884 }
5885 return closest.frame->CalcContentOffsetsFromFramePoint(pt);
5886
5887 // XXX should I add some kind of offset standardization?
5888 // consider <b>xxxxx</b><i>zzzzz</i>; should any click between the last
5889 // x and first z put the cursor in the same logical position in addition
5890 // to the same visual position?
5891}
5892
5893nsIFrame::ContentOffsets nsIFrame::CalcContentOffsetsFromFramePoint(
5894 const nsPoint& aPoint) {
5895 return OffsetsForSingleFrame(this, aPoint);
5896}
5897
5898bool nsIFrame::AssociateImage(const StyleImage& aImage) {
5899 imgRequestProxy* req = aImage.GetImageRequest();
5900 if (!req) {
5901 return false;
5902 }
5903
5904 mozilla::css::ImageLoader* loader =
5905 PresContext()->Document()->StyleImageLoader();
5906
5907 loader->AssociateRequestToFrame(req, this);
5908 return true;
5909}
5910
5911void nsIFrame::DisassociateImage(const StyleImage& aImage) {
5912 imgRequestProxy* req = aImage.GetImageRequest();
5913 if (!req) {
5914 return;
5915 }
5916
5917 mozilla::css::ImageLoader* loader =
5918 PresContext()->Document()->StyleImageLoader();
5919
5920 loader->DisassociateRequestFromFrame(req, this);
5921}
5922
5923StyleImageRendering nsIFrame::UsedImageRendering() const {
5924 ComputedStyle* style;
5925 if (IsCanvasFrame()) {
5926 // XXXdholbert Maybe we should use FindCanvasBackground here (instead of
5927 // FindBackground), since we're inside an IsCanvasFrame check? Though then
5928 // we'd also have to copypaste or abstract-away the multi-part root-frame
5929 // lookup that the canvas-flavored API requires.
5930 style = nsCSSRendering::FindBackground(this);
5931 } else {
5932 style = Style();
5933 }
5934 return style->StyleVisibility()->mImageRendering;
5935}
5936
5937// The touch-action CSS property applies to: all elements except: non-replaced
5938// inline elements, table rows, row groups, table columns, and column groups.
5939StyleTouchAction nsIFrame::UsedTouchAction() const {
5940 if (IsLineParticipant()) {
5941 return StyleTouchAction::AUTO;
5942 }
5943 auto& disp = *StyleDisplay();
5944 if (disp.IsInternalTableStyleExceptCell()) {
5945 return StyleTouchAction::AUTO;
5946 }
5947 return disp.mTouchAction;
5948}
5949
5950nsIFrame::Cursor nsIFrame::GetCursor(const nsPoint&) {
5951 StyleCursorKind kind = StyleUI()->Cursor().keyword;
5952 if (kind == StyleCursorKind::Auto) {
5953 // If this is editable, I-beam cursor is better for most elements.
5954 kind = (mContent && mContent->IsEditable()) ? StyleCursorKind::Text
5955 : StyleCursorKind::Default;
5956 }
5957 if (kind == StyleCursorKind::Text && GetWritingMode().IsVertical()) {
5958 // Per CSS UI spec, UA may treat value 'text' as
5959 // 'vertical-text' for vertical text.
5960 kind = StyleCursorKind::VerticalText;
5961 }
5962
5963 return Cursor{kind, AllowCustomCursorImage::Yes};
5964}
5965
5966// Resize and incremental reflow
5967
5968/* virtual */
5969void nsIFrame::MarkIntrinsicISizesDirty() {
5970 // If we're a flex item, clear our flex-item-specific cached measurements
5971 // (which likely depended on our now-stale intrinsic isize).
5972 if (IsFlexItem()) {
5973 nsFlexContainerFrame::MarkCachedFlexMeasurementsDirty(this);
5974 }
5975
5976 if (HasAnyStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT)) {
5977 nsFontInflationData::MarkFontInflationDataTextDirty(this);
5978 }
5979
5980 RemoveProperty(nsGridContainerFrame::CachedBAxisMeasurement::Prop());
5981}
5982
5983void nsIFrame::MarkSubtreeDirty() {
5984 if (HasAnyStateBits(NS_FRAME_IS_DIRTY)) {
5985 return;
5986 }
5987 // Unconditionally mark given frame dirty.
5988 AddStateBits(NS_FRAME_IS_DIRTY);
5989
5990 // Mark all descendants dirty, unless:
5991 // - Already dirty.
5992 // - TableColGroup
5993 AutoTArray<nsIFrame*, 32> stack;
5994 for (const auto& childLists : ChildLists()) {
5995 for (nsIFrame* kid : childLists.mList) {
5996 stack.AppendElement(kid);
5997 }
5998 }
5999 while (!stack.IsEmpty()) {
6000 nsIFrame* f = stack.PopLastElement();
6001 if (f->HasAnyStateBits(NS_FRAME_IS_DIRTY) || f->IsTableColGroupFrame()) {
6002 continue;
6003 }
6004
6005 f->AddStateBits(NS_FRAME_IS_DIRTY);
6006
6007 for (const auto& childLists : f->ChildLists()) {
6008 for (nsIFrame* kid : childLists.mList) {
6009 stack.AppendElement(kid);
6010 }
6011 }
6012 }
6013}
6014
6015/* virtual */
6016void nsIFrame::AddInlineMinISize(const IntrinsicSizeInput& aInput,
6017 InlineMinISizeData* aData) {
6018 // Note: we are one of the children that mPercentageBasisForChildren was
6019 // prepared for (i.e. our parent frame prepares the percentage basis for us,
6020 // not for our own children). Hence it's fine that we're resolving our
6021 // percentages sizes against this basis in IntrinsicForContainer().
6022 nscoord isize = nsLayoutUtils::IntrinsicForContainer(
6023 aInput.mContext, this, IntrinsicISizeType::MinISize,
6024 aInput.mPercentageBasisForChildren);
6025 aData->DefaultAddInlineMinISize(this, isize);
6026}
6027
6028/* virtual */
6029void nsIFrame::AddInlinePrefISize(const IntrinsicSizeInput& aInput,
6030 nsIFrame::InlinePrefISizeData* aData) {
6031 // Note: we are one of the children that mPercentageBasisForChildren was
6032 // prepared for (i.e. our parent frame prepares the percentage basis for us,
6033 // not for our own children). Hence it's fine that we're resolving our
6034 // percentages sizes against this basis in IntrinsicForContainer().
6035 nscoord isize = nsLayoutUtils::IntrinsicForContainer(
6036 aInput.mContext, this, IntrinsicISizeType::PrefISize,
6037 aInput.mPercentageBasisForChildren);
6038 aData->DefaultAddInlinePrefISize(isize);
6039}
6040
6041void nsIFrame::InlineMinISizeData::DefaultAddInlineMinISize(nsIFrame* aFrame,
6042 nscoord aISize,
6043 bool aAllowBreak) {
6044 auto parent = aFrame->GetParent();
6045 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"
, 6045); AnnotateMozCrashReason("MOZ_ASSERT" "(" "parent" ") ("
"Must have a parent if we get here!" ")"); do { *((volatile int
*)__null) = 6045; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
6046 const bool mayBreak = aAllowBreak && !aFrame->CanContinueTextRun() &&
6047 !parent->Style()->ShouldSuppressLineBreak() &&
6048 parent->StyleText()->WhiteSpaceCanWrap(parent);
6049 if (mayBreak) {
6050 OptionallyBreak();
6051 }
6052 mTrailingWhitespace = 0;
6053 mSkipWhitespace = false;
6054 mCurrentLine += aISize;
6055 mAtStartOfLine = false;
6056 if (mayBreak) {
6057 OptionallyBreak();
6058 }
6059}
6060
6061void nsIFrame::InlinePrefISizeData::DefaultAddInlinePrefISize(nscoord aISize) {
6062 mCurrentLine = NSCoordSaturatingAdd(mCurrentLine, aISize);
6063 mTrailingWhitespace = 0;
6064 mSkipWhitespace = false;
6065 mLineIsEmpty = false;
6066}
6067
6068void nsIFrame::InlineMinISizeData::ForceBreak() {
6069 mCurrentLine -= mTrailingWhitespace;
6070 mPrevLines = std::max(mPrevLines, mCurrentLine);
6071 mCurrentLine = mTrailingWhitespace = 0;
6072
6073 for (const FloatInfo& floatInfo : mFloats) {
6074 mPrevLines = std::max(floatInfo.ISize(), mPrevLines);
6075 }
6076 mFloats.Clear();
6077 mSkipWhitespace = true;
6078}
6079
6080void nsIFrame::InlineMinISizeData::OptionallyBreak(nscoord aHyphenWidth) {
6081 // If we can fit more content into a smaller width by staying on this
6082 // line (because we're still at a negative offset due to negative
6083 // text-indent or negative margin), don't break. Otherwise, do the
6084 // same as ForceBreak. it doesn't really matter when we accumulate
6085 // floats.
6086 if (mCurrentLine + aHyphenWidth < 0 || mAtStartOfLine) return;
6087 mCurrentLine += aHyphenWidth;
6088 ForceBreak();
6089}
6090
6091void nsIFrame::InlinePrefISizeData::ForceBreak(StyleClear aClearType) {
6092 // If this force break is not clearing any float, we can leave all the
6093 // floats to the next force break.
6094 if (!mFloats.IsEmpty() && aClearType != StyleClear::None) {
6095 // Preferred isize accumulated for floats that have already
6096 // been cleared past
6097 nscoord floatsDone = 0;
6098 // Preferred isize accumulated for floats that have not yet
6099 // been cleared past
6100 nscoord floatsCurLeft = 0, floatsCurRight = 0;
6101
6102 for (const FloatInfo& floatInfo : mFloats) {
6103 const nsStyleDisplay* floatDisp = floatInfo.Frame()->StyleDisplay();
6104 StyleClear clearType = floatDisp->mClear;
6105 if (clearType == StyleClear::Left || clearType == StyleClear::Right ||
6106 clearType == StyleClear::Both) {
6107 nscoord floatsCur = NSCoordSaturatingAdd(floatsCurLeft, floatsCurRight);
6108 if (floatsCur > floatsDone) {
6109 floatsDone = floatsCur;
6110 }
6111 if (clearType != StyleClear::Right) {
6112 floatsCurLeft = 0;
6113 }
6114 if (clearType != StyleClear::Left) {
6115 floatsCurRight = 0;
6116 }
6117 }
6118
6119 StyleFloat floatStyle = floatDisp->mFloat;
6120 nscoord& floatsCur =
6121 floatStyle == StyleFloat::Left ? floatsCurLeft : floatsCurRight;
6122 nscoord floatISize = floatInfo.ISize();
6123 // Negative-width floats don't change the available space so they
6124 // shouldn't change our intrinsic line isize either.
6125 floatsCur = NSCoordSaturatingAdd(floatsCur, std::max(0, floatISize));
6126 }
6127
6128 nscoord floatsCur = NSCoordSaturatingAdd(floatsCurLeft, floatsCurRight);
6129 if (floatsCur > floatsDone) {
6130 floatsDone = floatsCur;
6131 }
6132
6133 mCurrentLine = NSCoordSaturatingAdd(mCurrentLine, floatsDone);
6134
6135 if (aClearType == StyleClear::Both) {
6136 mFloats.Clear();
6137 } else {
6138 // If the break type does not clear all floats, it means there may
6139 // be some floats whose isize should contribute to the intrinsic
6140 // isize of the next line. The code here scans the current mFloats
6141 // and keeps floats which are not cleared by this break. Note that
6142 // floats may be cleared directly or indirectly. See below.
6143 nsTArray<FloatInfo> newFloats;
6144 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"
, 6146); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aClearType == StyleClear::Left || aClearType == StyleClear::Right"
") (" "Other values should have been handled in other branches"
")"); do { *((volatile int*)__null) = 6146; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6145 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"
, 6146); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aClearType == StyleClear::Left || aClearType == StyleClear::Right"
") (" "Other values should have been handled in other branches"
")"); do { *((volatile int*)__null) = 6146; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6146 "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"
, 6146); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aClearType == StyleClear::Left || aClearType == StyleClear::Right"
") (" "Other values should have been handled in other branches"
")"); do { *((volatile int*)__null) = 6146; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6147 StyleFloat clearFloatType =
6148 aClearType == StyleClear::Left ? StyleFloat::Left : StyleFloat::Right;
6149 // Iterate the array in reverse so that we can stop when there are
6150 // no longer any floats we need to keep. See below.
6151 for (FloatInfo& floatInfo : Reversed(mFloats)) {
6152 const nsStyleDisplay* floatDisp = floatInfo.Frame()->StyleDisplay();
6153 if (floatDisp->mFloat != clearFloatType) {
6154 newFloats.AppendElement(floatInfo);
6155 } else {
6156 // This is a float on the side that this break directly clears
6157 // which means we're not keeping it in mFloats. However, if
6158 // this float clears floats on the opposite side (via a value
6159 // of either 'both' or one of 'left'/'right'), any remaining
6160 // (earlier) floats on that side would be indirectly cleared
6161 // as well. Thus, we should break out of this loop and stop
6162 // considering earlier floats to be kept in mFloats.
6163 StyleClear clearType = floatDisp->mClear;
6164 if (clearType != aClearType && clearType != StyleClear::None) {
6165 break;
6166 }
6167 }
6168 }
6169 newFloats.Reverse();
6170 mFloats = std::move(newFloats);
6171 }
6172 }
6173
6174 mCurrentLine =
6175 NSCoordSaturatingSubtract(mCurrentLine, mTrailingWhitespace, nscoord_MAX);
6176 mPrevLines = std::max(mPrevLines, mCurrentLine);
6177 mCurrentLine = mTrailingWhitespace = 0;
6178 mSkipWhitespace = true;
6179 mLineIsEmpty = true;
6180}
6181
6182static nscoord ResolveMargin(const LengthPercentageOrAuto& aStyle,
6183 nscoord aPercentageBasis) {
6184 if (aStyle.IsAuto()) {
6185 return nscoord(0);
6186 }
6187 return nsLayoutUtils::ResolveToLength<false>(aStyle.AsLengthPercentage(),
6188 aPercentageBasis);
6189}
6190
6191static nscoord ResolvePadding(const LengthPercentage& aStyle,
6192 nscoord aPercentageBasis) {
6193 return nsLayoutUtils::ResolveToLength<true>(aStyle, aPercentageBasis);
6194}
6195
6196static nsIFrame::IntrinsicSizeOffsetData IntrinsicSizeOffsets(
6197 nsIFrame* aFrame, nscoord aPercentageBasis, bool aForISize) {
6198 nsIFrame::IntrinsicSizeOffsetData result;
6199 WritingMode wm = aFrame->GetWritingMode();
6200 const auto& margin = aFrame->StyleMargin()->mMargin;
6201 bool verticalAxis = aForISize == wm.IsVertical();
6202 if (verticalAxis) {
6203 result.margin += ResolveMargin(margin.Get(eSideTop), aPercentageBasis);
6204 result.margin += ResolveMargin(margin.Get(eSideBottom), aPercentageBasis);
6205 } else {
6206 result.margin += ResolveMargin(margin.Get(eSideLeft), aPercentageBasis);
6207 result.margin += ResolveMargin(margin.Get(eSideRight), aPercentageBasis);
6208 }
6209
6210 const auto& padding = aFrame->StylePadding()->mPadding;
6211 if (verticalAxis) {
6212 result.padding += ResolvePadding(padding.Get(eSideTop), aPercentageBasis);
6213 result.padding +=
6214 ResolvePadding(padding.Get(eSideBottom), aPercentageBasis);
6215 } else {
6216 result.padding += ResolvePadding(padding.Get(eSideLeft), aPercentageBasis);
6217 result.padding += ResolvePadding(padding.Get(eSideRight), aPercentageBasis);
6218 }
6219
6220 const nsStyleBorder* styleBorder = aFrame->StyleBorder();
6221 if (verticalAxis) {
6222 result.border += styleBorder->GetComputedBorderWidth(eSideTop);
6223 result.border += styleBorder->GetComputedBorderWidth(eSideBottom);
6224 } else {
6225 result.border += styleBorder->GetComputedBorderWidth(eSideLeft);
6226 result.border += styleBorder->GetComputedBorderWidth(eSideRight);
6227 }
6228
6229 const nsStyleDisplay* disp = aFrame->StyleDisplay();
6230 if (aFrame->IsThemed(disp)) {
6231 nsPresContext* presContext = aFrame->PresContext();
6232
6233 LayoutDeviceIntMargin border = presContext->Theme()->GetWidgetBorder(
6234 presContext->DeviceContext(), aFrame, disp->EffectiveAppearance());
6235 result.border = presContext->DevPixelsToAppUnits(
6236 verticalAxis ? border.TopBottom() : border.LeftRight());
6237
6238 LayoutDeviceIntMargin padding;
6239 if (presContext->Theme()->GetWidgetPadding(
6240 presContext->DeviceContext(), aFrame, disp->EffectiveAppearance(),
6241 &padding)) {
6242 result.padding = presContext->DevPixelsToAppUnits(
6243 verticalAxis ? padding.TopBottom() : padding.LeftRight());
6244 }
6245 }
6246 return result;
6247}
6248
6249/* virtual */ nsIFrame::IntrinsicSizeOffsetData nsIFrame::IntrinsicISizeOffsets(
6250 nscoord aPercentageBasis) {
6251 return IntrinsicSizeOffsets(this, aPercentageBasis, true);
6252}
6253
6254nsIFrame::IntrinsicSizeOffsetData nsIFrame::IntrinsicBSizeOffsets(
6255 nscoord aPercentageBasis) {
6256 return IntrinsicSizeOffsets(this, aPercentageBasis, false);
6257}
6258
6259/* virtual */
6260IntrinsicSize nsIFrame::GetIntrinsicSize() {
6261 // Defaults to no intrinsic size.
6262 return IntrinsicSize();
6263}
6264
6265AspectRatio nsIFrame::GetAspectRatio() const {
6266 // Per spec, 'aspect-ratio' property applies to all elements except inline
6267 // boxes and internal ruby or table boxes.
6268 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio
6269 // For those frame types that don't support aspect-ratio, they must not have
6270 // the natural ratio, so this early return is fine.
6271 if (!SupportsAspectRatio()) {
6272 return AspectRatio();
6273 }
6274
6275 const StyleAspectRatio& aspectRatio = StylePosition()->mAspectRatio;
6276 // If aspect-ratio is zero or infinite, it's a degenerate ratio and behaves
6277 // as auto.
6278 // https://drafts.csswg.org/css-sizing-4/#valdef-aspect-ratio-ratio
6279 if (!aspectRatio.BehavesAsAuto()) {
6280 // Non-auto. Return the preferred aspect ratio from the aspect-ratio style.
6281 return aspectRatio.ratio.AsRatio().ToLayoutRatio(UseBoxSizing::Yes);
6282 }
6283
6284 // The rest of the cases are when aspect-ratio has 'auto'.
6285 if (auto intrinsicRatio = GetIntrinsicRatio()) {
6286 return intrinsicRatio;
6287 }
6288
6289 if (aspectRatio.HasRatio()) {
6290 // If it's a degenerate ratio, this returns 0. Just the same as the auto
6291 // case.
6292 return aspectRatio.ratio.AsRatio().ToLayoutRatio(UseBoxSizing::No);
6293 }
6294
6295 return AspectRatio();
6296}
6297
6298/* virtual */
6299AspectRatio nsIFrame::GetIntrinsicRatio() const { return AspectRatio(); }
6300
6301static bool ShouldApplyAutomaticMinimumOnInlineAxis(
6302 WritingMode aWM, const nsStyleDisplay* aDisplay,
6303 const nsStylePosition* aPosition) {
6304 // Apply the automatic minimum size for aspect ratio:
6305 // Note: The replaced elements shouldn't be here, so we only check the scroll
6306 // container.
6307 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum
6308 return !aDisplay->IsScrollableOverflow() && aPosition->MinISize(aWM).IsAuto();
6309}
6310
6311/* virtual */
6312nsIFrame::SizeComputationResult nsIFrame::ComputeSize(
6313 gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
6314 nscoord aAvailableISize, const LogicalSize& aMargin,
6315 const LogicalSize& aBorderPadding, const StyleSizeOverrides& aSizeOverrides,
6316 ComputeSizeFlags aFlags) {
6317 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"
, 6319); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetIntrinsicRatio()"
") (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")"); do { *((volatile int*)__null) = 6319; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6318 "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"
, 6319); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetIntrinsicRatio()"
") (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")"); do { *((volatile int*)__null) = 6319; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6319 "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"
, 6319); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetIntrinsicRatio()"
") (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")"); do { *((volatile int*)__null) = 6319; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6320 LogicalSize result =
6321 ComputeAutoSize(aRenderingContext, aWM, aCBSize, aAvailableISize, aMargin,
6322 aBorderPadding, aSizeOverrides, aFlags);
6323 const nsStylePosition* stylePos = StylePosition();
6324 const nsStyleDisplay* disp = StyleDisplay();
6325 auto aspectRatioUsage = AspectRatioUsage::None;
6326
6327 const auto boxSizingAdjust = stylePos->mBoxSizing == StyleBoxSizing::Border
6328 ? aBorderPadding
6329 : LogicalSize(aWM);
6330 nscoord boxSizingToMarginEdgeISize = aMargin.ISize(aWM) +
6331 aBorderPadding.ISize(aWM) -
6332 boxSizingAdjust.ISize(aWM);
6333
6334 const auto& styleISize = aSizeOverrides.mStyleISize
6335 ? *aSizeOverrides.mStyleISize
6336 : stylePos->ISize(aWM);
6337 const auto& styleBSize = aSizeOverrides.mStyleBSize
6338 ? *aSizeOverrides.mStyleBSize
6339 : stylePos->BSize(aWM);
6340 const auto& aspectRatio = aSizeOverrides.mAspectRatio
6341 ? *aSizeOverrides.mAspectRatio
6342 : GetAspectRatio();
6343
6344 auto parentFrame = GetParent();
6345 auto alignCB = parentFrame;
6346 bool isGridItem = IsGridItem();
6347 const bool isSubgrid = IsSubgrid();
6348 if (parentFrame && parentFrame->IsTableWrapperFrame() && IsTableFrame()) {
6349 // An inner table frame is sized as a grid item if its table wrapper is,
6350 // because they actually have the same CB (the wrapper's CB).
6351 // @see ReflowInput::InitCBReflowInput
6352 auto tableWrapper = GetParent();
6353 auto grandParent = tableWrapper->GetParent();
6354 isGridItem = grandParent->IsGridContainerFrame() &&
6355 !tableWrapper->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW);
6356 if (isGridItem) {
6357 // When resolving justify/align-self below, we want to use the grid
6358 // container's justify/align-items value and WritingMode.
6359 alignCB = grandParent;
6360 }
6361 }
6362 const bool isFlexItem =
6363 IsFlexItem() && !parentFrame->HasAnyStateBits(
6364 NS_STATE_FLEX_IS_EMULATING_LEGACY_WEBKIT_BOX);
6365 // This variable only gets set (and used) if isFlexItem is true. It
6366 // indicates which axis (in this frame's own WM) corresponds to its
6367 // flex container's main axis.
6368 LogicalAxis flexMainAxis =
6369 LogicalAxis::Inline; // (init to make valgrind happy)
6370 if (isFlexItem) {
6371 flexMainAxis = nsFlexContainerFrame::IsItemInlineAxisMainAxis(this)
6372 ? LogicalAxis::Inline
6373 : LogicalAxis::Block;
6374 }
6375
6376 const bool isOrthogonal = aWM.IsOrthogonalTo(alignCB->GetWritingMode());
6377 const bool isAutoISize = styleISize.IsAuto();
6378 const bool isAutoBSize =
6379 nsLayoutUtils::IsAutoBSize(styleBSize, aCBSize.BSize(aWM));
6380
6381 // Compute inline-axis size
6382 const bool isSubgriddedInInlineAxis =
6383 isSubgrid && static_cast<nsGridContainerFrame*>(this)->IsColSubgrid();
6384
6385 // Per https://drafts.csswg.org/css-grid/#subgrid-box-alignment, if we are
6386 // subgridded in the inline-axis, ignore our style inline-size, and stretch to
6387 // fill the CB.
6388 const bool shouldComputeISize = !isAutoISize && !isSubgriddedInInlineAxis;
6389 if (shouldComputeISize) {
6390 auto iSizeResult =
6391 ComputeISizeValue(aRenderingContext, aWM, aCBSize, boxSizingAdjust,
6392 boxSizingToMarginEdgeISize, styleISize, styleBSize,
6393 aspectRatio, aFlags);
6394 result.ISize(aWM) = iSizeResult.mISize;
6395 aspectRatioUsage = iSizeResult.mAspectRatioUsage;
6396 } else if (MOZ_UNLIKELY(isGridItem)(__builtin_expect(!!(isGridItem), 0)) && !IsTrueOverflowContainer()) {
6397 // 'auto' inline-size for grid-level box - fill the CB for 'stretch' /
6398 // 'normal' and clamp it to the CB if requested:
6399 bool stretch = false;
6400 bool mayUseAspectRatio = aspectRatio && !isAutoBSize;
6401 if (!aFlags.contains(ComputeSizeFlag::ShrinkWrap) &&
6402 !StyleMargin()->HasInlineAxisAuto(aWM) &&
6403 !alignCB->IsMasonry(isOrthogonal ? LogicalAxis::Block
6404 : LogicalAxis::Inline)) {
6405 auto inlineAxisAlignment =
6406 isOrthogonal ? StylePosition()->UsedAlignSelf(alignCB->Style())._0
6407 : StylePosition()->UsedJustifySelf(alignCB->Style())._0;
6408 stretch = inlineAxisAlignment == StyleAlignFlags::STRETCH ||
6409 (inlineAxisAlignment == StyleAlignFlags::NORMAL &&
6410 !mayUseAspectRatio);
6411 }
6412
6413 // Apply the preferred aspect ratio for alignments other than *stretch* and
6414 // *normal without aspect ratio*.
6415 // The spec says all other values should size the items as fit-content, and
6416 // the intrinsic size should respect the preferred aspect ratio, so we also
6417 // apply aspect ratio for all other values.
6418 // https://drafts.csswg.org/css-grid/#grid-item-sizing
6419 if (!stretch && mayUseAspectRatio) {
6420 result.ISize(aWM) = ComputeISizeValueFromAspectRatio(
6421 aWM, aCBSize, boxSizingAdjust, styleBSize.AsLengthPercentage(),
6422 aspectRatio);
6423 aspectRatioUsage = AspectRatioUsage::ToComputeISize;
6424 }
6425
6426 if (stretch || aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize)) {
6427 auto iSizeToFillCB =
6428 std::max(nscoord(0), aCBSize.ISize(aWM) - aBorderPadding.ISize(aWM) -
6429 aMargin.ISize(aWM));
6430 if (stretch || result.ISize(aWM) > iSizeToFillCB) {
6431 result.ISize(aWM) = iSizeToFillCB;
6432 }
6433 }
6434 } else if (aspectRatio && !isAutoBSize) {
6435 // Note: if both the inline size and the block size are auto, the block axis
6436 // is the ratio-dependent axis by default. That means we only need to
6437 // transfer the resolved inline size via aspect-ratio to block axis later in
6438 // this method, but not the other way around.
6439 //
6440 // In this branch, we transfer the non-auto block size via aspect-ration to
6441 // inline axis.
6442 result.ISize(aWM) = ComputeISizeValueFromAspectRatio(
6443 aWM, aCBSize, boxSizingAdjust, styleBSize.AsLengthPercentage(),
6444 aspectRatio);
6445 aspectRatioUsage = AspectRatioUsage::ToComputeISize;
6446 }
6447
6448 // Calculate and apply transferred min & max size contraints.
6449 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-size-transfers
6450 //
6451 // Note: The basic principle is that sizing constraints transfer through the
6452 // aspect-ratio to the other side to preserve the aspect ratio to the extent
6453 // that they can without violating any sizes specified explicitly on that
6454 // affected axis.
6455 //
6456 // FIXME: The spec words may not be correct, so we may have to update this
6457 // tentative solution once this spec issue gets resolved. Here, we clamp the
6458 // flex base size by the transferred min and max sizes, and don't include
6459 // the transferred min & max sizes into its used min & max sizes. So this
6460 // lets us match other browsers' current behaviors.
6461 // https://github.com/w3c/csswg-drafts/issues/6071
6462 //
6463 // Note: This may make more sense if we clamp the flex base size in
6464 // FlexItem::ResolveFlexBaseSizeFromAspectRatio(). However, the result should
6465 // be identical. FlexItem::ResolveFlexBaseSizeFromAspectRatio() only handles
6466 // the case of the definite cross size, and the definite cross size is clamped
6467 // by the min & max cross sizes below in this function. This means its flex
6468 // base size has been clamped by the transferred min & max size already after
6469 // generating the flex items. So here we make the code more general for both
6470 // definite cross size and indefinite cross size.
6471 const bool isDefiniteISize = styleISize.IsLengthPercentage();
6472 const auto& minBSizeCoord = stylePos->MinBSize(aWM);
6473 const auto& maxBSizeCoord = stylePos->MaxBSize(aWM);
6474 const bool isAutoMinBSize =
6475 nsLayoutUtils::IsAutoBSize(minBSizeCoord, aCBSize.BSize(aWM));
6476 const bool isAutoMaxBSize =
6477 nsLayoutUtils::IsAutoBSize(maxBSizeCoord, aCBSize.BSize(aWM));
6478 if (aspectRatio && !isDefiniteISize) {
6479 // Note: the spec mentions that
6480 // 1. This transferred minimum is capped by any definite preferred or
6481 // maximum size in the destination axis.
6482 // 2. This transferred maximum is floored by any definite preferred or
6483 // minimum size in the destination axis.
6484 //
6485 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-size-transfers
6486 //
6487 // The spec requires us to clamp these by the specified size (it calls it
6488 // the preferred size). However, we actually don't need to worry about that,
6489 // because we are here only if the inline size is indefinite.
6490 //
6491 // We do not need to clamp the transferred minimum and maximum as long as we
6492 // always apply the transferred min/max size before the explicit min/max
6493 // size; the result will be identical.
6494 const nscoord transferredMinISize =
6495 isAutoMinBSize ? 0
6496 : ComputeISizeValueFromAspectRatio(
6497 aWM, aCBSize, boxSizingAdjust,
6498 minBSizeCoord.AsLengthPercentage(), aspectRatio);
6499 const nscoord transferredMaxISize =
6500 isAutoMaxBSize ? nscoord_MAX
6501 : ComputeISizeValueFromAspectRatio(
6502 aWM, aCBSize, boxSizingAdjust,
6503 maxBSizeCoord.AsLengthPercentage(), aspectRatio);
6504
6505 result.ISize(aWM) =
6506 CSSMinMax(result.ISize(aWM), transferredMinISize, transferredMaxISize);
6507 }
6508
6509 // Flex items ignore their min & max sizing properties in their
6510 // flex container's main-axis. (Those properties get applied later in
6511 // the flexbox algorithm.)
6512 const bool isFlexItemInlineAxisMainAxis =
6513 isFlexItem && flexMainAxis == LogicalAxis::Inline;
6514 // Grid items that are subgridded in inline-axis also ignore their min & max
6515 // sizing properties in that axis.
6516 const bool shouldIgnoreMinMaxISize =
6517 isFlexItemInlineAxisMainAxis || isSubgriddedInInlineAxis;
6518 const auto& maxISizeCoord = stylePos->MaxISize(aWM);
6519 nscoord maxISize = NS_UNCONSTRAINEDSIZE;
6520 if (!maxISizeCoord.IsNone() && !shouldIgnoreMinMaxISize) {
6521 maxISize = ComputeISizeValue(aRenderingContext, aWM, aCBSize,
6522 boxSizingAdjust, boxSizingToMarginEdgeISize,
6523 maxISizeCoord, styleBSize, aspectRatio, aFlags)
6524 .mISize;
6525 result.ISize(aWM) = std::min(maxISize, result.ISize(aWM));
6526 }
6527
6528 const IntrinsicSizeInput input(aRenderingContext,
6529 Some(aCBSize.ConvertTo(GetWritingMode(), aWM)),
6530 Nothing());
6531 const auto& minISizeCoord = stylePos->MinISize(aWM);
6532 nscoord minISize;
6533 if (!minISizeCoord.IsAuto() && !shouldIgnoreMinMaxISize) {
6534 minISize = ComputeISizeValue(aRenderingContext, aWM, aCBSize,
6535 boxSizingAdjust, boxSizingToMarginEdgeISize,
6536 minISizeCoord, styleBSize, aspectRatio, aFlags)
6537 .mISize;
6538 } else if (MOZ_UNLIKELY((__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IApplyAutoMinSize
)), 0))
6539 aFlags.contains(ComputeSizeFlag::IApplyAutoMinSize))(__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IApplyAutoMinSize
)), 0))
) {
6540 // This implements "Implied Minimum Size of Grid Items".
6541 // https://drafts.csswg.org/css-grid/#min-size-auto
6542 minISize = std::min(maxISize, GetMinISize(input));
6543 if (styleISize.IsLengthPercentage()) {
6544 minISize = std::min(minISize, result.ISize(aWM));
6545 } else if (aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize)) {
6546 // "if the grid item spans only grid tracks that have a fixed max track
6547 // sizing function, its automatic minimum size in that dimension is
6548 // further clamped to less than or equal to the size necessary to fit
6549 // its margin box within the resulting grid area (flooring at zero)"
6550 // https://drafts.csswg.org/css-grid/#min-size-auto
6551 auto maxMinISize =
6552 std::max(nscoord(0), aCBSize.ISize(aWM) - aBorderPadding.ISize(aWM) -
6553 aMargin.ISize(aWM));
6554 minISize = std::min(minISize, maxMinISize);
6555 }
6556 } else if (aspectRatioUsage == AspectRatioUsage::ToComputeISize &&
6557 ShouldApplyAutomaticMinimumOnInlineAxis(aWM, disp, stylePos)) {
6558 // This means we successfully applied aspect-ratio and now need to check
6559 // if we need to apply the automatic content-based minimum size:
6560 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum
6561 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"
, 6562); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasReplacedSizing()"
") (" "aspect-ratio minimums should not apply to replaced elements"
")"); do { *((volatile int*)__null) = 6562; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6562 "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"
, 6562); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasReplacedSizing()"
") (" "aspect-ratio minimums should not apply to replaced elements"
")"); do { *((volatile int*)__null) = 6562; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6563 // The inline size computed by aspect-ratio shouldn't less than the
6564 // min-content size, which should be capped by its maximum inline size.
6565 minISize = std::min(GetMinISize(input), maxISize);
6566 } else {
6567 // Treat "min-width: auto" as 0.
6568 // NOTE: Technically, "auto" is supposed to behave like "min-content" on
6569 // flex items. However, we don't need to worry about that here, because
6570 // flex items' min-sizes are intentionally ignored until the flex
6571 // container explicitly considers them during space distribution.
6572 minISize = 0;
6573 }
6574 result.ISize(aWM) = std::max(minISize, result.ISize(aWM));
6575
6576 // Compute block-axis size
6577 // (but not if we have auto bsize -- then, we'll just stick with the bsize
6578 // that we already calculated in the initial ComputeAutoSize() call. However,
6579 // if we have a valid preferred aspect ratio, we still have to compute the
6580 // block size because aspect ratio affects the intrinsic content size.)
6581 const bool isSubgriddedInBlockAxis =
6582 isSubgrid && static_cast<nsGridContainerFrame*>(this)->IsRowSubgrid();
6583
6584 // Per https://drafts.csswg.org/css-grid/#subgrid-box-alignment, if we are
6585 // subgridded in the block-axis, ignore our style block-size, and stretch to
6586 // fill the CB.
6587 const bool shouldComputeBSize = !isAutoBSize && !isSubgriddedInBlockAxis;
6588 if (shouldComputeBSize) {
6589 result.BSize(aWM) = nsLayoutUtils::ComputeBSizeValue(
6590 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6591 styleBSize.AsLengthPercentage());
6592 } else if (MOZ_UNLIKELY(isGridItem)(__builtin_expect(!!(isGridItem), 0)) && styleBSize.IsAuto() &&
6593 !aFlags.contains(ComputeSizeFlag::IsGridMeasuringReflow) &&
6594 !IsTrueOverflowContainer() &&
6595 !alignCB->IsMasonry(isOrthogonal ? LogicalAxis::Inline
6596 : LogicalAxis::Block)) {
6597 auto cbSize = aCBSize.BSize(aWM);
6598 if (cbSize != NS_UNCONSTRAINEDSIZE) {
6599 // 'auto' block-size for grid-level box - fill the CB for 'stretch' /
6600 // 'normal' and clamp it to the CB if requested:
6601 bool stretch = false;
6602 bool mayUseAspectRatio =
6603 aspectRatio && result.ISize(aWM) != NS_UNCONSTRAINEDSIZE;
6604 if (!StyleMargin()->HasBlockAxisAuto(aWM)) {
6605 auto blockAxisAlignment =
6606 isOrthogonal ? StylePosition()->UsedJustifySelf(alignCB->Style())._0
6607 : StylePosition()->UsedAlignSelf(alignCB->Style())._0;
6608 stretch = blockAxisAlignment == StyleAlignFlags::STRETCH ||
6609 (blockAxisAlignment == StyleAlignFlags::NORMAL &&
6610 !mayUseAspectRatio);
6611 }
6612
6613 // Apply the preferred aspect ratio for alignments other than *stretch*
6614 // and *normal without aspect ratio*.
6615 // The spec says all other values should size the items as fit-content,
6616 // and the intrinsic size should respect the preferred aspect ratio, so
6617 // we also apply aspect ratio for all other values.
6618 // https://drafts.csswg.org/css-grid/#grid-item-sizing
6619 if (!stretch && mayUseAspectRatio) {
6620 result.BSize(aWM) = aspectRatio.ComputeRatioDependentSize(
6621 LogicalAxis::Block, aWM, result.ISize(aWM), boxSizingAdjust);
6622 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"
, 6622); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aspectRatioUsage == AspectRatioUsage::None"
")"); do { *((volatile int*)__null) = 6622; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6623 aspectRatioUsage = AspectRatioUsage::ToComputeBSize;
6624 }
6625
6626 if (stretch || aFlags.contains(ComputeSizeFlag::BClampMarginBoxMinSize)) {
6627 auto bSizeToFillCB =
6628 std::max(nscoord(0),
6629 cbSize - aBorderPadding.BSize(aWM) - aMargin.BSize(aWM));
6630 if (stretch || (result.BSize(aWM) != NS_UNCONSTRAINEDSIZE &&
6631 result.BSize(aWM) > bSizeToFillCB)) {
6632 result.BSize(aWM) = bSizeToFillCB;
6633 }
6634 }
6635 }
6636 } else if (aspectRatio) {
6637 // If both inline and block dimensions are auto, the block axis is the
6638 // ratio-dependent axis by default.
6639 // If we have a super large inline size, aspect-ratio should still be
6640 // applied (so aspectRatioUsage flag is set as expected). That's why we
6641 // apply aspect-ratio unconditionally for auto block size here.
6642 result.BSize(aWM) = aspectRatio.ComputeRatioDependentSize(
6643 LogicalAxis::Block, aWM, result.ISize(aWM), boxSizingAdjust);
6644 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"
, 6644); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aspectRatioUsage == AspectRatioUsage::None"
")"); do { *((volatile int*)__null) = 6644; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6645 aspectRatioUsage = AspectRatioUsage::ToComputeBSize;
6646 }
6647
6648 if (result.BSize(aWM) != NS_UNCONSTRAINEDSIZE) {
6649 // Flex items ignore their min & max sizing properties in their flex
6650 // container's main-axis. (Those properties get applied later in the flexbox
6651 // algorithm.)
6652 const bool isFlexItemBlockAxisMainAxis =
6653 isFlexItem && flexMainAxis == LogicalAxis::Block;
6654 // Grid items that are subgridded in block-axis also ignore their min & max
6655 // sizing properties in that axis.
6656 const bool shouldIgnoreMinMaxBSize =
6657 isFlexItemBlockAxisMainAxis || isSubgriddedInBlockAxis;
6658 if (!isAutoMaxBSize && !shouldIgnoreMinMaxBSize) {
6659 nscoord maxBSize = nsLayoutUtils::ComputeBSizeValue(
6660 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6661 maxBSizeCoord.AsLengthPercentage());
6662 result.BSize(aWM) = std::min(maxBSize, result.BSize(aWM));
6663 }
6664
6665 if (!isAutoMinBSize && !shouldIgnoreMinMaxBSize) {
6666 nscoord minBSize = nsLayoutUtils::ComputeBSizeValue(
6667 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6668 minBSizeCoord.AsLengthPercentage());
6669 result.BSize(aWM) = std::max(minBSize, result.BSize(aWM));
6670 }
6671 }
6672
6673 if (IsThemed(disp)) {
6674 nsPresContext* pc = PresContext();
6675 const LayoutDeviceIntSize widget = pc->Theme()->GetMinimumWidgetSize(
6676 pc, this, disp->EffectiveAppearance());
6677
6678 // Convert themed widget's physical dimensions to logical coords
6679 LogicalSize size(aWM, LayoutDeviceIntSize::ToAppUnits(
6680 widget, pc->AppUnitsPerDevPixel()));
6681
6682 // GetMinimumWidgetSize() returns border-box; we need content-box.
6683 size -= aBorderPadding;
6684
6685 if (size.BSize(aWM) > result.BSize(aWM)) {
6686 result.BSize(aWM) = size.BSize(aWM);
6687 }
6688 if (size.ISize(aWM) > result.ISize(aWM)) {
6689 result.ISize(aWM) = size.ISize(aWM);
6690 }
6691 }
6692
6693 result.ISize(aWM) = std::max(0, result.ISize(aWM));
6694 result.BSize(aWM) = std::max(0, result.BSize(aWM));
6695
6696 return {result, aspectRatioUsage};
6697}
6698
6699nscoord nsIFrame::ComputeBSizeValueAsPercentageBasis(
6700 const StyleSize& aStyleBSize, const StyleSize& aStyleMinBSize,
6701 const StyleMaxSize& aStyleMaxBSize, nscoord aCBBSize,
6702 nscoord aContentEdgeToBoxSizingBSize) {
6703 if (nsLayoutUtils::IsAutoBSize(aStyleBSize, aCBBSize)) {
6704 return NS_UNCONSTRAINEDSIZE;
6705 }
6706
6707 const nscoord bSize = nsLayoutUtils::ComputeBSizeValue(
6708 aCBBSize, aContentEdgeToBoxSizingBSize, aStyleBSize.AsLengthPercentage());
6709
6710 const nscoord minBSize = nsLayoutUtils::IsAutoBSize(aStyleMinBSize, aCBBSize)
6711 ? 0
6712 : nsLayoutUtils::ComputeBSizeValue(
6713 aCBBSize, aContentEdgeToBoxSizingBSize,
6714 aStyleMinBSize.AsLengthPercentage());
6715
6716 const nscoord maxBSize = nsLayoutUtils::IsAutoBSize(aStyleMaxBSize, aCBBSize)
6717 ? NS_UNCONSTRAINEDSIZE
6718 : nsLayoutUtils::ComputeBSizeValue(
6719 aCBBSize, aContentEdgeToBoxSizingBSize,
6720 aStyleMaxBSize.AsLengthPercentage());
6721
6722 return CSSMinMax(bSize, minBSize, maxBSize);
6723}
6724
6725nsRect nsIFrame::ComputeTightBounds(DrawTarget* aDrawTarget) const {
6726 return InkOverflowRect();
6727}
6728
6729/* virtual */
6730nsresult nsIFrame::GetPrefWidthTightBounds(gfxContext* aContext, nscoord* aX,
6731 nscoord* aXMost) {
6732 return NS_ERROR_NOT_IMPLEMENTED;
6733}
6734
6735/* virtual */
6736LogicalSize nsIFrame::ComputeAutoSize(
6737 gfxContext* aRenderingContext, WritingMode aWM,
6738 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
6739 const mozilla::LogicalSize& aMargin,
6740 const mozilla::LogicalSize& aBorderPadding,
6741 const StyleSizeOverrides& aSizeOverrides, ComputeSizeFlags aFlags) {
6742 // Use basic shrink-wrapping as a default implementation.
6743 LogicalSize result(aWM, 0xdeadbeef, NS_UNCONSTRAINEDSIZE);
6744
6745 // don't bother setting it if the result won't be used
6746 const auto& styleISize = aSizeOverrides.mStyleISize
6747 ? *aSizeOverrides.mStyleISize
6748 : StylePosition()->ISize(aWM);
6749 if (styleISize.IsAuto()) {
6750 nscoord availBased =
6751 aAvailableISize - aMargin.ISize(aWM) - aBorderPadding.ISize(aWM);
6752 const auto* stylePos = StylePosition();
6753 const auto& styleBSize = aSizeOverrides.mStyleBSize
6754 ? *aSizeOverrides.mStyleBSize
6755 : stylePos->BSize(aWM);
6756 const LogicalSize contentEdgeToBoxSizing =
6757 stylePos->mBoxSizing == StyleBoxSizing::Border ? aBorderPadding
6758 : LogicalSize(aWM);
6759 const nscoord bSize = ComputeBSizeValueAsPercentageBasis(
6760 styleBSize, stylePos->MinBSize(aWM), stylePos->MaxBSize(aWM),
6761 aCBSize.BSize(aWM), contentEdgeToBoxSizing.BSize(aWM));
6762 const IntrinsicSizeInput input(
6763 aRenderingContext, Some(aCBSize.ConvertTo(GetWritingMode(), aWM)),
6764 Some(LogicalSize(aWM, NS_UNCONSTRAINEDSIZE, bSize)
6765 .ConvertTo(GetWritingMode(), aWM)));
6766 result.ISize(aWM) = ShrinkISizeToFit(input, availBased, aFlags);
6767 }
6768 return result;
6769}
6770
6771nscoord nsIFrame::ShrinkISizeToFit(const IntrinsicSizeInput& aInput,
6772 nscoord aISizeInCB,
6773 ComputeSizeFlags aFlags) {
6774 // If we're a container for font size inflation, then shrink
6775 // wrapping inside of us should not apply font size inflation.
6776 AutoMaybeDisableFontInflation an(this);
6777
6778 nscoord result;
6779 nscoord minISize = GetMinISize(aInput);
6780 if (minISize > aISizeInCB) {
6781 const bool clamp = aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize);
6782 result = MOZ_UNLIKELY(clamp)(__builtin_expect(!!(clamp), 0)) ? aISizeInCB : minISize;
6783 } else {
6784 nscoord prefISize = GetPrefISize(aInput);
6785 if (prefISize > aISizeInCB) {
6786 result = aISizeInCB;
6787 } else {
6788 result = prefISize;
6789 }
6790 }
6791 return result;
6792}
6793
6794nscoord nsIFrame::IntrinsicISizeFromInline(const IntrinsicSizeInput& aInput,
6795 IntrinsicISizeType aType) {
6796 MOZ_ASSERT(!IsContainerForFontSizeInflation(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!IsContainerForFontSizeInflation())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!IsContainerForFontSizeInflation
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!IsContainerForFontSizeInflation()" " (" "Should not be a container for font size inflation!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6797); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsContainerForFontSizeInflation()"
") (" "Should not be a container for font size inflation!" ")"
); do { *((volatile int*)__null) = 6797; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6797 "Should not be a container for font size inflation!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!IsContainerForFontSizeInflation())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!IsContainerForFontSizeInflation
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!IsContainerForFontSizeInflation()" " (" "Should not be a container for font size inflation!"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6797); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsContainerForFontSizeInflation()"
") (" "Should not be a container for font size inflation!" ")"
); do { *((volatile int*)__null) = 6797; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6798
6799 if (aType == IntrinsicISizeType::MinISize) {
6800 InlineMinISizeData data;
6801 AddInlineMinISize(aInput, &data);
6802 data.ForceBreak();
6803 return data.mPrevLines;
6804 }
6805
6806 InlinePrefISizeData data;
6807 AddInlinePrefISize(aInput, &data);
6808 data.ForceBreak();
6809 return data.mPrevLines;
6810}
6811
6812nscoord nsIFrame::ComputeISizeValueFromAspectRatio(
6813 WritingMode aWM, const LogicalSize& aCBSize,
6814 const LogicalSize& aContentEdgeToBoxSizing, const LengthPercentage& aBSize,
6815 const AspectRatio& aAspectRatio) const {
6816 MOZ_ASSERT(aAspectRatio, "Must have a valid AspectRatio!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aAspectRatio)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aAspectRatio))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("aAspectRatio" " ("
"Must have a valid AspectRatio!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6816); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAspectRatio"
") (" "Must have a valid AspectRatio!" ")"); do { *((volatile
int*)__null) = 6816; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
6817 const nscoord bSize = nsLayoutUtils::ComputeBSizeValue(
6818 aCBSize.BSize(aWM), aContentEdgeToBoxSizing.BSize(aWM), aBSize);
6819 return aAspectRatio.ComputeRatioDependentSize(LogicalAxis::Inline, aWM, bSize,
6820 aContentEdgeToBoxSizing);
6821}
6822
6823nsIFrame::ISizeComputationResult nsIFrame::ComputeISizeValue(
6824 gfxContext* aRenderingContext, const WritingMode aWM,
6825 const LogicalSize& aCBSize, const LogicalSize& aContentEdgeToBoxSizing,
6826 nscoord aBoxSizingToMarginEdge, ExtremumLength aSize,
6827 Maybe<nscoord> aAvailableISizeOverride, const StyleSize& aStyleBSize,
6828 const AspectRatio& aAspectRatio, ComputeSizeFlags aFlags) {
6829 auto GetAvailableISize = [&]() {
6830 return aCBSize.ISize(aWM) - aBoxSizingToMarginEdge -
6831 aContentEdgeToBoxSizing.ISize(aWM);
6832 };
6833
6834 // If 'this' is a container for font size inflation, then shrink
6835 // wrapping inside of it should not apply font size inflation.
6836 AutoMaybeDisableFontInflation an(this);
6837 // If we have an aspect-ratio and a definite block size, we should use them to
6838 // resolve the sizes with intrinsic keywords.
6839 // https://github.com/w3c/csswg-drafts/issues/5032
6840 Maybe<nscoord> iSizeFromAspectRatio = [&]() -> Maybe<nscoord> {
6841 if (aSize == ExtremumLength::MozAvailable ||
6842 aSize == ExtremumLength::Stretch) {
6843 return Nothing();
6844 }
6845 if (!aAspectRatio) {
6846 return Nothing();
6847 }
6848 if (nsLayoutUtils::IsAutoBSize(aStyleBSize, aCBSize.BSize(aWM))) {
6849 return Nothing();
6850 }
6851 return Some(ComputeISizeValueFromAspectRatio(
6852 aWM, aCBSize, aContentEdgeToBoxSizing, aStyleBSize.AsLengthPercentage(),
6853 aAspectRatio));
6854 }();
6855
6856 const auto* stylePos = StylePosition();
6857 const nscoord bSize = ComputeBSizeValueAsPercentageBasis(
6858 aStyleBSize, stylePos->MinBSize(aWM), stylePos->MaxBSize(aWM),
6859 aCBSize.BSize(aWM), aContentEdgeToBoxSizing.BSize(aWM));
6860 const IntrinsicSizeInput input(
6861 aRenderingContext, Some(aCBSize.ConvertTo(GetWritingMode(), aWM)),
6862 Some(LogicalSize(aWM, NS_UNCONSTRAINEDSIZE, bSize)
6863 .ConvertTo(GetWritingMode(), aWM)));
6864 nscoord result;
6865 switch (aSize) {
6866 case ExtremumLength::MaxContent:
6867 result =
6868 iSizeFromAspectRatio ? *iSizeFromAspectRatio : GetPrefISize(input);
6869 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"
, 6869); MOZ_PretendNoReturn(); } } while (0)
;
6870 return {result, iSizeFromAspectRatio ? AspectRatioUsage::ToComputeISize
6871 : AspectRatioUsage::None};
6872 case ExtremumLength::MinContent:
6873 result =
6874 iSizeFromAspectRatio ? *iSizeFromAspectRatio : GetMinISize(input);
6875 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"
, 6875); MOZ_PretendNoReturn(); } } while (0)
;
6876 if (MOZ_UNLIKELY((__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
6877 aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize))(__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
) {
6878 result = std::min(GetAvailableISize(), result);
6879 }
6880 return {result, iSizeFromAspectRatio ? AspectRatioUsage::ToComputeISize
6881 : AspectRatioUsage::None};
6882 case ExtremumLength::FitContentFunction:
6883 case ExtremumLength::FitContent: {
6884 nscoord pref = NS_UNCONSTRAINEDSIZE;
6885 nscoord min = 0;
6886 if (iSizeFromAspectRatio) {
6887 // The min-content and max-content size are identical and equal to the
6888 // size computed from the block size and the aspect ratio.
6889 pref = min = *iSizeFromAspectRatio;
6890 } else {
6891 pref = GetPrefISize(input);
6892 min = GetMinISize(input);
6893 }
6894
6895 const nscoord fill = aAvailableISizeOverride ? *aAvailableISizeOverride
6896 : GetAvailableISize();
6897 if (MOZ_UNLIKELY((__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
6898 aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize))(__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
) {
6899 min = std::min(min, fill);
6900 }
6901 result = std::max(min, std::min(pref, fill));
6902 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"
, 6902); MOZ_PretendNoReturn(); } } while (0)
;
6903 return {result};
6904 }
6905 case ExtremumLength::MozAvailable:
6906 case ExtremumLength::Stretch:
6907 return {GetAvailableISize()};
6908 }
6909 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"
, 6909); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Unknown extremum length?" ")"); do
{ *((volatile int*)__null) = 6909; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
6910 return {};
6911}
6912
6913nscoord nsIFrame::ComputeISizeValue(const WritingMode aWM,
6914 const LogicalSize& aCBSize,
6915 const LogicalSize& aContentEdgeToBoxSizing,
6916 const LengthPercentage& aSize) const {
6917 LAYOUT_WARN_IF_FALSE(do { if ((__builtin_expect(!!(mozilla::detail::log_test(sLayoutLog
, mozilla::LogLevel::Warning)), 0)) && !(aCBSize.ISize
(aWM) != NS_UNCONSTRAINEDSIZE)) { mozilla::detail::LayoutLogWarning
("have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size " "calculation"
, "aCBSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6921); } } while (0)
6918 aCBSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE,do { if ((__builtin_expect(!!(mozilla::detail::log_test(sLayoutLog
, mozilla::LogLevel::Warning)), 0)) && !(aCBSize.ISize
(aWM) != NS_UNCONSTRAINEDSIZE)) { mozilla::detail::LayoutLogWarning
("have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size " "calculation"
, "aCBSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6921); } } while (0)
6919 "have unconstrained inline-size; this should only result from "do { if ((__builtin_expect(!!(mozilla::detail::log_test(sLayoutLog
, mozilla::LogLevel::Warning)), 0)) && !(aCBSize.ISize
(aWM) != NS_UNCONSTRAINEDSIZE)) { mozilla::detail::LayoutLogWarning
("have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size " "calculation"
, "aCBSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6921); } } while (0)
6920 "very large sizes, not attempts at intrinsic inline-size "do { if ((__builtin_expect(!!(mozilla::detail::log_test(sLayoutLog
, mozilla::LogLevel::Warning)), 0)) && !(aCBSize.ISize
(aWM) != NS_UNCONSTRAINEDSIZE)) { mozilla::detail::LayoutLogWarning
("have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size " "calculation"
, "aCBSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6921); } } while (0)
6921 "calculation")do { if ((__builtin_expect(!!(mozilla::detail::log_test(sLayoutLog
, mozilla::LogLevel::Warning)), 0)) && !(aCBSize.ISize
(aWM) != NS_UNCONSTRAINEDSIZE)) { mozilla::detail::LayoutLogWarning
("have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size " "calculation"
, "aCBSize.ISize(aWM) != NS_UNCONSTRAINEDSIZE", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6921); } } while (0)
;
6922 NS_ASSERTION(aCBSize.ISize(aWM) >= 0, "inline-size less than zero")do { if (!(aCBSize.ISize(aWM) >= 0)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "inline-size less than zero", "aCBSize.ISize(aWM) >= 0",
"/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 6922); MOZ_PretendNoReturn(); } } while (0)
;
6923
6924 nscoord result = aSize.Resolve(aCBSize.ISize(aWM));
6925 // The result of a calc() expression might be less than 0; we
6926 // should clamp at runtime (below). (Percentages and coords that
6927 // are less than 0 have already been dropped by the parser.)
6928 result -= aContentEdgeToBoxSizing.ISize(aWM);
6929 return std::max(0, result);
6930}
6931
6932void nsIFrame::DidReflow(nsPresContext* aPresContext,
6933 const ReflowInput* aReflowInput) {
6934 NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, ("nsIFrame::DidReflow"))do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("nsIFrame::DidReflow"
); } } while (0)
;
6935
6936 if (IsHiddenByContentVisibilityOfInFlowParentForLayout()) {
6937 RemoveStateBits(NS_FRAME_IN_REFLOW);
6938 return;
6939 }
6940
6941 SVGObserverUtils::InvalidateDirectRenderingObservers(
6942 this, SVGObserverUtils::INVALIDATE_REFLOW);
6943
6944 RemoveStateBits(NS_FRAME_IN_REFLOW | NS_FRAME_FIRST_REFLOW |
6945 NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN);
6946
6947 // Clear bits that were used in ReflowInput::InitResizeFlags (see
6948 // comment there for why we can't clear it there).
6949 SetHasBSizeChange(false);
6950 SetHasPaddingChange(false);
6951
6952 // Notify the percent bsize observer if there is a percent bsize.
6953 // The observer may be able to initiate another reflow with a computed
6954 // bsize. This happens in the case where a table cell has no computed
6955 // bsize but can fabricate one when the cell bsize is known.
6956 if (aReflowInput && aReflowInput->mPercentBSizeObserver && !GetPrevInFlow()) {
6957 const auto& bsize =
6958 aReflowInput->mStylePosition->BSize(aReflowInput->GetWritingMode());
6959 if (bsize.HasPercent()) {
6960 aReflowInput->mPercentBSizeObserver->NotifyPercentBSize(*aReflowInput);
6961 }
6962 }
6963
6964 aPresContext->ReflowedFrame();
6965}
6966
6967void nsIFrame::FinishReflowWithAbsoluteFrames(nsPresContext* aPresContext,
6968 ReflowOutput& aDesiredSize,
6969 const ReflowInput& aReflowInput,
6970 nsReflowStatus& aStatus,
6971 bool aConstrainBSize) {
6972 ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowInput, aStatus,
6973 aConstrainBSize);
6974
6975 FinishAndStoreOverflow(&aDesiredSize, aReflowInput.mStyleDisplay);
6976}
6977
6978void nsIFrame::ReflowAbsoluteFrames(nsPresContext* aPresContext,
6979 ReflowOutput& aDesiredSize,
6980 const ReflowInput& aReflowInput,
6981 nsReflowStatus& aStatus,
6982 bool aConstrainBSize) {
6983 if (HasAbsolutelyPositionedChildren()) {
6984 nsAbsoluteContainingBlock* absoluteContainer = GetAbsoluteContainingBlock();
6985
6986 // Let the absolutely positioned container reflow any absolutely positioned
6987 // child frames that need to be reflowed
6988
6989 // The containing block for the abs pos kids is formed by our padding edge.
6990 nsMargin usedBorder = GetUsedBorder();
6991 nscoord containingBlockWidth =
6992 std::max(0, aDesiredSize.Width() - usedBorder.LeftRight());
6993 nscoord containingBlockHeight =
6994 std::max(0, aDesiredSize.Height() - usedBorder.TopBottom());
6995 nsContainerFrame* container = do_QueryFrame(this);
6996 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"
, 6997); MOZ_PretendNoReturn(); } } while (0)
6997 "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"
, 6997); MOZ_PretendNoReturn(); } } while (0)
;
6998
6999 nsRect containingBlock(0, 0, containingBlockWidth, containingBlockHeight);
7000 AbsPosReflowFlags flags =
7001 AbsPosReflowFlags::CBWidthAndHeightChanged; // XXX could be optimized
7002 if (aConstrainBSize) {
7003 flags |= AbsPosReflowFlags::ConstrainHeight;
7004 }
7005 absoluteContainer->Reflow(container, aPresContext, aReflowInput, aStatus,
7006 containingBlock, flags,
7007 &aDesiredSize.mOverflowAreas);
7008 }
7009}
7010
7011/* virtual */
7012bool nsIFrame::CanContinueTextRun() const {
7013 // By default, a frame will *not* allow a text run to be continued
7014 // through it.
7015 return false;
7016}
7017
7018void nsIFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
7019 const ReflowInput& aReflowInput,
7020 nsReflowStatus& aStatus) {
7021 MarkInReflow();
7022 DO_GLOBAL_REFLOW_COUNT("nsFrame")aPresContext->CountReflows(("nsFrame"), (nsIFrame*)this);;
7023 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"
, 7023); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStatus.IsEmpty()"
") (" "Caller should pass a fresh reflow status!" ")"); do {
*((volatile int*)__null) = 7023; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
7024 aDesiredSize.ClearSize();
7025}
7026
7027bool nsIFrame::IsContentDisabled() const {
7028 // FIXME(emilio): Doing this via CSS means callers must ensure the style is up
7029 // to date, and they don't!
7030 if (StyleUI()->UserInput() == StyleUserInput::None) {
7031 return true;
7032 }
7033
7034 auto* element = nsGenericHTMLElement::FromNodeOrNull(GetContent());
7035 return element && element->IsDisabled();
7036}
7037
7038bool nsIFrame::IsContentRelevant() const {
7039 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"
, 7040); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 7040; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
7040 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"
, 7040); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 7040; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7041
7042 auto* element = Element::FromNodeOrNull(GetContent());
7043 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"
, 7043); AnnotateMozCrashReason("MOZ_ASSERT" "(" "element" ")"
); do { *((volatile int*)__null) = 7043; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7044
7045 Maybe<ContentRelevancy> relevancy = element->GetContentRelevancy();
7046 return relevancy.isSome() && !relevancy->isEmpty();
7047}
7048
7049bool nsIFrame::HidesContent(
7050 const EnumSet<IncludeContentVisibility>& aInclude) const {
7051 auto effectiveContentVisibility = StyleDisplay()->ContentVisibility(*this);
7052 if (aInclude.contains(IncludeContentVisibility::Hidden) &&
7053 effectiveContentVisibility == StyleContentVisibility::Hidden) {
7054 return true;
7055 }
7056
7057 if (aInclude.contains(IncludeContentVisibility::Auto) &&
7058 effectiveContentVisibility == StyleContentVisibility::Auto) {
7059 return !IsContentRelevant();
7060 }
7061
7062 return false;
7063}
7064
7065bool nsIFrame::HidesContentForLayout() const {
7066 return HidesContent() && !PresShell()->IsForcingLayoutForHiddenContent(this);
7067}
7068
7069bool nsIFrame::IsHiddenByContentVisibilityOfInFlowParentForLayout() const {
7070 const auto* parent = GetInFlowParent();
7071 // The anonymous children owned by parent are important for properly sizing
7072 // their parents.
7073 return parent && parent->HidesContentForLayout() &&
7074 !(parent->HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES) &&
7075 Style()->IsAnonBox());
7076}
7077
7078nsIFrame* nsIFrame::GetClosestContentVisibilityAncestor(
7079 const EnumSet<IncludeContentVisibility>& aInclude) const {
7080 auto* parent = GetInFlowParent();
7081 bool isAnonymousBlock = Style()->IsAnonBox() && parent &&
7082 parent->HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES);
7083 for (nsIFrame* cur = parent; cur; cur = cur->GetInFlowParent()) {
7084 if (!isAnonymousBlock && cur->HidesContent(aInclude)) {
7085 return cur;
7086 }
7087
7088 // Anonymous boxes are not hidden by the content-visibility of their first
7089 // non-anonymous ancestor, but can be hidden by ancestors further up the
7090 // tree.
7091 isAnonymousBlock = false;
7092 }
7093
7094 return nullptr;
7095}
7096
7097bool nsIFrame::IsHiddenByContentVisibilityOnAnyAncestor(
7098 const EnumSet<IncludeContentVisibility>& aInclude) const {
7099 return !!GetClosestContentVisibilityAncestor(aInclude);
7100}
7101
7102bool nsIFrame::HasSelectionInSubtree() {
7103 if (IsSelected()) {
7104 return true;
7105 }
7106
7107 RefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
7108 if (!frameSelection) {
7109 return false;
7110 }
7111
7112 const Selection* selection =
7113 frameSelection->GetSelection(SelectionType::eNormal);
7114 if (!selection) {
7115 return false;
7116 }
7117
7118 for (uint32_t i = 0; i < selection->RangeCount(); i++) {
7119 auto* range = selection->GetRangeAt(i);
7120 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"
, 7120); AnnotateMozCrashReason("MOZ_ASSERT" "(" "range" ")")
; do { *((volatile int*)__null) = 7120; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7121
7122 const auto* commonAncestorNode =
7123 range->GetRegisteredClosestCommonInclusiveAncestor();
7124 if (commonAncestorNode &&
7125 commonAncestorNode->IsInclusiveDescendantOf(GetContent())) {
7126 return true;
7127 }
7128 }
7129
7130 return false;
7131}
7132
7133bool nsIFrame::UpdateIsRelevantContent(
7134 const ContentRelevancy& aRelevancyToUpdate) {
7135 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"
, 7136); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 7136; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
7136 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"
, 7136); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 7136; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7137
7138 auto* element = Element::FromNodeOrNull(GetContent());
7139 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"
, 7139); AnnotateMozCrashReason("MOZ_ASSERT" "(" "element" ")"
); do { *((volatile int*)__null) = 7139; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7140
7141 ContentRelevancy newRelevancy;
7142 Maybe<ContentRelevancy> oldRelevancy = element->GetContentRelevancy();
7143 if (oldRelevancy.isSome()) {
7144 newRelevancy = *oldRelevancy;
7145 }
7146
7147 auto setRelevancyValue = [&](ContentRelevancyReason reason, bool value) {
7148 if (value) {
7149 newRelevancy += reason;
7150 } else {
7151 newRelevancy -= reason;
7152 }
7153 };
7154
7155 if (!oldRelevancy ||
7156 aRelevancyToUpdate.contains(ContentRelevancyReason::Visible)) {
7157 Maybe<bool> visible = element->GetVisibleForContentVisibility();
7158 if (visible.isSome()) {
7159 setRelevancyValue(ContentRelevancyReason::Visible, *visible);
7160 }
7161 }
7162
7163 if (!oldRelevancy ||
7164 aRelevancyToUpdate.contains(ContentRelevancyReason::FocusInSubtree)) {
7165 setRelevancyValue(ContentRelevancyReason::FocusInSubtree,
7166 element->State().HasAtLeastOneOfStates(
7167 ElementState::FOCUS_WITHIN | ElementState::FOCUS));
7168 }
7169
7170 if (!oldRelevancy ||
7171 aRelevancyToUpdate.contains(ContentRelevancyReason::Selected)) {
7172 setRelevancyValue(ContentRelevancyReason::Selected,
7173 HasSelectionInSubtree());
7174 }
7175
7176 // If the proximity to the viewport has not been determined yet,
7177 // and neither the element nor its contents are focused or selected,
7178 // we should wait for the determination of the proximity. Otherwise,
7179 // there might be a redundant contentvisibilityautostatechange event.
7180 // See https://github.com/w3c/csswg-drafts/issues/9803
7181 bool isProximityToViewportDetermined =
7182 oldRelevancy ? true : element->GetVisibleForContentVisibility().isSome();
7183 if (!isProximityToViewportDetermined && newRelevancy.isEmpty()) {
7184 return false;
7185 }
7186
7187 bool overallRelevancyChanged =
7188 !oldRelevancy || oldRelevancy->isEmpty() != newRelevancy.isEmpty();
7189 if (!oldRelevancy || *oldRelevancy != newRelevancy) {
7190 element->SetContentRelevancy(newRelevancy);
7191 }
7192
7193 if (!overallRelevancyChanged) {
7194 return false;
7195 }
7196
7197 HandleLastRememberedSize();
7198 PresContext()->SetNeedsToUpdateHiddenByContentVisibilityForAnimations();
7199 PresShell()->FrameNeedsReflow(
7200 this, IntrinsicDirty::FrameAncestorsAndDescendants, NS_FRAME_IS_DIRTY);
7201 InvalidateFrame();
7202
7203 ContentVisibilityAutoStateChangeEventInit init;
7204 init.mSkipped = newRelevancy.isEmpty();
7205 RefPtr<ContentVisibilityAutoStateChangeEvent> event =
7206 ContentVisibilityAutoStateChangeEvent::Constructor(
7207 element, u"contentvisibilityautostatechange"_ns, init);
7208
7209 // Per
7210 // https://drafts.csswg.org/css-contain/#content-visibility-auto-state-changed
7211 // "This event is dispatched by posting a task at the time when the state
7212 // change occurs."
7213 RefPtr<AsyncEventDispatcher> asyncDispatcher =
7214 new AsyncEventDispatcher(element, event.forget());
7215 DebugOnly<nsresult> rv = asyncDispatcher->PostDOMEvent();
7216 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"
, 7216); MOZ_PretendNoReturn(); } } while (0)
;
7217 return true;
7218}
7219
7220nsresult nsIFrame::CharacterDataChanged(const CharacterDataChangeInfo&) {
7221 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"
, 7221); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should only be called for text frames"
")"); do { *((volatile int*)__null) = 7221; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7222 return NS_OK;
7223}
7224
7225nsresult nsIFrame::AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
7226 int32_t aModType) {
7227 return NS_OK;
7228}
7229
7230nsIFrame* nsIFrame::GetPrevContinuation() const { return nullptr; }
7231
7232void nsIFrame::SetPrevContinuation(nsIFrame*) {
7233 MOZ_ASSERT_UNREACHABLE("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" " (" "MOZ_ASSERT_UNREACHABLE: "
"Not splittable!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7233); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Not splittable!" ")"); do { *((volatile
int*)__null) = 7233; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7234}
7235
7236nsIFrame* nsIFrame::GetNextContinuation() const { return nullptr; }
7237
7238void nsIFrame::SetNextContinuation(nsIFrame*) {
7239 MOZ_ASSERT_UNREACHABLE("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" " (" "MOZ_ASSERT_UNREACHABLE: "
"Not splittable!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7239); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Not splittable!" ")"); do { *((volatile
int*)__null) = 7239; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7240}
7241
7242nsIFrame* nsIFrame::GetPrevInFlow() const { return nullptr; }
7243
7244void nsIFrame::SetPrevInFlow(nsIFrame*) {
7245 MOZ_ASSERT_UNREACHABLE("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" " (" "MOZ_ASSERT_UNREACHABLE: "
"Not splittable!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7245); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Not splittable!" ")"); do { *((volatile
int*)__null) = 7245; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7246}
7247
7248nsIFrame* nsIFrame::GetNextInFlow() const { return nullptr; }
7249
7250void nsIFrame::SetNextInFlow(nsIFrame*) {
7251 MOZ_ASSERT_UNREACHABLE("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" " (" "MOZ_ASSERT_UNREACHABLE: "
"Not splittable!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7251); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Not splittable!" ")"); do { *((volatile
int*)__null) = 7251; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7252}
7253
7254nsIFrame* nsIFrame::GetTailContinuation() {
7255 nsIFrame* frame = this;
7256 while (frame->HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER)) {
7257 frame = frame->GetPrevContinuation();
7258 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"
, 7258); MOZ_PretendNoReturn(); } } while (0)
;
7259 }
7260 for (nsIFrame* next = frame->GetNextContinuation();
7261 next && !next->HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER);
7262 next = frame->GetNextContinuation()) {
7263 frame = next;
7264 }
7265
7266 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"
, 7266); AnnotateMozCrashReason("MOZ_ASSERT" "(" "frame" ") ("
"illegal state in continuation chain." ")"); do { *((volatile
int*)__null) = 7266; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7267 return frame;
7268}
7269
7270// Associated view object
7271void nsIFrame::SetView(nsView* aView) {
7272 if (aView) {
7273 aView->SetFrame(this);
7274
7275#ifdef DEBUG1
7276 LayoutFrameType frameType = Type();
7277 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"
, 7281); MOZ_PretendNoReturn(); } } while (0)
7278 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"
, 7281); MOZ_PretendNoReturn(); } } while (0)
7279 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"
, 7281); MOZ_PretendNoReturn(); } } while (0)
7280 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"
, 7281); MOZ_PretendNoReturn(); } } while (0)
7281 "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"
, 7281); MOZ_PretendNoReturn(); } } while (0)
;
7282#endif
7283
7284 // Store the view on the frame.
7285 SetViewInternal(aView);
7286
7287 // Set the frame state bit that says the frame has a view
7288 AddStateBits(NS_FRAME_HAS_VIEW);
7289
7290 // Let all of the ancestors know they have a descendant with a view.
7291 for (nsIFrame* f = GetParent();
7292 f && !f->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
7293 f = f->GetParent())
7294 f->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
7295 } else {
7296 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"
, 7296); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Destroying a view while the frame is alive?"
")"); do { *((volatile int*)__null) = 7296; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7297 RemoveStateBits(NS_FRAME_HAS_VIEW);
7298 SetViewInternal(nullptr);
7299 }
7300}
7301
7302// Find the first geometric parent that has a view
7303nsIFrame* nsIFrame::GetAncestorWithView() const {
7304 for (nsIFrame* f = GetParent(); nullptr != f; f = f->GetParent()) {
7305 if (f->HasView()) {
7306 return f;
7307 }
7308 }
7309 return nullptr;
7310}
7311
7312template <nsPoint (nsIFrame::*PositionGetter)() const>
7313static nsPoint OffsetCalculator(const nsIFrame* aThis, const nsIFrame* aOther) {
7314 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"
, 7314); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOther" ") ("
"Must have frame for destination coordinate system!" ")"); do
{ *((volatile int*)__null) = 7314; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
7315
7316 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"
, 7317); MOZ_PretendNoReturn(); } } while (0)
7317 "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"
, 7317); MOZ_PretendNoReturn(); } } while (0)
;
7318
7319 nsPoint offset(0, 0);
7320 const nsIFrame* f;
7321 for (f = aThis; f != aOther && f; f = f->GetParent()) {
7322 offset += (f->*PositionGetter)();
7323 }
7324
7325 if (f != aOther) {
7326 // Looks like aOther wasn't an ancestor of |this|. So now we have
7327 // the root-frame-relative position of |this| in |offset|. Convert back
7328 // to the coordinates of aOther
7329 while (aOther) {
7330 offset -= (aOther->*PositionGetter)();
7331 aOther = aOther->GetParent();
7332 }
7333 }
7334
7335 return offset;
7336}
7337
7338nsPoint nsIFrame::GetOffsetTo(const nsIFrame* aOther) const {
7339 return OffsetCalculator<&nsIFrame::GetPosition>(this, aOther);
7340}
7341
7342nsPoint nsIFrame::GetOffsetToIgnoringScrolling(const nsIFrame* aOther) const {
7343 return OffsetCalculator<&nsIFrame::GetPositionIgnoringScrolling>(this,
7344 aOther);
7345}
7346
7347nsPoint nsIFrame::GetOffsetToCrossDoc(const nsIFrame* aOther) const {
7348 return GetOffsetToCrossDoc(aOther, PresContext()->AppUnitsPerDevPixel());
7349}
7350
7351nsPoint nsIFrame::GetOffsetToCrossDoc(const nsIFrame* aOther,
7352 const int32_t aAPD) const {
7353 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"
, 7353); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOther" ") ("
"Must have frame for destination coordinate system!" ")"); do
{ *((volatile int*)__null) = 7353; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
7354 MOZ_DIAGNOSTIC_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(PresContext()->GetRootPresContext() == aOther->
PresContext()->GetRootPresContext())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(PresContext()->GetRootPresContext
() == aOther->PresContext()->GetRootPresContext()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
" (" "trying to get the offset between frames in different document "
"hierarchies?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7358); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
") (" "trying to get the offset between frames in different document "
"hierarchies?" ")"); do { *((volatile int*)__null) = 7358; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
7355 PresContext()->GetRootPresContext() ==do { static_assert( mozilla::detail::AssertionConditionType<
decltype(PresContext()->GetRootPresContext() == aOther->
PresContext()->GetRootPresContext())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(PresContext()->GetRootPresContext
() == aOther->PresContext()->GetRootPresContext()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
" (" "trying to get the offset between frames in different document "
"hierarchies?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7358); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
") (" "trying to get the offset between frames in different document "
"hierarchies?" ")"); do { *((volatile int*)__null) = 7358; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
7356 aOther->PresContext()->GetRootPresContext(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(PresContext()->GetRootPresContext() == aOther->
PresContext()->GetRootPresContext())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(PresContext()->GetRootPresContext
() == aOther->PresContext()->GetRootPresContext()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
" (" "trying to get the offset between frames in different document "
"hierarchies?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7358); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
") (" "trying to get the offset between frames in different document "
"hierarchies?" ")"); do { *((volatile int*)__null) = 7358; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
7357 "trying to get the offset between frames in different document "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(PresContext()->GetRootPresContext() == aOther->
PresContext()->GetRootPresContext())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(PresContext()->GetRootPresContext
() == aOther->PresContext()->GetRootPresContext()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
" (" "trying to get the offset between frames in different document "
"hierarchies?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7358); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
") (" "trying to get the offset between frames in different document "
"hierarchies?" ")"); do { *((volatile int*)__null) = 7358; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
7358 "hierarchies?")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(PresContext()->GetRootPresContext() == aOther->
PresContext()->GetRootPresContext())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(PresContext()->GetRootPresContext
() == aOther->PresContext()->GetRootPresContext()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
" (" "trying to get the offset between frames in different document "
"hierarchies?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7358); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
") (" "trying to get the offset between frames in different document "
"hierarchies?" ")"); do { *((volatile int*)__null) = 7358; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
7359
7360 const nsIFrame* root = nullptr;
7361 // offset will hold the final offset
7362 // docOffset holds the currently accumulated offset at the current APD, it
7363 // will be converted and added to offset when the current APD changes.
7364 nsPoint offset(0, 0), docOffset(0, 0);
7365 const nsIFrame* f = this;
7366 int32_t currAPD = PresContext()->AppUnitsPerDevPixel();
7367 while (f && f != aOther) {
7368 docOffset += f->GetPosition();
7369 nsIFrame* parent = f->GetParent();
7370 if (parent) {
7371 f = parent;
7372 } else {
7373 nsPoint newOffset(0, 0);
7374 root = f;
7375 f = nsLayoutUtils::GetCrossDocParentFrameInProcess(f, &newOffset);
7376 int32_t newAPD = f ? f->PresContext()->AppUnitsPerDevPixel() : 0;
7377 if (!f || newAPD != currAPD) {
7378 // Convert docOffset to the right APD and add it to offset.
7379 offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD);
7380 docOffset.x = docOffset.y = 0;
7381 }
7382 currAPD = newAPD;
7383 docOffset += newOffset;
7384 }
7385 }
7386 if (f == aOther) {
7387 offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD);
7388 } else {
7389 // Looks like aOther wasn't an ancestor of |this|. So now we have
7390 // the root-document-relative position of |this| in |offset|. Subtract the
7391 // root-document-relative position of |aOther| from |offset|.
7392 // This call won't try to recurse again because root is an ancestor of
7393 // aOther.
7394 nsPoint negOffset = aOther->GetOffsetToCrossDoc(root, aAPD);
7395 offset -= negOffset;
7396 }
7397
7398 return offset;
7399}
7400
7401CSSIntRect nsIFrame::GetScreenRect() const {
7402 return CSSIntRect::FromAppUnitsToNearest(GetScreenRectInAppUnits());
7403}
7404
7405nsRect nsIFrame::GetScreenRectInAppUnits() const {
7406 nsPresContext* presContext = PresContext();
7407 nsIFrame* rootFrame = presContext->PresShell()->GetRootFrame();
7408 nsPoint rootScreenPos(0, 0);
7409 nsPoint rootFrameOffsetInParent(0, 0);
7410 nsIFrame* rootFrameParent = nsLayoutUtils::GetCrossDocParentFrameInProcess(
7411 rootFrame, &rootFrameOffsetInParent);
7412 if (rootFrameParent) {
7413 nsRect parentScreenRectAppUnits =
7414 rootFrameParent->GetScreenRectInAppUnits();
7415 nsPresContext* parentPresContext = rootFrameParent->PresContext();
7416 double parentScale = double(presContext->AppUnitsPerDevPixel()) /
7417 parentPresContext->AppUnitsPerDevPixel();
7418 nsPoint rootPt =
7419 parentScreenRectAppUnits.TopLeft() + rootFrameOffsetInParent;
7420 rootScreenPos.x = NS_round(parentScale * rootPt.x);
7421 rootScreenPos.y = NS_round(parentScale * rootPt.y);
7422 } else {
7423 nsCOMPtr<nsIWidget> rootWidget =
7424 presContext->PresShell()->GetViewManager()->GetRootWidget();
7425 if (rootWidget) {
7426 LayoutDeviceIntPoint rootDevPx = rootWidget->WidgetToScreenOffset();
7427 rootScreenPos.x = presContext->DevPixelsToAppUnits(rootDevPx.x);
7428 rootScreenPos.y = presContext->DevPixelsToAppUnits(rootDevPx.y);
7429 }
7430 }
7431
7432 return nsRect(rootScreenPos + GetOffsetTo(rootFrame), GetSize());
7433}
7434
7435// Returns the offset from this frame to the closest geometric parent that
7436// has a view. Also returns the containing view or null in case of error
7437void nsIFrame::GetOffsetFromView(nsPoint& aOffset, nsView** aView) const {
7438 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"
, 7438); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nullptr != aView"
") (" "null OUT parameter pointer" ")"); do { *((volatile int
*)__null) = 7438; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7439 nsIFrame* frame = const_cast<nsIFrame*>(this);
7440
7441 *aView = nullptr;
7442 aOffset.MoveTo(0, 0);
7443 do {
7444 aOffset += frame->GetPosition();
7445 frame = frame->GetParent();
7446 } while (frame && !frame->HasView());
7447
7448 if (frame) {
7449 *aView = frame->GetView();
7450 }
7451}
7452
7453nsIWidget* nsIFrame::GetNearestWidget() const {
7454 return GetClosestView()->GetNearestWidget(nullptr);
7455}
7456
7457nsIWidget* nsIFrame::GetNearestWidget(nsPoint& aOffset) const {
7458 nsPoint offsetToView;
7459 nsPoint offsetToWidget;
7460 nsIWidget* widget =
7461 GetClosestView(&offsetToView)->GetNearestWidget(&offsetToWidget);
7462 aOffset = offsetToView + offsetToWidget;
7463 return widget;
7464}
7465
7466Matrix4x4Flagged nsIFrame::GetTransformMatrix(ViewportType aViewportType,
7467 RelativeTo aStopAtAncestor,
7468 nsIFrame** aOutAncestor,
7469 uint32_t aFlags) const {
7470 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"
, 7470); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOutAncestor"
") (" "Need a place to put the ancestor!" ")"); do { *((volatile
int*)__null) = 7470; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7471
7472 /* If we're transformed, we want to hand back the combination
7473 * transform/translate matrix that will apply our current transform, then
7474 * shift us to our parent.
7475 */
7476 const bool isTransformed = IsTransformed();
7477 const nsIFrame* zoomedContentRoot = nullptr;
7478 if (aStopAtAncestor.mViewportType == ViewportType::Visual) {
7479 zoomedContentRoot = ViewportUtils::IsZoomedContentRoot(this);
7480 if (zoomedContentRoot) {
7481 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"
, 7481); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aViewportType != ViewportType::Visual"
")"); do { *((volatile int*)__null) = 7481; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7482 }
7483 }
7484
7485 if (isTransformed || zoomedContentRoot) {
7486 MOZ_ASSERT(GetParent())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(GetParent())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(GetParent()))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("GetParent()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7486); AnnotateMozCrashReason("MOZ_ASSERT" "(" "GetParent()"
")"); do { *((volatile int*)__null) = 7486; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7487 Matrix4x4Flagged result;
7488 int32_t scaleFactor =
7489 ((aFlags & IN_CSS_UNITS) ? AppUnitsPerCSSPixel()
7490 : PresContext()->AppUnitsPerDevPixel());
7491
7492 /* Compute the delta to the parent, which we need because we are converting
7493 * coordinates to our parent.
7494 */
7495 if (isTransformed) {
7496 // Note: this converts from Matrix4x4 to Matrix4x4Flagged.
7497 result = nsDisplayTransform::GetResultingTransformMatrix(
7498 this, nsPoint(), scaleFactor,
7499 nsDisplayTransform::INCLUDE_PERSPECTIVE);
7500 }
7501
7502 // The offset from a zoomed content root to its parent (e.g. from
7503 // a canvas frame to a scroll frame) is in layout coordinates, so
7504 // apply it before applying any layout-to-visual transform.
7505 *aOutAncestor = GetParent();
7506 nsPoint delta = GetPosition();
7507 /* Combine the raw transform with a translation to our parent. */
7508 result.PostTranslate(NSAppUnitsToFloatPixels(delta.x, scaleFactor),
7509 NSAppUnitsToFloatPixels(delta.y, scaleFactor), 0.0f);
7510
7511 if (zoomedContentRoot) {
7512 Matrix4x4Flagged layoutToVisual;
7513 ScrollableLayerGuid::ViewID targetScrollId =
7514 nsLayoutUtils::FindOrCreateIDFor(zoomedContentRoot->GetContent());
7515 if (aFlags & nsIFrame::IN_CSS_UNITS) {
7516 layoutToVisual =
7517 ViewportUtils::GetVisualToLayoutTransform(targetScrollId)
7518 .Inverse()
7519 .ToUnknownMatrix();
7520 } else {
7521 layoutToVisual =
7522 ViewportUtils::GetVisualToLayoutTransform<LayoutDevicePixel>(
7523 targetScrollId)
7524 .Inverse()
7525 .ToUnknownMatrix();
7526 }
7527 result = result * layoutToVisual;
7528 }
7529
7530 return result;
7531 }
7532
7533 // We are not transformed, so the returned transform is just going to be a
7534 // translation up to whatever ancestor we decide to stop at.
7535
7536 nsPoint crossdocOffset;
7537 *aOutAncestor =
7538 nsLayoutUtils::GetCrossDocParentFrameInProcess(this, &crossdocOffset);
7539
7540 /* Otherwise, we're not transformed. In that case, we'll walk up the frame
7541 * tree until we either hit the root frame or something that may be
7542 * transformed. We'll then change coordinates into that frame, since we're
7543 * guaranteed that nothing in-between can be transformed. First, however,
7544 * we have to check to see if we have a parent. If not, we'll set the
7545 * outparam to null (indicating that there's nothing left) and will hand back
7546 * the identity matrix.
7547 */
7548 if (!*aOutAncestor) return Matrix4x4Flagged();
7549
7550 /* Keep iterating while the frame can't possibly be transformed. */
7551 const nsIFrame* current = this;
7552 auto shouldStopAt = [](const nsIFrame* aCurrent, RelativeTo& aStopAtAncestor,
7553 nsIFrame* aOutAncestor, uint32_t aFlags) {
7554 return aOutAncestor->IsTransformed() ||
7555 ((aStopAtAncestor.mViewportType == ViewportType::Visual) &&
7556 ViewportUtils::IsZoomedContentRoot(aOutAncestor)) ||
7557 ((aFlags & STOP_AT_STACKING_CONTEXT_AND_DISPLAY_PORT) &&
7558 (aOutAncestor->IsStackingContext() ||
7559 DisplayPortUtils::FrameHasDisplayPort(aOutAncestor, aCurrent)));
7560 };
7561
7562 // We run the GetOffsetToCrossDoc code here as an optimization, instead of
7563 // walking the parent chain here and then asking GetOffsetToCrossDoc to walk
7564 // the same parent chain and compute the offset.
7565 const int32_t finalAPD = PresContext()->AppUnitsPerDevPixel();
7566 // offset accumulates the offset at finalAPD.
7567 nsPoint offset = GetPosition();
7568
7569 int32_t currAPD = (*aOutAncestor)->PresContext()->AppUnitsPerDevPixel();
7570 // docOffset accumulates the current offset at currAPD, and then flushes to
7571 // offset at finalAPD when the APD changes or we finish.
7572 nsPoint docOffset = crossdocOffset;
7573 MOZ_ASSERT(crossdocOffset == nsPoint(0, 0) || !GetParent())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(crossdocOffset == nsPoint(0, 0) || !GetParent())>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(crossdocOffset == nsPoint(0, 0) || !GetParent()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("crossdocOffset == nsPoint(0, 0) || !GetParent()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 7573); AnnotateMozCrashReason("MOZ_ASSERT" "(" "crossdocOffset == nsPoint(0, 0) || !GetParent()"
")"); do { *((volatile int*)__null) = 7573; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7574
7575 while (*aOutAncestor != aStopAtAncestor.mFrame &&
7576 !shouldStopAt(current, aStopAtAncestor, *aOutAncestor, aFlags)) {
7577 docOffset += (*aOutAncestor)->GetPosition();
7578
7579 nsIFrame* parent = (*aOutAncestor)->GetParent();
7580 if (!parent) {
7581 crossdocOffset.x = crossdocOffset.y = 0;
7582 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(*aOutAncestor,
7583 &crossdocOffset);
7584
7585 int32_t newAPD =
7586 parent ? parent->PresContext()->AppUnitsPerDevPixel() : currAPD;
7587 if (!parent || newAPD != currAPD) {
7588 // Convert docOffset to finalAPD and add it to offset.
7589 offset += docOffset.ScaleToOtherAppUnits(currAPD, finalAPD);
7590 docOffset.x = docOffset.y = 0;
7591 }
7592 currAPD = newAPD;
7593 docOffset += crossdocOffset;
7594
7595 if (!parent) break;
7596 }
7597
7598 current = *aOutAncestor;
7599 *aOutAncestor = parent;
7600 }
7601 offset += docOffset.ScaleToOtherAppUnits(currAPD, finalAPD);
7602
7603 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"
, 7603); MOZ_PretendNoReturn(); } } while (0)
;
7604
7605 int32_t scaleFactor =
7606 ((aFlags & IN_CSS_UNITS) ? AppUnitsPerCSSPixel()
7607 : PresContext()->AppUnitsPerDevPixel());
7608 return Matrix4x4Flagged::Translation2d(
7609 NSAppUnitsToFloatPixels(offset.x, scaleFactor),
7610 NSAppUnitsToFloatPixels(offset.y, scaleFactor));
7611}
7612
7613static void InvalidateRenderingObservers(nsIFrame* aDisplayRoot,
7614 nsIFrame* aFrame,
7615 bool aFrameChanged = true) {
7616 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"
, 7616); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame)"
")"); do { *((volatile int*)__null) = 7616; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7617 SVGObserverUtils::InvalidateDirectRenderingObservers(aFrame);
7618 nsIFrame* parent = aFrame;
7619 while (parent != aDisplayRoot &&
7620 (parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(parent)) &&
7621 !parent->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) {
7622 SVGObserverUtils::InvalidateDirectRenderingObservers(parent);
7623 }
7624
7625 if (!aFrameChanged) {
7626 return;
7627 }
7628
7629 aFrame->MarkNeedsDisplayItemRebuild();
7630}
7631
7632static void SchedulePaintInternal(
7633 nsIFrame* aDisplayRoot, nsIFrame* aFrame,
7634 nsIFrame::PaintType aType = nsIFrame::PAINT_DEFAULT) {
7635 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"
, 7635); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame)"
")"); do { *((volatile int*)__null) = 7635; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7636 nsPresContext* pres = aDisplayRoot->PresContext()->GetRootPresContext();
7637
7638 // No need to schedule a paint for an external document since they aren't
7639 // painted directly.
7640 if (!pres || (pres->Document() && pres->Document()->IsResourceDoc())) {
7641 return;
7642 }
7643 if (!pres->GetContainerWeak()) {
7644 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"
, 7644)
;
7645 return;
7646 }
7647
7648 pres->PresShell()->ScheduleViewManagerFlush();
7649
7650 if (aType == nsIFrame::PAINT_DEFAULT) {
7651 aDisplayRoot->AddStateBits(NS_FRAME_UPDATE_LAYER_TREE);
7652 }
7653}
7654
7655static void InvalidateFrameInternal(nsIFrame* aFrame, bool aHasDisplayItem,
7656 bool aRebuildDisplayItems) {
7657 if (aHasDisplayItem) {
7658 aFrame->AddStateBits(NS_FRAME_NEEDS_PAINT);
7659 }
7660
7661 if (aRebuildDisplayItems) {
7662 aFrame->MarkNeedsDisplayItemRebuild();
7663 }
7664 SVGObserverUtils::InvalidateDirectRenderingObservers(aFrame);
7665 bool needsSchedulePaint = false;
7666 if (nsLayoutUtils::IsPopup(aFrame)) {
7667 needsSchedulePaint = true;
7668 } else {
7669 nsIFrame* parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(aFrame);
7670 while (parent &&
7671 !parent->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) {
7672 if (aHasDisplayItem && !parent->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY)) {
7673 parent->AddStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT);
7674 }
7675 SVGObserverUtils::InvalidateDirectRenderingObservers(parent);
7676
7677 // If we're inside a popup, then we need to make sure that we
7678 // call schedule paint so that the NS_FRAME_UPDATE_LAYER_TREE
7679 // flag gets added to the popup display root frame.
7680 if (nsLayoutUtils::IsPopup(parent)) {
7681 needsSchedulePaint = true;
7682 break;
7683 }
7684 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(parent);
7685 }
7686 if (!parent) {
7687 needsSchedulePaint = true;
7688 }
7689 }
7690 if (!aHasDisplayItem) {
7691 return;
7692 }
7693 if (needsSchedulePaint) {
7694 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(aFrame);
7695 SchedulePaintInternal(displayRoot, aFrame);
7696 }
7697 if (aFrame->HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) {
7698 aFrame->RemoveProperty(nsIFrame::InvalidationRect());
7699 aFrame->RemoveStateBits(NS_FRAME_HAS_INVALID_RECT);
7700 }
7701}
7702
7703void nsIFrame::InvalidateFrameSubtree(bool aRebuildDisplayItems /* = true */) {
7704 InvalidateFrame(0, aRebuildDisplayItems);
7705
7706 if (HasAnyStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT)) {
7707 return;
7708 }
7709
7710 AddStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT);
7711
7712 for (const auto& childList : CrossDocChildLists()) {
7713 for (nsIFrame* child : childList.mList) {
7714 // Don't explicitly rebuild display items for our descendants,
7715 // since we should be marked and it implicitly includes all
7716 // descendants.
7717 child->InvalidateFrameSubtree(false);
7718 }
7719 }
7720}
7721
7722void nsIFrame::ClearInvalidationStateBits() {
7723 if (HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) {
7724 for (const auto& childList : CrossDocChildLists()) {
7725 for (nsIFrame* child : childList.mList) {
7726 child->ClearInvalidationStateBits();
7727 }
7728 }
7729 }
7730
7731 RemoveStateBits(NS_FRAME_NEEDS_PAINT | NS_FRAME_DESCENDANT_NEEDS_PAINT |
7732 NS_FRAME_ALL_DESCENDANTS_NEED_PAINT);
7733}
7734
7735bool HasRetainedDataFor(const nsIFrame* aFrame, uint32_t aDisplayItemKey) {
7736 if (RefPtr<WebRenderUserData> data =
7737 GetWebRenderUserData<WebRenderFallbackData>(aFrame,
7738 aDisplayItemKey)) {
7739 return true;
7740 }
7741
7742 return false;
7743}
7744
7745void nsIFrame::InvalidateFrame(uint32_t aDisplayItemKey,
7746 bool aRebuildDisplayItems /* = true */) {
7747 bool hasDisplayItem =
7748 !aDisplayItemKey || HasRetainedDataFor(this, aDisplayItemKey);
7749 InvalidateFrameInternal(this, hasDisplayItem, aRebuildDisplayItems);
7750}
7751
7752void nsIFrame::InvalidateFrameWithRect(const nsRect& aRect,
7753 uint32_t aDisplayItemKey,
7754 bool aRebuildDisplayItems /* = true */) {
7755 if (aRect.IsEmpty()) {
7756 return;
7757 }
7758 bool hasDisplayItem =
7759 !aDisplayItemKey || HasRetainedDataFor(this, aDisplayItemKey);
7760 bool alreadyInvalid = false;
7761 if (!HasAnyStateBits(NS_FRAME_NEEDS_PAINT)) {
7762 InvalidateFrameInternal(this, hasDisplayItem, aRebuildDisplayItems);
7763 } else {
7764 alreadyInvalid = true;
7765 }
7766
7767 if (!hasDisplayItem) {
7768 return;
7769 }
7770
7771 nsRect* rect;
7772 if (HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) {
7773 rect = GetProperty(InvalidationRect());
7774 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"
, 7774); AnnotateMozCrashReason("MOZ_ASSERT" "(" "rect" ")");
do { *((volatile int*)__null) = 7774; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7775 } else {
7776 if (alreadyInvalid) {
7777 return;
7778 }
7779 rect = new nsRect();
7780 AddProperty(InvalidationRect(), rect);
7781 AddStateBits(NS_FRAME_HAS_INVALID_RECT);
7782 }
7783
7784 *rect = rect->Union(aRect);
7785}
7786
7787bool nsIFrame::IsInvalid(nsRect& aRect) {
7788 if (!HasAnyStateBits(NS_FRAME_NEEDS_PAINT)) {
7789 return false;
7790 }
7791
7792 if (HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) {
7793 nsRect* rect = GetProperty(InvalidationRect());
7794 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"
, 7795); MOZ_PretendNoReturn(); } } while (0)
7795 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"
, 7795); MOZ_PretendNoReturn(); } } while (0)
;
7796 aRect = *rect;
7797 } else {
7798 aRect.SetEmpty();
7799 }
7800 return true;
7801}
7802
7803void nsIFrame::SchedulePaint(PaintType aType, bool aFrameChanged) {
7804 if (PresShell()->IsPaintingSuppressed()) {
7805 // We can't have any display items yet, and when we unsuppress we will
7806 // invalidate the root frame.
7807 return;
7808 }
7809 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this);
7810 InvalidateRenderingObservers(displayRoot, this, aFrameChanged);
7811 SchedulePaintInternal(displayRoot, this, aType);
7812}
7813
7814void nsIFrame::SchedulePaintWithoutInvalidatingObservers(PaintType aType) {
7815 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this);
7816 SchedulePaintInternal(displayRoot, this, aType);
7817}
7818
7819void nsIFrame::InvalidateLayer(DisplayItemType aDisplayItemKey,
7820 const nsIntRect* aDamageRect,
7821 const nsRect* aFrameDamageRect,
7822 uint32_t aFlags /* = 0 */) {
7823 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"
, 7823); MOZ_PretendNoReturn(); } } while (0)
;
7824
7825 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this);
7826 InvalidateRenderingObservers(displayRoot, this, false);
7827
7828 // Check if frame supports WebRender's async update
7829 if ((aFlags & UPDATE_IS_ASYNC) &&
7830 WebRenderUserData::SupportsAsyncUpdate(this)) {
7831 // WebRender does not use layer, then return nullptr.
7832 return;
7833 }
7834
7835 if (aFrameDamageRect && aFrameDamageRect->IsEmpty()) {
7836 return;
7837 }
7838
7839 // In the bug 930056, dialer app startup but not shown on the
7840 // screen because sometimes we don't have any retainned data
7841 // for remote type displayitem and thus Repaint event is not
7842 // triggered. So, always invalidate in this case.
7843 DisplayItemType displayItemKey = aDisplayItemKey;
7844 if (aDisplayItemKey == DisplayItemType::TYPE_REMOTE) {
7845 displayItemKey = DisplayItemType::TYPE_ZERO;
7846 }
7847
7848 if (aFrameDamageRect) {
7849 InvalidateFrameWithRect(*aFrameDamageRect,
7850 static_cast<uint32_t>(displayItemKey));
7851 } else {
7852 InvalidateFrame(static_cast<uint32_t>(displayItemKey));
7853 }
7854}
7855
7856static nsRect ComputeEffectsRect(nsIFrame* aFrame, const nsRect& aOverflowRect,
7857 const nsSize& aNewSize) {
7858 nsRect r = aOverflowRect;
7859
7860 if (aFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
7861 // For SVG frames, we only need to account for filters.
7862 // TODO: We could also take account of clipPath and mask to reduce the
7863 // ink overflow, but that's not essential.
7864 if (aFrame->StyleEffects()->HasFilters()) {
7865 SetOrUpdateRectValuedProperty(aFrame, nsIFrame::PreEffectsBBoxProperty(),
7866 r);
7867 r = SVGUtils::GetPostFilterInkOverflowRect(aFrame, aOverflowRect);
7868 }
7869 return r;
7870 }
7871
7872 // box-shadow
7873 r.UnionRect(r, nsLayoutUtils::GetBoxShadowRectForFrame(aFrame, aNewSize));
7874
7875 // border-image-outset.
7876 // We need to include border-image-outset because it can cause the
7877 // border image to be drawn beyond the border box.
7878
7879 // (1) It's important we not check whether there's a border-image
7880 // since the style hint for a change in border image doesn't cause
7881 // reflow, and that's probably more important than optimizing the
7882 // overflow areas for the silly case of border-image-outset without
7883 // border-image
7884 // (2) It's important that we not check whether the border-image
7885 // is actually loaded, since that would require us to reflow when
7886 // the image loads.
7887 const nsStyleBorder* styleBorder = aFrame->StyleBorder();
7888 nsMargin outsetMargin = styleBorder->GetImageOutset();
7889
7890 if (outsetMargin != nsMargin(0, 0, 0, 0)) {
7891 nsRect outsetRect(nsPoint(0, 0), aNewSize);
7892 outsetRect.Inflate(outsetMargin);
7893 r.UnionRect(r, outsetRect);
7894 }
7895
7896 // Note that we don't remove the outlineInnerRect if a frame loses outline
7897 // style. That would require an extra property lookup for every frame,
7898 // or a new frame state bit to track whether a property had been stored,
7899 // or something like that. It's not worth doing that here. At most it's
7900 // only one heap-allocated rect per frame and it will be cleaned up when
7901 // the frame dies.
7902
7903 if (SVGIntegrationUtils::UsingOverflowAffectingEffects(aFrame)) {
7904 SetOrUpdateRectValuedProperty(aFrame, nsIFrame::PreEffectsBBoxProperty(),
7905 r);
7906 r = SVGIntegrationUtils::ComputePostEffectsInkOverflowRect(aFrame, r);
7907 }
7908
7909 return r;
7910}
7911
7912void nsIFrame::SetPosition(const nsPoint& aPt) {
7913 if (mRect.TopLeft() == aPt) {
7914 return;
7915 }
7916 mRect.MoveTo(aPt);
7917 MarkNeedsDisplayItemRebuild();
7918}
7919
7920void nsIFrame::MovePositionBy(const nsPoint& aTranslation) {
7921 nsPoint position = GetNormalPosition() + aTranslation;
7922
7923 const nsMargin* computedOffsets = nullptr;
7924 if (IsRelativelyOrStickyPositioned()) {
7925 computedOffsets = GetProperty(nsIFrame::ComputedOffsetProperty());
7926 }
7927 ReflowInput::ApplyRelativePositioning(
7928 this, computedOffsets ? *computedOffsets : nsMargin(), &position);
7929 SetPosition(position);
7930}
7931
7932nsRect nsIFrame::GetNormalRect() const {
7933 // It might be faster to first check
7934 // StyleDisplay()->IsRelativelyPositionedStyle().
7935 bool hasProperty;
7936 nsPoint normalPosition = GetProperty(NormalPositionProperty(), &hasProperty);
7937 if (hasProperty) {
7938 return nsRect(normalPosition, GetSize());
7939 }
7940 return GetRect();
7941}
7942
7943nsRect nsIFrame::GetBoundingClientRect() {
7944 return nsLayoutUtils::GetAllInFlowRectsUnion(
7945 this, nsLayoutUtils::GetContainingBlockForClientRect(this),
7946 nsLayoutUtils::GetAllInFlowRectsFlag::AccountForTransforms);
7947}
7948
7949nsPoint nsIFrame::GetPositionIgnoringScrolling() const {
7950 return GetParent() ? GetParent()->GetPositionOfChildIgnoringScrolling(this)
7951 : GetPosition();
7952}
7953
7954nsRect nsIFrame::GetOverflowRect(OverflowType aType) const {
7955 // Note that in some cases the overflow area might not have been
7956 // updated (yet) to reflect any outline set on the frame or the area
7957 // of child frames. That's OK because any reflow that updates these
7958 // areas will invalidate the appropriate area, so any (mis)uses of
7959 // this method will be fixed up.
7960
7961 if (mOverflow.mType == OverflowStorageType::Large) {
7962 // there is an overflow rect, and it's not stored as deltas but as
7963 // a separately-allocated rect
7964 return GetOverflowAreasProperty()->Overflow(aType);
7965 }
7966
7967 if (aType == OverflowType::Ink &&
7968 mOverflow.mType != OverflowStorageType::None) {
7969 return InkOverflowFromDeltas();
7970 }
7971
7972 return GetRectRelativeToSelf();
7973}
7974
7975OverflowAreas nsIFrame::GetOverflowAreas() const {
7976 if (mOverflow.mType == OverflowStorageType::Large) {
7977 // there is an overflow rect, and it's not stored as deltas but as
7978 // a separately-allocated rect
7979 return *GetOverflowAreasProperty();
7980 }
7981
7982 return OverflowAreas(InkOverflowFromDeltas(),
7983 nsRect(nsPoint(0, 0), GetSize()));
7984}
7985
7986OverflowAreas nsIFrame::GetOverflowAreasRelativeToSelf() const {
7987 if (IsTransformed()) {
7988 if (OverflowAreas* preTransformOverflows =
7989 GetProperty(PreTransformOverflowAreasProperty())) {
7990 return *preTransformOverflows;
7991 }
7992 }
7993 return GetOverflowAreas();
7994}
7995
7996OverflowAreas nsIFrame::GetOverflowAreasRelativeToParent() const {
7997 return GetOverflowAreas() + GetPosition();
7998}
7999
8000OverflowAreas nsIFrame::GetActualAndNormalOverflowAreasRelativeToParent()
8001 const {
8002 if (MOZ_LIKELY(!IsRelativelyOrStickyPositioned())(__builtin_expect(!!(!IsRelativelyOrStickyPositioned()), 1))) {
8003 return GetOverflowAreasRelativeToParent();
8004 }
8005
8006 const OverflowAreas overflows = GetOverflowAreas();
8007 OverflowAreas actualAndNormalOverflows = overflows + GetNormalPosition();
8008 if (IsRelativelyPositioned()) {
8009 actualAndNormalOverflows.UnionWith(overflows + GetPosition());
8010 } else {
8011 // For sticky positioned elements, we only use the normal position for the
8012 // scrollable overflow. This avoids circular dependencies between sticky
8013 // positioned elements and their scroll container. (The scroll position and
8014 // the scroll container's size impact the sticky position, so we don't want
8015 // the sticky position to impact them.)
8016 MOZ_ASSERT(IsStickyPositioned())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsStickyPositioned())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsStickyPositioned()))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("IsStickyPositioned()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8016); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsStickyPositioned()"
")"); do { *((volatile int*)__null) = 8016; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8017 actualAndNormalOverflows.UnionWith(
8018 OverflowAreas(overflows.InkOverflow() + GetPosition(), nsRect()));
8019 }
8020 return actualAndNormalOverflows;
8021}
8022
8023nsRect nsIFrame::ScrollableOverflowRectRelativeToParent() const {
8024 return ScrollableOverflowRect() + GetPosition();
8025}
8026
8027nsRect nsIFrame::InkOverflowRectRelativeToParent() const {
8028 return InkOverflowRect() + GetPosition();
8029}
8030
8031nsRect nsIFrame::ScrollableOverflowRectRelativeToSelf() const {
8032 if (IsTransformed()) {
8033 if (OverflowAreas* preTransformOverflows =
8034 GetProperty(PreTransformOverflowAreasProperty())) {
8035 return preTransformOverflows->ScrollableOverflow();
8036 }
8037 }
8038 return ScrollableOverflowRect();
8039}
8040
8041nsRect nsIFrame::InkOverflowRectRelativeToSelf() const {
8042 if (IsTransformed()) {
8043 if (OverflowAreas* preTransformOverflows =
8044 GetProperty(PreTransformOverflowAreasProperty())) {
8045 return preTransformOverflows->InkOverflow();
8046 }
8047 }
8048 return InkOverflowRect();
8049}
8050
8051nsRect nsIFrame::PreEffectsInkOverflowRect() const {
8052 nsRect* r = GetProperty(nsIFrame::PreEffectsBBoxProperty());
8053 return r ? *r : InkOverflowRectRelativeToSelf();
8054}
8055
8056bool nsIFrame::UpdateOverflow() {
8057 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"
, 8058); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Non-display SVG do not maintain ink overflow rects" ")"
); do { *((volatile int*)__null) = 8058; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
8058 "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"
, 8058); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Non-display SVG do not maintain ink overflow rects" ")"
); do { *((volatile int*)__null) = 8058; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8059
8060 nsRect rect(nsPoint(0, 0), GetSize());
8061 OverflowAreas overflowAreas(rect, rect);
8062
8063 if (!ComputeCustomOverflow(overflowAreas)) {
8064 // If updating overflow wasn't supported by this frame, then it should
8065 // have scheduled any necessary reflows. We can return false to say nothing
8066 // changed, and wait for reflow to correct it.
8067 return false;
8068 }
8069
8070 UnionChildOverflow(overflowAreas);
8071
8072 if (FinishAndStoreOverflow(overflowAreas, GetSize())) {
8073 if (nsView* view = GetView()) {
8074 // Make sure the frame's view is properly sized.
8075 nsViewManager* vm = view->GetViewManager();
8076 vm->ResizeView(view, overflowAreas.InkOverflow());
8077 }
8078
8079 return true;
8080 }
8081
8082 // Frames that combine their 3d transform with their ancestors
8083 // only compute a pre-transform overflow rect, and then contribute
8084 // to the normal overflow rect of the preserve-3d root. Always return
8085 // true here so that we propagate changes up to the root for final
8086 // calculation.
8087 return Combines3DTransformWithAncestors();
8088}
8089
8090/* virtual */
8091bool nsIFrame::ComputeCustomOverflow(OverflowAreas& aOverflowAreas) {
8092 return true;
8093}
8094
8095bool nsIFrame::DoesClipChildrenInBothAxes() const {
8096 if (IsScrollContainerOrSubclass()) {
8097 return true;
8098 }
8099 const nsStyleDisplay* display = StyleDisplay();
8100 if (display->IsContainPaint() && SupportsContainLayoutAndPaint()) {
8101 return true;
8102 }
8103 return display->mOverflowX == StyleOverflow::Clip &&
8104 display->mOverflowY == StyleOverflow::Clip;
8105}
8106
8107/* virtual */
8108void nsIFrame::UnionChildOverflow(OverflowAreas& aOverflowAreas,
8109 bool aAsIfScrolled) {
8110 if (aAsIfScrolled || !DoesClipChildrenInBothAxes()) {
8111 nsLayoutUtils::UnionChildOverflow(this, aOverflowAreas);
8112 }
8113}
8114
8115// Return true if this form control element's preferred size property (but not
8116// percentage max size property) contains a percentage value that should be
8117// resolved against zero when calculating its min-content contribution in the
8118// corresponding axis.
8119//
8120// For proper replaced elements, the percentage value in both their max size
8121// property or preferred size property should be resolved against zero. This is
8122// handled in IsPercentageResolvedAgainstZero().
8123inline static bool FormControlShrinksForPercentSize(const nsIFrame* aFrame) {
8124 if (!aFrame->IsReplaced()) {
8125 // Quick test to reject most frames.
8126 return false;
8127 }
8128
8129 switch (aFrame->Type()) {
8130 case LayoutFrameType::Meter:
8131 case LayoutFrameType::Progress:
8132 case LayoutFrameType::Range:
8133 case LayoutFrameType::TextInput:
8134 case LayoutFrameType::ColorControl:
8135 case LayoutFrameType::ComboboxControl:
8136 case LayoutFrameType::ListControl:
8137 case LayoutFrameType::CheckboxRadio:
8138 case LayoutFrameType::FileControl:
8139 case LayoutFrameType::ImageControl:
8140 return true;
8141 default:
8142 // Buttons (GfxButtonControl / HTMLButtonControl) don't have this
8143 // shrinking behavior. (Note that color inputs do, even though they
8144 // inherit from button, so we can't use do_QueryFrame here.)
8145 return false;
8146 }
8147}
8148
8149bool nsIFrame::IsPercentageResolvedAgainstZero(
8150 const StyleSize& aStyleSize, const StyleMaxSize& aStyleMaxSize) const {
8151 const bool sizeHasPercent = aStyleSize.HasPercent();
8152 return ((sizeHasPercent || aStyleMaxSize.HasPercent()) &&
8153 HasReplacedSizing()) ||
8154 (sizeHasPercent && FormControlShrinksForPercentSize(this));
8155}
8156
8157// Summary of the Cyclic-Percentage Intrinsic Size Contribution Rules:
8158//
8159// Element Type | Replaced | Non-replaced
8160// Contribution Type | min-content max-content | min-content max-content
8161// ---------------------------------------------------------------------------
8162// min size | zero zero | zero zero
8163// max & preferred size | zero initial | initial initial
8164//
8165// https://drafts.csswg.org/css-sizing-3/#cyclic-percentage-contribution
8166bool nsIFrame::IsPercentageResolvedAgainstZero(const LengthPercentage& aSize,
8167 SizeProperty aProperty) const {
8168 // Early return to avoid calling the virtual function, IsFrameOfType().
8169 if (aProperty == SizeProperty::MinSize) {
8170 return true;
8171 }
8172
8173 const bool hasPercentOnReplaced = aSize.HasPercent() && HasReplacedSizing();
8174 if (aProperty == SizeProperty::MaxSize) {
8175 return hasPercentOnReplaced;
8176 }
8177
8178 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"
, 8178); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aProperty == SizeProperty::Size"
")"); do { *((volatile int*)__null) = 8178; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8179 return hasPercentOnReplaced ||
8180 (aSize.HasPercent() && FormControlShrinksForPercentSize(this));
8181}
8182
8183bool nsIFrame::IsBlockWrapper() const {
8184 auto pseudoType = Style()->GetPseudoType();
8185 return pseudoType == PseudoStyleType::mozBlockInsideInlineWrapper ||
8186 pseudoType == PseudoStyleType::buttonContent ||
8187 pseudoType == PseudoStyleType::cellContent ||
8188 pseudoType == PseudoStyleType::columnSpanWrapper;
8189}
8190
8191bool nsIFrame::IsBlockFrameOrSubclass() const {
8192 const nsBlockFrame* thisAsBlock = do_QueryFrame(this);
8193 return !!thisAsBlock;
8194}
8195
8196bool nsIFrame::IsImageFrameOrSubclass() const {
8197 const nsImageFrame* asImage = do_QueryFrame(this);
8198 return !!asImage;
8199}
8200
8201bool nsIFrame::IsScrollContainerOrSubclass() const {
8202 const bool result = IsScrollContainerFrame() || IsListControlFrame();
8203 MOZ_ASSERT(result == !!QueryFrame(ScrollContainerFrame::kFrameIID))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(result == !!QueryFrame(ScrollContainerFrame::kFrameIID
))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(result == !!QueryFrame(ScrollContainerFrame::kFrameIID
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("result == !!QueryFrame(ScrollContainerFrame::kFrameIID)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8203); AnnotateMozCrashReason("MOZ_ASSERT" "(" "result == !!QueryFrame(ScrollContainerFrame::kFrameIID)"
")"); do { *((volatile int*)__null) = 8203; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8204 return result;
8205}
8206
8207bool nsIFrame::IsSubgrid() const {
8208 return IsGridContainerFrame() &&
8209 static_cast<const nsGridContainerFrame*>(this)->IsSubgrid();
8210}
8211
8212static nsIFrame* GetNearestBlockContainer(nsIFrame* frame) {
8213 while (!frame->IsBlockContainer()) {
8214 frame = frame->GetParent();
8215 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"
, 8217); MOZ_PretendNoReturn(); } } while (0)
8216 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"
, 8217); MOZ_PretendNoReturn(); } } while (0)
8217 "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"
, 8217); MOZ_PretendNoReturn(); } } while (0)
;
8218 }
8219 return frame;
8220}
8221
8222bool nsIFrame::IsBlockContainer() const {
8223 // The block wrappers we use to wrap blocks inside inlines aren't
8224 // described in the CSS spec. We need to make them not be containing
8225 // blocks.
8226 // Since the parent of such a block is either a normal block or
8227 // another such pseudo, this shouldn't cause anything bad to happen.
8228 // Also the anonymous blocks inside table cells are not containing blocks.
8229 //
8230 // If we ever start skipping table row groups from being containing blocks,
8231 // you need to remove the StickyScrollContainer hack referencing bug 1421660.
8232 return !IsLineParticipant() && !IsBlockWrapper() && !IsSubgrid() &&
8233 // Table rows are not containing blocks either
8234 !IsTableRowFrame();
8235}
8236
8237nsIFrame* nsIFrame::GetContainingBlock(
8238 uint32_t aFlags, const nsStyleDisplay* aStyleDisplay) const {
8239 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"
, 8239); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStyleDisplay == StyleDisplay()"
")"); do { *((volatile int*)__null) = 8239; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8240
8241 // Keep this in sync with MightBeContainingBlockFor in ReflowInput.cpp.
8242
8243 if (!GetParent()) {
8244 return nullptr;
8245 }
8246 // MathML frames might have absolute positioning style, but they would
8247 // still be in-flow. So we have to check to make sure that the frame
8248 // is really out-of-flow too.
8249 nsIFrame* f;
8250 if (IsAbsolutelyPositioned(aStyleDisplay)) {
8251 f = GetParent(); // the parent is always the containing block
8252 } else {
8253 f = GetNearestBlockContainer(GetParent());
8254 }
8255
8256 if (aFlags & SKIP_SCROLLED_FRAME && f &&
8257 f->Style()->GetPseudoType() == PseudoStyleType::scrolledContent) {
8258 f = f->GetParent();
8259 }
8260 return f;
8261}
8262
8263#ifdef DEBUG_FRAME_DUMP1
8264
8265Maybe<uint32_t> nsIFrame::ContentIndexInContainer(const nsIFrame* aFrame) {
8266 if (nsIContent* content = aFrame->GetContent()) {
8267 return content->ComputeIndexInParentContent();
8268 }
8269 return Nothing();
8270}
8271
8272nsAutoCString nsIFrame::ListTag() const {
8273 nsAutoString tmp;
8274 GetFrameName(tmp);
8275
8276 nsAutoCString tag;
8277 tag += NS_ConvertUTF16toUTF8(tmp);
8278 tag += nsPrintfCString("@%p", static_cast<const void*>(this));
8279 return tag;
8280}
8281
8282std::string nsIFrame::ConvertToString(const LogicalRect& aRect,
8283 const WritingMode aWM, ListFlags aFlags) {
8284 if (aFlags.contains(ListFlag::DisplayInCSSPixels)) {
8285 // Abuse CSSRect to store all LogicalRect's dimensions in CSS pixels.
8286 return ToString(mozilla::CSSRect(CSSPixel::FromAppUnits(aRect.IStart(aWM)),
8287 CSSPixel::FromAppUnits(aRect.BStart(aWM)),
8288 CSSPixel::FromAppUnits(aRect.ISize(aWM)),
8289 CSSPixel::FromAppUnits(aRect.BSize(aWM))));
8290 }
8291 return ToString(aRect);
8292}
8293
8294std::string nsIFrame::ConvertToString(const LogicalSize& aSize,
8295 const WritingMode aWM, ListFlags aFlags) {
8296 if (aFlags.contains(ListFlag::DisplayInCSSPixels)) {
8297 // Abuse CSSSize to store all LogicalSize's dimensions in CSS pixels.
8298 return ToString(CSSSize(CSSPixel::FromAppUnits(aSize.ISize(aWM)),
8299 CSSPixel::FromAppUnits(aSize.BSize(aWM))));
8300 }
8301 return ToString(aSize);
8302}
8303
8304// Debugging
8305void nsIFrame::ListGeneric(nsACString& aTo, const char* aPrefix,
8306 ListFlags aFlags) const {
8307 aTo += aPrefix;
8308 aTo += ListTag();
8309 if (HasView()) {
8310 aTo += nsPrintfCString(" [view=%p]", static_cast<void*>(GetView()));
8311 }
8312 if (GetParent()) {
8313 aTo += nsPrintfCString(" parent=%p", static_cast<void*>(GetParent()));
8314 }
8315 if (GetNextSibling()) {
8316 aTo += nsPrintfCString(" next=%p", static_cast<void*>(GetNextSibling()));
8317 }
8318 if (GetPrevContinuation()) {
8319 bool fluid = GetPrevInFlow() == GetPrevContinuation();
8320 aTo += nsPrintfCString(" prev-%s=%p", fluid ? "in-flow" : "continuation",
8321 static_cast<void*>(GetPrevContinuation()));
8322 }
8323 if (GetNextContinuation()) {
8324 bool fluid = GetNextInFlow() == GetNextContinuation();
8325 aTo += nsPrintfCString(" next-%s=%p", fluid ? "in-flow" : "continuation",
8326 static_cast<void*>(GetNextContinuation()));
8327 }
8328 if (const nsAtom* const autoPageValue =
8329 GetProperty(AutoPageValueProperty())) {
8330 aTo += " AutoPage=";
8331 aTo += nsAtomCString(autoPageValue);
8332 }
8333 if (const nsIFrame::PageValues* const pageValues =
8334 GetProperty(PageValuesProperty())) {
8335 aTo += " PageValues={";
8336 if (pageValues->mStartPageValue) {
8337 aTo += nsAtomCString(pageValues->mStartPageValue);
8338 } else {
8339 aTo += "<null>";
8340 }
8341 aTo += ", ";
8342 if (pageValues->mEndPageValue) {
8343 aTo += nsAtomCString(pageValues->mEndPageValue);
8344 } else {
8345 aTo += "<null>";
8346 }
8347 aTo += "}";
8348 }
8349 void* IBsibling = GetProperty(IBSplitSibling());
8350 if (IBsibling) {
8351 aTo += nsPrintfCString(" IBSplitSibling=%p", IBsibling);
8352 }
8353 void* IBprevsibling = GetProperty(IBSplitPrevSibling());
8354 if (IBprevsibling) {
8355 aTo += nsPrintfCString(" IBSplitPrevSibling=%p", IBprevsibling);
8356 }
8357 if (nsLayoutUtils::FontSizeInflationEnabled(PresContext())) {
8358 if (HasAnyStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT)) {
8359 aTo += nsPrintfCString(" FFR");
8360 if (nsFontInflationData* data =
8361 nsFontInflationData::FindFontInflationDataFor(this)) {
8362 aTo += nsPrintfCString(
8363 ",enabled=%s,UIS=%s", data->InflationEnabled() ? "yes" : "no",
8364 ConvertToString(data->UsableISize(), aFlags).c_str());
8365 }
8366 }
8367 if (HasAnyStateBits(NS_FRAME_FONT_INFLATION_CONTAINER)) {
8368 aTo += nsPrintfCString(" FIC");
8369 }
8370 aTo += nsPrintfCString(" FI=%f", nsLayoutUtils::FontSizeInflationFor(this));
8371 }
8372 aTo += nsPrintfCString(" %s", ConvertToString(mRect, aFlags).c_str());
8373
8374 mozilla::WritingMode wm = GetWritingMode();
8375 if (wm.IsVertical() || wm.IsBidiRTL()) {
8376 aTo +=
8377 nsPrintfCString(" wm=%s logical-size=(%s)", ToString(wm).c_str(),
8378 ConvertToString(GetLogicalSize(), wm, aFlags).c_str());
8379 }
8380
8381 nsIFrame* parent = GetParent();
8382 if (parent) {
8383 WritingMode pWM = parent->GetWritingMode();
8384 if (pWM.IsVertical() || pWM.IsBidiRTL()) {
8385 nsSize containerSize = parent->mRect.Size();
8386 LogicalRect lr(pWM, mRect, containerSize);
8387 aTo += nsPrintfCString(" parent-wm=%s cs=(%s) logical-rect=%s",
8388 ToString(pWM).c_str(),
8389 ConvertToString(containerSize, aFlags).c_str(),
8390 ConvertToString(lr, pWM, aFlags).c_str());
8391 }
8392 }
8393 nsIFrame* f = const_cast<nsIFrame*>(this);
8394 if (f->HasOverflowAreas()) {
8395 nsRect io = f->InkOverflowRect();
8396 if (!io.IsEqualEdges(mRect)) {
8397 aTo += nsPrintfCString(" ink-overflow=%s",
8398 ConvertToString(io, aFlags).c_str());
8399 }
8400 nsRect so = f->ScrollableOverflowRect();
8401 if (!so.IsEqualEdges(mRect)) {
8402 aTo += nsPrintfCString(" scr-overflow=%s",
8403 ConvertToString(so, aFlags).c_str());
8404 }
8405 }
8406 if (OverflowAreas* preTransformOverflows =
8407 f->GetProperty(PreTransformOverflowAreasProperty())) {
8408 nsRect io = preTransformOverflows->InkOverflow();
8409 if (!io.IsEqualEdges(mRect) &&
8410 (!f->HasOverflowAreas() || !io.IsEqualEdges(f->InkOverflowRect()))) {
8411 aTo += nsPrintfCString(" pre-transform-ink-overflow=%s",
8412 ConvertToString(io, aFlags).c_str());
8413 }
8414 nsRect so = preTransformOverflows->ScrollableOverflow();
8415 if (!so.IsEqualEdges(mRect) &&
8416 (!f->HasOverflowAreas() ||
8417 !so.IsEqualEdges(f->ScrollableOverflowRect()))) {
8418 aTo += nsPrintfCString(" pre-transform-scr-overflow=%s",
8419 ConvertToString(so, aFlags).c_str());
8420 }
8421 }
8422 bool hasNormalPosition;
8423 nsPoint normalPosition = GetNormalPosition(&hasNormalPosition);
8424 if (hasNormalPosition) {
8425 aTo += nsPrintfCString(" normal-position=%s",
8426 ConvertToString(normalPosition, aFlags).c_str());
8427 }
8428 if (HasProperty(BidiDataProperty())) {
8429 FrameBidiData bidi = GetBidiData();
8430 aTo += nsPrintfCString(" bidi(%d,%d,%d)", bidi.baseLevel.Value(),
8431 bidi.embeddingLevel.Value(),
8432 bidi.precedingControl.Value());
8433 }
8434 if (IsTransformed()) {
8435 aTo += nsPrintfCString(" transformed");
8436 }
8437 if (ChildrenHavePerspective()) {
8438 aTo += nsPrintfCString(" perspective");
8439 }
8440 if (Extend3DContext()) {
8441 aTo += nsPrintfCString(" extend-3d");
8442 }
8443 if (Combines3DTransformWithAncestors()) {
8444 aTo += nsPrintfCString(" combines-3d-transform-with-ancestors");
8445 }
8446 if (mContent) {
8447 aTo += nsPrintfCString(" [content=%p]", static_cast<void*>(mContent));
8448 }
8449 aTo += nsPrintfCString(" [cs=%p", static_cast<void*>(mComputedStyle));
8450 if (mComputedStyle) {
8451 auto pseudoType = mComputedStyle->GetPseudoType();
8452 aTo += ToString(pseudoType).c_str();
8453 }
8454 aTo += "]";
8455
8456 auto contentVisibility = StyleDisplay()->ContentVisibility(*this);
8457 if (contentVisibility != StyleContentVisibility::Visible) {
8458 aTo += nsPrintfCString(" [content-visibility=");
8459 if (contentVisibility == StyleContentVisibility::Auto) {
8460 aTo += "auto, "_ns;
8461 } else if (contentVisibility == StyleContentVisibility::Hidden) {
8462 aTo += "hiden, "_ns;
8463 }
8464
8465 if (HidesContent()) {
8466 aTo += "HidesContent=hidden"_ns;
8467 } else {
8468 aTo += "HidesContent=visibile"_ns;
8469 }
8470 aTo += "]";
8471 }
8472
8473 if (IsFrameModified()) {
8474 aTo += nsPrintfCString(" modified");
8475 }
8476
8477 if (HasModifiedDescendants()) {
8478 aTo += nsPrintfCString(" has-modified-descendants");
8479 }
8480}
8481
8482void nsIFrame::List(FILE* out, const char* aPrefix, ListFlags aFlags) const {
8483 nsCString str;
8484 ListGeneric(str, aPrefix, aFlags);
8485 fprintf_stderr(out, "%s\n", str.get());
8486}
8487
8488void nsIFrame::ListTextRuns(FILE* out) const {
8489 nsTHashSet<const void*> seen;
8490 ListTextRuns(out, seen);
8491}
8492
8493void nsIFrame::ListTextRuns(FILE* out, nsTHashSet<const void*>& aSeen) const {
8494 for (const auto& childList : ChildLists()) {
8495 for (const nsIFrame* kid : childList.mList) {
8496 kid->ListTextRuns(out, aSeen);
8497 }
8498 }
8499}
8500
8501void nsIFrame::ListMatchedRules(FILE* out, const char* aPrefix) const {
8502 nsTArray<const StyleLockedDeclarationBlock*> rawDecls;
8503 Servo_ComputedValues_GetMatchingDeclarations(Style(), &rawDecls);
8504 for (const StyleLockedDeclarationBlock* rawRule : rawDecls) {
8505 nsAutoCString ruleText;
8506 Servo_DeclarationBlock_GetCssText(rawRule, &ruleText);
8507 fprintf_stderr(out, "%s%s\n", aPrefix, ruleText.get());
8508 }
8509}
8510
8511void nsIFrame::ListWithMatchedRules(FILE* out, const char* aPrefix) const {
8512 fprintf_stderr(out, "%s%s\n", aPrefix, ListTag().get());
8513
8514 nsCString rulePrefix;
8515 rulePrefix += aPrefix;
8516 rulePrefix += " ";
8517 ListMatchedRules(out, rulePrefix.get());
8518}
8519
8520nsresult nsIFrame::GetFrameName(nsAString& aResult) const {
8521 return MakeFrameName(u"Frame"_ns, aResult);
8522}
8523
8524nsresult nsIFrame::MakeFrameName(const nsAString& aType,
8525 nsAString& aResult) const {
8526 aResult = aType;
8527 if (mContent && !mContent->IsText()) {
8528 nsAutoString buf;
8529 mContent->NodeInfo()->NameAtom()->ToString(buf);
8530 if (nsAtom* id = mContent->GetID()) {
8531 buf.AppendLiteral(" id=");
8532 buf.Append(nsDependentAtomString(id));
8533 }
8534 if (IsSubDocumentFrame()) {
8535 nsAutoString src;
8536 mContent->AsElement()->GetAttr(nsGkAtoms::src, src);
8537 buf.AppendLiteral(" src=");
8538 buf.Append(src);
8539 }
8540 aResult.Append('(');
8541 aResult.Append(buf);
8542 aResult.Append(')');
8543 }
8544 aResult.Append('(');
8545 Maybe<uint32_t> index = ContentIndexInContainer(this);
8546 if (index.isSome()) {
8547 aResult.AppendInt(*index);
8548 } else {
8549 aResult.AppendInt(-1);
8550 }
8551 aResult.Append(')');
8552 return NS_OK;
8553}
8554
8555void nsIFrame::DumpFrameTree() const {
8556 PresShell()->GetRootFrame()->List(stderrstderr);
8557}
8558
8559void nsIFrame::DumpFrameTreeInCSSPixels() const {
8560 PresShell()->GetRootFrame()->List(stderrstderr, "", ListFlag::DisplayInCSSPixels);
8561}
8562
8563void nsIFrame::DumpFrameTreeLimited() const { List(stderrstderr); }
8564void nsIFrame::DumpFrameTreeLimitedInCSSPixels() const {
8565 List(stderrstderr, "", ListFlag::DisplayInCSSPixels);
8566}
8567
8568#endif
8569
8570bool nsIFrame::IsVisibleForPainting() const {
8571 return StyleVisibility()->IsVisible();
8572}
8573
8574bool nsIFrame::IsVisibleOrCollapsedForPainting() const {
8575 return StyleVisibility()->IsVisibleOrCollapsed();
8576}
8577
8578/* virtual */
8579bool nsIFrame::IsEmpty() {
8580 return IsHiddenByContentVisibilityOfInFlowParentForLayout();
8581}
8582
8583bool nsIFrame::CachedIsEmpty() {
8584 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"
, 8587); 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) = 8587
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
8585 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"
, 8587); 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) = 8587
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
8586 "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"
, 8587); 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) = 8587
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
8587 "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"
, 8587); 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) = 8587
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
8588 return IsEmpty();
8589}
8590
8591/* virtual */
8592bool nsIFrame::IsSelfEmpty() {
8593 return IsHiddenByContentVisibilityOfInFlowParentForLayout();
8594}
8595
8596nsresult nsIFrame::GetSelectionController(nsPresContext* aPresContext,
8597 nsISelectionController** aSelCon) {
8598 if (!aPresContext || !aSelCon) return NS_ERROR_INVALID_ARG;
8599
8600 nsIFrame* frame = this;
8601 while (frame && frame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)) {
8602 if (nsTextControlFrame* tcf = do_QueryFrame(frame)) {
8603 return tcf->GetOwnedSelectionController(aSelCon);
8604 }
8605 frame = frame->GetParent();
8606 }
8607
8608 *aSelCon = do_AddRef(aPresContext->PresShell()).take();
8609 return NS_OK;
8610}
8611
8612already_AddRefed<nsFrameSelection> nsIFrame::GetFrameSelection() {
8613 RefPtr<nsFrameSelection> fs =
8614 const_cast<nsFrameSelection*>(GetConstFrameSelection());
8615 return fs.forget();
8616}
8617
8618const nsFrameSelection* nsIFrame::GetConstFrameSelection() const {
8619 nsIFrame* frame = const_cast<nsIFrame*>(this);
8620 while (frame && frame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)) {
8621 if (nsTextControlFrame* tcf = do_QueryFrame(frame)) {
8622 return tcf->GetOwnedFrameSelection();
8623 }
8624 frame = frame->GetParent();
8625 }
8626
8627 return PresShell()->ConstFrameSelection();
8628}
8629
8630bool nsIFrame::IsFrameSelected() const {
8631 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"
, 8632); MOZ_PretendNoReturn(); } } while (0)
8632 "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"
, 8632); MOZ_PretendNoReturn(); } } while (0)
;
8633 if (StaticPrefs::dom_shadowdom_selection_across_boundary_enabled()) {
8634 if (const ShadowRoot* shadowRoot =
8635 GetContent()->GetShadowRootForSelection()) {
8636 return shadowRoot->IsSelected(0, shadowRoot->GetChildCount());
8637 }
8638 }
8639 return GetContent()->IsSelected(0, GetContent()->GetChildCount());
8640}
8641
8642nsresult nsIFrame::GetPointFromOffset(int32_t inOffset, nsPoint* outPoint) {
8643 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"
, 8643); AnnotateMozCrashReason("MOZ_ASSERT" "(" "outPoint != nullptr"
") (" "Null parameter" ")"); do { *((volatile int*)__null) =
8643; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false)
;
8644 nsRect contentRect = GetContentRectRelativeToSelf();
8645 nsPoint pt = contentRect.TopLeft();
8646 if (mContent) {
8647 nsIContent* newContent = mContent->GetParent();
8648 if (newContent) {
8649 const int32_t newOffset = newContent->ComputeIndexOf_Deprecated(mContent);
8650
8651 // Find the direction of the frame from the EmbeddingLevelProperty,
8652 // which is the resolved bidi level set in
8653 // nsBidiPresUtils::ResolveParagraph (odd levels = right-to-left).
8654 // If the embedding level isn't set, just use the CSS direction
8655 // property.
8656 bool hasBidiData;
8657 FrameBidiData bidiData = GetProperty(BidiDataProperty(), &hasBidiData);
8658 bool isRTL = hasBidiData
8659 ? bidiData.embeddingLevel.IsRTL()
8660 : StyleVisibility()->mDirection == StyleDirection::Rtl;
8661 if ((!isRTL && inOffset > newOffset) ||
8662 (isRTL && inOffset <= newOffset)) {
8663 pt = contentRect.TopRight();
8664 }
8665 }
8666 }
8667 *outPoint = pt;
8668 return NS_OK;
8669}
8670
8671nsresult nsIFrame::GetCharacterRectsInRange(int32_t aInOffset, int32_t aLength,
8672 nsTArray<nsRect>& aOutRect) {
8673 /* no text */
8674 return NS_ERROR_FAILURE;
8675}
8676
8677nsresult nsIFrame::GetChildFrameContainingOffset(int32_t inContentOffset,
8678 bool inHint,
8679 int32_t* outFrameContentOffset,
8680 nsIFrame** outChildFrame) {
8681 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"
, 8681); AnnotateMozCrashReason("MOZ_ASSERT" "(" "outChildFrame && outFrameContentOffset"
") (" "Null parameter" ")"); do { *((volatile int*)__null) =
8681; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false)
;
8682 *outFrameContentOffset = (int32_t)inHint;
8683 // the best frame to reflect any given offset would be a visible frame if
8684 // possible i.e. we are looking for a valid frame to place the blinking caret
8685 nsRect rect = GetRect();
8686 if (!rect.width || !rect.height) {
8687 // if we have a 0 width or height then lets look for another frame that
8688 // possibly has the same content. If we have no frames in flow then just
8689 // let us return 'this' frame
8690 nsIFrame* nextFlow = GetNextInFlow();
8691 if (nextFlow)
8692 return nextFlow->GetChildFrameContainingOffset(
8693 inContentOffset, inHint, outFrameContentOffset, outChildFrame);
8694 }
8695 *outChildFrame = this;
8696 return NS_OK;
8697}
8698
8699//
8700// What I've pieced together about this routine:
8701// Starting with a block frame (from which a line frame can be gotten)
8702// and a line number, drill down and get the first/last selectable
8703// frame on that line, depending on aPos->mDirection.
8704// aOutSideLimit != 0 means ignore aLineStart, instead work from
8705// the end (if > 0) or beginning (if < 0).
8706//
8707static nsresult GetNextPrevLineFromBlockFrame(PeekOffsetStruct* aPos,
8708 nsIFrame* aBlockFrame,
8709 int32_t aLineStart,
8710 int8_t aOutSideLimit) {
8711 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"
, 8711); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPos" ")");
do { *((volatile int*)__null) = 8711; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8712 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"
, 8712); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aBlockFrame"
")"); do { *((volatile int*)__null) = 8712; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8713
8714 nsPresContext* pc = aBlockFrame->PresContext();
8715
8716 // magic numbers: aLineStart will be -1 for end of block, 0 will be start of
8717 // block.
8718
8719 aPos->mResultFrame = nullptr;
8720 aPos->mResultContent = nullptr;
8721 aPos->mAttach = aPos->mDirection == eDirNext ? CaretAssociationHint::After
8722 : CaretAssociationHint::Before;
8723
8724 AutoAssertNoDomMutations guard;
8725 nsILineIterator* it = aBlockFrame->GetLineIterator();
8726 if (!it) {
8727 return NS_ERROR_FAILURE;
8728 }
8729 int32_t searchingLine = aLineStart;
8730 int32_t countLines = it->GetNumLines();
8731 if (aOutSideLimit > 0) { // start at end
8732 searchingLine = countLines;
8733 } else if (aOutSideLimit < 0) { // start at beginning
8734 searchingLine = -1; //"next" will be 0
8735 } else if ((aPos->mDirection == eDirPrevious && searchingLine == 0) ||
8736 (aPos->mDirection == eDirNext &&
8737 searchingLine >= (countLines - 1))) {
8738 // Not found.
8739 return NS_ERROR_FAILURE;
8740 }
8741 nsIFrame* resultFrame = nullptr;
8742 nsIFrame* farStoppingFrame = nullptr; // we keep searching until we find a
8743 // "this" frame then we go to next line
8744 nsIFrame* nearStoppingFrame = nullptr; // if we are backing up from edge,
8745 // stop here
8746 bool isBeforeFirstFrame, isAfterLastFrame;
8747 bool found = false;
8748
8749 const bool forceInEditableRegion =
8750 aPos->mOptions.contains(PeekOffsetOption::ForceEditableRegion);
8751 while (!found) {
8752 if (aPos->mDirection == eDirPrevious) {
8753 searchingLine--;
8754 } else {
8755 searchingLine++;
8756 }
8757 if ((aPos->mDirection == eDirPrevious && searchingLine < 0) ||
8758 (aPos->mDirection == eDirNext && searchingLine >= countLines)) {
8759 // we need to jump to new block frame.
8760 return NS_ERROR_FAILURE;
8761 }
8762 {
8763 auto line = it->GetLine(searchingLine).unwrap();
8764 if (!line.mNumFramesOnLine) {
8765 continue;
8766 }
8767 nsIFrame* firstFrame = nullptr;
8768 nsIFrame* lastFrame = nullptr;
8769 nsIFrame* frame = line.mFirstFrameOnLine;
8770 int32_t i = line.mNumFramesOnLine;
8771 do {
8772 // If the caller wants a frame for a inclusive ancestor of the ancestor
8773 // limiter, ignore frames for outside the limiter.
8774 if (aPos->FrameContentIsInAncestorLimiter(frame)) {
8775 if (!firstFrame) {
8776 firstFrame = frame;
8777 }
8778 lastFrame = frame;
8779 }
8780 if (i == 1) {
8781 break;
8782 }
8783 frame = frame->GetNextSibling();
8784 if (!frame) {
8785 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"
, 8785); MOZ_PretendNoReturn(); } while (0)
;
8786 return NS_ERROR_FAILURE;
8787 }
8788 } while (--i);
8789 if (!lastFrame) {
8790 // If we're looking for an editable content frame, but all frames in the
8791 // line are not in the specified editing host, return error because we
8792 // must reach the editing host boundary.
8793 return NS_ERROR_FAILURE;
8794 }
8795 nsIFrame::GetLastLeaf(&lastFrame);
8796
8797 if (aPos->mDirection == eDirNext) {
8798 nearStoppingFrame = firstFrame;
8799 farStoppingFrame = lastFrame;
8800 } else {
8801 nearStoppingFrame = lastFrame;
8802 farStoppingFrame = firstFrame;
8803 }
8804 }
8805 nsPoint offset;
8806 nsView* view; // used for call of get offset from view
8807 aBlockFrame->GetOffsetFromView(offset, &view);
8808 nsPoint newDesiredPos =
8809 aPos->mDesiredCaretPos -
8810 offset; // get desired position into blockframe coords
8811 // TODO: nsILineIterator::FindFrameAt should take optional editing host
8812 // parameter and if it's set, it should return the nearest editable frame
8813 // for the editing host when the frame at the desired position is not
8814 // editable.
8815 nsresult rv = it->FindFrameAt(searchingLine, newDesiredPos, &resultFrame,
8816 &isBeforeFirstFrame, &isAfterLastFrame);
8817 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
8818 continue;
8819 }
8820
8821 if (resultFrame) {
8822 // If ancestor limiter is specified and we reached outside content of it,
8823 // return error because we reached its element boundary.
8824 if (!aPos->FrameContentIsInAncestorLimiter(resultFrame)) {
8825 return NS_ERROR_FAILURE;
8826 }
8827 // check to see if this is ANOTHER blockframe inside the other one if so
8828 // then call into its lines
8829 if (resultFrame->CanProvideLineIterator()) {
8830 aPos->mResultFrame = resultFrame;
8831 return NS_OK;
8832 }
8833 // resultFrame is not a block frame
8834 Maybe<nsFrameIterator> frameIterator;
8835 frameIterator.emplace(
8836 pc, resultFrame, nsFrameIterator::Type::PostOrder,
8837 false, // aVisual
8838 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller),
8839 false, // aFollowOOFs
8840 false // aSkipPopupChecks
8841 );
8842
8843 auto FoundValidFrame = [forceInEditableRegion, aPos](
8844 const nsIFrame::ContentOffsets& aOffsets,
8845 const nsIFrame* aFrame) {
8846 if (!aOffsets.content) {
8847 return false;
8848 }
8849 if (!aFrame->IsSelectable(nullptr)) {
8850 return false;
8851 }
8852 if (aPos->mAncestorLimiter &&
8853 !aOffsets.content->IsInclusiveDescendantOf(
8854 aPos->mAncestorLimiter)) {
8855 return false;
8856 }
8857 if (forceInEditableRegion && !aOffsets.content->IsEditable()) {
8858 return false;
8859 }
8860 return true;
8861 };
8862
8863 nsIFrame* storeOldResultFrame = resultFrame;
8864 while (!found) {
8865 nsPoint point;
8866 nsRect tempRect = resultFrame->GetRect();
8867 nsPoint offset;
8868 nsView* view; // used for call of get offset from view
8869 resultFrame->GetOffsetFromView(offset, &view);
8870 if (!view) {
8871 return NS_ERROR_FAILURE;
8872 }
8873 if (resultFrame->GetWritingMode().IsVertical()) {
8874 point.y = aPos->mDesiredCaretPos.y;
8875 point.x = tempRect.width + offset.x;
8876 } else {
8877 point.y = tempRect.height + offset.y;
8878 point.x = aPos->mDesiredCaretPos.x;
8879 }
8880
8881 if (!resultFrame->HasView()) {
8882 nsView* view;
8883 nsPoint offset;
8884 resultFrame->GetOffsetFromView(offset, &view);
8885 nsIFrame::ContentOffsets offsets =
8886 resultFrame->GetContentOffsetsFromPoint(
8887 point - offset, nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE);
8888 aPos->mResultContent = offsets.content;
8889 aPos->mContentOffset = offsets.offset;
8890 aPos->mAttach = offsets.associate;
8891 if (FoundValidFrame(offsets, resultFrame)) {
8892 found = true;
8893 break;
8894 }
8895 }
8896
8897 if (aPos->mDirection == eDirPrevious &&
8898 resultFrame == farStoppingFrame) {
8899 break;
8900 }
8901 if (aPos->mDirection == eDirNext && resultFrame == nearStoppingFrame) {
8902 break;
8903 }
8904 // always try previous on THAT line if that fails go the other way
8905 resultFrame = frameIterator->Traverse(/* aForward = */ false);
8906 if (!resultFrame) {
8907 return NS_ERROR_FAILURE;
8908 }
8909 }
8910
8911 if (!found) {
8912 resultFrame = storeOldResultFrame;
8913 frameIterator.reset();
8914 frameIterator.emplace(
8915 pc, resultFrame, nsFrameIterator::Type::Leaf,
8916 false, // aVisual
8917 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller),
8918 false, // aFollowOOFs
8919 false // aSkipPopupChecks
8920 );
8921 MOZ_ASSERT(frameIterator)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(frameIterator)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(frameIterator))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("frameIterator",
"/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 8921); AnnotateMozCrashReason("MOZ_ASSERT" "(" "frameIterator"
")"); do { *((volatile int*)__null) = 8921; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8922 }
8923 while (!found) {
8924 nsPoint point = aPos->mDesiredCaretPos;
8925 nsView* view;
8926 nsPoint offset;
8927 resultFrame->GetOffsetFromView(offset, &view);
8928 nsIFrame::ContentOffsets offsets =
8929 resultFrame->GetContentOffsetsFromPoint(
8930 point - offset, nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE);
8931 aPos->mResultContent = offsets.content;
8932 aPos->mContentOffset = offsets.offset;
8933 aPos->mAttach = offsets.associate;
8934 if (FoundValidFrame(offsets, resultFrame)) {
8935 found = true;
8936 aPos->mAttach = resultFrame == farStoppingFrame
8937 ? CaretAssociationHint::Before
8938 : CaretAssociationHint::After;
8939 break;
8940 }
8941 if (aPos->mDirection == eDirPrevious &&
8942 resultFrame == nearStoppingFrame) {
8943 break;
8944 }
8945 if (aPos->mDirection == eDirNext && resultFrame == farStoppingFrame) {
8946 break;
8947 }
8948 // previous didnt work now we try "next"
8949 nsIFrame* tempFrame = frameIterator->Traverse(/* aForward = */ true);
8950 if (!tempFrame) {
8951 break;
8952 }
8953 resultFrame = tempFrame;
8954 }
8955 aPos->mResultFrame = resultFrame;
8956 } else {
8957 // we need to jump to new block frame.
8958 aPos->mAmount = eSelectLine;
8959 aPos->mStartOffset = 0;
8960 aPos->mAttach = aPos->mDirection == eDirNext
8961 ? CaretAssociationHint::Before
8962 : CaretAssociationHint::After;
8963 if (aPos->mDirection == eDirPrevious) {
8964 aPos->mStartOffset = -1; // start from end
8965 }
8966 return aBlockFrame->PeekOffset(aPos);
8967 }
8968 }
8969 return NS_OK;
8970}
8971
8972nsIFrame::CaretPosition nsIFrame::GetExtremeCaretPosition(bool aStart) {
8973 CaretPosition result;
8974
8975 FrameTarget targetFrame = DrillDownToSelectionFrame(this, !aStart, 0);
8976 FrameContentRange range = GetRangeForFrame(targetFrame.frame);
8977 result.mResultContent = range.content;
8978 result.mContentOffset = aStart ? range.start : range.end;
8979 return result;
8980}
8981
8982// If this is a preformatted text frame, see if it ends with a newline
8983static nsContentAndOffset FindLineBreakInText(nsIFrame* aFrame,
8984 nsDirection aDirection) {
8985 nsContentAndOffset result;
8986
8987 if (aFrame->IsGeneratedContentFrame() ||
8988 !aFrame->HasSignificantTerminalNewline()) {
8989 return result;
8990 }
8991
8992 int32_t endOffset = aFrame->GetOffsets().second;
8993 result.mContent = aFrame->GetContent();
8994 result.mOffset = endOffset - (aDirection == eDirPrevious ? 0 : 1);
8995 return result;
8996}
8997
8998// Find the first (or last) descendant of the given frame
8999// which is either a block-level frame or a BRFrame, or some other kind of break
9000// which stops the line.
9001static nsContentAndOffset FindLineBreakingFrame(nsIFrame* aFrame,
9002 nsDirection aDirection) {
9003 nsContentAndOffset result;
9004
9005 if (aFrame->IsGeneratedContentFrame()) {
9006 return result;
9007 }
9008
9009 // Treat form controls and other replaced inline level elements as inline
9010 // leaves.
9011 if (aFrame->IsReplaced() && aFrame->IsInlineOutside() &&
9012 !aFrame->IsBrFrame() && !aFrame->IsTextFrame()) {
9013 return result;
9014 }
9015
9016 // Check the frame itself
9017 // Fall through block-in-inline split frames because their mContent is
9018 // the content of the inline frames they were created from. The
9019 // first/last child of such frames is the real block frame we're
9020 // looking for.
9021 if ((aFrame->IsBlockOutside() &&
9022 !aFrame->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) ||
9023 aFrame->IsBrFrame()) {
9024 nsIContent* content = aFrame->GetContent();
9025 result.mContent = content->GetParent();
9026 // In some cases (bug 310589, bug 370174) we end up here with a null
9027 // content. This probably shouldn't ever happen, but since it sometimes
9028 // does, we want to avoid crashing here.
9029 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"
, 9029); MOZ_PretendNoReturn(); } } while (0)
;
9030 if (result.mContent) {
9031 result.mOffset = result.mContent->ComputeIndexOf_Deprecated(content) +
9032 (aDirection == eDirPrevious ? 1 : 0);
9033 }
9034 return result;
9035 }
9036
9037 result = FindLineBreakInText(aFrame, aDirection);
9038 if (result.mContent) {
9039 return result;
9040 }
9041
9042 // Iterate over children and call ourselves recursively
9043 if (aDirection == eDirPrevious) {
9044 nsIFrame* child = aFrame->PrincipalChildList().LastChild();
9045 while (child && !result.mContent) {
9046 result = FindLineBreakingFrame(child, aDirection);
9047 child = child->GetPrevSibling();
9048 }
9049 } else { // eDirNext
9050 nsIFrame* child = aFrame->PrincipalChildList().FirstChild();
9051 while (child && !result.mContent) {
9052 result = FindLineBreakingFrame(child, aDirection);
9053 child = child->GetNextSibling();
9054 }
9055 }
9056 return result;
9057}
9058
9059nsresult nsIFrame::PeekOffsetForParagraph(PeekOffsetStruct* aPos) {
9060 nsIFrame* frame = this;
9061 nsContentAndOffset blockFrameOrBR;
9062 blockFrameOrBR.mContent = nullptr;
9063 bool reachedLimit = frame->IsBlockOutside() || IsEditingHost(frame);
9064
9065 auto traverse = [&aPos](nsIFrame* current) {
9066 return aPos->mDirection == eDirPrevious ? current->GetPrevSibling()
9067 : current->GetNextSibling();
9068 };
9069
9070 // Go through containing frames until reaching a block frame.
9071 // In each step, search the previous (or next) siblings for the closest
9072 // "stop frame" (a block frame or a BRFrame).
9073 // If found, set it to be the selection boundary and abort.
9074 while (!reachedLimit) {
9075 nsIFrame* parent = frame->GetParent();
9076 // Treat a frame associated with the root content as if it were a block
9077 // frame.
9078 if (!frame->mContent || !frame->mContent->GetParent()) {
9079 reachedLimit = true;
9080 break;
9081 }
9082
9083 if (aPos->mDirection == eDirNext) {
9084 // Try to find our own line-break before looking at our siblings.
9085 blockFrameOrBR = FindLineBreakInText(frame, eDirNext);
9086 }
9087
9088 nsIFrame* sibling = traverse(frame);
9089 while (sibling && !blockFrameOrBR.mContent) {
9090 blockFrameOrBR = FindLineBreakingFrame(sibling, aPos->mDirection);
9091 sibling = traverse(sibling);
9092 }
9093 if (blockFrameOrBR.mContent) {
9094 aPos->mResultContent = blockFrameOrBR.mContent;
9095 aPos->mContentOffset = blockFrameOrBR.mOffset;
9096 break;
9097 }
9098 frame = parent;
9099 reachedLimit = frame && (frame->IsBlockOutside() || IsEditingHost(frame));
9100 }
9101
9102 if (reachedLimit) { // no "stop frame" found
9103 aPos->mResultContent = frame->GetContent();
9104 if (ShadowRoot* shadowRoot =
9105 aPos->mResultContent->GetShadowRootForSelection()) {
9106 // Even if there's no children for this node,
9107 // the elements inside the shadow root is still
9108 // selectable
9109 aPos->mResultContent = shadowRoot;
9110 }
9111 if (aPos->mDirection == eDirPrevious) {
9112 aPos->mContentOffset = 0;
9113 } else if (aPos->mResultContent) {
9114 aPos->mContentOffset = aPos->mResultContent->GetChildCount();
9115 }
9116 }
9117 return NS_OK;
9118}
9119
9120// Determine movement direction relative to frame
9121static bool IsMovingInFrameDirection(const nsIFrame* frame,
9122 nsDirection aDirection, bool aVisual) {
9123 bool isReverseDirection =
9124 aVisual && nsBidiPresUtils::IsReversedDirectionFrame(frame);
9125 return aDirection == (isReverseDirection ? eDirPrevious : eDirNext);
9126}
9127
9128// Determines "are we looking for a boundary between whitespace and
9129// non-whitespace (in the direction we're moving in)". It is true when moving
9130// forward and looking for a beginning of a word, or when moving backwards and
9131// looking for an end of a word.
9132static bool ShouldWordSelectionEatSpace(const PeekOffsetStruct& aPos) {
9133 if (aPos.mWordMovementType != eDefaultBehavior) {
9134 // aPos->mWordMovementType possible values:
9135 // eEndWord: eat the space if we're moving backwards
9136 // eStartWord: eat the space if we're moving forwards
9137 return (aPos.mWordMovementType == eEndWord) ==
9138 (aPos.mDirection == eDirPrevious);
9139 }
9140 // Use the hidden preference which is based on operating system
9141 // behavior. This pref only affects whether moving forward by word
9142 // should go to the end of this word or start of the next word. When
9143 // going backwards, the start of the word is always used, on every
9144 // operating system.
9145 return aPos.mDirection == eDirNext &&
9146 StaticPrefs::layout_word_select_eat_space_to_next_word();
9147}
9148
9149enum class OffsetIsAtLineEdge : bool { No, Yes };
9150
9151static void SetPeekResultFromFrame(PeekOffsetStruct& aPos, nsIFrame* aFrame,
9152 int32_t aOffset,
9153 OffsetIsAtLineEdge aAtLineEdge) {
9154 FrameContentRange range = GetRangeForFrame(aFrame);
9155 aPos.mResultFrame = aFrame;
9156 aPos.mResultContent = range.content;
9157 // Output offset is relative to content, not frame
9158 aPos.mContentOffset =
9159 aOffset < 0 ? range.end + aOffset + 1 : range.start + aOffset;
9160 if (aAtLineEdge == OffsetIsAtLineEdge::Yes) {
9161 aPos.mAttach = aPos.mContentOffset == range.start
9162 ? CaretAssociationHint::After
9163 : CaretAssociationHint::Before;
9164 }
9165}
9166
9167void nsIFrame::SelectablePeekReport::TransferTo(PeekOffsetStruct& aPos) const {
9168 return SetPeekResultFromFrame(aPos, mFrame, mOffset, OffsetIsAtLineEdge::No);
9169}
9170
9171nsIFrame::SelectablePeekReport::SelectablePeekReport(
9172 const mozilla::GenericErrorResult<nsresult>&& aErr) {
9173 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"
, 9173); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(NS_FAILED_impl(aErr.operator nsresult())), 0)))"
")"); do { *((volatile int*)__null) = 9173; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9174 // Return an empty report
9175}
9176
9177nsresult nsIFrame::PeekOffsetForCharacter(PeekOffsetStruct* aPos,
9178 int32_t aOffset) {
9179 SelectablePeekReport current{this, aOffset};
9180
9181 nsIFrame::FrameSearchResult peekSearchState = CONTINUE;
9182
9183 while (peekSearchState != FOUND) {
9184 const bool movingInFrameDirection = IsMovingInFrameDirection(
9185 current.mFrame, aPos->mDirection,
9186 aPos->mOptions.contains(PeekOffsetOption::Visual));
9187
9188 if (current.mJumpedLine) {
9189 // If we jumped lines, it's as if we found a character, but we still need
9190 // to eat non-renderable content on the new line.
9191 peekSearchState = current.PeekOffsetNoAmount(movingInFrameDirection);
9192 } else {
9193 PeekOffsetCharacterOptions options;
9194 options.mRespectClusters = aPos->mAmount == eSelectCluster;
9195 peekSearchState =
9196 current.PeekOffsetCharacter(movingInFrameDirection, options);
9197 }
9198
9199 current.mMovedOverNonSelectableText |=
9200 peekSearchState == CONTINUE_UNSELECTABLE;
9201
9202 if (peekSearchState != FOUND) {
9203 SelectablePeekReport next = current.mFrame->GetFrameFromDirection(*aPos);
9204 if (next.Failed()) {
9205 return NS_ERROR_FAILURE;
9206 }
9207 next.mJumpedLine |= current.mJumpedLine;
9208 next.mMovedOverNonSelectableText |= current.mMovedOverNonSelectableText;
9209 next.mHasSelectableFrame |= current.mHasSelectableFrame;
9210 current = next;
9211 }
9212
9213 // Found frame, but because we moved over non selectable text we want
9214 // the offset to be at the frame edge. Note that if we are extending the
9215 // selection, this doesn't matter.
9216 if (peekSearchState == FOUND && current.mMovedOverNonSelectableText &&
9217 (!aPos->mOptions.contains(PeekOffsetOption::Extend) ||
9218 current.mHasSelectableFrame)) {
9219 auto [start, end] = current.mFrame->GetOffsets();
9220 current.mOffset = aPos->mDirection == eDirNext ? 0 : end - start;
9221 }
9222 }
9223
9224 // Set outputs
9225 current.TransferTo(*aPos);
9226 // If we're dealing with a text frame and moving backward positions us at
9227 // the end of that line, decrease the offset by one to make sure that
9228 // we're placed before the linefeed character on the previous line.
9229 if (current.mOffset < 0 && current.mJumpedLine &&
9230 aPos->mDirection == eDirPrevious &&
9231 current.mFrame->HasSignificantTerminalNewline() &&
9232 !current.mIgnoredBrFrame) {
9233 --aPos->mContentOffset;
9234 }
9235 return NS_OK;
9236}
9237
9238nsresult nsIFrame::PeekOffsetForWord(PeekOffsetStruct* aPos, int32_t aOffset) {
9239 SelectablePeekReport current{this, aOffset};
9240 bool shouldStopAtHardBreak =
9241 aPos->mWordMovementType == eDefaultBehavior &&
9242 StaticPrefs::layout_word_select_eat_space_to_next_word();
9243 bool wordSelectEatSpace = ShouldWordSelectionEatSpace(*aPos);
9244
9245 PeekWordState state;
9246 while (true) {
9247 bool movingInFrameDirection = IsMovingInFrameDirection(
9248 current.mFrame, aPos->mDirection,
9249 aPos->mOptions.contains(PeekOffsetOption::Visual));
9250
9251 FrameSearchResult searchResult = current.mFrame->PeekOffsetWord(
9252 movingInFrameDirection, wordSelectEatSpace,
9253 aPos->mOptions.contains(PeekOffsetOption::IsKeyboardSelect),
9254 &current.mOffset, &state,
9255 !aPos->mOptions.contains(PeekOffsetOption::PreserveSpaces));
9256 if (searchResult == FOUND) {
9257 break;
9258 }
9259
9260 SelectablePeekReport next = [&]() {
9261 PeekOffsetOptions options = aPos->mOptions;
9262 if (state.mSawInlineCharacter) {
9263 // If we've already found a character, we don't want to stop at
9264 // placeholder frame boundary if there is in the word.
9265 options += PeekOffsetOption::StopAtPlaceholder;
9266 }
9267 return current.mFrame->GetFrameFromDirection(aPos->mDirection, options);
9268 }();
9269 if (next.Failed()) {
9270 // If we've crossed the line boundary, check to make sure that we
9271 // have not consumed a trailing newline as whitespace if it's
9272 // significant.
9273 if (next.mJumpedLine && wordSelectEatSpace &&
9274 current.mFrame->HasSignificantTerminalNewline() &&
9275 current.mFrame->StyleText()->mWhiteSpaceCollapse !=
9276 StyleWhiteSpaceCollapse::PreserveBreaks) {
9277 current.mOffset -= 1;
9278 }
9279 break;
9280 }
9281
9282 if ((next.mJumpedLine || next.mFoundPlaceholder) && !wordSelectEatSpace &&
9283 state.mSawBeforeType) {
9284 // We can't jump lines if we're looking for whitespace following
9285 // non-whitespace, and we already encountered non-whitespace.
9286 break;
9287 }
9288
9289 if (shouldStopAtHardBreak && next.mJumpedHardBreak) {
9290 /**
9291 * Prev, always: Jump and stop right there
9292 * Next, saw inline: just stop
9293 * Next, no inline: Jump and consume whitespaces
9294 */
9295 if (aPos->mDirection == eDirPrevious) {
9296 // Try moving to the previous line if exists
9297 current.TransferTo(*aPos);
9298 current.mFrame->PeekOffsetForCharacter(aPos, current.mOffset);
9299 return NS_OK;
9300 }
9301 if (state.mSawInlineCharacter || current.mJumpedHardBreak) {
9302 if (current.mFrame->HasSignificantTerminalNewline()) {
9303 current.mOffset -= 1;
9304 }
9305 current.TransferTo(*aPos);
9306 return NS_OK;
9307 }
9308 // Mark the state as whitespace and continue
9309 state.Update(false, true);
9310 }
9311
9312 if (next.mJumpedLine) {
9313 state.mContext.Truncate();
9314 }
9315 current = next;
9316 // Jumping a line is equivalent to encountering whitespace
9317 // This affects only when it already met an actual character
9318 if (wordSelectEatSpace && next.mJumpedLine) {
9319 state.SetSawBeforeType();
9320 }
9321 }
9322
9323 // Set outputs
9324 current.TransferTo(*aPos);
9325 return NS_OK;
9326}
9327
9328static nsIFrame* GetFirstSelectableDescendantWithLineIterator(
9329 const PeekOffsetStruct& aPeekOffsetStruct, nsIFrame* aParentFrame) {
9330 const bool forceEditableRegion = aPeekOffsetStruct.mOptions.contains(
9331 PeekOffsetOption::ForceEditableRegion);
9332 auto FoundValidFrame = [aPeekOffsetStruct,
9333 forceEditableRegion](const nsIFrame* aFrame) {
9334 if (!aFrame->IsSelectable(nullptr)) {
9335 return false;
9336 }
9337 if (!aPeekOffsetStruct.FrameContentIsInAncestorLimiter(aFrame)) {
9338 return false;
9339 }
9340 if (forceEditableRegion && !aFrame->ContentIsEditable()) {
9341 return false;
9342 }
9343 return true;
9344 };
9345
9346 for (nsIFrame* child : aParentFrame->PrincipalChildList()) {
9347 // some children may not be selectable, e.g. :before / :after pseudoelements
9348 // content with user-select: none, or contenteditable="false"
9349 // we need to skip them
9350 if (child->CanProvideLineIterator() && FoundValidFrame(child)) {
9351 return child;
9352 }
9353 if (nsIFrame* nested = GetFirstSelectableDescendantWithLineIterator(
9354 aPeekOffsetStruct, child)) {
9355 return nested;
9356 }
9357 }
9358 return nullptr;
9359}
9360
9361nsresult nsIFrame::PeekOffsetForLine(PeekOffsetStruct* aPos) {
9362 nsIFrame* blockFrame = this;
9363 nsresult result = NS_ERROR_FAILURE;
9364
9365 // outer loop
9366 // moving to a next block when no more blocks are available in a subtree
9367 AutoAssertNoDomMutations guard;
9368 while (NS_FAILED(result)((bool)(__builtin_expect(!!(NS_FAILED_impl(result)), 0)))) {
9369 auto [newBlock, lineFrame] = blockFrame->GetContainingBlockForLine(
9370 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller));
9371 if (!newBlock) {
9372 return NS_ERROR_FAILURE;
9373 }
9374 // FYI: If the editing host is an inline element, the block frame content
9375 // may be either not editable or editable but belonging to different editing
9376 // host.
9377 blockFrame = newBlock;
9378 nsILineIterator* iter = blockFrame->GetLineIterator();
9379 int32_t thisLine = iter->FindLineContaining(lineFrame);
9380 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"
, 9380)
) {
9381 return NS_ERROR_FAILURE;
9382 }
9383
9384 int8_t edgeCase = 0; // no edge case. This should look at thisLine
9385
9386 // this part will find a frame or a block frame. If it's a block frame
9387 // it will "drill down" to find a viable frame or it will return an
9388 // error.
9389 nsIFrame* lastFrame = this;
9390
9391 // inner loop - crawling the frames within a specific block subtree
9392 while (true) {
9393 result =
9394 GetNextPrevLineFromBlockFrame(aPos, blockFrame, thisLine, edgeCase);
9395 // we came back to same spot! keep going
9396 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) &&
9397 (!aPos->mResultFrame || aPos->mResultFrame == lastFrame)) {
9398 aPos->mResultFrame = nullptr;
9399 lastFrame = nullptr;
9400 if (aPos->mDirection == eDirPrevious) {
9401 thisLine--;
9402 } else {
9403 thisLine++;
9404 }
9405 continue;
9406 }
9407
9408 if (NS_FAILED(result)((bool)(__builtin_expect(!!(NS_FAILED_impl(result)), 0)))) {
9409 break;
9410 }
9411
9412 lastFrame = aPos->mResultFrame; // set last frame
9413 /* SPECIAL CHECK FOR NAVIGATION INTO TABLES
9414 * when we hit a frame which doesn't have line iterator, we need to
9415 * drill down and find a child with the line iterator to prevent the
9416 * crawling process to prematurely finish. Note that this is only sound if
9417 * we're guaranteed to not have multiple children implementing
9418 * LineIterator.
9419 *
9420 * So far known cases are:
9421 * 1) table wrapper (drill down into table row group)
9422 * 2) table cell (drill down into its only anon child)
9423 */
9424 const bool shouldDrillIntoChildren =
9425 aPos->mResultFrame->IsTableWrapperFrame() ||
9426 aPos->mResultFrame->IsTableCellFrame();
9427
9428 if (shouldDrillIntoChildren) {
9429 nsIFrame* child = GetFirstSelectableDescendantWithLineIterator(
9430 *aPos, aPos->mResultFrame);
9431 if (child) {
9432 aPos->mResultFrame = child;
9433 }
9434 }
9435
9436 if (!aPos->mResultFrame->CanProvideLineIterator()) {
9437 // no more selectable content at this level
9438 break;
9439 }
9440
9441 if (aPos->mResultFrame == blockFrame) {
9442 // Make sure block element is not the same as the one we had before.
9443 break;
9444 }
9445
9446 // we've struck another block element with selectable content!
9447 if (aPos->mDirection == eDirPrevious) {
9448 edgeCase = 1; // far edge, search from end backwards
9449 } else {
9450 edgeCase = -1; // near edge search from beginning onwards
9451 }
9452 thisLine = 0; // this line means nothing now.
9453 // everything else means something so keep looking "inside" the
9454 // block
9455 blockFrame = aPos->mResultFrame;
9456 }
9457 }
9458 return result;
9459}
9460
9461nsresult nsIFrame::PeekOffsetForLineEdge(PeekOffsetStruct* aPos) {
9462 // Adjusted so that the caret can't get confused when content changes
9463 nsIFrame* frame = AdjustFrameForSelectionStyles(this);
9464 Element* editingHost = frame->GetContent()->GetEditingHost();
9465
9466 auto [blockFrame, lineFrame] = frame->GetContainingBlockForLine(
9467 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller));
9468 if (!blockFrame) {
9469 return NS_ERROR_FAILURE;
9470 }
9471 AutoAssertNoDomMutations guard;
9472 nsILineIterator* it = blockFrame->GetLineIterator();
9473 int32_t thisLine = it->FindLineContaining(lineFrame);
9474 if (thisLine < 0) {
9475 return NS_ERROR_FAILURE;
9476 }
9477
9478 nsIFrame* baseFrame = nullptr;
9479 bool endOfLine = eSelectEndLine == aPos->mAmount;
9480
9481 if (aPos->mOptions.contains(PeekOffsetOption::Visual) &&
9482 PresContext()->BidiEnabled()) {
9483 nsIFrame* firstFrame;
9484 bool isReordered;
9485 nsIFrame* lastFrame;
9486 MOZ_TRY(do { auto mozTryTempResult_ = ::mozilla::ToResult(it->CheckLineOrder
(thisLine, &isReordered, &firstFrame, &lastFrame)
); if ((__builtin_expect(!!(mozTryTempResult_.isErr()), 0))) {
return mozTryTempResult_.propagateErr(); } } while (0)
9487 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)
;
9488 baseFrame = endOfLine ? lastFrame : firstFrame;
9489 } else {
9490 auto line = it->GetLine(thisLine).unwrap();
9491
9492 nsIFrame* frame = line.mFirstFrameOnLine;
9493 bool lastFrameWasEditable = false;
9494 for (int32_t count = line.mNumFramesOnLine; count;
9495 --count, frame = frame->GetNextSibling()) {
9496 if (frame->IsGeneratedContentFrame()) {
9497 continue;
9498 }
9499 // When jumping to the end of the line with the "end" key,
9500 // try to skip over brFrames
9501 if (endOfLine && line.mNumFramesOnLine > 1 && frame->IsBrFrame() &&
9502 lastFrameWasEditable == frame->GetContent()->IsEditable()) {
9503 continue;
9504 }
9505 lastFrameWasEditable =
9506 frame->GetContent() && frame->GetContent()->IsEditable();
9507 baseFrame = frame;
9508 if (!endOfLine) {
9509 break;
9510 }
9511 }
9512 }
9513 if (!baseFrame) {
9514 return NS_ERROR_FAILURE;
9515 }
9516 // Make sure we are not leaving our inline editing host if exists
9517 if (editingHost) {
9518 if (nsIFrame* frame = editingHost->GetPrimaryFrame()) {
9519 if (frame->IsInlineOutside() &&
9520 !editingHost->Contains(baseFrame->GetContent())) {
9521 baseFrame = frame;
9522 if (endOfLine) {
9523 baseFrame = baseFrame->LastContinuation();
9524 }
9525 }
9526 }
9527 }
9528 FrameTarget targetFrame = DrillDownToSelectionFrame(
9529 baseFrame, endOfLine, nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE);
9530 SetPeekResultFromFrame(*aPos, targetFrame.frame, endOfLine ? -1 : 0,
9531 OffsetIsAtLineEdge::Yes);
9532 if (endOfLine && targetFrame.frame->HasSignificantTerminalNewline()) {
9533 // Do not position the caret after the terminating newline if we're
9534 // trying to move to the end of line (see bug 596506)
9535 --aPos->mContentOffset;
9536 }
9537 if (!aPos->mResultContent) {
9538 return NS_ERROR_FAILURE;
9539 }
9540 return NS_OK;
9541}
9542
9543nsresult nsIFrame::PeekOffset(PeekOffsetStruct* aPos) {
9544 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"
, 9544); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPos" ")");
do { *((volatile int*)__null) = 9544; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9545
9546 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"
, 9546)
) {
9547 // FIXME(Bug 1654362): <caption> currently can remain dirty.
9548 return NS_ERROR_UNEXPECTED;
9549 }
9550
9551 // Translate content offset to be relative to frame
9552 int32_t offset = aPos->mStartOffset - GetRangeForFrame(this).start;
9553
9554 switch (aPos->mAmount) {
9555 case eSelectCharacter:
9556 case eSelectCluster:
9557 return PeekOffsetForCharacter(aPos, offset);
9558 case eSelectWordNoSpace:
9559 // eSelectWordNoSpace means that we should not be eating any whitespace
9560 // when moving to the adjacent word. This means that we should set aPos->
9561 // mWordMovementType to eEndWord if we're moving forwards, and to
9562 // eStartWord if we're moving backwards.
9563 if (aPos->mDirection == eDirPrevious) {
9564 aPos->mWordMovementType = eStartWord;
9565 } else {
9566 aPos->mWordMovementType = eEndWord;
9567 }
9568 // Intentionally fall through the eSelectWord case.
9569 [[fallthrough]];
9570 case eSelectWord:
9571 return PeekOffsetForWord(aPos, offset);
9572 case eSelectLine:
9573 return PeekOffsetForLine(aPos);
9574 case eSelectBeginLine:
9575 case eSelectEndLine:
9576 return PeekOffsetForLineEdge(aPos);
9577 case eSelectParagraph:
9578 return PeekOffsetForParagraph(aPos);
9579 default: {
9580 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"
, 9580); MOZ_PretendNoReturn(); } } while (0)
;
9581 return NS_ERROR_FAILURE;
9582 }
9583 }
9584}
9585
9586nsIFrame::FrameSearchResult nsIFrame::PeekOffsetNoAmount(bool aForward,
9587 int32_t* aOffset) {
9588 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"
, 9588); MOZ_PretendNoReturn(); } } while (0)
;
9589 // Sure, we can stop right here.
9590 return FOUND;
9591}
9592
9593nsIFrame::FrameSearchResult nsIFrame::PeekOffsetCharacter(
9594 bool aForward, int32_t* aOffset, PeekOffsetCharacterOptions aOptions) {
9595 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"
, 9595); MOZ_PretendNoReturn(); } } while (0)
;
9596 int32_t startOffset = *aOffset;
9597 // A negative offset means "end of frame", which in our case means offset 1.
9598 if (startOffset < 0) startOffset = 1;
9599 if (aForward == (startOffset == 0)) {
9600 // We're before the frame and moving forward, or after it and moving
9601 // backwards: skip to the other side and we're done.
9602 *aOffset = 1 - startOffset;
9603 return FOUND;
9604 }
9605 return CONTINUE;
9606}
9607
9608nsIFrame::FrameSearchResult nsIFrame::PeekOffsetWord(
9609 bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
9610 int32_t* aOffset, PeekWordState* aState, bool /*aTrimSpaces*/) {
9611 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"
, 9611); MOZ_PretendNoReturn(); } } while (0)
;
9612 int32_t startOffset = *aOffset;
9613 // This isn't text, so truncate the context
9614 aState->mContext.Truncate();
9615 if (startOffset < 0) startOffset = 1;
9616 if (aForward == (startOffset == 0)) {
9617 // We're before the frame and moving forward, or after it and moving
9618 // backwards. If we're looking for non-whitespace, we found it (without
9619 // skipping this frame).
9620 if (!aState->mAtStart) {
9621 if (aState->mLastCharWasPunctuation) {
9622 // We're not punctuation, so this is a punctuation boundary.
9623 if (BreakWordBetweenPunctuation(aState, aForward, false, false,
9624 aIsKeyboardSelect))
9625 return FOUND;
9626 } else {
9627 // This is not a punctuation boundary.
9628 if (aWordSelectEatSpace && aState->mSawBeforeType) return FOUND;
9629 }
9630 }
9631 // Otherwise skip to the other side and note that we encountered
9632 // non-whitespace.
9633 *aOffset = 1 - startOffset;
9634 aState->Update(false, // not punctuation
9635 false // not whitespace
9636 );
9637 if (!aWordSelectEatSpace) aState->SetSawBeforeType();
9638 }
9639 return CONTINUE;
9640}
9641
9642// static
9643bool nsIFrame::BreakWordBetweenPunctuation(const PeekWordState* aState,
9644 bool aForward, bool aPunctAfter,
9645 bool aWhitespaceAfter,
9646 bool aIsKeyboardSelect) {
9647 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"
, 9648); MOZ_PretendNoReturn(); } } while (0)
9648 "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"
, 9648); MOZ_PretendNoReturn(); } } while (0)
;
9649 if (aState->mLastCharWasWhitespace) {
9650 // We always stop between whitespace and punctuation
9651 return true;
9652 }
9653 if (!StaticPrefs::layout_word_select_stop_at_punctuation()) {
9654 // When this pref is false, we never stop at a punctuation boundary unless
9655 // it's followed by whitespace (in the relevant direction).
9656 return aWhitespaceAfter;
9657 }
9658 if (!aIsKeyboardSelect) {
9659 // mouse caret movement (e.g. word selection) always stops at every
9660 // punctuation boundary
9661 return true;
9662 }
9663 bool afterPunct = aForward ? aState->mLastCharWasPunctuation : aPunctAfter;
9664 if (!afterPunct) {
9665 // keyboard caret movement only stops after punctuation (in content order)
9666 return false;
9667 }
9668 // Stop only if we've seen some non-punctuation since the last whitespace;
9669 // don't stop after punctuation that follows whitespace.
9670 return aState->mSeenNonPunctuationSinceWhitespace;
9671}
9672
9673std::pair<nsIFrame*, nsIFrame*> nsIFrame::GetContainingBlockForLine(
9674 bool aLockScroll) const {
9675 const nsIFrame* parentFrame = this;
9676 const nsIFrame* frame;
9677 while (parentFrame) {
9678 frame = parentFrame;
9679 if (frame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
9680 // if we are searching for a frame that is not in flow we will not find
9681 // it. we must instead look for its placeholder
9682 if (frame->HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER)) {
9683 // abspos continuations don't have placeholders, get the fif
9684 frame = frame->FirstInFlow();
9685 }
9686 frame = frame->GetPlaceholderFrame();
9687 if (!frame) {
9688 return std::pair(nullptr, nullptr);
9689 }
9690 }
9691 parentFrame = frame->GetParent();
9692 if (parentFrame) {
9693 if (aLockScroll && parentFrame->IsScrollContainerFrame()) {
9694 return std::pair(nullptr, nullptr);
9695 }
9696 if (parentFrame->CanProvideLineIterator()) {
9697 return std::pair(const_cast<nsIFrame*>(parentFrame),
9698 const_cast<nsIFrame*>(frame));
9699 }
9700 }
9701 }
9702 return std::pair(nullptr, nullptr);
9703}
9704
9705Result<bool, nsresult> nsIFrame::IsVisuallyAtLineEdge(
9706 nsILineIterator* aLineIterator, int32_t aLine, nsDirection aDirection) {
9707 auto line = aLineIterator->GetLine(aLine).unwrap();
9708
9709 const bool lineIsRTL = aLineIterator->IsLineIteratorFlowRTL();
9710
9711 nsIFrame *firstFrame = nullptr, *lastFrame = nullptr;
9712 bool isReordered = false;
9713 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)
9714 &lastFrame))do { auto mozTryTempResult_ = ::mozilla::ToResult(aLineIterator
->CheckLineOrder(aLine, &isReordered, &firstFrame,
&lastFrame)); if ((__builtin_expect(!!(mozTryTempResult_
.isErr()), 0))) { return mozTryTempResult_.propagateErr(); } }
while (0)
;
9715 if (!firstFrame || !lastFrame) {
9716 return true; // XXX: Why true? We check whether `this` is at the edge...
9717 }
9718
9719 nsIFrame* leftmostFrame = lineIsRTL ? lastFrame : firstFrame;
9720 nsIFrame* rightmostFrame = lineIsRTL ? firstFrame : lastFrame;
9721 auto FrameIsRTL = [](nsIFrame* aFrame) {
9722 return nsBidiPresUtils::FrameDirection(aFrame) ==
9723 mozilla::intl::BidiDirection::RTL;
9724 };
9725 if (!lineIsRTL == (aDirection == eDirPrevious)) {
9726 nsIFrame* maybeLeftmostFrame = leftmostFrame;
9727 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9728 if (maybeLeftmostFrame == this) {
9729 return true;
9730 }
9731 // If left edge of the line starts with placeholder frames, we can ignore
9732 // them and should keep checking the following frames.
9733 if (!maybeLeftmostFrame->IsPlaceholderFrame()) {
9734 if ((FrameIsRTL(maybeLeftmostFrame) == lineIsRTL) ==
9735 (aDirection == eDirPrevious)) {
9736 nsIFrame::GetFirstLeaf(&maybeLeftmostFrame);
9737 } else {
9738 nsIFrame::GetLastLeaf(&maybeLeftmostFrame);
9739 }
9740 return maybeLeftmostFrame == this;
9741 }
9742 maybeLeftmostFrame = nsBidiPresUtils::GetFrameToRightOf(
9743 maybeLeftmostFrame, line.mFirstFrameOnLine, line.mNumFramesOnLine);
9744 if (!maybeLeftmostFrame) {
9745 return false;
9746 }
9747 }
9748 return false;
9749 }
9750
9751 nsIFrame* maybeRightmostFrame = rightmostFrame;
9752 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9753 if (maybeRightmostFrame == this) {
9754 return true;
9755 }
9756 // If the line ends with placehlder frames, we can ignore them and should
9757 // keep checking the preceding frames.
9758 if (!maybeRightmostFrame->IsPlaceholderFrame()) {
9759 if ((FrameIsRTL(maybeRightmostFrame) == lineIsRTL) ==
9760 (aDirection == eDirPrevious)) {
9761 nsIFrame::GetFirstLeaf(&maybeRightmostFrame);
9762 } else {
9763 nsIFrame::GetLastLeaf(&maybeRightmostFrame);
9764 }
9765 return maybeRightmostFrame == this;
9766 }
9767 maybeRightmostFrame = nsBidiPresUtils::GetFrameToLeftOf(
9768 maybeRightmostFrame, line.mFirstFrameOnLine, line.mNumFramesOnLine);
9769 if (!maybeRightmostFrame) {
9770 return false;
9771 }
9772 }
9773 return false;
9774}
9775
9776Result<bool, nsresult> nsIFrame::IsLogicallyAtLineEdge(
9777 nsILineIterator* aLineIterator, int32_t aLine, nsDirection aDirection) {
9778 auto line = aLineIterator->GetLine(aLine).unwrap();
9779 if (!line.mNumFramesOnLine) {
9780 return false;
9781 }
9782 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"
, 9782); AnnotateMozCrashReason("MOZ_ASSERT" "(" "line.mFirstFrameOnLine"
")"); do { *((volatile int*)__null) = 9782; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9783
9784 if (aDirection == eDirPrevious) {
9785 nsIFrame* maybeFirstFrame = line.mFirstFrameOnLine;
9786 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9787 if (maybeFirstFrame == this) {
9788 return true;
9789 }
9790 // If the line starts with placeholder frames, we can ignore them and
9791 // should keep checking the following frames.
9792 if (!maybeFirstFrame->IsPlaceholderFrame()) {
9793 nsIFrame::GetFirstLeaf(&maybeFirstFrame);
9794 return maybeFirstFrame == this;
9795 }
9796 maybeFirstFrame = maybeFirstFrame->GetNextSibling();
9797 if (!maybeFirstFrame) {
9798 return false;
9799 }
9800 }
9801 return false;
9802 }
9803
9804 // eDirNext
9805 nsIFrame* maybeLastFrame = line.GetLastFrameOnLine();
9806 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9807 if (maybeLastFrame == this) {
9808 return true;
9809 }
9810 // If the line ends with placehlder frames, we can ignore them and should
9811 // keep checking the preceding frames.
9812 if (!maybeLastFrame->IsPlaceholderFrame()) {
9813 nsIFrame::GetLastLeaf(&maybeLastFrame);
9814 return maybeLastFrame == this;
9815 }
9816 maybeLastFrame = maybeLastFrame->GetPrevSibling();
9817 }
9818 return false;
9819}
9820
9821nsIFrame::SelectablePeekReport nsIFrame::GetFrameFromDirection(
9822 nsDirection aDirection, const PeekOffsetOptions& aOptions) {
9823 SelectablePeekReport result;
9824
9825 nsPresContext* presContext = PresContext();
9826 const bool needsVisualTraversal =
9827 aOptions.contains(PeekOffsetOption::Visual) && presContext->BidiEnabled();
9828 const bool followOofs =
9829 !aOptions.contains(PeekOffsetOption::StopAtPlaceholder);
9830 nsFrameIterator frameIterator(
9831 presContext, this, nsFrameIterator::Type::Leaf, needsVisualTraversal,
9832 aOptions.contains(PeekOffsetOption::StopAtScroller), followOofs,
9833 false // aSkipPopupChecks
9834 );
9835
9836 // Find the prev/next selectable frame
9837 bool selectable = false;
9838 nsIFrame* traversedFrame = this;
9839 AutoAssertNoDomMutations guard;
9840 const nsIContent* const nativeAnonymousSubtreeContent =
9841 GetClosestNativeAnonymousSubtreeRoot();
9842 while (!selectable) {
9843 auto [blockFrame, lineFrame] = traversedFrame->GetContainingBlockForLine(
9844 aOptions.contains(PeekOffsetOption::StopAtScroller));
9845 if (!blockFrame) {
9846 return result;
9847 }
9848
9849 nsILineIterator* it = blockFrame->GetLineIterator();
9850 int32_t thisLine = it->FindLineContaining(lineFrame);
9851 if (thisLine < 0) {
9852 return result;
9853 }
9854
9855 bool atLineEdge;
9856 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)
9857 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)
9858 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)
9859 ? 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)
9860 : 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)
;
9861 if (atLineEdge) {
9862 result.mJumpedLine = true;
9863 if (!aOptions.contains(PeekOffsetOption::JumpLines)) {
9864 return result; // we are done. cannot jump lines
9865 }
9866 int32_t lineToCheckWrap =
9867 aDirection == eDirPrevious ? thisLine - 1 : thisLine;
9868 if (lineToCheckWrap < 0 ||
9869 !it->GetLine(lineToCheckWrap).unwrap().mIsWrapped) {
9870 result.mJumpedHardBreak = true;
9871 }
9872 }
9873
9874 traversedFrame = frameIterator.Traverse(aDirection == eDirNext);
9875 if (!traversedFrame) {
9876 return result;
9877 }
9878
9879 if (aOptions.contains(PeekOffsetOption::StopAtPlaceholder) &&
9880 traversedFrame->IsPlaceholderFrame()) {
9881 // XXX If the placeholder frame does not have meaningful content, the user
9882 // may want to select as a word around the out-of-flow cotent. However,
9883 // non-text frame resets context in nsIFrame::PeekOffsetWord(). Therefore,
9884 // next text frame considers the new word starts from its edge. So, it's
9885 // not enough to implement such behavior with adding a check here whether
9886 // the real frame may change the word with its contents if it were not
9887 // out-of-flow.
9888 result.mFoundPlaceholder = true;
9889 return result;
9890 }
9891
9892 auto IsSelectable =
9893 [aOptions, nativeAnonymousSubtreeContent](const nsIFrame* aFrame) {
9894 if (!aFrame->IsSelectable(nullptr)) {
9895 return false;
9896 }
9897 // If the new frame is in a native anonymous subtree, we should treat
9898 // it as not selectable unless the frame and found frame are in same
9899 // subtree.
9900 if (aFrame->GetClosestNativeAnonymousSubtreeRoot() !=
9901 nativeAnonymousSubtreeContent) {
9902 return false;
9903 }
9904 return !aOptions.contains(PeekOffsetOption::ForceEditableRegion) ||
9905 aFrame->GetContent()->IsEditable();
9906 };
9907
9908 // Skip br frames, but only if we can select something before hitting the
9909 // end of the line or a non-selectable region.
9910 if (atLineEdge && aDirection == eDirPrevious &&
9911 traversedFrame->IsBrFrame()) {
9912 for (nsIFrame* current = traversedFrame->GetPrevSibling(); current;
9913 current = current->GetPrevSibling()) {
9914 if (!current->IsBlockOutside() && IsSelectable(current)) {
9915 if (!current->IsBrFrame()) {
9916 result.mIgnoredBrFrame = true;
9917 }
9918 break;
9919 }
9920 }
9921 if (result.mIgnoredBrFrame) {
9922 continue;
9923 }
9924 }
9925
9926 selectable = IsSelectable(traversedFrame);
9927 if (!selectable) {
9928 if (traversedFrame->IsSelectable(nullptr)) {
9929 result.mHasSelectableFrame = true;
9930 }
9931 result.mMovedOverNonSelectableText = true;
9932 }
9933 } // while (!selectable)
9934
9935 result.mOffset = (aDirection == eDirNext) ? 0 : -1;
9936
9937 if (aOptions.contains(PeekOffsetOption::Visual) &&
9938 nsBidiPresUtils::IsReversedDirectionFrame(traversedFrame)) {
9939 // The new frame is reverse-direction, go to the other end
9940 result.mOffset = -1 - result.mOffset;
9941 }
9942 result.mFrame = traversedFrame;
9943 return result;
9944}
9945
9946nsIFrame::SelectablePeekReport nsIFrame::GetFrameFromDirection(
9947 const PeekOffsetStruct& aPos) {
9948 return GetFrameFromDirection(aPos.mDirection, aPos.mOptions);
9949}
9950
9951nsView* nsIFrame::GetClosestView(nsPoint* aOffset) const {
9952 nsPoint offset(0, 0);
9953 for (const nsIFrame* f = this; f; f = f->GetParent()) {
9954 if (f->HasView()) {
9955 if (aOffset) *aOffset = offset;
9956 return f->GetView();
9957 }
9958 offset += f->GetPosition();
9959 }
9960
9961 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"
, 9961); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "No view on any parent? How did that happen?"
")"); do { *((volatile int*)__null) = 9961; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9962 return nullptr;
9963}
9964
9965/* virtual */
9966void nsIFrame::ChildIsDirty(nsIFrame* aChild) {
9967 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"
, 9969); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should never be called on a frame that doesn't "
"inherit from nsContainerFrame" ")"); do { *((volatile int*)
__null) = 9969; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
9968 "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"
, 9969); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should never be called on a frame that doesn't "
"inherit from nsContainerFrame" ")"); do { *((volatile int*)
__null) = 9969; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
9969 "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"
, 9969); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should never be called on a frame that doesn't "
"inherit from nsContainerFrame" ")"); do { *((volatile int*)
__null) = 9969; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
9970}
9971
9972#ifdef ACCESSIBILITY1
9973a11y::AccType nsIFrame::AccessibleType() {
9974 if (IsTableCaption() && !GetRect().IsEmpty()) {
9975 return a11y::eHTMLCaptionType;
9976 }
9977 return a11y::eNoType;
9978}
9979#endif
9980
9981bool nsIFrame::ClearOverflowRects() {
9982 if (mOverflow.mType == OverflowStorageType::None) {
9983 return false;
9984 }
9985 if (mOverflow.mType == OverflowStorageType::Large) {
9986 RemoveProperty(OverflowAreasProperty());
9987 }
9988 mOverflow.mType = OverflowStorageType::None;
9989 return true;
9990}
9991
9992bool nsIFrame::SetOverflowAreas(const OverflowAreas& aOverflowAreas) {
9993 if (mOverflow.mType == OverflowStorageType::Large) {
9994 OverflowAreas* overflow = GetOverflowAreasProperty();
9995 bool changed = *overflow != aOverflowAreas;
9996 *overflow = aOverflowAreas;
9997
9998 // Don't bother with converting to the deltas form if we already
9999 // have a property.
10000 return changed;
10001 }
10002
10003 const nsRect& vis = aOverflowAreas.InkOverflow();
10004 uint32_t l = -vis.x, // left edge: positive delta is leftwards
10005 t = -vis.y, // top: positive is upwards
10006 r = vis.XMost() - mRect.width, // right: positive is rightwards
10007 b = vis.YMost() - mRect.height; // bottom: positive is downwards
10008 if (aOverflowAreas.ScrollableOverflow().IsEqualEdges(
10009 nsRect(nsPoint(0, 0), GetSize())) &&
10010 l <= InkOverflowDeltas::kMax && t <= InkOverflowDeltas::kMax &&
10011 r <= InkOverflowDeltas::kMax && b <= InkOverflowDeltas::kMax &&
10012 // we have to check these against zero because we *never* want to
10013 // set a frame as having no overflow in this function. This is
10014 // because FinishAndStoreOverflow calls this function prior to
10015 // SetRect based on whether the overflow areas match aNewSize.
10016 // In the case where the overflow areas exactly match mRect but
10017 // do not match aNewSize, we need to store overflow in a property
10018 // so that our eventual SetRect/SetSize will know that it has to
10019 // reset our overflow areas.
10020 (l | t | r | b) != 0) {
10021 InkOverflowDeltas oldDeltas = mOverflow.mInkOverflowDeltas;
10022 // It's a "small" overflow area so we store the deltas for each edge
10023 // directly in the frame, rather than allocating a separate rect.
10024 // If they're all zero, that's fine; we're setting things to
10025 // no-overflow.
10026 mOverflow.mInkOverflowDeltas.mLeft = l;
10027 mOverflow.mInkOverflowDeltas.mTop = t;
10028 mOverflow.mInkOverflowDeltas.mRight = r;
10029 mOverflow.mInkOverflowDeltas.mBottom = b;
10030 // There was no scrollable overflow before, and there isn't now.
10031 return oldDeltas != mOverflow.mInkOverflowDeltas;
10032 } else {
10033 bool changed =
10034 !aOverflowAreas.ScrollableOverflow().IsEqualEdges(
10035 nsRect(nsPoint(0, 0), GetSize())) ||
10036 !aOverflowAreas.InkOverflow().IsEqualEdges(InkOverflowFromDeltas());
10037
10038 // it's a large overflow area that we need to store as a property
10039 mOverflow.mType = OverflowStorageType::Large;
10040 AddProperty(OverflowAreasProperty(), new OverflowAreas(aOverflowAreas));
10041 return changed;
10042 }
10043}
10044
10045enum class ApplyTransform : bool { No, Yes };
10046
10047/**
10048 * Compute the outline inner rect (so without outline-width and outline-offset)
10049 * of aFrame, maybe iterating over its descendants, in aFrame's coordinate space
10050 * or its post-transform coordinate space (depending on aApplyTransform).
10051 */
10052static nsRect ComputeOutlineInnerRect(
10053 nsIFrame* aFrame, ApplyTransform aApplyTransform, bool& aOutValid,
10054 const nsSize* aSizeOverride = nullptr,
10055 const OverflowAreas* aOverflowOverride = nullptr) {
10056 const nsRect bounds(nsPoint(0, 0),
10057 aSizeOverride ? *aSizeOverride : aFrame->GetSize());
10058
10059 // The SVG container frames besides SVGTextFrame do not maintain
10060 // an accurate mRect. It will make the outline be larger than
10061 // we expect, we need to make them narrow to their children's outline.
10062 // aOutValid is set to false if the returned nsRect is not valid
10063 // and should not be included in the outline rectangle.
10064 aOutValid = !aFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT) ||
10065 !aFrame->IsSVGContainerFrame() || aFrame->IsSVGTextFrame();
10066
10067 nsRect u;
10068
10069 if (!aFrame->FrameMaintainsOverflow()) {
10070 return u;
10071 }
10072
10073 // Start from our border-box, transformed. See comment below about
10074 // transform of children.
10075 bool doTransform =
10076 aApplyTransform == ApplyTransform::Yes && aFrame->IsTransformed();
10077 TransformReferenceBox boundsRefBox(nullptr, bounds);
10078 if (doTransform) {
10079 u = nsDisplayTransform::TransformRect(bounds, aFrame, boundsRefBox);
10080 } else {
10081 u = bounds;
10082 }
10083
10084 if (aOutValid && !StaticPrefs::layout_outline_include_overflow()) {
10085 return u;
10086 }
10087
10088 // Only iterate through the children if the overflow areas suggest
10089 // that we might need to, and if the frame doesn't clip its overflow
10090 // anyway.
10091 if (aOverflowOverride) {
10092 if (!doTransform && bounds.IsEqualEdges(aOverflowOverride->InkOverflow()) &&
10093 bounds.IsEqualEdges(aOverflowOverride->ScrollableOverflow())) {
10094 return u;
10095 }
10096 } else {
10097 if (!doTransform && bounds.IsEqualEdges(aFrame->InkOverflowRect()) &&
10098 bounds.IsEqualEdges(aFrame->ScrollableOverflowRect())) {
10099 return u;
10100 }
10101 }
10102 const nsStyleDisplay* disp = aFrame->StyleDisplay();
10103 LayoutFrameType fType = aFrame->Type();
10104 if (fType == LayoutFrameType::ScrollContainer ||
10105 fType == LayoutFrameType::ListControl ||
10106 fType == LayoutFrameType::SVGOuterSVG) {
10107 return u;
10108 }
10109
10110 auto overflowClipAxes = aFrame->ShouldApplyOverflowClipping(disp);
10111 auto overflowClipMargin = aFrame->OverflowClipMargin(overflowClipAxes);
10112 if (overflowClipAxes == kPhysicalAxesBoth && overflowClipMargin == nsSize()) {
10113 return u;
10114 }
10115
10116 const nsStyleEffects* effects = aFrame->StyleEffects();
10117 Maybe<nsRect> clipPropClipRect =
10118 aFrame->GetClipPropClipRect(disp, effects, bounds.Size());
10119
10120 // Iterate over all children except pop-up, absolutely-positioned,
10121 // float, and overflow ones.
10122 const FrameChildListIDs skip = {
10123 FrameChildListID::Absolute, FrameChildListID::Fixed,
10124 FrameChildListID::Float, FrameChildListID::Overflow};
10125 for (const auto& [list, listID] : aFrame->ChildLists()) {
10126 if (skip.contains(listID)) {
10127 continue;
10128 }
10129
10130 for (nsIFrame* child : list) {
10131 if (child->IsPlaceholderFrame()) {
10132 continue;
10133 }
10134
10135 // Note that passing ApplyTransform::Yes when
10136 // child->Combines3DTransformWithAncestors() returns true is incorrect if
10137 // our aApplyTransform is No... but the opposite would be as well.
10138 // This is because elements within a preserve-3d scene are always
10139 // transformed up to the top of the scene. This means we don't have a
10140 // mechanism for getting a transform up to an intermediate point within
10141 // the scene. We choose to over-transform rather than under-transform
10142 // because this is consistent with other overflow areas.
10143 bool validRect = true;
10144 nsRect childRect =
10145 ComputeOutlineInnerRect(child, ApplyTransform::Yes, validRect) +
10146 child->GetPosition();
10147
10148 if (!validRect) {
10149 continue;
10150 }
10151
10152 if (clipPropClipRect) {
10153 // Intersect with the clip before transforming.
10154 childRect.IntersectRect(childRect, *clipPropClipRect);
10155 }
10156
10157 // Note that we transform each child separately according to
10158 // aFrame's transform, and then union, which gives a different
10159 // (smaller) result from unioning and then transforming the
10160 // union. This doesn't match the way we handle overflow areas
10161 // with 2-D transforms, though it does match the way we handle
10162 // overflow areas in preserve-3d 3-D scenes.
10163 if (doTransform && !child->Combines3DTransformWithAncestors()) {
10164 childRect =
10165 nsDisplayTransform::TransformRect(childRect, aFrame, boundsRefBox);
10166 }
10167
10168 // If a SVGContainer has a non-SVGContainer child, we assign
10169 // its child's outline to this SVGContainer directly.
10170 if (!aOutValid && validRect) {
10171 u = childRect;
10172 aOutValid = true;
10173 } else {
10174 u = u.UnionEdges(childRect);
10175 }
10176 }
10177 }
10178
10179 if (!overflowClipAxes.isEmpty()) {
10180 OverflowAreas::ApplyOverflowClippingOnRect(u, bounds, overflowClipAxes,
10181 overflowClipMargin);
10182 }
10183 return u;
10184}
10185
10186static void ComputeAndIncludeOutlineArea(nsIFrame* aFrame,
10187 OverflowAreas& aOverflowAreas,
10188 const nsSize& aNewSize) {
10189 const nsStyleOutline* outline = aFrame->StyleOutline();
10190 if (!outline->ShouldPaintOutline()) {
10191 return;
10192 }
10193
10194 // When the outline property is set on a :-moz-block-inside-inline-wrapper
10195 // pseudo-element, it inherited that outline from the inline that was broken
10196 // because it contained a block. In that case, we don't want a really wide
10197 // outline if the block inside the inline is narrow, so union the actual
10198 // contents of the anonymous blocks.
10199 nsIFrame* frameForArea = aFrame;
10200 do {
10201 PseudoStyleType pseudoType = frameForArea->Style()->GetPseudoType();
10202 if (pseudoType != PseudoStyleType::mozBlockInsideInlineWrapper) break;
10203 // If we're done, we really want it and all its later siblings.
10204 frameForArea = frameForArea->PrincipalChildList().FirstChild();
10205 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"
, 10205); MOZ_PretendNoReturn(); } } while (0)
;
10206 } while (frameForArea);
10207
10208 // Find the union of the border boxes of all descendants, or in
10209 // the block-in-inline case, all descendants we care about.
10210 //
10211 // Note that the interesting perspective-related cases are taken
10212 // care of by the code that handles those issues for overflow
10213 // calling FinishAndStoreOverflow again, which in turn calls this
10214 // function again. We still need to deal with preserve-3d a bit.
10215 nsRect innerRect;
10216 bool validRect = false;
10217 if (frameForArea == aFrame) {
10218 innerRect = ComputeOutlineInnerRect(aFrame, ApplyTransform::No, validRect,
10219 &aNewSize, &aOverflowAreas);
10220 } else {
10221 for (; frameForArea; frameForArea = frameForArea->GetNextSibling()) {
10222 nsRect r =
10223 ComputeOutlineInnerRect(frameForArea, ApplyTransform::Yes, validRect);
10224
10225 // Adjust for offsets transforms up to aFrame's pre-transform
10226 // (i.e., normal) coordinate space; see comments in
10227 // UnionBorderBoxes for some of the subtlety here.
10228 for (nsIFrame *f = frameForArea, *parent = f->GetParent();
10229 /* see middle of loop */; f = parent, parent = f->GetParent()) {
10230 r += f->GetPosition();
10231 if (parent == aFrame) {
10232 break;
10233 }
10234 if (parent->IsTransformed() && !f->Combines3DTransformWithAncestors()) {
10235 TransformReferenceBox refBox(parent);
10236 r = nsDisplayTransform::TransformRect(r, parent, refBox);
10237 }
10238 }
10239
10240 innerRect.UnionRect(innerRect, r);
10241 }
10242 }
10243
10244 // Keep this code in sync with nsDisplayOutline::GetInnerRect.
10245 if (innerRect == aFrame->GetRectRelativeToSelf()) {
10246 aFrame->RemoveProperty(nsIFrame::OutlineInnerRectProperty());
10247 } else {
10248 SetOrUpdateRectValuedProperty(aFrame, nsIFrame::OutlineInnerRectProperty(),
10249 innerRect);
10250 }
10251
10252 nsRect outerRect(innerRect);
10253 outerRect.Inflate(outline->EffectiveOffsetFor(outerRect));
10254
10255 if (outline->mOutlineStyle.IsAuto()) {
10256 nsPresContext* pc = aFrame->PresContext();
10257
10258 pc->Theme()->GetWidgetOverflow(pc->DeviceContext(), aFrame,
10259 StyleAppearance::FocusOutline, &outerRect);
10260 } else {
10261 const nscoord width = outline->GetOutlineWidth();
10262 outerRect.Inflate(width);
10263 }
10264
10265 nsRect& vo = aOverflowAreas.InkOverflow();
10266 vo = vo.UnionEdges(innerRect.Union(outerRect));
10267}
10268
10269bool nsIFrame::FinishAndStoreOverflow(OverflowAreas& aOverflowAreas,
10270 nsSize aNewSize, nsSize* aOldSize,
10271 const nsStyleDisplay* aStyleDisplay) {
10272 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"
, 10273); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Don't call - overflow rects not maintained on these SVG frames"
")"); do { *((volatile int*)__null) = 10273; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
10273 "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"
, 10273); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Don't call - overflow rects not maintained on these SVG frames"
")"); do { *((volatile int*)__null) = 10273; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10274
10275 const nsStyleDisplay* disp = StyleDisplayWithOptionalParam(aStyleDisplay);
10276 bool hasTransform = IsTransformed();
10277
10278 nsRect bounds(nsPoint(0, 0), aNewSize);
10279 // Store the passed in overflow area if we are a preserve-3d frame or we have
10280 // a transform, and it's not just the frame bounds.
10281 if (hasTransform || Combines3DTransformWithAncestors()) {
10282 if (!aOverflowAreas.InkOverflow().IsEqualEdges(bounds) ||
10283 !aOverflowAreas.ScrollableOverflow().IsEqualEdges(bounds)) {
10284 OverflowAreas* initial = GetProperty(nsIFrame::InitialOverflowProperty());
10285 if (!initial) {
10286 AddProperty(nsIFrame::InitialOverflowProperty(),
10287 new OverflowAreas(aOverflowAreas));
10288 } else if (initial != &aOverflowAreas) {
10289 *initial = aOverflowAreas;
10290 }
10291 } else {
10292 RemoveProperty(nsIFrame::InitialOverflowProperty());
10293 }
10294#ifdef DEBUG1
10295 SetProperty(nsIFrame::DebugInitialOverflowPropertyApplied(), true);
10296#endif
10297 } else {
10298#ifdef DEBUG1
10299 RemoveProperty(nsIFrame::DebugInitialOverflowPropertyApplied());
10300#endif
10301 }
10302
10303 nsSize oldSize = mRect.Size();
10304 bool sizeChanged = ((aOldSize ? *aOldSize : oldSize) != aNewSize);
10305
10306 // Our frame size may not have been computed and set yet, but code under
10307 // functions such as ComputeEffectsRect (which we're about to call) use the
10308 // values that are stored in our frame rect to compute their results. We
10309 // need the results from those functions to be based on the frame size that
10310 // we *will* have, so we temporarily set our frame size here before calling
10311 // those functions.
10312 //
10313 // XXX Someone should document here why we revert the frame size before we
10314 // return rather than just leaving it set.
10315 //
10316 // We pass false here to avoid invalidating display items for this temporary
10317 // change. We sometimes reflow frames multiple times, with the final size
10318 // being the same as the initial. The single call to SetSize after reflow is
10319 // done will take care of invalidating display items if the size has actually
10320 // changed.
10321 SetSize(aNewSize, false);
10322
10323 const auto overflowClipAxes = ShouldApplyOverflowClipping(disp);
10324
10325 if (ChildrenHavePerspective(disp) && sizeChanged) {
10326 RecomputePerspectiveChildrenOverflow(this);
10327
10328 if (overflowClipAxes != kPhysicalAxesBoth) {
10329 aOverflowAreas.SetAllTo(bounds);
10330 DebugOnly<bool> ok = ComputeCustomOverflow(aOverflowAreas);
10331
10332 // ComputeCustomOverflow() should not return false, when
10333 // FrameMaintainsOverflow() returns true.
10334 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"
, 10334); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ok" ") (" "FrameMaintainsOverflow() != ComputeCustomOverflow()"
")"); do { *((volatile int*)__null) = 10334; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10335
10336 UnionChildOverflow(aOverflowAreas);
10337 }
10338 }
10339
10340 // This is now called FinishAndStoreOverflow() instead of
10341 // StoreOverflow() because frame-generic ways of adding overflow
10342 // can happen here, e.g. CSS2 outline and native theme.
10343 // If the overflow area width or height is nscoord_MAX, then a saturating
10344 // union may have encountered an overflow, so the overflow may not contain the
10345 // frame border-box. Don't warn in that case.
10346 // Don't warn for SVG either, since SVG doesn't need the overflow area
10347 // to contain the frame bounds.
10348#ifdef DEBUG1
10349 for (const auto otype : AllOverflowTypes()) {
10350 const nsRect& r = aOverflowAreas.Overflow(otype);
10351 NS_ASSERTION(aNewSize.width == 0 || aNewSize.height == 0 ||do { if (!(aNewSize.width == 0 || aNewSize.height == 0 || r.width
== nscoord_MAX || r.height == nscoord_MAX || HasAnyStateBits
(NS_FRAME_SVG_LAYOUT) || r.Contains(nsRect(nsPoint(), 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(), aNewSize))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10355); MOZ_PretendNoReturn(); } } while (0)
10352 r.width == nscoord_MAX || r.height == nscoord_MAX ||do { if (!(aNewSize.width == 0 || aNewSize.height == 0 || r.width
== nscoord_MAX || r.height == nscoord_MAX || HasAnyStateBits
(NS_FRAME_SVG_LAYOUT) || r.Contains(nsRect(nsPoint(), 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(), aNewSize))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10355); MOZ_PretendNoReturn(); } } while (0)
10353 HasAnyStateBits(NS_FRAME_SVG_LAYOUT) ||do { if (!(aNewSize.width == 0 || aNewSize.height == 0 || r.width
== nscoord_MAX || r.height == nscoord_MAX || HasAnyStateBits
(NS_FRAME_SVG_LAYOUT) || r.Contains(nsRect(nsPoint(), 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(), aNewSize))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10355); MOZ_PretendNoReturn(); } } while (0)
10354 r.Contains(nsRect(nsPoint(), aNewSize)),do { if (!(aNewSize.width == 0 || aNewSize.height == 0 || r.width
== nscoord_MAX || r.height == nscoord_MAX || HasAnyStateBits
(NS_FRAME_SVG_LAYOUT) || r.Contains(nsRect(nsPoint(), 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(), aNewSize))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10355); MOZ_PretendNoReturn(); } } while (0)
10355 "Computed overflow area must contain frame bounds")do { if (!(aNewSize.width == 0 || aNewSize.height == 0 || r.width
== nscoord_MAX || r.height == nscoord_MAX || HasAnyStateBits
(NS_FRAME_SVG_LAYOUT) || r.Contains(nsRect(nsPoint(), 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(), aNewSize))"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 10355); MOZ_PretendNoReturn(); } } while (0)
;
10356 }
10357#endif
10358
10359 // Overflow area must always include the frame's top-left and bottom-right,
10360 // even if the frame rect is empty (so we can scroll to those positions).
10361 const bool shouldIncludeBounds = [&] {
10362 if (aNewSize.width == 0 && IsInlineFrame()) {
10363 // Pending a real fix for bug 426879, don't do this for inline frames with
10364 // zero width.
10365 return false;
10366 }
10367 if (HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
10368 // Do not do this for SVG either, since it will usually massively increase
10369 // the area unnecessarily (except for SVG that applies clipping, since
10370 // that's the pre-existing behavior, and breaks pre-rendering otherwise).
10371 // FIXME(bug 1770704): This check most likely wants to be removed or check
10372 // for specific frame types at least.
10373 return !overflowClipAxes.isEmpty();
10374 }
10375 return true;
10376 }();
10377
10378 if (shouldIncludeBounds) {
10379 for (const auto otype : AllOverflowTypes()) {
10380 nsRect& o = aOverflowAreas.Overflow(otype);
10381 o = o.UnionEdges(bounds);
10382 }
10383 }
10384
10385 // If we clip our children, clear accumulated overflow area in the affected
10386 // dimension(s). The children are actually clipped to the padding-box, but
10387 // since the overflow area should include the entire border-box, just set it
10388 // to the border-box size here.
10389 if (!overflowClipAxes.isEmpty()) {
10390 aOverflowAreas.ApplyClipping(bounds, overflowClipAxes,
10391 OverflowClipMargin(overflowClipAxes));
10392 }
10393
10394 ComputeAndIncludeOutlineArea(this, aOverflowAreas, aNewSize);
10395
10396 // Nothing in here should affect scrollable overflow.
10397 aOverflowAreas.InkOverflow() =
10398 ComputeEffectsRect(this, aOverflowAreas.InkOverflow(), aNewSize);
10399
10400 // Absolute position clipping
10401 const nsStyleEffects* effects = StyleEffects();
10402 Maybe<nsRect> clipPropClipRect = GetClipPropClipRect(disp, effects, aNewSize);
10403 if (clipPropClipRect) {
10404 for (const auto otype : AllOverflowTypes()) {
10405 nsRect& o = aOverflowAreas.Overflow(otype);
10406 o.IntersectRect(o, *clipPropClipRect);
10407 }
10408 }
10409
10410 /* If we're transformed, transform the overflow rect by the current
10411 * transformation. */
10412 if (hasTransform) {
10413 SetProperty(nsIFrame::PreTransformOverflowAreasProperty(),
10414 new OverflowAreas(aOverflowAreas));
10415
10416 if (Combines3DTransformWithAncestors()) {
10417 /* If we're a preserve-3d leaf frame, then our pre-transform overflow
10418 * should be correct. Our post-transform overflow is empty though, because
10419 * we only contribute to the overflow area of the preserve-3d root frame.
10420 * If we're an intermediate frame then the pre-transform overflow should
10421 * contain all our non-preserve-3d children, which is what we want. Again
10422 * we have no post-transform overflow.
10423 */
10424 aOverflowAreas.SetAllTo(nsRect());
10425 } else {
10426 TransformReferenceBox refBox(this);
10427 for (const auto otype : AllOverflowTypes()) {
10428 nsRect& o = aOverflowAreas.Overflow(otype);
10429 o = nsDisplayTransform::TransformRect(o, this, refBox);
10430 }
10431
10432 /* If we're the root of the 3d context, then we want to include the
10433 * overflow areas of all the participants. This won't have happened yet as
10434 * the code above set their overflow area to empty. Manually collect these
10435 * overflow areas now.
10436 */
10437 if (Extend3DContext(disp, effects)) {
10438 ComputePreserve3DChildrenOverflow(aOverflowAreas);
10439 }
10440 }
10441 } else {
10442 RemoveProperty(nsIFrame::PreTransformOverflowAreasProperty());
10443 }
10444
10445 /* Revert the size change in case some caller is depending on this. */
10446 SetSize(oldSize, false);
10447
10448 bool anyOverflowChanged;
10449 if (aOverflowAreas != OverflowAreas(bounds, bounds)) {
10450 anyOverflowChanged = SetOverflowAreas(aOverflowAreas);
10451 } else {
10452 anyOverflowChanged = ClearOverflowRects();
10453 }
10454
10455 if (anyOverflowChanged) {
10456 SVGObserverUtils::InvalidateDirectRenderingObservers(this);
10457 if (nsBlockFrame* block = do_QueryFrame(this)) {
10458 // NOTE(emilio): we need to use BeforeReflow::Yes, because we want to
10459 // invalidate in cases where we _used_ to have an overflow marker and no
10460 // longer do.
10461 if (TextOverflow::CanHaveOverflowMarkers(
10462 block, TextOverflow::BeforeReflow::Yes)) {
10463 DiscardDisplayItems(this, [](nsDisplayItem* aItem) {
10464 return aItem->GetType() == DisplayItemType::TYPE_TEXT_OVERFLOW;
10465 });
10466 SchedulePaint(PAINT_DEFAULT);
10467 }
10468 }
10469 }
10470 return anyOverflowChanged;
10471}
10472
10473void nsIFrame::RecomputePerspectiveChildrenOverflow(
10474 const nsIFrame* aStartFrame) {
10475 for (const auto& childList : ChildLists()) {
10476 for (nsIFrame* child : childList.mList) {
10477 if (!child->FrameMaintainsOverflow()) {
10478 continue; // frame does not maintain overflow rects
10479 }
10480 if (child->HasPerspective()) {
10481 OverflowAreas* overflow =
10482 child->GetProperty(nsIFrame::InitialOverflowProperty());
10483 nsRect bounds(nsPoint(0, 0), child->GetSize());
10484 if (overflow) {
10485 OverflowAreas overflowCopy = *overflow;
10486 child->FinishAndStoreOverflow(overflowCopy, bounds.Size());
10487 } else {
10488 OverflowAreas boundsOverflow;
10489 boundsOverflow.SetAllTo(bounds);
10490 child->FinishAndStoreOverflow(boundsOverflow, bounds.Size());
10491 }
10492 } else if (child->GetContent() == aStartFrame->GetContent() ||
10493 child->GetClosestFlattenedTreeAncestorPrimaryFrame() ==
10494 aStartFrame) {
10495 // If a frame is using perspective, then the size used to compute
10496 // perspective-origin is the size of the frame belonging to its parent
10497 // style. We must find any descendant frames using our size
10498 // (by recursing into frames that have the same containing block)
10499 // to update their overflow rects too.
10500 child->RecomputePerspectiveChildrenOverflow(aStartFrame);
10501 }
10502 }
10503 }
10504}
10505
10506void nsIFrame::ComputePreserve3DChildrenOverflow(
10507 OverflowAreas& aOverflowAreas) {
10508 // Find all descendants that participate in the 3d context, and include their
10509 // overflow. These descendants have an empty overflow, so won't have been
10510 // included in the normal overflow calculation. Any children that don't
10511 // participate have normal overflow, so will have been included already.
10512
10513 nsRect childVisual;
10514 nsRect childScrollable;
10515 for (const auto& childList : ChildLists()) {
10516 for (nsIFrame* child : childList.mList) {
10517 // If this child participates in the 3d context, then take the
10518 // pre-transform region (which contains all descendants that aren't
10519 // participating in the 3d context) and transform it into the 3d context
10520 // root coordinate space.
10521 if (child->Combines3DTransformWithAncestors()) {
10522 OverflowAreas childOverflow = child->GetOverflowAreasRelativeToSelf();
10523 TransformReferenceBox refBox(child);
10524 for (const auto otype : AllOverflowTypes()) {
10525 nsRect& o = childOverflow.Overflow(otype);
10526 o = nsDisplayTransform::TransformRect(o, child, refBox);
10527 }
10528
10529 aOverflowAreas.UnionWith(childOverflow);
10530
10531 // If this child also extends the 3d context, then recurse into it
10532 // looking for more participants.
10533 if (child->Extend3DContext()) {
10534 child->ComputePreserve3DChildrenOverflow(aOverflowAreas);
10535 }
10536 }
10537 }
10538 }
10539}
10540
10541bool nsIFrame::ZIndexApplies() const {
10542 return StyleDisplay()->IsPositionedStyle() || IsFlexOrGridItem() ||
10543 IsMenuPopupFrame();
10544}
10545
10546Maybe<int32_t> nsIFrame::ZIndex() const {
10547 if (!ZIndexApplies()) {
10548 return Nothing();
10549 }
10550 const auto& zIndex = StylePosition()->mZIndex;
10551 if (zIndex.IsAuto()) {
10552 return Nothing();
10553 }
10554 return Some(zIndex.AsInteger());
10555}
10556
10557bool nsIFrame::IsScrollAnchor(ScrollAnchorContainer** aOutContainer) {
10558 if (!mInScrollAnchorChain) {
10559 return false;
10560 }
10561
10562 nsIFrame* f = this;
10563
10564 // FIXME(emilio, bug 1629280): We should find a non-null anchor if we have the
10565 // flag set, but bug 1629280 makes it so that we cannot really assert it /
10566 // make this just a `while (true)`, and uncomment the below assertion.
10567 while (auto* container = ScrollAnchorContainer::FindFor(f)) {
10568 // MOZ_ASSERT(f->IsInScrollAnchorChain());
10569 if (nsIFrame* anchor = container->AnchorNode()) {
10570 if (anchor != this) {
10571 return false;
10572 }
10573 if (aOutContainer) {
10574 *aOutContainer = container;
10575 }
10576 return true;
10577 }
10578
10579 f = container->Frame();
10580 }
10581
10582 return false;
10583}
10584
10585bool nsIFrame::IsInScrollAnchorChain() const { return mInScrollAnchorChain; }
10586
10587void nsIFrame::SetInScrollAnchorChain(bool aInChain) {
10588 mInScrollAnchorChain = aInChain;
10589}
10590
10591uint32_t nsIFrame::GetDepthInFrameTree() const {
10592 uint32_t result = 0;
10593 for (nsContainerFrame* ancestor = GetParent(); ancestor;
10594 ancestor = ancestor->GetParent()) {
10595 result++;
10596 }
10597 return result;
10598}
10599
10600/**
10601 * This function takes a frame that is part of a block-in-inline split,
10602 * and _if_ that frame is an anonymous block created by an ib split it
10603 * returns the block's preceding inline. This is needed because the
10604 * split inline's style is the parent of the anonymous block's style.
10605 *
10606 * If aFrame is not an anonymous block, null is returned.
10607 */
10608static nsIFrame* GetIBSplitSiblingForAnonymousBlock(const nsIFrame* aFrame) {
10609 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"
, 10609); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame" ") ("
"Must have a non-null frame!" ")"); do { *((volatile int*)__null
) = 10609; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
10610 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"
, 10611); MOZ_PretendNoReturn(); } } while (0)
10611 "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"
, 10611); MOZ_PretendNoReturn(); } } while (0)
;
10612
10613 if (aFrame->Style()->GetPseudoType() !=
10614 PseudoStyleType::mozBlockInsideInlineWrapper) {
10615 // it's not an anonymous block
10616 return nullptr;
10617 }
10618
10619 // Find the first continuation of the frame. (Ugh. This ends up
10620 // being O(N^2) when it is called O(N) times.)
10621 aFrame = aFrame->FirstContinuation();
10622
10623 /*
10624 * Now look up the nsGkAtoms::IBSplitPrevSibling
10625 * property.
10626 */
10627 nsIFrame* ibSplitSibling =
10628 aFrame->GetProperty(nsIFrame::IBSplitPrevSibling());
10629 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"
, 10629); MOZ_PretendNoReturn(); } } while (0)
;
10630 return ibSplitSibling;
10631}
10632
10633/**
10634 * Get the parent, corrected for the mangled frame tree resulting from
10635 * having a block within an inline. The result only differs from the
10636 * result of |GetParent| when |GetParent| returns an anonymous block
10637 * that was created for an element that was 'display: inline' because
10638 * that element contained a block.
10639 *
10640 * Also skip anonymous scrolled-content parents; inherit directly from the
10641 * outer scroll frame.
10642 *
10643 * Also skip NAC parents if the child frame is NAC.
10644 */
10645static nsIFrame* GetCorrectedParent(const nsIFrame* aFrame) {
10646 nsIFrame* parent = aFrame->GetParent();
10647 if (!parent) {
10648 return nullptr;
10649 }
10650
10651 // For a table caption we want the _inner_ table frame (unless it's anonymous)
10652 // as the style parent.
10653 if (aFrame->IsTableCaption()) {
10654 nsIFrame* innerTable = parent->PrincipalChildList().FirstChild();
10655 if (!innerTable->Style()->IsAnonBox()) {
10656 return innerTable;
10657 }
10658 }
10659
10660 // Table wrappers are always anon boxes; if we're in here for an outer
10661 // table, that actually means its the _inner_ table that wants to
10662 // know its parent. So get the pseudo of the inner in that case.
10663 auto pseudo = aFrame->Style()->GetPseudoType();
10664 if (pseudo == PseudoStyleType::tableWrapper) {
10665 pseudo =
10666 aFrame->PrincipalChildList().FirstChild()->Style()->GetPseudoType();
10667 }
10668
10669 // Prevent a NAC pseudo-element from inheriting from its NAC parent, and
10670 // inherit from the NAC generator element instead.
10671 if (pseudo != PseudoStyleType::NotPseudo) {
10672 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"
, 10672); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetContent()"
")"); do { *((volatile int*)__null) = 10672; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10673 Element* element = Element::FromNode(aFrame->GetContent());
10674 // Make sure to avoid doing the fixup for non-element-backed pseudos like
10675 // ::first-line and such.
10676 if (element && !element->IsRootOfNativeAnonymousSubtree() &&
10677 element->GetPseudoElementType() == aFrame->Style()->GetPseudoType()) {
10678 while (parent->GetContent() &&
10679 !parent->GetContent()->IsRootOfNativeAnonymousSubtree()) {
10680 parent = parent->GetInFlowParent();
10681 }
10682 parent = parent->GetInFlowParent();
10683 }
10684 }
10685
10686 return nsIFrame::CorrectStyleParentFrame(parent, pseudo);
10687}
10688
10689/* static */
10690nsIFrame* nsIFrame::CorrectStyleParentFrame(nsIFrame* aProspectiveParent,
10691 PseudoStyleType aChildPseudo) {
10692 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"
, 10692); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aProspectiveParent"
") (" "Must have a prospective parent" ")"); do { *((volatile
int*)__null) = 10692; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
10693
10694 if (aChildPseudo != PseudoStyleType::NotPseudo) {
10695 // Non-inheriting anon boxes have no style parent frame at all.
10696 if (PseudoStyle::IsNonInheritingAnonBox(aChildPseudo)) {
10697 return nullptr;
10698 }
10699
10700 // Other anon boxes are parented to their actual parent already, except
10701 // for non-elements. Those should not be treated as an anon box.
10702 if (PseudoStyle::IsAnonBox(aChildPseudo) &&
10703 !nsCSSAnonBoxes::IsNonElement(aChildPseudo)) {
10704 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"
, 10706); MOZ_PretendNoReturn(); } } while (0)
10705 "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"
, 10706); MOZ_PretendNoReturn(); } } while (0)
10706 "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"
, 10706); MOZ_PretendNoReturn(); } } while (0)
;
10707 return aProspectiveParent;
10708 }
10709 }
10710
10711 // Otherwise, walk up out of all anon boxes. For placeholder frames, walk out
10712 // of all pseudo-elements as well. Otherwise ReparentComputedStyle could
10713 // cause style data to be out of sync with the frame tree.
10714 nsIFrame* parent = aProspectiveParent;
10715 do {
10716 if (parent->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) {
10717 nsIFrame* sibling = GetIBSplitSiblingForAnonymousBlock(parent);
10718
10719 if (sibling) {
10720 // |parent| was a block in an {ib} split; use the inline as
10721 // |the style parent.
10722 parent = sibling;
10723 }
10724 }
10725
10726 if (!parent->Style()->IsPseudoOrAnonBox()) {
10727 return parent;
10728 }
10729
10730 if (!parent->Style()->IsAnonBox() && aChildPseudo != PseudoStyleType::MAX) {
10731 // nsPlaceholderFrame passes in PseudoStyleType::MAX for
10732 // aChildPseudo (even though that's not a valid pseudo-type) just to
10733 // trigger this behavior of walking up to the nearest non-pseudo
10734 // ancestor.
10735 return parent;
10736 }
10737
10738 parent = parent->GetInFlowParent();
10739 } while (parent);
10740
10741 if (aProspectiveParent->Style()->GetPseudoType() ==
10742 PseudoStyleType::viewportScroll) {
10743 // aProspectiveParent is the scrollframe for a viewport
10744 // and the kids are the anonymous scrollbars
10745 return aProspectiveParent;
10746 }
10747
10748 // We can get here if the root element is absolutely positioned.
10749 // We can't test for this very accurately, but it can only happen
10750 // when the prospective parent is a canvas frame.
10751 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"
, 10752); MOZ_PretendNoReturn(); } } while (0)
10752 "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"
, 10752); MOZ_PretendNoReturn(); } } while (0)
;
10753 return nullptr;
10754}
10755
10756ComputedStyle* nsIFrame::DoGetParentComputedStyle(
10757 nsIFrame** aProviderFrame) const {
10758 *aProviderFrame = nullptr;
10759
10760 // Handle display:contents and the root frame, when there's no parent frame
10761 // to inherit from.
10762 if (MOZ_LIKELY(mContent)(__builtin_expect(!!(mContent), 1))) {
10763 Element* parentElement = mContent->GetFlattenedTreeParentElement();
10764 if (MOZ_LIKELY(parentElement)(__builtin_expect(!!(parentElement), 1))) {
10765 auto pseudo = Style()->GetPseudoType();
10766 if (pseudo == PseudoStyleType::NotPseudo || !mContent->IsElement() ||
10767 (!PseudoStyle::IsAnonBox(pseudo) &&
10768 // Ensure that we don't return the display:contents style
10769 // of the parent content for pseudos that have the same content
10770 // as their primary frame (like -moz-list-bullets do):
10771 IsPrimaryFrame()) ||
10772 /* if next is true then it's really a request for the table frame's
10773 parent context, see nsTable[Outer]Frame::GetParentComputedStyle. */
10774 pseudo == PseudoStyleType::tableWrapper) {
10775 // In some edge cases involving display: contents, we may end up here
10776 // for something that's pending to be reframed. In this case we return
10777 // the wrong style from here (because we've already lost track of it!),
10778 // but it's not a big deal as we're going to be reframed anyway.
10779 if (MOZ_LIKELY(parentElement->HasServoData())(__builtin_expect(!!(parentElement->HasServoData()), 1)) &&
10780 Servo_Element_IsDisplayContents(parentElement)) {
10781 RefPtr<ComputedStyle> style =
10782 ServoStyleSet::ResolveServoStyle(*parentElement);
10783 // NOTE(emilio): we return a weak reference because the element also
10784 // holds the style context alive. This is a bit silly (we could've
10785 // returned a weak ref directly), but it's probably not worth
10786 // optimizing, given this function has just one caller which is rare,
10787 // and this path is rare itself.
10788 return style;
10789 }
10790 }
10791 } else {
10792 if (Style()->GetPseudoType() == PseudoStyleType::NotPseudo) {
10793 // We're a frame for the root. We have no style parent.
10794 return nullptr;
10795 }
10796 }
10797 }
10798
10799 if (!HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
10800 /*
10801 * If this frame is an anonymous block created when an inline with a block
10802 * inside it got split, then the parent style is on its preceding inline. We
10803 * can get to it using GetIBSplitSiblingForAnonymousBlock.
10804 */
10805 if (HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) {
10806 nsIFrame* ibSplitSibling = GetIBSplitSiblingForAnonymousBlock(this);
10807 if (ibSplitSibling) {
10808 return (*aProviderFrame = ibSplitSibling)->Style();
10809 }
10810 }
10811
10812 // If this frame is one of the blocks that split an inline, we must
10813 // return the "special" inline parent, i.e., the parent that this
10814 // frame would have if we didn't mangle the frame structure.
10815 *aProviderFrame = GetCorrectedParent(this);
10816 return *aProviderFrame ? (*aProviderFrame)->Style() : nullptr;
10817 }
10818
10819 // We're an out-of-flow frame. For out-of-flow frames, we must
10820 // resolve underneath the placeholder's parent. The placeholder is
10821 // reached from the first-in-flow.
10822 nsPlaceholderFrame* placeholder = FirstInFlow()->GetPlaceholderFrame();
10823 if (!placeholder) {
10824 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"
, 10824); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "no placeholder frame for out-of-flow frame"
")"); do { *((volatile int*)__null) = 10824; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10825 *aProviderFrame = GetCorrectedParent(this);
10826 return *aProviderFrame ? (*aProviderFrame)->Style() : nullptr;
10827 }
10828 return placeholder->GetParentComputedStyleForOutOfFlow(aProviderFrame);
10829}
10830
10831void nsIFrame::GetLastLeaf(nsIFrame** aFrame) {
10832 if (!aFrame || !*aFrame ||
10833 // Don't enter into native anoymous subtree from the root like <input> or
10834 // <textarea>.
10835 (*aFrame)->ContentIsRootOfNativeAnonymousSubtree()) {
10836 return;
10837 }
10838 for (nsIFrame* maybeLastLeaf = (*aFrame)->PrincipalChildList().LastChild();
10839 maybeLastLeaf;) {
10840 nsIFrame* lastChildNotInSubTree = nullptr;
10841 for (nsIFrame* child = maybeLastLeaf; child;
10842 child = child->GetPrevSibling()) {
10843 // ignore anonymous elements, e.g. mozTableAdd* mozTableRemove*
10844 // see bug 278197 comment #12 #13 for details
10845 if (!child->ContentIsRootOfNativeAnonymousSubtree()) {
10846 lastChildNotInSubTree = child;
10847 break;
10848 }
10849 }
10850 if (!lastChildNotInSubTree) {
10851 return;
10852 }
10853 *aFrame = lastChildNotInSubTree;
10854 maybeLastLeaf = lastChildNotInSubTree->PrincipalChildList().LastChild();
10855 }
10856}
10857
10858void nsIFrame::GetFirstLeaf(nsIFrame** aFrame) {
10859 if (!aFrame || !*aFrame) return;
10860 nsIFrame* child = *aFrame;
10861 while (true) {
10862 child = child->PrincipalChildList().FirstChild();
10863 if (!child) return; // nothing to do
10864 *aFrame = child;
10865 }
10866}
10867
10868bool nsIFrame::IsFocusableDueToScrollFrame() {
10869 if (!IsScrollContainerFrame()) {
10870 if (nsFieldSetFrame* fieldset = do_QueryFrame(this)) {
10871 // TODO: Do we have similar special-cases like this where we can have
10872 // anonymous scrollable boxes hanging off a primary frame?
10873 if (nsIFrame* inner = fieldset->GetInner()) {
10874 return inner->IsFocusableDueToScrollFrame();
10875 }
10876 }
10877 return false;
10878 }
10879 if (!mContent->IsHTMLElement()) {
10880 return false;
10881 }
10882 if (mContent->IsRootOfNativeAnonymousSubtree()) {
10883 return false;
10884 }
10885 if (!mContent->GetParent()) {
10886 return false;
10887 }
10888 if (mContent->AsElement()->HasAttr(nsGkAtoms::tabindex)) {
10889 return false;
10890 }
10891 // Elements with scrollable view are focusable with script & tabbable
10892 // Otherwise you couldn't scroll them with keyboard, which is an accessibility
10893 // issue (e.g. Section 508 rules) However, we don't make them to be focusable
10894 // with the mouse, because the extra focus outlines are considered
10895 // unnecessarily ugly. When clicked on, the selection position within the
10896 // element will be enough to make them keyboard scrollable.
10897 auto* scrollContainer = static_cast<ScrollContainerFrame*>(this);
10898 if (scrollContainer->GetScrollStyles().IsHiddenInBothDirections()) {
10899 return false;
10900 }
10901 if (scrollContainer->GetScrollRange().IsEqualEdges(nsRect())) {
10902 return false;
10903 }
10904 return true;
10905}
10906
10907Focusable nsIFrame::IsFocusable(IsFocusableFlags aFlags) {
10908 // cannot focus content in print preview mode. Only the root can be focused,
10909 // but that's handled elsewhere.
10910 if (PresContext()->Type() == nsPresContext::eContext_PrintPreview) {
10911 return {};
10912 }
10913
10914 if (!mContent || !mContent->IsElement()) {
10915 return {};
10916 }
10917
10918 if (!(aFlags & IsFocusableFlags::IgnoreVisibility) &&
10919 !IsVisibleConsideringAncestors()) {
10920 return {};
10921 }
10922
10923 const StyleUserFocus uf = StyleUI()->UserFocus();
10924 if (uf == StyleUserFocus::None) {
10925 return {};
10926 }
10927 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"
, 10927); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!StyleUI()->IsInert()"
") (" "inert implies -moz-user-focus: none" ")"); do { *((volatile
int*)__null) = 10927; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
10928
10929 const PseudoStyleType pseudo = Style()->GetPseudoType();
10930 if (pseudo == PseudoStyleType::anonymousItem) {
10931 return {};
10932 }
10933
10934 Focusable focusable;
10935 if (auto* xul = nsXULElement::FromNode(mContent)) {
10936 // As a legacy special-case, -moz-user-focus controls focusability and
10937 // tabability of XUL elements in some circumstances (which default to
10938 // -moz-user-focus: ignore).
10939 auto focusability = xul->GetXULFocusability(aFlags);
10940 focusable.mFocusable =
10941 focusability.mForcedFocusable.valueOr(uf == StyleUserFocus::Normal);
10942 if (focusable) {
10943 focusable.mTabIndex = focusability.mForcedTabIndexIfFocusable.valueOr(0);
10944 }
10945 } else {
10946 focusable = mContent->IsFocusableWithoutStyle(aFlags);
10947 }
10948
10949 if (focusable) {
10950 return focusable;
10951 }
10952
10953 // If we're focusing with the mouse we never focus scroll areas.
10954 if (!(aFlags & IsFocusableFlags::WithMouse) &&
10955 IsFocusableDueToScrollFrame()) {
10956 return {true, 0};
10957 }
10958
10959 // FIXME(emilio): some callers rely on somewhat broken return values
10960 // (focusable = false, but non-negative tab-index) from
10961 // IsFocusableWithoutStyle (for image maps in particular).
10962 return focusable;
10963}
10964
10965/**
10966 * @return true if this text frame ends with a newline character which is
10967 * treated as preformatted. It should return false if this is not a text frame.
10968 */
10969bool nsIFrame::HasSignificantTerminalNewline() const { return false; }
10970
10971static StyleVerticalAlignKeyword ConvertSVGDominantBaselineToVerticalAlign(
10972 StyleDominantBaseline aDominantBaseline) {
10973 // Most of these are approximate mappings.
10974 switch (aDominantBaseline) {
10975 case StyleDominantBaseline::Hanging:
10976 case StyleDominantBaseline::TextBeforeEdge:
10977 return StyleVerticalAlignKeyword::TextTop;
10978 case StyleDominantBaseline::TextAfterEdge:
10979 case StyleDominantBaseline::Ideographic:
10980 return StyleVerticalAlignKeyword::TextBottom;
10981 case StyleDominantBaseline::Central:
10982 case StyleDominantBaseline::Middle:
10983 case StyleDominantBaseline::Mathematical:
10984 return StyleVerticalAlignKeyword::Middle;
10985 case StyleDominantBaseline::Auto:
10986 case StyleDominantBaseline::Alphabetic:
10987 return StyleVerticalAlignKeyword::Baseline;
10988 default:
10989 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"
, 10989); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "unexpected aDominantBaseline value"
")"); do { *((volatile int*)__null) = 10989; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10990 return StyleVerticalAlignKeyword::Baseline;
10991 }
10992}
10993
10994Maybe<StyleVerticalAlignKeyword> nsIFrame::VerticalAlignEnum() const {
10995 if (IsInSVGTextSubtree()) {
10996 StyleDominantBaseline dominantBaseline = StyleSVG()->mDominantBaseline;
10997 return Some(ConvertSVGDominantBaselineToVerticalAlign(dominantBaseline));
10998 }
10999
11000 const auto& verticalAlign = StyleDisplay()->mVerticalAlign;
11001 if (verticalAlign.IsKeyword()) {
11002 return Some(verticalAlign.AsKeyword());
11003 }
11004
11005 return Nothing();
11006}
11007
11008void nsIFrame::UpdateStyleOfChildAnonBox(nsIFrame* aChildFrame,
11009 ServoRestyleState& aRestyleState) {
11010#ifdef DEBUG1
11011 nsIFrame* parent = aChildFrame->GetInFlowParent();
11012 if (aChildFrame->IsTableFrame()) {
11013 parent = parent->GetParent();
11014 }
11015 if (parent->IsLineFrame()) {
11016 parent = parent->GetParent();
11017 }
11018 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"
, 11019); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent) == this"
") (" "This should only be used for children!" ")"); do { *(
(volatile int*)__null) = 11019; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
11019 "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"
, 11019); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent) == this"
") (" "This should only be used for children!" ")"); do { *(
(volatile int*)__null) = 11019; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
11020#endif // DEBUG
11021 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"
, 11023); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
") (" "What content node is it a frame for?" ")"); do { *((volatile
int*)__null) = 11023; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
11022 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"
, 11023); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
") (" "What content node is it a frame for?" ")"); do { *((volatile
int*)__null) = 11023; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
11023 "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"
, 11023); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
") (" "What content node is it a frame for?" ")"); do { *((volatile
int*)__null) = 11023; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
11024 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"
, 11025); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetPrevContinuation()"
") (" "Only first continuations should end up here" ")"); do
{ *((volatile int*)__null) = 11025; __attribute__((nomerge))
::abort(); } while (false); } } while (false)
11025 "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"
, 11025); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetPrevContinuation()"
") (" "Only first continuations should end up here" ")"); do
{ *((volatile int*)__null) = 11025; __attribute__((nomerge))
::abort(); } while (false); } } while (false)
;
11026
11027 // We could force the caller to pass in the pseudo, since some callers know it
11028 // statically... But this API is a bit nicer.
11029 auto pseudo = aChildFrame->Style()->GetPseudoType();
11030 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"
, 11030); AnnotateMozCrashReason("MOZ_ASSERT" "(" "PseudoStyle::IsAnonBox(pseudo)"
") (" "Child is not an anon box?" ")"); do { *((volatile int
*)__null) = 11030; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
11031 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"
, 11032); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!PseudoStyle::IsNonInheritingAnonBox(pseudo)"
") (" "Why did the caller bother calling us?" ")"); do { *((
volatile int*)__null) = 11032; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
11032 "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"
, 11032); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!PseudoStyle::IsNonInheritingAnonBox(pseudo)"
") (" "Why did the caller bother calling us?" ")"); do { *((
volatile int*)__null) = 11032; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
11033
11034 // Anon boxes inherit from their parent; that's us.
11035 RefPtr<ComputedStyle> newContext =
11036 aRestyleState.StyleSet().ResolveInheritingAnonymousBoxStyle(pseudo,
11037 Style());
11038
11039 nsChangeHint childHint =
11040 UpdateStyleOfOwnedChildFrame(aChildFrame, newContext, aRestyleState);
11041
11042 // Now that we've updated the style on aChildFrame, check whether it itself
11043 // has anon boxes to deal with.
11044 ServoRestyleState childrenState(*aChildFrame, aRestyleState, childHint,
11045 ServoRestyleState::CanUseHandledHints::Yes);
11046 aChildFrame->UpdateStyleOfOwnedAnonBoxes(childrenState);
11047
11048 // Assuming anon boxes don't have ::backdrop associated with them... if that
11049 // ever changes, we'd need to handle that here, like we do in
11050 // RestyleManager::ProcessPostTraversal
11051
11052 // We do need to handle block pseudo-elements here, though. Especially list
11053 // bullets.
11054 if (nsBlockFrame* block = do_QueryFrame(aChildFrame)) {
11055 block->UpdatePseudoElementStyles(childrenState);
11056 }
11057}
11058
11059/* static */
11060nsChangeHint nsIFrame::UpdateStyleOfOwnedChildFrame(
11061 nsIFrame* aChildFrame, ComputedStyle* aNewComputedStyle,
11062 ServoRestyleState& aRestyleState,
11063 const Maybe<ComputedStyle*>& aContinuationComputedStyle) {
11064 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"
, 11065); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetAdditionalComputedStyle(0)"
") (" "We don't handle additional styles here" ")"); do { *(
(volatile int*)__null) = 11065; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
11065 "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"
, 11065); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetAdditionalComputedStyle(0)"
") (" "We don't handle additional styles here" ")"); do { *(
(volatile int*)__null) = 11065; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
11066
11067 // Figure out whether we have an actual change. It's important that we do
11068 // this, for several reasons:
11069 //
11070 // 1) Even if all the child's changes are due to properties it inherits from
11071 // us, it's possible that no one ever asked us for those style structs and
11072 // hence changes to them aren't reflected in the changes handled at all.
11073 //
11074 // 2) Content can change stylesheets that change the styles of pseudos, and
11075 // extensions can add/remove stylesheets that change the styles of
11076 // anonymous boxes directly.
11077 uint32_t equalStructs; // Not used, actually.
11078 nsChangeHint childHint = aChildFrame->Style()->CalcStyleDifference(
11079 *aNewComputedStyle, &equalStructs);
11080
11081 // If aChildFrame is out of flow, then aRestyleState's "changes handled by the
11082 // parent" doesn't apply to it, because it may have some other parent in the
11083 // frame tree.
11084 if (!aChildFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
11085 childHint = NS_RemoveSubsumedHints(
11086 childHint, aRestyleState.ChangesHandledFor(aChildFrame));
11087 }
11088 if (childHint) {
11089 if (childHint & nsChangeHint_ReconstructFrame) {
11090 // If we generate a reconstruct here, remove any non-reconstruct hints we
11091 // may have already generated for this content.
11092 aRestyleState.ChangeList().PopChangesForContent(
11093 aChildFrame->GetContent());
11094 }
11095 aRestyleState.ChangeList().AppendChange(
11096 aChildFrame, aChildFrame->GetContent(), childHint);
11097 }
11098
11099 aChildFrame->SetComputedStyle(aNewComputedStyle);
11100 ComputedStyle* continuationStyle = aContinuationComputedStyle
11101 ? *aContinuationComputedStyle
11102 : aNewComputedStyle;
11103 for (nsIFrame* kid = aChildFrame->GetNextContinuation(); kid;
11104 kid = kid->GetNextContinuation()) {
11105 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"
, 11105); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!kid->GetAdditionalComputedStyle(0)"
")"); do { *((volatile int*)__null) = 11105; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11106 kid->SetComputedStyle(continuationStyle);
11107 }
11108
11109 return childHint;
11110}
11111
11112/* static */
11113void nsIFrame::AddInPopupStateBitToDescendants(nsIFrame* aFrame) {
11114 if (!aFrame->HasAnyStateBits(NS_FRAME_IN_POPUP) &&
11115 aFrame->TrackingVisibility()) {
11116 // Assume all frames in popups are visible.
11117 aFrame->IncApproximateVisibleCount();
11118 }
11119
11120 aFrame->AddStateBits(NS_FRAME_IN_POPUP);
11121
11122 for (const auto& childList : aFrame->CrossDocChildLists()) {
11123 for (nsIFrame* child : childList.mList) {
11124 AddInPopupStateBitToDescendants(child);
11125 }
11126 }
11127}
11128
11129/* static */
11130void nsIFrame::RemoveInPopupStateBitFromDescendants(nsIFrame* aFrame) {
11131 if (!aFrame->HasAnyStateBits(NS_FRAME_IN_POPUP) ||
11132 nsLayoutUtils::IsPopup(aFrame)) {
11133 return;
11134 }
11135
11136 aFrame->RemoveStateBits(NS_FRAME_IN_POPUP);
11137
11138 if (aFrame->TrackingVisibility()) {
11139 // We assume all frames in popups are visible, so this decrement balances
11140 // out the increment in AddInPopupStateBitToDescendants above.
11141 aFrame->DecApproximateVisibleCount();
11142 }
11143 for (const auto& childList : aFrame->CrossDocChildLists()) {
11144 for (nsIFrame* child : childList.mList) {
11145 RemoveInPopupStateBitFromDescendants(child);
11146 }
11147 }
11148}
11149
11150void nsIFrame::SetParent(nsContainerFrame* aParent) {
11151 // If our parent is a wrapper anon box, our new parent should be too. We
11152 // _can_ change parent if our parent is a wrapper anon box, because some
11153 // wrapper anon boxes can have continuations.
11154 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"
, 11155); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->Style()->IsInheritingAnonBox()"
")"); do { *((volatile int*)__null) = 11155; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false); } } while
(false)
11155 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"
, 11155); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->Style()->IsInheritingAnonBox()"
")"); do { *((volatile int*)__null) = 11155; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false); } } while
(false)
;
11156
11157 // Note that the current mParent may already be destroyed at this point.
11158 mParent = aParent;
11159 MOZ_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"
, 11159); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mParent || PresShell() == mParent->PresShell()"
")"); do { *((volatile int*)__null) = 11159; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11160
11161 if (HasAnyStateBits(NS_FRAME_HAS_VIEW | NS_FRAME_HAS_CHILD_WITH_VIEW)) {
11162 for (nsIFrame* f = aParent;
11163 f && !f->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
11164 f = f->GetParent()) {
11165 f->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
11166 }
11167 }
11168
11169 if (HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)) {
11170 for (nsIFrame* f = aParent; f; f = f->GetParent()) {
11171 if (f->HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)) {
11172 break;
11173 }
11174 f->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE);
11175 }
11176 }
11177
11178 if (HasAnyStateBits(NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE)) {
11179 for (nsIFrame* f = aParent; f; f = f->GetParent()) {
11180 if (f->HasAnyStateBits(
11181 NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE)) {
11182 break;
11183 }
11184 f->AddStateBits(NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE);
11185 }
11186 }
11187
11188 if (HasInvalidFrameInSubtree()) {
11189 for (nsIFrame* f = aParent;
11190 f && !f->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT |
11191 NS_FRAME_IS_NONDISPLAY);
11192 f = nsLayoutUtils::GetCrossDocParentFrameInProcess(f)) {
11193 f->AddStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT);
11194 }
11195 }
11196
11197 if (aParent->HasAnyStateBits(NS_FRAME_IN_POPUP)) {
11198 AddInPopupStateBitToDescendants(this);
11199 } else {
11200 RemoveInPopupStateBitFromDescendants(this);
11201 }
11202
11203 // If our new parent only has invalid children, then we just invalidate
11204 // ourselves too. This is probably faster than clearing the flag all
11205 // the way up the frame tree.
11206 if (aParent->HasAnyStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT)) {
11207 InvalidateFrame();
11208 } else {
11209 SchedulePaint();
11210 }
11211}
11212
11213bool nsIFrame::IsStackingContext(const nsStyleDisplay* aStyleDisplay,
11214 const nsStyleEffects* aStyleEffects) {
11215 // Properties that influence the output of this function should be handled in
11216 // change_bits_for_longhand as well.
11217 if (HasOpacity(aStyleDisplay, aStyleEffects, nullptr)) {
11218 return true;
11219 }
11220 if (IsTransformed()) {
11221 return true;
11222 }
11223 auto willChange = aStyleDisplay->mWillChange.bits;
11224 if (aStyleDisplay->IsContainPaint() || aStyleDisplay->IsContainLayout() ||
11225 willChange & StyleWillChangeBits::CONTAIN) {
11226 if (SupportsContainLayoutAndPaint()) {
11227 return true;
11228 }
11229 }
11230 // strictly speaking, 'perspective' doesn't require visual atomicity,
11231 // but the spec says it acts like the rest of these
11232 if (aStyleDisplay->HasPerspectiveStyle() ||
11233 willChange & StyleWillChangeBits::PERSPECTIVE) {
11234 if (SupportsCSSTransforms()) {
11235 return true;
11236 }
11237 }
11238 if (!StylePosition()->mZIndex.IsAuto() ||
11239 willChange & StyleWillChangeBits::Z_INDEX) {
11240 if (ZIndexApplies()) {
11241 return true;
11242 }
11243 }
11244 return aStyleEffects->mMixBlendMode != StyleBlend::Normal ||
11245 SVGIntegrationUtils::UsingEffectsForFrame(this) ||
11246 aStyleDisplay->IsPositionForcingStackingContext() ||
11247 aStyleDisplay->mIsolation != StyleIsolation::Auto ||
11248 willChange & StyleWillChangeBits::STACKING_CONTEXT_UNCONDITIONAL;
11249}
11250
11251bool nsIFrame::IsStackingContext() {
11252 return IsStackingContext(StyleDisplay(), StyleEffects());
11253}
11254
11255static bool IsFrameScrolledOutOfView(const nsIFrame* aTarget,
11256 const nsRect& aTargetRect,
11257 const nsIFrame* aParent) {
11258 // The ancestor frame we are checking if it clips out aTargetRect relative to
11259 // aTarget.
11260 nsIFrame* clipParent = nullptr;
11261
11262 // find the first scrollable frame or root frame if we are in a fixed pos
11263 // subtree
11264 for (nsIFrame* f = const_cast<nsIFrame*>(aParent); f;
11265 f = nsLayoutUtils::GetCrossDocParentFrameInProcess(f)) {
11266 ScrollContainerFrame* scrollContainerFrame = do_QueryFrame(f);
11267 if (scrollContainerFrame) {
11268 clipParent = f;
11269 break;
11270 }
11271 if (f->StyleDisplay()->mPosition == StylePositionProperty::Fixed &&
11272 nsLayoutUtils::IsReallyFixedPos(f)) {
11273 clipParent = f->GetParent();
11274 break;
11275 }
11276 }
11277
11278 if (!clipParent) {
11279 // Even if we couldn't find the nearest scrollable frame, it might mean we
11280 // are in an out-of-process iframe, try to see if |aTarget| frame is
11281 // scrolled out of view in an scrollable frame in a cross-process ancestor
11282 // document.
11283 return nsLayoutUtils::FrameIsScrolledOutOfViewInCrossProcess(aTarget);
11284 }
11285
11286 nsRect clipRect = clipParent->InkOverflowRectRelativeToSelf();
11287 // We consider that the target is scrolled out if the scrollable (or root)
11288 // frame is empty.
11289 if (clipRect.IsEmpty()) {
11290 return true;
11291 }
11292
11293 nsRect transformedRect = nsLayoutUtils::TransformFrameRectToAncestor(
11294 aTarget, aTargetRect, clipParent);
11295
11296 if (transformedRect.IsEmpty()) {
11297 // If the transformed rect is empty it represents a line or a point that we
11298 // should check is outside the the scrollable rect.
11299 if (transformedRect.x > clipRect.XMost() ||
11300 transformedRect.y > clipRect.YMost() ||
11301 clipRect.x > transformedRect.XMost() ||
11302 clipRect.y > transformedRect.YMost()) {
11303 return true;
11304 }
11305 } else if (!transformedRect.Intersects(clipRect)) {
11306 return true;
11307 }
11308
11309 nsIFrame* parent = clipParent->GetParent();
11310 if (!parent) {
11311 return false;
11312 }
11313
11314 return IsFrameScrolledOutOfView(aTarget, aTargetRect, parent);
11315}
11316
11317bool nsIFrame::IsScrolledOutOfView() const {
11318 nsRect rect = InkOverflowRectRelativeToSelf();
11319 return IsFrameScrolledOutOfView(this, rect, this);
11320}
11321
11322gfx::Matrix nsIFrame::ComputeWidgetTransform() const {
11323 const nsStyleUIReset* uiReset = StyleUIReset();
11324 if (uiReset->mMozWindowTransform.IsNone()) {
11325 return gfx::Matrix();
11326 }
11327
11328 TransformReferenceBox refBox(nullptr, nsRect(nsPoint(), GetSize()));
11329
11330 nsPresContext* presContext = PresContext();
11331 int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
11332 gfx::Matrix4x4 matrix = nsStyleTransformMatrix::ReadTransforms(
11333 uiReset->mMozWindowTransform, refBox, float(appUnitsPerDevPixel));
11334
11335 // Apply the -moz-window-transform-origin translation to the matrix.
11336 const StyleTransformOrigin& origin = uiReset->mWindowTransformOrigin;
11337 Point transformOrigin = nsStyleTransformMatrix::Convert2DPosition(
11338 origin.horizontal, origin.vertical, refBox, appUnitsPerDevPixel);
11339 matrix.ChangeBasis(Point3D(transformOrigin.x, transformOrigin.y, 0));
11340
11341 gfx::Matrix result2d;
11342 if (!matrix.CanDraw2D(&result2d)) {
11343 // FIXME: It would be preferable to reject non-2D transforms at parse time.
11344 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"
, 11346)
11345 "-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"
, 11346)
11346 "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"
, 11346)
;
11347 return gfx::Matrix();
11348 }
11349
11350 return result2d;
11351}
11352
11353void nsIFrame::DoUpdateStyleOfOwnedAnonBoxes(ServoRestyleState& aRestyleState) {
11354 // As a special case, we check for {ib}-split block frames here, rather
11355 // than have an nsInlineFrame::AppendDirectlyOwnedAnonBoxes implementation
11356 // that returns them.
11357 //
11358 // (If we did handle them in AppendDirectlyOwnedAnonBoxes, we would have to
11359 // return *all* of the in-flow {ib}-split block frames, not just the first
11360 // one. For restyling, we really just need the first in flow, and the other
11361 // user of the AppendOwnedAnonBoxes API, AllChildIterator, doesn't need to
11362 // know about them at all, since these block frames never create NAC. So we
11363 // avoid any unncessary hashtable lookups for the {ib}-split frames by calling
11364 // UpdateStyleOfOwnedAnonBoxesForIBSplit directly here.)
11365 if (IsInlineFrame()) {
11366 if (HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) {
11367 static_cast<nsInlineFrame*>(this)->UpdateStyleOfOwnedAnonBoxesForIBSplit(
11368 aRestyleState);
11369 }
11370 return;
11371 }
11372
11373 AutoTArray<OwnedAnonBox, 4> frames;
11374 AppendDirectlyOwnedAnonBoxes(frames);
11375 for (OwnedAnonBox& box : frames) {
11376 if (box.mUpdateStyleFn) {
11377 box.mUpdateStyleFn(this, box.mAnonBoxFrame, aRestyleState);
11378 } else {
11379 UpdateStyleOfChildAnonBox(box.mAnonBoxFrame, aRestyleState);
11380 }
11381 }
11382}
11383
11384/* virtual */
11385void nsIFrame::AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) {
11386 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"
, 11386); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES)"
")"); do { *((volatile int*)__null) = 11386; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11387 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: "
"Subclasses that have directly owned anonymous boxes should override "
"this method!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11389); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Subclasses that have directly owned anonymous boxes should override "
"this method!" ")"); do { *((volatile int*)__null) = 11389; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
11388 "Subclasses that have directly owned anonymous boxes should override "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: "
"Subclasses that have directly owned anonymous boxes should override "
"this method!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11389); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Subclasses that have directly owned anonymous boxes should override "
"this method!" ")"); do { *((volatile int*)__null) = 11389; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
11389 "this method!")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: "
"Subclasses that have directly owned anonymous boxes should override "
"this method!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11389); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Subclasses that have directly owned anonymous boxes should override "
"this method!" ")"); do { *((volatile int*)__null) = 11389; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
11390}
11391
11392void nsIFrame::DoAppendOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) {
11393 size_t i = aResult.Length();
11394 AppendDirectlyOwnedAnonBoxes(aResult);
11395
11396 // After appending the directly owned anonymous boxes of this frame to
11397 // aResult above, we need to check each of them to see if they own
11398 // any anonymous boxes themselves. Note that we keep progressing
11399 // through aResult, looking for additional entries in aResult from these
11400 // subsequent AppendDirectlyOwnedAnonBoxes calls. (Thus we can't
11401 // use a ranged for loop here.)
11402
11403 while (i < aResult.Length()) {
11404 nsIFrame* f = aResult[i].mAnonBoxFrame;
11405 if (f->HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES)) {
11406 f->AppendDirectlyOwnedAnonBoxes(aResult);
11407 }
11408 ++i;
11409 }
11410}
11411
11412nsIFrame::CaretPosition::CaretPosition() : mContentOffset(0) {}
11413
11414nsIFrame::CaretPosition::~CaretPosition() = default;
11415
11416bool nsIFrame::HasCSSAnimations() {
11417 auto* collection = AnimationCollection<CSSAnimation>::Get(this);
11418 return collection && !collection->mAnimations.IsEmpty();
11419}
11420
11421bool nsIFrame::HasCSSTransitions() {
11422 auto* collection = AnimationCollection<CSSTransition>::Get(this);
11423 return collection && !collection->mAnimations.IsEmpty();
11424}
11425
11426void nsIFrame::AddSizeOfExcludingThisForTree(nsWindowSizes& aSizes) const {
11427 aSizes.mLayoutFramePropertiesSize +=
11428 mProperties.SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
11429
11430 // We don't do this for Gecko because this stuff is stored in the nsPresArena
11431 // and so measured elsewhere.
11432 if (!aSizes.mState.HaveSeenPtr(mComputedStyle)) {
11433 mComputedStyle->AddSizeOfIncludingThis(aSizes,
11434 &aSizes.mLayoutComputedValuesNonDom);
11435 }
11436
11437 // And our additional styles.
11438 int32_t index = 0;
11439 while (auto* extra = GetAdditionalComputedStyle(index++)) {
11440 if (!aSizes.mState.HaveSeenPtr(extra)) {
11441 extra->AddSizeOfIncludingThis(aSizes,
11442 &aSizes.mLayoutComputedValuesNonDom);
11443 }
11444 }
11445
11446 for (const auto& childList : ChildLists()) {
11447 for (const nsIFrame* f : childList.mList) {
11448 f->AddSizeOfExcludingThisForTree(aSizes);
11449 }
11450 }
11451}
11452
11453nsRect nsIFrame::GetCompositorHitTestArea(nsDisplayListBuilder* aBuilder) {
11454 nsRect area;
11455
11456 ScrollContainerFrame* scrollContainerFrame =
11457 nsLayoutUtils::GetScrollContainerFrameFor(this);
11458 if (scrollContainerFrame) {
11459 // If this frame is the scrolled frame of a scroll container frame, then we
11460 // need to pick up the area corresponding to the overflow rect as well.
11461 // Otherwise the parts of the overflow that are not occupied by descendants
11462 // get skipped and the APZ code sends touch events to the content underneath
11463 // instead. See https://bugzilla.mozilla.org/show_bug.cgi?id=1127773#c15.
11464 area = ScrollableOverflowRect();
11465 } else {
11466 area = GetRectRelativeToSelf();
11467 }
11468
11469 if (!area.IsEmpty()) {
11470 return area + aBuilder->ToReferenceFrame(this);
11471 }
11472
11473 return area;
11474}
11475
11476CompositorHitTestInfo nsIFrame::GetCompositorHitTestInfo(
11477 nsDisplayListBuilder* aBuilder) {
11478 CompositorHitTestInfo result = CompositorHitTestInvisibleToHit;
11479
11480 if (aBuilder->IsInsidePointerEventsNoneDoc()) {
11481 // Somewhere up the parent document chain is a subdocument with pointer-
11482 // events:none set on it.
11483 return result;
11484 }
11485 if (!GetParent()) {
11486 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"
, 11486); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsViewportFrame()"
")"); do { *((volatile int*)__null) = 11486; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11487 // Viewport frames are never event targets, other frames, like canvas
11488 // frames, are the event targets for any regions viewport frames may cover.
11489 return result;
11490 }
11491 if (Style()->PointerEvents() == StylePointerEvents::None) {
11492 return result;
11493 }
11494 if (!StyleVisibility()->IsVisible()) {
11495 return result;
11496 }
11497
11498 // Anything that didn't match the above conditions is visible to hit-testing.
11499 result = CompositorHitTestFlags::eVisibleToHitTest;
11500 SVGUtils::MaskUsage maskUsage = SVGUtils::DetermineMaskUsage(this, false);
11501 if (maskUsage.UsingMaskOrClipPath()) {
11502 // If WebRender is enabled, simple clip-paths can be converted into WR
11503 // clips that WR knows how to hit-test against, so we don't need to mark
11504 // it as an irregular area.
11505 if (!maskUsage.IsSimpleClipShape()) {
11506 result += CompositorHitTestFlags::eIrregularArea;
11507 }
11508 }
11509
11510 if (aBuilder->IsBuildingNonLayerizedScrollbar()) {
11511 // Scrollbars may be painted into a layer below the actual layer they will
11512 // scroll, and therefore wheel events may be dispatched to the outer frame
11513 // instead of the intended scrollframe. To address this, we force a d-t-c
11514 // region on scrollbar frames that won't be placed in their own layer. See
11515 // bug 1213324 for details.
11516 result += CompositorHitTestFlags::eInactiveScrollframe;
11517 } else if (aBuilder->GetAncestorHasApzAwareEventHandler()) {
11518 result += CompositorHitTestFlags::eApzAwareListeners;
11519 } else if (IsRangeFrame()) {
11520 // Range frames handle touch events directly without having a touch listener
11521 // so we need to let APZ know that this area cares about events.
11522 result += CompositorHitTestFlags::eApzAwareListeners;
11523 }
11524
11525 if (aBuilder->IsTouchEventPrefEnabledDoc()) {
11526 // Inherit the touch-action flags from the parent, if there is one. We do
11527 // this because of how the touch-action on a frame combines the touch-action
11528 // from ancestor DOM elements. Refer to the documentation in
11529 // TouchActionHelper.cpp for details; this code is meant to be equivalent to
11530 // that code, but woven into the top-down recursive display list building
11531 // process.
11532 CompositorHitTestInfo inheritedTouchAction =
11533 aBuilder->GetCompositorHitTestInfo() & CompositorHitTestTouchActionMask;
11534
11535 nsIFrame* touchActionFrame = this;
11536 if (ScrollContainerFrame* scrollContainerFrame =
11537 nsLayoutUtils::GetScrollContainerFrameFor(this)) {
11538 ScrollStyles ss = scrollContainerFrame->GetScrollStyles();
11539 if (ss.mVertical != StyleOverflow::Hidden ||
11540 ss.mHorizontal != StyleOverflow::Hidden) {
11541 touchActionFrame = scrollContainerFrame;
11542 // On scrollframes, stop inheriting the pan-x and pan-y flags; instead,
11543 // reset them back to zero to allow panning on the scrollframe unless we
11544 // encounter an element that disables it that's inside the scrollframe.
11545 // This is equivalent to the |considerPanning| variable in
11546 // TouchActionHelper.cpp, but for a top-down traversal.
11547 CompositorHitTestInfo panMask(
11548 CompositorHitTestFlags::eTouchActionPanXDisabled,
11549 CompositorHitTestFlags::eTouchActionPanYDisabled);
11550 inheritedTouchAction -= panMask;
11551 }
11552 }
11553
11554 result += inheritedTouchAction;
11555
11556 const StyleTouchAction touchAction = touchActionFrame->UsedTouchAction();
11557 // The CSS allows the syntax auto | none | [pan-x || pan-y] | manipulation
11558 // so we can eliminate some combinations of things.
11559 if (touchAction == StyleTouchAction::AUTO) {
11560 // nothing to do
11561 } else if (touchAction & StyleTouchAction::MANIPULATION) {
11562 result += CompositorHitTestFlags::eTouchActionAnimatingZoomDisabled;
11563 } else {
11564 // This path handles the cases none | [pan-x || pan-y || pinch-zoom] so
11565 // double-tap is disabled in here.
11566 if (!(touchAction & StyleTouchAction::PINCH_ZOOM)) {
11567 result += CompositorHitTestFlags::eTouchActionPinchZoomDisabled;
11568 }
11569
11570 result += CompositorHitTestFlags::eTouchActionAnimatingZoomDisabled;
11571
11572 if (!(touchAction & StyleTouchAction::PAN_X)) {
11573 result += CompositorHitTestFlags::eTouchActionPanXDisabled;
11574 }
11575 if (!(touchAction & StyleTouchAction::PAN_Y)) {
11576 result += CompositorHitTestFlags::eTouchActionPanYDisabled;
11577 }
11578 if (touchAction & StyleTouchAction::NONE) {
11579 // all the touch-action disabling flags will already have been set above
11580 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"
, 11580); AnnotateMozCrashReason("MOZ_ASSERT" "(" "result.contains(CompositorHitTestTouchActionMask)"
")"); do { *((volatile int*)__null) = 11580; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11581 }
11582 }
11583 }
11584
11585 const Maybe<ScrollDirection> scrollDirection =
11586 aBuilder->GetCurrentScrollbarDirection();
11587 if (scrollDirection.isSome()) {
11588 if (GetContent()->IsXULElement(nsGkAtoms::thumb)) {
11589 const bool thumbGetsLayer = aBuilder->GetCurrentScrollbarTarget() !=
11590 layers::ScrollableLayerGuid::NULL_SCROLL_ID;
11591 if (thumbGetsLayer) {
11592 result += CompositorHitTestFlags::eScrollbarThumb;
11593 } else {
11594 result += CompositorHitTestFlags::eInactiveScrollframe;
11595 }
11596 }
11597
11598 if (*scrollDirection == ScrollDirection::eVertical) {
11599 result += CompositorHitTestFlags::eScrollbarVertical;
11600 }
11601
11602 // includes the ScrollbarFrame, SliderFrame, anything else that
11603 // might be inside the xul:scrollbar
11604 result += CompositorHitTestFlags::eScrollbar;
11605 }
11606
11607 return result;
11608}
11609
11610// Returns true if we can guarantee there is no visible descendants.
11611static bool HasNoVisibleDescendants(const nsIFrame* aFrame) {
11612 for (const auto& childList : aFrame->ChildLists()) {
11613 for (nsIFrame* f : childList.mList) {
11614 if (nsPlaceholderFrame::GetRealFrameFor(f)
11615 ->IsVisibleOrMayHaveVisibleDescendants()) {
11616 return false;
11617 }
11618 }
11619 }
11620 return true;
11621}
11622
11623void nsIFrame::UpdateVisibleDescendantsState() {
11624 if (StyleVisibility()->IsVisible()) {
11625 // Notify invisible ancestors that a visible descendant exists now.
11626 nsIFrame* ancestor;
11627 for (ancestor = GetInFlowParent();
11628 ancestor && !ancestor->StyleVisibility()->IsVisible();
11629 ancestor = ancestor->GetInFlowParent()) {
11630 ancestor->mAllDescendantsAreInvisible = false;
11631 }
11632 } else {
11633 mAllDescendantsAreInvisible = HasNoVisibleDescendants(this);
11634 }
11635}
11636
11637PhysicalAxes nsIFrame::ShouldApplyOverflowClipping(
11638 const nsStyleDisplay* aDisp) const {
11639 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"
, 11639); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDisp == StyleDisplay()"
") (" "Wrong display struct" ")"); do { *((volatile int*)__null
) = 11639; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
11640
11641 // 'contain:paint', which we handle as 'overflow:clip' here. Except for
11642 // scrollframes we don't need contain:paint to add any clipping, because
11643 // the scrollable frame will already clip overflowing content, and because
11644 // 'contain:paint' should prevent all means of escaping that clipping
11645 // (e.g. because it forms a fixed-pos containing block).
11646 if (aDisp->IsContainPaint() && !IsScrollContainerFrame() &&
11647 SupportsContainLayoutAndPaint()) {
11648 return kPhysicalAxesBoth;
11649 }
11650
11651 // and overflow:hidden that we should interpret as clip
11652 if (aDisp->mOverflowX == StyleOverflow::Hidden &&
11653 aDisp->mOverflowY == StyleOverflow::Hidden) {
11654 // REVIEW: these are the frame types that set up clipping.
11655 LayoutFrameType type = Type();
11656 switch (type) {
11657 case LayoutFrameType::CheckboxRadio:
11658 case LayoutFrameType::ComboboxControl:
11659 case LayoutFrameType::HTMLButtonControl:
11660 case LayoutFrameType::ListControl:
11661 case LayoutFrameType::Meter:
11662 case LayoutFrameType::Progress:
11663 case LayoutFrameType::Range:
11664 case LayoutFrameType::SubDocument:
11665 case LayoutFrameType::SVGForeignObject:
11666 case LayoutFrameType::SVGInnerSVG:
11667 case LayoutFrameType::SVGOuterSVG:
11668 case LayoutFrameType::SVGSymbol:
11669 case LayoutFrameType::Table:
11670 case LayoutFrameType::TableCell:
11671 return kPhysicalAxesBoth;
11672 case LayoutFrameType::TextInput:
11673 // It has an anonymous scroll container frame that handles any overflow.
11674 return PhysicalAxes();
11675 default:
11676 break;
11677 }
11678 }
11679
11680 // clip overflow:clip, except for nsListControlFrame which is
11681 // a ScrollContainerFrame sub-class.
11682 if (MOZ_UNLIKELY((aDisp->mOverflowX == mozilla::StyleOverflow::Clip ||(__builtin_expect(!!((aDisp->mOverflowX == mozilla::StyleOverflow
::Clip || aDisp->mOverflowY == mozilla::StyleOverflow::Clip
) && !IsListControlFrame()), 0))
11683 aDisp->mOverflowY == mozilla::StyleOverflow::Clip) &&(__builtin_expect(!!((aDisp->mOverflowX == mozilla::StyleOverflow
::Clip || aDisp->mOverflowY == mozilla::StyleOverflow::Clip
) && !IsListControlFrame()), 0))
11684 !IsListControlFrame())(__builtin_expect(!!((aDisp->mOverflowX == mozilla::StyleOverflow
::Clip || aDisp->mOverflowY == mozilla::StyleOverflow::Clip
) && !IsListControlFrame()), 0))
) {
11685 // FIXME: we could use GetViewportScrollStylesOverrideElement() here instead
11686 // if that worked correctly in a print context. (see bug 1654667)
11687 const auto* element = Element::FromNodeOrNull(GetContent());
11688 if (!element ||
11689 !PresContext()->ElementWouldPropagateScrollStyles(*element)) {
11690 PhysicalAxes axes;
11691 if (aDisp->mOverflowX == mozilla::StyleOverflow::Clip) {
11692 axes += PhysicalAxis::Horizontal;
11693 }
11694 if (aDisp->mOverflowY == mozilla::StyleOverflow::Clip) {
11695 axes += PhysicalAxis::Vertical;
11696 }
11697 return axes;
11698 }
11699 }
11700
11701 if (HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
11702 return PhysicalAxes();
11703 }
11704
11705 return IsSuppressedScrollableBlockForPrint() ? kPhysicalAxesBoth
11706 : PhysicalAxes();
11707}
11708
11709bool nsIFrame::IsSuppressedScrollableBlockForPrint() const {
11710 // This condition needs to match the suppressScrollFrame logic in the frame
11711 // constructor.
11712 if (!PresContext()->IsPaginated() || !IsBlockFrame() ||
11713 !StyleDisplay()->IsScrollableOverflow() ||
11714 !StyleDisplay()->IsBlockOutsideStyle() ||
11715 mContent->IsInNativeAnonymousSubtree()) {
11716 return false;
11717 }
11718 if (auto* element = Element::FromNode(mContent);
11719 element && PresContext()->ElementWouldPropagateScrollStyles(*element)) {
11720 return false;
11721 }
11722 return true;
11723}
11724
11725bool nsIFrame::HasUnreflowedContainerQueryAncestor() const {
11726 // If this frame has done the first reflow, its ancestors are guaranteed to
11727 // have as well.
11728 if (!HasAnyStateBits(NS_FRAME_FIRST_REFLOW) ||
11729 !PresContext()->HasContainerQueryFrames()) {
11730 return false;
11731 }
11732 for (nsIFrame* cur = GetInFlowParent(); cur; cur = cur->GetInFlowParent()) {
11733 if (!cur->HasAnyStateBits(NS_FRAME_FIRST_REFLOW)) {
11734 // Done first reflow from this ancestor up, including query containers.
11735 return false;
11736 }
11737 if (cur->StyleDisplay()->IsQueryContainer()) {
11738 return true;
11739 }
11740 }
11741 // No query container from this frame up to root.
11742 return false;
11743}
11744
11745bool nsIFrame::ShouldBreakBefore(
11746 const ReflowInput::BreakType aBreakType) const {
11747 const auto* display = StyleDisplay();
11748 return ShouldBreakBetween(display, display->mBreakBefore, aBreakType);
11749}
11750
11751bool nsIFrame::ShouldBreakAfter(const ReflowInput::BreakType aBreakType) const {
11752 const auto* display = StyleDisplay();
11753 return ShouldBreakBetween(display, display->mBreakAfter, aBreakType);
11754}
11755
11756bool nsIFrame::ShouldBreakBetween(
11757 const nsStyleDisplay* aDisplay, const StyleBreakBetween aBreakBetween,
11758 const ReflowInput::BreakType aBreakType) const {
11759 const bool shouldBreakBetween = [&] {
11760 switch (aBreakBetween) {
11761 case StyleBreakBetween::Always:
11762 return true;
11763 case StyleBreakBetween::Auto:
11764 case StyleBreakBetween::Avoid:
11765 return false;
11766 case StyleBreakBetween::Page:
11767 case StyleBreakBetween::Left:
11768 case StyleBreakBetween::Right:
11769 return aBreakType == ReflowInput::BreakType::Page;
11770 }
11771 MOZ_ASSERT_UNREACHABLE("Unknown break-between 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: "
"Unknown break-between value!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11771); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Unknown break-between value!" ")"
); do { *((volatile int*)__null) = 11771; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
11772 return false;
11773 }();
11774
11775 if (!shouldBreakBetween) {
11776 return false;
11777 }
11778 if (IsAbsolutelyPositioned(aDisplay)) {
11779 // 'break-before' and 'break-after' properties does not apply to
11780 // absolutely-positioned boxes.
11781 return false;
11782 }
11783 return true;
11784}
11785
11786#ifdef DEBUG1
11787static void GetTagName(nsIFrame* aFrame, nsIContent* aContent, int aResultSize,
11788 char* aResult) {
11789 if (aContent) {
11790 snprintf(aResult, aResultSize, "%s@%p",
11791 nsAtomCString(aContent->NodeInfo()->NameAtom()).get(), aFrame);
11792 } else {
11793 snprintf(aResult, aResultSize, "@%p", aFrame);
11794 }
11795}
11796
11797void nsIFrame::Trace(const char* aMethod, bool aEnter) {
11798 if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)(int(((mozilla::LogModule*)(sFrameLogModule))->Level()) &
(0x1))
) {
11799 char tagbuf[40];
11800 GetTagName(this, mContent, sizeof(tagbuf), tagbuf);
11801 printf_stderr("%s: %s %s", tagbuf, aEnter ? "enter" : "exit", aMethod);
11802 }
11803}
11804
11805void nsIFrame::Trace(const char* aMethod, bool aEnter,
11806 const nsReflowStatus& aStatus) {
11807 if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)(int(((mozilla::LogModule*)(sFrameLogModule))->Level()) &
(0x1))
) {
11808 char tagbuf[40];
11809 GetTagName(this, mContent, sizeof(tagbuf), tagbuf);
11810 printf_stderr("%s: %s %s, status=%scomplete%s", tagbuf,
11811 aEnter ? "enter" : "exit", aMethod,
11812 aStatus.IsIncomplete() ? "not" : "",
11813 (aStatus.NextInFlowNeedsReflow()) ? "+reflow" : "");
11814 }
11815}
11816
11817void nsIFrame::TraceMsg(const char* aFormatString, ...) {
11818 if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)(int(((mozilla::LogModule*)(sFrameLogModule))->Level()) &
(0x1))
) {
11819 // Format arguments into a buffer
11820 char argbuf[200];
11821 va_list ap;
11822 va_start(ap, aFormatString)__builtin_va_start(ap, aFormatString);
11823 VsprintfLiteral(argbuf, aFormatString, ap);
11824 va_end(ap)__builtin_va_end(ap);
11825
11826 char tagbuf[40];
11827 GetTagName(this, mContent, sizeof(tagbuf), tagbuf);
11828 printf_stderr("%s: %s", tagbuf, argbuf);
11829 }
11830}
11831
11832void nsIFrame::VerifyDirtyBitSet(const nsFrameList& aFrameList) {
11833 for (nsIFrame* f : aFrameList) {
11834 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"
, 11834); MOZ_PretendNoReturn(); } } while (0)
;
11835 }
11836}
11837
11838// Validation of SideIsVertical.
11839# define CASE(side, result) \
11840 static_assert(SideIsVertical(side) == result, "SideIsVertical is wrong")
11841CASE(eSideTop, false);
11842CASE(eSideRight, true);
11843CASE(eSideBottom, false);
11844CASE(eSideLeft, true);
11845# undef CASE
11846
11847// Validation of HalfCornerIsX.
11848# define CASE(corner, result) \
11849 static_assert(HalfCornerIsX(corner) == result, "HalfCornerIsX is wrong")
11850CASE(eCornerTopLeftX, true);
11851CASE(eCornerTopLeftY, false);
11852CASE(eCornerTopRightX, true);
11853CASE(eCornerTopRightY, false);
11854CASE(eCornerBottomRightX, true);
11855CASE(eCornerBottomRightY, false);
11856CASE(eCornerBottomLeftX, true);
11857CASE(eCornerBottomLeftY, false);
11858# undef CASE
11859
11860// Validation of HalfToFullCorner.
11861# define CASE(corner, result) \
11862 static_assert(HalfToFullCorner(corner) == result, \
11863 "HalfToFullCorner is " \
11864 "wrong")
11865CASE(eCornerTopLeftX, eCornerTopLeft);
11866CASE(eCornerTopLeftY, eCornerTopLeft);
11867CASE(eCornerTopRightX, eCornerTopRight);
11868CASE(eCornerTopRightY, eCornerTopRight);
11869CASE(eCornerBottomRightX, eCornerBottomRight);
11870CASE(eCornerBottomRightY, eCornerBottomRight);
11871CASE(eCornerBottomLeftX, eCornerBottomLeft);
11872CASE(eCornerBottomLeftY, eCornerBottomLeft);
11873# undef CASE
11874
11875// Validation of FullToHalfCorner.
11876# define CASE(corner, vert, result) \
11877 static_assert(FullToHalfCorner(corner, vert) == result, \
11878 "FullToHalfCorner is wrong")
11879CASE(eCornerTopLeft, false, eCornerTopLeftX);
11880CASE(eCornerTopLeft, true, eCornerTopLeftY);
11881CASE(eCornerTopRight, false, eCornerTopRightX);
11882CASE(eCornerTopRight, true, eCornerTopRightY);
11883CASE(eCornerBottomRight, false, eCornerBottomRightX);
11884CASE(eCornerBottomRight, true, eCornerBottomRightY);
11885CASE(eCornerBottomLeft, false, eCornerBottomLeftX);
11886CASE(eCornerBottomLeft, true, eCornerBottomLeftY);
11887# undef CASE
11888
11889// Validation of SideToFullCorner.
11890# define CASE(side, second, result) \
11891 static_assert(SideToFullCorner(side, second) == result, \
11892 "SideToFullCorner is wrong")
11893CASE(eSideTop, false, eCornerTopLeft);
11894CASE(eSideTop, true, eCornerTopRight);
11895
11896CASE(eSideRight, false, eCornerTopRight);
11897CASE(eSideRight, true, eCornerBottomRight);
11898
11899CASE(eSideBottom, false, eCornerBottomRight);
11900CASE(eSideBottom, true, eCornerBottomLeft);
11901
11902CASE(eSideLeft, false, eCornerBottomLeft);
11903CASE(eSideLeft, true, eCornerTopLeft);
11904# undef CASE
11905
11906// Validation of SideToHalfCorner.
11907# define CASE(side, second, parallel, result) \
11908 static_assert(SideToHalfCorner(side, second, parallel) == result, \
11909 "SideToHalfCorner is wrong")
11910CASE(eSideTop, false, true, eCornerTopLeftX);
11911CASE(eSideTop, false, false, eCornerTopLeftY);
11912CASE(eSideTop, true, true, eCornerTopRightX);
11913CASE(eSideTop, true, false, eCornerTopRightY);
11914
11915CASE(eSideRight, false, false, eCornerTopRightX);
11916CASE(eSideRight, false, true, eCornerTopRightY);
11917CASE(eSideRight, true, false, eCornerBottomRightX);
11918CASE(eSideRight, true, true, eCornerBottomRightY);
11919
11920CASE(eSideBottom, false, true, eCornerBottomRightX);
11921CASE(eSideBottom, false, false, eCornerBottomRightY);
11922CASE(eSideBottom, true, true, eCornerBottomLeftX);
11923CASE(eSideBottom, true, false, eCornerBottomLeftY);
11924
11925CASE(eSideLeft, false, false, eCornerBottomLeftX);
11926CASE(eSideLeft, false, true, eCornerBottomLeftY);
11927CASE(eSideLeft, true, false, eCornerTopLeftX);
11928CASE(eSideLeft, true, true, eCornerTopLeftY);
11929# undef CASE
11930
11931#endif