From 4f668b70817ace4ed3a45ba4e43cdc19df84d3db Mon Sep 17 00:00:00 2001 From: "kmcclusk%netscape.com" Date: Thu, 11 Feb 1999 01:13:28 +0000 Subject: [PATCH] Fixed border rendering during printing for Select and text, and text areas. Implemented SetProperty/GetProperty methods for FileControlFrame Added nsGenericHTMLElement::GetPrimaryFrame check for nsnull for doc return type. nsHTMLInputElement.cpp replace NS_OK == with NS_SUCCEEDED in GetValue and SetValue Added GetName and GetValue utility methods to nsFormControlHelper modified nsButtonControlFrame::PaintButton to take the label to paint as an extra parameter. This allows it to be callable from the nsFileControlFrame code to render the button. git-svn-id: svn://10.0.0.236/trunk@20325 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/content/src/nsGenericHTMLElement.cpp | 24 +++++----- .../html/content/src/nsHTMLInputElement.cpp | 16 ++++--- mozilla/layout/forms/nsFileControlFrame.cpp | 41 ++++++++++++++++- mozilla/layout/forms/nsFileControlFrame.h | 5 +++ mozilla/layout/forms/nsFormControlFrame.cpp | 2 + mozilla/layout/forms/nsFormControlFrame.h | 9 ++-- mozilla/layout/forms/nsFormControlHelper.cpp | 45 +++++++++++++++++++ mozilla/layout/forms/nsFormControlHelper.h | 4 +- mozilla/layout/forms/nsTextControlFrame.cpp | 44 +++++++++--------- mozilla/layout/forms/nsTextControlFrame.h | 17 +++---- .../html/content/src/nsGenericHTMLElement.cpp | 24 +++++----- .../html/content/src/nsHTMLInputElement.cpp | 16 ++++--- .../html/forms/src/nsButtonControlFrame.cpp | 11 ++--- .../html/forms/src/nsButtonControlFrame.h | 15 +++---- .../html/forms/src/nsFileControlFrame.cpp | 41 ++++++++++++++++- .../html/forms/src/nsFileControlFrame.h | 5 +++ .../html/forms/src/nsFormControlFrame.cpp | 2 + .../html/forms/src/nsFormControlFrame.h | 9 ++-- .../html/forms/src/nsFormControlHelper.cpp | 45 +++++++++++++++++++ .../html/forms/src/nsFormControlHelper.h | 4 +- .../html/forms/src/nsSelectControlFrame.cpp | 6 +-- .../html/forms/src/nsTextControlFrame.cpp | 44 +++++++++--------- .../html/forms/src/nsTextControlFrame.h | 17 +++---- 23 files changed, 317 insertions(+), 129 deletions(-) diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index d7865fe0106..b4c99a822d3 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -1415,22 +1415,24 @@ nsGenericHTMLElement::GetPrimaryFrame(nsIHTMLContent* aContent, nsIFormControlFrame *&aFormControlFrame) { nsIDocument* doc = nsnull; - nsresult res; + nsresult res = NS_OK; // Get the document if (NS_OK == aContent->GetDocument(doc)) { - // Get presentation shell 0 - nsIPresShell* presShell = doc->GetShellAt(0); - if (nsnull != presShell) { - nsIFrame *frame = nsnull; - presShell->GetPrimaryFrameFor(aContent, frame); - if (nsnull != frame) { - res = frame->QueryInterface(kIFormControlFrameIID, (void**)&aFormControlFrame); + if (nsnull != doc) { + // Get presentation shell 0 + nsIPresShell* presShell = doc->GetShellAt(0); + if (nsnull != presShell) { + nsIFrame *frame = nsnull; + presShell->GetPrimaryFrameFor(aContent, frame); + if (nsnull != frame) { + res = frame->QueryInterface(kIFormControlFrameIID, (void**)&aFormControlFrame); + } + NS_RELEASE(presShell); } - NS_RELEASE(presShell); + NS_RELEASE(doc); } - NS_RELEASE(doc); } - + return res; } diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 10db0cf9103..75ae77ed775 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -321,9 +321,11 @@ nsHTMLInputElement::GetValue(nsString& aValue) GetType(&type); if (NS_FORM_INPUT_TEXT == type || NS_FORM_INPUT_PASSWORD == type) { nsIFormControlFrame* formControlFrame = nsnull; - if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) { - formControlFrame->GetProperty(nsHTMLAtoms::value, aValue); - NS_RELEASE(formControlFrame); + if (NS_SUCCEEDED(nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame))) { + if (nsnull != formControlFrame) { + formControlFrame->GetProperty(nsHTMLAtoms::value, aValue); + NS_RELEASE(formControlFrame); + } return NS_OK; } } @@ -338,9 +340,11 @@ nsHTMLInputElement::SetValue(const nsString& aValue) GetType(&type); if (NS_FORM_INPUT_TEXT == type) { nsIFormControlFrame* formControlFrame = nsnull; - if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) { - formControlFrame->SetProperty(nsHTMLAtoms::value, aValue); - NS_RELEASE(formControlFrame); + if (NS_SUCCEEDED(nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame))) { + if (nsnull != formControlFrame ) { + formControlFrame->SetProperty(nsHTMLAtoms::value, aValue); + NS_RELEASE(formControlFrame); + } } } return NS_OK; diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index fac6fde5854..ddcec697647 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -285,6 +285,8 @@ nsFileControlFrame::GetName(nsString* aResult) return result; } + + PRInt32 nsFileControlFrame::GetMaxNumValues() { @@ -358,12 +360,49 @@ nsFileControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext, return 0; } + NS_IMETHODIMP nsFileControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) { + if (nsHTMLAtoms::value == aName) { + mTextFrame->SetTextControlFrameState(aValue); + } return NS_OK; -} +} NS_IMETHODIMP nsFileControlFrame::GetProperty(nsIAtom* aName, nsString& aValue) { + // Return the value of the property from the widget it is not null. + // If widget is null, assume the widget is GFX-rendered and return a member variable instead. + + if (nsHTMLAtoms::value == aName) { + mTextFrame->GetTextControlFrameState(aValue); + } + return NS_OK; +} + + +NS_METHOD +nsFileControlFrame::Paint(nsIPresContext& aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsFramePaintLayer aWhichLayer) +{ + // Since the file control has a mTextFrame which does not live in the content model + // it is necessary to get the current text value from the nsFileControlFrame through the + // content model, then explicitly ask the test frame to draw it. + // The mTextFrame's Paint method will still be called, but it will not render the current + // contents because it will not be possible for the content associated with the mTextFrame to + // get a handle to it frame in the presentation shell 0. + + // mTextFrame->Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); + mBrowseFrame->PaintButton(aPresContext, aRenderingContext, aDirtyRect, nsAutoString("Browse")); + if (eFramePaintLayer_Content == aWhichLayer) { + nsString text; + if (NS_SUCCEEDED(nsFormControlHelper::GetValue(mContent, &text))) { + mTextFrame->PaintTextControl(aPresContext, aRenderingContext, aDirtyRect, text, mStyleContext); + } + } + + return NS_OK; } diff --git a/mozilla/layout/forms/nsFileControlFrame.h b/mozilla/layout/forms/nsFileControlFrame.h index 9fad7f2b923..518132e3aee 100644 --- a/mozilla/layout/forms/nsFileControlFrame.h +++ b/mozilla/layout/forms/nsFileControlFrame.h @@ -31,6 +31,11 @@ class nsFileControlFrame : public nsHTMLContainerFrame, public: nsFileControlFrame(); + NS_IMETHOD Paint(nsIPresContext& aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsFramePaintLayer aWhichLayer); + // nsIFormControlFrame NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); diff --git a/mozilla/layout/forms/nsFormControlFrame.cpp b/mozilla/layout/forms/nsFormControlFrame.cpp index 97e32594fcd..a7928308415 100644 --- a/mozilla/layout/forms/nsFormControlFrame.cpp +++ b/mozilla/layout/forms/nsFormControlFrame.cpp @@ -512,6 +512,7 @@ nsFormControlFrame::GetName(nsString* aResult) return result; } + NS_IMETHODIMP nsFormControlFrame::GetValue(nsString* aResult) { @@ -533,6 +534,7 @@ nsFormControlFrame::GetValue(nsString* aResult) return result; } + PRBool nsFormControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter) { diff --git a/mozilla/layout/forms/nsFormControlFrame.h b/mozilla/layout/forms/nsFormControlFrame.h index bfa4771cf3c..d6dab78827f 100644 --- a/mozilla/layout/forms/nsFormControlFrame.h +++ b/mozilla/layout/forms/nsFormControlFrame.h @@ -195,14 +195,15 @@ public: const nsHTMLReflowState& aReflowState, nsSize& aSize); + // nsIFormControlFrame + NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); + NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); + protected: virtual ~nsFormControlFrame(); - // nsIFormControlFrame - NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); - NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); - + /** * Determine if the control uses a native widget for rendering * @param aRequiresWidget is set to PR_TRUE if it has a native widget, PR_FALSE otherwise. diff --git a/mozilla/layout/forms/nsFormControlHelper.cpp b/mozilla/layout/forms/nsFormControlHelper.cpp index 866eae3e27f..caeea426168 100644 --- a/mozilla/layout/forms/nsFormControlHelper.cpp +++ b/mozilla/layout/forms/nsFormControlHelper.cpp @@ -917,3 +917,48 @@ nsFormControlHelper::PaintCircularBorder(nsIPresContext& aPresContext, aRenderingContext.PopState(clip); } + +nsresult +nsFormControlHelper::GetName(nsIContent* aContent,nsString* aResult) +{ + nsresult result = NS_FORM_NOTOK; + if (nsnull != aContent) { + nsIHTMLContent* formControl = nsnull; + result = aContent->QueryInterface(kIHTMLContentIID, (void**)&formControl); + if ((NS_OK == result) && formControl) { + nsHTMLValue value; + result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); + if (NS_CONTENT_ATTR_HAS_VALUE == result) { + if (eHTMLUnit_String == value.GetUnit()) { + value.GetStringValue(*aResult); + } + } + NS_RELEASE(formControl); + } + } + return result; +} + + +nsresult +nsFormControlHelper::GetValue(nsIContent* aContent, nsString* aResult) +{ + nsresult result = NS_FORM_NOTOK; + if (nsnull != aContent) { + nsIHTMLContent* formControl = nsnull; + result = aContent->QueryInterface(kIHTMLContentIID, (void**)&formControl); + if ((NS_OK == result) && formControl) { + nsHTMLValue value; + result = formControl->GetHTMLAttribute(nsHTMLAtoms::value, value); + if (NS_CONTENT_ATTR_HAS_VALUE == result) { + if (eHTMLUnit_String == value.GetUnit()) { + value.GetStringValue(*aResult); + } + } + NS_RELEASE(formControl); + } + } + return result; +} + + diff --git a/mozilla/layout/forms/nsFormControlHelper.h b/mozilla/layout/forms/nsFormControlHelper.h index d5047d8bfb6..58b973ab9e2 100644 --- a/mozilla/layout/forms/nsFormControlHelper.h +++ b/mozilla/layout/forms/nsFormControlHelper.h @@ -113,7 +113,9 @@ public: static void ForceDrawFrame(nsIFrame * aFrame); - + static nsresult GetValue(nsIContent* aContent, nsString* aResult); + static nsresult GetName(nsIContent* aContent, nsString* aResult); + /** * Utility to convert a string to a PRBool * @param aValue string to convert to a PRBool diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index b1de76fccd6..e17a8c96435 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -578,15 +578,14 @@ nsTextControlFrame::GetFrameName(nsString& aResult) const void nsTextControlFrame::PaintTextControl(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect) + const nsRect& aDirtyRect, + nsString& aText, + nsIStyleContext* aStyleContext) { aRenderingContext.PushState(); - nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, - eFramePaintLayer_Content); - const nsStyleSpacing* spacing = - (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); + (const nsStyleSpacing*)aStyleContext->GetStyleData(eStyleStruct_Spacing); nsMargin border; spacing->CalcBorderFor(this, border); @@ -627,10 +626,8 @@ nsTextControlFrame::PaintTextControl(nsIPresContext& aPresContext, nscoord textWidth; nscoord textHeight; - nsString text; - - GetText(&text, PR_FALSE); - aRenderingContext.GetWidth(text, textWidth); + + aRenderingContext.GetWidth(aText, textWidth); nsIFontMetrics* metrics; context->GetMetricsFor(font, metrics); @@ -648,13 +645,13 @@ nsTextControlFrame::PaintTextControl(nsIPresContext& aPresContext, metrics->GetMaxAscent(textHeight); y = ((inside.height - textHeight) / 2) + inside.y; PRInt32 i; - PRInt32 len = text.Length(); - text.SetLength(0); + PRInt32 len = aText.Length(); + aText.SetLength(0); for (i=0;iGetStyleData(eStyleStruct_Color); + const nsStyleColor* myColor = (const nsStyleColor*)aStyleContext->GetStyleData(eStyleStruct_Color); nsIAtom * sbAtom = NS_NewAtom(":SCROLLBAR-LOOK"); - nsIStyleContext* scrollbarStyle = aPresContext.ResolvePseudoStyleContextFor(mContent, sbAtom, mStyleContext); + nsIStyleContext* scrollbarStyle = aPresContext.ResolvePseudoStyleContextFor(mContent, sbAtom, aStyleContext); NS_RELEASE(sbAtom); sbAtom = NS_NewAtom(":SCROLLBAR-ARROW-LOOK"); - nsIStyleContext* arrowStyle = aPresContext.ResolvePseudoStyleContextFor(mContent, sbAtom, mStyleContext); + nsIStyleContext* arrowStyle = aPresContext.ResolvePseudoStyleContextFor(mContent, sbAtom, aStyleContext); NS_RELEASE(sbAtom); nsRect srect(mRect.width-scrollbarScaledWidth-(2*onePixel), 2*onePixel, scrollbarScaledWidth, mRect.height-(onePixel*4)-scrollbarScaledWidth); @@ -734,8 +731,11 @@ nsTextControlFrame::Paint(nsIPresContext& aPresContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) { + nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); if (eFramePaintLayer_Content == aWhichLayer) { - PaintTextControl(aPresContext, aRenderingContext, aDirtyRect); + nsString text; + GetText(&text, PR_FALSE); + PaintTextControl(aPresContext, aRenderingContext, aDirtyRect, text, mStyleContext); } return NS_OK; } @@ -767,7 +767,7 @@ void nsTextControlFrame::SetTextControlFrameState(const nsString& aValue) nsITextWidget* text = nsnull; nsITextAreaWidget* textArea = nsnull; PRUint32 size = 0; - if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) { + if (NS_SUCCEEDED(mWidget->QueryInterface(kITextWidgetIID,(void**)&text))) { text->SetText(aValue,size); NS_RELEASE(text); } else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID, diff --git a/mozilla/layout/forms/nsTextControlFrame.h b/mozilla/layout/forms/nsTextControlFrame.h index a8fdb7ca931..62aa135b379 100644 --- a/mozilla/layout/forms/nsTextControlFrame.h +++ b/mozilla/layout/forms/nsTextControlFrame.h @@ -66,11 +66,6 @@ public: NS_IMETHOD GetCursor(nsIPresContext& aPresContext, nsPoint& aPoint, PRInt32& aCursor); - // - // XXX: The following paint methods are TEMPORARY. It is being used to get printing working - // under windows. Later it may be used to GFX-render the controls to the display. - // Expect this code to repackaged and moved to a new location in the future. - // NS_IMETHOD Paint(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, @@ -78,17 +73,17 @@ public: virtual void PaintTextControl(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); - - ///XXX: End o the temporary methods - - -protected: + const nsRect& aDirtyRect, nsString& aText, + nsIStyleContext* aStyleContext); // Utility methods to get and set current widget state void GetTextControlFrameState(nsString& aValue); void SetTextControlFrameState(const nsString& aValue); +protected: + + + virtual void GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredLayoutSize, diff --git a/mozilla/layout/html/content/src/nsGenericHTMLElement.cpp b/mozilla/layout/html/content/src/nsGenericHTMLElement.cpp index d7865fe0106..b4c99a822d3 100644 --- a/mozilla/layout/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/layout/html/content/src/nsGenericHTMLElement.cpp @@ -1415,22 +1415,24 @@ nsGenericHTMLElement::GetPrimaryFrame(nsIHTMLContent* aContent, nsIFormControlFrame *&aFormControlFrame) { nsIDocument* doc = nsnull; - nsresult res; + nsresult res = NS_OK; // Get the document if (NS_OK == aContent->GetDocument(doc)) { - // Get presentation shell 0 - nsIPresShell* presShell = doc->GetShellAt(0); - if (nsnull != presShell) { - nsIFrame *frame = nsnull; - presShell->GetPrimaryFrameFor(aContent, frame); - if (nsnull != frame) { - res = frame->QueryInterface(kIFormControlFrameIID, (void**)&aFormControlFrame); + if (nsnull != doc) { + // Get presentation shell 0 + nsIPresShell* presShell = doc->GetShellAt(0); + if (nsnull != presShell) { + nsIFrame *frame = nsnull; + presShell->GetPrimaryFrameFor(aContent, frame); + if (nsnull != frame) { + res = frame->QueryInterface(kIFormControlFrameIID, (void**)&aFormControlFrame); + } + NS_RELEASE(presShell); } - NS_RELEASE(presShell); + NS_RELEASE(doc); } - NS_RELEASE(doc); } - + return res; } diff --git a/mozilla/layout/html/content/src/nsHTMLInputElement.cpp b/mozilla/layout/html/content/src/nsHTMLInputElement.cpp index 10db0cf9103..75ae77ed775 100644 --- a/mozilla/layout/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLInputElement.cpp @@ -321,9 +321,11 @@ nsHTMLInputElement::GetValue(nsString& aValue) GetType(&type); if (NS_FORM_INPUT_TEXT == type || NS_FORM_INPUT_PASSWORD == type) { nsIFormControlFrame* formControlFrame = nsnull; - if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) { - formControlFrame->GetProperty(nsHTMLAtoms::value, aValue); - NS_RELEASE(formControlFrame); + if (NS_SUCCEEDED(nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame))) { + if (nsnull != formControlFrame) { + formControlFrame->GetProperty(nsHTMLAtoms::value, aValue); + NS_RELEASE(formControlFrame); + } return NS_OK; } } @@ -338,9 +340,11 @@ nsHTMLInputElement::SetValue(const nsString& aValue) GetType(&type); if (NS_FORM_INPUT_TEXT == type) { nsIFormControlFrame* formControlFrame = nsnull; - if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) { - formControlFrame->SetProperty(nsHTMLAtoms::value, aValue); - NS_RELEASE(formControlFrame); + if (NS_SUCCEEDED(nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame))) { + if (nsnull != formControlFrame ) { + formControlFrame->SetProperty(nsHTMLAtoms::value, aValue); + NS_RELEASE(formControlFrame); + } } } return NS_OK; diff --git a/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp index 73d19e39b34..73b64b5b7a5 100644 --- a/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp @@ -222,7 +222,9 @@ nsButtonControlFrame::Paint(nsIPresContext& aPresContext, nsFramePaintLayer aWhichLayer) { if (eFramePaintLayer_Content == aWhichLayer) { - PaintButton(aPresContext, aRenderingContext, aDirtyRect); + nsString label; + nsresult result = GetValue(&label); + PaintButton(aPresContext, aRenderingContext, aDirtyRect, label); } return NS_OK; } @@ -385,16 +387,15 @@ nsButtonControlFrame::GetFrameName(nsString& aResult) const void nsButtonControlFrame::PaintButton(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect) + const nsRect& aDirtyRect, + nsString& aLabel) { - nsString label; - nsresult result = GetValue(&label); nsFormControlHelper::PaintRectangularButton(aPresContext, aRenderingContext, aDirtyRect, mRect.width, mRect.height,PR_FALSE, PR_FALSE, - mStyleContext, label, this); + mStyleContext, aLabel, this); } diff --git a/mozilla/layout/html/forms/src/nsButtonControlFrame.h b/mozilla/layout/html/forms/src/nsButtonControlFrame.h index 09a1b506ee8..dd70de90c8e 100644 --- a/mozilla/layout/html/forms/src/nsButtonControlFrame.h +++ b/mozilla/layout/html/forms/src/nsButtonControlFrame.h @@ -77,21 +77,20 @@ public: // Sets listener for button click void SetMouseListener(nsIFormControlFrame* aListener) { mMouseListener = aListener; } + virtual void PaintButton(nsIPresContext& aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsString& aLabel); + protected: virtual void GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredLayoutSize, nsSize& aDesiredWidgetSize); - // - // XXX: The following methods are TEMPORARY. They are being used to get printing working - // under windows. Later it may be used to GFX-render the controls to the display. - // Expect this code to repackaged and moved to a new location in the future. - virtual void PaintButton(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); - // XXX: End of the temporary methods + + nsIFormControlFrame* mMouseListener; // for browse buttons only }; diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index fac6fde5854..ddcec697647 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -285,6 +285,8 @@ nsFileControlFrame::GetName(nsString* aResult) return result; } + + PRInt32 nsFileControlFrame::GetMaxNumValues() { @@ -358,12 +360,49 @@ nsFileControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext, return 0; } + NS_IMETHODIMP nsFileControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) { + if (nsHTMLAtoms::value == aName) { + mTextFrame->SetTextControlFrameState(aValue); + } return NS_OK; -} +} NS_IMETHODIMP nsFileControlFrame::GetProperty(nsIAtom* aName, nsString& aValue) { + // Return the value of the property from the widget it is not null. + // If widget is null, assume the widget is GFX-rendered and return a member variable instead. + + if (nsHTMLAtoms::value == aName) { + mTextFrame->GetTextControlFrameState(aValue); + } + return NS_OK; +} + + +NS_METHOD +nsFileControlFrame::Paint(nsIPresContext& aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsFramePaintLayer aWhichLayer) +{ + // Since the file control has a mTextFrame which does not live in the content model + // it is necessary to get the current text value from the nsFileControlFrame through the + // content model, then explicitly ask the test frame to draw it. + // The mTextFrame's Paint method will still be called, but it will not render the current + // contents because it will not be possible for the content associated with the mTextFrame to + // get a handle to it frame in the presentation shell 0. + + // mTextFrame->Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); + mBrowseFrame->PaintButton(aPresContext, aRenderingContext, aDirtyRect, nsAutoString("Browse")); + if (eFramePaintLayer_Content == aWhichLayer) { + nsString text; + if (NS_SUCCEEDED(nsFormControlHelper::GetValue(mContent, &text))) { + mTextFrame->PaintTextControl(aPresContext, aRenderingContext, aDirtyRect, text, mStyleContext); + } + } + + return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.h b/mozilla/layout/html/forms/src/nsFileControlFrame.h index 9fad7f2b923..518132e3aee 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.h +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.h @@ -31,6 +31,11 @@ class nsFileControlFrame : public nsHTMLContainerFrame, public: nsFileControlFrame(); + NS_IMETHOD Paint(nsIPresContext& aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsFramePaintLayer aWhichLayer); + // nsIFormControlFrame NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp index 97e32594fcd..a7928308415 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp @@ -512,6 +512,7 @@ nsFormControlFrame::GetName(nsString* aResult) return result; } + NS_IMETHODIMP nsFormControlFrame::GetValue(nsString* aResult) { @@ -533,6 +534,7 @@ nsFormControlFrame::GetValue(nsString* aResult) return result; } + PRBool nsFormControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter) { diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.h b/mozilla/layout/html/forms/src/nsFormControlFrame.h index bfa4771cf3c..d6dab78827f 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.h +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.h @@ -195,14 +195,15 @@ public: const nsHTMLReflowState& aReflowState, nsSize& aSize); + // nsIFormControlFrame + NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); + NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); + protected: virtual ~nsFormControlFrame(); - // nsIFormControlFrame - NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); - NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); - + /** * Determine if the control uses a native widget for rendering * @param aRequiresWidget is set to PR_TRUE if it has a native widget, PR_FALSE otherwise. diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp index 866eae3e27f..caeea426168 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp @@ -917,3 +917,48 @@ nsFormControlHelper::PaintCircularBorder(nsIPresContext& aPresContext, aRenderingContext.PopState(clip); } + +nsresult +nsFormControlHelper::GetName(nsIContent* aContent,nsString* aResult) +{ + nsresult result = NS_FORM_NOTOK; + if (nsnull != aContent) { + nsIHTMLContent* formControl = nsnull; + result = aContent->QueryInterface(kIHTMLContentIID, (void**)&formControl); + if ((NS_OK == result) && formControl) { + nsHTMLValue value; + result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); + if (NS_CONTENT_ATTR_HAS_VALUE == result) { + if (eHTMLUnit_String == value.GetUnit()) { + value.GetStringValue(*aResult); + } + } + NS_RELEASE(formControl); + } + } + return result; +} + + +nsresult +nsFormControlHelper::GetValue(nsIContent* aContent, nsString* aResult) +{ + nsresult result = NS_FORM_NOTOK; + if (nsnull != aContent) { + nsIHTMLContent* formControl = nsnull; + result = aContent->QueryInterface(kIHTMLContentIID, (void**)&formControl); + if ((NS_OK == result) && formControl) { + nsHTMLValue value; + result = formControl->GetHTMLAttribute(nsHTMLAtoms::value, value); + if (NS_CONTENT_ATTR_HAS_VALUE == result) { + if (eHTMLUnit_String == value.GetUnit()) { + value.GetStringValue(*aResult); + } + } + NS_RELEASE(formControl); + } + } + return result; +} + + diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.h b/mozilla/layout/html/forms/src/nsFormControlHelper.h index d5047d8bfb6..58b973ab9e2 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.h +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.h @@ -113,7 +113,9 @@ public: static void ForceDrawFrame(nsIFrame * aFrame); - + static nsresult GetValue(nsIContent* aContent, nsString* aResult); + static nsresult GetName(nsIContent* aContent, nsString* aResult); + /** * Utility to convert a string to a PRBool * @param aValue string to convert to a PRBool diff --git a/mozilla/layout/html/forms/src/nsSelectControlFrame.cpp b/mozilla/layout/html/forms/src/nsSelectControlFrame.cpp index 6dfac53bfb3..bb47f81877e 100644 --- a/mozilla/layout/html/forms/src/nsSelectControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsSelectControlFrame.cpp @@ -736,10 +736,6 @@ nsSelectControlFrame::PaintSelectControl(nsIPresContext& aPresContext, { aRenderingContext.PushState(); - - nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, - eFramePaintLayer_Content); - /** * Resolve style for a pseudo frame within the given aParentContent & aParentContext. * The tag should be uppercase and inclue the colon. @@ -913,6 +909,8 @@ nsSelectControlFrame::Paint(nsIPresContext& aPresContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) { + nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, + aWhichLayer); if (eFramePaintLayer_Content == aWhichLayer) { PaintSelectControl(aPresContext, aRenderingContext, aDirtyRect); } diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp index b1de76fccd6..e17a8c96435 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp @@ -578,15 +578,14 @@ nsTextControlFrame::GetFrameName(nsString& aResult) const void nsTextControlFrame::PaintTextControl(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect) + const nsRect& aDirtyRect, + nsString& aText, + nsIStyleContext* aStyleContext) { aRenderingContext.PushState(); - nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, - eFramePaintLayer_Content); - const nsStyleSpacing* spacing = - (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); + (const nsStyleSpacing*)aStyleContext->GetStyleData(eStyleStruct_Spacing); nsMargin border; spacing->CalcBorderFor(this, border); @@ -627,10 +626,8 @@ nsTextControlFrame::PaintTextControl(nsIPresContext& aPresContext, nscoord textWidth; nscoord textHeight; - nsString text; - - GetText(&text, PR_FALSE); - aRenderingContext.GetWidth(text, textWidth); + + aRenderingContext.GetWidth(aText, textWidth); nsIFontMetrics* metrics; context->GetMetricsFor(font, metrics); @@ -648,13 +645,13 @@ nsTextControlFrame::PaintTextControl(nsIPresContext& aPresContext, metrics->GetMaxAscent(textHeight); y = ((inside.height - textHeight) / 2) + inside.y; PRInt32 i; - PRInt32 len = text.Length(); - text.SetLength(0); + PRInt32 len = aText.Length(); + aText.SetLength(0); for (i=0;iGetStyleData(eStyleStruct_Color); + const nsStyleColor* myColor = (const nsStyleColor*)aStyleContext->GetStyleData(eStyleStruct_Color); nsIAtom * sbAtom = NS_NewAtom(":SCROLLBAR-LOOK"); - nsIStyleContext* scrollbarStyle = aPresContext.ResolvePseudoStyleContextFor(mContent, sbAtom, mStyleContext); + nsIStyleContext* scrollbarStyle = aPresContext.ResolvePseudoStyleContextFor(mContent, sbAtom, aStyleContext); NS_RELEASE(sbAtom); sbAtom = NS_NewAtom(":SCROLLBAR-ARROW-LOOK"); - nsIStyleContext* arrowStyle = aPresContext.ResolvePseudoStyleContextFor(mContent, sbAtom, mStyleContext); + nsIStyleContext* arrowStyle = aPresContext.ResolvePseudoStyleContextFor(mContent, sbAtom, aStyleContext); NS_RELEASE(sbAtom); nsRect srect(mRect.width-scrollbarScaledWidth-(2*onePixel), 2*onePixel, scrollbarScaledWidth, mRect.height-(onePixel*4)-scrollbarScaledWidth); @@ -734,8 +731,11 @@ nsTextControlFrame::Paint(nsIPresContext& aPresContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) { + nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); if (eFramePaintLayer_Content == aWhichLayer) { - PaintTextControl(aPresContext, aRenderingContext, aDirtyRect); + nsString text; + GetText(&text, PR_FALSE); + PaintTextControl(aPresContext, aRenderingContext, aDirtyRect, text, mStyleContext); } return NS_OK; } @@ -767,7 +767,7 @@ void nsTextControlFrame::SetTextControlFrameState(const nsString& aValue) nsITextWidget* text = nsnull; nsITextAreaWidget* textArea = nsnull; PRUint32 size = 0; - if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) { + if (NS_SUCCEEDED(mWidget->QueryInterface(kITextWidgetIID,(void**)&text))) { text->SetText(aValue,size); NS_RELEASE(text); } else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID, diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.h b/mozilla/layout/html/forms/src/nsTextControlFrame.h index a8fdb7ca931..62aa135b379 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.h +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.h @@ -66,11 +66,6 @@ public: NS_IMETHOD GetCursor(nsIPresContext& aPresContext, nsPoint& aPoint, PRInt32& aCursor); - // - // XXX: The following paint methods are TEMPORARY. It is being used to get printing working - // under windows. Later it may be used to GFX-render the controls to the display. - // Expect this code to repackaged and moved to a new location in the future. - // NS_IMETHOD Paint(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, @@ -78,17 +73,17 @@ public: virtual void PaintTextControl(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); - - ///XXX: End o the temporary methods - - -protected: + const nsRect& aDirtyRect, nsString& aText, + nsIStyleContext* aStyleContext); // Utility methods to get and set current widget state void GetTextControlFrameState(nsString& aValue); void SetTextControlFrameState(const nsString& aValue); +protected: + + + virtual void GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsHTMLReflowMetrics& aDesiredLayoutSize,