From c820f47543dcb7946c9e3bd8fb6b89b6904c0f8a Mon Sep 17 00:00:00 2001 From: "roc+%cs.cmu.edu" Date: Sun, 18 Jul 2004 12:02:53 +0000 Subject: [PATCH] Bug 251501. Refactor handling where frames get inserted on content insertion. r+sr=dbaron git-svn-id: svn://10.0.0.236/trunk@159417 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsCSSFrameConstructor.cpp | 55 +------------------ mozilla/layout/base/public/nsIFrame.h | 5 ++ .../layout/forms/nsComboboxControlFrame.cpp | 4 ++ mozilla/layout/forms/nsComboboxControlFrame.h | 2 + mozilla/layout/forms/nsListControlFrame.cpp | 6 ++ mozilla/layout/forms/nsListControlFrame.h | 2 + mozilla/layout/generic/nsGfxScrollFrame.cpp | 12 ++-- mozilla/layout/generic/nsGfxScrollFrame.h | 16 ++++++ mozilla/layout/generic/nsIFrame.h | 5 ++ .../layout/html/base/src/nsGfxScrollFrame.cpp | 12 ++-- .../layout/html/base/src/nsGfxScrollFrame.h | 16 ++++++ .../html/forms/src/nsComboboxControlFrame.cpp | 4 ++ .../html/forms/src/nsComboboxControlFrame.h | 2 + .../html/forms/src/nsListControlFrame.cpp | 6 ++ .../html/forms/src/nsListControlFrame.h | 2 + .../html/style/src/nsCSSFrameConstructor.cpp | 55 +------------------ .../layout/html/table/src/nsTableCellFrame.h | 4 ++ .../layout/html/table/src/nsTableOuterFrame.h | 4 ++ mozilla/layout/tables/nsTableCellFrame.h | 4 ++ mozilla/layout/tables/nsTableOuterFrame.h | 4 ++ 20 files changed, 100 insertions(+), 120 deletions(-) diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index b61a07df7b0..bc97854bf06 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -7364,59 +7364,10 @@ nsCSSFrameConstructor::GetFrameFor(nsIPresShell* aPresShell, nsIFrame* frame; aPresShell->GetPrimaryFrameFor(aContent, &frame); - if (nsnull != frame) { - // Check to see if the content is a select and - // then if it has a drop down (thus making it a combobox) - // The drop down is a ListControlFrame derived from a - // nsHTMLScrollFrame then get the area frame and that will be the parent - // What is unclear here, is if any of this fails, should it return - // the nsComboboxControlFrame or null? - nsCOMPtr selectElement; - nsresult res = aContent->QueryInterface(NS_GET_IID(nsIDOMHTMLSelectElement), - (void**)getter_AddRefs(selectElement)); - if (NS_SUCCEEDED(res) && selectElement) { - nsIComboboxControlFrame * comboboxFrame; - res = frame->QueryInterface(NS_GET_IID(nsIComboboxControlFrame), - (void**)&comboboxFrame); - nsIFrame * listFrame; - if (NS_SUCCEEDED(res) && comboboxFrame) { - comboboxFrame->GetDropDown(&listFrame); - } else { - listFrame = frame; - } + if (!frame) + return nsnull; - if (listFrame != nsnull) { - nsIListControlFrame * list; - res = listFrame->QueryInterface(NS_GET_IID(nsIListControlFrame), - (void**)&list); - if (NS_SUCCEEDED(res) && list) { - list->GetOptionsContainer(aPresContext, &frame); - } - } - } else { - // If the primary frame is a scroll frame, then get the scrolled frame. - // That's the frame that gets the reflow command - const nsStyleDisplay* display = frame->GetStyleDisplay(); - - // If the primary frame supports IScrollableFrame, then get the scrolled frame. - // That's the frame that gets the reflow command - nsIScrollableFrame *pScrollableFrame = nsnull; - if (NS_SUCCEEDED( frame->QueryInterface(NS_GET_IID(nsIScrollableFrame), - (void **)&pScrollableFrame) )) - { - pScrollableFrame->GetScrolledFrame( aPresContext, frame ); - } - - // if we get an outer table frame use its 1st child which is a table inner frame - // if we get a table cell frame use its 1st child which is an area frame - else if ((NS_STYLE_DISPLAY_TABLE == display->mDisplay) || - (NS_STYLE_DISPLAY_TABLE_CELL == display->mDisplay)) { - frame = frame->GetFirstChild(nsnull); - } - } - } - - return frame; + return frame->GetContentInsertionFrame(); } nsIFrame* diff --git a/mozilla/layout/base/public/nsIFrame.h b/mozilla/layout/base/public/nsIFrame.h index bba9a79a33f..5c66d546816 100644 --- a/mozilla/layout/base/public/nsIFrame.h +++ b/mozilla/layout/base/public/nsIFrame.h @@ -549,6 +549,11 @@ public: */ nsIContent* GetContent() const { return mContent; } + /** + * Get the frame that should be the parent for the frames of child elements + */ + virtual nsIFrame* GetContentInsertionFrame() { return this; } + /** * Get the offsets of the frame. most will be 0,0 * diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 29cbb0a7beb..340cae42854 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -1962,6 +1962,10 @@ nsComboboxControlFrame::GetProperty(nsIAtom* aName, nsAString& aValue) return result; } +nsIFrame* +nsComboboxControlFrame::GetContentInsertionFrame() { + return mDropdownFrame->GetContentInsertionFrame(); +} NS_IMETHODIMP nsComboboxControlFrame::CreateDisplayFrame(nsIPresContext* aPresContext) diff --git a/mozilla/layout/forms/nsComboboxControlFrame.h b/mozilla/layout/forms/nsComboboxControlFrame.h index 6aceb016dbc..a2f16d6e98a 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.h +++ b/mozilla/layout/forms/nsComboboxControlFrame.h @@ -138,6 +138,8 @@ public: NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext, const nsPoint& aPoint, nsFramePaintLayer aWhichLayer, nsIFrame** aFrame); + virtual nsIFrame* GetContentInsertionFrame(); + // nsIFormControlFrame NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight); NS_IMETHOD GetName(nsAString* aName); diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index da83f5cc192..40491c72ee6 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -1441,6 +1441,12 @@ nsListControlFrame::IsOptionElement(nsIContent* aContent) return result; } +nsIFrame* +nsListControlFrame::GetContentInsertionFrame() { + nsIFrame* frame; + GetOptionsContainer(GetPresContext(), &frame); + return frame->GetContentInsertionFrame(); +} //--------------------------------------------------------- // Starts at the passed in content object and walks up the diff --git a/mozilla/layout/forms/nsListControlFrame.h b/mozilla/layout/forms/nsListControlFrame.h index fb0fd9237c7..d370f521bd3 100644 --- a/mozilla/layout/forms/nsListControlFrame.h +++ b/mozilla/layout/forms/nsListControlFrame.h @@ -119,6 +119,8 @@ public: nsFramePaintLayer aWhichLayer, PRUint32 aFlags = 0); + virtual nsIFrame* GetContentInsertionFrame(); + /** * Get the "type" of the frame * diff --git a/mozilla/layout/generic/nsGfxScrollFrame.cpp b/mozilla/layout/generic/nsGfxScrollFrame.cpp index 952612f8584..c4e2f49fda3 100644 --- a/mozilla/layout/generic/nsGfxScrollFrame.cpp +++ b/mozilla/layout/generic/nsGfxScrollFrame.cpp @@ -102,10 +102,8 @@ nsHTMLScrollFrame::nsHTMLScrollFrame(nsIPresShell* aShell, PRBool aIsRoot) NS_IMETHODIMP nsHTMLScrollFrame::GetScrolledFrame(nsIPresContext* aPresContext, nsIFrame *&aScrolledFrame) const { - nsIBox* child = nsnull; - mInner.mScrollAreaBox->GetChildBox(&child); - child->GetFrame(&aScrolledFrame); - return NS_OK; + aScrolledFrame = mInner.GetScrolledFrame(); + return NS_OK; } NS_IMETHODIMP @@ -644,10 +642,8 @@ nsXULScrollFrame::nsXULScrollFrame(nsIPresShell* aShell, PRBool aIsRoot) NS_IMETHODIMP nsXULScrollFrame::GetScrolledFrame(nsIPresContext* aPresContext, nsIFrame *&aScrolledFrame) const { - nsIBox* child = nsnull; - mInner.mScrollAreaBox->GetChildBox(&child); - child->GetFrame(&aScrolledFrame); - return NS_OK; + aScrolledFrame = mInner.GetScrolledFrame(); + return NS_OK; } NS_IMETHODIMP diff --git a/mozilla/layout/generic/nsGfxScrollFrame.h b/mozilla/layout/generic/nsGfxScrollFrame.h index b7225b4c60e..fe94df56851 100644 --- a/mozilla/layout/generic/nsGfxScrollFrame.h +++ b/mozilla/layout/generic/nsGfxScrollFrame.h @@ -112,6 +112,14 @@ public: nsIScrollableView* GetScrollableView() const; + nsIFrame* GetScrolledFrame() const { + nsIBox* childBox; + nsIFrame* frame; + mScrollAreaBox->GetChildBox(&childBox); + childBox->GetFrame(&frame); + return frame; + } + void ScrollbarChanged(nsIPresContext* aPresContext, nscoord aX, nscoord aY, PRUint32 aFlags); void SetScrollbarVisibility(nsIBox* aScrollbar, PRBool aVisible); @@ -207,6 +215,10 @@ public: PRInt32& aContentOffsetEnd, PRBool& aBeginFrameContent); + virtual nsIFrame* GetContentInsertionFrame() { + return mInner.GetScrolledFrame()->GetContentInsertionFrame(); + } + // nsIAnonymousContentCreator NS_IMETHOD CreateAnonymousContent(nsIPresContext* aPresContext, nsISupportsArray& aAnonymousItems); @@ -330,6 +342,10 @@ public: PRInt32& aContentOffsetEnd, PRBool& aBeginFrameContent); + virtual nsIFrame* GetContentInsertionFrame() { + return mInner.GetScrolledFrame()->GetContentInsertionFrame(); + } + // nsIAnonymousContentCreator NS_IMETHOD CreateAnonymousContent(nsIPresContext* aPresContext, nsISupportsArray& aAnonymousItems); diff --git a/mozilla/layout/generic/nsIFrame.h b/mozilla/layout/generic/nsIFrame.h index bba9a79a33f..5c66d546816 100644 --- a/mozilla/layout/generic/nsIFrame.h +++ b/mozilla/layout/generic/nsIFrame.h @@ -549,6 +549,11 @@ public: */ nsIContent* GetContent() const { return mContent; } + /** + * Get the frame that should be the parent for the frames of child elements + */ + virtual nsIFrame* GetContentInsertionFrame() { return this; } + /** * Get the offsets of the frame. most will be 0,0 * diff --git a/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp b/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp index 952612f8584..c4e2f49fda3 100644 --- a/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp +++ b/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp @@ -102,10 +102,8 @@ nsHTMLScrollFrame::nsHTMLScrollFrame(nsIPresShell* aShell, PRBool aIsRoot) NS_IMETHODIMP nsHTMLScrollFrame::GetScrolledFrame(nsIPresContext* aPresContext, nsIFrame *&aScrolledFrame) const { - nsIBox* child = nsnull; - mInner.mScrollAreaBox->GetChildBox(&child); - child->GetFrame(&aScrolledFrame); - return NS_OK; + aScrolledFrame = mInner.GetScrolledFrame(); + return NS_OK; } NS_IMETHODIMP @@ -644,10 +642,8 @@ nsXULScrollFrame::nsXULScrollFrame(nsIPresShell* aShell, PRBool aIsRoot) NS_IMETHODIMP nsXULScrollFrame::GetScrolledFrame(nsIPresContext* aPresContext, nsIFrame *&aScrolledFrame) const { - nsIBox* child = nsnull; - mInner.mScrollAreaBox->GetChildBox(&child); - child->GetFrame(&aScrolledFrame); - return NS_OK; + aScrolledFrame = mInner.GetScrolledFrame(); + return NS_OK; } NS_IMETHODIMP diff --git a/mozilla/layout/html/base/src/nsGfxScrollFrame.h b/mozilla/layout/html/base/src/nsGfxScrollFrame.h index b7225b4c60e..fe94df56851 100644 --- a/mozilla/layout/html/base/src/nsGfxScrollFrame.h +++ b/mozilla/layout/html/base/src/nsGfxScrollFrame.h @@ -112,6 +112,14 @@ public: nsIScrollableView* GetScrollableView() const; + nsIFrame* GetScrolledFrame() const { + nsIBox* childBox; + nsIFrame* frame; + mScrollAreaBox->GetChildBox(&childBox); + childBox->GetFrame(&frame); + return frame; + } + void ScrollbarChanged(nsIPresContext* aPresContext, nscoord aX, nscoord aY, PRUint32 aFlags); void SetScrollbarVisibility(nsIBox* aScrollbar, PRBool aVisible); @@ -207,6 +215,10 @@ public: PRInt32& aContentOffsetEnd, PRBool& aBeginFrameContent); + virtual nsIFrame* GetContentInsertionFrame() { + return mInner.GetScrolledFrame()->GetContentInsertionFrame(); + } + // nsIAnonymousContentCreator NS_IMETHOD CreateAnonymousContent(nsIPresContext* aPresContext, nsISupportsArray& aAnonymousItems); @@ -330,6 +342,10 @@ public: PRInt32& aContentOffsetEnd, PRBool& aBeginFrameContent); + virtual nsIFrame* GetContentInsertionFrame() { + return mInner.GetScrolledFrame()->GetContentInsertionFrame(); + } + // nsIAnonymousContentCreator NS_IMETHOD CreateAnonymousContent(nsIPresContext* aPresContext, nsISupportsArray& aAnonymousItems); diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 29cbb0a7beb..340cae42854 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -1962,6 +1962,10 @@ nsComboboxControlFrame::GetProperty(nsIAtom* aName, nsAString& aValue) return result; } +nsIFrame* +nsComboboxControlFrame::GetContentInsertionFrame() { + return mDropdownFrame->GetContentInsertionFrame(); +} NS_IMETHODIMP nsComboboxControlFrame::CreateDisplayFrame(nsIPresContext* aPresContext) diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.h b/mozilla/layout/html/forms/src/nsComboboxControlFrame.h index 6aceb016dbc..a2f16d6e98a 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.h +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.h @@ -138,6 +138,8 @@ public: NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext, const nsPoint& aPoint, nsFramePaintLayer aWhichLayer, nsIFrame** aFrame); + virtual nsIFrame* GetContentInsertionFrame(); + // nsIFormControlFrame NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight); NS_IMETHOD GetName(nsAString* aName); diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index da83f5cc192..40491c72ee6 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -1441,6 +1441,12 @@ nsListControlFrame::IsOptionElement(nsIContent* aContent) return result; } +nsIFrame* +nsListControlFrame::GetContentInsertionFrame() { + nsIFrame* frame; + GetOptionsContainer(GetPresContext(), &frame); + return frame->GetContentInsertionFrame(); +} //--------------------------------------------------------- // Starts at the passed in content object and walks up the diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.h b/mozilla/layout/html/forms/src/nsListControlFrame.h index fb0fd9237c7..d370f521bd3 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.h +++ b/mozilla/layout/html/forms/src/nsListControlFrame.h @@ -119,6 +119,8 @@ public: nsFramePaintLayer aWhichLayer, PRUint32 aFlags = 0); + virtual nsIFrame* GetContentInsertionFrame(); + /** * Get the "type" of the frame * diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index b61a07df7b0..bc97854bf06 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -7364,59 +7364,10 @@ nsCSSFrameConstructor::GetFrameFor(nsIPresShell* aPresShell, nsIFrame* frame; aPresShell->GetPrimaryFrameFor(aContent, &frame); - if (nsnull != frame) { - // Check to see if the content is a select and - // then if it has a drop down (thus making it a combobox) - // The drop down is a ListControlFrame derived from a - // nsHTMLScrollFrame then get the area frame and that will be the parent - // What is unclear here, is if any of this fails, should it return - // the nsComboboxControlFrame or null? - nsCOMPtr selectElement; - nsresult res = aContent->QueryInterface(NS_GET_IID(nsIDOMHTMLSelectElement), - (void**)getter_AddRefs(selectElement)); - if (NS_SUCCEEDED(res) && selectElement) { - nsIComboboxControlFrame * comboboxFrame; - res = frame->QueryInterface(NS_GET_IID(nsIComboboxControlFrame), - (void**)&comboboxFrame); - nsIFrame * listFrame; - if (NS_SUCCEEDED(res) && comboboxFrame) { - comboboxFrame->GetDropDown(&listFrame); - } else { - listFrame = frame; - } + if (!frame) + return nsnull; - if (listFrame != nsnull) { - nsIListControlFrame * list; - res = listFrame->QueryInterface(NS_GET_IID(nsIListControlFrame), - (void**)&list); - if (NS_SUCCEEDED(res) && list) { - list->GetOptionsContainer(aPresContext, &frame); - } - } - } else { - // If the primary frame is a scroll frame, then get the scrolled frame. - // That's the frame that gets the reflow command - const nsStyleDisplay* display = frame->GetStyleDisplay(); - - // If the primary frame supports IScrollableFrame, then get the scrolled frame. - // That's the frame that gets the reflow command - nsIScrollableFrame *pScrollableFrame = nsnull; - if (NS_SUCCEEDED( frame->QueryInterface(NS_GET_IID(nsIScrollableFrame), - (void **)&pScrollableFrame) )) - { - pScrollableFrame->GetScrolledFrame( aPresContext, frame ); - } - - // if we get an outer table frame use its 1st child which is a table inner frame - // if we get a table cell frame use its 1st child which is an area frame - else if ((NS_STYLE_DISPLAY_TABLE == display->mDisplay) || - (NS_STYLE_DISPLAY_TABLE_CELL == display->mDisplay)) { - frame = frame->GetFirstChild(nsnull); - } - } - } - - return frame; + return frame->GetContentInsertionFrame(); } nsIFrame* diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.h b/mozilla/layout/html/table/src/nsTableCellFrame.h index 53e15b5eeee..50f3cf1dae8 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.h +++ b/mozilla/layout/html/table/src/nsTableCellFrame.h @@ -116,6 +116,10 @@ public: nsIAtom* aListName, nsIFrame* aOldFrame); + virtual nsIFrame* GetContentInsertionFrame() { + return GetFirstChild(nsnull)->GetContentInsertionFrame(); + } + virtual void NotifyPercentHeight(const nsHTMLReflowState& aReflowState); virtual PRBool NeedsToObserve(const nsHTMLReflowState& aReflowState); diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.h b/mozilla/layout/html/table/src/nsTableOuterFrame.h index 95556d9bc10..0b2ca81c911 100644 --- a/mozilla/layout/html/table/src/nsTableOuterFrame.h +++ b/mozilla/layout/html/table/src/nsTableOuterFrame.h @@ -122,6 +122,10 @@ public: nsIAtom* aListName, nsIFrame* aOldFrame); + virtual nsIFrame* GetContentInsertionFrame() { + return GetFirstChild(nsnull)->GetContentInsertionFrame(); + } + #ifdef ACCESSIBILITY NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); #endif diff --git a/mozilla/layout/tables/nsTableCellFrame.h b/mozilla/layout/tables/nsTableCellFrame.h index 53e15b5eeee..50f3cf1dae8 100644 --- a/mozilla/layout/tables/nsTableCellFrame.h +++ b/mozilla/layout/tables/nsTableCellFrame.h @@ -116,6 +116,10 @@ public: nsIAtom* aListName, nsIFrame* aOldFrame); + virtual nsIFrame* GetContentInsertionFrame() { + return GetFirstChild(nsnull)->GetContentInsertionFrame(); + } + virtual void NotifyPercentHeight(const nsHTMLReflowState& aReflowState); virtual PRBool NeedsToObserve(const nsHTMLReflowState& aReflowState); diff --git a/mozilla/layout/tables/nsTableOuterFrame.h b/mozilla/layout/tables/nsTableOuterFrame.h index 95556d9bc10..0b2ca81c911 100644 --- a/mozilla/layout/tables/nsTableOuterFrame.h +++ b/mozilla/layout/tables/nsTableOuterFrame.h @@ -122,6 +122,10 @@ public: nsIAtom* aListName, nsIFrame* aOldFrame); + virtual nsIFrame* GetContentInsertionFrame() { + return GetFirstChild(nsnull)->GetContentInsertionFrame(); + } + #ifdef ACCESSIBILITY NS_IMETHOD GetAccessible(nsIAccessible** aAccessible); #endif