From 6790bf9cf4d3c9f0516cc56e21e3eac911e3c53d Mon Sep 17 00:00:00 2001 From: "troy%netscape.com" Date: Thu, 29 Oct 1998 23:25:02 +0000 Subject: [PATCH] Changed to use a scroll frame for the BODY git-svn-id: svn://10.0.0.236/trunk@13686 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/style/src/nsHTMLStyleSheet.cpp | 29 +++++++++++++++++-- mozilla/layout/generic/nsHTMLFrame.cpp | 10 +++++++ mozilla/layout/html/base/src/nsHTMLFrame.cpp | 10 +++++++ .../layout/html/base/src/nsScrollFrame.cpp | 25 +++++++++++++--- mozilla/layout/html/document/src/ua.css | 2 +- .../html/style/src/nsHTMLStyleSheet.cpp | 29 +++++++++++++++++-- mozilla/layout/style/nsHTMLStyleSheet.cpp | 29 +++++++++++++++++-- mozilla/layout/style/ua.css | 2 +- 8 files changed, 124 insertions(+), 12 deletions(-) diff --git a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp index f3efda832d8..62f07846e0a 100644 --- a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp @@ -332,6 +332,8 @@ protected: PRBool IsScrollable(nsIFrame* aFrame, const nsStyleDisplay* aDisplay); + nsIFrame* GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent); + protected: PRUint32 mInHeap : 1; PRUint32 mRefCnt : 31; @@ -1530,6 +1532,10 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, aFrameSubTree->SetStyleContext(aPresContext, pseudoStyle); NS_RELEASE(pseudoStyle); + // Reset the scrolled frame's geometric and content parent + aFrameSubTree->SetGeometricParent(scrollFrame); + aFrameSubTree->SetContentParent(scrollFrame); + // Initialize the scroll frame scrollFrame->Init(*aPresContext, aFrameSubTree); aFrameSubTree = scrollFrame; @@ -1545,13 +1551,32 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, return rv; } +nsIFrame* +HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent) +{ + nsIFrame* frame = aPresShell->FindFrameWithContent(aContent); + + if (nsnull != frame) { + // If the primary frame is a scroll frame, then get the scrolled frame. + // That's the frame that gets the reflow command + const nsStyleDisplay* display; + frame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display); + + if (display->IsBlockLevel() && IsScrollable(frame, display)) { + frame->FirstChild(frame); + } + } + + return frame; +} + NS_IMETHODIMP HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext, nsIContent* aContainer, PRInt32 aNewIndexInContainer) { nsIPresShell* shell = aPresContext->GetShell(); - nsIFrame* parentFrame = shell->FindFrameWithContent(aContainer); + nsIFrame* parentFrame = GetFrameFor(shell, aContainer); #ifdef NS_DEBUG if (nsnull == parentFrame) { @@ -1595,7 +1620,7 @@ HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext, NS_RELEASE(child); } - // adjust parent frame for table inner/outer frame + // Adjust parent frame for table inner/outer frame // we need to do this here because we need both the parent frame and the constructed frame nsresult result = NS_OK; nsIFrame *adjustedParentFrame=parentFrame; diff --git a/mozilla/layout/generic/nsHTMLFrame.cpp b/mozilla/layout/generic/nsHTMLFrame.cpp index d3042e99abc..03545be65ab 100644 --- a/mozilla/layout/generic/nsHTMLFrame.cpp +++ b/mozilla/layout/generic/nsHTMLFrame.cpp @@ -106,6 +106,7 @@ RootFrame::RootFrame(nsIContent* aContent) NS_IMETHODIMP RootFrame::Init(nsIPresContext& aPresContext, nsIFrame* aChildList) { +#if 0 // Construct the root content frame and set its style context mFirstChild = new RootContentFrame(mContent, this); nsIStyleContext* pseudoStyleContext = @@ -121,6 +122,10 @@ RootFrame::Init(nsIPresContext& aPresContext, nsIFrame* aChildList) // Queue up the frames for the root content frame return mFirstChild->Init(aPresContext, aChildList); +#else + mFirstChild = aChildList; + return NS_OK; +#endif } NS_IMETHODIMP @@ -155,6 +160,11 @@ RootFrame::Reflow(nsIPresContext& aPresContext, nsHTMLReflowMetrics desiredSize(nsnull); nsHTMLReflowState kidReflowState(aPresContext, mFirstChild, aReflowState, aReflowState.maxSize); + // XXX HACK + kidReflowState.widthConstraint = eHTMLFrameConstraint_Fixed; + kidReflowState.minWidth = aReflowState.maxSize.width; + kidReflowState.heightConstraint = eHTMLFrameConstraint_Fixed; + kidReflowState.minHeight = aReflowState.maxSize.height; nsIHTMLReflow* htmlReflow; if (NS_OK == mFirstChild->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { diff --git a/mozilla/layout/html/base/src/nsHTMLFrame.cpp b/mozilla/layout/html/base/src/nsHTMLFrame.cpp index d3042e99abc..03545be65ab 100644 --- a/mozilla/layout/html/base/src/nsHTMLFrame.cpp +++ b/mozilla/layout/html/base/src/nsHTMLFrame.cpp @@ -106,6 +106,7 @@ RootFrame::RootFrame(nsIContent* aContent) NS_IMETHODIMP RootFrame::Init(nsIPresContext& aPresContext, nsIFrame* aChildList) { +#if 0 // Construct the root content frame and set its style context mFirstChild = new RootContentFrame(mContent, this); nsIStyleContext* pseudoStyleContext = @@ -121,6 +122,10 @@ RootFrame::Init(nsIPresContext& aPresContext, nsIFrame* aChildList) // Queue up the frames for the root content frame return mFirstChild->Init(aPresContext, aChildList); +#else + mFirstChild = aChildList; + return NS_OK; +#endif } NS_IMETHODIMP @@ -155,6 +160,11 @@ RootFrame::Reflow(nsIPresContext& aPresContext, nsHTMLReflowMetrics desiredSize(nsnull); nsHTMLReflowState kidReflowState(aPresContext, mFirstChild, aReflowState, aReflowState.maxSize); + // XXX HACK + kidReflowState.widthConstraint = eHTMLFrameConstraint_Fixed; + kidReflowState.minWidth = aReflowState.maxSize.width; + kidReflowState.heightConstraint = eHTMLFrameConstraint_Fixed; + kidReflowState.minHeight = aReflowState.maxSize.height; nsIHTMLReflow* htmlReflow; if (NS_OK == mFirstChild->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { diff --git a/mozilla/layout/html/base/src/nsScrollFrame.cpp b/mozilla/layout/html/base/src/nsScrollFrame.cpp index 526707c84ec..b886c952c28 100644 --- a/mozilla/layout/html/base/src/nsScrollFrame.cpp +++ b/mozilla/layout/html/base/src/nsScrollFrame.cpp @@ -187,10 +187,12 @@ nsScrollFrame::CreateScrollingView() view->QueryInterface(kScrollViewIID, (void**)&scrollingView); // Set the scroll prefrence +#if 0 nsScrollPreference scrollPref = (NS_STYLE_OVERFLOW_SCROLL == display->mOverflow) ? nsScrollPreference_kAlwaysScroll : nsScrollPreference_kAuto; scrollingView->SetScrollPreference(scrollPref); +#endif // Set the scrolling view's insets to whatever our border is nsMargin border; @@ -293,6 +295,11 @@ nsScrollFrame::Reflow(nsIPresContext& aPresContext, // The reflow state width reflects space for the content area only, so don't // subtract for borders... scrollAreaSize.width = aReflowState.minWidth; + + if (eHTMLFrameConstraint_Fixed == aReflowState.widthConstraint) { + scrollAreaSize.width -= border.left + border.right; + scrollAreaSize.width -= NSToCoordRound(sbWidth); + } } else { // Use the max width in the reflow state @@ -311,6 +318,16 @@ nsScrollFrame::Reflow(nsIPresContext& aPresContext, // The reflow state height reflects space for the content area only, so don't // subtract for borders... scrollAreaSize.height = aReflowState.minHeight; + + if (eHTMLFrameConstraint_Fixed == aReflowState.heightConstraint) { + scrollAreaSize.height -= border.top + border.bottom; + + // If scrollbars are always visible then subtract for the + // height of the horizontal scrollbar + if (NS_STYLE_OVERFLOW_SCROLL == display->mOverflow) { + scrollAreaSize.height -= NSToCoordRound(sbHeight); + } + } } else { // Use the max height in the reflow state @@ -340,7 +357,7 @@ nsScrollFrame::Reflow(nsIPresContext& aPresContext, // Make sure the scrolled frame fills the entire scroll area along a // fixed dimension - if (aReflowState.HaveConstrainedHeight()) { + if ((eHTMLFrameConstraint_Fixed == aReflowState.heightConstraint) || aReflowState.HaveConstrainedHeight()) { if (kidDesiredSize.height < scrollAreaSize.height) { kidDesiredSize.height = scrollAreaSize.height; } @@ -354,7 +371,7 @@ nsScrollFrame::Reflow(nsIPresContext& aPresContext, } } } - if (aReflowState.HaveConstrainedWidth()) { + if ((eHTMLFrameConstraint_Fixed == aReflowState.widthConstraint) || aReflowState.HaveConstrainedWidth()) { if (kidDesiredSize.width < scrollAreaSize.width) { kidDesiredSize.width = scrollAreaSize.width; } @@ -378,14 +395,14 @@ nsScrollFrame::Reflow(nsIPresContext& aPresContext, // Compute our desired size. If our size was fixed then use the fixed size; // otherwise, shrink wrap around the scrolled frame - if (aReflowState.HaveConstrainedWidth()) { + if ((eHTMLFrameConstraint_Fixed == aReflowState.widthConstraint) || aReflowState.HaveConstrainedWidth()) { aDesiredSize.width = scrollAreaSize.width; } else { aDesiredSize.width = kidDesiredSize.width; } aDesiredSize.width += border.left + border.right + NSToCoordRound(sbWidth); - if (aReflowState.HaveConstrainedHeight()) { + if ((eHTMLFrameConstraint_Fixed == aReflowState.heightConstraint) || aReflowState.HaveConstrainedHeight()) { aDesiredSize.height = scrollAreaSize.height; } else { aDesiredSize.height = kidDesiredSize.height; diff --git a/mozilla/layout/html/document/src/ua.css b/mozilla/layout/html/document/src/ua.css index 8288abd7204..ca0cba8d805 100644 --- a/mozilla/layout/html/document/src/ua.css +++ b/mozilla/layout/html/document/src/ua.css @@ -27,7 +27,7 @@ BODY { line-height: normal; //XXX not yet... margin: 8px; padding: 8px; - overflow: auto; + overflow: scroll; } FRAMESET { diff --git a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp index f3efda832d8..62f07846e0a 100644 --- a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp @@ -332,6 +332,8 @@ protected: PRBool IsScrollable(nsIFrame* aFrame, const nsStyleDisplay* aDisplay); + nsIFrame* GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent); + protected: PRUint32 mInHeap : 1; PRUint32 mRefCnt : 31; @@ -1530,6 +1532,10 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, aFrameSubTree->SetStyleContext(aPresContext, pseudoStyle); NS_RELEASE(pseudoStyle); + // Reset the scrolled frame's geometric and content parent + aFrameSubTree->SetGeometricParent(scrollFrame); + aFrameSubTree->SetContentParent(scrollFrame); + // Initialize the scroll frame scrollFrame->Init(*aPresContext, aFrameSubTree); aFrameSubTree = scrollFrame; @@ -1545,13 +1551,32 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, return rv; } +nsIFrame* +HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent) +{ + nsIFrame* frame = aPresShell->FindFrameWithContent(aContent); + + if (nsnull != frame) { + // If the primary frame is a scroll frame, then get the scrolled frame. + // That's the frame that gets the reflow command + const nsStyleDisplay* display; + frame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display); + + if (display->IsBlockLevel() && IsScrollable(frame, display)) { + frame->FirstChild(frame); + } + } + + return frame; +} + NS_IMETHODIMP HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext, nsIContent* aContainer, PRInt32 aNewIndexInContainer) { nsIPresShell* shell = aPresContext->GetShell(); - nsIFrame* parentFrame = shell->FindFrameWithContent(aContainer); + nsIFrame* parentFrame = GetFrameFor(shell, aContainer); #ifdef NS_DEBUG if (nsnull == parentFrame) { @@ -1595,7 +1620,7 @@ HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext, NS_RELEASE(child); } - // adjust parent frame for table inner/outer frame + // Adjust parent frame for table inner/outer frame // we need to do this here because we need both the parent frame and the constructed frame nsresult result = NS_OK; nsIFrame *adjustedParentFrame=parentFrame; diff --git a/mozilla/layout/style/nsHTMLStyleSheet.cpp b/mozilla/layout/style/nsHTMLStyleSheet.cpp index f3efda832d8..62f07846e0a 100644 --- a/mozilla/layout/style/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/style/nsHTMLStyleSheet.cpp @@ -332,6 +332,8 @@ protected: PRBool IsScrollable(nsIFrame* aFrame, const nsStyleDisplay* aDisplay); + nsIFrame* GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent); + protected: PRUint32 mInHeap : 1; PRUint32 mRefCnt : 31; @@ -1530,6 +1532,10 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, aFrameSubTree->SetStyleContext(aPresContext, pseudoStyle); NS_RELEASE(pseudoStyle); + // Reset the scrolled frame's geometric and content parent + aFrameSubTree->SetGeometricParent(scrollFrame); + aFrameSubTree->SetContentParent(scrollFrame); + // Initialize the scroll frame scrollFrame->Init(*aPresContext, aFrameSubTree); aFrameSubTree = scrollFrame; @@ -1545,13 +1551,32 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, return rv; } +nsIFrame* +HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIContent* aContent) +{ + nsIFrame* frame = aPresShell->FindFrameWithContent(aContent); + + if (nsnull != frame) { + // If the primary frame is a scroll frame, then get the scrolled frame. + // That's the frame that gets the reflow command + const nsStyleDisplay* display; + frame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display); + + if (display->IsBlockLevel() && IsScrollable(frame, display)) { + frame->FirstChild(frame); + } + } + + return frame; +} + NS_IMETHODIMP HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext, nsIContent* aContainer, PRInt32 aNewIndexInContainer) { nsIPresShell* shell = aPresContext->GetShell(); - nsIFrame* parentFrame = shell->FindFrameWithContent(aContainer); + nsIFrame* parentFrame = GetFrameFor(shell, aContainer); #ifdef NS_DEBUG if (nsnull == parentFrame) { @@ -1595,7 +1620,7 @@ HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext, NS_RELEASE(child); } - // adjust parent frame for table inner/outer frame + // Adjust parent frame for table inner/outer frame // we need to do this here because we need both the parent frame and the constructed frame nsresult result = NS_OK; nsIFrame *adjustedParentFrame=parentFrame; diff --git a/mozilla/layout/style/ua.css b/mozilla/layout/style/ua.css index 8288abd7204..ca0cba8d805 100644 --- a/mozilla/layout/style/ua.css +++ b/mozilla/layout/style/ua.css @@ -27,7 +27,7 @@ BODY { line-height: normal; //XXX not yet... margin: 8px; padding: 8px; - overflow: auto; + overflow: scroll; } FRAMESET {