Bug 365189 document.width/document.height flush layout too late. r+sr=roc.

This commit is contained in:
sharparrow1@yahoo.com 2007-05-22 20:52:53 -07:00
Родитель b3d0e6d715
Коммит fb6e0510ad
6 изменённых файлов: 36 добавлений и 160 удалений

Просмотреть файл

@ -49,11 +49,6 @@
#include "nsHTMLParts.h"
#include "nsRuleData.h"
// temporary
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIFrame.h"
class nsHTMLTableRowElement : public nsGenericHTMLElement,
public nsIDOMHTMLTableRowElement
{
@ -93,31 +88,6 @@ protected:
nsRefPtr<nsContentList> mCells;
};
#ifdef XXX_debugging
static
void DebugList(nsIDOMHTMLTableElement* aTable) {
nsCOMPtr<nsIContent> content = do_QueryInterface(aTable);
if (content) {
nsCOMPtr<nsIDocument> doc;
result = content->GetDocument(getter_AddRefs(doc));
if (doc) {
nsCOMPtr<nsIContent> root;
doc->GetRootContent(getter_AddRefs(root));
if (root) {
root->List();
}
nsIPresShell *shell = doc->GetPrimaryShell();
if (shell) {
nsIFrame* rootFrame = shell->FrameManager()->GetRootFrame();
if (rootFrame) {
rootFrame->List(stdout, 0);
}
}
}
}
}
#endif
NS_IMPL_NS_NEW_HTML_ELEMENT(TableRow)

Просмотреть файл

@ -52,15 +52,11 @@
#include "nsScriptLoader.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
#include "nsIPresShell.h"
#include "nsIViewManager.h"
#include "nsIWidget.h"
#include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsINodeInfo.h"
#include "nsHTMLTokens.h"
#include "nsIAppShell.h"
#include "nsWidgetsCID.h"
#include "nsCRT.h"
#include "prtime.h"
#include "prlog.h"
@ -89,7 +85,6 @@
#include "nsGkAtoms.h"
#include "nsContentUtils.h"
#include "nsIFrame.h"
#include "nsIChannel.h"
#include "nsIHttpChannel.h"
#include "nsIDocShell.h"

Просмотреть файл

