File: | var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp |
Warning: | line 170, column 5 Value stored to 'result' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | /* rendering object for replaced elements with image data */ |
8 | |
9 | #include "nsImageFrame.h" |
10 | |
11 | #include "TextDrawTarget.h" |
12 | #include "gfx2DGlue.h" |
13 | #include "gfxContext.h" |
14 | #include "gfxUtils.h" |
15 | #include "mozilla/dom/NameSpaceConstants.h" |
16 | #include "mozilla/intl/BidiEmbeddingLevel.h" |
17 | #include "mozilla/ComputedStyle.h" |
18 | #include "mozilla/DebugOnly.h" |
19 | #include "mozilla/Encoding.h" |
20 | #include "mozilla/HTMLEditor.h" |
21 | #include "mozilla/dom/FetchPriority.h" |
22 | #include "mozilla/dom/ImageTracker.h" |
23 | #include "mozilla/gfx/2D.h" |
24 | #include "mozilla/gfx/Helpers.h" |
25 | #include "mozilla/gfx/PathHelpers.h" |
26 | #include "mozilla/dom/GeneratedImageContent.h" |
27 | #include "mozilla/dom/HTMLAreaElement.h" |
28 | #include "mozilla/dom/HTMLImageElement.h" |
29 | #include "mozilla/dom/ReferrerInfo.h" |
30 | #include "mozilla/dom/ResponsiveImageSelector.h" |
31 | #include "mozilla/dom/LargestContentfulPaint.h" |
32 | #include "mozilla/image/WebRenderImageProvider.h" |
33 | #include "mozilla/layers/RenderRootStateManager.h" |
34 | #include "mozilla/layers/WebRenderLayerManager.h" |
35 | #include "mozilla/MouseEvents.h" |
36 | #include "mozilla/PresShell.h" |
37 | #include "mozilla/PresShellInlines.h" |
38 | #include "mozilla/StaticPrefs_browser.h" |
39 | #include "mozilla/StaticPrefs_image.h" |
40 | #include "mozilla/StaticPrefs_layout.h" |
41 | #include "mozilla/SVGImageContext.h" |
42 | #include "mozilla/Unused.h" |
43 | |
44 | #include "nsCOMPtr.h" |
45 | #include "nsFontMetrics.h" |
46 | #include "nsIFrameInlines.h" |
47 | #include "nsIImageLoadingContent.h" |
48 | #include "nsImageLoadingContent.h" |
49 | #include "nsImageRenderer.h" |
50 | #include "nsObjectLoadingContent.h" |
51 | #include "nsString.h" |
52 | #include "nsPrintfCString.h" |
53 | #include "nsPresContext.h" |
54 | #include "nsGkAtoms.h" |
55 | #include "mozilla/dom/Document.h" |
56 | #include "nsContentUtils.h" |
57 | #include "nsCSSAnonBoxes.h" |
58 | #include "nsStyleConsts.h" |
59 | #include "nsStyleUtil.h" |
60 | #include "nsTransform2D.h" |
61 | #include "nsImageMap.h" |
62 | #include "nsILoadGroup.h" |
63 | #include "nsNetUtil.h" |
64 | #include "nsNetCID.h" |
65 | #include "nsCSSRendering.h" |
66 | #include "nsNameSpaceManager.h" |
67 | #include <algorithm> |
68 | #ifdef ACCESSIBILITY1 |
69 | # include "nsAccessibilityService.h" |
70 | #endif |
71 | #include "nsLayoutUtils.h" |
72 | #include "nsDisplayList.h" |
73 | #include "nsIContent.h" |
74 | #include "mozilla/dom/Selection.h" |
75 | #include "nsIURIMutator.h" |
76 | |
77 | #include "imgIContainer.h" |
78 | #include "imgLoader.h" |
79 | #include "imgRequestProxy.h" |
80 | |
81 | #include "nsCSSFrameConstructor.h" |
82 | #include "nsRange.h" |
83 | |
84 | #include "nsError.h" |
85 | #include "nsBidiUtils.h" |
86 | #include "nsBidiPresUtils.h" |
87 | |
88 | #include "gfxRect.h" |
89 | #include "ImageRegion.h" |
90 | #include "ImageContainer.h" |
91 | #include "mozilla/ServoStyleSet.h" |
92 | #include "nsBlockFrame.h" |
93 | #include "nsStyleStructInlines.h" |
94 | |
95 | #include "mozilla/Preferences.h" |
96 | |
97 | #include "mozilla/dom/Link.h" |
98 | #include "mozilla/dom/HTMLAnchorElement.h" |
99 | #include "mozilla/dom/BrowserChild.h" |
100 | |
101 | using namespace mozilla; |
102 | using namespace mozilla::dom; |
103 | using namespace mozilla::gfx; |
104 | using namespace mozilla::image; |
105 | using namespace mozilla::layers; |
106 | |
107 | using mozilla::layout::TextDrawTarget; |
108 | |
109 | class nsDisplayGradient final : public nsPaintedDisplayItem { |
110 | public: |
111 | nsDisplayGradient(nsDisplayListBuilder* aBuilder, nsImageFrame* aFrame) |
112 | : nsPaintedDisplayItem(aBuilder, aFrame) { |
113 | MOZ_COUNT_CTOR(nsDisplayGradient)do { static_assert(std::is_class_v<nsDisplayGradient>, "Token '" "nsDisplayGradient" "' is not a class type."); static_assert (!std::is_base_of<nsISupports, nsDisplayGradient>::value , "nsISupports classes don't need to call MOZ_COUNT_CTOR or " "MOZ_COUNT_DTOR");; NS_LogCtor((void*)this, "nsDisplayGradient" , sizeof(*this)); } while (0); |
114 | } |
115 | ~nsDisplayGradient() final { MOZ_COUNT_DTOR(nsDisplayGradient)do { static_assert(std::is_class_v<nsDisplayGradient>, "Token '" "nsDisplayGradient" "' is not a class type."); static_assert (!std::is_base_of<nsISupports, nsDisplayGradient>::value , "nsISupports classes don't need to call MOZ_COUNT_CTOR or " "MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "nsDisplayGradient" , sizeof(*this)); } while (0); } |
116 | |
117 | nsRect GetBounds(bool* aSnap) const { |
118 | *aSnap = true; |
119 | return Frame()->GetContentRectRelativeToSelf() + ToReferenceFrame(); |
120 | } |
121 | |
122 | nsRect GetBounds(nsDisplayListBuilder*, bool* aSnap) const final { |
123 | return GetBounds(aSnap); |
124 | } |
125 | |
126 | void Paint(nsDisplayListBuilder*, gfxContext* aCtx) final; |
127 | |
128 | bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder&, |
129 | mozilla::wr::IpcResourceUpdateQueue&, |
130 | const StackingContextHelper&, |
131 | mozilla::layers::RenderRootStateManager*, |
132 | nsDisplayListBuilder*) final; |
133 | |
134 | NS_DISPLAY_DECL_NAME("Gradient", TYPE_GRADIENT)const char* Name() const override { return "Gradient"; } constexpr static DisplayItemType ItemType() { return DisplayItemType:: TYPE_GRADIENT; } private: void* operator new(size_t aSize, nsDisplayListBuilder * aBuilder) { return aBuilder->Allocate(aSize, DisplayItemType ::TYPE_GRADIENT); } template <typename T, typename F, typename ... Args> friend T* mozilla::MakeDisplayItemWithIndex( nsDisplayListBuilder * aBuilder, F* aFrame, const uint16_t aIndex, Args&&... aArgs); public: |
135 | }; |
136 | |
137 | void nsDisplayGradient::Paint(nsDisplayListBuilder* aBuilder, |
138 | gfxContext* aCtx) { |
139 | auto* frame = static_cast<nsImageFrame*>(Frame()); |
140 | nsImageRenderer imageRenderer(frame, frame->GetImageFromStyle(), |
141 | aBuilder->GetImageRendererFlags()); |
142 | nsSize size = frame->GetSize(); |
143 | imageRenderer.SetPreferredSize({}, size); |
144 | |
145 | ImgDrawResult result; |
146 | if (!imageRenderer.PrepareImage()) { |
147 | result = imageRenderer.PrepareResult(); |
148 | } else { |
149 | nsRect dest(ToReferenceFrame(), size); |
150 | result = imageRenderer.DrawLayer( |
151 | frame->PresContext(), *aCtx, dest, dest, dest.TopLeft(), |
152 | GetPaintRect(aBuilder, aCtx), dest.Size(), /* aOpacity = */ 1.0f); |
153 | } |
154 | Unused << result; |
155 | } |
156 | |
157 | bool nsDisplayGradient::CreateWebRenderCommands( |
158 | wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources, |
159 | const StackingContextHelper& aSc, |
160 | mozilla::layers::RenderRootStateManager* aManager, |
161 | nsDisplayListBuilder* aDisplayListBuilder) { |
162 | auto* frame = static_cast<nsImageFrame*>(Frame()); |
163 | nsImageRenderer imageRenderer(frame, frame->GetImageFromStyle(), |
164 | aDisplayListBuilder->GetImageRendererFlags()); |
165 | nsSize size = frame->GetSize(); |
166 | imageRenderer.SetPreferredSize({}, size); |
167 | |
168 | ImgDrawResult result; |
169 | if (!imageRenderer.PrepareImage()) { |
170 | result = imageRenderer.PrepareResult(); |
Value stored to 'result' is never read | |
171 | } else { |
172 | nsRect dest(ToReferenceFrame(), size); |
173 | result = imageRenderer.BuildWebRenderDisplayItemsForLayer( |
174 | frame->PresContext(), aBuilder, aResources, aSc, aManager, this, dest, |
175 | dest, dest.TopLeft(), dest, dest.Size(), |
176 | /* aOpacity = */ 1.0f); |
177 | if (result == ImgDrawResult::NOT_SUPPORTED) { |
178 | return false; |
179 | } |
180 | } |
181 | return true; |
182 | } |
183 | |
184 | // sizes (pixels) for image icon, padding and border frame |
185 | #define ICON_SIZE(16) (16) |
186 | #define ICON_PADDING(3) (3) |
187 | #define ALT_BORDER_WIDTH(1) (1) |
188 | |
189 | // Default alignment value (so we can tell an unset value from a set value) |
190 | #define ALIGN_UNSETuint8_t(-1) uint8_t(-1) |
191 | |
192 | class BrokenImageIcon final : public imgINotificationObserver { |
193 | // private class that wraps the data and logic needed for |
194 | // broken image and loading image icons |
195 | public: |
196 | explicit BrokenImageIcon(const nsImageFrame& aFrame); |
197 | static void Shutdown(); |
198 | |
199 | NS_DECL_ISUPPORTSpublic: virtual nsresult QueryInterface(const nsIID& aIID , void** aInstancePtr) override; virtual MozExternalRefCountType AddRef(void) override; virtual MozExternalRefCountType Release (void) override; using HasThreadSafeRefCnt = std::false_type; protected: nsAutoRefCnt mRefCnt; nsAutoOwningThread _mOwningThread ; public: |
200 | NS_DECL_IMGINOTIFICATIONOBSERVERvirtual void Notify(imgIRequest *aProxy, int32_t aType, const nsIntRect * aRect) override; |
201 | |
202 | static imgRequestProxy* GetImage(nsImageFrame* aFrame) { |
203 | return Get(*aFrame).mImage.get(); |
204 | } |
205 | |
206 | static void AddObserver(nsImageFrame* aFrame) { |
207 | auto& instance = Get(*aFrame); |
208 | MOZ_ASSERT(!instance.mObservers.Contains(aFrame),do { static_assert( mozilla::detail::AssertionConditionType< decltype(!instance.mObservers.Contains(aFrame))>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(!instance.mObservers.Contains(aFrame)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!instance.mObservers.Contains(aFrame)" " (" "Observer shouldn't aleady be in array" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 209); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!instance.mObservers.Contains(aFrame)" ") (" "Observer shouldn't aleady be in array" ")"); do { *(( volatile int*)__null) = 209; __attribute__((nomerge)) ::abort (); } while (false); } } while (false) |
209 | "Observer shouldn't aleady be in array")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!instance.mObservers.Contains(aFrame))>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(!instance.mObservers.Contains(aFrame)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!instance.mObservers.Contains(aFrame)" " (" "Observer shouldn't aleady be in array" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 209); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!instance.mObservers.Contains(aFrame)" ") (" "Observer shouldn't aleady be in array" ")"); do { *(( volatile int*)__null) = 209; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
210 | instance.mObservers.AppendElement(aFrame); |
211 | } |
212 | |
213 | static void RemoveObserver(nsImageFrame* aFrame) { |
214 | auto& instance = Get(*aFrame); |
215 | DebugOnly<bool> didRemove = instance.mObservers.RemoveElement(aFrame); |
216 | MOZ_ASSERT(didRemove, "Observer not in array")do { static_assert( mozilla::detail::AssertionConditionType< decltype(didRemove)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(didRemove))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("didRemove" " (" "Observer not in array" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 216); AnnotateMozCrashReason("MOZ_ASSERT" "(" "didRemove" ") (" "Observer not in array" ")"); do { *((volatile int*)__null) = 216; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
217 | } |
218 | |
219 | private: |
220 | static BrokenImageIcon& Get(const nsImageFrame& aFrame) { |
221 | if (!gSingleton) { |
222 | gSingleton = new BrokenImageIcon(aFrame); |
223 | } |
224 | return *gSingleton; |
225 | } |
226 | |
227 | ~BrokenImageIcon() = default; |
228 | |
229 | nsTObserverArray<nsImageFrame*> mObservers; |
230 | RefPtr<imgRequestProxy> mImage; |
231 | |
232 | static StaticRefPtr<BrokenImageIcon> gSingleton; |
233 | }; |
234 | |
235 | StaticRefPtr<BrokenImageIcon> BrokenImageIcon::gSingleton; |
236 | |
237 | NS_IMPL_ISUPPORTS(BrokenImageIcon, imgINotificationObserver)MozExternalRefCountType BrokenImageIcon::AddRef(void) { static_assert (!std::is_destructible_v<BrokenImageIcon>, "Reference-counted class " "BrokenImageIcon" " should not have a public destructor. " "Make this class's destructor non-public" ); do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 237); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { *((volatile int*)__null) = 237; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("BrokenImageIcon" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("BrokenImageIcon" != nullptr ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "\"BrokenImageIcon\" != nullptr" " (" "Must specify a name" ")" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 237); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"BrokenImageIcon\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 237; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("BrokenImageIcon" " not thread-safe"); nsrefcnt count = ++mRefCnt; NS_LogAddRef((this), (count), ("BrokenImageIcon" ), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType BrokenImageIcon::Release(void) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(int32_t(mRefCnt) > 0))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 237); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { *((volatile int*)__null) = 237 ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("BrokenImageIcon" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("BrokenImageIcon" != nullptr ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "\"BrokenImageIcon\" != nullptr" " (" "Must specify a name" ")" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 237); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"BrokenImageIcon\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 237; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("BrokenImageIcon" " not thread-safe"); const char* const nametmp = "BrokenImageIcon"; nsrefcnt count = -- mRefCnt; NS_LogRelease((this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count ; } nsresult BrokenImageIcon::QueryInterface(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak (NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 237); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<BrokenImageIcon, imgINotificationObserver >, int32_t( reinterpret_cast<char*>(static_cast<imgINotificationObserver *>((BrokenImageIcon*)0x1000)) - reinterpret_cast<char*> ((BrokenImageIcon*)0x1000))}, {&mozilla::detail::kImplementedIID <BrokenImageIcon, nsISupports>, int32_t(reinterpret_cast <char*>(static_cast<nsISupports*>( static_cast< imgINotificationObserver*>((BrokenImageIcon*)0x1000))) - reinterpret_cast <char*>((BrokenImageIcon*)0x1000))}, { nullptr, 0 } } ; static_assert((sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface" ); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID , aInstancePtr, table); return rv; } |
238 | |
239 | BrokenImageIcon::BrokenImageIcon(const nsImageFrame& aFrame) { |
240 | constexpr auto brokenSrc = u"resource://gre-resources/broken-image.png"_ns; |
241 | nsCOMPtr<nsIURI> realURI; |
242 | NS_NewURI(getter_AddRefs(realURI), brokenSrc); |
243 | |
244 | MOZ_ASSERT(realURI, "how?")do { static_assert( mozilla::detail::AssertionConditionType< decltype(realURI)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(realURI))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("realURI" " (" "how?" ")" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 244); AnnotateMozCrashReason("MOZ_ASSERT" "(" "realURI" ") (" "how?" ")"); do { *((volatile int*)__null) = 244; __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false); |
245 | if (NS_WARN_IF(!realURI)NS_warn_if_impl(!realURI, "!realURI", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 245)) { |
246 | return; |
247 | } |
248 | |
249 | nsPresContext* pc = aFrame.PresContext(); |
250 | Document* doc = pc->Document(); |
251 | RefPtr<imgLoader> il = nsContentUtils::GetImgLoaderForDocument(doc); |
252 | |
253 | nsCOMPtr<nsILoadGroup> loadGroup = doc->GetDocumentLoadGroup(); |
254 | |
255 | // For icon loads, we don't need to merge with the loadgroup flags |
256 | const nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL; |
257 | const nsContentPolicyType contentPolicyType = |
258 | nsIContentPolicy::TYPE_INTERNAL_IMAGE; |
259 | |
260 | nsresult rv = |
261 | il->LoadImage(realURI, /* icon URI */ |
262 | nullptr, /* initial document URI; this is only |
263 | relevant for cookies, so does not |
264 | apply to icons. */ |
265 | nullptr, /* referrer (not relevant for icons) */ |
266 | nullptr, /* principal (not relevant for icons) */ |
267 | 0, loadGroup, this, nullptr, /* No context */ |
268 | nullptr, /* Not associated with any particular document */ |
269 | loadFlags, nullptr, contentPolicyType, u""_ns, |
270 | false, /* aUseUrgentStartForChannel */ |
271 | false, /* aLinkPreload */ |
272 | 0, FetchPriority::Auto, getter_AddRefs(mImage)); |
273 | Unused << NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv )), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 273); |
274 | } |
275 | |
276 | void BrokenImageIcon::Shutdown() { |
277 | if (!gSingleton) { |
278 | return; |
279 | } |
280 | if (gSingleton->mImage) { |
281 | gSingleton->mImage->CancelAndForgetObserver(NS_ERROR_FAILURE); |
282 | gSingleton->mImage = nullptr; |
283 | } |
284 | gSingleton = nullptr; |
285 | } |
286 | |
287 | void BrokenImageIcon::Notify(imgIRequest* aRequest, int32_t aType, |
288 | const nsIntRect* aData) { |
289 | MOZ_ASSERT(aRequest)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aRequest)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aRequest))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aRequest", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 289); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRequest" ")" ); do { *((volatile int*)__null) = 289; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
290 | |
291 | if (aType != imgINotificationObserver::LOAD_COMPLETE && |
292 | aType != imgINotificationObserver::FRAME_UPDATE) { |
293 | return; |
294 | } |
295 | |
296 | if (aType == imgINotificationObserver::LOAD_COMPLETE) { |
297 | nsCOMPtr<imgIContainer> image; |
298 | aRequest->GetImage(getter_AddRefs(image)); |
299 | if (!image) { |
300 | return; |
301 | } |
302 | |
303 | // Retrieve the image's intrinsic size. |
304 | int32_t width = 0; |
305 | int32_t height = 0; |
306 | image->GetWidth(&width); |
307 | image->GetHeight(&height); |
308 | |
309 | // Request a decode at that size. |
310 | image->RequestDecodeForSize(IntSize(width, height), |
311 | imgIContainer::DECODE_FLAGS_DEFAULT | |
312 | imgIContainer::FLAG_HIGH_QUALITY_SCALING); |
313 | } |
314 | |
315 | for (nsImageFrame* frame : mObservers.ForwardRange()) { |
316 | frame->InvalidateFrame(); |
317 | } |
318 | } |
319 | |
320 | // test if the width and height are fixed, looking at the style data |
321 | // This is used by nsImageFrame::ImageFrameTypeFor and should not be used for |
322 | // layout decisions. |
323 | static bool HaveSpecifiedSize(const nsStylePosition* aStylePosition) { |
324 | // check the width and height values in the reflow input's style struct |
325 | // - if width and height are specified as either coord or percentage, then |
326 | // the size of the image frame is constrained |
327 | return aStylePosition->mWidth.IsLengthPercentage() && |
328 | aStylePosition->mHeight.IsLengthPercentage(); |
329 | } |
330 | |
331 | template <typename SizeOrMaxSize> |
332 | static bool DependsOnIntrinsicSize(const SizeOrMaxSize& aMinOrMaxSize) { |
333 | auto length = nsIFrame::ToExtremumLength(aMinOrMaxSize); |
334 | if (!length) { |
335 | return false; |
336 | } |
337 | switch (*length) { |
338 | case nsIFrame::ExtremumLength::MinContent: |
339 | case nsIFrame::ExtremumLength::MaxContent: |
340 | case nsIFrame::ExtremumLength::FitContent: |
341 | case nsIFrame::ExtremumLength::FitContentFunction: |
342 | return true; |
343 | case nsIFrame::ExtremumLength::MozAvailable: |
344 | return false; |
345 | } |
346 | MOZ_ASSERT_UNREACHABLE("Unknown sizing keyword?")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 sizing keyword?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 346); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "Unknown sizing keyword?" ")"); do { *((volatile int*)__null) = 346; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
347 | return false; |
348 | } |
349 | |
350 | // Decide whether we can optimize away reflows that result from the |
351 | // image's intrinsic size changing. |
352 | static bool SizeDependsOnIntrinsicSize(const ReflowInput& aReflowInput) { |
353 | const auto& position = *aReflowInput.mStylePosition; |
354 | WritingMode wm = aReflowInput.GetWritingMode(); |
355 | // Don't try to make this optimization when an image has percentages |
356 | // in its 'width' or 'height'. The percentages might be treated like |
357 | // auto (especially for intrinsic width calculations and for heights). |
358 | // |
359 | // min-width: min-content and such can also affect our intrinsic size. |
360 | // but note that those keywords on the block axis behave like auto, so we |
361 | // don't need to check them. |
362 | // |
363 | // Flex item's min-[width|height]:auto resolution depends on intrinsic size. |
364 | return !position.mHeight.ConvertsToLength() || |
365 | !position.mWidth.ConvertsToLength() || |
366 | DependsOnIntrinsicSize(position.MinISize(wm)) || |
367 | DependsOnIntrinsicSize(position.MaxISize(wm)) || |
368 | aReflowInput.mFrame->IsFlexItem(); |
369 | } |
370 | |
371 | nsIFrame* NS_NewImageFrame(PresShell* aPresShell, ComputedStyle* aStyle) { |
372 | return new (aPresShell) nsImageFrame(aStyle, aPresShell->GetPresContext(), |
373 | nsImageFrame::Kind::ImageLoadingContent); |
374 | } |
375 | |
376 | nsIFrame* NS_NewXULImageFrame(PresShell* aPresShell, ComputedStyle* aStyle) { |
377 | return new (aPresShell) nsImageFrame(aStyle, aPresShell->GetPresContext(), |
378 | nsImageFrame::Kind::XULImage); |
379 | } |
380 | |
381 | nsIFrame* NS_NewImageFrameForContentProperty(PresShell* aPresShell, |
382 | ComputedStyle* aStyle) { |
383 | return new (aPresShell) nsImageFrame(aStyle, aPresShell->GetPresContext(), |
384 | nsImageFrame::Kind::ContentProperty); |
385 | } |
386 | |
387 | nsIFrame* NS_NewImageFrameForGeneratedContentIndex(PresShell* aPresShell, |
388 | ComputedStyle* aStyle) { |
389 | return new (aPresShell) |
390 | nsImageFrame(aStyle, aPresShell->GetPresContext(), |
391 | nsImageFrame::Kind::ContentPropertyAtIndex); |
392 | } |
393 | |
394 | nsIFrame* NS_NewImageFrameForListStyleImage(PresShell* aPresShell, |
395 | ComputedStyle* aStyle) { |
396 | return new (aPresShell) nsImageFrame(aStyle, aPresShell->GetPresContext(), |
397 | nsImageFrame::Kind::ListStyleImage); |
398 | } |
399 | |
400 | bool nsImageFrame::ShouldShowBrokenImageIcon() const { |
401 | // NOTE(emilio, https://github.com/w3c/csswg-drafts/issues/2832): WebKit and |
402 | // Blink behave differently here for content: url(..), for now adapt to |
403 | // Blink's behavior. |
404 | if (mKind != Kind::ImageLoadingContent) { |
405 | return false; |
406 | } |
407 | |
408 | if (!StaticPrefs::browser_display_show_image_placeholders()) { |
409 | return false; |
410 | } |
411 | |
412 | // <img alt=""> is special, and it shouldn't draw the broken image icon, |
413 | // unlike the no-alt attribute or non-empty-alt-attribute case. |
414 | if (auto* image = HTMLImageElement::FromNode(mContent)) { |
415 | const nsAttrValue* alt = image->GetParsedAttr(nsGkAtoms::alt); |
416 | if (alt && alt->IsEmptyString()) { |
417 | return false; |
418 | } |
419 | } |
420 | |
421 | // check for broken images. valid null images (eg. img src="") are |
422 | // not considered broken because they have no image requests |
423 | if (nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest()) { |
424 | uint32_t imageStatus; |
425 | return NS_SUCCEEDED(currentRequest->GetImageStatus(&imageStatus))((bool)(__builtin_expect(!!(!NS_FAILED_impl(currentRequest-> GetImageStatus(&imageStatus))), 1))) && |
426 | (imageStatus & imgIRequest::STATUS_ERROR); |
427 | } |
428 | |
429 | nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent); |
430 | MOZ_ASSERT(imageLoader)do { static_assert( mozilla::detail::AssertionConditionType< decltype(imageLoader)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(imageLoader))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("imageLoader", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 430); AnnotateMozCrashReason("MOZ_ASSERT" "(" "imageLoader" ")"); do { *((volatile int*)__null) = 430; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
431 | // Show the broken image icon only if we've tried to perform a load at all |
432 | // (that is, if we have a current uri). |
433 | nsCOMPtr<nsIURI> currentURI = imageLoader->GetCurrentURI(); |
434 | return !!currentURI; |
435 | } |
436 | |
437 | nsImageFrame* nsImageFrame::CreateContinuingFrame( |
438 | mozilla::PresShell* aPresShell, ComputedStyle* aStyle) const { |
439 | return new (aPresShell) |
440 | nsImageFrame(aStyle, aPresShell->GetPresContext(), mKind); |
441 | } |
442 | |
443 | NS_IMPL_FRAMEARENA_HELPERS(nsImageFrame)void* nsImageFrame ::operator new(size_t sz, mozilla::PresShell * aShell) { return aShell->AllocateFrame(nsQueryFrame::nsImageFrame_id , sz); } |
444 | |
445 | nsImageFrame::nsImageFrame(ComputedStyle* aStyle, nsPresContext* aPresContext, |
446 | ClassID aID, Kind aKind) |
447 | : nsAtomicContainerFrame(aStyle, aPresContext, aID), |
448 | mIntrinsicSize(0, 0), |
449 | mKind(aKind) { |
450 | EnableVisibilityTracking(); |
451 | } |
452 | |
453 | nsImageFrame::~nsImageFrame() = default; |
454 | |
455 | NS_QUERYFRAME_HEAD(nsImageFrame)void* nsImageFrame ::QueryFrame(FrameIID id) const { switch ( id) { |
456 | NS_QUERYFRAME_ENTRY(nsImageFrame)case nsImageFrame ::kFrameIID: { static_assert( std::is_same_v <nsImageFrame, nsImageFrame ::Has_NS_DECL_QUERYFRAME_TARGET >, "nsImageFrame" " must declare itself as a queryframe target" ); return const_cast<nsImageFrame*>(static_cast<const nsImageFrame*>(this)); } |
457 | NS_QUERYFRAME_TAIL_INHERITING(nsAtomicContainerFrame)default: break; } return nsAtomicContainerFrame ::QueryFrame( id); } |
458 | |
459 | #ifdef ACCESSIBILITY1 |
460 | a11y::AccType nsImageFrame::AccessibleType() { |
461 | if (mKind == Kind::ListStyleImage) { |
462 | // This is an HTMLListBulletAccessible. |
463 | return a11y::eNoType; |
464 | } |
465 | |
466 | // Don't use GetImageMap() to avoid reentrancy into accessibility. |
467 | if (HasImageMap()) { |
468 | return a11y::eHTMLImageMapType; |
469 | } |
470 | |
471 | return a11y::eImageType; |
472 | } |
473 | #endif |
474 | |
475 | void nsImageFrame::DisconnectMap() { |
476 | if (!mImageMap) { |
477 | return; |
478 | } |
479 | |
480 | mImageMap->Destroy(); |
481 | mImageMap = nullptr; |
482 | |
483 | #ifdef ACCESSIBILITY1 |
484 | if (nsAccessibilityService* accService = GetAccService()) { |
485 | accService->RecreateAccessible(PresShell(), mContent); |
486 | } |
487 | #endif |
488 | } |
489 | |
490 | void nsImageFrame::Destroy(DestroyContext& aContext) { |
491 | MaybeSendIntrinsicSizeAndRatioToEmbedder(Nothing(), Nothing()); |
492 | |
493 | if (mReflowCallbackPosted) { |
494 | PresShell()->CancelReflowCallback(this); |
495 | mReflowCallbackPosted = false; |
496 | } |
497 | |
498 | // Tell our image map, if there is one, to clean up |
499 | // This causes the nsImageMap to unregister itself as |
500 | // a DOM listener. |
501 | DisconnectMap(); |
502 | |
503 | MOZ_ASSERT(mListener)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mListener)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mListener))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mListener", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 503); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mListener" ")" ); do { *((volatile int*)__null) = 503; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
504 | |
505 | if (mKind == Kind::ImageLoadingContent) { |
506 | MOZ_ASSERT(!mOwnedRequest)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mOwnedRequest)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mOwnedRequest))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mOwnedRequest" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 506); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOwnedRequest" ")"); do { *((volatile int*)__null) = 506; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
507 | MOZ_ASSERT(!mOwnedRequestRegistered)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mOwnedRequestRegistered)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mOwnedRequestRegistered))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mOwnedRequestRegistered" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 507); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOwnedRequestRegistered" ")"); do { *((volatile int*)__null) = 507; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
508 | nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent); |
509 | MOZ_ASSERT(imageLoader)do { static_assert( mozilla::detail::AssertionConditionType< decltype(imageLoader)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(imageLoader))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("imageLoader", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 509); AnnotateMozCrashReason("MOZ_ASSERT" "(" "imageLoader" ")"); do { *((volatile int*)__null) = 509; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
510 | |
511 | // Notify our image loading content that we are going away so it can |
512 | // deregister with our refresh driver. |
513 | imageLoader->FrameDestroyed(this); |
514 | imageLoader->RemoveNativeObserver(mListener); |
515 | } else { |
516 | DeinitOwnedRequest(); |
517 | } |
518 | |
519 | // set the frame to null so we don't send messages to a dead object. |
520 | mListener->SetFrame(nullptr); |
521 | mListener = nullptr; |
522 | |
523 | // If we were displaying an icon, take ourselves off the list |
524 | if (mDisplayingIcon) { |
525 | BrokenImageIcon::RemoveObserver(this); |
526 | } |
527 | |
528 | nsAtomicContainerFrame::Destroy(aContext); |
529 | } |
530 | |
531 | void nsImageFrame::DeinitOwnedRequest() { |
532 | MOZ_ASSERT(mKind != Kind::ImageLoadingContent)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mKind != Kind::ImageLoadingContent)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mKind != Kind::ImageLoadingContent ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mKind != Kind::ImageLoadingContent", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 532); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mKind != Kind::ImageLoadingContent" ")"); do { *((volatile int*)__null) = 532; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
533 | if (!mOwnedRequest) { |
534 | return; |
535 | } |
536 | PresContext()->Document()->ImageTracker()->Remove(mOwnedRequest); |
537 | nsLayoutUtils::DeregisterImageRequest(PresContext(), mOwnedRequest, |
538 | &mOwnedRequestRegistered); |
539 | mOwnedRequest->CancelAndForgetObserver(NS_BINDING_ABORTED); |
540 | mOwnedRequest = nullptr; |
541 | } |
542 | |
543 | void nsImageFrame::DidSetComputedStyle(ComputedStyle* aOldStyle) { |
544 | nsAtomicContainerFrame::DidSetComputedStyle(aOldStyle); |
545 | |
546 | // A ::marker's default size is calculated from the font's em-size. |
547 | if (IsForMarkerPseudo()) { |
548 | mIntrinsicSize = IntrinsicSize(0, 0); |
549 | UpdateIntrinsicSize(); |
550 | } |
551 | |
552 | // Normal "owned" images reframe when `content` or `list-style-image` change, |
553 | // but XUL images don't (and we don't really need to). So deal with the |
554 | // dynamic list-style-image change in that case. |
555 | // |
556 | // TODO(emilio): We might want to do the same for regular list-style-image or |
557 | // even simple content: url() changes. |
558 | if (mKind == Kind::XULImage && aOldStyle) { |
559 | if (!mContent->AsElement()->HasNonEmptyAttr(nsGkAtoms::src) && |
560 | aOldStyle->StyleList()->mListStyleImage != |
561 | StyleList()->mListStyleImage) { |
562 | UpdateXULImage(); |
563 | } |
564 | // If we have no image our intrinsic size might be themed. We need to |
565 | // update the size even if the effective appearance hasn't changed to |
566 | // deal correctly with theme changes. |
567 | if (!mOwnedRequest) { |
568 | UpdateIntrinsicSize(); |
569 | } |
570 | } |
571 | |
572 | // We need to update our orientation either if we had no ComputedStyle before |
573 | // because this is the first time it's been set, or if the image-orientation |
574 | // property changed from its previous value. |
575 | bool shouldUpdateOrientation = false; |
576 | nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest(); |
577 | const auto newOrientation = |
578 | StyleVisibility()->UsedImageOrientation(currentRequest); |
579 | if (mImage) { |
580 | if (aOldStyle) { |
581 | auto oldOrientation = |
582 | aOldStyle->StyleVisibility()->UsedImageOrientation(currentRequest); |
583 | shouldUpdateOrientation = oldOrientation != newOrientation; |
584 | } else { |
585 | shouldUpdateOrientation = true; |
586 | } |
587 | } |
588 | |
589 | if (shouldUpdateOrientation) { |
590 | nsCOMPtr<imgIContainer> image(mImage->Unwrap()); |
591 | mImage = nsLayoutUtils::OrientImage(image, newOrientation); |
592 | |
593 | UpdateIntrinsicSize(); |
594 | UpdateIntrinsicRatio(); |
595 | } else if (!aOldStyle || aOldStyle->StylePosition()->mAspectRatio != |
596 | StylePosition()->mAspectRatio) { |
597 | UpdateIntrinsicRatio(); |
598 | } |
599 | } |
600 | |
601 | static bool SizeIsAvailable(imgIRequest* aRequest) { |
602 | if (!aRequest) { |
603 | return false; |
604 | } |
605 | |
606 | uint32_t imageStatus = 0; |
607 | nsresult rv = aRequest->GetImageStatus(&imageStatus); |
608 | return NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && (imageStatus & imgIRequest::STATUS_SIZE_AVAILABLE); |
609 | } |
610 | |
611 | const StyleImage* nsImageFrame::GetImageFromStyle() const { |
612 | switch (mKind) { |
613 | case Kind::ImageLoadingContent: |
614 | break; |
615 | case Kind::ListStyleImage: |
616 | MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType< decltype(GetParent()->GetContent()->IsGeneratedContentContainerForMarker ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(GetParent()->GetContent()->IsGeneratedContentContainerForMarker ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("GetParent()->GetContent()->IsGeneratedContentContainerForMarker()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 617); AnnotateMozCrashReason("MOZ_ASSERT" "(" "GetParent()->GetContent()->IsGeneratedContentContainerForMarker()" ")"); do { *((volatile int*)__null) = 617; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
617 | GetParent()->GetContent()->IsGeneratedContentContainerForMarker())do { static_assert( mozilla::detail::AssertionConditionType< decltype(GetParent()->GetContent()->IsGeneratedContentContainerForMarker ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(GetParent()->GetContent()->IsGeneratedContentContainerForMarker ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("GetParent()->GetContent()->IsGeneratedContentContainerForMarker()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 617); AnnotateMozCrashReason("MOZ_ASSERT" "(" "GetParent()->GetContent()->IsGeneratedContentContainerForMarker()" ")"); do { *((volatile int*)__null) = 617; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
618 | MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage))do { static_assert( mozilla::detail::AssertionConditionType< decltype(mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage ))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage)" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 618); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage)" ")"); do { *((volatile int*)__null) = 618; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
619 | return &StyleList()->mListStyleImage; |
620 | case Kind::XULImage: |
621 | MOZ_ASSERT(!mContent->AsElement()->HasNonEmptyAttr(nsGkAtoms::src))do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mContent->AsElement()->HasNonEmptyAttr(nsGkAtoms ::src))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!mContent->AsElement()->HasNonEmptyAttr(nsGkAtoms ::src)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!mContent->AsElement()->HasNonEmptyAttr(nsGkAtoms::src)" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 621); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mContent->AsElement()->HasNonEmptyAttr(nsGkAtoms::src)" ")"); do { *((volatile int*)__null) = 621; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
622 | return &StyleList()->mListStyleImage; |
623 | case Kind::ContentProperty: |
624 | case Kind::ContentPropertyAtIndex: { |
625 | uint32_t contentIndex = 0; |
626 | const nsStyleContent* styleContent = StyleContent(); |
627 | if (mKind == Kind::ContentPropertyAtIndex) { |
628 | MOZ_RELEASE_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType< decltype(mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage ))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage)" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 629); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage)" ")"); do { *((volatile int*)__null) = 629; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
629 | mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage))do { static_assert( mozilla::detail::AssertionConditionType< decltype(mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage ))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage)" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 629); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mContent->IsHTMLElement(nsGkAtoms::mozgeneratedcontentimage)" ")"); do { *((volatile int*)__null) = 629; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
630 | contentIndex = |
631 | static_cast<GeneratedImageContent*>(mContent.get())->Index(); |
632 | |
633 | // TODO(emilio): Consider inheriting the `content` property instead of |
634 | // doing this parent traversal? |
635 | nsIFrame* parent = GetParent(); |
636 | MOZ_DIAGNOSTIC_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType< decltype(parent->GetContent()->IsGeneratedContentContainerForMarker () || parent->GetContent()->IsGeneratedContentContainerForAfter () || parent->GetContent()->IsGeneratedContentContainerForBefore ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(parent->GetContent()->IsGeneratedContentContainerForMarker () || parent->GetContent()->IsGeneratedContentContainerForAfter () || parent->GetContent()->IsGeneratedContentContainerForBefore ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("parent->GetContent()->IsGeneratedContentContainerForMarker() || parent->GetContent()->IsGeneratedContentContainerForAfter() || parent->GetContent()->IsGeneratedContentContainerForBefore()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 639); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "parent->GetContent()->IsGeneratedContentContainerForMarker() || parent->GetContent()->IsGeneratedContentContainerForAfter() || parent->GetContent()->IsGeneratedContentContainerForBefore()" ")"); do { *((volatile int*)__null) = 639; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
637 | parent->GetContent()->IsGeneratedContentContainerForMarker() ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(parent->GetContent()->IsGeneratedContentContainerForMarker () || parent->GetContent()->IsGeneratedContentContainerForAfter () || parent->GetContent()->IsGeneratedContentContainerForBefore ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(parent->GetContent()->IsGeneratedContentContainerForMarker () || parent->GetContent()->IsGeneratedContentContainerForAfter () || parent->GetContent()->IsGeneratedContentContainerForBefore ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("parent->GetContent()->IsGeneratedContentContainerForMarker() || parent->GetContent()->IsGeneratedContentContainerForAfter() || parent->GetContent()->IsGeneratedContentContainerForBefore()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 639); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "parent->GetContent()->IsGeneratedContentContainerForMarker() || parent->GetContent()->IsGeneratedContentContainerForAfter() || parent->GetContent()->IsGeneratedContentContainerForBefore()" ")"); do { *((volatile int*)__null) = 639; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
638 | parent->GetContent()->IsGeneratedContentContainerForAfter() ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(parent->GetContent()->IsGeneratedContentContainerForMarker () || parent->GetContent()->IsGeneratedContentContainerForAfter () || parent->GetContent()->IsGeneratedContentContainerForBefore ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(parent->GetContent()->IsGeneratedContentContainerForMarker () || parent->GetContent()->IsGeneratedContentContainerForAfter () || parent->GetContent()->IsGeneratedContentContainerForBefore ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("parent->GetContent()->IsGeneratedContentContainerForMarker() || parent->GetContent()->IsGeneratedContentContainerForAfter() || parent->GetContent()->IsGeneratedContentContainerForBefore()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 639); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "parent->GetContent()->IsGeneratedContentContainerForMarker() || parent->GetContent()->IsGeneratedContentContainerForAfter() || parent->GetContent()->IsGeneratedContentContainerForBefore()" ")"); do { *((volatile int*)__null) = 639; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
639 | parent->GetContent()->IsGeneratedContentContainerForBefore())do { static_assert( mozilla::detail::AssertionConditionType< decltype(parent->GetContent()->IsGeneratedContentContainerForMarker () || parent->GetContent()->IsGeneratedContentContainerForAfter () || parent->GetContent()->IsGeneratedContentContainerForBefore ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(parent->GetContent()->IsGeneratedContentContainerForMarker () || parent->GetContent()->IsGeneratedContentContainerForAfter () || parent->GetContent()->IsGeneratedContentContainerForBefore ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("parent->GetContent()->IsGeneratedContentContainerForMarker() || parent->GetContent()->IsGeneratedContentContainerForAfter() || parent->GetContent()->IsGeneratedContentContainerForBefore()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 639); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "parent->GetContent()->IsGeneratedContentContainerForMarker() || parent->GetContent()->IsGeneratedContentContainerForAfter() || parent->GetContent()->IsGeneratedContentContainerForBefore()" ")"); do { *((volatile int*)__null) = 639; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
640 | nsIFrame* nonAnonymousParent = parent; |
641 | while (nonAnonymousParent->Style()->IsAnonBox()) { |
642 | nonAnonymousParent = nonAnonymousParent->GetParent(); |
643 | } |
644 | MOZ_DIAGNOSTIC_ASSERT(parent->GetContent() ==do { static_assert( mozilla::detail::AssertionConditionType< decltype(parent->GetContent() == nonAnonymousParent->GetContent ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(parent->GetContent() == nonAnonymousParent->GetContent ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("parent->GetContent() == nonAnonymousParent->GetContent()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 645); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "parent->GetContent() == nonAnonymousParent->GetContent()" ")"); do { *((volatile int*)__null) = 645; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
645 | nonAnonymousParent->GetContent())do { static_assert( mozilla::detail::AssertionConditionType< decltype(parent->GetContent() == nonAnonymousParent->GetContent ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(parent->GetContent() == nonAnonymousParent->GetContent ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("parent->GetContent() == nonAnonymousParent->GetContent()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 645); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "parent->GetContent() == nonAnonymousParent->GetContent()" ")"); do { *((volatile int*)__null) = 645; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
646 | styleContent = nonAnonymousParent->StyleContent(); |
647 | } |
648 | auto items = styleContent->NonAltContentItems(); |
649 | MOZ_RELEASE_ASSERT(contentIndex < items.Length())do { static_assert( mozilla::detail::AssertionConditionType< decltype(contentIndex < items.Length())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(contentIndex < items.Length ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("contentIndex < items.Length()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 649); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "contentIndex < items.Length()" ")"); do { *((volatile int*)__null) = 649; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
650 | const auto& contentItem = items[contentIndex]; |
651 | MOZ_RELEASE_ASSERT(contentItem.IsImage())do { static_assert( mozilla::detail::AssertionConditionType< decltype(contentItem.IsImage())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(contentItem.IsImage()))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("contentItem.IsImage()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 651); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "contentItem.IsImage()" ")"); do { *((volatile int*)__null) = 651; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
652 | return &contentItem.AsImage(); |
653 | } |
654 | } |
655 | MOZ_ASSERT_UNREACHABLE("Don't call me")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: " "Don't call me" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 655); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "Don't call me" ")"); do { *((volatile int*)__null) = 655; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
656 | return nullptr; |
657 | } |
658 | |
659 | void nsImageFrame::UpdateXULImage() { |
660 | MOZ_ASSERT(mKind == Kind::XULImage)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mKind == Kind::XULImage)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mKind == Kind::XULImage))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("mKind == Kind::XULImage" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 660); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mKind == Kind::XULImage" ")"); do { *((volatile int*)__null) = 660; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
661 | DeinitOwnedRequest(); |
662 | |
663 | nsAutoString src; |
664 | nsPresContext* pc = PresContext(); |
665 | if (mContent->AsElement()->GetAttr(nsGkAtoms::src, src) && !src.IsEmpty()) { |
666 | nsContentPolicyType contentPolicyType; |
667 | nsCOMPtr<nsIPrincipal> triggeringPrincipal; |
668 | uint64_t requestContextID = 0; |
669 | nsContentUtils::GetContentPolicyTypeForUIImageLoading( |
670 | mContent, getter_AddRefs(triggeringPrincipal), contentPolicyType, |
671 | &requestContextID); |
672 | nsCOMPtr<nsIURI> uri; |
673 | nsContentUtils::NewURIWithDocumentCharset( |
674 | getter_AddRefs(uri), src, pc->Document(), mContent->GetBaseURI()); |
675 | if (uri) { |
676 | auto referrerInfo = MakeRefPtr<ReferrerInfo>(*mContent->AsElement()); |
677 | nsContentUtils::LoadImage( |
678 | uri, mContent, pc->Document(), triggeringPrincipal, requestContextID, |
679 | referrerInfo, mListener, nsIRequest::LOAD_NORMAL, u""_ns, |
680 | getter_AddRefs(mOwnedRequest), contentPolicyType); |
681 | SetupOwnedRequest(); |
682 | } |
683 | } else { |
684 | const auto* image = GetImageFromStyle(); |
685 | if (image->IsImageRequestType()) { |
686 | if (imgRequestProxy* proxy = image->GetImageRequest()) { |
687 | proxy->Clone(mListener, pc->Document(), getter_AddRefs(mOwnedRequest)); |
688 | SetupOwnedRequest(); |
689 | } |
690 | } |
691 | } |
692 | |
693 | if (!mOwnedRequest) { |
694 | UpdateImage(nullptr, nullptr); |
695 | } |
696 | } |
697 | |
698 | void nsImageFrame::Init(nsIContent* aContent, nsContainerFrame* aParent, |
699 | nsIFrame* aPrevInFlow) { |
700 | MOZ_ASSERT_IF(aPrevInFlow,do { if (aPrevInFlow) { do { static_assert( mozilla::detail:: AssertionConditionType<decltype(aPrevInFlow->Type() == Type () && static_cast<nsImageFrame*>(aPrevInFlow)-> mKind == mKind)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(aPrevInFlow->Type() == Type () && static_cast<nsImageFrame*>(aPrevInFlow)-> mKind == mKind))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("aPrevInFlow->Type() == Type() && static_cast<nsImageFrame*>(aPrevInFlow)->mKind == mKind" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 702); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrevInFlow->Type() == Type() && static_cast<nsImageFrame*>(aPrevInFlow)->mKind == mKind" ")"); do { *((volatile int*)__null) = 702; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
701 | aPrevInFlow->Type() == Type() &&do { if (aPrevInFlow) { do { static_assert( mozilla::detail:: AssertionConditionType<decltype(aPrevInFlow->Type() == Type () && static_cast<nsImageFrame*>(aPrevInFlow)-> mKind == mKind)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(aPrevInFlow->Type() == Type () && static_cast<nsImageFrame*>(aPrevInFlow)-> mKind == mKind))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("aPrevInFlow->Type() == Type() && static_cast<nsImageFrame*>(aPrevInFlow)->mKind == mKind" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 702); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrevInFlow->Type() == Type() && static_cast<nsImageFrame*>(aPrevInFlow)->mKind == mKind" ")"); do { *((volatile int*)__null) = 702; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
702 | static_cast<nsImageFrame*>(aPrevInFlow)->mKind == mKind)do { if (aPrevInFlow) { do { static_assert( mozilla::detail:: AssertionConditionType<decltype(aPrevInFlow->Type() == Type () && static_cast<nsImageFrame*>(aPrevInFlow)-> mKind == mKind)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(aPrevInFlow->Type() == Type () && static_cast<nsImageFrame*>(aPrevInFlow)-> mKind == mKind))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("aPrevInFlow->Type() == Type() && static_cast<nsImageFrame*>(aPrevInFlow)->mKind == mKind" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 702); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrevInFlow->Type() == Type() && static_cast<nsImageFrame*>(aPrevInFlow)->mKind == mKind" ")"); do { *((volatile int*)__null) = 702; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
703 | |
704 | nsAtomicContainerFrame::Init(aContent, aParent, aPrevInFlow); |
705 | |
706 | mListener = new nsImageListener(this); |
707 | |
708 | GetImageMap(); // Ensure to init the image map asap. This is important to |
709 | // make <area> elements focusable. |
710 | |
711 | if (StaticPrefs::layout_image_eager_broken_image_icon()) { |
712 | Unused << BrokenImageIcon::GetImage(this); |
713 | } |
714 | |
715 | nsPresContext* pc = PresContext(); |
716 | if (mKind == Kind::ImageLoadingContent) { |
717 | nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(aContent); |
718 | MOZ_ASSERT(imageLoader)do { static_assert( mozilla::detail::AssertionConditionType< decltype(imageLoader)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(imageLoader))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("imageLoader", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 718); AnnotateMozCrashReason("MOZ_ASSERT" "(" "imageLoader" ")"); do { *((volatile int*)__null) = 718; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
719 | imageLoader->AddNativeObserver(mListener); |
720 | // We have a PresContext now, so we need to notify the image content node |
721 | // that it can register images. |
722 | imageLoader->FrameCreated(this); |
723 | AssertSyncDecodingHintIsInSync(); |
724 | if (nsIDocShell* docShell = pc->GetDocShell()) { |
725 | RefPtr<BrowsingContext> bc = docShell->GetBrowsingContext(); |
726 | mIsInObjectOrEmbed = bc->IsEmbedderTypeObjectOrEmbed() && |
727 | pc->Document()->IsImageDocument(); |
728 | } |
729 | } else if (mKind == Kind::XULImage) { |
730 | UpdateXULImage(); |
731 | } else { |
732 | const StyleImage* image = GetImageFromStyle(); |
733 | if (image->IsImageRequestType()) { |
734 | if (imgRequestProxy* proxy = image->GetImageRequest()) { |
735 | proxy->Clone(mListener, pc->Document(), getter_AddRefs(mOwnedRequest)); |
736 | SetupOwnedRequest(); |
737 | } |
738 | } |
739 | } |
740 | |
741 | // Give image loads associated with an image frame a small priority boost. |
742 | if (nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest()) { |
743 | uint32_t categoryToBoostPriority = imgIRequest::CATEGORY_FRAME_INIT; |
744 | |
745 | // Increase load priority further if intrinsic size might be important for |
746 | // layout. |
747 | if (!HaveSpecifiedSize(StylePosition())) { |
748 | categoryToBoostPriority |= imgIRequest::CATEGORY_SIZE_QUERY; |
749 | } |
750 | |
751 | currentRequest->BoostPriority(categoryToBoostPriority); |
752 | } |
753 | |
754 | MaybeSendIntrinsicSizeAndRatioToEmbedder(); |
755 | } |
756 | |
757 | void nsImageFrame::SetupOwnedRequest() { |
758 | MOZ_ASSERT(mKind != Kind::ImageLoadingContent)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mKind != Kind::ImageLoadingContent)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mKind != Kind::ImageLoadingContent ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mKind != Kind::ImageLoadingContent", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 758); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mKind != Kind::ImageLoadingContent" ")"); do { *((volatile int*)__null) = 758; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
759 | if (!mOwnedRequest) { |
760 | return; |
761 | } |
762 | |
763 | // We're not using AssociateRequestToFrame for the content property, so we |
764 | // need to add it to the image tracker manually. |
765 | PresContext()->Document()->ImageTracker()->Add(mOwnedRequest); |
766 | |
767 | uint32_t status = 0; |
768 | nsresult rv = mOwnedRequest->GetImageStatus(&status); |
769 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
770 | return; |
771 | } |
772 | |
773 | if (status & imgIRequest::STATUS_SIZE_AVAILABLE) { |
774 | nsCOMPtr<imgIContainer> image; |
775 | mOwnedRequest->GetImage(getter_AddRefs(image)); |
776 | OnSizeAvailable(mOwnedRequest, image); |
777 | } |
778 | |
779 | if (status & imgIRequest::STATUS_FRAME_COMPLETE) { |
780 | mFirstFrameComplete = true; |
781 | } |
782 | |
783 | if (status & imgIRequest::STATUS_IS_ANIMATED) { |
784 | nsLayoutUtils::RegisterImageRequest(PresContext(), mOwnedRequest, |
785 | &mOwnedRequestRegistered); |
786 | } |
787 | } |
788 | |
789 | static void ScaleIntrinsicSizeForDensity(IntrinsicSize& aSize, |
790 | const ImageResolution& aResolution) { |
791 | if (aSize.width) { |
792 | aResolution.ApplyXTo(aSize.width.ref()); |
793 | } |
794 | if (aSize.height) { |
795 | aResolution.ApplyYTo(aSize.height.ref()); |
796 | } |
797 | } |
798 | |
799 | static void ScaleIntrinsicSizeForDensity(imgIContainer* aImage, |
800 | nsIContent& aContent, |
801 | IntrinsicSize& aSize) { |
802 | ImageResolution resolution = aImage->GetResolution(); |
803 | if (auto* image = HTMLImageElement::FromNode(aContent)) { |
804 | if (auto* selector = image->GetResponsiveImageSelector()) { |
805 | resolution.ScaleBy(selector->GetSelectedImageDensity()); |
806 | } |
807 | } |
808 | ScaleIntrinsicSizeForDensity(aSize, resolution); |
809 | } |
810 | |
811 | static nscoord ListImageDefaultLength(const nsImageFrame& aFrame) { |
812 | // https://drafts.csswg.org/css-lists-3/#image-markers |
813 | // The spec says we should use 1em x 1em, but that seems too large. |
814 | // See disussion in https://github.com/w3c/csswg-drafts/issues/4207 |
815 | auto* pc = aFrame.PresContext(); |
816 | RefPtr<nsFontMetrics> fm = |
817 | nsLayoutUtils::GetFontMetricsForComputedStyle(aFrame.Style(), pc); |
818 | RefPtr<gfxFont> font = fm->GetThebesFontGroup()->GetFirstValidFont(); |
819 | auto emAU = |
820 | font->GetMetrics(fm->Orientation()).emHeight * pc->AppUnitsPerDevPixel(); |
821 | return std::max(NSToCoordRound(0.4f * emAU), |
822 | nsPresContext::CSSPixelsToAppUnits(1)); |
823 | } |
824 | |
825 | IntrinsicSize nsImageFrame::ComputeIntrinsicSize( |
826 | bool aIgnoreContainment) const { |
827 | const auto containAxes = |
828 | aIgnoreContainment ? ContainSizeAxes(false, false) : GetContainSizeAxes(); |
829 | if (containAxes.IsBoth()) { |
830 | return FinishIntrinsicSize(containAxes, IntrinsicSize(0, 0)); |
831 | } |
832 | |
833 | nsSize size; |
834 | if (mImage && NS_SUCCEEDED(mImage->GetIntrinsicSize(&size))((bool)(__builtin_expect(!!(!NS_FAILED_impl(mImage->GetIntrinsicSize (&size))), 1)))) { |
835 | IntrinsicSize intrinsicSize; |
836 | intrinsicSize.width = size.width == -1 ? Nothing() : Some(size.width); |
837 | intrinsicSize.height = size.height == -1 ? Nothing() : Some(size.height); |
838 | if (mKind == nsImageFrame::Kind::ListStyleImage) { |
839 | if (intrinsicSize.width.isNothing() || intrinsicSize.height.isNothing()) { |
840 | nscoord defaultLength = ListImageDefaultLength(*this); |
841 | if (intrinsicSize.width.isNothing()) { |
842 | intrinsicSize.width = Some(defaultLength); |
843 | } |
844 | if (intrinsicSize.height.isNothing()) { |
845 | intrinsicSize.height = Some(defaultLength); |
846 | } |
847 | } |
848 | } |
849 | if (mKind == nsImageFrame::Kind::ImageLoadingContent || |
850 | (mKind == nsImageFrame::Kind::XULImage && |
851 | GetContent()->AsElement()->HasNonEmptyAttr(nsGkAtoms::src))) { |
852 | ScaleIntrinsicSizeForDensity(mImage, *GetContent(), intrinsicSize); |
853 | } else { |
854 | ScaleIntrinsicSizeForDensity( |
855 | intrinsicSize, GetImageFromStyle()->GetResolution(*Style())); |
856 | } |
857 | return FinishIntrinsicSize(containAxes, intrinsicSize); |
858 | } |
859 | |
860 | if (mKind == nsImageFrame::Kind::ListStyleImage) { |
861 | // Note: images are handled above, this handles gradients etc. |
862 | const nscoord defaultLength = ListImageDefaultLength(*this); |
863 | return FinishIntrinsicSize(containAxes, |
864 | IntrinsicSize(defaultLength, defaultLength)); |
865 | } |
866 | |
867 | if (mKind == nsImageFrame::Kind::XULImage && IsThemed()) { |
868 | nsPresContext* pc = PresContext(); |
869 | // FIXME: const_cast here is a bit evil but IsThemed and so does the same. |
870 | const auto widgetSize = pc->Theme()->GetMinimumWidgetSize( |
871 | pc, const_cast<nsImageFrame*>(this), |
872 | StyleDisplay()->EffectiveAppearance()); |
873 | const IntrinsicSize intrinsicSize( |
874 | LayoutDeviceIntSize::ToAppUnits(widgetSize, pc->AppUnitsPerDevPixel())); |
875 | return FinishIntrinsicSize(containAxes, intrinsicSize); |
876 | } |
877 | |
878 | if (ShouldShowBrokenImageIcon()) { |
879 | nscoord edgeLengthToUse = nsPresContext::CSSPixelsToAppUnits( |
880 | ICON_SIZE(16) + (2 * (ICON_PADDING(3) + ALT_BORDER_WIDTH(1)))); |
881 | return FinishIntrinsicSize(containAxes, |
882 | IntrinsicSize(edgeLengthToUse, edgeLengthToUse)); |
883 | } |
884 | |
885 | if (ShouldUseMappedAspectRatio() && |
886 | StylePosition()->mAspectRatio.HasRatio()) { |
887 | return IntrinsicSize(); |
888 | } |
889 | |
890 | // XXX: No FinishIntrinsicSize? |
891 | return IntrinsicSize(0, 0); |
892 | } |
893 | |
894 | // For compat reasons, see bug 1602047, we don't use the intrinsic ratio from |
895 | // width="" and height="" for images with no src attribute (no request). |
896 | // |
897 | // But we shouldn't get fooled by <img loading=lazy>. We do want to apply the |
898 | // ratio then... |
899 | bool nsImageFrame::ShouldUseMappedAspectRatio() const { |
900 | if (mKind != Kind::ImageLoadingContent) { |
901 | return true; |
902 | } |
903 | nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest(); |
904 | if (currentRequest) { |
905 | return true; |
906 | } |
907 | // TODO(emilio): Investigate the compat situation of the above check, maybe we |
908 | // can just check for empty src attribute or something... |
909 | auto* image = HTMLImageElement::FromNode(mContent); |
910 | return image && image->IsAwaitingLoadOrLazyLoading(); |
911 | } |
912 | |
913 | bool nsImageFrame::UpdateIntrinsicSize() { |
914 | IntrinsicSize oldIntrinsicSize = mIntrinsicSize; |
915 | mIntrinsicSize = ComputeIntrinsicSize(); |
916 | return mIntrinsicSize != oldIntrinsicSize; |
917 | } |
918 | |
919 | AspectRatio nsImageFrame::ComputeIntrinsicRatioForImage( |
920 | imgIContainer* aImage, bool aIgnoreContainment) const { |
921 | if (!aIgnoreContainment && GetContainSizeAxes().IsAny()) { |
922 | return AspectRatio(); |
923 | } |
924 | |
925 | if (aImage) { |
926 | if (Maybe<AspectRatio> fromImage = aImage->GetIntrinsicRatio()) { |
927 | return *fromImage; |
928 | } |
929 | } |
930 | if (ShouldUseMappedAspectRatio()) { |
931 | const StyleAspectRatio& ratio = StylePosition()->mAspectRatio; |
932 | if (ratio.auto_ && ratio.HasRatio()) { |
933 | // Return the mapped intrinsic aspect ratio stored in |
934 | // nsStylePosition::mAspectRatio. |
935 | return ratio.ratio.AsRatio().ToLayoutRatio(UseBoxSizing::Yes); |
936 | } |
937 | } |
938 | if (ShouldShowBrokenImageIcon()) { |
939 | return AspectRatio(1.0f); |
940 | } |
941 | return AspectRatio(); |
942 | } |
943 | |
944 | bool nsImageFrame::UpdateIntrinsicRatio() { |
945 | AspectRatio oldIntrinsicRatio = mIntrinsicRatio; |
946 | mIntrinsicRatio = ComputeIntrinsicRatioForImage(mImage); |
947 | return mIntrinsicRatio != oldIntrinsicRatio; |
948 | } |
949 | |
950 | bool nsImageFrame::GetSourceToDestTransform(nsTransform2D& aTransform) { |
951 | nsRect destRect = GetDestRect(GetContentRectRelativeToSelf()); |
952 | // Set the translation components, based on destRect |
953 | // XXXbz does this introduce rounding errors because of the cast to |
954 | // float? Should we just manually add that stuff in every time |
955 | // instead? |
956 | aTransform.SetToTranslate(float(destRect.x), float(destRect.y)); |
957 | |
958 | // NOTE(emilio): This intrinsicSize is not the same as the layout intrinsic |
959 | // size (mIntrinsicSize), which can be scaled due to ResponsiveImageSelector, |
960 | // see ScaleIntrinsicSizeForDensity. |
961 | nsSize intrinsicSize; |
962 | if (!mImage || !NS_SUCCEEDED(mImage->GetIntrinsicSize(&intrinsicSize))((bool)(__builtin_expect(!!(!NS_FAILED_impl(mImage->GetIntrinsicSize (&intrinsicSize))), 1))) || |
963 | intrinsicSize.IsEmpty()) { |
964 | return false; |
965 | } |
966 | |
967 | aTransform.SetScale(float(destRect.width) / float(intrinsicSize.width), |
968 | float(destRect.height) / float(intrinsicSize.height)); |
969 | return true; |
970 | } |
971 | |
972 | // This function checks whether the given request is the current request for our |
973 | // mContent. |
974 | bool nsImageFrame::IsPendingLoad(imgIRequest* aRequest) const { |
975 | // Default to pending load in case of errors |
976 | if (mKind != Kind::ImageLoadingContent) { |
977 | MOZ_ASSERT(aRequest == mOwnedRequest)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aRequest == mOwnedRequest)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aRequest == mOwnedRequest))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("aRequest == mOwnedRequest" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 977); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRequest == mOwnedRequest" ")"); do { *((volatile int*)__null) = 977; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
978 | return false; |
979 | } |
980 | |
981 | nsCOMPtr<nsIImageLoadingContent> imageLoader(do_QueryInterface(mContent)); |
982 | MOZ_ASSERT(imageLoader)do { static_assert( mozilla::detail::AssertionConditionType< decltype(imageLoader)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(imageLoader))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("imageLoader", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 982); AnnotateMozCrashReason("MOZ_ASSERT" "(" "imageLoader" ")"); do { *((volatile int*)__null) = 982; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
983 | |
984 | int32_t requestType = nsIImageLoadingContent::UNKNOWN_REQUEST; |
985 | imageLoader->GetRequestType(aRequest, &requestType); |
986 | |
987 | return requestType != nsIImageLoadingContent::CURRENT_REQUEST; |
988 | } |
989 | |
990 | nsRect nsImageFrame::SourceRectToDest(const nsIntRect& aRect) { |
991 | // When scaling the image, row N of the source image may (depending on |
992 | // the scaling function) be used to draw any row in the destination image |
993 | // between floor(F * (N-1)) and ceil(F * (N+1)), where F is the |
994 | // floating-point scaling factor. The same holds true for columns. |
995 | // So, we start by computing that bound without the floor and ceiling. |
996 | |
997 | nsRect r(nsPresContext::CSSPixelsToAppUnits(aRect.x - 1), |
998 | nsPresContext::CSSPixelsToAppUnits(aRect.y - 1), |
999 | nsPresContext::CSSPixelsToAppUnits(aRect.width + 2), |
1000 | nsPresContext::CSSPixelsToAppUnits(aRect.height + 2)); |
1001 | |
1002 | nsTransform2D sourceToDest; |
1003 | if (!GetSourceToDestTransform(sourceToDest)) { |
1004 | // Failed to generate transform matrix. Return our whole content area, |
1005 | // to be on the safe side (since this method is used for generating |
1006 | // invalidation rects). |
1007 | return GetContentRectRelativeToSelf(); |
1008 | } |
1009 | |
1010 | sourceToDest.TransformCoord(&r.x, &r.y, &r.width, &r.height); |
1011 | |
1012 | // Now, round the edges out to the pixel boundary. |
1013 | nscoord scale = nsPresContext::CSSPixelsToAppUnits(1); |
1014 | nscoord right = r.x + r.width; |
1015 | nscoord bottom = r.y + r.height; |
1016 | |
1017 | r.x -= (scale + (r.x % scale)) % scale; |
1018 | r.y -= (scale + (r.y % scale)) % scale; |
1019 | r.width = right + ((scale - (right % scale)) % scale) - r.x; |
1020 | r.height = bottom + ((scale - (bottom % scale)) % scale) - r.y; |
1021 | |
1022 | return r; |
1023 | } |
1024 | |
1025 | static bool ImageOk(ElementState aState) { |
1026 | return !aState.HasState(ElementState::BROKEN); |
1027 | } |
1028 | |
1029 | static bool HasAltText(const Element& aElement) { |
1030 | // We always return some alternate text for <input>, see |
1031 | // nsCSSFrameConstructor::GetAlternateTextFor. |
1032 | if (aElement.IsHTMLElement(nsGkAtoms::input)) { |
1033 | return true; |
1034 | } |
1035 | |
1036 | MOZ_ASSERT(aElement.IsHTMLElement(nsGkAtoms::img))do { static_assert( mozilla::detail::AssertionConditionType< decltype(aElement.IsHTMLElement(nsGkAtoms::img))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(aElement.IsHTMLElement(nsGkAtoms::img)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aElement.IsHTMLElement(nsGkAtoms::img)" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1036); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aElement.IsHTMLElement(nsGkAtoms::img)" ")"); do { *((volatile int*)__null) = 1036; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1037 | return aElement.HasNonEmptyAttr(nsGkAtoms::alt); |
1038 | } |
1039 | |
1040 | bool nsImageFrame::ShouldCreateImageFrameForContentProperty( |
1041 | const Element& aElement, const ComputedStyle& aStyle) { |
1042 | if (aElement.IsRootOfNativeAnonymousSubtree()) { |
1043 | return false; |
1044 | } |
1045 | Span<const StyleContentItem> items = |
1046 | aStyle.StyleContent()->NonAltContentItems(); |
1047 | return items.Length() == 1 && items[0].IsImage(); |
1048 | } |
1049 | |
1050 | // Check if we want to use an image frame or just let the frame constructor make |
1051 | // us into an inline, and if so, which kind of image frame should we create. |
1052 | /* static */ |
1053 | auto nsImageFrame::ImageFrameTypeFor( |
1054 | const Element& aElement, const ComputedStyle& aStyle) -> ImageFrameType { |
1055 | if (ShouldCreateImageFrameForContentProperty(aElement, aStyle)) { |
1056 | // Prefer the content property, for compat reasons, see bug 1484928. |
1057 | return ImageFrameType::ForContentProperty; |
1058 | } |
1059 | |
1060 | if (ImageOk(aElement.State())) { |
1061 | // Image is fine or loading; do the image frame thing |
1062 | return ImageFrameType::ForElementRequest; |
1063 | } |
1064 | |
1065 | if (aStyle.StyleUIReset()->mMozForceBrokenImageIcon) { |
1066 | return ImageFrameType::ForElementRequest; |
1067 | } |
1068 | |
1069 | if (!HasAltText(aElement)) { |
1070 | return ImageFrameType::ForElementRequest; |
1071 | } |
1072 | |
1073 | // FIXME(emilio, bug 1788767): We definitely don't reframe when |
1074 | // HaveSpecifiedSize changes... |
1075 | if (aElement.OwnerDoc()->GetCompatibilityMode() == eCompatibility_NavQuirks && |
1076 | HaveSpecifiedSize(aStyle.StylePosition())) { |
1077 | return ImageFrameType::ForElementRequest; |
1078 | } |
1079 | |
1080 | return ImageFrameType::None; |
1081 | } |
1082 | |
1083 | void nsImageFrame::Notify(imgIRequest* aRequest, int32_t aType, |
1084 | const nsIntRect* aRect) { |
1085 | if (aType == imgINotificationObserver::SIZE_AVAILABLE) { |
1086 | nsCOMPtr<imgIContainer> image; |
1087 | aRequest->GetImage(getter_AddRefs(image)); |
1088 | return OnSizeAvailable(aRequest, image); |
1089 | } |
1090 | |
1091 | if (aType == imgINotificationObserver::FRAME_UPDATE) { |
1092 | return OnFrameUpdate(aRequest, aRect); |
1093 | } |
1094 | |
1095 | if (aType == imgINotificationObserver::FRAME_COMPLETE) { |
1096 | mFirstFrameComplete = true; |
1097 | } |
1098 | |
1099 | if (aType == imgINotificationObserver::IS_ANIMATED && |
1100 | mKind != Kind::ImageLoadingContent) { |
1101 | nsLayoutUtils::RegisterImageRequest(PresContext(), mOwnedRequest, |
1102 | &mOwnedRequestRegistered); |
1103 | } |
1104 | |
1105 | if (aType == imgINotificationObserver::LOAD_COMPLETE) { |
1106 | LargestContentfulPaint::MaybeProcessImageForElementTiming( |
1107 | static_cast<imgRequestProxy*>(aRequest), GetContent()->AsElement()); |
1108 | uint32_t imgStatus; |
1109 | aRequest->GetImageStatus(&imgStatus); |
1110 | nsresult status = |
1111 | imgStatus & imgIRequest::STATUS_ERROR ? NS_ERROR_FAILURE : NS_OK; |
1112 | return OnLoadComplete(aRequest, status); |
1113 | } |
1114 | } |
1115 | |
1116 | void nsImageFrame::OnSizeAvailable(imgIRequest* aRequest, |
1117 | imgIContainer* aImage) { |
1118 | if (!aImage) { |
1119 | return; |
1120 | } |
1121 | |
1122 | /* Get requested animation policy from the pres context: |
1123 | * normal = 0 |
1124 | * one frame = 1 |
1125 | * one loop = 2 |
1126 | */ |
1127 | aImage->SetAnimationMode(PresContext()->ImageAnimationMode()); |
1128 | |
1129 | if (IsPendingLoad(aRequest)) { |
1130 | // We don't care |
1131 | return; |
1132 | } |
1133 | |
1134 | UpdateImage(aRequest, aImage); |
1135 | } |
1136 | |
1137 | void nsImageFrame::UpdateImage(imgIRequest* aRequest, imgIContainer* aImage) { |
1138 | if (SizeIsAvailable(aRequest)) { |
1139 | StyleImageOrientation orientation = |
1140 | StyleVisibility()->UsedImageOrientation(aRequest); |
1141 | // This is valid and for the current request, so update our stored image |
1142 | // container, orienting according to our style. |
1143 | mImage = nsLayoutUtils::OrientImage(aImage, orientation); |
1144 | MOZ_ASSERT(mImage)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mImage)>::isValid, "invalid assertion condition") ; if ((__builtin_expect(!!(!(!!(mImage))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mImage", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1144); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mImage" ")" ); do { *((volatile int*)__null) = 1144; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1145 | } else { |
1146 | // We no longer have a valid image, so release our stored image container. |
1147 | mImage = mPrevImage = nullptr; |
1148 | if (mKind == Kind::ListStyleImage) { |
1149 | auto* genContent = static_cast<GeneratedImageContent*>(GetContent()); |
1150 | genContent->NotifyLoadFailed(); |
1151 | // No need to continue below since the above state change will destroy |
1152 | // this frame. |
1153 | return; |
1154 | } |
1155 | } |
1156 | |
1157 | UpdateIntrinsicSizeAndRatio(); |
1158 | |
1159 | if (!GotInitialReflow()) { |
1160 | return; |
1161 | } |
1162 | |
1163 | // We're going to need to repaint now either way. |
1164 | InvalidateFrame(); |
1165 | } |
1166 | |
1167 | void nsImageFrame::OnFrameUpdate(imgIRequest* aRequest, |
1168 | const nsIntRect* aRect) { |
1169 | if (NS_WARN_IF(!aRect)NS_warn_if_impl(!aRect, "!aRect", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1169)) { |
1170 | return; |
1171 | } |
1172 | |
1173 | if (!GotInitialReflow()) { |
1174 | // Don't bother to do anything; we have a reflow coming up! |
1175 | return; |
1176 | } |
1177 | |
1178 | if (mFirstFrameComplete && !StyleVisibility()->IsVisible()) { |
1179 | return; |
1180 | } |
1181 | |
1182 | if (IsPendingLoad(aRequest)) { |
1183 | // We don't care |
1184 | return; |
1185 | } |
1186 | |
1187 | nsIntRect layerInvalidRect = |
1188 | mImage ? mImage->GetImageSpaceInvalidationRect(*aRect) : *aRect; |
1189 | |
1190 | if (layerInvalidRect.IsEqualInterior(GetMaxSizedIntRect())) { |
1191 | // Invalidate our entire area. |
1192 | InvalidateSelf(nullptr, nullptr); |
1193 | return; |
1194 | } |
1195 | |
1196 | nsRect frameInvalidRect = SourceRectToDest(layerInvalidRect); |
1197 | InvalidateSelf(&layerInvalidRect, &frameInvalidRect); |
1198 | } |
1199 | |
1200 | void nsImageFrame::InvalidateSelf(const nsIntRect* aLayerInvalidRect, |
1201 | const nsRect* aFrameInvalidRect) { |
1202 | // Check if WebRender has interacted with this frame. If it has |
1203 | // we need to let it know that things have changed. |
1204 | const auto type = DisplayItemType::TYPE_IMAGE; |
1205 | const auto providerId = mImage ? mImage->GetProviderId() : 0; |
1206 | if (WebRenderUserData::ProcessInvalidateForImage(this, type, providerId)) { |
1207 | return; |
1208 | } |
1209 | |
1210 | InvalidateLayer(type, aLayerInvalidRect, aFrameInvalidRect); |
1211 | |
1212 | if (!mFirstFrameComplete) { |
1213 | InvalidateLayer(DisplayItemType::TYPE_ALT_FEEDBACK, aLayerInvalidRect, |
1214 | aFrameInvalidRect); |
1215 | } |
1216 | } |
1217 | |
1218 | void nsImageFrame::MaybeSendIntrinsicSizeAndRatioToEmbedder() { |
1219 | MaybeSendIntrinsicSizeAndRatioToEmbedder(Some(GetIntrinsicSize()), |
1220 | Some(GetAspectRatio())); |
1221 | } |
1222 | |
1223 | void nsImageFrame::MaybeSendIntrinsicSizeAndRatioToEmbedder( |
1224 | Maybe<IntrinsicSize> aIntrinsicSize, Maybe<AspectRatio> aIntrinsicRatio) { |
1225 | if (!mIsInObjectOrEmbed || !mImage) { |
1226 | return; |
1227 | } |
1228 | |
1229 | nsCOMPtr<nsIDocShell> docShell = PresContext()->GetDocShell(); |
1230 | if (!docShell) { |
1231 | return; |
1232 | } |
1233 | |
1234 | BrowsingContext* bc = docShell->GetBrowsingContext(); |
1235 | if (!bc) { |
1236 | return; |
1237 | } |
1238 | MOZ_ASSERT(bc->IsContentSubframe())do { static_assert( mozilla::detail::AssertionConditionType< decltype(bc->IsContentSubframe())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(bc->IsContentSubframe())) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("bc->IsContentSubframe()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1238); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bc->IsContentSubframe()" ")"); do { *((volatile int*)__null) = 1238; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1239 | |
1240 | if (bc->GetParent()->IsInProcess()) { |
1241 | if (Element* embedder = bc->GetEmbedderElement()) { |
1242 | if (nsCOMPtr<nsIObjectLoadingContent> olc = do_QueryInterface(embedder)) { |
1243 | static_cast<nsObjectLoadingContent*>(olc.get()) |
1244 | ->SubdocumentIntrinsicSizeOrRatioChanged(aIntrinsicSize, |
1245 | aIntrinsicRatio); |
1246 | } else { |
1247 | MOZ_ASSERT_UNREACHABLE("Got out of sync?")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: " "Got out of sync?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1247); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "Got out of sync?" ")"); do { *(( volatile int*)__null) = 1247; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
1248 | } |
1249 | return; |
1250 | } |
1251 | } |
1252 | |
1253 | if (BrowserChild* browserChild = BrowserChild::GetFrom(docShell)) { |
1254 | Unused << browserChild->SendIntrinsicSizeOrRatioChanged(aIntrinsicSize, |
1255 | aIntrinsicRatio); |
1256 | } |
1257 | } |
1258 | |
1259 | void nsImageFrame::OnLoadComplete(imgIRequest* aRequest, nsresult aStatus) { |
1260 | NotifyNewCurrentRequest(aRequest, aStatus); |
1261 | } |
1262 | |
1263 | void nsImageFrame::ElementStateChanged(ElementState aStates) { |
1264 | if (!(aStates & ElementState::BROKEN)) { |
1265 | return; |
1266 | } |
1267 | if (mKind != Kind::ImageLoadingContent) { |
1268 | return; |
1269 | } |
1270 | if (!ImageOk(mContent->AsElement()->State())) { |
1271 | UpdateImage(nullptr, nullptr); |
1272 | } |
1273 | } |
1274 | |
1275 | void nsImageFrame::ResponsiveContentDensityChanged() { |
1276 | UpdateIntrinsicSizeAndRatio(); |
1277 | } |
1278 | |
1279 | void nsImageFrame::UpdateIntrinsicSizeAndRatio() { |
1280 | bool intrinsicSizeOrRatioChanged = [&] { |
1281 | // NOTE(emilio): We intentionally want to call both functions and avoid |
1282 | // short-circuiting. |
1283 | bool intrinsicSizeChanged = UpdateIntrinsicSize(); |
1284 | bool intrinsicRatioChanged = UpdateIntrinsicRatio(); |
1285 | return intrinsicSizeChanged || intrinsicRatioChanged; |
1286 | }(); |
1287 | |
1288 | if (!intrinsicSizeOrRatioChanged) { |
1289 | return; |
1290 | } |
1291 | |
1292 | // Our aspect-ratio property value changed, and an embedding <object> or |
1293 | // <embed> might care about that. |
1294 | MaybeSendIntrinsicSizeAndRatioToEmbedder(); |
1295 | |
1296 | if (!GotInitialReflow()) { |
1297 | return; |
1298 | } |
1299 | |
1300 | // Now we need to reflow if we have an unconstrained size and have |
1301 | // already gotten the initial reflow. |
1302 | if (!HasAnyStateBits(IMAGE_SIZECONSTRAINED)) { |
1303 | PresShell()->FrameNeedsReflow( |
1304 | this, IntrinsicDirty::FrameAncestorsAndDescendants, NS_FRAME_IS_DIRTY); |
1305 | } else if (PresShell()->IsActive()) { |
1306 | // We've already gotten the initial reflow, and our size hasn't changed, |
1307 | // so we're ready to request a decode. |
1308 | MaybeDecodeForPredictedSize(); |
1309 | } |
1310 | } |
1311 | |
1312 | void nsImageFrame::NotifyNewCurrentRequest(imgIRequest* aRequest, |
1313 | nsresult aStatus) { |
1314 | nsCOMPtr<imgIContainer> image; |
1315 | aRequest->GetImage(getter_AddRefs(image)); |
1316 | NS_ASSERTION(image || NS_FAILED(aStatus),do { if (!(image || ((bool)(__builtin_expect(!!(NS_FAILED_impl (aStatus)), 0))))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Successful load with no container?" , "image || NS_FAILED(aStatus)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1317); MOZ_PretendNoReturn(); } } while (0) |
1317 | "Successful load with no container?")do { if (!(image || ((bool)(__builtin_expect(!!(NS_FAILED_impl (aStatus)), 0))))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Successful load with no container?" , "image || NS_FAILED(aStatus)", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1317); MOZ_PretendNoReturn(); } } while (0); |
1318 | UpdateImage(aRequest, image); |
1319 | } |
1320 | |
1321 | void nsImageFrame::MaybeDecodeForPredictedSize() { |
1322 | // Check that we're ready to decode. |
1323 | if (!mImage) { |
1324 | return; // Nothing to do yet. |
1325 | } |
1326 | |
1327 | if (mComputedSize.IsEmpty()) { |
1328 | return; // We won't draw anything, so no point in decoding. |
1329 | } |
1330 | |
1331 | if (GetVisibility() != Visibility::ApproximatelyVisible) { |
1332 | return; // We're not visible, so don't decode. |
1333 | } |
1334 | |
1335 | // OK, we're ready to decode. Compute the scale to the screen... |
1336 | mozilla::PresShell* presShell = PresShell(); |
1337 | MatrixScales scale = |
1338 | ScaleFactor<UnknownUnits, UnknownUnits>( |
1339 | presShell->GetCumulativeResolution()) * |
1340 | nsLayoutUtils::GetTransformToAncestorScaleExcludingAnimated(this); |
1341 | auto resolutionToScreen = ViewAs<LayoutDeviceToScreenScale2D>(scale); |
1342 | |
1343 | // If we are in a remote browser, then apply scaling from ancestor browsers |
1344 | if (BrowserChild* browserChild = BrowserChild::GetFrom(presShell)) { |
1345 | resolutionToScreen = |
1346 | resolutionToScreen * ViewAs<ScreenToScreenScale2D>( |
1347 | browserChild->GetEffectsInfo().mRasterScale); |
1348 | } |
1349 | |
1350 | // ...and this frame's content box... |
1351 | const nsPoint offset = |
1352 | GetOffsetToCrossDoc(nsLayoutUtils::GetReferenceFrame(this)); |
1353 | const nsRect frameContentBox = GetContentRectRelativeToSelf() + offset; |
1354 | |
1355 | // ...and our predicted dest rect... |
1356 | const int32_t factor = PresContext()->AppUnitsPerDevPixel(); |
1357 | const LayoutDeviceRect destRect = |
1358 | LayoutDeviceRect::FromAppUnits(GetDestRect(frameContentBox), factor); |
1359 | |
1360 | // ...and use them to compute our predicted size in screen pixels. |
1361 | const ScreenSize predictedScreenSize = destRect.Size() * resolutionToScreen; |
1362 | const ScreenIntSize predictedScreenIntSize = |
1363 | RoundedToInt(predictedScreenSize); |
1364 | if (predictedScreenIntSize.IsEmpty()) { |
1365 | return; |
1366 | } |
1367 | |
1368 | // Determine the optimal image size to use. |
1369 | uint32_t flags = imgIContainer::FLAG_HIGH_QUALITY_SCALING | |
1370 | imgIContainer::FLAG_ASYNC_NOTIFY; |
1371 | SamplingFilter samplingFilter = |
1372 | nsLayoutUtils::GetSamplingFilterForFrame(this); |
1373 | gfxSize gfxPredictedScreenSize = |
1374 | gfxSize(predictedScreenIntSize.width, predictedScreenIntSize.height); |
1375 | nsIntSize predictedImageSize = mImage->OptimalImageSizeForDest( |
1376 | gfxPredictedScreenSize, imgIContainer::FRAME_CURRENT, samplingFilter, |
1377 | flags); |
1378 | |
1379 | // Request a decode. |
1380 | mImage->RequestDecodeForSize(predictedImageSize, flags); |
1381 | } |
1382 | |
1383 | nsRect nsImageFrame::GetDestRect(const nsRect& aFrameContentBox, |
1384 | nsPoint* aAnchorPoint) { |
1385 | // Note: To get the "dest rect", we have to provide the "constraint rect" |
1386 | // (which is the content-box, with the effects of fragmentation undone). |
1387 | nsRect constraintRect(aFrameContentBox.TopLeft(), mComputedSize); |
1388 | constraintRect.y -= GetContinuationOffset(); |
1389 | |
1390 | auto intrinsicSize = mIntrinsicSize; |
1391 | auto intrinsicRatio = mIntrinsicRatio; |
1392 | if (GetContainSizeAxes().IsAny()) { |
1393 | // Ignore containment for object-fit computations. |
1394 | const bool ignoreContainment = true; |
1395 | intrinsicSize = ComputeIntrinsicSize(ignoreContainment); |
1396 | intrinsicRatio = ComputeIntrinsicRatioForImage(mImage, ignoreContainment); |
1397 | } |
1398 | return nsLayoutUtils::ComputeObjectDestRect(constraintRect, intrinsicSize, |
1399 | intrinsicRatio, StylePosition(), |
1400 | aAnchorPoint); |
1401 | } |
1402 | |
1403 | bool nsImageFrame::IsForMarkerPseudo() const { |
1404 | if (mKind == Kind::ImageLoadingContent) { |
1405 | return false; |
1406 | } |
1407 | auto* subtreeRoot = GetContent()->GetClosestNativeAnonymousSubtreeRoot(); |
1408 | return subtreeRoot && subtreeRoot->IsGeneratedContentContainerForMarker(); |
1409 | } |
1410 | |
1411 | void nsImageFrame::EnsureIntrinsicSizeAndRatio() { |
1412 | const auto containAxes = GetContainSizeAxes(); |
1413 | if (containAxes.IsBoth()) { |
1414 | // If we have 'contain:size', then we have no intrinsic aspect ratio, |
1415 | // and the intrinsic size is determined by contain-intrinsic-size, |
1416 | // regardless of what our underlying image may think. |
1417 | mIntrinsicSize = FinishIntrinsicSize(containAxes, IntrinsicSize(0, 0)); |
1418 | mIntrinsicRatio = AspectRatio(); |
1419 | return; |
1420 | } |
1421 | |
1422 | // If mIntrinsicSize.width and height are 0, then we need to update from the |
1423 | // image container. Note that we handle ::marker intrinsic size/ratio in |
1424 | // DidSetComputedStyle. |
1425 | if (mIntrinsicSize != IntrinsicSize(0, 0) && !IsForMarkerPseudo()) { |
1426 | return; |
1427 | } |
1428 | |
1429 | bool intrinsicSizeOrRatioChanged = UpdateIntrinsicSize(); |
1430 | intrinsicSizeOrRatioChanged = |
1431 | UpdateIntrinsicRatio() || intrinsicSizeOrRatioChanged; |
1432 | |
1433 | if (intrinsicSizeOrRatioChanged) { |
1434 | // Our aspect-ratio property value changed, and an embedding <object> or |
1435 | // <embed> might care about that. |
1436 | MaybeSendIntrinsicSizeAndRatioToEmbedder(); |
1437 | } |
1438 | } |
1439 | |
1440 | nsIFrame::SizeComputationResult nsImageFrame::ComputeSize( |
1441 | gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize, |
1442 | nscoord aAvailableISize, const LogicalSize& aMargin, |
1443 | const LogicalSize& aBorderPadding, const StyleSizeOverrides& aSizeOverrides, |
1444 | ComputeSizeFlags aFlags) { |
1445 | EnsureIntrinsicSizeAndRatio(); |
1446 | return {ComputeSizeWithIntrinsicDimensions( |
1447 | aRenderingContext, aWM, mIntrinsicSize, GetAspectRatio(), aCBSize, |
1448 | aMargin, aBorderPadding, aSizeOverrides, aFlags), |
1449 | AspectRatioUsage::None}; |
1450 | } |
1451 | |
1452 | Element* nsImageFrame::GetMapElement() const { |
1453 | return IsForImageLoadingContent() |
1454 | ? nsImageLoadingContent::FindImageMap(mContent->AsElement()) |
1455 | : nullptr; |
1456 | } |
1457 | |
1458 | // get the offset into the content area of the image where aImg starts if it is |
1459 | // a continuation. |
1460 | nscoord nsImageFrame::GetContinuationOffset() const { |
1461 | nscoord offset = 0; |
1462 | for (nsIFrame* f = GetPrevInFlow(); f; f = f->GetPrevInFlow()) { |
1463 | offset += f->GetContentRect().height; |
1464 | } |
1465 | NS_ASSERTION(offset >= 0, "bogus GetContentRect")do { if (!(offset >= 0)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "bogus GetContentRect", "offset >= 0", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1465); MOZ_PretendNoReturn(); } } while (0); |
1466 | return offset; |
1467 | } |
1468 | |
1469 | nscoord nsImageFrame::GetMinISize(gfxContext* aRenderingContext) { |
1470 | // XXX The caller doesn't account for constraints of the block-size, |
1471 | // min-block-size, and max-block-size properties. |
1472 | EnsureIntrinsicSizeAndRatio(); |
1473 | return mIntrinsicSize.ISize(GetWritingMode()).valueOr(0); |
1474 | } |
1475 | |
1476 | nscoord nsImageFrame::GetPrefISize(gfxContext* aRenderingContext) { |
1477 | // XXX The caller doesn't account for constraints of the block-size, |
1478 | // min-block-size, and max-block-size properties. |
1479 | EnsureIntrinsicSizeAndRatio(); |
1480 | return mIntrinsicSize.ISize(GetWritingMode()).valueOr(0); |
1481 | } |
1482 | |
1483 | void nsImageFrame::ReflowChildren(nsPresContext* aPresContext, |
1484 | const ReflowInput& aReflowInput, |
1485 | const LogicalSize& aImageSize) { |
1486 | for (nsIFrame* child : mFrames) { |
1487 | ReflowOutput childDesiredSize(aReflowInput); |
1488 | WritingMode wm = GetWritingMode(); |
1489 | // Shouldn't be hard to support if we want, but why bother. |
1490 | MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType< decltype(wm == child->GetWritingMode())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(wm == child->GetWritingMode ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("wm == child->GetWritingMode()" " (" "We don't expect mismatched writing-modes in content we control" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1492); AnnotateMozCrashReason("MOZ_ASSERT" "(" "wm == child->GetWritingMode()" ") (" "We don't expect mismatched writing-modes in content we control" ")"); do { *((volatile int*)__null) = 1492; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
1491 | wm == child->GetWritingMode(),do { static_assert( mozilla::detail::AssertionConditionType< decltype(wm == child->GetWritingMode())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(wm == child->GetWritingMode ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("wm == child->GetWritingMode()" " (" "We don't expect mismatched writing-modes in content we control" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1492); AnnotateMozCrashReason("MOZ_ASSERT" "(" "wm == child->GetWritingMode()" ") (" "We don't expect mismatched writing-modes in content we control" ")"); do { *((volatile int*)__null) = 1492; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
1492 | "We don't expect mismatched writing-modes in content we control")do { static_assert( mozilla::detail::AssertionConditionType< decltype(wm == child->GetWritingMode())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(wm == child->GetWritingMode ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("wm == child->GetWritingMode()" " (" "We don't expect mismatched writing-modes in content we control" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1492); AnnotateMozCrashReason("MOZ_ASSERT" "(" "wm == child->GetWritingMode()" ") (" "We don't expect mismatched writing-modes in content we control" ")"); do { *((volatile int*)__null) = 1492; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1493 | nsReflowStatus childStatus; |
1494 | |
1495 | LogicalPoint childOffset(wm); |
1496 | ReflowInput childReflowInput(aPresContext, aReflowInput, child, aImageSize); |
1497 | const nsSize containerSize = aImageSize.GetPhysicalSize(wm); |
1498 | ReflowChild(child, aPresContext, childDesiredSize, childReflowInput, wm, |
1499 | childOffset, containerSize, ReflowChildFlags::Default, |
1500 | childStatus); |
1501 | |
1502 | FinishReflowChild(child, aPresContext, childDesiredSize, &childReflowInput, |
1503 | wm, childOffset, containerSize, |
1504 | ReflowChildFlags::Default); |
1505 | } |
1506 | } |
1507 | |
1508 | void nsImageFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics, |
1509 | const ReflowInput& aReflowInput, |
1510 | nsReflowStatus& aStatus) { |
1511 | MarkInReflow(); |
1512 | DO_GLOBAL_REFLOW_COUNT("nsImageFrame")aPresContext->CountReflows(("nsImageFrame"), (nsIFrame*)this );; |
1513 | 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/nsImageFrame.cpp" , 1513); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStatus.IsEmpty()" ") (" "Caller should pass a fresh reflow status!" ")"); do { *((volatile int*)__null) = 1513; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
1514 | NS_FRAME_TRACE(do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("enter nsImageFrame::Reflow: availSize=%d,%d" , aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight ()); } } while (0) |
1515 | NS_FRAME_TRACE_CALLS,do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("enter nsImageFrame::Reflow: availSize=%d,%d" , aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight ()); } } while (0) |
1516 | ("enter nsImageFrame::Reflow: availSize=%d,%d",do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("enter nsImageFrame::Reflow: availSize=%d,%d" , aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight ()); } } while (0) |
1517 | aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight()))do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("enter nsImageFrame::Reflow: availSize=%d,%d" , aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight ()); } } while (0); |
1518 | |
1519 | MOZ_ASSERT(HasAnyStateBits(NS_FRAME_IN_REFLOW), "frame is not in reflow")do { static_assert( mozilla::detail::AssertionConditionType< decltype(HasAnyStateBits(NS_FRAME_IN_REFLOW))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(HasAnyStateBits(NS_FRAME_IN_REFLOW )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("HasAnyStateBits(NS_FRAME_IN_REFLOW)" " (" "frame is not in reflow" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1519); AnnotateMozCrashReason("MOZ_ASSERT" "(" "HasAnyStateBits(NS_FRAME_IN_REFLOW)" ") (" "frame is not in reflow" ")"); do { *((volatile int*)__null ) = 1519; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false); |
1520 | |
1521 | // see if we have a frozen size (i.e. a fixed width and height) |
1522 | if (!SizeDependsOnIntrinsicSize(aReflowInput)) { |
1523 | AddStateBits(IMAGE_SIZECONSTRAINED); |
1524 | } else { |
1525 | RemoveStateBits(IMAGE_SIZECONSTRAINED); |
1526 | } |
1527 | |
1528 | mComputedSize = aReflowInput.ComputedPhysicalSize(); |
1529 | |
1530 | const auto wm = GetWritingMode(); |
1531 | aMetrics.SetSize(wm, aReflowInput.ComputedSizeWithBorderPadding(wm)); |
1532 | |
1533 | if (GetPrevInFlow()) { |
1534 | aMetrics.Width() = GetPrevInFlow()->GetSize().width; |
1535 | nscoord y = GetContinuationOffset(); |
1536 | aMetrics.Height() -= y + aReflowInput.ComputedPhysicalBorderPadding().top; |
1537 | aMetrics.Height() = std::max(0, aMetrics.Height()); |
1538 | } |
1539 | |
1540 | // we have to split images if we are: |
1541 | // in Paginated mode, we need to have a constrained height, and have a height |
1542 | // larger than our available height |
1543 | uint32_t loadStatus = imgIRequest::STATUS_NONE; |
1544 | if (nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest()) { |
1545 | currentRequest->GetImageStatus(&loadStatus); |
1546 | } |
1547 | |
1548 | if (aPresContext->IsPaginated() && |
1549 | ((loadStatus & imgIRequest::STATUS_SIZE_AVAILABLE) || |
1550 | HasAnyStateBits(IMAGE_SIZECONSTRAINED)) && |
1551 | NS_UNCONSTRAINEDSIZE != aReflowInput.AvailableHeight() && |
1552 | aMetrics.Height() > aReflowInput.AvailableHeight()) { |
1553 | // our desired height was greater than 0, so to avoid infinite |
1554 | // splitting, use 1 pixel as the min |
1555 | aMetrics.Height() = std::max(nsPresContext::CSSPixelsToAppUnits(1), |
1556 | aReflowInput.AvailableHeight()); |
1557 | aStatus.SetIncomplete(); |
1558 | } |
1559 | |
1560 | aMetrics.SetOverflowAreasToDesiredBounds(); |
1561 | bool imageOK = mKind != Kind::ImageLoadingContent || |
1562 | ImageOk(mContent->AsElement()->State()); |
1563 | |
1564 | // Determine if the size is available |
1565 | bool haveSize = false; |
1566 | if (loadStatus & imgIRequest::STATUS_SIZE_AVAILABLE) { |
1567 | haveSize = true; |
1568 | } |
1569 | |
1570 | if (!imageOK || !haveSize) { |
1571 | nsRect altFeedbackSize( |
1572 | 0, 0, |
1573 | nsPresContext::CSSPixelsToAppUnits( |
1574 | ICON_SIZE(16) + 2 * (ICON_PADDING(3) + ALT_BORDER_WIDTH(1))), |
1575 | nsPresContext::CSSPixelsToAppUnits( |
1576 | ICON_SIZE(16) + 2 * (ICON_PADDING(3) + ALT_BORDER_WIDTH(1)))); |
1577 | // We include the altFeedbackSize in our ink overflow, but not in our |
1578 | // scrollable overflow, since it doesn't really need to be scrolled to |
1579 | // outside the image. |
1580 | nsRect& inkOverflow = aMetrics.InkOverflow(); |
1581 | inkOverflow.UnionRect(inkOverflow, altFeedbackSize); |
1582 | } else if (PresShell()->IsActive()) { |
1583 | // We've just reflowed and we should have an accurate size, so we're ready |
1584 | // to request a decode. |
1585 | MaybeDecodeForPredictedSize(); |
1586 | } |
1587 | FinishAndStoreOverflow(&aMetrics, aReflowInput.mStyleDisplay); |
1588 | |
1589 | // Reflow the child frames. Our children can't affect our size in any way. |
1590 | ReflowChildren(aPresContext, aReflowInput, aMetrics.Size(GetWritingMode())); |
1591 | |
1592 | if (HasAnyStateBits(NS_FRAME_FIRST_REFLOW) && !mReflowCallbackPosted) { |
1593 | mReflowCallbackPosted = true; |
1594 | PresShell()->PostReflowCallback(this); |
1595 | } |
1596 | |
1597 | NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, ("exit nsImageFrame::Reflow: size=%d,%d",do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("exit nsImageFrame::Reflow: size=%d,%d" , aMetrics.Width(), aMetrics.Height()); } } while (0) |
1598 | aMetrics.Width(), aMetrics.Height()))do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("exit nsImageFrame::Reflow: size=%d,%d" , aMetrics.Width(), aMetrics.Height()); } } while (0); |
1599 | } |
1600 | |
1601 | bool nsImageFrame::ReflowFinished() { |
1602 | mReflowCallbackPosted = false; |
1603 | |
1604 | // XXX(seth): We don't need this. The purpose of updating visibility |
1605 | // synchronously is to ensure that animated images start animating |
1606 | // immediately. In the short term, however, |
1607 | // nsImageLoadingContent::OnUnlockedDraw() is enough to ensure that |
1608 | // animations start as soon as the image is painted for the first time, and in |
1609 | // the long term we want to update visibility information from the display |
1610 | // list whenever we paint, so we don't actually need to do this. However, to |
1611 | // avoid behavior changes during the transition from the old image visibility |
1612 | // code, we'll leave it in for now. |
1613 | UpdateVisibilitySynchronously(); |
1614 | |
1615 | return false; |
1616 | } |
1617 | |
1618 | void nsImageFrame::ReflowCallbackCanceled() { mReflowCallbackPosted = false; } |
1619 | |
1620 | // Computes the width of the specified string. aMaxWidth specifies the maximum |
1621 | // width available. Once this limit is reached no more characters are measured. |
1622 | // The number of characters that fit within the maximum width are returned in |
1623 | // aMaxFit. NOTE: it is assumed that the fontmetrics have already been selected |
1624 | // into the rendering context before this is called (for performance). MMP |
1625 | nscoord nsImageFrame::MeasureString(const char16_t* aString, int32_t aLength, |
1626 | nscoord aMaxWidth, uint32_t& aMaxFit, |
1627 | gfxContext& aContext, |
1628 | nsFontMetrics& aFontMetrics) { |
1629 | nscoord totalWidth = 0; |
1630 | aFontMetrics.SetTextRunRTL(false); |
1631 | nscoord spaceWidth = aFontMetrics.SpaceWidth(); |
1632 | |
1633 | aMaxFit = 0; |
1634 | while (aLength > 0) { |
1635 | // Find the next place we can line break |
1636 | uint32_t len = aLength; |
1637 | bool trailingSpace = false; |
1638 | for (int32_t i = 0; i < aLength; i++) { |
1639 | if (dom::IsSpaceCharacter(aString[i]) && (i > 0)) { |
1640 | len = i; // don't include the space when measuring |
1641 | trailingSpace = true; |
1642 | break; |
1643 | } |
1644 | } |
1645 | |
1646 | // Measure this chunk of text, and see if it fits |
1647 | nscoord width = nsLayoutUtils::AppUnitWidthOfStringBidi( |
1648 | aString, len, this, aFontMetrics, aContext); |
1649 | bool fits = (totalWidth + width) <= aMaxWidth; |
1650 | |
1651 | // If it fits on the line, or it's the first word we've processed then |
1652 | // include it |
1653 | if (fits || (0 == totalWidth)) { |
1654 | // New piece fits |
1655 | totalWidth += width; |
1656 | |
1657 | // If there's a trailing space then see if it fits as well |
1658 | if (trailingSpace) { |
1659 | if ((totalWidth + spaceWidth) <= aMaxWidth) { |
1660 | totalWidth += spaceWidth; |
1661 | } else { |
1662 | // Space won't fit. Leave it at the end but don't include it in |
1663 | // the width |
1664 | fits = false; |
1665 | } |
1666 | |
1667 | len++; |
1668 | } |
1669 | |
1670 | aMaxFit += len; |
1671 | aString += len; |
1672 | aLength -= len; |
1673 | } |
1674 | |
1675 | if (!fits) { |
1676 | break; |
1677 | } |
1678 | } |
1679 | return totalWidth; |
1680 | } |
1681 | |
1682 | // Formats the alt-text to fit within the specified rectangle. Breaks lines |
1683 | // between words if a word would extend past the edge of the rectangle |
1684 | void nsImageFrame::DisplayAltText(nsPresContext* aPresContext, |
1685 | gfxContext& aRenderingContext, |
1686 | const nsString& aAltText, |
1687 | const nsRect& aRect) { |
1688 | // Set font and color |
1689 | aRenderingContext.SetColor( |
1690 | sRGBColor::FromABGR(StyleText()->mColor.ToColor())); |
1691 | RefPtr<nsFontMetrics> fm = |
1692 | nsLayoutUtils::GetInflatedFontMetricsForFrame(this); |
1693 | |
1694 | // Format the text to display within the formatting rect |
1695 | |
1696 | nscoord maxAscent = fm->MaxAscent(); |
1697 | nscoord maxDescent = fm->MaxDescent(); |
1698 | nscoord lineHeight = fm->MaxHeight(); // line-relative, so an x-coordinate |
1699 | // length if writing mode is vertical |
1700 | |
1701 | WritingMode wm = GetWritingMode(); |
1702 | bool isVertical = wm.IsVertical(); |
1703 | |
1704 | fm->SetVertical(isVertical); |
1705 | fm->SetTextOrientation(StyleVisibility()->mTextOrientation); |
1706 | |
1707 | // XXX It would be nice if there was a way to have the font metrics tell |
1708 | // use where to break the text given a maximum width. At a minimum we need |
1709 | // to be able to get the break character... |
1710 | const char16_t* str = aAltText.get(); |
1711 | int32_t strLen = aAltText.Length(); |
1712 | nsPoint pt = wm.IsVerticalRL() ? aRect.TopRight() - nsPoint(lineHeight, 0) |
1713 | : aRect.TopLeft(); |
1714 | nscoord iSize = isVertical ? aRect.height : aRect.width; |
1715 | |
1716 | if (!aPresContext->BidiEnabled() && HasRTLChars(aAltText)) { |
1717 | aPresContext->SetBidiEnabled(); |
1718 | } |
1719 | |
1720 | // Always show the first line, even if we have to clip it below |
1721 | bool firstLine = true; |
1722 | while (strLen > 0) { |
1723 | if (!firstLine) { |
1724 | // If we've run out of space, break out of the loop |
1725 | if ((!isVertical && (pt.y + maxDescent) >= aRect.YMost()) || |
1726 | (wm.IsVerticalRL() && (pt.x + maxDescent < aRect.x)) || |
1727 | (wm.IsVerticalLR() && (pt.x + maxDescent >= aRect.XMost()))) { |
1728 | break; |
1729 | } |
1730 | } |
1731 | |
1732 | // Determine how much of the text to display on this line |
1733 | uint32_t maxFit; // number of characters that fit |
1734 | nscoord strWidth = |
1735 | MeasureString(str, strLen, iSize, maxFit, aRenderingContext, *fm); |
1736 | |
1737 | // Display the text |
1738 | nsresult rv = NS_ERROR_FAILURE; |
1739 | |
1740 | if (aPresContext->BidiEnabled()) { |
1741 | mozilla::intl::BidiEmbeddingLevel level; |
1742 | nscoord x, y; |
1743 | |
1744 | if (isVertical) { |
1745 | x = pt.x + maxDescent; |
1746 | if (wm.IsBidiLTR()) { |
1747 | y = aRect.y; |
1748 | level = mozilla::intl::BidiEmbeddingLevel::LTR(); |
1749 | } else { |
1750 | y = aRect.YMost() - strWidth; |
1751 | level = mozilla::intl::BidiEmbeddingLevel::RTL(); |
1752 | } |
1753 | } else { |
1754 | y = pt.y + maxAscent; |
1755 | if (wm.IsBidiLTR()) { |
1756 | x = aRect.x; |
1757 | level = mozilla::intl::BidiEmbeddingLevel::LTR(); |
1758 | } else { |
1759 | x = aRect.XMost() - strWidth; |
1760 | level = mozilla::intl::BidiEmbeddingLevel::RTL(); |
1761 | } |
1762 | } |
1763 | |
1764 | rv = nsBidiPresUtils::RenderText( |
1765 | str, maxFit, level, aPresContext, aRenderingContext, |
1766 | aRenderingContext.GetDrawTarget(), *fm, x, y); |
1767 | } |
1768 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
1769 | nsLayoutUtils::DrawUniDirString(str, maxFit, |
1770 | isVertical |
1771 | ? nsPoint(pt.x + maxDescent, pt.y) |
1772 | : nsPoint(pt.x, pt.y + maxAscent), |
1773 | *fm, aRenderingContext); |
1774 | } |
1775 | |
1776 | // Move to the next line |
1777 | str += maxFit; |
1778 | strLen -= maxFit; |
1779 | if (wm.IsVerticalRL()) { |
1780 | pt.x -= lineHeight; |
1781 | } else if (wm.IsVerticalLR()) { |
1782 | pt.x += lineHeight; |
1783 | } else { |
1784 | pt.y += lineHeight; |
1785 | } |
1786 | |
1787 | firstLine = false; |
1788 | } |
1789 | } |
1790 | |
1791 | struct nsRecessedBorder : public nsStyleBorder { |
1792 | explicit nsRecessedBorder(nscoord aBorderWidth) { |
1793 | for (const auto side : AllPhysicalSides()) { |
1794 | BorderColorFor(side) = StyleColor::Black(); |
1795 | mBorder.Side(side) = aBorderWidth; |
1796 | // Note: use SetBorderStyle here because we want to affect |
1797 | // mComputedBorder |
1798 | SetBorderStyle(side, StyleBorderStyle::Inset); |
1799 | } |
1800 | } |
1801 | }; |
1802 | |
1803 | class nsDisplayAltFeedback final : public nsPaintedDisplayItem { |
1804 | public: |
1805 | nsDisplayAltFeedback(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame) |
1806 | : nsPaintedDisplayItem(aBuilder, aFrame) {} |
1807 | |
1808 | nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) const final { |
1809 | *aSnap = false; |
1810 | return mFrame->InkOverflowRectRelativeToSelf() + ToReferenceFrame(); |
1811 | } |
1812 | |
1813 | void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) final { |
1814 | // Always sync decode, because these icons are UI, and since they're not |
1815 | // discardable we'll pay the price of sync decoding at most once. |
1816 | uint32_t flags = imgIContainer::FLAG_SYNC_DECODE; |
1817 | |
1818 | nsImageFrame* f = static_cast<nsImageFrame*>(mFrame); |
1819 | Unused << f->DisplayAltFeedback(*aCtx, GetPaintRect(aBuilder, aCtx), |
1820 | ToReferenceFrame(), flags); |
1821 | } |
1822 | |
1823 | bool CreateWebRenderCommands( |
1824 | mozilla::wr::DisplayListBuilder& aBuilder, |
1825 | mozilla::wr::IpcResourceUpdateQueue& aResources, |
1826 | const StackingContextHelper& aSc, |
1827 | mozilla::layers::RenderRootStateManager* aManager, |
1828 | nsDisplayListBuilder* aDisplayListBuilder) final { |
1829 | // Always sync decode, because these icons are UI, and since they're not |
1830 | // discardable we'll pay the price of sync decoding at most once. |
1831 | uint32_t flags = |
1832 | imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY; |
1833 | nsImageFrame* f = static_cast<nsImageFrame*>(mFrame); |
1834 | ImgDrawResult result = f->DisplayAltFeedbackWithoutLayer( |
1835 | this, aBuilder, aResources, aSc, aManager, aDisplayListBuilder, |
1836 | ToReferenceFrame(), flags); |
1837 | |
1838 | return result == ImgDrawResult::SUCCESS; |
1839 | } |
1840 | |
1841 | NS_DISPLAY_DECL_NAME("AltFeedback", TYPE_ALT_FEEDBACK)const char* Name() const override { return "AltFeedback"; } constexpr static DisplayItemType ItemType() { return DisplayItemType:: TYPE_ALT_FEEDBACK; } private: void* operator new(size_t aSize , nsDisplayListBuilder* aBuilder) { return aBuilder->Allocate (aSize, DisplayItemType::TYPE_ALT_FEEDBACK); } template <typename T, typename F, typename... Args> friend T* mozilla::MakeDisplayItemWithIndex ( nsDisplayListBuilder* aBuilder, F* aFrame, const uint16_t aIndex , Args&&... aArgs); public: |
1842 | }; |
1843 | |
1844 | ImgDrawResult nsImageFrame::DisplayAltFeedback(gfxContext& aRenderingContext, |
1845 | const nsRect& aDirtyRect, |
1846 | nsPoint aPt, uint32_t aFlags) { |
1847 | // Whether we draw the broken or loading icon. |
1848 | bool isLoading = mKind != Kind::ImageLoadingContent || |
1849 | ImageOk(mContent->AsElement()->State()); |
1850 | |
1851 | // Calculate the content area. |
1852 | nsRect inner = GetContentRectRelativeToSelf() + aPt; |
1853 | |
1854 | // Display a recessed one pixel border |
1855 | nscoord borderEdgeWidth = |
1856 | nsPresContext::CSSPixelsToAppUnits(ALT_BORDER_WIDTH(1)); |
1857 | |
1858 | // if inner area is empty, then make it big enough for at least the icon |
1859 | if (inner.IsEmpty()) { |
1860 | inner.SizeTo(2 * (nsPresContext::CSSPixelsToAppUnits( |
1861 | ICON_SIZE(16) + ICON_PADDING(3) + ALT_BORDER_WIDTH(1))), |
1862 | 2 * (nsPresContext::CSSPixelsToAppUnits( |
1863 | ICON_SIZE(16) + ICON_PADDING(3) + ALT_BORDER_WIDTH(1)))); |
1864 | } |
1865 | |
1866 | // Make sure we have enough room to actually render the border within |
1867 | // our frame bounds |
1868 | if ((inner.width < 2 * borderEdgeWidth) || |
1869 | (inner.height < 2 * borderEdgeWidth)) { |
1870 | return ImgDrawResult::SUCCESS; |
1871 | } |
1872 | |
1873 | // Paint the border |
1874 | if (!isLoading) { |
1875 | nsRecessedBorder recessedBorder(borderEdgeWidth); |
1876 | |
1877 | // Assert that we're not drawing a border-image here; if we were, we |
1878 | // couldn't ignore the ImgDrawResult that PaintBorderWithStyleBorder |
1879 | // returns. |
1880 | MOZ_ASSERT(recessedBorder.mBorderImageSource.IsNone())do { static_assert( mozilla::detail::AssertionConditionType< decltype(recessedBorder.mBorderImageSource.IsNone())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(recessedBorder.mBorderImageSource.IsNone()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("recessedBorder.mBorderImageSource.IsNone()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1880); AnnotateMozCrashReason("MOZ_ASSERT" "(" "recessedBorder.mBorderImageSource.IsNone()" ")"); do { *((volatile int*)__null) = 1880; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
1881 | |
1882 | Unused << nsCSSRendering::PaintBorderWithStyleBorder( |
1883 | PresContext(), aRenderingContext, this, inner, inner, recessedBorder, |
1884 | mComputedStyle, PaintBorderFlags::SyncDecodeImages); |
1885 | } |
1886 | |
1887 | // Adjust the inner rect to account for the one pixel recessed border, |
1888 | // and a six pixel padding on each edge |
1889 | inner.Deflate( |
1890 | nsPresContext::CSSPixelsToAppUnits(ICON_PADDING(3) + ALT_BORDER_WIDTH(1)), |
1891 | nsPresContext::CSSPixelsToAppUnits(ICON_PADDING(3) + ALT_BORDER_WIDTH(1))); |
1892 | if (inner.IsEmpty()) { |
1893 | return ImgDrawResult::SUCCESS; |
1894 | } |
1895 | |
1896 | DrawTarget* drawTarget = aRenderingContext.GetDrawTarget(); |
1897 | |
1898 | // Clip so we don't render outside the inner rect |
1899 | aRenderingContext.Save(); |
1900 | aRenderingContext.Clip(NSRectToSnappedRect( |
1901 | inner, PresContext()->AppUnitsPerDevPixel(), *drawTarget)); |
1902 | |
1903 | ImgDrawResult result = ImgDrawResult::SUCCESS; |
1904 | |
1905 | // Check if we should display image placeholders |
1906 | if (ShouldShowBrokenImageIcon()) { |
1907 | result = ImgDrawResult::NOT_READY; |
1908 | nscoord size = nsPresContext::CSSPixelsToAppUnits(ICON_SIZE(16)); |
1909 | imgIRequest* request = BrokenImageIcon::GetImage(this); |
1910 | |
1911 | // If we weren't previously displaying an icon, register ourselves |
1912 | // as an observer for load and animation updates and flag that we're |
1913 | // doing so now. |
1914 | if (request && !mDisplayingIcon) { |
1915 | BrokenImageIcon::AddObserver(this); |
1916 | mDisplayingIcon = true; |
1917 | } |
1918 | |
1919 | WritingMode wm = GetWritingMode(); |
1920 | bool flushRight = wm.IsPhysicalRTL(); |
1921 | |
1922 | // If the icon in question is loaded, draw it. |
1923 | uint32_t imageStatus = 0; |
1924 | if (request) request->GetImageStatus(&imageStatus); |
1925 | if (imageStatus & imgIRequest::STATUS_LOAD_COMPLETE && |
1926 | !(imageStatus & imgIRequest::STATUS_ERROR)) { |
1927 | nsCOMPtr<imgIContainer> imgCon; |
1928 | request->GetImage(getter_AddRefs(imgCon)); |
1929 | MOZ_ASSERT(imgCon, "Load complete, but no image container?")do { static_assert( mozilla::detail::AssertionConditionType< decltype(imgCon)>::isValid, "invalid assertion condition") ; if ((__builtin_expect(!!(!(!!(imgCon))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("imgCon" " (" "Load complete, but no image container?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 1929); AnnotateMozCrashReason("MOZ_ASSERT" "(" "imgCon" ") (" "Load complete, but no image container?" ")"); do { *((volatile int*)__null) = 1929; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
1930 | nsRect dest(flushRight ? inner.XMost() - size : inner.x, inner.y, size, |
1931 | size); |
1932 | result = nsLayoutUtils::DrawSingleImage( |
1933 | aRenderingContext, PresContext(), imgCon, |
1934 | nsLayoutUtils::GetSamplingFilterForFrame(this), dest, aDirtyRect, |
1935 | SVGImageContext(), aFlags); |
1936 | } |
1937 | |
1938 | // If we could not draw the icon, just draw some graffiti in the mean time. |
1939 | if (result == ImgDrawResult::NOT_READY) { |
1940 | ColorPattern color(ToDeviceColor(sRGBColor(1.f, 0.f, 0.f, 1.f))); |
1941 | |
1942 | nscoord iconXPos = flushRight ? inner.XMost() - size : inner.x; |
1943 | |
1944 | // stroked rect: |
1945 | nsRect rect(iconXPos, inner.y, size, size); |
1946 | Rect devPxRect = ToRect(nsLayoutUtils::RectToGfxRect( |
1947 | rect, PresContext()->AppUnitsPerDevPixel())); |
1948 | drawTarget->StrokeRect(devPxRect, color); |
1949 | |
1950 | // filled circle in bottom right quadrant of stroked rect: |
1951 | nscoord twoPX = nsPresContext::CSSPixelsToAppUnits(2); |
1952 | rect = nsRect(iconXPos + size / 2, inner.y + size / 2, size / 2 - twoPX, |
1953 | size / 2 - twoPX); |
1954 | devPxRect = ToRect(nsLayoutUtils::RectToGfxRect( |
1955 | rect, PresContext()->AppUnitsPerDevPixel())); |
1956 | RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder(); |
1957 | AppendEllipseToPath(builder, devPxRect.Center(), devPxRect.Size()); |
1958 | RefPtr<Path> ellipse = builder->Finish(); |
1959 | drawTarget->Fill(ellipse, color); |
1960 | } |
1961 | |
1962 | // Reduce the inner rect by the width of the icon, and leave an |
1963 | // additional ICON_PADDING pixels for padding |
1964 | int32_t paddedIconSize = |
1965 | nsPresContext::CSSPixelsToAppUnits(ICON_SIZE(16) + ICON_PADDING(3)); |
1966 | if (wm.IsVertical()) { |
1967 | inner.y += paddedIconSize; |
1968 | inner.height -= paddedIconSize; |
1969 | } else { |
1970 | if (!flushRight) { |
1971 | inner.x += paddedIconSize; |
1972 | } |
1973 | inner.width -= paddedIconSize; |
1974 | } |
1975 | } |
1976 | |
1977 | // If there's still room, display the alt-text |
1978 | if (!inner.IsEmpty()) { |
1979 | nsAutoString altText; |
1980 | nsCSSFrameConstructor::GetAlternateTextFor(*mContent->AsElement(), altText); |
1981 | DisplayAltText(PresContext(), aRenderingContext, altText, inner); |
1982 | } |
1983 | |
1984 | aRenderingContext.Restore(); |
1985 | |
1986 | return result; |
1987 | } |
1988 | |
1989 | ImgDrawResult nsImageFrame::DisplayAltFeedbackWithoutLayer( |
1990 | nsDisplayItem* aItem, mozilla::wr::DisplayListBuilder& aBuilder, |
1991 | mozilla::wr::IpcResourceUpdateQueue& aResources, |
1992 | const StackingContextHelper& aSc, |
1993 | mozilla::layers::RenderRootStateManager* aManager, |
1994 | nsDisplayListBuilder* aDisplayListBuilder, nsPoint aPt, uint32_t aFlags) { |
1995 | // Whether we draw the broken or loading icon. |
1996 | bool isLoading = mKind != Kind::ImageLoadingContent || |
1997 | ImageOk(mContent->AsElement()->State()); |
1998 | |
1999 | // Calculate the content area. |
2000 | nsRect inner = GetContentRectRelativeToSelf() + aPt; |
2001 | |
2002 | // Display a recessed one pixel border |
2003 | nscoord borderEdgeWidth = |
2004 | nsPresContext::CSSPixelsToAppUnits(ALT_BORDER_WIDTH(1)); |
2005 | |
2006 | // if inner area is empty, then make it big enough for at least the icon |
2007 | if (inner.IsEmpty()) { |
2008 | inner.SizeTo(2 * (nsPresContext::CSSPixelsToAppUnits( |
2009 | ICON_SIZE(16) + ICON_PADDING(3) + ALT_BORDER_WIDTH(1))), |
2010 | 2 * (nsPresContext::CSSPixelsToAppUnits( |
2011 | ICON_SIZE(16) + ICON_PADDING(3) + ALT_BORDER_WIDTH(1)))); |
2012 | } |
2013 | |
2014 | // Make sure we have enough room to actually render the border within |
2015 | // our frame bounds |
2016 | if ((inner.width < 2 * borderEdgeWidth) || |
2017 | (inner.height < 2 * borderEdgeWidth)) { |
2018 | return ImgDrawResult::SUCCESS; |
2019 | } |
2020 | |
2021 | // If the TextDrawTarget requires fallback we need to rollback everything we |
2022 | // may have added to the display list, but we don't find that out until the |
2023 | // end. |
2024 | bool textDrawResult = true; |
2025 | class AutoSaveRestore { |
2026 | public: |
2027 | explicit AutoSaveRestore(mozilla::wr::DisplayListBuilder& aBuilder, |
2028 | bool& aTextDrawResult) |
2029 | : mBuilder(aBuilder), mTextDrawResult(aTextDrawResult) { |
2030 | mBuilder.Save(); |
2031 | } |
2032 | ~AutoSaveRestore() { |
2033 | // If we have to use fallback for the text restore the builder and remove |
2034 | // anything else we added to the display list, we need to use fallback. |
2035 | if (mTextDrawResult) { |
2036 | mBuilder.ClearSave(); |
2037 | } else { |
2038 | mBuilder.Restore(); |
2039 | } |
2040 | } |
2041 | |
2042 | private: |
2043 | mozilla::wr::DisplayListBuilder& mBuilder; |
2044 | bool& mTextDrawResult; |
2045 | }; |
2046 | |
2047 | AutoSaveRestore autoSaveRestore(aBuilder, textDrawResult); |
2048 | |
2049 | // Paint the border |
2050 | if (!isLoading) { |
2051 | nsRecessedBorder recessedBorder(borderEdgeWidth); |
2052 | // Assert that we're not drawing a border-image here; if we were, we |
2053 | // couldn't ignore the ImgDrawResult that PaintBorderWithStyleBorder |
2054 | // returns. |
2055 | MOZ_ASSERT(recessedBorder.mBorderImageSource.IsNone())do { static_assert( mozilla::detail::AssertionConditionType< decltype(recessedBorder.mBorderImageSource.IsNone())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(recessedBorder.mBorderImageSource.IsNone()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("recessedBorder.mBorderImageSource.IsNone()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2055); AnnotateMozCrashReason("MOZ_ASSERT" "(" "recessedBorder.mBorderImageSource.IsNone()" ")"); do { *((volatile int*)__null) = 2055; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2056 | |
2057 | nsRect rect = nsRect(aPt, GetSize()); |
2058 | Unused << nsCSSRendering::CreateWebRenderCommandsForBorderWithStyleBorder( |
2059 | aItem, this, rect, aBuilder, aResources, aSc, aManager, |
2060 | aDisplayListBuilder, recessedBorder); |
2061 | } |
2062 | |
2063 | // Adjust the inner rect to account for the one pixel recessed border, |
2064 | // and a six pixel padding on each edge |
2065 | inner.Deflate( |
2066 | nsPresContext::CSSPixelsToAppUnits(ICON_PADDING(3) + ALT_BORDER_WIDTH(1)), |
2067 | nsPresContext::CSSPixelsToAppUnits(ICON_PADDING(3) + ALT_BORDER_WIDTH(1))); |
2068 | if (inner.IsEmpty()) { |
2069 | return ImgDrawResult::SUCCESS; |
2070 | } |
2071 | |
2072 | // Clip to this rect so we don't render outside the inner rect |
2073 | const auto bounds = LayoutDeviceRect::FromAppUnits( |
2074 | inner, PresContext()->AppUnitsPerDevPixel()); |
2075 | auto wrBounds = wr::ToLayoutRect(bounds); |
2076 | |
2077 | // Check if we should display image placeholders |
2078 | if (ShouldShowBrokenImageIcon()) { |
2079 | ImgDrawResult result = ImgDrawResult::NOT_READY; |
2080 | nscoord size = nsPresContext::CSSPixelsToAppUnits(ICON_SIZE(16)); |
2081 | imgIRequest* request = BrokenImageIcon::GetImage(this); |
2082 | |
2083 | // If we weren't previously displaying an icon, register ourselves |
2084 | // as an observer for load and animation updates and flag that we're |
2085 | // doing so now. |
2086 | if (request && !mDisplayingIcon) { |
2087 | BrokenImageIcon::AddObserver(this); |
2088 | mDisplayingIcon = true; |
2089 | } |
2090 | |
2091 | WritingMode wm = GetWritingMode(); |
2092 | const bool flushRight = wm.IsPhysicalRTL(); |
2093 | |
2094 | // If the icon in question is loaded, draw it. |
2095 | uint32_t imageStatus = 0; |
2096 | if (request) request->GetImageStatus(&imageStatus); |
2097 | if (imageStatus & imgIRequest::STATUS_LOAD_COMPLETE && |
2098 | !(imageStatus & imgIRequest::STATUS_ERROR)) { |
2099 | nsCOMPtr<imgIContainer> imgCon; |
2100 | request->GetImage(getter_AddRefs(imgCon)); |
2101 | MOZ_ASSERT(imgCon, "Load complete, but no image container?")do { static_assert( mozilla::detail::AssertionConditionType< decltype(imgCon)>::isValid, "invalid assertion condition") ; if ((__builtin_expect(!!(!(!!(imgCon))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("imgCon" " (" "Load complete, but no image container?" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2101); AnnotateMozCrashReason("MOZ_ASSERT" "(" "imgCon" ") (" "Load complete, but no image container?" ")"); do { *((volatile int*)__null) = 2101; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
2102 | |
2103 | nsRect dest(flushRight ? inner.XMost() - size : inner.x, inner.y, size, |
2104 | size); |
2105 | |
2106 | const int32_t factor = PresContext()->AppUnitsPerDevPixel(); |
2107 | const auto destRect = LayoutDeviceRect::FromAppUnits(dest, factor); |
2108 | |
2109 | SVGImageContext svgContext; |
2110 | Maybe<ImageIntRegion> region; |
2111 | IntSize decodeSize = |
2112 | nsLayoutUtils::ComputeImageContainerDrawingParameters( |
2113 | imgCon, this, destRect, destRect, aSc, aFlags, svgContext, |
2114 | region); |
2115 | RefPtr<image::WebRenderImageProvider> provider; |
2116 | result = imgCon->GetImageProvider(aManager->LayerManager(), decodeSize, |
2117 | svgContext, region, aFlags, |
2118 | getter_AddRefs(provider)); |
2119 | if (provider) { |
2120 | bool wrResult = aManager->CommandBuilder().PushImageProvider( |
2121 | aItem, provider, result, aBuilder, aResources, destRect, bounds); |
2122 | result &= wrResult ? ImgDrawResult::SUCCESS : ImgDrawResult::NOT_READY; |
2123 | } else { |
2124 | // We don't use &= here because we want the result to be NOT_READY so |
2125 | // the next block executes. |
2126 | result = ImgDrawResult::NOT_READY; |
2127 | } |
2128 | } |
2129 | |
2130 | // If we could not draw the icon, just draw some graffiti in the mean time. |
2131 | if (result == ImgDrawResult::NOT_READY) { |
2132 | auto color = wr::ColorF{1.0f, 0.0f, 0.0f, 1.0f}; |
2133 | bool isBackfaceVisible = !aItem->BackfaceIsHidden(); |
2134 | |
2135 | nscoord iconXPos = flushRight ? inner.XMost() - size : inner.x; |
2136 | |
2137 | // stroked rect: |
2138 | nsRect rect(iconXPos, inner.y, size, size); |
2139 | auto devPxRect = LayoutDeviceRect::FromAppUnits( |
2140 | rect, PresContext()->AppUnitsPerDevPixel()); |
2141 | auto dest = wr::ToLayoutRect(devPxRect); |
2142 | |
2143 | auto borderWidths = wr::ToBorderWidths(1.0, 1.0, 1.0, 1.0); |
2144 | wr::BorderSide side = {color, wr::BorderStyle::Solid}; |
2145 | wr::BorderSide sides[4] = {side, side, side, side}; |
2146 | Range<const wr::BorderSide> sidesRange(sides, 4); |
2147 | aBuilder.PushBorder(dest, wrBounds, isBackfaceVisible, borderWidths, |
2148 | sidesRange, wr::EmptyBorderRadius()); |
2149 | |
2150 | // filled circle in bottom right quadrant of stroked rect: |
2151 | nscoord twoPX = nsPresContext::CSSPixelsToAppUnits(2); |
2152 | rect = nsRect(iconXPos + size / 2, inner.y + size / 2, size / 2 - twoPX, |
2153 | size / 2 - twoPX); |
2154 | devPxRect = LayoutDeviceRect::FromAppUnits( |
2155 | rect, PresContext()->AppUnitsPerDevPixel()); |
2156 | dest = wr::ToLayoutRect(devPxRect); |
2157 | |
2158 | aBuilder.PushRoundedRect(dest, wrBounds, isBackfaceVisible, color); |
2159 | } |
2160 | |
2161 | // Reduce the inner rect by the width of the icon, and leave an |
2162 | // additional ICON_PADDING pixels for padding |
2163 | int32_t paddedIconSize = |
2164 | nsPresContext::CSSPixelsToAppUnits(ICON_SIZE(16) + ICON_PADDING(3)); |
2165 | if (wm.IsVertical()) { |
2166 | inner.y += paddedIconSize; |
2167 | inner.height -= paddedIconSize; |
2168 | } else { |
2169 | if (!flushRight) { |
2170 | inner.x += paddedIconSize; |
2171 | } |
2172 | inner.width -= paddedIconSize; |
2173 | } |
2174 | } |
2175 | |
2176 | // Draw text |
2177 | if (!inner.IsEmpty()) { |
2178 | RefPtr<TextDrawTarget> textDrawer = |
2179 | new TextDrawTarget(aBuilder, aResources, aSc, aManager, aItem, inner, |
2180 | /* aCallerDoesSaveRestore = */ true); |
2181 | MOZ_ASSERT(textDrawer->IsValid())do { static_assert( mozilla::detail::AssertionConditionType< decltype(textDrawer->IsValid())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(textDrawer->IsValid()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("textDrawer->IsValid()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2181); AnnotateMozCrashReason("MOZ_ASSERT" "(" "textDrawer->IsValid()" ")"); do { *((volatile int*)__null) = 2181; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2182 | if (textDrawer->IsValid()) { |
2183 | gfxContext captureCtx(textDrawer); |
2184 | |
2185 | nsAutoString altText; |
2186 | nsCSSFrameConstructor::GetAlternateTextFor(*mContent->AsElement(), |
2187 | altText); |
2188 | DisplayAltText(PresContext(), captureCtx, altText, inner); |
2189 | |
2190 | textDrawer->TerminateShadows(); |
2191 | textDrawResult = !textDrawer->CheckHasUnsupportedFeatures(); |
2192 | } |
2193 | } |
2194 | |
2195 | // Purposely ignore local DrawResult because we handled it not being success |
2196 | // already. |
2197 | return textDrawResult ? ImgDrawResult::SUCCESS : ImgDrawResult::NOT_READY; |
2198 | } |
2199 | |
2200 | // We want to sync-decode in this case, as otherwise we either need to flash |
2201 | // white while waiting to decode the new image, or paint the old image with a |
2202 | // different aspect-ratio, which would be bad as it'd be stretched. |
2203 | // |
2204 | // See bug 1589955. |
2205 | static bool OldImageHasDifferentRatio(const nsImageFrame& aFrame, |
2206 | imgIContainer& aImage, |
2207 | imgIContainer* aPrevImage) { |
2208 | if (!aPrevImage || aPrevImage == &aImage) { |
2209 | return false; |
2210 | } |
2211 | |
2212 | // If we don't depend on our intrinsic image size / ratio, we're good. |
2213 | // |
2214 | // FIXME(emilio): There's the case of the old image being painted |
2215 | // intrinsically, and src and styles changing at the same time... Maybe we |
2216 | // should keep track of the old GetPaintRect()'s ratio and the image's ratio, |
2217 | // instead of checking this bit? |
2218 | if (aFrame.HasAnyStateBits(IMAGE_SIZECONSTRAINED)) { |
2219 | return false; |
2220 | } |
2221 | |
2222 | auto currentRatio = aFrame.GetIntrinsicRatio(); |
2223 | auto oldRatio = aFrame.ComputeIntrinsicRatioForImage(aPrevImage); |
2224 | return oldRatio != currentRatio; |
2225 | } |
2226 | |
2227 | #ifdef DEBUG1 |
2228 | void nsImageFrame::AssertSyncDecodingHintIsInSync() const { |
2229 | if (!IsForImageLoadingContent()) { |
2230 | return; |
2231 | } |
2232 | nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent); |
2233 | MOZ_ASSERT(imageLoader)do { static_assert( mozilla::detail::AssertionConditionType< decltype(imageLoader)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(imageLoader))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("imageLoader", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2233); AnnotateMozCrashReason("MOZ_ASSERT" "(" "imageLoader" ")"); do { *((volatile int*)__null) = 2233; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2234 | |
2235 | // The opposite is not true, we might have some other heuristics which force |
2236 | // sync-decoding of images. |
2237 | MOZ_ASSERT_IF(imageLoader->GetSyncDecodingHint(), mForceSyncDecoding)do { if (imageLoader->GetSyncDecodingHint()) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(mForceSyncDecoding )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(mForceSyncDecoding))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("mForceSyncDecoding", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2237); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mForceSyncDecoding" ")"); do { *((volatile int*)__null) = 2237; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
2238 | } |
2239 | #endif |
2240 | |
2241 | void nsDisplayImage::Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) { |
2242 | MOZ_ASSERT(mImage)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mImage)>::isValid, "invalid assertion condition") ; if ((__builtin_expect(!!(!(!!(mImage))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mImage", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2242); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mImage" ")" ); do { *((volatile int*)__null) = 2242; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2243 | auto* frame = static_cast<nsImageFrame*>(mFrame); |
2244 | frame->AssertSyncDecodingHintIsInSync(); |
2245 | |
2246 | const bool oldImageIsDifferent = |
2247 | OldImageHasDifferentRatio(*frame, *mImage, mPrevImage); |
2248 | |
2249 | uint32_t flags = aBuilder->GetImageDecodeFlags(); |
2250 | if (aBuilder->ShouldSyncDecodeImages() || oldImageIsDifferent || |
2251 | frame->mForceSyncDecoding) { |
2252 | flags |= imgIContainer::FLAG_SYNC_DECODE; |
2253 | } |
2254 | |
2255 | ImgDrawResult result = frame->PaintImage( |
2256 | *aCtx, ToReferenceFrame(), GetPaintRect(aBuilder, aCtx), mImage, flags); |
2257 | |
2258 | if (result == ImgDrawResult::NOT_READY || |
2259 | result == ImgDrawResult::INCOMPLETE || |
2260 | result == ImgDrawResult::TEMPORARY_ERROR) { |
2261 | // If the current image failed to paint because it's still loading or |
2262 | // decoding, try painting the previous image. |
2263 | if (mPrevImage) { |
2264 | result = |
2265 | frame->PaintImage(*aCtx, ToReferenceFrame(), |
2266 | GetPaintRect(aBuilder, aCtx), mPrevImage, flags); |
2267 | } |
2268 | } |
2269 | } |
2270 | |
2271 | nsRect nsDisplayImage::GetDestRect() const { |
2272 | bool snap = true; |
2273 | const nsRect frameContentBox = GetBounds(&snap); |
2274 | nsImageFrame* imageFrame = static_cast<nsImageFrame*>(mFrame); |
2275 | return imageFrame->GetDestRect(frameContentBox); |
2276 | } |
2277 | |
2278 | nsRegion nsDisplayImage::GetOpaqueRegion(nsDisplayListBuilder* aBuilder, |
2279 | bool* aSnap) const { |
2280 | *aSnap = false; |
2281 | if (mImage && mImage->WillDrawOpaqueNow()) { |
2282 | const nsRect frameContentBox = GetBounds(aSnap); |
2283 | return GetDestRect().Intersect(frameContentBox); |
2284 | } |
2285 | return nsRegion(); |
2286 | } |
2287 | |
2288 | bool nsDisplayImage::CreateWebRenderCommands( |
2289 | mozilla::wr::DisplayListBuilder& aBuilder, |
2290 | mozilla::wr::IpcResourceUpdateQueue& aResources, |
2291 | const StackingContextHelper& aSc, RenderRootStateManager* aManager, |
2292 | nsDisplayListBuilder* aDisplayListBuilder) { |
2293 | if (!mImage) { |
2294 | return false; |
2295 | } |
2296 | |
2297 | MOZ_ASSERT(mFrame->IsImageFrame() || mFrame->IsImageControlFrame())do { static_assert( mozilla::detail::AssertionConditionType< decltype(mFrame->IsImageFrame() || mFrame->IsImageControlFrame ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(mFrame->IsImageFrame() || mFrame->IsImageControlFrame ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("mFrame->IsImageFrame() || mFrame->IsImageControlFrame()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2297); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mFrame->IsImageFrame() || mFrame->IsImageControlFrame()" ")"); do { *((volatile int*)__null) = 2297; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2298 | // Image layer doesn't support draw focus ring for image map. |
2299 | auto* frame = static_cast<nsImageFrame*>(mFrame); |
2300 | if (frame->HasImageMap()) { |
2301 | return false; |
2302 | } |
2303 | |
2304 | frame->AssertSyncDecodingHintIsInSync(); |
2305 | const bool oldImageIsDifferent = |
2306 | OldImageHasDifferentRatio(*frame, *mImage, mPrevImage); |
2307 | |
2308 | uint32_t flags = aDisplayListBuilder->GetImageDecodeFlags(); |
2309 | if (aDisplayListBuilder->ShouldSyncDecodeImages() || oldImageIsDifferent || |
2310 | frame->mForceSyncDecoding) { |
2311 | flags |= imgIContainer::FLAG_SYNC_DECODE; |
2312 | } |
2313 | if (StaticPrefs::image_svg_blob_image() && |
2314 | mImage->GetType() == imgIContainer::TYPE_VECTOR) { |
2315 | flags |= imgIContainer::FLAG_RECORD_BLOB; |
2316 | } |
2317 | |
2318 | const nsRect destAppUnits = GetDestRect(); |
2319 | const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel(); |
2320 | LayoutDeviceRect destRect( |
2321 | LayoutDeviceRect::FromAppUnits(destAppUnits, factor)); |
2322 | |
2323 | SVGImageContext svgContext; |
2324 | Maybe<ImageIntRegion> region; |
2325 | IntSize decodeSize = nsLayoutUtils::ComputeImageContainerDrawingParameters( |
2326 | mImage, mFrame, destRect, destRect, aSc, flags, svgContext, region); |
2327 | |
2328 | RefPtr<image::WebRenderImageProvider> provider; |
2329 | ImgDrawResult drawResult = |
2330 | mImage->GetImageProvider(aManager->LayerManager(), decodeSize, svgContext, |
2331 | region, flags, getter_AddRefs(provider)); |
2332 | |
2333 | if (nsCOMPtr<imgIRequest> currentRequest = frame->GetCurrentRequest()) { |
2334 | LCPHelpers::FinalizeLCPEntryForImage( |
2335 | frame->GetContent()->AsElement(), |
2336 | static_cast<imgRequestProxy*>(currentRequest.get()), |
2337 | destAppUnits - ToReferenceFrame()); |
2338 | } |
2339 | |
2340 | // While we got a container, it may not contain a fully decoded surface. If |
2341 | // that is the case, and we have an image we were previously displaying which |
2342 | // has a fully decoded surface, then we should prefer the previous image. |
2343 | bool updatePrevImage = false; |
2344 | switch (drawResult) { |
2345 | case ImgDrawResult::NOT_READY: |
2346 | case ImgDrawResult::INCOMPLETE: |
2347 | case ImgDrawResult::TEMPORARY_ERROR: |
2348 | if (mPrevImage && mPrevImage != mImage) { |
2349 | // The current image and the previous image might be switching between |
2350 | // rasterized surfaces and blob recordings, so we need to update the |
2351 | // flags appropriately. |
2352 | uint32_t prevFlags = flags; |
2353 | if (StaticPrefs::image_svg_blob_image() && |
2354 | mPrevImage->GetType() == imgIContainer::TYPE_VECTOR) { |
2355 | prevFlags |= imgIContainer::FLAG_RECORD_BLOB; |
2356 | } else { |
2357 | prevFlags &= ~imgIContainer::FLAG_RECORD_BLOB; |
2358 | } |
2359 | |
2360 | RefPtr<image::WebRenderImageProvider> prevProvider; |
2361 | ImgDrawResult prevDrawResult = mPrevImage->GetImageProvider( |
2362 | aManager->LayerManager(), decodeSize, svgContext, region, prevFlags, |
2363 | getter_AddRefs(prevProvider)); |
2364 | if (prevProvider && (prevDrawResult == ImgDrawResult::SUCCESS || |
2365 | prevDrawResult == ImgDrawResult::WRONG_SIZE)) { |
2366 | // We use WRONG_SIZE here to ensure that when the frame next tries to |
2367 | // invalidate due to a frame update from the current image, we don't |
2368 | // consider the result from the previous image to be a valid result to |
2369 | // avoid redrawing. |
2370 | drawResult = ImgDrawResult::WRONG_SIZE; |
2371 | provider = std::move(prevProvider); |
2372 | flags = prevFlags; |
2373 | break; |
2374 | } |
2375 | |
2376 | // Previous image was unusable; we can forget about it. |
2377 | updatePrevImage = true; |
2378 | } |
2379 | break; |
2380 | case ImgDrawResult::NOT_SUPPORTED: |
2381 | return false; |
2382 | default: |
2383 | updatePrevImage = mPrevImage != mImage; |
2384 | break; |
2385 | } |
2386 | |
2387 | // The previous image was not used, and is different from the current image. |
2388 | // We should forget about it. We need to update the frame as well because the |
2389 | // display item may get recreated. |
2390 | if (updatePrevImage) { |
2391 | mPrevImage = mImage; |
2392 | frame->mPrevImage = frame->mImage; |
2393 | } |
2394 | |
2395 | // If the image provider is null, we don't want to fallback. Any other |
2396 | // failure will be due to resource constraints and fallback is unlikely to |
2397 | // help us. Hence we can ignore the return value from PushImage. |
2398 | aManager->CommandBuilder().PushImageProvider( |
2399 | this, provider, drawResult, aBuilder, aResources, destRect, destRect); |
2400 | return true; |
2401 | } |
2402 | |
2403 | ImgDrawResult nsImageFrame::PaintImage(gfxContext& aRenderingContext, |
2404 | nsPoint aPt, const nsRect& aDirtyRect, |
2405 | imgIContainer* aImage, uint32_t aFlags) { |
2406 | DrawTarget* drawTarget = aRenderingContext.GetDrawTarget(); |
2407 | |
2408 | // Render the image into our content area (the area inside |
2409 | // the borders and padding) |
2410 | NS_ASSERTION(GetContentRectRelativeToSelf().width == mComputedSize.width,do { if (!(GetContentRectRelativeToSelf().width == mComputedSize .width)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "bad width", "GetContentRectRelativeToSelf().width == mComputedSize.width" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2411); MOZ_PretendNoReturn(); } } while (0) |
2411 | "bad width")do { if (!(GetContentRectRelativeToSelf().width == mComputedSize .width)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "bad width", "GetContentRectRelativeToSelf().width == mComputedSize.width" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2411); MOZ_PretendNoReturn(); } } while (0); |
2412 | |
2413 | nsPoint anchorPoint; |
2414 | nsRect dest = GetDestRect(GetContentRectRelativeToSelf() + aPt, &anchorPoint); |
2415 | |
2416 | SVGImageContext svgContext; |
2417 | SVGImageContext::MaybeStoreContextPaint(svgContext, this, aImage); |
2418 | |
2419 | ImgDrawResult result = nsLayoutUtils::DrawSingleImage( |
2420 | aRenderingContext, PresContext(), aImage, |
2421 | nsLayoutUtils::GetSamplingFilterForFrame(this), dest, aDirtyRect, |
2422 | svgContext, aFlags, &anchorPoint); |
2423 | |
2424 | if (nsImageMap* map = GetImageMap()) { |
2425 | gfxPoint devPixelOffset = nsLayoutUtils::PointToGfxPoint( |
2426 | dest.TopLeft(), PresContext()->AppUnitsPerDevPixel()); |
2427 | AutoRestoreTransform autoRestoreTransform(drawTarget); |
2428 | drawTarget->SetTransform( |
2429 | drawTarget->GetTransform().PreTranslate(ToPoint(devPixelOffset))); |
2430 | |
2431 | // solid white stroke: |
2432 | ColorPattern white(ToDeviceColor(sRGBColor::OpaqueWhite())); |
2433 | map->Draw(this, *drawTarget, white); |
2434 | |
2435 | // then dashed black stroke over the top: |
2436 | ColorPattern black(ToDeviceColor(sRGBColor::OpaqueBlack())); |
2437 | StrokeOptions strokeOptions; |
2438 | nsLayoutUtils::InitDashPattern(strokeOptions, StyleBorderStyle::Dotted); |
2439 | map->Draw(this, *drawTarget, black, strokeOptions); |
2440 | } |
2441 | |
2442 | if (result == ImgDrawResult::SUCCESS) { |
2443 | mPrevImage = aImage; |
2444 | } else if (result == ImgDrawResult::BAD_IMAGE) { |
2445 | mPrevImage = nullptr; |
2446 | } |
2447 | |
2448 | return result; |
2449 | } |
2450 | |
2451 | already_AddRefed<imgIRequest> nsImageFrame::GetCurrentRequest() const { |
2452 | if (mKind != Kind::ImageLoadingContent) { |
2453 | return do_AddRef(mOwnedRequest); |
2454 | } |
2455 | |
2456 | MOZ_ASSERT(!mOwnedRequest)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mOwnedRequest)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mOwnedRequest))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mOwnedRequest" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2456); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOwnedRequest" ")"); do { *((volatile int*)__null) = 2456; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2457 | |
2458 | nsCOMPtr<imgIRequest> request; |
2459 | nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent); |
2460 | MOZ_ASSERT(imageLoader)do { static_assert( mozilla::detail::AssertionConditionType< decltype(imageLoader)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(imageLoader))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("imageLoader", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2460); AnnotateMozCrashReason("MOZ_ASSERT" "(" "imageLoader" ")"); do { *((volatile int*)__null) = 2460; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
2461 | imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, |
2462 | getter_AddRefs(request)); |
2463 | return request.forget(); |
2464 | } |
2465 | |
2466 | void nsImageFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, |
2467 | const nsDisplayListSet& aLists) { |
2468 | if (!IsVisibleForPainting()) { |
2469 | return; |
2470 | } |
2471 | |
2472 | DisplayBorderBackgroundOutline(aBuilder, aLists); |
2473 | |
2474 | if (HidesContent()) { |
2475 | DisplaySelectionOverlay(aBuilder, aLists.Content(), |
2476 | nsISelectionDisplay::DISPLAY_IMAGES); |
2477 | return; |
2478 | } |
2479 | |
2480 | uint32_t clipFlags = |
2481 | nsStyleUtil::ObjectPropsMightCauseOverflow(StylePosition()) |
2482 | ? 0 |
2483 | : DisplayListClipState::ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT; |
2484 | |
2485 | DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox clip( |
2486 | aBuilder, this, clipFlags); |
2487 | |
2488 | if (!mComputedSize.IsEmpty()) { |
2489 | const bool imageOK = mKind != Kind::ImageLoadingContent || |
2490 | ImageOk(mContent->AsElement()->State()); |
2491 | |
2492 | nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest(); |
2493 | |
2494 | const bool isImageFromStyle = |
2495 | mKind != Kind::ImageLoadingContent && mKind != Kind::XULImage; |
2496 | const bool drawAltFeedback = [&] { |
2497 | if (!imageOK) { |
2498 | return true; |
2499 | } |
2500 | // If we're a gradient, we don't need to draw alt feedback. |
2501 | if (isImageFromStyle && !GetImageFromStyle()->IsImageRequestType()) { |
2502 | return false; |
2503 | } |
2504 | // XXX(seth): The SizeIsAvailable check here should not be necessary - the |
2505 | // intention is that a non-null mImage means we have a size, but there is |
2506 | // currently some code that violates this invariant. |
2507 | return !mImage || !SizeIsAvailable(currentRequest); |
2508 | }(); |
2509 | |
2510 | if (drawAltFeedback) { |
2511 | // No image yet, or image load failed. Draw the alt-text and an icon |
2512 | // indicating the status |
2513 | aLists.Content()->AppendNewToTop<nsDisplayAltFeedback>(aBuilder, this); |
2514 | |
2515 | // This image is visible (we are being asked to paint it) but it's not |
2516 | // decoded yet. And we are not going to ask the image to draw, so this |
2517 | // may be the only chance to tell it that it should decode. |
2518 | if (currentRequest) { |
2519 | uint32_t status = 0; |
2520 | currentRequest->GetImageStatus(&status); |
2521 | if (!(status & imgIRequest::STATUS_DECODE_COMPLETE)) { |
2522 | MaybeDecodeForPredictedSize(); |
2523 | } |
2524 | // Increase loading priority if the image is ready to be displayed. |
2525 | if (!(status & imgIRequest::STATUS_LOAD_COMPLETE)) { |
2526 | currentRequest->BoostPriority(imgIRequest::CATEGORY_DISPLAY); |
2527 | } |
2528 | } |
2529 | } else { |
2530 | if (mImage) { |
2531 | aLists.Content()->AppendNewToTop<nsDisplayImage>(aBuilder, this, mImage, |
2532 | mPrevImage); |
2533 | } else if (isImageFromStyle) { |
2534 | aLists.Content()->AppendNewToTop<nsDisplayGradient>(aBuilder, this); |
2535 | } |
2536 | |
2537 | // If we were previously displaying an icon, we're not anymore |
2538 | if (mDisplayingIcon) { |
2539 | BrokenImageIcon::RemoveObserver(this); |
2540 | mDisplayingIcon = false; |
2541 | } |
2542 | } |
2543 | } |
2544 | |
2545 | if (ShouldDisplaySelection()) { |
2546 | DisplaySelectionOverlay(aBuilder, aLists.Content(), |
2547 | nsISelectionDisplay::DISPLAY_IMAGES); |
2548 | } |
2549 | |
2550 | BuildDisplayListForNonBlockChildren(aBuilder, aLists); |
2551 | } |
2552 | |
2553 | bool nsImageFrame::ShouldDisplaySelection() { |
2554 | int16_t displaySelection = PresShell()->GetSelectionFlags(); |
2555 | if (!(displaySelection & nsISelectionDisplay::DISPLAY_IMAGES)) { |
2556 | // no need to check the blue border, we cannot be drawn selected. |
2557 | return false; |
2558 | } |
2559 | |
2560 | if (displaySelection != nsISelectionDisplay::DISPLAY_ALL) { |
2561 | return true; |
2562 | } |
2563 | |
2564 | // If the image is currently resize target of the editor, don't draw the |
2565 | // selection overlay. |
2566 | HTMLEditor* htmlEditor = nsContentUtils::GetHTMLEditor(PresContext()); |
2567 | if (!htmlEditor) { |
2568 | return true; |
2569 | } |
2570 | |
2571 | return htmlEditor->GetResizerTarget() != mContent; |
2572 | } |
2573 | |
2574 | nsImageMap* nsImageFrame::GetImageMap() { |
2575 | if (!mImageMap) { |
2576 | if (nsIContent* map = GetMapElement()) { |
2577 | mImageMap = new nsImageMap(); |
2578 | mImageMap->Init(this, map); |
2579 | } |
2580 | } |
2581 | |
2582 | return mImageMap; |
2583 | } |
2584 | |
2585 | bool nsImageFrame::IsServerImageMap() { |
2586 | return mContent->AsElement()->HasAttr(nsGkAtoms::ismap); |
2587 | } |
2588 | |
2589 | CSSIntPoint nsImageFrame::TranslateEventCoords(const nsPoint& aPoint) { |
2590 | const nsRect contentRect = GetContentRectRelativeToSelf(); |
2591 | // Subtract out border and padding here so that the coordinates are |
2592 | // now relative to the content area of this frame. |
2593 | return CSSPixel::FromAppUnitsRounded(aPoint - contentRect.TopLeft()); |
2594 | } |
2595 | |
2596 | bool nsImageFrame::GetAnchorHREFTargetAndNode(nsIURI** aHref, nsString& aTarget, |
2597 | nsIContent** aNode) { |
2598 | aTarget.Truncate(); |
2599 | *aHref = nullptr; |
2600 | *aNode = nullptr; |
2601 | |
2602 | // Walk up the content tree, looking for an nsIDOMAnchorElement |
2603 | for (nsIContent* content = mContent->GetParent(); content; |
2604 | content = content->GetParent()) { |
2605 | nsCOMPtr<dom::Link> link = do_QueryInterface(content); |
2606 | if (!link) { |
2607 | continue; |
2608 | } |
2609 | if (nsCOMPtr<nsIURI> href = link->GetURI()) { |
2610 | href.forget(aHref); |
2611 | } |
2612 | |
2613 | if (auto* anchor = HTMLAnchorElement::FromNode(content)) { |
2614 | anchor->GetLinkTarget(aTarget); |
2615 | } |
2616 | NS_ADDREF(*aNode = content)(*aNode = content)->AddRef(); |
2617 | return *aHref != nullptr; |
2618 | } |
2619 | return false; |
2620 | } |
2621 | |
2622 | bool nsImageFrame::IsLeafDynamic() const { |
2623 | if (mKind != Kind::ImageLoadingContent) { |
2624 | // Image frames created for "content: url()" could have an author-controlled |
2625 | // shadow root, we want to be a regular leaf for those. |
2626 | return true; |
2627 | } |
2628 | // For elements that create image frames, calling attachShadow() will throw, |
2629 | // so the only ShadowRoot we could ever have is a UA widget. |
2630 | const auto* shadow = mContent->AsElement()->GetShadowRoot(); |
2631 | MOZ_ASSERT_IF(shadow, shadow->IsUAWidget())do { if (shadow) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(shadow->IsUAWidget())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(shadow->IsUAWidget()))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("shadow->IsUAWidget()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2631); AnnotateMozCrashReason("MOZ_ASSERT" "(" "shadow->IsUAWidget()" ")"); do { *((volatile int*)__null) = 2631; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
2632 | return !shadow; |
2633 | } |
2634 | |
2635 | nsresult nsImageFrame::GetContentForEvent(const WidgetEvent* aEvent, |
2636 | nsIContent** aContent) { |
2637 | NS_ENSURE_ARG_POINTER(aContent)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/nsImageFrame.cpp" , 2637); return NS_ERROR_INVALID_POINTER; } } while (false); |
2638 | |
2639 | nsIFrame* f = nsLayoutUtils::GetNonGeneratedAncestor(this); |
2640 | if (f != this) { |
2641 | return f->GetContentForEvent(aEvent, aContent); |
2642 | } |
2643 | |
2644 | // XXX We need to make this special check for area element's capturing the |
2645 | // mouse due to bug 135040. Remove it once that's fixed. |
2646 | nsIContent* capturingContent = aEvent->HasMouseEventMessage() |
2647 | ? PresShell::GetCapturingContent() |
2648 | : nullptr; |
2649 | if (capturingContent && capturingContent->GetPrimaryFrame() == this) { |
2650 | *aContent = capturingContent; |
2651 | NS_IF_ADDREF(*aContent)ns_if_addref(*aContent); |
2652 | return NS_OK; |
2653 | } |
2654 | |
2655 | if (nsImageMap* map = GetImageMap()) { |
2656 | const CSSIntPoint p = TranslateEventCoords( |
2657 | nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, RelativeTo{this})); |
2658 | nsCOMPtr<nsIContent> area = map->GetArea(p); |
2659 | if (area) { |
2660 | area.forget(aContent); |
2661 | return NS_OK; |
2662 | } |
2663 | } |
2664 | |
2665 | *aContent = GetContent(); |
2666 | NS_IF_ADDREF(*aContent)ns_if_addref(*aContent); |
2667 | return NS_OK; |
2668 | } |
2669 | |
2670 | // XXX what should clicks on transparent pixels do? |
2671 | nsresult nsImageFrame::HandleEvent(nsPresContext* aPresContext, |
2672 | WidgetGUIEvent* aEvent, |
2673 | nsEventStatus* aEventStatus) { |
2674 | 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/nsImageFrame.cpp" , 2674); return NS_ERROR_INVALID_POINTER; } } while (false); |
2675 | |
2676 | if ((aEvent->mMessage == ePointerClick && |
2677 | aEvent->AsMouseEvent()->mButton == MouseButton::ePrimary) || |
2678 | aEvent->mMessage == eMouseMove) { |
2679 | nsImageMap* map = GetImageMap(); |
2680 | bool isServerMap = IsServerImageMap(); |
2681 | if (map || isServerMap) { |
2682 | CSSIntPoint p = |
2683 | TranslateEventCoords(nsLayoutUtils::GetEventCoordinatesRelativeTo( |
2684 | aEvent, RelativeTo{this})); |
2685 | |
2686 | // Even though client-side image map triggering happens |
2687 | // through content, we need to make sure we're not inside |
2688 | // (in case we deal with a case of both client-side and |
2689 | // sever-side on the same image - it happens!) |
2690 | const bool inside = map && map->GetArea(p); |
2691 | |
2692 | if (!inside && isServerMap) { |
2693 | // Server side image maps use the href in a containing anchor |
2694 | // element to provide the basis for the destination url. |
2695 | nsCOMPtr<nsIURI> uri; |
2696 | nsAutoString target; |
2697 | nsCOMPtr<nsIContent> anchorNode; |
2698 | if (GetAnchorHREFTargetAndNode(getter_AddRefs(uri), target, |
2699 | getter_AddRefs(anchorNode))) { |
2700 | // XXX if the mouse is over/clicked in the border/padding area |
2701 | // we should probably just pretend nothing happened. Nav4 |
2702 | // keeps the x,y coordinates positive as we do; IE doesn't |
2703 | // bother. Both of them send the click through even when the |
2704 | // mouse is over the border. |
2705 | if (p.x < 0) p.x = 0; |
2706 | if (p.y < 0) p.y = 0; |
2707 | |
2708 | nsAutoCString spec; |
2709 | nsresult rv = uri->GetSpec(spec); |
2710 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2710); return rv; } } while (false); |
2711 | |
2712 | spec += nsPrintfCString("?%d,%d", p.x.value, p.y.value); |
2713 | rv = NS_MutateURI(uri).SetSpec(spec).Finalize(uri); |
2714 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2714); return rv; } } while (false); |
2715 | |
2716 | bool clicked = false; |
2717 | if (aEvent->mMessage == ePointerClick && |
2718 | !aEvent->DefaultPrevented()) { |
2719 | *aEventStatus = nsEventStatus_eConsumeDoDefault; |
2720 | clicked = true; |
2721 | } |
2722 | nsContentUtils::TriggerLink(anchorNode, uri, target, clicked, |
2723 | /* isTrusted */ true); |
2724 | } |
2725 | } |
2726 | } |
2727 | } |
2728 | |
2729 | return nsAtomicContainerFrame::HandleEvent(aPresContext, aEvent, |
2730 | aEventStatus); |
2731 | } |
2732 | |
2733 | nsIFrame::Cursor nsImageFrame::GetCursor(const nsPoint& aPoint) { |
2734 | nsImageMap* map = GetImageMap(); |
2735 | if (!map) { |
2736 | return nsIFrame::GetCursor(aPoint); |
2737 | } |
2738 | const CSSIntPoint p = TranslateEventCoords(aPoint); |
2739 | HTMLAreaElement* area = map->GetArea(p); |
2740 | if (!area) { |
2741 | return nsIFrame::GetCursor(aPoint); |
2742 | } |
2743 | |
2744 | // Use the cursor from the style of the *area* element. |
2745 | RefPtr<ComputedStyle> areaStyle = |
2746 | PresShell()->StyleSet()->ResolveStyleLazily(*area); |
2747 | |
2748 | // This is one of the cases, like the <xul:tree> pseudo-style stuff, where we |
2749 | // get styles out of the blue and expect to trigger image loads for those. |
2750 | areaStyle->StartImageLoads(*PresContext()->Document()); |
2751 | |
2752 | StyleCursorKind kind = areaStyle->StyleUI()->Cursor().keyword; |
2753 | if (kind == StyleCursorKind::Auto) { |
2754 | kind = StyleCursorKind::Default; |
2755 | } |
2756 | return Cursor{kind, AllowCustomCursorImage::Yes, std::move(areaStyle)}; |
2757 | } |
2758 | |
2759 | nsresult nsImageFrame::AttributeChanged(int32_t aNameSpaceID, |
2760 | nsAtom* aAttribute, int32_t aModType) { |
2761 | nsresult rv = nsAtomicContainerFrame::AttributeChanged(aNameSpaceID, |
2762 | aAttribute, aModType); |
2763 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
2764 | return rv; |
2765 | } |
2766 | if (nsGkAtoms::alt == aAttribute) { |
2767 | PresShell()->FrameNeedsReflow( |
2768 | this, IntrinsicDirty::FrameAncestorsAndDescendants, NS_FRAME_IS_DIRTY); |
2769 | } |
2770 | if (mKind == Kind::XULImage && aAttribute == nsGkAtoms::src && |
2771 | aNameSpaceID == kNameSpaceID_None) { |
2772 | UpdateXULImage(); |
2773 | } |
2774 | return NS_OK; |
2775 | } |
2776 | |
2777 | void nsImageFrame::OnVisibilityChange( |
2778 | Visibility aNewVisibility, const Maybe<OnNonvisible>& aNonvisibleAction) { |
2779 | if (mKind == Kind::ImageLoadingContent) { |
2780 | nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent); |
2781 | imageLoader->OnVisibilityChange(aNewVisibility, aNonvisibleAction); |
2782 | } |
2783 | |
2784 | if (aNewVisibility == Visibility::ApproximatelyVisible && |
2785 | PresShell()->IsActive()) { |
2786 | MaybeDecodeForPredictedSize(); |
2787 | } |
2788 | |
2789 | nsAtomicContainerFrame::OnVisibilityChange(aNewVisibility, aNonvisibleAction); |
2790 | } |
2791 | |
2792 | #ifdef DEBUG_FRAME_DUMP1 |
2793 | nsresult nsImageFrame::GetFrameName(nsAString& aResult) const { |
2794 | return MakeFrameName(u"ImageFrame"_ns, aResult); |
2795 | } |
2796 | |
2797 | void nsImageFrame::List(FILE* out, const char* aPrefix, |
2798 | ListFlags aFlags) const { |
2799 | nsCString str; |
2800 | ListGeneric(str, aPrefix, aFlags); |
2801 | |
2802 | // output the img src url |
2803 | if (nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest()) { |
2804 | nsCOMPtr<nsIURI> uri = currentRequest->GetURI(); |
2805 | nsAutoCString uristr; |
2806 | uri->GetAsciiSpec(uristr); |
2807 | str += nsPrintfCString(" [src=%s]", uristr.get()); |
2808 | } |
2809 | fprintf_stderr(out, "%s\n", str.get()); |
2810 | } |
2811 | #endif |
2812 | |
2813 | LogicalSides nsImageFrame::GetLogicalSkipSides() const { |
2814 | LogicalSides skip(mWritingMode); |
2815 | if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak ==(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak == StyleBoxDecorationBreak::Clone), 0)) |
2816 | StyleBoxDecorationBreak::Clone)(__builtin_expect(!!(StyleBorder()->mBoxDecorationBreak == StyleBoxDecorationBreak::Clone), 0))) { |
2817 | return skip; |
2818 | } |
2819 | if (GetPrevInFlow()) { |
2820 | skip += LogicalSide::BStart; |
2821 | } |
2822 | if (GetNextInFlow()) { |
2823 | skip += LogicalSide::BEnd; |
2824 | } |
2825 | return skip; |
2826 | } |
2827 | NS_IMPL_ISUPPORTS(nsImageListener, imgINotificationObserver)MozExternalRefCountType nsImageListener::AddRef(void) { static_assert (!std::is_destructible_v<nsImageListener>, "Reference-counted class " "nsImageListener" " should not have a public destructor. " "Make this class's destructor non-public" ); do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2827); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { *((volatile int*)__null) = 2827; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsImageListener" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("nsImageListener" != nullptr ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "\"nsImageListener\" != nullptr" " (" "Must specify a name" ")" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2827); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsImageListener\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 2827; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("nsImageListener" " not thread-safe"); nsrefcnt count = ++mRefCnt; NS_LogAddRef((this), (count), ("nsImageListener" ), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType nsImageListener::Release(void) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(int32_t(mRefCnt) > 0))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2827); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { *((volatile int*)__null) = 2827 ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsImageListener" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("nsImageListener" != nullptr ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "\"nsImageListener\" != nullptr" " (" "Must specify a name" ")" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2827); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsImageListener\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 2827; __attribute__((nomerge)) ::abort(); } while (false) ; } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("nsImageListener" " not thread-safe"); const char* const nametmp = "nsImageListener"; nsrefcnt count = -- mRefCnt; NS_LogRelease((this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count ; } nsresult nsImageListener::QueryInterface(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak (NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsImageFrame.cpp" , 2827); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<nsImageListener, imgINotificationObserver >, int32_t( reinterpret_cast<char*>(static_cast<imgINotificationObserver *>((nsImageListener*)0x1000)) - reinterpret_cast<char*> ((nsImageListener*)0x1000))}, {&mozilla::detail::kImplementedIID <nsImageListener, nsISupports>, int32_t(reinterpret_cast <char*>(static_cast<nsISupports*>( static_cast< imgINotificationObserver*>((nsImageListener*)0x1000))) - reinterpret_cast <char*>((nsImageListener*)0x1000))}, { nullptr, 0 } } ; static_assert((sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface" ); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID , aInstancePtr, table); return rv; } |
2828 | |
2829 | nsImageListener::nsImageListener(nsImageFrame* aFrame) : mFrame(aFrame) {} |
2830 | |
2831 | nsImageListener::~nsImageListener() = default; |
2832 | |
2833 | void nsImageListener::Notify(imgIRequest* aRequest, int32_t aType, |
2834 | const nsIntRect* aData) { |
2835 | if (!mFrame) { |
2836 | return; |
2837 | } |
2838 | |
2839 | return mFrame->Notify(aRequest, aType, aData); |
2840 | } |
2841 | |
2842 | static bool IsInAutoWidthTableCellForQuirk(nsIFrame* aFrame) { |
2843 | if (eCompatibility_NavQuirks != aFrame->PresContext()->CompatibilityMode()) |
2844 | return false; |
2845 | // Check if the parent of the closest nsBlockFrame has auto width. |
2846 | nsBlockFrame* ancestor = nsLayoutUtils::FindNearestBlockAncestor(aFrame); |
2847 | if (ancestor->Style()->GetPseudoType() == PseudoStyleType::cellContent) { |
2848 | // Assume direct parent is a table cell frame. |
2849 | nsIFrame* grandAncestor = static_cast<nsIFrame*>(ancestor->GetParent()); |
2850 | return grandAncestor && grandAncestor->StylePosition()->mWidth.IsAuto(); |
2851 | } |
2852 | return false; |
2853 | } |
2854 | |
2855 | void nsImageFrame::AddInlineMinISize(gfxContext* aRenderingContext, |
2856 | nsIFrame::InlineMinISizeData* aData) { |
2857 | nscoord isize = nsLayoutUtils::IntrinsicForContainer( |
2858 | aRenderingContext, this, IntrinsicISizeType::MinISize); |
2859 | bool canBreak = !IsInAutoWidthTableCellForQuirk(this); |
2860 | aData->DefaultAddInlineMinISize(this, isize, canBreak); |
2861 | } |
2862 | |
2863 | void nsImageFrame::ReleaseGlobals() { BrokenImageIcon::Shutdown(); } |