| File: | var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp |
| Warning: | line 254, column 9 Value stored to 'subdocRootFrame' 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 | /* |
| 8 | * rendering object for replaced elements that contain a document, such |
| 9 | * as <frame>, <iframe>, and some <object>s |
| 10 | */ |
| 11 | |
| 12 | #include "nsSubDocumentFrame.h" |
| 13 | |
| 14 | #include "mozilla/ComputedStyleInlines.h" |
| 15 | #include "mozilla/Preferences.h" |
| 16 | #include "mozilla/PresShell.h" |
| 17 | #include "mozilla/ScrollContainerFrame.h" |
| 18 | #include "mozilla/StaticPrefs_layout.h" |
| 19 | #include "mozilla/Unused.h" |
| 20 | #include "mozilla/dom/Document.h" |
| 21 | #include "mozilla/dom/HTMLFrameElement.h" |
| 22 | #include "mozilla/dom/ImageDocument.h" |
| 23 | #include "mozilla/dom/BrowserParent.h" |
| 24 | #include "mozilla/dom/RemoteBrowser.h" |
| 25 | |
| 26 | #include "nsCOMPtr.h" |
| 27 | #include "nsGenericHTMLElement.h" |
| 28 | #include "nsGenericHTMLFrameElement.h" |
| 29 | #include "nsAttrValueInlines.h" |
| 30 | #include "nsIDocShell.h" |
| 31 | #include "nsIDocumentViewer.h" |
| 32 | #include "nsIContentInlines.h" |
| 33 | #include "nsPresContext.h" |
| 34 | #include "nsView.h" |
| 35 | #include "nsViewManager.h" |
| 36 | #include "nsGkAtoms.h" |
| 37 | #include "nsStyleConsts.h" |
| 38 | #include "nsStyleStruct.h" |
| 39 | #include "nsStyleStructInlines.h" |
| 40 | #include "nsFrameSetFrame.h" |
| 41 | #include "nsNameSpaceManager.h" |
| 42 | #include "nsDisplayList.h" |
| 43 | #include "nsIObjectLoadingContent.h" |
| 44 | #include "nsLayoutUtils.h" |
| 45 | #include "nsContentUtils.h" |
| 46 | #include "nsServiceManagerUtils.h" |
| 47 | #include "nsQueryObject.h" |
| 48 | #include "RetainedDisplayListBuilder.h" |
| 49 | #include "nsObjectLoadingContent.h" |
| 50 | |
| 51 | #include "mozilla/layers/WebRenderUserData.h" |
| 52 | #include "mozilla/layers/WebRenderScrollData.h" |
| 53 | #include "mozilla/layers/RenderRootStateManager.h" |
| 54 | #include "mozilla/layers/StackingContextHelper.h" // for StackingContextHelper |
| 55 | #include "mozilla/ProfilerLabels.h" |
| 56 | |
| 57 | using namespace mozilla; |
| 58 | using namespace mozilla::dom; |
| 59 | using namespace mozilla::gfx; |
| 60 | using namespace mozilla::layers; |
| 61 | |
| 62 | static Document* GetDocumentFromView(nsView* aView) { |
| 63 | MOZ_ASSERT(aView, "null view")do { static_assert( mozilla::detail::AssertionConditionType< decltype(aView)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(aView))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("aView" " (" "null view" ")" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 63); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aView" ") (" "null view" ")"); do { *((volatile int*)__null) = 63; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 64 | |
| 65 | nsViewManager* vm = aView->GetViewManager(); |
| 66 | PresShell* presShell = vm ? vm->GetPresShell() : nullptr; |
| 67 | return presShell ? presShell->GetDocument() : nullptr; |
| 68 | } |
| 69 | |
| 70 | static void PropagateIsUnderHiddenEmbedderElement(nsFrameLoader* aFrameLoader, |
| 71 | bool aValue) { |
| 72 | if (!aFrameLoader) { |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | if (BrowsingContext* bc = aFrameLoader->GetExtantBrowsingContext()) { |
| 77 | if (bc->IsUnderHiddenEmbedderElement() != aValue) { |
| 78 | Unused << bc->SetIsUnderHiddenEmbedderElement(aValue); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | nsSubDocumentFrame::nsSubDocumentFrame(ComputedStyle* aStyle, |
| 84 | nsPresContext* aPresContext) |
| 85 | : nsAtomicContainerFrame(aStyle, aPresContext, kClassID), |
| 86 | mOuterView(nullptr), |
| 87 | mInnerView(nullptr), |
| 88 | mIsInline(false), |
| 89 | mPostedReflowCallback(false), |
| 90 | mDidCreateDoc(false), |
| 91 | mCallingShow(false), |
| 92 | mIsInObjectOrEmbed(false) {} |
| 93 | |
| 94 | #ifdef ACCESSIBILITY1 |
| 95 | a11y::AccType nsSubDocumentFrame::AccessibleType() { |
| 96 | return a11y::eOuterDocType; |
| 97 | } |
| 98 | #endif |
| 99 | |
| 100 | NS_QUERYFRAME_HEAD(nsSubDocumentFrame)void* nsSubDocumentFrame ::QueryFrame(FrameIID id) const { switch (id) { |
| 101 | NS_QUERYFRAME_ENTRY(nsSubDocumentFrame)case nsSubDocumentFrame ::kFrameIID: { static_assert( std::is_same_v <nsSubDocumentFrame, nsSubDocumentFrame ::Has_NS_DECL_QUERYFRAME_TARGET >, "nsSubDocumentFrame" " must declare itself as a queryframe target" ); return const_cast<nsSubDocumentFrame*>(static_cast< const nsSubDocumentFrame*>(this)); } |
| 102 | NS_QUERYFRAME_TAIL_INHERITING(nsAtomicContainerFrame)default: break; } return nsAtomicContainerFrame ::QueryFrame( id); } |
| 103 | |
| 104 | class AsyncFrameInit : public Runnable { |
| 105 | public: |
| 106 | explicit AsyncFrameInit(nsIFrame* aFrame) |
| 107 | : mozilla::Runnable("AsyncFrameInit"), mFrame(aFrame) {} |
| 108 | NS_IMETHODvirtual nsresult Run() override { |
| 109 | AUTO_PROFILER_LABEL("AsyncFrameInit::Run", OTHER)mozilla::AutoProfilerLabel raiiObject109( "AsyncFrameInit::Run" , nullptr, JS::ProfilingCategoryPair::OTHER); |
| 110 | if (mFrame.IsAlive()) { |
| 111 | static_cast<nsSubDocumentFrame*>(mFrame.GetFrame())->ShowViewer(); |
| 112 | } |
| 113 | return NS_OK; |
| 114 | } |
| 115 | |
| 116 | private: |
| 117 | WeakFrame mFrame; |
| 118 | }; |
| 119 | |
| 120 | void nsSubDocumentFrame::Init(nsIContent* aContent, nsContainerFrame* aParent, |
| 121 | nsIFrame* aPrevInFlow) { |
| 122 | MOZ_ASSERT(aContent)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aContent)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aContent))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aContent", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 122); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aContent" ")" ); do { *((volatile int*)__null) = 122; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 123 | // determine if we are a <frame> or <iframe> |
| 124 | mIsInline = !aContent->IsHTMLElement(nsGkAtoms::frame); |
| 125 | |
| 126 | nsAtomicContainerFrame::Init(aContent, aParent, aPrevInFlow); |
| 127 | |
| 128 | // CreateView() creates this frame's view, stored in mOuterView. It needs to |
| 129 | // be created first since it's the parent of the inner view, stored in |
| 130 | // mInnerView. |
| 131 | CreateView(); |
| 132 | EnsureInnerView(); |
| 133 | |
| 134 | // Set the primary frame now so that nsDocumentViewer::FindContainerView |
| 135 | // called from within EndSwapDocShellsForViews below can find it if needed. |
| 136 | aContent->SetPrimaryFrame(this); |
| 137 | |
| 138 | // If we have a detached subdoc's root view on our frame loader, re-insert it |
| 139 | // into the view tree. This happens when we've been reframed, and ensures the |
| 140 | // presentation persists across reframes. |
| 141 | if (RefPtr<nsFrameLoader> frameloader = FrameLoader()) { |
| 142 | bool hadFrame = false; |
| 143 | nsIFrame* detachedFrame = frameloader->GetDetachedSubdocFrame(&hadFrame); |
| 144 | frameloader->SetDetachedSubdocFrame(nullptr); |
| 145 | nsView* detachedView = detachedFrame ? detachedFrame->GetView() : nullptr; |
| 146 | if (detachedView) { |
| 147 | // Restore stashed presentation. |
| 148 | InsertViewsInReverseOrder(detachedView, mInnerView); |
| 149 | EndSwapDocShellsForViews(mInnerView->GetFirstChild()); |
| 150 | } else if (hadFrame) { |
| 151 | // Presentation is for a different document, don't restore it. |
| 152 | frameloader->Hide(); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // NOTE: The frame loader might not yet be initialized yet. If it's not, the |
| 157 | // call in ShowViewer() should pick things up. |
| 158 | UpdateEmbeddedBrowsingContextDependentData(); |
| 159 | nsContentUtils::AddScriptRunner(new AsyncFrameInit(this)); |
| 160 | } |
| 161 | |
| 162 | void nsSubDocumentFrame::UpdateEmbeddedBrowsingContextDependentData() { |
| 163 | if (!mFrameLoader) { |
| 164 | return; |
| 165 | } |
| 166 | BrowsingContext* bc = mFrameLoader->GetExtantBrowsingContext(); |
| 167 | if (!bc) { |
| 168 | return; |
| 169 | } |
| 170 | mIsInObjectOrEmbed = bc->IsEmbedderTypeObjectOrEmbed(); |
| 171 | MaybeUpdateRemoteStyle(); |
| 172 | MaybeUpdateEmbedderColorScheme(); |
| 173 | PropagateIsUnderHiddenEmbedderElement( |
| 174 | PresShell()->IsUnderHiddenEmbedderElement() || |
| 175 | !StyleVisibility()->IsVisible()); |
| 176 | } |
| 177 | |
| 178 | void nsSubDocumentFrame::PropagateIsUnderHiddenEmbedderElement(bool aValue) { |
| 179 | ::PropagateIsUnderHiddenEmbedderElement(mFrameLoader, aValue); |
| 180 | } |
| 181 | |
| 182 | void nsSubDocumentFrame::ShowViewer() { |
| 183 | if (mCallingShow) { |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | RefPtr<nsFrameLoader> frameloader = FrameLoader(); |
| 188 | if (!frameloader || frameloader->IsDead()) { |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | if (!frameloader->IsRemoteFrame() && !PresContext()->IsDynamic()) { |
| 193 | // We let the printing code take care of loading the document and |
| 194 | // initializing the shell; just create the inner view for it to use. |
| 195 | (void)EnsureInnerView(); |
| 196 | } else { |
| 197 | AutoWeakFrame weakThis(this); |
| 198 | mCallingShow = true; |
| 199 | bool didCreateDoc = frameloader->Show(this); |
| 200 | if (!weakThis.IsAlive()) { |
| 201 | return; |
| 202 | } |
| 203 | mCallingShow = false; |
| 204 | mDidCreateDoc = didCreateDoc; |
| 205 | if (!HasAnyStateBits(NS_FRAME_FIRST_REFLOW)) { |
| 206 | frameloader->UpdatePositionAndSize(this); |
| 207 | } |
| 208 | if (!weakThis.IsAlive()) { |
| 209 | return; |
| 210 | } |
| 211 | UpdateEmbeddedBrowsingContextDependentData(); |
| 212 | InvalidateFrame(); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | nsIFrame* nsSubDocumentFrame::GetSubdocumentRootFrame() { |
| 217 | if (!mInnerView) return nullptr; |
| 218 | nsView* subdocView = mInnerView->GetFirstChild(); |
| 219 | return subdocView ? subdocView->GetFrame() : nullptr; |
| 220 | } |
| 221 | |
| 222 | mozilla::PresShell* nsSubDocumentFrame::GetSubdocumentPresShellForPainting( |
| 223 | uint32_t aFlags) { |
| 224 | if (!mInnerView) return nullptr; |
| 225 | |
| 226 | nsView* subdocView = mInnerView->GetFirstChild(); |
| 227 | if (!subdocView) return nullptr; |
| 228 | |
| 229 | mozilla::PresShell* presShell = nullptr; |
| 230 | |
| 231 | nsIFrame* subdocRootFrame = subdocView->GetFrame(); |
| 232 | if (subdocRootFrame) { |
| 233 | presShell = subdocRootFrame->PresShell(); |
| 234 | } |
| 235 | |
| 236 | // If painting is suppressed in the presshell, we try to look for a better |
| 237 | // presshell to use. |
| 238 | if (!presShell || (presShell->IsPaintingSuppressed() && |
| 239 | !(aFlags & IGNORE_PAINT_SUPPRESSION))) { |
| 240 | // During page transition mInnerView will sometimes have two children, the |
| 241 | // first being the new page that may not have any frame, and the second |
| 242 | // being the old page that will probably have a frame. |
| 243 | nsView* nextView = subdocView->GetNextSibling(); |
| 244 | nsIFrame* frame = nullptr; |
| 245 | if (nextView) { |
| 246 | frame = nextView->GetFrame(); |
| 247 | } |
| 248 | if (frame) { |
| 249 | mozilla::PresShell* presShellForNextView = frame->PresShell(); |
| 250 | if (!presShell || (presShellForNextView && |
| 251 | !presShellForNextView->IsPaintingSuppressed() && |
| 252 | StaticPrefs::layout_show_previous_page())) { |
| 253 | subdocView = nextView; |
| 254 | subdocRootFrame = frame; |
Value stored to 'subdocRootFrame' is never read | |
| 255 | presShell = presShellForNextView; |
| 256 | } |
| 257 | } |
| 258 | if (!presShell) { |
| 259 | // If we don't have a frame we use this roundabout way to get the pres |
| 260 | // shell. |
| 261 | if (!mFrameLoader) return nullptr; |
| 262 | nsIDocShell* docShell = mFrameLoader->GetDocShell(IgnoreErrors()); |
| 263 | if (!docShell) return nullptr; |
| 264 | presShell = docShell->GetPresShell(); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | return presShell; |
| 269 | } |
| 270 | |
| 271 | nsRect nsSubDocumentFrame::GetDestRect() { |
| 272 | nsRect rect = GetContent()->IsHTMLElement(nsGkAtoms::frame) |
| 273 | ? GetRectRelativeToSelf() |
| 274 | : GetContentRectRelativeToSelf(); |
| 275 | return GetDestRect(rect); |
| 276 | } |
| 277 | |
| 278 | nsRect nsSubDocumentFrame::GetDestRect(const nsRect& aConstraintRect) { |
| 279 | // Adjust subdocument size, according to 'object-fit' and the subdocument's |
| 280 | // intrinsic size and ratio. |
| 281 | return nsLayoutUtils::ComputeObjectDestRect( |
| 282 | aConstraintRect, ComputeIntrinsicSize(/* aIgnoreContainment = */ true), |
| 283 | GetIntrinsicRatio(), StylePosition()); |
| 284 | } |
| 285 | |
| 286 | ScreenIntSize nsSubDocumentFrame::GetSubdocumentSize() { |
| 287 | if (HasAnyStateBits(NS_FRAME_FIRST_REFLOW)) { |
| 288 | if (RefPtr<nsFrameLoader> frameloader = FrameLoader()) { |
| 289 | nsIFrame* detachedFrame = frameloader->GetDetachedSubdocFrame(); |
| 290 | if (nsView* view = detachedFrame ? detachedFrame->GetView() : nullptr) { |
| 291 | nsSize size = view->GetBounds().Size(); |
| 292 | nsPresContext* presContext = detachedFrame->PresContext(); |
| 293 | return ScreenIntSize(presContext->AppUnitsToDevPixels(size.width), |
| 294 | presContext->AppUnitsToDevPixels(size.height)); |
| 295 | } |
| 296 | } |
| 297 | // Pick some default size for now. Using 10x10 because that's what the |
| 298 | // code used to do. |
| 299 | return ScreenIntSize(10, 10); |
| 300 | } |
| 301 | |
| 302 | nsSize docSizeAppUnits = GetDestRect().Size(); |
| 303 | nsPresContext* pc = PresContext(); |
| 304 | return ScreenIntSize(pc->AppUnitsToDevPixels(docSizeAppUnits.width), |
| 305 | pc->AppUnitsToDevPixels(docSizeAppUnits.height)); |
| 306 | } |
| 307 | |
| 308 | static void WrapBackgroundColorInOwnLayer(nsDisplayListBuilder* aBuilder, |
| 309 | nsIFrame* aFrame, |
| 310 | nsDisplayList* aList) { |
| 311 | for (nsDisplayItem* item : aList->TakeItems()) { |
| 312 | if (item->GetType() == DisplayItemType::TYPE_BACKGROUND_COLOR) { |
| 313 | nsDisplayList tmpList(aBuilder); |
| 314 | tmpList.AppendToTop(item); |
| 315 | item = MakeDisplayItemWithIndex<nsDisplayOwnLayer>( |
| 316 | aBuilder, aFrame, /* aIndex = */ nsDisplayOwnLayer::OwnLayerForSubdoc, |
| 317 | &tmpList, aBuilder->CurrentActiveScrolledRoot(), |
| 318 | nsDisplayOwnLayerFlags::None, ScrollbarData{}, true, false); |
| 319 | } |
| 320 | aList->AppendToTop(item); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | void nsSubDocumentFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, |
| 325 | const nsDisplayListSet& aLists) { |
| 326 | if (!IsVisibleForPainting()) { |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | const bool forEvents = aBuilder->IsForEventDelivery(); |
| 331 | if (forEvents && Style()->PointerEvents() == StylePointerEvents::None) { |
| 332 | // If we are pointer-events:none then we don't need to HitTest background or |
| 333 | // anything else. |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | nsFrameLoader* frameLoader = FrameLoader(); |
| 338 | const bool isRemoteFrame = frameLoader && frameLoader->IsRemoteFrame(); |
| 339 | |
| 340 | nsDisplayListCollection decorations(aBuilder); |
| 341 | DisplayBorderBackgroundOutline(aBuilder, decorations); |
| 342 | if (isRemoteFrame) { |
| 343 | // Wrap background colors of <iframe>s with remote subdocuments in their |
| 344 | // own layer so we generate a ColorLayer. This is helpful for optimizing |
| 345 | // compositing; we can skip compositing the ColorLayer when the |
| 346 | // remote content is opaque. |
| 347 | WrapBackgroundColorInOwnLayer(aBuilder, this, |
| 348 | decorations.BorderBackground()); |
| 349 | } |
| 350 | decorations.MoveTo(aLists); |
| 351 | |
| 352 | if (forEvents && !ContentReactsToPointerEvents()) { |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | if (HidesContent()) { |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | // If we're passing pointer events to children then we have to descend into |
| 361 | // subdocuments no matter what, to determine which parts are transparent for |
| 362 | // hit-testing or event regions. |
| 363 | if (!mInnerView || !aBuilder->GetDescendIntoSubdocuments()) { |
| 364 | return; |
| 365 | } |
| 366 | |
| 367 | if (isRemoteFrame) { |
| 368 | // We're the subdoc for <browser remote="true"> and it has |
| 369 | // painted content. Display its shadow layer tree. |
| 370 | DisplayListClipState::AutoSaveRestore clipState(aBuilder); |
| 371 | clipState.ClipContainingBlockDescendantsToContentBox(aBuilder, this); |
| 372 | |
| 373 | aLists.Content()->AppendNewToTop<nsDisplayRemote>(aBuilder, this); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | RefPtr<mozilla::PresShell> presShell = GetSubdocumentPresShellForPainting( |
| 378 | aBuilder->IsIgnoringPaintSuppression() ? IGNORE_PAINT_SUPPRESSION : 0); |
| 379 | |
| 380 | if (!presShell) { |
| 381 | return; |
| 382 | } |
| 383 | |
| 384 | if (aBuilder->IsInFilter()) { |
| 385 | Document* outerDoc = PresShell()->GetDocument(); |
| 386 | Document* innerDoc = presShell->GetDocument(); |
| 387 | if (outerDoc && innerDoc) { |
| 388 | if (!outerDoc->NodePrincipal()->Equals(innerDoc->NodePrincipal())) { |
| 389 | outerDoc->SetUseCounter(eUseCounter_custom_FilteredCrossOriginIFrame); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | nsIFrame* subdocRootFrame = presShell->GetRootFrame(); |
| 395 | |
| 396 | nsPresContext* presContext = presShell->GetPresContext(); |
| 397 | |
| 398 | int32_t parentAPD = PresContext()->AppUnitsPerDevPixel(); |
| 399 | int32_t subdocAPD = presContext->AppUnitsPerDevPixel(); |
| 400 | |
| 401 | nsRect visible; |
| 402 | nsRect dirty; |
| 403 | bool ignoreViewportScrolling = false; |
| 404 | if (subdocRootFrame) { |
| 405 | // get the dirty rect relative to the root frame of the subdoc |
| 406 | visible = aBuilder->GetVisibleRect() + GetOffsetToCrossDoc(subdocRootFrame); |
| 407 | dirty = aBuilder->GetDirtyRect() + GetOffsetToCrossDoc(subdocRootFrame); |
| 408 | // and convert into the appunits of the subdoc |
| 409 | visible = visible.ScaleToOtherAppUnitsRoundOut(parentAPD, subdocAPD); |
| 410 | dirty = dirty.ScaleToOtherAppUnitsRoundOut(parentAPD, subdocAPD); |
| 411 | |
| 412 | if (ScrollContainerFrame* sf = presShell->GetRootScrollContainerFrame()) { |
| 413 | // Use a copy, so the rects don't get modified. |
| 414 | nsRect copyOfDirty = dirty; |
| 415 | nsRect copyOfVisible = visible; |
| 416 | // TODO(botond): Can we just axe this DecideScrollableLayer call? |
| 417 | sf->DecideScrollableLayer(aBuilder, ©OfVisible, ©OfDirty, |
| 418 | /* aSetBase = */ true); |
| 419 | |
| 420 | ignoreViewportScrolling = presShell->IgnoringViewportScrolling(); |
| 421 | } |
| 422 | |
| 423 | aBuilder->EnterPresShell(subdocRootFrame, !ContentReactsToPointerEvents()); |
| 424 | aBuilder->IncrementPresShellPaintCount(presShell); |
| 425 | } else { |
| 426 | visible = aBuilder->GetVisibleRect(); |
| 427 | dirty = aBuilder->GetDirtyRect(); |
| 428 | } |
| 429 | |
| 430 | DisplayListClipState::AutoSaveRestore clipState(aBuilder); |
| 431 | clipState.ClipContainingBlockDescendantsToContentBox(aBuilder, this); |
| 432 | |
| 433 | ScrollContainerFrame* sf = presShell->GetRootScrollContainerFrame(); |
| 434 | bool constructZoomItem = subdocRootFrame && parentAPD != subdocAPD; |
| 435 | bool needsOwnLayer = constructZoomItem || |
| 436 | presContext->IsRootContentDocumentCrossProcess() || |
| 437 | (sf && sf->IsScrollingActive()); |
| 438 | |
| 439 | nsDisplayList childItems(aBuilder); |
| 440 | |
| 441 | { |
| 442 | DisplayListClipState::AutoSaveRestore nestedClipState(aBuilder); |
| 443 | if (needsOwnLayer) { |
| 444 | // Clear current clip. There's no point in propagating it down, since |
| 445 | // the layer we will construct will be clipped by the current clip. |
| 446 | // In fact for nsDisplayZoom propagating it down would be incorrect since |
| 447 | // nsDisplayZoom changes the meaning of appunits. |
| 448 | nestedClipState.Clear(); |
| 449 | } |
| 450 | |
| 451 | // Invoke AutoBuildingDisplayList to ensure that the correct dirty rect |
| 452 | // is used to compute the visible rect if AddCanvasBackgroundColorItem |
| 453 | // creates a display item. |
| 454 | nsIFrame* frame = subdocRootFrame ? subdocRootFrame : this; |
| 455 | nsDisplayListBuilder::AutoBuildingDisplayList building(aBuilder, frame, |
| 456 | visible, dirty); |
| 457 | |
| 458 | if (subdocRootFrame) { |
| 459 | bool hasDocumentLevelListenersForApzAwareEvents = |
| 460 | gfxPlatform::AsyncPanZoomEnabled() && |
| 461 | nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(presShell); |
| 462 | |
| 463 | aBuilder->SetAncestorHasApzAwareEventHandler( |
| 464 | hasDocumentLevelListenersForApzAwareEvents); |
| 465 | subdocRootFrame->BuildDisplayListForStackingContext(aBuilder, |
| 466 | &childItems); |
| 467 | if (!aBuilder->IsForEventDelivery()) { |
| 468 | // If we are going to use a displayzoom below then any items we put |
| 469 | // under it need to have underlying frames from the subdocument. So we |
| 470 | // need to calculate the bounds based on which frame will be the |
| 471 | // underlying frame for the canvas background color item. |
| 472 | nsRect bounds = |
| 473 | GetContentRectRelativeToSelf() + aBuilder->ToReferenceFrame(this); |
| 474 | bounds = bounds.ScaleToOtherAppUnitsRoundOut(parentAPD, subdocAPD); |
| 475 | |
| 476 | // Add the canvas background color to the bottom of the list. This |
| 477 | // happens after we've built the list so that |
| 478 | // AddCanvasBackgroundColorItem can monkey with the contents if |
| 479 | // necessary. |
| 480 | presShell->AddCanvasBackgroundColorItem(aBuilder, &childItems, frame, |
| 481 | bounds, NS_RGBA(0, 0, 0, 0)((nscolor)(((0) << 24) | ((0) << 16) | ((0) << 8) | (0)))); |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | if (subdocRootFrame) { |
| 487 | aBuilder->LeavePresShell(subdocRootFrame, &childItems); |
| 488 | } |
| 489 | |
| 490 | // Generate a resolution and/or zoom item if needed. If one or both of those |
| 491 | // is created, we don't need to create a separate nsDisplaySubDocument. |
| 492 | |
| 493 | nsDisplayOwnLayerFlags flags = |
| 494 | nsDisplayOwnLayerFlags::GenerateSubdocInvalidations; |
| 495 | // If ignoreViewportScrolling is true then the top most layer we create here |
| 496 | // is going to become the scrollable layer for the root scroll frame, so we |
| 497 | // want to add nsDisplayOwnLayer::GENERATE_SCROLLABLE_LAYER to whatever layer |
| 498 | // becomes the topmost. We do this below. |
| 499 | if (constructZoomItem) { |
| 500 | nsDisplayOwnLayerFlags zoomFlags = flags; |
| 501 | if (ignoreViewportScrolling) { |
| 502 | zoomFlags |= nsDisplayOwnLayerFlags::GenerateScrollableLayer; |
| 503 | } |
| 504 | childItems.AppendNewToTop<nsDisplayZoom>(aBuilder, subdocRootFrame, this, |
| 505 | &childItems, subdocAPD, parentAPD, |
| 506 | zoomFlags); |
| 507 | |
| 508 | needsOwnLayer = false; |
| 509 | } |
| 510 | // Wrap the zoom item in the resolution item if we have both because we want |
| 511 | // the resolution scale applied on top of the app units per dev pixel |
| 512 | // conversion. |
| 513 | if (ignoreViewportScrolling) { |
| 514 | flags |= nsDisplayOwnLayerFlags::GenerateScrollableLayer; |
| 515 | } |
| 516 | |
| 517 | // We always want top level content documents to be in their own layer. |
| 518 | nsDisplaySubDocument* layerItem = MakeDisplayItem<nsDisplaySubDocument>( |
| 519 | aBuilder, subdocRootFrame ? subdocRootFrame : this, this, &childItems, |
| 520 | flags); |
| 521 | if (layerItem) { |
| 522 | childItems.AppendToTop(layerItem); |
| 523 | layerItem->SetShouldFlattenAway(!needsOwnLayer); |
| 524 | } |
| 525 | |
| 526 | if (aBuilder->IsForFrameVisibility()) { |
| 527 | // We don't add the childItems to the return list as we're dealing with them |
| 528 | // here. |
| 529 | presShell->RebuildApproximateFrameVisibilityDisplayList(childItems); |
| 530 | childItems.DeleteAll(aBuilder); |
| 531 | } else { |
| 532 | aLists.Content()->AppendToTop(&childItems); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | #ifdef DEBUG_FRAME_DUMP1 |
| 537 | void nsSubDocumentFrame::List(FILE* out, const char* aPrefix, |
| 538 | ListFlags aFlags) const { |
| 539 | nsCString str; |
| 540 | ListGeneric(str, aPrefix, aFlags); |
| 541 | fprintf_stderr(out, "%s\n", str.get()); |
| 542 | |
| 543 | if (aFlags.contains(ListFlag::TraverseSubdocumentFrames)) { |
| 544 | nsSubDocumentFrame* f = const_cast<nsSubDocumentFrame*>(this); |
| 545 | nsIFrame* subdocRootFrame = f->GetSubdocumentRootFrame(); |
| 546 | if (subdocRootFrame) { |
| 547 | nsCString pfx(aPrefix); |
| 548 | pfx += " "; |
| 549 | subdocRootFrame->List(out, pfx.get(), aFlags); |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | nsresult nsSubDocumentFrame::GetFrameName(nsAString& aResult) const { |
| 555 | return MakeFrameName(u"FrameOuter"_ns, aResult); |
| 556 | } |
| 557 | #endif |
| 558 | |
| 559 | nscoord nsSubDocumentFrame::IntrinsicISize(const IntrinsicSizeInput& aInput, |
| 560 | IntrinsicISizeType aType) { |
| 561 | // Note: when computing max-content inline size (i.e. when aType is |
| 562 | // IntrinsicISizeType::PrefISize), if the subdocument is an SVG document, then |
| 563 | // in theory we want to return the same value that SVGOuterSVGFrame does. That |
| 564 | // method has some special handling of percentage values to avoid unhelpful |
| 565 | // zero sizing in the presence of orthogonal writing modes. We don't bother |
| 566 | // with that for SVG documents in <embed> and <object>, since that special |
| 567 | // handling doesn't look up across document boundaries anyway. |
| 568 | return GetIntrinsicSize().ISize(GetWritingMode()).valueOr(0); |
| 569 | } |
| 570 | |
| 571 | /* virtual */ |
| 572 | IntrinsicSize nsSubDocumentFrame::GetIntrinsicSize() { |
| 573 | return ComputeIntrinsicSize(); |
| 574 | } |
| 575 | |
| 576 | IntrinsicSize nsSubDocumentFrame::ComputeIntrinsicSize( |
| 577 | bool aIgnoreContainment) const { |
| 578 | const auto containAxes = |
| 579 | aIgnoreContainment ? ContainSizeAxes(false, false) : GetContainSizeAxes(); |
| 580 | if (containAxes.IsBoth()) { |
| 581 | // Intrinsic size of 'contain:size' replaced elements is determined by |
| 582 | // contain-intrinsic-size. |
| 583 | return FinishIntrinsicSize(containAxes, IntrinsicSize(0, 0)); |
| 584 | } |
| 585 | |
| 586 | if (nsCOMPtr<nsIObjectLoadingContent> iolc = do_QueryInterface(mContent)) { |
| 587 | const auto* olc = static_cast<nsObjectLoadingContent*>(iolc.get()); |
| 588 | if (auto size = olc->GetSubdocumentIntrinsicSize()) { |
| 589 | // Use the intrinsic size from the child SVG document, if available. |
| 590 | return FinishIntrinsicSize(containAxes, *size); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | if (!IsInline()) { |
| 595 | return {}; // <frame> elements have no useful intrinsic size. |
| 596 | } |
| 597 | |
| 598 | if (mContent->IsXULElement()) { |
| 599 | return {}; // XUL <iframe> and <browser> have no useful intrinsic size |
| 600 | } |
| 601 | |
| 602 | // We must be an HTML <iframe>. Return fallback size. |
| 603 | return FinishIntrinsicSize(containAxes, |
| 604 | IntrinsicSize(kFallbackIntrinsicSize)); |
| 605 | } |
| 606 | |
| 607 | /* virtual */ |
| 608 | AspectRatio nsSubDocumentFrame::GetIntrinsicRatio() const { |
| 609 | // FIXME(emilio): This should probably respect contain: size and return no |
| 610 | // ratio in the case subDocRoot is non-null. Otherwise we do it by virtue of |
| 611 | // using a zero-size below and reusing GetIntrinsicSize(). |
| 612 | if (nsCOMPtr<nsIObjectLoadingContent> iolc = do_QueryInterface(mContent)) { |
| 613 | auto olc = static_cast<nsObjectLoadingContent*>(iolc.get()); |
| 614 | |
| 615 | auto ratio = olc->GetSubdocumentIntrinsicRatio(); |
| 616 | if (ratio && *ratio) { |
| 617 | // Use the intrinsic aspect ratio from the child SVG document, if |
| 618 | // available. |
| 619 | return *ratio; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | // NOTE(emilio): Even though we have an intrinsic size, we may not have an |
| 624 | // intrinsic ratio. For example `<iframe style="width: 100px">` should not |
| 625 | // shrink in the vertical axis to preserve the 300x150 ratio. |
| 626 | return nsAtomicContainerFrame::GetIntrinsicRatio(); |
| 627 | } |
| 628 | |
| 629 | /* virtual */ |
| 630 | nsIFrame::SizeComputationResult nsSubDocumentFrame::ComputeSize( |
| 631 | gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize, |
| 632 | nscoord aAvailableISize, const LogicalSize& aMargin, |
| 633 | const LogicalSize& aBorderPadding, const StyleSizeOverrides& aSizeOverrides, |
| 634 | ComputeSizeFlags aFlags) { |
| 635 | return {ComputeSizeWithIntrinsicDimensions( |
| 636 | aRenderingContext, aWM, GetIntrinsicSize(), GetAspectRatio(), |
| 637 | aCBSize, aMargin, aBorderPadding, aSizeOverrides, aFlags), |
| 638 | AspectRatioUsage::None}; |
| 639 | } |
| 640 | |
| 641 | void nsSubDocumentFrame::Reflow(nsPresContext* aPresContext, |
| 642 | ReflowOutput& aDesiredSize, |
| 643 | const ReflowInput& aReflowInput, |
| 644 | nsReflowStatus& aStatus) { |
| 645 | MarkInReflow(); |
| 646 | DO_GLOBAL_REFLOW_COUNT("nsSubDocumentFrame")aPresContext->CountReflows(("nsSubDocumentFrame"), (nsIFrame *)this);; |
| 647 | 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/nsSubDocumentFrame.cpp" , 647); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aStatus.IsEmpty()" ") (" "Caller should pass a fresh reflow status!" ")"); do { *((volatile int*)__null) = 647; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
| 648 | NS_FRAME_TRACE(do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("enter nsSubDocumentFrame::Reflow: maxSize=%d,%d" , aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight ()); } } while (0) |
| 649 | NS_FRAME_TRACE_CALLS,do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("enter nsSubDocumentFrame::Reflow: maxSize=%d,%d" , aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight ()); } } while (0) |
| 650 | ("enter nsSubDocumentFrame::Reflow: maxSize=%d,%d",do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("enter nsSubDocumentFrame::Reflow: maxSize=%d,%d" , aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight ()); } } while (0) |
| 651 | aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight()))do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("enter nsSubDocumentFrame::Reflow: maxSize=%d,%d" , aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight ()); } } while (0); |
| 652 | |
| 653 | NS_ASSERTION(aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE,do { if (!(aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained inline-size here " "thanks to the rules of reflow", "aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 655); MOZ_PretendNoReturn(); } } while (0) |
| 654 | "Shouldn't have unconstrained inline-size here "do { if (!(aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained inline-size here " "thanks to the rules of reflow", "aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 655); MOZ_PretendNoReturn(); } } while (0) |
| 655 | "thanks to the rules of reflow")do { if (!(aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained inline-size here " "thanks to the rules of reflow", "aReflowInput.ComputedISize() != NS_UNCONSTRAINEDSIZE" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 655); MOZ_PretendNoReturn(); } } while (0); |
| 656 | NS_ASSERTION(aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE,do { if (!(aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained block-size here " "thanks to ComputeAutoSize", "aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 658); MOZ_PretendNoReturn(); } } while (0) |
| 657 | "Shouldn't have unconstrained block-size here "do { if (!(aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained block-size here " "thanks to ComputeAutoSize", "aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 658); MOZ_PretendNoReturn(); } } while (0) |
| 658 | "thanks to ComputeAutoSize")do { if (!(aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Shouldn't have unconstrained block-size here " "thanks to ComputeAutoSize", "aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 658); MOZ_PretendNoReturn(); } } while (0); |
| 659 | |
| 660 | NS_ASSERTION(mContent->GetPrimaryFrame() == this, "Shouldn't happen")do { if (!(mContent->GetPrimaryFrame() == this)) { NS_DebugBreak (NS_DEBUG_ASSERTION, "Shouldn't happen", "mContent->GetPrimaryFrame() == this" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 660); MOZ_PretendNoReturn(); } } while (0); |
| 661 | |
| 662 | // XUL <iframe> or <browser>, or HTML <iframe>, <object> or <embed> |
| 663 | const auto wm = aReflowInput.GetWritingMode(); |
| 664 | aDesiredSize.SetSize(wm, aReflowInput.ComputedSizeWithBorderPadding(wm)); |
| 665 | |
| 666 | // "offset" is the offset of our content area from our frame's |
| 667 | // top-left corner. |
| 668 | nsPoint offset = nsPoint(aReflowInput.ComputedPhysicalBorderPadding().left, |
| 669 | aReflowInput.ComputedPhysicalBorderPadding().top); |
| 670 | |
| 671 | if (mInnerView) { |
| 672 | const nsMargin& bp = aReflowInput.ComputedPhysicalBorderPadding(); |
| 673 | nsSize innerSize(aDesiredSize.Width() - bp.LeftRight(), |
| 674 | aDesiredSize.Height() - bp.TopBottom()); |
| 675 | |
| 676 | // Size & position the view according to 'object-fit' & 'object-position'. |
| 677 | nsRect destRect = GetDestRect(nsRect(offset, innerSize)); |
| 678 | nsViewManager* vm = mInnerView->GetViewManager(); |
| 679 | vm->MoveViewTo(mInnerView, destRect.x, destRect.y); |
| 680 | vm->ResizeView(mInnerView, nsRect(nsPoint(0, 0), destRect.Size())); |
| 681 | } |
| 682 | |
| 683 | aDesiredSize.SetOverflowAreasToDesiredBounds(); |
| 684 | |
| 685 | FinishAndStoreOverflow(&aDesiredSize); |
| 686 | |
| 687 | if (!aPresContext->IsRootPaginatedDocument() && !mPostedReflowCallback) { |
| 688 | PresShell()->PostReflowCallback(this); |
| 689 | mPostedReflowCallback = true; |
| 690 | } |
| 691 | |
| 692 | NS_FRAME_TRACE(do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("exit nsSubDocumentFrame::Reflow: size=%d,%d status=%s" , aDesiredSize.Width(), aDesiredSize.Height(), ToString(aStatus ).c_str()); } } while (0) |
| 693 | NS_FRAME_TRACE_CALLS,do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("exit nsSubDocumentFrame::Reflow: size=%d,%d status=%s" , aDesiredSize.Width(), aDesiredSize.Height(), ToString(aStatus ).c_str()); } } while (0) |
| 694 | ("exit nsSubDocumentFrame::Reflow: size=%d,%d status=%s",do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("exit nsSubDocumentFrame::Reflow: size=%d,%d status=%s" , aDesiredSize.Width(), aDesiredSize.Height(), ToString(aStatus ).c_str()); } } while (0) |
| 695 | aDesiredSize.Width(), aDesiredSize.Height(), ToString(aStatus).c_str()))do { if ((int(((mozilla::LogModule*)(nsIFrame::sFrameLogModule ))->Level()) & (0x1))) { TraceMsg ("exit nsSubDocumentFrame::Reflow: size=%d,%d status=%s" , aDesiredSize.Width(), aDesiredSize.Height(), ToString(aStatus ).c_str()); } } while (0); |
| 696 | } |
| 697 | |
| 698 | bool nsSubDocumentFrame::ReflowFinished() { |
| 699 | mPostedReflowCallback = false; |
| 700 | nsFrameLoader* fl = FrameLoader(); |
| 701 | if (!fl) { |
| 702 | return false; |
| 703 | } |
| 704 | if (fl->IsRemoteFrame() && fl->HasRemoteBrowserBeenSized()) { |
| 705 | // For remote frames we don't need to update the size and position instantly |
| 706 | // (but we should try to do so if we haven't shown it yet). |
| 707 | return false; |
| 708 | } |
| 709 | RefPtr { fl } -> UpdatePositionAndSize(this); |
| 710 | return false; |
| 711 | } |
| 712 | |
| 713 | void nsSubDocumentFrame::ReflowCallbackCanceled() { |
| 714 | mPostedReflowCallback = false; |
| 715 | } |
| 716 | |
| 717 | nsresult nsSubDocumentFrame::AttributeChanged(int32_t aNameSpaceID, |
| 718 | nsAtom* aAttribute, |
| 719 | int32_t aModType) { |
| 720 | if (aNameSpaceID != kNameSpaceID_None) { |
| 721 | return NS_OK; |
| 722 | } |
| 723 | |
| 724 | // If the noResize attribute changes, dis/allow frame to be resized |
| 725 | if (aAttribute == nsGkAtoms::noresize) { |
| 726 | // Note that we're not doing content type checks, but that's ok -- if |
| 727 | // they'd fail we will just end up with a null framesetFrame. |
| 728 | if (mContent->GetParent()->IsHTMLElement(nsGkAtoms::frameset)) { |
| 729 | nsIFrame* parentFrame = GetParent(); |
| 730 | |
| 731 | if (parentFrame) { |
| 732 | // There is no interface for nsHTMLFramesetFrame so QI'ing to |
| 733 | // concrete class, yay! |
| 734 | nsHTMLFramesetFrame* framesetFrame = do_QueryFrame(parentFrame); |
| 735 | if (framesetFrame) { |
| 736 | framesetFrame->RecalculateBorderResize(); |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | } else if (aAttribute == nsGkAtoms::marginwidth || |
| 741 | aAttribute == nsGkAtoms::marginheight) { |
| 742 | // Notify the frameloader |
| 743 | if (RefPtr<nsFrameLoader> frameloader = FrameLoader()) { |
| 744 | frameloader->MarginsChanged(); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | return NS_OK; |
| 749 | } |
| 750 | |
| 751 | void nsSubDocumentFrame::MaybeUpdateEmbedderColorScheme() { |
| 752 | nsFrameLoader* fl = mFrameLoader.get(); |
| 753 | if (!fl) { |
| 754 | return; |
| 755 | } |
| 756 | |
| 757 | BrowsingContext* bc = fl->GetExtantBrowsingContext(); |
| 758 | if (!bc) { |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | auto ToOverride = [](ColorScheme aScheme) -> PrefersColorSchemeOverride { |
| 763 | return aScheme == ColorScheme::Dark ? PrefersColorSchemeOverride::Dark |
| 764 | : PrefersColorSchemeOverride::Light; |
| 765 | }; |
| 766 | |
| 767 | EmbedderColorSchemes schemes{ |
| 768 | ToOverride(LookAndFeel::ColorSchemeForFrame(this, ColorSchemeMode::Used)), |
| 769 | ToOverride( |
| 770 | LookAndFeel::ColorSchemeForFrame(this, ColorSchemeMode::Preferred))}; |
| 771 | if (bc->GetEmbedderColorSchemes() == schemes) { |
| 772 | return; |
| 773 | } |
| 774 | |
| 775 | Unused << bc->SetEmbedderColorSchemes(schemes); |
| 776 | } |
| 777 | |
| 778 | void nsSubDocumentFrame::MaybeUpdateRemoteStyle( |
| 779 | ComputedStyle* aOldComputedStyle) { |
| 780 | if (!mIsInObjectOrEmbed) { |
| 781 | return; |
| 782 | } |
| 783 | |
| 784 | if (aOldComputedStyle && |
| 785 | aOldComputedStyle->StyleVisibility()->mImageRendering == |
| 786 | Style()->StyleVisibility()->mImageRendering) { |
| 787 | return; |
| 788 | } |
| 789 | |
| 790 | if (!mFrameLoader) { |
| 791 | return; |
| 792 | } |
| 793 | |
| 794 | if (mFrameLoader->IsRemoteFrame()) { |
| 795 | mFrameLoader->UpdateRemoteStyle( |
| 796 | Style()->StyleVisibility()->mImageRendering); |
| 797 | return; |
| 798 | } |
| 799 | |
| 800 | BrowsingContext* context = mFrameLoader->GetExtantBrowsingContext(); |
| 801 | if (!context) { |
| 802 | return; |
| 803 | } |
| 804 | |
| 805 | Document* document = context->GetDocument(); |
| 806 | if (!document) { |
| 807 | return; |
| 808 | } |
| 809 | |
| 810 | if (document->IsImageDocument()) { |
| 811 | document->AsImageDocument()->UpdateRemoteStyle( |
| 812 | Style()->StyleVisibility()->mImageRendering); |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | void nsSubDocumentFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) { |
| 817 | nsAtomicContainerFrame::DidSetComputedStyle(aOldComputedStyle); |
| 818 | |
| 819 | MaybeUpdateEmbedderColorScheme(); |
| 820 | |
| 821 | MaybeUpdateRemoteStyle(aOldComputedStyle); |
| 822 | |
| 823 | // If this presshell has invisible ancestors, we don't need to propagate the |
| 824 | // visibility style change to the subdocument since the subdocument should |
| 825 | // have already set the IsUnderHiddenEmbedderElement flag in |
| 826 | // nsSubDocumentFrame::Init. |
| 827 | if (PresShell()->IsUnderHiddenEmbedderElement()) { |
| 828 | return; |
| 829 | } |
| 830 | |
| 831 | const bool isVisible = StyleVisibility()->IsVisible(); |
| 832 | if (!aOldComputedStyle || |
| 833 | isVisible != aOldComputedStyle->StyleVisibility()->IsVisible()) { |
| 834 | PropagateIsUnderHiddenEmbedderElement(!isVisible); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | nsIFrame* NS_NewSubDocumentFrame(PresShell* aPresShell, ComputedStyle* aStyle) { |
| 839 | return new (aPresShell) |
| 840 | nsSubDocumentFrame(aStyle, aPresShell->GetPresContext()); |
| 841 | } |
| 842 | |
| 843 | NS_IMPL_FRAMEARENA_HELPERS(nsSubDocumentFrame)void* nsSubDocumentFrame ::operator new(size_t sz, mozilla::PresShell * aShell) { return aShell->AllocateFrame(nsQueryFrame::nsSubDocumentFrame_id , sz); } |
| 844 | |
| 845 | class nsHideViewer final : public Runnable { |
| 846 | public: |
| 847 | nsHideViewer(nsIContent* aFrameElement, nsFrameLoader* aFrameLoader, |
| 848 | PresShell* aPresShell, bool aHideViewerIfFrameless) |
| 849 | : mozilla::Runnable("nsHideViewer"), |
| 850 | mFrameElement(aFrameElement), |
| 851 | mFrameLoader(aFrameLoader), |
| 852 | mPresShell(aPresShell), |
| 853 | mHideViewerIfFrameless(aHideViewerIfFrameless) { |
| 854 | NS_ASSERTION(mFrameElement, "Must have a frame element")do { if (!(mFrameElement)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Must have a frame element", "mFrameElement", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 854); MOZ_PretendNoReturn(); } } while (0); |
| 855 | NS_ASSERTION(mFrameLoader, "Must have a frame loader")do { if (!(mFrameLoader)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Must have a frame loader", "mFrameLoader", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 855); MOZ_PretendNoReturn(); } } while (0); |
| 856 | NS_ASSERTION(mPresShell, "Must have a presshell")do { if (!(mPresShell)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Must have a presshell" , "mPresShell", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 856); MOZ_PretendNoReturn(); } } while (0); |
| 857 | } |
| 858 | |
| 859 | MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODvirtual nsresult Run() override { |
| 860 | // Flush frames, to ensure any pending display:none changes are made. |
| 861 | // Note it can be unsafe to flush if we've destroyed the presentation |
| 862 | // for some other reason, like if we're shutting down. |
| 863 | // |
| 864 | // But avoid the flush if we know for sure we're away, like when we're out |
| 865 | // of the document already. |
| 866 | // |
| 867 | // FIXME(emilio): This could still be a perf footgun when removing lots of |
| 868 | // siblings where each of them cause the reframe of an ancestor which happen |
| 869 | // to contain a subdocument. |
| 870 | // |
| 871 | // We should find some way to avoid that! |
| 872 | if (!mPresShell->IsDestroying() && mFrameElement->IsInComposedDoc()) { |
| 873 | mPresShell->FlushPendingNotifications(FlushType::Frames); |
| 874 | } |
| 875 | |
| 876 | // Either the frame has been constructed by now, or it never will be, |
| 877 | // either way we want to clear the stashed views. |
| 878 | mFrameLoader->SetDetachedSubdocFrame(nullptr); |
| 879 | |
| 880 | nsSubDocumentFrame* frame = do_QueryFrame(mFrameElement->GetPrimaryFrame()); |
| 881 | if (!frame || frame->FrameLoader() != mFrameLoader) { |
| 882 | PropagateIsUnderHiddenEmbedderElement(mFrameLoader, true); |
| 883 | if (mHideViewerIfFrameless) { |
| 884 | // The frame element has no nsIFrame for the same frame loader. |
| 885 | // Hide the nsFrameLoader, which destroys the presentation. |
| 886 | mFrameLoader->Hide(); |
| 887 | } |
| 888 | } |
| 889 | return NS_OK; |
| 890 | } |
| 891 | |
| 892 | private: |
| 893 | const nsCOMPtr<nsIContent> mFrameElement; |
| 894 | const RefPtr<nsFrameLoader> mFrameLoader; |
| 895 | const RefPtr<PresShell> mPresShell; |
| 896 | const bool mHideViewerIfFrameless; |
| 897 | }; |
| 898 | |
| 899 | static nsView* BeginSwapDocShellsForViews(nsView* aSibling); |
| 900 | |
| 901 | void nsSubDocumentFrame::Destroy(DestroyContext& aContext) { |
| 902 | if (mPostedReflowCallback) { |
| 903 | PresShell()->CancelReflowCallback(this); |
| 904 | mPostedReflowCallback = false; |
| 905 | } |
| 906 | |
| 907 | // Detach the subdocument's views and stash them in the frame loader. |
| 908 | // We can then reattach them if we're being reframed (for example if |
| 909 | // the frame has been made position:fixed). |
| 910 | if (RefPtr<nsFrameLoader> frameloader = FrameLoader()) { |
| 911 | ClearDisplayItems(); |
| 912 | |
| 913 | nsView* detachedViews = |
| 914 | ::BeginSwapDocShellsForViews(mInnerView->GetFirstChild()); |
| 915 | |
| 916 | frameloader->SetDetachedSubdocFrame( |
| 917 | detachedViews ? detachedViews->GetFrame() : nullptr); |
| 918 | |
| 919 | // We call nsFrameLoader::HideViewer() in a script runner so that we can |
| 920 | // safely determine whether the frame is being reframed or destroyed. |
| 921 | nsContentUtils::AddScriptRunner(new nsHideViewer( |
| 922 | mContent, frameloader, PresShell(), (mDidCreateDoc || mCallingShow))); |
| 923 | } |
| 924 | |
| 925 | nsAtomicContainerFrame::Destroy(aContext); |
| 926 | } |
| 927 | |
| 928 | nsFrameLoader* nsSubDocumentFrame::FrameLoader() const { |
| 929 | if (mFrameLoader) { |
| 930 | return mFrameLoader; |
| 931 | } |
| 932 | |
| 933 | if (RefPtr<nsFrameLoaderOwner> loaderOwner = do_QueryObject(GetContent())) { |
| 934 | mFrameLoader = loaderOwner->GetFrameLoader(); |
| 935 | } |
| 936 | |
| 937 | return mFrameLoader; |
| 938 | } |
| 939 | |
| 940 | auto nsSubDocumentFrame::GetRemotePaintData() const -> RemoteFramePaintData { |
| 941 | if (mRetainedRemoteFrame) { |
| 942 | return *mRetainedRemoteFrame; |
| 943 | } |
| 944 | |
| 945 | RemoteFramePaintData data; |
| 946 | nsFrameLoader* fl = FrameLoader(); |
| 947 | if (!fl) { |
| 948 | return data; |
| 949 | } |
| 950 | |
| 951 | auto* rb = fl->GetRemoteBrowser(); |
| 952 | if (!rb) { |
| 953 | return data; |
| 954 | } |
| 955 | data.mLayersId = rb->GetLayersId(); |
| 956 | data.mTabId = rb->GetTabId(); |
| 957 | return data; |
| 958 | } |
| 959 | |
| 960 | void nsSubDocumentFrame::ResetFrameLoader(RetainPaintData aRetain) { |
| 961 | if (aRetain == RetainPaintData::Yes && mFrameLoader) { |
| 962 | mRetainedRemoteFrame = Some(GetRemotePaintData()); |
| 963 | } else { |
| 964 | mRetainedRemoteFrame.reset(); |
| 965 | } |
| 966 | mFrameLoader = nullptr; |
| 967 | ClearDisplayItems(); |
| 968 | nsContentUtils::AddScriptRunner(new AsyncFrameInit(this)); |
| 969 | } |
| 970 | |
| 971 | void nsSubDocumentFrame::ClearRetainedPaintData() { |
| 972 | mRetainedRemoteFrame.reset(); |
| 973 | ClearDisplayItems(); |
| 974 | InvalidateFrameSubtree(); |
| 975 | } |
| 976 | |
| 977 | // XXX this should be called ObtainDocShell or something like that, |
| 978 | // to indicate that it could have side effects |
| 979 | nsIDocShell* nsSubDocumentFrame::GetDocShell() const { |
| 980 | // How can FrameLoader() return null??? |
| 981 | if (NS_WARN_IF(!FrameLoader())NS_warn_if_impl(!FrameLoader(), "!FrameLoader()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 981)) { |
| 982 | return nullptr; |
| 983 | } |
| 984 | return mFrameLoader->GetDocShell(IgnoreErrors()); |
| 985 | } |
| 986 | |
| 987 | static void DestroyDisplayItemDataForFrames(nsIFrame* aFrame) { |
| 988 | // Destroying a WebRenderUserDataTable can cause destruction of other objects |
| 989 | // which can remove frame properties in their destructor. If we delete a frame |
| 990 | // property it runs the destructor of the stored object in the middle of |
| 991 | // updating the frame property table, so if the destruction of that object |
| 992 | // causes another update to the frame property table it would leave the frame |
| 993 | // property table in an inconsistent state. So we remove it from the table and |
| 994 | // then destroy it. (bug 1530657) |
| 995 | WebRenderUserDataTable* userDataTable = |
| 996 | aFrame->TakeProperty(WebRenderUserDataProperty::Key()); |
| 997 | if (userDataTable) { |
| 998 | for (const auto& data : userDataTable->Values()) { |
| 999 | data->RemoveFromTable(); |
| 1000 | } |
| 1001 | delete userDataTable; |
| 1002 | } |
| 1003 | |
| 1004 | for (const auto& childList : aFrame->ChildLists()) { |
| 1005 | for (nsIFrame* child : childList.mList) { |
| 1006 | DestroyDisplayItemDataForFrames(child); |
| 1007 | } |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | static CallState BeginSwapDocShellsForDocument(Document& aDocument) { |
| 1012 | if (PresShell* presShell = aDocument.GetPresShell()) { |
| 1013 | // Disable painting while the views are detached, see bug 946929. |
| 1014 | presShell->SetNeverPainting(true); |
| 1015 | |
| 1016 | if (nsIFrame* rootFrame = presShell->GetRootFrame()) { |
| 1017 | ::DestroyDisplayItemDataForFrames(rootFrame); |
| 1018 | } |
| 1019 | } |
| 1020 | aDocument.EnumerateSubDocuments(BeginSwapDocShellsForDocument); |
| 1021 | return CallState::Continue; |
| 1022 | } |
| 1023 | |
| 1024 | static nsView* BeginSwapDocShellsForViews(nsView* aSibling) { |
| 1025 | // Collect the removed sibling views in reverse order in 'removedViews'. |
| 1026 | nsView* removedViews = nullptr; |
| 1027 | while (aSibling) { |
| 1028 | if (Document* doc = ::GetDocumentFromView(aSibling)) { |
| 1029 | ::BeginSwapDocShellsForDocument(*doc); |
| 1030 | } |
| 1031 | nsView* next = aSibling->GetNextSibling(); |
| 1032 | aSibling->GetViewManager()->RemoveChild(aSibling); |
| 1033 | aSibling->SetNextSibling(removedViews); |
| 1034 | removedViews = aSibling; |
| 1035 | aSibling = next; |
| 1036 | } |
| 1037 | return removedViews; |
| 1038 | } |
| 1039 | |
| 1040 | /* static */ |
| 1041 | void nsSubDocumentFrame::InsertViewsInReverseOrder(nsView* aSibling, |
| 1042 | nsView* aParent) { |
| 1043 | MOZ_ASSERT(aParent, "null view")do { static_assert( mozilla::detail::AssertionConditionType< decltype(aParent)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aParent))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aParent" " (" "null view" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 1043); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aParent" ") (" "null view" ")"); do { *((volatile int*)__null) = 1043; __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false); |
| 1044 | MOZ_ASSERT(!aParent->GetFirstChild(), "inserting into non-empty list")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!aParent->GetFirstChild())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!aParent->GetFirstChild() ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "!aParent->GetFirstChild()" " (" "inserting into non-empty list" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 1044); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aParent->GetFirstChild()" ") (" "inserting into non-empty list" ")"); do { *((volatile int*)__null) = 1044; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 1045 | |
| 1046 | nsViewManager* vm = aParent->GetViewManager(); |
| 1047 | while (aSibling) { |
| 1048 | nsView* next = aSibling->GetNextSibling(); |
| 1049 | aSibling->SetNextSibling(nullptr); |
| 1050 | // true means 'after' in document order which is 'before' in view order, |
| 1051 | // so this call prepends the child, thus reversing the siblings as we go. |
| 1052 | vm->InsertChild(aParent, aSibling, nullptr, true); |
| 1053 | aSibling = next; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | nsresult nsSubDocumentFrame::BeginSwapDocShells(nsIFrame* aOther) { |
| 1058 | if (!aOther || !aOther->IsSubDocumentFrame()) { |
| 1059 | return NS_ERROR_NOT_IMPLEMENTED; |
| 1060 | } |
| 1061 | |
| 1062 | nsSubDocumentFrame* other = static_cast<nsSubDocumentFrame*>(aOther); |
| 1063 | if (!mFrameLoader || !mDidCreateDoc || mCallingShow || !other->mFrameLoader || |
| 1064 | !other->mDidCreateDoc) { |
| 1065 | return NS_ERROR_NOT_IMPLEMENTED; |
| 1066 | } |
| 1067 | |
| 1068 | ClearDisplayItems(); |
| 1069 | other->ClearDisplayItems(); |
| 1070 | |
| 1071 | if (mInnerView && other->mInnerView) { |
| 1072 | nsView* ourSubdocViews = mInnerView->GetFirstChild(); |
| 1073 | nsView* ourRemovedViews = ::BeginSwapDocShellsForViews(ourSubdocViews); |
| 1074 | nsView* otherSubdocViews = other->mInnerView->GetFirstChild(); |
| 1075 | nsView* otherRemovedViews = ::BeginSwapDocShellsForViews(otherSubdocViews); |
| 1076 | |
| 1077 | InsertViewsInReverseOrder(ourRemovedViews, other->mInnerView); |
| 1078 | InsertViewsInReverseOrder(otherRemovedViews, mInnerView); |
| 1079 | } |
| 1080 | mFrameLoader.swap(other->mFrameLoader); |
| 1081 | return NS_OK; |
| 1082 | } |
| 1083 | |
| 1084 | static CallState EndSwapDocShellsForDocument(Document& aDocument) { |
| 1085 | // Our docshell and view trees have been updated for the new hierarchy. |
| 1086 | // Now also update all nsDeviceContext::mWidget to that of the |
| 1087 | // container view in the new hierarchy. |
| 1088 | if (nsCOMPtr<nsIDocShell> ds = aDocument.GetDocShell()) { |
| 1089 | nsCOMPtr<nsIDocumentViewer> viewer; |
| 1090 | ds->GetDocViewer(getter_AddRefs(viewer)); |
| 1091 | while (viewer) { |
| 1092 | RefPtr<nsPresContext> pc = viewer->GetPresContext(); |
| 1093 | if (pc && pc->GetPresShell()) { |
| 1094 | pc->GetPresShell()->SetNeverPainting(ds->IsInvisible()); |
| 1095 | } |
| 1096 | nsDeviceContext* dc = pc ? pc->DeviceContext() : nullptr; |
| 1097 | if (dc) { |
| 1098 | nsView* v = viewer->FindContainerView(); |
| 1099 | dc->Init(v ? v->GetNearestWidget(nullptr) : nullptr); |
| 1100 | } |
| 1101 | viewer = viewer->GetPreviousViewer(); |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | aDocument.EnumerateSubDocuments(EndSwapDocShellsForDocument); |
| 1106 | return CallState::Continue; |
| 1107 | } |
| 1108 | |
| 1109 | /* static */ |
| 1110 | void nsSubDocumentFrame::EndSwapDocShellsForViews(nsView* aSibling) { |
| 1111 | for (; aSibling; aSibling = aSibling->GetNextSibling()) { |
| 1112 | if (Document* doc = ::GetDocumentFromView(aSibling)) { |
| 1113 | ::EndSwapDocShellsForDocument(*doc); |
| 1114 | } |
| 1115 | nsIFrame* frame = aSibling->GetFrame(); |
| 1116 | if (frame) { |
| 1117 | nsIFrame* parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(frame); |
| 1118 | if (parent->HasAnyStateBits(NS_FRAME_IN_POPUP)) { |
| 1119 | nsIFrame::AddInPopupStateBitToDescendants(frame); |
| 1120 | } else { |
| 1121 | nsIFrame::RemoveInPopupStateBitFromDescendants(frame); |
| 1122 | } |
| 1123 | if (frame->HasInvalidFrameInSubtree()) { |
| 1124 | while (parent && |
| 1125 | !parent->HasAnyStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT | |
| 1126 | NS_FRAME_IS_NONDISPLAY)) { |
| 1127 | parent->AddStateBits(NS_FRAME_DESCENDANT_NEEDS_PAINT); |
| 1128 | parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(parent); |
| 1129 | } |
| 1130 | } |
| 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | void nsSubDocumentFrame::EndSwapDocShells(nsIFrame* aOther) { |
| 1136 | nsSubDocumentFrame* other = static_cast<nsSubDocumentFrame*>(aOther); |
| 1137 | AutoWeakFrame weakThis(this); |
| 1138 | AutoWeakFrame weakOther(aOther); |
| 1139 | |
| 1140 | if (mInnerView) { |
| 1141 | EndSwapDocShellsForViews(mInnerView->GetFirstChild()); |
| 1142 | } |
| 1143 | if (other->mInnerView) { |
| 1144 | EndSwapDocShellsForViews(other->mInnerView->GetFirstChild()); |
| 1145 | } |
| 1146 | |
| 1147 | // Now make sure we reflow both frames, in case their contents |
| 1148 | // determine their size. |
| 1149 | // And repaint them, for good measure, in case there's nothing |
| 1150 | // interesting that happens during reflow. |
| 1151 | if (weakThis.IsAlive()) { |
| 1152 | PresShell()->FrameNeedsReflow(this, IntrinsicDirty::FrameAndAncestors, |
| 1153 | NS_FRAME_IS_DIRTY); |
| 1154 | InvalidateFrameSubtree(); |
| 1155 | PropagateIsUnderHiddenEmbedderElement( |
| 1156 | PresShell()->IsUnderHiddenEmbedderElement() || |
| 1157 | !StyleVisibility()->IsVisible()); |
| 1158 | } |
| 1159 | if (weakOther.IsAlive()) { |
| 1160 | other->PresShell()->FrameNeedsReflow( |
| 1161 | other, IntrinsicDirty::FrameAndAncestors, NS_FRAME_IS_DIRTY); |
| 1162 | other->InvalidateFrameSubtree(); |
| 1163 | other->PropagateIsUnderHiddenEmbedderElement( |
| 1164 | other->PresShell()->IsUnderHiddenEmbedderElement() || |
| 1165 | !other->StyleVisibility()->IsVisible()); |
| 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | void nsSubDocumentFrame::ClearDisplayItems() { |
| 1170 | if (auto* builder = nsLayoutUtils::GetRetainedDisplayListBuilder(this)) { |
| 1171 | DL_LOGD("nsSubDocumentFrame::ClearDisplayItems() %p", this)do { const ::mozilla::LogModule* moz_real_module = GetLoggerByProcess (); if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , LogLevel::Debug)), 0))) { mozilla::detail::log_print(moz_real_module , LogLevel::Debug, "nsSubDocumentFrame::ClearDisplayItems() %p" , this); } } while (0); |
| 1172 | builder->ClearRetainedData(); |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | nsView* nsSubDocumentFrame::EnsureInnerView() { |
| 1177 | if (mInnerView) { |
| 1178 | return mInnerView; |
| 1179 | } |
| 1180 | |
| 1181 | // create, init, set the parent of the view |
| 1182 | nsView* outerView = GetView(); |
| 1183 | NS_ASSERTION(outerView, "Must have an outer view already")do { if (!(outerView)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Must have an outer view already" , "outerView", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 1183); MOZ_PretendNoReturn(); } } while (0); |
| 1184 | nsRect viewBounds(0, 0, 0, 0); // size will be fixed during reflow |
| 1185 | |
| 1186 | nsViewManager* viewMan = outerView->GetViewManager(); |
| 1187 | nsView* innerView = viewMan->CreateView(viewBounds, outerView); |
| 1188 | if (!innerView) { |
| 1189 | NS_ERROR("Could not create inner view")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "Could not create inner view" , "Error", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 1189); MOZ_PretendNoReturn(); } while (0); |
| 1190 | return nullptr; |
| 1191 | } |
| 1192 | mInnerView = innerView; |
| 1193 | viewMan->InsertChild(outerView, innerView, nullptr, true); |
| 1194 | |
| 1195 | return mInnerView; |
| 1196 | } |
| 1197 | |
| 1198 | nsPoint nsSubDocumentFrame::GetExtraOffset() const { |
| 1199 | MOZ_ASSERT(mInnerView)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mInnerView)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mInnerView))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mInnerView", "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 1199); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mInnerView" ")"); do { *((volatile int*)__null) = 1199; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1200 | return mInnerView->GetPosition(); |
| 1201 | } |
| 1202 | |
| 1203 | void nsSubDocumentFrame::SubdocumentIntrinsicSizeOrRatioChanged() { |
| 1204 | const nsStylePosition* pos = StylePosition(); |
| 1205 | bool dependsOnIntrinsics = |
| 1206 | !pos->mWidth.ConvertsToLength() || !pos->mHeight.ConvertsToLength(); |
| 1207 | |
| 1208 | if (dependsOnIntrinsics || pos->mObjectFit != StyleObjectFit::Fill) { |
| 1209 | auto dirtyHint = dependsOnIntrinsics |
| 1210 | ? IntrinsicDirty::FrameAncestorsAndDescendants |
| 1211 | : IntrinsicDirty::None; |
| 1212 | PresShell()->FrameNeedsReflow(this, dirtyHint, NS_FRAME_IS_DIRTY); |
| 1213 | InvalidateFrame(); |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | bool nsSubDocumentFrame::ContentReactsToPointerEvents() const { |
| 1218 | if (Style()->PointerEvents() == StylePointerEvents::None) { |
| 1219 | return false; |
| 1220 | } |
| 1221 | if (mIsInObjectOrEmbed) { |
| 1222 | if (nsCOMPtr<nsIObjectLoadingContent> iolc = do_QueryInterface(mContent)) { |
| 1223 | const auto* olc = static_cast<nsObjectLoadingContent*>(iolc.get()); |
| 1224 | if (olc->IsSyntheticImageDocument()) { |
| 1225 | return false; |
| 1226 | } |
| 1227 | } |
| 1228 | } |
| 1229 | return true; |
| 1230 | } |
| 1231 | |
| 1232 | // Return true iff |aManager| is a "temporary layer manager". They're |
| 1233 | // used for small software rendering tasks, like drawWindow. That's |
| 1234 | // currently implemented by a BasicLayerManager without a backing |
| 1235 | // widget, and hence in non-retained mode. |
| 1236 | nsDisplayRemote::nsDisplayRemote(nsDisplayListBuilder* aBuilder, |
| 1237 | nsSubDocumentFrame* aFrame) |
| 1238 | : nsPaintedDisplayItem(aBuilder, aFrame), |
| 1239 | mEventRegionsOverride(EventRegionsOverride::NoOverride) { |
| 1240 | if (aBuilder->IsInsidePointerEventsNoneDoc() || |
| 1241 | !aFrame->ContentReactsToPointerEvents()) { |
| 1242 | mEventRegionsOverride |= EventRegionsOverride::ForceEmptyHitRegion; |
| 1243 | } |
| 1244 | if (nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents( |
| 1245 | aFrame->PresShell())) { |
| 1246 | mEventRegionsOverride |= EventRegionsOverride::ForceDispatchToContent; |
| 1247 | } |
| 1248 | |
| 1249 | mPaintData = aFrame->GetRemotePaintData(); |
| 1250 | } |
| 1251 | |
| 1252 | namespace mozilla { |
| 1253 | |
| 1254 | void nsDisplayRemote::Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) { |
| 1255 | DrawTarget* target = aCtx->GetDrawTarget(); |
| 1256 | if (!target->IsRecording() || mPaintData.mTabId == 0) { |
| 1257 | NS_WARNING("Remote iframe not rendered")NS_DebugBreak(NS_DEBUG_WARNING, "Remote iframe not rendered", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/generic/nsSubDocumentFrame.cpp" , 1257); |
| 1258 | return; |
| 1259 | } |
| 1260 | |
| 1261 | // Rendering the inner document will apply a scale to account for its app |
| 1262 | // units per dev pixel ratio. We want to apply the inverse scaling using our |
| 1263 | // app units per dev pixel ratio, so that no actual scaling will be applied if |
| 1264 | // they match. For in-process rendering, nsSubDocumentFrame creates an |
| 1265 | // nsDisplayZoom item if the app units per dev pixel ratio changes. |
| 1266 | // |
| 1267 | // Similarly, rendering the inner document will scale up by the cross process |
| 1268 | // paint scale again, so we also need to account for that. |
| 1269 | const int32_t appUnitsPerDevPixel = |
| 1270 | mFrame->PresContext()->AppUnitsPerDevPixel(); |
| 1271 | |
| 1272 | gfxContextMatrixAutoSaveRestore saveMatrix(aCtx); |
| 1273 | gfxFloat targetAuPerDev = |
| 1274 | gfxFloat(AppUnitsPerCSSPixel()) / aCtx->GetCrossProcessPaintScale(); |
| 1275 | |
| 1276 | gfxFloat scale = targetAuPerDev / appUnitsPerDevPixel; |
| 1277 | aCtx->Multiply(gfxMatrix::Scaling(scale, scale)); |
| 1278 | |
| 1279 | Rect destRect = |
| 1280 | NSRectToSnappedRect(GetContentRect(), targetAuPerDev, *target); |
| 1281 | target->DrawDependentSurface(mPaintData.mTabId, destRect); |
| 1282 | } |
| 1283 | |
| 1284 | bool nsDisplayRemote::CreateWebRenderCommands( |
| 1285 | mozilla::wr::DisplayListBuilder& aBuilder, |
| 1286 | mozilla::wr::IpcResourceUpdateQueue& aResources, |
| 1287 | const StackingContextHelper& aSc, |
| 1288 | mozilla::layers::RenderRootStateManager* aManager, |
| 1289 | nsDisplayListBuilder* aDisplayListBuilder) { |
| 1290 | if (!mPaintData.mLayersId.IsValid()) { |
| 1291 | return true; |
| 1292 | } |
| 1293 | |
| 1294 | auto* subDocFrame = static_cast<nsSubDocumentFrame*>(mFrame); |
| 1295 | nsRect destRect = subDocFrame->GetDestRect(); |
| 1296 | if (aDisplayListBuilder->IsForPainting()) { |
| 1297 | subDocFrame->SetRasterScale(aSc.GetInheritedScale()); |
| 1298 | const nsRect buildingRect = GetBuildingRect() - ToReferenceFrame(); |
| 1299 | Maybe<nsRect> visibleRect = |
| 1300 | buildingRect.EdgeInclusiveIntersection(destRect); |
| 1301 | if (visibleRect) { |
| 1302 | *visibleRect -= destRect.TopLeft(); |
| 1303 | } |
| 1304 | subDocFrame->SetVisibleRect(visibleRect); |
| 1305 | } |
| 1306 | nscoord auPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel(); |
| 1307 | nsPoint layerOffset = |
| 1308 | aDisplayListBuilder->ToReferenceFrame(mFrame) + destRect.TopLeft(); |
| 1309 | mOffset = LayoutDevicePoint::FromAppUnits(layerOffset, auPerDevPixel); |
| 1310 | |
| 1311 | destRect.MoveTo(0, 0); |
| 1312 | auto rect = LayoutDeviceRect::FromAppUnits(destRect, auPerDevPixel); |
| 1313 | rect += mOffset; |
| 1314 | |
| 1315 | aBuilder.PushIFrame(rect, !BackfaceIsHidden(), |
| 1316 | mozilla::wr::AsPipelineId(mPaintData.mLayersId), |
| 1317 | /*ignoreMissingPipelines*/ true); |
| 1318 | |
| 1319 | return true; |
| 1320 | } |
| 1321 | |
| 1322 | bool nsDisplayRemote::UpdateScrollData( |
| 1323 | mozilla::layers::WebRenderScrollData* aData, |
| 1324 | mozilla::layers::WebRenderLayerScrollData* aLayerData) { |
| 1325 | if (!mPaintData.mLayersId.IsValid()) { |
| 1326 | return true; |
| 1327 | } |
| 1328 | |
| 1329 | if (aLayerData) { |
| 1330 | aLayerData->SetReferentId(mPaintData.mLayersId); |
| 1331 | |
| 1332 | auto size = static_cast<nsSubDocumentFrame*>(mFrame)->GetSubdocumentSize(); |
| 1333 | Matrix4x4 m = Matrix4x4::Translation(mOffset.x, mOffset.y, 0.0); |
| 1334 | aLayerData->SetTransform(m); |
| 1335 | aLayerData->SetEventRegionsOverride(mEventRegionsOverride); |
| 1336 | aLayerData->SetRemoteDocumentSize(LayerIntSize(size.width, size.height)); |
| 1337 | } |
| 1338 | return true; |
| 1339 | } |
| 1340 | |
| 1341 | nsFrameLoader* nsDisplayRemote::GetFrameLoader() const { |
| 1342 | return static_cast<nsSubDocumentFrame*>(mFrame)->FrameLoader(); |
| 1343 | } |
| 1344 | |
| 1345 | } // namespace mozilla |