Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp
Warning:line 3563, 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-18/lib/clang/18 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D 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-18/lib/clang/18/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 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-07-30-004816-4182763-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::IsPrimaryFrameOfRootOrBodyElement() const {
582 if (!IsPrimaryFrame()) {
583 return false;
584 }
585 nsIContent* content = GetContent();
586 Document* document = content->OwnerDoc();
587 return content == document->GetRootElement() ||
588 content == document->GetBodyElement();
589}
590
591bool nsIFrame::IsRenderedLegend() const {
592 if (auto* parent = GetParent(); parent && parent->IsFieldSetFrame()) {
593 return static_cast<nsFieldSetFrame*>(parent)->GetLegend() == this;
594 }
595 return false;
596}
597
598void nsIFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
599 nsIFrame* aPrevInFlow) {
600 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"
, 600); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsQueryFrame::FrameIID(mClass) == GetFrameId()"
")"); do { *((volatile int*)__null) = 600; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
601 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"
, 601); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mContent" ") ("
"Double-initing a frame?" ")"); do { *((volatile int*)__null
) = 601; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
602
603 mContent = aContent;
604 mParent = aParent;
605 MOZ_DIAGNOSTIC_ASSERT(!mParent || PresShell() == mParent->PresShell())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mParent || PresShell() == mParent->PresShell())>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!mParent || PresShell() == mParent->PresShell()))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mParent || PresShell() == mParent->PresShell()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 605); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mParent || PresShell() == mParent->PresShell()"
")"); do { *((volatile int*)__null) = 605; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
606
607 if (aPrevInFlow) {
608 mWritingMode = aPrevInFlow->GetWritingMode();
609
610 // Copy some state bits from prev-in-flow (the bits that should apply
611 // throughout a continuation chain). The bits are sorted according to their
612 // order in nsFrameStateBits.h.
613
614 // clang-format off
615 AddStateBits(aPrevInFlow->GetStateBits() &
616 (NS_FRAME_GENERATED_CONTENT |
617 NS_FRAME_OUT_OF_FLOW |
618 NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN |
619 NS_FRAME_INDEPENDENT_SELECTION |
620 NS_FRAME_PART_OF_IBSPLIT |
621 NS_FRAME_MAY_BE_TRANSFORMED |
622 NS_FRAME_HAS_MULTI_COLUMN_ANCESTOR));
623 // clang-format on
624
625 // Copy other bits in nsIFrame from prev-in-flow.
626 mHasColumnSpanSiblings = aPrevInFlow->HasColumnSpanSiblings();
627 } else {
628 PresContext()->ConstructedFrame();
629 }
630
631 if (GetParent()) {
632 if (MOZ_UNLIKELY(mContent == PresContext()->Document()->GetRootElement() &&(__builtin_expect(!!(mContent == PresContext()->Document()
->GetRootElement() && mContent == GetParent()->
GetContent()), 0))
633 mContent == GetParent()->GetContent())(__builtin_expect(!!(mContent == PresContext()->Document()
->GetRootElement() && mContent == GetParent()->
GetContent()), 0))
) {
634 // Our content is the root element and we have the same content as our
635 // parent. That is, we are the internal anonymous frame of the root
636 // element. Copy the used mWritingMode from our parent because
637 // mDocElementContainingBlock gets its mWritingMode from <body>.
638 mWritingMode = GetParent()->GetWritingMode();
639 }
640
641 // Copy some state bits from our parent (the bits that should apply
642 // recursively throughout a subtree). The bits are sorted according to their
643 // order in nsFrameStateBits.h.
644
645 // clang-format off
646 AddStateBits(GetParent()->GetStateBits() &
647 (NS_FRAME_GENERATED_CONTENT |
648 NS_FRAME_INDEPENDENT_SELECTION |
649 NS_FRAME_IS_SVG_TEXT |
650 NS_FRAME_IN_POPUP |
651 NS_FRAME_IS_NONDISPLAY));
652 // clang-format on
653
654 if (HasAnyStateBits(NS_FRAME_IN_POPUP) && TrackingVisibility()) {
655 // Assume all frames in popups are visible.
656 IncApproximateVisibleCount();
657 }
658 }
659 if (aPrevInFlow) {
660 mMayHaveOpacityAnimation = aPrevInFlow->MayHaveOpacityAnimation();
661 mMayHaveTransformAnimation = aPrevInFlow->MayHaveTransformAnimation();
662 } else if (mContent) {
663 // It's fine to fetch the EffectSet for the style frame here because in the
664 // following code we take care of the case where animations may target
665 // a different frame.
666 EffectSet* effectSet = EffectSet::GetForStyleFrame(this);
667 if (effectSet) {
668 mMayHaveOpacityAnimation = effectSet->MayHaveOpacityAnimation();
669
670 if (effectSet->MayHaveTransformAnimation()) {
671 // If we are the inner table frame for display:table content, then
672 // transform animations should go on our parent frame (the table wrapper
673 // frame).
674 //
675 // We do this when initializing the child frame (table inner frame),
676 // because when initializng the table wrapper frame, we don't yet have
677 // access to its children so we can't tell if we have transform
678 // animations or not.
679 if (SupportsCSSTransforms()) {
680 mMayHaveTransformAnimation = true;
681 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
682 } else if (aParent && nsLayoutUtils::GetStyleFrame(aParent) == this) {
683 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"
, 686); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 686; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
684 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"
, 686); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 686; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
685 "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"
, 686); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 686; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
686 " 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"
, 686); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->SupportsCSSTransforms()"
") (" "Style frames that don't support transforms should have parents"
" that do" ")"); do { *((volatile int*)__null) = 686; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
687 aParent->mMayHaveTransformAnimation = true;
688 aParent->AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
689 }
690 }
691 }
692 }
693
694 const nsStyleDisplay* disp = StyleDisplay();
695 if (disp->HasTransform(this)) {
696 // If 'transform' dynamically changes, RestyleManager takes care of
697 // updating this bit.
698 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
699 }
700
701 if (nsLayoutUtils::FontSizeInflationEnabled(PresContext()) ||
702 !GetParent()
703#ifdef DEBUG1
704 // We have assertions that check inflation invariants even when
705 // font size inflation is not enabled.
706 || true
707#endif
708 ) {
709 if (IsFontSizeInflationContainer(this, disp)) {
710 AddStateBits(NS_FRAME_FONT_INFLATION_CONTAINER);
711 if (!GetParent() ||
712 // I'd use NS_FRAME_OUT_OF_FLOW, but it's not set yet.
713 disp->IsFloating(this) || disp->IsAbsolutelyPositioned(this) ||
714 GetParent()->IsFlexContainerFrame() ||
715 GetParent()->IsGridContainerFrame()) {
716 AddStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT);
717 }
718 }
719 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"
, 721); MOZ_PretendNoReturn(); } } while (0)
720 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"
, 721); MOZ_PretendNoReturn(); } } while (0)
721 "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"
, 721); MOZ_PretendNoReturn(); } } while (0)
;
722 }
723
724 if (TrackingVisibility() && PresShell()->AssumeAllFramesVisible()) {
725 IncApproximateVisibleCount();
726 }
727
728 DidSetComputedStyle(nullptr);
729
730 // For a newly created frame, we need to update this frame's visibility state.
731 // Usually we update the state when the frame is restyled and has a
732 // VisibilityChange change hint but we don't generate any change hints for
733 // newly created frames.
734 // Note: We don't need to do this for placeholders since placeholders have
735 // different styles so that the styles don't have visibility:hidden even if
736 // the parent has visibility:hidden style. We also don't need to update the
737 // state when creating continuations because its visibility is the same as its
738 // prev-in-flow, and the animation code cares only primary frames.
739 if (!IsPlaceholderFrame() && !aPrevInFlow) {
740 UpdateVisibleDescendantsState();
741 }
742
743 if (!aPrevInFlow && HasAnyStateBits(NS_FRAME_IS_NONDISPLAY)) {
744 // We aren't going to get a reflow, so nothing else will call
745 // InvalidateRenderingObservers, we have to do it here.
746 SVGObserverUtils::InvalidateRenderingObservers(this);
747 }
748}
749
750void nsIFrame::InitPrimaryFrame() {
751 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"
, 751); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsPrimaryFrame()"
")"); do { *((volatile int*)__null) = 751; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
752 HandlePrimaryFrameStyleChange(nullptr);
753}
754
755void nsIFrame::HandlePrimaryFrameStyleChange(ComputedStyle* aOldStyle) {
756 const nsStyleDisplay* disp = StyleDisplay();
757 const nsStyleDisplay* oldDisp =
758 aOldStyle ? aOldStyle->StyleDisplay() : nullptr;
759
760 const bool wasQueryContainer = oldDisp && oldDisp->IsQueryContainer();
761 const bool isQueryContainer = disp->IsQueryContainer();
762 if (wasQueryContainer != isQueryContainer) {
763 auto* pc = PresContext();
764 if (isQueryContainer) {
765 pc->RegisterContainerQueryFrame(this);
766 } else {
767 pc->UnregisterContainerQueryFrame(this);
768 }
769 }
770
771 const auto cv = disp->ContentVisibility(*this);
772 if (!oldDisp || oldDisp->ContentVisibility(*this) != cv) {
773 if (cv == StyleContentVisibility::Auto) {
774 PresShell()->RegisterContentVisibilityAutoFrame(this);
775 } else {
776 if (auto* element = Element::FromNodeOrNull(GetContent())) {
777 element->ClearContentRelevancy();
778 }
779 PresShell()->UnregisterContentVisibilityAutoFrame(this);
780 }
781 PresContext()->SetNeedsToUpdateHiddenByContentVisibilityForAnimations();
782 }
783
784 HandleLastRememberedSize();
785}
786
787void nsIFrame::Destroy(DestroyContext& aContext) {
788 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"
, 789); MOZ_PretendNoReturn(); } } while (0)
789 "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"
, 789); MOZ_PretendNoReturn(); } } while (0)
;
790 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"
, 791); MOZ_PretendNoReturn(); } } while (0)
791 "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"
, 791); MOZ_PretendNoReturn(); } } while (0)
;
792 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"
, 792); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAbsolutelyPositionedChildren()"
")"); do { *((volatile int*)__null) = 792; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
793 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"
, 794); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)"
") (" "NS_FRAME_PART_OF_IBSPLIT set on non-nsContainerFrame?"
")"); do { *((volatile int*)__null) = 794; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
794 "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"
, 794); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)"
") (" "NS_FRAME_PART_OF_IBSPLIT set on non-nsContainerFrame?"
")"); do { *((volatile int*)__null) = 794; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
795
796 MaybeScheduleReflowSVGNonDisplayText(this);
797
798 SVGObserverUtils::InvalidateDirectRenderingObservers(this);
799
800 const auto* disp = StyleDisplay();
801 if (disp->mPosition == StylePositionProperty::Sticky) {
802 if (auto* ssc =
803 StickyScrollContainer::GetStickyScrollContainerForFrame(this)) {
804 ssc->RemoveFrame(this);
805 }
806 }
807
808 if (HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
809 if (nsPlaceholderFrame* placeholder = GetPlaceholderFrame()) {
810 placeholder->SetOutOfFlowFrame(nullptr);
811 }
812 }
813
814 nsPresContext* pc = PresContext();
815 mozilla::PresShell* ps = pc->GetPresShell();
816 if (IsPrimaryFrame()) {
817 if (disp->IsQueryContainer()) {
818 pc->UnregisterContainerQueryFrame(this);
819 }
820 if (disp->ContentVisibility(*this) == StyleContentVisibility::Auto) {
821 ps->UnregisterContentVisibilityAutoFrame(this);
822 }
823 // This needs to happen before we clear our Properties() table.
824 ActiveLayerTracker::TransferActivityToContent(this, mContent);
825 }
826
827 ScrollAnchorContainer* anchor = nullptr;
828 if (IsScrollAnchor(&anchor)) {
829 anchor->InvalidateAnchor();
830 }
831
832 if (HasCSSAnimations() || HasCSSTransitions() ||
833 // It's fine to look up the style frame here since if we're destroying the
834 // frames for display:table content we should be destroying both wrapper
835 // and inner frame.
836 EffectSet::GetForStyleFrame(this)) {
837 // If no new frame for this element is created by the end of the
838 // restyling process, stop animations and transitions for this frame
839 RestyleManager::AnimationsWithDestroyedFrame* adf =
840 pc->RestyleManager()->GetAnimationsWithDestroyedFrame();
841 // AnimationsWithDestroyedFrame only lives during the restyling process.
842 if (adf) {
843 adf->Put(mContent, mComputedStyle);
844 }
845 }
846
847 // Disable visibility tracking. Note that we have to do this before we clear
848 // frame properties and lose track of whether we were previously visible.
849 // XXX(seth): It'd be ideal to assert that we're already marked nonvisible
850 // here, but it's unfortunately tricky to guarantee in the face of things like
851 // frame reconstruction induced by style changes.
852 DisableVisibilityTracking();
853
854 // Ensure that we're not in the approximately visible list anymore.
855 ps->RemoveFrameFromApproximatelyVisibleList(this);
856
857 ps->NotifyDestroyingFrame(this);
858
859 if (HasAnyStateBits(NS_FRAME_EXTERNAL_REFERENCE)) {
860 ps->ClearFrameRefs(this);
861 }
862
863 nsView* view = GetView();
864 if (view) {
865 view->SetFrame(nullptr);
866 view->Destroy();
867 }
868
869 // Make sure that our deleted frame can't be returned from GetPrimaryFrame()
870 if (IsPrimaryFrame()) {
871 mContent->SetPrimaryFrame(nullptr);
872
873 // Pass the root of a generated content subtree (e.g. ::after/::before) to
874 // aPostDestroyData to unbind it after frame destruction is done.
875 if (HasAnyStateBits(NS_FRAME_GENERATED_CONTENT) &&
876 mContent->IsRootOfNativeAnonymousSubtree()) {
877 aContext.AddAnonymousContent(mContent.forget());
878 }
879 }
880
881 // Remove all properties attached to the frame, to ensure any property
882 // destructors that need the frame pointer are handled properly.
883 RemoveAllProperties();
884
885 // Must retrieve the object ID before calling destructors, so the
886 // vtable is still valid.
887 //
888 // Note to future tweakers: having the method that returns the
889 // object size call the destructor will not avoid an indirect call;
890 // the compiler cannot devirtualize the call to the destructor even
891 // if it's from a method defined in the same class.
892
893 nsQueryFrame::FrameIID id = GetFrameId();
894 this->~nsIFrame();
895
896#ifdef DEBUG1
897 {
898 nsIFrame* rootFrame = ps->GetRootFrame();
899 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"
, 899); AnnotateMozCrashReason("MOZ_ASSERT" "(" "rootFrame" ")"
); do { *((volatile int*)__null) = 899; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
900 if (this != rootFrame) {
901 auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(rootFrame);
902 auto* data = builder ? builder->Data() : nullptr;
903
904 const bool inData =
905 data && (data->IsModified(this) || data->HasProps(this));
906
907 if (inData) {
908 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)
;
909 }
910
911 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"
, 911); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!inData" ") ("
"Deleted frame in retained data!" ")"); do { *((volatile int
*)__null) = 911; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
912 }
913 }
914#endif
915
916 // Now that we're totally cleaned out, we need to add ourselves to
917 // the presshell's recycler.
918 ps->FreeFrame(id, this);
919}
920
921std::pair<int32_t, int32_t> nsIFrame::GetOffsets() const {
922 return std::make_pair(0, 0);
923}
924
925static void CompareLayers(
926 const nsStyleImageLayers* aFirstLayers,
927 const nsStyleImageLayers* aSecondLayers,
928 const std::function<void(imgRequestProxy* aReq)>& aCallback) {
929 NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, (*aFirstLayers))for (uint32_t i = ((*aFirstLayers)).mImageCount; (i)-- != 0;) {
930 const auto& image = aFirstLayers->mLayers[i].mImage;
931 if (!image.IsImageRequestType() || !image.IsResolved()) {
932 continue;
933 }
934
935 // aCallback is called when the style image in aFirstLayers is thought to
936 // be different with the corresponded one in aSecondLayers
937 if (!aSecondLayers || i >= aSecondLayers->mImageCount ||
938 (!aSecondLayers->mLayers[i].mImage.IsResolved() ||
939 image.GetImageRequest() !=
940 aSecondLayers->mLayers[i].mImage.GetImageRequest())) {
941 if (imgRequestProxy* req = image.GetImageRequest()) {
942 aCallback(req);
943 }
944 }
945 }
946}
947
948static void AddAndRemoveImageAssociations(
949 ImageLoader& aImageLoader, nsIFrame* aFrame,
950 const nsStyleImageLayers* aOldLayers,
951 const nsStyleImageLayers* aNewLayers) {
952 // If the old context had a background-image image, or mask-image image,
953 // and new context does not have the same image, clear the image load
954 // notifier (which keeps the image loading, if it still is) for the frame.
955 // We want to do this conservatively because some frames paint their
956 // backgrounds from some other frame's style data, and we don't want
957 // to clear those notifiers unless we have to. (They'll be reset
958 // when we paint, although we could miss a notification in that
959 // interval.)
960 if (aOldLayers && aFrame->HasImageRequest()) {
961 CompareLayers(aOldLayers, aNewLayers, [&](imgRequestProxy* aReq) {
962 aImageLoader.DisassociateRequestFromFrame(aReq, aFrame);
963 });
964 }
965
966 CompareLayers(aNewLayers, aOldLayers, [&](imgRequestProxy* aReq) {
967 aImageLoader.AssociateRequestToFrame(aReq, aFrame);
968 });
969}
970
971void nsIFrame::AddDisplayItem(nsDisplayItem* aItem) {
972 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"
, 972); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mDisplayItems.Contains(aItem)"
")"); do { *((volatile int*)__null) = 972; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
973 mDisplayItems.AppendElement(aItem);
974#ifdef ACCESSIBILITY1
975 if (nsAccessibilityService* accService = GetAccService()) {
976 accService->NotifyOfPossibleBoundsChange(PresShell(), mContent);
977 }
978#endif
979}
980
981bool nsIFrame::RemoveDisplayItem(nsDisplayItem* aItem) {
982 return mDisplayItems.RemoveElement(aItem);
983}
984
985bool nsIFrame::HasDisplayItems() { return !mDisplayItems.IsEmpty(); }
986
987bool nsIFrame::HasDisplayItem(nsDisplayItem* aItem) {
988 return mDisplayItems.Contains(aItem);
989}
990
991bool nsIFrame::HasDisplayItem(uint32_t aKey) {
992 for (nsDisplayItem* i : mDisplayItems) {
993 if (i->GetPerFrameKey() == aKey) {
994 return true;
995 }
996 }
997 return false;
998}
999
1000template <typename Condition>
1001static void DiscardDisplayItems(nsIFrame* aFrame, Condition aCondition) {
1002 for (nsDisplayItem* i : aFrame->DisplayItems()) {
1003 // Only discard items that are invalidated by this frame, as we're only
1004 // guaranteed to rebuild those items. Table background items are created by
1005 // the relevant table part, but have the cell frame as the primary frame,
1006 // and we don't want to remove them if this is the cell.
1007 if (aCondition(i) && i->FrameForInvalidation() == aFrame) {
1008 i->SetCantBeReused();
1009 }
1010 }
1011}
1012
1013static void DiscardOldItems(nsIFrame* aFrame) {
1014 DiscardDisplayItems(aFrame,
1015 [](nsDisplayItem* aItem) { return aItem->IsOldItem(); });
1016}
1017
1018void nsIFrame::RemoveDisplayItemDataForDeletion() {
1019 // Destroying a WebRenderUserDataTable can cause destruction of other objects
1020 // which can remove frame properties in their destructor. If we delete a frame
1021 // property it runs the destructor of the stored object in the middle of
1022 // updating the frame property table, so if the destruction of that object
1023 // causes another update to the frame property table it would leave the frame
1024 // property table in an inconsistent state. So we remove it from the table and
1025 // then destroy it. (bug 1530657)
1026 WebRenderUserDataTable* userDataTable =
1027 TakeProperty(WebRenderUserDataProperty::Key());
1028 if (userDataTable) {
1029 for (const auto& data : userDataTable->Values()) {
1030 data->RemoveFromTable();
1031 }
1032 delete userDataTable;
1033 }
1034
1035 if (!nsLayoutUtils::AreRetainedDisplayListsEnabled()) {
1036 // Retained display lists are disabled, no need to update
1037 // RetainedDisplayListData.
1038 return;
1039 }
1040
1041 auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(this);
1042 if (!builder) {
1043 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"
, 1043); AnnotateMozCrashReason("MOZ_ASSERT" "(" "DisplayItems().IsEmpty()"
")"); do { *((volatile int*)__null) = 1043; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1044 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"
, 1044); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsFrameModified()"
")"); do { *((volatile int*)__null) = 1044; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1045 return;
1046 }
1047
1048 for (nsDisplayItem* i : DisplayItems()) {
1049 if (i->GetDependentFrame() == this && !i->HasDeletedFrame()) {
1050 i->Frame()->MarkNeedsDisplayItemRebuild();
1051 }
1052 i->RemoveFrame(this);
1053 }
1054
1055 DisplayItems().Clear();
1056
1057 nsAutoString name;
1058#ifdef DEBUG_FRAME_DUMP1
1059 if (DL_LOG_TEST(LogLevel::Debug)(__builtin_expect(!!(mozilla::detail::log_test(GetLoggerByProcess
(), LogLevel::Debug)), 0))
) {
1060 GetFrameName(name);
1061 }
1062#endif
1063 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)
1064 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)
;
1065
1066 auto* data = builder->Data();
1067 if (MayHaveWillChangeBudget()) {
1068 // Keep the frame in list, so it can be removed from the will-change budget.
1069 data->Flags(this) = RetainedDisplayListData::FrameFlag::HadWillChange;
1070 } else {
1071 data->Remove(this);
1072 }
1073}
1074
1075void nsIFrame::MarkNeedsDisplayItemRebuild() {
1076 if (!nsLayoutUtils::AreRetainedDisplayListsEnabled() || IsFrameModified() ||
1077 HasAnyStateBits(NS_FRAME_IN_POPUP)) {
1078 // Skip frames that are already marked modified.
1079 return;
1080 }
1081
1082 if (Type() == LayoutFrameType::Placeholder) {
1083 nsIFrame* oof = static_cast<nsPlaceholderFrame*>(this)->GetOutOfFlowFrame();
1084 if (oof) {
1085 oof->MarkNeedsDisplayItemRebuild();
1086 }
1087 // Do not mark placeholder frames modified.
1088 return;
1089 }
1090
1091#ifdef ACCESSIBILITY1
1092 if (nsAccessibilityService* accService = GetAccService()) {
1093 accService->NotifyOfPossibleBoundsChange(PresShell(), mContent);
1094 }
1095#endif
1096
1097 nsIFrame* rootFrame = PresShell()->GetRootFrame();
1098
1099 if (rootFrame->IsFrameModified()) {
1100 // The whole frame tree is modified.
1101 return;
1102 }
1103
1104 auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(this);
1105 if (!builder) {
1106 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"
, 1106); AnnotateMozCrashReason("MOZ_ASSERT" "(" "DisplayItems().IsEmpty()"
")"); do { *((volatile int*)__null) = 1106; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1107 return;
1108 }
1109
1110 RetainedDisplayListData* data = builder->Data();
1111 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"
, 1111); AnnotateMozCrashReason("MOZ_ASSERT" "(" "data" ")");
do { *((volatile int*)__null) = 1111; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1112
1113 if (data->AtModifiedFrameLimit()) {
1114 // This marks the whole frame tree modified.
1115 // See |RetainedDisplayListBuilder::ShouldBuildPartial()|.
1116 data->AddModifiedFrame(rootFrame);
1117 return;
1118 }
1119
1120 nsAutoString name;
1121#ifdef DEBUG_FRAME_DUMP1
1122 if (DL_LOG_TEST(LogLevel::Debug)(__builtin_expect(!!(mozilla::detail::log_test(GetLoggerByProcess
(), LogLevel::Debug)), 0))
) {
1123 GetFrameName(name);
1124 }
1125#endif
1126
1127 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)
1128 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)
;
1129
1130 data->AddModifiedFrame(this);
1131
1132 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"
, 1133); AnnotateMozCrashReason("MOZ_ASSERT" "(" "PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding) == 0"
")"); do { *((volatile int*)__null) = 1133; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1133 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"
, 1133); AnnotateMozCrashReason("MOZ_ASSERT" "(" "PresContext()->LayoutPhaseCount(nsLayoutPhase::DisplayListBuilding) == 0"
")"); do { *((volatile int*)__null) = 1133; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1134
1135 // Hopefully this is cheap, but we could use a frame state bit to note
1136 // the presence of dependencies to speed it up.
1137 for (nsDisplayItem* i : DisplayItems()) {
1138 if (i->HasDeletedFrame() || i->Frame() == this) {
1139 // Ignore the items with deleted frames, and the items with |this| as
1140 // the primary frame.
1141 continue;
1142 }
1143
1144 if (i->GetDependentFrame() == this) {
1145 // For items with |this| as a dependent frame, mark the primary frame
1146 // for rebuild.
1147 i->Frame()->MarkNeedsDisplayItemRebuild();
1148 }
1149 }
1150}
1151
1152// Subclass hook for style post processing
1153/* virtual */
1154void nsIFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) {
1155#ifdef ACCESSIBILITY1
1156 // Don't notify for reconstructed frames here, since the frame is still being
1157 // constructed at this point and so LocalAccessible::GetFrame() will return
1158 // null. Style changes for reconstructed frames are handled in
1159 // DocAccessible::PruneOrInsertSubtree.
1160 if (aOldComputedStyle) {
1161 if (nsAccessibilityService* accService = GetAccService()) {
1162 accService->NotifyOfComputedStyleChange(PresShell(), mContent);
1163 }
1164 }
1165#endif
1166
1167 MaybeScheduleReflowSVGNonDisplayText(this);
1168
1169 Document* doc = PresContext()->Document();
1170 ImageLoader* loader = doc->StyleImageLoader();
1171 // Continuing text frame doesn't initialize its continuation pointer before
1172 // reaching here for the first time, so we have to exclude text frames. This
1173 // doesn't affect correctness because text can't match selectors.
1174 //
1175 // FIXME(emilio): We should consider fixing that.
1176 //
1177 // TODO(emilio): Can we avoid doing some / all of the image stuff when
1178 // isNonTextFirstContinuation is false? We should consider doing this just for
1179 // primary frames and pseudos, but the first-line reparenting code makes it
1180 // all bad, should get around to bug 1465474 eventually :(
1181 const bool isNonText = !IsTextFrame();
1182 if (isNonText) {
1183 mComputedStyle->StartImageLoads(*doc, aOldComputedStyle);
1184 }
1185
1186 const nsStyleImageLayers* oldLayers =
1187 aOldComputedStyle ? &aOldComputedStyle->StyleBackground()->mImage
1188 : nullptr;
1189 const nsStyleImageLayers* newLayers = &StyleBackground()->mImage;
1190 AddAndRemoveImageAssociations(*loader, this, oldLayers, newLayers);
1191
1192 oldLayers =
1193 aOldComputedStyle ? &aOldComputedStyle->StyleSVGReset()->mMask : nullptr;
1194 newLayers = &StyleSVGReset()->mMask;
1195 AddAndRemoveImageAssociations(*loader, this, oldLayers, newLayers);
1196
1197 const nsStyleDisplay* disp = StyleDisplay();
1198 bool handleStickyChange = false;
1199 if (aOldComputedStyle) {
1200 // Detect style changes that should trigger a scroll anchor adjustment
1201 // suppression.
1202 // https://drafts.csswg.org/css-scroll-anchoring/#suppression-triggers
1203 bool needAnchorSuppression = false;
1204
1205 const nsStyleMargin* oldMargin = aOldComputedStyle->StyleMargin();
1206 if (oldMargin->mMargin != StyleMargin()->mMargin) {
1207 needAnchorSuppression = true;
1208 }
1209
1210 const nsStylePadding* oldPadding = aOldComputedStyle->StylePadding();
1211 if (oldPadding->mPadding != StylePadding()->mPadding) {
1212 SetHasPaddingChange(true);
1213 needAnchorSuppression = true;
1214 }
1215
1216 const nsStyleDisplay* oldDisp = aOldComputedStyle->StyleDisplay();
1217 if (oldDisp->mOverflowAnchor != disp->mOverflowAnchor) {
1218 if (auto* container = ScrollAnchorContainer::FindFor(this)) {
1219 container->InvalidateAnchor();
1220 }
1221 if (ScrollContainerFrame* scrollContainerFrame = do_QueryFrame(this)) {
1222 scrollContainerFrame->Anchor()->InvalidateAnchor();
1223 }
1224 }
1225
1226 if (mInScrollAnchorChain) {
1227 const nsStylePosition* pos = StylePosition();
1228 const nsStylePosition* oldPos = aOldComputedStyle->StylePosition();
1229 if (!needAnchorSuppression &&
1230 (oldPos->mOffset != pos->mOffset || oldPos->mWidth != pos->mWidth ||
1231 oldPos->mMinWidth != pos->mMinWidth ||
1232 oldPos->mMaxWidth != pos->mMaxWidth ||
1233 oldPos->mHeight != pos->mHeight ||
1234 oldPos->mMinHeight != pos->mMinHeight ||
1235 oldPos->mMaxHeight != pos->mMaxHeight ||
1236 oldDisp->mPosition != disp->mPosition ||
1237 oldDisp->mTransform != disp->mTransform)) {
1238 needAnchorSuppression = true;
1239 }
1240
1241 if (needAnchorSuppression &&
1242 StaticPrefs::layout_css_scroll_anchoring_suppressions_enabled()) {
1243 ScrollAnchorContainer::FindFor(this)->SuppressAdjustments();
1244 }
1245 }
1246
1247 if (disp->mPosition != oldDisp->mPosition) {
1248 if (!disp->IsRelativelyOrStickyPositionedStyle() &&
1249 oldDisp->IsRelativelyOrStickyPositionedStyle()) {
1250 RemoveProperty(NormalPositionProperty());
1251 }
1252
1253 handleStickyChange = disp->mPosition == StylePositionProperty::Sticky ||
1254 oldDisp->mPosition == StylePositionProperty::Sticky;
1255 }
1256 if (disp->mScrollSnapAlign != oldDisp->mScrollSnapAlign) {
1257 ScrollSnapUtils::PostPendingResnapFor(this);
1258 }
1259 if (aOldComputedStyle->IsRootElementStyle() &&
1260 disp->mScrollSnapType != oldDisp->mScrollSnapType) {
1261 if (ScrollContainerFrame* sf =
1262 PresShell()->GetRootScrollContainerFrame()) {
1263 sf->PostPendingResnap();
1264 }
1265 }
1266 if (StyleUIReset()->mMozSubtreeHiddenOnlyVisually &&
1267 !aOldComputedStyle->StyleUIReset()->mMozSubtreeHiddenOnlyVisually) {
1268 PresShell::ClearMouseCapture(this);
1269 }
1270 } else { // !aOldComputedStyle
1271 handleStickyChange = disp->mPosition == StylePositionProperty::Sticky;
1272 }
1273
1274 if (handleStickyChange && !HasAnyStateBits(NS_FRAME_IS_NONDISPLAY) &&
1275 !GetPrevInFlow()) {
1276 // Note that we only add first continuations, but we really only
1277 // want to add first continuation-or-ib-split-siblings. But since we don't
1278 // yet know if we're a later part of a block-in-inline split, we'll just
1279 // add later members of a block-in-inline split here, and then
1280 // StickyScrollContainer will remove them later.
1281 if (auto* ssc =
1282 StickyScrollContainer::GetStickyScrollContainerForFrame(this)) {
1283 if (disp->mPosition == StylePositionProperty::Sticky) {
1284 ssc->AddFrame(this);
1285 } else {
1286 ssc->RemoveFrame(this);
1287 }
1288 }
1289 }
1290
1291 imgIRequest* oldBorderImage =
1292 aOldComputedStyle
1293 ? aOldComputedStyle->StyleBorder()->GetBorderImageRequest()
1294 : nullptr;
1295 imgIRequest* newBorderImage = StyleBorder()->GetBorderImageRequest();
1296 // FIXME (Bug 759996): The following is no longer true.
1297 // For border-images, we can't be as conservative (we need to set the
1298 // new loaders if there has been any change) since the CalcDifference
1299 // call depended on the result of GetComputedBorder() and that result
1300 // depends on whether the image has loaded, start the image load now
1301 // so that we'll get notified when it completes loading and can do a
1302 // restyle. Otherwise, the image might finish loading from the
1303 // network before we start listening to its notifications, and then
1304 // we'll never know that it's finished loading. Likewise, we want to
1305 // do this for freshly-created frames to prevent a similar race if the
1306 // image loads between reflow (which can depend on whether the image
1307 // is loaded) and paint. We also don't really care about any callers who try
1308 // to paint borders with a different style, because they won't have the
1309 // correct size for the border either.
1310 if (oldBorderImage != newBorderImage) {
1311 // stop and restart the image loading/notification
1312 if (oldBorderImage && HasImageRequest()) {
1313 loader->DisassociateRequestFromFrame(oldBorderImage, this);
1314 }
1315 if (newBorderImage) {
1316 loader->AssociateRequestToFrame(newBorderImage, this);
1317 }
1318 }
1319
1320 auto GetShapeImageRequest = [](const ComputedStyle* aStyle) -> imgIRequest* {
1321 if (!aStyle) {
1322 return nullptr;
1323 }
1324 auto& shape = aStyle->StyleDisplay()->mShapeOutside;
1325 if (!shape.IsImage()) {
1326 return nullptr;
1327 }
1328 return shape.AsImage().GetImageRequest();
1329 };
1330
1331 imgIRequest* oldShapeImage = GetShapeImageRequest(aOldComputedStyle);
1332 imgIRequest* newShapeImage = GetShapeImageRequest(Style());
1333 if (oldShapeImage != newShapeImage) {
1334 if (oldShapeImage && HasImageRequest()) {
1335 loader->DisassociateRequestFromFrame(oldShapeImage, this);
1336 }
1337 if (newShapeImage) {
1338 loader->AssociateRequestToFrame(
1339 newShapeImage, this,
1340 ImageLoader::Flags::
1341 RequiresReflowOnFirstFrameCompleteAndLoadEventBlocking);
1342 }
1343 }
1344
1345 // SVGObserverUtils::GetEffectProperties() asserts that we only invoke it with
1346 // the first continuation so we need to check that in advance.
1347 const bool isNonTextFirstContinuation = isNonText && !GetPrevContinuation();
1348 if (isNonTextFirstContinuation) {
1349 // Kick off loading of external SVG resources referenced from properties if
1350 // any. This currently includes filter, clip-path, and mask.
1351 SVGObserverUtils::InitiateResourceDocLoads(this);
1352 }
1353
1354 // If the page contains markup that overrides text direction, and
1355 // does not contain any characters that would activate the Unicode
1356 // bidi algorithm, we need to call |SetBidiEnabled| on the pres
1357 // context before reflow starts. See bug 115921.
1358 if (StyleVisibility()->mDirection == StyleDirection::Rtl) {
1359 PresContext()->SetBidiEnabled();
1360 }
1361
1362 // The following part is for caching offset-path:path(). We cache the
1363 // flatten gfx path, so we don't have to rebuild and re-flattern it at
1364 // each cycle if we have animations on offset-* with a fixed offset-path.
1365 const StyleOffsetPath* oldPath =
1366 aOldComputedStyle ? &aOldComputedStyle->StyleDisplay()->mOffsetPath
1367 : nullptr;
1368 const StyleOffsetPath& newPath = StyleDisplay()->mOffsetPath;
1369 if (!oldPath || *oldPath != newPath) {
1370 // FIXME: Bug 1837042. Cache all basic shapes.
1371 if (newPath.IsPath()) {
1372 RefPtr<gfx::PathBuilder> builder = MotionPathUtils::GetPathBuilder();
1373 RefPtr<gfx::Path> path =
1374 MotionPathUtils::BuildSVGPath(newPath.AsSVGPathData(), builder);
1375 if (path) {
1376 // The newPath could be path('') (i.e. empty path), so its gfx path
1377 // could be nullptr, and so we only set property for a non-empty path.
1378 SetProperty(nsIFrame::OffsetPathCache(), path.forget().take());
1379 } else {
1380 // May have an old cached path, so we have to delete it.
1381 RemoveProperty(nsIFrame::OffsetPathCache());
1382 }
1383 } else if (oldPath) {
1384 RemoveProperty(nsIFrame::OffsetPathCache());
1385 }
1386 }
1387
1388 if (IsPrimaryFrame()) {
1389 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"
, 1389); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOldComputedStyle"
")"); do { *((volatile int*)__null) = 1389; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1390 HandlePrimaryFrameStyleChange(aOldComputedStyle);
1391 }
1392
1393 RemoveStateBits(NS_FRAME_SIMPLE_EVENT_REGIONS | NS_FRAME_SIMPLE_DISPLAYLIST);
1394
1395 mMayHaveRoundedCorners = true;
1396}
1397
1398void nsIFrame::HandleLastRememberedSize() {
1399 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"
, 1399); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsPrimaryFrame()"
")"); do { *((volatile int*)__null) = 1399; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1400 // Storing a last remembered size requires contain-intrinsic-size.
1401 if (!StaticPrefs::layout_css_contain_intrinsic_size_enabled()) {
1402 return;
1403 }
1404 auto* element = Element::FromNodeOrNull(mContent);
1405 if (!element) {
1406 return;
1407 }
1408 const WritingMode wm = GetWritingMode();
1409 const nsStylePosition* stylePos = StylePosition();
1410 bool canRememberBSize = stylePos->ContainIntrinsicBSize(wm).HasAuto();
1411 bool canRememberISize = stylePos->ContainIntrinsicISize(wm).HasAuto();
1412 if (!canRememberBSize) {
1413 element->RemoveLastRememberedBSize();
1414 }
1415 if (!canRememberISize) {
1416 element->RemoveLastRememberedISize();
1417 }
1418 if ((canRememberBSize || canRememberISize) && !HidesContent()) {
1419 bool isNonReplacedInline = IsLineParticipant() && !IsReplaced();
1420 if (!isNonReplacedInline) {
1421 PresContext()->Document()->ObserveForLastRememberedSize(*element);
1422 return;
1423 }
1424 }
1425 PresContext()->Document()->UnobserveForLastRememberedSize(*element);
1426}
1427
1428#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED1
1429void nsIFrame::AssertNewStyleIsSane(ComputedStyle& aNewStyle) {
1430 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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1431 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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1432 // ::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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1433 // 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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1434 (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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1435 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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1436 // ::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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1437 // 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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1438 // 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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1439 (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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1440 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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1441 (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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1442 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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1443 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"
, 1443); 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) = 1443; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1444}
1445#endif
1446
1447void nsIFrame::ReparentFrameViewTo(nsViewManager* aViewManager,
1448 nsView* aNewParentView) {
1449 if (HasView()) {
1450 if (IsMenuPopupFrame()) {
1451 // This view must be parented by the root view, don't reparent it.
1452 return;
1453 }
1454 nsView* view = GetView();
1455 aViewManager->RemoveChild(view);
1456
1457 // The view will remember the Z-order and other attributes that have been
1458 // set on it.
1459 nsView* insertBefore =
1460 nsLayoutUtils::FindSiblingViewFor(aNewParentView, this);
1461 aViewManager->InsertChild(aNewParentView, view, insertBefore,
1462 insertBefore != nullptr);
1463 } else if (HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW)) {
1464 for (const auto& childList : ChildLists()) {
1465 // Iterate the child frames, and check each child frame to see if it has
1466 // a view
1467 for (nsIFrame* child : childList.mList) {
1468 child->ReparentFrameViewTo(aViewManager, aNewParentView);
1469 }
1470 }
1471 }
1472}
1473
1474void nsIFrame::SyncFrameViewProperties(nsView* aView) {
1475 if (!aView) {
1476 aView = GetView();
1477 if (!aView) {
1478 return;
1479 }
1480 }
1481
1482 nsViewManager* vm = aView->GetViewManager();
1483
1484 // Make sure visibility is correct. This only affects nsSubDocumentFrame.
1485 if (!SupportsVisibilityHidden()) {
1486 // See if the view should be hidden or visible
1487 ComputedStyle* sc = Style();
1488 vm->SetViewVisibility(aView, sc->StyleVisibility()->IsVisible()
1489 ? ViewVisibility::Show
1490 : ViewVisibility::Hide);
1491 }
1492}
1493
1494void nsIFrame::CreateView() {
1495 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"
, 1495); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasView()"
")"); do { *((volatile int*)__null) = 1495; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1496
1497 nsView* parentView = GetParent()->GetClosestView();
1498 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"
, 1498); AnnotateMozCrashReason("MOZ_ASSERT" "(" "parentView"
") (" "no parent with view" ")"); do { *((volatile int*)__null
) = 1498; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
1499
1500 nsViewManager* viewManager = parentView->GetViewManager();
1501 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"
, 1501); AnnotateMozCrashReason("MOZ_ASSERT" "(" "viewManager"
") (" "null view manager" ")"); do { *((volatile int*)__null
) = 1501; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
1502
1503 nsView* view = viewManager->CreateView(GetRect(), parentView);
1504 SyncFrameViewProperties(view);
1505
1506 nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(parentView, this);
1507 // we insert this view 'above' the insertBefore view, unless insertBefore is
1508 // null, in which case we want to call with aAbove == false to insert at the
1509 // beginning in document order
1510 viewManager->InsertChild(parentView, view, insertBefore,
1511 insertBefore != nullptr);
1512
1513 // REVIEW: Don't create a widget for fixed-pos elements anymore.
1514 // ComputeRepaintRegionForCopy will calculate the right area to repaint
1515 // when we scroll.
1516 // Reparent views on any child frames (or their descendants) to this
1517 // view. We can just call ReparentFrameViewTo on this frame because
1518 // we know this frame has no view, so it will crawl the children. Also,
1519 // we know that any descendants with views must have 'parentView' as their
1520 // parent view.
1521 ReparentFrameViewTo(viewManager, view);
1522
1523 // Remember our view
1524 SetView(view);
1525
1526 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)
1527 ("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)
;
1528}
1529
1530/* virtual */
1531nsMargin nsIFrame::GetUsedMargin() const {
1532 nsMargin margin;
1533 if (((mState & NS_FRAME_FIRST_REFLOW) && !(mState & NS_FRAME_IN_REFLOW)) ||
1534 IsInSVGTextSubtree()) {
1535 return margin;
1536 }
1537
1538 if (nsMargin* m = GetProperty(UsedMarginProperty())) {
1539 margin = *m;
1540 } else if (!StyleMargin()->GetMargin(margin)) {
1541 // If we get here, our caller probably shouldn't be calling us...
1542 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"
, 1544); MOZ_PretendNoReturn(); } while (0)
1543 "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"
, 1544); MOZ_PretendNoReturn(); } while (0)
1544 "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"
, 1544); MOZ_PretendNoReturn(); } while (0)
;
1545 }
1546 return margin;
1547}
1548
1549/* virtual */
1550nsMargin nsIFrame::GetUsedBorder() const {
1551 if (((mState & NS_FRAME_FIRST_REFLOW) && !(mState & NS_FRAME_IN_REFLOW)) ||
1552 IsInSVGTextSubtree()) {
1553 return {};
1554 }
1555
1556 const nsStyleDisplay* disp = StyleDisplay();
1557 if (IsThemed(disp)) {
1558 // Theme methods don't use const-ness.
1559 auto* mutable_this = const_cast<nsIFrame*>(this);
1560 nsPresContext* pc = PresContext();
1561 LayoutDeviceIntMargin widgetBorder = pc->Theme()->GetWidgetBorder(
1562 pc->DeviceContext(), mutable_this, disp->EffectiveAppearance());
1563 return LayoutDevicePixel::ToAppUnits(widgetBorder,
1564 pc->AppUnitsPerDevPixel());
1565 }
1566
1567 return StyleBorder()->GetComputedBorder();
1568}
1569
1570/* virtual */
1571nsMargin nsIFrame::GetUsedPadding() const {
1572 nsMargin padding;
1573 if (((mState & NS_FRAME_FIRST_REFLOW) && !(mState & NS_FRAME_IN_REFLOW)) ||
1574 IsInSVGTextSubtree()) {
1575 return padding;
1576 }
1577
1578 const nsStyleDisplay* disp = StyleDisplay();
1579 if (IsThemed(disp)) {
1580 // Theme methods don't use const-ness.
1581 nsIFrame* mutable_this = const_cast<nsIFrame*>(this);
1582 nsPresContext* pc = PresContext();
1583 LayoutDeviceIntMargin widgetPadding;
1584 if (pc->Theme()->GetWidgetPadding(pc->DeviceContext(), mutable_this,
1585 disp->EffectiveAppearance(),
1586 &widgetPadding)) {
1587 return LayoutDevicePixel::ToAppUnits(widgetPadding,
1588 pc->AppUnitsPerDevPixel());
1589 }
1590 }
1591
1592 if (nsMargin* p = GetProperty(UsedPaddingProperty())) {
1593 padding = *p;
1594 } else if (!StylePadding()->GetPadding(padding)) {
1595 // If we get here, our caller probably shouldn't be calling us...
1596 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"
, 1598); MOZ_PretendNoReturn(); } while (0)
1597 "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"
, 1598); MOZ_PretendNoReturn(); } while (0)
1598 "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"
, 1598); MOZ_PretendNoReturn(); } while (0)
;
1599 }
1600 return padding;
1601}
1602
1603nsIFrame::Sides nsIFrame::GetSkipSides() const {
1604 if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak ==(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Clone), 0))
1605 StyleBoxDecorationBreak::Clone)(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Clone), 0))
&&
1606 !HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER)) {
1607 return Sides();
1608 }
1609
1610 // Convert the logical skip sides to physical sides using the frame's
1611 // writing mode
1612 WritingMode writingMode = GetWritingMode();
1613 LogicalSides logicalSkip = GetLogicalSkipSides();
1614 Sides skip;
1615
1616 if (logicalSkip.BStart()) {
1617 if (writingMode.IsVertical()) {
1618 skip |= writingMode.IsVerticalLR() ? SideBits::eLeft : SideBits::eRight;
1619 } else {
1620 skip |= SideBits::eTop;
1621 }
1622 }
1623
1624 if (logicalSkip.BEnd()) {
1625 if (writingMode.IsVertical()) {
1626 skip |= writingMode.IsVerticalLR() ? SideBits::eRight : SideBits::eLeft;
1627 } else {
1628 skip |= SideBits::eBottom;
1629 }
1630 }
1631
1632 if (logicalSkip.IStart()) {
1633 if (writingMode.IsVertical()) {
1634 skip |= SideBits::eTop;
1635 } else {
1636 skip |= writingMode.IsBidiLTR() ? SideBits::eLeft : SideBits::eRight;
1637 }
1638 }
1639
1640 if (logicalSkip.IEnd()) {
1641 if (writingMode.IsVertical()) {
1642 skip |= SideBits::eBottom;
1643 } else {
1644 skip |= writingMode.IsBidiLTR() ? SideBits::eRight : SideBits::eLeft;
1645 }
1646 }
1647 return skip;
1648}
1649
1650nsRect nsIFrame::GetPaddingRectRelativeToSelf() const {
1651 nsMargin border = GetUsedBorder().ApplySkipSides(GetSkipSides());
1652 nsRect r(0, 0, mRect.width, mRect.height);
1653 r.Deflate(border);
1654 return r;
1655}
1656
1657nsRect nsIFrame::GetPaddingRect() const {
1658 return GetPaddingRectRelativeToSelf() + GetPosition();
1659}
1660
1661WritingMode nsIFrame::WritingModeForLine(WritingMode aSelfWM,
1662 nsIFrame* aSubFrame) const {
1663 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"
, 1663); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aSelfWM == GetWritingMode()"
")"); do { *((volatile int*)__null) = 1663; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1664 WritingMode writingMode = aSelfWM;
1665
1666 if (StyleTextReset()->mUnicodeBidi == StyleUnicodeBidi::Plaintext) {
1667 mozilla::intl::BidiEmbeddingLevel frameLevel =
1668 nsBidiPresUtils::GetFrameBaseLevel(aSubFrame);
1669 writingMode.SetDirectionFromBidiLevel(frameLevel);
1670 }
1671
1672 return writingMode;
1673}
1674
1675nsRect nsIFrame::GetMarginRect() const {
1676 return GetMarginRectRelativeToSelf() + GetPosition();
1677}
1678
1679nsRect nsIFrame::GetMarginRectRelativeToSelf() const {
1680 nsMargin m = GetUsedMargin().ApplySkipSides(GetSkipSides());
1681 nsRect r(0, 0, mRect.width, mRect.height);
1682 r.Inflate(m);
1683 return r;
1684}
1685
1686bool nsIFrame::IsTransformed() const {
1687 if (!HasAnyStateBits(NS_FRAME_MAY_BE_TRANSFORMED)) {
1688 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"
, 1688); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsCSSTransformed()"
")"); do { *((volatile int*)__null) = 1688; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1689 MOZ_ASSERT(!IsSVGTransformed())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!IsSVGTransformed())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!IsSVGTransformed()))), 0)))
{ do { } while (false); MOZ_ReportAssertionFailure("!IsSVGTransformed()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 1689); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsSVGTransformed()"
")"); do { *((volatile int*)__null) = 1689; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1690 return false;
1691 }
1692 return IsCSSTransformed() || IsSVGTransformed();
1693}
1694
1695bool nsIFrame::IsCSSTransformed() const {
1696 return HasAnyStateBits(NS_FRAME_MAY_BE_TRANSFORMED) &&
1697 (StyleDisplay()->HasTransform(this) || HasAnimationOfTransform());
1698}
1699
1700bool nsIFrame::HasAnimationOfTransform() const {
1701 return IsPrimaryFrame() &&
1702 nsLayoutUtils::HasAnimationOfTransformAndMotionPath(this) &&
1703 SupportsCSSTransforms();
1704}
1705
1706bool nsIFrame::ChildrenHavePerspective(
1707 const nsStyleDisplay* aStyleDisplay) const {
1708 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"
, 1708); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStyleDisplay == StyleDisplay()"
")"); do { *((volatile int*)__null) = 1708; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1709 return aStyleDisplay->HasPerspective(this);
1710}
1711
1712bool nsIFrame::HasAnimationOfOpacity(EffectSet* aEffectSet) const {
1713 return ((nsLayoutUtils::IsPrimaryStyleFrame(this) ||
1714 nsLayoutUtils::FirstContinuationOrIBSplitSibling(this)
1715 ->IsPrimaryFrame()) &&
1716 nsLayoutUtils::HasAnimationOfPropertySet(
1717 this, nsCSSPropertyIDSet::OpacityProperties(), aEffectSet));
1718}
1719
1720bool nsIFrame::HasOpacityInternal(float aThreshold,
1721 const nsStyleDisplay* aStyleDisplay,
1722 const nsStyleEffects* aStyleEffects,
1723 EffectSet* aEffectSet) const {
1724 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"
, 1724); AnnotateMozCrashReason("MOZ_ASSERT" "(" "0.0 <= aThreshold && aThreshold <= 1.0"
") (" "Invalid argument" ")"); do { *((volatile int*)__null)
= 1724; __attribute__((nomerge)) ::abort(); } while (false);
} } while (false)
;
1725 if (aStyleEffects->mOpacity < aThreshold ||
1726 aStyleDisplay->mWillChange.bits & StyleWillChangeBits::OPACITY) {
1727 return true;
1728 }
1729
1730 if (!mMayHaveOpacityAnimation) {
1731 return false;
1732 }
1733
1734 return HasAnimationOfOpacity(aEffectSet);
1735}
1736
1737bool nsIFrame::IsSVGTransformed(gfx::Matrix* aOwnTransforms,
1738 gfx::Matrix* aFromParentTransforms) const {
1739 return false;
1740}
1741
1742bool nsIFrame::Extend3DContext(const nsStyleDisplay* aStyleDisplay,
1743 const nsStyleEffects* aStyleEffects,
1744 mozilla::EffectSet* aEffectSetForOpacity) const {
1745 if (!HasAnyStateBits(NS_FRAME_MAY_BE_TRANSFORMED)) {
1746 return false;
1747 }
1748 const nsStyleDisplay* disp = StyleDisplayWithOptionalParam(aStyleDisplay);
1749 if (disp->mTransformStyle != StyleTransformStyle::Preserve3d ||
1750 !SupportsCSSTransforms()) {
1751 return false;
1752 }
1753
1754 // If we're all scroll frame, then all descendants will be clipped, so we
1755 // can't preserve 3d.
1756 if (IsScrollContainerFrame()) {
1757 return false;
1758 }
1759
1760 const nsStyleEffects* effects = StyleEffectsWithOptionalParam(aStyleEffects);
1761 if (HasOpacity(disp, effects, aEffectSetForOpacity)) {
1762 return false;
1763 }
1764
1765 return ShouldApplyOverflowClipping(disp).isEmpty() &&
1766 !GetClipPropClipRect(disp, effects, GetSize()) &&
1767 !SVGIntegrationUtils::UsingEffectsForFrame(this) &&
1768 !effects->HasMixBlendMode() &&
1769 disp->mIsolation != StyleIsolation::Isolate;
1770}
1771
1772bool nsIFrame::Combines3DTransformWithAncestors() const {
1773 // Check these first as they are faster then both calls below and are we are
1774 // likely to hit the early return (backface hidden is uncommon and
1775 // GetReferenceFrame is a hot caller of this which only calls this if
1776 // IsCSSTransformed is false).
1777 if (!IsCSSTransformed() && !BackfaceIsHidden()) {
1778 return false;
1779 }
1780 nsIFrame* parent = GetClosestFlattenedTreeAncestorPrimaryFrame();
1781 return parent && parent->Extend3DContext();
1782}
1783
1784bool nsIFrame::In3DContextAndBackfaceIsHidden() const {
1785 // While both tests fail most of the time, test BackfaceIsHidden()
1786 // first since it's likely to fail faster.
1787 return BackfaceIsHidden() && Combines3DTransformWithAncestors();
1788}
1789
1790bool nsIFrame::HasPerspective() const {
1791 if (!IsCSSTransformed()) {
1792 return false;
1793 }
1794 nsIFrame* parent = GetClosestFlattenedTreeAncestorPrimaryFrame();
1795 if (!parent) {
1796 return false;
1797 }
1798 return parent->ChildrenHavePerspective();
1799}
1800
1801nsRect nsIFrame::GetContentRectRelativeToSelf() const {
1802 nsMargin bp = GetUsedBorderAndPadding().ApplySkipSides(GetSkipSides());
1803 nsRect r(0, 0, mRect.width, mRect.height);
1804 r.Deflate(bp);
1805 return r;
1806}
1807
1808nsRect nsIFrame::GetContentRect() const {
1809 return GetContentRectRelativeToSelf() + GetPosition();
1810}
1811
1812bool nsIFrame::ComputeBorderRadii(const BorderRadius& aBorderRadius,
1813 const nsSize& aFrameSize,
1814 const nsSize& aBorderArea, Sides aSkipSides,
1815 nscoord aRadii[8]) {
1816 // Percentages are relative to whichever side they're on.
1817 for (const auto i : mozilla::AllPhysicalHalfCorners()) {
1818 const LengthPercentage& c = aBorderRadius.Get(i);
1819 nscoord axis = HalfCornerIsX(i) ? aFrameSize.width : aFrameSize.height;
1820 aRadii[i] = std::max(0, c.Resolve(axis));
1821 }
1822
1823 if (aSkipSides.Top()) {
1824 aRadii[eCornerTopLeftX] = 0;
1825 aRadii[eCornerTopLeftY] = 0;
1826 aRadii[eCornerTopRightX] = 0;
1827 aRadii[eCornerTopRightY] = 0;
1828 }
1829
1830 if (aSkipSides.Right()) {
1831 aRadii[eCornerTopRightX] = 0;
1832 aRadii[eCornerTopRightY] = 0;
1833 aRadii[eCornerBottomRightX] = 0;
1834 aRadii[eCornerBottomRightY] = 0;
1835 }
1836
1837 if (aSkipSides.Bottom()) {
1838 aRadii[eCornerBottomRightX] = 0;
1839 aRadii[eCornerBottomRightY] = 0;
1840 aRadii[eCornerBottomLeftX] = 0;
1841 aRadii[eCornerBottomLeftY] = 0;
1842 }
1843
1844 if (aSkipSides.Left()) {
1845 aRadii[eCornerBottomLeftX] = 0;
1846 aRadii[eCornerBottomLeftY] = 0;
1847 aRadii[eCornerTopLeftX] = 0;
1848 aRadii[eCornerTopLeftY] = 0;
1849 }
1850
1851 // css3-background specifies this algorithm for reducing
1852 // corner radii when they are too big.
1853 bool haveRadius = false;
1854 double ratio = 1.0f;
1855 for (const auto side : mozilla::AllPhysicalSides()) {
1856 uint32_t hc1 = SideToHalfCorner(side, false, true);
1857 uint32_t hc2 = SideToHalfCorner(side, true, true);
1858 nscoord length =
1859 SideIsVertical(side) ? aBorderArea.height : aBorderArea.width;
1860 nscoord sum = aRadii[hc1] + aRadii[hc2];
1861 if (sum) {
1862 haveRadius = true;
1863 // avoid floating point division in the normal case
1864 if (length < sum) {
1865 ratio = std::min(ratio, double(length) / sum);
1866 }
1867 }
1868 }
1869 if (ratio < 1.0) {
1870 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1871 aRadii[corner] *= ratio;
1872 }
1873 }
1874
1875 return haveRadius;
1876}
1877
1878void nsIFrame::AdjustBorderRadii(nscoord aRadii[8], const nsMargin& aOffsets) {
1879 auto AdjustOffset = [](const uint32_t aRadius, const nscoord aOffset) {
1880 // Implement the cubic formula to adjust offset when aOffset > 0 and
1881 // aRadius / aOffset < 1.
1882 // https://drafts.csswg.org/css-shapes/#valdef-shape-box-margin-box
1883 if (aOffset > 0) {
1884 const double ratio = aRadius / double(aOffset);
1885 if (ratio < 1.0) {
1886 return nscoord(aOffset * (1.0 + std::pow(ratio - 1, 3)));
1887 }
1888 }
1889 return aOffset;
1890 };
1891
1892 for (const auto side : mozilla::AllPhysicalSides()) {
1893 const nscoord offset = aOffsets.Side(side);
1894 const uint32_t hc1 = SideToHalfCorner(side, false, false);
1895 const uint32_t hc2 = SideToHalfCorner(side, true, false);
1896 if (aRadii[hc1] > 0) {
1897 const nscoord offset1 = AdjustOffset(aRadii[hc1], offset);
1898 aRadii[hc1] = std::max(0, aRadii[hc1] + offset1);
1899 }
1900 if (aRadii[hc2] > 0) {
1901 const nscoord offset2 = AdjustOffset(aRadii[hc2], offset);
1902 aRadii[hc2] = std::max(0, aRadii[hc2] + offset2);
1903 }
1904 }
1905}
1906
1907static inline bool RadiiAreDefinitelyZero(const BorderRadius& aBorderRadius) {
1908 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1909 if (!aBorderRadius.Get(corner).IsDefinitelyZero()) {
1910 return false;
1911 }
1912 }
1913 return true;
1914}
1915
1916/* virtual */
1917bool nsIFrame::GetBorderRadii(const nsSize& aFrameSize,
1918 const nsSize& aBorderArea, Sides aSkipSides,
1919 nscoord aRadii[8]) const {
1920 if (!mMayHaveRoundedCorners) {
1921 memset(aRadii, 0, sizeof(nscoord) * 8);
1922 return false;
1923 }
1924
1925 if (IsThemed()) {
1926 // When we're themed, the native theme code draws the border and
1927 // background, and therefore it doesn't make sense to tell other
1928 // code that's interested in border-radius that we have any radii.
1929 //
1930 // In an ideal world, we might have a way for the them to tell us an
1931 // border radius, but since we don't, we're better off assuming
1932 // zero.
1933 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1934 aRadii[corner] = 0;
1935 }
1936 return false;
1937 }
1938
1939 const auto& radii = StyleBorder()->mBorderRadius;
1940 const bool hasRadii =
1941 ComputeBorderRadii(radii, aFrameSize, aBorderArea, aSkipSides, aRadii);
1942 if (!hasRadii) {
1943 // TODO(emilio): Maybe we can just remove this bit and do the
1944 // IsDefinitelyZero check unconditionally. That should still avoid most of
1945 // the work, though maybe not the cache miss of going through the style and
1946 // the border struct.
1947 const_cast<nsIFrame*>(this)->mMayHaveRoundedCorners =
1948 !RadiiAreDefinitelyZero(radii);
1949 }
1950 return hasRadii;
1951}
1952
1953bool nsIFrame::GetBorderRadii(nscoord aRadii[8]) const {
1954 nsSize sz = GetSize();
1955 return GetBorderRadii(sz, sz, GetSkipSides(), aRadii);
1956}
1957
1958bool nsIFrame::GetMarginBoxBorderRadii(nscoord aRadii[8]) const {
1959 return GetBoxBorderRadii(aRadii, GetUsedMargin());
1960}
1961
1962bool nsIFrame::GetPaddingBoxBorderRadii(nscoord aRadii[8]) const {
1963 return GetBoxBorderRadii(aRadii, -GetUsedBorder());
1964}
1965
1966bool nsIFrame::GetContentBoxBorderRadii(nscoord aRadii[8]) const {
1967 return GetBoxBorderRadii(aRadii, -GetUsedBorderAndPadding());
1968}
1969
1970bool nsIFrame::GetBoxBorderRadii(nscoord aRadii[8],
1971 const nsMargin& aOffsets) const {
1972 if (!GetBorderRadii(aRadii)) {
1973 return false;
1974 }
1975 AdjustBorderRadii(aRadii, aOffsets);
1976 for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
1977 if (aRadii[corner]) {
1978 return true;
1979 }
1980 }
1981 return false;
1982}
1983
1984bool nsIFrame::GetShapeBoxBorderRadii(nscoord aRadii[8]) const {
1985 using Tag = StyleShapeOutside::Tag;
1986 auto& shapeOutside = StyleDisplay()->mShapeOutside;
1987 auto box = StyleShapeBox::MarginBox;
1988 switch (shapeOutside.tag) {
1989 case Tag::Image:
1990 case Tag::None:
1991 return false;
1992 case Tag::Box:
1993 box = shapeOutside.AsBox();
1994 break;
1995 case Tag::Shape:
1996 box = shapeOutside.AsShape()._1;
1997 break;
1998 }
1999
2000 switch (box) {
2001 case StyleShapeBox::ContentBox:
2002 return GetContentBoxBorderRadii(aRadii);
2003 case StyleShapeBox::PaddingBox:
2004 return GetPaddingBoxBorderRadii(aRadii);
2005 case StyleShapeBox::BorderBox:
2006 return GetBorderRadii(aRadii);
2007 case StyleShapeBox::MarginBox:
2008 return GetMarginBoxBorderRadii(aRadii);
2009 default:
2010 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"
, 2010); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Unexpected box value" ")"); do {
*((volatile int*)__null) = 2010; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
2011 return false;
2012 }
2013}
2014
2015nscoord nsIFrame::OneEmInAppUnits() const {
2016 return StyleFont()
2017 ->mFont.size.ScaledBy(nsLayoutUtils::FontSizeInflationFor(this))
2018 .ToAppUnits();
2019}
2020
2021ComputedStyle* nsIFrame::GetAdditionalComputedStyle(int32_t aIndex) const {
2022 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"
, 2022); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aIndex >= 0"
") (" "invalid index number" ")"); do { *((volatile int*)__null
) = 2022; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
2023 return nullptr;
2024}
2025
2026void nsIFrame::SetAdditionalComputedStyle(int32_t aIndex,
2027 ComputedStyle* aComputedStyle) {
2028 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"
, 2028); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aIndex >= 0"
") (" "invalid index number" ")"); do { *((volatile int*)__null
) = 2028; __attribute__((nomerge)) ::abort(); } while (false)
; } } while (false)
;
2029}
2030
2031nscoord nsIFrame::SynthesizeFallbackBaseline(
2032 WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
2033 const auto margin = GetLogicalUsedMargin(aWM);
2034 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"
, 2034); MOZ_PretendNoReturn(); } } while (0)
;
2035 if (aWM.IsCentralBaseline()) {
2036 return (BSize(aWM) + GetLogicalUsedMargin(aWM).BEnd(aWM)) / 2;
2037 }
2038 // Baseline for inverted line content is the top (block-start) margin edge,
2039 // as the frame is in effect "flipped" for alignment purposes.
2040 if (aWM.IsLineInverted()) {
2041 const auto marginStart = margin.BStart(aWM);
2042 return aBaselineGroup == BaselineSharingGroup::First
2043 ? -marginStart
2044 : BSize(aWM) + marginStart;
2045 }
2046 // Otherwise, the bottom margin edge, per CSS2.1's definition of the
2047 // 'baseline' value of 'vertical-align'.
2048 const auto marginEnd = margin.BEnd(aWM);
2049 return aBaselineGroup == BaselineSharingGroup::First ? BSize(aWM) + marginEnd
2050 : -marginEnd;
2051}
2052
2053nscoord nsIFrame::GetLogicalBaseline(WritingMode aWM) const {
2054 return GetLogicalBaseline(aWM, GetDefaultBaselineSharingGroup(),
2055 BaselineExportContext::LineLayout);
2056}
2057
2058nscoord nsIFrame::GetLogicalBaseline(
2059 WritingMode aWM, BaselineSharingGroup aBaselineGroup,
2060 BaselineExportContext aExportContext) const {
2061 const auto result =
2062 GetNaturalBaselineBOffset(aWM, aBaselineGroup, aExportContext)
2063 .valueOrFrom([this, aWM, aBaselineGroup]() {
2064 return SynthesizeFallbackBaseline(aWM, aBaselineGroup);
2065 });
2066 if (aBaselineGroup == BaselineSharingGroup::Last) {
2067 return BSize(aWM) - result;
2068 }
2069 return result;
2070}
2071
2072const nsFrameList& nsIFrame::GetChildList(ChildListID aListID) const {
2073 if (IsAbsoluteContainer() && aListID == GetAbsoluteListID()) {
2074 return GetAbsoluteContainingBlock()->GetChildList();
2075 } else {
2076 return nsFrameList::EmptyList();
2077 }
2078}
2079
2080void nsIFrame::GetChildLists(nsTArray<ChildList>* aLists) const {
2081 if (IsAbsoluteContainer()) {
2082 const nsFrameList& absoluteList =
2083 GetAbsoluteContainingBlock()->GetChildList();
2084 absoluteList.AppendIfNonempty(aLists, GetAbsoluteListID());
2085 }
2086}
2087
2088AutoTArray<nsIFrame::ChildList, 4> nsIFrame::CrossDocChildLists() {
2089 AutoTArray<ChildList, 4> childLists;
2090 nsSubDocumentFrame* subdocumentFrame = do_QueryFrame(this);
2091 if (subdocumentFrame) {
2092 // Descend into the subdocument
2093 nsIFrame* root = subdocumentFrame->GetSubdocumentRootFrame();
2094 if (root) {
2095 childLists.EmplaceBack(
2096 nsFrameList(root, nsLayoutUtils::GetLastSibling(root)),
2097 FrameChildListID::Principal);
2098 }
2099 }
2100
2101 GetChildLists(&childLists);
2102 return childLists;
2103}
2104
2105nsIFrame::CaretBlockAxisMetrics nsIFrame::GetCaretBlockAxisMetrics(
2106 mozilla::WritingMode aWM, const nsFontMetrics& aFM) const {
2107 // Note(dshin): Ultimately, this does something highly similar (But still
2108 // different) to `nsLayoutUtils::GetFirstLinePosition`.
2109 const auto baseline = GetCaretBaseline();
2110 nscoord ascent = 0, descent = 0;
2111 ascent = aFM.MaxAscent();
2112 descent = aFM.MaxDescent();
2113 const nscoord height = ascent + descent;
2114 if (aWM.IsVertical() && aWM.IsLineInverted()) {
2115 return CaretBlockAxisMetrics{.mOffset = baseline - descent,
2116 .mExtent = height};
2117 }
2118 return CaretBlockAxisMetrics{.mOffset = baseline - ascent, .mExtent = height};
2119}
2120
2121const nsAtom* nsIFrame::ComputePageValue(const nsAtom* aAutoValue) const {
2122 const nsAtom* value = aAutoValue ? aAutoValue : nsGkAtoms::_empty;
2123 const nsIFrame* frame = this;
2124 // Find what CSS page name value this frame's subtree has, if any.
2125 // Starting with this frame, check if a page name other than auto is present,
2126 // and record it if so. Then, if the current frame is a container frame, find
2127 // the first non-placeholder child and repeat.
2128 // This will find the most deeply nested first in-flow child of this frame's
2129 // subtree, and return its page name (with auto resolved if applicable, and
2130 // subtrees with no page-names returning the empty atom rather than null).
2131 do {
2132 if (const nsAtom* maybePageName = frame->GetStylePageName()) {
2133 value = maybePageName;
2134 }
2135 // Get the next frame to read from.
2136 const nsIFrame* firstNonPlaceholderFrame = nullptr;
2137 // If this is a container frame, inspect its in-flow children.
2138 if (const nsContainerFrame* containerFrame = do_QueryFrame(frame)) {
2139 for (const nsIFrame* childFrame : containerFrame->PrincipalChildList()) {
2140 if (!childFrame->IsPlaceholderFrame()) {
2141 firstNonPlaceholderFrame = childFrame;
2142 break;
2143 }
2144 }
2145 }
2146 frame = firstNonPlaceholderFrame;
2147 } while (frame);
2148 return value;
2149}
2150
2151Visibility nsIFrame::GetVisibility() const {
2152 if (!HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)) {
2153 return Visibility::Untracked;
2154 }
2155
2156 bool isSet = false;
2157 uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet);
2158
2159 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"
, 2161); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2161; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2160 "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"
, 2161); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2161; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2161 "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"
, 2161); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2161; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2162
2163 return visibleCount > 0 ? Visibility::ApproximatelyVisible
2164 : Visibility::ApproximatelyNonVisible;
2165}
2166
2167void nsIFrame::UpdateVisibilitySynchronously() {
2168 mozilla::PresShell* presShell = PresShell();
2169 if (!presShell) {
2170 return;
2171 }
2172
2173 if (presShell->AssumeAllFramesVisible()) {
2174 presShell->EnsureFrameInApproximatelyVisibleList(this);
2175 return;
2176 }
2177
2178 bool visible = StyleVisibility()->IsVisible();
2179 nsIFrame* f = GetParent();
2180 nsRect rect = GetRectRelativeToSelf();
2181 nsIFrame* rectFrame = this;
2182 while (f && visible) {
2183 if (ScrollContainerFrame* sf = do_QueryFrame(f)) {
2184 nsRect transformedRect =
2185 nsLayoutUtils::TransformFrameRectToAncestor(rectFrame, rect, f);
2186 if (!sf->IsRectNearlyVisible(transformedRect)) {
2187 visible = false;
2188 break;
2189 }
2190
2191 // In this code we're trying to synchronously update *approximate*
2192 // visibility. (In the future we may update precise visibility here as
2193 // well, which is why the method name does not contain 'approximate'.) The
2194 // IsRectNearlyVisible() check above tells us that the rect we're checking
2195 // is approximately visible within the scrollframe, but we still need to
2196 // ensure that, even if it was scrolled into view, it'd be visible when we
2197 // consider the rest of the document. To do that, we move transformedRect
2198 // to be contained in the scrollport as best we can (it might not fit) to
2199 // pretend that it was scrolled into view.
2200 rect = transformedRect.MoveInsideAndClamp(sf->GetScrollPortRect());
2201 rectFrame = f;
2202 }
2203 nsIFrame* parent = f->GetParent();
2204 if (!parent) {
2205 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(f);
2206 if (parent && parent->PresContext()->IsChrome()) {
2207 break;
2208 }
2209 }
2210 f = parent;
2211 }
2212
2213 if (visible) {
2214 presShell->EnsureFrameInApproximatelyVisibleList(this);
2215 } else {
2216 presShell->RemoveFrameFromApproximatelyVisibleList(this);
2217 }
2218}
2219
2220void nsIFrame::EnableVisibilityTracking() {
2221 if (HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)) {
2222 return; // Nothing to do.
2223 }
2224
2225 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"
, 2227); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasProperty(VisibilityStateProperty())"
") (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")"); do { *((volatile int*)__null) = 2227; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2226 "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"
, 2227); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasProperty(VisibilityStateProperty())"
") (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")"); do { *((volatile int*)__null) = 2227; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2227 "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"
, 2227); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasProperty(VisibilityStateProperty())"
") (" "Shouldn't have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is not set"
")"); do { *((volatile int*)__null) = 2227; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2228
2229 // Add the state bit so we know to track visibility for this frame, and
2230 // initialize the frame property.
2231 AddStateBits(NS_FRAME_VISIBILITY_IS_TRACKED);
2232 SetProperty(VisibilityStateProperty(), 0);
2233
2234 mozilla::PresShell* presShell = PresShell();
2235 if (!presShell) {
2236 return;
2237 }
2238
2239 // Schedule a visibility update. This method will virtually always be called
2240 // when layout has changed anyway, so it's very unlikely that any additional
2241 // visibility updates will be triggered by this, but this way we guarantee
2242 // that if this frame is currently visible we'll eventually find out.
2243 presShell->ScheduleApproximateFrameVisibilityUpdateSoon();
2244}
2245
2246void nsIFrame::DisableVisibilityTracking() {
2247 if (!HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)) {
2248 return; // Nothing to do.
2249 }
2250
2251 bool isSet = false;
2252 uint32_t visibleCount = TakeProperty(VisibilityStateProperty(), &isSet);
2253
2254 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"
, 2256); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2256; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2255 "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"
, 2256); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2256; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2256 "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"
, 2256); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2256; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2257
2258 RemoveStateBits(NS_FRAME_VISIBILITY_IS_TRACKED);
2259
2260 if (visibleCount == 0) {
2261 return; // We were nonvisible.
2262 }
2263
2264 // We were visible, so send an OnVisibilityChange() notification.
2265 OnVisibilityChange(Visibility::ApproximatelyNonVisible);
2266}
2267
2268void nsIFrame::DecApproximateVisibleCount(
2269 const Maybe<OnNonvisible>& aNonvisibleAction
2270 /* = Nothing() */) {
2271 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"
, 2271); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)"
")"); do { *((volatile int*)__null) = 2271; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2272
2273 bool isSet = false;
2274 uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet);
2275
2276 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"
, 2278); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2278; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2277 "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"
, 2278); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2278; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2278 "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"
, 2278); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2278; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2279 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"
, 2281); AnnotateMozCrashReason("MOZ_ASSERT" "(" "visibleCount > 0"
") (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")"); do { *((volatile int*)__null) = 2281; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2280 "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"
, 2281); AnnotateMozCrashReason("MOZ_ASSERT" "(" "visibleCount > 0"
") (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")"); do { *((volatile int*)__null) = 2281; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2281 "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"
, 2281); AnnotateMozCrashReason("MOZ_ASSERT" "(" "visibleCount > 0"
") (" "Frame is already nonvisible and we're " "decrementing its visible count?"
")"); do { *((volatile int*)__null) = 2281; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2282
2283 visibleCount--;
2284 SetProperty(VisibilityStateProperty(), visibleCount);
2285 if (visibleCount > 0) {
2286 return;
2287 }
2288
2289 // We just became nonvisible, so send an OnVisibilityChange() notification.
2290 OnVisibilityChange(Visibility::ApproximatelyNonVisible, aNonvisibleAction);
2291}
2292
2293void nsIFrame::IncApproximateVisibleCount() {
2294 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"
, 2294); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_VISIBILITY_IS_TRACKED)"
")"); do { *((volatile int*)__null) = 2294; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2295
2296 bool isSet = false;
2297 uint32_t visibleCount = GetProperty(VisibilityStateProperty(), &isSet);
2298
2299 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"
, 2301); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2301; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2300 "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"
, 2301); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2301; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2301 "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"
, 2301); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isSet" ") ("
"Should have a VisibilityStateProperty value " "if NS_FRAME_VISIBILITY_IS_TRACKED is set"
")"); do { *((volatile int*)__null) = 2301; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2302
2303 visibleCount++;
2304 SetProperty(VisibilityStateProperty(), visibleCount);
2305 if (visibleCount > 1) {
2306 return;
2307 }
2308
2309 // We just became visible, so send an OnVisibilityChange() notification.
2310 OnVisibilityChange(Visibility::ApproximatelyVisible);
2311}
2312
2313void nsIFrame::OnVisibilityChange(Visibility aNewVisibility,
2314 const Maybe<OnNonvisible>& aNonvisibleAction
2315 /* = Nothing() */) {
2316 // XXX(seth): In bug 1218990 we'll implement visibility tracking for CSS
2317 // images here.
2318}
2319
2320static nsIFrame* GetActiveSelectionFrame(nsPresContext* aPresContext,
2321 nsIFrame* aFrame) {
2322 nsIContent* capturingContent = PresShell::GetCapturingContent();
2323 if (capturingContent) {
2324 nsIFrame* activeFrame = aPresContext->GetPrimaryFrameFor(capturingContent);
2325 return activeFrame ? activeFrame : aFrame;
2326 }
2327
2328 return aFrame;
2329}
2330
2331int16_t nsIFrame::DetermineDisplaySelection() {
2332 int16_t selType = nsISelectionController::SELECTION_OFF;
2333
2334 nsCOMPtr<nsISelectionController> selCon;
2335 nsresult result =
2336 GetSelectionController(PresContext(), getter_AddRefs(selCon));
2337 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) && selCon) {
2338 result = selCon->GetDisplaySelection(&selType);
2339 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) &&
2340 (selType != nsISelectionController::SELECTION_OFF)) {
2341 // Check whether style allows selection.
2342 if (!IsSelectable(nullptr)) {
2343 selType = nsISelectionController::SELECTION_OFF;
2344 }
2345 }
2346 }
2347 return selType;
2348}
2349
2350static Element* FindElementAncestorForMozSelection(nsIContent* aContent) {
2351 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"
, 2351); return nullptr; } } while (false)
;
2352 while (aContent && aContent->IsInNativeAnonymousSubtree()) {
2353 aContent = aContent->GetClosestNativeAnonymousSubtreeRootParentOrHost();
2354 }
2355 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"
, 2355); MOZ_PretendNoReturn(); } } while (0)
;
2356 return aContent ? aContent->GetAsElementOrParentElement() : nullptr;
2357}
2358
2359already_AddRefed<ComputedStyle> nsIFrame::ComputeSelectionStyle(
2360 int16_t aSelectionStatus) const {
2361 // Just bail out if not a selection-status that ::selection applies to.
2362 if (aSelectionStatus != nsISelectionController::SELECTION_ON &&
2363 aSelectionStatus != nsISelectionController::SELECTION_DISABLED) {
2364 return nullptr;
2365 }
2366 Element* element = FindElementAncestorForMozSelection(GetContent());
2367 if (!element) {
2368 return nullptr;
2369 }
2370 RefPtr<ComputedStyle> pseudoStyle =
2371 PresContext()->StyleSet()->ProbePseudoElementStyle(
2372 *element, PseudoStyleType::selection, nullptr, Style());
2373 if (!pseudoStyle) {
2374 return nullptr;
2375 }
2376 // When in high-contrast mode, the style system ends up ignoring the color
2377 // declarations, which means that the ::selection style becomes the inherited
2378 // color, and default background. That's no good.
2379 // When force-color-adjust is set to none allow using the color styles,
2380 // as they will not be replaced.
2381 if (PresContext()->ForcingColors() &&
2382 pseudoStyle->StyleText()->mForcedColorAdjust !=
2383 StyleForcedColorAdjust::None) {
2384 return nullptr;
2385 }
2386 return do_AddRef(pseudoStyle);
2387}
2388
2389already_AddRefed<ComputedStyle> nsIFrame::ComputeHighlightSelectionStyle(
2390 nsAtom* aHighlightName) {
2391 Element* element = FindElementAncestorForMozSelection(GetContent());
2392 if (!element) {
2393 return nullptr;
2394 }
2395 return PresContext()->StyleSet()->ProbePseudoElementStyle(
2396 *element, PseudoStyleType::highlight, aHighlightName, Style());
2397}
2398
2399already_AddRefed<ComputedStyle> nsIFrame::ComputeTargetTextStyle() const {
2400 const Element* element = FindElementAncestorForMozSelection(GetContent());
2401 if (!element) {
2402 return nullptr;
2403 }
2404 return PresContext()->StyleSet()->ProbePseudoElementStyle(
2405 *element, PseudoStyleType::targetText, nullptr, Style());
2406}
2407
2408bool nsIFrame::CanBeDynamicReflowRoot() const {
2409 const auto& display = *StyleDisplay();
2410 if (IsLineParticipant() || display.mDisplay.IsRuby() ||
2411 display.IsInnerTableStyle() ||
2412 display.DisplayInside() == StyleDisplayInside::Table) {
2413 // We have a display type where 'width' and 'height' don't actually set the
2414 // width or height (i.e., the size depends on content).
2415 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"
, 2416); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT)"
") (" "should not have dynamic reflow root bit" ")"); do { *
((volatile int*)__null) = 2416; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
2416 "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"
, 2416); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_DYNAMIC_REFLOW_ROOT)"
") (" "should not have dynamic reflow root bit" ")"); do { *
((volatile int*)__null) = 2416; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
2417 return false;
2418 }
2419
2420 // In general, frames that have contain:layout+size can be reflow roots.
2421 // (One exception: table-wrapper frames don't work well as reflow roots,
2422 // because their inner-table ReflowInput init path tries to reuse & deref
2423 // the wrapper's containing block's reflow input, which may be null if we
2424 // initiate reflow from the table-wrapper itself.)
2425 //
2426 // Changes to `contain` force frame reconstructions, so we used to use
2427 // NS_FRAME_REFLOW_ROOT, this bit could be set for the whole lifetime of
2428 // this frame. But after the support of `content-visibility: auto` which
2429 // is with contain layout + size when it's not relevant to user, and only
2430 // with contain layout when it is relevant. The frame does not reconstruct
2431 // when the relevancy changes. So we use NS_FRAME_DYNAMIC_REFLOW_ROOT instead.
2432 //
2433 // We place it above the pref check on purpose, to make sure it works for
2434 // containment even with the pref disabled.
2435 if (display.IsContainLayout() && GetContainSizeAxes().IsBoth()) {
2436 return true;
2437 }
2438
2439 if (!StaticPrefs::layout_dynamic_reflow_roots_enabled()) {
2440 return false;
2441 }
2442
2443 // We can't serve as a dynamic reflow root if our used 'width' and 'height'
2444 // might be influenced by content.
2445 //
2446 // FIXME: For display:block, we should probably optimize inline-size: auto.
2447 // FIXME: Other flex and grid cases?
2448 const auto& pos = *StylePosition();
2449 const auto& width = pos.mWidth;
2450 const auto& height = pos.mHeight;
2451 if (!width.IsLengthPercentage() || width.HasPercent() ||
2452 !height.IsLengthPercentage() || height.HasPercent() ||
2453 IsIntrinsicKeyword(pos.mMinWidth) || IsIntrinsicKeyword(pos.mMaxWidth) ||
2454 IsIntrinsicKeyword(pos.mMinHeight) ||
2455 IsIntrinsicKeyword(pos.mMaxHeight) ||
2456 ((pos.mMinWidth.IsAuto() || pos.mMinHeight.IsAuto()) &&
2457 IsFlexOrGridItem())) {
2458 return false;
2459 }
2460
2461 // If our flex-basis is 'auto', it'll defer to 'width' (or 'height') which
2462 // we've already checked. Otherwise, it preempts them, so we need to
2463 // perform the same "could-this-value-be-influenced-by-content" checks that
2464 // we performed for 'width' and 'height' above.
2465 if (IsFlexItem()) {
2466 const auto& flexBasis = pos.mFlexBasis;
2467 if (!flexBasis.IsAuto()) {
2468 if (!flexBasis.IsSize() || !flexBasis.AsSize().IsLengthPercentage() ||
2469 flexBasis.AsSize().HasPercent()) {
2470 return false;
2471 }
2472 }
2473 }
2474
2475 if (!IsFixedPosContainingBlock()) {
2476 // We can't treat this frame as a reflow root, since dynamic changes
2477 // to absolutely-positioned frames inside of it require that we
2478 // reflow the placeholder before we reflow the absolutely positioned
2479 // frame.
2480 // FIXME: Alternatively, we could sort the reflow roots in
2481 // PresShell::ProcessReflowCommands by depth in the tree, from
2482 // deepest to least deep. However, for performance (FIXME) we
2483 // should really be sorting them in the opposite order!
2484 return false;
2485 }
2486
2487 // If we participate in a container's block reflow context, or margins
2488 // can collapse through us, we can't be a dynamic reflow root.
2489 if (IsBlockFrameOrSubclass() && !HasAnyStateBits(NS_BLOCK_BFC)) {
2490 return false;
2491 }
2492
2493 // Subgrids are never reflow roots, but 'contain:layout/paint' prevents
2494 // creating a subgrid in the first place.
2495 if (pos.mGridTemplateColumns.IsSubgrid() ||
2496 pos.mGridTemplateRows.IsSubgrid()) {
2497 // NOTE: we could check that 'display' of our parent's primary frame is
2498 // '[inline-]grid' here but that's probably not worth it in practice.
2499 if (!display.IsContainLayout() && !display.IsContainPaint()) {
2500 return false;
2501 }
2502 }
2503
2504 // If we are split, we can't be a dynamic reflow root. Our reflow status may
2505 // change after reflow, and our parent is responsible to create or delete our
2506 // next-in-flow.
2507 if (GetPrevContinuation() || GetNextContinuation()) {
2508 return false;
2509 }
2510
2511 return true;
2512}
2513
2514/********************************************************
2515 * Refreshes each content's frame
2516 *********************************************************/
2517
2518void nsIFrame::DisplayOutlineUnconditional(nsDisplayListBuilder* aBuilder,
2519 const nsDisplayListSet& aLists) {
2520 // Per https://drafts.csswg.org/css-tables-3/#global-style-overrides:
2521 // "All css properties of table-column and table-column-group boxes are
2522 // ignored, except when explicitly specified by this specification."
2523 // CSS outlines fall into this category, so we skip them on these boxes.
2524 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"
, 2524); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsTableColGroupFrame() && !IsTableColFrame()"
")"); do { *((volatile int*)__null) = 2524; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2525 const auto& outline = *StyleOutline();
2526
2527 if (!outline.ShouldPaintOutline()) {
2528 return;
2529 }
2530
2531 // Outlines are painted by the table wrapper frame.
2532 if (IsTableFrame()) {
2533 return;
2534 }
2535
2536 if (HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT) &&
2537 ScrollableOverflowRect().IsEmpty()) {
2538 // Skip parts of IB-splits with an empty overflow rect, see bug 434301.
2539 // We may still want to fix some of the overflow area calculations over in
2540 // that bug.
2541 return;
2542 }
2543
2544 // We don't display outline-style: auto on themed frames that have their own
2545 // focus indicators.
2546 if (outline.mOutlineStyle.IsAuto()) {
2547 auto* disp = StyleDisplay();
2548 if (IsThemed(disp) && PresContext()->Theme()->ThemeDrawsFocusForWidget(
2549 this, disp->EffectiveAppearance())) {
2550 return;
2551 }
2552 }
2553
2554 aLists.Outlines()->AppendNewToTop<nsDisplayOutline>(aBuilder, this);
2555}
2556
2557void nsIFrame::DisplayOutline(nsDisplayListBuilder* aBuilder,
2558 const nsDisplayListSet& aLists) {
2559 if (!IsVisibleForPainting()) return;
2560
2561 DisplayOutlineUnconditional(aBuilder, aLists);
2562}
2563
2564void nsIFrame::DisplayInsetBoxShadowUnconditional(
2565 nsDisplayListBuilder* aBuilder, nsDisplayList* aList) {
2566 // XXXbz should box-shadow for rows/rowgroups/columns/colgroups get painted
2567 // just because we're visible? Or should it depend on the cell visibility
2568 // when we're not the whole table?
2569 const auto* effects = StyleEffects();
2570 if (effects->HasBoxShadowWithInset(true)) {
2571 aList->AppendNewToTop<nsDisplayBoxShadowInner>(aBuilder, this);
2572 }
2573}
2574
2575void nsIFrame::DisplayInsetBoxShadow(nsDisplayListBuilder* aBuilder,
2576 nsDisplayList* aList) {
2577 if (!IsVisibleForPainting()) return;
2578
2579 DisplayInsetBoxShadowUnconditional(aBuilder, aList);
2580}
2581
2582void nsIFrame::DisplayOutsetBoxShadowUnconditional(
2583 nsDisplayListBuilder* aBuilder, nsDisplayList* aList) {
2584 // XXXbz should box-shadow for rows/rowgroups/columns/colgroups get painted
2585 // just because we're visible? Or should it depend on the cell visibility
2586 // when we're not the whole table?
2587 const auto* effects = StyleEffects();
2588 if (effects->HasBoxShadowWithInset(false)) {
2589 aList->AppendNewToTop<nsDisplayBoxShadowOuter>(aBuilder, this);
2590 }
2591}
2592
2593void nsIFrame::DisplayOutsetBoxShadow(nsDisplayListBuilder* aBuilder,
2594 nsDisplayList* aList) {
2595 if (!IsVisibleForPainting()) return;
2596
2597 DisplayOutsetBoxShadowUnconditional(aBuilder, aList);
2598}
2599
2600void nsIFrame::DisplayCaret(nsDisplayListBuilder* aBuilder,
2601 nsDisplayList* aList) {
2602 if (!IsVisibleForPainting()) return;
2603
2604 aList->AppendNewToTop<nsDisplayCaret>(aBuilder, this);
2605}
2606
2607nscolor nsIFrame::GetCaretColorAt(int32_t aOffset) {
2608 return nsLayoutUtils::GetColor(this, &nsStyleUI::mCaretColor);
2609}
2610
2611auto nsIFrame::ComputeShouldPaintBackground() const -> ShouldPaintBackground {
2612 nsPresContext* pc = PresContext();
2613 ShouldPaintBackground settings{pc->GetBackgroundColorDraw(),
2614 pc->GetBackgroundImageDraw()};
2615 if (settings.mColor && settings.mImage) {
2616 return settings;
2617 }
2618
2619 if (StyleVisibility()->mPrintColorAdjust == StylePrintColorAdjust::Exact) {
2620 return {true, true};
2621 }
2622
2623 return settings;
2624}
2625
2626bool nsIFrame::DisplayBackgroundUnconditional(nsDisplayListBuilder* aBuilder,
2627 const nsDisplayListSet& aLists) {
2628 if (aBuilder->IsForEventDelivery() && !aBuilder->HitTestIsForVisibility()) {
2629 // For hit-testing, we generally just need a light-weight data structure
2630 // like nsDisplayEventReceiver. But if the hit-testing is for visibility,
2631 // then we need to know the opaque region in order to determine whether to
2632 // stop or not.
2633 aLists.BorderBackground()->AppendNewToTop<nsDisplayEventReceiver>(aBuilder,
2634 this);
2635 return false;
2636 }
2637
2638 const AppendedBackgroundType result =
2639 nsDisplayBackgroundImage::AppendBackgroundItemsToTop(
2640 aBuilder, this,
2641 GetRectRelativeToSelf() + aBuilder->ToReferenceFrame(this),
2642 aLists.BorderBackground());
2643
2644 if (result == AppendedBackgroundType::None) {
2645 aBuilder->BuildCompositorHitTestInfoIfNeeded(this,
2646 aLists.BorderBackground());
2647 }
2648
2649 return result == AppendedBackgroundType::ThemedBackground;
2650}
2651
2652void nsIFrame::DisplayBorderBackgroundOutline(nsDisplayListBuilder* aBuilder,
2653 const nsDisplayListSet& aLists) {
2654 // The visibility check belongs here since child elements have the
2655 // opportunity to override the visibility property and display even if
2656 // their parent is hidden.
2657 if (!IsVisibleForPainting()) {
2658 return;
2659 }
2660
2661 DisplayOutsetBoxShadowUnconditional(aBuilder, aLists.BorderBackground());
2662
2663 bool bgIsThemed = DisplayBackgroundUnconditional(aBuilder, aLists);
2664 DisplayInsetBoxShadowUnconditional(aBuilder, aLists.BorderBackground());
2665
2666 // If there's a themed background, we should not create a border item.
2667 // It won't be rendered.
2668 // Don't paint borders for tables here, since they paint them in a different
2669 // order.
2670 if (!bgIsThemed && StyleBorder()->HasBorder() && !IsTableFrame()) {
2671 aLists.BorderBackground()->AppendNewToTop<nsDisplayBorder>(aBuilder, this);
2672 }
2673
2674 DisplayOutlineUnconditional(aBuilder, aLists);
2675}
2676
2677inline static bool IsSVGContentWithCSSClip(const nsIFrame* aFrame) {
2678 // The CSS spec says that the 'clip' property only applies to absolutely
2679 // positioned elements, whereas the SVG spec says that it applies to SVG
2680 // elements regardless of the value of the 'position' property. Here we obey
2681 // the CSS spec for outer-<svg> (since that's what we generally do), but
2682 // obey the SVG spec for other SVG elements to which 'clip' applies.
2683 return aFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT) &&
2684 aFrame->GetContent()->IsAnyOfSVGElements(nsGkAtoms::svg,
2685 nsGkAtoms::foreignObject);
2686}
2687
2688Maybe<nsRect> nsIFrame::GetClipPropClipRect(const nsStyleDisplay* aDisp,
2689 const nsStyleEffects* aEffects,
2690 const nsSize& aSize) const {
2691 if (aEffects->mClip.IsAuto() ||
2692 !(aDisp->IsAbsolutelyPositioned(this) || IsSVGContentWithCSSClip(this))) {
2693 return Nothing();
2694 }
2695
2696 auto& clipRect = aEffects->mClip.AsRect();
2697 nsRect rect = clipRect.ToLayoutRect();
2698 if (MOZ_LIKELY(StyleBorder()->mBoxDecorationBreak ==(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Slice), 1))
2699 StyleBoxDecorationBreak::Slice)(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak ==
StyleBoxDecorationBreak::Slice), 1))
) {
2700 // The clip applies to the joined boxes so it's relative the first
2701 // continuation.
2702 nscoord y = 0;
2703 for (nsIFrame* f = GetPrevContinuation(); f; f = f->GetPrevContinuation()) {
2704 y += f->GetRect().height;
2705 }
2706 rect.MoveBy(nsPoint(0, -y));
2707 }
2708
2709 if (clipRect.right.IsAuto()) {
2710 rect.width = aSize.width - rect.x;
2711 }
2712 if (clipRect.bottom.IsAuto()) {
2713 rect.height = aSize.height - rect.y;
2714 }
2715 return Some(rect);
2716}
2717
2718/**
2719 * If the CSS 'overflow' property applies to this frame, and is not
2720 * handled by constructing a dedicated nsHTML/XULScrollFrame, set up clipping
2721 * for that overflow in aBuilder->ClipState() to clip all containing-block
2722 * descendants.
2723 */
2724static void ApplyOverflowClipping(
2725 nsDisplayListBuilder* aBuilder, const nsIFrame* aFrame,
2726 PhysicalAxes aClipAxes,
2727 DisplayListClipState::AutoClipMultiple& aClipState) {
2728 // Only 'clip' is handled here (and 'hidden' for table frames, and any
2729 // non-'visible' value for blocks in a paginated context).
2730 // We allow 'clip' to apply to any kind of frame. This is required by
2731 // comboboxes which make their display text (an inline frame) have clipping.
2732 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"
, 2732); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aClipAxes.isEmpty()"
")"); do { *((volatile int*)__null) = 2732; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2733 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"
, 2734); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay()) == aClipAxes"
")"); do { *((volatile int*)__null) = 2734; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2734 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"
, 2734); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->ShouldApplyOverflowClipping(aFrame->StyleDisplay()) == aClipAxes"
")"); do { *((volatile int*)__null) = 2734; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2735
2736 nsRect clipRect;
2737 bool haveRadii = false;
2738 nscoord radii[8];
2739 auto* disp = aFrame->StyleDisplay();
2740 // Only deflate the padding if we clip to the content-box in that axis.
2741 auto wm = aFrame->GetWritingMode();
2742 bool cbH = (wm.IsVertical() ? disp->mOverflowClipBoxBlock
2743 : disp->mOverflowClipBoxInline) ==
2744 StyleOverflowClipBox::ContentBox;
2745 bool cbV = (wm.IsVertical() ? disp->mOverflowClipBoxInline
2746 : disp->mOverflowClipBoxBlock) ==
2747 StyleOverflowClipBox::ContentBox;
2748
2749 nsMargin boxMargin = -aFrame->GetUsedPadding();
2750 if (!cbH) {
2751 boxMargin.left = boxMargin.right = nscoord(0);
2752 }
2753 if (!cbV) {
2754 boxMargin.top = boxMargin.bottom = nscoord(0);
2755 }
2756
2757 auto clipMargin = aFrame->OverflowClipMargin(aClipAxes);
2758
2759 boxMargin -= aFrame->GetUsedBorder();
2760 boxMargin += nsMargin(clipMargin.height, clipMargin.width, clipMargin.height,
2761 clipMargin.width);
2762 boxMargin.ApplySkipSides(aFrame->GetSkipSides());
2763
2764 nsRect rect(nsPoint(0, 0), aFrame->GetSize());
2765 rect.Inflate(boxMargin);
2766 if (MOZ_UNLIKELY(!aClipAxes.contains(PhysicalAxis::Horizontal))(__builtin_expect(!!(!aClipAxes.contains(PhysicalAxis::Horizontal
)), 0))
) {
2767 // NOTE(mats) We shouldn't be clipping at all in this dimension really,
2768 // but clipping in just one axis isn't supported by our GFX APIs so we
2769 // clip to our visual overflow rect instead.
2770 nsRect o = aFrame->InkOverflowRect();
2771 rect.x = o.x;
2772 rect.width = o.width;
2773 }
2774 if (MOZ_UNLIKELY(!aClipAxes.contains(PhysicalAxis::Vertical))(__builtin_expect(!!(!aClipAxes.contains(PhysicalAxis::Vertical
)), 0))
) {
2775 // See the note above.
2776 nsRect o = aFrame->InkOverflowRect();
2777 rect.y = o.y;
2778 rect.height = o.height;
2779 }
2780 clipRect = rect + aBuilder->ToReferenceFrame(aFrame);
2781 haveRadii = aFrame->GetBoxBorderRadii(radii, boxMargin);
2782 aClipState.ClipContainingBlockDescendantsExtra(clipRect,
2783 haveRadii ? radii : nullptr);
2784}
2785
2786nsSize nsIFrame::OverflowClipMargin(PhysicalAxes aClipAxes) const {
2787 nsSize result;
2788 if (aClipAxes.isEmpty()) {
2789 return result;
2790 }
2791 const auto& margin = StyleMargin()->mOverflowClipMargin;
2792 if (margin.IsZero()) {
2793 return result;
2794 }
2795 nscoord marginAu = margin.ToAppUnits();
2796 if (aClipAxes.contains(PhysicalAxis::Horizontal)) {
2797 result.width = marginAu;
2798 }
2799 if (aClipAxes.contains(PhysicalAxis::Vertical)) {
2800 result.height = marginAu;
2801 }
2802 return result;
2803}
2804
2805/**
2806 * Returns whether a display item that gets created with the builder's current
2807 * state will have a scrolled clip, i.e. a clip that is scrolled by a scroll
2808 * frame which does not move the item itself.
2809 */
2810static bool BuilderHasScrolledClip(nsDisplayListBuilder* aBuilder) {
2811 const DisplayItemClipChain* currentClip =
2812 aBuilder->ClipState().GetCurrentCombinedClipChain(aBuilder);
2813 if (!currentClip) {
2814 return false;
2815 }
2816
2817 const ActiveScrolledRoot* currentClipASR = currentClip->mASR;
2818 const ActiveScrolledRoot* currentASR = aBuilder->CurrentActiveScrolledRoot();
2819 return ActiveScrolledRoot::PickDescendant(currentClipASR, currentASR) !=
2820 currentASR;
2821}
2822
2823class AutoSaveRestoreContainsBlendMode {
2824 nsDisplayListBuilder& mBuilder;
2825 bool mSavedContainsBlendMode;
2826
2827 public:
2828 explicit AutoSaveRestoreContainsBlendMode(nsDisplayListBuilder& aBuilder)
2829 : mBuilder(aBuilder),
2830 mSavedContainsBlendMode(aBuilder.ContainsBlendMode()) {}
2831
2832 ~AutoSaveRestoreContainsBlendMode() {
2833 mBuilder.SetContainsBlendMode(mSavedContainsBlendMode);
2834 }
2835};
2836
2837static bool IsFrameOrAncestorApzAware(nsIFrame* aFrame) {
2838 nsIContent* node = aFrame->GetContent();
2839 if (!node) {
2840 return false;
2841 }
2842
2843 do {
2844 if (node->IsNodeApzAware()) {
2845 return true;
2846 }
2847 nsIContent* shadowRoot = node->GetShadowRoot();
2848 if (shadowRoot && shadowRoot->IsNodeApzAware()) {
2849 return true;
2850 }
2851
2852 // Even if the node owning aFrame doesn't have apz-aware event listeners
2853 // itself, its shadow root or display: contents ancestors (which have no
2854 // frames) might, so we need to account for them too.
2855 } while ((node = node->GetFlattenedTreeParent()) && node->IsElement() &&
2856 node->AsElement()->IsDisplayContents());
2857
2858 return false;
2859}
2860
2861static void CheckForApzAwareEventHandlers(nsDisplayListBuilder* aBuilder,
2862 nsIFrame* aFrame) {
2863 if (aBuilder->GetAncestorHasApzAwareEventHandler()) {
2864 return;
2865 }
2866
2867 if (IsFrameOrAncestorApzAware(aFrame)) {
2868 aBuilder->SetAncestorHasApzAwareEventHandler(true);
2869 }
2870}
2871
2872static void UpdateCurrentHitTestInfo(nsDisplayListBuilder* aBuilder,
2873 nsIFrame* aFrame) {
2874 if (!aBuilder->BuildCompositorHitTestInfo()) {
2875 // Compositor hit test info is not used.
2876 return;
2877 }
2878
2879 CheckForApzAwareEventHandlers(aBuilder, aFrame);
2880
2881 const CompositorHitTestInfo info = aFrame->GetCompositorHitTestInfo(aBuilder);
2882 aBuilder->SetCompositorHitTestInfo(info);
2883}
2884
2885/**
2886 * True if aDescendant participates the context aAncestor participating.
2887 */
2888static bool FrameParticipatesIn3DContext(nsIFrame* aAncestor,
2889 nsIFrame* aDescendant) {
2890 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"
, 2890); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAncestor != aDescendant"
")"); do { *((volatile int*)__null) = 2890; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2891 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"
, 2891); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAncestor->GetContent() != aDescendant->GetContent()"
")"); do { *((volatile int*)__null) = 2891; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2892 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"
, 2892); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAncestor->Extend3DContext()"
")"); do { *((volatile int*)__null) = 2892; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2893
2894 nsIFrame* ancestor = aAncestor->FirstContinuation();
2895 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"
, 2895); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ancestor->IsPrimaryFrame()"
")"); do { *((volatile int*)__null) = 2895; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2896
2897 nsIFrame* frame;
2898 for (frame = aDescendant->GetClosestFlattenedTreeAncestorPrimaryFrame();
2899 frame && ancestor != frame;
2900 frame = frame->GetClosestFlattenedTreeAncestorPrimaryFrame()) {
2901 if (!frame->Extend3DContext()) {
2902 return false;
2903 }
2904 }
2905
2906 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"
, 2906); AnnotateMozCrashReason("MOZ_ASSERT" "(" "frame == ancestor"
")"); do { *((volatile int*)__null) = 2906; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2907 return true;
2908}
2909
2910static bool ItemParticipatesIn3DContext(nsIFrame* aAncestor,
2911 nsDisplayItem* aItem) {
2912 auto type = aItem->GetType();
2913 const bool isContainer = type == DisplayItemType::TYPE_WRAP_LIST ||
2914 type == DisplayItemType::TYPE_CONTAINER;
2915
2916 if (isContainer && aItem->GetChildren()->Length() == 1) {
2917 // If the wraplist has only one child item, use the type of that item.
2918 type = aItem->GetChildren()->GetBottom()->GetType();
2919 }
2920
2921 if (type != DisplayItemType::TYPE_TRANSFORM &&
2922 type != DisplayItemType::TYPE_PERSPECTIVE) {
2923 return false;
2924 }
2925 nsIFrame* transformFrame = aItem->Frame();
2926 if (aAncestor->GetContent() == transformFrame->GetContent()) {
2927 return true;
2928 }
2929 return FrameParticipatesIn3DContext(aAncestor, transformFrame);
2930}
2931
2932static void WrapSeparatorTransform(nsDisplayListBuilder* aBuilder,
2933 nsIFrame* aFrame,
2934 nsDisplayList* aNonParticipants,
2935 nsDisplayList* aParticipants, int aIndex,
2936 nsDisplayItem** aSeparator) {
2937 if (aNonParticipants->IsEmpty()) {
2938 return;
2939 }
2940
2941 nsDisplayTransform* item = MakeDisplayItemWithIndex<nsDisplayTransform>(
2942 aBuilder, aFrame, aIndex, aNonParticipants, aBuilder->GetVisibleRect());
2943
2944 if (*aSeparator == nullptr && item) {
2945 *aSeparator = item;
2946 }
2947
2948 aParticipants->AppendToTop(item);
2949}
2950
2951// Try to compute a clip rect to bound the contents of the mask item
2952// that will be built for |aMaskedFrame|. If we're not able to compute
2953// one, return an empty Maybe.
2954// The returned clip rect, if there is one, is relative to |aMaskedFrame|.
2955static Maybe<nsRect> ComputeClipForMaskItem(
2956 nsDisplayListBuilder* aBuilder, nsIFrame* aMaskedFrame,
2957 const SVGUtils::MaskUsage& aMaskUsage) {
2958 const nsStyleSVGReset* svgReset = aMaskedFrame->StyleSVGReset();
2959
2960 nsPoint offsetToUserSpace =
2961 nsLayoutUtils::ComputeOffsetToUserSpace(aBuilder, aMaskedFrame);
2962 int32_t devPixelRatio = aMaskedFrame->PresContext()->AppUnitsPerDevPixel();
2963 gfxPoint devPixelOffsetToUserSpace =
2964 nsLayoutUtils::PointToGfxPoint(offsetToUserSpace, devPixelRatio);
2965 CSSToLayoutDeviceScale cssToDevScale =
2966 aMaskedFrame->PresContext()->CSSToDevPixelScale();
2967
2968 nsPoint toReferenceFrame;
2969 aBuilder->FindReferenceFrameFor(aMaskedFrame, &toReferenceFrame);
2970
2971 Maybe<gfxRect> combinedClip;
2972 if (aMaskUsage.ShouldApplyBasicShapeOrPath()) {
2973 Maybe<Rect> result =
2974 CSSClipPathInstance::GetBoundingRectForBasicShapeOrPathClip(
2975 aMaskedFrame, svgReset->mClipPath);
2976 if (result) {
2977 combinedClip = Some(ThebesRect(*result));
2978 }
2979 } else if (aMaskUsage.ShouldApplyClipPath()) {
2980 gfxRect result = SVGUtils::GetBBox(
2981 aMaskedFrame,
2982 SVGUtils::eBBoxIncludeClipped | SVGUtils::eBBoxIncludeFill |
2983 SVGUtils::eBBoxIncludeMarkers | SVGUtils::eBBoxIncludeStroke |
2984 SVGUtils::eDoNotClipToBBoxOfContentInsideClipPath);
2985 combinedClip = Some(
2986 ThebesRect((CSSRect::FromUnknownRect(ToRect(result)) * cssToDevScale)
2987 .ToUnknownRect()));
2988 } else {
2989 // The code for this case is adapted from ComputeMaskGeometry().
2990
2991 nsRect borderArea(toReferenceFrame, aMaskedFrame->GetSize());
2992 borderArea -= offsetToUserSpace;
2993
2994 // Use an infinite dirty rect to pass into nsCSSRendering::
2995 // GetImageLayerClip() because we don't have an actual dirty rect to
2996 // pass in. This is fine because the only time GetImageLayerClip() will
2997 // not intersect the incoming dirty rect with something is in the "NoClip"
2998 // case, and we handle that specially.
2999 nsRect dirtyRect(nscoord_MIN / 2, nscoord_MIN / 2, nscoord_MAX,
3000 nscoord_MAX);
3001
3002 nsIFrame* firstFrame =
3003 nsLayoutUtils::FirstContinuationOrIBSplitSibling(aMaskedFrame);
3004 nsTArray<SVGMaskFrame*> maskFrames;
3005 // XXX check return value?
3006 SVGObserverUtils::GetAndObserveMasks(firstFrame, &maskFrames);
3007
3008 for (uint32_t i = 0; i < maskFrames.Length(); ++i) {
3009 gfxRect clipArea;
3010 if (maskFrames[i]) {
3011 clipArea = maskFrames[i]->GetMaskArea(aMaskedFrame);
3012 clipArea = ThebesRect(
3013 (CSSRect::FromUnknownRect(ToRect(clipArea)) * cssToDevScale)
3014 .ToUnknownRect());
3015 } else {
3016 const auto& layer = svgReset->mMask.mLayers[i];
3017 if (layer.mClip == StyleGeometryBox::NoClip) {
3018 return Nothing();
3019 }
3020
3021 nsCSSRendering::ImageLayerClipState clipState;
3022 nsCSSRendering::GetImageLayerClip(
3023 layer, aMaskedFrame, *aMaskedFrame->StyleBorder(), borderArea,
3024 dirtyRect, false /* aWillPaintBorder */, devPixelRatio, &clipState);
3025 clipArea = clipState.mDirtyRectInDevPx;
3026 }
3027 combinedClip = UnionMaybeRects(combinedClip, Some(clipArea));
3028 }
3029 }
3030 if (combinedClip) {
3031 if (combinedClip->IsEmpty()) {
3032 // *clipForMask might be empty if all mask references are not resolvable
3033 // or the size of them are empty. We still need to create a transparent
3034 // mask before bug 1276834 fixed, so don't clip ctx by an empty rectangle
3035 // for for now.
3036 return Nothing();
3037 }
3038
3039 // Convert to user space.
3040 *combinedClip += devPixelOffsetToUserSpace;
3041
3042 // Round the clip out. In FrameLayerBuilder we round clips to nearest
3043 // pixels, and if we have a really thin clip here, that can cause the
3044 // clip to become empty if we didn't round out here.
3045 // The rounding happens in coordinates that are relative to the reference
3046 // frame, which matches what FrameLayerBuilder does.
3047 combinedClip->RoundOut();
3048
3049 // Convert to app units.
3050 nsRect result =
3051 nsLayoutUtils::RoundGfxRectToAppRect(*combinedClip, devPixelRatio);
3052
3053 // The resulting clip is relative to the reference frame, but the caller
3054 // expects it to be relative to the masked frame, so adjust it.
3055 result -= toReferenceFrame;
3056 return Some(result);
3057 }
3058 return Nothing();
3059}
3060
3061struct AutoCheckBuilder {
3062 explicit AutoCheckBuilder(nsDisplayListBuilder* aBuilder)
3063 : mBuilder(aBuilder) {
3064 aBuilder->Check();
3065 }
3066
3067 ~AutoCheckBuilder() { mBuilder->Check(); }
3068
3069 nsDisplayListBuilder* mBuilder;
3070};
3071
3072/**
3073 * Tries to reuse a top-level stacking context item from the previous paint.
3074 * Returns true if an item was reused, otherwise false.
3075 */
3076bool TryToReuseStackingContextItem(nsDisplayListBuilder* aBuilder,
3077 nsDisplayList* aList, nsIFrame* aFrame) {
3078 if (!aBuilder->IsForPainting() || !aBuilder->IsPartialUpdate() ||
3079 aBuilder->InInvalidSubtree()) {
3080 return false;
3081 }
3082
3083 if (aFrame->IsFrameModified() || aFrame->HasModifiedDescendants()) {
3084 return false;
3085 }
3086
3087 auto& items = aFrame->DisplayItems();
3088 auto* res = std::find_if(
3089 items.begin(), items.end(),
3090 [](nsDisplayItem* aItem) { return aItem->IsPreProcessed(); });
3091
3092 if (res == items.end()) {
3093 return false;
3094 }
3095
3096 nsDisplayItem* container = *res;
3097 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"
, 3097); AnnotateMozCrashReason("MOZ_ASSERT" "(" "container->Frame() == aFrame"
")"); do { *((volatile int*)__null) = 3097; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3098 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)
3099 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)
;
3100
3101 aList->AppendToTop(container);
3102 aBuilder->ReuseDisplayItem(container);
3103 return true;
3104}
3105
3106void nsIFrame::BuildDisplayListForStackingContext(
3107 nsDisplayListBuilder* aBuilder, nsDisplayList* aList,
3108 bool* aCreatedContainerItem) {
3109#ifdef DEBUG1
3110 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)
;
3111 ScopeExit e(
3112 [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)
; });
3113#endif
3114
3115 AutoCheckBuilder check(aBuilder);
3116
3117 if (aBuilder->IsReusingStackingContextItems() &&
3118 TryToReuseStackingContextItem(aBuilder, aList, this)) {
3119 if (aCreatedContainerItem) {
3120 *aCreatedContainerItem = true;
3121 }
3122 return;
3123 }
3124
3125 if (HasAnyStateBits(NS_FRAME_TOO_DEEP_IN_FRAME_TREE)) {
3126 return;
3127 }
3128
3129 const auto& style = *Style();
3130 const nsStyleDisplay* disp = style.StyleDisplay();
3131 const nsStyleEffects* effects = style.StyleEffects();
3132 EffectSet* effectSetForOpacity =
3133 EffectSet::GetForFrame(this, nsCSSPropertyIDSet::OpacityProperties());
3134 // We can stop right away if this is a zero-opacity stacking context and
3135 // we're painting, and we're not animating opacity.
3136 bool needHitTestInfo = aBuilder->BuildCompositorHitTestInfo() &&
3137 Style()->PointerEvents() != StylePointerEvents::None;
3138 bool opacityItemForEventsOnly = false;
3139 if (effects->IsTransparent() && aBuilder->IsForPainting() &&
3140 !(disp->mWillChange.bits & StyleWillChangeBits::OPACITY) &&
3141 !nsLayoutUtils::HasAnimationOfPropertySet(
3142 this, nsCSSPropertyIDSet::OpacityProperties(), effectSetForOpacity)) {
3143 if (needHitTestInfo) {
3144 opacityItemForEventsOnly = true;
3145 } else {
3146 return;
3147 }
3148 }
3149
3150 if (aBuilder->IsForPainting() && disp->mWillChange.bits) {
3151 aBuilder->AddToWillChangeBudget(this, GetSize());
3152 }
3153
3154 // For preserves3d, use the dirty rect already installed on the
3155 // builder, since aDirtyRect maybe distorted for transforms along
3156 // the chain.
3157 nsRect visibleRect = aBuilder->GetVisibleRect();
3158 nsRect dirtyRect = aBuilder->GetDirtyRect();
3159
3160 // We build an opacity item if it's not going to be drawn by SVG content.
3161 // We could in principle skip creating an nsDisplayOpacity item if
3162 // nsDisplayOpacity::NeedsActiveLayer returns false and usingSVGEffects is
3163 // true (the nsDisplayFilter/nsDisplayMasksAndClipPaths could handle the
3164 // opacity). Since SVG has perf issues where we sometimes spend a lot of
3165 // time creating display list items that might be helpful. We'd need to
3166 // restore our mechanism to do that (changed in bug 1482403), and we'd
3167 // need to invalidate the frame if the value that would be return from
3168 // NeedsActiveLayer was to change, which we don't currently do.
3169 const bool useOpacity =
3170 HasVisualOpacity(disp, effects, effectSetForOpacity) &&
3171 !SVGUtils::CanOptimizeOpacity(this);
3172
3173 const bool isTransformed = IsTransformed();
3174 const bool hasPerspective = isTransformed && HasPerspective();
3175 const bool extend3DContext =
3176 Extend3DContext(disp, effects, effectSetForOpacity);
3177 const bool combines3DTransformWithAncestors =
3178 (extend3DContext || isTransformed) && Combines3DTransformWithAncestors();
3179
3180 Maybe<nsDisplayListBuilder::AutoPreserves3DContext> autoPreserves3DContext;
3181 if (extend3DContext && !combines3DTransformWithAncestors) {
3182 // Start a new preserves3d context to keep informations on
3183 // nsDisplayListBuilder.
3184 autoPreserves3DContext.emplace(aBuilder);
3185 // Save dirty rect on the builder to avoid being distorted for
3186 // multiple transforms along the chain.
3187 aBuilder->SavePreserves3DRect();
3188
3189 // We rebuild everything within preserve-3d and don't try
3190 // to retain, so override the dirty rect now.
3191 if (aBuilder->IsRetainingDisplayList()) {
3192 dirtyRect = visibleRect;
3193 aBuilder->SetDisablePartialUpdates(true);
3194 }
3195 }
3196
3197 const bool useBlendMode = effects->mMixBlendMode != StyleBlend::Normal;
3198 if (useBlendMode) {
3199 aBuilder->SetContainsBlendMode(true);
3200 }
3201
3202 // reset blend mode so we can keep track if this stacking context needs have
3203 // a nsDisplayBlendContainer. Set the blend mode back when the routine exits
3204 // so we keep track if the parent stacking context needs a container too.
3205 AutoSaveRestoreContainsBlendMode autoRestoreBlendMode(*aBuilder);
3206 aBuilder->SetContainsBlendMode(false);
3207
3208 // NOTE: When changing this condition make sure to tweak ScrollContainerFrame
3209 // as well.
3210 bool usingBackdropFilter = effects->HasBackdropFilters() &&
3211 IsVisibleForPainting() &&
3212 !style.IsRootElementStyle();
3213
3214 nsRect visibleRectOutsideTransform = visibleRect;
3215 nsDisplayTransform::PrerenderInfo prerenderInfo;
3216 bool inTransform = aBuilder->IsInTransform();
3217 if (isTransformed) {
3218 prerenderInfo = nsDisplayTransform::ShouldPrerenderTransformedContent(
3219 aBuilder, this, &visibleRect);
3220
3221 switch (prerenderInfo.mDecision) {
3222 case nsDisplayTransform::PrerenderDecision::Full:
3223 case nsDisplayTransform::PrerenderDecision::Partial:
3224 dirtyRect = visibleRect;
3225 break;
3226 case nsDisplayTransform::PrerenderDecision::No: {
3227 // If we didn't prerender an animated frame in a preserve-3d context,
3228 // then we want disable async animations for the rest of the preserve-3d
3229 // (especially ancestors).
3230 if ((extend3DContext || combines3DTransformWithAncestors) &&
3231 prerenderInfo.mHasAnimations) {
3232 aBuilder->SavePreserves3DAllowAsyncAnimation(false);
3233 }
3234
3235 const nsRect overflow = InkOverflowRectRelativeToSelf();
3236 if (overflow.IsEmpty() && !extend3DContext) {
3237 return;
3238 }
3239
3240 // If we're in preserve-3d then grab the dirty rect that was given to
3241 // the root and transform using the combined transform.
3242 if (combines3DTransformWithAncestors) {
3243 visibleRect = dirtyRect = aBuilder->GetPreserves3DRect();
3244 }
3245
3246 float appPerDev = PresContext()->AppUnitsPerDevPixel();
3247 auto transform = nsDisplayTransform::GetResultingTransformMatrix(
3248 this, nsPoint(), appPerDev,
3249 nsDisplayTransform::kTransformRectFlags);
3250 nsRect untransformedDirtyRect;
3251 if (nsDisplayTransform::UntransformRect(dirtyRect, overflow, transform,
3252 appPerDev,
3253 &untransformedDirtyRect)) {
3254 dirtyRect = untransformedDirtyRect;
3255 nsDisplayTransform::UntransformRect(visibleRect, overflow, transform,
3256 appPerDev, &visibleRect);
3257 } else {
3258 // This should only happen if the transform is singular, in which case
3259 // nothing is visible anyway
3260 dirtyRect.SetEmpty();
3261 visibleRect.SetEmpty();
3262 }
3263 }
3264 }
3265 inTransform = true;
3266 } else if (IsFixedPosContainingBlock()) {
3267 // Restict the building area to the overflow rect for these frames, since
3268 // RetainedDisplayListBuilder uses it to know if the size of the stacking
3269 // context changed.
3270 visibleRect.IntersectRect(visibleRect, InkOverflowRect());
3271 dirtyRect.IntersectRect(dirtyRect, InkOverflowRect());
3272 }
3273
3274 bool hasOverrideDirtyRect = false;
3275 // If we're doing a partial build, we're not invalid and we're capable
3276 // of having an override building rect (stacking context and fixed pos
3277 // containing block), then we should assume we have one.
3278 // Either we have an explicit one, or nothing in our subtree changed and
3279 // we have an implicit empty rect.
3280 //
3281 // These conditions should match |CanStoreDisplayListBuildingRect()| in
3282 // RetainedDisplayListBuilder.cpp
3283 if (!aBuilder->IsReusingStackingContextItems() &&
3284 aBuilder->IsPartialUpdate() && !aBuilder->InInvalidSubtree() &&
3285 !IsFrameModified() && IsFixedPosContainingBlock() &&
3286 !GetPrevContinuation() && !GetNextContinuation()) {
3287 dirtyRect = nsRect();
3288 if (HasOverrideDirtyRegion()) {
3289 nsDisplayListBuilder::DisplayListBuildingData* data =
3290 GetProperty(nsDisplayListBuilder::DisplayListBuildingRect());
3291 if (data) {
3292 dirtyRect = data->mDirtyRect.Intersect(visibleRect);
3293 hasOverrideDirtyRect = true;
3294 }
3295 }
3296 }
3297
3298 bool usingFilter = effects->HasFilters() && !style.IsRootElementStyle();
3299 SVGUtils::MaskUsage maskUsage = SVGUtils::DetermineMaskUsage(this, false);
3300 bool usingMask = maskUsage.UsingMaskOrClipPath();
3301 bool usingSVGEffects = usingFilter || usingMask;
3302
3303 nsRect visibleRectOutsideSVGEffects = visibleRect;
3304 nsDisplayList hoistedScrollInfoItemsStorage(aBuilder);
3305 if (usingSVGEffects) {
3306 dirtyRect =
3307 SVGIntegrationUtils::GetRequiredSourceForInvalidArea(this, dirtyRect);
3308 visibleRect =
3309 SVGIntegrationUtils::GetRequiredSourceForInvalidArea(this, visibleRect);
3310 aBuilder->EnterSVGEffectsContents(this, &hoistedScrollInfoItemsStorage);
3311 }
3312
3313 bool useStickyPosition = disp->mPosition == StylePositionProperty::Sticky;
3314
3315 bool useFixedPosition =
3316 disp->mPosition == StylePositionProperty::Fixed &&
3317 (DisplayPortUtils::IsFixedPosFrameInDisplayPort(this) ||
3318 BuilderHasScrolledClip(aBuilder));
3319
3320 nsDisplayListBuilder::AutoBuildingDisplayList buildingDisplayList(
3321 aBuilder, this, visibleRect, dirtyRect, isTransformed);
3322
3323 UpdateCurrentHitTestInfo(aBuilder, this);
3324
3325 // Depending on the effects that are applied to this frame, we can create
3326 // multiple container display items and wrap them around our contents.
3327 // This enum lists all the potential container display items, in the order
3328 // outside to inside.
3329 enum class ContainerItemType : uint8_t {
3330 None = 0,
3331 OwnLayerIfNeeded,
3332 BlendMode,
3333 FixedPosition,
3334 OwnLayerForTransformWithRoundedClip,
3335 Perspective,
3336 Transform,
3337 SeparatorTransforms,
3338 Opacity,
3339 Filter,
3340 BlendContainer
3341 };
3342
3343 nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
3344
3345 auto cssClip = GetClipPropClipRect(disp, effects, GetSize());
3346 auto ApplyClipProp = [&](DisplayListClipState::AutoSaveRestore& aClipState) {
3347 if (!cssClip) {
3348 return;
3349 }
3350 nsPoint offset = aBuilder->GetCurrentFrameOffsetToReferenceFrame();
3351 aBuilder->IntersectDirtyRect(*cssClip);
3352 aBuilder->IntersectVisibleRect(*cssClip);
3353 aClipState.ClipContentDescendants(*cssClip + offset);
3354 };
3355
3356 // The CSS clip property is effectively inside the transform, but outside the
3357 // filters. So if we're not transformed we can apply it just here for
3358 // simplicity, instead of on each of the places that handle clipCapturedBy.
3359 DisplayListClipState::AutoSaveRestore untransformedCssClip(aBuilder);
3360 if (!isTransformed) {
3361 ApplyClipProp(untransformedCssClip);
3362 }
3363
3364 // If there is a current clip, then depending on the container items we
3365 // create, different things can happen to it. Some container items simply
3366 // propagate the clip to their children and aren't clipped themselves.
3367 // But other container items, especially those that establish a different
3368 // geometry for their contents (e.g. transforms), capture the clip on
3369 // themselves and unset the clip for their contents. If we create more than
3370 // one of those container items, the clip will be captured on the outermost
3371 // one and the inner container items will be unclipped.
3372 ContainerItemType clipCapturedBy = ContainerItemType::None;
3373 if (useFixedPosition) {
3374 clipCapturedBy = ContainerItemType::FixedPosition;
3375 } else if (isTransformed) {
3376 const DisplayItemClipChain* currentClip =
3377 aBuilder->ClipState().GetCurrentCombinedClipChain(aBuilder);
3378 if ((hasPerspective || extend3DContext) &&
3379 (currentClip && currentClip->HasRoundedCorners())) {
3380 // If we're creating an nsDisplayTransform item that is going to combine
3381 // its transform with its children (preserve-3d or perspective), then we
3382 // can't have an intermediate surface. Mask layers force an intermediate
3383 // surface, so if we're going to need both then create a separate
3384 // wrapping layer for the mask.
3385 clipCapturedBy = ContainerItemType::OwnLayerForTransformWithRoundedClip;
3386 } else if (hasPerspective) {
3387 clipCapturedBy = ContainerItemType::Perspective;
3388 } else {
3389 clipCapturedBy = ContainerItemType::Transform;
3390 }
3391 } else if (usingFilter) {
3392 clipCapturedBy = ContainerItemType::Filter;
3393 }
3394
3395 DisplayListClipState::AutoSaveRestore clipState(aBuilder);
3396 if (clipCapturedBy != ContainerItemType::None) {
3397 clipState.Clear();
3398 }
3399
3400 DisplayListClipState::AutoSaveRestore transformedCssClip(aBuilder);
3401 if (isTransformed) {
3402 // FIXME(emilio, bug 1525159): In the case we have a both a transform _and_
3403 // filters, this clips the input to the filters as well, which is not
3404 // correct (clipping by the `clip` property is supposed to happen after
3405 // applying the filter effects, per [1].
3406 //
3407 // This is not a regression though, since we used to do that anyway before
3408 // bug 1514384, and even without the transform we get it wrong.
3409 //
3410 // [1]: https://drafts.fxtf.org/css-masking/#placement
3411 ApplyClipProp(transformedCssClip);
3412 }
3413
3414 uint32_t numActiveScrollframesEncounteredBefore =
3415 aBuilder->GetNumActiveScrollframesEncountered();
3416
3417 nsDisplayListCollection set(aBuilder);
3418 Maybe<nsRect> clipForMask;
3419 {
3420 DisplayListClipState::AutoSaveRestore nestedClipState(aBuilder);
3421 nsDisplayListBuilder::AutoInTransformSetter inTransformSetter(aBuilder,
3422 inTransform);
3423 nsDisplayListBuilder::AutoEnterFilter filterASRSetter(aBuilder,
3424 usingFilter);
3425 nsDisplayListBuilder::AutoInEventsOnly inEventsSetter(
3426 aBuilder, opacityItemForEventsOnly);
3427
3428 // If we have a mask, compute a clip to bound the masked content.
3429 // This is necessary in case the content moves with an ancestor
3430 // ASR of the mask.
3431 // Don't do this if we also have a filter, because then the clip
3432 // would be applied before the filter, violating
3433 // https://www.w3.org/TR/filter-effects-1/#placement.
3434 // Filters are a containing block for fixed and absolute descendants,
3435 // so the masked content cannot move with an ancestor ASR.
3436 if (usingMask && !usingFilter) {
3437 clipForMask = ComputeClipForMaskItem(aBuilder, this, maskUsage);
3438 if (clipForMask) {
3439 aBuilder->IntersectDirtyRect(*clipForMask);
3440 aBuilder->IntersectVisibleRect(*clipForMask);
3441 nestedClipState.ClipContentDescendants(
3442 *clipForMask + aBuilder->GetCurrentFrameOffsetToReferenceFrame());
3443 }
3444 }
3445
3446 // extend3DContext also guarantees that applyAbsPosClipping and
3447 // usingSVGEffects are false We only modify the preserve-3d rect if we are
3448 // the top of a preserve-3d heirarchy
3449 if (extend3DContext) {
3450 // Mark these first so MarkAbsoluteFramesForDisplayList knows if we are
3451 // going to be forced to descend into frames.
3452 aBuilder->MarkPreserve3DFramesForDisplayList(this);
3453 }
3454
3455 aBuilder->AdjustWindowDraggingRegion(this);
3456
3457 MarkAbsoluteFramesForDisplayList(aBuilder);
3458 aBuilder->Check();
3459 BuildDisplayList(aBuilder, set);
3460 SetBuiltDisplayList(true);
3461 aBuilder->Check();
3462 aBuilder->DisplayCaret(this, set.Outlines());
3463
3464 // Blend modes are a real pain for retained display lists. We build a blend
3465 // container item if the built list contains any blend mode items within
3466 // the current stacking context. This can change without an invalidation
3467 // to the stacking context frame, or the blend mode frame (e.g. by moving
3468 // an intermediate frame).
3469 // When we gain/remove a blend container item, we need to mark this frame
3470 // as invalid and have the full display list for merging to track
3471 // the change correctly.
3472 // It seems really hard to track this in advance, as the bookkeeping
3473 // required to note which stacking contexts have blend descendants
3474 // is complex and likely to be buggy.
3475 // Instead we're doing the sad thing, detecting it afterwards, and just
3476 // repeating display list building if it changed.
3477 // We have to repeat building for the entire display list (or at least
3478 // the outer stacking context), since we need to mark this frame as invalid
3479 // to remove any existing content that isn't wrapped in the blend container,
3480 // and then we need to build content infront/behind the blend container
3481 // to get correct positioning during merging.
3482 if (aBuilder->ContainsBlendMode() && aBuilder->IsRetainingDisplayList()) {
3483 if (aBuilder->IsPartialUpdate()) {
3484 aBuilder->SetPartialBuildFailed(true);
3485 } else {
3486 aBuilder->SetDisablePartialUpdates(true);
3487 }
3488 }
3489 }
3490
3491 if (aBuilder->IsBackgroundOnly()) {
3492 set.BlockBorderBackgrounds()->DeleteAll(aBuilder);
3493 set.Floats()->DeleteAll(aBuilder);
3494 set.Content()->DeleteAll(aBuilder);
3495 set.PositionedDescendants()->DeleteAll(aBuilder);
3496 set.Outlines()->DeleteAll(aBuilder);
3497 }
3498
3499 if (hasOverrideDirtyRect &&
3500 StaticPrefs::layout_display_list_show_rebuild_area()) {
3501 nsDisplaySolidColor* color = MakeDisplayItem<nsDisplaySolidColor>(
3502 aBuilder, this,
3503 dirtyRect + aBuilder->GetCurrentFrameOffsetToReferenceFrame(),
3504 NS_RGBA(255, 0, 0, 64)((nscolor)(((64) << 24) | ((0) << 16) | ((0) <<
8) | (255)))
, false);
3505 if (color) {
3506 color->SetOverrideZIndex(INT32_MAX(2147483647));
3507 set.PositionedDescendants()->AppendToTop(color);
3508 }
3509 }
3510
3511 nsIContent* content = GetContent();
3512 if (!content) {
3513 content = PresContext()->Document()->GetRootElement();
3514 }
3515
3516 nsDisplayList resultList(aBuilder);
3517 set.SerializeWithCorrectZOrder(&resultList, content);
3518
3519 // Get the ASR to use for the container items that we create here.
3520 const ActiveScrolledRoot* containerItemASR = contASRTracker.GetContainerASR();
3521
3522 bool createdContainer = false;
3523
3524 // If adding both a nsDisplayBlendContainer and a nsDisplayBlendMode to the
3525 // same list, the nsDisplayBlendContainer should be added first. This only
3526 // happens when the element creating this stacking context has mix-blend-mode
3527 // and also contains a child which has mix-blend-mode.
3528 // The nsDisplayBlendContainer must be added to the list first, so it does not
3529 // isolate the containing element blending as well.
3530 if (aBuilder->ContainsBlendMode()) {
3531 resultList.AppendToTop(nsDisplayBlendContainer::CreateForMixBlendMode(
3532 aBuilder, this, &resultList, containerItemASR));
3533 createdContainer = true;
3534 }
3535
3536 if (usingBackdropFilter) {
3537 nsRect backdropRect =
3538 GetRectRelativeToSelf() + aBuilder->ToReferenceFrame(this);
3539 resultList.AppendNewToTop<nsDisplayBackdropFilters>(
3540 aBuilder, this, &resultList, backdropRect, this);
3541 createdContainer = true;
3542 }
3543
3544 // If there are any SVG effects, wrap the list up in an SVG effects item
3545 // (which also handles CSS group opacity). Note that we create an SVG effects
3546 // item even if resultList is empty, since a filter can produce graphical
3547 // output even if the element being filtered wouldn't otherwise do so.
3548 if (usingSVGEffects) {
3549 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"
, 3550); AnnotateMozCrashReason("MOZ_ASSERT" "(" "usingFilter || usingMask"
") (" "Beside filter & mask/clip-path, what else effect do we have?"
")"); do { *((volatile int*)__null) = 3550; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
3550 "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"
, 3550); AnnotateMozCrashReason("MOZ_ASSERT" "(" "usingFilter || usingMask"
") (" "Beside filter & mask/clip-path, what else effect do we have?"
")"); do { *((volatile int*)__null) = 3550; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3551
3552 if (clipCapturedBy == ContainerItemType::Filter) {
3553 clipState.Restore();
3554 }
3555 // Revert to the post-filter dirty rect.
3556 aBuilder->SetVisibleRect(visibleRectOutsideSVGEffects);
3557
3558 // Skip all filter effects while generating glyph mask.
3559 if (usingFilter && !aBuilder->IsForGenerateGlyphMask()) {
3560 /* List now emptied, so add the new list to the top. */
3561 resultList.AppendNewToTop<nsDisplayFilters>(aBuilder, this, &resultList,
3562 this, usingBackdropFilter);
3563 createdContainer = true;
Value stored to 'createdContainer' is never read
3564 }
3565
3566 if (usingMask) {
3567 // The mask should move with aBuilder->CurrentActiveScrolledRoot(), so
3568 // that's the ASR we prefer to use for the mask item. However, we can
3569 // only do this if the mask if clipped with respect to that ASR, because
3570 // an item always needs to have finite bounds with respect to its ASR.
3571 // If we weren't able to compute a clip for the mask, we fall back to
3572 // using containerItemASR, which is the lowest common ancestor clip of
3573 // the mask's contents. That's not entirely correct, but it satisfies
3574 // the base requirement of the ASR system (that items have finite bounds
3575 // wrt. their ASR).
3576 const ActiveScrolledRoot* maskASR =
3577 clipForMask.isSome() ? aBuilder->CurrentActiveScrolledRoot()
3578 : containerItemASR;
3579 /* List now emptied, so add the new list to the top. */
3580 resultList.AppendNewToTop<nsDisplayMasksAndClipPaths>(
3581 aBuilder, this, &resultList, maskASR, usingBackdropFilter);
3582 createdContainer = true;
3583 }
3584
3585 // TODO(miko): We could probably create a wraplist here and avoid creating
3586 // it later in |BuildDisplayListForChild()|.
3587 createdContainer = false;
3588
3589 // Also add the hoisted scroll info items. We need those for APZ scrolling
3590 // because nsDisplayMasksAndClipPaths items can't build active layers.
3591 aBuilder->ExitSVGEffectsContents();
3592 resultList.AppendToTop(&hoistedScrollInfoItemsStorage);
3593 }
3594
3595 // If the list is non-empty and there is CSS group opacity without SVG
3596 // effects, wrap it up in an opacity item.
3597 if (useOpacity) {
3598 const bool needsActiveOpacityLayer =
3599 nsDisplayOpacity::NeedsActiveLayer(aBuilder, this);
3600 resultList.AppendNewToTop<nsDisplayOpacity>(
3601 aBuilder, this, &resultList, containerItemASR, opacityItemForEventsOnly,
3602 needsActiveOpacityLayer, usingBackdropFilter);
3603 createdContainer = true;
3604 }
3605
3606 // If we're going to apply a transformation and don't have preserve-3d set,
3607 // wrap everything in an nsDisplayTransform. If there's nothing in the list,
3608 // don't add anything.
3609 //
3610 // For the preserve-3d case we want to individually wrap every child in the
3611 // list with a separate nsDisplayTransform instead. When the child is already
3612 // an nsDisplayTransform, we can skip this step, as the computed transform
3613 // will already include our own.
3614 //
3615 // We also traverse into sublists created by nsDisplayWrapList, so that we
3616 // find all the correct children.
3617 if (isTransformed && extend3DContext) {
3618 // Install dummy nsDisplayTransform as a leaf containing
3619 // descendants not participating this 3D rendering context.
3620 nsDisplayList nonparticipants(aBuilder);
3621 nsDisplayList participants(aBuilder);
3622 int index = 1;
3623
3624 nsDisplayItem* separator = nullptr;
3625
3626 // TODO: This can be simplified: |participants| is just |resultList|.
3627 for (nsDisplayItem* item : resultList.TakeItems()) {
3628 if (ItemParticipatesIn3DContext(this, item) &&
3629 !item->GetClip().HasClip()) {
3630 // The frame of this item participates the same 3D context.
3631 WrapSeparatorTransform(aBuilder, this, &nonparticipants, &participants,
3632 index++, &separator);
3633
3634 participants.AppendToTop(item);
3635 } else {
3636 // The frame of the item doesn't participate the current
3637 // context, or has no transform.
3638 //
3639 // For items participating but not transformed, they are add
3640 // to nonparticipants to get a separator layer for handling
3641 // clips, if there is, on an intermediate surface.
3642 // \see ContainerLayer::DefaultComputeEffectiveTransforms().
3643 nonparticipants.AppendToTop(item);
3644 }
3645 }
3646 WrapSeparatorTransform(aBuilder, this, &nonparticipants, &participants,
3647 index++, &separator);
3648
3649 if (separator) {
3650 createdContainer = true;
3651 }
3652
3653 resultList.AppendToTop(&participants);
3654 }
3655
3656 if (isTransformed) {
3657 transformedCssClip.Restore();
3658 if (clipCapturedBy == ContainerItemType::Transform) {
3659 // Restore clip state now so nsDisplayTransform is clipped properly.
3660 clipState.Restore();
3661 }
3662 // Revert to the dirtyrect coming in from the parent, without our transform
3663 // taken into account.
3664 aBuilder->SetVisibleRect(visibleRectOutsideTransform);
3665
3666 if (this != aBuilder->RootReferenceFrame()) {
3667 // Revert to the outer reference frame and offset because all display
3668 // items we create from now on are outside the transform.
3669 nsPoint toOuterReferenceFrame;
3670 const nsIFrame* outerReferenceFrame =
3671 aBuilder->FindReferenceFrameFor(GetParent(), &toOuterReferenceFrame);
3672 toOuterReferenceFrame += GetPosition();
3673
3674 buildingDisplayList.SetReferenceFrameAndCurrentOffset(
3675 outerReferenceFrame, toOuterReferenceFrame);
3676 }
3677
3678 // We would like to block async animations for ancestors of ones not
3679 // prerendered in the preserve-3d tree. Now that we've finished processing
3680 // all descendants, update allowAsyncAnimation to take their prerender
3681 // state into account
3682 // FIXME: We don't block async animations for previous siblings because
3683 // their prerender decisions have been made. We may have to figure out a
3684 // better way to rollback their prerender decisions.
3685 // Alternatively we could not block animations for later siblings, and only
3686 // block them for ancestors of a blocked one.
3687 if ((extend3DContext || combines3DTransformWithAncestors) &&
3688 prerenderInfo.CanUseAsyncAnimations() &&
3689 !aBuilder->GetPreserves3DAllowAsyncAnimation()) {
3690 // aBuilder->GetPreserves3DAllowAsyncAnimation() means the inner or
3691 // previous silbing frames are allowed/disallowed for async animations.
3692 prerenderInfo.mDecision = nsDisplayTransform::PrerenderDecision::No;
3693 }
3694
3695 nsDisplayTransform* transformItem = MakeDisplayItem<nsDisplayTransform>(
3696 aBuilder, this, &resultList, visibleRect, prerenderInfo.mDecision);
3697 if (transformItem) {
3698 resultList.AppendToTop(transformItem);
3699 createdContainer = true;
3700
3701 if (numActiveScrollframesEncounteredBefore !=
3702 aBuilder->GetNumActiveScrollframesEncountered()) {
3703 transformItem->SetContainsASRs(true);
3704 }
3705
3706 if (hasPerspective) {
3707 transformItem->MarkWithAssociatedPerspective();
3708
3709 if (clipCapturedBy == ContainerItemType::Perspective) {
3710 clipState.Restore();
3711 }
3712 resultList.AppendNewToTop<nsDisplayPerspective>(aBuilder, this,
3713 &resultList);
3714 createdContainer = true;
3715 }
3716 }
3717 }
3718
3719 if (clipCapturedBy ==
3720 ContainerItemType::OwnLayerForTransformWithRoundedClip) {
3721 clipState.Restore();
3722 resultList.AppendNewToTopWithIndex<nsDisplayOwnLayer>(
3723 aBuilder, this,
3724 /* aIndex = */ nsDisplayOwnLayer::OwnLayerForTransformWithRoundedClip,
3725 &resultList, aBuilder->CurrentActiveScrolledRoot(),
3726 nsDisplayOwnLayerFlags::None, ScrollbarData{},
3727 /* aForceActive = */ false, false);
3728 createdContainer = true;
3729 }
3730
3731 // If we have sticky positioning, wrap it in a sticky position item.
3732 if (useFixedPosition) {
3733 if (clipCapturedBy == ContainerItemType::FixedPosition) {
3734 clipState.Restore();
3735 }
3736 // The ASR for the fixed item should be the ASR of our containing block,
3737 // which has been set as the builder's current ASR, unless this frame is
3738 // invisible and we hadn't saved display item data for it. In that case,
3739 // we need to take the containerItemASR since we might have fixed children.
3740 // For WebRender, we want to the know what |containerItemASR| is for the
3741 // case where the fixed-pos item is not a "real" fixed-pos item (e.g. it's
3742 // nested inside a scrolling transform), so we stash that on the display
3743 // item as well.
3744 const ActiveScrolledRoot* fixedASR = ActiveScrolledRoot::PickAncestor(
3745 containerItemASR, aBuilder->CurrentActiveScrolledRoot());
3746 resultList.AppendNewToTop<nsDisplayFixedPosition>(
3747 aBuilder, this, &resultList, fixedASR, containerItemASR);
3748 createdContainer = true;
3749 } else if (useStickyPosition) {
3750 // For position:sticky, the clip needs to be applied both to the sticky
3751 // container item and to the contents. The container item needs the clip
3752 // because a scrolled clip needs to move independently from the sticky
3753 // contents, and the contents need the clip so that they have finite
3754 // clipped bounds with respect to the container item's ASR. The latter is
3755 // a little tricky in the case where the sticky item has both fixed and
3756 // non-fixed descendants, because that means that the sticky container
3757 // item's ASR is the ASR of the fixed descendant.
3758 // For WebRender display list building, though, we still want to know the
3759 // the ASR that the sticky container item would normally have, so we stash
3760 // that on the display item as the "container ASR" (i.e. the normal ASR of
3761 // the container item, excluding the special behaviour induced by fixed
3762 // descendants).
3763 const ActiveScrolledRoot* stickyASR = ActiveScrolledRoot::PickAncestor(
3764 containerItemASR, aBuilder->CurrentActiveScrolledRoot());
3765
3766 auto* stickyItem = MakeDisplayItem<nsDisplayStickyPosition>(
3767 aBuilder, this, &resultList, stickyASR,
3768 aBuilder->CurrentActiveScrolledRoot(),
3769 clipState.IsClippedToDisplayPort());
3770
3771 bool shouldFlatten = true;
3772
3773 StickyScrollContainer* stickyScrollContainer =
3774 StickyScrollContainer::GetStickyScrollContainerForFrame(this);
3775 if (stickyScrollContainer && stickyScrollContainer->ScrollContainer()
3776 ->IsMaybeAsynchronouslyScrolled()) {
3777 shouldFlatten = false;
3778 }
3779
3780 stickyItem->SetShouldFlatten(shouldFlatten);
3781
3782 resultList.AppendToTop(stickyItem);
3783 createdContainer = true;
3784
3785 // If the sticky element is inside a filter, annotate the scroll frame that
3786 // scrolls the filter as having out-of-flow content inside a filter (this
3787 // inhibits paint skipping).
3788 if (aBuilder->GetFilterASR() && aBuilder->GetFilterASR() == stickyASR) {
3789 aBuilder->GetFilterASR()
3790 ->mScrollContainerFrame->SetHasOutOfFlowContentInsideFilter();
3791 }
3792 }
3793
3794 // If there's blending, wrap up the list in a blend-mode item. Note that
3795 // opacity can be applied before blending as the blend color is not affected
3796 // by foreground opacity (only background alpha).
3797 if (useBlendMode) {
3798 DisplayListClipState::AutoSaveRestore blendModeClipState(aBuilder);
3799 resultList.AppendNewToTop<nsDisplayBlendMode>(aBuilder, this, &resultList,
3800 effects->mMixBlendMode,
3801 containerItemASR, false);
3802 createdContainer = true;
3803 }
3804
3805 if (aBuilder->IsReusingStackingContextItems()) {
3806 if (resultList.IsEmpty()) {
3807 return;
3808 }
3809
3810 nsDisplayItem* container = resultList.GetBottom();
3811 if (resultList.Length() > 1 || container->Frame() != this) {
3812 container = MakeDisplayItem<nsDisplayContainer>(
3813 aBuilder, this, containerItemASR, &resultList);
3814 } else {
3815 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"
, 3815); AnnotateMozCrashReason("MOZ_ASSERT" "(" "resultList.Length() == 1"
")"); do { *((volatile int*)__null) = 3815; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3816 resultList.Clear();
3817 }
3818
3819 // Mark the outermost display item as reusable. These display items and
3820 // their chidren can be reused during the next paint if no ancestor or
3821 // descendant frames have been modified.
3822 if (!container->IsReusedItem()) {
3823 container->SetReusable();
3824 }
3825 aList->AppendToTop(container);
3826 createdContainer = true;
3827 } else {
3828 aList->AppendToTop(&resultList);
3829 }
3830
3831 if (aCreatedContainerItem) {
3832 *aCreatedContainerItem = createdContainer;
3833 }
3834}
3835
3836static nsDisplayItem* WrapInWrapList(nsDisplayListBuilder* aBuilder,
3837 nsIFrame* aFrame, nsDisplayList* aList,
3838 const ActiveScrolledRoot* aContainerASR,
3839 bool aBuiltContainerItem = false) {
3840 nsDisplayItem* item = aList->GetBottom();
3841 if (!item) {
3842 return nullptr;
3843 }
3844
3845 // We need a wrap list if there are multiple items, or if the single
3846 // item has a different frame. This can change in a partial build depending
3847 // on which items we build, so we need to ensure that we don't transition
3848 // to/from a wrap list without invalidating correctly.
3849 bool needsWrapList =
3850 aList->Length() > 1 || item->Frame() != aFrame || item->GetChildren();
3851
3852 // If we have an explicit container item (that can't change without an
3853 // invalidation) or we're doing a full build and don't need a wrap list, then
3854 // we can skip adding one.
3855 if (aBuiltContainerItem || (!aBuilder->IsPartialUpdate() && !needsWrapList)) {
3856 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"
, 3856); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aList->Length() == 1"
")"); do { *((volatile int*)__null) = 3856; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3857 aList->Clear();
3858 return item;
3859 }
3860
3861 // If we're doing a partial build and we didn't need a wrap list
3862 // previously then we can try to work from there.
3863 if (aBuilder->IsPartialUpdate() &&
3864 !aFrame->HasDisplayItem(uint32_t(DisplayItemType::TYPE_CONTAINER))) {
3865 // If we now need a wrap list, we must previously have had no display items
3866 // or a single one belonging to this frame. Mark the item itself as
3867 // discarded so that RetainedDisplayListBuilder uses the ones we just built.
3868 // We don't want to mark the frame as modified as that would invalidate
3869 // positioned descendants that might be outside of this list, and might not
3870 // have been rebuilt this time.
3871 if (needsWrapList) {
3872 DiscardOldItems(aFrame);
3873 } else {
3874 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"
, 3874); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aList->Length() == 1"
")"); do { *((volatile int*)__null) = 3874; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3875 aList->Clear();
3876 return item;
3877 }
3878 }
3879
3880 // The last case we could try to handle is when we previously had a wrap list,
3881 // but no longer need it. Unfortunately we can't differentiate this case from
3882 // a partial build where other children exist but we just didn't build them
3883 // this time.
3884 // TODO:RetainedDisplayListBuilder's merge phase has the full list and
3885 // could strip them out.
3886
3887 return MakeDisplayItem<nsDisplayContainer>(aBuilder, aFrame, aContainerASR,
3888 aList);
3889}
3890
3891/**
3892 * Check if a frame should be visited for building display list.
3893 */
3894static bool DescendIntoChild(nsDisplayListBuilder* aBuilder,
3895 const nsIFrame* aChild, const nsRect& aVisible,
3896 const nsRect& aDirty) {
3897 if (aChild->HasAnyStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO)) {
3898 return true;
3899 }
3900
3901 // If the child is a scrollframe that we want to ignore, then we need
3902 // to descend into it because its scrolled child may intersect the dirty
3903 // area even if the scrollframe itself doesn't.
3904 if (aChild == aBuilder->GetIgnoreScrollFrame()) {
3905 return true;
3906 }
3907
3908 // There are cases where the "ignore scroll frame" on the builder is not set
3909 // correctly, and so we additionally want to catch cases where the child is
3910 // a root scrollframe and we are ignoring scrolling on the viewport.
3911 if (aChild == aBuilder->GetPresShellIgnoreScrollFrame()) {
3912 return true;
3913 }
3914
3915 nsRect overflow = aChild->InkOverflowRect();
3916
3917 // On mobile, there may be a dynamic toolbar. The root content document's
3918 // root scroll frame's ink overflow rect does not include the toolbar
3919 // height, but if the toolbar is hidden, we still want to be able to target
3920 // content underneath the toolbar, so expand the overflow rect here to
3921 // allow display list building to descend into the scroll frame.
3922 if (aBuilder->IsForEventDelivery() &&
3923 aChild == aChild->PresShell()->GetRootScrollContainerFrame() &&
3924 aChild->PresContext()->IsRootContentDocumentCrossProcess() &&
3925 aChild->PresContext()->HasDynamicToolbar()) {
3926 overflow.SizeTo(nsLayoutUtils::ExpandHeightForDynamicToolbar(
3927 aChild->PresContext(), overflow.Size()));
3928 }
3929
3930 if (aDirty.Intersects(overflow)) {
3931 return true;
3932 }
3933
3934 if (aChild->ForceDescendIntoIfVisible() && aVisible.Intersects(overflow)) {
3935 return true;
3936 }
3937
3938 if (aChild->IsTablePart()) {
3939 // Relative positioning and transforms can cause table parts to move, but we
3940 // will still paint the backgrounds for their ancestor parts under them at
3941 // their 'normal' position. That means that we must consider the overflow
3942 // rects at both positions.
3943
3944 // We convert the overflow rect into the nsTableFrame's coordinate
3945 // space, applying the normal position offset at each step. Then we
3946 // compare that against the builder's cached dirty rect in table
3947 // coordinate space.
3948 const nsIFrame* f = aChild;
3949 nsRect normalPositionOverflowRelativeToTable = overflow;
3950
3951 while (f->IsTablePart()) {
3952 normalPositionOverflowRelativeToTable += f->GetNormalPosition();
3953 f = f->GetParent();
3954 }
3955
3956 nsDisplayTableBackgroundSet* tableBGs = aBuilder->GetTableBackgroundSet();
3957 if (tableBGs && tableBGs->GetDirtyRect().Intersects(
3958 normalPositionOverflowRelativeToTable)) {
3959 return true;
3960 }
3961 }
3962
3963 return false;
3964}
3965
3966void nsIFrame::BuildDisplayListForSimpleChild(nsDisplayListBuilder* aBuilder,
3967 nsIFrame* aChild,
3968 const nsDisplayListSet& aLists) {
3969 // This is the shortcut for frames been handled along the common
3970 // path, the most common one of THE COMMON CASE mentioned later.
3971 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"
, 3971); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aChild->Type() != LayoutFrameType::Placeholder"
")"); do { *((volatile int*)__null) = 3971; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3972 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"
, 3974); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
") (" "It should be held for painting to window" ")"); do { *
((volatile int*)__null) = 3974; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
3973 !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"
, 3974); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
") (" "It should be held for painting to window" ")"); do { *
((volatile int*)__null) = 3974; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
3974 "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"
, 3974); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aBuilder->GetSelectedFramesOnly() && !aBuilder->GetIncludeAllOutOfFlows()"
") (" "It should be held for painting to window" ")"); do { *
((volatile int*)__null) = 3974; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
3975 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"
, 3975); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aChild->HasAnyStateBits(NS_FRAME_SIMPLE_DISPLAYLIST)"
")"); do { *((volatile int*)__null) = 3975; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3976
3977 const nsPoint offset = aChild->GetOffsetTo(this);
3978 const nsRect visible = aBuilder->GetVisibleRect() - offset;
3979 const nsRect dirty = aBuilder->GetDirtyRect() - offset;
3980
3981 if (!DescendIntoChild(aBuilder, aChild, visible, dirty)) {
3982 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)
;
3983 return;
3984 }
3985
3986 // Child cannot be transformed since it is not a stacking context.
3987 nsDisplayListBuilder::AutoBuildingDisplayList buildingForChild(
3988 aBuilder, aChild, visible, dirty, false);
3989
3990 UpdateCurrentHitTestInfo(aBuilder, aChild);
3991
3992 aChild->MarkAbsoluteFramesForDisplayList(aBuilder);
3993 aBuilder->AdjustWindowDraggingRegion(aChild);
3994 aBuilder->Check();
3995 aChild->BuildDisplayList(aBuilder, aLists);
3996 aChild->SetBuiltDisplayList(true);
3997 aBuilder->Check();
3998 aBuilder->DisplayCaret(aChild, aLists.Outlines());
3999}
4000
4001static bool ShouldSkipFrame(nsDisplayListBuilder* aBuilder,
4002 const nsIFrame* aFrame) {
4003 // If painting is restricted to just the background of the top level frame,
4004 // then we have nothing to do here.
4005 if (aBuilder->IsBackgroundOnly()) {
4006 return true;
4007 }
4008 if (aBuilder->IsForGenerateGlyphMask() &&
4009 (!aFrame->IsTextFrame() && aFrame->IsLeaf())) {
4010 return true;
4011 }
4012 // The placeholder frame should have the same content as the OOF frame.
4013 if (aBuilder->GetSelectedFramesOnly() &&
4014 (aFrame->IsLeaf() && !aFrame->IsSelected())) {
4015 return true;
4016 }
4017 static const nsFrameState skipFlags =
4018 (NS_FRAME_TOO_DEEP_IN_FRAME_TREE | NS_FRAME_IS_NONDISPLAY);
4019 if (aFrame->HasAnyStateBits(skipFlags)) {
4020 return true;
4021 }
4022 return aFrame->StyleUIReset()->mMozSubtreeHiddenOnlyVisually;
4023}
4024
4025void nsIFrame::BuildDisplayListForChild(nsDisplayListBuilder* aBuilder,
4026 nsIFrame* aChild,
4027 const nsDisplayListSet& aLists,
4028 DisplayChildFlags aFlags) {
4029 AutoCheckBuilder check(aBuilder);
4030#ifdef DEBUG1
4031 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)
;
4032 ScopeExit e(
4033 [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)
; });
4034#endif
4035
4036 if (ShouldSkipFrame(aBuilder, aChild)) {
4037 return;
4038 }
4039
4040 if (HidesContent()) {
4041 return;
4042 }
4043
4044 nsIFrame* child = aChild;
4045 auto* placeholder = child->IsPlaceholderFrame()
4046 ? static_cast<nsPlaceholderFrame*>(child)
4047 : nullptr;
4048 nsIFrame* childOrOutOfFlow =
4049 placeholder ? placeholder->GetOutOfFlowFrame() : child;
4050
4051 // If we're generating a display list for printing, include Link items for
4052 // frames that correspond to HTML link elements so that we can have active
4053 // links in saved PDF output. Note that the state of "within a link" is
4054 // set on the display-list builder, such that all descendants of the link
4055 // element will generate display-list links.
4056 // TODO: we should be able to optimize this so as to avoid creating links
4057 // for the same destination that entirely overlap each other, which adds
4058 // nothing useful to the final PDF.
4059 Maybe<nsDisplayListBuilder::Linkifier> linkifier;
4060 if (StaticPrefs::print_save_as_pdf_links_enabled() &&
4061 aBuilder->IsForPrinting()) {
4062 linkifier.emplace(aBuilder, childOrOutOfFlow, aLists.Content());
4063 linkifier->MaybeAppendLink(aBuilder, childOrOutOfFlow);
4064 }
4065
4066 nsIFrame* parent = childOrOutOfFlow->GetParent();
4067 const auto* parentDisplay = parent->StyleDisplay();
4068 const auto overflowClipAxes =
4069 parent->ShouldApplyOverflowClipping(parentDisplay);
4070
4071 const bool isPaintingToWindow = aBuilder->IsPaintingToWindow();
4072 const bool doingShortcut =
4073 isPaintingToWindow &&
4074 child->HasAnyStateBits(NS_FRAME_SIMPLE_DISPLAYLIST) &&
4075 // Animations may change the stacking context state.
4076 // ShouldApplyOverflowClipping is affected by the parent style, which does
4077 // not invalidate the NS_FRAME_SIMPLE_DISPLAYLIST bit.
4078 !(!overflowClipAxes.isEmpty() || child->MayHaveTransformAnimation() ||
4079 child->MayHaveOpacityAnimation());
4080
4081 if (aBuilder->IsForPainting()) {
4082 aBuilder->ClearWillChangeBudgetStatus(child);
4083 }
4084
4085 if (StaticPrefs::layout_css_scroll_anchoring_highlight()) {
4086 if (child->FirstContinuation()->IsScrollAnchor()) {
4087 nsRect bounds = child->GetContentRectRelativeToSelf() +
4088 aBuilder->ToReferenceFrame(child);
4089 nsDisplaySolidColor* color = MakeDisplayItem<nsDisplaySolidColor>(
4090 aBuilder, child, bounds, NS_RGBA(255, 0, 255, 64)((nscolor)(((64) << 24) | ((255) << 16) | ((0) <<
8) | (255)))
);
4091 if (color) {
4092 color->SetOverrideZIndex(INT32_MAX(2147483647));
4093 aLists.PositionedDescendants()->AppendToTop(color);
4094 }
4095 }
4096 }
4097
4098 if (doingShortcut) {
4099 BuildDisplayListForSimpleChild(aBuilder, child, aLists);
4100 return;
4101 }
4102
4103 // dirty rect in child-relative coordinates
4104 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"
, 4104); MOZ_PretendNoReturn(); } } while (0)
;
4105 const nsPoint offset = child->GetOffsetTo(this);
4106 nsRect visible = aBuilder->GetVisibleRect() - offset;
4107 nsRect dirty = aBuilder->GetDirtyRect() - offset;
4108
4109 nsDisplayListBuilder::OutOfFlowDisplayData* savedOutOfFlowData = nullptr;
4110 if (placeholder) {
4111 if (placeholder->HasAnyStateBits(PLACEHOLDER_FOR_TOPLAYER)) {
4112 // If the out-of-flow frame is in the top layer, the viewport frame
4113 // will paint it. Skip it here. Note that, only out-of-flow frames
4114 // with this property should be skipped, because non-HTML elements
4115 // may stop their children from being out-of-flow. Those frames
4116 // should still be handled in the normal in-flow path.
4117 return;
4118 }
4119
4120 child = childOrOutOfFlow;
4121 if (aBuilder->IsForPainting()) {
4122 aBuilder->ClearWillChangeBudgetStatus(child);
4123 }
4124
4125 // If 'child' is a pushed float then it's owned by a block that's not an
4126 // ancestor of the placeholder, and it will be painted by that block and
4127 // should not be painted through the placeholder. Also recheck
4128 // NS_FRAME_TOO_DEEP_IN_FRAME_TREE and NS_FRAME_IS_NONDISPLAY.
4129 static const nsFrameState skipFlags =
4130 (NS_FRAME_IS_PUSHED_FLOAT | NS_FRAME_TOO_DEEP_IN_FRAME_TREE |
4131 NS_FRAME_IS_NONDISPLAY);
4132 if (child->HasAnyStateBits(skipFlags) || nsLayoutUtils::IsPopup(child)) {
4133 return;
4134 }
4135
4136 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"
, 4136); AnnotateMozCrashReason("MOZ_ASSERT" "(" "child->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)"
")"); do { *((volatile int*)__null) = 4136; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4137 savedOutOfFlowData = nsDisplayListBuilder::GetOutOfFlowData(child);
4138
4139 if (aBuilder->GetIncludeAllOutOfFlows()) {
4140 visible = child->InkOverflowRect();
4141 dirty = child->InkOverflowRect();
4142 } else if (savedOutOfFlowData) {
4143 visible =
4144 savedOutOfFlowData->GetVisibleRectForFrame(aBuilder, child, &dirty);
4145 } else {
4146 // The out-of-flow frame did not intersect the dirty area. We may still
4147 // need to traverse into it, since it may contain placeholders we need
4148 // to enter to reach other out-of-flow frames that are visible.
4149 visible.SetEmpty();
4150 dirty.SetEmpty();
4151 }
4152 }
4153
4154 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"
, 4155); MOZ_PretendNoReturn(); } } while (0)
4155 "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"
, 4155); MOZ_PretendNoReturn(); } } while (0)
;
4156
4157 if (!DescendIntoChild(aBuilder, child, visible, dirty)) {
4158 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
)
;
4159 return;
4160 }
4161
4162 const bool isSVG = child->HasAnyStateBits(NS_FRAME_SVG_LAYOUT);
4163
4164 // This flag is raised if the control flow strays off the common path.
4165 // The common path is the most common one of THE COMMON CASE mentioned later.
4166 bool awayFromCommonPath = !isPaintingToWindow;
4167
4168 // true if this is a real or pseudo stacking context
4169 bool pseudoStackingContext =
4170 aFlags.contains(DisplayChildFlag::ForcePseudoStackingContext);
4171
4172 if (!pseudoStackingContext && !isSVG &&
4173 aFlags.contains(DisplayChildFlag::Inline) &&
4174 !child->IsLineParticipant()) {
4175 // child is a non-inline frame in an inline context, i.e.,
4176 // it acts like inline-block or inline-table. Therefore it is a
4177 // pseudo-stacking-context.
4178 pseudoStackingContext = true;
4179 }
4180
4181 const nsStyleDisplay* ourDisp = StyleDisplay();
4182 // Don't paint our children if the theme object is a leaf.
4183 if (IsThemed(ourDisp) && !PresContext()->Theme()->WidgetIsContainer(
4184 ourDisp->EffectiveAppearance())) {
4185 return;
4186 }
4187
4188 // Since we're now sure that we're adding this frame to the display list
4189 // (which means we're painting it, modulo occlusion), mark it as visible
4190 // within the displayport.
4191 if (isPaintingToWindow && child->TrackingVisibility() &&
4192 child->IsVisibleForPainting()) {
4193 child->PresShell()->EnsureFrameInApproximatelyVisibleList(child);
4194 awayFromCommonPath = true;
4195 }
4196
4197 // Child is composited if it's transformed, partially transparent, or has
4198 // SVG effects or a blend mode..
4199 const nsStyleDisplay* disp = child->StyleDisplay();
4200 const nsStyleEffects* effects = child->StyleEffects();
4201
4202 const bool isPositioned = disp->IsPositionedStyle();
4203 const bool isStackingContext =
4204 aFlags.contains(DisplayChildFlag::ForceStackingContext) ||
4205 child->IsStackingContext(disp, effects);
4206
4207 if (pseudoStackingContext || isStackingContext || isPositioned ||
4208 placeholder || (!isSVG && disp->IsFloating(child)) ||
4209 (isSVG && effects->mClip.IsRect() && IsSVGContentWithCSSClip(child))) {
4210 pseudoStackingContext = true;
4211 awayFromCommonPath = true;
4212 }
4213
4214 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"
, 4215); MOZ_PretendNoReturn(); } } while (0)
4215 "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"
, 4215); MOZ_PretendNoReturn(); } } while (0)
;
4216
4217 nsDisplayListBuilder::AutoBuildingDisplayList buildingForChild(
4218 aBuilder, child, visible, dirty);
4219
4220 UpdateCurrentHitTestInfo(aBuilder, child);
4221
4222 DisplayListClipState::AutoClipMultiple clipState(aBuilder);
4223 nsDisplayListBuilder::AutoCurrentActiveScrolledRootSetter asrSetter(aBuilder);
4224
4225 if (savedOutOfFlowData) {
4226 aBuilder->SetBuildingInvisibleItems(false);
4227
4228 clipState.SetClipChainForContainingBlockDescendants(
4229 savedOutOfFlowData->mContainingBlockClipChain);
4230 asrSetter.SetCurrentActiveScrolledRoot(
4231 savedOutOfFlowData->mContainingBlockActiveScrolledRoot);
4232 asrSetter.SetCurrentScrollParentId(savedOutOfFlowData->mScrollParentId);
4233 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"
, 4234); AnnotateMozCrashReason("MOZ_ASSERT" "(" "awayFromCommonPath"
") (" "It is impossible when savedOutOfFlowData is true" ")"
); do { *((volatile int*)__null) = 4234; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4234 "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"
, 4234); AnnotateMozCrashReason("MOZ_ASSERT" "(" "awayFromCommonPath"
") (" "It is impossible when savedOutOfFlowData is true" ")"
); do { *((volatile int*)__null) = 4234; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4235 } else if (HasAnyStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO) &&
4236 placeholder) {
4237 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"
, 4237); MOZ_PretendNoReturn(); } } while (0)
;
4238 // Every item we build from now until we descent into an out of flow that
4239 // does have saved out of flow data should be invisible. This state gets
4240 // restored when AutoBuildingDisplayList gets out of scope.
4241 aBuilder->SetBuildingInvisibleItems(true);
4242
4243 // If we have nested out-of-flow frames and the outer one isn't visible
4244 // then we won't have stored clip data for it. We can just clear the clip
4245 // instead since we know we won't render anything, and the inner out-of-flow
4246 // frame will setup the correct clip for itself.
4247 clipState.SetClipChainForContainingBlockDescendants(nullptr);
4248 }
4249
4250 // Setup clipping for the parent's overflow:clip,
4251 // or overflow:hidden on elements that don't support scrolling (and therefore
4252 // don't create nsHTML/XULScrollFrame). This clipping needs to not clip
4253 // anything directly rendered by the parent, only the rendering of its
4254 // children.
4255 // Don't use overflowClip to restrict the dirty rect, since some of the
4256 // descendants may not be clipped by it. Even if we end up with unnecessary
4257 // display items, they'll be pruned during ComputeVisibility.
4258 //
4259 // FIXME(emilio): Why can't we handle this more similarly to `clip` (on the
4260 // parent, rather than on the children)? Would ClipContentDescendants do what
4261 // we want?
4262 if (!overflowClipAxes.isEmpty()) {
4263 ApplyOverflowClipping(aBuilder, parent, overflowClipAxes, clipState);
4264 awayFromCommonPath = true;
4265 }
4266
4267 nsDisplayList list(aBuilder);
4268 nsDisplayList extraPositionedDescendants(aBuilder);
4269 const ActiveScrolledRoot* wrapListASR;
4270 bool builtContainerItem = false;
4271 if (isStackingContext) {
4272 // True stacking context.
4273 // For stacking contexts, BuildDisplayListForStackingContext handles
4274 // clipping and MarkAbsoluteFramesForDisplayList.
4275 nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
4276 child->BuildDisplayListForStackingContext(aBuilder, &list,
4277 &builtContainerItem);
4278 wrapListASR = contASRTracker.GetContainerASR();
4279 if (!aBuilder->IsReusingStackingContextItems() &&
4280 aBuilder->GetCaretFrame() == child) {
4281 builtContainerItem = false;
4282 }
4283 } else {
4284 Maybe<nsRect> clipPropClip =
4285 child->GetClipPropClipRect(disp, effects, child->GetSize());
4286 if (clipPropClip) {
4287 aBuilder->IntersectVisibleRect(*clipPropClip);
4288 aBuilder->IntersectDirtyRect(*clipPropClip);
4289 clipState.ClipContentDescendants(*clipPropClip +
4290 aBuilder->ToReferenceFrame(child));
4291 awayFromCommonPath = true;
4292 }
4293
4294 child->MarkAbsoluteFramesForDisplayList(aBuilder);
4295 child->SetBuiltDisplayList(true);
4296
4297 // Some SVG frames might change opacity without invalidating the frame, so
4298 // exclude them from the fast-path.
4299 if (!awayFromCommonPath && !child->IsSVGFrame()) {
4300 // The shortcut is available for the child for next time.
4301 child->AddStateBits(NS_FRAME_SIMPLE_DISPLAYLIST);
4302 }
4303
4304 if (!pseudoStackingContext) {
4305 // THIS IS THE COMMON CASE.
4306 // Not a pseudo or real stacking context. Do the simple thing and
4307 // return early.
4308 aBuilder->AdjustWindowDraggingRegion(child);
4309 aBuilder->Check();
4310 child->BuildDisplayList(aBuilder, aLists);
4311 aBuilder->Check();
4312 aBuilder->DisplayCaret(child, aLists.Outlines());
4313 return;
4314 }
4315
4316 // A pseudo-stacking context (e.g., a positioned element with z-index auto).
4317 // We allow positioned descendants of the child to escape to our parent
4318 // stacking context's positioned descendant list, because they might be
4319 // z-index:non-auto
4320 nsDisplayListCollection pseudoStack(aBuilder);
4321
4322 aBuilder->AdjustWindowDraggingRegion(child);
4323 nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
4324 aBuilder->Check();
4325 child->BuildDisplayList(aBuilder, pseudoStack);
4326 aBuilder->Check();
4327 if (aBuilder->DisplayCaret(child, pseudoStack.Outlines())) {
4328 builtContainerItem = false;
4329 }
4330 wrapListASR = contASRTracker.GetContainerASR();
4331
4332 list.AppendToTop(pseudoStack.BorderBackground());
4333 list.AppendToTop(pseudoStack.BlockBorderBackgrounds());
4334 list.AppendToTop(pseudoStack.Floats());
4335 list.AppendToTop(pseudoStack.Content());
4336 list.AppendToTop(pseudoStack.Outlines());
4337 extraPositionedDescendants.AppendToTop(pseudoStack.PositionedDescendants());
4338 }
4339
4340 buildingForChild.RestoreBuildingInvisibleItemsValue();
4341
4342 if (!list.IsEmpty()) {
4343 if (isPositioned || isStackingContext) {
4344 // Genuine stacking contexts, and positioned pseudo-stacking-contexts,
4345 // go in this level.
4346 nsDisplayItem* item = WrapInWrapList(aBuilder, child, &list, wrapListASR,
4347 builtContainerItem);
4348 if (isSVG) {
4349 aLists.Content()->AppendToTop(item);
4350 } else {
4351 aLists.PositionedDescendants()->AppendToTop(item);
4352 }
4353 } else if (!isSVG && disp->IsFloating(child)) {
4354 aLists.Floats()->AppendToTop(
4355 WrapInWrapList(aBuilder, child, &list, wrapListASR));
4356 } else {
4357 aLists.Content()->AppendToTop(&list);
4358 }
4359 }
4360 // We delay placing the positioned descendants of positioned frames to here,
4361 // because in the absence of z-index this is the correct order for them.
4362 // This doesn't affect correctness because the positioned descendants list
4363 // is sorted by z-order and content in BuildDisplayListForStackingContext,
4364 // but it means that sort routine needs to do less work.
4365 aLists.PositionedDescendants()->AppendToTop(&extraPositionedDescendants);
4366}
4367
4368void nsIFrame::MarkAbsoluteFramesForDisplayList(
4369 nsDisplayListBuilder* aBuilder) {
4370 if (IsAbsoluteContainer()) {
4371 aBuilder->MarkFramesForDisplayList(
4372 this, GetAbsoluteContainingBlock()->GetChildList());
4373 }
4374}
4375
4376nsresult nsIFrame::GetContentForEvent(const WidgetEvent* aEvent,
4377 nsIContent** aContent) {
4378 nsIFrame* f = nsLayoutUtils::GetNonGeneratedAncestor(this);
4379 *aContent = f->GetContent();
4380 NS_IF_ADDREF(*aContent)ns_if_addref(*aContent);
4381 return NS_OK;
4382}
4383
4384void nsIFrame::FireDOMEvent(const nsAString& aDOMEventName,
4385 nsIContent* aContent) {
4386 nsIContent* target = aContent ? aContent : GetContent();
4387
4388 if (target) {
4389 RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
4390 target, aDOMEventName, CanBubble::eYes, ChromeOnlyDispatch::eNo);
4391 DebugOnly<nsresult> rv = asyncDispatcher->PostDOMEvent();
4392 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"
, 4392); MOZ_PretendNoReturn(); } } while (0)
;
4393 }
4394}
4395
4396nsresult nsIFrame::HandleEvent(nsPresContext* aPresContext,
4397 WidgetGUIEvent* aEvent,
4398 nsEventStatus* aEventStatus) {
4399 if (aEvent->mMessage == eMouseMove) {
4400 // XXX If the second argument of HandleDrag() is WidgetMouseEvent,
4401 // the implementation becomes simpler.
4402 return HandleDrag(aPresContext, aEvent, aEventStatus);
4403 }
4404
4405 if ((aEvent->mClass == eMouseEventClass &&
4406 aEvent->AsMouseEvent()->mButton == MouseButton::ePrimary) ||
4407 aEvent->mClass == eTouchEventClass) {
4408 if (aEvent->mMessage == eMouseDown || aEvent->mMessage == eTouchStart) {
4409 HandlePress(aPresContext, aEvent, aEventStatus);
4410 } else if (aEvent->mMessage == eMouseUp || aEvent->mMessage == eTouchEnd) {
4411 HandleRelease(aPresContext, aEvent, aEventStatus);
4412 }
4413 return NS_OK;
4414 }
4415
4416 // When secondary buttion is down, we need to move selection to make users
4417 // possible to paste something at click point quickly.
4418 // When middle button is down, we need to just move selection and focus at
4419 // the clicked point. Note that even if middle click paste is not enabled,
4420 // Chrome moves selection at middle mouse button down. So, we should follow
4421 // the behavior for the compatibility.
4422 if (aEvent->mMessage == eMouseDown) {
4423 WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
4424 if (mouseEvent && (mouseEvent->mButton == MouseButton::eSecondary ||
4425 mouseEvent->mButton == MouseButton::eMiddle)) {
4426 if (*aEventStatus == nsEventStatus_eConsumeNoDefault) {
4427 return NS_OK;
4428 }
4429 return MoveCaretToEventPoint(aPresContext, mouseEvent, aEventStatus);
4430 }
4431 }
4432
4433 return NS_OK;
4434}
4435
4436nsresult nsIFrame::GetDataForTableSelection(
4437 const nsFrameSelection* aFrameSelection, mozilla::PresShell* aPresShell,
4438 WidgetMouseEvent* aMouseEvent, nsIContent** aParentContent,
4439 int32_t* aContentOffset, TableSelectionMode* aTarget) {
4440 if (!aFrameSelection || !aPresShell || !aMouseEvent || !aParentContent ||
4441 !aContentOffset || !aTarget)
4442 return NS_ERROR_NULL_POINTER;
4443
4444 *aParentContent = nullptr;
4445 *aContentOffset = 0;
4446 *aTarget = TableSelectionMode::None;
4447
4448 int16_t displaySelection = aPresShell->GetSelectionFlags();
4449
4450 bool selectingTableCells = aFrameSelection->IsInTableSelectionMode();
4451
4452 // DISPLAY_ALL means we're in an editor.
4453 // If already in cell selection mode,
4454 // continue selecting with mouse drag or end on mouse up,
4455 // or when using shift key to extend block of cells
4456 // (Mouse down does normal selection unless Ctrl/Cmd is pressed)
4457 bool doTableSelection =
4458 displaySelection == nsISelectionDisplay::DISPLAY_ALL &&
4459 selectingTableCells &&
4460 (aMouseEvent->mMessage == eMouseMove ||
4461 (aMouseEvent->mMessage == eMouseUp &&
4462 aMouseEvent->mButton == MouseButton::ePrimary) ||
4463 aMouseEvent->IsShift());
4464
4465 if (!doTableSelection) {
4466 // In Browser, special 'table selection' key must be pressed for table
4467 // selection or when just Shift is pressed and we're already in table/cell
4468 // selection mode
4469#ifdef XP_MACOSX
4470 doTableSelection = aMouseEvent->IsMeta() ||
4471 (aMouseEvent->IsShift() && selectingTableCells);
4472#else
4473 doTableSelection = aMouseEvent->IsControl() ||
4474 (aMouseEvent->IsShift() && selectingTableCells);
4475#endif
4476 }
4477 if (!doTableSelection) return NS_OK;
4478
4479 // Get the cell frame or table frame (or parent) of the current content node
4480 nsIFrame* frame = this;
4481 bool foundCell = false;
4482 bool foundTable = false;
4483
4484 // Get the limiting node to stop parent frame search
4485 nsIContent* limiter = aFrameSelection->GetLimiter();
4486
4487 // If our content node is an ancestor of the limiting node,
4488 // we should stop the search right now.
4489 if (limiter && limiter->IsInclusiveDescendantOf(GetContent())) return NS_OK;
4490
4491 // We don't initiate row/col selection from here now,
4492 // but we may in future
4493 // bool selectColumn = false;
4494 // bool selectRow = false;
4495
4496 while (frame) {
4497 // Check for a table cell by querying to a known CellFrame interface
4498 nsITableCellLayout* cellElement = do_QueryFrame(frame);
4499 if (cellElement) {
4500 foundCell = true;
4501 // TODO: If we want to use proximity to top or left border
4502 // for row and column selection, this is the place to do it
4503 break;
4504 } else {
4505 // If not a cell, check for table
4506 // This will happen when starting frame is the table or child of a table,
4507 // such as a row (we were inbetween cells or in table border)
4508 nsTableWrapperFrame* tableFrame = do_QueryFrame(frame);
4509 if (tableFrame) {
4510 foundTable = true;
4511 // TODO: How can we select row when along left table edge
4512 // or select column when along top edge?
4513 break;
4514 } else {
4515 frame = frame->GetParent();
4516 // Stop if we have hit the selection's limiting content node
4517 if (frame && frame->GetContent() == limiter) break;
4518 }
4519 }
4520 }
4521 // We aren't in a cell or table
4522 if (!foundCell && !foundTable) return NS_OK;
4523
4524 nsIContent* tableOrCellContent = frame->GetContent();
4525 if (!tableOrCellContent) return NS_ERROR_FAILURE;
4526
4527 nsCOMPtr<nsIContent> parentContent = tableOrCellContent->GetParent();
4528 if (!parentContent) return NS_ERROR_FAILURE;
4529
4530 const int32_t offset =
4531 parentContent->ComputeIndexOf_Deprecated(tableOrCellContent);
4532 // Not likely?
4533 if (offset < 0) {
4534 return NS_ERROR_FAILURE;
4535 }
4536
4537 // Everything is OK -- set the return values
4538 parentContent.forget(aParentContent);
4539
4540 *aContentOffset = offset;
4541
4542#if 0
4543 if (selectRow)
4544 *aTarget = TableSelectionMode::Row;
4545 else if (selectColumn)
4546 *aTarget = TableSelectionMode::Column;
4547 else
4548#endif
4549 if (foundCell) {
4550 *aTarget = TableSelectionMode::Cell;
4551 } else if (foundTable) {
4552 *aTarget = TableSelectionMode::Table;
4553 }
4554
4555 return NS_OK;
4556}
4557
4558static bool IsEditingHost(const nsIFrame* aFrame) {
4559 nsIContent* content = aFrame->GetContent();
4560 return content && content->IsEditingHost();
4561}
4562
4563static StyleUserSelect UsedUserSelect(const nsIFrame* aFrame) {
4564 if (aFrame->IsGeneratedContentFrame()) {
4565 return StyleUserSelect::None;
4566 }
4567
4568 // Per https://drafts.csswg.org/css-ui-4/#content-selection:
4569 //
4570 // The used value is the same as the computed value, except:
4571 //
4572 // 1 - on editable elements where the used value is always 'contain'
4573 // regardless of the computed value
4574 // 2 - when the computed value is auto, in which case the used value is one
4575 // of the other values...
4576 //
4577 // See https://github.com/w3c/csswg-drafts/issues/3344 to see why we do this
4578 // at used-value time instead of at computed-value time.
4579
4580 if (aFrame->IsTextInputFrame() || IsEditingHost(aFrame)) {
4581 // We don't implement 'contain' itself, but we make 'text' behave as
4582 // 'contain' for contenteditable and <input> / <textarea> elements anyway so
4583 // this is ok.
4584 return StyleUserSelect::Text;
4585 }
4586
4587 auto style = aFrame->Style()->UserSelect();
4588 if (style != StyleUserSelect::Auto) {
4589 return style;
4590 }
4591
4592 auto* parent = nsLayoutUtils::GetParentOrPlaceholderFor(aFrame);
4593 return parent ? UsedUserSelect(parent) : StyleUserSelect::Text;
4594}
4595
4596bool nsIFrame::IsSelectable(StyleUserSelect* aSelectStyle) const {
4597 auto style = UsedUserSelect(this);
4598 if (aSelectStyle) {
4599 *aSelectStyle = style;
4600 }
4601 return style != StyleUserSelect::None;
4602}
4603
4604bool nsIFrame::ShouldHaveLineIfEmpty() const {
4605 if (Style()->IsPseudoOrAnonBox() &&
4606 Style()->GetPseudoType() != PseudoStyleType::scrolledContent) {
4607 return false;
4608 }
4609 return IsEditingHost(this);
4610}
4611
4612/**
4613 * Handles the Mouse Press Event for the frame
4614 */
4615NS_IMETHODIMPnsresult
4616nsIFrame::HandlePress(nsPresContext* aPresContext, WidgetGUIEvent* aEvent,
4617 nsEventStatus* aEventStatus) {
4618 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"
, 4618); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4619 if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
4620 return NS_OK;
4621 }
4622
4623 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"
, 4623); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4624 if (aEvent->mClass == eTouchEventClass) {
4625 return NS_OK;
4626 }
4627
4628 return MoveCaretToEventPoint(aPresContext, aEvent->AsMouseEvent(),
4629 aEventStatus);
4630}
4631
4632nsresult nsIFrame::MoveCaretToEventPoint(nsPresContext* aPresContext,
4633 WidgetMouseEvent* aMouseEvent,
4634 nsEventStatus* aEventStatus) {
4635 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"
, 4635); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPresContext"
")"); do { *((volatile int*)__null) = 4635; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4636 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"
, 4636); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aMouseEvent"
")"); do { *((volatile int*)__null) = 4636; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4637 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"
, 4637); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aMouseEvent->mMessage == eMouseDown"
")"); do { *((volatile int*)__null) = 4637; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4638 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"
, 4638); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aEventStatus"
")"); do { *((volatile int*)__null) = 4638; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4639 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"
, 4639); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsEventStatus_eConsumeNoDefault != *aEventStatus"
")"); do { *((volatile int*)__null) = 4639; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4640
4641 mozilla::PresShell* presShell = aPresContext->GetPresShell();
4642 if (!presShell) {
4643 return NS_ERROR_FAILURE;
4644 }
4645
4646 // We often get out of sync state issues with mousedown events that
4647 // get interrupted by alerts/dialogs.
4648 // Check with the ESM to see if we should process this one
4649 if (!aPresContext->EventStateManager()->EventStatusOK(aMouseEvent)) {
4650 return NS_OK;
4651 }
4652
4653 const nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
4654 aMouseEvent, RelativeTo{this});
4655
4656 // When not using `alt`, and clicking on a draggable, but non-editable
4657 // element, don't do anything, and let d&d handle the event.
4658 //
4659 // See bug 48876, bug 388659 and bug 55921 for context here.
4660 //
4661 // FIXME(emilio): The .Contains(pt) check looks a bit fishy. When would it be
4662 // false given we're the event target? If it is needed, why not checking the
4663 // actual draggable node rect instead?
4664 if (!aMouseEvent->IsAlt() && GetRectRelativeToSelf().Contains(pt)) {
4665 for (nsIContent* content = mContent; content;
4666 content = content->GetFlattenedTreeParent()) {
4667 if (nsContentUtils::ContentIsDraggable(content) &&
4668 !content->IsEditable()) {
4669 return NS_OK;
4670 }
4671 }
4672 }
4673
4674 // If we are in Navigator and the click is in a draggable node, we don't want
4675 // to start selection because we don't want to interfere with a potential
4676 // drag of said node and steal all its glory.
4677 const bool isEditor =
4678 presShell->GetSelectionFlags() == nsISelectionDisplay::DISPLAY_ALL;
4679
4680 // Don't do something if it's middle button down event.
4681 const bool isPrimaryButtonDown =
4682 aMouseEvent->mButton == MouseButton::ePrimary;
4683
4684 // check whether style allows selection
4685 // if not, don't tell selection the mouse event even occurred.
4686 StyleUserSelect selectStyle;
4687 // check for select: none
4688 if (!IsSelectable(&selectStyle)) {
4689 return NS_OK;
4690 }
4691
4692 if (isPrimaryButtonDown) {
4693 // If the mouse is dragged outside the nearest enclosing scrollable area
4694 // while making a selection, the area will be scrolled. To do this, capture
4695 // the mouse on the nearest scroll container frame. If there isn't a scroll
4696 // container frame, or something else is already capturing the mouse,
4697 // there's no reason to capture.
4698 if (!PresShell::GetCapturingContent()) {
4699 ScrollContainerFrame* scrollContainerFrame =
4700 nsLayoutUtils::GetNearestScrollContainerFrame(
4701 this, nsLayoutUtils::SCROLLABLE_SAME_DOC |
4702 nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
4703 if (scrollContainerFrame) {
4704 nsIFrame* capturingFrame = scrollContainerFrame;
4705 PresShell::SetCapturingContent(capturingFrame->GetContent(),
4706 CaptureFlags::IgnoreAllowedState);
4707 }
4708 }
4709 }
4710
4711 // XXX This is screwy; it really should use the selection frame, not the
4712 // event frame
4713 const nsFrameSelection* frameselection =
4714 selectStyle == StyleUserSelect::Text ? GetConstFrameSelection()
4715 : presShell->ConstFrameSelection();
4716
4717 if (!frameselection || frameselection->GetDisplaySelection() ==
4718 nsISelectionController::SELECTION_OFF) {
4719 return NS_OK; // nothing to do we cannot affect selection from here
4720 }
4721
4722#ifdef XP_MACOSX
4723 // If Control key is pressed on macOS, it should be treated as right click.
4724 // So, don't change selection.
4725 if (aMouseEvent->IsControl()) {
4726 return NS_OK;
4727 }
4728 const bool control = aMouseEvent->IsMeta();
4729#else
4730 const bool control = aMouseEvent->IsControl();
4731#endif
4732
4733 RefPtr<nsFrameSelection> fc = const_cast<nsFrameSelection*>(frameselection);
4734 if (isPrimaryButtonDown && aMouseEvent->mClickCount > 1) {
4735 // These methods aren't const but can't actually delete anything,
4736 // so no need for AutoWeakFrame.
4737 fc->SetDragState(true);
4738 return HandleMultiplePress(aPresContext, aMouseEvent, aEventStatus,
4739 control);
4740 }
4741
4742 ContentOffsets offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN);
4743
4744 if (!offsets.content) {
4745 return NS_ERROR_FAILURE;
4746 }
4747
4748 const bool isSecondaryButton =
4749 aMouseEvent->mButton == MouseButton::eSecondary;
4750 if (isSecondaryButton &&
4751 !MovingCaretToEventPointAllowedIfSecondaryButtonEvent(
4752 *frameselection, *aMouseEvent, *offsets.content,
4753 // When we collapse selection in nsFrameSelection::TakeFocus,
4754 // we always collapse selection to the start offset. Therefore,
4755 // we can ignore the end offset here. E.g., when an <img> is clicked,
4756 // set the primary offset to after it, but the the secondary offset
4757 // may be before it, see OffsetsForSingleFrame for the detail.
4758 offsets.StartOffset())) {
4759 return NS_OK;
4760 }
4761
4762 if (aMouseEvent->mMessage == eMouseDown &&
4763 aMouseEvent->mButton == MouseButton::eMiddle &&
4764 !offsets.content->IsEditable()) {
4765 // However, some users don't like the Chrome compatible behavior of
4766 // middle mouse click. They want to keep selection after starting
4767 // autoscroll. However, the selection change is important for middle
4768 // mouse past. Therefore, we should allow users to take the traditional
4769 // behavior back by themselves unless middle click paste is enabled or
4770 // autoscrolling is disabled.
4771 if (!Preferences::GetBool("middlemouse.paste", false) &&
4772 Preferences::GetBool("general.autoScroll", false) &&
4773 Preferences::GetBool("general.autoscroll.prevent_to_collapse_selection_"
4774 "by_middle_mouse_down",
4775 false)) {
4776 return NS_OK;
4777 }
4778 }
4779
4780 if (isPrimaryButtonDown) {
4781 // Let Ctrl/Cmd + left mouse down do table selection instead of drag
4782 // initiation.
4783 nsCOMPtr<nsIContent> parentContent;
4784 int32_t contentOffset;
4785 TableSelectionMode target;
4786 nsresult rv = GetDataForTableSelection(
4787 frameselection, presShell, aMouseEvent, getter_AddRefs(parentContent),
4788 &contentOffset, &target);
4789 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && parentContent) {
4790 fc->SetDragState(true);
4791 return fc->HandleTableSelection(parentContent, contentOffset, target,
4792 aMouseEvent);
4793 }
4794 }
4795
4796 fc->SetDelayedCaretData(0);
4797
4798 if (isPrimaryButtonDown) {
4799 // Check if any part of this frame is selected, and if the user clicked
4800 // inside the selected region, and if it's the left button. If so, we delay
4801 // starting a new selection since the user may be trying to drag the
4802 // selected region to some other app.
4803
4804 if (GetContent() && GetContent()->IsMaybeSelected()) {
4805 bool inSelection = false;
4806 UniquePtr<SelectionDetails> details = frameselection->LookUpSelection(
4807 offsets.content, 0, offsets.EndOffset(), false);
4808
4809 //
4810 // If there are any details, check to see if the user clicked
4811 // within any selected region of the frame.
4812 //
4813
4814 for (SelectionDetails* curDetail = details.get(); curDetail;
4815 curDetail = curDetail->mNext.get()) {
4816 //
4817 // If the user clicked inside a selection, then just
4818 // return without doing anything. We will handle placing
4819 // the caret later on when the mouse is released. We ignore
4820 // the spellcheck, find and url formatting selections.
4821 //
4822 if (curDetail->mSelectionType != SelectionType::eSpellCheck &&
4823 curDetail->mSelectionType != SelectionType::eFind &&
4824 curDetail->mSelectionType != SelectionType::eURLSecondary &&
4825 curDetail->mSelectionType != SelectionType::eURLStrikeout &&
4826 curDetail->mSelectionType != SelectionType::eHighlight &&
4827 curDetail->mStart <= offsets.StartOffset() &&
4828 offsets.EndOffset() <= curDetail->mEnd) {
4829 inSelection = true;
4830 }
4831 }
4832
4833 if (inSelection) {
4834 fc->SetDragState(false);
4835 fc->SetDelayedCaretData(aMouseEvent);
4836 return NS_OK;
4837 }
4838 }
4839
4840 fc->SetDragState(true);
4841 }
4842
4843 // Do not touch any nsFrame members after this point without adding
4844 // weakFrame checks.
4845 const nsFrameSelection::FocusMode focusMode = [&]() {
4846 // If "Shift" and "Ctrl" are both pressed, "Shift" is given precedence. This
4847 // mimics the old behaviour.
4848 const bool isShift =
4849 aMouseEvent->IsShift() &&
4850 // If Shift + secondary button press shoud open context menu without a
4851 // contextmenu event, user wants to open context menu like as a
4852 // secondary button press without Shift key.
4853 !(isSecondaryButton &&
4854 StaticPrefs::dom_event_contextmenu_shift_suppresses_event());
4855 if (isShift) {
4856 // If clicked in a link when focused content is editable, we should
4857 // collapse selection in the link for compatibility with Blink.
4858 if (isEditor) {
4859 for (Element* element : mContent->InclusiveAncestorsOfType<Element>()) {
4860 if (element->IsLink()) {
4861 return nsFrameSelection::FocusMode::kCollapseToNewPoint;
4862 }
4863 }
4864 }
4865 return nsFrameSelection::FocusMode::kExtendSelection;
4866 }
4867
4868 if (isPrimaryButtonDown && control) {
4869 return nsFrameSelection::FocusMode::kMultiRangeSelection;
4870 }
4871
4872 return nsFrameSelection::FocusMode::kCollapseToNewPoint;
4873 }();
4874
4875 nsresult rv = fc->HandleClick(
4876 MOZ_KnownLive(offsets.content)(offsets.content) /* bug 1636889 */, offsets.StartOffset(),
4877 offsets.EndOffset(), focusMode, offsets.associate);
4878 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4879 return rv;
4880 }
4881
4882 // We don't handle mouse button up if it's middle button.
4883 if (isPrimaryButtonDown && offsets.offset != offsets.secondaryOffset) {
4884 fc->MaintainSelection();
4885 }
4886
4887 if (isPrimaryButtonDown && isEditor && !aMouseEvent->IsShift() &&
4888 (offsets.EndOffset() - offsets.StartOffset()) == 1) {
4889 // A single node is selected and we aren't extending an existing selection,
4890 // which means the user clicked directly on an object (either
4891 // `user-select: all` or a non-text node without children). Therefore,
4892 // disable selection extension during mouse moves.
4893 // XXX This is a bit hacky; shouldn't editor be able to deal with this?
4894 fc->SetDragState(false);
4895 }
4896
4897 return NS_OK;
4898}
4899
4900bool nsIFrame::MovingCaretToEventPointAllowedIfSecondaryButtonEvent(
4901 const nsFrameSelection& aFrameSelection,
4902 WidgetMouseEvent& aSecondaryButtonEvent,
4903 const nsIContent& aContentAtEventPoint, int32_t aOffsetAtEventPoint) const {
4904 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"
, 4904); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aSecondaryButtonEvent.mButton == MouseButton::eSecondary"
")"); do { *((volatile int*)__null) = 4904; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4905
4906 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"
, 4906)
) {
4907 return false;
4908 }
4909
4910 const bool contentIsEditable = aContentAtEventPoint.IsEditable();
4911 const TextControlElement* const contentAsTextControl =
4912 TextControlElement::FromNodeOrNull(
4913 aContentAtEventPoint.IsTextControlElement()
4914 ? &aContentAtEventPoint
4915 : aContentAtEventPoint.GetClosestNativeAnonymousSubtreeRoot());
4916 if (Selection* selection =
4917 aFrameSelection.GetSelection(SelectionType::eNormal)) {
4918 const bool selectionIsCollapsed =
4919 selection->AreNormalAndCrossShadowBoundaryRangesCollapsed();
4920 // If right click in a selection range, we should not collapse
4921 // selection.
4922 if (!selectionIsCollapsed && nsContentUtils::IsPointInSelection(
4923 *selection, aContentAtEventPoint,
4924 static_cast<uint32_t>(aOffsetAtEventPoint),
4925 true /* aAllowCrossShadowBoundary */)) {
4926 return false;
4927 }
4928 const bool wantToPreventMoveCaret =
4929 StaticPrefs::
4930 ui_mouse_right_click_move_caret_stop_if_in_focused_editable_node() &&
4931 selectionIsCollapsed && (contentIsEditable || contentAsTextControl);
4932 const bool wantToPreventCollapseSelection =
4933 StaticPrefs::
4934 ui_mouse_right_click_collapse_selection_stop_if_non_collapsed_selection() &&
4935 !selectionIsCollapsed;
4936 if (wantToPreventMoveCaret || wantToPreventCollapseSelection) {
4937 // If currently selection is limited in an editing host, we should not
4938 // collapse selection nor move caret if the clicked point is in the
4939 // ancestor limiter. Otherwise, this mouse click moves focus from the
4940 // editing host to different one or blur the editing host. In this case,
4941 // we need to update selection because keeping current selection in the
4942 // editing host looks like it's not blurred.
4943 // FIXME: If the active editing host is the document element, editor
4944 // does not set ancestor limiter properly. Fix it in the editor side.
4945 if (nsIContent* ancestorLimiter = selection->GetAncestorLimiter()) {
4946 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"
, 4946); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ancestorLimiter->IsEditable()"
")"); do { *((volatile int*)__null) = 4946; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4947 return !aContentAtEventPoint.IsInclusiveDescendantOf(ancestorLimiter);
4948 }
4949 }
4950 // If selection is editable and `stop_if_in_focused_editable_node` pref is
4951 // set to true, user does not want to move caret to right click place if
4952 // clicked in the focused text control element.
4953 if (wantToPreventMoveCaret && contentAsTextControl &&
4954 contentAsTextControl == nsFocusManager::GetFocusedElementStatic()) {
4955 return false;
4956 }
4957 // If currently selection is not limited in an editing host, we should
4958 // collapse selection only when this click moves focus to an editing
4959 // host because we need to update selection in this case.
4960 if (wantToPreventCollapseSelection && !contentIsEditable) {
4961 return false;
4962 }
4963 }
4964
4965 return !StaticPrefs::
4966 ui_mouse_right_click_collapse_selection_stop_if_non_editable_node() ||
4967 // The user does not want to collapse selection into non-editable
4968 // content by a right button click.
4969 contentIsEditable ||
4970 // Treat clicking in a text control as always clicked on editable
4971 // content because we want a hack only for clicking in normal text
4972 // nodes which is outside any editing hosts.
4973 contentAsTextControl;
4974}
4975
4976nsresult nsIFrame::SelectByTypeAtPoint(nsPresContext* aPresContext,
4977 const nsPoint& aPoint,
4978 nsSelectionAmount aBeginAmountType,
4979 nsSelectionAmount aEndAmountType,
4980 uint32_t aSelectFlags) {
4981 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"
, 4981); return NS_ERROR_INVALID_POINTER; } } while (false)
;
4982
4983 // No point in selecting if selection is turned off
4984 if (DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF) {
4985 return NS_OK;
4986 }
4987
4988 ContentOffsets offsets = GetContentOffsetsFromPoint(
4989 aPoint, SKIP_HIDDEN | IGNORE_NATIVE_ANONYMOUS_SUBTREE);
4990 if (!offsets.content) {
4991 return NS_ERROR_FAILURE;
4992 }
4993
4994 uint32_t offset;
4995 nsIFrame* frame = SelectionMovementUtils::GetFrameForNodeOffset(
4996 offsets.content, offsets.offset, offsets.associate, &offset);
4997 if (!frame) {
4998 return NS_ERROR_FAILURE;
4999 }
5000 return frame->PeekBackwardAndForward(
5001 aBeginAmountType, aEndAmountType, static_cast<int32_t>(offset),
5002 aBeginAmountType != eSelectWord, aSelectFlags);
5003}
5004
5005/**
5006 * Multiple Mouse Press -- line or paragraph selection -- for the frame.
5007 * Wouldn't it be nice if this didn't have to be hardwired into Frame code?
5008 */
5009NS_IMETHODIMPnsresult
5010nsIFrame::HandleMultiplePress(nsPresContext* aPresContext,
5011 WidgetGUIEvent* aEvent,
5012 nsEventStatus* aEventStatus, bool aControlHeld) {
5013 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"
, 5013); return NS_ERROR_INVALID_POINTER; } } while (false)
;
5014 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"
, 5014); return NS_ERROR_INVALID_POINTER; } } while (false)
;
5015
5016 if (nsEventStatus_eConsumeNoDefault == *aEventStatus ||
5017 DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF) {
5018 return NS_OK;
5019 }
5020
5021 // Find out whether we're doing line or paragraph selection.
5022 // If browser.triple_click_selects_paragraph is true, triple-click selects
5023 // paragraph. Otherwise, triple-click selects line, and quadruple-click
5024 // selects paragraph (on platforms that support quadruple-click).
5025 nsSelectionAmount beginAmount, endAmount;
5026 WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
5027 if (!mouseEvent) {
5028 return NS_OK;
5029 }
5030
5031 if (mouseEvent->mClickCount == 4) {
5032 beginAmount = endAmount = eSelectParagraph;
5033 } else if (mouseEvent->mClickCount == 3) {
5034 if (Preferences::GetBool("browser.triple_click_selects_paragraph")) {
5035 beginAmount = endAmount = eSelectParagraph;
5036 } else {
5037 beginAmount = eSelectBeginLine;
5038 endAmount = eSelectEndLine;
5039 }
5040 } else if (mouseEvent->mClickCount == 2) {
5041 // We only want inline frames; PeekBackwardAndForward dislikes blocks
5042 beginAmount = endAmount = eSelectWord;
5043 } else {
5044 return NS_OK;
5045 }
5046
5047 nsPoint relPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(
5048 mouseEvent, RelativeTo{this});
5049 return SelectByTypeAtPoint(aPresContext, relPoint, beginAmount, endAmount,
5050 (aControlHeld ? SELECT_ACCUMULATE : 0));
5051}
5052
5053nsresult nsIFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack,
5054 nsSelectionAmount aAmountForward,
5055 int32_t aStartPos, bool aJumpLines,
5056 uint32_t aSelectFlags) {
5057 nsIFrame* baseFrame = this;
5058 int32_t baseOffset = aStartPos;
5059 nsresult rv;
5060
5061 PeekOffsetOptions peekOffsetOptions{PeekOffsetOption::StopAtScroller};
5062 if (aJumpLines) {
5063 peekOffsetOptions += PeekOffsetOption::JumpLines;
5064 }
5065
5066 if (aAmountBack == eSelectWord) {
5067 // To avoid selecting the previous word when at start of word,
5068 // first move one character forward.
5069 PeekOffsetStruct pos(eSelectCharacter, eDirNext, aStartPos, nsPoint(0, 0),
5070 peekOffsetOptions);
5071 rv = PeekOffset(&pos);
5072 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
5073 baseFrame = pos.mResultFrame;
5074 baseOffset = pos.mContentOffset;
5075 }
5076 }
5077
5078 // Search backward for a boundary.
5079 PeekOffsetStruct startpos(aAmountBack, eDirPrevious, baseOffset,
5080 nsPoint(0, 0), peekOffsetOptions);
5081 rv = baseFrame->PeekOffset(&startpos);
5082 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5083 return rv;
5084 }
5085
5086 // If the backward search stayed within the same frame, search forward from
5087 // that position for the end boundary; but if it crossed out to a sibling or
5088 // ancestor, start from the original position.
5089 if (startpos.mResultFrame == baseFrame) {
5090 baseOffset = startpos.mContentOffset;
5091 } else {
5092 baseFrame = this;
5093 baseOffset = aStartPos;
5094 }
5095
5096 PeekOffsetStruct endpos(aAmountForward, eDirNext, baseOffset, nsPoint(0, 0),
5097 peekOffsetOptions);
5098 rv = baseFrame->PeekOffset(&endpos);
5099 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5100 return rv;
5101 }
5102
5103 // Keep frameSelection alive.
5104 RefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
5105
5106 const nsFrameSelection::FocusMode focusMode =
5107 (aSelectFlags & SELECT_ACCUMULATE)
5108 ? nsFrameSelection::FocusMode::kMultiRangeSelection
5109 : nsFrameSelection::FocusMode::kCollapseToNewPoint;
5110 rv = frameSelection->HandleClick(
5111 MOZ_KnownLive(startpos.mResultContent)(startpos.mResultContent) /* bug 1636889 */,
5112 startpos.mContentOffset, startpos.mContentOffset, focusMode,
5113 CaretAssociationHint::After);
5114 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5115 return rv;
5116 }
5117
5118 rv = frameSelection->HandleClick(
5119 MOZ_KnownLive(endpos.mResultContent)(endpos.mResultContent) /* bug 1636889 */,
5120 endpos.mContentOffset, endpos.mContentOffset,
5121 nsFrameSelection::FocusMode::kExtendSelection,
5122 CaretAssociationHint::Before);
5123 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5124 return rv;
5125 }
5126 if (aAmountBack == eSelectWord) {
5127 frameSelection->SetClickSelectionType(ClickSelectionType::Double);
5128 } else if (aAmountBack == eSelectParagraph) {
5129 frameSelection->SetClickSelectionType(ClickSelectionType::Triple);
5130 }
5131
5132 // maintain selection
5133 return frameSelection->MaintainSelection(aAmountBack);
5134}
5135
5136NS_IMETHODIMPnsresult nsIFrame::HandleDrag(nsPresContext* aPresContext,
5137 WidgetGUIEvent* aEvent,
5138 nsEventStatus* aEventStatus) {
5139 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"
, 5140); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aEvent->mClass == eMouseEventClass"
") (" "HandleDrag can only handle mouse event" ")"); do { *(
(volatile int*)__null) = 5140; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
5140 "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"
, 5140); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aEvent->mClass == eMouseEventClass"
") (" "HandleDrag can only handle mouse event" ")"); do { *(
(volatile int*)__null) = 5140; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
5141
5142 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"
, 5142); return NS_ERROR_INVALID_POINTER; } } while (false)
;
5143
5144 RefPtr<nsFrameSelection> frameselection = GetFrameSelection();
5145 if (!frameselection) {
5146 return NS_OK;
5147 }
5148
5149 bool mouseDown = frameselection->GetDragState();
5150 if (!mouseDown) {
5151 return NS_OK;
5152 }
5153
5154 nsIFrame* scrollbar =
5155 nsLayoutUtils::GetClosestFrameOfType(this, LayoutFrameType::Scrollbar);
5156 if (!scrollbar) {
5157 // XXX Do we really need to exclude non-selectable content here?
5158 // GetContentOffsetsFromPoint can handle it just fine, although some
5159 // other stuff might not like it.
5160 // NOTE: DetermineDisplaySelection() returns SELECTION_OFF for
5161 // non-selectable frames.
5162 if (DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF) {
5163 return NS_OK;
5164 }
5165 }
5166
5167 frameselection->StopAutoScrollTimer();
5168
5169 // Check if we are dragging in a table cell
5170 nsCOMPtr<nsIContent> parentContent;
5171 int32_t contentOffset;
5172 TableSelectionMode target;
5173 WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
5174 mozilla::PresShell* presShell = aPresContext->PresShell();
5175 nsresult result;
5176 result = GetDataForTableSelection(frameselection, presShell, mouseEvent,
5177 getter_AddRefs(parentContent),
5178 &contentOffset, &target);
5179
5180 AutoWeakFrame weakThis = this;
5181 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) && parentContent) {
5182 result = frameselection->HandleTableSelection(parentContent, contentOffset,
5183 target, mouseEvent);
5184 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"
, 5184)
) {
5185 return result;
5186 }
5187 } else {
5188 nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent,
5189 RelativeTo{this});
5190 frameselection->HandleDrag(this, pt);
5191 }
5192
5193 // The frameselection object notifies selection listeners synchronously above
5194 // which might have killed us.
5195 if (!weakThis.IsAlive()) {
5196 return NS_OK;
5197 }
5198
5199 // Get the nearest scroll container frame.
5200 ScrollContainerFrame* scrollContainerFrame =
5201 nsLayoutUtils::GetNearestScrollContainerFrame(
5202 this, nsLayoutUtils::SCROLLABLE_SAME_DOC |
5203 nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
5204
5205 if (scrollContainerFrame) {
5206 nsIFrame* capturingFrame = scrollContainerFrame->GetScrolledFrame();
5207 if (capturingFrame) {
5208 nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
5209 mouseEvent, RelativeTo{capturingFrame});
5210 frameselection->StartAutoScrollTimer(capturingFrame, pt, 30);
5211 }
5212 }
5213
5214 return NS_OK;
5215}
5216
5217/**
5218 * This static method handles part of the nsIFrame::HandleRelease in a way
5219 * which doesn't rely on the nsFrame object to stay alive.
5220 */
5221MOZ_CAN_RUN_SCRIPT_BOUNDARY static nsresult HandleFrameSelection(
5222 nsFrameSelection* aFrameSelection, nsIFrame::ContentOffsets& aOffsets,
5223 bool aHandleTableSel, int32_t aContentOffsetForTableSel,
5224 TableSelectionMode aTargetForTableSel,
5225 nsIContent* aParentContentForTableSel, WidgetGUIEvent* aEvent,
5226 const nsEventStatus* aEventStatus) {
5227 if (!aFrameSelection) {
5228 return NS_OK;
5229 }
5230
5231 nsresult rv = NS_OK;
5232
5233 if (nsEventStatus_eConsumeNoDefault != *aEventStatus) {
5234 if (!aHandleTableSel) {
5235 if (!aOffsets.content || !aFrameSelection->HasDelayedCaretData()) {
5236 return NS_ERROR_FAILURE;
5237 }
5238
5239 // We are doing this to simulate what we would have done on HandlePress.
5240 // We didn't do it there to give the user an opportunity to drag
5241 // the text, but since they didn't drag, we want to place the
5242 // caret.
5243 // However, we'll use the mouse position from the release, since:
5244 // * it's easier
5245 // * that's the normal click position to use (although really, in
5246 // the normal case, small movements that don't count as a drag
5247 // can do selection)
5248 aFrameSelection->SetDragState(true);
5249
5250 const nsFrameSelection::FocusMode focusMode =
5251 aFrameSelection->IsShiftDownInDelayedCaretData()
5252 ? nsFrameSelection::FocusMode::kExtendSelection
5253 : nsFrameSelection::FocusMode::kCollapseToNewPoint;
5254 rv = aFrameSelection->HandleClick(
5255 MOZ_KnownLive(aOffsets.content)(aOffsets.content) /* bug 1636889 */,
5256 aOffsets.StartOffset(), aOffsets.EndOffset(), focusMode,
5257 aOffsets.associate);
5258 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5259 return rv;
5260 }
5261 } else if (aParentContentForTableSel) {
5262 aFrameSelection->SetDragState(false);
5263 rv = aFrameSelection->HandleTableSelection(
5264 aParentContentForTableSel, aContentOffsetForTableSel,
5265 aTargetForTableSel, aEvent->AsMouseEvent());
5266 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
5267 return rv;
5268 }
5269 }
5270 aFrameSelection->SetDelayedCaretData(0);
5271 }
5272
5273 aFrameSelection->SetDragState(false);
5274 aFrameSelection->StopAutoScrollTimer();
5275
5276 return NS_OK;
5277}
5278
5279NS_IMETHODIMPnsresult nsIFrame::HandleRelease(nsPresContext* aPresContext,
5280 WidgetGUIEvent* aEvent,
5281 nsEventStatus* aEventStatus) {
5282 if (aEvent->mClass != eMouseEventClass) {
5283 return NS_OK;
5284 }
5285
5286 nsIFrame* activeFrame = GetActiveSelectionFrame(aPresContext, this);
5287
5288 nsCOMPtr<nsIContent> captureContent = PresShell::GetCapturingContent();
5289
5290 bool selectionOff =
5291 (DetermineDisplaySelection() == nsISelectionController::SELECTION_OFF);
5292
5293 RefPtr<nsFrameSelection> frameselection;
5294 ContentOffsets offsets;
5295 nsCOMPtr<nsIContent> parentContent;
5296 int32_t contentOffsetForTableSel = 0;
5297 TableSelectionMode targetForTableSel = TableSelectionMode::None;
5298 bool handleTableSelection = true;
5299
5300 if (!selectionOff) {
5301 frameselection = GetFrameSelection();
5302 if (nsEventStatus_eConsumeNoDefault != *aEventStatus && frameselection) {
5303 // Check if the frameselection recorded the mouse going down.
5304 // If not, the user must have clicked in a part of the selection.
5305 // Place the caret before continuing!
5306
5307 if (frameselection->MouseDownRecorded()) {
5308 nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
5309 aEvent, RelativeTo{this});
5310 offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN);
5311 handleTableSelection = false;
5312 } else {
5313 GetDataForTableSelection(frameselection, PresShell(),
5314 aEvent->AsMouseEvent(),
5315 getter_AddRefs(parentContent),
5316 &contentOffsetForTableSel, &targetForTableSel);
5317 }
5318 }
5319 }
5320
5321 // We might be capturing in some other document and the event just happened to
5322 // trickle down here. Make sure that document's frame selection is notified.
5323 // Note, this may cause the current nsFrame object to be deleted, bug 336592.
5324 RefPtr<nsFrameSelection> frameSelection;
5325 if (activeFrame != this && activeFrame->DetermineDisplaySelection() !=
5326 nsISelectionController::SELECTION_OFF) {
5327 frameSelection = activeFrame->GetFrameSelection();
5328 }
5329
5330 // Also check the selection of the capturing content which might be in a
5331 // different document.
5332 if (!frameSelection && captureContent) {
5333 if (Document* doc = captureContent->GetComposedDoc()) {
5334 mozilla::PresShell* capturingPresShell = doc->GetPresShell();
5335 if (capturingPresShell &&
5336 capturingPresShell != PresContext()->GetPresShell()) {
5337 frameSelection = capturingPresShell->FrameSelection();
5338 }
5339 }
5340 }
5341
5342 if (frameSelection) {
5343 AutoWeakFrame wf(this);
5344 frameSelection->SetDragState(false);
5345 frameSelection->StopAutoScrollTimer();
5346 if (wf.IsAlive()) {
5347 ScrollContainerFrame* scrollContainerFrame =
5348 nsLayoutUtils::GetNearestScrollContainerFrame(
5349 this, nsLayoutUtils::SCROLLABLE_SAME_DOC |
5350 nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
5351 if (scrollContainerFrame) {
5352 // Perform any additional scrolling needed to maintain CSS snap point
5353 // requirements when autoscrolling is over.
5354 scrollContainerFrame->ScrollSnap();
5355 }
5356 }
5357 }
5358
5359 // Do not call any methods of the current object after this point!!!
5360 // The object is perhaps dead!
5361
5362 return selectionOff ? NS_OK
5363 : HandleFrameSelection(
5364 frameselection, offsets, handleTableSelection,
5365 contentOffsetForTableSel, targetForTableSel,
5366 parentContent, aEvent, aEventStatus);
5367}
5368
5369struct MOZ_STACK_CLASS FrameContentRange {
5370 FrameContentRange(nsIContent* aContent, int32_t aStart, int32_t aEnd)
5371 : content(aContent), start(aStart), end(aEnd) {}
5372 nsCOMPtr<nsIContent> content;
5373 int32_t start;
5374 int32_t end;
5375};
5376
5377// Retrieve the content offsets of a frame
5378static FrameContentRange GetRangeForFrame(const nsIFrame* aFrame) {
5379 nsIContent* content = aFrame->GetContent();
5380 if (!content) {
5381 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"
, 5381)
;
5382 return FrameContentRange(nullptr, -1, -1);
5383 }
5384
5385 LayoutFrameType type = aFrame->Type();
5386 if (type == LayoutFrameType::Text) {
5387 auto [offset, offsetEnd] = aFrame->GetOffsets();
5388 return FrameContentRange(content, offset, offsetEnd);
5389 }
5390
5391 if (type == LayoutFrameType::Br) {
5392 nsIContent* parent = content->GetParent();
5393 const int32_t beginOffset = parent->ComputeIndexOf_Deprecated(content);
5394 return FrameContentRange(parent, beginOffset, beginOffset);
5395 }
5396
5397 while (content->IsRootOfNativeAnonymousSubtree()) {
5398 content = content->GetParent();
5399 }
5400
5401 nsIContent* parent = content->GetParent();
5402 if (aFrame->IsBlockOutside() || !parent) {
5403 return FrameContentRange(content, 0, content->GetChildCount());
5404 }
5405
5406 // TODO(emilio): Revise this in presence of Shadow DOM / display: contents,
5407 // it's likely that we don't want to just walk the light tree, and we need to
5408 // change the representation of FrameContentRange.
5409 const int32_t index = parent->ComputeIndexOf_Deprecated(content);
5410 MOZ_ASSERT(index >= 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(index >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(index >= 0))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("index >= 0",
"/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 5410); AnnotateMozCrashReason("MOZ_ASSERT" "(" "index >= 0"
")"); do { *((volatile int*)__null) = 5410; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5411 return FrameContentRange(parent, index, index + 1);
5412}
5413
5414// The FrameTarget represents the closest frame to a point that can be selected
5415// The frame is the frame represented, frameEdge says whether one end of the
5416// frame is the result (in which case different handling is needed), and
5417// afterFrame says which end is represented if frameEdge is true
5418struct FrameTarget {
5419 explicit operator bool() const { return !!frame; }
5420
5421 nsIFrame* frame = nullptr;
5422 bool frameEdge = false;
5423 bool afterFrame = false;
5424};
5425
5426// See function implementation for information
5427static FrameTarget GetSelectionClosestFrame(nsIFrame* aFrame,
5428 const nsPoint& aPoint,
5429 uint32_t aFlags);
5430
5431static bool SelfIsSelectable(nsIFrame* aFrame, nsIFrame* aParentFrame,
5432 uint32_t aFlags) {
5433 // We should not move selection into a native anonymous subtree when handling
5434 // selection outside it.
5435 if ((aFlags & nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE) &&
5436 aParentFrame->GetClosestNativeAnonymousSubtreeRoot() !=
5437 aFrame->GetClosestNativeAnonymousSubtreeRoot()) {
5438 return false;
5439 }
5440 if ((aFlags & nsIFrame::SKIP_HIDDEN) &&
5441 !aFrame->StyleVisibility()->IsVisible()) {
5442 return false;
5443 }
5444 return !aFrame->IsGeneratedContentFrame() &&
5445 aFrame->Style()->UserSelect() != StyleUserSelect::None;
5446}
5447
5448static bool FrameContentCanHaveParentSelectionRange(nsIFrame* aFrame) {
5449 // If we are only near (not directly over) then don't traverse
5450 // frames with independent selection (e.g. text and list controls, see bug
5451 // 268497). Note that this prevents any of the users of this method from
5452 // entering form controls.
5453 // XXX We might want some way to allow using the up-arrow to go into a form
5454 // control, but the focus didn't work right anyway; it'd probably be enough
5455 // if the left and right arrows could enter textboxes (which I don't believe
5456 // they can at the moment)
5457 if (aFrame->IsTextInputFrame() || aFrame->IsListControlFrame()) {
5458 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"
, 5458); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5458; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5459 return false;
5460 }
5461
5462 // Failure in this assertion means a new type of frame forms the root of an
5463 // NS_FRAME_INDEPENDENT_SELECTION subtree. In such case, the condition above
5464 // should be changed to handle it.
5465 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"
, 5467); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5467; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
5466 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"
, 5467); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5467; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
5467 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"
, 5467); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetParent()->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)"
")"); do { *((volatile int*)__null) = 5467; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
5468
5469 return !aFrame->IsGeneratedContentFrame();
5470}
5471
5472static bool SelectionDescendToKids(nsIFrame* aFrame) {
5473 if (!FrameContentCanHaveParentSelectionRange(aFrame)) {
5474 return false;
5475 }
5476 auto style = aFrame->Style()->UserSelect();
5477 return style != StyleUserSelect::All && style != StyleUserSelect::None;
5478}
5479
5480static FrameTarget GetSelectionClosestFrameForChild(nsIFrame* aChild,
5481 const nsPoint& aPoint,
5482 uint32_t aFlags) {
5483 nsIFrame* parent = aChild->GetParent();
5484 if (SelectionDescendToKids(aChild)) {
5485 nsPoint pt = aPoint - aChild->GetOffsetTo(parent);
5486 return GetSelectionClosestFrame(aChild, pt, aFlags);
5487 }
5488 return FrameTarget{aChild, false, false};
5489}
5490
5491// When the cursor needs to be at the beginning of a block, it shouldn't be
5492// before the first child. A click on a block whose first child is a block
5493// should put the cursor in the child. The cursor shouldn't be between the
5494// blocks, because that's not where it's expected.
5495// Note that this method is guaranteed to succeed.
5496static FrameTarget DrillDownToSelectionFrame(nsIFrame* aFrame, bool aEndFrame,
5497 uint32_t aFlags) {
5498 if (SelectionDescendToKids(aFrame)) {
5499 nsIFrame* result = nullptr;
5500 nsIFrame* frame = aFrame->PrincipalChildList().FirstChild();
5501 if (!aEndFrame) {
5502 while (frame &&
5503 (!SelfIsSelectable(frame, aFrame, aFlags) || frame->IsEmpty())) {
5504 frame = frame->GetNextSibling();
5505 }
5506 if (frame) {
5507 result = frame;
5508 }
5509 } else {
5510 // Because the frame tree is singly linked, to find the last frame,
5511 // we have to iterate through all the frames
5512 // XXX I have a feeling this could be slow for long blocks, although
5513 // I can't find any slowdowns
5514 while (frame) {
5515 if (!frame->IsEmpty() && SelfIsSelectable(frame, aFrame, aFlags)) {
5516 result = frame;
5517 }
5518 frame = frame->GetNextSibling();
5519 }
5520 }
5521 if (result) {
5522 return DrillDownToSelectionFrame(result, aEndFrame, aFlags);
5523 }
5524 }
5525 // If the current frame has no targetable children, target the current frame
5526 return FrameTarget{aFrame, true, aEndFrame};
5527}
5528
5529// This method finds the closest valid FrameTarget on a given line; if there is
5530// no valid FrameTarget on the line, it returns a null FrameTarget
5531static FrameTarget GetSelectionClosestFrameForLine(
5532 nsBlockFrame* aParent, nsBlockFrame::LineIterator aLine,
5533 const nsPoint& aPoint, uint32_t aFlags) {
5534 // Account for end of lines (any iterator from the block is valid)
5535 if (aLine == aParent->LinesEnd()) {
5536 return DrillDownToSelectionFrame(aParent, true, aFlags);
5537 }
5538 nsIFrame* frame = aLine->mFirstChild;
5539 nsIFrame* closestFromIStart = nullptr;
5540 nsIFrame* closestFromIEnd = nullptr;
5541 nscoord closestIStart = aLine->IStart(), closestIEnd = aLine->IEnd();
5542 WritingMode wm = aLine->mWritingMode;
5543 LogicalPoint pt(wm, aPoint, aLine->mContainerSize);
5544 bool canSkipBr = false;
5545 bool lastFrameWasEditable = false;
5546 for (int32_t n = aLine->GetChildCount(); n;
5547 --n, frame = frame->GetNextSibling()) {
5548 // Skip brFrames. Can only skip if the line contains at least
5549 // one selectable and non-empty frame before. Also, avoid skipping brs if
5550 // the previous thing had a different editableness than us, since then we
5551 // may end up not being able to select after it if the br is the last thing
5552 // on the line.
5553 if (!SelfIsSelectable(frame, aParent, aFlags) || frame->IsEmpty() ||
5554 (canSkipBr && frame->IsBrFrame() &&
5555 lastFrameWasEditable == frame->GetContent()->IsEditable())) {
5556 continue;
5557 }
5558 canSkipBr = true;
5559 lastFrameWasEditable =
5560 frame->GetContent() && frame->GetContent()->IsEditable();
5561 LogicalRect frameRect =
5562 LogicalRect(wm, frame->GetRect(), aLine->mContainerSize);
5563 if (pt.I(wm) >= frameRect.IStart(wm)) {
5564 if (pt.I(wm) < frameRect.IEnd(wm)) {
5565 return GetSelectionClosestFrameForChild(frame, aPoint, aFlags);
5566 }
5567 if (frameRect.IEnd(wm) >= closestIStart) {
5568 closestFromIStart = frame;
5569 closestIStart = frameRect.IEnd(wm);
5570 }
5571 } else {
5572 if (frameRect.IStart(wm) <= closestIEnd) {
5573 closestFromIEnd = frame;
5574 closestIEnd = frameRect.IStart(wm);
5575 }
5576 }
5577 }
5578 if (!closestFromIStart && !closestFromIEnd) {
5579 // We should only get here if there are no selectable frames on a line
5580 // XXX Do we need more elaborate handling here?
5581 return FrameTarget();
5582 }
5583 if (closestFromIStart &&
5584 (!closestFromIEnd ||
5585 (abs(pt.I(wm) - closestIStart) <= abs(pt.I(wm) - closestIEnd)))) {
5586 return GetSelectionClosestFrameForChild(closestFromIStart, aPoint, aFlags);
5587 }
5588 return GetSelectionClosestFrameForChild(closestFromIEnd, aPoint, aFlags);
5589}
5590
5591// This method is for the special handling we do for block frames; they're
5592// special because they represent paragraphs and because they are organized
5593// into lines, which have bounds that are not stored elsewhere in the
5594// frame tree. Returns a null FrameTarget for frames which are not
5595// blocks or blocks with no lines except editable one.
5596static FrameTarget GetSelectionClosestFrameForBlock(nsIFrame* aFrame,
5597 const nsPoint& aPoint,
5598 uint32_t aFlags) {
5599 nsBlockFrame* bf = do_QueryFrame(aFrame);
5600 if (!bf) {
5601 return FrameTarget();
5602 }
5603
5604 // This code searches for the correct line
5605 nsBlockFrame::LineIterator end = bf->LinesEnd();
5606 nsBlockFrame::LineIterator curLine = bf->LinesBegin();
5607 nsBlockFrame::LineIterator closestLine = end;
5608
5609 if (curLine != end) {
5610 // Convert aPoint into a LogicalPoint in the writing-mode of this block
5611 WritingMode wm = curLine->mWritingMode;
5612 LogicalPoint pt(wm, aPoint, curLine->mContainerSize);
5613 do {
5614 // Check to see if our point lies within the line's block-direction bounds
5615 nscoord BCoord = pt.B(wm) - curLine->BStart();
5616 nscoord BSize = curLine->BSize();
5617 if (BCoord >= 0 && BCoord < BSize) {
5618 closestLine = curLine;
5619 break; // We found the line; stop looking
5620 }
5621 if (BCoord < 0) break;
5622 ++curLine;
5623 } while (curLine != end);
5624
5625 if (closestLine == end) {
5626 nsBlockFrame::LineIterator prevLine = curLine.prev();
5627 nsBlockFrame::LineIterator nextLine = curLine;
5628 // Avoid empty lines
5629 while (nextLine != end && nextLine->IsEmpty()) ++nextLine;
5630 while (prevLine != end && prevLine->IsEmpty()) --prevLine;
5631
5632 // This hidden pref dictates whether a point above or below all lines
5633 // comes up with a line or the beginning or end of the frame; 0 on
5634 // Windows, 1 on other platforms by default at the writing of this code
5635 int32_t dragOutOfFrame =
5636 Preferences::GetInt("browser.drag_out_of_frame_style");
5637
5638 if (prevLine == end) {
5639 if (dragOutOfFrame == 1 || nextLine == end)
5640 return DrillDownToSelectionFrame(aFrame, false, aFlags);
5641 closestLine = nextLine;
5642 } else if (nextLine == end) {
5643 if (dragOutOfFrame == 1)
5644 return DrillDownToSelectionFrame(aFrame, true, aFlags);
5645 closestLine = prevLine;
5646 } else { // Figure out which line is closer
5647 if (pt.B(wm) - prevLine->BEnd() < nextLine->BStart() - pt.B(wm))
5648 closestLine = prevLine;
5649 else
5650 closestLine = nextLine;
5651 }
5652 }
5653 }
5654
5655 do {
5656 if (auto target =
5657 GetSelectionClosestFrameForLine(bf, closestLine, aPoint, aFlags)) {
5658 return target;
5659 }
5660 ++closestLine;
5661 } while (closestLine != end);
5662
5663 // Fall back to just targeting the last targetable place
5664 return DrillDownToSelectionFrame(aFrame, true, aFlags);
5665}
5666
5667// Use frame edge for grid, flex, table, and non-editable images. Choose the
5668// edge based on the point position past the frame rect. If past the middle,
5669// caret should be at end, otherwise at start. This behavior matches Blink.
5670//
5671// TODO(emilio): Can we use this code path for other replaced elements other
5672// than images? Or even all other frames? We only get there when we didn't find
5673// selectable children... At least one XUL test fails if we make this apply to
5674// XUL labels. Also, editable images need _not_ to use the frame edge, see
5675// below.
5676static bool UseFrameEdge(nsIFrame* aFrame) {
5677 if (aFrame->IsFlexOrGridContainer() || aFrame->IsTableFrame()) {
5678 return true;
5679 }
5680 const nsImageFrame* image = do_QueryFrame(aFrame);
5681 if (image && !aFrame->GetContent()->IsEditable()) {
5682 // Editable images are a special-case because editing relies on clicking on
5683 // an editable image selecting it, for it to show resizers.
5684 return true;
5685 }
5686 return false;
5687}
5688
5689static FrameTarget LastResortFrameTargetForFrame(nsIFrame* aFrame,
5690 const nsPoint& aPoint) {
5691 if (!UseFrameEdge(aFrame)) {
5692 return {aFrame, false, false};
5693 }
5694 const auto& rect = aFrame->GetRectRelativeToSelf();
5695 nscoord reference;
5696 nscoord middle;
5697 if (aFrame->GetWritingMode().IsVertical()) {
5698 reference = aPoint.y;
5699 middle = rect.Height() / 2;
5700 } else {
5701 reference = aPoint.x;
5702 middle = rect.Width() / 2;
5703 }
5704 const bool afterFrame = reference > middle;
5705 return {aFrame, true, afterFrame};
5706}
5707
5708// GetSelectionClosestFrame is the helper function that calculates the closest
5709// frame to the given point.
5710// It doesn't completely account for offset styles, so needs to be used in
5711// restricted environments.
5712// Cannot handle overlapping frames correctly, so it should receive the output
5713// of GetFrameForPoint
5714// Guaranteed to return a valid FrameTarget.
5715// aPoint is relative to aFrame.
5716static FrameTarget GetSelectionClosestFrame(nsIFrame* aFrame,
5717 const nsPoint& aPoint,
5718 uint32_t aFlags) {
5719 // Handle blocks; if the frame isn't a block, the method fails
5720 if (auto target = GetSelectionClosestFrameForBlock(aFrame, aPoint, aFlags)) {
5721 return target;
5722 }
5723
5724 if (aFlags & nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE &&
5725 !FrameContentCanHaveParentSelectionRange(aFrame)) {
5726 return LastResortFrameTargetForFrame(aFrame, aPoint);
5727 }
5728
5729 if (nsIFrame* kid = aFrame->PrincipalChildList().FirstChild()) {
5730 // Go through all the child frames to find the closest one
5731 nsIFrame::FrameWithDistance closest = {nullptr, nscoord_MAX, nscoord_MAX};
5732 for (; kid; kid = kid->GetNextSibling()) {
5733 if (!SelfIsSelectable(kid, aFrame, aFlags) || kid->IsEmpty()) {
5734 continue;
5735 }
5736
5737 kid->FindCloserFrameForSelection(aPoint, &closest);
5738 }
5739 if (closest.mFrame) {
5740 if (closest.mFrame->IsInSVGTextSubtree())
5741 return FrameTarget{closest.mFrame, false, false};
5742 return GetSelectionClosestFrameForChild(closest.mFrame, aPoint, aFlags);
5743 }
5744 }
5745
5746 return LastResortFrameTargetForFrame(aFrame, aPoint);
5747}
5748
5749static nsIFrame::ContentOffsets OffsetsForSingleFrame(nsIFrame* aFrame,
5750 const nsPoint& aPoint) {
5751 nsIFrame::ContentOffsets offsets;
5752 FrameContentRange range = GetRangeForFrame(aFrame);
5753 offsets.content = range.content;
5754 // If there are continuations (meaning it's not one rectangle), this is the
5755 // best this function can do
5756 if (aFrame->GetNextContinuation() || aFrame->GetPrevContinuation()) {
5757 offsets.offset = range.start;
5758 offsets.secondaryOffset = range.end;
5759 offsets.associate = CaretAssociationHint::After;
5760 return offsets;
5761 }
5762
5763 // Figure out whether the offsets should be over, after, or before the frame
5764 nsRect rect(nsPoint(0, 0), aFrame->GetSize());
5765
5766 bool isBlock = !aFrame->StyleDisplay()->IsInlineFlow();
5767 bool isRtl = (aFrame->StyleVisibility()->mDirection == StyleDirection::Rtl);
5768 if ((isBlock && rect.y < aPoint.y) ||
5769 (!isBlock && ((isRtl && rect.x + rect.width / 2 > aPoint.x) ||
5770 (!isRtl && rect.x + rect.width / 2 < aPoint.x)))) {
5771 offsets.offset = range.end;
5772 if (rect.Contains(aPoint))
5773 offsets.secondaryOffset = range.start;
5774 else
5775 offsets.secondaryOffset = range.end;
5776 } else {
5777 offsets.offset = range.start;
5778 if (rect.Contains(aPoint))
5779 offsets.secondaryOffset = range.end;
5780 else
5781 offsets.secondaryOffset = range.start;
5782 }
5783 offsets.associate = offsets.offset == range.start
5784 ? CaretAssociationHint::After
5785 : CaretAssociationHint::Before;
5786 return offsets;
5787}
5788
5789static nsIFrame* AdjustFrameForSelectionStyles(nsIFrame* aFrame) {
5790 nsIFrame* adjustedFrame = aFrame;
5791 for (nsIFrame* frame = aFrame; frame; frame = frame->GetParent()) {
5792 // These are the conditions that make all children not able to handle
5793 // a cursor.
5794 auto userSelect = frame->Style()->UserSelect();
5795 if (userSelect != StyleUserSelect::Auto &&
5796 userSelect != StyleUserSelect::All) {
5797 break;
5798 }
5799 if (userSelect == StyleUserSelect::All ||
5800 frame->IsGeneratedContentFrame()) {
5801 adjustedFrame = frame;
5802 }
5803 }
5804 return adjustedFrame;
5805}
5806
5807nsIFrame::ContentOffsets nsIFrame::GetContentOffsetsFromPoint(
5808 const nsPoint& aPoint, uint32_t aFlags) {
5809 nsIFrame* adjustedFrame;
5810 if (aFlags & IGNORE_SELECTION_STYLE) {
5811 adjustedFrame = this;
5812 } else {
5813 // This section of code deals with special selection styles. Note that
5814 // -moz-all exists, even though it doesn't need to be explicitly handled.
5815 //
5816 // The offset is forced not to end up in generated content; content offsets
5817 // cannot represent content outside of the document's content tree.
5818
5819 adjustedFrame = AdjustFrameForSelectionStyles(this);
5820
5821 // `user-select: all` needs special handling, because clicking on it should
5822 // lead to the whole frame being selected.
5823 if (adjustedFrame->Style()->UserSelect() == StyleUserSelect::All) {
5824 nsPoint adjustedPoint = aPoint + GetOffsetTo(adjustedFrame);
5825 return OffsetsForSingleFrame(adjustedFrame, adjustedPoint);
5826 }
5827
5828 // For other cases, try to find a closest frame starting from the parent of
5829 // the unselectable frame
5830 if (adjustedFrame != this) {
5831 adjustedFrame = adjustedFrame->GetParent();
5832 }
5833 }
5834
5835 nsPoint adjustedPoint = aPoint + GetOffsetTo(adjustedFrame);
5836
5837 FrameTarget closest =
5838 GetSelectionClosestFrame(adjustedFrame, adjustedPoint, aFlags);
5839
5840 // If the correct offset is at one end of a frame, use offset-based
5841 // calculation method
5842 if (closest.frameEdge) {
5843 ContentOffsets offsets;
5844 FrameContentRange range = GetRangeForFrame(closest.frame);
5845 offsets.content = range.content;
5846 if (closest.afterFrame)
5847 offsets.offset = range.end;
5848 else
5849 offsets.offset = range.start;
5850 offsets.secondaryOffset = offsets.offset;
5851 offsets.associate = offsets.offset == range.start
5852 ? CaretAssociationHint::After
5853 : CaretAssociationHint::Before;
5854 return offsets;
5855 }
5856
5857 nsPoint pt;
5858 if (closest.frame != this) {
5859 if (closest.frame->IsInSVGTextSubtree()) {
5860 pt = nsLayoutUtils::TransformAncestorPointToFrame(
5861 RelativeTo{closest.frame}, aPoint, RelativeTo{this});
5862 } else {
5863 pt = aPoint - closest.frame->GetOffsetTo(this);
5864 }
5865 } else {
5866 pt = aPoint;
5867 }
5868 return closest.frame->CalcContentOffsetsFromFramePoint(pt);
5869
5870 // XXX should I add some kind of offset standardization?
5871 // consider <b>xxxxx</b><i>zzzzz</i>; should any click between the last
5872 // x and first z put the cursor in the same logical position in addition
5873 // to the same visual position?
5874}
5875
5876nsIFrame::ContentOffsets nsIFrame::CalcContentOffsetsFromFramePoint(
5877 const nsPoint& aPoint) {
5878 return OffsetsForSingleFrame(this, aPoint);
5879}
5880
5881bool nsIFrame::AssociateImage(const StyleImage& aImage) {
5882 imgRequestProxy* req = aImage.GetImageRequest();
5883 if (!req) {
5884 return false;
5885 }
5886
5887 mozilla::css::ImageLoader* loader =
5888 PresContext()->Document()->StyleImageLoader();
5889
5890 loader->AssociateRequestToFrame(req, this);
5891 return true;
5892}
5893
5894void nsIFrame::DisassociateImage(const StyleImage& aImage) {
5895 imgRequestProxy* req = aImage.GetImageRequest();
5896 if (!req) {
5897 return;
5898 }
5899
5900 mozilla::css::ImageLoader* loader =
5901 PresContext()->Document()->StyleImageLoader();
5902
5903 loader->DisassociateRequestFromFrame(req, this);
5904}
5905
5906StyleImageRendering nsIFrame::UsedImageRendering() const {
5907 ComputedStyle* style;
5908 if (IsCanvasFrame()) {
5909 // XXXdholbert Maybe we should use FindCanvasBackground here (instead of
5910 // FindBackground), since we're inside an IsCanvasFrame check? Though then
5911 // we'd also have to copypaste or abstract-away the multi-part root-frame
5912 // lookup that the canvas-flavored API requires.
5913 style = nsCSSRendering::FindBackground(this);
5914 } else {
5915 style = Style();
5916 }
5917 return style->StyleVisibility()->mImageRendering;
5918}
5919
5920// The touch-action CSS property applies to: all elements except: non-replaced
5921// inline elements, table rows, row groups, table columns, and column groups.
5922StyleTouchAction nsIFrame::UsedTouchAction() const {
5923 if (IsLineParticipant()) {
5924 return StyleTouchAction::AUTO;
5925 }
5926 auto& disp = *StyleDisplay();
5927 if (disp.IsInternalTableStyleExceptCell()) {
5928 return StyleTouchAction::AUTO;
5929 }
5930 return disp.mTouchAction;
5931}
5932
5933nsIFrame::Cursor nsIFrame::GetCursor(const nsPoint&) {
5934 StyleCursorKind kind = StyleUI()->Cursor().keyword;
5935 if (kind == StyleCursorKind::Auto) {
5936 // If this is editable, I-beam cursor is better for most elements.
5937 kind = (mContent && mContent->IsEditable()) ? StyleCursorKind::Text
5938 : StyleCursorKind::Default;
5939 }
5940 if (kind == StyleCursorKind::Text && GetWritingMode().IsVertical()) {
5941 // Per CSS UI spec, UA may treat value 'text' as
5942 // 'vertical-text' for vertical text.
5943 kind = StyleCursorKind::VerticalText;
5944 }
5945
5946 return Cursor{kind, AllowCustomCursorImage::Yes};
5947}
5948
5949// Resize and incremental reflow
5950
5951/* virtual */
5952void nsIFrame::MarkIntrinsicISizesDirty() {
5953 // If we're a flex item, clear our flex-item-specific cached measurements
5954 // (which likely depended on our now-stale intrinsic isize).
5955 if (IsFlexItem()) {
5956 nsFlexContainerFrame::MarkCachedFlexMeasurementsDirty(this);
5957 }
5958
5959 if (HasAnyStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT)) {
5960 nsFontInflationData::MarkFontInflationDataTextDirty(this);
5961 }
5962
5963 RemoveProperty(nsGridContainerFrame::CachedBAxisMeasurement::Prop());
5964}
5965
5966void nsIFrame::MarkSubtreeDirty() {
5967 if (HasAnyStateBits(NS_FRAME_IS_DIRTY)) {
5968 return;
5969 }
5970 // Unconditionally mark given frame dirty.
5971 AddStateBits(NS_FRAME_IS_DIRTY);
5972
5973 // Mark all descendants dirty, unless:
5974 // - Already dirty.
5975 // - TableColGroup
5976 AutoTArray<nsIFrame*, 32> stack;
5977 for (const auto& childLists : ChildLists()) {
5978 for (nsIFrame* kid : childLists.mList) {
5979 stack.AppendElement(kid);
5980 }
5981 }
5982 while (!stack.IsEmpty()) {
5983 nsIFrame* f = stack.PopLastElement();
5984 if (f->HasAnyStateBits(NS_FRAME_IS_DIRTY) || f->IsTableColGroupFrame()) {
5985 continue;
5986 }
5987
5988 f->AddStateBits(NS_FRAME_IS_DIRTY);
5989
5990 for (const auto& childLists : f->ChildLists()) {
5991 for (nsIFrame* kid : childLists.mList) {
5992 stack.AppendElement(kid);
5993 }
5994 }
5995 }
5996}
5997
5998/* virtual */
5999void nsIFrame::AddInlineMinISize(gfxContext* aRenderingContext,
6000 nsIFrame::InlineMinISizeData* aData) {
6001 nscoord isize = nsLayoutUtils::IntrinsicForContainer(
6002 aRenderingContext, this, IntrinsicISizeType::MinISize);
6003 aData->DefaultAddInlineMinISize(this, isize);
6004}
6005
6006/* virtual */
6007void nsIFrame::AddInlinePrefISize(gfxContext* aRenderingContext,
6008 nsIFrame::InlinePrefISizeData* aData) {
6009 nscoord isize = nsLayoutUtils::IntrinsicForContainer(
6010 aRenderingContext, this, IntrinsicISizeType::PrefISize);
6011 aData->DefaultAddInlinePrefISize(isize);
6012}
6013
6014void nsIFrame::InlineMinISizeData::DefaultAddInlineMinISize(nsIFrame* aFrame,
6015 nscoord aISize,
6016 bool aAllowBreak) {
6017 auto parent = aFrame->GetParent();
6018 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"
, 6018); AnnotateMozCrashReason("MOZ_ASSERT" "(" "parent" ") ("
"Must have a parent if we get here!" ")"); do { *((volatile int
*)__null) = 6018; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
6019 const bool mayBreak = aAllowBreak && !aFrame->CanContinueTextRun() &&
6020 !parent->Style()->ShouldSuppressLineBreak() &&
6021 parent->StyleText()->WhiteSpaceCanWrap(parent);
6022 if (mayBreak) {
6023 OptionallyBreak();
6024 }
6025 mTrailingWhitespace = 0;
6026 mSkipWhitespace = false;
6027 mCurrentLine += aISize;
6028 mAtStartOfLine = false;
6029 if (mayBreak) {
6030 OptionallyBreak();
6031 }
6032}
6033
6034void nsIFrame::InlinePrefISizeData::DefaultAddInlinePrefISize(nscoord aISize) {
6035 mCurrentLine = NSCoordSaturatingAdd(mCurrentLine, aISize);
6036 mTrailingWhitespace = 0;
6037 mSkipWhitespace = false;
6038 mLineIsEmpty = false;
6039}
6040
6041void nsIFrame::InlineMinISizeData::ForceBreak() {
6042 mCurrentLine -= mTrailingWhitespace;
6043 mPrevLines = std::max(mPrevLines, mCurrentLine);
6044 mCurrentLine = mTrailingWhitespace = 0;
6045
6046 for (const FloatInfo& floatInfo : mFloats) {
6047 mPrevLines = std::max(floatInfo.ISize(), mPrevLines);
6048 }
6049 mFloats.Clear();
6050 mSkipWhitespace = true;
6051}
6052
6053void nsIFrame::InlineMinISizeData::OptionallyBreak(nscoord aHyphenWidth) {
6054 // If we can fit more content into a smaller width by staying on this
6055 // line (because we're still at a negative offset due to negative
6056 // text-indent or negative margin), don't break. Otherwise, do the
6057 // same as ForceBreak. it doesn't really matter when we accumulate
6058 // floats.
6059 if (mCurrentLine + aHyphenWidth < 0 || mAtStartOfLine) return;
6060 mCurrentLine += aHyphenWidth;
6061 ForceBreak();
6062}
6063
6064void nsIFrame::InlinePrefISizeData::ForceBreak(StyleClear aClearType) {
6065 // If this force break is not clearing any float, we can leave all the
6066 // floats to the next force break.
6067 if (!mFloats.IsEmpty() && aClearType != StyleClear::None) {
6068 // Preferred isize accumulated for floats that have already
6069 // been cleared past
6070 nscoord floatsDone = 0;
6071 // Preferred isize accumulated for floats that have not yet
6072 // been cleared past
6073 nscoord floatsCurLeft = 0, floatsCurRight = 0;
6074
6075 for (const FloatInfo& floatInfo : mFloats) {
6076 const nsStyleDisplay* floatDisp = floatInfo.Frame()->StyleDisplay();
6077 StyleClear clearType = floatDisp->mClear;
6078 if (clearType == StyleClear::Left || clearType == StyleClear::Right ||
6079 clearType == StyleClear::Both) {
6080 nscoord floatsCur = NSCoordSaturatingAdd(floatsCurLeft, floatsCurRight);
6081 if (floatsCur > floatsDone) {
6082 floatsDone = floatsCur;
6083 }
6084 if (clearType != StyleClear::Right) {
6085 floatsCurLeft = 0;
6086 }
6087 if (clearType != StyleClear::Left) {
6088 floatsCurRight = 0;
6089 }
6090 }
6091
6092 StyleFloat floatStyle = floatDisp->mFloat;
6093 nscoord& floatsCur =
6094 floatStyle == StyleFloat::Left ? floatsCurLeft : floatsCurRight;
6095 nscoord floatISize = floatInfo.ISize();
6096 // Negative-width floats don't change the available space so they
6097 // shouldn't change our intrinsic line isize either.
6098 floatsCur = NSCoordSaturatingAdd(floatsCur, std::max(0, floatISize));
6099 }
6100
6101 nscoord floatsCur = NSCoordSaturatingAdd(floatsCurLeft, floatsCurRight);
6102 if (floatsCur > floatsDone) {
6103 floatsDone = floatsCur;
6104 }
6105
6106 mCurrentLine = NSCoordSaturatingAdd(mCurrentLine, floatsDone);
6107
6108 if (aClearType == StyleClear::Both) {
6109 mFloats.Clear();
6110 } else {
6111 // If the break type does not clear all floats, it means there may
6112 // be some floats whose isize should contribute to the intrinsic
6113 // isize of the next line. The code here scans the current mFloats
6114 // and keeps floats which are not cleared by this break. Note that
6115 // floats may be cleared directly or indirectly. See below.
6116 nsTArray<FloatInfo> newFloats;
6117 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"
, 6119); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aClearType == StyleClear::Left || aClearType == StyleClear::Right"
") (" "Other values should have been handled in other branches"
")"); do { *((volatile int*)__null) = 6119; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6118 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"
, 6119); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aClearType == StyleClear::Left || aClearType == StyleClear::Right"
") (" "Other values should have been handled in other branches"
")"); do { *((volatile int*)__null) = 6119; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6119 "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"
, 6119); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aClearType == StyleClear::Left || aClearType == StyleClear::Right"
") (" "Other values should have been handled in other branches"
")"); do { *((volatile int*)__null) = 6119; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6120 StyleFloat clearFloatType =
6121 aClearType == StyleClear::Left ? StyleFloat::Left : StyleFloat::Right;
6122 // Iterate the array in reverse so that we can stop when there are
6123 // no longer any floats we need to keep. See below.
6124 for (FloatInfo& floatInfo : Reversed(mFloats)) {
6125 const nsStyleDisplay* floatDisp = floatInfo.Frame()->StyleDisplay();
6126 if (floatDisp->mFloat != clearFloatType) {
6127 newFloats.AppendElement(floatInfo);
6128 } else {
6129 // This is a float on the side that this break directly clears
6130 // which means we're not keeping it in mFloats. However, if
6131 // this float clears floats on the opposite side (via a value
6132 // of either 'both' or one of 'left'/'right'), any remaining
6133 // (earlier) floats on that side would be indirectly cleared
6134 // as well. Thus, we should break out of this loop and stop
6135 // considering earlier floats to be kept in mFloats.
6136 StyleClear clearType = floatDisp->mClear;
6137 if (clearType != aClearType && clearType != StyleClear::None) {
6138 break;
6139 }
6140 }
6141 }
6142 newFloats.Reverse();
6143 mFloats = std::move(newFloats);
6144 }
6145 }
6146
6147 mCurrentLine =
6148 NSCoordSaturatingSubtract(mCurrentLine, mTrailingWhitespace, nscoord_MAX);
6149 mPrevLines = std::max(mPrevLines, mCurrentLine);
6150 mCurrentLine = mTrailingWhitespace = 0;
6151 mSkipWhitespace = true;
6152 mLineIsEmpty = true;
6153}
6154
6155static nscoord ResolveMargin(const LengthPercentageOrAuto& aStyle,
6156 nscoord aPercentageBasis) {
6157 if (aStyle.IsAuto()) {
6158 return nscoord(0);
6159 }
6160 return nsLayoutUtils::ResolveToLength<false>(aStyle.AsLengthPercentage(),
6161 aPercentageBasis);
6162}
6163
6164static nscoord ResolvePadding(const LengthPercentage& aStyle,
6165 nscoord aPercentageBasis) {
6166 return nsLayoutUtils::ResolveToLength<true>(aStyle, aPercentageBasis);
6167}
6168
6169static nsIFrame::IntrinsicSizeOffsetData IntrinsicSizeOffsets(
6170 nsIFrame* aFrame, nscoord aPercentageBasis, bool aForISize) {
6171 nsIFrame::IntrinsicSizeOffsetData result;
6172 WritingMode wm = aFrame->GetWritingMode();
6173 const auto& margin = aFrame->StyleMargin()->mMargin;
6174 bool verticalAxis = aForISize == wm.IsVertical();
6175 if (verticalAxis) {
6176 result.margin += ResolveMargin(margin.Get(eSideTop), aPercentageBasis);
6177 result.margin += ResolveMargin(margin.Get(eSideBottom), aPercentageBasis);
6178 } else {
6179 result.margin += ResolveMargin(margin.Get(eSideLeft), aPercentageBasis);
6180 result.margin += ResolveMargin(margin.Get(eSideRight), aPercentageBasis);
6181 }
6182
6183 const auto& padding = aFrame->StylePadding()->mPadding;
6184 if (verticalAxis) {
6185 result.padding += ResolvePadding(padding.Get(eSideTop), aPercentageBasis);
6186 result.padding +=
6187 ResolvePadding(padding.Get(eSideBottom), aPercentageBasis);
6188 } else {
6189 result.padding += ResolvePadding(padding.Get(eSideLeft), aPercentageBasis);
6190 result.padding += ResolvePadding(padding.Get(eSideRight), aPercentageBasis);
6191 }
6192
6193 const nsStyleBorder* styleBorder = aFrame->StyleBorder();
6194 if (verticalAxis) {
6195 result.border += styleBorder->GetComputedBorderWidth(eSideTop);
6196 result.border += styleBorder->GetComputedBorderWidth(eSideBottom);
6197 } else {
6198 result.border += styleBorder->GetComputedBorderWidth(eSideLeft);
6199 result.border += styleBorder->GetComputedBorderWidth(eSideRight);
6200 }
6201
6202 const nsStyleDisplay* disp = aFrame->StyleDisplay();
6203 if (aFrame->IsThemed(disp)) {
6204 nsPresContext* presContext = aFrame->PresContext();
6205
6206 LayoutDeviceIntMargin border = presContext->Theme()->GetWidgetBorder(
6207 presContext->DeviceContext(), aFrame, disp->EffectiveAppearance());
6208 result.border = presContext->DevPixelsToAppUnits(
6209 verticalAxis ? border.TopBottom() : border.LeftRight());
6210
6211 LayoutDeviceIntMargin padding;
6212 if (presContext->Theme()->GetWidgetPadding(
6213 presContext->DeviceContext(), aFrame, disp->EffectiveAppearance(),
6214 &padding)) {
6215 result.padding = presContext->DevPixelsToAppUnits(
6216 verticalAxis ? padding.TopBottom() : padding.LeftRight());
6217 }
6218 }
6219 return result;
6220}
6221
6222/* virtual */ nsIFrame::IntrinsicSizeOffsetData nsIFrame::IntrinsicISizeOffsets(
6223 nscoord aPercentageBasis) {
6224 return IntrinsicSizeOffsets(this, aPercentageBasis, true);
6225}
6226
6227nsIFrame::IntrinsicSizeOffsetData nsIFrame::IntrinsicBSizeOffsets(
6228 nscoord aPercentageBasis) {
6229 return IntrinsicSizeOffsets(this, aPercentageBasis, false);
6230}
6231
6232/* virtual */
6233IntrinsicSize nsIFrame::GetIntrinsicSize() {
6234 // Defaults to no intrinsic size.
6235 return IntrinsicSize();
6236}
6237
6238AspectRatio nsIFrame::GetAspectRatio() const {
6239 // Per spec, 'aspect-ratio' property applies to all elements except inline
6240 // boxes and internal ruby or table boxes.
6241 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio
6242 // For those frame types that don't support aspect-ratio, they must not have
6243 // the natural ratio, so this early return is fine.
6244 if (!SupportsAspectRatio()) {
6245 return AspectRatio();
6246 }
6247
6248 const StyleAspectRatio& aspectRatio = StylePosition()->mAspectRatio;
6249 // If aspect-ratio is zero or infinite, it's a degenerate ratio and behaves
6250 // as auto.
6251 // https://drafts.csswg.org/css-sizing-4/#valdef-aspect-ratio-ratio
6252 if (!aspectRatio.BehavesAsAuto()) {
6253 // Non-auto. Return the preferred aspect ratio from the aspect-ratio style.
6254 return aspectRatio.ratio.AsRatio().ToLayoutRatio(UseBoxSizing::Yes);
6255 }
6256
6257 // The rest of the cases are when aspect-ratio has 'auto'.
6258 if (auto intrinsicRatio = GetIntrinsicRatio()) {
6259 return intrinsicRatio;
6260 }
6261
6262 if (aspectRatio.HasRatio()) {
6263 // If it's a degenerate ratio, this returns 0. Just the same as the auto
6264 // case.
6265 return aspectRatio.ratio.AsRatio().ToLayoutRatio(UseBoxSizing::No);
6266 }
6267
6268 return AspectRatio();
6269}
6270
6271/* virtual */
6272AspectRatio nsIFrame::GetIntrinsicRatio() const { return AspectRatio(); }
6273
6274static bool ShouldApplyAutomaticMinimumOnInlineAxis(
6275 WritingMode aWM, const nsStyleDisplay* aDisplay,
6276 const nsStylePosition* aPosition) {
6277 // Apply the automatic minimum size for aspect ratio:
6278 // Note: The replaced elements shouldn't be here, so we only check the scroll
6279 // container.
6280 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum
6281 return !aDisplay->IsScrollableOverflow() && aPosition->MinISize(aWM).IsAuto();
6282}
6283
6284/* virtual */
6285nsIFrame::SizeComputationResult nsIFrame::ComputeSize(
6286 gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
6287 nscoord aAvailableISize, const LogicalSize& aMargin,
6288 const LogicalSize& aBorderPadding, const StyleSizeOverrides& aSizeOverrides,
6289 ComputeSizeFlags aFlags) {
6290 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"
, 6292); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetIntrinsicRatio()"
") (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")"); do { *((volatile int*)__null) = 6292; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6291 "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"
, 6292); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetIntrinsicRatio()"
") (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")"); do { *((volatile int*)__null) = 6292; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6292 "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"
, 6292); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetIntrinsicRatio()"
") (" "Please override this method and call " "nsContainerFrame::ComputeSizeWithIntrinsicDimensions instead."
")"); do { *((volatile int*)__null) = 6292; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6293 LogicalSize result =
6294 ComputeAutoSize(aRenderingContext, aWM, aCBSize, aAvailableISize, aMargin,
6295 aBorderPadding, aSizeOverrides, aFlags);
6296 const nsStylePosition* stylePos = StylePosition();
6297 const nsStyleDisplay* disp = StyleDisplay();
6298 auto aspectRatioUsage = AspectRatioUsage::None;
6299
6300 const auto boxSizingAdjust = stylePos->mBoxSizing == StyleBoxSizing::Border
6301 ? aBorderPadding
6302 : LogicalSize(aWM);
6303 nscoord boxSizingToMarginEdgeISize = aMargin.ISize(aWM) +
6304 aBorderPadding.ISize(aWM) -
6305 boxSizingAdjust.ISize(aWM);
6306
6307 const auto& styleISize = aSizeOverrides.mStyleISize
6308 ? *aSizeOverrides.mStyleISize
6309 : stylePos->ISize(aWM);
6310 const auto& styleBSize = aSizeOverrides.mStyleBSize
6311 ? *aSizeOverrides.mStyleBSize
6312 : stylePos->BSize(aWM);
6313 const auto& aspectRatio = aSizeOverrides.mAspectRatio
6314 ? *aSizeOverrides.mAspectRatio
6315 : GetAspectRatio();
6316
6317 auto parentFrame = GetParent();
6318 auto alignCB = parentFrame;
6319 bool isGridItem = IsGridItem();
6320 const bool isSubgrid = IsSubgrid();
6321 if (parentFrame && parentFrame->IsTableWrapperFrame() && IsTableFrame()) {
6322 // An inner table frame is sized as a grid item if its table wrapper is,
6323 // because they actually have the same CB (the wrapper's CB).
6324 // @see ReflowInput::InitCBReflowInput
6325 auto tableWrapper = GetParent();
6326 auto grandParent = tableWrapper->GetParent();
6327 isGridItem = grandParent->IsGridContainerFrame() &&
6328 !tableWrapper->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW);
6329 if (isGridItem) {
6330 // When resolving justify/align-self below, we want to use the grid
6331 // container's justify/align-items value and WritingMode.
6332 alignCB = grandParent;
6333 }
6334 }
6335 const bool isFlexItem =
6336 IsFlexItem() && !parentFrame->HasAnyStateBits(
6337 NS_STATE_FLEX_IS_EMULATING_LEGACY_WEBKIT_BOX);
6338 // This variable only gets set (and used) if isFlexItem is true. It
6339 // indicates which axis (in this frame's own WM) corresponds to its
6340 // flex container's main axis.
6341 LogicalAxis flexMainAxis =
6342 LogicalAxis::Inline; // (init to make valgrind happy)
6343 if (isFlexItem) {
6344 flexMainAxis = nsFlexContainerFrame::IsItemInlineAxisMainAxis(this)
6345 ? LogicalAxis::Inline
6346 : LogicalAxis::Block;
6347 }
6348
6349 const bool isOrthogonal = aWM.IsOrthogonalTo(alignCB->GetWritingMode());
6350 const bool isAutoISize = styleISize.IsAuto();
6351 const bool isAutoBSize =
6352 nsLayoutUtils::IsAutoBSize(styleBSize, aCBSize.BSize(aWM));
6353
6354 // Compute inline-axis size
6355 const bool isSubgriddedInInlineAxis =
6356 isSubgrid && static_cast<nsGridContainerFrame*>(this)->IsColSubgrid();
6357
6358 // Per https://drafts.csswg.org/css-grid/#subgrid-box-alignment, if we are
6359 // subgridded in the inline-axis, ignore our style inline-size, and stretch to
6360 // fill the CB.
6361 const bool shouldComputeISize = !isAutoISize && !isSubgriddedInInlineAxis;
6362 if (shouldComputeISize) {
6363 auto iSizeResult =
6364 ComputeISizeValue(aRenderingContext, aWM, aCBSize, boxSizingAdjust,
6365 boxSizingToMarginEdgeISize, styleISize, styleBSize,
6366 aspectRatio, aFlags);
6367 result.ISize(aWM) = iSizeResult.mISize;
6368 aspectRatioUsage = iSizeResult.mAspectRatioUsage;
6369 } else if (MOZ_UNLIKELY(isGridItem)(__builtin_expect(!!(isGridItem), 0)) && !IsTrueOverflowContainer()) {
6370 // 'auto' inline-size for grid-level box - fill the CB for 'stretch' /
6371 // 'normal' and clamp it to the CB if requested:
6372 bool stretch = false;
6373 bool mayUseAspectRatio = aspectRatio && !isAutoBSize;
6374 if (!aFlags.contains(ComputeSizeFlag::ShrinkWrap) &&
6375 !StyleMargin()->HasInlineAxisAuto(aWM) &&
6376 !alignCB->IsMasonry(isOrthogonal ? LogicalAxis::Block
6377 : LogicalAxis::Inline)) {
6378 auto inlineAxisAlignment =
6379 isOrthogonal ? StylePosition()->UsedAlignSelf(alignCB->Style())._0
6380 : StylePosition()->UsedJustifySelf(alignCB->Style())._0;
6381 stretch = inlineAxisAlignment == StyleAlignFlags::STRETCH ||
6382 (inlineAxisAlignment == StyleAlignFlags::NORMAL &&
6383 !mayUseAspectRatio);
6384 }
6385
6386 // Apply the preferred aspect ratio for alignments other than *stretch* and
6387 // *normal without aspect ratio*.
6388 // The spec says all other values should size the items as fit-content, and
6389 // the intrinsic size should respect the preferred aspect ratio, so we also
6390 // apply aspect ratio for all other values.
6391 // https://drafts.csswg.org/css-grid/#grid-item-sizing
6392 if (!stretch && mayUseAspectRatio) {
6393 result.ISize(aWM) = ComputeISizeValueFromAspectRatio(
6394 aWM, aCBSize, boxSizingAdjust, styleBSize.AsLengthPercentage(),
6395 aspectRatio);
6396 aspectRatioUsage = AspectRatioUsage::ToComputeISize;
6397 }
6398
6399 if (stretch || aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize)) {
6400 auto iSizeToFillCB =
6401 std::max(nscoord(0), aCBSize.ISize(aWM) - aBorderPadding.ISize(aWM) -
6402 aMargin.ISize(aWM));
6403 if (stretch || result.ISize(aWM) > iSizeToFillCB) {
6404 result.ISize(aWM) = iSizeToFillCB;
6405 }
6406 }
6407 } else if (aspectRatio && !isAutoBSize) {
6408 // Note: if both the inline size and the block size are auto, the block axis
6409 // is the ratio-dependent axis by default. That means we only need to
6410 // transfer the resolved inline size via aspect-ratio to block axis later in
6411 // this method, but not the other way around.
6412 //
6413 // In this branch, we transfer the non-auto block size via aspect-ration to
6414 // inline axis.
6415 result.ISize(aWM) = ComputeISizeValueFromAspectRatio(
6416 aWM, aCBSize, boxSizingAdjust, styleBSize.AsLengthPercentage(),
6417 aspectRatio);
6418 aspectRatioUsage = AspectRatioUsage::ToComputeISize;
6419 }
6420
6421 // Calculate and apply transferred min & max size contraints.
6422 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-size-transfers
6423 //
6424 // Note: The basic principle is that sizing constraints transfer through the
6425 // aspect-ratio to the other side to preserve the aspect ratio to the extent
6426 // that they can without violating any sizes specified explicitly on that
6427 // affected axis.
6428 //
6429 // FIXME: The spec words may not be correct, so we may have to update this
6430 // tentative solution once this spec issue gets resolved. Here, we clamp the
6431 // flex base size by the transferred min and max sizes, and don't include
6432 // the transferred min & max sizes into its used min & max sizes. So this
6433 // lets us match other browsers' current behaviors.
6434 // https://github.com/w3c/csswg-drafts/issues/6071
6435 //
6436 // Note: This may make more sense if we clamp the flex base size in
6437 // FlexItem::ResolveFlexBaseSizeFromAspectRatio(). However, the result should
6438 // be identical. FlexItem::ResolveFlexBaseSizeFromAspectRatio() only handles
6439 // the case of the definite cross size, and the definite cross size is clamped
6440 // by the min & max cross sizes below in this function. This means its flex
6441 // base size has been clamped by the transferred min & max size already after
6442 // generating the flex items. So here we make the code more general for both
6443 // definite cross size and indefinite cross size.
6444 const bool isDefiniteISize = styleISize.IsLengthPercentage();
6445 const auto& minBSizeCoord = stylePos->MinBSize(aWM);
6446 const auto& maxBSizeCoord = stylePos->MaxBSize(aWM);
6447 const bool isAutoMinBSize =
6448 nsLayoutUtils::IsAutoBSize(minBSizeCoord, aCBSize.BSize(aWM));
6449 const bool isAutoMaxBSize =
6450 nsLayoutUtils::IsAutoBSize(maxBSizeCoord, aCBSize.BSize(aWM));
6451 if (aspectRatio && !isDefiniteISize) {
6452 // Note: the spec mentions that
6453 // 1. This transferred minimum is capped by any definite preferred or
6454 // maximum size in the destination axis.
6455 // 2. This transferred maximum is floored by any definite preferred or
6456 // minimum size in the destination axis.
6457 //
6458 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-size-transfers
6459 //
6460 // The spec requires us to clamp these by the specified size (it calls it
6461 // the preferred size). However, we actually don't need to worry about that,
6462 // because we are here only if the inline size is indefinite.
6463 //
6464 // We do not need to clamp the transferred minimum and maximum as long as we
6465 // always apply the transferred min/max size before the explicit min/max
6466 // size; the result will be identical.
6467 const nscoord transferredMinISize =
6468 isAutoMinBSize ? 0
6469 : ComputeISizeValueFromAspectRatio(
6470 aWM, aCBSize, boxSizingAdjust,
6471 minBSizeCoord.AsLengthPercentage(), aspectRatio);
6472 const nscoord transferredMaxISize =
6473 isAutoMaxBSize ? nscoord_MAX
6474 : ComputeISizeValueFromAspectRatio(
6475 aWM, aCBSize, boxSizingAdjust,
6476 maxBSizeCoord.AsLengthPercentage(), aspectRatio);
6477
6478 result.ISize(aWM) = NS_CSS_MINMAX(result.ISize(aWM), transferredMinISize,
6479 transferredMaxISize);
6480 }
6481
6482 // Flex items ignore their min & max sizing properties in their
6483 // flex container's main-axis. (Those properties get applied later in
6484 // the flexbox algorithm.)
6485 const bool isFlexItemInlineAxisMainAxis =
6486 isFlexItem && flexMainAxis == LogicalAxis::Inline;
6487 // Grid items that are subgridded in inline-axis also ignore their min & max
6488 // sizing properties in that axis.
6489 const bool shouldIgnoreMinMaxISize =
6490 isFlexItemInlineAxisMainAxis || isSubgriddedInInlineAxis;
6491 const auto& maxISizeCoord = stylePos->MaxISize(aWM);
6492 nscoord maxISize = NS_UNCONSTRAINEDSIZE;
6493 if (!maxISizeCoord.IsNone() && !shouldIgnoreMinMaxISize) {
6494 maxISize = ComputeISizeValue(aRenderingContext, aWM, aCBSize,
6495 boxSizingAdjust, boxSizingToMarginEdgeISize,
6496 maxISizeCoord, styleBSize, aspectRatio, aFlags)
6497 .mISize;
6498 result.ISize(aWM) = std::min(maxISize, result.ISize(aWM));
6499 }
6500
6501 const auto& minISizeCoord = stylePos->MinISize(aWM);
6502 nscoord minISize;
6503 if (!minISizeCoord.IsAuto() && !shouldIgnoreMinMaxISize) {
6504 minISize = ComputeISizeValue(aRenderingContext, aWM, aCBSize,
6505 boxSizingAdjust, boxSizingToMarginEdgeISize,
6506 minISizeCoord, styleBSize, aspectRatio, aFlags)
6507 .mISize;
6508 } else if (MOZ_UNLIKELY((__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IApplyAutoMinSize
)), 0))
6509 aFlags.contains(ComputeSizeFlag::IApplyAutoMinSize))(__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IApplyAutoMinSize
)), 0))
) {
6510 // This implements "Implied Minimum Size of Grid Items".
6511 // https://drafts.csswg.org/css-grid/#min-size-auto
6512 minISize = std::min(maxISize, GetMinISize(aRenderingContext));
6513 if (styleISize.IsLengthPercentage()) {
6514 minISize = std::min(minISize, result.ISize(aWM));
6515 } else if (aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize)) {
6516 // "if the grid item spans only grid tracks that have a fixed max track
6517 // sizing function, its automatic minimum size in that dimension is
6518 // further clamped to less than or equal to the size necessary to fit
6519 // its margin box within the resulting grid area (flooring at zero)"
6520 // https://drafts.csswg.org/css-grid/#min-size-auto
6521 auto maxMinISize =
6522 std::max(nscoord(0), aCBSize.ISize(aWM) - aBorderPadding.ISize(aWM) -
6523 aMargin.ISize(aWM));
6524 minISize = std::min(minISize, maxMinISize);
6525 }
6526 } else if (aspectRatioUsage == AspectRatioUsage::ToComputeISize &&
6527 ShouldApplyAutomaticMinimumOnInlineAxis(aWM, disp, stylePos)) {
6528 // This means we successfully applied aspect-ratio and now need to check
6529 // if we need to apply the automatic content-based minimum size:
6530 // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum
6531 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"
, 6532); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasReplacedSizing()"
") (" "aspect-ratio minimums should not apply to replaced elements"
")"); do { *((volatile int*)__null) = 6532; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6532 "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"
, 6532); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasReplacedSizing()"
") (" "aspect-ratio minimums should not apply to replaced elements"
")"); do { *((volatile int*)__null) = 6532; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6533 // The inline size computed by aspect-ratio shouldn't less than the
6534 // min-content size, which should be capped by its maximum inline size.
6535 minISize = std::min(GetMinISize(aRenderingContext), maxISize);
6536 } else {
6537 // Treat "min-width: auto" as 0.
6538 // NOTE: Technically, "auto" is supposed to behave like "min-content" on
6539 // flex items. However, we don't need to worry about that here, because
6540 // flex items' min-sizes are intentionally ignored until the flex
6541 // container explicitly considers them during space distribution.
6542 minISize = 0;
6543 }
6544 result.ISize(aWM) = std::max(minISize, result.ISize(aWM));
6545
6546 // Compute block-axis size
6547 // (but not if we have auto bsize -- then, we'll just stick with the bsize
6548 // that we already calculated in the initial ComputeAutoSize() call. However,
6549 // if we have a valid preferred aspect ratio, we still have to compute the
6550 // block size because aspect ratio affects the intrinsic content size.)
6551 const bool isSubgriddedInBlockAxis =
6552 isSubgrid && static_cast<nsGridContainerFrame*>(this)->IsRowSubgrid();
6553
6554 // Per https://drafts.csswg.org/css-grid/#subgrid-box-alignment, if we are
6555 // subgridded in the block-axis, ignore our style block-size, and stretch to
6556 // fill the CB.
6557 const bool shouldComputeBSize = !isAutoBSize && !isSubgriddedInBlockAxis;
6558 if (shouldComputeBSize) {
6559 result.BSize(aWM) = nsLayoutUtils::ComputeBSizeValue(
6560 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6561 styleBSize.AsLengthPercentage());
6562 } else if (MOZ_UNLIKELY(isGridItem)(__builtin_expect(!!(isGridItem), 0)) && styleBSize.IsAuto() &&
6563 !aFlags.contains(ComputeSizeFlag::IsGridMeasuringReflow) &&
6564 !IsTrueOverflowContainer() &&
6565 !alignCB->IsMasonry(isOrthogonal ? LogicalAxis::Inline
6566 : LogicalAxis::Block)) {
6567 auto cbSize = aCBSize.BSize(aWM);
6568 if (cbSize != NS_UNCONSTRAINEDSIZE) {
6569 // 'auto' block-size for grid-level box - fill the CB for 'stretch' /
6570 // 'normal' and clamp it to the CB if requested:
6571 bool stretch = false;
6572 bool mayUseAspectRatio =
6573 aspectRatio && result.ISize(aWM) != NS_UNCONSTRAINEDSIZE;
6574 if (!StyleMargin()->HasBlockAxisAuto(aWM)) {
6575 auto blockAxisAlignment =
6576 isOrthogonal ? StylePosition()->UsedJustifySelf(alignCB->Style())._0
6577 : StylePosition()->UsedAlignSelf(alignCB->Style())._0;
6578 stretch = blockAxisAlignment == StyleAlignFlags::STRETCH ||
6579 (blockAxisAlignment == StyleAlignFlags::NORMAL &&
6580 !mayUseAspectRatio);
6581 }
6582
6583 // Apply the preferred aspect ratio for alignments other than *stretch*
6584 // and *normal without aspect ratio*.
6585 // The spec says all other values should size the items as fit-content,
6586 // and the intrinsic size should respect the preferred aspect ratio, so
6587 // we also apply aspect ratio for all other values.
6588 // https://drafts.csswg.org/css-grid/#grid-item-sizing
6589 if (!stretch && mayUseAspectRatio) {
6590 result.BSize(aWM) = aspectRatio.ComputeRatioDependentSize(
6591 LogicalAxis::Block, aWM, result.ISize(aWM), boxSizingAdjust);
6592 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"
, 6592); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aspectRatioUsage == AspectRatioUsage::None"
")"); do { *((volatile int*)__null) = 6592; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6593 aspectRatioUsage = AspectRatioUsage::ToComputeBSize;
6594 }
6595
6596 if (stretch || aFlags.contains(ComputeSizeFlag::BClampMarginBoxMinSize)) {
6597 auto bSizeToFillCB =
6598 std::max(nscoord(0),
6599 cbSize - aBorderPadding.BSize(aWM) - aMargin.BSize(aWM));
6600 if (stretch || (result.BSize(aWM) != NS_UNCONSTRAINEDSIZE &&
6601 result.BSize(aWM) > bSizeToFillCB)) {
6602 result.BSize(aWM) = bSizeToFillCB;
6603 }
6604 }
6605 }
6606 } else if (aspectRatio) {
6607 // If both inline and block dimensions are auto, the block axis is the
6608 // ratio-dependent axis by default.
6609 // If we have a super large inline size, aspect-ratio should still be
6610 // applied (so aspectRatioUsage flag is set as expected). That's why we
6611 // apply aspect-ratio unconditionally for auto block size here.
6612 result.BSize(aWM) = aspectRatio.ComputeRatioDependentSize(
6613 LogicalAxis::Block, aWM, result.ISize(aWM), boxSizingAdjust);
6614 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"
, 6614); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aspectRatioUsage == AspectRatioUsage::None"
")"); do { *((volatile int*)__null) = 6614; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6615 aspectRatioUsage = AspectRatioUsage::ToComputeBSize;
6616 }
6617
6618 if (result.BSize(aWM) != NS_UNCONSTRAINEDSIZE) {
6619 // Flex items ignore their min & max sizing properties in their flex
6620 // container's main-axis. (Those properties get applied later in the flexbox
6621 // algorithm.)
6622 const bool isFlexItemBlockAxisMainAxis =
6623 isFlexItem && flexMainAxis == LogicalAxis::Block;
6624 // Grid items that are subgridded in block-axis also ignore their min & max
6625 // sizing properties in that axis.
6626 const bool shouldIgnoreMinMaxBSize =
6627 isFlexItemBlockAxisMainAxis || isSubgriddedInBlockAxis;
6628 if (!isAutoMaxBSize && !shouldIgnoreMinMaxBSize) {
6629 nscoord maxBSize = nsLayoutUtils::ComputeBSizeValue(
6630 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6631 maxBSizeCoord.AsLengthPercentage());
6632 result.BSize(aWM) = std::min(maxBSize, result.BSize(aWM));
6633 }
6634
6635 if (!isAutoMinBSize && !shouldIgnoreMinMaxBSize) {
6636 nscoord minBSize = nsLayoutUtils::ComputeBSizeValue(
6637 aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
6638 minBSizeCoord.AsLengthPercentage());
6639 result.BSize(aWM) = std::max(minBSize, result.BSize(aWM));
6640 }
6641 }
6642
6643 if (IsThemed(disp)) {
6644 nsPresContext* pc = PresContext();
6645 const LayoutDeviceIntSize widget = pc->Theme()->GetMinimumWidgetSize(
6646 pc, this, disp->EffectiveAppearance());
6647
6648 // Convert themed widget's physical dimensions to logical coords
6649 LogicalSize size(aWM, LayoutDeviceIntSize::ToAppUnits(
6650 widget, pc->AppUnitsPerDevPixel()));
6651
6652 // GetMinimumWidgetSize() returns border-box; we need content-box.
6653 size -= aBorderPadding;
6654
6655 if (size.BSize(aWM) > result.BSize(aWM)) {
6656 result.BSize(aWM) = size.BSize(aWM);
6657 }
6658 if (size.ISize(aWM) > result.ISize(aWM)) {
6659 result.ISize(aWM) = size.ISize(aWM);
6660 }
6661 }
6662
6663 result.ISize(aWM) = std::max(0, result.ISize(aWM));
6664 result.BSize(aWM) = std::max(0, result.BSize(aWM));
6665
6666 return {result, aspectRatioUsage};
6667}
6668
6669nsRect nsIFrame::ComputeTightBounds(DrawTarget* aDrawTarget) const {
6670 return InkOverflowRect();
6671}
6672
6673/* virtual */
6674nsresult nsIFrame::GetPrefWidthTightBounds(gfxContext* aContext, nscoord* aX,
6675 nscoord* aXMost) {
6676 return NS_ERROR_NOT_IMPLEMENTED;
6677}
6678
6679/* virtual */
6680LogicalSize nsIFrame::ComputeAutoSize(
6681 gfxContext* aRenderingContext, WritingMode aWM,
6682 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
6683 const mozilla::LogicalSize& aMargin,
6684 const mozilla::LogicalSize& aBorderPadding,
6685 const StyleSizeOverrides& aSizeOverrides, ComputeSizeFlags aFlags) {
6686 // Use basic shrink-wrapping as a default implementation.
6687 LogicalSize result(aWM, 0xdeadbeef, NS_UNCONSTRAINEDSIZE);
6688
6689 // don't bother setting it if the result won't be used
6690 const auto& styleISize = aSizeOverrides.mStyleISize
6691 ? *aSizeOverrides.mStyleISize
6692 : StylePosition()->ISize(aWM);
6693 if (styleISize.IsAuto()) {
6694 nscoord availBased =
6695 aAvailableISize - aMargin.ISize(aWM) - aBorderPadding.ISize(aWM);
6696 result.ISize(aWM) = ShrinkISizeToFit(aRenderingContext, availBased, aFlags);
6697 }
6698 return result;
6699}
6700
6701nscoord nsIFrame::ShrinkISizeToFit(gfxContext* aRenderingContext,
6702 nscoord aISizeInCB,
6703 ComputeSizeFlags aFlags) {
6704 // If we're a container for font size inflation, then shrink
6705 // wrapping inside of us should not apply font size inflation.
6706 AutoMaybeDisableFontInflation an(this);
6707
6708 nscoord result;
6709 nscoord minISize = GetMinISize(aRenderingContext);
6710 if (minISize > aISizeInCB) {
6711 const bool clamp = aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize);
6712 result = MOZ_UNLIKELY(clamp)(__builtin_expect(!!(clamp), 0)) ? aISizeInCB : minISize;
6713 } else {
6714 nscoord prefISize = GetPrefISize(aRenderingContext);
6715 if (prefISize > aISizeInCB) {
6716 result = aISizeInCB;
6717 } else {
6718 result = prefISize;
6719 }
6720 }
6721 return result;
6722}
6723
6724nscoord nsIFrame::IntrinsicISizeFromInline(gfxContext* aContext,
6725 IntrinsicISizeType aType) {
6726 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"
, 6727); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsContainerForFontSizeInflation()"
") (" "Should not be a container for font size inflation!" ")"
); do { *((volatile int*)__null) = 6727; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6727 "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"
, 6727); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!IsContainerForFontSizeInflation()"
") (" "Should not be a container for font size inflation!" ")"
); do { *((volatile int*)__null) = 6727; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6728
6729 if (aType == IntrinsicISizeType::MinISize) {
6730 InlineMinISizeData data;
6731 AddInlineMinISize(aContext, &data);
6732 data.ForceBreak();
6733 return data.mPrevLines;
6734 }
6735
6736 InlinePrefISizeData data;
6737 AddInlinePrefISize(aContext, &data);
6738 data.ForceBreak();
6739 return data.mPrevLines;
6740}
6741
6742nscoord nsIFrame::ComputeISizeValueFromAspectRatio(
6743 WritingMode aWM, const LogicalSize& aCBSize,
6744 const LogicalSize& aContentEdgeToBoxSizing, const LengthPercentage& aBSize,
6745 const AspectRatio& aAspectRatio) const {
6746 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"
, 6746); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aAspectRatio"
") (" "Must have a valid AspectRatio!" ")"); do { *((volatile
int*)__null) = 6746; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
6747 const nscoord bSize = nsLayoutUtils::ComputeBSizeValue(
6748 aCBSize.BSize(aWM), aContentEdgeToBoxSizing.BSize(aWM), aBSize);
6749 return aAspectRatio.ComputeRatioDependentSize(LogicalAxis::Inline, aWM, bSize,
6750 aContentEdgeToBoxSizing);
6751}
6752
6753nsIFrame::ISizeComputationResult nsIFrame::ComputeISizeValue(
6754 gfxContext* aRenderingContext, const WritingMode aWM,
6755 const LogicalSize& aCBSize, const LogicalSize& aContentEdgeToBoxSizing,
6756 nscoord aBoxSizingToMarginEdge, ExtremumLength aSize,
6757 Maybe<nscoord> aAvailableISizeOverride, const StyleSize& aStyleBSize,
6758 const AspectRatio& aAspectRatio, ComputeSizeFlags aFlags) {
6759 auto GetAvailableISize = [&]() {
6760 return aCBSize.ISize(aWM) - aBoxSizingToMarginEdge -
6761 aContentEdgeToBoxSizing.ISize(aWM);
6762 };
6763
6764 // If 'this' is a container for font size inflation, then shrink
6765 // wrapping inside of it should not apply font size inflation.
6766 AutoMaybeDisableFontInflation an(this);
6767 // If we have an aspect-ratio and a definite block size, we should use them to
6768 // resolve the sizes with intrinsic keywords.
6769 // https://github.com/w3c/csswg-drafts/issues/5032
6770 Maybe<nscoord> iSizeFromAspectRatio = [&]() -> Maybe<nscoord> {
6771 if (aSize == ExtremumLength::MozAvailable ||
6772 aSize == ExtremumLength::Stretch) {
6773 return Nothing();
6774 }
6775 if (!aAspectRatio) {
6776 return Nothing();
6777 }
6778 if (nsLayoutUtils::IsAutoBSize(aStyleBSize, aCBSize.BSize(aWM))) {
6779 return Nothing();
6780 }
6781 return Some(ComputeISizeValueFromAspectRatio(
6782 aWM, aCBSize, aContentEdgeToBoxSizing, aStyleBSize.AsLengthPercentage(),
6783 aAspectRatio));
6784 }();
6785
6786 nscoord result;
6787 switch (aSize) {
6788 case ExtremumLength::MaxContent:
6789 result = iSizeFromAspectRatio ? *iSizeFromAspectRatio
6790 : GetPrefISize(aRenderingContext);
6791 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"
, 6791); MOZ_PretendNoReturn(); } } while (0)
;
6792 return {result, iSizeFromAspectRatio ? AspectRatioUsage::ToComputeISize
6793 : AspectRatioUsage::None};
6794 case ExtremumLength::MinContent:
6795 result = iSizeFromAspectRatio ? *iSizeFromAspectRatio
6796 : GetMinISize(aRenderingContext);
6797 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"
, 6797); MOZ_PretendNoReturn(); } } while (0)
;
6798 if (MOZ_UNLIKELY((__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
6799 aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize))(__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
) {
6800 result = std::min(GetAvailableISize(), result);
6801 }
6802 return {result, iSizeFromAspectRatio ? AspectRatioUsage::ToComputeISize
6803 : AspectRatioUsage::None};
6804 case ExtremumLength::FitContentFunction:
6805 case ExtremumLength::FitContent: {
6806 nscoord pref = NS_UNCONSTRAINEDSIZE;
6807 nscoord min = 0;
6808 if (iSizeFromAspectRatio) {
6809 // The min-content and max-content size are identical and equal to the
6810 // size computed from the block size and the aspect ratio.
6811 pref = min = *iSizeFromAspectRatio;
6812 } else {
6813 pref = GetPrefISize(aRenderingContext);
6814 min = GetMinISize(aRenderingContext);
6815 }
6816
6817 const nscoord fill = aAvailableISizeOverride ? *aAvailableISizeOverride
6818 : GetAvailableISize();
6819 if (MOZ_UNLIKELY((__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
6820 aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize))(__builtin_expect(!!(aFlags.contains(ComputeSizeFlag::IClampMarginBoxMinSize
)), 0))
) {
6821 min = std::min(min, fill);
6822 }
6823 result = std::max(min, std::min(pref, fill));
6824 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"
, 6824); MOZ_PretendNoReturn(); } } while (0)
;
6825 return {result};
6826 }
6827 case ExtremumLength::MozAvailable:
6828 case ExtremumLength::Stretch:
6829 return {GetAvailableISize()};
6830 }
6831 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"
, 6831); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Unknown extremum length?" ")"); do
{ *((volatile int*)__null) = 6831; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
6832 return {};
6833}
6834
6835nscoord nsIFrame::ComputeISizeValue(const WritingMode aWM,
6836 const LogicalSize& aCBSize,
6837 const LogicalSize& aContentEdgeToBoxSizing,
6838 const LengthPercentage& aSize) const {
6839 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"
, 6843); } } while (0)
6840 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"
, 6843); } } while (0)
6841 "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"
, 6843); } } while (0)
6842 "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"
, 6843); } } while (0)
6843 "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"
, 6843); } } while (0)
;
6844 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"
, 6844); MOZ_PretendNoReturn(); } } while (0)
;
6845
6846 nscoord result = aSize.Resolve(aCBSize.ISize(aWM));
6847 // The result of a calc() expression might be less than 0; we
6848 // should clamp at runtime (below). (Percentages and coords that
6849 // are less than 0 have already been dropped by the parser.)
6850 result -= aContentEdgeToBoxSizing.ISize(aWM);
6851 return std::max(0, result);
6852}
6853
6854void nsIFrame::DidReflow(nsPresContext* aPresContext,
6855 const ReflowInput* aReflowInput) {
6856 NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, ("nsIFrame::DidReflow"))do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule
))->Level()) & (0x1))) { TraceMsg ("nsIFrame::DidReflow"
); } } while (0)
;
6857
6858 if (IsHiddenByContentVisibilityOfInFlowParentForLayout()) {
6859 RemoveStateBits(NS_FRAME_IN_REFLOW);
6860 return;
6861 }
6862
6863 SVGObserverUtils::InvalidateDirectRenderingObservers(
6864 this, SVGObserverUtils::INVALIDATE_REFLOW);
6865
6866 RemoveStateBits(NS_FRAME_IN_REFLOW | NS_FRAME_FIRST_REFLOW |
6867 NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN);
6868
6869 // Clear bits that were used in ReflowInput::InitResizeFlags (see
6870 // comment there for why we can't clear it there).
6871 SetHasBSizeChange(false);
6872 SetHasPaddingChange(false);
6873
6874 // Notify the percent bsize observer if there is a percent bsize.
6875 // The observer may be able to initiate another reflow with a computed
6876 // bsize. This happens in the case where a table cell has no computed
6877 // bsize but can fabricate one when the cell bsize is known.
6878 if (aReflowInput && aReflowInput->mPercentBSizeObserver && !GetPrevInFlow()) {
6879 const auto& bsize =
6880 aReflowInput->mStylePosition->BSize(aReflowInput->GetWritingMode());
6881 if (bsize.HasPercent()) {
6882 aReflowInput->mPercentBSizeObserver->NotifyPercentBSize(*aReflowInput);
6883 }
6884 }
6885
6886 aPresContext->ReflowedFrame();
6887}
6888
6889void nsIFrame::FinishReflowWithAbsoluteFrames(nsPresContext* aPresContext,
6890 ReflowOutput& aDesiredSize,
6891 const ReflowInput& aReflowInput,
6892 nsReflowStatus& aStatus,
6893 bool aConstrainBSize) {
6894 ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowInput, aStatus,
6895 aConstrainBSize);
6896
6897 FinishAndStoreOverflow(&aDesiredSize, aReflowInput.mStyleDisplay);
6898}
6899
6900void nsIFrame::ReflowAbsoluteFrames(nsPresContext* aPresContext,
6901 ReflowOutput& aDesiredSize,
6902 const ReflowInput& aReflowInput,
6903 nsReflowStatus& aStatus,
6904 bool aConstrainBSize) {
6905 if (HasAbsolutelyPositionedChildren()) {
6906 nsAbsoluteContainingBlock* absoluteContainer = GetAbsoluteContainingBlock();
6907
6908 // Let the absolutely positioned container reflow any absolutely positioned
6909 // child frames that need to be reflowed
6910
6911 // The containing block for the abs pos kids is formed by our padding edge.
6912 nsMargin usedBorder = GetUsedBorder();
6913 nscoord containingBlockWidth =
6914 std::max(0, aDesiredSize.Width() - usedBorder.LeftRight());
6915 nscoord containingBlockHeight =
6916 std::max(0, aDesiredSize.Height() - usedBorder.TopBottom());
6917 nsContainerFrame* container = do_QueryFrame(this);
6918 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"
, 6919); MOZ_PretendNoReturn(); } } while (0)
6919 "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"
, 6919); MOZ_PretendNoReturn(); } } while (0)
;
6920
6921 nsRect containingBlock(0, 0, containingBlockWidth, containingBlockHeight);
6922 AbsPosReflowFlags flags =
6923 AbsPosReflowFlags::CBWidthAndHeightChanged; // XXX could be optimized
6924 if (aConstrainBSize) {
6925 flags |= AbsPosReflowFlags::ConstrainHeight;
6926 }
6927 absoluteContainer->Reflow(container, aPresContext, aReflowInput, aStatus,
6928 containingBlock, flags,
6929 &aDesiredSize.mOverflowAreas);
6930 }
6931}
6932
6933/* virtual */
6934bool nsIFrame::CanContinueTextRun() const {
6935 // By default, a frame will *not* allow a text run to be continued
6936 // through it.
6937 return false;
6938}
6939
6940void nsIFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
6941 const ReflowInput& aReflowInput,
6942 nsReflowStatus& aStatus) {
6943 MarkInReflow();
6944 DO_GLOBAL_REFLOW_COUNT("nsFrame")aPresContext->CountReflows(("nsFrame"), (nsIFrame*)this);;
6945 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"
, 6945); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStatus.IsEmpty()"
") (" "Caller should pass a fresh reflow status!" ")"); do {
*((volatile int*)__null) = 6945; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
6946 aDesiredSize.ClearSize();
6947}
6948
6949bool nsIFrame::IsContentDisabled() const {
6950 // FIXME(emilio): Doing this via CSS means callers must ensure the style is up
6951 // to date, and they don't!
6952 if (StyleUI()->UserInput() == StyleUserInput::None) {
6953 return true;
6954 }
6955
6956 auto* element = nsGenericHTMLElement::FromNodeOrNull(GetContent());
6957 return element && element->IsDisabled();
6958}
6959
6960bool nsIFrame::IsContentRelevant() const {
6961 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"
, 6962); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 6962; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6962 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"
, 6962); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 6962; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6963
6964 auto* element = Element::FromNodeOrNull(GetContent());
6965 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"
, 6965); AnnotateMozCrashReason("MOZ_ASSERT" "(" "element" ")"
); do { *((volatile int*)__null) = 6965; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6966
6967 Maybe<ContentRelevancy> relevancy = element->GetContentRelevancy();
6968 return relevancy.isSome() && !relevancy->isEmpty();
6969}
6970
6971bool nsIFrame::HidesContent(
6972 const EnumSet<IncludeContentVisibility>& aInclude) const {
6973 auto effectiveContentVisibility = StyleDisplay()->ContentVisibility(*this);
6974 if (aInclude.contains(IncludeContentVisibility::Hidden) &&
6975 effectiveContentVisibility == StyleContentVisibility::Hidden) {
6976 return true;
6977 }
6978
6979 if (aInclude.contains(IncludeContentVisibility::Auto) &&
6980 effectiveContentVisibility == StyleContentVisibility::Auto) {
6981 return !IsContentRelevant();
6982 }
6983
6984 return false;
6985}
6986
6987bool nsIFrame::HidesContentForLayout() const {
6988 return HidesContent() && !PresShell()->IsForcingLayoutForHiddenContent(this);
6989}
6990
6991bool nsIFrame::IsHiddenByContentVisibilityOfInFlowParentForLayout() const {
6992 const auto* parent = GetInFlowParent();
6993 // The anonymous children owned by parent are important for properly sizing
6994 // their parents.
6995 return parent && parent->HidesContentForLayout() &&
6996 !(parent->HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES) &&
6997 Style()->IsAnonBox());
6998}
6999
7000nsIFrame* nsIFrame::GetClosestContentVisibilityAncestor(
7001 const EnumSet<IncludeContentVisibility>& aInclude) const {
7002 auto* parent = GetInFlowParent();
7003 bool isAnonymousBlock = Style()->IsAnonBox() && parent &&
7004 parent->HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES);
7005 for (nsIFrame* cur = parent; cur; cur = cur->GetInFlowParent()) {
7006 if (!isAnonymousBlock && cur->HidesContent(aInclude)) {
7007 return cur;
7008 }
7009
7010 // Anonymous boxes are not hidden by the content-visibility of their first
7011 // non-anonymous ancestor, but can be hidden by ancestors further up the
7012 // tree.
7013 isAnonymousBlock = false;
7014 }
7015
7016 return nullptr;
7017}
7018
7019bool nsIFrame::IsHiddenByContentVisibilityOnAnyAncestor(
7020 const EnumSet<IncludeContentVisibility>& aInclude) const {
7021 return !!GetClosestContentVisibilityAncestor(aInclude);
7022}
7023
7024bool nsIFrame::HasSelectionInSubtree() {
7025 if (IsSelected()) {
7026 return true;
7027 }
7028
7029 RefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
7030 if (!frameSelection) {
7031 return false;
7032 }
7033
7034 const Selection* selection =
7035 frameSelection->GetSelection(SelectionType::eNormal);
7036 if (!selection) {
7037 return false;
7038 }
7039
7040 for (uint32_t i = 0; i < selection->RangeCount(); i++) {
7041 auto* range = selection->GetRangeAt(i);
7042 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"
, 7042); AnnotateMozCrashReason("MOZ_ASSERT" "(" "range" ")")
; do { *((volatile int*)__null) = 7042; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7043
7044 const auto* commonAncestorNode =
7045 range->GetRegisteredClosestCommonInclusiveAncestor();
7046 if (commonAncestorNode &&
7047 commonAncestorNode->IsInclusiveDescendantOf(GetContent())) {
7048 return true;
7049 }
7050 }
7051
7052 return false;
7053}
7054
7055bool nsIFrame::UpdateIsRelevantContent(
7056 const ContentRelevancy& aRelevancyToUpdate) {
7057 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"
, 7058); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 7058; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
7058 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"
, 7058); AnnotateMozCrashReason("MOZ_ASSERT" "(" "StyleDisplay()->ContentVisibility(*this) == StyleContentVisibility::Auto"
")"); do { *((volatile int*)__null) = 7058; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7059
7060 auto* element = Element::FromNodeOrNull(GetContent());
7061 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"
, 7061); AnnotateMozCrashReason("MOZ_ASSERT" "(" "element" ")"
); do { *((volatile int*)__null) = 7061; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7062
7063 ContentRelevancy newRelevancy;
7064 Maybe<ContentRelevancy> oldRelevancy = element->GetContentRelevancy();
7065 if (oldRelevancy.isSome()) {
7066 newRelevancy = *oldRelevancy;
7067 }
7068
7069 auto setRelevancyValue = [&](ContentRelevancyReason reason, bool value) {
7070 if (value) {
7071 newRelevancy += reason;
7072 } else {
7073 newRelevancy -= reason;
7074 }
7075 };
7076
7077 if (!oldRelevancy ||
7078 aRelevancyToUpdate.contains(ContentRelevancyReason::Visible)) {
7079 Maybe<bool> visible = element->GetVisibleForContentVisibility();
7080 if (visible.isSome()) {
7081 setRelevancyValue(ContentRelevancyReason::Visible, *visible);
7082 }
7083 }
7084
7085 if (!oldRelevancy ||
7086 aRelevancyToUpdate.contains(ContentRelevancyReason::FocusInSubtree)) {
7087 setRelevancyValue(ContentRelevancyReason::FocusInSubtree,
7088 element->State().HasAtLeastOneOfStates(
7089 ElementState::FOCUS_WITHIN | ElementState::FOCUS));
7090 }
7091
7092 if (!oldRelevancy ||
7093 aRelevancyToUpdate.contains(ContentRelevancyReason::Selected)) {
7094 setRelevancyValue(ContentRelevancyReason::Selected,
7095 HasSelectionInSubtree());
7096 }
7097
7098 // If the proximity to the viewport has not been determined yet,
7099 // and neither the element nor its contents are focused or selected,
7100 // we should wait for the determination of the proximity. Otherwise,
7101 // there might be a redundant contentvisibilityautostatechange event.
7102 // See https://github.com/w3c/csswg-drafts/issues/9803
7103 bool isProximityToViewportDetermined =
7104 oldRelevancy ? true : element->GetVisibleForContentVisibility().isSome();
7105 if (!isProximityToViewportDetermined && newRelevancy.isEmpty()) {
7106 return false;
7107 }
7108
7109 bool overallRelevancyChanged =
7110 !oldRelevancy || oldRelevancy->isEmpty() != newRelevancy.isEmpty();
7111 if (!oldRelevancy || *oldRelevancy != newRelevancy) {
7112 element->SetContentRelevancy(newRelevancy);
7113 }
7114
7115 if (!overallRelevancyChanged) {
7116 return false;
7117 }
7118
7119 HandleLastRememberedSize();
7120 PresContext()->SetNeedsToUpdateHiddenByContentVisibilityForAnimations();
7121 PresShell()->FrameNeedsReflow(
7122 this, IntrinsicDirty::FrameAncestorsAndDescendants, NS_FRAME_IS_DIRTY);
7123 InvalidateFrame();
7124
7125 ContentVisibilityAutoStateChangeEventInit init;
7126 init.mSkipped = newRelevancy.isEmpty();
7127 RefPtr<ContentVisibilityAutoStateChangeEvent> event =
7128 ContentVisibilityAutoStateChangeEvent::Constructor(
7129 element, u"contentvisibilityautostatechange"_ns, init);
7130
7131 // Per
7132 // https://drafts.csswg.org/css-contain/#content-visibility-auto-state-changed
7133 // "This event is dispatched by posting a task at the time when the state
7134 // change occurs."
7135 RefPtr<AsyncEventDispatcher> asyncDispatcher =
7136 new AsyncEventDispatcher(element, event.forget());
7137 DebugOnly<nsresult> rv = asyncDispatcher->PostDOMEvent();
7138 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"
, 7138); MOZ_PretendNoReturn(); } } while (0)
;
7139 return true;
7140}
7141
7142nsresult nsIFrame::CharacterDataChanged(const CharacterDataChangeInfo&) {
7143 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"
, 7143); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should only be called for text frames"
")"); do { *((volatile int*)__null) = 7143; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7144 return NS_OK;
7145}
7146
7147nsresult nsIFrame::AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
7148 int32_t aModType) {
7149 return NS_OK;
7150}
7151
7152nsIFrame* nsIFrame::GetPrevContinuation() const { return nullptr; }
7153
7154void nsIFrame::SetPrevContinuation(nsIFrame*) {
7155 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"
, 7155); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Not splittable!" ")"); do { *((volatile
int*)__null) = 7155; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7156}
7157
7158nsIFrame* nsIFrame::GetNextContinuation() const { return nullptr; }
7159
7160void nsIFrame::SetNextContinuation(nsIFrame*) {
7161 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"
, 7161); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Not splittable!" ")"); do { *((volatile
int*)__null) = 7161; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7162}
7163
7164nsIFrame* nsIFrame::GetPrevInFlow() const { return nullptr; }
7165
7166void nsIFrame::SetPrevInFlow(nsIFrame*) {
7167 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"
, 7167); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Not splittable!" ")"); do { *((volatile
int*)__null) = 7167; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7168}
7169
7170nsIFrame* nsIFrame::GetNextInFlow() const { return nullptr; }
7171
7172void nsIFrame::SetNextInFlow(nsIFrame*) {
7173 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"
, 7173); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Not splittable!" ")"); do { *((volatile
int*)__null) = 7173; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7174}
7175
7176nsIFrame* nsIFrame::GetTailContinuation() {
7177 nsIFrame* frame = this;
7178 while (frame->HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER)) {
7179 frame = frame->GetPrevContinuation();
7180 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"
, 7180); MOZ_PretendNoReturn(); } } while (0)
;
7181 }
7182 for (nsIFrame* next = frame->GetNextContinuation();
7183 next && !next->HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER);
7184 next = frame->GetNextContinuation()) {
7185 frame = next;
7186 }
7187
7188 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"
, 7188); AnnotateMozCrashReason("MOZ_ASSERT" "(" "frame" ") ("
"illegal state in continuation chain." ")"); do { *((volatile
int*)__null) = 7188; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7189 return frame;
7190}
7191
7192// Associated view object
7193void nsIFrame::SetView(nsView* aView) {
7194 if (aView) {
7195 aView->SetFrame(this);
7196
7197#ifdef DEBUG1
7198 LayoutFrameType frameType = Type();
7199 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"
, 7203); MOZ_PretendNoReturn(); } } while (0)
7200 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"
, 7203); MOZ_PretendNoReturn(); } } while (0)
7201 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"
, 7203); MOZ_PretendNoReturn(); } } while (0)
7202 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"
, 7203); MOZ_PretendNoReturn(); } } while (0)
7203 "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"
, 7203); MOZ_PretendNoReturn(); } } while (0)
;
7204#endif
7205
7206 // Store the view on the frame.
7207 SetViewInternal(aView);
7208
7209 // Set the frame state bit that says the frame has a view
7210 AddStateBits(NS_FRAME_HAS_VIEW);
7211
7212 // Let all of the ancestors know they have a descendant with a view.
7213 for (nsIFrame* f = GetParent();
7214 f && !f->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
7215 f = f->GetParent())
7216 f->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
7217 } else {
7218 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"
, 7218); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Destroying a view while the frame is alive?"
")"); do { *((volatile int*)__null) = 7218; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7219 RemoveStateBits(NS_FRAME_HAS_VIEW);
7220 SetViewInternal(nullptr);
7221 }
7222}
7223
7224// Find the first geometric parent that has a view
7225nsIFrame* nsIFrame::GetAncestorWithView() const {
7226 for (nsIFrame* f = GetParent(); nullptr != f; f = f->GetParent()) {
7227 if (f->HasView()) {
7228 return f;
7229 }
7230 }
7231 return nullptr;
7232}
7233
7234template <nsPoint (nsIFrame::*PositionGetter)() const>
7235static nsPoint OffsetCalculator(const nsIFrame* aThis, const nsIFrame* aOther) {
7236 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"
, 7236); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOther" ") ("
"Must have frame for destination coordinate system!" ")"); do
{ *((volatile int*)__null) = 7236; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
7237
7238 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"
, 7239); MOZ_PretendNoReturn(); } } while (0)
7239 "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"
, 7239); MOZ_PretendNoReturn(); } } while (0)
;
7240
7241 nsPoint offset(0, 0);
7242 const nsIFrame* f;
7243 for (f = aThis; f != aOther && f; f = f->GetParent()) {
7244 offset += (f->*PositionGetter)();
7245 }
7246
7247 if (f != aOther) {
7248 // Looks like aOther wasn't an ancestor of |this|. So now we have
7249 // the root-frame-relative position of |this| in |offset|. Convert back
7250 // to the coordinates of aOther
7251 while (aOther) {
7252 offset -= (aOther->*PositionGetter)();
7253 aOther = aOther->GetParent();
7254 }
7255 }
7256
7257 return offset;
7258}
7259
7260nsPoint nsIFrame::GetOffsetTo(const nsIFrame* aOther) const {
7261 return OffsetCalculator<&nsIFrame::GetPosition>(this, aOther);
7262}
7263
7264nsPoint nsIFrame::GetOffsetToIgnoringScrolling(const nsIFrame* aOther) const {
7265 return OffsetCalculator<&nsIFrame::GetPositionIgnoringScrolling>(this,
7266 aOther);
7267}
7268
7269nsPoint nsIFrame::GetOffsetToCrossDoc(const nsIFrame* aOther) const {
7270 return GetOffsetToCrossDoc(aOther, PresContext()->AppUnitsPerDevPixel());
7271}
7272
7273nsPoint nsIFrame::GetOffsetToCrossDoc(const nsIFrame* aOther,
7274 const int32_t aAPD) const {
7275 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"
, 7275); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOther" ") ("
"Must have frame for destination coordinate system!" ")"); do
{ *((volatile int*)__null) = 7275; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
7276 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"
, 7280); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
") (" "trying to get the offset between frames in different document "
"hierarchies?" ")"); do { *((volatile int*)__null) = 7280; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
7277 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"
, 7280); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
") (" "trying to get the offset between frames in different document "
"hierarchies?" ")"); do { *((volatile int*)__null) = 7280; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
7278 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"
, 7280); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
") (" "trying to get the offset between frames in different document "
"hierarchies?" ")"); do { *((volatile int*)__null) = 7280; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
7279 "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"
, 7280); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
") (" "trying to get the offset between frames in different document "
"hierarchies?" ")"); do { *((volatile int*)__null) = 7280; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
7280 "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"
, 7280); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "PresContext()->GetRootPresContext() == aOther->PresContext()->GetRootPresContext()"
") (" "trying to get the offset between frames in different document "
"hierarchies?" ")"); do { *((volatile int*)__null) = 7280; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
7281
7282 const nsIFrame* root = nullptr;
7283 // offset will hold the final offset
7284 // docOffset holds the currently accumulated offset at the current APD, it
7285 // will be converted and added to offset when the current APD changes.
7286 nsPoint offset(0, 0), docOffset(0, 0);
7287 const nsIFrame* f = this;
7288 int32_t currAPD = PresContext()->AppUnitsPerDevPixel();
7289 while (f && f != aOther) {
7290 docOffset += f->GetPosition();
7291 nsIFrame* parent = f->GetParent();
7292 if (parent) {
7293 f = parent;
7294 } else {
7295 nsPoint newOffset(0, 0);
7296 root = f;
7297 f = nsLayoutUtils::GetCrossDocParentFrameInProcess(f, &newOffset);
7298 int32_t newAPD = f ? f->PresContext()->AppUnitsPerDevPixel() : 0;
7299 if (!f || newAPD != currAPD) {
7300 // Convert docOffset to the right APD and add it to offset.
7301 offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD);
7302 docOffset.x = docOffset.y = 0;
7303 }
7304 currAPD = newAPD;
7305 docOffset += newOffset;
7306 }
7307 }
7308 if (f == aOther) {
7309 offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD);
7310 } else {
7311 // Looks like aOther wasn't an ancestor of |this|. So now we have
7312 // the root-document-relative position of |this| in |offset|. Subtract the
7313 // root-document-relative position of |aOther| from |offset|.
7314 // This call won't try to recurse again because root is an ancestor of
7315 // aOther.
7316 nsPoint negOffset = aOther->GetOffsetToCrossDoc(root, aAPD);
7317 offset -= negOffset;
7318 }
7319
7320 return offset;
7321}
7322
7323CSSIntRect nsIFrame::GetScreenRect() const {
7324 return CSSIntRect::FromAppUnitsToNearest(GetScreenRectInAppUnits());
7325}
7326
7327nsRect nsIFrame::GetScreenRectInAppUnits() const {
7328 nsPresContext* presContext = PresContext();
7329 nsIFrame* rootFrame = presContext->PresShell()->GetRootFrame();
7330 nsPoint rootScreenPos(0, 0);
7331 nsPoint rootFrameOffsetInParent(0, 0);
7332 nsIFrame* rootFrameParent = nsLayoutUtils::GetCrossDocParentFrameInProcess(
7333 rootFrame, &rootFrameOffsetInParent);
7334 if (rootFrameParent) {
7335 nsRect parentScreenRectAppUnits =
7336 rootFrameParent->GetScreenRectInAppUnits();
7337 nsPresContext* parentPresContext = rootFrameParent->PresContext();
7338 double parentScale = double(presContext->AppUnitsPerDevPixel()) /
7339 parentPresContext->AppUnitsPerDevPixel();
7340 nsPoint rootPt =
7341 parentScreenRectAppUnits.TopLeft() + rootFrameOffsetInParent;
7342 rootScreenPos.x = NS_round(parentScale * rootPt.x);
7343 rootScreenPos.y = NS_round(parentScale * rootPt.y);
7344 } else {
7345 nsCOMPtr<nsIWidget> rootWidget =
7346 presContext->PresShell()->GetViewManager()->GetRootWidget();
7347 if (rootWidget) {
7348 LayoutDeviceIntPoint rootDevPx = rootWidget->WidgetToScreenOffset();
7349 rootScreenPos.x = presContext->DevPixelsToAppUnits(rootDevPx.x);
7350 rootScreenPos.y = presContext->DevPixelsToAppUnits(rootDevPx.y);
7351 }
7352 }
7353
7354 return nsRect(rootScreenPos + GetOffsetTo(rootFrame), GetSize());
7355}
7356
7357// Returns the offset from this frame to the closest geometric parent that
7358// has a view. Also returns the containing view or null in case of error
7359void nsIFrame::GetOffsetFromView(nsPoint& aOffset, nsView** aView) const {
7360 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"
, 7360); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nullptr != aView"
") (" "null OUT parameter pointer" ")"); do { *((volatile int
*)__null) = 7360; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7361 nsIFrame* frame = const_cast<nsIFrame*>(this);
7362
7363 *aView = nullptr;
7364 aOffset.MoveTo(0, 0);
7365 do {
7366 aOffset += frame->GetPosition();
7367 frame = frame->GetParent();
7368 } while (frame && !frame->HasView());
7369
7370 if (frame) {
7371 *aView = frame->GetView();
7372 }
7373}
7374
7375nsIWidget* nsIFrame::GetNearestWidget() const {
7376 return GetClosestView()->GetNearestWidget(nullptr);
7377}
7378
7379nsIWidget* nsIFrame::GetNearestWidget(nsPoint& aOffset) const {
7380 nsPoint offsetToView;
7381 nsPoint offsetToWidget;
7382 nsIWidget* widget =
7383 GetClosestView(&offsetToView)->GetNearestWidget(&offsetToWidget);
7384 aOffset = offsetToView + offsetToWidget;
7385 return widget;
7386}
7387
7388Matrix4x4Flagged nsIFrame::GetTransformMatrix(ViewportType aViewportType,
7389 RelativeTo aStopAtAncestor,
7390 nsIFrame** aOutAncestor,
7391 uint32_t aFlags) const {
7392 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"
, 7392); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aOutAncestor"
") (" "Need a place to put the ancestor!" ")"); do { *((volatile
int*)__null) = 7392; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
7393
7394 /* If we're transformed, we want to hand back the combination
7395 * transform/translate matrix that will apply our current transform, then
7396 * shift us to our parent.
7397 */
7398 const bool isTransformed = IsTransformed();
7399 const nsIFrame* zoomedContentRoot = nullptr;
7400 if (aStopAtAncestor.mViewportType == ViewportType::Visual) {
7401 zoomedContentRoot = ViewportUtils::IsZoomedContentRoot(this);
7402 if (zoomedContentRoot) {
7403 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"
, 7403); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aViewportType != ViewportType::Visual"
")"); do { *((volatile int*)__null) = 7403; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7404 }
7405 }
7406
7407 if (isTransformed || zoomedContentRoot) {
7408 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"
, 7408); AnnotateMozCrashReason("MOZ_ASSERT" "(" "GetParent()"
")"); do { *((volatile int*)__null) = 7408; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7409 Matrix4x4 result;
7410 int32_t scaleFactor =
7411 ((aFlags & IN_CSS_UNITS) ? AppUnitsPerCSSPixel()
7412 : PresContext()->AppUnitsPerDevPixel());
7413
7414 /* Compute the delta to the parent, which we need because we are converting
7415 * coordinates to our parent.
7416 */
7417 if (isTransformed) {
7418 result = nsDisplayTransform::GetResultingTransformMatrix(
7419 this, nsPoint(), scaleFactor,
7420 nsDisplayTransform::INCLUDE_PERSPECTIVE);
7421 }
7422
7423 // The offset from a zoomed content root to its parent (e.g. from
7424 // a canvas frame to a scroll frame) is in layout coordinates, so
7425 // apply it before applying any layout-to-visual transform.
7426 *aOutAncestor = GetParent();
7427 nsPoint delta = GetPosition();
7428 /* Combine the raw transform with a translation to our parent. */
7429 result.PostTranslate(NSAppUnitsToFloatPixels(delta.x, scaleFactor),
7430 NSAppUnitsToFloatPixels(delta.y, scaleFactor), 0.0f);
7431
7432 if (zoomedContentRoot) {
7433 Matrix4x4 layoutToVisual;
7434 ScrollableLayerGuid::ViewID targetScrollId =
7435 nsLayoutUtils::FindOrCreateIDFor(zoomedContentRoot->GetContent());
7436 if (aFlags & nsIFrame::IN_CSS_UNITS) {
7437 layoutToVisual =
7438 ViewportUtils::GetVisualToLayoutTransform(targetScrollId)
7439 .Inverse()
7440 .ToUnknownMatrix();
7441 } else {
7442 layoutToVisual =
7443 ViewportUtils::GetVisualToLayoutTransform<LayoutDevicePixel>(
7444 targetScrollId)
7445 .Inverse()
7446 .ToUnknownMatrix();
7447 }
7448 result = result * layoutToVisual;
7449 }
7450
7451 return result;
7452 }
7453
7454 // We are not transformed, so the returned transform is just going to be a
7455 // translation up to whatever ancestor we decide to stop at.
7456
7457 nsPoint crossdocOffset;
7458 *aOutAncestor =
7459 nsLayoutUtils::GetCrossDocParentFrameInProcess(this, &crossdocOffset);
7460
7461 /* Otherwise, we're not transformed. In that case, we'll walk up the frame
7462 * tree until we either hit the root frame or something that may be
7463 * transformed. We'll then change coordinates into that frame, since we're
7464 * guaranteed that nothing in-between can be transformed. First, however,
7465 * we have to check to see if we have a parent. If not, we'll set the
7466 * outparam to null (indicating that there's nothing left) and will hand back
7467 * the identity matrix.
7468 */
7469 if (!*aOutAncestor) return Matrix4x4Flagged();
7470
7471 /* Keep iterating while the frame can't possibly be transformed. */
7472 const nsIFrame* current = this;
7473 auto shouldStopAt = [](const nsIFrame* aCurrent, RelativeTo& aStopAtAncestor,
7474 nsIFrame* aOutAncestor, uint32_t aFlags) {
7475 return aOutAncestor->IsTransformed() ||
7476 ((aStopAtAncestor.mViewportType == ViewportType::Visual) &&
7477 ViewportUtils::IsZoomedContentRoot(aOutAncestor)) ||
7478 ((aFlags & STOP_AT_STACKING_CONTEXT_AND_DISPLAY_PORT) &&
7479 (aOutAncestor->IsStackingContext() ||
7480 DisplayPortUtils::FrameHasDisplayPort(aOutAncestor, aCurrent)));
7481 };
7482
7483 // We run the GetOffsetToCrossDoc code here as an optimization, instead of
7484 // walking the parent chain here and then asking GetOffsetToCrossDoc to walk
7485 // the same parent chain and compute the offset.
7486 const int32_t finalAPD = PresContext()->AppUnitsPerDevPixel();
7487 // offset accumulates the offset at finalAPD.
7488 nsPoint offset = GetPosition();
7489
7490 int32_t currAPD = (*aOutAncestor)->PresContext()->AppUnitsPerDevPixel();
7491 // docOffset accumulates the current offset at currAPD, and then flushes to
7492 // offset at finalAPD when the APD changes or we finish.
7493 nsPoint docOffset = crossdocOffset;
7494 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"
, 7494); AnnotateMozCrashReason("MOZ_ASSERT" "(" "crossdocOffset == nsPoint(0, 0) || !GetParent()"
")"); do { *((volatile int*)__null) = 7494; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7495
7496 while (*aOutAncestor != aStopAtAncestor.mFrame &&
7497 !shouldStopAt(current, aStopAtAncestor, *aOutAncestor, aFlags)) {
7498 docOffset += (*aOutAncestor)->GetPosition();
7499
7500 nsIFrame* parent = (*aOutAncestor)->GetParent();
7501 if (!parent) {
7502 crossdocOffset.x = crossdocOffset.y = 0;
7503 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(*aOutAncestor,
7504 &crossdocOffset);
7505
7506 int32_t newAPD =
7507 parent ? parent->PresContext()->AppUnitsPerDevPixel() : currAPD;
7508 if (!parent || newAPD != currAPD) {
7509 // Convert docOffset to finalAPD and add it to offset.
7510 offset += docOffset.ScaleToOtherAppUnits(currAPD, finalAPD);
7511 docOffset.x = docOffset.y = 0;
7512 }
7513 currAPD = newAPD;
7514 docOffset += crossdocOffset;
7515
7516 if (!parent) break;
7517 }
7518
7519 current = *aOutAncestor;
7520 *aOutAncestor = parent;
7521 }
7522 offset += docOffset.ScaleToOtherAppUnits(currAPD, finalAPD);
7523
7524 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"
, 7524); MOZ_PretendNoReturn(); } } while (0)
;
7525
7526 int32_t scaleFactor =
7527 ((aFlags & IN_CSS_UNITS) ? AppUnitsPerCSSPixel()
7528 : PresContext()->AppUnitsPerDevPixel());
7529 return Matrix4x4Flagged::Translation2d(
7530 NSAppUnitsToFloatPixels(offset.x, scaleFactor),
7531 NSAppUnitsToFloatPixels(offset.y, scaleFactor));
7532}
7533
7534static void InvalidateRenderingObservers(nsIFrame* aDisplayRoot,
7535 nsIFrame* aFrame,
7536 bool aFrameChanged = true) {
7537 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"
, 7537); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame)"
")"); do { *((volatile int*)__null) = 7537; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7538 SVGObserverUtils::InvalidateDirectRenderingObservers(aFrame);
7539 nsIFrame* parent = aFrame;
7540 while (parent != aDisplayRoot &&
7541 (parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(parent)) &&
7542 !parent->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) {
7543 SVGObserverUtils::InvalidateDirectRenderingObservers(parent);
7544 }
7545
7546 if (!aFrameChanged) {
7547 return;
7548 }
7549
7550 aFrame->MarkNeedsDisplayItemRebuild();
7551}
7552
7553static void SchedulePaintInternal(
7554 nsIFrame* aDisplayRoot, nsIFrame* aFrame,
7555 nsIFrame::PaintType aType = nsIFrame::PAINT_DEFAULT) {
7556 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"
, 7556); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDisplayRoot == nsLayoutUtils::GetDisplayRootFrame(aFrame)"
")"); do { *((volatile int*)__null) = 7556; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7557 nsPresContext* pres = aDisplayRoot->PresContext()->GetRootPresContext();
7558
7559 // No need to schedule a paint for an external document since they aren't
7560 // painted directly.
7561 if (!pres || (pres->Document() && pres->Document()->IsResourceDoc())) {
7562 return;
7563 }
7564 if (!pres->GetContainerWeak()) {
7565 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"
, 7565)
;
7566 return;
7567 }
7568
7569 pres->PresShell()->ScheduleViewManagerFlush();
7570
7571 if (aType == nsIFrame::PAINT_DEFAULT) {
7572 aDisplayRoot->AddStateBits(NS_FRAME_UPDATE_LAYER_TREE);
7573 }
7574}
7575
7576static void InvalidateFrameInternal(nsIFrame* aFrame, bool aHasDisplayItem,
7577 bool aRebuildDisplayItems) {
7578 if (aHasDisplayItem) {
7579 aFrame->AddStateBits(NS_FRAME_NEEDS_PAINT);
7580 }
7581
7582 if (aRebuildDisplayItems) {
7583 aFrame->MarkNeedsDisplayItemRebuild();
7584 }
7585 SVGObserverUtils::InvalidateDirectRenderingObservers(aFrame);
7586 bool needsSchedulePaint = false;
7587 if (nsLayoutUtils::IsPopup(aFrame)) {
7588 needsSchedulePaint = true;
7589 } else {
7590 nsIFrame* parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(aFrame);
7591 while (parent &&
7592 !parent->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) {
7593 if (aHasDisplayItem && !parent->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY)) {
7594 parent->AddStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT);
7595 }
7596 SVGObserverUtils::InvalidateDirectRenderingObservers(parent);
7597
7598 // If we're inside a popup, then we need to make sure that we
7599 // call schedule paint so that the NS_FRAME_UPDATE_LAYER_TREE
7600 // flag gets added to the popup display root frame.
7601 if (nsLayoutUtils::IsPopup(parent)) {
7602 needsSchedulePaint = true;
7603 break;
7604 }
7605 parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(parent);
7606 }
7607 if (!parent) {
7608 needsSchedulePaint = true;
7609 }
7610 }
7611 if (!aHasDisplayItem) {
7612 return;
7613 }
7614 if (needsSchedulePaint) {
7615 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(aFrame);
7616 SchedulePaintInternal(displayRoot, aFrame);
7617 }
7618 if (aFrame->HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) {
7619 aFrame->RemoveProperty(nsIFrame::InvalidationRect());
7620 aFrame->RemoveStateBits(NS_FRAME_HAS_INVALID_RECT);
7621 }
7622}
7623
7624void nsIFrame::InvalidateFrameSubtree(bool aRebuildDisplayItems /* = true */) {
7625 InvalidateFrame(0, aRebuildDisplayItems);
7626
7627 if (HasAnyStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT)) {
7628 return;
7629 }
7630
7631 AddStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT);
7632
7633 for (const auto& childList : CrossDocChildLists()) {
7634 for (nsIFrame* child : childList.mList) {
7635 // Don't explicitly rebuild display items for our descendants,
7636 // since we should be marked and it implicitly includes all
7637 // descendants.
7638 child->InvalidateFrameSubtree(false);
7639 }
7640 }
7641}
7642
7643void nsIFrame::ClearInvalidationStateBits() {
7644 if (HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT)) {
7645 for (const auto& childList : CrossDocChildLists()) {
7646 for (nsIFrame* child : childList.mList) {
7647 child->ClearInvalidationStateBits();
7648 }
7649 }
7650 }
7651
7652 RemoveStateBits(NS_FRAME_NEEDS_PAINT | NS_FRAME_DESCENDANT_NEEDS_PAINT |
7653 NS_FRAME_ALL_DESCENDANTS_NEED_PAINT);
7654}
7655
7656bool HasRetainedDataFor(const nsIFrame* aFrame, uint32_t aDisplayItemKey) {
7657 if (RefPtr<WebRenderUserData> data =
7658 GetWebRenderUserData<WebRenderFallbackData>(aFrame,
7659 aDisplayItemKey)) {
7660 return true;
7661 }
7662
7663 return false;
7664}
7665
7666void nsIFrame::InvalidateFrame(uint32_t aDisplayItemKey,
7667 bool aRebuildDisplayItems /* = true */) {
7668 bool hasDisplayItem =
7669 !aDisplayItemKey || HasRetainedDataFor(this, aDisplayItemKey);
7670 InvalidateFrameInternal(this, hasDisplayItem, aRebuildDisplayItems);
7671}
7672
7673void nsIFrame::InvalidateFrameWithRect(const nsRect& aRect,
7674 uint32_t aDisplayItemKey,
7675 bool aRebuildDisplayItems /* = true */) {
7676 if (aRect.IsEmpty()) {
7677 return;
7678 }
7679 bool hasDisplayItem =
7680 !aDisplayItemKey || HasRetainedDataFor(this, aDisplayItemKey);
7681 bool alreadyInvalid = false;
7682 if (!HasAnyStateBits(NS_FRAME_NEEDS_PAINT)) {
7683 InvalidateFrameInternal(this, hasDisplayItem, aRebuildDisplayItems);
7684 } else {
7685 alreadyInvalid = true;
7686 }
7687
7688 if (!hasDisplayItem) {
7689 return;
7690 }
7691
7692 nsRect* rect;
7693 if (HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) {
7694 rect = GetProperty(InvalidationRect());
7695 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"
, 7695); AnnotateMozCrashReason("MOZ_ASSERT" "(" "rect" ")");
do { *((volatile int*)__null) = 7695; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7696 } else {
7697 if (alreadyInvalid) {
7698 return;
7699 }
7700 rect = new nsRect();
7701 AddProperty(InvalidationRect(), rect);
7702 AddStateBits(NS_FRAME_HAS_INVALID_RECT);
7703 }
7704
7705 *rect = rect->Union(aRect);
7706}
7707
7708bool nsIFrame::IsInvalid(nsRect& aRect) {
7709 if (!HasAnyStateBits(NS_FRAME_NEEDS_PAINT)) {
7710 return false;
7711 }
7712
7713 if (HasAnyStateBits(NS_FRAME_HAS_INVALID_RECT)) {
7714 nsRect* rect = GetProperty(InvalidationRect());
7715 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"
, 7716); MOZ_PretendNoReturn(); } } while (0)
7716 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"
, 7716); MOZ_PretendNoReturn(); } } while (0)
;
7717 aRect = *rect;
7718 } else {
7719 aRect.SetEmpty();
7720 }
7721 return true;
7722}
7723
7724void nsIFrame::SchedulePaint(PaintType aType, bool aFrameChanged) {
7725 if (PresShell()->IsPaintingSuppressed()) {
7726 // We can't have any display items yet, and when we unsuppress we will
7727 // invalidate the root frame.
7728 return;
7729 }
7730 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this);
7731 InvalidateRenderingObservers(displayRoot, this, aFrameChanged);
7732 SchedulePaintInternal(displayRoot, this, aType);
7733}
7734
7735void nsIFrame::SchedulePaintWithoutInvalidatingObservers(PaintType aType) {
7736 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this);
7737 SchedulePaintInternal(displayRoot, this, aType);
7738}
7739
7740void nsIFrame::InvalidateLayer(DisplayItemType aDisplayItemKey,
7741 const nsIntRect* aDamageRect,
7742 const nsRect* aFrameDamageRect,
7743 uint32_t aFlags /* = 0 */) {
7744 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"
, 7744); MOZ_PretendNoReturn(); } } while (0)
;
7745
7746 nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(this);
7747 InvalidateRenderingObservers(displayRoot, this, false);
7748
7749 // Check if frame supports WebRender's async update
7750 if ((aFlags & UPDATE_IS_ASYNC) &&
7751 WebRenderUserData::SupportsAsyncUpdate(this)) {
7752 // WebRender does not use layer, then return nullptr.
7753 return;
7754 }
7755
7756 if (aFrameDamageRect && aFrameDamageRect->IsEmpty()) {
7757 return;
7758 }
7759
7760 // In the bug 930056, dialer app startup but not shown on the
7761 // screen because sometimes we don't have any retainned data
7762 // for remote type displayitem and thus Repaint event is not
7763 // triggered. So, always invalidate in this case.
7764 DisplayItemType displayItemKey = aDisplayItemKey;
7765 if (aDisplayItemKey == DisplayItemType::TYPE_REMOTE) {
7766 displayItemKey = DisplayItemType::TYPE_ZERO;
7767 }
7768
7769 if (aFrameDamageRect) {
7770 InvalidateFrameWithRect(*aFrameDamageRect,
7771 static_cast<uint32_t>(displayItemKey));
7772 } else {
7773 InvalidateFrame(static_cast<uint32_t>(displayItemKey));
7774 }
7775}
7776
7777static nsRect ComputeEffectsRect(nsIFrame* aFrame, const nsRect& aOverflowRect,
7778 const nsSize& aNewSize) {
7779 nsRect r = aOverflowRect;
7780
7781 if (aFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
7782 // For SVG frames, we only need to account for filters.
7783 // TODO: We could also take account of clipPath and mask to reduce the
7784 // ink overflow, but that's not essential.
7785 if (aFrame->StyleEffects()->HasFilters()) {
7786 SetOrUpdateRectValuedProperty(aFrame, nsIFrame::PreEffectsBBoxProperty(),
7787 r);
7788 r = SVGUtils::GetPostFilterInkOverflowRect(aFrame, aOverflowRect);
7789 }
7790 return r;
7791 }
7792
7793 // box-shadow
7794 r.UnionRect(r, nsLayoutUtils::GetBoxShadowRectForFrame(aFrame, aNewSize));
7795
7796 // border-image-outset.
7797 // We need to include border-image-outset because it can cause the
7798 // border image to be drawn beyond the border box.
7799
7800 // (1) It's important we not check whether there's a border-image
7801 // since the style hint for a change in border image doesn't cause
7802 // reflow, and that's probably more important than optimizing the
7803 // overflow areas for the silly case of border-image-outset without
7804 // border-image
7805 // (2) It's important that we not check whether the border-image
7806 // is actually loaded, since that would require us to reflow when
7807 // the image loads.
7808 const nsStyleBorder* styleBorder = aFrame->StyleBorder();
7809 nsMargin outsetMargin = styleBorder->GetImageOutset();
7810
7811 if (outsetMargin != nsMargin(0, 0, 0, 0)) {
7812 nsRect outsetRect(nsPoint(0, 0), aNewSize);
7813 outsetRect.Inflate(outsetMargin);
7814 r.UnionRect(r, outsetRect);
7815 }
7816
7817 // Note that we don't remove the outlineInnerRect if a frame loses outline
7818 // style. That would require an extra property lookup for every frame,
7819 // or a new frame state bit to track whether a property had been stored,
7820 // or something like that. It's not worth doing that here. At most it's
7821 // only one heap-allocated rect per frame and it will be cleaned up when
7822 // the frame dies.
7823
7824 if (SVGIntegrationUtils::UsingOverflowAffectingEffects(aFrame)) {
7825 SetOrUpdateRectValuedProperty(aFrame, nsIFrame::PreEffectsBBoxProperty(),
7826 r);
7827 r = SVGIntegrationUtils::ComputePostEffectsInkOverflowRect(aFrame, r);
7828 }
7829
7830 return r;
7831}
7832
7833void nsIFrame::SetPosition(const nsPoint& aPt) {
7834 if (mRect.TopLeft() == aPt) {
7835 return;
7836 }
7837 mRect.MoveTo(aPt);
7838 MarkNeedsDisplayItemRebuild();
7839}
7840
7841void nsIFrame::MovePositionBy(const nsPoint& aTranslation) {
7842 nsPoint position = GetNormalPosition() + aTranslation;
7843
7844 const nsMargin* computedOffsets = nullptr;
7845 if (IsRelativelyOrStickyPositioned()) {
7846 computedOffsets = GetProperty(nsIFrame::ComputedOffsetProperty());
7847 }
7848 ReflowInput::ApplyRelativePositioning(
7849 this, computedOffsets ? *computedOffsets : nsMargin(), &position);
7850 SetPosition(position);
7851}
7852
7853nsRect nsIFrame::GetNormalRect() const {
7854 // It might be faster to first check
7855 // StyleDisplay()->IsRelativelyPositionedStyle().
7856 bool hasProperty;
7857 nsPoint normalPosition = GetProperty(NormalPositionProperty(), &hasProperty);
7858 if (hasProperty) {
7859 return nsRect(normalPosition, GetSize());
7860 }
7861 return GetRect();
7862}
7863
7864nsRect nsIFrame::GetBoundingClientRect() {
7865 return nsLayoutUtils::GetAllInFlowRectsUnion(
7866 this, nsLayoutUtils::GetContainingBlockForClientRect(this),
7867 nsLayoutUtils::GetAllInFlowRectsFlag::AccountForTransforms);
7868}
7869
7870nsPoint nsIFrame::GetPositionIgnoringScrolling() const {
7871 return GetParent() ? GetParent()->GetPositionOfChildIgnoringScrolling(this)
7872 : GetPosition();
7873}
7874
7875nsRect nsIFrame::GetOverflowRect(OverflowType aType) const {
7876 // Note that in some cases the overflow area might not have been
7877 // updated (yet) to reflect any outline set on the frame or the area
7878 // of child frames. That's OK because any reflow that updates these
7879 // areas will invalidate the appropriate area, so any (mis)uses of
7880 // this method will be fixed up.
7881
7882 if (mOverflow.mType == OverflowStorageType::Large) {
7883 // there is an overflow rect, and it's not stored as deltas but as
7884 // a separately-allocated rect
7885 return GetOverflowAreasProperty()->Overflow(aType);
7886 }
7887
7888 if (aType == OverflowType::Ink &&
7889 mOverflow.mType != OverflowStorageType::None) {
7890 return InkOverflowFromDeltas();
7891 }
7892
7893 return GetRectRelativeToSelf();
7894}
7895
7896OverflowAreas nsIFrame::GetOverflowAreas() const {
7897 if (mOverflow.mType == OverflowStorageType::Large) {
7898 // there is an overflow rect, and it's not stored as deltas but as
7899 // a separately-allocated rect
7900 return *GetOverflowAreasProperty();
7901 }
7902
7903 return OverflowAreas(InkOverflowFromDeltas(),
7904 nsRect(nsPoint(0, 0), GetSize()));
7905}
7906
7907OverflowAreas nsIFrame::GetOverflowAreasRelativeToSelf() const {
7908 if (IsTransformed()) {
7909 if (OverflowAreas* preTransformOverflows =
7910 GetProperty(PreTransformOverflowAreasProperty())) {
7911 return *preTransformOverflows;
7912 }
7913 }
7914 return GetOverflowAreas();
7915}
7916
7917OverflowAreas nsIFrame::GetOverflowAreasRelativeToParent() const {
7918 return GetOverflowAreas() + GetPosition();
7919}
7920
7921OverflowAreas nsIFrame::GetActualAndNormalOverflowAreasRelativeToParent()
7922 const {
7923 if (MOZ_LIKELY(!IsRelativelyOrStickyPositioned())(__builtin_expect(!!(!IsRelativelyOrStickyPositioned()), 1))) {
7924 return GetOverflowAreasRelativeToParent();
7925 }
7926
7927 const OverflowAreas overflows = GetOverflowAreas();
7928 OverflowAreas actualAndNormalOverflows = overflows + GetNormalPosition();
7929 if (IsRelativelyPositioned()) {
7930 actualAndNormalOverflows.UnionWith(overflows + GetPosition());
7931 } else {
7932 // For sticky positioned elements, we only use the normal position for the
7933 // scrollable overflow. This avoids circular dependencies between sticky
7934 // positioned elements and their scroll container. (The scroll position and
7935 // the scroll container's size impact the sticky position, so we don't want
7936 // the sticky position to impact them.)
7937 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"
, 7937); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsStickyPositioned()"
")"); do { *((volatile int*)__null) = 7937; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7938 actualAndNormalOverflows.UnionWith(
7939 OverflowAreas(overflows.InkOverflow() + GetPosition(), nsRect()));
7940 }
7941 return actualAndNormalOverflows;
7942}
7943
7944nsRect nsIFrame::ScrollableOverflowRectRelativeToParent() const {
7945 return ScrollableOverflowRect() + GetPosition();
7946}
7947
7948nsRect nsIFrame::InkOverflowRectRelativeToParent() const {
7949 return InkOverflowRect() + GetPosition();
7950}
7951
7952nsRect nsIFrame::ScrollableOverflowRectRelativeToSelf() const {
7953 if (IsTransformed()) {
7954 if (OverflowAreas* preTransformOverflows =
7955 GetProperty(PreTransformOverflowAreasProperty())) {
7956 return preTransformOverflows->ScrollableOverflow();
7957 }
7958 }
7959 return ScrollableOverflowRect();
7960}
7961
7962nsRect nsIFrame::InkOverflowRectRelativeToSelf() const {
7963 if (IsTransformed()) {
7964 if (OverflowAreas* preTransformOverflows =
7965 GetProperty(PreTransformOverflowAreasProperty())) {
7966 return preTransformOverflows->InkOverflow();
7967 }
7968 }
7969 return InkOverflowRect();
7970}
7971
7972nsRect nsIFrame::PreEffectsInkOverflowRect() const {
7973 nsRect* r = GetProperty(nsIFrame::PreEffectsBBoxProperty());
7974 return r ? *r : InkOverflowRectRelativeToSelf();
7975}
7976
7977bool nsIFrame::UpdateOverflow() {
7978 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"
, 7979); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Non-display SVG do not maintain ink overflow rects" ")"
); do { *((volatile int*)__null) = 7979; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
7979 "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"
, 7979); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Non-display SVG do not maintain ink overflow rects" ")"
); do { *((volatile int*)__null) = 7979; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7980
7981 nsRect rect(nsPoint(0, 0), GetSize());
7982 OverflowAreas overflowAreas(rect, rect);
7983
7984 if (!ComputeCustomOverflow(overflowAreas)) {
7985 // If updating overflow wasn't supported by this frame, then it should
7986 // have scheduled any necessary reflows. We can return false to say nothing
7987 // changed, and wait for reflow to correct it.
7988 return false;
7989 }
7990
7991 UnionChildOverflow(overflowAreas);
7992
7993 if (FinishAndStoreOverflow(overflowAreas, GetSize())) {
7994 if (nsView* view = GetView()) {
7995 // Make sure the frame's view is properly sized.
7996 nsViewManager* vm = view->GetViewManager();
7997 vm->ResizeView(view, overflowAreas.InkOverflow());
7998 }
7999
8000 return true;
8001 }
8002
8003 // Frames that combine their 3d transform with their ancestors
8004 // only compute a pre-transform overflow rect, and then contribute
8005 // to the normal overflow rect of the preserve-3d root. Always return
8006 // true here so that we propagate changes up to the root for final
8007 // calculation.
8008 return Combines3DTransformWithAncestors();
8009}
8010
8011/* virtual */
8012bool nsIFrame::ComputeCustomOverflow(OverflowAreas& aOverflowAreas) {
8013 return true;
8014}
8015
8016bool nsIFrame::DoesClipChildrenInBothAxes() const {
8017 if (IsScrollContainerOrSubclass()) {
8018 return true;
8019 }
8020 const nsStyleDisplay* display = StyleDisplay();
8021 if (display->IsContainPaint() && SupportsContainLayoutAndPaint()) {
8022 return true;
8023 }
8024 return display->mOverflowX == StyleOverflow::Clip &&
8025 display->mOverflowY == StyleOverflow::Clip;
8026}
8027
8028/* virtual */
8029void nsIFrame::UnionChildOverflow(OverflowAreas& aOverflowAreas) {
8030 if (!DoesClipChildrenInBothAxes()) {
8031 nsLayoutUtils::UnionChildOverflow(this, aOverflowAreas);
8032 }
8033}
8034
8035// Return true if this form control element's preferred size property (but not
8036// percentage max size property) contains a percentage value that should be
8037// resolved against zero when calculating its min-content contribution in the
8038// corresponding axis.
8039//
8040// For proper replaced elements, the percentage value in both their max size
8041// property or preferred size property should be resolved against zero. This is
8042// handled in IsPercentageResolvedAgainstZero().
8043inline static bool FormControlShrinksForPercentSize(const nsIFrame* aFrame) {
8044 if (!aFrame->IsReplaced()) {
8045 // Quick test to reject most frames.
8046 return false;
8047 }
8048
8049 switch (aFrame->Type()) {
8050 case LayoutFrameType::Meter:
8051 case LayoutFrameType::Progress:
8052 case LayoutFrameType::Range:
8053 case LayoutFrameType::TextInput:
8054 case LayoutFrameType::ColorControl:
8055 case LayoutFrameType::ComboboxControl:
8056 case LayoutFrameType::ListControl:
8057 case LayoutFrameType::CheckboxRadio:
8058 case LayoutFrameType::FileControl:
8059 case LayoutFrameType::ImageControl:
8060 return true;
8061 default:
8062 // Buttons (GfxButtonControl / HTMLButtonControl) don't have this
8063 // shrinking behavior. (Note that color inputs do, even though they
8064 // inherit from button, so we can't use do_QueryFrame here.)
8065 return false;
8066 }
8067}
8068
8069bool nsIFrame::IsPercentageResolvedAgainstZero(
8070 const StyleSize& aStyleSize, const StyleMaxSize& aStyleMaxSize) const {
8071 const bool sizeHasPercent = aStyleSize.HasPercent();
8072 return ((sizeHasPercent || aStyleMaxSize.HasPercent()) &&
8073 HasReplacedSizing()) ||
8074 (sizeHasPercent && FormControlShrinksForPercentSize(this));
8075}
8076
8077// Summary of the Cyclic-Percentage Intrinsic Size Contribution Rules:
8078//
8079// Element Type | Replaced | Non-replaced
8080// Contribution Type | min-content max-content | min-content max-content
8081// ---------------------------------------------------------------------------
8082// min size | zero zero | zero zero
8083// max & preferred size | zero initial | initial initial
8084//
8085// https://drafts.csswg.org/css-sizing-3/#cyclic-percentage-contribution
8086bool nsIFrame::IsPercentageResolvedAgainstZero(const LengthPercentage& aSize,
8087 SizeProperty aProperty) const {
8088 // Early return to avoid calling the virtual function, IsFrameOfType().
8089 if (aProperty == SizeProperty::MinSize) {
8090 return true;
8091 }
8092
8093 const bool hasPercentOnReplaced = aSize.HasPercent() && HasReplacedSizing();
8094 if (aProperty == SizeProperty::MaxSize) {
8095 return hasPercentOnReplaced;
8096 }
8097
8098 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"
, 8098); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aProperty == SizeProperty::Size"
")"); do { *((volatile int*)__null) = 8098; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8099 return hasPercentOnReplaced ||
8100 (aSize.HasPercent() && FormControlShrinksForPercentSize(this));
8101}
8102
8103bool nsIFrame::IsBlockWrapper() const {
8104 auto pseudoType = Style()->GetPseudoType();
8105 return pseudoType == PseudoStyleType::mozBlockInsideInlineWrapper ||
8106 pseudoType == PseudoStyleType::buttonContent ||
8107 pseudoType == PseudoStyleType::cellContent ||
8108 pseudoType == PseudoStyleType::columnSpanWrapper;
8109}
8110
8111bool nsIFrame::IsBlockFrameOrSubclass() const {
8112 const nsBlockFrame* thisAsBlock = do_QueryFrame(this);
8113 return !!thisAsBlock;
8114}
8115
8116bool nsIFrame::IsImageFrameOrSubclass() const {
8117 const nsImageFrame* asImage = do_QueryFrame(this);
8118 return !!asImage;
8119}
8120
8121bool nsIFrame::IsScrollContainerOrSubclass() const {
8122 const bool result = IsScrollContainerFrame() || IsListControlFrame();
8123 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"
, 8123); AnnotateMozCrashReason("MOZ_ASSERT" "(" "result == !!QueryFrame(ScrollContainerFrame::kFrameIID)"
")"); do { *((volatile int*)__null) = 8123; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8124 return result;
8125}
8126
8127bool nsIFrame::IsSubgrid() const {
8128 return IsGridContainerFrame() &&
8129 static_cast<const nsGridContainerFrame*>(this)->IsSubgrid();
8130}
8131
8132static nsIFrame* GetNearestBlockContainer(nsIFrame* frame) {
8133 while (!frame->IsBlockContainer()) {
8134 frame = frame->GetParent();
8135 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"
, 8137); MOZ_PretendNoReturn(); } } while (0)
8136 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"
, 8137); MOZ_PretendNoReturn(); } } while (0)
8137 "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"
, 8137); MOZ_PretendNoReturn(); } } while (0)
;
8138 }
8139 return frame;
8140}
8141
8142bool nsIFrame::IsBlockContainer() const {
8143 // The block wrappers we use to wrap blocks inside inlines aren't
8144 // described in the CSS spec. We need to make them not be containing
8145 // blocks.
8146 // Since the parent of such a block is either a normal block or
8147 // another such pseudo, this shouldn't cause anything bad to happen.
8148 // Also the anonymous blocks inside table cells are not containing blocks.
8149 //
8150 // If we ever start skipping table row groups from being containing blocks,
8151 // you need to remove the StickyScrollContainer hack referencing bug 1421660.
8152 return !IsLineParticipant() && !IsBlockWrapper() && !IsSubgrid() &&
8153 // Table rows are not containing blocks either
8154 !IsTableRowFrame();
8155}
8156
8157nsIFrame* nsIFrame::GetContainingBlock(
8158 uint32_t aFlags, const nsStyleDisplay* aStyleDisplay) const {
8159 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"
, 8159); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStyleDisplay == StyleDisplay()"
")"); do { *((volatile int*)__null) = 8159; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8160
8161 // Keep this in sync with MightBeContainingBlockFor in ReflowInput.cpp.
8162
8163 if (!GetParent()) {
8164 return nullptr;
8165 }
8166 // MathML frames might have absolute positioning style, but they would
8167 // still be in-flow. So we have to check to make sure that the frame
8168 // is really out-of-flow too.
8169 nsIFrame* f;
8170 if (IsAbsolutelyPositioned(aStyleDisplay)) {
8171 f = GetParent(); // the parent is always the containing block
8172 } else {
8173 f = GetNearestBlockContainer(GetParent());
8174 }
8175
8176 if (aFlags & SKIP_SCROLLED_FRAME && f &&
8177 f->Style()->GetPseudoType() == PseudoStyleType::scrolledContent) {
8178 f = f->GetParent();
8179 }
8180 return f;
8181}
8182
8183#ifdef DEBUG_FRAME_DUMP1
8184
8185Maybe<uint32_t> nsIFrame::ContentIndexInContainer(const nsIFrame* aFrame) {
8186 if (nsIContent* content = aFrame->GetContent()) {
8187 return content->ComputeIndexInParentContent();
8188 }
8189 return Nothing();
8190}
8191
8192nsAutoCString nsIFrame::ListTag() const {
8193 nsAutoString tmp;
8194 GetFrameName(tmp);
8195
8196 nsAutoCString tag;
8197 tag += NS_ConvertUTF16toUTF8(tmp);
8198 tag += nsPrintfCString("@%p", static_cast<const void*>(this));
8199 return tag;
8200}
8201
8202std::string nsIFrame::ConvertToString(const LogicalRect& aRect,
8203 const WritingMode aWM, ListFlags aFlags) {
8204 if (aFlags.contains(ListFlag::DisplayInCSSPixels)) {
8205 // Abuse CSSRect to store all LogicalRect's dimensions in CSS pixels.
8206 return ToString(mozilla::CSSRect(CSSPixel::FromAppUnits(aRect.IStart(aWM)),
8207 CSSPixel::FromAppUnits(aRect.BStart(aWM)),
8208 CSSPixel::FromAppUnits(aRect.ISize(aWM)),
8209 CSSPixel::FromAppUnits(aRect.BSize(aWM))));
8210 }
8211 return ToString(aRect);
8212}
8213
8214std::string nsIFrame::ConvertToString(const LogicalSize& aSize,
8215 const WritingMode aWM, ListFlags aFlags) {
8216 if (aFlags.contains(ListFlag::DisplayInCSSPixels)) {
8217 // Abuse CSSSize to store all LogicalSize's dimensions in CSS pixels.
8218 return ToString(CSSSize(CSSPixel::FromAppUnits(aSize.ISize(aWM)),
8219 CSSPixel::FromAppUnits(aSize.BSize(aWM))));
8220 }
8221 return ToString(aSize);
8222}
8223
8224// Debugging
8225void nsIFrame::ListGeneric(nsACString& aTo, const char* aPrefix,
8226 ListFlags aFlags) const {
8227 aTo += aPrefix;
8228 aTo += ListTag();
8229 if (HasView()) {
8230 aTo += nsPrintfCString(" [view=%p]", static_cast<void*>(GetView()));
8231 }
8232 if (GetParent()) {
8233 aTo += nsPrintfCString(" parent=%p", static_cast<void*>(GetParent()));
8234 }
8235 if (GetNextSibling()) {
8236 aTo += nsPrintfCString(" next=%p", static_cast<void*>(GetNextSibling()));
8237 }
8238 if (GetPrevContinuation()) {
8239 bool fluid = GetPrevInFlow() == GetPrevContinuation();
8240 aTo += nsPrintfCString(" prev-%s=%p", fluid ? "in-flow" : "continuation",
8241 static_cast<void*>(GetPrevContinuation()));
8242 }
8243 if (GetNextContinuation()) {
8244 bool fluid = GetNextInFlow() == GetNextContinuation();
8245 aTo += nsPrintfCString(" next-%s=%p", fluid ? "in-flow" : "continuation",
8246 static_cast<void*>(GetNextContinuation()));
8247 }
8248 if (const nsAtom* const autoPageValue =
8249 GetProperty(AutoPageValueProperty())) {
8250 aTo += " AutoPage=";
8251 aTo += nsAtomCString(autoPageValue);
8252 }
8253 if (const nsIFrame::PageValues* const pageValues =
8254 GetProperty(PageValuesProperty())) {
8255 aTo += " PageValues={";
8256 if (pageValues->mStartPageValue) {
8257 aTo += nsAtomCString(pageValues->mStartPageValue);
8258 } else {
8259 aTo += "<null>";
8260 }
8261 aTo += ", ";
8262 if (pageValues->mEndPageValue) {
8263 aTo += nsAtomCString(pageValues->mEndPageValue);
8264 } else {
8265 aTo += "<null>";
8266 }
8267 aTo += "}";
8268 }
8269 void* IBsibling = GetProperty(IBSplitSibling());
8270 if (IBsibling) {
8271 aTo += nsPrintfCString(" IBSplitSibling=%p", IBsibling);
8272 }
8273 void* IBprevsibling = GetProperty(IBSplitPrevSibling());
8274 if (IBprevsibling) {
8275 aTo += nsPrintfCString(" IBSplitPrevSibling=%p", IBprevsibling);
8276 }
8277 if (nsLayoutUtils::FontSizeInflationEnabled(PresContext())) {
8278 if (HasAnyStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT)) {
8279 aTo += nsPrintfCString(" FFR");
8280 if (nsFontInflationData* data =
8281 nsFontInflationData::FindFontInflationDataFor(this)) {
8282 aTo += nsPrintfCString(
8283 ",enabled=%s,UIS=%s", data->InflationEnabled() ? "yes" : "no",
8284 ConvertToString(data->UsableISize(), aFlags).c_str());
8285 }
8286 }
8287 if (HasAnyStateBits(NS_FRAME_FONT_INFLATION_CONTAINER)) {
8288 aTo += nsPrintfCString(" FIC");
8289 }
8290 aTo += nsPrintfCString(" FI=%f", nsLayoutUtils::FontSizeInflationFor(this));
8291 }
8292 aTo += nsPrintfCString(" %s", ConvertToString(mRect, aFlags).c_str());
8293
8294 mozilla::WritingMode wm = GetWritingMode();
8295 if (wm.IsVertical() || wm.IsBidiRTL()) {
8296 aTo +=
8297 nsPrintfCString(" wm=%s logical-size=(%s)", ToString(wm).c_str(),
8298 ConvertToString(GetLogicalSize(), wm, aFlags).c_str());
8299 }
8300
8301 nsIFrame* parent = GetParent();
8302 if (parent) {
8303 WritingMode pWM = parent->GetWritingMode();
8304 if (pWM.IsVertical() || pWM.IsBidiRTL()) {
8305 nsSize containerSize = parent->mRect.Size();
8306 LogicalRect lr(pWM, mRect, containerSize);
8307 aTo += nsPrintfCString(" parent-wm=%s cs=(%s) logical-rect=%s",
8308 ToString(pWM).c_str(),
8309 ConvertToString(containerSize, aFlags).c_str(),
8310 ConvertToString(lr, pWM, aFlags).c_str());
8311 }
8312 }
8313 nsIFrame* f = const_cast<nsIFrame*>(this);
8314 if (f->HasOverflowAreas()) {
8315 nsRect io = f->InkOverflowRect();
8316 if (!io.IsEqualEdges(mRect)) {
8317 aTo += nsPrintfCString(" ink-overflow=%s",
8318 ConvertToString(io, aFlags).c_str());
8319 }
8320 nsRect so = f->ScrollableOverflowRect();
8321 if (!so.IsEqualEdges(mRect)) {
8322 aTo += nsPrintfCString(" scr-overflow=%s",
8323 ConvertToString(so, aFlags).c_str());
8324 }
8325 }
8326 if (OverflowAreas* preTransformOverflows =
8327 f->GetProperty(PreTransformOverflowAreasProperty())) {
8328 nsRect io = preTransformOverflows->InkOverflow();
8329 if (!io.IsEqualEdges(mRect) &&
8330 (!f->HasOverflowAreas() || !io.IsEqualEdges(f->InkOverflowRect()))) {
8331 aTo += nsPrintfCString(" pre-transform-ink-overflow=%s",
8332 ConvertToString(io, aFlags).c_str());
8333 }
8334 nsRect so = preTransformOverflows->ScrollableOverflow();
8335 if (!so.IsEqualEdges(mRect) &&
8336 (!f->HasOverflowAreas() ||
8337 !so.IsEqualEdges(f->ScrollableOverflowRect()))) {
8338 aTo += nsPrintfCString(" pre-transform-scr-overflow=%s",
8339 ConvertToString(so, aFlags).c_str());
8340 }
8341 }
8342 bool hasNormalPosition;
8343 nsPoint normalPosition = GetNormalPosition(&hasNormalPosition);
8344 if (hasNormalPosition) {
8345 aTo += nsPrintfCString(" normal-position=%s",
8346 ConvertToString(normalPosition, aFlags).c_str());
8347 }
8348 if (HasProperty(BidiDataProperty())) {
8349 FrameBidiData bidi = GetBidiData();
8350 aTo += nsPrintfCString(" bidi(%d,%d,%d)", bidi.baseLevel.Value(),
8351 bidi.embeddingLevel.Value(),
8352 bidi.precedingControl.Value());
8353 }
8354 if (IsTransformed()) {
8355 aTo += nsPrintfCString(" transformed");
8356 }
8357 if (ChildrenHavePerspective()) {
8358 aTo += nsPrintfCString(" perspective");
8359 }
8360 if (Extend3DContext()) {
8361 aTo += nsPrintfCString(" extend-3d");
8362 }
8363 if (Combines3DTransformWithAncestors()) {
8364 aTo += nsPrintfCString(" combines-3d-transform-with-ancestors");
8365 }
8366 if (mContent) {
8367 aTo += nsPrintfCString(" [content=%p]", static_cast<void*>(mContent));
8368 }
8369 aTo += nsPrintfCString(" [cs=%p", static_cast<void*>(mComputedStyle));
8370 if (mComputedStyle) {
8371 auto pseudoType = mComputedStyle->GetPseudoType();
8372 aTo += ToString(pseudoType).c_str();
8373 }
8374 aTo += "]";
8375
8376 auto contentVisibility = StyleDisplay()->ContentVisibility(*this);
8377 if (contentVisibility != StyleContentVisibility::Visible) {
8378 aTo += nsPrintfCString(" [content-visibility=");
8379 if (contentVisibility == StyleContentVisibility::Auto) {
8380 aTo += "auto, "_ns;
8381 } else if (contentVisibility == StyleContentVisibility::Hidden) {
8382 aTo += "hiden, "_ns;
8383 }
8384
8385 if (HidesContent()) {
8386 aTo += "HidesContent=hidden"_ns;
8387 } else {
8388 aTo += "HidesContent=visibile"_ns;
8389 }
8390 aTo += "]";
8391 }
8392
8393 if (IsFrameModified()) {
8394 aTo += nsPrintfCString(" modified");
8395 }
8396
8397 if (HasModifiedDescendants()) {
8398 aTo += nsPrintfCString(" has-modified-descendants");
8399 }
8400}
8401
8402void nsIFrame::List(FILE* out, const char* aPrefix, ListFlags aFlags) const {
8403 nsCString str;
8404 ListGeneric(str, aPrefix, aFlags);
8405 fprintf_stderr(out, "%s\n", str.get());
8406}
8407
8408void nsIFrame::ListTextRuns(FILE* out) const {
8409 nsTHashSet<const void*> seen;
8410 ListTextRuns(out, seen);
8411}
8412
8413void nsIFrame::ListTextRuns(FILE* out, nsTHashSet<const void*>& aSeen) const {
8414 for (const auto& childList : ChildLists()) {
8415 for (const nsIFrame* kid : childList.mList) {
8416 kid->ListTextRuns(out, aSeen);
8417 }
8418 }
8419}
8420
8421void nsIFrame::ListMatchedRules(FILE* out, const char* aPrefix) const {
8422 nsTArray<const StyleLockedStyleRule*> rawRuleList;
8423 Servo_ComputedValues_GetStyleRuleList(mComputedStyle, &rawRuleList);
8424 for (const StyleLockedStyleRule* rawRule : rawRuleList) {
8425 nsAutoCString ruleText;
8426 Servo_StyleRule_GetCssText(rawRule, &ruleText);
8427 fprintf_stderr(out, "%s%s\n", aPrefix, ruleText.get());
8428 }
8429}
8430
8431void nsIFrame::ListWithMatchedRules(FILE* out, const char* aPrefix) const {
8432 fprintf_stderr(out, "%s%s\n", aPrefix, ListTag().get());
8433
8434 nsCString rulePrefix;
8435 rulePrefix += aPrefix;
8436 rulePrefix += " ";
8437 ListMatchedRules(out, rulePrefix.get());
8438}
8439
8440nsresult nsIFrame::GetFrameName(nsAString& aResult) const {
8441 return MakeFrameName(u"Frame"_ns, aResult);
8442}
8443
8444nsresult nsIFrame::MakeFrameName(const nsAString& aType,
8445 nsAString& aResult) const {
8446 aResult = aType;
8447 if (mContent && !mContent->IsText()) {
8448 nsAutoString buf;
8449 mContent->NodeInfo()->NameAtom()->ToString(buf);
8450 if (nsAtom* id = mContent->GetID()) {
8451 buf.AppendLiteral(" id=");
8452 buf.Append(nsDependentAtomString(id));
8453 }
8454 if (IsSubDocumentFrame()) {
8455 nsAutoString src;
8456 mContent->AsElement()->GetAttr(nsGkAtoms::src, src);
8457 buf.AppendLiteral(" src=");
8458 buf.Append(src);
8459 }
8460 aResult.Append('(');
8461 aResult.Append(buf);
8462 aResult.Append(')');
8463 }
8464 aResult.Append('(');
8465 Maybe<uint32_t> index = ContentIndexInContainer(this);
8466 if (index.isSome()) {
8467 aResult.AppendInt(*index);
8468 } else {
8469 aResult.AppendInt(-1);
8470 }
8471 aResult.Append(')');
8472 return NS_OK;
8473}
8474
8475void nsIFrame::DumpFrameTree() const {
8476 PresShell()->GetRootFrame()->List(stderrstderr);
8477}
8478
8479void nsIFrame::DumpFrameTreeInCSSPixels() const {
8480 PresShell()->GetRootFrame()->List(stderrstderr, "", ListFlag::DisplayInCSSPixels);
8481}
8482
8483void nsIFrame::DumpFrameTreeLimited() const { List(stderrstderr); }
8484void nsIFrame::DumpFrameTreeLimitedInCSSPixels() const {
8485 List(stderrstderr, "", ListFlag::DisplayInCSSPixels);
8486}
8487
8488#endif
8489
8490bool nsIFrame::IsVisibleForPainting() const {
8491 return StyleVisibility()->IsVisible();
8492}
8493
8494bool nsIFrame::IsVisibleOrCollapsedForPainting() const {
8495 return StyleVisibility()->IsVisibleOrCollapsed();
8496}
8497
8498/* virtual */
8499bool nsIFrame::IsEmpty() {
8500 return IsHiddenByContentVisibilityOfInFlowParentForLayout();
8501}
8502
8503bool nsIFrame::CachedIsEmpty() {
8504 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"
, 8507); 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) = 8507
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
8505 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"
, 8507); 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) = 8507
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
8506 "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"
, 8507); 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) = 8507
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
8507 "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"
, 8507); 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) = 8507
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
8508 return IsEmpty();
8509}
8510
8511/* virtual */
8512bool nsIFrame::IsSelfEmpty() {
8513 return IsHiddenByContentVisibilityOfInFlowParentForLayout();
8514}
8515
8516nsresult nsIFrame::GetSelectionController(nsPresContext* aPresContext,
8517 nsISelectionController** aSelCon) {
8518 if (!aPresContext || !aSelCon) return NS_ERROR_INVALID_ARG;
8519
8520 nsIFrame* frame = this;
8521 while (frame && frame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)) {
8522 if (nsTextControlFrame* tcf = do_QueryFrame(frame)) {
8523 return tcf->GetOwnedSelectionController(aSelCon);
8524 }
8525 frame = frame->GetParent();
8526 }
8527
8528 *aSelCon = do_AddRef(aPresContext->PresShell()).take();
8529 return NS_OK;
8530}
8531
8532already_AddRefed<nsFrameSelection> nsIFrame::GetFrameSelection() {
8533 RefPtr<nsFrameSelection> fs =
8534 const_cast<nsFrameSelection*>(GetConstFrameSelection());
8535 return fs.forget();
8536}
8537
8538const nsFrameSelection* nsIFrame::GetConstFrameSelection() const {
8539 nsIFrame* frame = const_cast<nsIFrame*>(this);
8540 while (frame && frame->HasAnyStateBits(NS_FRAME_INDEPENDENT_SELECTION)) {
8541 if (nsTextControlFrame* tcf = do_QueryFrame(frame)) {
8542 return tcf->GetOwnedFrameSelection();
8543 }
8544 frame = frame->GetParent();
8545 }
8546
8547 return PresShell()->ConstFrameSelection();
8548}
8549
8550bool nsIFrame::IsFrameSelected() const {
8551 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"
, 8552); MOZ_PretendNoReturn(); } } while (0)
8552 "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"
, 8552); MOZ_PretendNoReturn(); } } while (0)
;
8553 if (StaticPrefs::dom_shadowdom_selection_across_boundary_enabled()) {
8554 if (const ShadowRoot* shadowRoot =
8555 GetContent()->GetShadowRootForSelection()) {
8556 return shadowRoot->IsSelected(0, shadowRoot->GetChildCount());
8557 }
8558 }
8559 return GetContent()->IsSelected(0, GetContent()->GetChildCount());
8560}
8561
8562nsresult nsIFrame::GetPointFromOffset(int32_t inOffset, nsPoint* outPoint) {
8563 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"
, 8563); AnnotateMozCrashReason("MOZ_ASSERT" "(" "outPoint != nullptr"
") (" "Null parameter" ")"); do { *((volatile int*)__null) =
8563; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false)
;
8564 nsRect contentRect = GetContentRectRelativeToSelf();
8565 nsPoint pt = contentRect.TopLeft();
8566 if (mContent) {
8567 nsIContent* newContent = mContent->GetParent();
8568 if (newContent) {
8569 const int32_t newOffset = newContent->ComputeIndexOf_Deprecated(mContent);
8570
8571 // Find the direction of the frame from the EmbeddingLevelProperty,
8572 // which is the resolved bidi level set in
8573 // nsBidiPresUtils::ResolveParagraph (odd levels = right-to-left).
8574 // If the embedding level isn't set, just use the CSS direction
8575 // property.
8576 bool hasBidiData;
8577 FrameBidiData bidiData = GetProperty(BidiDataProperty(), &hasBidiData);
8578 bool isRTL = hasBidiData
8579 ? bidiData.embeddingLevel.IsRTL()
8580 : StyleVisibility()->mDirection == StyleDirection::Rtl;
8581 if ((!isRTL && inOffset > newOffset) ||
8582 (isRTL && inOffset <= newOffset)) {
8583 pt = contentRect.TopRight();
8584 }
8585 }
8586 }
8587 *outPoint = pt;
8588 return NS_OK;
8589}
8590
8591nsresult nsIFrame::GetCharacterRectsInRange(int32_t aInOffset, int32_t aLength,
8592 nsTArray<nsRect>& aOutRect) {
8593 /* no text */
8594 return NS_ERROR_FAILURE;
8595}
8596
8597nsresult nsIFrame::GetChildFrameContainingOffset(int32_t inContentOffset,
8598 bool inHint,
8599 int32_t* outFrameContentOffset,
8600 nsIFrame** outChildFrame) {
8601 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"
, 8601); AnnotateMozCrashReason("MOZ_ASSERT" "(" "outChildFrame && outFrameContentOffset"
") (" "Null parameter" ")"); do { *((volatile int*)__null) =
8601; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false)
;
8602 *outFrameContentOffset = (int32_t)inHint;
8603 // the best frame to reflect any given offset would be a visible frame if
8604 // possible i.e. we are looking for a valid frame to place the blinking caret
8605 nsRect rect = GetRect();
8606 if (!rect.width || !rect.height) {
8607 // if we have a 0 width or height then lets look for another frame that
8608 // possibly has the same content. If we have no frames in flow then just
8609 // let us return 'this' frame
8610 nsIFrame* nextFlow = GetNextInFlow();
8611 if (nextFlow)
8612 return nextFlow->GetChildFrameContainingOffset(
8613 inContentOffset, inHint, outFrameContentOffset, outChildFrame);
8614 }
8615 *outChildFrame = this;
8616 return NS_OK;
8617}
8618
8619//
8620// What I've pieced together about this routine:
8621// Starting with a block frame (from which a line frame can be gotten)
8622// and a line number, drill down and get the first/last selectable
8623// frame on that line, depending on aPos->mDirection.
8624// aOutSideLimit != 0 means ignore aLineStart, instead work from
8625// the end (if > 0) or beginning (if < 0).
8626//
8627static nsresult GetNextPrevLineFromBlockFrame(PeekOffsetStruct* aPos,
8628 nsIFrame* aBlockFrame,
8629 int32_t aLineStart,
8630 int8_t aOutSideLimit) {
8631 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"
, 8631); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPos" ")");
do { *((volatile int*)__null) = 8631; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8632 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"
, 8632); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aBlockFrame"
")"); do { *((volatile int*)__null) = 8632; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8633
8634 nsPresContext* pc = aBlockFrame->PresContext();
8635
8636 // magic numbers: aLineStart will be -1 for end of block, 0 will be start of
8637 // block.
8638
8639 aPos->mResultFrame = nullptr;
8640 aPos->mResultContent = nullptr;
8641 aPos->mAttach = aPos->mDirection == eDirNext ? CaretAssociationHint::After
8642 : CaretAssociationHint::Before;
8643
8644 AutoAssertNoDomMutations guard;
8645 nsILineIterator* it = aBlockFrame->GetLineIterator();
8646 if (!it) {
8647 return NS_ERROR_FAILURE;
8648 }
8649 int32_t searchingLine = aLineStart;
8650 int32_t countLines = it->GetNumLines();
8651 if (aOutSideLimit > 0) { // start at end
8652 searchingLine = countLines;
8653 } else if (aOutSideLimit < 0) { // start at beginning
8654 searchingLine = -1; //"next" will be 0
8655 } else if ((aPos->mDirection == eDirPrevious && searchingLine == 0) ||
8656 (aPos->mDirection == eDirNext &&
8657 searchingLine >= (countLines - 1))) {
8658 // Not found.
8659 return NS_ERROR_FAILURE;
8660 }
8661 nsIFrame* resultFrame = nullptr;
8662 nsIFrame* farStoppingFrame = nullptr; // we keep searching until we find a
8663 // "this" frame then we go to next line
8664 nsIFrame* nearStoppingFrame = nullptr; // if we are backing up from edge,
8665 // stop here
8666 bool isBeforeFirstFrame, isAfterLastFrame;
8667 bool found = false;
8668
8669 const bool forceInEditableRegion =
8670 aPos->mOptions.contains(PeekOffsetOption::ForceEditableRegion);
8671 while (!found) {
8672 if (aPos->mDirection == eDirPrevious) {
8673 searchingLine--;
8674 } else {
8675 searchingLine++;
8676 }
8677 if ((aPos->mDirection == eDirPrevious && searchingLine < 0) ||
8678 (aPos->mDirection == eDirNext && searchingLine >= countLines)) {
8679 // we need to jump to new block frame.
8680 return NS_ERROR_FAILURE;
8681 }
8682 {
8683 auto line = it->GetLine(searchingLine).unwrap();
8684 if (!line.mNumFramesOnLine) {
8685 continue;
8686 }
8687 nsIFrame* firstFrame = nullptr;
8688 nsIFrame* lastFrame = nullptr;
8689 nsIFrame* frame = line.mFirstFrameOnLine;
8690 int32_t i = line.mNumFramesOnLine;
8691 do {
8692 // If the caller wants a frame for a inclusive ancestor of the ancestor
8693 // limiter, ignore frames for outside the limiter.
8694 if (aPos->FrameContentIsInAncestorLimiter(frame)) {
8695 if (!firstFrame) {
8696 firstFrame = frame;
8697 }
8698 lastFrame = frame;
8699 }
8700 if (i == 1) {
8701 break;
8702 }
8703 frame = frame->GetNextSibling();
8704 if (!frame) {
8705 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"
, 8705); MOZ_PretendNoReturn(); } while (0)
;
8706 return NS_ERROR_FAILURE;
8707 }
8708 } while (--i);
8709 if (!lastFrame) {
8710 // If we're looking for an editable content frame, but all frames in the
8711 // line are not in the specified editing host, return error because we
8712 // must reach the editing host boundary.
8713 return NS_ERROR_FAILURE;
8714 }
8715 nsIFrame::GetLastLeaf(&lastFrame);
8716
8717 if (aPos->mDirection == eDirNext) {
8718 nearStoppingFrame = firstFrame;
8719 farStoppingFrame = lastFrame;
8720 } else {
8721 nearStoppingFrame = lastFrame;
8722 farStoppingFrame = firstFrame;
8723 }
8724 }
8725 nsPoint offset;
8726 nsView* view; // used for call of get offset from view
8727 aBlockFrame->GetOffsetFromView(offset, &view);
8728 nsPoint newDesiredPos =
8729 aPos->mDesiredCaretPos -
8730 offset; // get desired position into blockframe coords
8731 // TODO: nsILineIterator::FindFrameAt should take optional editing host
8732 // parameter and if it's set, it should return the nearest editable frame
8733 // for the editing host when the frame at the desired position is not
8734 // editable.
8735 nsresult rv = it->FindFrameAt(searchingLine, newDesiredPos, &resultFrame,
8736 &isBeforeFirstFrame, &isAfterLastFrame);
8737 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
8738 continue;
8739 }
8740
8741 if (resultFrame) {
8742 // If ancestor limiter is specified and we reached outside content of it,
8743 // return error because we reached its element boundary.
8744 if (!aPos->FrameContentIsInAncestorLimiter(resultFrame)) {
8745 return NS_ERROR_FAILURE;
8746 }
8747 // check to see if this is ANOTHER blockframe inside the other one if so
8748 // then call into its lines
8749 if (resultFrame->CanProvideLineIterator()) {
8750 aPos->mResultFrame = resultFrame;
8751 return NS_OK;
8752 }
8753 // resultFrame is not a block frame
8754 Maybe<nsFrameIterator> frameIterator;
8755 frameIterator.emplace(
8756 pc, resultFrame, nsFrameIterator::Type::PostOrder,
8757 false, // aVisual
8758 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller),
8759 false, // aFollowOOFs
8760 false // aSkipPopupChecks
8761 );
8762
8763 auto FoundValidFrame = [forceInEditableRegion, aPos](
8764 const nsIFrame::ContentOffsets& aOffsets,
8765 const nsIFrame* aFrame) {
8766 if (!aOffsets.content) {
8767 return false;
8768 }
8769 if (!aFrame->IsSelectable(nullptr)) {
8770 return false;
8771 }
8772 if (aPos->mAncestorLimiter &&
8773 !aOffsets.content->IsInclusiveDescendantOf(
8774 aPos->mAncestorLimiter)) {
8775 return false;
8776 }
8777 if (forceInEditableRegion && !aOffsets.content->IsEditable()) {
8778 return false;
8779 }
8780 return true;
8781 };
8782
8783 nsIFrame* storeOldResultFrame = resultFrame;
8784 while (!found) {
8785 nsPoint point;
8786 nsRect tempRect = resultFrame->GetRect();
8787 nsPoint offset;
8788 nsView* view; // used for call of get offset from view
8789 resultFrame->GetOffsetFromView(offset, &view);
8790 if (!view) {
8791 return NS_ERROR_FAILURE;
8792 }
8793 if (resultFrame->GetWritingMode().IsVertical()) {
8794 point.y = aPos->mDesiredCaretPos.y;
8795 point.x = tempRect.width + offset.x;
8796 } else {
8797 point.y = tempRect.height + offset.y;
8798 point.x = aPos->mDesiredCaretPos.x;
8799 }
8800
8801 if (!resultFrame->HasView()) {
8802 nsView* view;
8803 nsPoint offset;
8804 resultFrame->GetOffsetFromView(offset, &view);
8805 nsIFrame::ContentOffsets offsets =
8806 resultFrame->GetContentOffsetsFromPoint(
8807 point - offset, nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE);
8808 aPos->mResultContent = offsets.content;
8809 aPos->mContentOffset = offsets.offset;
8810 aPos->mAttach = offsets.associate;
8811 if (FoundValidFrame(offsets, resultFrame)) {
8812 found = true;
8813 break;
8814 }
8815 }
8816
8817 if (aPos->mDirection == eDirPrevious &&
8818 resultFrame == farStoppingFrame) {
8819 break;
8820 }
8821 if (aPos->mDirection == eDirNext && resultFrame == nearStoppingFrame) {
8822 break;
8823 }
8824 // always try previous on THAT line if that fails go the other way
8825 resultFrame = frameIterator->Traverse(/* aForward = */ false);
8826 if (!resultFrame) {
8827 return NS_ERROR_FAILURE;
8828 }
8829 }
8830
8831 if (!found) {
8832 resultFrame = storeOldResultFrame;
8833 frameIterator.reset();
8834 frameIterator.emplace(
8835 pc, resultFrame, nsFrameIterator::Type::Leaf,
8836 false, // aVisual
8837 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller),
8838 false, // aFollowOOFs
8839 false // aSkipPopupChecks
8840 );
8841 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"
, 8841); AnnotateMozCrashReason("MOZ_ASSERT" "(" "frameIterator"
")"); do { *((volatile int*)__null) = 8841; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8842 }
8843 while (!found) {
8844 nsPoint point = aPos->mDesiredCaretPos;
8845 nsView* view;
8846 nsPoint offset;
8847 resultFrame->GetOffsetFromView(offset, &view);
8848 nsIFrame::ContentOffsets offsets =
8849 resultFrame->GetContentOffsetsFromPoint(
8850 point - offset, nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE);
8851 aPos->mResultContent = offsets.content;
8852 aPos->mContentOffset = offsets.offset;
8853 aPos->mAttach = offsets.associate;
8854 if (FoundValidFrame(offsets, resultFrame)) {
8855 found = true;
8856 aPos->mAttach = resultFrame == farStoppingFrame
8857 ? CaretAssociationHint::Before
8858 : CaretAssociationHint::After;
8859 break;
8860 }
8861 if (aPos->mDirection == eDirPrevious &&
8862 resultFrame == nearStoppingFrame) {
8863 break;
8864 }
8865 if (aPos->mDirection == eDirNext && resultFrame == farStoppingFrame) {
8866 break;
8867 }
8868 // previous didnt work now we try "next"
8869 nsIFrame* tempFrame = frameIterator->Traverse(/* aForward = */ true);
8870 if (!tempFrame) {
8871 break;
8872 }
8873 resultFrame = tempFrame;
8874 }
8875 aPos->mResultFrame = resultFrame;
8876 } else {
8877 // we need to jump to new block frame.
8878 aPos->mAmount = eSelectLine;
8879 aPos->mStartOffset = 0;
8880 aPos->mAttach = aPos->mDirection == eDirNext
8881 ? CaretAssociationHint::Before
8882 : CaretAssociationHint::After;
8883 if (aPos->mDirection == eDirPrevious) {
8884 aPos->mStartOffset = -1; // start from end
8885 }
8886 return aBlockFrame->PeekOffset(aPos);
8887 }
8888 }
8889 return NS_OK;
8890}
8891
8892nsIFrame::CaretPosition nsIFrame::GetExtremeCaretPosition(bool aStart) {
8893 CaretPosition result;
8894
8895 FrameTarget targetFrame = DrillDownToSelectionFrame(this, !aStart, 0);
8896 FrameContentRange range = GetRangeForFrame(targetFrame.frame);
8897 result.mResultContent = range.content;
8898 result.mContentOffset = aStart ? range.start : range.end;
8899 return result;
8900}
8901
8902// If this is a preformatted text frame, see if it ends with a newline
8903static nsContentAndOffset FindLineBreakInText(nsIFrame* aFrame,
8904 nsDirection aDirection) {
8905 nsContentAndOffset result;
8906
8907 if (aFrame->IsGeneratedContentFrame() ||
8908 !aFrame->HasSignificantTerminalNewline()) {
8909 return result;
8910 }
8911
8912 int32_t endOffset = aFrame->GetOffsets().second;
8913 result.mContent = aFrame->GetContent();
8914 result.mOffset = endOffset - (aDirection == eDirPrevious ? 0 : 1);
8915 return result;
8916}
8917
8918// Find the first (or last) descendant of the given frame
8919// which is either a block-level frame or a BRFrame, or some other kind of break
8920// which stops the line.
8921static nsContentAndOffset FindLineBreakingFrame(nsIFrame* aFrame,
8922 nsDirection aDirection) {
8923 nsContentAndOffset result;
8924
8925 if (aFrame->IsGeneratedContentFrame()) {
8926 return result;
8927 }
8928
8929 // Treat form controls and other replaced inline level elements as inline
8930 // leaves.
8931 if (aFrame->IsReplaced() && aFrame->IsInlineOutside() &&
8932 !aFrame->IsBrFrame() && !aFrame->IsTextFrame()) {
8933 return result;
8934 }
8935
8936 // Check the frame itself
8937 // Fall through block-in-inline split frames because their mContent is
8938 // the content of the inline frames they were created from. The
8939 // first/last child of such frames is the real block frame we're
8940 // looking for.
8941 if ((aFrame->IsBlockOutside() &&
8942 !aFrame->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) ||
8943 aFrame->IsBrFrame()) {
8944 nsIContent* content = aFrame->GetContent();
8945 result.mContent = content->GetParent();
8946 // In some cases (bug 310589, bug 370174) we end up here with a null
8947 // content. This probably shouldn't ever happen, but since it sometimes
8948 // does, we want to avoid crashing here.
8949 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"
, 8949); MOZ_PretendNoReturn(); } } while (0)
;
8950 if (result.mContent) {
8951 result.mOffset = result.mContent->ComputeIndexOf_Deprecated(content) +
8952 (aDirection == eDirPrevious ? 1 : 0);
8953 }
8954 return result;
8955 }
8956
8957 result = FindLineBreakInText(aFrame, aDirection);
8958 if (result.mContent) {
8959 return result;
8960 }
8961
8962 // Iterate over children and call ourselves recursively
8963 if (aDirection == eDirPrevious) {
8964 nsIFrame* child = aFrame->PrincipalChildList().LastChild();
8965 while (child && !result.mContent) {
8966 result = FindLineBreakingFrame(child, aDirection);
8967 child = child->GetPrevSibling();
8968 }
8969 } else { // eDirNext
8970 nsIFrame* child = aFrame->PrincipalChildList().FirstChild();
8971 while (child && !result.mContent) {
8972 result = FindLineBreakingFrame(child, aDirection);
8973 child = child->GetNextSibling();
8974 }
8975 }
8976 return result;
8977}
8978
8979nsresult nsIFrame::PeekOffsetForParagraph(PeekOffsetStruct* aPos) {
8980 nsIFrame* frame = this;
8981 nsContentAndOffset blockFrameOrBR;
8982 blockFrameOrBR.mContent = nullptr;
8983 bool reachedLimit = frame->IsBlockOutside() || IsEditingHost(frame);
8984
8985 auto traverse = [&aPos](nsIFrame* current) {
8986 return aPos->mDirection == eDirPrevious ? current->GetPrevSibling()
8987 : current->GetNextSibling();
8988 };
8989
8990 // Go through containing frames until reaching a block frame.
8991 // In each step, search the previous (or next) siblings for the closest
8992 // "stop frame" (a block frame or a BRFrame).
8993 // If found, set it to be the selection boundary and abort.
8994 while (!reachedLimit) {
8995 nsIFrame* parent = frame->GetParent();
8996 // Treat a frame associated with the root content as if it were a block
8997 // frame.
8998 if (!frame->mContent || !frame->mContent->GetParent()) {
8999 reachedLimit = true;
9000 break;
9001 }
9002
9003 if (aPos->mDirection == eDirNext) {
9004 // Try to find our own line-break before looking at our siblings.
9005 blockFrameOrBR = FindLineBreakInText(frame, eDirNext);
9006 }
9007
9008 nsIFrame* sibling = traverse(frame);
9009 while (sibling && !blockFrameOrBR.mContent) {
9010 blockFrameOrBR = FindLineBreakingFrame(sibling, aPos->mDirection);
9011 sibling = traverse(sibling);
9012 }
9013 if (blockFrameOrBR.mContent) {
9014 aPos->mResultContent = blockFrameOrBR.mContent;
9015 aPos->mContentOffset = blockFrameOrBR.mOffset;
9016 break;
9017 }
9018 frame = parent;
9019 reachedLimit = frame && (frame->IsBlockOutside() || IsEditingHost(frame));
9020 }
9021
9022 if (reachedLimit) { // no "stop frame" found
9023 aPos->mResultContent = frame->GetContent();
9024 if (ShadowRoot* shadowRoot =
9025 aPos->mResultContent->GetShadowRootForSelection()) {
9026 // Even if there's no children for this node,
9027 // the elements inside the shadow root is still
9028 // selectable
9029 aPos->mResultContent = shadowRoot;
9030 }
9031 if (aPos->mDirection == eDirPrevious) {
9032 aPos->mContentOffset = 0;
9033 } else if (aPos->mResultContent) {
9034 aPos->mContentOffset = aPos->mResultContent->GetChildCount();
9035 }
9036 }
9037 return NS_OK;
9038}
9039
9040// Determine movement direction relative to frame
9041static bool IsMovingInFrameDirection(const nsIFrame* frame,
9042 nsDirection aDirection, bool aVisual) {
9043 bool isReverseDirection =
9044 aVisual && nsBidiPresUtils::IsReversedDirectionFrame(frame);
9045 return aDirection == (isReverseDirection ? eDirPrevious : eDirNext);
9046}
9047
9048// Determines "are we looking for a boundary between whitespace and
9049// non-whitespace (in the direction we're moving in)". It is true when moving
9050// forward and looking for a beginning of a word, or when moving backwards and
9051// looking for an end of a word.
9052static bool ShouldWordSelectionEatSpace(const PeekOffsetStruct& aPos) {
9053 if (aPos.mWordMovementType != eDefaultBehavior) {
9054 // aPos->mWordMovementType possible values:
9055 // eEndWord: eat the space if we're moving backwards
9056 // eStartWord: eat the space if we're moving forwards
9057 return (aPos.mWordMovementType == eEndWord) ==
9058 (aPos.mDirection == eDirPrevious);
9059 }
9060 // Use the hidden preference which is based on operating system
9061 // behavior. This pref only affects whether moving forward by word
9062 // should go to the end of this word or start of the next word. When
9063 // going backwards, the start of the word is always used, on every
9064 // operating system.
9065 return aPos.mDirection == eDirNext &&
9066 StaticPrefs::layout_word_select_eat_space_to_next_word();
9067}
9068
9069enum class OffsetIsAtLineEdge : bool { No, Yes };
9070
9071static void SetPeekResultFromFrame(PeekOffsetStruct& aPos, nsIFrame* aFrame,
9072 int32_t aOffset,
9073 OffsetIsAtLineEdge aAtLineEdge) {
9074 FrameContentRange range = GetRangeForFrame(aFrame);
9075 aPos.mResultFrame = aFrame;
9076 aPos.mResultContent = range.content;
9077 // Output offset is relative to content, not frame
9078 aPos.mContentOffset =
9079 aOffset < 0 ? range.end + aOffset + 1 : range.start + aOffset;
9080 if (aAtLineEdge == OffsetIsAtLineEdge::Yes) {
9081 aPos.mAttach = aPos.mContentOffset == range.start
9082 ? CaretAssociationHint::After
9083 : CaretAssociationHint::Before;
9084 }
9085}
9086
9087void nsIFrame::SelectablePeekReport::TransferTo(PeekOffsetStruct& aPos) const {
9088 return SetPeekResultFromFrame(aPos, mFrame, mOffset, OffsetIsAtLineEdge::No);
9089}
9090
9091nsIFrame::SelectablePeekReport::SelectablePeekReport(
9092 const mozilla::GenericErrorResult<nsresult>&& aErr) {
9093 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"
, 9093); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(NS_FAILED_impl(aErr.operator nsresult())), 0)))"
")"); do { *((volatile int*)__null) = 9093; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9094 // Return an empty report
9095}
9096
9097nsresult nsIFrame::PeekOffsetForCharacter(PeekOffsetStruct* aPos,
9098 int32_t aOffset) {
9099 SelectablePeekReport current{this, aOffset};
9100
9101 nsIFrame::FrameSearchResult peekSearchState = CONTINUE;
9102
9103 while (peekSearchState != FOUND) {
9104 const bool movingInFrameDirection = IsMovingInFrameDirection(
9105 current.mFrame, aPos->mDirection,
9106 aPos->mOptions.contains(PeekOffsetOption::Visual));
9107
9108 if (current.mJumpedLine) {
9109 // If we jumped lines, it's as if we found a character, but we still need
9110 // to eat non-renderable content on the new line.
9111 peekSearchState = current.PeekOffsetNoAmount(movingInFrameDirection);
9112 } else {
9113 PeekOffsetCharacterOptions options;
9114 options.mRespectClusters = aPos->mAmount == eSelectCluster;
9115 peekSearchState =
9116 current.PeekOffsetCharacter(movingInFrameDirection, options);
9117 }
9118
9119 current.mMovedOverNonSelectableText |=
9120 peekSearchState == CONTINUE_UNSELECTABLE;
9121
9122 if (peekSearchState != FOUND) {
9123 SelectablePeekReport next = current.mFrame->GetFrameFromDirection(*aPos);
9124 if (next.Failed()) {
9125 return NS_ERROR_FAILURE;
9126 }
9127 next.mJumpedLine |= current.mJumpedLine;
9128 next.mMovedOverNonSelectableText |= current.mMovedOverNonSelectableText;
9129 next.mHasSelectableFrame |= current.mHasSelectableFrame;
9130 current = next;
9131 }
9132
9133 // Found frame, but because we moved over non selectable text we want
9134 // the offset to be at the frame edge. Note that if we are extending the
9135 // selection, this doesn't matter.
9136 if (peekSearchState == FOUND && current.mMovedOverNonSelectableText &&
9137 (!aPos->mOptions.contains(PeekOffsetOption::Extend) ||
9138 current.mHasSelectableFrame)) {
9139 auto [start, end] = current.mFrame->GetOffsets();
9140 current.mOffset = aPos->mDirection == eDirNext ? 0 : end - start;
9141 }
9142 }
9143
9144 // Set outputs
9145 current.TransferTo(*aPos);
9146 // If we're dealing with a text frame and moving backward positions us at
9147 // the end of that line, decrease the offset by one to make sure that
9148 // we're placed before the linefeed character on the previous line.
9149 if (current.mOffset < 0 && current.mJumpedLine &&
9150 aPos->mDirection == eDirPrevious &&
9151 current.mFrame->HasSignificantTerminalNewline() &&
9152 !current.mIgnoredBrFrame) {
9153 --aPos->mContentOffset;
9154 }
9155 return NS_OK;
9156}
9157
9158nsresult nsIFrame::PeekOffsetForWord(PeekOffsetStruct* aPos, int32_t aOffset) {
9159 SelectablePeekReport current{this, aOffset};
9160 bool shouldStopAtHardBreak =
9161 aPos->mWordMovementType == eDefaultBehavior &&
9162 StaticPrefs::layout_word_select_eat_space_to_next_word();
9163 bool wordSelectEatSpace = ShouldWordSelectionEatSpace(*aPos);
9164
9165 PeekWordState state;
9166 while (true) {
9167 bool movingInFrameDirection = IsMovingInFrameDirection(
9168 current.mFrame, aPos->mDirection,
9169 aPos->mOptions.contains(PeekOffsetOption::Visual));
9170
9171 FrameSearchResult searchResult = current.mFrame->PeekOffsetWord(
9172 movingInFrameDirection, wordSelectEatSpace,
9173 aPos->mOptions.contains(PeekOffsetOption::IsKeyboardSelect),
9174 &current.mOffset, &state,
9175 !aPos->mOptions.contains(PeekOffsetOption::PreserveSpaces));
9176 if (searchResult == FOUND) {
9177 break;
9178 }
9179
9180 SelectablePeekReport next = [&]() {
9181 PeekOffsetOptions options = aPos->mOptions;
9182 if (state.mSawInlineCharacter) {
9183 // If we've already found a character, we don't want to stop at
9184 // placeholder frame boundary if there is in the word.
9185 options += PeekOffsetOption::StopAtPlaceholder;
9186 }
9187 return current.mFrame->GetFrameFromDirection(aPos->mDirection, options);
9188 }();
9189 if (next.Failed()) {
9190 // If we've crossed the line boundary, check to make sure that we
9191 // have not consumed a trailing newline as whitespace if it's
9192 // significant.
9193 if (next.mJumpedLine && wordSelectEatSpace &&
9194 current.mFrame->HasSignificantTerminalNewline() &&
9195 current.mFrame->StyleText()->mWhiteSpaceCollapse !=
9196 StyleWhiteSpaceCollapse::PreserveBreaks) {
9197 current.mOffset -= 1;
9198 }
9199 break;
9200 }
9201
9202 if ((next.mJumpedLine || next.mFoundPlaceholder) && !wordSelectEatSpace &&
9203 state.mSawBeforeType) {
9204 // We can't jump lines if we're looking for whitespace following
9205 // non-whitespace, and we already encountered non-whitespace.
9206 break;
9207 }
9208
9209 if (shouldStopAtHardBreak && next.mJumpedHardBreak) {
9210 /**
9211 * Prev, always: Jump and stop right there
9212 * Next, saw inline: just stop
9213 * Next, no inline: Jump and consume whitespaces
9214 */
9215 if (aPos->mDirection == eDirPrevious) {
9216 // Try moving to the previous line if exists
9217 current.TransferTo(*aPos);
9218 current.mFrame->PeekOffsetForCharacter(aPos, current.mOffset);
9219 return NS_OK;
9220 }
9221 if (state.mSawInlineCharacter || current.mJumpedHardBreak) {
9222 if (current.mFrame->HasSignificantTerminalNewline()) {
9223 current.mOffset -= 1;
9224 }
9225 current.TransferTo(*aPos);
9226 return NS_OK;
9227 }
9228 // Mark the state as whitespace and continue
9229 state.Update(false, true);
9230 }
9231
9232 if (next.mJumpedLine) {
9233 state.mContext.Truncate();
9234 }
9235 current = next;
9236 // Jumping a line is equivalent to encountering whitespace
9237 // This affects only when it already met an actual character
9238 if (wordSelectEatSpace && next.mJumpedLine) {
9239 state.SetSawBeforeType();
9240 }
9241 }
9242
9243 // Set outputs
9244 current.TransferTo(*aPos);
9245 return NS_OK;
9246}
9247
9248static nsIFrame* GetFirstSelectableDescendantWithLineIterator(
9249 const PeekOffsetStruct& aPeekOffsetStruct, nsIFrame* aParentFrame) {
9250 const bool forceEditableRegion = aPeekOffsetStruct.mOptions.contains(
9251 PeekOffsetOption::ForceEditableRegion);
9252 auto FoundValidFrame = [aPeekOffsetStruct,
9253 forceEditableRegion](const nsIFrame* aFrame) {
9254 if (!aFrame->IsSelectable(nullptr)) {
9255 return false;
9256 }
9257 if (!aPeekOffsetStruct.FrameContentIsInAncestorLimiter(aFrame)) {
9258 return false;
9259 }
9260 if (forceEditableRegion && !aFrame->ContentIsEditable()) {
9261 return false;
9262 }
9263 return true;
9264 };
9265
9266 for (nsIFrame* child : aParentFrame->PrincipalChildList()) {
9267 // some children may not be selectable, e.g. :before / :after pseudoelements
9268 // content with user-select: none, or contenteditable="false"
9269 // we need to skip them
9270 if (child->CanProvideLineIterator() && FoundValidFrame(child)) {
9271 return child;
9272 }
9273 if (nsIFrame* nested = GetFirstSelectableDescendantWithLineIterator(
9274 aPeekOffsetStruct, child)) {
9275 return nested;
9276 }
9277 }
9278 return nullptr;
9279}
9280
9281nsresult nsIFrame::PeekOffsetForLine(PeekOffsetStruct* aPos) {
9282 nsIFrame* blockFrame = this;
9283 nsresult result = NS_ERROR_FAILURE;
9284
9285 // outer loop
9286 // moving to a next block when no more blocks are available in a subtree
9287 AutoAssertNoDomMutations guard;
9288 while (NS_FAILED(result)((bool)(__builtin_expect(!!(NS_FAILED_impl(result)), 0)))) {
9289 auto [newBlock, lineFrame] = blockFrame->GetContainingBlockForLine(
9290 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller));
9291 if (!newBlock) {
9292 return NS_ERROR_FAILURE;
9293 }
9294 // FYI: If the editing host is an inline element, the block frame content
9295 // may be either not editable or editable but belonging to different editing
9296 // host.
9297 blockFrame = newBlock;
9298 nsILineIterator* iter = blockFrame->GetLineIterator();
9299 int32_t thisLine = iter->FindLineContaining(lineFrame);
9300 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"
, 9300)
) {
9301 return NS_ERROR_FAILURE;
9302 }
9303
9304 int8_t edgeCase = 0; // no edge case. This should look at thisLine
9305
9306 // this part will find a frame or a block frame. If it's a block frame
9307 // it will "drill down" to find a viable frame or it will return an
9308 // error.
9309 nsIFrame* lastFrame = this;
9310
9311 // inner loop - crawling the frames within a specific block subtree
9312 while (true) {
9313 result =
9314 GetNextPrevLineFromBlockFrame(aPos, blockFrame, thisLine, edgeCase);
9315 // we came back to same spot! keep going
9316 if (NS_SUCCEEDED(result)((bool)(__builtin_expect(!!(!NS_FAILED_impl(result)), 1))) &&
9317 (!aPos->mResultFrame || aPos->mResultFrame == lastFrame)) {
9318 aPos->mResultFrame = nullptr;
9319 lastFrame = nullptr;
9320 if (aPos->mDirection == eDirPrevious) {
9321 thisLine--;
9322 } else {
9323 thisLine++;
9324 }
9325 continue;
9326 }
9327
9328 if (NS_FAILED(result)((bool)(__builtin_expect(!!(NS_FAILED_impl(result)), 0)))) {
9329 break;
9330 }
9331
9332 lastFrame = aPos->mResultFrame; // set last frame
9333 /* SPECIAL CHECK FOR NAVIGATION INTO TABLES
9334 * when we hit a frame which doesn't have line iterator, we need to
9335 * drill down and find a child with the line iterator to prevent the
9336 * crawling process to prematurely finish. Note that this is only sound if
9337 * we're guaranteed to not have multiple children implementing
9338 * LineIterator.
9339 *
9340 * So far known cases are:
9341 * 1) table wrapper (drill down into table row group)
9342 * 2) table cell (drill down into its only anon child)
9343 */
9344 const bool shouldDrillIntoChildren =
9345 aPos->mResultFrame->IsTableWrapperFrame() ||
9346 aPos->mResultFrame->IsTableCellFrame();
9347
9348 if (shouldDrillIntoChildren) {
9349 nsIFrame* child = GetFirstSelectableDescendantWithLineIterator(
9350 *aPos, aPos->mResultFrame);
9351 if (child) {
9352 aPos->mResultFrame = child;
9353 }
9354 }
9355
9356 if (!aPos->mResultFrame->CanProvideLineIterator()) {
9357 // no more selectable content at this level
9358 break;
9359 }
9360
9361 if (aPos->mResultFrame == blockFrame) {
9362 // Make sure block element is not the same as the one we had before.
9363 break;
9364 }
9365
9366 // we've struck another block element with selectable content!
9367 if (aPos->mDirection == eDirPrevious) {
9368 edgeCase = 1; // far edge, search from end backwards
9369 } else {
9370 edgeCase = -1; // near edge search from beginning onwards
9371 }
9372 thisLine = 0; // this line means nothing now.
9373 // everything else means something so keep looking "inside" the
9374 // block
9375 blockFrame = aPos->mResultFrame;
9376 }
9377 }
9378 return result;
9379}
9380
9381nsresult nsIFrame::PeekOffsetForLineEdge(PeekOffsetStruct* aPos) {
9382 // Adjusted so that the caret can't get confused when content changes
9383 nsIFrame* frame = AdjustFrameForSelectionStyles(this);
9384 Element* editingHost = frame->GetContent()->GetEditingHost();
9385
9386 auto [blockFrame, lineFrame] = frame->GetContainingBlockForLine(
9387 aPos->mOptions.contains(PeekOffsetOption::StopAtScroller));
9388 if (!blockFrame) {
9389 return NS_ERROR_FAILURE;
9390 }
9391 AutoAssertNoDomMutations guard;
9392 nsILineIterator* it = blockFrame->GetLineIterator();
9393 int32_t thisLine = it->FindLineContaining(lineFrame);
9394 if (thisLine < 0) {
9395 return NS_ERROR_FAILURE;
9396 }
9397
9398 nsIFrame* baseFrame = nullptr;
9399 bool endOfLine = eSelectEndLine == aPos->mAmount;
9400
9401 if (aPos->mOptions.contains(PeekOffsetOption::Visual) &&
9402 PresContext()->BidiEnabled()) {
9403 nsIFrame* firstFrame;
9404 bool isReordered;
9405 nsIFrame* lastFrame;
9406 MOZ_TRY(do { auto mozTryTempResult_ = ::mozilla::ToResult(it->CheckLineOrder
(thisLine, &isReordered, &firstFrame, &lastFrame)
); if ((__builtin_expect(!!(mozTryTempResult_.isErr()), 0))) {
return mozTryTempResult_.propagateErr(); } } while (0)
9407 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)
;
9408 baseFrame = endOfLine ? lastFrame : firstFrame;
9409 } else {
9410 auto line = it->GetLine(thisLine).unwrap();
9411
9412 nsIFrame* frame = line.mFirstFrameOnLine;
9413 bool lastFrameWasEditable = false;
9414 for (int32_t count = line.mNumFramesOnLine; count;
9415 --count, frame = frame->GetNextSibling()) {
9416 if (frame->IsGeneratedContentFrame()) {
9417 continue;
9418 }
9419 // When jumping to the end of the line with the "end" key,
9420 // try to skip over brFrames
9421 if (endOfLine && line.mNumFramesOnLine > 1 && frame->IsBrFrame() &&
9422 lastFrameWasEditable == frame->GetContent()->IsEditable()) {
9423 continue;
9424 }
9425 lastFrameWasEditable =
9426 frame->GetContent() && frame->GetContent()->IsEditable();
9427 baseFrame = frame;
9428 if (!endOfLine) {
9429 break;
9430 }
9431 }
9432 }
9433 if (!baseFrame) {
9434 return NS_ERROR_FAILURE;
9435 }
9436 // Make sure we are not leaving our inline editing host if exists
9437 if (editingHost) {
9438 if (nsIFrame* frame = editingHost->GetPrimaryFrame()) {
9439 if (frame->IsInlineOutside() &&
9440 !editingHost->Contains(baseFrame->GetContent())) {
9441 baseFrame = frame;
9442 if (endOfLine) {
9443 baseFrame = baseFrame->LastContinuation();
9444 }
9445 }
9446 }
9447 }
9448 FrameTarget targetFrame = DrillDownToSelectionFrame(
9449 baseFrame, endOfLine, nsIFrame::IGNORE_NATIVE_ANONYMOUS_SUBTREE);
9450 SetPeekResultFromFrame(*aPos, targetFrame.frame, endOfLine ? -1 : 0,
9451 OffsetIsAtLineEdge::Yes);
9452 if (endOfLine && targetFrame.frame->HasSignificantTerminalNewline()) {
9453 // Do not position the caret after the terminating newline if we're
9454 // trying to move to the end of line (see bug 596506)
9455 --aPos->mContentOffset;
9456 }
9457 if (!aPos->mResultContent) {
9458 return NS_ERROR_FAILURE;
9459 }
9460 return NS_OK;
9461}
9462
9463nsresult nsIFrame::PeekOffset(PeekOffsetStruct* aPos) {
9464 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"
, 9464); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPos" ")");
do { *((volatile int*)__null) = 9464; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9465
9466 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"
, 9466)
) {
9467 // FIXME(Bug 1654362): <caption> currently can remain dirty.
9468 return NS_ERROR_UNEXPECTED;
9469 }
9470
9471 // Translate content offset to be relative to frame
9472 int32_t offset = aPos->mStartOffset - GetRangeForFrame(this).start;
9473
9474 switch (aPos->mAmount) {
9475 case eSelectCharacter:
9476 case eSelectCluster:
9477 return PeekOffsetForCharacter(aPos, offset);
9478 case eSelectWordNoSpace:
9479 // eSelectWordNoSpace means that we should not be eating any whitespace
9480 // when moving to the adjacent word. This means that we should set aPos->
9481 // mWordMovementType to eEndWord if we're moving forwards, and to
9482 // eStartWord if we're moving backwards.
9483 if (aPos->mDirection == eDirPrevious) {
9484 aPos->mWordMovementType = eStartWord;
9485 } else {
9486 aPos->mWordMovementType = eEndWord;
9487 }
9488 // Intentionally fall through the eSelectWord case.
9489 [[fallthrough]];
9490 case eSelectWord:
9491 return PeekOffsetForWord(aPos, offset);
9492 case eSelectLine:
9493 return PeekOffsetForLine(aPos);
9494 case eSelectBeginLine:
9495 case eSelectEndLine:
9496 return PeekOffsetForLineEdge(aPos);
9497 case eSelectParagraph:
9498 return PeekOffsetForParagraph(aPos);
9499 default: {
9500 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"
, 9500); MOZ_PretendNoReturn(); } } while (0)
;
9501 return NS_ERROR_FAILURE;
9502 }
9503 }
9504}
9505
9506nsIFrame::FrameSearchResult nsIFrame::PeekOffsetNoAmount(bool aForward,
9507 int32_t* aOffset) {
9508 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"
, 9508); MOZ_PretendNoReturn(); } } while (0)
;
9509 // Sure, we can stop right here.
9510 return FOUND;
9511}
9512
9513nsIFrame::FrameSearchResult nsIFrame::PeekOffsetCharacter(
9514 bool aForward, int32_t* aOffset, PeekOffsetCharacterOptions aOptions) {
9515 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"
, 9515); MOZ_PretendNoReturn(); } } while (0)
;
9516 int32_t startOffset = *aOffset;
9517 // A negative offset means "end of frame", which in our case means offset 1.
9518 if (startOffset < 0) startOffset = 1;
9519 if (aForward == (startOffset == 0)) {
9520 // We're before the frame and moving forward, or after it and moving
9521 // backwards: skip to the other side and we're done.
9522 *aOffset = 1 - startOffset;
9523 return FOUND;
9524 }
9525 return CONTINUE;
9526}
9527
9528nsIFrame::FrameSearchResult nsIFrame::PeekOffsetWord(
9529 bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
9530 int32_t* aOffset, PeekWordState* aState, bool /*aTrimSpaces*/) {
9531 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"
, 9531); MOZ_PretendNoReturn(); } } while (0)
;
9532 int32_t startOffset = *aOffset;
9533 // This isn't text, so truncate the context
9534 aState->mContext.Truncate();
9535 if (startOffset < 0) startOffset = 1;
9536 if (aForward == (startOffset == 0)) {
9537 // We're before the frame and moving forward, or after it and moving
9538 // backwards. If we're looking for non-whitespace, we found it (without
9539 // skipping this frame).
9540 if (!aState->mAtStart) {
9541 if (aState->mLastCharWasPunctuation) {
9542 // We're not punctuation, so this is a punctuation boundary.
9543 if (BreakWordBetweenPunctuation(aState, aForward, false, false,
9544 aIsKeyboardSelect))
9545 return FOUND;
9546 } else {
9547 // This is not a punctuation boundary.
9548 if (aWordSelectEatSpace && aState->mSawBeforeType) return FOUND;
9549 }
9550 }
9551 // Otherwise skip to the other side and note that we encountered
9552 // non-whitespace.
9553 *aOffset = 1 - startOffset;
9554 aState->Update(false, // not punctuation
9555 false // not whitespace
9556 );
9557 if (!aWordSelectEatSpace) aState->SetSawBeforeType();
9558 }
9559 return CONTINUE;
9560}
9561
9562// static
9563bool nsIFrame::BreakWordBetweenPunctuation(const PeekWordState* aState,
9564 bool aForward, bool aPunctAfter,
9565 bool aWhitespaceAfter,
9566 bool aIsKeyboardSelect) {
9567 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"
, 9568); MOZ_PretendNoReturn(); } } while (0)
9568 "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"
, 9568); MOZ_PretendNoReturn(); } } while (0)
;
9569 if (aState->mLastCharWasWhitespace) {
9570 // We always stop between whitespace and punctuation
9571 return true;
9572 }
9573 if (!StaticPrefs::layout_word_select_stop_at_punctuation()) {
9574 // When this pref is false, we never stop at a punctuation boundary unless
9575 // it's followed by whitespace (in the relevant direction).
9576 return aWhitespaceAfter;
9577 }
9578 if (!aIsKeyboardSelect) {
9579 // mouse caret movement (e.g. word selection) always stops at every
9580 // punctuation boundary
9581 return true;
9582 }
9583 bool afterPunct = aForward ? aState->mLastCharWasPunctuation : aPunctAfter;
9584 if (!afterPunct) {
9585 // keyboard caret movement only stops after punctuation (in content order)
9586 return false;
9587 }
9588 // Stop only if we've seen some non-punctuation since the last whitespace;
9589 // don't stop after punctuation that follows whitespace.
9590 return aState->mSeenNonPunctuationSinceWhitespace;
9591}
9592
9593std::pair<nsIFrame*, nsIFrame*> nsIFrame::GetContainingBlockForLine(
9594 bool aLockScroll) const {
9595 const nsIFrame* parentFrame = this;
9596 const nsIFrame* frame;
9597 while (parentFrame) {
9598 frame = parentFrame;
9599 if (frame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
9600 // if we are searching for a frame that is not in flow we will not find
9601 // it. we must instead look for its placeholder
9602 if (frame->HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER)) {
9603 // abspos continuations don't have placeholders, get the fif
9604 frame = frame->FirstInFlow();
9605 }
9606 frame = frame->GetPlaceholderFrame();
9607 if (!frame) {
9608 return std::pair(nullptr, nullptr);
9609 }
9610 }
9611 parentFrame = frame->GetParent();
9612 if (parentFrame) {
9613 if (aLockScroll && parentFrame->IsScrollContainerFrame()) {
9614 return std::pair(nullptr, nullptr);
9615 }
9616 if (parentFrame->CanProvideLineIterator()) {
9617 return std::pair(const_cast<nsIFrame*>(parentFrame),
9618 const_cast<nsIFrame*>(frame));
9619 }
9620 }
9621 }
9622 return std::pair(nullptr, nullptr);
9623}
9624
9625Result<bool, nsresult> nsIFrame::IsVisuallyAtLineEdge(
9626 nsILineIterator* aLineIterator, int32_t aLine, nsDirection aDirection) {
9627 auto line = aLineIterator->GetLine(aLine).unwrap();
9628
9629 const bool lineIsRTL = aLineIterator->IsLineIteratorFlowRTL();
9630
9631 nsIFrame *firstFrame = nullptr, *lastFrame = nullptr;
9632 bool isReordered = false;
9633 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)
9634 &lastFrame))do { auto mozTryTempResult_ = ::mozilla::ToResult(aLineIterator
->CheckLineOrder(aLine, &isReordered, &firstFrame,
&lastFrame)); if ((__builtin_expect(!!(mozTryTempResult_
.isErr()), 0))) { return mozTryTempResult_.propagateErr(); } }
while (0)
;
9635 if (!firstFrame || !lastFrame) {
9636 return true; // XXX: Why true? We check whether `this` is at the edge...
9637 }
9638
9639 nsIFrame* leftmostFrame = lineIsRTL ? lastFrame : firstFrame;
9640 nsIFrame* rightmostFrame = lineIsRTL ? firstFrame : lastFrame;
9641 auto FrameIsRTL = [](nsIFrame* aFrame) {
9642 return nsBidiPresUtils::FrameDirection(aFrame) ==
9643 mozilla::intl::BidiDirection::RTL;
9644 };
9645 if (!lineIsRTL == (aDirection == eDirPrevious)) {
9646 nsIFrame* maybeLeftmostFrame = leftmostFrame;
9647 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9648 if (maybeLeftmostFrame == this) {
9649 return true;
9650 }
9651 // If left edge of the line starts with placeholder frames, we can ignore
9652 // them and should keep checking the following frames.
9653 if (!maybeLeftmostFrame->IsPlaceholderFrame()) {
9654 if ((FrameIsRTL(maybeLeftmostFrame) == lineIsRTL) ==
9655 (aDirection == eDirPrevious)) {
9656 nsIFrame::GetFirstLeaf(&maybeLeftmostFrame);
9657 } else {
9658 nsIFrame::GetLastLeaf(&maybeLeftmostFrame);
9659 }
9660 return maybeLeftmostFrame == this;
9661 }
9662 maybeLeftmostFrame = nsBidiPresUtils::GetFrameToRightOf(
9663 maybeLeftmostFrame, line.mFirstFrameOnLine, line.mNumFramesOnLine);
9664 if (!maybeLeftmostFrame) {
9665 return false;
9666 }
9667 }
9668 return false;
9669 }
9670
9671 nsIFrame* maybeRightmostFrame = rightmostFrame;
9672 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9673 if (maybeRightmostFrame == this) {
9674 return true;
9675 }
9676 // If the line ends with placehlder frames, we can ignore them and should
9677 // keep checking the preceding frames.
9678 if (!maybeRightmostFrame->IsPlaceholderFrame()) {
9679 if ((FrameIsRTL(maybeRightmostFrame) == lineIsRTL) ==
9680 (aDirection == eDirPrevious)) {
9681 nsIFrame::GetFirstLeaf(&maybeRightmostFrame);
9682 } else {
9683 nsIFrame::GetLastLeaf(&maybeRightmostFrame);
9684 }
9685 return maybeRightmostFrame == this;
9686 }
9687 maybeRightmostFrame = nsBidiPresUtils::GetFrameToLeftOf(
9688 maybeRightmostFrame, line.mFirstFrameOnLine, line.mNumFramesOnLine);
9689 if (!maybeRightmostFrame) {
9690 return false;
9691 }
9692 }
9693 return false;
9694}
9695
9696Result<bool, nsresult> nsIFrame::IsLogicallyAtLineEdge(
9697 nsILineIterator* aLineIterator, int32_t aLine, nsDirection aDirection) {
9698 auto line = aLineIterator->GetLine(aLine).unwrap();
9699 if (!line.mNumFramesOnLine) {
9700 return false;
9701 }
9702 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"
, 9702); AnnotateMozCrashReason("MOZ_ASSERT" "(" "line.mFirstFrameOnLine"
")"); do { *((volatile int*)__null) = 9702; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9703
9704 if (aDirection == eDirPrevious) {
9705 nsIFrame* maybeFirstFrame = line.mFirstFrameOnLine;
9706 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9707 if (maybeFirstFrame == this) {
9708 return true;
9709 }
9710 // If the line starts with placeholder frames, we can ignore them and
9711 // should keep checking the following frames.
9712 if (!maybeFirstFrame->IsPlaceholderFrame()) {
9713 nsIFrame::GetFirstLeaf(&maybeFirstFrame);
9714 return maybeFirstFrame == this;
9715 }
9716 maybeFirstFrame = maybeFirstFrame->GetNextSibling();
9717 if (!maybeFirstFrame) {
9718 return false;
9719 }
9720 }
9721 return false;
9722 }
9723
9724 // eDirNext
9725 nsIFrame* maybeLastFrame = line.GetLastFrameOnLine();
9726 for ([[maybe_unused]] int32_t i : IntegerRange(line.mNumFramesOnLine)) {
9727 if (maybeLastFrame == this) {
9728 return true;
9729 }
9730 // If the line ends with placehlder frames, we can ignore them and should
9731 // keep checking the preceding frames.
9732 if (!maybeLastFrame->IsPlaceholderFrame()) {
9733 nsIFrame::GetLastLeaf(&maybeLastFrame);
9734 return maybeLastFrame == this;
9735 }
9736 maybeLastFrame = maybeLastFrame->GetPrevSibling();
9737 }
9738 return false;
9739}
9740
9741nsIFrame::SelectablePeekReport nsIFrame::GetFrameFromDirection(
9742 nsDirection aDirection, const PeekOffsetOptions& aOptions) {
9743 SelectablePeekReport result;
9744
9745 nsPresContext* presContext = PresContext();
9746 const bool needsVisualTraversal =
9747 aOptions.contains(PeekOffsetOption::Visual) && presContext->BidiEnabled();
9748 const bool followOofs =
9749 !aOptions.contains(PeekOffsetOption::StopAtPlaceholder);
9750 nsFrameIterator frameIterator(
9751 presContext, this, nsFrameIterator::Type::Leaf, needsVisualTraversal,
9752 aOptions.contains(PeekOffsetOption::StopAtScroller), followOofs,
9753 false // aSkipPopupChecks
9754 );
9755
9756 // Find the prev/next selectable frame
9757 bool selectable = false;
9758 nsIFrame* traversedFrame = this;
9759 AutoAssertNoDomMutations guard;
9760 const nsIContent* const nativeAnonymousSubtreeContent =
9761 GetClosestNativeAnonymousSubtreeRoot();
9762 while (!selectable) {
9763 auto [blockFrame, lineFrame] = traversedFrame->GetContainingBlockForLine(
9764 aOptions.contains(PeekOffsetOption::StopAtScroller));
9765 if (!blockFrame) {
9766 return result;
9767 }
9768
9769 nsILineIterator* it = blockFrame->GetLineIterator();
9770 int32_t thisLine = it->FindLineContaining(lineFrame);
9771 if (thisLine < 0) {
9772 return result;
9773 }
9774
9775 bool atLineEdge;
9776 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)
9777 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)
9778 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)
9779 ? 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)
9780 : 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)
;
9781 if (atLineEdge) {
9782 result.mJumpedLine = true;
9783 if (!aOptions.contains(PeekOffsetOption::JumpLines)) {
9784 return result; // we are done. cannot jump lines
9785 }
9786 int32_t lineToCheckWrap =
9787 aDirection == eDirPrevious ? thisLine - 1 : thisLine;
9788 if (lineToCheckWrap < 0 ||
9789 !it->GetLine(lineToCheckWrap).unwrap().mIsWrapped) {
9790 result.mJumpedHardBreak = true;
9791 }
9792 }
9793
9794 traversedFrame = frameIterator.Traverse(aDirection == eDirNext);
9795 if (!traversedFrame) {
9796 return result;
9797 }
9798
9799 if (aOptions.contains(PeekOffsetOption::StopAtPlaceholder) &&
9800 traversedFrame->IsPlaceholderFrame()) {
9801 // XXX If the placeholder frame does not have meaningful content, the user
9802 // may want to select as a word around the out-of-flow cotent. However,
9803 // non-text frame resets context in nsIFrame::PeekOffsetWord(). Therefore,
9804 // next text frame considers the new word starts from its edge. So, it's
9805 // not enough to implement such behavior with adding a check here whether
9806 // the real frame may change the word with its contents if it were not
9807 // out-of-flow.
9808 result.mFoundPlaceholder = true;
9809 return result;
9810 }
9811
9812 auto IsSelectable =
9813 [aOptions, nativeAnonymousSubtreeContent](const nsIFrame* aFrame) {
9814 if (!aFrame->IsSelectable(nullptr)) {
9815 return false;
9816 }
9817 // If the new frame is in a native anonymous subtree, we should treat
9818 // it as not selectable unless the frame and found frame are in same
9819 // subtree.
9820 if (aFrame->GetClosestNativeAnonymousSubtreeRoot() !=
9821 nativeAnonymousSubtreeContent) {
9822 return false;
9823 }
9824 return !aOptions.contains(PeekOffsetOption::ForceEditableRegion) ||
9825 aFrame->GetContent()->IsEditable();
9826 };
9827
9828 // Skip br frames, but only if we can select something before hitting the
9829 // end of the line or a non-selectable region.
9830 if (atLineEdge && aDirection == eDirPrevious &&
9831 traversedFrame->IsBrFrame()) {
9832 for (nsIFrame* current = traversedFrame->GetPrevSibling(); current;
9833 current = current->GetPrevSibling()) {
9834 if (!current->IsBlockOutside() && IsSelectable(current)) {
9835 if (!current->IsBrFrame()) {
9836 result.mIgnoredBrFrame = true;
9837 }
9838 break;
9839 }
9840 }
9841 if (result.mIgnoredBrFrame) {
9842 continue;
9843 }
9844 }
9845
9846 selectable = IsSelectable(traversedFrame);
9847 if (!selectable) {
9848 if (traversedFrame->IsSelectable(nullptr)) {
9849 result.mHasSelectableFrame = true;
9850 }
9851 result.mMovedOverNonSelectableText = true;
9852 }
9853 } // while (!selectable)
9854
9855 result.mOffset = (aDirection == eDirNext) ? 0 : -1;
9856
9857 if (aOptions.contains(PeekOffsetOption::Visual) &&
9858 nsBidiPresUtils::IsReversedDirectionFrame(traversedFrame)) {
9859 // The new frame is reverse-direction, go to the other end
9860 result.mOffset = -1 - result.mOffset;
9861 }
9862 result.mFrame = traversedFrame;
9863 return result;
9864}
9865
9866nsIFrame::SelectablePeekReport nsIFrame::GetFrameFromDirection(
9867 const PeekOffsetStruct& aPos) {
9868 return GetFrameFromDirection(aPos.mDirection, aPos.mOptions);
9869}
9870
9871nsView* nsIFrame::GetClosestView(nsPoint* aOffset) const {
9872 nsPoint offset(0, 0);
9873 for (const nsIFrame* f = this; f; f = f->GetParent()) {
9874 if (f->HasView()) {
9875 if (aOffset) *aOffset = offset;
9876 return f->GetView();
9877 }
9878 offset += f->GetPosition();
9879 }
9880
9881 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"
, 9881); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "No view on any parent? How did that happen?"
")"); do { *((volatile int*)__null) = 9881; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9882 return nullptr;
9883}
9884
9885/* virtual */
9886void nsIFrame::ChildIsDirty(nsIFrame* aChild) {
9887 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"
, 9889); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should never be called on a frame that doesn't "
"inherit from nsContainerFrame" ")"); do { *((volatile int*)
__null) = 9889; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
9888 "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"
, 9889); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should never be called on a frame that doesn't "
"inherit from nsContainerFrame" ")"); do { *((volatile int*)
__null) = 9889; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
9889 "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"
, 9889); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "should never be called on a frame that doesn't "
"inherit from nsContainerFrame" ")"); do { *((volatile int*)
__null) = 9889; __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
9890}
9891
9892#ifdef ACCESSIBILITY1
9893a11y::AccType nsIFrame::AccessibleType() {
9894 if (IsTableCaption() && !GetRect().IsEmpty()) {
9895 return a11y::eHTMLCaptionType;
9896 }
9897 return a11y::eNoType;
9898}
9899#endif
9900
9901bool nsIFrame::ClearOverflowRects() {
9902 if (mOverflow.mType == OverflowStorageType::None) {
9903 return false;
9904 }
9905 if (mOverflow.mType == OverflowStorageType::Large) {
9906 RemoveProperty(OverflowAreasProperty());
9907 }
9908 mOverflow.mType = OverflowStorageType::None;
9909 return true;
9910}
9911
9912bool nsIFrame::SetOverflowAreas(const OverflowAreas& aOverflowAreas) {
9913 if (mOverflow.mType == OverflowStorageType::Large) {
9914 OverflowAreas* overflow = GetOverflowAreasProperty();
9915 bool changed = *overflow != aOverflowAreas;
9916 *overflow = aOverflowAreas;
9917
9918 // Don't bother with converting to the deltas form if we already
9919 // have a property.
9920 return changed;
9921 }
9922
9923 const nsRect& vis = aOverflowAreas.InkOverflow();
9924 uint32_t l = -vis.x, // left edge: positive delta is leftwards
9925 t = -vis.y, // top: positive is upwards
9926 r = vis.XMost() - mRect.width, // right: positive is rightwards
9927 b = vis.YMost() - mRect.height; // bottom: positive is downwards
9928 if (aOverflowAreas.ScrollableOverflow().IsEqualEdges(
9929 nsRect(nsPoint(0, 0), GetSize())) &&
9930 l <= InkOverflowDeltas::kMax && t <= InkOverflowDeltas::kMax &&
9931 r <= InkOverflowDeltas::kMax && b <= InkOverflowDeltas::kMax &&
9932 // we have to check these against zero because we *never* want to
9933 // set a frame as having no overflow in this function. This is
9934 // because FinishAndStoreOverflow calls this function prior to
9935 // SetRect based on whether the overflow areas match aNewSize.
9936 // In the case where the overflow areas exactly match mRect but
9937 // do not match aNewSize, we need to store overflow in a property
9938 // so that our eventual SetRect/SetSize will know that it has to
9939 // reset our overflow areas.
9940 (l | t | r | b) != 0) {
9941 InkOverflowDeltas oldDeltas = mOverflow.mInkOverflowDeltas;
9942 // It's a "small" overflow area so we store the deltas for each edge
9943 // directly in the frame, rather than allocating a separate rect.
9944 // If they're all zero, that's fine; we're setting things to
9945 // no-overflow.
9946 mOverflow.mInkOverflowDeltas.mLeft = l;
9947 mOverflow.mInkOverflowDeltas.mTop = t;
9948 mOverflow.mInkOverflowDeltas.mRight = r;
9949 mOverflow.mInkOverflowDeltas.mBottom = b;
9950 // There was no scrollable overflow before, and there isn't now.
9951 return oldDeltas != mOverflow.mInkOverflowDeltas;
9952 } else {
9953 bool changed =
9954 !aOverflowAreas.ScrollableOverflow().IsEqualEdges(
9955 nsRect(nsPoint(0, 0), GetSize())) ||
9956 !aOverflowAreas.InkOverflow().IsEqualEdges(InkOverflowFromDeltas());
9957
9958 // it's a large overflow area that we need to store as a property
9959 mOverflow.mType = OverflowStorageType::Large;
9960 AddProperty(OverflowAreasProperty(), new OverflowAreas(aOverflowAreas));
9961 return changed;
9962 }
9963}
9964
9965enum class ApplyTransform : bool { No, Yes };
9966
9967/**
9968 * Compute the outline inner rect (so without outline-width and outline-offset)
9969 * of aFrame, maybe iterating over its descendants, in aFrame's coordinate space
9970 * or its post-transform coordinate space (depending on aApplyTransform).
9971 */
9972static nsRect ComputeOutlineInnerRect(
9973 nsIFrame* aFrame, ApplyTransform aApplyTransform, bool& aOutValid,
9974 const nsSize* aSizeOverride = nullptr,
9975 const OverflowAreas* aOverflowOverride = nullptr) {
9976 const nsRect bounds(nsPoint(0, 0),
9977 aSizeOverride ? *aSizeOverride : aFrame->GetSize());
9978
9979 // The SVG container frames besides SVGTextFrame do not maintain
9980 // an accurate mRect. It will make the outline be larger than
9981 // we expect, we need to make them narrow to their children's outline.
9982 // aOutValid is set to false if the returned nsRect is not valid
9983 // and should not be included in the outline rectangle.
9984 aOutValid = !aFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT) ||
9985 !aFrame->IsSVGContainerFrame() || aFrame->IsSVGTextFrame();
9986
9987 nsRect u;
9988
9989 if (!aFrame->FrameMaintainsOverflow()) {
9990 return u;
9991 }
9992
9993 // Start from our border-box, transformed. See comment below about
9994 // transform of children.
9995 bool doTransform =
9996 aApplyTransform == ApplyTransform::Yes && aFrame->IsTransformed();
9997 TransformReferenceBox boundsRefBox(nullptr, bounds);
9998 if (doTransform) {
9999 u = nsDisplayTransform::TransformRect(bounds, aFrame, boundsRefBox);
10000 } else {
10001 u = bounds;
10002 }
10003
10004 if (aOutValid && !StaticPrefs::layout_outline_include_overflow()) {
10005 return u;
10006 }
10007
10008 // Only iterate through the children if the overflow areas suggest
10009 // that we might need to, and if the frame doesn't clip its overflow
10010 // anyway.
10011 if (aOverflowOverride) {
10012 if (!doTransform && bounds.IsEqualEdges(aOverflowOverride->InkOverflow()) &&
10013 bounds.IsEqualEdges(aOverflowOverride->ScrollableOverflow())) {
10014 return u;
10015 }
10016 } else {
10017 if (!doTransform && bounds.IsEqualEdges(aFrame->InkOverflowRect()) &&
10018 bounds.IsEqualEdges(aFrame->ScrollableOverflowRect())) {
10019 return u;
10020 }
10021 }
10022 const nsStyleDisplay* disp = aFrame->StyleDisplay();
10023 LayoutFrameType fType = aFrame->Type();
10024 if (fType == LayoutFrameType::ScrollContainer ||
10025 fType == LayoutFrameType::ListControl ||
10026 fType == LayoutFrameType::SVGOuterSVG) {
10027 return u;
10028 }
10029
10030 auto overflowClipAxes = aFrame->ShouldApplyOverflowClipping(disp);
10031 auto overflowClipMargin = aFrame->OverflowClipMargin(overflowClipAxes);
10032 if (overflowClipAxes == kPhysicalAxesBoth && overflowClipMargin == nsSize()) {
10033 return u;
10034 }
10035
10036 const nsStyleEffects* effects = aFrame->StyleEffects();
10037 Maybe<nsRect> clipPropClipRect =
10038 aFrame->GetClipPropClipRect(disp, effects, bounds.Size());
10039
10040 // Iterate over all children except pop-up, absolutely-positioned,
10041 // float, and overflow ones.
10042 const FrameChildListIDs skip = {
10043 FrameChildListID::Absolute, FrameChildListID::Fixed,
10044 FrameChildListID::Float, FrameChildListID::Overflow};
10045 for (const auto& [list, listID] : aFrame->ChildLists()) {
10046 if (skip.contains(listID)) {
10047 continue;
10048 }
10049
10050 for (nsIFrame* child : list) {
10051 if (child->IsPlaceholderFrame()) {
10052 continue;
10053 }
10054
10055 // Note that passing ApplyTransform::Yes when
10056 // child->Combines3DTransformWithAncestors() returns true is incorrect if
10057 // our aApplyTransform is No... but the opposite would be as well.
10058 // This is because elements within a preserve-3d scene are always
10059 // transformed up to the top of the scene. This means we don't have a
10060 // mechanism for getting a transform up to an intermediate point within
10061 // the scene. We choose to over-transform rather than under-transform
10062 // because this is consistent with other overflow areas.
10063 bool validRect = true;
10064 nsRect childRect =
10065 ComputeOutlineInnerRect(child, ApplyTransform::Yes, validRect) +
10066 child->GetPosition();
10067
10068 if (!validRect) {
10069 continue;
10070 }
10071
10072 if (clipPropClipRect) {
10073 // Intersect with the clip before transforming.
10074 childRect.IntersectRect(childRect, *clipPropClipRect);
10075 }
10076
10077 // Note that we transform each child separately according to
10078 // aFrame's transform, and then union, which gives a different
10079 // (smaller) result from unioning and then transforming the
10080 // union. This doesn't match the way we handle overflow areas
10081 // with 2-D transforms, though it does match the way we handle
10082 // overflow areas in preserve-3d 3-D scenes.
10083 if (doTransform && !child->Combines3DTransformWithAncestors()) {
10084 childRect =
10085 nsDisplayTransform::TransformRect(childRect, aFrame, boundsRefBox);
10086 }
10087
10088 // If a SVGContainer has a non-SVGContainer child, we assign
10089 // its child's outline to this SVGContainer directly.
10090 if (!aOutValid && validRect) {
10091 u = childRect;
10092 aOutValid = true;
10093 } else {
10094 u = u.UnionEdges(childRect);
10095 }
10096 }
10097 }
10098
10099 if (!overflowClipAxes.isEmpty()) {
10100 OverflowAreas::ApplyOverflowClippingOnRect(u, bounds, overflowClipAxes,
10101 overflowClipMargin);
10102 }
10103 return u;
10104}
10105
10106static void ComputeAndIncludeOutlineArea(nsIFrame* aFrame,
10107 OverflowAreas& aOverflowAreas,
10108 const nsSize& aNewSize) {
10109 const nsStyleOutline* outline = aFrame->StyleOutline();
10110 if (!outline->ShouldPaintOutline()) {
10111 return;
10112 }
10113
10114 // When the outline property is set on a :-moz-block-inside-inline-wrapper
10115 // pseudo-element, it inherited that outline from the inline that was broken
10116 // because it contained a block. In that case, we don't want a really wide
10117 // outline if the block inside the inline is narrow, so union the actual
10118 // contents of the anonymous blocks.
10119 nsIFrame* frameForArea = aFrame;
10120 do {
10121 PseudoStyleType pseudoType = frameForArea->Style()->GetPseudoType();
10122 if (pseudoType != PseudoStyleType::mozBlockInsideInlineWrapper) break;
10123 // If we're done, we really want it and all its later siblings.
10124 frameForArea = frameForArea->PrincipalChildList().FirstChild();
10125 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"
, 10125); MOZ_PretendNoReturn(); } } while (0)
;
10126 } while (frameForArea);
10127
10128 // Find the union of the border boxes of all descendants, or in
10129 // the block-in-inline case, all descendants we care about.
10130 //
10131 // Note that the interesting perspective-related cases are taken
10132 // care of by the code that handles those issues for overflow
10133 // calling FinishAndStoreOverflow again, which in turn calls this
10134 // function again. We still need to deal with preserve-3d a bit.
10135 nsRect innerRect;
10136 bool validRect = false;
10137 if (frameForArea == aFrame) {
10138 innerRect = ComputeOutlineInnerRect(aFrame, ApplyTransform::No, validRect,
10139 &aNewSize, &aOverflowAreas);
10140 } else {
10141 for (; frameForArea; frameForArea = frameForArea->GetNextSibling()) {
10142 nsRect r =
10143 ComputeOutlineInnerRect(frameForArea, ApplyTransform::Yes, validRect);
10144
10145 // Adjust for offsets transforms up to aFrame's pre-transform
10146 // (i.e., normal) coordinate space; see comments in
10147 // UnionBorderBoxes for some of the subtlety here.
10148 for (nsIFrame *f = frameForArea, *parent = f->GetParent();
10149 /* see middle of loop */; f = parent, parent = f->GetParent()) {
10150 r += f->GetPosition();
10151 if (parent == aFrame) {
10152 break;
10153 }
10154 if (parent->IsTransformed() && !f->Combines3DTransformWithAncestors()) {
10155 TransformReferenceBox refBox(parent);
10156 r = nsDisplayTransform::TransformRect(r, parent, refBox);
10157 }
10158 }
10159
10160 innerRect.UnionRect(innerRect, r);
10161 }
10162 }
10163
10164 // Keep this code in sync with nsDisplayOutline::GetInnerRect.
10165 if (innerRect == aFrame->GetRectRelativeToSelf()) {
10166 aFrame->RemoveProperty(nsIFrame::OutlineInnerRectProperty());
10167 } else {
10168 SetOrUpdateRectValuedProperty(aFrame, nsIFrame::OutlineInnerRectProperty(),
10169 innerRect);
10170 }
10171
10172 nsRect outerRect(innerRect);
10173 outerRect.Inflate(outline->EffectiveOffsetFor(outerRect));
10174
10175 if (outline->mOutlineStyle.IsAuto()) {
10176 nsPresContext* pc = aFrame->PresContext();
10177
10178 pc->Theme()->GetWidgetOverflow(pc->DeviceContext(), aFrame,
10179 StyleAppearance::FocusOutline, &outerRect);
10180 } else {
10181 const nscoord width = outline->GetOutlineWidth();
10182 outerRect.Inflate(width);
10183 }
10184
10185 nsRect& vo = aOverflowAreas.InkOverflow();
10186 vo = vo.UnionEdges(innerRect.Union(outerRect));
10187}
10188
10189bool nsIFrame::FinishAndStoreOverflow(OverflowAreas& aOverflowAreas,
10190 nsSize aNewSize, nsSize* aOldSize,
10191 const nsStyleDisplay* aStyleDisplay) {
10192 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"
, 10193); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Don't call - overflow rects not maintained on these SVG frames"
")"); do { *((volatile int*)__null) = 10193; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
10193 "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"
, 10193); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FrameMaintainsOverflow()"
") (" "Don't call - overflow rects not maintained on these SVG frames"
")"); do { *((volatile int*)__null) = 10193; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10194
10195 const nsStyleDisplay* disp = StyleDisplayWithOptionalParam(aStyleDisplay);
10196 bool hasTransform = IsTransformed();
10197
10198 nsRect bounds(nsPoint(0, 0), aNewSize);
10199 // Store the passed in overflow area if we are a preserve-3d frame or we have
10200 // a transform, and it's not just the frame bounds.
10201 if (hasTransform || Combines3DTransformWithAncestors()) {
10202 if (!aOverflowAreas.InkOverflow().IsEqualEdges(bounds) ||
10203 !aOverflowAreas.ScrollableOverflow().IsEqualEdges(bounds)) {
10204 OverflowAreas* initial = GetProperty(nsIFrame::InitialOverflowProperty());
10205 if (!initial) {
10206 AddProperty(nsIFrame::InitialOverflowProperty(),
10207 new OverflowAreas(aOverflowAreas));
10208 } else if (initial != &aOverflowAreas) {
10209 *initial = aOverflowAreas;
10210 }
10211 } else {
10212 RemoveProperty(nsIFrame::InitialOverflowProperty());
10213 }
10214#ifdef DEBUG1
10215 SetProperty(nsIFrame::DebugInitialOverflowPropertyApplied(), true);
10216#endif
10217 } else {
10218#ifdef DEBUG1
10219 RemoveProperty(nsIFrame::DebugInitialOverflowPropertyApplied());
10220#endif
10221 }
10222
10223 nsSize oldSize = mRect.Size();
10224 bool sizeChanged = ((aOldSize ? *aOldSize : oldSize) != aNewSize);
10225
10226 // Our frame size may not have been computed and set yet, but code under
10227 // functions such as ComputeEffectsRect (which we're about to call) use the
10228 // values that are stored in our frame rect to compute their results. We
10229 // need the results from those functions to be based on the frame size that
10230 // we *will* have, so we temporarily set our frame size here before calling
10231 // those functions.
10232 //
10233 // XXX Someone should document here why we revert the frame size before we
10234 // return rather than just leaving it set.
10235 //
10236 // We pass false here to avoid invalidating display items for this temporary
10237 // change. We sometimes reflow frames multiple times, with the final size
10238 // being the same as the initial. The single call to SetSize after reflow is
10239 // done will take care of invalidating display items if the size has actually
10240 // changed.
10241 SetSize(aNewSize, false);
10242
10243 const auto overflowClipAxes = ShouldApplyOverflowClipping(disp);
10244
10245 if (ChildrenHavePerspective(disp) && sizeChanged) {
10246 RecomputePerspectiveChildrenOverflow(this);
10247
10248 if (overflowClipAxes != kPhysicalAxesBoth) {
10249 aOverflowAreas.SetAllTo(bounds);
10250 DebugOnly<bool> ok = ComputeCustomOverflow(aOverflowAreas);
10251
10252 // ComputeCustomOverflow() should not return false, when
10253 // FrameMaintainsOverflow() returns true.
10254 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"
, 10254); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ok" ") (" "FrameMaintainsOverflow() != ComputeCustomOverflow()"
")"); do { *((volatile int*)__null) = 10254; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10255
10256 UnionChildOverflow(aOverflowAreas);
10257 }
10258 }
10259
10260 // This is now called FinishAndStoreOverflow() instead of
10261 // StoreOverflow() because frame-generic ways of adding overflow
10262 // can happen here, e.g. CSS2 outline and native theme.
10263 // If the overflow area width or height is nscoord_MAX, then a saturating
10264 // union may have encountered an overflow, so the overflow may not contain the
10265 // frame border-box. Don't warn in that case.
10266 // Don't warn for SVG either, since SVG doesn't need the overflow area
10267 // to contain the frame bounds.
10268#ifdef DEBUG1
10269 for (const auto otype : AllOverflowTypes()) {
10270 const nsRect& r = aOverflowAreas.Overflow(otype);
10271 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"
, 10275); MOZ_PretendNoReturn(); } } while (0)
10272 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"
, 10275); MOZ_PretendNoReturn(); } } while (0)
10273 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"
, 10275); MOZ_PretendNoReturn(); } } while (0)
10274 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"
, 10275); MOZ_PretendNoReturn(); } } while (0)
10275 "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"
, 10275); MOZ_PretendNoReturn(); } } while (0)
;
10276 }
10277#endif
10278
10279 // Overflow area must always include the frame's top-left and bottom-right,
10280 // even if the frame rect is empty (so we can scroll to those positions).
10281 const bool shouldIncludeBounds = [&] {
10282 if (aNewSize.width == 0 && IsInlineFrame()) {
10283 // Pending a real fix for bug 426879, don't do this for inline frames with
10284 // zero width.
10285 return false;
10286 }
10287 if (HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
10288 // Do not do this for SVG either, since it will usually massively increase
10289 // the area unnecessarily (except for SVG that applies clipping, since
10290 // that's the pre-existing behavior, and breaks pre-rendering otherwise).
10291 // FIXME(bug 1770704): This check most likely wants to be removed or check
10292 // for specific frame types at least.
10293 return !overflowClipAxes.isEmpty();
10294 }
10295 return true;
10296 }();
10297
10298 if (shouldIncludeBounds) {
10299 for (const auto otype : AllOverflowTypes()) {
10300 nsRect& o = aOverflowAreas.Overflow(otype);
10301 o = o.UnionEdges(bounds);
10302 }
10303 }
10304
10305 // If we clip our children, clear accumulated overflow area in the affected
10306 // dimension(s). The children are actually clipped to the padding-box, but
10307 // since the overflow area should include the entire border-box, just set it
10308 // to the border-box size here.
10309 if (!overflowClipAxes.isEmpty()) {
10310 aOverflowAreas.ApplyClipping(bounds, overflowClipAxes,
10311 OverflowClipMargin(overflowClipAxes));
10312 }
10313
10314 ComputeAndIncludeOutlineArea(this, aOverflowAreas, aNewSize);
10315
10316 // Nothing in here should affect scrollable overflow.
10317 aOverflowAreas.InkOverflow() =
10318 ComputeEffectsRect(this, aOverflowAreas.InkOverflow(), aNewSize);
10319
10320 // Absolute position clipping
10321 const nsStyleEffects* effects = StyleEffects();
10322 Maybe<nsRect> clipPropClipRect = GetClipPropClipRect(disp, effects, aNewSize);
10323 if (clipPropClipRect) {
10324 for (const auto otype : AllOverflowTypes()) {
10325 nsRect& o = aOverflowAreas.Overflow(otype);
10326 o.IntersectRect(o, *clipPropClipRect);
10327 }
10328 }
10329
10330 /* If we're transformed, transform the overflow rect by the current
10331 * transformation. */
10332 if (hasTransform) {
10333 SetProperty(nsIFrame::PreTransformOverflowAreasProperty(),
10334 new OverflowAreas(aOverflowAreas));
10335
10336 if (Combines3DTransformWithAncestors()) {
10337 /* If we're a preserve-3d leaf frame, then our pre-transform overflow
10338 * should be correct. Our post-transform overflow is empty though, because
10339 * we only contribute to the overflow area of the preserve-3d root frame.
10340 * If we're an intermediate frame then the pre-transform overflow should
10341 * contain all our non-preserve-3d children, which is what we want. Again
10342 * we have no post-transform overflow.
10343 */
10344 aOverflowAreas.SetAllTo(nsRect());
10345 } else {
10346 TransformReferenceBox refBox(this);
10347 for (const auto otype : AllOverflowTypes()) {
10348 nsRect& o = aOverflowAreas.Overflow(otype);
10349 o = nsDisplayTransform::TransformRect(o, this, refBox);
10350 }
10351
10352 /* If we're the root of the 3d context, then we want to include the
10353 * overflow areas of all the participants. This won't have happened yet as
10354 * the code above set their overflow area to empty. Manually collect these
10355 * overflow areas now.
10356 */
10357 if (Extend3DContext(disp, effects)) {
10358 ComputePreserve3DChildrenOverflow(aOverflowAreas);
10359 }
10360 }
10361 } else {
10362 RemoveProperty(nsIFrame::PreTransformOverflowAreasProperty());
10363 }
10364
10365 /* Revert the size change in case some caller is depending on this. */
10366 SetSize(oldSize, false);
10367
10368 bool anyOverflowChanged;
10369 if (aOverflowAreas != OverflowAreas(bounds, bounds)) {
10370 anyOverflowChanged = SetOverflowAreas(aOverflowAreas);
10371 } else {
10372 anyOverflowChanged = ClearOverflowRects();
10373 }
10374
10375 if (anyOverflowChanged) {
10376 SVGObserverUtils::InvalidateDirectRenderingObservers(this);
10377 if (nsBlockFrame* block = do_QueryFrame(this)) {
10378 // NOTE(emilio): we need to use BeforeReflow::Yes, because we want to
10379 // invalidate in cases where we _used_ to have an overflow marker and no
10380 // longer do.
10381 if (TextOverflow::CanHaveOverflowMarkers(
10382 block, TextOverflow::BeforeReflow::Yes)) {
10383 DiscardDisplayItems(this, [](nsDisplayItem* aItem) {
10384 return aItem->GetType() == DisplayItemType::TYPE_TEXT_OVERFLOW;
10385 });
10386 SchedulePaint(PAINT_DEFAULT);
10387 }
10388 }
10389 }
10390 return anyOverflowChanged;
10391}
10392
10393void nsIFrame::RecomputePerspectiveChildrenOverflow(
10394 const nsIFrame* aStartFrame) {
10395 for (const auto& childList : ChildLists()) {
10396 for (nsIFrame* child : childList.mList) {
10397 if (!child->FrameMaintainsOverflow()) {
10398 continue; // frame does not maintain overflow rects
10399 }
10400 if (child->HasPerspective()) {
10401 OverflowAreas* overflow =
10402 child->GetProperty(nsIFrame::InitialOverflowProperty());
10403 nsRect bounds(nsPoint(0, 0), child->GetSize());
10404 if (overflow) {
10405 OverflowAreas overflowCopy = *overflow;
10406 child->FinishAndStoreOverflow(overflowCopy, bounds.Size());
10407 } else {
10408 OverflowAreas boundsOverflow;
10409 boundsOverflow.SetAllTo(bounds);
10410 child->FinishAndStoreOverflow(boundsOverflow, bounds.Size());
10411 }
10412 } else if (child->GetContent() == aStartFrame->GetContent() ||
10413 child->GetClosestFlattenedTreeAncestorPrimaryFrame() ==
10414 aStartFrame) {
10415 // If a frame is using perspective, then the size used to compute
10416 // perspective-origin is the size of the frame belonging to its parent
10417 // style. We must find any descendant frames using our size
10418 // (by recursing into frames that have the same containing block)
10419 // to update their overflow rects too.
10420 child->RecomputePerspectiveChildrenOverflow(aStartFrame);
10421 }
10422 }
10423 }
10424}
10425
10426void nsIFrame::ComputePreserve3DChildrenOverflow(
10427 OverflowAreas& aOverflowAreas) {
10428 // Find all descendants that participate in the 3d context, and include their
10429 // overflow. These descendants have an empty overflow, so won't have been
10430 // included in the normal overflow calculation. Any children that don't
10431 // participate have normal overflow, so will have been included already.
10432
10433 nsRect childVisual;
10434 nsRect childScrollable;
10435 for (const auto& childList : ChildLists()) {
10436 for (nsIFrame* child : childList.mList) {
10437 // If this child participates in the 3d context, then take the
10438 // pre-transform region (which contains all descendants that aren't
10439 // participating in the 3d context) and transform it into the 3d context
10440 // root coordinate space.
10441 if (child->Combines3DTransformWithAncestors()) {
10442 OverflowAreas childOverflow = child->GetOverflowAreasRelativeToSelf();
10443 TransformReferenceBox refBox(child);
10444 for (const auto otype : AllOverflowTypes()) {
10445 nsRect& o = childOverflow.Overflow(otype);
10446 o = nsDisplayTransform::TransformRect(o, child, refBox);
10447 }
10448
10449 aOverflowAreas.UnionWith(childOverflow);
10450
10451 // If this child also extends the 3d context, then recurse into it
10452 // looking for more participants.
10453 if (child->Extend3DContext()) {
10454 child->ComputePreserve3DChildrenOverflow(aOverflowAreas);
10455 }
10456 }
10457 }
10458 }
10459}
10460
10461bool nsIFrame::ZIndexApplies() const {
10462 return StyleDisplay()->IsPositionedStyle() || IsFlexOrGridItem() ||
10463 IsMenuPopupFrame();
10464}
10465
10466Maybe<int32_t> nsIFrame::ZIndex() const {
10467 if (!ZIndexApplies()) {
10468 return Nothing();
10469 }
10470 const auto& zIndex = StylePosition()->mZIndex;
10471 if (zIndex.IsAuto()) {
10472 return Nothing();
10473 }
10474 return Some(zIndex.AsInteger());
10475}
10476
10477bool nsIFrame::IsScrollAnchor(ScrollAnchorContainer** aOutContainer) {
10478 if (!mInScrollAnchorChain) {
10479 return false;
10480 }
10481
10482 nsIFrame* f = this;
10483
10484 // FIXME(emilio, bug 1629280): We should find a non-null anchor if we have the
10485 // flag set, but bug 1629280 makes it so that we cannot really assert it /
10486 // make this just a `while (true)`, and uncomment the below assertion.
10487 while (auto* container = ScrollAnchorContainer::FindFor(f)) {
10488 // MOZ_ASSERT(f->IsInScrollAnchorChain());
10489 if (nsIFrame* anchor = container->AnchorNode()) {
10490 if (anchor != this) {
10491 return false;
10492 }
10493 if (aOutContainer) {
10494 *aOutContainer = container;
10495 }
10496 return true;
10497 }
10498
10499 f = container->Frame();
10500 }
10501
10502 return false;
10503}
10504
10505bool nsIFrame::IsInScrollAnchorChain() const { return mInScrollAnchorChain; }
10506
10507void nsIFrame::SetInScrollAnchorChain(bool aInChain) {
10508 mInScrollAnchorChain = aInChain;
10509}
10510
10511uint32_t nsIFrame::GetDepthInFrameTree() const {
10512 uint32_t result = 0;
10513 for (nsContainerFrame* ancestor = GetParent(); ancestor;
10514 ancestor = ancestor->GetParent()) {
10515 result++;
10516 }
10517 return result;
10518}
10519
10520/**
10521 * This function takes a frame that is part of a block-in-inline split,
10522 * and _if_ that frame is an anonymous block created by an ib split it
10523 * returns the block's preceding inline. This is needed because the
10524 * split inline's style is the parent of the anonymous block's style.
10525 *
10526 * If aFrame is not an anonymous block, null is returned.
10527 */
10528static nsIFrame* GetIBSplitSiblingForAnonymousBlock(const nsIFrame* aFrame) {
10529 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"
, 10529); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame" ") ("
"Must have a non-null frame!" ")"); do { *((volatile int*)__null
) = 10529; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
10530 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"
, 10531); MOZ_PretendNoReturn(); } } while (0)
10531 "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"
, 10531); MOZ_PretendNoReturn(); } } while (0)
;
10532
10533 if (aFrame->Style()->GetPseudoType() !=
10534 PseudoStyleType::mozBlockInsideInlineWrapper) {
10535 // it's not an anonymous block
10536 return nullptr;
10537 }
10538
10539 // Find the first continuation of the frame. (Ugh. This ends up
10540 // being O(N^2) when it is called O(N) times.)
10541 aFrame = aFrame->FirstContinuation();
10542
10543 /*
10544 * Now look up the nsGkAtoms::IBSplitPrevSibling
10545 * property.
10546 */
10547 nsIFrame* ibSplitSibling =
10548 aFrame->GetProperty(nsIFrame::IBSplitPrevSibling());
10549 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"
, 10549); MOZ_PretendNoReturn(); } } while (0)
;
10550 return ibSplitSibling;
10551}
10552
10553/**
10554 * Get the parent, corrected for the mangled frame tree resulting from
10555 * having a block within an inline. The result only differs from the
10556 * result of |GetParent| when |GetParent| returns an anonymous block
10557 * that was created for an element that was 'display: inline' because
10558 * that element contained a block.
10559 *
10560 * Also skip anonymous scrolled-content parents; inherit directly from the
10561 * outer scroll frame.
10562 *
10563 * Also skip NAC parents if the child frame is NAC.
10564 */
10565static nsIFrame* GetCorrectedParent(const nsIFrame* aFrame) {
10566 nsIFrame* parent = aFrame->GetParent();
10567 if (!parent) {
10568 return nullptr;
10569 }
10570
10571 // For a table caption we want the _inner_ table frame (unless it's anonymous)
10572 // as the style parent.
10573 if (aFrame->IsTableCaption()) {
10574 nsIFrame* innerTable = parent->PrincipalChildList().FirstChild();
10575 if (!innerTable->Style()->IsAnonBox()) {
10576 return innerTable;
10577 }
10578 }
10579
10580 // Table wrappers are always anon boxes; if we're in here for an outer
10581 // table, that actually means its the _inner_ table that wants to
10582 // know its parent. So get the pseudo of the inner in that case.
10583 auto pseudo = aFrame->Style()->GetPseudoType();
10584 if (pseudo == PseudoStyleType::tableWrapper) {
10585 pseudo =
10586 aFrame->PrincipalChildList().FirstChild()->Style()->GetPseudoType();
10587 }
10588
10589 // Prevent a NAC pseudo-element from inheriting from its NAC parent, and
10590 // inherit from the NAC generator element instead.
10591 if (pseudo != PseudoStyleType::NotPseudo) {
10592 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"
, 10592); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFrame->GetContent()"
")"); do { *((volatile int*)__null) = 10592; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10593 Element* element = Element::FromNode(aFrame->GetContent());
10594 // Make sure to avoid doing the fixup for non-element-backed pseudos like
10595 // ::first-line and such.
10596 if (element && !element->IsRootOfNativeAnonymousSubtree() &&
10597 element->GetPseudoElementType() == aFrame->Style()->GetPseudoType()) {
10598 while (parent->GetContent() &&
10599 !parent->GetContent()->IsRootOfNativeAnonymousSubtree()) {
10600 parent = parent->GetInFlowParent();
10601 }
10602 parent = parent->GetInFlowParent();
10603 }
10604 }
10605
10606 return nsIFrame::CorrectStyleParentFrame(parent, pseudo);
10607}
10608
10609/* static */
10610nsIFrame* nsIFrame::CorrectStyleParentFrame(nsIFrame* aProspectiveParent,
10611 PseudoStyleType aChildPseudo) {
10612 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"
, 10612); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aProspectiveParent"
") (" "Must have a prospective parent" ")"); do { *((volatile
int*)__null) = 10612; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
10613
10614 if (aChildPseudo != PseudoStyleType::NotPseudo) {
10615 // Non-inheriting anon boxes have no style parent frame at all.
10616 if (PseudoStyle::IsNonInheritingAnonBox(aChildPseudo)) {
10617 return nullptr;
10618 }
10619
10620 // Other anon boxes are parented to their actual parent already, except
10621 // for non-elements. Those should not be treated as an anon box.
10622 if (PseudoStyle::IsAnonBox(aChildPseudo) &&
10623 !nsCSSAnonBoxes::IsNonElement(aChildPseudo)) {
10624 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"
, 10626); MOZ_PretendNoReturn(); } } while (0)
10625 "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"
, 10626); MOZ_PretendNoReturn(); } } while (0)
10626 "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"
, 10626); MOZ_PretendNoReturn(); } } while (0)
;
10627 return aProspectiveParent;
10628 }
10629 }
10630
10631 // Otherwise, walk up out of all anon boxes. For placeholder frames, walk out
10632 // of all pseudo-elements as well. Otherwise ReparentComputedStyle could
10633 // cause style data to be out of sync with the frame tree.
10634 nsIFrame* parent = aProspectiveParent;
10635 do {
10636 if (parent->HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) {
10637 nsIFrame* sibling = GetIBSplitSiblingForAnonymousBlock(parent);
10638
10639 if (sibling) {
10640 // |parent| was a block in an {ib} split; use the inline as
10641 // |the style parent.
10642 parent = sibling;
10643 }
10644 }
10645
10646 if (!parent->Style()->IsPseudoOrAnonBox()) {
10647 return parent;
10648 }
10649
10650 if (!parent->Style()->IsAnonBox() && aChildPseudo != PseudoStyleType::MAX) {
10651 // nsPlaceholderFrame passes in PseudoStyleType::MAX for
10652 // aChildPseudo (even though that's not a valid pseudo-type) just to
10653 // trigger this behavior of walking up to the nearest non-pseudo
10654 // ancestor.
10655 return parent;
10656 }
10657
10658 parent = parent->GetInFlowParent();
10659 } while (parent);
10660
10661 if (aProspectiveParent->Style()->GetPseudoType() ==
10662 PseudoStyleType::viewportScroll) {
10663 // aProspectiveParent is the scrollframe for a viewport
10664 // and the kids are the anonymous scrollbars
10665 return aProspectiveParent;
10666 }
10667
10668 // We can get here if the root element is absolutely positioned.
10669 // We can't test for this very accurately, but it can only happen
10670 // when the prospective parent is a canvas frame.
10671 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"
, 10672); MOZ_PretendNoReturn(); } } while (0)
10672 "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"
, 10672); MOZ_PretendNoReturn(); } } while (0)
;
10673 return nullptr;
10674}
10675
10676ComputedStyle* nsIFrame::DoGetParentComputedStyle(
10677 nsIFrame** aProviderFrame) const {
10678 *aProviderFrame = nullptr;
10679
10680 // Handle display:contents and the root frame, when there's no parent frame
10681 // to inherit from.
10682 if (MOZ_LIKELY(mContent)(__builtin_expect(!!(mContent), 1))) {
10683 Element* parentElement = mContent->GetFlattenedTreeParentElement();
10684 if (MOZ_LIKELY(parentElement)(__builtin_expect(!!(parentElement), 1))) {
10685 auto pseudo = Style()->GetPseudoType();
10686 if (pseudo == PseudoStyleType::NotPseudo || !mContent->IsElement() ||
10687 (!PseudoStyle::IsAnonBox(pseudo) &&
10688 // Ensure that we don't return the display:contents style
10689 // of the parent content for pseudos that have the same content
10690 // as their primary frame (like -moz-list-bullets do):
10691 IsPrimaryFrame()) ||
10692 /* if next is true then it's really a request for the table frame's
10693 parent context, see nsTable[Outer]Frame::GetParentComputedStyle. */
10694 pseudo == PseudoStyleType::tableWrapper) {
10695 // In some edge cases involving display: contents, we may end up here
10696 // for something that's pending to be reframed. In this case we return
10697 // the wrong style from here (because we've already lost track of it!),
10698 // but it's not a big deal as we're going to be reframed anyway.
10699 if (MOZ_LIKELY(parentElement->HasServoData())(__builtin_expect(!!(parentElement->HasServoData()), 1)) &&
10700 Servo_Element_IsDisplayContents(parentElement)) {
10701 RefPtr<ComputedStyle> style =
10702 ServoStyleSet::ResolveServoStyle(*parentElement);
10703 // NOTE(emilio): we return a weak reference because the element also
10704 // holds the style context alive. This is a bit silly (we could've
10705 // returned a weak ref directly), but it's probably not worth
10706 // optimizing, given this function has just one caller which is rare,
10707 // and this path is rare itself.
10708 return style;
10709 }
10710 }
10711 } else {
10712 if (Style()->GetPseudoType() == PseudoStyleType::NotPseudo) {
10713 // We're a frame for the root. We have no style parent.
10714 return nullptr;
10715 }
10716 }
10717 }
10718
10719 if (!HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
10720 /*
10721 * If this frame is an anonymous block created when an inline with a block
10722 * inside it got split, then the parent style is on its preceding inline. We
10723 * can get to it using GetIBSplitSiblingForAnonymousBlock.
10724 */
10725 if (HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) {
10726 nsIFrame* ibSplitSibling = GetIBSplitSiblingForAnonymousBlock(this);
10727 if (ibSplitSibling) {
10728 return (*aProviderFrame = ibSplitSibling)->Style();
10729 }
10730 }
10731
10732 // If this frame is one of the blocks that split an inline, we must
10733 // return the "special" inline parent, i.e., the parent that this
10734 // frame would have if we didn't mangle the frame structure.
10735 *aProviderFrame = GetCorrectedParent(this);
10736 return *aProviderFrame ? (*aProviderFrame)->Style() : nullptr;
10737 }
10738
10739 // We're an out-of-flow frame. For out-of-flow frames, we must
10740 // resolve underneath the placeholder's parent. The placeholder is
10741 // reached from the first-in-flow.
10742 nsPlaceholderFrame* placeholder = FirstInFlow()->GetPlaceholderFrame();
10743 if (!placeholder) {
10744 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"
, 10744); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "no placeholder frame for out-of-flow frame"
")"); do { *((volatile int*)__null) = 10744; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10745 *aProviderFrame = GetCorrectedParent(this);
10746 return *aProviderFrame ? (*aProviderFrame)->Style() : nullptr;
10747 }
10748 return placeholder->GetParentComputedStyleForOutOfFlow(aProviderFrame);
10749}
10750
10751void nsIFrame::GetLastLeaf(nsIFrame** aFrame) {
10752 if (!aFrame || !*aFrame ||
10753 // Don't enter into native anoymous subtree from the root like <input> or
10754 // <textarea>.
10755 (*aFrame)->ContentIsRootOfNativeAnonymousSubtree()) {
10756 return;
10757 }
10758 for (nsIFrame* maybeLastLeaf = (*aFrame)->PrincipalChildList().LastChild();
10759 maybeLastLeaf;) {
10760 nsIFrame* lastChildNotInSubTree = nullptr;
10761 for (nsIFrame* child = maybeLastLeaf; child;
10762 child = child->GetPrevSibling()) {
10763 // ignore anonymous elements, e.g. mozTableAdd* mozTableRemove*
10764 // see bug 278197 comment #12 #13 for details
10765 if (!child->ContentIsRootOfNativeAnonymousSubtree()) {
10766 lastChildNotInSubTree = child;
10767 break;
10768 }
10769 }
10770 if (!lastChildNotInSubTree) {
10771 return;
10772 }
10773 *aFrame = lastChildNotInSubTree;
10774 maybeLastLeaf = lastChildNotInSubTree->PrincipalChildList().LastChild();
10775 }
10776}
10777
10778void nsIFrame::GetFirstLeaf(nsIFrame** aFrame) {
10779 if (!aFrame || !*aFrame) return;
10780 nsIFrame* child = *aFrame;
10781 while (true) {
10782 child = child->PrincipalChildList().FirstChild();
10783 if (!child) return; // nothing to do
10784 *aFrame = child;
10785 }
10786}
10787
10788bool nsIFrame::IsFocusableDueToScrollFrame() {
10789 if (!IsScrollContainerFrame()) {
10790 if (nsFieldSetFrame* fieldset = do_QueryFrame(this)) {
10791 // TODO: Do we have similar special-cases like this where we can have
10792 // anonymous scrollable boxes hanging off a primary frame?
10793 if (nsIFrame* inner = fieldset->GetInner()) {
10794 return inner->IsFocusableDueToScrollFrame();
10795 }
10796 }
10797 return false;
10798 }
10799 if (!mContent->IsHTMLElement()) {
10800 return false;
10801 }
10802 if (mContent->IsRootOfNativeAnonymousSubtree()) {
10803 return false;
10804 }
10805 if (!mContent->GetParent()) {
10806 return false;
10807 }
10808 if (mContent->AsElement()->HasAttr(nsGkAtoms::tabindex)) {
10809 return false;
10810 }
10811 // Elements with scrollable view are focusable with script & tabbable
10812 // Otherwise you couldn't scroll them with keyboard, which is an accessibility
10813 // issue (e.g. Section 508 rules) However, we don't make them to be focusable
10814 // with the mouse, because the extra focus outlines are considered
10815 // unnecessarily ugly. When clicked on, the selection position within the
10816 // element will be enough to make them keyboard scrollable.
10817 auto* scrollContainer = static_cast<ScrollContainerFrame*>(this);
10818 if (scrollContainer->GetScrollStyles().IsHiddenInBothDirections()) {
10819 return false;
10820 }
10821 if (scrollContainer->GetScrollRange().IsEqualEdges(nsRect())) {
10822 return false;
10823 }
10824 return true;
10825}
10826
10827Focusable nsIFrame::IsFocusable(IsFocusableFlags aFlags) {
10828 // cannot focus content in print preview mode. Only the root can be focused,
10829 // but that's handled elsewhere.
10830 if (PresContext()->Type() == nsPresContext::eContext_PrintPreview) {
10831 return {};
10832 }
10833
10834 if (!mContent || !mContent->IsElement()) {
10835 return {};
10836 }
10837
10838 if (!(aFlags & IsFocusableFlags::IgnoreVisibility) &&
10839 !IsVisibleConsideringAncestors()) {
10840 return {};
10841 }
10842
10843 const StyleUserFocus uf = StyleUI()->UserFocus();
10844 if (uf == StyleUserFocus::None) {
10845 return {};
10846 }
10847 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"
, 10847); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!StyleUI()->IsInert()"
") (" "inert implies -moz-user-focus: none" ")"); do { *((volatile
int*)__null) = 10847; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
10848
10849 const PseudoStyleType pseudo = Style()->GetPseudoType();
10850 if (pseudo == PseudoStyleType::anonymousItem) {
10851 return {};
10852 }
10853
10854 Focusable focusable;
10855 if (auto* xul = nsXULElement::FromNode(mContent)) {
10856 // As a legacy special-case, -moz-user-focus controls focusability and
10857 // tabability of XUL elements in some circumstances (which default to
10858 // -moz-user-focus: ignore).
10859 auto focusability = xul->GetXULFocusability(aFlags);
10860 focusable.mFocusable =
10861 focusability.mForcedFocusable.valueOr(uf == StyleUserFocus::Normal);
10862 if (focusable) {
10863 focusable.mTabIndex = focusability.mForcedTabIndexIfFocusable.valueOr(0);
10864 }
10865 } else {
10866 focusable = mContent->IsFocusableWithoutStyle(aFlags);
10867 }
10868
10869 if (focusable) {
10870 return focusable;
10871 }
10872
10873 // If we're focusing with the mouse we never focus scroll areas.
10874 if (!(aFlags & IsFocusableFlags::WithMouse) &&
10875 IsFocusableDueToScrollFrame()) {
10876 return {true, 0};
10877 }
10878
10879 // FIXME(emilio): some callers rely on somewhat broken return values
10880 // (focusable = false, but non-negative tab-index) from
10881 // IsFocusableWithoutStyle (for image maps in particular).
10882 return focusable;
10883}
10884
10885/**
10886 * @return true if this text frame ends with a newline character which is
10887 * treated as preformatted. It should return false if this is not a text frame.
10888 */
10889bool nsIFrame::HasSignificantTerminalNewline() const { return false; }
10890
10891static StyleVerticalAlignKeyword ConvertSVGDominantBaselineToVerticalAlign(
10892 StyleDominantBaseline aDominantBaseline) {
10893 // Most of these are approximate mappings.
10894 switch (aDominantBaseline) {
10895 case StyleDominantBaseline::Hanging:
10896 case StyleDominantBaseline::TextBeforeEdge:
10897 return StyleVerticalAlignKeyword::TextTop;
10898 case StyleDominantBaseline::TextAfterEdge:
10899 case StyleDominantBaseline::Ideographic:
10900 return StyleVerticalAlignKeyword::TextBottom;
10901 case StyleDominantBaseline::Central:
10902 case StyleDominantBaseline::Middle:
10903 case StyleDominantBaseline::Mathematical:
10904 return StyleVerticalAlignKeyword::Middle;
10905 case StyleDominantBaseline::Auto:
10906 case StyleDominantBaseline::Alphabetic:
10907 return StyleVerticalAlignKeyword::Baseline;
10908 default:
10909 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"
, 10909); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "unexpected aDominantBaseline value"
")"); do { *((volatile int*)__null) = 10909; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10910 return StyleVerticalAlignKeyword::Baseline;
10911 }
10912}
10913
10914Maybe<StyleVerticalAlignKeyword> nsIFrame::VerticalAlignEnum() const {
10915 if (IsInSVGTextSubtree()) {
10916 StyleDominantBaseline dominantBaseline = StyleSVG()->mDominantBaseline;
10917 return Some(ConvertSVGDominantBaselineToVerticalAlign(dominantBaseline));
10918 }
10919
10920 const auto& verticalAlign = StyleDisplay()->mVerticalAlign;
10921 if (verticalAlign.IsKeyword()) {
10922 return Some(verticalAlign.AsKeyword());
10923 }
10924
10925 return Nothing();
10926}
10927
10928void nsIFrame::UpdateStyleOfChildAnonBox(nsIFrame* aChildFrame,
10929 ServoRestyleState& aRestyleState) {
10930#ifdef DEBUG1
10931 nsIFrame* parent = aChildFrame->GetInFlowParent();
10932 if (aChildFrame->IsTableFrame()) {
10933 parent = parent->GetParent();
10934 }
10935 if (parent->IsLineFrame()) {
10936 parent = parent->GetParent();
10937 }
10938 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"
, 10939); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent) == this"
") (" "This should only be used for children!" ")"); do { *(
(volatile int*)__null) = 10939; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
10939 "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"
, 10939); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nsLayoutUtils::FirstContinuationOrIBSplitSibling(parent) == this"
") (" "This should only be used for children!" ")"); do { *(
(volatile int*)__null) = 10939; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
10940#endif // DEBUG
10941 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"
, 10943); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
") (" "What content node is it a frame for?" ")"); do { *((volatile
int*)__null) = 10943; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
10942 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"
, 10943); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
") (" "What content node is it a frame for?" ")"); do { *((volatile
int*)__null) = 10943; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
10943 "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"
, 10943); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!GetContent() || !aChildFrame->GetContent() || aChildFrame->GetContent() == GetContent()"
") (" "What content node is it a frame for?" ")"); do { *((volatile
int*)__null) = 10943; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
10944 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"
, 10945); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetPrevContinuation()"
") (" "Only first continuations should end up here" ")"); do
{ *((volatile int*)__null) = 10945; __attribute__((nomerge))
::abort(); } while (false); } } while (false)
10945 "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"
, 10945); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetPrevContinuation()"
") (" "Only first continuations should end up here" ")"); do
{ *((volatile int*)__null) = 10945; __attribute__((nomerge))
::abort(); } while (false); } } while (false)
;
10946
10947 // We could force the caller to pass in the pseudo, since some callers know it
10948 // statically... But this API is a bit nicer.
10949 auto pseudo = aChildFrame->Style()->GetPseudoType();
10950 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"
, 10950); AnnotateMozCrashReason("MOZ_ASSERT" "(" "PseudoStyle::IsAnonBox(pseudo)"
") (" "Child is not an anon box?" ")"); do { *((volatile int
*)__null) = 10950; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
10951 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"
, 10952); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!PseudoStyle::IsNonInheritingAnonBox(pseudo)"
") (" "Why did the caller bother calling us?" ")"); do { *((
volatile int*)__null) = 10952; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
10952 "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"
, 10952); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!PseudoStyle::IsNonInheritingAnonBox(pseudo)"
") (" "Why did the caller bother calling us?" ")"); do { *((
volatile int*)__null) = 10952; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
10953
10954 // Anon boxes inherit from their parent; that's us.
10955 RefPtr<ComputedStyle> newContext =
10956 aRestyleState.StyleSet().ResolveInheritingAnonymousBoxStyle(pseudo,
10957 Style());
10958
10959 nsChangeHint childHint =
10960 UpdateStyleOfOwnedChildFrame(aChildFrame, newContext, aRestyleState);
10961
10962 // Now that we've updated the style on aChildFrame, check whether it itself
10963 // has anon boxes to deal with.
10964 ServoRestyleState childrenState(*aChildFrame, aRestyleState, childHint,
10965 ServoRestyleState::CanUseHandledHints::Yes);
10966 aChildFrame->UpdateStyleOfOwnedAnonBoxes(childrenState);
10967
10968 // Assuming anon boxes don't have ::backdrop associated with them... if that
10969 // ever changes, we'd need to handle that here, like we do in
10970 // RestyleManager::ProcessPostTraversal
10971
10972 // We do need to handle block pseudo-elements here, though. Especially list
10973 // bullets.
10974 if (nsBlockFrame* block = do_QueryFrame(aChildFrame)) {
10975 block->UpdatePseudoElementStyles(childrenState);
10976 }
10977}
10978
10979/* static */
10980nsChangeHint nsIFrame::UpdateStyleOfOwnedChildFrame(
10981 nsIFrame* aChildFrame, ComputedStyle* aNewComputedStyle,
10982 ServoRestyleState& aRestyleState,
10983 const Maybe<ComputedStyle*>& aContinuationComputedStyle) {
10984 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"
, 10985); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetAdditionalComputedStyle(0)"
") (" "We don't handle additional styles here" ")"); do { *(
(volatile int*)__null) = 10985; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
10985 "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"
, 10985); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aChildFrame->GetAdditionalComputedStyle(0)"
") (" "We don't handle additional styles here" ")"); do { *(
(volatile int*)__null) = 10985; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
10986
10987 // Figure out whether we have an actual change. It's important that we do
10988 // this, for several reasons:
10989 //
10990 // 1) Even if all the child's changes are due to properties it inherits from
10991 // us, it's possible that no one ever asked us for those style structs and
10992 // hence changes to them aren't reflected in the changes handled at all.
10993 //
10994 // 2) Content can change stylesheets that change the styles of pseudos, and
10995 // extensions can add/remove stylesheets that change the styles of
10996 // anonymous boxes directly.
10997 uint32_t equalStructs; // Not used, actually.
10998 nsChangeHint childHint = aChildFrame->Style()->CalcStyleDifference(
10999 *aNewComputedStyle, &equalStructs);
11000
11001 // If aChildFrame is out of flow, then aRestyleState's "changes handled by the
11002 // parent" doesn't apply to it, because it may have some other parent in the
11003 // frame tree.
11004 if (!aChildFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
11005 childHint = NS_RemoveSubsumedHints(
11006 childHint, aRestyleState.ChangesHandledFor(aChildFrame));
11007 }
11008 if (childHint) {
11009 if (childHint & nsChangeHint_ReconstructFrame) {
11010 // If we generate a reconstruct here, remove any non-reconstruct hints we
11011 // may have already generated for this content.
11012 aRestyleState.ChangeList().PopChangesForContent(
11013 aChildFrame->GetContent());
11014 }
11015 aRestyleState.ChangeList().AppendChange(
11016 aChildFrame, aChildFrame->GetContent(), childHint);
11017 }
11018
11019 aChildFrame->SetComputedStyle(aNewComputedStyle);
11020 ComputedStyle* continuationStyle = aContinuationComputedStyle
11021 ? *aContinuationComputedStyle
11022 : aNewComputedStyle;
11023 for (nsIFrame* kid = aChildFrame->GetNextContinuation(); kid;
11024 kid = kid->GetNextContinuation()) {
11025 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"
, 11025); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!kid->GetAdditionalComputedStyle(0)"
")"); do { *((volatile int*)__null) = 11025; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11026 kid->SetComputedStyle(continuationStyle);
11027 }
11028
11029 return childHint;
11030}
11031
11032/* static */
11033void nsIFrame::AddInPopupStateBitToDescendants(nsIFrame* aFrame) {
11034 if (!aFrame->HasAnyStateBits(NS_FRAME_IN_POPUP) &&
11035 aFrame->TrackingVisibility()) {
11036 // Assume all frames in popups are visible.
11037 aFrame->IncApproximateVisibleCount();
11038 }
11039
11040 aFrame->AddStateBits(NS_FRAME_IN_POPUP);
11041
11042 for (const auto& childList : aFrame->CrossDocChildLists()) {
11043 for (nsIFrame* child : childList.mList) {
11044 AddInPopupStateBitToDescendants(child);
11045 }
11046 }
11047}
11048
11049/* static */
11050void nsIFrame::RemoveInPopupStateBitFromDescendants(nsIFrame* aFrame) {
11051 if (!aFrame->HasAnyStateBits(NS_FRAME_IN_POPUP) ||
11052 nsLayoutUtils::IsPopup(aFrame)) {
11053 return;
11054 }
11055
11056 aFrame->RemoveStateBits(NS_FRAME_IN_POPUP);
11057
11058 if (aFrame->TrackingVisibility()) {
11059 // We assume all frames in popups are visible, so this decrement balances
11060 // out the increment in AddInPopupStateBitToDescendants above.
11061 aFrame->DecApproximateVisibleCount();
11062 }
11063 for (const auto& childList : aFrame->CrossDocChildLists()) {
11064 for (nsIFrame* child : childList.mList) {
11065 RemoveInPopupStateBitFromDescendants(child);
11066 }
11067 }
11068}
11069
11070void nsIFrame::SetParent(nsContainerFrame* aParent) {
11071 // If our parent is a wrapper anon box, our new parent should be too. We
11072 // _can_ change parent if our parent is a wrapper anon box, because some
11073 // wrapper anon boxes can have continuations.
11074 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"
, 11075); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->Style()->IsInheritingAnonBox()"
")"); do { *((volatile int*)__null) = 11075; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false); } } while
(false)
11075 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"
, 11075); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent->Style()->IsInheritingAnonBox()"
")"); do { *((volatile int*)__null) = 11075; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false); } } while
(false)
;
11076
11077 // Note that the current mParent may already be destroyed at this point.
11078 mParent = aParent;
11079 MOZ_DIAGNOSTIC_ASSERT(!mParent || PresShell() == mParent->PresShell())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mParent || PresShell() == mParent->PresShell())>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(!mParent || PresShell() == mParent->PresShell()))
), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mParent || PresShell() == mParent->PresShell()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsIFrame.cpp"
, 11079); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!mParent || PresShell() == mParent->PresShell()"
")"); do { *((volatile int*)__null) = 11079; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11080
11081 if (HasAnyStateBits(NS_FRAME_HAS_VIEW | NS_FRAME_HAS_CHILD_WITH_VIEW)) {
11082 for (nsIFrame* f = aParent;
11083 f && !f->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
11084 f = f->GetParent()) {
11085 f->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
11086 }
11087 }
11088
11089 if (HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)) {
11090 for (nsIFrame* f = aParent; f; f = f->GetParent()) {
11091 if (f->HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)) {
11092 break;
11093 }
11094 f->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE);
11095 }
11096 }
11097
11098 if (HasAnyStateBits(NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE)) {
11099 for (nsIFrame* f = aParent; f; f = f->GetParent()) {
11100 if (f->HasAnyStateBits(
11101 NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE)) {
11102 break;
11103 }
11104 f->AddStateBits(NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE);
11105 }
11106 }
11107
11108 if (HasInvalidFrameInSubtree()) {
11109 for (nsIFrame* f = aParent;
11110 f && !f->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT |
11111 NS_FRAME_IS_NONDISPLAY);
11112 f = nsLayoutUtils::GetCrossDocParentFrameInProcess(f)) {
11113 f->AddStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT);
11114 }
11115 }
11116
11117 if (aParent->HasAnyStateBits(NS_FRAME_IN_POPUP)) {
11118 AddInPopupStateBitToDescendants(this);
11119 } else {
11120 RemoveInPopupStateBitFromDescendants(this);
11121 }
11122
11123 // If our new parent only has invalid children, then we just invalidate
11124 // ourselves too. This is probably faster than clearing the flag all
11125 // the way up the frame tree.
11126 if (aParent->HasAnyStateBits(NS_FRAME_ALL_DESCENDANTS_NEED_PAINT)) {
11127 InvalidateFrame();
11128 } else {
11129 SchedulePaint();
11130 }
11131}
11132
11133bool nsIFrame::IsStackingContext(const nsStyleDisplay* aStyleDisplay,
11134 const nsStyleEffects* aStyleEffects) {
11135 // Properties that influence the output of this function should be handled in
11136 // change_bits_for_longhand as well.
11137 if (HasOpacity(aStyleDisplay, aStyleEffects, nullptr)) {
11138 return true;
11139 }
11140 if (IsTransformed()) {
11141 return true;
11142 }
11143 auto willChange = aStyleDisplay->mWillChange.bits;
11144 if (aStyleDisplay->IsContainPaint() || aStyleDisplay->IsContainLayout() ||
11145 willChange & StyleWillChangeBits::CONTAIN) {
11146 if (SupportsContainLayoutAndPaint()) {
11147 return true;
11148 }
11149 }
11150 // strictly speaking, 'perspective' doesn't require visual atomicity,
11151 // but the spec says it acts like the rest of these
11152 if (aStyleDisplay->HasPerspectiveStyle() ||
11153 willChange & StyleWillChangeBits::PERSPECTIVE) {
11154 if (SupportsCSSTransforms()) {
11155 return true;
11156 }
11157 }
11158 if (!StylePosition()->mZIndex.IsAuto() ||
11159 willChange & StyleWillChangeBits::Z_INDEX) {
11160 if (ZIndexApplies()) {
11161 return true;
11162 }
11163 }
11164 return aStyleEffects->mMixBlendMode != StyleBlend::Normal ||
11165 SVGIntegrationUtils::UsingEffectsForFrame(this) ||
11166 aStyleDisplay->IsPositionForcingStackingContext() ||
11167 aStyleDisplay->mIsolation != StyleIsolation::Auto ||
11168 willChange & StyleWillChangeBits::STACKING_CONTEXT_UNCONDITIONAL;
11169}
11170
11171bool nsIFrame::IsStackingContext() {
11172 return IsStackingContext(StyleDisplay(), StyleEffects());
11173}
11174
11175static bool IsFrameScrolledOutOfView(const nsIFrame* aTarget,
11176 const nsRect& aTargetRect,
11177 const nsIFrame* aParent) {
11178 // The ancestor frame we are checking if it clips out aTargetRect relative to
11179 // aTarget.
11180 nsIFrame* clipParent = nullptr;
11181
11182 // find the first scrollable frame or root frame if we are in a fixed pos
11183 // subtree
11184 for (nsIFrame* f = const_cast<nsIFrame*>(aParent); f;
11185 f = nsLayoutUtils::GetCrossDocParentFrameInProcess(f)) {
11186 ScrollContainerFrame* scrollContainerFrame = do_QueryFrame(f);
11187 if (scrollContainerFrame) {
11188 clipParent = f;
11189 break;
11190 }
11191 if (f->StyleDisplay()->mPosition == StylePositionProperty::Fixed &&
11192 nsLayoutUtils::IsReallyFixedPos(f)) {
11193 clipParent = f->GetParent();
11194 break;
11195 }
11196 }
11197
11198 if (!clipParent) {
11199 // Even if we couldn't find the nearest scrollable frame, it might mean we
11200 // are in an out-of-process iframe, try to see if |aTarget| frame is
11201 // scrolled out of view in an scrollable frame in a cross-process ancestor
11202 // document.
11203 return nsLayoutUtils::FrameIsScrolledOutOfViewInCrossProcess(aTarget);
11204 }
11205
11206 nsRect clipRect = clipParent->InkOverflowRectRelativeToSelf();
11207 // We consider that the target is scrolled out if the scrollable (or root)
11208 // frame is empty.
11209 if (clipRect.IsEmpty()) {
11210 return true;
11211 }
11212
11213 nsRect transformedRect = nsLayoutUtils::TransformFrameRectToAncestor(
11214 aTarget, aTargetRect, clipParent);
11215
11216 if (transformedRect.IsEmpty()) {
11217 // If the transformed rect is empty it represents a line or a point that we
11218 // should check is outside the the scrollable rect.
11219 if (transformedRect.x > clipRect.XMost() ||
11220 transformedRect.y > clipRect.YMost() ||
11221 clipRect.x > transformedRect.XMost() ||
11222 clipRect.y > transformedRect.YMost()) {
11223 return true;
11224 }
11225 } else if (!transformedRect.Intersects(clipRect)) {
11226 return true;
11227 }
11228
11229 nsIFrame* parent = clipParent->GetParent();
11230 if (!parent) {
11231 return false;
11232 }
11233
11234 return IsFrameScrolledOutOfView(aTarget, aTargetRect, parent);
11235}
11236
11237bool nsIFrame::IsScrolledOutOfView() const {
11238 nsRect rect = InkOverflowRectRelativeToSelf();
11239 return IsFrameScrolledOutOfView(this, rect, this);
11240}
11241
11242gfx::Matrix nsIFrame::ComputeWidgetTransform() const {
11243 const nsStyleUIReset* uiReset = StyleUIReset();
11244 if (uiReset->mMozWindowTransform.IsNone()) {
11245 return gfx::Matrix();
11246 }
11247
11248 TransformReferenceBox refBox(nullptr, nsRect(nsPoint(), GetSize()));
11249
11250 nsPresContext* presContext = PresContext();
11251 int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
11252 gfx::Matrix4x4 matrix = nsStyleTransformMatrix::ReadTransforms(
11253 uiReset->mMozWindowTransform, refBox, float(appUnitsPerDevPixel));
11254
11255 // Apply the -moz-window-transform-origin translation to the matrix.
11256 const StyleTransformOrigin& origin = uiReset->mWindowTransformOrigin;
11257 Point transformOrigin = nsStyleTransformMatrix::Convert2DPosition(
11258 origin.horizontal, origin.vertical, refBox, appUnitsPerDevPixel);
11259 matrix.ChangeBasis(Point3D(transformOrigin.x, transformOrigin.y, 0));
11260
11261 gfx::Matrix result2d;
11262 if (!matrix.CanDraw2D(&result2d)) {
11263 // FIXME: It would be preferable to reject non-2D transforms at parse time.
11264 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"
, 11266)
11265 "-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"
, 11266)
11266 "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"
, 11266)
;
11267 return gfx::Matrix();
11268 }
11269
11270 return result2d;
11271}
11272
11273void nsIFrame::DoUpdateStyleOfOwnedAnonBoxes(ServoRestyleState& aRestyleState) {
11274 // As a special case, we check for {ib}-split block frames here, rather
11275 // than have an nsInlineFrame::AppendDirectlyOwnedAnonBoxes implementation
11276 // that returns them.
11277 //
11278 // (If we did handle them in AppendDirectlyOwnedAnonBoxes, we would have to
11279 // return *all* of the in-flow {ib}-split block frames, not just the first
11280 // one. For restyling, we really just need the first in flow, and the other
11281 // user of the AppendOwnedAnonBoxes API, AllChildIterator, doesn't need to
11282 // know about them at all, since these block frames never create NAC. So we
11283 // avoid any unncessary hashtable lookups for the {ib}-split frames by calling
11284 // UpdateStyleOfOwnedAnonBoxesForIBSplit directly here.)
11285 if (IsInlineFrame()) {
11286 if (HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) {
11287 static_cast<nsInlineFrame*>(this)->UpdateStyleOfOwnedAnonBoxesForIBSplit(
11288 aRestyleState);
11289 }
11290 return;
11291 }
11292
11293 AutoTArray<OwnedAnonBox, 4> frames;
11294 AppendDirectlyOwnedAnonBoxes(frames);
11295 for (OwnedAnonBox& box : frames) {
11296 if (box.mUpdateStyleFn) {
11297 box.mUpdateStyleFn(this, box.mAnonBoxFrame, aRestyleState);
11298 } else {
11299 UpdateStyleOfChildAnonBox(box.mAnonBoxFrame, aRestyleState);
11300 }
11301 }
11302}
11303
11304/* virtual */
11305void nsIFrame::AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) {
11306 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"
, 11306); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES)"
")"); do { *((volatile int*)__null) = 11306; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11307 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"
, 11309); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Subclasses that have directly owned anonymous boxes should override "
"this method!" ")"); do { *((volatile int*)__null) = 11309; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
11308 "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"
, 11309); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Subclasses that have directly owned anonymous boxes should override "
"this method!" ")"); do { *((volatile int*)__null) = 11309; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
11309 "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"
, 11309); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Subclasses that have directly owned anonymous boxes should override "
"this method!" ")"); do { *((volatile int*)__null) = 11309; __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
11310}
11311
11312void nsIFrame::DoAppendOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) {
11313 size_t i = aResult.Length();
11314 AppendDirectlyOwnedAnonBoxes(aResult);
11315
11316 // After appending the directly owned anonymous boxes of this frame to
11317 // aResult above, we need to check each of them to see if they own
11318 // any anonymous boxes themselves. Note that we keep progressing
11319 // through aResult, looking for additional entries in aResult from these
11320 // subsequent AppendDirectlyOwnedAnonBoxes calls. (Thus we can't
11321 // use a ranged for loop here.)
11322
11323 while (i < aResult.Length()) {
11324 nsIFrame* f = aResult[i].mAnonBoxFrame;
11325 if (f->HasAnyStateBits(NS_FRAME_OWNS_ANON_BOXES)) {
11326 f->AppendDirectlyOwnedAnonBoxes(aResult);
11327 }
11328 ++i;
11329 }
11330}
11331
11332nsIFrame::CaretPosition::CaretPosition() : mContentOffset(0) {}
11333
11334nsIFrame::CaretPosition::~CaretPosition() = default;
11335
11336bool nsIFrame::HasCSSAnimations() {
11337 auto* collection = AnimationCollection<CSSAnimation>::Get(this);
11338 return collection && !collection->mAnimations.IsEmpty();
11339}
11340
11341bool nsIFrame::HasCSSTransitions() {
11342 auto* collection = AnimationCollection<CSSTransition>::Get(this);
11343 return collection && !collection->mAnimations.IsEmpty();
11344}
11345
11346void nsIFrame::AddSizeOfExcludingThisForTree(nsWindowSizes& aSizes) const {
11347 aSizes.mLayoutFramePropertiesSize +=
11348 mProperties.SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
11349
11350 // We don't do this for Gecko because this stuff is stored in the nsPresArena
11351 // and so measured elsewhere.
11352 if (!aSizes.mState.HaveSeenPtr(mComputedStyle)) {
11353 mComputedStyle->AddSizeOfIncludingThis(aSizes,
11354 &aSizes.mLayoutComputedValuesNonDom);
11355 }
11356
11357 // And our additional styles.
11358 int32_t index = 0;
11359 while (auto* extra = GetAdditionalComputedStyle(index++)) {
11360 if (!aSizes.mState.HaveSeenPtr(extra)) {
11361 extra->AddSizeOfIncludingThis(aSizes,
11362 &aSizes.mLayoutComputedValuesNonDom);
11363 }
11364 }
11365
11366 for (const auto& childList : ChildLists()) {
11367 for (const nsIFrame* f : childList.mList) {
11368 f->AddSizeOfExcludingThisForTree(aSizes);
11369 }
11370 }
11371}
11372
11373nsRect nsIFrame::GetCompositorHitTestArea(nsDisplayListBuilder* aBuilder) {
11374 nsRect area;
11375
11376 ScrollContainerFrame* scrollContainerFrame =
11377 nsLayoutUtils::GetScrollContainerFrameFor(this);
11378 if (scrollContainerFrame) {
11379 // If this frame is the scrolled frame of a scroll container frame, then we
11380 // need to pick up the area corresponding to the overflow rect as well.
11381 // Otherwise the parts of the overflow that are not occupied by descendants
11382 // get skipped and the APZ code sends touch events to the content underneath
11383 // instead. See https://bugzilla.mozilla.org/show_bug.cgi?id=1127773#c15.
11384 area = ScrollableOverflowRect();
11385 } else {
11386 area = GetRectRelativeToSelf();
11387 }
11388
11389 if (!area.IsEmpty()) {
11390 return area + aBuilder->ToReferenceFrame(this);
11391 }
11392
11393 return area;
11394}
11395
11396CompositorHitTestInfo nsIFrame::GetCompositorHitTestInfo(
11397 nsDisplayListBuilder* aBuilder) {
11398 CompositorHitTestInfo result = CompositorHitTestInvisibleToHit;
11399
11400 if (aBuilder->IsInsidePointerEventsNoneDoc()) {
11401 // Somewhere up the parent document chain is a subdocument with pointer-
11402 // events:none set on it.
11403 return result;
11404 }
11405 if (!GetParent()) {
11406 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"
, 11406); AnnotateMozCrashReason("MOZ_ASSERT" "(" "IsViewportFrame()"
")"); do { *((volatile int*)__null) = 11406; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11407 // Viewport frames are never event targets, other frames, like canvas
11408 // frames, are the event targets for any regions viewport frames may cover.
11409 return result;
11410 }
11411 if (Style()->PointerEvents() == StylePointerEvents::None) {
11412 return result;
11413 }
11414 if (!StyleVisibility()->IsVisible()) {
11415 return result;
11416 }
11417
11418 // Anything that didn't match the above conditions is visible to hit-testing.
11419 result = CompositorHitTestFlags::eVisibleToHitTest;
11420 SVGUtils::MaskUsage maskUsage = SVGUtils::DetermineMaskUsage(this, false);
11421 if (maskUsage.UsingMaskOrClipPath()) {
11422 // If WebRender is enabled, simple clip-paths can be converted into WR
11423 // clips that WR knows how to hit-test against, so we don't need to mark
11424 // it as an irregular area.
11425 if (!maskUsage.IsSimpleClipShape()) {
11426 result += CompositorHitTestFlags::eIrregularArea;
11427 }
11428 }
11429
11430 if (aBuilder->IsBuildingNonLayerizedScrollbar()) {
11431 // Scrollbars may be painted into a layer below the actual layer they will
11432 // scroll, and therefore wheel events may be dispatched to the outer frame
11433 // instead of the intended scrollframe. To address this, we force a d-t-c
11434 // region on scrollbar frames that won't be placed in their own layer. See
11435 // bug 1213324 for details.
11436 result += CompositorHitTestFlags::eInactiveScrollframe;
11437 } else if (aBuilder->GetAncestorHasApzAwareEventHandler()) {
11438 result += CompositorHitTestFlags::eApzAwareListeners;
11439 } else if (IsRangeFrame()) {
11440 // Range frames handle touch events directly without having a touch listener
11441 // so we need to let APZ know that this area cares about events.
11442 result += CompositorHitTestFlags::eApzAwareListeners;
11443 }
11444
11445 if (aBuilder->IsTouchEventPrefEnabledDoc()) {
11446 // Inherit the touch-action flags from the parent, if there is one. We do
11447 // this because of how the touch-action on a frame combines the touch-action
11448 // from ancestor DOM elements. Refer to the documentation in
11449 // TouchActionHelper.cpp for details; this code is meant to be equivalent to
11450 // that code, but woven into the top-down recursive display list building
11451 // process.
11452 CompositorHitTestInfo inheritedTouchAction =
11453 aBuilder->GetCompositorHitTestInfo() & CompositorHitTestTouchActionMask;
11454
11455 nsIFrame* touchActionFrame = this;
11456 if (ScrollContainerFrame* scrollContainerFrame =
11457 nsLayoutUtils::GetScrollContainerFrameFor(this)) {
11458 ScrollStyles ss = scrollContainerFrame->GetScrollStyles();
11459 if (ss.mVertical != StyleOverflow::Hidden ||
11460 ss.mHorizontal != StyleOverflow::Hidden) {
11461 touchActionFrame = scrollContainerFrame;
11462 // On scrollframes, stop inheriting the pan-x and pan-y flags; instead,
11463 // reset them back to zero to allow panning on the scrollframe unless we
11464 // encounter an element that disables it that's inside the scrollframe.
11465 // This is equivalent to the |considerPanning| variable in
11466 // TouchActionHelper.cpp, but for a top-down traversal.
11467 CompositorHitTestInfo panMask(
11468 CompositorHitTestFlags::eTouchActionPanXDisabled,
11469 CompositorHitTestFlags::eTouchActionPanYDisabled);
11470 inheritedTouchAction -= panMask;
11471 }
11472 }
11473
11474 result += inheritedTouchAction;
11475
11476 const StyleTouchAction touchAction = touchActionFrame->UsedTouchAction();
11477 // The CSS allows the syntax auto | none | [pan-x || pan-y] | manipulation
11478 // so we can eliminate some combinations of things.
11479 if (touchAction == StyleTouchAction::AUTO) {
11480 // nothing to do
11481 } else if (touchAction & StyleTouchAction::MANIPULATION) {
11482 result += CompositorHitTestFlags::eTouchActionAnimatingZoomDisabled;
11483 } else {
11484 // This path handles the cases none | [pan-x || pan-y || pinch-zoom] so
11485 // double-tap is disabled in here.
11486 if (!(touchAction & StyleTouchAction::PINCH_ZOOM)) {
11487 result += CompositorHitTestFlags::eTouchActionPinchZoomDisabled;
11488 }
11489
11490 result += CompositorHitTestFlags::eTouchActionAnimatingZoomDisabled;
11491
11492 if (!(touchAction & StyleTouchAction::PAN_X)) {
11493 result += CompositorHitTestFlags::eTouchActionPanXDisabled;
11494 }
11495 if (!(touchAction & StyleTouchAction::PAN_Y)) {
11496 result += CompositorHitTestFlags::eTouchActionPanYDisabled;
11497 }
11498 if (touchAction & StyleTouchAction::NONE) {
11499 // all the touch-action disabling flags will already have been set above
11500 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"
, 11500); AnnotateMozCrashReason("MOZ_ASSERT" "(" "result.contains(CompositorHitTestTouchActionMask)"
")"); do { *((volatile int*)__null) = 11500; __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11501 }
11502 }
11503 }
11504
11505 const Maybe<ScrollDirection> scrollDirection =
11506 aBuilder->GetCurrentScrollbarDirection();
11507 if (scrollDirection.isSome()) {
11508 if (GetContent()->IsXULElement(nsGkAtoms::thumb)) {
11509 const bool thumbGetsLayer = aBuilder->GetCurrentScrollbarTarget() !=
11510 layers::ScrollableLayerGuid::NULL_SCROLL_ID;
11511 if (thumbGetsLayer) {
11512 result += CompositorHitTestFlags::eScrollbarThumb;
11513 } else {
11514 result += CompositorHitTestFlags::eInactiveScrollframe;
11515 }
11516 }
11517
11518 if (*scrollDirection == ScrollDirection::eVertical) {
11519 result += CompositorHitTestFlags::eScrollbarVertical;
11520 }
11521
11522 // includes the ScrollbarFrame, SliderFrame, anything else that
11523 // might be inside the xul:scrollbar
11524 result += CompositorHitTestFlags::eScrollbar;
11525 }
11526
11527 return result;
11528}
11529
11530// Returns true if we can guarantee there is no visible descendants.
11531static bool HasNoVisibleDescendants(const nsIFrame* aFrame) {
11532 for (const auto& childList : aFrame->ChildLists()) {
11533 for (nsIFrame* f : childList.mList) {
11534 if (nsPlaceholderFrame::GetRealFrameFor(f)
11535 ->IsVisibleOrMayHaveVisibleDescendants()) {
11536 return false;
11537 }
11538 }
11539 }
11540 return true;
11541}
11542
11543void nsIFrame::UpdateVisibleDescendantsState() {
11544 if (StyleVisibility()->IsVisible()) {
11545 // Notify invisible ancestors that a visible descendant exists now.
11546 nsIFrame* ancestor;
11547 for (ancestor = GetInFlowParent();
11548 ancestor && !ancestor->StyleVisibility()->IsVisible();
11549 ancestor = ancestor->GetInFlowParent()) {
11550 ancestor->mAllDescendantsAreInvisible = false;
11551 }
11552 } else {
11553 mAllDescendantsAreInvisible = HasNoVisibleDescendants(this);
11554 }
11555}
11556
11557PhysicalAxes nsIFrame::ShouldApplyOverflowClipping(
11558 const nsStyleDisplay* aDisp) const {
11559 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"
, 11559); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDisp == StyleDisplay()"
") (" "Wrong display struct" ")"); do { *((volatile int*)__null
) = 11559; __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
11560
11561 // 'contain:paint', which we handle as 'overflow:clip' here. Except for
11562 // scrollframes we don't need contain:paint to add any clipping, because
11563 // the scrollable frame will already clip overflowing content, and because
11564 // 'contain:paint' should prevent all means of escaping that clipping
11565 // (e.g. because it forms a fixed-pos containing block).
11566 if (aDisp->IsContainPaint() && !IsScrollContainerFrame() &&
11567 SupportsContainLayoutAndPaint()) {
11568 return kPhysicalAxesBoth;
11569 }
11570
11571 // and overflow:hidden that we should interpret as clip
11572 if (aDisp->mOverflowX == StyleOverflow::Hidden &&
11573 aDisp->mOverflowY == StyleOverflow::Hidden) {
11574 // REVIEW: these are the frame types that set up clipping.
11575 LayoutFrameType type = Type();
11576 switch (type) {
11577 case LayoutFrameType::CheckboxRadio:
11578 case LayoutFrameType::ComboboxControl:
11579 case LayoutFrameType::HTMLButtonControl:
11580 case LayoutFrameType::ListControl:
11581 case LayoutFrameType::Meter:
11582 case LayoutFrameType::Progress:
11583 case LayoutFrameType::Range:
11584 case LayoutFrameType::SubDocument:
11585 case LayoutFrameType::SVGForeignObject:
11586 case LayoutFrameType::SVGInnerSVG:
11587 case LayoutFrameType::SVGOuterSVG:
11588 case LayoutFrameType::SVGSymbol:
11589 case LayoutFrameType::Table:
11590 case LayoutFrameType::TableCell:
11591 return kPhysicalAxesBoth;
11592 case LayoutFrameType::TextInput:
11593 // It has an anonymous scroll container frame that handles any overflow.
11594 return PhysicalAxes();
11595 default:
11596 break;
11597 }
11598 }
11599
11600 // clip overflow:clip, except for nsListControlFrame which is
11601 // a ScrollContainerFrame sub-class.
11602 if (MOZ_UNLIKELY((aDisp->mOverflowX == mozilla::StyleOverflow::Clip ||(__builtin_expect(!!((aDisp->mOverflowX == mozilla::StyleOverflow
::Clip || aDisp->mOverflowY == mozilla::StyleOverflow::Clip
) && !IsListControlFrame()), 0))
11603 aDisp->mOverflowY == mozilla::StyleOverflow::Clip) &&(__builtin_expect(!!((aDisp->mOverflowX == mozilla::StyleOverflow
::Clip || aDisp->mOverflowY == mozilla::StyleOverflow::Clip
) && !IsListControlFrame()), 0))
11604 !IsListControlFrame())(__builtin_expect(!!((aDisp->mOverflowX == mozilla::StyleOverflow
::Clip || aDisp->mOverflowY == mozilla::StyleOverflow::Clip
) && !IsListControlFrame()), 0))
) {
11605 // FIXME: we could use GetViewportScrollStylesOverrideElement() here instead
11606 // if that worked correctly in a print context. (see bug 1654667)
11607 const auto* element = Element::FromNodeOrNull(GetContent());
11608 if (!element ||
11609 !PresContext()->ElementWouldPropagateScrollStyles(*element)) {
11610 PhysicalAxes axes;
11611 if (aDisp->mOverflowX == mozilla::StyleOverflow::Clip) {
11612 axes += PhysicalAxis::Horizontal;
11613 }
11614 if (aDisp->mOverflowY == mozilla::StyleOverflow::Clip) {
11615 axes += PhysicalAxis::Vertical;
11616 }
11617 return axes;
11618 }
11619 }
11620
11621 if (HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
11622 return PhysicalAxes();
11623 }
11624
11625 return IsSuppressedScrollableBlockForPrint() ? kPhysicalAxesBoth
11626 : PhysicalAxes();
11627}
11628
11629bool nsIFrame::IsSuppressedScrollableBlockForPrint() const {
11630 // This condition needs to match the suppressScrollFrame logic in the frame
11631 // constructor.
11632 if (!PresContext()->IsPaginated() || !IsBlockFrame() ||
11633 !StyleDisplay()->IsScrollableOverflow() ||
11634 !StyleDisplay()->IsBlockOutsideStyle() ||
11635 mContent->IsInNativeAnonymousSubtree()) {
11636 return false;
11637 }
11638 if (auto* element = Element::FromNode(mContent);
11639 element && PresContext()->ElementWouldPropagateScrollStyles(*element)) {
11640 return false;
11641 }
11642 return true;
11643}
11644
11645bool nsIFrame::HasUnreflowedContainerQueryAncestor() const {
11646 // If this frame has done the first reflow, its ancestors are guaranteed to
11647 // have as well.
11648 if (!HasAnyStateBits(NS_FRAME_FIRST_REFLOW) ||
11649 !PresContext()->HasContainerQueryFrames()) {
11650 return false;
11651 }
11652 for (nsIFrame* cur = GetInFlowParent(); cur; cur = cur->GetInFlowParent()) {
11653 if (!cur->HasAnyStateBits(NS_FRAME_FIRST_REFLOW)) {
11654 // Done first reflow from this ancestor up, including query containers.
11655 return false;
11656 }
11657 if (cur->StyleDisplay()->IsQueryContainer()) {
11658 return true;
11659 }
11660 }
11661 // No query container from this frame up to root.
11662 return false;
11663}
11664
11665bool nsIFrame::ShouldBreakBefore(
11666 const ReflowInput::BreakType aBreakType) const {
11667 const auto* display = StyleDisplay();
11668 return ShouldBreakBetween(display, display->mBreakBefore, aBreakType);
11669}
11670
11671bool nsIFrame::ShouldBreakAfter(const ReflowInput::BreakType aBreakType) const {
11672 const auto* display = StyleDisplay();
11673 return ShouldBreakBetween(display, display->mBreakAfter, aBreakType);
11674}
11675
11676bool nsIFrame::ShouldBreakBetween(
11677 const nsStyleDisplay* aDisplay, const StyleBreakBetween aBreakBetween,
11678 const ReflowInput::BreakType aBreakType) const {
11679 const bool shouldBreakBetween = [&] {
11680 switch (aBreakBetween) {
11681 case StyleBreakBetween::Always:
11682 return true;
11683 case StyleBreakBetween::Auto:
11684 case StyleBreakBetween::Avoid:
11685 return false;
11686 case StyleBreakBetween::Page:
11687 case StyleBreakBetween::Left:
11688 case StyleBreakBetween::Right:
11689 return aBreakType == ReflowInput::BreakType::Page;
11690 }
11691 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"
, 11691); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Unknown break-between value!" ")"
); do { *((volatile int*)__null) = 11691; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
11692 return false;
11693 }();
11694
11695 if (!shouldBreakBetween) {
11696 return false;
11697 }
11698 if (IsAbsolutelyPositioned(aDisplay)) {
11699 // 'break-before' and 'break-after' properties does not apply to
11700 // absolutely-positioned boxes.
11701 return false;
11702 }
11703 return true;
11704}
11705
11706#ifdef DEBUG1
11707static void GetTagName(nsIFrame* aFrame, nsIContent* aContent, int aResultSize,
11708 char* aResult) {
11709 if (aContent) {
11710 snprintf(aResult, aResultSize, "%s@%p",
11711 nsAtomCString(aContent->NodeInfo()->NameAtom()).get(), aFrame);
11712 } else {
11713 snprintf(aResult, aResultSize, "@%p", aFrame);
11714 }
11715}
11716
11717void nsIFrame::Trace(const char* aMethod, bool aEnter) {
11718 if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)(int(((mozilla::LogModule*)(sFrameLogModule))->Level()) &
(0x1))
) {
11719 char tagbuf[40];
11720 GetTagName(this, mContent, sizeof(tagbuf), tagbuf);
11721 printf_stderr("%s: %s %s", tagbuf, aEnter ? "enter" : "exit", aMethod);
11722 }
11723}
11724
11725void nsIFrame::Trace(const char* aMethod, bool aEnter,
11726 const nsReflowStatus& aStatus) {
11727 if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)(int(((mozilla::LogModule*)(sFrameLogModule))->Level()) &
(0x1))
) {
11728 char tagbuf[40];
11729 GetTagName(this, mContent, sizeof(tagbuf), tagbuf);
11730 printf_stderr("%s: %s %s, status=%scomplete%s", tagbuf,
11731 aEnter ? "enter" : "exit", aMethod,
11732 aStatus.IsIncomplete() ? "not" : "",
11733 (aStatus.NextInFlowNeedsReflow()) ? "+reflow" : "");
11734 }
11735}
11736
11737void nsIFrame::TraceMsg(const char* aFormatString, ...) {
11738 if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)(int(((mozilla::LogModule*)(sFrameLogModule))->Level()) &
(0x1))
) {
11739 // Format arguments into a buffer
11740 char argbuf[200];
11741 va_list ap;
11742 va_start(ap, aFormatString)__builtin_va_start(ap, aFormatString);
11743 VsprintfLiteral(argbuf, aFormatString, ap);
11744 va_end(ap)__builtin_va_end(ap);
11745
11746 char tagbuf[40];
11747 GetTagName(this, mContent, sizeof(tagbuf), tagbuf);
11748 printf_stderr("%s: %s", tagbuf, argbuf);
11749 }
11750}
11751
11752void nsIFrame::VerifyDirtyBitSet(const nsFrameList& aFrameList) {
11753 for (nsIFrame* f : aFrameList) {
11754 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"
, 11754); MOZ_PretendNoReturn(); } } while (0)
;
11755 }
11756}
11757
11758// Validation of SideIsVertical.
11759# define CASE(side, result) \
11760 static_assert(SideIsVertical(side) == result, "SideIsVertical is wrong")
11761CASE(eSideTop, false);
11762CASE(eSideRight, true);
11763CASE(eSideBottom, false);
11764CASE(eSideLeft, true);
11765# undef CASE
11766
11767// Validation of HalfCornerIsX.
11768# define CASE(corner, result) \
11769 static_assert(HalfCornerIsX(corner) == result, "HalfCornerIsX is wrong")
11770CASE(eCornerTopLeftX, true);
11771CASE(eCornerTopLeftY, false);
11772CASE(eCornerTopRightX, true);
11773CASE(eCornerTopRightY, false);
11774CASE(eCornerBottomRightX, true);
11775CASE(eCornerBottomRightY, false);
11776CASE(eCornerBottomLeftX, true);
11777CASE(eCornerBottomLeftY, false);
11778# undef CASE
11779
11780// Validation of HalfToFullCorner.
11781# define CASE(corner, result) \
11782 static_assert(HalfToFullCorner(corner) == result, \
11783 "HalfToFullCorner is " \
11784 "wrong")
11785CASE(eCornerTopLeftX, eCornerTopLeft);
11786CASE(eCornerTopLeftY, eCornerTopLeft);
11787CASE(eCornerTopRightX, eCornerTopRight);
11788CASE(eCornerTopRightY, eCornerTopRight);
11789CASE(eCornerBottomRightX, eCornerBottomRight);
11790CASE(eCornerBottomRightY, eCornerBottomRight);
11791CASE(eCornerBottomLeftX, eCornerBottomLeft);
11792CASE(eCornerBottomLeftY, eCornerBottomLeft);
11793# undef CASE
11794
11795// Validation of FullToHalfCorner.
11796# define CASE(corner, vert, result) \
11797 static_assert(FullToHalfCorner(corner, vert) == result, \
11798 "FullToHalfCorner is wrong")
11799CASE(eCornerTopLeft, false, eCornerTopLeftX);
11800CASE(eCornerTopLeft, true, eCornerTopLeftY);
11801CASE(eCornerTopRight, false, eCornerTopRightX);
11802CASE(eCornerTopRight, true, eCornerTopRightY);
11803CASE(eCornerBottomRight, false, eCornerBottomRightX);
11804CASE(eCornerBottomRight, true, eCornerBottomRightY);
11805CASE(eCornerBottomLeft, false, eCornerBottomLeftX);
11806CASE(eCornerBottomLeft, true, eCornerBottomLeftY);
11807# undef CASE
11808
11809// Validation of SideToFullCorner.
11810# define CASE(side, second, result) \
11811 static_assert(SideToFullCorner(side, second) == result, \
11812 "SideToFullCorner is wrong")
11813CASE(eSideTop, false, eCornerTopLeft);
11814CASE(eSideTop, true, eCornerTopRight);
11815
11816CASE(eSideRight, false, eCornerTopRight);
11817CASE(eSideRight, true, eCornerBottomRight);
11818
11819CASE(eSideBottom, false, eCornerBottomRight);
11820CASE(eSideBottom, true, eCornerBottomLeft);
11821
11822CASE(eSideLeft, false, eCornerBottomLeft);
11823CASE(eSideLeft, true, eCornerTopLeft);
11824# undef CASE
11825
11826// Validation of SideToHalfCorner.
11827# define CASE(side, second, parallel, result) \
11828 static_assert(SideToHalfCorner(side, second, parallel) == result, \
11829 "SideToHalfCorner is wrong")
11830CASE(eSideTop, false, true, eCornerTopLeftX);
11831CASE(eSideTop, false, false, eCornerTopLeftY);
11832CASE(eSideTop, true, true, eCornerTopRightX);
11833CASE(eSideTop, true, false, eCornerTopRightY);
11834
11835CASE(eSideRight, false, false, eCornerTopRightX);
11836CASE(eSideRight, false, true, eCornerTopRightY);
11837CASE(eSideRight, true, false, eCornerBottomRightX);
11838CASE(eSideRight, true, true, eCornerBottomRightY);
11839
11840CASE(eSideBottom, false, true, eCornerBottomRightX);
11841CASE(eSideBottom, false, false, eCornerBottomRightY);
11842CASE(eSideBottom, true, true, eCornerBottomLeftX);
11843CASE(eSideBottom, true, false, eCornerBottomLeftY);
11844
11845CASE(eSideLeft, false, false, eCornerBottomLeftX);
11846CASE(eSideLeft, false, true, eCornerBottomLeftY);
11847CASE(eSideLeft, true, false, eCornerTopLeftX);
11848CASE(eSideLeft, true, true, eCornerTopLeftY);
11849# undef CASE
11850
11851#endif