Expose GetBodyContent and use it to avoid performance hit of nsIDOMHTMLDocument::GetBody. b=331530 r+sr=sicking a=schrep

This commit is contained in:
dbaron@dbaron.org 2008-02-19 08:48:09 -08:00
parent 18987947d2
commit f68cc8299a
6 changed files with 27 additions and 18 deletions

View File

@ -7,7 +7,7 @@
#include "nsHTMLDocument.h"
%}
%pseudo-iid nsIHTMLDocument 61e989a8-70cd-4582-845e-6e5e12559a83
%pseudo-iid nsIHTMLDocument 48546d61-6097-462b-89b1-57e2221444dc
NS_INTERFACE_MAP_BEGIN(nsHTMLDocument, nsDocument)
NS_INTERFACE_MAP_ENTRY(nsIHTMLDocument)

View File

@ -3561,6 +3561,12 @@ nsHTMLDocument::ResolveName(const nsAString& aName,
//----------------------------
/* virtual */ nsIContent*
nsHTMLDocument::GetBodyContentExternal()
{
return GetBodyContent();
}
nsIContent*
nsHTMLDocument::GetBodyContent()
{

View File

@ -212,6 +212,8 @@ public:
mDisableCookieAccess = PR_TRUE;
}
virtual nsIContent* GetBodyContentExternal();
void EndUpdate(nsUpdateType aUpdateType);
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLDocument, nsDocument)

View File

@ -54,9 +54,11 @@ class nsIContent;
class nsIDOMHTMLBodyElement;
class nsIScriptElement;
// Update htmldocument.gqi when updating this IID!
// 48546d61-6097-462b-89b1-57e2221444dc
#define NS_IHTMLDOCUMENT_IID \
{ 0x61e989a8, 0x70cd, 0x4582, \
{ 0x84, 0x5e, 0x6e, 0x5e, 0x12, 0x55, 0x9a, 0x83 } }
{ 0x48546d61, 0x6097, 0x462b, \
{ 0x89, 0xb1, 0x57, 0xe2, 0x22, 0x14, 0x44, 0xdc } }
/**
* HTML document extensions to nsIDocument.
@ -173,6 +175,12 @@ public:
* Disables getting and setting cookies
*/
virtual void DisableCookieAccess() = 0;
/**
* Get the first <body> child of the root <html>, but don't do
* anything <frameset>-related (like nsIDOMHTMLDocument::GetBody).
*/
virtual nsIContent* GetBodyContentExternal() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIHTMLDocument, NS_IHTMLDOCUMENT_IID)

View File

@ -65,8 +65,7 @@
#include "nsITheme.h"
#include "nsThemeConstants.h"
#include "nsIServiceManager.h"
#include "nsIDOMHTMLBodyElement.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIHTMLDocument.h"
#include "nsLayoutUtils.h"
#include "nsINameSpaceManager.h"
@ -3147,11 +3146,9 @@ FindCanvasBackground(nsIFrame* aForFrame,
if (content) {
// Use |GetOwnerDoc| so it works during destruction.
nsIDocument* document = content->GetOwnerDoc();
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(document);
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document);
if (htmlDoc) {
nsCOMPtr<nsIDOMHTMLElement> body;
htmlDoc->GetBody(getter_AddRefs(body));
nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(body);
nsIContent* bodyContent = htmlDoc->GetBodyContentExternal();
// We need to null check the body node (bug 118829) since
// there are cases, thanks to the fix for bug 5569, where we
// will reflow a document with no body. In particular, if a
@ -3215,13 +3212,11 @@ FindElementBackground(nsIFrame* aForFrame,
// We should only look at the <html> background if we're in an HTML document
nsIDocument* document = content->GetOwnerDoc();
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(document);
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document);
if (!htmlDoc)
return PR_TRUE;
nsCOMPtr<nsIDOMHTMLElement> body;
htmlDoc->GetBody(getter_AddRefs(body));
nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(body);
nsIContent* bodyContent = htmlDoc->GetBodyContentExternal();
if (bodyContent != content)
return PR_TRUE; // this wasn't the background that was propagated

View File

@ -70,7 +70,7 @@
#include "nsPresState.h"
#include "nsIGlobalHistory3.h"
#include "nsDocShellCID.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIHTMLDocument.h"
#include "nsEventDispatcher.h"
#include "nsContentUtils.h"
#include "nsLayoutUtils.h"
@ -2107,11 +2107,9 @@ nsGfxScrollFrameInner::IsLTR() const
nsIContent *root = document->GetRootContent();
// But for HTML we want the body element.
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(document);
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document);
if (htmlDoc) {
nsCOMPtr<nsIDOMHTMLElement> body;
htmlDoc->GetBody(getter_AddRefs(body));
nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(body);
nsIContent *bodyContent = htmlDoc->GetBodyContentExternal();
if (bodyContent)
root = bodyContent; // we can trust the document to hold on to it
}