Bug 1259246. Move nsIPresShell::GetRealPrimaryFrameFor to nsLayoutUtils::GetRealPrimaryFrameFor. r=dholbert

The function doesn't need to be a non-static member of nsIPresShell: it only checks if the document of the passed in element matches the presshell's document, and then the remaining code could be static. It has only one user, nsDocumentViewer::FindContainerView, and it doesn't care about the specific presshell, it just wants the primary frame, so it doesn't need the document check.

This lets us simplify nsDocumentViewer::FindContainerView because it had to jump through hoops to get the presshell.
This commit is contained in:
Timothy Nikkel 2016-04-23 15:18:26 -05:00
parent 122b4efd17
commit 4fa1d92384
6 changed files with 36 additions and 56 deletions

View File

@ -2462,24 +2462,7 @@ nsDocumentViewer::FindContainerView()
return nullptr; return nullptr;
} }
nsCOMPtr<nsIPresShell> parentPresShell; nsIFrame* subdocFrame = nsLayoutUtils::GetRealPrimaryFrameFor(containerElement);
nsCOMPtr<nsIDocument> parentDoc = containerElement->GetUncomposedDoc();
if (parentDoc) {
parentPresShell = parentDoc->GetShell();
}
if (!parentPresShell) {
nsCOMPtr<nsIDocShellTreeItem> parentDocShellItem;
docShell->GetParent(getter_AddRefs(parentDocShellItem));
if (parentDocShellItem) {
nsCOMPtr<nsIDocShell> parentDocShell = do_QueryInterface(parentDocShellItem);
parentPresShell = parentDocShell->GetPresShell();
}
}
if (!parentPresShell) {
NS_WARNING("Subdocument container has no presshell");
} else {
nsIFrame* subdocFrame = parentPresShell->GetRealPrimaryFrameFor(containerElement);
if (subdocFrame) { if (subdocFrame) {
// subdocFrame might not be a subdocument frame; the frame // subdocFrame might not be a subdocument frame; the frame
// constructor can treat a <frame> as an inline in some XBL // constructor can treat a <frame> as an inline in some XBL
@ -2500,7 +2483,6 @@ nsDocumentViewer::FindContainerView()
} }
} }
} }
}
return containerView; return containerView;
} }

View File

@ -497,15 +497,6 @@ public:
*/ */
virtual nsCanvasFrame* GetCanvasFrame() const = 0; virtual nsCanvasFrame* GetCanvasFrame() const = 0;
/**
* Gets the real primary frame associated with the content object.
*
* In the case of absolutely positioned elements and floated elements,
* the real primary frame is the frame that is out of the flow and not the
* placeholder frame.
*/
virtual nsIFrame* GetRealPrimaryFrameFor(nsIContent* aContent) const = 0;
/** /**
* Gets the placeholder frame associated with the specified frame. This is * Gets the placeholder frame associated with the specified frame. This is
* a helper frame that forwards the request to the frame manager. * a helper frame that forwards the request to the frame manager.

View File

@ -1577,6 +1577,17 @@ nsLayoutUtils::GetStyleFrame(const nsIContent* aContent)
return nsLayoutUtils::GetStyleFrame(frame); return nsLayoutUtils::GetStyleFrame(frame);
} }
/* static */ nsIFrame*
nsLayoutUtils::GetRealPrimaryFrameFor(const nsIContent* aContent)
{
nsIFrame *frame = aContent->GetPrimaryFrame();
if (!frame) {
return nullptr;
}
return nsPlaceholderFrame::GetRealFrameFor(frame);
}
nsIFrame* nsIFrame*
nsLayoutUtils::GetFloatFromPlaceholder(nsIFrame* aFrame) { nsLayoutUtils::GetFloatFromPlaceholder(nsIFrame* aFrame) {
NS_ASSERTION(nsGkAtoms::placeholderFrame == aFrame->GetType(), NS_ASSERTION(nsGkAtoms::placeholderFrame == aFrame->GetType(),

View File

@ -363,6 +363,15 @@ public:
*/ */
static nsIFrame* GetStyleFrame(const nsIContent* aContent); static nsIFrame* GetStyleFrame(const nsIContent* aContent);
/**
* Gets the real primary frame associated with the content object.
*
* In the case of absolutely positioned elements and floated elements,
* the real primary frame is the frame that is out of the flow and not the
* placeholder frame.
*/
static nsIFrame* GetRealPrimaryFrameFor(const nsIContent* aContent);
/** /**
* IsGeneratedContentFor returns true if aFrame is the outermost * IsGeneratedContentFor returns true if aFrame is the outermost
* frame for generated content of type aPseudoElement for aContent. * frame for generated content of type aPseudoElement for aContent.

View File

@ -4552,18 +4552,6 @@ PresShell::StyleRuleRemoved(StyleSheetHandle aStyleSheet)
RecordStyleSheetChange(aStyleSheet); RecordStyleSheetChange(aStyleSheet);
} }
nsIFrame*
PresShell::GetRealPrimaryFrameFor(nsIContent* aContent) const
{
if (aContent->GetComposedDoc() != GetDocument()) {
return nullptr;
}
nsIFrame *primaryFrame = aContent->GetPrimaryFrame();
if (!primaryFrame)
return nullptr;
return nsPlaceholderFrame::GetRealFrameFor(primaryFrame);
}
nsIFrame* nsIFrame*
PresShell::GetPlaceholderFrameFor(nsIFrame* aFrame) const PresShell::GetPlaceholderFrameFor(nsIFrame* aFrame) const
{ {

View File

@ -123,7 +123,6 @@ public:
virtual nsresult ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight) override; virtual nsresult ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight) override;
virtual nsIPageSequenceFrame* GetPageSequenceFrame() const override; virtual nsIPageSequenceFrame* GetPageSequenceFrame() const override;
virtual nsCanvasFrame* GetCanvasFrame() const override; virtual nsCanvasFrame* GetCanvasFrame() const override;
virtual nsIFrame* GetRealPrimaryFrameFor(nsIContent* aContent) const override;
virtual nsIFrame* GetPlaceholderFrameFor(nsIFrame* aFrame) const override; virtual nsIFrame* GetPlaceholderFrameFor(nsIFrame* aFrame) const override;
virtual void FrameNeedsReflow(nsIFrame *aFrame, IntrinsicDirty aIntrinsicDirty, virtual void FrameNeedsReflow(nsIFrame *aFrame, IntrinsicDirty aIntrinsicDirty,