From 441a24c006f9f33617395a951d2208bc7b37660f Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Sat, 8 Jan 2000 15:53:48 +0000 Subject: [PATCH] Added unconstrainted reflow optimization methods r=kmcclusk bug=12653 git-svn-id: svn://10.0.0.236/trunk@57210 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/nsFormControlFrame.cpp | 70 +++++++++++++++++++ mozilla/layout/forms/nsFormControlFrame.h | 16 +++++ .../layout/forms/nsHTMLButtonControlFrame.cpp | 14 ++++ .../layout/forms/nsHTMLButtonControlFrame.h | 4 ++ .../html/forms/src/nsFormControlFrame.cpp | 70 +++++++++++++++++++ .../html/forms/src/nsFormControlFrame.h | 16 +++++ .../forms/src/nsHTMLButtonControlFrame.cpp | 14 ++++ .../html/forms/src/nsHTMLButtonControlFrame.h | 4 ++ 8 files changed, 208 insertions(+) diff --git a/mozilla/layout/forms/nsFormControlFrame.cpp b/mozilla/layout/forms/nsFormControlFrame.cpp index 672cb3e973d..0794fa717c0 100644 --- a/mozilla/layout/forms/nsFormControlFrame.cpp +++ b/mozilla/layout/forms/nsFormControlFrame.cpp @@ -71,6 +71,12 @@ nsFormControlFrame::nsFormControlFrame() mFormFrame = nsnull; mSuggestedWidth = NS_FORMSIZE_NOTSET; mSuggestedHeight = NS_FORMSIZE_NOTSET; + + // Reflow Optimization + mCacheSize.width = -1; + mCacheSize.height = -1; + mCachedMaxElementSize.width = -1; + mCachedMaxElementSize.height = -1; } nsFormControlFrame::~nsFormControlFrame() @@ -98,6 +104,63 @@ nsFormControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) return nsLeafFrame::QueryInterface(aIID, aInstancePtr); } +void nsFormControlFrame::SetupCachedSizes(nsSize& aCacheSize, + nsSize& aCachedMaxElementSize, + nsHTMLReflowMetrics& aDesiredSize) +{ + aCacheSize.width = aDesiredSize.width; + aCacheSize.height = aDesiredSize.height; + if (aDesiredSize.maxElementSize != nsnull) { + aCachedMaxElementSize.width = aDesiredSize.maxElementSize->width; + aCachedMaxElementSize.height = aDesiredSize.maxElementSize->height; + } +} + +nsresult nsFormControlFrame::SkipResizeReflow(nsSize& aCacheSize, + nsSize& aCachedMaxElementSize, + nsIPresContext* aPresContext, + nsHTMLReflowMetrics& aDesiredSize, + const nsHTMLReflowState& aReflowState, + nsReflowStatus& aStatus) +{ +#if 1 + if (aReflowState.reason == eReflowReason_Resize) { + if (NS_UNCONSTRAINEDSIZE == aReflowState.mComputedWidth && + NS_UNCONSTRAINEDSIZE == aReflowState.mComputedHeight) { + + if (aCacheSize.width > -1 && aCacheSize.height > -1) { + aDesiredSize.width = aCacheSize.width; + aDesiredSize.height = aCacheSize.height; + if (aDesiredSize.maxElementSize != nsnull) { + aDesiredSize.maxElementSize->width = aCachedMaxElementSize.width; + aDesiredSize.maxElementSize->height = aCachedMaxElementSize.height; + } + aDesiredSize.ascent = aDesiredSize.height; + aDesiredSize.descent = 0; + aStatus = NS_FRAME_COMPLETE; + return NS_OK; + } + } else { + if (aCacheSize.width == aReflowState.mComputedWidth && + aCacheSize.height == aReflowState.mComputedHeight) { + aDesiredSize.width = aCacheSize.width; + aDesiredSize.height = aCacheSize.height; + if (aDesiredSize.maxElementSize != nsnull) { + aDesiredSize.maxElementSize->width = aCachedMaxElementSize.width; + aDesiredSize.maxElementSize->height = aCachedMaxElementSize.height; + } + aDesiredSize.ascent = aDesiredSize.height; + aDesiredSize.descent = 0; + aStatus = NS_FRAME_COMPLETE; + return NS_OK; + } + } + } +#endif + return NS_ERROR_FAILURE; + +} + nscoord nsFormControlFrame::GetScrollbarWidth(float aPixToTwip) { @@ -244,6 +307,12 @@ nsFormControlFrame::Reflow(nsIPresContext* aPresContext, nsFormFrame::AddFormControlFrame(aPresContext, *NS_STATIC_CAST(nsIFrame*, this)); } + nsresult skiprv = SkipResizeReflow(mCacheSize, mCachedMaxElementSize, aPresContext, + aDesiredSize, aReflowState, aStatus); + if (NS_SUCCEEDED(skiprv)) { + return skiprv; + } + nsWidgetRendering mode; aPresContext->GetWidgetRenderingMode(&mode); if (eWidgetRendering_Native == mode) { @@ -267,6 +336,7 @@ nsFormControlFrame::Reflow(nsIPresContext* aPresContext, } aStatus = NS_FRAME_COMPLETE; + SetupCachedSizes(mCacheSize, mCachedMaxElementSize, aDesiredSize); return NS_OK; } diff --git a/mozilla/layout/forms/nsFormControlFrame.h b/mozilla/layout/forms/nsFormControlFrame.h index 2662c685c33..bc812bec117 100644 --- a/mozilla/layout/forms/nsFormControlFrame.h +++ b/mozilla/layout/forms/nsFormControlFrame.h @@ -208,7 +208,19 @@ public: // nsIFormControlFrame NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsString& aValue); + NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); + // Resize Reflow Optimiaztion Methods + static void SetupCachedSizes(nsSize& aCacheSize, + nsSize& aCachedMaxElementSize, + nsHTMLReflowMetrics& aDesiredSize); + + static nsresult SkipResizeReflow(nsSize& aCacheSize, + nsSize& aCachedMaxElementSize, + nsIPresContext* aPresContext, + nsHTMLReflowMetrics& aDesiredSize, + const nsHTMLReflowState& aReflowState, + nsReflowStatus& aStatus); protected: @@ -289,6 +301,10 @@ protected: nscoord mSuggestedWidth; nscoord mSuggestedHeight; + // Reflow Optimization + nsSize mCacheSize; + nsSize mCachedMaxElementSize; + private: NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp index c09a63918d7..67be0465f18 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp @@ -53,6 +53,7 @@ #include "nsColor.h" #include "nsIDocument.h" #include "nsButtonFrameRenderer.h" +#include "nsFormControlFrame.h" static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID); @@ -82,6 +83,11 @@ nsHTMLButtonControlFrame::nsHTMLButtonControlFrame() mTranslatedRect = nsRect(0,0,0,0); mDidInit = PR_FALSE; mRenderer.SetNameSpace(kNameSpaceID_None); + + mCacheSize.width = -1; + mCacheSize.height = -1; + mCachedMaxElementSize.width = -1; + mCachedMaxElementSize.height = -1; } nsHTMLButtonControlFrame::~nsHTMLButtonControlFrame() @@ -510,6 +516,12 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext* aPresContext, nsFormFrame::AddFormControlFrame(aPresContext, *NS_STATIC_CAST(nsIFrame*, this)); } + nsresult skiprv = nsFormControlFrame::SkipResizeReflow(mCacheSize, mCachedMaxElementSize, aPresContext, + aDesiredSize, aReflowState, aStatus); + if (NS_SUCCEEDED(skiprv)) { + return skiprv; + } + // XXX remove the following when the reflow state is fixed ButtonHack((nsHTMLReflowState&)aReflowState, "html4 button"); @@ -651,6 +663,8 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext* aPresContext, aStatus = NS_FRAME_COMPLETE; + + nsFormControlFrame::SetupCachedSizes(mCacheSize, mCachedMaxElementSize, aDesiredSize); return NS_OK; } diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.h b/mozilla/layout/forms/nsHTMLButtonControlFrame.h index 7d38a22f8c9..4aace2ee354 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.h +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.h @@ -155,6 +155,10 @@ protected: nsRect mTranslatedRect; PRBool mDidInit; nsButtonFrameRenderer mRenderer; + + //Resize Reflow OpitmizationSize; + nsSize mCacheSize; + nsSize mCachedMaxElementSize; }; #endif diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp index 672cb3e973d..0794fa717c0 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp @@ -71,6 +71,12 @@ nsFormControlFrame::nsFormControlFrame() mFormFrame = nsnull; mSuggestedWidth = NS_FORMSIZE_NOTSET; mSuggestedHeight = NS_FORMSIZE_NOTSET; + + // Reflow Optimization + mCacheSize.width = -1; + mCacheSize.height = -1; + mCachedMaxElementSize.width = -1; + mCachedMaxElementSize.height = -1; } nsFormControlFrame::~nsFormControlFrame() @@ -98,6 +104,63 @@ nsFormControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) return nsLeafFrame::QueryInterface(aIID, aInstancePtr); } +void nsFormControlFrame::SetupCachedSizes(nsSize& aCacheSize, + nsSize& aCachedMaxElementSize, + nsHTMLReflowMetrics& aDesiredSize) +{ + aCacheSize.width = aDesiredSize.width; + aCacheSize.height = aDesiredSize.height; + if (aDesiredSize.maxElementSize != nsnull) { + aCachedMaxElementSize.width = aDesiredSize.maxElementSize->width; + aCachedMaxElementSize.height = aDesiredSize.maxElementSize->height; + } +} + +nsresult nsFormControlFrame::SkipResizeReflow(nsSize& aCacheSize, + nsSize& aCachedMaxElementSize, + nsIPresContext* aPresContext, + nsHTMLReflowMetrics& aDesiredSize, + const nsHTMLReflowState& aReflowState, + nsReflowStatus& aStatus) +{ +#if 1 + if (aReflowState.reason == eReflowReason_Resize) { + if (NS_UNCONSTRAINEDSIZE == aReflowState.mComputedWidth && + NS_UNCONSTRAINEDSIZE == aReflowState.mComputedHeight) { + + if (aCacheSize.width > -1 && aCacheSize.height > -1) { + aDesiredSize.width = aCacheSize.width; + aDesiredSize.height = aCacheSize.height; + if (aDesiredSize.maxElementSize != nsnull) { + aDesiredSize.maxElementSize->width = aCachedMaxElementSize.width; + aDesiredSize.maxElementSize->height = aCachedMaxElementSize.height; + } + aDesiredSize.ascent = aDesiredSize.height; + aDesiredSize.descent = 0; + aStatus = NS_FRAME_COMPLETE; + return NS_OK; + } + } else { + if (aCacheSize.width == aReflowState.mComputedWidth && + aCacheSize.height == aReflowState.mComputedHeight) { + aDesiredSize.width = aCacheSize.width; + aDesiredSize.height = aCacheSize.height; + if (aDesiredSize.maxElementSize != nsnull) { + aDesiredSize.maxElementSize->width = aCachedMaxElementSize.width; + aDesiredSize.maxElementSize->height = aCachedMaxElementSize.height; + } + aDesiredSize.ascent = aDesiredSize.height; + aDesiredSize.descent = 0; + aStatus = NS_FRAME_COMPLETE; + return NS_OK; + } + } + } +#endif + return NS_ERROR_FAILURE; + +} + nscoord nsFormControlFrame::GetScrollbarWidth(float aPixToTwip) { @@ -244,6 +307,12 @@ nsFormControlFrame::Reflow(nsIPresContext* aPresContext, nsFormFrame::AddFormControlFrame(aPresContext, *NS_STATIC_CAST(nsIFrame*, this)); } + nsresult skiprv = SkipResizeReflow(mCacheSize, mCachedMaxElementSize, aPresContext, + aDesiredSize, aReflowState, aStatus); + if (NS_SUCCEEDED(skiprv)) { + return skiprv; + } + nsWidgetRendering mode; aPresContext->GetWidgetRenderingMode(&mode); if (eWidgetRendering_Native == mode) { @@ -267,6 +336,7 @@ nsFormControlFrame::Reflow(nsIPresContext* aPresContext, } aStatus = NS_FRAME_COMPLETE; + SetupCachedSizes(mCacheSize, mCachedMaxElementSize, aDesiredSize); return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.h b/mozilla/layout/html/forms/src/nsFormControlFrame.h index 2662c685c33..bc812bec117 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.h +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.h @@ -208,7 +208,19 @@ public: // nsIFormControlFrame NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsString& aValue); + NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); + // Resize Reflow Optimiaztion Methods + static void SetupCachedSizes(nsSize& aCacheSize, + nsSize& aCachedMaxElementSize, + nsHTMLReflowMetrics& aDesiredSize); + + static nsresult SkipResizeReflow(nsSize& aCacheSize, + nsSize& aCachedMaxElementSize, + nsIPresContext* aPresContext, + nsHTMLReflowMetrics& aDesiredSize, + const nsHTMLReflowState& aReflowState, + nsReflowStatus& aStatus); protected: @@ -289,6 +301,10 @@ protected: nscoord mSuggestedWidth; nscoord mSuggestedHeight; + // Reflow Optimization + nsSize mCacheSize; + nsSize mCachedMaxElementSize; + private: NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp index c09a63918d7..67be0465f18 100644 --- a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp @@ -53,6 +53,7 @@ #include "nsColor.h" #include "nsIDocument.h" #include "nsButtonFrameRenderer.h" +#include "nsFormControlFrame.h" static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID); @@ -82,6 +83,11 @@ nsHTMLButtonControlFrame::nsHTMLButtonControlFrame() mTranslatedRect = nsRect(0,0,0,0); mDidInit = PR_FALSE; mRenderer.SetNameSpace(kNameSpaceID_None); + + mCacheSize.width = -1; + mCacheSize.height = -1; + mCachedMaxElementSize.width = -1; + mCachedMaxElementSize.height = -1; } nsHTMLButtonControlFrame::~nsHTMLButtonControlFrame() @@ -510,6 +516,12 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext* aPresContext, nsFormFrame::AddFormControlFrame(aPresContext, *NS_STATIC_CAST(nsIFrame*, this)); } + nsresult skiprv = nsFormControlFrame::SkipResizeReflow(mCacheSize, mCachedMaxElementSize, aPresContext, + aDesiredSize, aReflowState, aStatus); + if (NS_SUCCEEDED(skiprv)) { + return skiprv; + } + // XXX remove the following when the reflow state is fixed ButtonHack((nsHTMLReflowState&)aReflowState, "html4 button"); @@ -651,6 +663,8 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext* aPresContext, aStatus = NS_FRAME_COMPLETE; + + nsFormControlFrame::SetupCachedSizes(mCacheSize, mCachedMaxElementSize, aDesiredSize); return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.h b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.h index 7d38a22f8c9..4aace2ee354 100644 --- a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.h +++ b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.h @@ -155,6 +155,10 @@ protected: nsRect mTranslatedRect; PRBool mDidInit; nsButtonFrameRenderer mRenderer; + + //Resize Reflow OpitmizationSize; + nsSize mCacheSize; + nsSize mCachedMaxElementSize; }; #endif