From 6a2ad594078ef1738161f574b308bf011cd28ebd Mon Sep 17 00:00:00 2001 From: "evaughan%netscape.com" Date: Wed, 5 Apr 2000 00:19:00 +0000 Subject: [PATCH] 1) Bug fixes. 2) Changed to fix rods text control 3) Added new Grid widget --- layout/base/nsCSSFrameConstructor.cpp | 52 +-- layout/generic/nsGfxScrollFrame.cpp | 31 ++ layout/generic/nsGfxScrollFrame.h | 5 + layout/html/base/src/nsGfxScrollFrame.cpp | 31 ++ layout/html/base/src/nsGfxScrollFrame.h | 5 + .../html/style/src/nsCSSFrameConstructor.cpp | 52 +-- layout/xul/base/src/makefile.win | 8 + layout/xul/base/src/nsBox.cpp | 2 +- layout/xul/base/src/nsBoxFrame.cpp | 54 ++- layout/xul/base/src/nsBoxFrame.h | 11 +- layout/xul/base/src/nsBoxLayout.cpp | 2 +- layout/xul/base/src/nsBoxLayoutState.cpp | 22 +- layout/xul/base/src/nsBoxToBlockAdaptor.cpp | 8 +- layout/xul/base/src/nsDeckFrame.cpp | 17 +- layout/xul/base/src/nsDeckFrame.h | 4 +- layout/xul/base/src/nsGridLayout.cpp | 103 +++++ layout/xul/base/src/nsGridLayout.h | 53 +++ layout/xul/base/src/nsIMonument.h | 85 ++++ layout/xul/base/src/nsMonumentLayout.cpp | 370 ++++++++++++++++++ layout/xul/base/src/nsObeliskLayout.cpp | 214 ++++++++++ layout/xul/base/src/nsObeliskLayout.h | 66 ++++ layout/xul/base/src/nsRootBoxFrame.cpp | 7 +- layout/xul/base/src/nsSpringFrame.cpp | 6 +- layout/xul/base/src/nsSprocketLayout.cpp | 13 +- layout/xul/base/src/nsSprocketLayout.h | 8 +- layout/xul/base/src/nsStackFrame.cpp | 17 +- layout/xul/base/src/nsStackFrame.h | 5 +- layout/xul/base/src/nsStackLayout.cpp | 12 +- layout/xul/base/src/nsStackLayout.h | 9 +- layout/xul/base/src/nsTabFrame.cpp | 16 +- layout/xul/base/src/nsTempleLayout.cpp | 177 +++++++++ layout/xul/base/src/nsTempleLayout.h | 58 +++ 32 files changed, 1412 insertions(+), 111 deletions(-) create mode 100644 layout/xul/base/src/nsGridLayout.cpp create mode 100644 layout/xul/base/src/nsGridLayout.h create mode 100644 layout/xul/base/src/nsIMonument.h create mode 100644 layout/xul/base/src/nsMonumentLayout.cpp create mode 100644 layout/xul/base/src/nsObeliskLayout.cpp create mode 100644 layout/xul/base/src/nsObeliskLayout.h create mode 100644 layout/xul/base/src/nsTempleLayout.cpp create mode 100644 layout/xul/base/src/nsTempleLayout.h diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 56c5383628e1..496a4b91c136 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -157,23 +157,9 @@ nsresult NS_NewGfxListControlFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); #endif -// grid - -/* -nsresult -NS_NewGridFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); nsresult -NS_NewTempleFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsHorizontal); - -nsresult -NS_NewObeliskFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsHorizontal); - -// end grid -*/ - -nsresult -NS_NewRootBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); +NS_NewRootBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame); nsresult NS_NewThumbFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); @@ -188,13 +174,13 @@ nsresult NS_NewTabFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); nsresult -NS_NewDeckFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); +NS_NewDeckFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayoutManager = nsnull); nsresult NS_NewSpringFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); nsresult -NS_NewStackFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); +NS_NewStackFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayoutManager = nsnull); nsresult NS_NewProgressMeterFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); @@ -217,9 +203,6 @@ NS_NewTitledBoxInnerFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); nsresult NS_NewTitleFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); -nsresult -NS_NewBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot); - nsresult NS_NewButtonBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame); @@ -262,6 +245,18 @@ NS_NewMenuFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRUint32 aFlag nsresult NS_NewMenuBarFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); +// grid +nsresult +NS_NewGridLayout ( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout ); + +nsresult +NS_NewObeliskLayout ( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout ); + +nsresult +NS_NewTempleLayout ( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout ); + +// end grid + #endif //static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID); @@ -5412,13 +5407,13 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell, rv = NS_NewMenuPopupFrame(aPresShell, &newFrame); } - /* - // ------- Begin Grid --------- else if (aTag == nsXULAtoms::grid) { processChildren = PR_TRUE; isReplaced = PR_TRUE; - rv = NS_NewGridFrame(aPresShell, &newFrame); + nsCOMPtr layout; + NS_NewGridLayout(aPresShell, layout); + rv = NS_NewBoxFrame(aPresShell, &newFrame, PR_FALSE, layout); const nsStyleDisplay* display = (const nsStyleDisplay*) aStyleContext->GetStyleData(eStyleStruct_Display); @@ -5445,7 +5440,10 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell, processChildren = PR_TRUE; isReplaced = PR_TRUE; PRBool isHorizontal = (aTag == nsXULAtoms::columns); - rv = NS_NewTempleFrame(aPresShell, &newFrame, isHorizontal); + + nsCOMPtr layout; + NS_NewTempleLayout(aPresShell, layout); + rv = NS_NewBoxFrame(aPresShell, &newFrame, PR_FALSE, layout, isHorizontal); const nsStyleDisplay* display = (const nsStyleDisplay*) aStyleContext->GetStyleData(eStyleStruct_Display); @@ -5472,7 +5470,9 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell, processChildren = PR_TRUE; isReplaced = PR_TRUE; PRBool isHorizontal = (aTag == nsXULAtoms::row); - rv = NS_NewObeliskFrame(aPresShell, &newFrame, isHorizontal); + nsCOMPtr layout; + NS_NewObeliskLayout(aPresShell, layout); + rv = NS_NewBoxFrame(aPresShell, &newFrame, PR_FALSE, layout, isHorizontal); const nsStyleDisplay* display = (const nsStyleDisplay*) aStyleContext->GetStyleData(eStyleStruct_Display); @@ -5493,7 +5493,7 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell, } } //------- End Grid ------ -*/ + else if (aTag == nsXULAtoms::title) { processChildren = PR_TRUE; isReplaced = PR_TRUE; diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 617ee8702a33..a2b7d6d2b007 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -521,6 +521,37 @@ nsGfxScrollFrame::GetMaxSize(nsBoxLayoutState& aState, nsSize& aSize) return NS_OK; } +NS_IMETHODIMP +nsGfxScrollFrame::Reflow(nsIPresContext* aPresContext, + nsHTMLReflowMetrics& aDesiredSize, + const nsHTMLReflowState& aReflowState, + nsReflowStatus& aStatus) +{ + nsresult rv = nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus); + + /* + // max sure the max element size reflects + // our min width + if (aDesiredSize.maxElementSize) + { + // get the ara frame is the scrollarea + nsIBox* child = nsnull; + mInner->mScrollAreaBox->GetChildBox(&child); + nsBoxLayoutState state(aPresContext, aReflowState, aDesiredSize); + nsSize minSize(0,0); + child->GetMinSize(state, minSize); + AddMargin(child, minSize); + AddBorderAndPadding(mInner->mScrollAreaBox, minSize); + AddInset(mInner->mScrollAreaBox, minSize); + AddBorderAndPadding(minSize); + AddInset(minSize); + aDesiredSize.maxElementSize->width += minSize.width; + } + */ + + return rv; +} + NS_IMETHODIMP_(nsrefcnt) nsGfxScrollFrame::AddRef(void) { diff --git a/layout/generic/nsGfxScrollFrame.h b/layout/generic/nsGfxScrollFrame.h index c625d0aa3ed4..85856e75024b 100644 --- a/layout/generic/nsGfxScrollFrame.h +++ b/layout/generic/nsGfxScrollFrame.h @@ -62,6 +62,11 @@ public: nsIAtom* aListName, nsIFrame* aChildList); + NS_IMETHOD Reflow(nsIPresContext* aPresContext, + nsHTMLReflowMetrics& aDesiredSize, + const nsHTMLReflowState& aReflowState, + nsReflowStatus& aStatus); + // Because there can be only one child frame, these two function return // NS_ERROR_FAILURE NS_IMETHOD AppendFrames(nsIPresContext* aPresContext, diff --git a/layout/html/base/src/nsGfxScrollFrame.cpp b/layout/html/base/src/nsGfxScrollFrame.cpp index 617ee8702a33..a2b7d6d2b007 100644 --- a/layout/html/base/src/nsGfxScrollFrame.cpp +++ b/layout/html/base/src/nsGfxScrollFrame.cpp @@ -521,6 +521,37 @@ nsGfxScrollFrame::GetMaxSize(nsBoxLayoutState& aState, nsSize& aSize) return NS_OK; } +NS_IMETHODIMP +nsGfxScrollFrame::Reflow(nsIPresContext* aPresContext, + nsHTMLReflowMetrics& aDesiredSize, + const nsHTMLReflowState& aReflowState, + nsReflowStatus& aStatus) +{ + nsresult rv = nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus); + + /* + // max sure the max element size reflects + // our min width + if (aDesiredSize.maxElementSize) + { + // get the ara frame is the scrollarea + nsIBox* child = nsnull; + mInner->mScrollAreaBox->GetChildBox(&child); + nsBoxLayoutState state(aPresContext, aReflowState, aDesiredSize); + nsSize minSize(0,0); + child->GetMinSize(state, minSize); + AddMargin(child, minSize); + AddBorderAndPadding(mInner->mScrollAreaBox, minSize); + AddInset(mInner->mScrollAreaBox, minSize); + AddBorderAndPadding(minSize); + AddInset(minSize); + aDesiredSize.maxElementSize->width += minSize.width; + } + */ + + return rv; +} + NS_IMETHODIMP_(nsrefcnt) nsGfxScrollFrame::AddRef(void) { diff --git a/layout/html/base/src/nsGfxScrollFrame.h b/layout/html/base/src/nsGfxScrollFrame.h index c625d0aa3ed4..85856e75024b 100644 --- a/layout/html/base/src/nsGfxScrollFrame.h +++ b/layout/html/base/src/nsGfxScrollFrame.h @@ -62,6 +62,11 @@ public: nsIAtom* aListName, nsIFrame* aChildList); + NS_IMETHOD Reflow(nsIPresContext* aPresContext, + nsHTMLReflowMetrics& aDesiredSize, + const nsHTMLReflowState& aReflowState, + nsReflowStatus& aStatus); + // Because there can be only one child frame, these two function return // NS_ERROR_FAILURE NS_IMETHOD AppendFrames(nsIPresContext* aPresContext, diff --git a/layout/html/style/src/nsCSSFrameConstructor.cpp b/layout/html/style/src/nsCSSFrameConstructor.cpp index 56c5383628e1..496a4b91c136 100644 --- a/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -157,23 +157,9 @@ nsresult NS_NewGfxListControlFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); #endif -// grid - -/* -nsresult -NS_NewGridFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); nsresult -NS_NewTempleFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsHorizontal); - -nsresult -NS_NewObeliskFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsHorizontal); - -// end grid -*/ - -nsresult -NS_NewRootBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); +NS_NewRootBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame); nsresult NS_NewThumbFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); @@ -188,13 +174,13 @@ nsresult NS_NewTabFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); nsresult -NS_NewDeckFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); +NS_NewDeckFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayoutManager = nsnull); nsresult NS_NewSpringFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); nsresult -NS_NewStackFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); +NS_NewStackFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayoutManager = nsnull); nsresult NS_NewProgressMeterFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); @@ -217,9 +203,6 @@ NS_NewTitledBoxInnerFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); nsresult NS_NewTitleFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); -nsresult -NS_NewBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot); - nsresult NS_NewButtonBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame); @@ -262,6 +245,18 @@ NS_NewMenuFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRUint32 aFlag nsresult NS_NewMenuBarFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); +// grid +nsresult +NS_NewGridLayout ( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout ); + +nsresult +NS_NewObeliskLayout ( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout ); + +nsresult +NS_NewTempleLayout ( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout ); + +// end grid + #endif //static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID); @@ -5412,13 +5407,13 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell, rv = NS_NewMenuPopupFrame(aPresShell, &newFrame); } - /* - // ------- Begin Grid --------- else if (aTag == nsXULAtoms::grid) { processChildren = PR_TRUE; isReplaced = PR_TRUE; - rv = NS_NewGridFrame(aPresShell, &newFrame); + nsCOMPtr layout; + NS_NewGridLayout(aPresShell, layout); + rv = NS_NewBoxFrame(aPresShell, &newFrame, PR_FALSE, layout); const nsStyleDisplay* display = (const nsStyleDisplay*) aStyleContext->GetStyleData(eStyleStruct_Display); @@ -5445,7 +5440,10 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell, processChildren = PR_TRUE; isReplaced = PR_TRUE; PRBool isHorizontal = (aTag == nsXULAtoms::columns); - rv = NS_NewTempleFrame(aPresShell, &newFrame, isHorizontal); + + nsCOMPtr layout; + NS_NewTempleLayout(aPresShell, layout); + rv = NS_NewBoxFrame(aPresShell, &newFrame, PR_FALSE, layout, isHorizontal); const nsStyleDisplay* display = (const nsStyleDisplay*) aStyleContext->GetStyleData(eStyleStruct_Display); @@ -5472,7 +5470,9 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell, processChildren = PR_TRUE; isReplaced = PR_TRUE; PRBool isHorizontal = (aTag == nsXULAtoms::row); - rv = NS_NewObeliskFrame(aPresShell, &newFrame, isHorizontal); + nsCOMPtr layout; + NS_NewObeliskLayout(aPresShell, layout); + rv = NS_NewBoxFrame(aPresShell, &newFrame, PR_FALSE, layout, isHorizontal); const nsStyleDisplay* display = (const nsStyleDisplay*) aStyleContext->GetStyleData(eStyleStruct_Display); @@ -5493,7 +5493,7 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell, } } //------- End Grid ------ -*/ + else if (aTag == nsXULAtoms::title) { processChildren = PR_TRUE; isReplaced = PR_TRUE; diff --git a/layout/xul/base/src/makefile.win b/layout/xul/base/src/makefile.win index 47380138d8f7..c1be212bf311 100644 --- a/layout/xul/base/src/makefile.win +++ b/layout/xul/base/src/makefile.win @@ -28,6 +28,10 @@ REQUIRES=xpcom raptor pref DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN CPPSRCS= \ + nsGridLayout.cpp \ + nsTempleLayout.cpp \ + nsObeliskLayout.cpp \ + nsMonumentLayout.cpp \ nsImageBoxFrame.cpp \ nsRootBoxFrame.cpp \ nsStackLayout.cpp \ @@ -83,6 +87,10 @@ CPPSRCS= \ $(NULL) CPP_OBJS= \ + .\$(OBJDIR)\nsGridLayout.obj \ + .\$(OBJDIR)\nsTempleLayout.obj \ + .\$(OBJDIR)\nsObeliskLayout.obj \ + .\$(OBJDIR)\nsMonumentLayout.obj \ .\$(OBJDIR)\nsImageBoxFrame.obj \ .\$(OBJDIR)\nsRootBoxFrame.obj \ .\$(OBJDIR)\nsStackLayout.obj \ diff --git a/layout/xul/base/src/nsBox.cpp b/layout/xul/base/src/nsBox.cpp index 810a7d826071..fb7a4e4b17f9 100644 --- a/layout/xul/base/src/nsBox.cpp +++ b/layout/xul/base/src/nsBox.cpp @@ -44,7 +44,7 @@ #include "nsHTMLAtoms.h" #include "nsXULAtoms.h" -nsBox::nsBox(nsIPresShell* aShell):mParentBox(nsnull),mNextChild(nsnull),mMouseThrough(always) +nsBox::nsBox(nsIPresShell* aShell):mParentBox(nsnull),mNextChild(nsnull),mMouseThrough(sometimes) { //mX = 0; //mY = 0; diff --git a/layout/xul/base/src/nsBoxFrame.cpp b/layout/xul/base/src/nsBoxFrame.cpp index 0dfe2a79ef60..796c37e60a89 100644 --- a/layout/xul/base/src/nsBoxFrame.cpp +++ b/layout/xul/base/src/nsBoxFrame.cpp @@ -172,7 +172,6 @@ public: static PRBool gDebug; static nsIBox* mDebugChild; - #ifdef DEBUG_REFLOW PRInt32 reflowCount; #endif @@ -190,28 +189,33 @@ PRInt32 gReflows = 0; #endif nsresult -NS_NewBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot) +NS_NewBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot, nsIBoxLayout* aLayoutManager, PRBool aIsHorizontal) { NS_PRECONDITION(aNewFrame, "null OUT ptr"); if (nsnull == aNewFrame) { return NS_ERROR_NULL_POINTER; } - nsBoxFrame* it = new (aPresShell) nsBoxFrame(aPresShell, aIsRoot); + nsBoxFrame* it = new (aPresShell) nsBoxFrame(aPresShell, aIsRoot, aLayoutManager, aIsHorizontal); if (nsnull == it) return NS_ERROR_OUT_OF_MEMORY; *aNewFrame = it; + return NS_OK; } // NS_NewBoxFrame -nsBoxFrame::nsBoxFrame(nsIPresShell* aPresShell, PRBool aIsRoot):nsContainerBox(aPresShell) +nsBoxFrame::nsBoxFrame(nsIPresShell* aPresShell, PRBool aIsRoot, nsIBoxLayout* aLayoutManager, PRBool aIsHorizontal):nsContainerBox(aPresShell) { mInner = new (aPresShell) nsBoxFrameInner(aPresShell, this); // if not otherwise specified boxes by default are horizontal. - mState |= NS_STATE_IS_HORIZONTAL; + if (aIsHorizontal) { + mState |= NS_STATE_IS_HORIZONTAL; + mState |= NS_STATE_DEFAULT_HORIZONTAL; + } + mState |= NS_STATE_AUTO_STRETCH; if (aIsRoot) @@ -223,9 +227,22 @@ nsBoxFrame::nsBoxFrame(nsIPresShell* aPresShell, PRBool aIsRoot):nsContainerBox( NeedsRecalc(); - nsSprocketLayout* layout = new nsSprocketLayout(aPresShell); + +#ifdef DEBUG_REFLOW + mInner->reflowCount = 100; +#endif + + // if no layout manager specified us the static sprocket layout + nsCOMPtr layout = aLayoutManager; + + if (layout == nsnull) { + NS_NewSprocketLayout(aPresShell, layout); + } + SetLayoutManager(layout); + NeedsRecalc(); + #ifdef DEBUG_REFLOW mInner->reflowCount = 100; #endif @@ -302,7 +319,10 @@ nsBoxFrame::Init(nsIPresContext* aPresContext, GetInitialVAlignment(mInner->mValign); GetInitialHAlignment(mInner->mHalign); - PRBool orient = mState & NS_STATE_IS_HORIZONTAL; + PRBool orient = PR_FALSE; + if (mState & NS_STATE_DEFAULT_HORIZONTAL) + orient = PR_TRUE; + GetInitialOrientation(orient); if (orient) mState |= NS_STATE_IS_HORIZONTAL; @@ -605,7 +625,7 @@ nsBoxFrame::Reflow(nsIPresContext* aPresContext, nsBoxLayoutState state(aPresContext, aReflowState, aDesiredSize); // coelesce reflows if we are root. - if (state.HandleReflow(this, (mState & NS_STATE_IS_ROOT))) { + if (state.HandleReflow(this, mState & NS_STATE_IS_ROOT)) { aDesiredSize.width = 10; aDesiredSize.height = 10; aDesiredSize.ascent = 0; @@ -631,8 +651,8 @@ nsBoxFrame::Reflow(nsIPresContext* aPresContext, // if we are told to layout intrinic then get our preferred size. if (computedSize.width == NS_INTRINSICSIZE || computedSize.height == NS_INTRINSICSIZE) { - nsSize minSize; - nsSize maxSize; + nsSize minSize(0,0); + nsSize maxSize(0,0); GetPrefSize(state, prefSize); GetMinSize(state, minSize); GetMaxSize(state, maxSize); @@ -676,6 +696,20 @@ nsBoxFrame::Reflow(nsIPresContext* aPresContext, aDesiredSize.ascent = ascent; aDesiredSize.descent = 0; + // max sure the max element size reflects + // our min width + nsSize* size = nsnull; + state.GetMaxElementSize(&size); + if (size) + { + nsSize minSize(0,0); + GetMinSize(state, minSize); + if (mRect.width < minSize.width) + size->width = minSize.width; + else + size->width = mRect.width; + } + return NS_OK; } diff --git a/layout/xul/base/src/nsBoxFrame.h b/layout/xul/base/src/nsBoxFrame.h index 2ac5a599c033..1ea614326d01 100644 --- a/layout/xul/base/src/nsBoxFrame.h +++ b/layout/xul/base/src/nsBoxFrame.h @@ -56,12 +56,18 @@ class nsHTMLInfo; #define NS_STATE_SET_TO_DEBUG 0x04000000 #define NS_STATE_DEBUG_WAS_SET 0x08000000 #define NS_STATE_IS_COLLAPSED 0x10000000 +#define NS_STATE_DEFAULT_HORIZONTAL 0x20000000 class nsBoxFrame : public nsHTMLContainerFrame, public nsContainerBox { public: - friend nsresult NS_NewBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot = PR_FALSE); + friend nsresult NS_NewBoxFrame(nsIPresShell* aPresShell, + nsIFrame** aNewFrame, + PRBool aIsRoot = PR_FALSE, + nsIBoxLayout* aLayoutManager = nsnull, + PRBool aDefaultHorizontal = PR_TRUE); + // gets the rect inside our border and debug border. If you wish to paint inside a box // call this method to get the rect so you don't draw on the debug border or outer border. @@ -159,8 +165,9 @@ public: virtual nsresult GetContentOf(nsIContent** aContent); + nsBoxFrame(nsIPresShell* aPresShell, PRBool aIsRoot = nsnull, nsIBoxLayout* aLayoutManager = nsnull, PRBool aDefaultHorizontal = PR_TRUE); + protected: - nsBoxFrame(nsIPresShell* aPresShell, PRBool aIsRoot = PR_FALSE); virtual void PropagateDebug(nsBoxLayoutState& aState); diff --git a/layout/xul/base/src/nsBoxLayout.cpp b/layout/xul/base/src/nsBoxLayout.cpp index 5901a3b672e5..53bf0e70b9e1 100644 --- a/layout/xul/base/src/nsBoxLayout.cpp +++ b/layout/xul/base/src/nsBoxLayout.cpp @@ -52,7 +52,7 @@ nsBoxLayout::GetParentLayout(nsIBox* aBox, nsIBoxLayout** aParent) aBox->GetParentBox(&parent); if (parent) { - aBox->GetLayoutManager(aParent); + parent->GetLayoutManager(aParent); return; } diff --git a/layout/xul/base/src/nsBoxLayoutState.cpp b/layout/xul/base/src/nsBoxLayoutState.cpp index bdc6f2a25b4c..1f03d617147f 100644 --- a/layout/xul/base/src/nsBoxLayoutState.cpp +++ b/layout/xul/base/src/nsBoxLayoutState.cpp @@ -156,15 +156,19 @@ nsBoxLayoutState::UnWind(nsIReflowCommand* aCommand, nsIBox* aBox, PRBool aCoele // ok we got a box is it the target? if (incrementalChild == target) { - if (!aCoelesce) { - nsFrameState state; - nsIFrame* frame; - aBox->GetFrame(&frame); - frame->GetFrameState(&state); + nsFrameState state; + nsIFrame* frame; + aBox->GetFrame(&frame); + frame->GetFrameState(&state); + + if (aCoelesce) + state &= ~NS_FRAME_HAS_DIRTY_CHILDREN; + else state |= NS_FRAME_HAS_DIRTY_CHILDREN; - frame->SetFrameState(state); - } - // the target is a box? + + frame->SetFrameState(state); + + // the target is a box? // mark it dirty generating a new reflow command targeted // at us and coelesce out this one. ibox->MarkDirty(*this); @@ -175,7 +179,7 @@ nsBoxLayoutState::UnWind(nsIReflowCommand* aCommand, nsIBox* aBox, PRBool aCoele nsIBox* parent; ibox->GetParentBox(&parent); parent->MarkDirty(*this); - //DirtyAllChildren(*this, box); + DirtyAllChildren(*this, ibox); } // yes we coelesed diff --git a/layout/xul/base/src/nsBoxToBlockAdaptor.cpp b/layout/xul/base/src/nsBoxToBlockAdaptor.cpp index 3e37ecb6dbd6..10a11f940f24 100644 --- a/layout/xul/base/src/nsBoxToBlockAdaptor.cpp +++ b/layout/xul/base/src/nsBoxToBlockAdaptor.cpp @@ -170,9 +170,6 @@ nsBoxToBlockAdaptor::GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize) if (currentSize) { desiredSize.maxElementSize = nsnull; - if (size.width > currentSize->width) - currentSize->width = size.width; - if (size.height > currentSize->height) currentSize->height = size.height; } @@ -315,10 +312,7 @@ nsBoxToBlockAdaptor::Layout(nsBoxLayoutState& aState) desiredSize.maxElementSize = nsnull; if (size.width > currentSize->width) - currentSize->width = size.width; - - if (size.height > currentSize->height) - currentSize->height = size.height; + currentSize->width = size.width; } mAscent = desiredSize.ascent; diff --git a/layout/xul/base/src/nsDeckFrame.cpp b/layout/xul/base/src/nsDeckFrame.cpp index 0c43967348d5..6f18ddccbc62 100644 --- a/layout/xul/base/src/nsDeckFrame.cpp +++ b/layout/xul/base/src/nsDeckFrame.cpp @@ -47,17 +47,16 @@ #include "nsStackLayout.h" nsresult -NS_NewDeckFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ) +NS_NewDeckFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayoutManager) { NS_PRECONDITION(aNewFrame, "null OUT ptr"); if (nsnull == aNewFrame) { return NS_ERROR_NULL_POINTER; } - nsDeckFrame* it = new (aPresShell) nsDeckFrame(aPresShell); + nsDeckFrame* it = new (aPresShell) nsDeckFrame(aPresShell, aLayoutManager); if (nsnull == it) return NS_ERROR_OUT_OF_MEMORY; - *aNewFrame = it; return NS_OK; @@ -66,12 +65,16 @@ NS_NewDeckFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ) nsCOMPtr nsDeckFrame::gLayout = nsnull; -nsDeckFrame::nsDeckFrame(nsIPresShell* aPresShell):nsBoxFrame(aPresShell) +nsDeckFrame::nsDeckFrame(nsIPresShell* aPresShell, nsIBoxLayout* aLayoutManager):nsBoxFrame(aPresShell) { - if (!gLayout) - gLayout = new nsStackLayout(aPresShell); + // if no layout manager specified us the static sprocket layout + nsCOMPtr layout = aLayoutManager; - SetLayoutManager(gLayout); + if (layout == nsnull) { + NS_NewStackLayout(aPresShell, layout); + } + + SetLayoutManager(layout); } NS_IMETHODIMP diff --git a/layout/xul/base/src/nsDeckFrame.h b/layout/xul/base/src/nsDeckFrame.h index 57bad08848b5..1e87c49776bf 100644 --- a/layout/xul/base/src/nsDeckFrame.h +++ b/layout/xul/base/src/nsDeckFrame.h @@ -37,7 +37,7 @@ class nsDeckFrame : public nsBoxFrame { public: - friend nsresult NS_NewDeckFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame); + friend nsresult NS_NewDeckFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayoutManager); @@ -66,6 +66,8 @@ public: return NS_OK; } + nsDeckFrame(nsIPresShell* aPresShell, nsIBoxLayout* aLayout = nsnull); + protected: nsDeckFrame(nsIPresShell* aPresShell); diff --git a/layout/xul/base/src/nsGridLayout.cpp b/layout/xul/base/src/nsGridLayout.cpp new file mode 100644 index 000000000000..12a0f6b39173 --- /dev/null +++ b/layout/xul/base/src/nsGridLayout.cpp @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +// +// Eric Vaughan +// Netscape Communications +// +// See documentation in associated header file +// + +#include "nsGridLayout.h" +#include "nsTempleLayout.h" +#include "nsIBox.h" + +nsresult +NS_NewGridLayout( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout) +{ + aNewLayout = new nsGridLayout(aPresShell); + + return NS_OK; + +} + +nsGridLayout::nsGridLayout(nsIPresShell* aPresShell):nsStackLayout() +{ +} + +/** + * Get the monuments in the other temple at the give monument index + */ +NS_IMETHODIMP +nsGridLayout::GetOtherMonumentsAt(nsIBox* aBox, PRInt32 aIndexOfObelisk, nsBoxSizeList** aList, nsMonumentLayout* aRequestor) +{ + nsTempleLayout* temple = nsnull; + nsIBox* templeBox = nsnull; + GetOtherTemple(aBox, &temple, &templeBox, aRequestor); + if (temple) + return temple->GetMonumentsAt(templeBox, aIndexOfObelisk, aList); + else + *aList = nsnull; + + return NS_OK; +} + +/** + * a Grid always has 2 temples. This is called by one temple to get the other + */ +NS_IMETHODIMP +nsGridLayout::GetOtherTemple(nsIBox* aBox, nsTempleLayout** aTemple, nsIBox** aTempleBox, nsMonumentLayout* aRequestor) +{ + // this is really easy. We know the index of the temple who requested + // so find our other temple who doesn't have that index. + + nsIBox* child = nsnull; + aBox->GetChildBox(&child); + + while(child) + { + nsIBoxLayout* layout = nsnull; + child->GetLayoutManager(&layout); + + // must find a temple that is not our requestor and is a monument. + if (layout != aRequestor) { + nsIMonument* monument = nsnull; + if (NS_SUCCEEDED(layout->QueryInterface(NS_GET_IID(nsIMonument), (void**)&monument)) && monument) + { + nsTempleLayout* temple = nsnull; + monument->CastToTemple(&temple); + if (temple) { + // yes its a temple. + *aTemple = temple; + *aTempleBox = child; + return NS_OK; + } + } + } + + child->GetNextBox(&child); + } + + *aTemple = nsnull; + + return NS_OK; +} diff --git a/layout/xul/base/src/nsGridLayout.h b/layout/xul/base/src/nsGridLayout.h new file mode 100644 index 000000000000..61400a4011db --- /dev/null +++ b/layout/xul/base/src/nsGridLayout.h @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +/** + + Author: + Eric D Vaughan + +**/ + +#ifndef nsGridLayout_h___ +#define nsGridLayout_h___ + +#include "nsStackLayout.h" +#include "nsCOMPtr.h" +class nsTempleLayout; +class nsMonumentLayout; +class nsBoxSizeList; + +class nsGridLayout : public nsStackLayout +{ +public: + + friend nsresult NS_NewGridLayout(nsIPresShell* aPresShell, nsCOMPtr& aNewLayout); + + NS_IMETHOD GetOtherMonumentsAt(nsIBox* aBox, PRInt32 aIndexOfObelisk, nsBoxSizeList** aList, nsMonumentLayout* aRequestor = nsnull); + NS_IMETHOD GetOtherTemple(nsIBox* aBox, nsTempleLayout** aTempleLayout, nsIBox** aTempleBox, nsMonumentLayout* aRequestor = nsnull); + +protected: + nsGridLayout(nsIPresShell* aShell); +}; // class nsGridLayout + +#endif + diff --git a/layout/xul/base/src/nsIMonument.h b/layout/xul/base/src/nsIMonument.h new file mode 100644 index 000000000000..47ad29324fda --- /dev/null +++ b/layout/xul/base/src/nsIMonument.h @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Author: + * Eric D Vaughan + * + * Contributor(s): + */ + +#ifndef nsIMonument_h___ +#define nsIMonument_h___ + +#include "nsISupports.h" +#include "nsIFrame.h" + +class nsIBox; +class nsBoxLayoutState; +class nsTempleLayout; +class nsObeliskLayout; +class nsMonumentLayout; +class nsBoxLayoutState; +class nsIPresShell; + +class nsBoxSizeList +{ +public: + virtual nsBoxSize GetBoxSize(nsBoxLayoutState& aState)=0; + virtual nsBoxSizeList* GetFirst()=0; + virtual nsBoxSizeList* GetLast()=0; + virtual nsBoxSizeList* GetNext()=0; + virtual nsBoxSizeList* GetParent()=0; + virtual nsBoxSizeList* GetAt(PRInt32 aIndex)=0; + virtual void SetParent(nsBoxSizeList* aParent)=0; + virtual void SetNext(nsBoxLayoutState& aState, nsBoxSizeList* aNext)=0; + virtual void Append(nsBoxLayoutState& aState, nsBoxSizeList* aChild)=0; + virtual void Clear(nsBoxLayoutState& aState)=0; + virtual PRInt32 GetCount()=0; + virtual void Desecrate()=0; + virtual void AddRef()=0; + virtual void Release(nsBoxLayoutState& aState)=0; + virtual PRBool IsSet()=0; + virtual nsIBox* GetBox()=0; + virtual PRInt32 GetRefCount()=0; +}; + +// {AF0C1603-06C3-11d4-BA07-001083023C1E} +#define NS_IMONUMENT_IID { 0xaf0c1603, 0x6c3, 0x11d4, { 0xba, 0x7, 0x0, 0x10, 0x83, 0x2, 0x3c, 0x1e } }; + +class nsIMonument : public nsISupports { + +public: + + static const nsIID& GetIID() { static nsIID iid = NS_IBOX_LAYOUT_IID; return iid; } + + NS_IMETHOD CastToTemple(nsTempleLayout** aTemple)=0; + NS_IMETHOD CastToObelisk(nsObeliskLayout** aObelisk)=0; + NS_IMETHOD GetOtherMonuments(nsIBox* aBox, nsBoxSizeList** aList)=0; + NS_IMETHOD GetOtherMonumentsAt(nsIBox* aBox, PRInt32 aIndexOfObelisk, nsBoxSizeList** aList, nsMonumentLayout* aRequestor = nsnull)=0; + NS_IMETHOD GetOtherTemple(nsIBox* aBox, nsTempleLayout** aTemple, nsIBox** aTempleBox, nsMonumentLayout* aRequestor = nsnull)=0; + NS_IMETHOD GetMonumentsAt(nsIBox* aBox, PRInt32 aMonumentIndex, nsBoxSizeList** aList)=0; + //NS_IMETHOD CountMonuments(PRInt32& aCount)=0; + NS_IMETHOD BuildBoxSizeList(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSize** aFirst, nsBoxSize** aLast)=0; + NS_IMETHOD GetParentMonument(nsIBox* aBox, nsIMonument** aMonument)=0; + NS_IMETHOD GetMonumentList(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSizeList** aList)=0; + +}; + +#endif + diff --git a/layout/xul/base/src/nsMonumentLayout.cpp b/layout/xul/base/src/nsMonumentLayout.cpp new file mode 100644 index 000000000000..880e4bea111f --- /dev/null +++ b/layout/xul/base/src/nsMonumentLayout.cpp @@ -0,0 +1,370 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +// +// Eric Vaughan +// Netscape Communications +// +// See documentation in associated header file +// + +#include "nsMonumentLayout.h" +#include "nsBoxLayoutState.h" +#include "nsIBox.h" +#include "nsBox.h" + +//------ nsInfoListNodeImpl ---- + +void +nsBoxSizeListNodeImpl::Release(nsBoxLayoutState& aState) +{ + mRefCount--; + if (mRefCount == 0) { + Clear(aState); + delete this; + } +} + +void +nsBoxSizeListNodeImpl::Desecrate() +{ + if (mParent) + mParent->Desecrate(); +} + +void nsBoxSizeListNodeImpl::SetNext(nsBoxLayoutState& aState, nsBoxSizeList* aNext) +{ + if (mNext) { + mNext->Release(aState); + } + + mNext = aNext; + aNext->AddRef(); +} + +void +nsBoxSizeListNodeImpl::Append(nsBoxLayoutState& aState, nsBoxSizeList* aChild) +{ + NS_ERROR("Attept at append to a leaf"); +} + +nsBoxSizeListNodeImpl::nsBoxSizeListNodeImpl(nsIBox* aBox):mNext(nsnull), + mParent(nsnull), + mRefCount(1), + mBox(aBox), + mIsSet(PR_FALSE) +{ +} + + +nsBoxSizeList* +nsBoxSizeListNodeImpl::GetAt(PRInt32 aIndex) +{ + nsBoxSizeList* node = this; + PRInt32 count = 0; + while(node) + { + if (count == aIndex) + return node; + + node = node->GetNext(); + count++; + } + + return nsnull; +} + + +//------ nsInfoListImpl2 ---- + +nsBoxSizeListImpl::nsBoxSizeListImpl(nsIBox* aBox):nsBoxSizeListNodeImpl(aBox),mFirst(nsnull),mLast(nsnull),mCount(0) +{ +} + +void +nsBoxSizeListImpl::Clear(nsBoxLayoutState& aState) +{ + nsBoxSizeList* list = mFirst; + while(list) + { + list->Release(aState); + list = list->GetNext(); + } + + mFirst = nsnull; + mLast = nsnull; +} + +void +nsBoxSizeListImpl::Append(nsBoxLayoutState& aState, nsBoxSizeList* aChild) +{ + if (!mFirst) + mFirst = aChild; + else + mLast->SetNext(aState, aChild); + + mLast = aChild; + aChild->SetParent(this); + aChild->AddRef(); +} + +void +nsBoxSizeListImpl::Desecrate() +{ + if (mIsSet) { + mIsSet = PR_FALSE; + nsBoxSizeListNodeImpl::Desecrate(); + } +} + +nsBoxSize +nsBoxSizeListImpl::GetBoxSize(nsBoxLayoutState& aState) +{ + if (!mIsSet) { + + mIsSet = PR_TRUE; + + mBoxSize.Clear(); + + nsBoxSizeList* node = mFirst; + + PRBool isHorizontal = PR_FALSE; + mBox->GetOrientation(isHorizontal); + + while(node) { + nsIBox* box = node->GetBox(); + + nsSize pref(0,0); + nsSize min(0,0); + nsSize max(NS_INTRINSICSIZE,NS_INTRINSICSIZE); + nscoord ascent = 0; + nscoord flex = 0; + + box->GetPrefSize(aState, pref); + box->GetMinSize(aState, min); + box->GetMaxSize(aState, max); + box->GetAscent(aState, ascent); + box->GetFlex(aState, flex); + mBoxSize.Add(min, pref, max, ascent, flex, !isHorizontal); + + node = node->GetNext(); + } + } + + return mBoxSize; +} + +// ------ nsMonumentLayout ------ + +nsMonumentLayout::nsMonumentLayout(nsIPresShell* aPresShell):nsSprocketLayout() +{ +} + +/* +PRBool +nsMonumentLayout::GetInitialOrientation(PRBool& aIsHorizontal) +{ + aIsHorizontal = (mState & NS_STATE_IS_HORIZONTAL); + return PR_TRUE; +} +*/ + +NS_IMETHODIMP +nsMonumentLayout::CastToTemple(nsTempleLayout** aTemple) +{ + *aTemple = nsnull; + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsMonumentLayout::CastToObelisk(nsObeliskLayout** aObelisk) +{ + *aObelisk = nsnull; + return NS_ERROR_FAILURE; +} + +/* +void +nsMonumentLayout::SetHorizontal(PRBool aIsHorizontal) +{ + if (aIsHorizontal) + mState |= NS_STATE_IS_HORIZONTAL; + else + mState &= ~NS_STATE_IS_HORIZONTAL; +} +*/ + +NS_IMETHODIMP +nsMonumentLayout::GetParentMonument(nsIBox* aBox, nsIMonument** aMonument) +{ + // go up and find our parent monument. Skip and non monument + // parents. + nsIBoxLayout* parent = this; + *aMonument = nsnull; + while (parent) { + GetParentLayout(aBox, &parent); + + if (parent && NS_SUCCEEDED(parent->QueryInterface(NS_GET_IID(nsIMonument), (void**)aMonument)) && *aMonument) + return NS_OK; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsMonumentLayout::GetOtherMonuments(nsIBox* aBox, nsBoxSizeList** aList) +{ + nsIMonument* parent; + GetParentMonument(aBox, &parent); + return parent->GetOtherMonumentsAt(aBox, 0, aList, this); +} + +/** + * Get the monuments in the other temple at the give monument index + */ +NS_IMETHODIMP +nsMonumentLayout::GetOtherMonumentsAt(nsIBox* aBox, PRInt32 aIndexOfObelisk, nsBoxSizeList** aList, nsMonumentLayout* aRequestor) +{ + PRInt32 index = 0; + nsIBox* child = nsnull; + aBox->GetChildBox(&child); + PRInt32 count = 0; + while(child) + { + nsIBoxLayout* layout = nsnull; + child->GetLayoutManager(&layout); + nsIMonument* monument = nsnull; + if (layout == aRequestor) { + index = count; + break; + } + + child->GetNextBox(&child); + count++; + } + + NS_ASSERTION(index != -1,"Error can't find requestor!!"); + aIndexOfObelisk += index; + + nsIMonument* parent; + GetParentMonument(aBox, &parent); + + parent->GetOtherMonumentsAt(aBox, aIndexOfObelisk, aList, this); + return NS_OK; +} + +NS_IMETHODIMP +nsMonumentLayout::GetOtherTemple(nsIBox* aBox, nsTempleLayout** aTemple, nsIBox** aTempleBox, nsMonumentLayout* aRequestor) +{ + nsIMonument* parent; + GetParentMonument(aBox, &parent); + parent->GetOtherTemple(aBox, aTemple, aTempleBox, this); + return NS_OK; +} + +NS_IMETHODIMP +nsMonumentLayout::GetMonumentsAt(nsIBox* aBox, PRInt32 aMonumentIndex, nsBoxSizeList** aList) +{ + // create an info list for the given column. + nsIBox* box = nsnull; + aBox->GetChildBox(&box); + PRInt32 count = 0; + while(box) { + if (count == aMonumentIndex) + { + *aList = new nsBoxSizeListNodeImpl(box); + return NS_OK; + } + box->GetNextBox(&box); + count++; + } + return NS_ERROR_FAILURE; +} + +/* +NS_IMETHODIMP +nsMonumentLayout::CountMonuments(PRInt32& aCount) +{ + aCount = 1; + return NS_OK; +} +*/ + +NS_IMETHODIMP +nsMonumentLayout::BuildBoxSizeList(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSize** aFirst, nsBoxSize** aLast) +{ + *aFirst = *aLast = new nsBoxSize(); + + nsSize pref(0,0); + nsSize min(0,0); + nsSize max(NS_INTRINSICSIZE,NS_INTRINSICSIZE); + nscoord flex = 0; + nscoord ascent = 0; + + aBox->GetPrefSize(aState, pref); + aBox->GetMinSize(aState, min); + aBox->GetMaxSize(aState, max); + aBox->GetAscent(aState, ascent); + aBox->GetFlex(aState, flex); + nsBox::BoundsCheck(min, pref, max); + nsMargin borderPadding(0,0,0,0); + aBox->GetBorderAndPadding(borderPadding); + + nsMargin margin(0,0,0,0); + aBox->GetMargin(margin); + + PRBool isHorizontal = PR_FALSE; + aBox->GetOrientation(isHorizontal); + + (*aFirst)->Add(min, pref, max, ascent, flex, isHorizontal); + (*aFirst)->Add(borderPadding,isHorizontal); + (*aFirst)->Add(margin,isHorizontal); + + return NS_OK; +} + +NS_IMETHODIMP +nsMonumentLayout::GetMonumentList(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSizeList** aList) +{ + nsIBox* child = nsnull; + aBox->GetChildBox(&child); + nsBoxSizeList* last = nsnull; + while(child) + { + nsBoxSizeList* newOne = new nsBoxSizeListNodeImpl(child); + if (*aList == nsnull) + *aList = last = newOne; + else { + last->SetNext(aState, newOne); + last = newOne; + } + } + + return NS_OK; +} + +NS_IMPL_ADDREF_INHERITED(nsMonumentLayout, nsBoxLayout); +NS_IMPL_RELEASE_INHERITED(nsMonumentLayout, nsBoxLayout); + +NS_INTERFACE_MAP_BEGIN(nsMonumentLayout) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMonument) +NS_INTERFACE_MAP_END_INHERITING(nsBoxLayout) diff --git a/layout/xul/base/src/nsObeliskLayout.cpp b/layout/xul/base/src/nsObeliskLayout.cpp new file mode 100644 index 000000000000..3c35b47f3e54 --- /dev/null +++ b/layout/xul/base/src/nsObeliskLayout.cpp @@ -0,0 +1,214 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +// +// Eric Vaughan +// Netscape Communications +// +// See documentation in associated header file +// + +#include "nsObeliskLayout.h" +#include "nsTempleLayout.h" +#include "nsBoxLayoutState.h" +#include "nsBox.h" + +nsresult +NS_NewObeliskLayout( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout) +{ + aNewLayout = new nsObeliskLayout(aPresShell); + + return NS_OK; + +} + +nsObeliskLayout::nsObeliskLayout(nsIPresShell* aPresShell):nsMonumentLayout(aPresShell), mOtherMonumentList(nsnull) +{ + mOtherMonumentList = nsnull; +} + +NS_IMETHODIMP +nsObeliskLayout::CastToObelisk(nsObeliskLayout** aObelisk) +{ + *aObelisk = this; + return NS_OK; +} + +void +nsObeliskLayout::UpdateMonuments(nsIBox* aBox, nsBoxLayoutState& aState) +{ + if (!mOtherMonumentList || mOtherMonumentList->GetRefCount() == 1) + { + if (mOtherMonumentList) { + mOtherMonumentList->Release(aState); + } + + mOtherMonumentList = nsnull; + GetOtherMonuments(aBox, &mOtherMonumentList); + } +} + +NS_IMETHODIMP +nsObeliskLayout::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize) +{ + nsresult rv = nsMonumentLayout::GetPrefSize(aBox, aState, aSize); + + UpdateMonuments(aBox, aState); + + nsBoxSizeList* node = mOtherMonumentList; + + PRBool isHorizontal = PR_FALSE; + aBox->GetOrientation(isHorizontal); + + // for each info + while(node) + { + // if the infos pref width is greater than aSize's use it. + // if the infos min width is greater than aSize's use it. + // if the infos max width is smaller than aSizes then set it. + nsBoxSize size = node->GetBoxSize(aState); + + nscoord s = size.pref; + nscoord& s2 = GET_HEIGHT(aSize, isHorizontal); + + if (s > s2) + s2 = s; + + node = node->GetNext(); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsObeliskLayout::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize) +{ + nsresult rv = nsMonumentLayout::GetMinSize(aBox, aState, aSize); + + UpdateMonuments(aBox, aState); + + nsBoxSizeList* node = mOtherMonumentList; + + PRBool isHorizontal = PR_FALSE; + aBox->GetOrientation(isHorizontal); + + // for each info + while(node) + { + // if the infos pref width is greater than aSize's use it. + // if the infos min width is greater than aSize's use it. + // if the infos max width is smaller than aSizes then set it. + nsBoxSize size = node->GetBoxSize(aState); + + nscoord s = size.min; + nscoord& s2 = GET_HEIGHT(aSize, isHorizontal); + + if (s > s2) + s2 = s; + + node = node->GetNext(); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsObeliskLayout::GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize) +{ + nsresult rv = nsMonumentLayout::GetMaxSize(aBox, aState, aSize); + + UpdateMonuments(aBox, aState); + + nsBoxSizeList* node = mOtherMonumentList; + + PRBool isHorizontal = PR_FALSE; + aBox->GetOrientation(isHorizontal); + + // for each info + while(node) + { + // if the infos pref width is greater than aSize's use it. + // if the infos min width is greater than aSize's use it. + // if the infos max width is smaller than aSizes then set it. + nsBoxSize size = node->GetBoxSize(aState); + + nscoord s = size.max; + nscoord& s2 = GET_HEIGHT(aSize, isHorizontal); + + if (s > s2) + s2 = s; + + node = node->GetNext(); + } + + return NS_OK; +} + +void +nsObeliskLayout::ChildNeedsLayout(nsIBox* aBox, nsIBoxLayout* aChild) +{ + // if one of our cells has changed size and needs reflow + // make sure we clean any cached information about it. + nsIBoxLayout* layout; + GetParentLayout(aBox, &layout); + nsTempleLayout* parent = nsnull; + nsIMonument* monument = nsnull; + + nsIBox* child = nsnull; + aBox->GetChildBox(&child); + PRInt32 count = 0; + while(child) + { + nsIBoxLayout* layout = nsnull; + child->GetLayoutManager(&layout); + if (layout && NS_SUCCEEDED(layout->QueryInterface(NS_GET_IID(nsIMonument), (void**)&monument)) && monument) + { + if (layout == aChild) { + parent->EncriptionChanged(count); + return; + } + } + child->GetNextBox(&child); + count++; + } +} + +void +nsObeliskLayout::ComputeChildSizes(nsIBox* aBox, + nsBoxLayoutState& aState, + nscoord& aGivenSize, + nsBoxSize* aBoxSizes, + nsComputedBoxSize* aComputedBoxSizes) +{ + nsTempleLayout* temple = nsnull; + nsIBox* aTempleBox = nsnull; + GetOtherTemple(aBox, &temple, &aTempleBox); + if (temple) { + // substitute our sizes for the other temples obelisk sizes. + nsBoxSize* last = nsnull; + temple->BuildBoxSizeList(aTempleBox, aState, &aBoxSizes, &last); + } + + nsSprocketLayout::ComputeChildSizes(aBox, aState, aGivenSize, aBoxSizes, aComputedBoxSizes); +} + + diff --git a/layout/xul/base/src/nsObeliskLayout.h b/layout/xul/base/src/nsObeliskLayout.h new file mode 100644 index 000000000000..7ff806c8eee5 --- /dev/null +++ b/layout/xul/base/src/nsObeliskLayout.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +/** + + Author: + Eric D Vaughan + +**/ + +#ifndef nsObeliskLayout_h___ +#define nsObeliskLayout_h___ + +#include "nsMonumentLayout.h" +#include "nsCOMPtr.h" + +class nsObeliskLayout : public nsMonumentLayout +{ +public: + + friend nsresult NS_NewObeliskLayout(nsIPresShell* aPresShell, nsCOMPtr& aNewLayout); + + NS_IMETHOD GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize); + NS_IMETHOD GetMinSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize); + NS_IMETHOD GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize); + NS_IMETHOD CastToObelisk(nsObeliskLayout** aObelisk); + +protected: + + void ChildNeedsLayout(nsIBox* aBox, nsIBoxLayout* aChild); + virtual void UpdateMonuments(nsIBox* aBox, nsBoxLayoutState& aState); + + virtual void ComputeChildSizes(nsIBox* aBox, + nsBoxLayoutState& aState, + nscoord& aGivenSize, + nsBoxSize* aBoxSizes, + nsComputedBoxSize* aComputedBoxSizes); + +nsObeliskLayout(nsIPresShell* aShell); + +private: + nsBoxSizeList* mOtherMonumentList; + +}; // class nsObeliskLayout + +#endif + diff --git a/layout/xul/base/src/nsRootBoxFrame.cpp b/layout/xul/base/src/nsRootBoxFrame.cpp index baa650f6d208..bd82794ec73f 100644 --- a/layout/xul/base/src/nsRootBoxFrame.cpp +++ b/layout/xul/base/src/nsRootBoxFrame.cpp @@ -100,8 +100,6 @@ public: NS_IMETHOD GetFrameName(nsString& aResult) const; NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; #endif - - }; //---------------------------------------------------------------------- @@ -118,13 +116,16 @@ NS_NewRootBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) return NS_ERROR_OUT_OF_MEMORY; } - it->SetLayoutManager(new nsStackLayout(aPresShell)); *aNewFrame = it; + return NS_OK; } nsRootBoxFrame::nsRootBoxFrame(nsIPresShell* aShell):nsBoxFrame(aShell, PR_TRUE) { + nsCOMPtr layout; + NS_NewStackLayout(aShell, layout); + SetLayoutManager(layout); } NS_IMETHODIMP diff --git a/layout/xul/base/src/nsSpringFrame.cpp b/layout/xul/base/src/nsSpringFrame.cpp index f021f44d870d..b84aeb2c2baa 100644 --- a/layout/xul/base/src/nsSpringFrame.cpp +++ b/layout/xul/base/src/nsSpringFrame.cpp @@ -54,6 +54,7 @@ NS_IMETHODIMP nsSpringFrame::GetFrameForPoint(nsIPresContext* aPresContext, if (!mRect.Contains(aPoint)) return NS_ERROR_FAILURE; + /* // see if it is in our border, padding, or inset nsRect r(mRect); nsMargin m; @@ -62,9 +63,12 @@ NS_IMETHODIMP nsSpringFrame::GetFrameForPoint(nsIPresContext* aPresContext, GetBorderAndPadding(m); r.Deflate(m); if (!r.Contains(aPoint)) { + */ *aFrame = this; + /* return NS_OK; } + */ - return NS_ERROR_FAILURE; + return NS_OK; } diff --git a/layout/xul/base/src/nsSprocketLayout.cpp b/layout/xul/base/src/nsSprocketLayout.cpp index ec665d597767..21900d05d3ce 100644 --- a/layout/xul/base/src/nsSprocketLayout.cpp +++ b/layout/xul/base/src/nsSprocketLayout.cpp @@ -44,6 +44,8 @@ #include "nsXULAtoms.h" #include "nsBoxFrame.h" +nsCOMPtr nsSprocketLayout::gInstance = new nsSprocketLayout(); + class nsBoxSizeSpecial : public nsBoxSize { public: @@ -62,7 +64,16 @@ public: #define DEBUG_BORDER_SIZE 2 #define COIL_SIZE 8 -nsSprocketLayout::nsSprocketLayout(nsIPresShell* aShell) + +nsresult +NS_NewSprocketLayout( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout) +{ + // we have not instance variables so just return our static one. + aNewLayout = nsSprocketLayout::gInstance; + return NS_OK; +} + +nsSprocketLayout::nsSprocketLayout() { } diff --git a/layout/xul/base/src/nsSprocketLayout.h b/layout/xul/base/src/nsSprocketLayout.h index a30d91d4a644..46eb340c127b 100644 --- a/layout/xul/base/src/nsSprocketLayout.h +++ b/layout/xul/base/src/nsSprocketLayout.h @@ -27,6 +27,7 @@ #define nsSprocketLayout_h___ #include "nsBoxLayout.h" +#include "nsCOMPtr.h" class nsBoxSize { @@ -87,6 +88,7 @@ class nsSprocketLayout : public nsBoxLayout { public: + friend nsresult NS_NewSprocketLayout(nsIPresShell* aPresShell, nsCOMPtr& aNewLayout); NS_IMETHOD Layout(nsIBox* aBox, nsBoxLayoutState& aState); @@ -97,7 +99,7 @@ public: NS_IMETHOD GetAscent(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nscoord& aAscent); NS_IMETHOD IsCollapsed(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, PRBool& aCollapsed); - nsSprocketLayout(nsIPresShell* aShell); + nsSprocketLayout(); protected: @@ -148,6 +150,10 @@ protected: virtual void GetFrameState(nsIBox* aBox, nsFrameState& aState); virtual void SetFrameState(nsIBox* aBox, nsFrameState aState); + // because the sprocket layout manager has no instance variables. We + // can make a static on and reuse it everywhere. + static nsCOMPtr gInstance; + }; #endif diff --git a/layout/xul/base/src/nsStackFrame.cpp b/layout/xul/base/src/nsStackFrame.cpp index 8bdb7716e2c6..c187b2cfaab7 100644 --- a/layout/xul/base/src/nsStackFrame.cpp +++ b/layout/xul/base/src/nsStackFrame.cpp @@ -47,29 +47,34 @@ #include "nsStackLayout.h" nsresult -NS_NewStackFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ) +NS_NewStackFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayoutManager) { NS_PRECONDITION(aNewFrame, "null OUT ptr"); if (nsnull == aNewFrame) { return NS_ERROR_NULL_POINTER; } - nsStackFrame* it = new (aPresShell) nsStackFrame(aPresShell); + nsStackFrame* it = new (aPresShell) nsStackFrame(aPresShell, aLayoutManager); if (nsnull == it) return NS_ERROR_OUT_OF_MEMORY; *aNewFrame = it; + return NS_OK; } // NS_NewStackFrame nsCOMPtr nsStackFrame::gLayout = nsnull; -nsStackFrame::nsStackFrame(nsIPresShell* aPresShell):nsBoxFrame(aPresShell) +nsStackFrame::nsStackFrame(nsIPresShell* aPresShell, nsIBoxLayout* aLayoutManager):nsBoxFrame(aPresShell) { - if (!gLayout) - gLayout = new nsStackLayout(aPresShell); + // if no layout manager specified us the stack layout + nsCOMPtr layout = aLayoutManager; - SetLayoutManager(gLayout); + if (layout == nsnull) { + NS_NewStackLayout(aPresShell, layout); + } + + SetLayoutManager(layout); } diff --git a/layout/xul/base/src/nsStackFrame.h b/layout/xul/base/src/nsStackFrame.h index 68c3e3cf6e5e..efee8e6f89e2 100644 --- a/layout/xul/base/src/nsStackFrame.h +++ b/layout/xul/base/src/nsStackFrame.h @@ -37,7 +37,7 @@ class nsStackFrame : public nsBoxFrame { public: - friend nsresult NS_NewStackFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame); + friend nsresult NS_NewStackFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, nsIBoxLayout* aLayout = nsnull); NS_IMETHOD GetFrameName(nsString& aResult) const { @@ -68,6 +68,9 @@ private: const nsRect& aRect, const nsPoint& aPoint, nsIFrame** aFrame); + + nsStackFrame(nsIPresShell* aPresShell, nsIBoxLayout* aLayout = nsnull); + protected: nsStackFrame(nsIPresShell* aPresShell); diff --git a/layout/xul/base/src/nsStackLayout.cpp b/layout/xul/base/src/nsStackLayout.cpp index 9c129e54317a..375a5febf652 100644 --- a/layout/xul/base/src/nsStackLayout.cpp +++ b/layout/xul/base/src/nsStackLayout.cpp @@ -46,7 +46,17 @@ #include "nsBoxLayoutState.h" #include "nsIBox.h" -nsStackLayout::nsStackLayout(nsIPresShell* aPresShell) +nsCOMPtr nsStackLayout::gInstance = new nsStackLayout(); + +nsresult +NS_NewStackLayout( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout) +{ + // we have not instance variables so just return our static one. + aNewLayout = nsStackLayout::gInstance; + return NS_OK; +} + +nsStackLayout::nsStackLayout() { } diff --git a/layout/xul/base/src/nsStackLayout.h b/layout/xul/base/src/nsStackLayout.h index 0ecaf28d8111..061987142359 100644 --- a/layout/xul/base/src/nsStackLayout.h +++ b/layout/xul/base/src/nsStackLayout.h @@ -32,12 +32,15 @@ #define nsStackLayout_h___ #include "nsBoxLayout.h" +#include "nsCOMPtr.h" class nsStackLayout : public nsBoxLayout { public: - nsStackLayout(nsIPresShell* aShell); + friend nsresult NS_NewStackLayout(nsIPresShell* aPresShell, nsCOMPtr& aNewLayout); + + nsStackLayout(); NS_IMETHOD Layout(nsIBox* aBox, nsBoxLayoutState& aState); @@ -45,6 +48,10 @@ public: NS_IMETHOD GetMinSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize); NS_IMETHOD GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize); NS_IMETHOD GetAscent(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nscoord& aAscent); + +private: + static nsCOMPtr gInstance; + }; // class nsStackLayout diff --git a/layout/xul/base/src/nsTabFrame.cpp b/layout/xul/base/src/nsTabFrame.cpp index 0b9c4d13e08d..4163fa95dcb3 100644 --- a/layout/xul/base/src/nsTabFrame.cpp +++ b/layout/xul/base/src/nsTabFrame.cpp @@ -155,17 +155,21 @@ nsTabFrame::GetChildWithTag(nsIAtom* atom, nsCOMPtr start, nsCOMPtr< nsresult nsTabFrame::GetTabControl(nsCOMPtr content, nsCOMPtr& tabcontrol) { - while(nsnull != content) - { - content->GetParent(*getter_AddRefs(content)); + nsCOMPtr parent; - if (content) { + while(content != nsnull) + { + content->GetParent(*getter_AddRefs(parent)); + + if (parent) { nsCOMPtr atom; - if (content->GetTag(*getter_AddRefs(atom)) == NS_OK && atom.get() == nsXULAtoms::tabcontrol) { - tabcontrol = content; + if (parent->GetTag(*getter_AddRefs(atom)) == NS_OK && atom.get() == nsXULAtoms::tabcontrol) { + tabcontrol = parent; return NS_OK; } } + + content = parent; } tabcontrol = nsnull; diff --git a/layout/xul/base/src/nsTempleLayout.cpp b/layout/xul/base/src/nsTempleLayout.cpp new file mode 100644 index 000000000000..b3aa67d7b03d --- /dev/null +++ b/layout/xul/base/src/nsTempleLayout.cpp @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +// +// Eric Vaughan +// Netscape Communications +// +// See documentation in associated header file +// + +#include "nsTempleLayout.h" +#include "nsIBox.h" +#include "nsCOMPtr.h" + +nsresult +NS_NewTempleLayout( nsIPresShell* aPresShell, nsCOMPtr& aNewLayout) +{ + aNewLayout = new nsTempleLayout(aPresShell); + + return NS_OK; + +} + +nsTempleLayout::nsTempleLayout(nsIPresShell* aPresShell):nsMonumentLayout(aPresShell), mMonuments(nsnull) +{ +} + +NS_IMETHODIMP +nsTempleLayout::CastToTemple(nsTempleLayout** aTemple) +{ + *aTemple = this; + return NS_OK; +} + +void +nsTempleLayout::EncriptionChanged(PRInt32 aIndex) +{ + // if a cell changes size. + if (mMonuments) { + nsBoxSizeList* size = mMonuments->GetAt(aIndex); + if (size) + size->Desecrate(); + } +} + +NS_IMETHODIMP +nsTempleLayout::GetMonumentList(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSizeList** aList) +{ + if (mMonuments) { + *aList = mMonuments; + return NS_OK; + } + + *aList = nsnull; + + // run through our children. + // ask each child for its monument list + // append the list to our list + nsIBox* box = nsnull; + aBox->GetChildBox(&box); + nsBoxSizeList* current = nsnull; + + while(box) { + + nsIMonument* monument = nsnull; + if (NS_SUCCEEDED(box->QueryInterface(NS_GET_IID(nsIMonument), (void**)&monument)) && monument) + { + if (!mMonuments) { + mMonuments = new nsBoxSizeListImpl(box); + } + + current = mMonuments; + nsBoxSizeList* node = nsnull; + monument->GetMonumentList(aBox, aState, &node); + + while(node) + { + current->Append(aState, node); + if (!current->GetNext()) { + nsBoxSizeList* newOne = new nsBoxSizeListImpl(box); + current->SetNext(aState, newOne); + current = newOne; + } else { + current = current->GetNext(); + } + + node = node->GetNext(); + } + + box->GetNextBox(&box); + } + } + + *aList = mMonuments; + return NS_OK; +} + +NS_IMETHODIMP +nsTempleLayout::BuildBoxSizeList(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSize** aFirst, nsBoxSize** aLast) +{ + nsIBox* box = nsnull; + aBox->GetChildBox(&box); + + aFirst = nsnull; + aLast = nsnull; + + nsBoxSize* first; + nsBoxSize* last; + PRInt32 count = 0; + while(box) { + nsIMonument* monument = nsnull; + if (NS_SUCCEEDED(box->QueryInterface(NS_GET_IID(nsIMonument), (void**)&monument)) && monument) + { + monument->BuildBoxSizeList(box, aState, &first, &last); + if (count == 0) + *aFirst = first; + else + (*aLast)->next = first; + + *aLast = last; + } + box->GetNextBox(&box); + count++; + } + + nsMargin borderPadding(0,0,0,0); + aBox->GetBorderAndPadding(borderPadding); + nsMargin margin(0,0,0,0); + aBox->GetMargin(margin); + + nsMargin leftMargin(borderPadding.left + margin.left, borderPadding.top + margin.top, 0, 0); + nsMargin rightMargin(0,0, borderPadding.right + margin.right, borderPadding.bottom + margin.bottom); + + PRBool isHorizontal = PR_FALSE; + aBox->GetOrientation(isHorizontal); + + (*aFirst)->Add(leftMargin,isHorizontal); + (*aLast)->Add(rightMargin,isHorizontal); + + return NS_OK; +} + +/* +void +nsTempleLayout::DesecrateMonuments(nsBoxLayoutState& aState) +{ + mMonuments->Clear(aState); + delete mMonuments; + mMonuments = nsnull; +} + +NS_IMETHODIMP +nsTempleLayout::ChildrenAddedOrRemoved() +{ + DesecrateMonuments(aPresContext); + return nsMonumentLayout::ChildrenAddedOrRemoved(); +} +*/ diff --git a/layout/xul/base/src/nsTempleLayout.h b/layout/xul/base/src/nsTempleLayout.h new file mode 100644 index 000000000000..1aea43002793 --- /dev/null +++ b/layout/xul/base/src/nsTempleLayout.h @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +/** + + Author: + Eric D Vaughan + +**/ + +#ifndef nsTempleLayout_h___ +#define nsTempleLayout_h___ + +#include "nsMonumentLayout.h" + +class nsTempleLayout : public nsMonumentLayout +{ +public: + + friend nsresult NS_NewTempleLayout(nsIPresShell* aPresShell, nsCOMPtr& aNewLayout); + + //NS_IMETHOD GetMonumentsAt(nsIBox* aBox, PRInt32 aMonumentIndex, nsBoxSizeList** aList); + //NS_IMETHOD CountMonuments(PRInt32& aCount); + NS_IMETHOD CastToTemple(nsTempleLayout** aTemple); + NS_IMETHOD BuildBoxSizeList(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSize** aFirst, nsBoxSize** aLast); + NS_IMETHOD GetMonumentList(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSizeList** aList); + + virtual void EncriptionChanged(PRInt32 aIndex); + +protected: + + nsTempleLayout(nsIPresShell* aShell); + +private: + nsBoxSizeList* mMonuments; +}; + +#endif +