From e4d98926903a2f80590c7c44b62631c83c64f26f Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Wed, 23 Aug 2000 10:38:42 +0000 Subject: [PATCH] GfxBtn now implements method CreateFrameFor so it can create the text node with the proper style context parentage. b=49740 =kmcclusk,attinasi git-svn-id: svn://10.0.0.236/trunk@76959 18797224-902f-48f8-a5cc-f745e15eee43 --- .../layout/forms/nsGfxButtonControlFrame.cpp | 48 +++++++++++++++++++ .../layout/forms/nsGfxButtonControlFrame.h | 2 +- .../forms/src/nsGfxButtonControlFrame.cpp | 48 +++++++++++++++++++ .../html/forms/src/nsGfxButtonControlFrame.h | 2 +- 4 files changed, 98 insertions(+), 2 deletions(-) diff --git a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp index 40602459002..8807df59ce0 100644 --- a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp @@ -397,6 +397,54 @@ nsGfxButtonControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, return result; } +// Create the text content used as label for the button. +// The frame will be generated by the frame constructor. +NS_IMETHODIMP +nsGfxButtonControlFrame::CreateFrameFor(nsIPresContext* aPresContext, + nsIContent * aContent, + nsIFrame** aFrame) +{ + nsIFrame * newFrame = nsnull; + nsresult rv = NS_ERROR_FAILURE; + + if (aFrame) + *aFrame = nsnull; + + nsCOMPtr content(do_QueryInterface(mTextContent)); + if (aContent == content.get()) { + nsCOMPtr shell; + aPresContext->GetShell(getter_AddRefs(shell)); + + nsIFrame * parentFrame = mFrames.FirstChild(); + nsCOMPtr styleContext; + parentFrame->GetStyleContext(getter_AddRefs(styleContext)); + + rv = NS_NewTextFrame(shell, &newFrame); + if (NS_FAILED(rv)) { return rv; } + if (!newFrame) { return NS_ERROR_NULL_POINTER; } + nsCOMPtr textStyleContext; + rv = aPresContext->ResolvePseudoStyleContextFor(content, + nsHTMLAtoms::textPseudo, + styleContext, + PR_FALSE, + getter_AddRefs(textStyleContext)); + if (NS_FAILED(rv)) { return rv; } + if (!textStyleContext) { return NS_ERROR_NULL_POINTER; } + + if (styleContext) { + // initialize the text frame + newFrame->Init(aPresContext, content, parentFrame, textStyleContext, nsnull); + newFrame->SetInitialChildList(aPresContext, nsnull, nsnull); + rv = NS_OK; + } + } + + if (aFrame) { + *aFrame = newFrame; + } + return rv; +} + NS_IMETHODIMP nsGfxButtonControlFrame::SetDocumentForAnonymousContent(nsIDocument* aDocument, PRBool aDeep, diff --git a/mozilla/layout/forms/nsGfxButtonControlFrame.h b/mozilla/layout/forms/nsGfxButtonControlFrame.h index 12531898a1b..8bec39b52be 100644 --- a/mozilla/layout/forms/nsGfxButtonControlFrame.h +++ b/mozilla/layout/forms/nsGfxButtonControlFrame.h @@ -73,7 +73,7 @@ public: PRBool aCompileEventHandlers); NS_IMETHOD CreateFrameFor(nsIPresContext* aPresContext, nsIContent * aContent, - nsIFrame** aFrame) { if (aFrame) *aFrame = nsnull; return NS_ERROR_FAILURE; } + nsIFrame** aFrame); protected: NS_IMETHOD AddComputedBorderPaddingToDesiredSize(nsHTMLReflowMetrics& aDesiredSize, diff --git a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp index 40602459002..8807df59ce0 100644 --- a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp @@ -397,6 +397,54 @@ nsGfxButtonControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, return result; } +// Create the text content used as label for the button. +// The frame will be generated by the frame constructor. +NS_IMETHODIMP +nsGfxButtonControlFrame::CreateFrameFor(nsIPresContext* aPresContext, + nsIContent * aContent, + nsIFrame** aFrame) +{ + nsIFrame * newFrame = nsnull; + nsresult rv = NS_ERROR_FAILURE; + + if (aFrame) + *aFrame = nsnull; + + nsCOMPtr content(do_QueryInterface(mTextContent)); + if (aContent == content.get()) { + nsCOMPtr shell; + aPresContext->GetShell(getter_AddRefs(shell)); + + nsIFrame * parentFrame = mFrames.FirstChild(); + nsCOMPtr styleContext; + parentFrame->GetStyleContext(getter_AddRefs(styleContext)); + + rv = NS_NewTextFrame(shell, &newFrame); + if (NS_FAILED(rv)) { return rv; } + if (!newFrame) { return NS_ERROR_NULL_POINTER; } + nsCOMPtr textStyleContext; + rv = aPresContext->ResolvePseudoStyleContextFor(content, + nsHTMLAtoms::textPseudo, + styleContext, + PR_FALSE, + getter_AddRefs(textStyleContext)); + if (NS_FAILED(rv)) { return rv; } + if (!textStyleContext) { return NS_ERROR_NULL_POINTER; } + + if (styleContext) { + // initialize the text frame + newFrame->Init(aPresContext, content, parentFrame, textStyleContext, nsnull); + newFrame->SetInitialChildList(aPresContext, nsnull, nsnull); + rv = NS_OK; + } + } + + if (aFrame) { + *aFrame = newFrame; + } + return rv; +} + NS_IMETHODIMP nsGfxButtonControlFrame::SetDocumentForAnonymousContent(nsIDocument* aDocument, PRBool aDeep, diff --git a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h index 12531898a1b..8bec39b52be 100644 --- a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.h @@ -73,7 +73,7 @@ public: PRBool aCompileEventHandlers); NS_IMETHOD CreateFrameFor(nsIPresContext* aPresContext, nsIContent * aContent, - nsIFrame** aFrame) { if (aFrame) *aFrame = nsnull; return NS_ERROR_FAILURE; } + nsIFrame** aFrame); protected: NS_IMETHOD AddComputedBorderPaddingToDesiredSize(nsHTMLReflowMetrics& aDesiredSize,