Bug 1116714 part 2 - Don't create a frame for the custom content container when it has no children. r=roc

This commit is contained in:
Mats Palmgren 2015-01-20 18:20:04 +00:00
parent ff5524e902
commit 19090c22bf
3 changed files with 42 additions and 0 deletions

View File

@ -5252,6 +5252,7 @@ nsIDocument::InsertAnonymousContent(Element& aElement, ErrorResult& aRv)
return nullptr;
}
nsAutoScriptBlocker scriptBlocker;
nsCOMPtr<Element> container = shell->GetCanvasFrame()
->GetCustomContentContainer();
if (!container) {
@ -5276,6 +5277,8 @@ nsIDocument::InsertAnonymousContent(Element& aElement, ErrorResult& aRv)
new AnonymousContent(clonedElement->AsElement());
mAnonymousContents.AppendElement(anonymousContent);
shell->GetCanvasFrame()->ShowCustomContentContainer();
return anonymousContent.forget();
}
@ -5289,6 +5292,7 @@ nsIDocument::RemoveAnonymousContent(AnonymousContent& aContent,
return;
}
nsAutoScriptBlocker scriptBlocker;
nsCOMPtr<Element> container = shell->GetCanvasFrame()
->GetCustomContentContainer();
if (!container) {
@ -5314,6 +5318,9 @@ nsIDocument::RemoveAnonymousContent(AnonymousContent& aContent,
break;
}
}
if (mAnonymousContents.IsEmpty()) {
shell->GetCanvasFrame()->HideCustomContentContainer();
}
}
//

View File

@ -53,6 +53,24 @@ NS_QUERYFRAME_HEAD(nsCanvasFrame)
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
void
nsCanvasFrame::ShowCustomContentContainer()
{
if (mCustomContentContainer) {
mCustomContentContainer->UnsetAttr(kNameSpaceID_None, nsGkAtoms::hidden, true);
}
}
void
nsCanvasFrame::HideCustomContentContainer()
{
if (mCustomContentContainer) {
mCustomContentContainer->SetAttr(kNameSpaceID_None, nsGkAtoms::hidden,
NS_LITERAL_STRING("true"),
true);
}
}
nsresult
nsCanvasFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
@ -126,6 +144,11 @@ nsCanvasFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
mCustomContentContainer->AppendChildTo(node->AsContent(), true);
}
// Only create a frame for mCustomContentContainer if it has some children.
if (len == 0) {
HideCustomContentContainer();
}
return NS_OK;
}

View File

@ -104,6 +104,18 @@ public:
return mCustomContentContainer;
}
/**
* Unhide the CustomContentContainer. This call only has an effect if
* mCustomContentContainer is non-null.
*/
void ShowCustomContentContainer();
/**
* Hide the CustomContentContainer. This call only has an effect if
* mCustomContentContainer is non-null.
*/
void HideCustomContentContainer();
/** SetHasFocus tells the CanvasFrame to draw with focus ring
* @param aHasFocus true to show focus ring, false to hide it
*/