@ -81,8 +81,6 @@
#include "nsDOMError.h"
#include "nsIPrincipal.h"
#include "nsIScriptSecurityManager.h"
#include "nsIScrollableView.h"
#include "nsIView.h"
#include "nsAttrName.h"
#include "nsNodeUtils.h"
@ -2731,14 +2729,18 @@ nsHTMLDocument::GetNumFormsSynchronous()
}
nsresult
nsHTMLDocument::GetPixelDimensions(nsIPresShell* aShell,
PRInt32* aWidth,
PRInt32* aHeight)
nsHTMLDocument::GetBodySize(PRInt32* aWidth,
PRInt32* aHeight)
{
*aWidth = *aHeight = 0;
FlushPendingNotifications(Flush_Layout);
nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
if (!shell)
return NS_OK;
// Find the <body> element: this is what we'll want to use for the
// document's width and height values.
if (!mBodyContent && !GetBodyContent()) {
@ -2748,32 +2750,14 @@ nsHTMLDocument::GetPixelDimensions(nsIPresShell* aShell,
nsCOMPtr<nsIContent> body = do_QueryInterface(mBodyContent);
// Now grab its frame
nsIFrame* frame = aShell->GetPrimaryFrameFor(body);
if (frame) {
nsSize size;
nsIView* view = frame->GetView();
nsIFrame* frame = shell->GetPrimaryFrameFor(body);
if (!frame)
return NS_OK;
nsSize size = frame->GetSize();
// If we have a view check if it's scrollable. If not,
// just use the view size itself
if (view) {
nsIScrollableView* scrollableView = view->ToScrollableView();
if (scrollableView) {
scrollableView->GetScrolledView(view);
}
nsRect r = view->GetBounds();
size.height = r.height;
size.width = r.width;
}
// If we don't have a view, use the frame size
else {
size = frame->GetSize();
}
*aWidth = nsPresContext::AppUnitsToIntCSSPixels(size.width);
*aHeight = nsPresContext::AppUnitsToIntCSSPixels(size.height);
}
*aWidth = nsPresContext::AppUnitsToIntCSSPixels(size.width);
*aHeight = nsPresContext::AppUnitsToIntCSSPixels(size.height);
return NS_OK;
}
@ -2782,44 +2766,18 @@ NS_IMETHODIMP
nsHTMLDocument::GetWidth(PRInt32* aWidth)
{
NS_ENSURE_ARG_POINTER(aWidth);
*aWidth = 0;
// We make the assumption that the first presentation shell
// is the one for which we need information.
// Since GetPixelDimensions flushes and flushing can destroy
// our shell, hold a strong ref to it.
nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
if (!shell) {
return NS_OK;
}
PRInt32 dummy;
// GetPixelDimensions() does the flushing for us, no need to flush
// here too
return GetPixelDimensions(shell, aWidth, &dummy);
PRInt32 height;
return GetBodySize(aWidth, &height);
}
NS_IMETHODIMP
nsHTMLDocument::GetHeight(PRInt32* aHeight)
{
NS_ENSURE_ARG_POINTER(aHeight);
*aHeight = 0;
// We make the assumption that the first presentation shell
// is the one for which we need information.
// Since GetPixelDimensions flushes and flushing can destroy
// our shell, hold a strong ref to it.
nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
if (!shell) {
return NS_OK;
}
PRInt32 dummy;
// GetPixelDimensions() does the flushing for us, no need to flush
// here too
return GetPixelDimensions(shell, &dummy, aHeight);
PRInt32 width;
return GetBodySize(&width, aHeight);
}
NS_IMETHODIMP

Просмотреть файл

@ -210,9 +210,8 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLDocument, nsDocument)
protected:
nsresult GetPixelDimensions(nsIPresShell* aShell,
PRInt32* aWidth,
PRInt32* aHeight);
nsresult GetBodySize(PRInt32* aWidth,
PRInt32* aHeight);
nsresult RegisterNamedItems(nsIContent *aContent);
nsresult UnregisterNamedItems(nsIContent *aContent);

Просмотреть файл

@ -1371,46 +1371,25 @@ nsXULDocument::Persist(nsIContent* aElement, PRInt32 aNameSpaceID,
nsresult
nsXULDocument::GetPixelDimensions(nsIPresShell* aShell, PRInt32* aWidth,
PRInt32* aHeight)
nsXULDocument::GetViewportSize(PRInt32* aWidth,
PRInt32* aHeight)
{
nsresult result = NS_OK;
nsSize size;
*aWidth = *aHeight = 0;
FlushPendingNotifications(Flush_Layout);
nsIFrame* frame =
mRootContent ? aShell->GetPrimaryFrameFor(mRootContent) : nsnull;
if (frame) {
nsIView* view = frame->GetView();
// If we have a view check if it's scrollable. If not,
// just use the view size itself
if (view) {
nsIScrollableView* scrollableView = view->ToScrollableView();
nsIPresShell *shell = GetPrimaryShell();
NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
if (scrollableView) {
scrollableView->GetScrolledView(view);
}
nsIFrame* frame = shell->GetRootFrame();
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
nsRect r = view->GetBounds();
size.height = r.height;
size.width = r.width;
}
// If we don't have a view, use the frame size
else {
size = frame->GetSize();
}
nsSize size = frame->GetSize();
*aWidth = nsPresContext::AppUnitsToIntCSSPixels(size.width);
*aHeight = nsPresContext::AppUnitsToIntCSSPixels(size.height);
}
else {
*aWidth = 0;
*aHeight = 0;
result = NS_ERROR_FAILURE;
}
*aWidth = nsPresContext::AppUnitsToIntCSSPixels(size.width);
*aHeight = nsPresContext::AppUnitsToIntCSSPixels(size.height);
return result;
return NS_OK;
}
NS_IMETHODIMP
@ -1418,20 +1397,8 @@ nsXULDocument::GetWidth(PRInt32* aWidth)
{
NS_ENSURE_ARG_POINTER(aWidth);
nsresult rv = NS_OK;
// We make the assumption that the first presentation shell
// is the one for which we need information.
nsIPresShell *shell = GetPrimaryShell();
if (shell) {
PRInt32 width, height;
rv = GetPixelDimensions(shell, &width, &height);
*aWidth = width;
} else
*aWidth = 0;
return rv;
PRInt32 height;
return GetViewportSize(aWidth, &height);
}
NS_IMETHODIMP
@ -1439,20 +1406,8 @@ nsXULDocument::GetHeight(PRInt32* aHeight)
{
NS_ENSURE_ARG_POINTER(aHeight);
nsresult rv = NS_OK;
// We make the assumption that the first presentation shell
// is the one for which we need information.
nsIPresShell *shell = GetPrimaryShell();
if (shell) {
PRInt32 width, height;
rv = GetPixelDimensions(shell, &width, &height);
*aHeight = height;
} else
*aHeight = 0;
return rv;
PRInt32 width;
return GetViewportSize(&width, aHeight);
}
//----------------------------------------------------------------------

Просмотреть файл

@ -188,8 +188,7 @@ protected:
nsresult
RemoveElementFromMap(nsIContent* aElement);
nsresult GetPixelDimensions(nsIPresShell* aShell, PRInt32* aWidth,
PRInt32* aHeight);
nsresult GetViewportSize(PRInt32* aWidth, PRInt32* aHeight);
static PRIntn
RemoveElementsFromMapByContent(const PRUnichar* aID,