Bug 201300. Get rid of document observer from nsGfxScrollFrame. r+sr=bz

This commit is contained in:
roc+%cs.cmu.edu 2003-04-09 11:27:09 +00:00
parent 61cded3928
commit 12c5a8aa8b
8 changed files with 89 additions and 161 deletions

View File

@ -135,6 +135,10 @@ public:
PRBool aHorizontalVisible) = 0;
NS_IMETHOD GetScrollbarBox(PRBool aVertical, nsIBox** aResult) = 0;
NS_IMETHOD CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aModType) = 0;
};
#endif

View File

@ -73,8 +73,7 @@
#include "nsGUIEvent.h"
//----------------------------------------------------------------------
class nsGfxScrollFrameInner : public nsIDocumentObserver,
public nsIScrollPositionListener {
class nsGfxScrollFrameInner : public nsIScrollPositionListener {
NS_DECL_ISUPPORTS
@ -88,63 +87,10 @@ public:
NS_IMETHOD ScrollPositionWillChange(nsIScrollableView* aScrollable, nscoord aX, nscoord aY);
NS_IMETHOD ScrollPositionDidChange(nsIScrollableView* aScrollable, nscoord aX, nscoord aY);
// nsIDocumentObserver
NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD BeginReflow(nsIDocument *aDocument,
nsIPresShell* aShell) { return NS_OK; }
NS_IMETHOD EndReflow(nsIDocument *aDocument,
nsIPresShell* aShell) { return NS_OK; }
NS_IMETHOD ContentChanged(nsIDocument* aDoc,
nsIContent* aContent,
nsISupports* aSubContent) { return NS_OK; }
NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument,
nsIContent* aContent1,
nsIContent* aContent2,
PRInt32 aStateMask) { return NS_OK; }
NS_IMETHOD AttributeChanged(nsIDocument *aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType,
nsChangeHint aHint);
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
nsIContent* aContainer,
PRInt32 aNewIndexInContainer) { return NS_OK; }
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer) { return NS_OK; }
NS_IMETHOD ContentReplaced(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aOldChild,
nsIContent* aNewChild,
PRInt32 aIndexInContainer) { return NS_OK; }
NS_IMETHOD ContentRemoved(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer) { return NS_OK; }
NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet) { return NS_OK; }
NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet) { return NS_OK; }
NS_IMETHOD StyleSheetApplicableStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aApplicable) { return NS_OK; }
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
nsChangeHint aHint) { return NS_OK; }
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument) { mDocument = nsnull; return NS_OK; }
// This gets called when the 'curpos' attribute on one of the scrollbars changes
nsresult CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aModType);
PRBool SetAttribute(nsIBox* aBox, nsIAtom* aAtom, nscoord aSize, PRBool aReflow=PR_TRUE);
PRInt32 GetIntegerAttribute(nsIBox* aFrame, nsIAtom* atom, PRInt32 defaultValue);
@ -190,7 +136,6 @@ public:
nsIBox* mVScrollbarBox;
nsIBox* mScrollAreaBox;
nscoord mOnePixel;
nsCOMPtr<nsIDocument> mDocument;
nsGfxScrollFrame* mOuter;
nsIScrollableView* mScrollableView;
nscoord mMaxElementWidth;
@ -207,7 +152,7 @@ public:
PRPackedBool mFrameInitiatedScroll;
};
NS_IMPL_ISUPPORTS2(nsGfxScrollFrameInner, nsIDocumentObserver, nsIScrollPositionListener)
NS_IMPL_ISUPPORTS1(nsGfxScrollFrameInner, nsIScrollPositionListener)
nsresult
NS_NewGfxScrollFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIDocument* aDocument, PRBool aIsRoot)
@ -228,7 +173,6 @@ nsGfxScrollFrame::nsGfxScrollFrame(nsIPresShell* aShell, nsIDocument* aDocument,
{
mInner = new nsGfxScrollFrameInner(this);
mInner->AddRef();
mInner->mDocument = aDocument;
mPresContext = nsnull;
mInner->mIsRoot = PR_FALSE;
mInner->mNeverReflowed = PR_TRUE;
@ -406,6 +350,12 @@ NS_IMETHODIMP
nsGfxScrollFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
nsISupportsArray& aAnonymousChildren)
{
nsCOMPtr<nsIPresShell> shell;
aPresContext->GetShell(getter_AddRefs(shell));
nsCOMPtr<nsIDocument> document;
if (shell)
shell->GetDocument(getter_AddRefs(document));
// The anonymous <div> used by <inputs> never gets scrollbars.
nsCOMPtr<nsITextControlFrame> textFrame(do_QueryInterface(mParent));
if (textFrame) {
@ -432,7 +382,8 @@ nsGfxScrollFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
return NS_ERROR_FAILURE;
nsCOMPtr<nsINodeInfoManager> nodeInfoManager;
mInner->mDocument->GetNodeInfoManager(*getter_AddRefs(nodeInfoManager));
if (document)
document->GetNodeInfoManager(*getter_AddRefs(nodeInfoManager));
NS_ENSURE_TRUE(nodeInfoManager, NS_ERROR_FAILURE);
nsCOMPtr<nsINodeInfo> nodeInfo;
@ -498,7 +449,6 @@ nsGfxScrollFrame::Init(nsIPresContext* aPresContext,
nsresult rv = nsBoxFrame::Init(aPresContext, aContent,
aParent, aStyleContext,
aPrevInFlow);
mInner->mDocument->AddObserver(mInner);
return rv;
}
@ -986,12 +936,17 @@ nsGfxScrollFrameInner::ScrollPositionDidChange(nsIScrollableView* aScrollable, n
}
NS_IMETHODIMP
nsGfxScrollFrameInner::AttributeChanged(nsIDocument *aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType,
nsChangeHint aHint)
nsGfxScrollFrame::CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aModType)
{
return mInner->CurPosAttributeChanged(aPresContext, aChild, aModType);
}
nsresult
nsGfxScrollFrameInner::CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aContent,
PRInt32 aModType)
{
// Attribute changes on the scrollbars happen in one of three ways:
// 1) The scrollbar changed the attribute in response to some user event
@ -1661,10 +1616,6 @@ nsGfxScrollFrameInner::ScrollbarChanged(nsIPresContext* aPresContext, nscoord aX
nsGfxScrollFrameInner::~nsGfxScrollFrameInner()
{
if (mDocument) {
mDocument->RemoveObserver(this);
mDocument = nsnull;
}
}
/**

View File

@ -155,6 +155,10 @@ public:
NS_IMETHOD GetScrollbarBox(PRBool aVertical, nsIBox** aResult);
NS_IMETHOD CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aModType);
NS_IMETHOD GetClipSize(nsIPresContext* aPresContext,
nscoord *aWidth,
nscoord *aHeight) const;

View File

@ -135,6 +135,10 @@ public:
PRBool aHorizontalVisible) = 0;
NS_IMETHOD GetScrollbarBox(PRBool aVertical, nsIBox** aResult) = 0;
NS_IMETHOD CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aModType) = 0;
};
#endif

View File

@ -73,8 +73,7 @@
#include "nsGUIEvent.h"
//----------------------------------------------------------------------
class nsGfxScrollFrameInner : public nsIDocumentObserver,
public nsIScrollPositionListener {
class nsGfxScrollFrameInner : public nsIScrollPositionListener {
NS_DECL_ISUPPORTS
@ -88,63 +87,10 @@ public:
NS_IMETHOD ScrollPositionWillChange(nsIScrollableView* aScrollable, nscoord aX, nscoord aY);
NS_IMETHOD ScrollPositionDidChange(nsIScrollableView* aScrollable, nscoord aX, nscoord aY);
// nsIDocumentObserver
NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD BeginReflow(nsIDocument *aDocument,
nsIPresShell* aShell) { return NS_OK; }
NS_IMETHOD EndReflow(nsIDocument *aDocument,
nsIPresShell* aShell) { return NS_OK; }
NS_IMETHOD ContentChanged(nsIDocument* aDoc,
nsIContent* aContent,
nsISupports* aSubContent) { return NS_OK; }
NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument,
nsIContent* aContent1,
nsIContent* aContent2,
PRInt32 aStateMask) { return NS_OK; }
NS_IMETHOD AttributeChanged(nsIDocument *aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType,
nsChangeHint aHint);
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
nsIContent* aContainer,
PRInt32 aNewIndexInContainer) { return NS_OK; }
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer) { return NS_OK; }
NS_IMETHOD ContentReplaced(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aOldChild,
nsIContent* aNewChild,
PRInt32 aIndexInContainer) { return NS_OK; }
NS_IMETHOD ContentRemoved(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer) { return NS_OK; }
NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet) { return NS_OK; }
NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet) { return NS_OK; }
NS_IMETHOD StyleSheetApplicableStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aApplicable) { return NS_OK; }
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
nsChangeHint aHint) { return NS_OK; }
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument) { mDocument = nsnull; return NS_OK; }
// This gets called when the 'curpos' attribute on one of the scrollbars changes
nsresult CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aModType);
PRBool SetAttribute(nsIBox* aBox, nsIAtom* aAtom, nscoord aSize, PRBool aReflow=PR_TRUE);
PRInt32 GetIntegerAttribute(nsIBox* aFrame, nsIAtom* atom, PRInt32 defaultValue);
@ -190,7 +136,6 @@ public:
nsIBox* mVScrollbarBox;
nsIBox* mScrollAreaBox;
nscoord mOnePixel;
nsCOMPtr<nsIDocument> mDocument;
nsGfxScrollFrame* mOuter;
nsIScrollableView* mScrollableView;
nscoord mMaxElementWidth;
@ -207,7 +152,7 @@ public:
PRPackedBool mFrameInitiatedScroll;
};
NS_IMPL_ISUPPORTS2(nsGfxScrollFrameInner, nsIDocumentObserver, nsIScrollPositionListener)
NS_IMPL_ISUPPORTS1(nsGfxScrollFrameInner, nsIScrollPositionListener)
nsresult
NS_NewGfxScrollFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIDocument* aDocument, PRBool aIsRoot)
@ -228,7 +173,6 @@ nsGfxScrollFrame::nsGfxScrollFrame(nsIPresShell* aShell, nsIDocument* aDocument,
{
mInner = new nsGfxScrollFrameInner(this);
mInner->AddRef();
mInner->mDocument = aDocument;
mPresContext = nsnull;
mInner->mIsRoot = PR_FALSE;
mInner->mNeverReflowed = PR_TRUE;
@ -406,6 +350,12 @@ NS_IMETHODIMP
nsGfxScrollFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
nsISupportsArray& aAnonymousChildren)
{
nsCOMPtr<nsIPresShell> shell;
aPresContext->GetShell(getter_AddRefs(shell));
nsCOMPtr<nsIDocument> document;
if (shell)
shell->GetDocument(getter_AddRefs(document));
// The anonymous <div> used by <inputs> never gets scrollbars.
nsCOMPtr<nsITextControlFrame> textFrame(do_QueryInterface(mParent));
if (textFrame) {
@ -432,7 +382,8 @@ nsGfxScrollFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
return NS_ERROR_FAILURE;
nsCOMPtr<nsINodeInfoManager> nodeInfoManager;
mInner->mDocument->GetNodeInfoManager(*getter_AddRefs(nodeInfoManager));
if (document)
document->GetNodeInfoManager(*getter_AddRefs(nodeInfoManager));
NS_ENSURE_TRUE(nodeInfoManager, NS_ERROR_FAILURE);
nsCOMPtr<nsINodeInfo> nodeInfo;
@ -498,7 +449,6 @@ nsGfxScrollFrame::Init(nsIPresContext* aPresContext,
nsresult rv = nsBoxFrame::Init(aPresContext, aContent,
aParent, aStyleContext,
aPrevInFlow);
mInner->mDocument->AddObserver(mInner);
return rv;
}
@ -986,12 +936,17 @@ nsGfxScrollFrameInner::ScrollPositionDidChange(nsIScrollableView* aScrollable, n
}
NS_IMETHODIMP
nsGfxScrollFrameInner::AttributeChanged(nsIDocument *aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType,
nsChangeHint aHint)
nsGfxScrollFrame::CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aModType)
{
return mInner->CurPosAttributeChanged(aPresContext, aChild, aModType);
}
nsresult
nsGfxScrollFrameInner::CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aContent,
PRInt32 aModType)
{
// Attribute changes on the scrollbars happen in one of three ways:
// 1) The scrollbar changed the attribute in response to some user event
@ -1661,10 +1616,6 @@ nsGfxScrollFrameInner::ScrollbarChanged(nsIPresContext* aPresContext, nscoord aX
nsGfxScrollFrameInner::~nsGfxScrollFrameInner()
{
if (mDocument) {
mDocument->RemoveObserver(this);
mDocument = nsnull;
}
}
/**

View File

@ -155,6 +155,10 @@ public:
NS_IMETHOD GetScrollbarBox(PRBool aVertical, nsIBox** aResult);
NS_IMETHOD CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aModType);
NS_IMETHOD GetClipSize(nsIPresContext* aPresContext,
nscoord *aWidth,
nscoord *aHeight) const;

View File

@ -145,6 +145,11 @@ public:
NS_IMETHOD ScrollTo(nsIPresContext* aContext, nscoord aX, nscoord aY, PRUint32 aFlags);
NS_IMETHOD GetScrollbarBox(PRBool aVertical, nsIBox** aResult) { *aResult = nsnull; return NS_OK; };
// nsScrollFrame will die soon, anyway
NS_IMETHOD CurPosAttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aModType) {}
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void) { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release(void) { return NS_OK; }

View File

@ -44,6 +44,8 @@
#include "nsScrollbarFrame.h"
#include "nsScrollbarButtonFrame.h"
#include "nsXULAtoms.h"
#include "nsIScrollableFrame.h"
#include "nsIView.h"
#include "nsIViewManager.h"
@ -120,20 +122,23 @@ nsScrollbarFrame::AttributeChanged(nsIPresContext* aPresContext,
{
nsresult rv = nsBoxFrame::AttributeChanged(aPresContext, aChild,
aNameSpaceID, aAttribute, aModType, aHint);
/*// if the current position changes
if ( aAttribute == nsXULAtoms::curpos ||
aAttribute == nsXULAtoms::maxpos ||
aAttribute == nsXULAtoms::pageincrement ||
aAttribute == nsXULAtoms::increment) {
// tell the slider its attribute changed so it can
// update itself
nsIFrame* slider;
nsScrollbarButtonFrame::GetChildWithTag(aPresContext, nsXULAtoms::slider, this, slider);
if (slider)
slider->AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aModType, aHint);
}
*/
// if the current position changes, notify any nsGfxScrollFrame
// parent we may have
if (aAttribute != nsXULAtoms::curpos)
return rv;
nsIFrame* parent;
GetParent(&parent);
if (!parent)
return rv;
nsIScrollableFrame* scrollable = nsnull;
parent->QueryInterface(NS_GET_IID(nsIScrollableFrame), (void**)&scrollable);
if (!scrollable)
return rv;
scrollable->CurPosAttributeChanged(aPresContext, aChild, aModType);
return rv;
}