зеркало из https://github.com/mozilla/gecko-dev.git
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.
This commit is contained in:
Родитель
309df9da98
Коммит
3d131e6a4a
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;i<len;i++) {
|
||||
text.Append("*");
|
||||
aText.Append("*");
|
||||
}
|
||||
}
|
||||
aRenderingContext.DrawString(text, x, y);
|
||||
aRenderingContext.DrawString(aText, x, y);
|
||||
} else {
|
||||
float sbWidth;
|
||||
float sbHeight;
|
||||
|
@ -674,35 +671,35 @@ nsTextControlFrame::PaintTextControl(nsIPresContext& aPresContext,
|
|||
|
||||
// Draw multi-line text
|
||||
PRInt32 oldPos = 0;
|
||||
PRInt32 pos = text.Find('\n', 0);
|
||||
PRInt32 pos = aText.Find('\n', 0);
|
||||
while (1) {
|
||||
nsString substr;
|
||||
if (-1 == pos) {
|
||||
// Single line, no carriage return.
|
||||
text.Right(substr, text.Length()-oldPos);
|
||||
aText.Right(substr, aText.Length()-oldPos);
|
||||
aRenderingContext.DrawString(substr, x, y);
|
||||
break;
|
||||
}
|
||||
// Strip off substr up to carriage return
|
||||
text.Mid(substr, oldPos, ((pos - oldPos) - 1));
|
||||
aText.Mid(substr, oldPos, ((pos - oldPos) - 1));
|
||||
|
||||
aRenderingContext.DrawString(substr, x, y);
|
||||
y += textHeight;
|
||||
// Advance to the next carriage return
|
||||
pos++;
|
||||
oldPos = pos;
|
||||
pos = text.Find('\n', pos);
|
||||
pos = aText.Find('\n', pos);
|
||||
}
|
||||
|
||||
aRenderingContext.PopState(clipEmpty);
|
||||
|
||||
// Scrollbars
|
||||
const nsStyleColor* myColor = (const nsStyleColor*)mStyleContext->GetStyleData(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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;i<len;i++) {
|
||||
text.Append("*");
|
||||
aText.Append("*");
|
||||
}
|
||||
}
|
||||
aRenderingContext.DrawString(text, x, y);
|
||||
aRenderingContext.DrawString(aText, x, y);
|
||||
} else {
|
||||
float sbWidth;
|
||||
float sbHeight;
|
||||
|
@ -674,35 +671,35 @@ nsTextControlFrame::PaintTextControl(nsIPresContext& aPresContext,
|
|||
|
||||
// Draw multi-line text
|
||||
PRInt32 oldPos = 0;
|
||||
PRInt32 pos = text.Find('\n', 0);
|
||||
PRInt32 pos = aText.Find('\n', 0);
|
||||
while (1) {
|
||||
nsString substr;
|
||||
if (-1 == pos) {
|
||||
// Single line, no carriage return.
|
||||
text.Right(substr, text.Length()-oldPos);
|
||||
aText.Right(substr, aText.Length()-oldPos);
|
||||
aRenderingContext.DrawString(substr, x, y);
|
||||
break;
|
||||
}
|
||||
// Strip off substr up to carriage return
|
||||
text.Mid(substr, oldPos, ((pos - oldPos) - 1));
|
||||
aText.Mid(substr, oldPos, ((pos - oldPos) - 1));
|
||||
|
||||
aRenderingContext.DrawString(substr, x, y);
|
||||
y += textHeight;
|
||||
// Advance to the next carriage return
|
||||
pos++;
|
||||
oldPos = pos;
|
||||
pos = text.Find('\n', pos);
|
||||
pos = aText.Find('\n', pos);
|
||||
}
|
||||
|
||||
aRenderingContext.PopState(clipEmpty);
|
||||
|
||||
// Scrollbars
|
||||
const nsStyleColor* myColor = (const nsStyleColor*)mStyleContext->GetStyleData(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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Загрузка…
Ссылка в новой задаче