Land bug 72747 in pieces: Simplify the mechanism used to prevent framesets from having scrollbars. b=72747 r+sr=roc

This commit is contained in:
dbaron%dbaron.org 2004-09-04 19:51:21 +00:00
parent 51fd4d10d8
commit 9984902fd6
13 changed files with 58 additions and 190 deletions

View File

@ -120,7 +120,7 @@
#include "nsIFocusController.h"
#include "nsIScrollableView.h"
#include "nsIScrollable.h"
#include "nsIHTMLDocument.h"
#include "nsITimelineService.h"
#include "nsGfxCIID.h"
@ -678,23 +678,11 @@ DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow)
mViewManager->SetDefaultBackgroundColor(mPresContext->DefaultBackgroundColor());
if (aDoInitialReflow) {
nsCOMPtr<nsIScrollable> sc = do_QueryInterface(mContainer);
if (sc) {
nsCOMPtr<nsIDOMHTMLFrameSetElement> frameset(do_QueryInterface(mDocument->GetRootContent()));
if (frameset) {
// If this is a frameset (i.e. not a frame) then we never want
// scrollbars on it, the scrollbars go inside the frames
// inside the frameset...
sc->SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,
nsIScrollable::Scrollbar_Never);
sc->SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_X,
nsIScrollable::Scrollbar_Never);
} else {
sc->ResetScrollbarPreferences();
}
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
if (htmlDoc) {
nsCOMPtr<nsIDOMHTMLFrameSetElement> frameset =
do_QueryInterface(mDocument->GetRootContent());
htmlDoc->SetIsFrameset(frameset != nsnull);
}
// Initial reflow

View File

@ -108,7 +108,6 @@
#include "nsTimer.h"
#include "nsITimer.h"
#include "nsDOMError.h"
#include "nsIScrollable.h"
#include "nsContentPolicyUtils.h"
#include "nsIScriptContext.h"
#include "nsStyleLinkElement.h"
@ -3646,24 +3645,9 @@ HTMLContentSink::StartLayout()
mLastNotificationTime = PR_Now();
// If it's a frameset document then disable scrolling.
// Else, reset scrolling to default settings for this shell.
// This must happen before the initial reflow, when we create the root frame
nsCOMPtr<nsIScrollable> scrollableContainer = do_QueryInterface(mDocShell);
if (scrollableContainer) {
if (mFrameset) {
scrollableContainer->
SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,
nsIScrollable::Scrollbar_Never);
scrollableContainer->
SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_X,
nsIScrollable::Scrollbar_Never);
} else {
scrollableContainer->ResetScrollbarPreferences();
}
}
mHTMLDocument->SetIsFrameset(mFrameset != nsnull);
nsContentSink::StartLayout(!!mFrameset);
nsContentSink::StartLayout(mFrameset != nsnull);
}
void

View File

@ -119,6 +119,9 @@ public:
return mWriteLevel != PRUint32(0);
}
virtual PRBool GetIsFrameset() { return mIsFrameset; }
virtual void SetIsFrameset(PRBool aFrameset) { mIsFrameset = aFrameset; }
virtual void ContentAppended(nsIContent* aContainer,
PRInt32 aNewIndexInContainer);
virtual void ContentInserted(nsIContent* aContainer,
@ -319,6 +322,8 @@ protected:
*/
PRPackedBool mDomainWasSet;
PRPackedBool mIsFrameset;
PLDHashTable mIdAndNameHashTable;
nsCOMPtr<nsIWyciwygChannel> mWyciwygChannel;

View File

@ -111,6 +111,9 @@ public:
virtual PRInt32 GetNumFormsSynchronous() = 0;
virtual PRBool IsWriting() = 0;
virtual PRBool GetIsFrameset() = 0;
virtual void SetIsFrameset(PRBool aFrameset) = 0;
};
#endif /* nsIHTMLDocument_h___ */

View File

