commit 4bbf8598d130b17b120f13a9f065fe275fc0b80e parent ca2b22e0f7d7f9619fd582580caf75ac0e4c4131 Author: Emilio Cobos Álvarez <emilio@crisal.io> Date: Wed, 12 Nov 2025 01:51:22 +0000 Bug 1998125 - Remove a lot of now unused view code. r=layout-reviewers,firefox-style-system-reviewers,dshin No need to reposition views during layout and so on, now that we don't use views for either popups nor subdocuments. No need for nsView to have parent / sibling / children either. Differential Revision: https://phabricator.services.mozilla.com/D271205 Diffstat:
34 files changed, 91 insertions(+), 1151 deletions(-)
diff --git a/accessible/generic/LocalAccessible.cpp b/accessible/generic/LocalAccessible.cpp @@ -317,12 +317,6 @@ uint64_t LocalAccessible::VisibilityState() const { // scrolled out. nsIFrame* curFrame = frame; do { - if (nsView* view = curFrame->GetView()) { - if (view->GetVisibility() == ViewVisibility::Hide) { - return states::INVISIBLE; - } - } - if (nsMenuPopupFrame* popup = do_QueryFrame(curFrame)) { return popup->IsOpen() ? 0 : states::INVISIBLE; } diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp @@ -4017,43 +4017,6 @@ void PresShell::SchedulePaint() { } } -void PresShell::ClearMouseCaptureOnView(nsView* aView) { - if (nsIContent* capturingContent = GetCapturingContent()) { - if (aView) { - // if a view was specified, ensure that the captured content is within - // this view. - nsIFrame* frame = capturingContent->GetPrimaryFrame(); - if (frame) { - nsView* view = frame->GetClosestView(); - // if there is no view, capturing won't be handled any more, so - // just release the capture. - if (view) { - do { - if (view == aView) { - ReleaseCapturingContent(); - // the view containing the captured content likely disappeared so - // disable capture for now. - AllowMouseCapture(false); - break; - } - - view = view->GetParent(); - } while (view); - // return if the view wasn't found - return; - } - } - } - - ReleaseCapturingContent(); - } - - // disable mouse capture until the next mousedown as a dialog has opened - // or a drag has started. Otherwise, someone could start capture during - // the modal dialog or drag. - AllowMouseCapture(false); -} - void PresShell::ClearMouseCapture() { ReleaseCapturingContent(); AllowMouseCapture(false); @@ -5808,10 +5771,6 @@ static nsView* FindViewContaining(nsView* aRelativeToView, nsView* aView, nsPoint aPt) { MOZ_ASSERT(aRelativeToView->GetFrame()); - if (aView->GetVisibility() == ViewVisibility::Hide) { - return nullptr; - } - nsIFrame* frame = aView->GetFrame(); if (frame) { if (!frame->PresShell()->IsActive() || @@ -5828,14 +5787,9 @@ static nsView* FindViewContaining(nsView* aRelativeToView, // none of them can be between the root frame and the zoom boundary. bool crossingZoomBoundary = false; if (aRelativeToViewportType == ViewportType::Visual) { - if (!aRelativeToView->GetParent() || - aRelativeToView->GetViewManager() != - aRelativeToView->GetParent()->GetViewManager()) { - if (aRelativeToView->GetFrame() - ->PresContext() - ->IsRootContentDocumentCrossProcess()) { - crossingZoomBoundary = true; - } + if (nsIFrame* f = aRelativeToView->GetFrame(); + f && f->PresContext()->IsRootContentDocumentCrossProcess()) { + crossingZoomBoundary = true; } } @@ -5865,7 +5819,7 @@ static nsView* FindViewContaining(nsView* aRelativeToView, // hittesting against the view of the subdocument frame that contains us // already happened and succeeded before getting here. if (!crossingZoomBoundary) { - if (!aView->GetDimensions().Contains(aPt)) { + if (!aView->GetBounds().Contains(aPt)) { return nullptr; } } @@ -5874,14 +5828,6 @@ static nsView* FindViewContaining(nsView* aRelativeToView, aRelativeToViewportType = nextRelativeToViewportType; } - for (nsView* v = aView->GetFirstChild(); v; v = v->GetNextSibling()) { - nsView* r = - FindViewContaining(aRelativeToView, aRelativeToViewportType, v, aPt); - if (r) { - return r; - } - } - return frame ? aView : nullptr; } @@ -5890,11 +5836,6 @@ static BrowserBridgeChild* GetChildBrowser(nsView* aView) { return nullptr; } nsIFrame* frame = aView->GetFrame(); - if (!frame && aView->GetParent()) { - // If frame is null then view is an anonymous inner view, and we want - // the frame from the corresponding outer view. - frame = aView->GetParent()->GetFrame(); - } if (!frame || !frame->GetContent()) { return nullptr; } @@ -7208,16 +7149,7 @@ nsIFrame* PresShell::GetClosestAncestorFrameForAncestorView() const { return nullptr; } nsView* view = vm->GetRootView(); - while (view && !view->GetFrame()) { - view = view->GetParent(); - } - - nsIFrame* frame = nullptr; - if (view) { - frame = view->GetFrame(); - } - - return frame; + return view ? view->GetFrame() : nullptr; } static CallState FlushThrottledStyles(Document& aDocument) { @@ -10741,16 +10673,6 @@ bool PresShell::DoReflow(nsIFrame* target, bool aInterruptible, NS_ASSERTION(status.IsEmpty(), "reflow roots should never split"); target->SetSize(boundsRelativeToTarget.Size()); - - // Always use boundsRelativeToTarget here, not desiredSize.InkOverflowRect(), - // because for root frames (where they could be different, since root frames - // are allowed to have overflow) the root view bounds need to match the - // viewport bounds; the view manager "window dimensions" code depends on it. - if (auto* view = target->GetView()) { - nsContainerFrame::SyncFrameViewAfterReflow(mPresContext, target, view, - boundsRelativeToTarget); - } - target->DidReflow(mPresContext, nullptr); if (target->IsInScrollAnchorChain()) { ScrollAnchorContainer* container = ScrollAnchorContainer::FindFor(target); @@ -11948,7 +11870,6 @@ void PresShell::UpdateAnchorPosForScroll( // Update positioned frame's overflow, then the absolute containing // block's. positioned->UpdateOverflow(); - nsContainerFrame::PlaceFrameView(positioned); positioned->GetParent()->UpdateOverflow(); referenceData->mDefaultScrollShift = offset; return true; diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h @@ -206,8 +206,6 @@ class PresShell final : public nsStubDocumentObserver, return sCapturingContentInfo.mPreventDrag && sCapturingContentInfo.mContent; } - static void ClearMouseCaptureOnView(nsView* aView); - // Clear the capture content if it exists in this process. static void ClearMouseCapture(); diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp @@ -2670,7 +2670,6 @@ ViewportFrame* nsCSSFrameConstructor::ConstructRootFrame() { // Bind the viewport frame to the root view if (nsView* rootView = mPresShell->GetViewManager()->GetRootView()) { viewportFrame->SetView(rootView); - viewportFrame->SyncFrameViewProperties(rootView); rootView->SetNeedsWindowPropertiesSync(); } diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp @@ -1918,7 +1918,7 @@ nsDocumentViewer::SetBoundsWithFlags(const LayoutDeviceIntRect& aBounds, nscoord height = NSIntPixelsToAppUnits(mBounds.height, p2a); nsView* rootView = mViewManager->GetRootView(); if (boundsChanged && rootView) { - nsRect viewDims = rootView->GetDimensions(); + nsRect viewDims = rootView->GetBounds(); // If the view/frame tree and prescontext visible area already has the new // size but we did not, then it's likely that we got reflowed in response // to a call to GetContentSize. Thus there is a disconnect between the @@ -2182,10 +2182,8 @@ void nsDocumentViewer::MakeWindow(const nsSize& aSize) { mViewManager = new nsViewManager(mPresContext->DeviceContext()); - // The root view is always at 0,0. - nsRect tbounds(nsPoint(), aSize); // Create a view - nsView* view = mViewManager->CreateView(tbounds, nullptr); + nsView* view = mViewManager->CreateView(aSize); // Create a widget if we were given a parent widget or don't have a // container view that we can hook up to without a widget. diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp @@ -4517,7 +4517,6 @@ static nsSize MeasureIntrinsicContentSize( const nsIFrame::ReflowChildFlags flags = nsIFrame::ReflowChildFlags::NoMoveFrame | - nsIFrame::ReflowChildFlags::NoSizeView | nsIFrame::ReflowChildFlags::NoDeleteNextInFlowChild; nsContainerFrame::FinishReflowChild(aFrame, pc, reflowOutput, &reflowInput, childWM, LogicalPoint(parentWM), nsSize(), diff --git a/layout/forms/nsFieldSetFrame.cpp b/layout/forms/nsFieldSetFrame.cpp @@ -698,8 +698,6 @@ void nsFieldSetFrame::Reflow(nsPresContext* aPresContext, containerSize); legend->SetPosition(wm, actualLegendPos, containerSize); - nsContainerFrame::PositionFrameView(legend); - nsContainerFrame::PositionChildViews(legend); } // Skip our block-end border if we're INCOMPLETE. diff --git a/layout/generic/AbsoluteContainingBlock.cpp b/layout/generic/AbsoluteContainingBlock.cpp @@ -1373,16 +1373,6 @@ void AbsoluteContainingBlock::ReflowAbsoluteFrame( bEndInsetAuto ? 0 : offsets.BEnd(outerWM), iStartInsetAuto ? 0 : offsets.IStart(outerWM)}; cb.mRect.Deflate(insetModification.GetPhysicalMargin(outerWM)); - - nsView* view = aKidFrame->GetView(); - if (view) { - // Size and position the view and set its opacity, visibility, content - // transparency, and clip - nsContainerFrame::SyncFrameViewAfterReflow( - aPresContext, aKidFrame, view, kidDesiredSize.InkOverflow()); - } else { - nsContainerFrame::PositionChildViews(aKidFrame); - } } aKidFrame->DidReflow(aPresContext, &kidReflowInput); @@ -1419,7 +1409,6 @@ void AbsoluteContainingBlock::ReflowAbsoluteFrame( // Ensure that the positioned frame's overflow is updated. Absolutely // containing block's overflow will be updated shortly below. aKidFrame->UpdateOverflow(); - nsContainerFrame::PlaceFrameView(aKidFrame); } aAnchorPosResolutionCache->mReferenceData->mDefaultScrollShift = offset; }(); @@ -1480,7 +1469,6 @@ void AbsoluteContainingBlock::ReflowAbsoluteFrame( } aKidFrame->SetPosition(position); aKidFrame->UpdateOverflow(); - nsContainerFrame::PlaceFrameView(aKidFrame); }(); // If author asked for `position-visibility: no-overflow` and we overflow diff --git a/layout/generic/BlockReflowState.cpp b/layout/generic/BlockReflowState.cpp @@ -435,8 +435,6 @@ void BlockReflowState::RecoverFloats(nsLineList::iterator aLine, for (nsIFrame* floatFrame : aLine->Floats()) { if (aDeltaBCoord != 0) { floatFrame->MovePositionBy(nsPoint(0, aDeltaBCoord)); - nsContainerFrame::PositionFrameView(floatFrame); - nsContainerFrame::PositionChildViews(floatFrame); } #ifdef DEBUG if (nsBlockFrame::gNoisyReflow || nsBlockFrame::gNoisyFloatManager) { @@ -884,14 +882,10 @@ BlockReflowState::PlaceFloatResult BlockReflowState::FlowAndPlaceFloat( ReflowInput::ApplyRelativePositioning(aFloat, wm, floatOffsets, &origin, ContainerSize()); - // Position the float and make sure and views are properly - // positioned. We need to explicitly position its child views as - // well, since we're moving the float after flowing it. + // Position the float. bool moved = aFloat->GetLogicalPosition(wm, ContainerSize()) != origin; if (moved) { aFloat->SetPosition(wm, origin, ContainerSize()); - nsContainerFrame::PositionFrameView(aFloat); - nsContainerFrame::PositionChildViews(aFloat); } // Update the float combined area state diff --git a/layout/generic/ScrollContainerFrame.cpp b/layout/generic/ScrollContainerFrame.cpp @@ -917,15 +917,9 @@ void ScrollContainerFrame::ReflowScrolledFrame(ScrollReflowInput& aState, mHasHorizontalScrollbar = didHaveHorizontalScrollbar; mHasVerticalScrollbar = didHaveVerticalScrollbar; - // Don't resize or position the view (if any) because we're going to resize - // it to the correct size anyway in PlaceScrollArea. Allowing it to - // resize here would size it to the natural height of the frame, - // which will usually be different from the scrollport height; - // invalidating the difference will cause unnecessary repainting. - FinishReflowChild( - mScrolledFrame, presContext, *aMetrics, &kidReflowInput, wm, - LogicalPoint(wm), dummyContainerSize, - ReflowChildFlags::NoMoveFrame | ReflowChildFlags::NoSizeView); + FinishReflowChild(mScrolledFrame, presContext, *aMetrics, &kidReflowInput, wm, + LogicalPoint(wm), dummyContainerSize, + ReflowChildFlags::NoMoveFrame); if (mScrolledFrame->HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)) { // Propagate NS_FRAME_CONTAINS_RELATIVE_BSIZE from our inner scrolled frame @@ -1138,19 +1132,8 @@ void ScrollContainerFrame::PlaceScrollArea(ScrollReflowInput& aState, // Using FinishAndStoreOverflow is needed so the overflow rect gets set // correctly. It also messes with the overflow rect in the 'clip' case, but // scrolled frames can't have 'overflow' either. - // This needs to happen before SyncFrameViewAfterReflow so - // HasOverflowRect() will return the correct value. OverflowAreas overflow(scrolledArea, scrolledArea); mScrolledFrame->FinishAndStoreOverflow(overflow, mScrolledFrame->GetSize()); - - // Note that making the view *exactly* the size of the scrolled area - // is critical, since the view scrolling code uses the size of the - // scrolled view to clamp scroll requests. - // Normally the mScrolledFrame won't have a view but in some cases it - // might create its own. - nsContainerFrame::SyncFrameViewAfterReflow( - mScrolledFrame->PresContext(), mScrolledFrame, mScrolledFrame->GetView(), - scrolledArea, ReflowChildFlags::Default); } nscoord ScrollContainerFrame::IntrinsicScrollbarGutterSizeAtInlineEdges() @@ -2555,32 +2538,6 @@ void ScrollContainerFrame::ScrollToWithOrigin(nsPoint aScrollPosition, } } -// We can't use nsContainerFrame::PositionChildViews here because -// we don't want to invalidate views that have moved. -static void AdjustViews(nsIFrame* aFrame) { - nsView* view = aFrame->GetView(); - if (view) { - nsPoint pt; - aFrame->GetParent()->GetClosestView(&pt); - pt += aFrame->GetPosition(); - view->SetPosition(pt.x, pt.y); - - return; - } - - if (!aFrame->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW)) { - return; - } - - // Call AdjustViews recursively for all child frames except the popup list as - // the views for popups are not scrolled. - for (const auto& [list, listID] : aFrame->ChildLists()) { - for (nsIFrame* child : list) { - AdjustViews(child); - } - } -} - void ScrollContainerFrame::MarkScrollbarsDirtyForReflow() const { auto* presShell = PresShell(); if (mVScrollbarBox) { @@ -2774,8 +2731,6 @@ void ScrollContainerFrame::TriggerDisplayPortExpiration() { void ScrollContainerFrame::ScrollVisual() { MarkEverScrolled(); - - AdjustViews(mScrolledFrame); // We need to call this after fixing up the view positions // to be consistent with the frame hierarchy. MarkRecentlyScrolled(); diff --git a/layout/generic/ViewportFrame.cpp b/layout/generic/ViewportFrame.cpp @@ -24,6 +24,8 @@ #include "nsLayoutUtils.h" #include "nsPlaceholderFrame.h" #include "nsSubDocumentFrame.h" +#include "nsView.h" +#include "nsViewManager.h" using namespace mozilla; @@ -337,6 +339,14 @@ void ViewportFrame::RemoveFrame(DestroyContext& aContext, ChildListID aListID, } #endif +void ViewportFrame::Destroy(DestroyContext& aContext) { + // Prevent event dispatch during destruction. + if (auto* view = GetView()) { + view->SetFrame(nullptr); + } + nsContainerFrame::Destroy(aContext); +} + nscoord ViewportFrame::IntrinsicISize(const IntrinsicSizeInput& aInput, IntrinsicISizeType aType) { return mFrames.IsEmpty() @@ -488,6 +498,11 @@ void ViewportFrame::Reflow(nsPresContext* aPresContext, // so we don't need to change our overflow areas. FinishAndStoreOverflow(&aDesiredSize); + if (auto* view = GetView()) { + view->GetViewManager()->ResizeView( + view, nsRect(nsPoint(), aDesiredSize.PhysicalSize())); + } + NS_FRAME_TRACE_REFLOW_OUT("ViewportFrame::Reflow", aStatus); } diff --git a/layout/generic/ViewportFrame.h b/layout/generic/ViewportFrame.h @@ -48,6 +48,7 @@ class ViewportFrame : public nsContainerFrame { void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override; #endif + void Destroy(DestroyContext&) override; void BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsDisplayListSet& aLists) override; diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp @@ -2356,7 +2356,6 @@ void nsBlockFrame::AlignContent(BlockReflowState& aState, } for (nsIFrame* kid : GetChildList(FrameChildListID::Float)) { kid->MovePositionBy(wm, translation); - nsContainerFrame::PlaceFrameView(kid); } nsIFrame* outsideMarker = GetOutsideMarker(); if (outsideMarker && !mLines.empty()) { @@ -2944,7 +2943,6 @@ bool nsBlockFrame::LinesAreEmpty() const { bool nsBlockFrame::ReflowDirtyLines(BlockReflowState& aState) { bool keepGoing = true; - bool repositionViews = false; // should we really need this? bool foundAnyClears = aState.mTrailingClearFromPIF != UsedClear::None; bool willReflowAgain = false; bool usedOverflowWrap = false; @@ -3354,8 +3352,6 @@ bool nsBlockFrame::ReflowDirtyLines(BlockReflowState& aState) { if (deltaBCoord != 0) { SlideLine(aState, line, deltaBCoord); - } else { - repositionViews = true; } NS_ASSERTION(!line->IsDirty() || !line->HasFloats(), @@ -3443,11 +3439,6 @@ bool nsBlockFrame::ReflowDirtyLines(BlockReflowState& aState) { : line->mFirstChild->GetPrevSibling(); } - // Should we really have to do this? - if (repositionViews) { - nsContainerFrame::PlaceFrameView(this); - } - // We can skip trying to pull up the next line if our height is constrained // (so we can report being incomplete) and there is no next in flow or we // were told not to or we know it will be futile, i.e., @@ -3932,22 +3923,17 @@ void nsBlockFrame::MoveChildFramesOfLine(nsLineBox* aLine, if (aDeltaBCoord) { kid->MovePositionBy(wm, translation); } - - // Make sure the frame's view and any child views are updated - nsContainerFrame::PlaceFrameView(kid); } else { // Adjust the block-dir coordinate of the frames in the line. // Note: we need to re-position views even if aDeltaBCoord is 0, because // one of our parent frames may have moved and so the view's position // relative to its parent may have changed. - int32_t n = aLine->GetChildCount(); - while (--n >= 0) { - if (aDeltaBCoord) { + if (aDeltaBCoord) { + int32_t n = aLine->GetChildCount(); + while (--n >= 0) { kid->MovePositionBy(wm, translation); + kid = kid->GetNextSibling(); } - // Make sure the frame's view and any child views are updated - nsContainerFrame::PlaceFrameView(kid); - kid = kid->GetNextSibling(); } } } @@ -4183,9 +4169,6 @@ void nsBlockFrame::ReflowBlockFrame(BlockReflowState& aState, const nscoord startingBCoord = aState.mBCoord; const CollapsingMargin incomingMargin = aState.mPrevBEndMargin; nscoord clearance; - // Save the original position of the frame so that we can reposition - // its view as needed. - nsPoint originalPosition = frame->GetPosition(); while (true) { clearance = 0; nscoord bStartMargin = 0; @@ -4553,13 +4536,6 @@ void nsBlockFrame::ReflowBlockFrame(BlockReflowState& aState, aState.mPrevChild = frame; if (childReflowInput->WillReflowAgainForClearance()) { - // If an ancestor of ours is going to reflow for clearance, we - // need to avoid calling PlaceBlock, because it unsets dirty bits - // on the child block (both itself, and through its call to - // nsIFrame::DidReflow), and those dirty bits imply dirtiness for - // all of the child block, including the lines it didn't reflow. - NS_ASSERTION(originalPosition == frame->GetPosition(), - "we need to call PositionChildViews"); return; } @@ -4760,14 +4736,6 @@ void nsBlockFrame::ReflowBlockFrame(BlockReflowState& aState, break; // out of the reflow retry loop } - // Now that we've got its final position all figured out, position any child - // views it may have. Note that the case when frame has a view got handled - // by FinishReflowChild, but that function didn't have the coordinates needed - // to correctly decide whether to reposition child views. - if (originalPosition != frame->GetPosition() && !frame->GetView()) { - nsContainerFrame::PositionChildViews(frame); - } - #ifdef DEBUG VerifyLines(true); #endif @@ -7456,11 +7424,6 @@ void nsBlockFrame::ReflowFloat(BlockReflowState& aState, ReflowInput& aFloatRI, // of |PlaceFrameView| here? WritingMode metricsWM = metrics.GetWritingMode(); aFloat->SetSize(metricsWM, metrics.Size(metricsWM)); - if (auto* view = aFloat->GetView()) { - nsContainerFrame::SyncFrameViewAfterReflow(aState.mPresContext, aFloat, - view, metrics.InkOverflow(), - ReflowChildFlags::NoMoveView); - } aFloat->DidReflow(aState.mPresContext, &aFloatRI); } diff --git a/layout/generic/nsColumnSetFrame.cpp b/layout/generic/nsColumnSetFrame.cpp @@ -416,7 +416,6 @@ static void MoveChildTo(nsIFrame* aChild, LogicalPoint aOrigin, WritingMode aWM, } aChild->SetPosition(aWM, aOrigin, aContainerSize); - nsContainerFrame::PlaceFrameView(aChild); } nscoord nsColumnSetFrame::IntrinsicISize(const IntrinsicSizeInput& input, diff --git a/layout/generic/nsContainerFrame.cpp b/layout/generic/nsContainerFrame.cpp @@ -43,8 +43,6 @@ #include "nsPrintfCString.h" #include "nsRect.h" #include "nsStyleConsts.h" -#include "nsView.h" -#include "nsViewManager.h" using namespace mozilla; using namespace mozilla::dom; @@ -63,19 +61,6 @@ NS_QUERYFRAME_HEAD(nsContainerFrame) NS_QUERYFRAME_ENTRY(nsContainerFrame) NS_QUERYFRAME_TAIL_INHERITING(nsSplittableFrame) -void nsContainerFrame::Init(nsIContent* aContent, nsContainerFrame* aParent, - nsIFrame* aPrevInFlow) { - nsSplittableFrame::Init(aContent, aParent, aPrevInFlow); - if (aPrevInFlow) { - // Make sure we copy bits from our prev-in-flow that will affect - // us. A continuation for a container frame needs to know if it - // has a child with a view so that we'll properly reposition it. - if (aPrevInFlow->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW)) { - AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW); - } - } -} - void nsContainerFrame::SetInitialChildList(ChildListID aListID, nsFrameList&& aChildList) { #ifdef DEBUG @@ -225,11 +210,6 @@ void nsContainerFrame::SafelyDestroyFrameListProp( } void nsContainerFrame::Destroy(DestroyContext& aContext) { - // Prevent event dispatch during destruction. - if (auto* view = GetView()) { - view->SetFrame(nullptr); - } - DestroyAbsoluteFrames(aContext); // Destroy frames on the principal child list. @@ -560,40 +540,6 @@ nsIFrame::FrameSearchResult nsContainerFrame::PeekOffsetCharacter( ///////////////////////////////////////////////////////////////////////////// // Helper member functions -/** - * Position the view associated with |aKidFrame|, if there is one. A - * container frame should call this method after positioning a frame, - * but before |Reflow|. - */ -void nsContainerFrame::PositionFrameView(nsIFrame* aKidFrame) { - if (MOZ_LIKELY(!aKidFrame->MayHaveView())) { - return; - } - nsIFrame* parentFrame = aKidFrame->GetParent(); - if (!parentFrame) { - return; - } - auto* view = aKidFrame->GetView(); - if (!view) { - return; - } - - nsViewManager* vm = view->GetViewManager(); - nsPoint pt; - nsView* ancestorView = parentFrame->GetClosestView(&pt); - - if (ancestorView != view->GetParent()) { - NS_ASSERTION(ancestorView == view->GetParent()->GetParent(), - "Allowed only one anonymous view between frames"); - // parentFrame is responsible for positioning aKidFrame's view - // explicitly - return; - } - - pt += aKidFrame->GetPosition(); - vm->MoveViewTo(view, pt.x, pt.y); -} - void nsContainerFrame::ReparentFrame(nsIFrame* aFrame, nsContainerFrame* aOldParent, nsContainerFrame* aNewParent) { @@ -662,26 +608,6 @@ void nsContainerFrame::SetSizeConstraints(nsPresContext* aPresContext, aWidget->SetSizeConstraints(constraints); } -void nsContainerFrame::SyncFrameViewAfterReflow(nsPresContext* aPresContext, - nsIFrame* aFrame, nsView* aView, - const nsRect& aInkOverflowArea, - ReflowChildFlags aFlags) { - if (!aView) { - return; - } - - // Make sure the view is sized and positioned correctly - if (!(aFlags & ReflowChildFlags::NoMoveView)) { - PositionFrameView(aFrame); - } - - if (!(aFlags & ReflowChildFlags::NoSizeView)) { - nsViewManager* vm = aView->GetViewManager(); - - vm->ResizeView(aView, aInkOverflowArea); - } -} - void nsContainerFrame::DoInlineMinISize(const IntrinsicSizeInput& aInput, InlineMinISizeData* aData) { auto handleChildren = [&](auto frame, auto data) { @@ -784,11 +710,6 @@ void nsContainerFrame::ReflowChild( aKidFrame->SetPosition(aWM, aPos, aContainerSize); } - if (!(aFlags & ReflowChildFlags::NoMoveView)) { - PositionFrameView(aKidFrame); - PositionChildViews(aKidFrame); - } - // Reflow the child frame aKidFrame->Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus); @@ -825,11 +746,6 @@ void nsContainerFrame::ReflowChild(nsIFrame* aKidFrame, aKidFrame->SetPosition(nsPoint(aX, aY)); } - if (!(aFlags & ReflowChildFlags::NoMoveView)) { - PositionFrameView(aKidFrame); - PositionChildViews(aKidFrame); - } - // Reflow the child frame aKidFrame->Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus); @@ -849,29 +765,6 @@ void nsContainerFrame::ReflowChild(nsIFrame* aKidFrame, } } -/** - * Position the views of |aFrame|'s descendants. A container frame - * should call this method if it moves a frame after |Reflow|. - */ -void nsContainerFrame::PositionChildViews(nsIFrame* aFrame) { - if (!aFrame->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW)) { - return; - } - - // Recursively walk aFrame's child frames. - // Process the additional child lists, but skip the popup list as the view for - // popups is managed by the parent. - // Currently only nsMenuFrame has a popupList and during layout will adjust - // the view manually to position the popup. - for (const auto& [list, listID] : aFrame->ChildLists()) { - for (nsIFrame* childFrame : list) { - // Position the frame's view (if it has one) otherwise recursively - // process its children - PlaceFrameView(childFrame); - } - } -} - void nsContainerFrame::FinishReflowChild( nsIFrame* aKidFrame, nsPresContext* aPresContext, const ReflowOutput& aDesiredSize, const ReflowInput* aReflowInput, @@ -887,7 +780,6 @@ void nsContainerFrame::FinishReflowChild( "FinishReflowChild with unconstrained container width!"); } - nsPoint curOrigin = aKidFrame->GetPosition(); const LogicalSize convertedSize = aDesiredSize.Size(aWM); LogicalPoint pos(aPos); @@ -910,18 +802,6 @@ void nsContainerFrame::FinishReflowChild( aKidFrame->SetSize(aWM, convertedSize); } - if (nsView* view = aKidFrame->GetView()) { - // Make sure the frame's view is properly sized and positioned and has - // things like opacity correct - SyncFrameViewAfterReflow(aPresContext, aKidFrame, view, - aDesiredSize.InkOverflow(), aFlags); - } else if (!(aFlags & ReflowChildFlags::NoMoveView) && - curOrigin != aKidFrame->GetPosition()) { - // If the frame has moved, then we need to make sure any child views are - // correctly positioned - PositionChildViews(aKidFrame); - } - aKidFrame->DidReflow(aPresContext, aReflowInput); } #if defined(_MSC_VER) && !defined(__clang__) && defined(_M_AMD64) @@ -940,7 +820,6 @@ void nsContainerFrame::FinishReflowChild(nsIFrame* aKidFrame, "only the logical version supports ApplyRelativePositioning " "since ApplyRelativePositioning requires the container size"); - nsPoint curOrigin = aKidFrame->GetPosition(); nsPoint pos(aX, aY); nsSize size(aDesiredSize.PhysicalSize()); @@ -951,17 +830,6 @@ void nsContainerFrame::FinishReflowChild(nsIFrame* aKidFrame, aKidFrame->SetSize(size); } - if (nsView* view = aKidFrame->GetView()) { - // Make sure the frame's view is properly sized and positioned and has - // things like opacity correct - SyncFrameViewAfterReflow(aPresContext, aKidFrame, view, - aDesiredSize.InkOverflow(), aFlags); - } else if (!(aFlags & ReflowChildFlags::NoMoveView) && curOrigin != pos) { - // If the frame has moved, then we need to make sure any child views are - // correctly positioned - PositionChildViews(aKidFrame); - } - aKidFrame->DidReflow(aPresContext, aReflowInput); } diff --git a/layout/generic/nsContainerFrame.h b/layout/generic/nsContainerFrame.h @@ -47,8 +47,6 @@ class nsContainerFrame : public nsSplittableFrame { NS_DECL_QUERYFRAME // nsIFrame overrides - void Init(nsIContent* aContent, nsContainerFrame* aParent, - nsIFrame* aPrevInFlow) override; nsContainerFrame* GetContentInsertionFrame() override { return this; } const nsFrameList& GetChildList(ChildListID aList) const override; @@ -151,9 +149,6 @@ class nsContainerFrame : public nsSplittableFrame { virtual void DeleteNextInFlowChild(DestroyContext&, nsIFrame* aNextInFlow, bool aDeletingEmptyFrames); - // Positions the frame's view based on the frame's origin - static void PositionFrameView(nsIFrame* aKidFrame); - /** * Reparent aFrame from aOldParent to aNewParent. */ @@ -172,12 +167,6 @@ class nsContainerFrame : public nsSplittableFrame { nsContainerFrame* aOldParent, nsContainerFrame* aNewParent); - // Set the view's size and position after its frame has been reflowed. - static void SyncFrameViewAfterReflow( - nsPresContext* aPresContext, nsIFrame* aFrame, nsView* aView, - const nsRect& aInkOverflowArea, - ReflowChildFlags aFlags = ReflowChildFlags::Default); - /** * Converts the minimum and maximum sizes given in inner window app units to * outer window device pixel sizes and assigns these constraints to the @@ -282,8 +271,6 @@ class nsContainerFrame : public nsSplittableFrame { const ReflowInput* aReflowInput, nscoord aX, nscoord aY, ReflowChildFlags aFlags); - static void PositionChildViews(nsIFrame* aFrame); - /** * Let the absolutely positioned containing block reflow any absolutely * positioned child frames that need to be reflowed. @@ -461,14 +448,6 @@ class nsContainerFrame : public nsSplittableFrame { virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsDisplayListSet& aLists) override; - static void PlaceFrameView(nsIFrame* aFrame) { - if (aFrame->GetView()) { - nsContainerFrame::PositionFrameView(aFrame); - } else { - nsContainerFrame::PositionChildViews(aFrame); - } - } - /** * Returns a CSS Box Alignment constant which the caller can use to align * the absolutely-positioned child (whose ReflowInput is aChildRI) within diff --git a/layout/generic/nsFlexContainerFrame.cpp b/layout/generic/nsFlexContainerFrame.cpp @@ -6265,8 +6265,6 @@ void nsFlexContainerFrame::MoveFlexItemToFinalPosition( FLEX_ITEM_LOG(aItem.Frame(), "Moving item to its desired position %s", ToString(pos).c_str()); aItem.Frame()->SetPosition(outerWM, pos, aContainerSize); - PositionFrameView(aItem.Frame()); - PositionChildViews(aItem.Frame()); } nsReflowStatus nsFlexContainerFrame::ReflowFlexItem( diff --git a/layout/generic/nsFrameStateBits.h b/layout/generic/nsFrameStateBits.h @@ -165,8 +165,7 @@ FRAME_STATE_BIT(Generic, 16, NS_FRAME_MAY_BE_TRANSFORMED) // or is incomplete (its next sibling is a bidi continuation) FRAME_STATE_BIT(Generic, 17, NS_FRAME_IS_BIDI) -// If this bit is set the frame has descendant with a view -FRAME_STATE_BIT(Generic, 18, NS_FRAME_HAS_CHILD_WITH_VIEW) +// Free bit here. // If this bit is set, then reflow may be dispatched from the current // frame instead of the root frame. diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp @@ -5735,7 +5735,6 @@ static nscoord MeasuringReflow(nsIFrame* aChild, nsReflowStatus childStatus; const nsIFrame::ReflowChildFlags flags = nsIFrame::ReflowChildFlags::NoMoveFrame | - nsIFrame::ReflowChildFlags::NoSizeView | nsIFrame::ReflowChildFlags::NoDeleteNextInFlowChild; // Reflowing the child might invalidate the cache, so we declare the variable diff --git a/layout/generic/nsIFrame.cpp b/layout/generic/nsIFrame.cpp @@ -344,11 +344,6 @@ bool nsIFrame::IsVisibleConsideringAncestors(uint32_t aFlags) const { const nsIFrame* frame = this; while (frame) { - nsView* view = frame->GetView(); - if (view && view->GetVisibility() == ViewVisibility::Hide) { - return false; - } - // Checking mMozSubtreeHiddenOnlyVisually is relatively slow because it // involves loading more memory. It's only allowed in chrome sheets so let's // only support it in the parent process so we can mostly optimize this out @@ -1522,26 +1517,6 @@ void nsIFrame::AssertNewStyleIsSane(ComputedStyle& aNewStyle) { } #endif -void nsIFrame::SyncFrameViewProperties(nsView* aView) { - if (!aView) { - aView = GetView(); - if (!aView) { - return; - } - } - - nsViewManager* vm = aView->GetViewManager(); - - // Make sure visibility is correct. This only affects nsSubDocumentFrame. - if (!SupportsVisibilityHidden()) { - // See if the view should be hidden or visible - ComputedStyle* sc = Style(); - vm->SetViewVisibility(aView, sc->StyleVisibility()->IsVisible() - ? ViewVisibility::Show - : ViewVisibility::Hide); - } -} - /* virtual */ nsMargin nsIFrame::GetUsedMargin() const { nsMargin margin; @@ -7740,17 +7715,11 @@ nsIFrame* nsIFrame::GetTailContinuation() { void nsIFrame::SetView(nsView* aView) { if (aView) { MOZ_ASSERT(MayHaveView(), "Only specific frame types can have an nsView"); + MOZ_ASSERT(!GetParent(), "Only the viewport can have views"); aView->SetFrame(this); // Store the view on the frame. SetViewInternal(aView); - - // Let all of the ancestors know they have a descendant with a view. - for (nsIFrame* f = GetParent(); - f && !f->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW); - f = f->GetParent()) { - f->AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW); - } } else { MOZ_ASSERT_UNREACHABLE("Destroying a view while the frame is alive?"); SetViewInternal(nullptr); @@ -11714,12 +11683,8 @@ void nsIFrame::SetParent(nsContainerFrame* aParent) { MOZ_ASSERT(!mParent || PresShell() == mParent->PresShell()); nsFrameState flagsToPropagateSameDoc = - GetStateBits() & - (NS_FRAME_HAS_CHILD_WITH_VIEW | NS_FRAME_CONTAINS_RELATIVE_BSIZE | - NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE); - if (GetView()) { - flagsToPropagateSameDoc |= NS_FRAME_HAS_CHILD_WITH_VIEW; - } + GetStateBits() & (NS_FRAME_CONTAINS_RELATIVE_BSIZE | + NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE); if (flagsToPropagateSameDoc) { for (nsIFrame* f = aParent; f; f = f->GetParent()) { if (f->HasAllStateBits(flagsToPropagateSameDoc)) { diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h @@ -3159,28 +3159,20 @@ class nsIFrame : public nsQueryFrame { virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aReflowOutput, const ReflowInput& aReflowInput, nsReflowStatus& aStatus); - // Option flags for ReflowChild(), FinishReflowChild(), and - // SyncFrameViewAfterReflow(). + // Option flags for ReflowChild(), FinishReflowChild() enum class ReflowChildFlags : uint32_t { Default = 0, - // Don't position the frame's view. Set this if you don't want to - // automatically sync the frame and view. - NoMoveView = 1 << 0, - - // Don't move the frame. Also implies NoMoveView. - NoMoveFrame = (1 << 1) | NoMoveView, - - // Don't size the frame's view. - NoSizeView = 1 << 2, + // Don't move the frame. + NoMoveFrame = (1 << 0), // Only applies to ReflowChild; if true, don't delete the next-in-flow, even // if the reflow is fully complete. - NoDeleteNextInFlowChild = 1 << 3, + NoDeleteNextInFlowChild = 1 << 1, // Only applies to FinishReflowChild. Tell it to call // ApplyRelativePositioning. - ApplyRelativePositioning = 1 << 4, + ApplyRelativePositioning = 1 << 2, }; /** @@ -3350,14 +3342,6 @@ class nsIFrame : public nsQueryFrame { nsView* GetClosestView(nsPoint* aOffset = nullptr) const; /** - * Sets the view's attributes from the frame style. - * Call this for nsChangeHint_SyncFrameView style changes or when the view - * has just been created. - * @param aView the frame's view or use GetView() if nullptr is given - */ - void SyncFrameViewProperties(nsView* aView = nullptr); - - /** * Get the offset between the coordinate systems of |this| and aOther. * Adding the return value to a point in the coordinate system of |this| * will transform the point to the coordinate system of aOther. diff --git a/layout/generic/nsLineLayout.cpp b/layout/generic/nsLineLayout.cpp @@ -3426,15 +3426,6 @@ void nsLineLayout::RelativePositionFrames(PerSpanData* psd, // Adjust the origin of the frame ApplyRelativePositioning(pfd); - // We must position the view correctly before positioning its - // descendants so that widgets are positioned properly (since only - // some views have widgets). - if (auto* view = frame->GetView()) { - nsContainerFrame::SyncFrameViewAfterReflow( - mPresContext, frame, view, pfd->mOverflowAreas.InkOverflow(), - nsIFrame::ReflowChildFlags::NoSizeView); - } - // Note: the combined area of a child is in its coordinate // system. We adjust the childs combined area into our coordinate // system before computing the aggregated value by adding in @@ -3463,24 +3454,6 @@ void nsLineLayout::RelativePositionFrames(PerSpanData* psd, } frame->FinishAndStoreOverflow(r, frame->GetSize()); } - - // If we have something that's not an inline but with a complex frame - // hierarchy inside that contains views, they need to be - // positioned. - // All descendant views must be repositioned even if this frame - // does have a view in case this frame's view does not have a - // widget and some of the descendant views do have widgets -- - // otherwise the widgets won't be repositioned. - nsContainerFrame::PositionChildViews(frame); - } - - // Do this here (rather than along with setting the overflow rect - // below) so we get leaf frames as well. No need to worry - // about the root span, since it doesn't have a frame. - if (auto* view = frame->GetView()) { - nsContainerFrame::SyncFrameViewAfterReflow( - mPresContext, frame, view, r.InkOverflow(), - nsIFrame::ReflowChildFlags::NoMoveView); } overflowAreas.UnionWith(r + frame->GetPosition()); diff --git a/layout/generic/nsRubyTextContainerFrame.cpp b/layout/generic/nsRubyTextContainerFrame.cpp @@ -146,7 +146,6 @@ void nsRubyTextContainerFrame::Reflow(nsPresContext* aPresContext, // Relative positioning hasn't happened yet. // So MovePositionBy should not be used here. child->SetPosition(rtcWM, pos, containerSize); - nsContainerFrame::PlaceFrameView(child); } aDesiredSize.SetSize(rtcWM, size); } else { diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp @@ -1184,7 +1184,6 @@ nsresult nsPrintJob::SetRootView(nsPrintObject* aPO, bool aDocumentIsTopLevel, bool& doReturn, nsSize& adjSize) { bool canCreateScrollbars = true; - nsView* rootView; if (!aDocumentIsTopLevel) { nsIFrame* frame = aPO->mContent ? aPO->mContent->GetPrimaryFrame() : nullptr; @@ -1210,24 +1209,16 @@ nsresult nsPrintJob::SetRootView(nsPrintObject* aPO, bool aDocumentIsTopLevel, adjSize = mPrt->mPrintDC->GetDeviceSurfaceDimensions(); } - if ((rootView = aPO->mViewManager->GetRootView())) { - // Remove it from its existing parent if necessary - aPO->mViewManager->RemoveChild(rootView); - rootView->SetParent(nullptr); - } else { + if (!aPO->mViewManager->GetRootView()) { // Create a child window of the parent that is our "root view/window" - nsRect tbounds = nsRect(nsPoint(), adjSize); - rootView = aPO->mViewManager->CreateView(tbounds, nullptr); - NS_ENSURE_TRUE(rootView, NS_ERROR_OUT_OF_MEMORY); + nsView* rootView = aPO->mViewManager->CreateView(adjSize); + aPO->mViewManager->SetRootView(rootView); } if (mIsCreatingPrintPreview && aDocumentIsTopLevel) { aPO->mPresContext->SetPaginatedScrolling(canCreateScrollbars); } - // Setup hierarchical relationship in view manager - aPO->mViewManager->SetRootView(rootView); - return NS_OK; } diff --git a/layout/style/RestyleManager.cpp b/layout/style/RestyleManager.cpp @@ -749,11 +749,10 @@ static bool gInApplyRenderingChangeToTree = false; #endif /** - * Sync views on the frame and all of it's descendants (following placeholders). * The change hint should be some combination of nsChangeHint_RepaintFrame, * nsChangeHint_UpdateOpacityLayer and nsChangeHint_SchedulePaint, nothing else. */ -static void SyncViewsAndInvalidateDescendants(nsIFrame*, nsChangeHint); +static void InvalidateDescendants(nsIFrame*, nsChangeHint); static void StyleChangeReflow(nsIFrame* aFrame, nsChangeHint aHint); @@ -819,14 +818,6 @@ static bool RecomputePosition(nsIFrame* aFrame) { return true; } - // Don't process position changes on frames which have views or the ones which - // have a view somewhere in their descendants, because the corresponding view - // needs to be repositioned properly as well. - if (aFrame->GetView() || - aFrame->HasAnyStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW)) { - return false; - } - if (aFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) { // If the frame has an intrinsic block-size, we resolve its 'auto' margins // after doing layout, since we need to know the frame's block size. See @@ -1178,11 +1169,11 @@ static void DoApplyRenderingChangeToTree(nsIFrame* aFrame, aFrame = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(aFrame)) { // Invalidate and sync views on all descendant frames, following // placeholders. We don't need to update transforms in - // SyncViewsAndInvalidateDescendants, because there can't be any + // InvalidateDescendants, because there can't be any // out-of-flows or popups that need to be transformed; all out-of-flow // descendants of the transformed element must also be descendants of the // transformed frame. - SyncViewsAndInvalidateDescendants( + InvalidateDescendants( aFrame, nsChangeHint(aChange & (nsChangeHint_RepaintFrame | nsChangeHint_UpdateOpacityLayer | nsChangeHint_SchedulePaint))); @@ -1249,8 +1240,7 @@ static void DoApplyRenderingChangeToTree(nsIFrame* aFrame, } } -static void SyncViewsAndInvalidateDescendants(nsIFrame* aFrame, - nsChangeHint aChange) { +static void InvalidateDescendants(nsIFrame* aFrame, nsChangeHint aChange) { MOZ_ASSERT(gInApplyRenderingChangeToTree, "should only be called within ApplyRenderingChangeToTree"); @@ -1260,8 +1250,6 @@ static void SyncViewsAndInvalidateDescendants(nsIFrame* aFrame, nsChangeHint_SchedulePaint)), "Invalid change flag"); - aFrame->SyncFrameViewProperties(); - for (const auto& [list, listID] : aFrame->ChildLists()) { for (nsIFrame* child : list) { if (!child->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) { @@ -1272,7 +1260,7 @@ static void SyncViewsAndInvalidateDescendants(nsIFrame* aFrame, nsPlaceholderFrame::GetRealFrameForPlaceholder(child); DoApplyRenderingChangeToTree(outOfFlowFrame, aChange); } else { // regular frame - SyncViewsAndInvalidateDescendants(child, aChange); + InvalidateDescendants(child, aChange); } } } diff --git a/layout/tables/nsTableCellFrame.cpp b/layout/tables/nsTableCellFrame.cpp @@ -471,10 +471,6 @@ void nsTableCellFrame::AlignChildWithinCell( FinishAndStoreOverflow(&reflowOutput); if (kidPosition != kidRect.Origin(innerWM)) { - // Make sure any child views are correctly positioned. We know the inner - // table cell won't have a view. - nsContainerFrame::PositionChildViews(inner); - // Invalidate new overflow rect. inner->InvalidateFrameSubtree(); } diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp @@ -212,12 +212,6 @@ void nsTableFrame::Destroy(DestroyContext& aContext) { nsContainerFrame::Destroy(aContext); } -// Make sure any views are positioned properly -void nsTableFrame::RePositionViews(nsIFrame* aFrame) { - nsContainerFrame::PositionFrameView(aFrame); - nsContainerFrame::PositionChildViews(aFrame); -} - static bool IsRepeatedFrame(nsIFrame* kidFrame) { return (kidFrame->IsTableRowFrame() || kidFrame->IsTableRowGroupFrame()) && kidFrame->HasAnyStateBits(NS_REPEATED_ROW_OR_ROWGROUP); @@ -1787,7 +1781,6 @@ void nsTableFrame::Reflow(nsPresContext* aPresContext, if (0 != xAdjustmentForAllKids) { for (nsIFrame* kid : mFrames) { kid->MovePositionBy(nsPoint(xAdjustmentForAllKids, 0)); - RePositionViews(kid); } } } @@ -2884,7 +2877,6 @@ void nsTableFrame::ReflowChildren(TableReflowInput& aReflowInput, // move to the new position kidFrame->MovePositionBy( wm, LogicalPoint(wm, 0, aReflowInput.mBCoord - kidRect.BStart(wm))); - RePositionViews(kidFrame); // invalidate the new position kidFrame->InvalidateFrameSubtree(); } @@ -3088,7 +3080,6 @@ void nsTableFrame::DistributeBSizeToRows(const ReflowInput& aReflowInput, amountUsed += amountForRow; amountUsedByRG += amountForRow; // rowFrame->DidResize(); - nsTableFrame::RePositionViews(rowFrame); rgFrame->InvalidateFrameWithRect(origRowRect); rgFrame->InvalidateFrame(); @@ -3099,7 +3090,6 @@ void nsTableFrame::DistributeBSizeToRows(const ReflowInput& aReflowInput, rowFrame->InvalidateFrameSubtree(); rowFrame->MovePositionBy( wm, LogicalPoint(wm, 0, bOriginRow - rowNormalRect.BStart(wm))); - nsTableFrame::RePositionViews(rowFrame); rowFrame->InvalidateFrameSubtree(); } bOriginRow += rowNormalRect.BSize(wm) + rowSpacing; @@ -3129,7 +3119,6 @@ void nsTableFrame::DistributeBSizeToRows(const ReflowInput& aReflowInput, rgFrame->MovePositionBy( wm, LogicalPoint(wm, 0, bOriginRG - rgNormalRect.BStart(wm))); // Make sure child views are properly positioned - nsTableFrame::RePositionViews(rgFrame); rgFrame->InvalidateFrameSubtree(); } bOriginRG = bEndRG; @@ -3263,8 +3252,6 @@ void nsTableFrame::DistributeBSizeToRows(const ReflowInput& aReflowInput, amountUsedByRG += amountForRow; NS_ASSERTION((amountUsed <= aAmount), "invalid row allocation"); // rowFrame->DidResize(); - nsTableFrame::RePositionViews(rowFrame); - nsTableFrame::InvalidateTableFrame(rowFrame, origRowRect, rowInkOverflow, false); } else { @@ -3272,7 +3259,6 @@ void nsTableFrame::DistributeBSizeToRows(const ReflowInput& aReflowInput, rowFrame->InvalidateFrameSubtree(); rowFrame->MovePositionBy( wm, LogicalPoint(wm, 0, bOriginRow - rowNormalRect.BStart(wm))); - nsTableFrame::RePositionViews(rowFrame); rowFrame->InvalidateFrameSubtree(); } bOriginRow += rowNormalRect.BSize(wm) + rowSpacing; @@ -3308,7 +3294,6 @@ void nsTableFrame::DistributeBSizeToRows(const ReflowInput& aReflowInput, rowFrame = rowFrame->GetNextRow()) { rowFrame->InvalidateFrameSubtree(); rowFrame->MovePositionBy(nsPoint(rgWidth, 0)); - nsTableFrame::RePositionViews(rowFrame); rowFrame->InvalidateFrameSubtree(); } } @@ -3317,7 +3302,6 @@ void nsTableFrame::DistributeBSizeToRows(const ReflowInput& aReflowInput, rgFrame->MovePositionBy( wm, LogicalPoint(wm, 0, bOriginRG - rgNormalRect.BStart(wm))); // Make sure child views are properly positioned - nsTableFrame::RePositionViews(rgFrame); rgFrame->InvalidateFrameSubtree(); } bOriginRG = bEndRG; diff --git a/layout/tables/nsTableFrame.h b/layout/tables/nsTableFrame.h @@ -178,8 +178,6 @@ class nsTableFrame : public nsContainerFrame { // special height reflow will occur. static void RequestSpecialBSizeReflow(const ReflowInput& aReflowInput); - static void RePositionViews(nsIFrame* aFrame); - static bool PageBreakAfter(nsIFrame* aSourceFrame, nsIFrame* aNextFrame); // Register or deregister a positioned table part with its nsTableFrame. diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp @@ -355,7 +355,6 @@ void nsTableRowFrame::DidResize(ForceAlignTopForTableCell aForceAlignTop) { if (oldPos != newPos) { cellFrame->SetPosition(wm, newPos, containerSize); - nsTableFrame::RePositionViews(cellFrame); } } @@ -781,16 +780,6 @@ void nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext, desiredSize.SetSize(wm, cellDesiredSize); desiredSize.mOverflowAreas = kidFrame->GetOverflowAreas(); - - // if we are in a floated table, our position is not yet established, so - // we cannot reposition our views the containing block will do this for - // us after positioning the table - if (!aTableFrame.IsFloating()) { - // Because we may have moved the frame we need to make sure any views - // are positioned properly. We have to do this, because any one of our - // parent frames could have moved and we have no way of knowing... - nsTableFrame::RePositionViews(kidFrame); - } } if (NS_UNCONSTRAINEDSIZE == aReflowInput.AvailableBSize()) { @@ -854,7 +843,6 @@ void nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext, // positioning. kidFrame->MovePositionBy( wm, LogicalPoint(wm, iCoord - origKidNormalPosition.I(wm), 0)); - nsTableFrame::RePositionViews(kidFrame); // invalidate the new position kidFrame->InvalidateFrameSubtree(); } @@ -911,7 +899,6 @@ void nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext, kidFrame->MovePositionBy( wm, LogicalPoint(wm, 0, kidFrame->BSize(wm) - aDesiredSize.BSize(wm))); - nsTableFrame::RePositionViews(kidFrame); // Do we need to InvalidateFrameSubtree() here? } } @@ -1198,7 +1185,6 @@ nscoord nsTableRowFrame::CollapseRowIfNecessary(nscoord aRowOffset, OverflowAreas cellOverflow(cellPhysicalBounds, cellPhysicalBounds); cellFrame->FinishAndStoreOverflow(cellOverflow, cRect.Size(wm).GetPhysicalSize(wm)); - nsTableFrame::RePositionViews(cellFrame); ConsiderChildOverflow(overflow, cellFrame); if (aRowOffset == 0) { @@ -1211,8 +1197,6 @@ nscoord nsTableRowFrame::CollapseRowIfNecessary(nscoord aRowOffset, SetRect(wm, rowRect, containerSize); overflow.UnionAllWith(nsRect(0, 0, rowRect.Width(wm), rowRect.Height(wm))); FinishAndStoreOverflow(overflow, rowRect.Size(wm).GetPhysicalSize(wm)); - - nsTableFrame::RePositionViews(this); nsTableFrame::InvalidateTableFrame(this, oldRect, oldInkOverflow, false); return shift; } diff --git a/layout/tables/nsTableRowGroupFrame.cpp b/layout/tables/nsTableRowGroupFrame.cpp @@ -432,7 +432,6 @@ void nsTableRowGroupFrame::ReflowChildren( const LogicalPoint offset(wm, 0, aReflowInput.mBCoord - oldPosition.B(wm)); kidFrame->MovePositionBy(wm, offset); - nsTableFrame::RePositionViews(kidFrame); kidFrame->InvalidateFrameSubtree(); } @@ -828,7 +827,6 @@ void nsTableRowGroupFrame::CalculateRowBSizes(nsPresContext* aPresContext, false); if (deltaB != 0) { - nsTableFrame::RePositionViews(rowFrame); // XXXbz we don't need to update our overflow area? } } @@ -891,7 +889,6 @@ nscoord nsTableRowGroupFrame::CollapseRowGroupIfNecessary(nscoord aBTotalOffset, overflow.UnionAllWith( nsRect(0, 0, groupRect.Width(aWM), groupRect.Height(aWM))); FinishAndStoreOverflow(overflow, groupRect.Size(aWM).GetPhysicalSize(aWM)); - nsTableFrame::RePositionViews(this); nsTableFrame::InvalidateTableFrame(this, oldGroupRect, oldGroupInkOverflow, false); diff --git a/view/nsView.cpp b/view/nsView.cpp @@ -28,15 +28,9 @@ using namespace mozilla; using namespace mozilla::widget; -nsView::nsView(nsViewManager* aViewManager, ViewVisibility aVisibility) +nsView::nsView(nsViewManager* aViewManager) : mViewManager(aViewManager), - mParent(nullptr), - mNextSibling(nullptr), - mFirstChild(nullptr), mFrame(nullptr), - mVis(aVisibility), - mPosX(0), - mPosY(0), mWidgetIsTopLevel(false), mForcedRepaint(false), mNeedsWindowPropertiesSync(false) { @@ -50,45 +44,22 @@ nsView::nsView(nsViewManager* aViewManager, ViewVisibility aVisibility) void nsView::DropMouseGrabbing() { if (mViewManager->GetPresShell()) { - PresShell::ClearMouseCaptureOnView(this); + PresShell::ClearMouseCapture(); } } nsView::~nsView() { MOZ_COUNT_DTOR(nsView); - while (GetFirstChild()) { - nsView* child = GetFirstChild(); - if (child->GetViewManager() == mViewManager) { - child->Destroy(); - } else { - // just unhook it. Someone else will want to destroy this. - RemoveChild(child); - } - } - if (mViewManager) { DropMouseGrabbing(); nsView* rootView = mViewManager->GetRootView(); - - if (rootView) { - // Root views can have parents! - if (mParent) { - mViewManager->RemoveChild(this); - } - - if (rootView == this) { - // Inform the view manager that the root view has gone away... - mViewManager->SetRootView(nullptr); - } - } else if (mParent) { - mParent->RemoveChild(this); + if (rootView == this) { + // Inform the view manager that the root view has gone away... + mViewManager->SetRootView(nullptr); } - mViewManager = nullptr; - } else if (mParent) { - mParent->RemoveChild(this); } if (mPreviousWindow) { @@ -164,24 +135,6 @@ void nsView::Destroy() { nsView::operator delete(this); } -void nsView::SetPosition(nscoord aX, nscoord aY) { - mDimBounds.MoveBy(aX - mPosX, aY - mPosY); - mPosX = aX; - mPosY = aY; - - NS_ASSERTION(GetParent() || (aX == 0 && aY == 0), - "Don't try to move the root widget to something non-zero"); -} - -bool nsView::IsEffectivelyVisible() { - for (nsView* v = this; v; v = v->mParent) { - if (v->GetVisibility() == ViewVisibility::Hide) { - return false; - } - } - return true; -} - struct WidgetViewBounds { nsRect mBounds; int32_t mRoundTo = 1; @@ -239,9 +192,8 @@ static LayoutDeviceIntRect WidgetViewBoundsToDevicePixels( LayoutDeviceIntRect nsView::CalcWidgetBounds(WindowType aType, TransparencyMode aTransparency) { int32_t p2a = mViewManager->AppUnitsPerDevPixel(); - auto viewBounds = CalcWidgetViewBounds( - mDimBounds, p2a, GetParent() ? GetParent()->GetFrame() : nullptr, - mWindow.get(), aType); + auto viewBounds = + CalcWidgetViewBounds(mDimBounds, p2a, nullptr, mWindow.get(), aType); auto newBounds = WidgetViewBoundsToDevicePixels(viewBounds, p2a, aType, aTransparency); @@ -253,10 +205,10 @@ LayoutDeviceIntRect nsView::CalcWidgetBounds(WindowType aType, // mViewToWidgetOffset is added to coordinates relative to the view origin // to get coordinates relative to the widget. // The view origin, relative to the parent widget, is at - // (mPosX,mPosY) - mDimBounds.TopLeft() + viewBounds.TopLeft(). + // mDimBounds.TopLeft() + viewBounds.TopLeft(). // Our widget, relative to the parent widget, is roundedOffset. - mViewToWidgetOffset = nsPoint(mPosX, mPosY) - mDimBounds.TopLeft() + - viewBounds.mBounds.TopLeft() - roundedOffset; + mViewToWidgetOffset = + mDimBounds.TopLeft() + viewBounds.mBounds.TopLeft() - roundedOffset; return newBounds; } @@ -276,85 +228,15 @@ LayoutDeviceIntRect nsView::RecalcWidgetBounds() { } void nsView::SetDimensions(const nsRect& aRect) { - nsRect dims = aRect; - dims.MoveBy(mPosX, mPosY); - // Don't use nsRect's operator== here, since it returns true when // both rects are empty even if they have different widths and we // have cases where that sort of thing matters to us. - if (mDimBounds.TopLeft() == dims.TopLeft() && - mDimBounds.Size() == dims.Size()) { + if (mDimBounds.TopLeft() == aRect.TopLeft() && + mDimBounds.Size() == aRect.Size()) { return; } - mDimBounds = dims; -} - -void nsView::NotifyEffectiveVisibilityChanged(bool aEffectivelyVisible) { - if (!aEffectivelyVisible) { - DropMouseGrabbing(); - } - - SetForcedRepaint(true); - - for (nsView* child = mFirstChild; child; child = child->mNextSibling) { - if (child->mVis == ViewVisibility::Hide) { - // It was effectively hidden and still is - continue; - } - // Our child is visible if we are - child->NotifyEffectiveVisibilityChanged(aEffectivelyVisible); - } -} - -void nsView::SetVisibility(ViewVisibility aVisibility) { - mVis = aVisibility; - NotifyEffectiveVisibilityChanged(IsEffectivelyVisible()); -} - -void nsView::InsertChild(nsView* aChild, nsView* aSibling) { - MOZ_ASSERT(nullptr != aChild, "null ptr"); - - if (nullptr != aChild) { - if (nullptr != aSibling) { -#ifdef DEBUG - NS_ASSERTION(aSibling->GetParent() == this, - "tried to insert view with invalid sibling"); -#endif - // insert after sibling - aChild->SetNextSibling(aSibling->GetNextSibling()); - aSibling->SetNextSibling(aChild); - } else { - aChild->SetNextSibling(mFirstChild); - mFirstChild = aChild; - } - aChild->SetParent(this); - } -} - -void nsView::RemoveChild(nsView* child) { - MOZ_ASSERT(nullptr != child, "null ptr"); - - if (nullptr != child) { - nsView* prevKid = nullptr; - nsView* kid = mFirstChild; - DebugOnly<bool> found = false; - while (nullptr != kid) { - if (kid == child) { - if (nullptr != prevKid) { - prevKid->SetNextSibling(kid->GetNextSibling()); - } else { - mFirstChild = kid->GetNextSibling(); - } - child->SetParent(nullptr); - found = true; - break; - } - prevKid = kid; - kid = kid->GetNextSibling(); - } - NS_ASSERTION(found, "tried to remove non child"); - } + mDimBounds = aRect; } void nsView::SetNeedsWindowPropertiesSync() { @@ -469,106 +351,14 @@ void nsView::List(FILE* out, int32_t aIndent) const { windowBounds.Width(), windowBounds.Height()); } nsRect brect = GetBounds(); - fprintf(out, "{%d,%d,%d,%d} @ %d,%d", brect.X(), brect.Y(), brect.Width(), - brect.Height(), mPosX, mPosY); - fprintf(out, " vis=%d frame=%p <\n", int(mVis), mFrame); - for (nsView* kid = mFirstChild; kid; kid = kid->GetNextSibling()) { - NS_ASSERTION(kid->GetParent() == this, "incorrect parent"); - kid->List(out, aIndent + 1); - } + fprintf(out, "{%d,%d,%d,%d}", brect.X(), brect.Y(), brect.Width(), + brect.Height()); + fprintf(out, " vis=%d frame=%p <\n", mFrame); for (i = aIndent; --i >= 0;) fputs(" ", out); fputs(">\n", out); } #endif // DEBUG -nsPoint nsView::GetOffsetTo(const nsView* aOther) const { - return GetOffsetTo(aOther, GetViewManager()->AppUnitsPerDevPixel()); -} - -nsPoint nsView::GetOffsetTo(const nsView* aOther, const int32_t aAPD) const { - MOZ_ASSERT(GetParent() || !aOther || aOther->GetParent() || this == aOther, - "caller of (outer) GetOffsetTo must not pass unrelated views"); - // We accumulate the final result in offset - nsPoint offset(0, 0); - // The offset currently accumulated at the current APD - nsPoint docOffset(0, 0); - const nsView* v = this; - nsViewManager* currVM = v->GetViewManager(); - int32_t currAPD = currVM->AppUnitsPerDevPixel(); - const nsView* root = nullptr; - for (; v != aOther && v; root = v, v = v->GetParent()) { - nsViewManager* newVM = v->GetViewManager(); - if (newVM != currVM) { - int32_t newAPD = newVM->AppUnitsPerDevPixel(); - if (newAPD != currAPD) { - offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD); - docOffset.x = docOffset.y = 0; - currAPD = newAPD; - } - currVM = newVM; - } - docOffset += v->GetPosition(); - } - offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD); - - if (v != aOther) { - // Looks like aOther wasn't an ancestor of |this|. So now we have - // the root-VM-relative position of |this| in |offset|. Get the - // root-VM-relative position of aOther and subtract it. - nsPoint negOffset = aOther->GetOffsetTo(root, aAPD); - offset -= negOffset; - } - - return offset; -} - -nsIWidget* nsView::GetNearestWidget(nsPoint* aOffset) const { - return GetNearestWidget(aOffset, GetViewManager()->AppUnitsPerDevPixel()); -} - -nsIWidget* nsView::GetNearestWidget(nsPoint* aOffset, - const int32_t aAPD) const { - // aOffset is based on the view's position, which ignores any chrome on - // attached parent widgets. - - // We accumulate the final result in pt - nsPoint pt(0, 0); - // The offset currently accumulated at the current APD - nsPoint docPt(0, 0); - const nsView* v = this; - nsViewManager* currVM = v->GetViewManager(); - int32_t currAPD = currVM->AppUnitsPerDevPixel(); - for (; v && !v->HasWidget(); v = v->GetParent()) { - nsViewManager* newVM = v->GetViewManager(); - if (newVM != currVM) { - int32_t newAPD = newVM->AppUnitsPerDevPixel(); - if (newAPD != currAPD) { - pt += docPt.ScaleToOtherAppUnits(currAPD, aAPD); - docPt.x = docPt.y = 0; - currAPD = newAPD; - } - currVM = newVM; - } - docPt += v->GetPosition(); - } - if (!v) { - if (aOffset) { - pt += docPt.ScaleToOtherAppUnits(currAPD, aAPD); - *aOffset = pt; - } - return nullptr; - } - - // pt is now the offset from v's origin to this view's origin. - // We add the ViewToWidgetOffset to get the offset to the widget. - if (aOffset) { - docPt += v->ViewToWidgetOffset(); - pt += docPt.ScaleToOtherAppUnits(currAPD, aAPD); - *aOffset = pt; - } - return v->GetWidget(); -} - bool nsView::IsRoot() const { NS_ASSERTION(mViewManager != nullptr, " View manager is null in nsView::IsRoot()"); diff --git a/view/nsView.h b/view/nsView.h @@ -93,12 +93,6 @@ enum class WindowType : uint8_t; * nsDocumentViewer::ShouldAttachToTopLevel) */ -// Enumerated type to indicate the visibility of a layer. -// hide - the layer is not shown. -// show - the layer is shown irrespective of the visibility of -// the layer's parent. -enum class ViewVisibility : uint8_t { Hide = 0, Show = 1 }; - //---------------------------------------------------------------------- /** @@ -151,20 +145,6 @@ class nsView final : public nsIWidgetListener { void Destroy(); /** - * Called to get the position of a view. - * The specified coordinates are relative to the parent view's origin, but - * are in appunits of this. - * This is the (0, 0) origin of the coordinate space established by this view. - * @param x out parameter for x position - * @param y out parameter for y position - */ - nsPoint GetPosition() const { - NS_ASSERTION(!IsRoot() || (mPosX == 0 && mPosY == 0), - "root views should always have explicit position of (0,0)"); - return nsPoint(mPosX, mPosY); - } - - /** * Called to get the dimensions and position of the view's bounds. * The view's bounds (x,y) are relative to the origin of the parent view, but * are in appunits of this. @@ -175,60 +155,6 @@ class nsView final : public nsIWidgetListener { nsRect GetBounds() const { return mDimBounds; } /** - * The bounds of this view relative to this view. So this is the same as - * GetBounds except this is relative to this view instead of the parent view. - */ - nsRect GetDimensions() const { - nsRect r = mDimBounds; - r.MoveBy(-mPosX, -mPosY); - return r; - } - - /** - * Get the offset between the coordinate systems of |this| and aOther. - * Adding the return value to a point in the coordinate system of |this| - * will transform the point to the coordinate system of aOther. - * - * The offset is expressed in appunits of |this|. So if you are getting the - * offset between views in different documents that might have different - * appunits per devpixel ratios you need to be careful how you use the - * result. - * - * If aOther is null, this will return the offset of |this| from the - * root of the viewmanager tree. - * - * This function is fastest when aOther is an ancestor of |this|. - * - * NOTE: this actually returns the offset from aOther to |this|, but - * that offset is added to transform _coordinates_ from |this| to aOther. - */ - nsPoint GetOffsetTo(const nsView* aOther) const; - - /** - * Called to query the visibility state of a view. - * @result current visibility state - */ - ViewVisibility GetVisibility() const { return mVis; } - - /** - * Called to query the parent of the view. - * @result view's parent - */ - nsView* GetParent() const { return mParent; } - - /** - * The view's first child is the child which is earliest in document order. - * @result first child - */ - nsView* GetFirstChild() const { return mFirstChild; } - - /** - * Called to query the next sibling of the view. - * @result view's next sibling - */ - nsView* GetNextSibling() const { return mNextSibling; } - - /** * Set the view's frame. */ void SetFrame(nsIFrame* aRootFrame) { mFrame = aRootFrame; } @@ -239,18 +165,6 @@ class nsView final : public nsIWidgetListener { nsIFrame* GetFrame() const { return mFrame; } /** - * Get the nearest widget in this view or a parent of this view and - * the offset from the widget's origin to this view's origin - * @param aOffset - if non-null the offset from this view's origin to the - * widget's origin (usually positive) expressed in appunits of this will be - * returned in aOffset. - * @return the widget closest to this view; can be null because some view - * trees don't have widgets at all (e.g., printing), but if any view in the - * view tree has a widget, then it's safe to assume this will not return null - */ - nsIWidget* GetNearestWidget(nsPoint* aOffset) const; - - /** * Destroys the associated widget for this view. If this method is * not called explicitly, the widget when be destroyed when its * view gets destroyed. @@ -346,19 +260,6 @@ class nsView final : public nsIWidgetListener { // origin) to view origin expressed in appunits of this. nsPoint ViewToWidgetOffset() const { return mViewToWidgetOffset; } - /** - * Called to indicate that the position of the view has been changed. - * The specified coordinates are in the parent view's coordinate space. - * @param x new x position - * @param y new y position - */ - void SetPosition(nscoord aX, nscoord aY); - void SetParent(nsView* aParent) { mParent = aParent; } - void SetNextSibling(nsView* aSibling) { - NS_ASSERTION(aSibling != this, "Can't be our own sibling!"); - mNextSibling = aSibling; - } - // nsIWidgetListener mozilla::PresShell* GetPresShell() override; nsView* GetView() override { return this; } @@ -388,19 +289,14 @@ class nsView final : public nsIWidgetListener { virtual ~nsView(); - nsPoint GetOffsetTo(const nsView* aOther, const int32_t aAPD) const; - nsIWidget* GetNearestWidget(nsPoint* aOffset, const int32_t aAPD) const; - bool IsPrimaryFramePaintSuppressed(); private: - explicit nsView(nsViewManager* = nullptr, - ViewVisibility = ViewVisibility::Show); + explicit nsView(nsViewManager* = nullptr); bool ForcedRepaint() { return mForcedRepaint; } void InitializeWindow(bool aEnableDragDrop, bool aResetVisibility); - bool IsEffectivelyVisible(); /** * Called to indicate that the dimensions of the view have been changed. @@ -410,13 +306,6 @@ class nsView final : public nsIWidgetListener { */ void SetDimensions(const nsRect& aRect); - /** - * Called to indicate that the visibility of a view has been - * changed. - * @param visibility new visibility state - */ - void SetVisibility(ViewVisibility visibility); - // Helper function to get mouse grabbing off this view (by moving it to the // parent, if we can) void DropMouseGrabbing(); @@ -424,27 +313,16 @@ class nsView final : public nsIWidgetListener { bool IsDirty() const { return mIsDirty; } void SetIsDirty(bool aDirty) { mIsDirty = aDirty; } - void InsertChild(nsView* aChild, nsView* aSibling); - void RemoveChild(nsView* aChild); - void AssertNoWindow(); - void NotifyEffectiveVisibilityChanged(bool aEffectivelyVisible); - void CallOnAllRemoteChildren( const std::function<mozilla::CallState(mozilla::dom::BrowserParent*)>& aCallback); nsViewManager* mViewManager; - nsView* mParent; nsCOMPtr<nsIWidget> mWindow; nsCOMPtr<nsIWidget> mPreviousWindow; - nsView* mNextSibling; - nsView* mFirstChild; nsIFrame* mFrame; - ViewVisibility mVis; - // position relative our parent view origin but in our appunits - nscoord mPosX, mPosY; // relative to parent, but in our appunits nsRect mDimBounds; // in our appunits diff --git a/view/nsViewManager.cpp b/view/nsViewManager.cpp @@ -73,12 +73,9 @@ nsViewManager::~nsViewManager() { "Releasing nsViewManager without having called Destroy on " "the PresShell!"); } -nsView* nsViewManager::CreateView(const nsRect& aBounds, nsView* aParent, - ViewVisibility aVisibilityFlag) { - auto* v = new nsView(this, aVisibilityFlag); - v->SetParent(aParent); - v->SetPosition(aBounds.X(), aBounds.Y()); - nsRect dim(0, 0, aBounds.Width(), aBounds.Height()); +nsView* nsViewManager::CreateView(const nsSize& aSize) { + auto* v = new nsView(this); + nsRect dim(nsPoint(), aSize); v->SetDimensions(dim); return v; } @@ -95,7 +92,7 @@ void nsViewManager::SetRootView(nsView* aView) { void nsViewManager::GetWindowDimensions(nscoord* aWidth, nscoord* aHeight) { if (nullptr != mRootView) { if (mDelayedResize == nsSize(NSCOORD_NONE, NSCOORD_NONE)) { - nsRect dim = mRootView->GetDimensions(); + nsRect dim = mRootView->GetBounds(); *aWidth = dim.Width(); *aHeight = dim.Height(); } else { @@ -109,7 +106,7 @@ void nsViewManager::GetWindowDimensions(nscoord* aWidth, nscoord* aHeight) { } void nsViewManager::DoSetWindowDimensions(nscoord aWidth, nscoord aHeight) { - nsRect oldDim = mRootView->GetDimensions(); + nsRect oldDim = mRootView->GetBounds(); nsRect newDim(0, 0, aWidth, aHeight); // We care about resizes even when one dimension is already zero. if (oldDim.IsEqualEdges(newDim)) { @@ -124,8 +121,7 @@ void nsViewManager::DoSetWindowDimensions(nscoord aWidth, nscoord aHeight) { bool nsViewManager::ShouldDelayResize() const { MOZ_ASSERT(mRootView); - if (!mRootView->IsEffectivelyVisible() || !mPresShell || - !mPresShell->IsVisible()) { + if (!mPresShell || !mPresShell->IsVisible()) { return true; } if (nsRefreshDriver* rd = mPresShell->GetRefreshDriver()) { @@ -169,36 +165,6 @@ void nsViewManager::FlushDelayedResize() { } } -// Convert aIn from being relative to and in appunits of aFromView, to being -// relative to and in appunits of aToView. -static nsRect ConvertRectBetweenViews(const nsRect& aIn, nsView* aFromView, - nsView* aToView) { - nsRect out = aIn; - out.MoveBy(aFromView->GetOffsetTo(aToView)); - out = out.ScaleToOtherAppUnitsRoundOut( - aFromView->GetViewManager()->AppUnitsPerDevPixel(), - aToView->GetViewManager()->AppUnitsPerDevPixel()); - return out; -} - -nsView* nsViewManager::GetDisplayRootFor(nsView* aView) { - nsView* displayRoot = aView; - for (;;) { - nsView* displayParent = displayRoot->GetParent(); - if (!displayParent) { - return displayRoot; - } - - // Any popup view is a display root. - if (displayRoot->GetFrame() && - displayRoot->GetFrame()->IsMenuPopupFrame()) { - return displayRoot; - } - - displayRoot = displayParent; - } -} - nsViewManager* nsViewManager::RootViewManager() const { const auto* cur = this; while (auto* parent = cur->GetParentViewManager()) { @@ -250,8 +216,8 @@ void nsViewManager::Refresh(nsView* aView, nsAutoScriptBlocker scriptBlocker; SetPainting(true); - NS_ASSERTION(GetDisplayRootFor(aView) == aView, - "Widgets that we paint must all be display roots"); + MOZ_ASSERT(!aView->GetFrame() || !aView->GetFrame()->GetParent(), + "Frame should be a display root"); if (RefPtr<PresShell> presShell = mPresShell) { #ifdef MOZ_DUMP_PAINTING @@ -331,12 +297,6 @@ void nsViewManager::ProcessPendingUpdatesRecurse( return; } - for (nsView* childView = aView->GetFirstChild(); childView; - childView = childView->GetNextSibling()) { - childView->GetViewManager()->ProcessPendingUpdatesRecurse(childView, - aWidgets); - } - nsIWidget* widget = aView->GetWidget(); if (widget) { aWidgets.AppendElement(widget); @@ -349,18 +309,11 @@ void nsViewManager::ProcessPendingUpdatesPaint(nsIWidget* aWidget) { if (aWidget->NeedsPaint()) { // If an ancestor widget was hidden and then shown, we could // have a delayed resize to handle. - for (RefPtr<nsViewManager> vm = this; vm; - vm = vm->mRootView->GetParent() - ? vm->mRootView->GetParent()->GetViewManager() - : nullptr) { - if (vm->mDelayedResize != nsSize(NSCOORD_NONE, NSCOORD_NONE) && - vm->mRootView->IsEffectivelyVisible() && vm->mPresShell && - vm->mPresShell->IsVisible()) { - vm->FlushDelayedResize(); - } + if (mDelayedResize != nsSize(NSCOORD_NONE, NSCOORD_NONE) && mPresShell && + mPresShell->IsVisible()) { + FlushDelayedResize(); } nsView* view = nsView::GetViewFor(aWidget); - if (!view) { NS_ERROR("FlushDelayedResize destroyed the nsView?"); return; @@ -401,19 +354,13 @@ void nsViewManager::FlushDirtyRegionToWidget(nsView* aView) { NS_ASSERTION(aView->GetViewManager() == this, "FlushDirtyRegionToWidget called on view we don't own"); - if (!aView->IsDirty()) { + if (!aView->IsDirty() || !aView->HasWidget()) { return; } - const nsRect dirtyRegion = aView->GetDimensions(); - nsView* nearestViewWithWidget = aView; - while (!nearestViewWithWidget->HasWidget() && - nearestViewWithWidget->GetParent()) { - nearestViewWithWidget = nearestViewWithWidget->GetParent(); - } - nsRect r = ConvertRectBetweenViews(dirtyRegion, aView, nearestViewWithWidget); - nsViewManager* widgetVM = nearestViewWithWidget->GetViewManager(); - widgetVM->InvalidateWidgetArea(nearestViewWithWidget, r); + const nsRect dirtyRegion = aView->GetBounds(); + nsViewManager* widgetVM = aView->GetViewManager(); + widgetVM->InvalidateWidgetArea(aView, dirtyRegion); aView->SetIsDirty(false); } @@ -464,15 +411,8 @@ void nsViewManager::InvalidateWidgetArea(nsView* aWidgetView, } static bool ShouldIgnoreInvalidation(nsViewManager* aVM) { - while (aVM) { - PresShell* presShell = aVM->GetPresShell(); - if (!presShell || presShell->ShouldIgnoreInvalidation()) { - return true; - } - nsView* view = aVM->GetRootView()->GetParent(); - aVM = view ? view->GetViewManager() : nullptr; - } - return false; + PresShell* presShell = aVM->GetPresShell(); + return !presShell || presShell->ShouldIgnoreInvalidation(); } void nsViewManager::InvalidateView(nsView* aView) { @@ -488,7 +428,9 @@ void nsViewManager::InvalidateView(nsView* aView) { if (aView->GetBounds().IsEmpty()) { return; } - GetDisplayRootFor(aView)->SetIsDirty(true); + MOZ_ASSERT(!aView->GetFrame() || !aView->GetFrame()->GetParent(), + "Frame should be a display root"); + aView->SetIsDirty(true); } void nsViewManager::InvalidateAllViews() { @@ -502,13 +444,6 @@ void nsViewManager::InvalidateAllViews() { void nsViewManager::InvalidateViews(nsView* aView) { // Invalidate this view. InvalidateView(aView); - - // Invalidate all children as well. - nsView* childView = aView->GetFirstChild(); - while (nullptr != childView) { - childView->GetViewManager()->InvalidateViews(childView); - childView = childView->GetNextSibling(); - } } void nsViewManager::WillPaintWindow(nsIWidget* aWidget) { @@ -567,32 +502,12 @@ void nsViewManager::DispatchEvent(WidgetGUIEvent* aEvent, nsView* aView, } // Find the view whose coordinates system we're in. - nsView* view = aView; - bool dispatchUsingCoordinates = aEvent->IsUsingCoordinates(); - if (dispatchUsingCoordinates) { - // Will dispatch using coordinates. Pretty bogus but it's consistent - // with what presshell does. - view = GetDisplayRootFor(view); - } - // If the view has no frame, look for a view that does. - nsIFrame* frame = view->GetFrame(); - if (!frame && (dispatchUsingCoordinates || aEvent->HasKeyEventMessage() || - aEvent->IsIMERelatedEvent())) { - while (view && !view->GetFrame()) { - view = view->GetParent(); - } - - if (view) { - frame = view->GetFrame(); - } - } - - if (frame) { + if (nsIFrame* frame = aView->GetFrame()) { // Hold a refcount to the presshell. The continued existence of the // presshell will delay deletion of this view hierarchy should the event // want to cause its destruction in, say, some JavaScript event handler. - if (RefPtr<PresShell> presShell = view->GetViewManager()->GetPresShell()) { + if (RefPtr<PresShell> presShell = aView->GetViewManager()->GetPresShell()) { presShell->HandleEvent(frame, aEvent, false, aStatus); return; } @@ -601,78 +516,10 @@ void nsViewManager::DispatchEvent(WidgetGUIEvent* aEvent, nsView* aView, *aStatus = nsEventStatus_eIgnore; } -void nsViewManager::InsertChild(nsView* aParent, nsView* aChild, - nsView* aSibling, bool aAfter) { - MOZ_ASSERT(nullptr != aParent, "null ptr"); - MOZ_ASSERT(nullptr != aChild, "null ptr"); - NS_ASSERTION(aSibling == nullptr || aSibling->GetParent() == aParent, - "tried to insert view with invalid sibling"); - NS_ASSERTION(!IsViewInserted(aChild), - "tried to insert an already-inserted view"); - - if ((nullptr != aParent) && (nullptr != aChild)) { - // if aAfter is set, we will insert the child after 'prev' (i.e. after 'kid' - // in document order, otherwise after 'kid' (i.e. before 'kid' in document - // order). - - if (nullptr == aSibling) { - if (aAfter) { - // insert at end of document order, i.e., before first view - // this is the common case, by far - aParent->InsertChild(aChild, nullptr); - } else { - // insert at beginning of document order, i.e., after last view - nsView* kid = aParent->GetFirstChild(); - nsView* prev = nullptr; - while (kid) { - prev = kid; - kid = kid->GetNextSibling(); - } - // prev is last view or null if there are no children - aParent->InsertChild(aChild, prev); - } - } else { - nsView* kid = aParent->GetFirstChild(); - nsView* prev = nullptr; - while (kid && aSibling != kid) { - // get the next sibling view - prev = kid; - kid = kid->GetNextSibling(); - } - NS_ASSERTION(kid != nullptr, "couldn't find sibling in child list"); - if (aAfter) { - // insert after 'kid' in document order, i.e. before in view order - aParent->InsertChild(aChild, prev); - } else { - // insert before 'kid' in document order, i.e. after in view order - aParent->InsertChild(aChild, kid); - } - } - } -} - -void nsViewManager::RemoveChild(nsView* aChild) { - NS_ASSERTION(aChild, "aChild must not be null"); - - nsView* parent = aChild->GetParent(); - - if (nullptr != parent) { - NS_ASSERTION( - aChild->GetViewManager() == this || parent->GetViewManager() == this, - "wrong view manager"); - parent->RemoveChild(aChild); - } -} - -void nsViewManager::MoveViewTo(nsView* aView, nscoord aX, nscoord aY) { - NS_ASSERTION(aView->GetViewManager() == this, "wrong view manager"); - aView->SetPosition(aX, aY); -} - void nsViewManager::ResizeView(nsView* aView, const nsRect& aRect) { NS_ASSERTION(aView->GetViewManager() == this, "wrong view manager"); - nsRect oldDimensions = aView->GetDimensions(); + nsRect oldDimensions = aView->GetBounds(); if (!oldDimensions.IsEqualEdges(aRect)) { aView->SetDimensions(aRect); } @@ -684,31 +531,6 @@ void nsViewManager::ResizeView(nsView* aView, const nsRect& aRect) { // because layout will change it back again if necessary. } -void nsViewManager::SetViewVisibility(nsView* aView, ViewVisibility aVisible) { - NS_ASSERTION(aView->GetViewManager() == this, "wrong view manager"); - - if (aVisible != aView->GetVisibility()) { - aView->SetVisibility(aVisible); - } -} - -bool nsViewManager::IsViewInserted(nsView* aView) { - if (mRootView == aView) { - return true; - } - if (aView->GetParent() == nullptr) { - return false; - } - nsView* view = aView->GetParent()->GetFirstChild(); - while (view != nullptr) { - if (view == aView) { - return true; - } - view = view->GetNextSibling(); - } - return false; -} - LayoutDeviceIntRect nsViewManager::ViewToWidget(nsView* aView, const nsRect& aRect) const { NS_ASSERTION(aView->GetViewManager() == this, "wrong view manager"); @@ -761,11 +583,6 @@ void nsViewManager::UpdateWidgetGeometry() { if (vm != aParentVM) { aVMs.AppendElement(vm); } - - for (nsView* child = aView->GetFirstChild(); child; - child = child->GetNextSibling()) { - CollectVMsForWillPaint(child, vm, aVMs); - } } void nsViewManager::CallWillPaintOnObservers() { @@ -778,7 +595,7 @@ void nsViewManager::CallWillPaintOnObservers() { AutoTArray<RefPtr<nsViewManager>, 2> VMs; CollectVMsForWillPaint(mRootView, nullptr, VMs); for (const auto& vm : VMs) { - if (vm->GetRootView() && vm->GetRootView()->IsEffectivelyVisible()) { + if (vm->GetRootView()) { if (RefPtr<PresShell> presShell = vm->GetPresShell()) { presShell->WillPaint(); } diff --git a/view/nsViewManager.h b/view/nsViewManager.h @@ -48,20 +48,12 @@ class nsViewManager final { /** * Create an ordinary view - * @param aBounds initial bounds for view + * @param aSize initial size for view * XXX We should eliminate this parameter; you can set the bounds * after CreateView - * @param aParent intended parent for view. this is not actually set in the - * nsView through this method. it is only used by the initialization - * code to walk up the view tree, if necessary, to find resources. - * XXX We should eliminate this parameter! - * @param aVisibilityFlag initial visibility state of view - * XXX We should eliminate this parameter; you can set it after - * CreateView * @result The new view. Never null. */ - nsView* CreateView(const nsRect& aBounds, nsView* aParent, - ViewVisibility aVisibilityFlag = ViewVisibility::Show); + nsView* CreateView(const nsSize& aSize); /** * Get the root of the view tree. @@ -125,44 +117,6 @@ class nsViewManager final { nsEventStatus* aStatus); /** - * Given a parent view, insert another view as its child. - * aSibling and aAbove control the "document order" for the insertion. - * If aSibling is null, the view is inserted at the end of the document order - * if aAfter is true, otherwise it is inserted at the beginning. - * If aSibling is non-null, then if aAfter is true, the view is inserted - * after the sibling in document order (appearing above the sibling unless - * overriden by z-order). - * If it is false, the view is inserted before the sibling. - * The view manager generates the appopriate dirty regions. - * @param aParent parent view - * @param aChild child view - * @param aSibling sibling view - * @param aAfter after or before in the document order - */ - void InsertChild(nsView* aParent, nsView* aChild, nsView* aSibling, - bool aAfter); - - /** - * Remove a specific child view from its parent. This will NOT remove its - * placeholder if there is one. The view manager generates the appropriate - * dirty regions. - * @param aParent parent view - * @param aChild child view - */ - void RemoveChild(nsView* aChild); - - /** - * Move a view to the specified position, provided in parent coordinates. - * The new position is the (0, 0) origin for the view's coordinate system. - * The view's bounds may extend above or to the left of this point. - * The view manager generates the appropriate dirty regions. - * @param aView view to move - * @param aX x value for new view position - * @param aY y value for new view position - */ - void MoveViewTo(nsView* aView, nscoord aX, nscoord aY); - - /** * Resize a view. In addition to setting the width and height, you can * set the x and y of its bounds relative to its position. Negative x and y * will let the view extend above and to the left of the (0,0) point in its @@ -174,19 +128,6 @@ class nsViewManager final { void ResizeView(nsView* aView, const nsRect& aRect); /** - * Set the visibility of a view. Hidden views have the effect of hiding - * their descendants as well. This does not affect painting, so layout - * is responsible for ensuring that content in hidden views is not - * painted nor handling events. It does affect the visibility of widgets; - * if a view is hidden, descendant views with widgets have their widgets - * hidden. - * The view manager generates the appropriate dirty regions. - * @param aView view to change visibility state of - * @param visible new visibility state - */ - void SetViewVisibility(nsView* aView, ViewVisibility aVisible); - - /** * Set the presshell associated with this manager * @param aPresShell - new presshell */ @@ -219,12 +160,6 @@ class nsViewManager final { static uint32_t GetLastUserEventTime() { return gLastUserEventTime; } /** - * Find the nearest display root view for the view aView. This is the view for - * the nearest enclosing popup or the root view for the root document. - */ - static nsView* GetDisplayRootFor(nsView* aView); - - /** * Flush the accumulated dirty region to the widget and update widget * geometry. */ @@ -269,10 +204,6 @@ class nsViewManager final { MOZ_CAN_RUN_SCRIPT void Refresh(nsView* aView, const LayoutDeviceIntRegion& aRegion); - // Utilities - - bool IsViewInserted(nsView* aView); - /** * Intersects aRect with aView's bounds and then transforms it from aView's * coordinate system to the coordinate system of the widget attached to