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