@ -267,13 +267,6 @@ nsMediaDocument::CreateSyntheticDocument()
nsresult
nsMediaDocument::StartLayout()
{
// Reset scrolling to default settings for this shell.
// This must happen before the initial reflow, when we create the root frame
nsCOMPtr<nsIScrollable> scrollableContainer(do_QueryReferent(mDocumentContainer));
if (scrollableContainer) {
scrollableContainer->ResetScrollbarPreferences();
}
PRUint32 numberOfShells = GetNumberOfShells();
for (PRUint32 i = 0; i < numberOfShells; i++) {
nsIPresShell *shell = GetShellAt(i);

View File

@ -78,7 +78,6 @@
#include "prlog.h"
#include "prmem.h"
#include "nsParserUtils.h"
#include "nsIScrollable.h"
#include "nsRect.h"
#include "nsGenericElement.h"
#include "nsIWebNavigation.h"
@ -832,12 +831,6 @@ nsXMLContentSink::PopContent()
void
nsXMLContentSink::StartLayout()
{
// Reset scrolling to default settings for this shell.
// This must happen before the initial reflow, when we create the root frame
nsCOMPtr<nsIScrollable> scrollableContainer(do_QueryInterface(mDocShell));
if (scrollableContainer) {
scrollableContainer->ResetScrollbarPreferences();
}
PRBool topLevelFrameset = PR_FALSE;
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
if (docShellAsItem) {

View File

@ -268,7 +268,6 @@ nsDocShell::nsDocShell():
mMarginHeight(0),
mItemType(typeContent),
mContentListener(nsnull),
mCurrentScrollbarPref(Scrollbar_Auto, Scrollbar_Auto),
mDefaultScrollbarPref(Scrollbar_Auto, Scrollbar_Auto),
mEditorData(nsnull),
mParent(nsnull),
@ -3653,29 +3652,6 @@ nsDocShell::SetScrollRangeEx(PRInt32 minHorizontalPos,
return NS_ERROR_FAILURE;
}
// Get scroll setting for this document only
//
// One important client is nsCSSFrameConstructor::ConstructRootFrame()
NS_IMETHODIMP
nsDocShell::GetCurrentScrollbarPreferences(PRInt32 scrollOrientation,
PRInt32 * scrollbarPref)
{
NS_ENSURE_ARG_POINTER(scrollbarPref);
switch (scrollOrientation) {
case ScrollOrientation_X:
*scrollbarPref = mCurrentScrollbarPref.x;
return NS_OK;
case ScrollOrientation_Y:
*scrollbarPref = mCurrentScrollbarPref.y;
return NS_OK;
default:
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
}
return NS_ERROR_FAILURE;
}
// This returns setting for all documents in this webshell
NS_IMETHODIMP
nsDocShell::GetDefaultScrollbarPreferences(PRInt32 scrollOrientation,
@ -3697,39 +3673,14 @@ nsDocShell::GetDefaultScrollbarPreferences(PRInt32 scrollOrientation,
return NS_ERROR_FAILURE;
}
// Set scrolling preference for this document only.
// Set scrolling preference for all documents in this shell
//
// There are three possible values stored in the shell:
// 1) NS_STYLE_OVERFLOW_HIDDEN = no scrollbars
// 2) NS_STYLE_OVERFLOW_AUTO = scrollbars appear if needed
// 3) NS_STYLE_OVERFLOW_SCROLL = scrollbars always
// 1) nsIScrollable::Scrollbar_Never = no scrollbar
// 2) nsIScrollable::Scrollbar_Auto = scrollbar appears if the document
// being displayed would normally have scrollbar
// 3) nsIScrollable::Scrollbar_Always = scrollbar always appears
//
// XXX Currently OVERFLOW_SCROLL isn't honored,
// as it is not implemented by Gfx scrollbars
// XXX setting has no effect after the root frame is created
// as it is not implemented by Gfx scrollbars
//
// One important client is HTMLContentSink::StartLayout()
NS_IMETHODIMP
nsDocShell::SetCurrentScrollbarPreferences(PRInt32 scrollOrientation,
PRInt32 scrollbarPref)
{
switch (scrollOrientation) {
case ScrollOrientation_X:
mCurrentScrollbarPref.x = scrollbarPref;
return NS_OK;
case ScrollOrientation_Y:
mCurrentScrollbarPref.y = scrollbarPref;
return NS_OK;
default:
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
}
return NS_ERROR_FAILURE;
}
// Set scrolling preference for all documents in this shell
// One important client is nsHTMLFrameInnerFrame::CreateWebShell()
NS_IMETHODIMP
nsDocShell::SetDefaultScrollbarPreferences(PRInt32 scrollOrientation,
@ -3750,19 +3701,6 @@ nsDocShell::SetDefaultScrollbarPreferences(PRInt32 scrollOrientation,
return NS_ERROR_FAILURE;
}
// Reset 'current' scrollbar settings to 'default'.
// This must be called before every document load or else
// frameset scrollbar settings (e.g. <IFRAME SCROLLING="no">
// will not be preserved.
//
// One important client is HTMLContentSink::StartLayout()
NS_IMETHODIMP
nsDocShell::ResetScrollbarPreferences()
{
mCurrentScrollbarPref = mDefaultScrollbarPref;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetScrollbarVisibility(PRBool * verticalVisible,
PRBool * horizontalVisible)

View File

@ -411,7 +411,6 @@ protected:
nsCOMPtr<nsIGlobalHistory2> mGlobalHistory;
nsCOMPtr<nsISupports> mLoadCookie; // the load cookie associated with the window context.
nsCOMPtr<nsIWebBrowserFind> mFind;
nsPoint mCurrentScrollbarPref; // this document only
nsPoint mDefaultScrollbarPref; // persistent across doc loads
// Reference to the SHEntry for this docshell until the page is destroyed.
// Somebody give me better name

View File

@ -48,7 +48,7 @@
* min and the max.
*/
[scriptable, uuid(70bd2967-288b-4d0b-880a-de0b7c15a77c)]
[scriptable, uuid(919e792a-6490-40b8-bba5-f9e9ad5640c8)]
interface nsIScrollable : nsISupports
{
/*
@ -114,11 +114,8 @@ interface nsIScrollable : nsISupports
default is 'scrolling preference for all documents in this shell'
resetScrollbarPreferences resets current to default
*/
long getCurrentScrollbarPreferences(in long scrollOrientation);
void setCurrentScrollbarPreferences(in long scrollOrientation, in long scrollbarPref);
long getDefaultScrollbarPreferences(in long scrollOrientation);
void setDefaultScrollbarPreferences(in long scrollOrientation, in long scrollbarPref);
void resetScrollbarPreferences();
/*
Get information about whether the vertical and horizontal scrollbars are

View File

@ -1524,15 +1524,6 @@ NS_IMETHODIMP nsWebBrowser::SetScrollRangeEx(PRInt32 aMinHorizontalPos,
aMaxHorizontalPos, aMinVerticalPos, aMaxVerticalPos);
}
NS_IMETHODIMP nsWebBrowser::GetCurrentScrollbarPreferences(PRInt32 aScrollOrientation,
PRInt32* aScrollbarPref)
{
NS_ENSURE_STATE(mDocShell);
return mDocShellAsScrollable->GetCurrentScrollbarPreferences(aScrollOrientation,
aScrollbarPref);
}
NS_IMETHODIMP nsWebBrowser::GetDefaultScrollbarPreferences(PRInt32 aScrollOrientation,
PRInt32* aScrollbarPref)
{
@ -1542,16 +1533,6 @@ NS_IMETHODIMP nsWebBrowser::GetDefaultScrollbarPreferences(PRInt32 aScrollOrient
aScrollbarPref);
}
NS_IMETHODIMP nsWebBrowser::SetCurrentScrollbarPreferences(PRInt32 aScrollOrientation,
PRInt32 aScrollbarPref)
{
NS_ENSURE_STATE(mDocShell);
return mDocShellAsScrollable->SetCurrentScrollbarPreferences(aScrollOrientation,
aScrollbarPref);
}
NS_IMETHODIMP nsWebBrowser::SetDefaultScrollbarPreferences(PRInt32 aScrollOrientation,
PRInt32 aScrollbarPref)
{
@ -1561,13 +1542,6 @@ NS_IMETHODIMP nsWebBrowser::SetDefaultScrollbarPreferences(PRInt32 aScrollOrient
aScrollbarPref);
}
NS_IMETHODIMP nsWebBrowser::ResetScrollbarPreferences()
{
NS_ENSURE_STATE(mDocShell);
return mDocShellAsScrollable->ResetScrollbarPreferences();
}
NS_IMETHODIMP nsWebBrowser::GetScrollbarVisibility(PRBool* aVerticalVisible,
PRBool* aHorizontalVisible)
{

View File

@ -3824,7 +3824,6 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
// for print-preview, but not when printing), then create a scroll frame that
// will act as the scrolling mechanism for the viewport.
// XXX Do we even need a viewport when printing to a printer?
PRBool isScrollable = PR_TRUE;
//isScrollable = PR_FALSE;
@ -3833,11 +3832,11 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
// the viewport.
//
// Threre are three possible values stored in the docshell:
// 1) NS_STYLE_OVERFLOW_HIDDEN = no scrollbars
// 2) NS_STYLE_OVERFLOW_AUTO = scrollbars appear if needed
// 3) NS_STYLE_OVERFLOW_SCROLL = scrollbars always
// 1) nsIScrollable::Scrollbar_Never = no scrollbars
// 2) nsIScrollable::Scrollbar_Auto = scrollbars appear if needed
// 3) nsIScrollable::Scrollbar_Always = scrollbars always
// Only need to create a scroll frame/view for cases 2 and 3.
// Currently OVERFLOW_SCROLL isn't honored, as
// Currently Scrollbar_Always isn't honored, as
// scrollportview::SetScrollPref is not implemented.
PRBool isHTML = aDocElement->IsContentOfType(nsIContent::eHTML);
@ -3848,12 +3847,16 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
}
// Never create scrollbars for XUL documents
#ifdef MOZ_XUL
if (isXUL) {
isScrollable = PR_FALSE;
} else
#endif
{
PRBool isScrollable = !isXUL;
// Never create scrollbars for frameset documents.
if (isHTML) {
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
if (htmlDoc && htmlDoc->GetIsFrameset())
isScrollable = PR_FALSE;
}
if (isScrollable) {
nsresult rv;
if (aPresContext) {
nsCOMPtr<nsISupports> container = aPresContext->GetContainer();
@ -3862,7 +3865,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
if (NS_SUCCEEDED(rv) && scrollableContainer) {
PRInt32 scrolling = -1;
// XXX We should get prefs for X and Y and deal with these independently!
scrollableContainer->GetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,&scrolling);
scrollableContainer->GetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,&scrolling);
if (nsIScrollable::Scrollbar_Never == scrolling) {
isScrollable = PR_FALSE;
}

View File

@ -120,7 +120,7 @@
#include "nsIFocusController.h"
#include "nsIScrollableView.h"
#include "nsIScrollable.h"
#include "nsIHTMLDocument.h"
#include "nsITimelineService.h"
#include "nsGfxCIID.h"
@ -678,23 +678,11 @@ DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow)
mViewManager->SetDefaultBackgroundColor(mPresContext->DefaultBackgroundColor());
if (aDoInitialReflow) {
nsCOMPtr<nsIScrollable> sc = do_QueryInterface(mContainer);
if (sc) {
nsCOMPtr<nsIDOMHTMLFrameSetElement> frameset(do_QueryInterface(mDocument->GetRootContent()));
if (frameset) {
// If this is a frameset (i.e. not a frame) then we never want
// scrollbars on it, the scrollbars go inside the frames
// inside the frameset...
sc->SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,
nsIScrollable::Scrollbar_Never);
sc->SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_X,
nsIScrollable::Scrollbar_Never);
} else {
sc->ResetScrollbarPreferences();
}
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
if (htmlDoc) {
nsCOMPtr<nsIDOMHTMLFrameSetElement> frameset =
do_QueryInterface(mDocument->GetRootContent());
htmlDoc->SetIsFrameset(frameset != nsnull);
}
// Initial reflow

View File

@ -3824,7 +3824,6 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
// for print-preview, but not when printing), then create a scroll frame that
// will act as the scrolling mechanism for the viewport.
// XXX Do we even need a viewport when printing to a printer?
PRBool isScrollable = PR_TRUE;
//isScrollable = PR_FALSE;
@ -3833,11 +3832,11 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
// the viewport.
//
// Threre are three possible values stored in the docshell:
// 1) NS_STYLE_OVERFLOW_HIDDEN = no scrollbars
// 2) NS_STYLE_OVERFLOW_AUTO = scrollbars appear if needed
// 3) NS_STYLE_OVERFLOW_SCROLL = scrollbars always
// 1) nsIScrollable::Scrollbar_Never = no scrollbars
// 2) nsIScrollable::Scrollbar_Auto = scrollbars appear if needed
// 3) nsIScrollable::Scrollbar_Always = scrollbars always
// Only need to create a scroll frame/view for cases 2 and 3.
// Currently OVERFLOW_SCROLL isn't honored, as
// Currently Scrollbar_Always isn't honored, as
// scrollportview::SetScrollPref is not implemented.
PRBool isHTML = aDocElement->IsContentOfType(nsIContent::eHTML);
@ -3848,12 +3847,16 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
}
// Never create scrollbars for XUL documents
#ifdef MOZ_XUL
if (isXUL) {
isScrollable = PR_FALSE;
} else
#endif
{
PRBool isScrollable = !isXUL;
// Never create scrollbars for frameset documents.
if (isHTML) {
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
if (htmlDoc && htmlDoc->GetIsFrameset())
isScrollable = PR_FALSE;
}
if (isScrollable) {
nsresult rv;
if (aPresContext) {
nsCOMPtr<nsISupports> container = aPresContext->GetContainer();
@ -3862,7 +3865,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
if (NS_SUCCEEDED(rv) && scrollableContainer) {
PRInt32 scrolling = -1;
// XXX We should get prefs for X and Y and deal with these independently!
scrollableContainer->GetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,&scrolling);
scrollableContainer->GetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,&scrolling);
if (nsIScrollable::Scrollbar_Never == scrolling) {
isScrollable = PR_FALSE;
}