From 6a1d4627641a2b814424bbe5205d3fab4562fea2 Mon Sep 17 00:00:00 2001 From: "pierre%netscape.com" Date: Fri, 6 Aug 1999 05:11:39 +0000 Subject: [PATCH] breaking up gfx & native widgets git-svn-id: svn://10.0.0.236/trunk@42404 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsCSSFrameConstructor.cpp | 108 +++++- mozilla/layout/base/nsCSSFrameConstructor.h | 10 + mozilla/layout/base/nsPresContext.h | 7 + mozilla/layout/base/public/nsIPresContext.h | 7 + mozilla/layout/base/public/nsPresContext.h | 7 + mozilla/layout/forms/nsFileControlFrame.cpp | 13 - mozilla/layout/forms/nsFileControlFrame.h | 2 - mozilla/layout/forms/nsFormControlFrame.cpp | 259 +------------ mozilla/layout/forms/nsFormControlFrame.h | 18 - mozilla/layout/forms/nsTextControlFrame.h | 4 +- mozilla/layout/generic/nsHTMLParts.h | 11 +- mozilla/layout/html/base/src/nsHTMLParts.h | 11 +- mozilla/layout/html/forms/src/Makefile.in | 11 +- mozilla/layout/html/forms/src/makefile.win | 26 +- .../html/forms/src/nsButtonControlFrame.cpp | 280 +------------- .../html/forms/src/nsButtonControlFrame.h | 52 +-- .../html/forms/src/nsCheckboxControlFrame.cpp | 321 +--------------- .../html/forms/src/nsFileControlFrame.cpp | 13 - .../html/forms/src/nsFileControlFrame.h | 2 - .../html/forms/src/nsFormControlFrame.cpp | 259 +------------ .../html/forms/src/nsFormControlFrame.h | 18 - mozilla/layout/html/forms/src/nsFormFrame.cpp | 2 +- .../html/forms/src/nsGfxTextControlFrame.cpp | 8 +- .../html/forms/src/nsGfxTextControlFrame.h | 3 + .../forms/src/nsNativeTextControlFrame.cpp | 12 +- .../html/forms/src/nsNativeTextControlFrame.h | 3 + .../html/forms/src/nsRadioControlFrame.cpp | 345 +----------------- .../html/forms/src/nsRadioControlFrame.h | 64 +--- .../html/forms/src/nsTextControlFrame.h | 4 +- .../html/style/src/nsCSSFrameConstructor.cpp | 108 +++++- .../html/style/src/nsCSSFrameConstructor.h | 10 + mozilla/layout/macbuild/layout.mcp | Bin 149920 -> 152480 bytes 32 files changed, 377 insertions(+), 1621 deletions(-) diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index ffa75c02123..2659db59274 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -798,22 +798,22 @@ nsCSSFrameConstructor::CreateInputFrame(nsIPresContext *aPresContext, nsAutoString val; if (NS_OK == aContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, val)) { if (val.EqualsIgnoreCase("submit")) { - rv = NS_NewButtonControlFrame(&aFrame); + rv = ConstructButtonControlFrame(aPresContext, aFrame); } else if (val.EqualsIgnoreCase("reset")) { - rv = NS_NewButtonControlFrame(&aFrame); + rv = ConstructButtonControlFrame(aPresContext, aFrame); } else if (val.EqualsIgnoreCase("button")) { - rv = NS_NewButtonControlFrame(&aFrame); + rv = ConstructButtonControlFrame(aPresContext, aFrame); } else if (val.EqualsIgnoreCase("checkbox")) { - rv = NS_NewCheckboxControlFrame(&aFrame); + rv = ConstructCheckboxControlFrame(aPresContext, aFrame); } else if (val.EqualsIgnoreCase("file")) { rv = NS_NewFileControlFrame(&aFrame); } else if (val.EqualsIgnoreCase("hidden")) { - rv = NS_NewButtonControlFrame(&aFrame); + rv = ConstructButtonControlFrame(aPresContext, aFrame); } else if (val.EqualsIgnoreCase("image")) { rv = NS_NewImageControlFrame(&aFrame); @@ -2350,13 +2350,71 @@ nsCSSFrameConstructor::CreatePlaceholderFrameFor(nsIPresContext* aPresContext, return rv; } + +nsWidgetRendering +nsCSSFrameConstructor::GetFormElementRenderingMode(nsIPresContext* aPresContext, + nsWidgetType aWidgetType) +{ + if (!aPresContext) { return eWidgetRendering_Gfx;} + + nsWidgetRendering mode; + aPresContext->GetWidgetRenderingMode(&mode); + + switch (mode) + { + case eWidgetRendering_Gfx: + return eWidgetRendering_Gfx; + + case eWidgetRendering_PartialGfx: + switch (aWidgetType) + { + case eWidgetType_Button: + case eWidgetType_Checkbox: + case eWidgetType_Radio: + case eWidgetType_Text: + return eWidgetRendering_Gfx; + + default: + return eWidgetRendering_Native; + } + + case eWidgetRendering_Native: + PRBool useNativeWidgets = PR_FALSE; + nsIDeviceContext* dc; + aPresContext->GetDeviceContext(&dc); + if (dc) { + PRBool supportsWidgets; + if (NS_SUCCEEDED(dc->SupportsNativeWidgets(supportsWidgets))) { + useNativeWidgets = supportsWidgets; + } + NS_RELEASE(dc); + } + if (useNativeWidgets) + return eWidgetRendering_Native; + else + return eWidgetRendering_Gfx; + } + return eWidgetRendering_Gfx; +} + + nsresult nsCSSFrameConstructor::ConstructRadioControlFrame(nsIPresContext* aPresContext, nsIFrame*& aNewFrame, nsIContent* aContent, nsIStyleContext* aStyleContext) { - nsresult rv = NS_NewRadioControlFrame(&aNewFrame); + nsresult rv = NS_OK; + if (GetFormElementRenderingMode(aPresContext, eWidgetType_Radio) == eWidgetRendering_Gfx) + rv = NS_NewGfxRadioControlFrame(&aNewFrame); + else + rv = NS_NewNativeRadioControlFrame(&aNewFrame); + + if (NS_FAILED(rv)) { + aNewFrame = nsnull; + return rv; + } + nsCOMPtr radioStyle; aPresContext->ResolvePseudoStyleContextFor(aContent, nsHTMLAtoms::radioPseudo, aStyleContext, PR_FALSE, getter_AddRefs(radioStyle)); @@ -2368,6 +2426,38 @@ nsCSSFrameConstructor::ConstructRadioControlFrame(nsIPresContext* aPresContext, return rv; } +nsresult +nsCSSFrameConstructor::ConstructCheckboxControlFrame(nsIPresContext* aPresContext, + nsIFrame*& aNewFrame) +{ + nsresult rv = NS_OK; + if (GetFormElementRenderingMode(aPresContext, eWidgetType_Checkbox) == eWidgetRendering_Gfx) + rv = NS_NewGfxCheckboxControlFrame(&aNewFrame); + else + rv = NS_NewNativeCheckboxControlFrame(&aNewFrame); + + if (NS_FAILED(rv)) { + aNewFrame = nsnull; + } + return rv; +} + +nsresult +nsCSSFrameConstructor::ConstructButtonControlFrame(nsIPresContext* aPresContext, + nsIFrame*& aNewFrame) +{ + nsresult rv = NS_OK; + if (GetFormElementRenderingMode(aPresContext, eWidgetType_Button) == eWidgetRendering_Gfx) + rv = NS_NewGfxButtonControlFrame(&aNewFrame); + else + rv = NS_NewNativeButtonControlFrame(&aNewFrame); + + if (NS_FAILED(rv)) { + aNewFrame = nsnull; + } + return rv; +} + nsresult nsCSSFrameConstructor::ConstructTextControlFrame(nsIPresContext* aPresContext, nsIFrame*& aNewFrame) @@ -2517,12 +2607,12 @@ nsCSSFrameConstructor::ConstructSelectFrame(nsIPresContext* aPresContex } NS_RELEASE(select); } else { - rv = NS_NewSelectControlFrame(&aNewFrame); + rv = NS_NewNativeSelectControlFrame(&aNewFrame); } } else { // Not frame based. Use a SelectFrame which creates a native widget. - rv = NS_NewSelectControlFrame(&aNewFrame); + rv = NS_NewNativeSelectControlFrame(&aNewFrame); } return rv; @@ -2866,7 +2956,7 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresContext* aPresContext, // Create a frame based on the tag if (aTag == nsXULAtoms::button) - rv = NS_NewButtonControlFrame(&newFrame); + rv = ConstructButtonControlFrame(aPresContext, newFrame); else if (aTag == nsXULAtoms::checkbox) rv = NS_NewTriStateCheckboxFrame(&newFrame); else if (aTag == nsXULAtoms::spinner) diff --git a/mozilla/layout/base/nsCSSFrameConstructor.h b/mozilla/layout/base/nsCSSFrameConstructor.h index f698058b3c7..3fa35437abb 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.h +++ b/mozilla/layout/base/nsCSSFrameConstructor.h @@ -20,6 +20,7 @@ #include "nsIStyleFrameConstruction.h" #include "nslayout.h" +#include "nsIPresContext.h" class nsIDocument; struct nsFrameItems; @@ -404,11 +405,20 @@ protected: nsIFrame* aParentFrame, nsIFrame*& aFrame); + nsWidgetRendering GetFormElementRenderingMode(nsIPresContext* aPresContext, + nsWidgetType aWidgetType); + nsresult ConstructRadioControlFrame(nsIPresContext* aPresContext, nsIFrame*& aNewFrame, nsIContent* aContent, nsIStyleContext* aStyleContext); + nsresult ConstructCheckboxControlFrame(nsIPresContext* aPresContext, + nsIFrame*& aNewFrame); + + nsresult ConstructButtonControlFrame(nsIPresContext* aPresContext, + nsIFrame*& aNewFrame); + nsresult ConstructTextControlFrame(nsIPresContext* aPresContext, nsIFrame*& aNewFrame); diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index e2d84fa10d8..e58513560f5 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -57,6 +57,13 @@ enum nsWidgetRendering { eWidgetRendering_PartialGfx = 3 }; +enum nsWidgetType { + eWidgetType_Button = 1, + eWidgetType_Checkbox = 2, + eWidgetType_Radio = 3, + eWidgetType_Text = 4 +}; + // An interface for presentation contexts. Presentation contexts are // objects that provide an outer context for a presentation shell. class nsIPresContext : public nsISupports { diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index e2d84fa10d8..e58513560f5 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -57,6 +57,13 @@ enum nsWidgetRendering { eWidgetRendering_PartialGfx = 3 }; +enum nsWidgetType { + eWidgetType_Button = 1, + eWidgetType_Checkbox = 2, + eWidgetType_Radio = 3, + eWidgetType_Text = 4 +}; + // An interface for presentation contexts. Presentation contexts are // objects that provide an outer context for a presentation shell. class nsIPresContext : public nsISupports { diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index e2d84fa10d8..e58513560f5 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -57,6 +57,13 @@ enum nsWidgetRendering { eWidgetRendering_PartialGfx = 3 }; +enum nsWidgetType { + eWidgetType_Button = 1, + eWidgetType_Checkbox = 2, + eWidgetType_Radio = 3, + eWidgetType_Text = 4 +}; + // An interface for presentation contexts. Presentation contexts are // objects that provide an outer context for a presentation shell. class nsIPresContext : public nsISupports { diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index d21f30f0642..70b47cf01f5 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -416,19 +416,6 @@ NS_IMETHODIMP nsFileControlFrame::GetProperty(nsIAtom* aName, nsString& aValue) return NS_OK; } -PRBool -nsFileControlFrame::HasWidget() -{ - PRBool hasWidget = PR_FALSE; - nsIWidget* widget; - mTextFrame->GetWidget(&widget); - if (widget) { - NS_RELEASE(widget); - hasWidget = PR_TRUE; - } - return(hasWidget); -} - diff --git a/mozilla/layout/forms/nsFileControlFrame.h b/mozilla/layout/forms/nsFileControlFrame.h index eef454d3327..cb604749742 100644 --- a/mozilla/layout/forms/nsFileControlFrame.h +++ b/mozilla/layout/forms/nsFileControlFrame.h @@ -85,8 +85,6 @@ public: virtual nsresult RequiresWidget(PRBool &aRequiresWidget); - PRBool HasWidget(); - // from nsIAnonymousContentCreator NS_IMETHOD CreateAnonymousContent(nsISupportsArray& aChildList); diff --git a/mozilla/layout/forms/nsFormControlFrame.cpp b/mozilla/layout/forms/nsFormControlFrame.cpp index 4dff9feb9e0..3ea3d5500c2 100644 --- a/mozilla/layout/forms/nsFormControlFrame.cpp +++ b/mozilla/layout/forms/nsFormControlFrame.cpp @@ -63,9 +63,7 @@ static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID); nsFormControlFrame::nsFormControlFrame() : nsLeafFrame() { - mLastMouseState = eMouseNone; mDidInit = PR_FALSE; - mWidget = nsnull; mFormFrame = nsnull; mSuggestedWidth = NS_FORMSIZE_NOTSET; mSuggestedHeight = NS_FORMSIZE_NOTSET; @@ -74,7 +72,6 @@ nsFormControlFrame::nsFormControlFrame() nsFormControlFrame::~nsFormControlFrame() { mFormFrame = nsnull; - NS_IF_RELEASE(mWidget); } nsresult @@ -231,101 +228,16 @@ nsFormControlFrame::Reflow(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { - nsresult result = NS_OK; - // add ourself as an nsIFormControlFrame if (!mFormFrame && (eReflowReason_Initial == aReflowState.reason)) { nsFormFrame::AddFormControlFrame(aPresContext, *this); } - nsCOMPtr dx; - aPresContext.GetDeviceContext(getter_AddRefs(dx)); - PRBool requiresWidget = PR_TRUE; - - // Checkto see if the device context supports widgets at all - if (dx) { - dx->SupportsNativeWidgets(requiresWidget); - } - - nsWidgetRendering mode; - aPresContext.GetWidgetRenderingMode(&mode); - if ((eWidgetRendering_Gfx == mode) || (eWidgetRendering_PartialGfx == mode)) { - // Check with the frame to see if requires a widget to render - if (PR_TRUE == requiresWidget) { - RequiresWidget(requiresWidget); - } - } - GetDesiredSize(&aPresContext, aReflowState, aDesiredSize, mWidgetSize); if (!mDidInit) { - if (PR_TRUE == requiresWidget) { - nsCOMPtr presShell; - aPresContext.GetShell(getter_AddRefs(presShell)); - nsCOMPtr viewMan; - presShell->GetViewManager(getter_AddRefs(viewMan)); - nsRect boundBox(0, 0, aDesiredSize.width, aDesiredSize.height); - - // absolutely positioned controls already have a view but not a widget - nsIView* view = nsnull; - GetView(&view); - if (nsnull == view) { - result = nsComponentManager::CreateInstance(kViewCID, nsnull, kIViewIID, (void **)&view); - if (!NS_SUCCEEDED(result)) { - NS_ASSERTION(0, "Could not create view for form control"); - aStatus = NS_FRAME_NOT_COMPLETE; - return result; - } - - nsIFrame* parWithView; - nsIView *parView; - - GetParentWithView(&parWithView); - parWithView->GetView(&parView); - - // initialize the view as hidden since we don't know the (x,y) until Paint - result = view->Init(viewMan, boundBox, parView, nsnull, nsViewVisibility_kHide); - if (NS_OK != result) { - NS_ASSERTION(0, "view initialization failed"); - aStatus = NS_FRAME_NOT_COMPLETE; - return NS_OK; - } - - viewMan->InsertChild(parView, view, 0); - SetView(view); - } - - PRInt32 type; - GetType(&type); - const nsIID& id = GetCID(); - - if ((NS_FORM_INPUT_HIDDEN != type) && (PR_TRUE == requiresWidget)) { - // Do the following only if a widget is created - nsWidgetInitData* initData = GetWidgetInitData(aPresContext); // needs to be deleted - view->CreateWidget(id, initData); - - if (nsnull != initData) { - delete(initData); - } - - // set our widget - result = GetWidget(view, &mWidget); - if ((PR_FALSE == NS_SUCCEEDED(result)) || (nsnull == mWidget)) { // keep the ref on mWidget - NS_ASSERTION(0, "could not get widget"); - } - } - - PostCreateWidget(&aPresContext, aDesiredSize.width, aDesiredSize.height); - mDidInit = PR_TRUE; - - if ((aDesiredSize.width != boundBox.width) || (aDesiredSize.height != boundBox.height)) { - viewMan->ResizeView(view, aDesiredSize.width, aDesiredSize.height); - } - - } else { - PostCreateWidget(&aPresContext, aDesiredSize.width, aDesiredSize.height); - mDidInit = PR_TRUE; - } + PostCreateWidget(&aPresContext, aDesiredSize.width, aDesiredSize.height); + mDidInit = PR_TRUE; } aDesiredSize.ascent = aDesiredSize.height; @@ -340,108 +252,20 @@ nsFormControlFrame::Reflow(nsIPresContext& aPresContext, } -NS_IMETHODIMP -nsFormControlFrame::AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute, - PRInt32 aHint) -{ - if (nsnull != mWidget) { - if (nsHTMLAtoms::disabled == aAttribute) { - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - } - } - return NS_OK; -} - nsWidgetInitData* nsFormControlFrame::GetWidgetInitData(nsIPresContext& aPresContext) { return nsnull; } -void -nsFormControlFrame::SetColors(nsIPresContext& aPresContext) -{ - if (mWidget) { - nsCompatibility mode; - aPresContext.GetCompatibilityMode(&mode); - const nsStyleColor* color = - (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color); - if (nsnull != color) { - if (!(NS_STYLE_BG_COLOR_TRANSPARENT & color->mBackgroundFlags)) { - mWidget->SetBackgroundColor(color->mBackgroundColor); -#ifdef bug_1021_closed - } else if (eCompatibility_NavQuirks == mode) { -#else - } else { -#endif - mWidget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF)); - } - mWidget->SetForegroundColor(color->mColor); - } - } -} - void nsFormControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight) { } -// native widgets don't need to repaint void nsFormControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) { - if (mWidget) { - if (aOn) { - mWidget->SetFocus(); - } - else { - //Unsetting of focus on native widget is accomplised - //by pushing focus up to its parent - nsIWidget *parentWidget = mWidget->GetParent(); - if (parentWidget) { - parentWidget->SetFocus(); - NS_RELEASE(parentWidget); - } - } - } -} - -nsresult -nsFormControlFrame::GetWidget(nsIWidget** aWidget) -{ - if (mWidget) { - NS_ADDREF(mWidget); - *aWidget = mWidget; - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - return NS_OK; - } else { - *aWidget = nsnull; - return NS_FORM_NOTOK; - } -} - -nsresult -nsFormControlFrame::GetWidget(nsIView* aView, nsIWidget** aWidget) -{ - nsIWidget* widget; - aView->GetWidget(widget); - nsresult result; - - if (nsnull == widget) { - *aWidget = nsnull; - result = NS_ERROR_FAILURE; - - } else { - result = widget->QueryInterface(kIWidgetIID, (void**)aWidget); // keep the ref - if (NS_FAILED(result)) { - NS_ASSERTION(0, "The widget interface is invalid"); // need to print out more details of the widget - } - NS_RELEASE(widget); - } - - return result; } const nsIID& @@ -571,74 +395,25 @@ NS_METHOD nsFormControlFrame::HandleEvent(nsIPresContext& aPresContext, return NS_OK; } - if (nsnull != mWidget) { - // make sure that the widget in the event is this input - // XXX if there is no view, it could be an image button. Unfortunately, - // every image button will get every event. - nsIView* view; - GetView(&view); - if (view) { - if (mWidget != aEvent->widget) { - aEventStatus = nsEventStatus_eIgnore; - return NS_OK; - } - } - } - // if not native then use the NS_MOUSE_LEFT_CLICK to see if pressed // unfortunately native widgets don't seem to handle this right. // so use the old code for native stuff. -EDV - if (nsnull == mWidget) { - switch (aEvent->message) { - case NS_MOUSE_LEFT_CLICK: - MouseClicked(&aPresContext); - break; - } - } else { - //printf(" %d %d %d %d (%d,%d) \n", this, aEvent->widget, aEvent->widgetSupports, - // aEvent->message, aEvent->point.x, aEvent->point.y); - - PRInt32 type; - GetType(&type); - switch (aEvent->message) { - case NS_MOUSE_ENTER: - mLastMouseState = eMouseEnter; - break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - if (NS_FORM_INPUT_IMAGE == type) { - mLastMouseState = eMouseDown; - } else { - mLastMouseState = (eMouseEnter == mLastMouseState) ? eMouseDown : eMouseNone; - } - break; - case NS_MOUSE_LEFT_BUTTON_UP: - if (eMouseDown == mLastMouseState) { - MouseClicked(&aPresContext); - } - mLastMouseState = eMouseEnter; - break; - case NS_MOUSE_EXIT: - mLastMouseState = eMouseNone; - break; - case NS_CONTROL_CHANGE: - ControlChanged(&aPresContext); - break; - } - } - - // see if a key was pressed - switch (aEvent->message) { - case NS_KEY_DOWN: - if (NS_KEY_EVENT == aEvent->eventStructType) { - nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; - if (NS_VK_RETURN == keyEvent->keyCode) { - EnterPressed(aPresContext); - } - else if (NS_VK_SPACE == keyEvent->keyCode) { + switch (aEvent->message) { + case NS_MOUSE_LEFT_CLICK: MouseClicked(&aPresContext); - } - } - break; + break; + + case NS_KEY_DOWN: + if (NS_KEY_EVENT == aEvent->eventStructType) { + nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; + if (NS_VK_RETURN == keyEvent->keyCode) { + EnterPressed(aPresContext); + } + else if (NS_VK_SPACE == keyEvent->keyCode) { + MouseClicked(&aPresContext); + } + } + break; } aEventStatus = nsEventStatus_eConsumeDoDefault; diff --git a/mozilla/layout/forms/nsFormControlFrame.h b/mozilla/layout/forms/nsFormControlFrame.h index 4d807356638..847bd3666c7 100644 --- a/mozilla/layout/forms/nsFormControlFrame.h +++ b/mozilla/layout/forms/nsFormControlFrame.h @@ -90,11 +90,6 @@ public: const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus); - - NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute, - PRInt32 aHint); // new behavior /** @@ -116,15 +111,6 @@ public: virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues, nsString* aNames); - /** - * Get the widget associated with this frame - * @param aView the view associated with the frame. It is a convience parm. - * @param aWidget the address of address of where the widget will be placed. - * This method doses an AddRef on the widget. - */ - nsresult GetWidget(nsIView* aView, nsIWidget** aWidget); - nsresult GetWidget(nsIWidget** aWidget); - /** * Respond to a enter key being pressed */ @@ -148,8 +134,6 @@ public: nscoord& aWidth, nscoord& aHeight); virtual void SetFocus(PRBool aOn = PR_TRUE, PRBool aRepaint = PR_FALSE); - - void SetColors(nsIPresContext& aPresContext); virtual void Reset(); virtual PRBool IsSuccessful(nsIFormControlFrame* aSubmitter); @@ -272,8 +256,6 @@ protected: nsresult SetDefaultCheckState(PRBool aState); - nsMouseState mLastMouseState; - nsIWidget* mWidget; nsSize mWidgetSize; PRBool mDidInit; nsPoint mLastClickPoint; diff --git a/mozilla/layout/forms/nsTextControlFrame.h b/mozilla/layout/forms/nsTextControlFrame.h index 989f6d70815..075a830883c 100644 --- a/mozilla/layout/forms/nsTextControlFrame.h +++ b/mozilla/layout/forms/nsTextControlFrame.h @@ -19,12 +19,12 @@ #ifndef nsTextControlFrame_h___ #define nsTextControlFrame_h___ -#include "nsFormControlFrame.h" +#include "nsNativeFormControlFrame.h" class nsIContent; class nsIFrame; class nsIPresContext; -class nsTextControlFrame : public nsFormControlFrame +class nsTextControlFrame : public nsNativeFormControlFrame { /* ---------- methods implemented by base class ---------- */ public: diff --git a/mozilla/layout/generic/nsHTMLParts.h b/mozilla/layout/generic/nsHTMLParts.h index f8d2b73a0e6..69ca5188232 100644 --- a/mozilla/layout/generic/nsHTMLParts.h +++ b/mozilla/layout/generic/nsHTMLParts.h @@ -315,18 +315,21 @@ extern nsresult NS_NewFirstLineFrame(nsIFrame** aNewFrame); // forms extern nsresult NS_NewFormFrame(nsIFrame** aResult); -extern nsresult NS_NewButtonControlFrame(nsIFrame** aResult); +extern nsresult NS_NewGfxButtonControlFrame(nsIFrame** aResult); +extern nsresult NS_NewNativeButtonControlFrame(nsIFrame** aResult); extern nsresult NS_NewImageControlFrame(nsIFrame** aResult); extern nsresult NS_NewHTMLButtonControlFrame(nsIFrame** aResult); -extern nsresult NS_NewCheckboxControlFrame(nsIFrame** aResult); +extern nsresult NS_NewGfxCheckboxControlFrame(nsIFrame** aResult); +extern nsresult NS_NewNativeCheckboxControlFrame(nsIFrame** aResult); extern nsresult NS_NewFieldSetFrame(nsIFrame** aResult); extern nsresult NS_NewFileControlFrame(nsIFrame** aResult); extern nsresult NS_NewLabelFrame(nsIFrame** aResult); extern nsresult NS_NewLegendFrame(nsIFrame** aResult); extern nsresult NS_NewNativeTextControlFrame(nsIFrame** aNewFrame); extern nsresult NS_NewGfxTextControlFrame(nsIFrame** aNewFrame); -extern nsresult NS_NewRadioControlFrame(nsIFrame** aResult); -extern nsresult NS_NewSelectControlFrame(nsIFrame** aResult); +extern nsresult NS_NewGfxRadioControlFrame(nsIFrame** aResult); +extern nsresult NS_NewNativeRadioControlFrame(nsIFrame** aResult); +extern nsresult NS_NewNativeSelectControlFrame(nsIFrame** aResult); extern nsresult NS_NewListControlFrame(nsIFrame** aResult); extern nsresult NS_NewComboboxControlFrame(nsIFrame** aResult); diff --git a/mozilla/layout/html/base/src/nsHTMLParts.h b/mozilla/layout/html/base/src/nsHTMLParts.h index f8d2b73a0e6..69ca5188232 100644 --- a/mozilla/layout/html/base/src/nsHTMLParts.h +++ b/mozilla/layout/html/base/src/nsHTMLParts.h @@ -315,18 +315,21 @@ extern nsresult NS_NewFirstLineFrame(nsIFrame** aNewFrame); // forms extern nsresult NS_NewFormFrame(nsIFrame** aResult); -extern nsresult NS_NewButtonControlFrame(nsIFrame** aResult); +extern nsresult NS_NewGfxButtonControlFrame(nsIFrame** aResult); +extern nsresult NS_NewNativeButtonControlFrame(nsIFrame** aResult); extern nsresult NS_NewImageControlFrame(nsIFrame** aResult); extern nsresult NS_NewHTMLButtonControlFrame(nsIFrame** aResult); -extern nsresult NS_NewCheckboxControlFrame(nsIFrame** aResult); +extern nsresult NS_NewGfxCheckboxControlFrame(nsIFrame** aResult); +extern nsresult NS_NewNativeCheckboxControlFrame(nsIFrame** aResult); extern nsresult NS_NewFieldSetFrame(nsIFrame** aResult); extern nsresult NS_NewFileControlFrame(nsIFrame** aResult); extern nsresult NS_NewLabelFrame(nsIFrame** aResult); extern nsresult NS_NewLegendFrame(nsIFrame** aResult); extern nsresult NS_NewNativeTextControlFrame(nsIFrame** aNewFrame); extern nsresult NS_NewGfxTextControlFrame(nsIFrame** aNewFrame); -extern nsresult NS_NewRadioControlFrame(nsIFrame** aResult); -extern nsresult NS_NewSelectControlFrame(nsIFrame** aResult); +extern nsresult NS_NewGfxRadioControlFrame(nsIFrame** aResult); +extern nsresult NS_NewNativeRadioControlFrame(nsIFrame** aResult); +extern nsresult NS_NewNativeSelectControlFrame(nsIFrame** aResult); extern nsresult NS_NewListControlFrame(nsIFrame** aResult); extern nsresult NS_NewComboboxControlFrame(nsIFrame** aResult); diff --git a/mozilla/layout/html/forms/src/Makefile.in b/mozilla/layout/html/forms/src/Makefile.in index 81e0da41dc5..c9dca670460 100644 --- a/mozilla/layout/html/forms/src/Makefile.in +++ b/mozilla/layout/html/forms/src/Makefile.in @@ -42,13 +42,22 @@ CPPSRCS = \ nsTextControlFrame.cpp \ nsNativeTextControlFrame.cpp \ nsGfxTextControlFrame.cpp \ - nsSelectControlFrame.cpp \ + nsNativeSelectControlFrame.cpp \ nsFieldSetFrame.cpp \ nsLegendFrame.cpp \ nsHTMLButtonControlFrame.cpp \ nsLabelFrame.cpp \ nsImageControlFrame.cpp \ nsButtonFrameRenderer.cpp \ + nsGfxButtonControlFrame.cpp \ + nsGfxCheckboxControlFrame.cpp \ + nsGfxRadioControlFrame.cpp \ + nsNativeButtonControlFrame.cpp \ + nsNativeCheckboxControlFram.cpp \ + nsNativeFormControlFrame.cpp \ + nsNativeRadioControlFrame.cpp \ + nsNativeSelectControlFrame.cpp \ + nsRadioControlGroup.cpp \ $(NULL) MODULE=layout diff --git a/mozilla/layout/html/forms/src/makefile.win b/mozilla/layout/html/forms/src/makefile.win index 6e99f7bbbb8..9f9039b50bf 100644 --- a/mozilla/layout/html/forms/src/makefile.win +++ b/mozilla/layout/html/forms/src/makefile.win @@ -36,13 +36,22 @@ CPPSRCS= \ nsTextControlFrame.cpp \ nsGfxTextControlFrame.cpp \ nsTextControlFrame.cpp \ - nsSelectControlFrame.cpp \ + nsNativeSelectControlFrame.cpp \ nsFieldSetFrame.cpp \ nsLegendFrame.cpp \ nsHTMLButtonControlFrame.cpp \ nsLabelFrame.cpp \ nsButtonFrameRenderer.cpp \ - nsImageControlFrame.cpp + nsImageControlFrame.cpp \ + nsGfxButtonControlFrame.cpp \ + nsGfxCheckboxControlFrame.cpp \ + nsGfxRadioControlFrame.cpp \ + nsNativeButtonControlFrame.cpp \ + nsNativeCheckboxControlFram.cpp \ + nsNativeFormControlFrame.cpp \ + nsNativeRadioControlFrame.cpp \ + nsNativeSelectControlFrame.cpp \ + nsRadioControlGroup.cpp CPP_OBJS= \ .\$(OBJDIR)\nsFormControlHelper.obj \ @@ -57,13 +66,22 @@ CPP_OBJS= \ .\$(OBJDIR)\nsTextControlFrame.obj \ .\$(OBJDIR)\nsGfxTextControlFrame.obj \ .\$(OBJDIR)\nsNativeTextControlFrame.obj \ - .\$(OBJDIR)\nsSelectControlFrame.obj \ + .\$(OBJDIR)\nsNativeSelectControlFrame.obj \ .\$(OBJDIR)\nsFieldSetFrame.obj \ .\$(OBJDIR)\nsLegendFrame.obj \ .\$(OBJDIR)\nsHTMLButtonControlFrame.obj \ .\$(OBJDIR)\nsLabelFrame.obj \ .\$(OBJDIR)\nsButtonFrameRenderer.obj \ - .\$(OBJDIR)\nsImageControlFrame.obj + .\$(OBJDIR)\nsImageControlFrame.obj \ + .\$(OBJDIR)\nsGfxButtonControlFrame.obj \ + .\$(OBJDIR)\nsGfxCheckboxControlFrame.obj \ + .\$(OBJDIR)\nsGfxRadioControlFrame.obj \ + .\$(OBJDIR)\nsNativeButtonControlFrame.obj \ + .\$(OBJDIR)\nsNativeCheckboxControlFram.obj \ + .\$(OBJDIR)\nsNativeFormControlFrame.obj \ + .\$(OBJDIR)\nsNativeRadioControlFrame.obj \ + .\$(OBJDIR)\nsNativeSelectControlFrame.obj \ + .\$(OBJDIR)\nsRadioControlGroup.obj LINCS= -I$(PUBLIC)\xpcom \ diff --git a/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp index fbc1e32ba90..2012187283c 100644 --- a/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp @@ -19,7 +19,6 @@ #include "nsFileControlFrame.h" #include "nsFormControlHelper.h" #include "nsButtonControlFrame.h" -#include "nsHTMLParts.h" #include "nsIRenderingContext.h" #include "nsIPresContext.h" #include "nsIPresShell.h" @@ -54,23 +53,6 @@ static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID); static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); -nsButtonControlFrame::nsButtonControlFrame() -{ - mRenderer.SetNameSpace(kNameSpaceID_None); -} - -NS_IMETHODIMP -nsButtonControlFrame::Init(nsIPresContext& aPresContext, - nsIContent* aContent, - nsIFrame* aParent, - nsIStyleContext* aContext, - nsIFrame* aPrevInFlow) -{ - nsresult rv = nsFormControlFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); - mRenderer.SetFrame(this,aPresContext); - return rv; -} - void nsButtonControlFrame::GetDefaultLabel(nsString& aString) { @@ -96,7 +78,7 @@ nsButtonControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter) PRInt32 type; GetType(&type); if ((NS_FORM_INPUT_HIDDEN == type) || (this == aSubmitter)) { - return nsFormControlFrame::IsSuccessful(aSubmitter); + return Inherited::IsSuccessful(aSubmitter); } else { return PR_FALSE; } @@ -141,21 +123,6 @@ nsButtonControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, } } -nsresult -NS_NewButtonControlFrame(nsIFrame** aNewFrame) -{ - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsButtonControlFrame* it = new nsButtonControlFrame; - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; -} - nscoord nsButtonControlFrame::GetVerticalBorderWidth(float aPixToTwip) const { @@ -207,125 +174,6 @@ nsButtonControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext, } } -// -// ReResolveStyleContext -// -// When the style context changes, make sure that all of our styles are still up to date. -// -NS_IMETHODIMP -nsButtonControlFrame::ReResolveStyleContext ( nsIPresContext* aPresContext, nsIStyleContext* aParentContext, - PRInt32 aParentChange, - nsStyleChangeList* aChangeList, PRInt32* aLocalChange) -{ - // this re-resolves |mStyleContext|, so it may change - nsresult rv = nsFormControlFrame::ReResolveStyleContext(aPresContext, aParentContext, - aParentChange, aChangeList, aLocalChange); - if (NS_FAILED(rv)) { - return rv; - } - - if (NS_COMFALSE != rv) { // frame style changed - if (aLocalChange) { - aParentChange = *aLocalChange; // tell children about or change - } - } - mRenderer.ReResolveStyles(*aPresContext, aParentChange, aChangeList, aLocalChange); - - return rv; - -} // ReResolveStyleContext - - - -NS_IMETHODIMP -nsButtonControlFrame::AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute, - PRInt32 aHint) -{ - nsresult result = NS_OK; - if (mWidget) { - if (nsHTMLAtoms::value == aAttribute) { - nsIButton* button = nsnull; - result = mWidget->QueryInterface(kIButtonIID, (void**)&button); - if ((NS_SUCCEEDED(result)) && (nsnull != button)) { - nsString value; - /*XXXnsresult result = */GetValue(&value); - button->SetLabel(value); - NS_RELEASE(button); - nsFormFrame::StyleChangeReflow(aPresContext, this); - } - } else if (nsHTMLAtoms::size == aAttribute) { - nsFormFrame::StyleChangeReflow(aPresContext, this); - } - // Allow the base class to handle common attributes supported - // by all form elements... - else { - result = nsFormControlFrame::AttributeChanged(aPresContext, aChild, aAttribute, aHint); - } - } else { - if (nsHTMLAtoms::value == aAttribute) { - // redraw button with the changed value - Invalidate(mRect, PR_FALSE); - } - } - return result; -} - - -NS_METHOD -nsButtonControlFrame::Paint(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer) -{ - const nsStyleDisplay* disp = (const nsStyleDisplay*) - mStyleContext->GetStyleData(eStyleStruct_Display); - if (!disp->mVisible) - return NS_OK; - - nsRect rect(0, 0, mRect.width, mRect.height); - mRenderer.PaintButton(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, rect); - - if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { - nsString label; - nsresult result = GetValue(&label); - - if (NS_CONTENT_ATTR_HAS_VALUE != result) { - GetDefaultLabel(label); - } - - nsRect content; - mRenderer.GetButtonContentRect(rect,content); - - // paint the title - const nsStyleFont* fontStyle = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font); - const nsStyleColor* colorStyle = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color); - - aRenderingContext.SetFont(fontStyle->mFont); - - PRBool clipState; - aRenderingContext.PushState(); - aRenderingContext.SetClipRect(rect, nsClipCombine_kIntersect, clipState); - // if disabled paint - if (PR_TRUE == mRenderer.isDisabled()) - { - float p2t; - aPresContext.GetScaledPixelsToTwips(&p2t); - nscoord pixel = NSIntPixelsToTwips(1, p2t); - - aRenderingContext.SetColor(NS_RGB(255,255,255)); - aRenderingContext.DrawString(label, content.x + pixel, content.y+ pixel); - } - - aRenderingContext.SetColor(colorStyle->mColor); - aRenderingContext.DrawString(label, content.x, content.y); - aRenderingContext.PopState(clipState); - } - - return NS_OK; -} - void nsButtonControlFrame::MouseClicked(nsIPresContext* aPresContext) @@ -367,82 +215,6 @@ nsButtonControlFrame::MouseClicked(nsIPresContext* aPresContext) } } -NS_METHOD -nsButtonControlFrame::Reflow(nsIPresContext& aPresContext, - nsHTMLReflowMetrics& aDesiredSize, - const nsHTMLReflowState& aReflowState, - nsReflowStatus& aStatus) -{ - - // add ourself as an nsIFormControlFrame - if (!mFormFrame && (eReflowReason_Initial == aReflowState.reason)) { - nsFormFrame::AddFormControlFrame(aPresContext, *this); - } - - PRInt32 type; - GetType(&type); - - nsWidgetRendering mode; - aPresContext.GetWidgetRenderingMode(&mode); - - if (eWidgetRendering_Gfx == mode || eWidgetRendering_PartialGfx == mode || NS_FORM_INPUT_IMAGE == type) { - // add ourself as an nsIFormControlFrame - if (!mFormFrame && (eReflowReason_Initial == aReflowState.reason)) { - nsFormFrame::AddFormControlFrame(aPresContext, *this); - } - - if ((NS_FORMSIZE_NOTSET != mSuggestedWidth) && ( - NS_FORMSIZE_NOTSET != mSuggestedHeight)) - { - aDesiredSize.width = mSuggestedWidth; - aDesiredSize.height = mSuggestedHeight; - aDesiredSize.ascent = mSuggestedHeight; - aDesiredSize.descent = 0; - if (aDesiredSize.maxElementSize) { - aDesiredSize.maxElementSize->width = mSuggestedWidth; - aDesiredSize.maxElementSize->height = mSuggestedWidth; - } - - if (nsnull != aDesiredSize.maxElementSize) { - aDesiredSize.maxElementSize->width = aDesiredSize.width; - aDesiredSize.maxElementSize->height = aDesiredSize.height; - } - - aStatus = NS_FRAME_COMPLETE; - return NS_OK; - - } - - nsSize ignore; - GetDesiredSize(&aPresContext, aReflowState, aDesiredSize, ignore); - - // if our size is intrinsic. Then we need to return the size we really need - // so include our inner borders we use for focus. - nsMargin added = mRenderer.GetAddedButtonBorderAndPadding(); - if (aReflowState.mComputedWidth == NS_INTRINSICSIZE) - aDesiredSize.width += added.left + added.right; - - if (aReflowState.mComputedHeight == NS_INTRINSICSIZE) - aDesiredSize.height += added.top + added.bottom; - - nsMargin bp(0,0,0,0); - AddBordersAndPadding(&aPresContext, aReflowState, aDesiredSize, bp); - - - if (nsnull != aDesiredSize.maxElementSize) { - aDesiredSize.AddBorderPaddingToMaxElementSize(bp); - aDesiredSize.maxElementSize->width += added.left + added.right; - aDesiredSize.maxElementSize->height += added.top + added.bottom; - - } - aStatus = NS_FRAME_COMPLETE; - return NS_OK; - } - else { - return nsFormControlFrame:: Reflow(aPresContext, aDesiredSize, aReflowState, aStatus); - } -} - void nsButtonControlFrame::GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, @@ -516,30 +288,6 @@ nsButtonControlFrame::GetDesiredSize(nsIPresContext* aPresContext, aDesiredWidgetSize.height= aDesiredLayoutSize.height; } - -void -nsButtonControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight) -{ - nsIButton* button = nsnull; - if (mWidget && (NS_OK == mWidget->QueryInterface(kIButtonIID,(void**)&button))) { - nsFont font(aPresContext->GetDefaultFixedFontDeprecated()); - GetFont(aPresContext, font); - mWidget->SetFont(font); - SetColors(*aPresContext); - - nsAutoString value; - nsresult result = GetValue(&value); - - if (NS_CONTENT_ATTR_HAS_VALUE != result) { - GetDefaultLabel(value); - } - button->SetLabel(value); - NS_RELEASE(button); - - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - } -} - const nsIID& nsButtonControlFrame::GetIID() { @@ -560,32 +308,6 @@ nsButtonControlFrame::GetFrameName(nsString& aResult) const return MakeFrameName("ButtonControl", aResult); } - -void -nsButtonControlFrame::PaintButton(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsString& aLabel, const nsRect& aRect) -{ - -} - -NS_IMETHODIMP -nsButtonControlFrame::HandleEvent(nsIPresContext& aPresContext, - nsGUIEvent* aEvent, - nsEventStatus& aEventStatus) -{ - nsWidgetRendering mode; - aPresContext.GetWidgetRenderingMode(&mode); - - // if disabled do nothing - if (mRenderer.isDisabled()) { - return NS_OK; - } - - return nsFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus); -} - void nsButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) { diff --git a/mozilla/layout/html/forms/src/nsButtonControlFrame.h b/mozilla/layout/html/forms/src/nsButtonControlFrame.h index d6f2433caab..007df32f7c1 100644 --- a/mozilla/layout/html/forms/src/nsButtonControlFrame.h +++ b/mozilla/layout/html/forms/src/nsButtonControlFrame.h @@ -19,13 +19,15 @@ #ifndef nsButtonControlFrame_h___ #define nsButtonControlFrame_h___ -#include "nsFormControlFrame.h" +#include "nsNativeFormControlFrame.h" #include "nsButtonFrameRenderer.h" -class nsButtonControlFrame : public nsFormControlFrame { +class nsButtonControlFrame : public nsNativeFormControlFrame { +private: + typedef nsNativeFormControlFrame Inherited; + public: - nsButtonControlFrame(); // nsFormControlFrame overrides nsresult RequiresWidget(PRBool &aHasWidget); @@ -33,39 +35,8 @@ public: NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); - NS_IMETHOD Paint(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer); - - NS_IMETHOD Reflow(nsIPresContext& aPresContext, - nsHTMLReflowMetrics& aDesiredSize, - const nsHTMLReflowState& aReflowState, - nsReflowStatus& aStatus); - - NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute, - PRInt32 aHint); - - NS_IMETHOD Init(nsIPresContext& aPresContext, - nsIContent* aContent, - nsIFrame* aParent, - nsIStyleContext* aContext, - nsIFrame* asPrevInFlow); - - NS_IMETHOD ReResolveStyleContext ( nsIPresContext* aPresContext, - nsIStyleContext* aParentContext, - PRInt32 aParentChange, - nsStyleChangeList* aChangeList, - PRInt32* aLocalChange) ; - NS_IMETHOD GetFrameName(nsString& aResult) const; - virtual void PostCreateWidget(nsIPresContext* aPresContext, - nscoord& aWidth, - nscoord& aHeight); - virtual void MouseClicked(nsIPresContext* aPresContext); virtual const nsIID& GetCID(); @@ -92,16 +63,6 @@ public: // Sets listener for button click void SetMouseListener(nsIFormControlFrame* aListener) { mMouseListener = aListener; } - virtual void PaintButton(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsString& aLabel, - const nsRect& aRect); - - NS_IMETHOD HandleEvent(nsIPresContext& aPresContext, - nsGUIEvent* aEvent, - nsEventStatus& aEventStatus); - protected: virtual void GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, @@ -115,9 +76,6 @@ protected: nsIFormControlFrame* mMouseListener; // for browse buttons only - - //GFX-rendered state variables - nsButtonFrameRenderer mRenderer; }; diff --git a/mozilla/layout/html/forms/src/nsCheckboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsCheckboxControlFrame.cpp index 0ff3b24bb6c..083a411b7d0 100644 --- a/mozilla/layout/html/forms/src/nsCheckboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsCheckboxControlFrame.cpp @@ -16,129 +16,14 @@ * Reserved. */ +#include "nsCheckboxControlFrame.h" #include "nsICheckButton.h" -#include "nsFormControlFrame.h" -#include "nsFormControlHelper.h" -#include "nsFormFrame.h" -#include "nsIContent.h" -#include "prtypes.h" -#include "nsIFrame.h" -#include "nsIAtom.h" -#include "nsIPresContext.h" -#include "nsIHTMLContent.h" -#include "nsHTMLIIDs.h" +#include "nsNativeFormControlFrame.h" #include "nsWidgetsCID.h" -#include "nsIView.h" +#include "nsIContent.h" #include "nsHTMLAtoms.h" -#include "nsIStyleContext.h" -#include "nsStyleUtil.h" -#include "nsIFormControl.h" -#include "nsIDOMHTMLInputElement.h" -#include "nsCSSRendering.h" -#include "nsILookAndFeel.h" -#include "nsIComponentManager.h" -#define NS_DEFAULT_CHECKBOX_SIZE 12 - -static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID); -static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID); -static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); -static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); - -class nsCheckboxControlFrame : public nsFormControlFrame { -public: - nsCheckboxControlFrame(); - virtual void PostCreateWidget(nsIPresContext* aPresContext, - nscoord& aWidth, - nscoord& aHeight); - - NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute, - PRInt32 aHint); - - NS_IMETHOD GetFrameName(nsString& aResult) const { - return MakeFrameName("CheckboxControl", aResult); - } - - virtual const nsIID& GetCID(); - - virtual const nsIID& GetIID(); - - virtual void MouseClicked(nsIPresContext* aPresContext); - - virtual PRInt32 GetMaxNumValues(); - - virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, - nsString* aValues, nsString* aNames); - - virtual void Reset(); - - // nsIFormControlFrame - NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); - NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); - - // Utility methods for implementing SetProperty/GetProperty - void SetCheckboxControlFrameState(const nsString& aValue); - void GetCheckboxControlFrameState(nsString& aValue); - - // nsFormControlFrame overrides - nsresult RequiresWidget(PRBool &aHasWidget); - - // - // Methods used to GFX-render the checkbox - // - - virtual void PaintCheckBox(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer); - - NS_IMETHOD Paint(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer); - - NS_IMETHOD HandleEvent(nsIPresContext& aPresContext, - nsGUIEvent* aEvent, - nsEventStatus& aEventStatus); - - //End of GFX-rendering methods - -protected: - virtual nscoord GetCheckboxSize(float aPixToTwip) const; - virtual void GetDesiredSize(nsIPresContext* aPresContext, - const nsHTMLReflowState& aReflowState, - nsHTMLReflowMetrics& aDesiredLayoutSize, - nsSize& aDesiredWidgetSize); - - //GFX-rendered state variables - PRBool mMouseDownOnCheckbox; - PRBool mChecked; -}; - -nsresult -NS_NewCheckboxControlFrame(nsIFrame** aNewFrame) -{ - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsCheckboxControlFrame* it = new nsCheckboxControlFrame; - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; -} - -nsCheckboxControlFrame::nsCheckboxControlFrame() -{ - // Initialize GFX-rendered state - mMouseDownOnCheckbox = PR_FALSE; - mChecked = PR_FALSE; -} const nsIID& nsCheckboxControlFrame::GetIID() @@ -154,49 +39,6 @@ nsCheckboxControlFrame::GetCID() return kCheckboxCID; } -nscoord -nsCheckboxControlFrame::GetCheckboxSize(float aPixToTwip) const -{ - nsILookAndFeel * lookAndFeel; - PRInt32 checkboxSize = 0; - if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_CheckboxSize, checkboxSize); - NS_RELEASE(lookAndFeel); - } - if (checkboxSize == 0) - checkboxSize = NS_DEFAULT_CHECKBOX_SIZE; - return NSIntPixelsToTwips(checkboxSize, aPixToTwip); -} - -void -nsCheckboxControlFrame::GetDesiredSize(nsIPresContext* aPresContext, - const nsHTMLReflowState& aReflowState, - nsHTMLReflowMetrics& aDesiredLayoutSize, - nsSize& aDesiredWidgetSize) -{ - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - - nsWidgetRendering mode; - aPresContext->GetWidgetRenderingMode(&mode); - if (eWidgetRendering_Gfx == mode) { - nsFormControlFrame::GetDesiredSize(aPresContext, aReflowState, - aDesiredLayoutSize, aDesiredWidgetSize); - } else { - aDesiredWidgetSize.width = GetCheckboxSize(p2t); - aDesiredWidgetSize.height = aDesiredWidgetSize.width; - aDesiredLayoutSize.width = aDesiredWidgetSize.width; - aDesiredLayoutSize.height = aDesiredWidgetSize.height; - aDesiredLayoutSize.ascent = aDesiredLayoutSize.height; - aDesiredLayoutSize.descent = 0; - if (aDesiredLayoutSize.maxElementSize) { - aDesiredLayoutSize.maxElementSize->width = aDesiredLayoutSize.width; - aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height; - } - } -} - - void nsCheckboxControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight) { @@ -209,48 +51,11 @@ nsCheckboxControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& else SetProperty(nsHTMLAtoms::checked, NS_STRING_FALSE); } - - if (mWidget != nsnull) { - SetColors(*aPresContext); - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - } -} - -NS_IMETHODIMP -nsCheckboxControlFrame::AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute, - PRInt32 aHint) -{ - nsresult result = NS_OK; - if (mWidget) { - if (nsHTMLAtoms::checked == aAttribute) { - nsICheckButton* button = nsnull; - result = mWidget->QueryInterface(GetIID(), (void**)&button); - if ((NS_SUCCEEDED(result)) && (nsnull != button)) { - PRBool checkedAttr; - GetCurrentCheckState(&checkedAttr); - PRBool checkedPrevState; - button->GetState(checkedPrevState); - if (checkedAttr != checkedPrevState) { - button->SetState(checkedAttr); - } - NS_RELEASE(button); - } - } - // Allow the base class to handle common attributes supported - // by all form elements... - else { - result = nsFormControlFrame::AttributeChanged(aPresContext, aChild, aAttribute, aHint); - } - } - return result; } void nsCheckboxControlFrame::MouseClicked(nsIPresContext* aPresContext) { - mMouseDownOnCheckbox = PR_FALSE; PRBool oldState; GetCurrentCheckState(&oldState); PRBool newState = oldState ? PR_FALSE : PR_TRUE; @@ -275,22 +80,10 @@ nsCheckboxControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValue } PRBool result = PR_TRUE; - PRBool state = PR_FALSE; + PRBool state = GetCheckboxState(); nsAutoString value; nsresult valueResult = GetValue(&value); - - nsICheckButton* checkBox = nsnull; - if (nsnull != mWidget) { - // native-widget - if (NS_SUCCEEDED(mWidget->QueryInterface(kICheckButtonIID,(void**)&checkBox))) { - checkBox->GetState(state); - NS_RELEASE(checkBox); - } - } else { - // gfx-rendered - state = mChecked; - } if (PR_TRUE != state) { result = PR_FALSE; @@ -315,59 +108,6 @@ nsCheckboxControlFrame::Reset() SetCurrentCheckState(checked); } -void -nsCheckboxControlFrame::PaintCheckBox(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer) -{ - aRenderingContext.PushState(); - - float p2t; - aPresContext.GetScaledPixelsToTwips(&p2t); - - PRBool checked = PR_FALSE; - - // Get current checked state through content model. - // XXX: This is very inefficient, but it is necessary in the case of printing. - // During printing the Paint is called but the actual state of the checkbox - // is in a frame in presentation shell 0. - /*XXXnsresult result = */GetCurrentCheckState(&checked); - if (PR_TRUE == checked) { - // Draw check mark - const nsStyleColor* color = (const nsStyleColor*) - mStyleContext->GetStyleData(eStyleStruct_Color); - aRenderingContext.SetColor(color->mColor); - nsFormControlHelper::PaintCheckMark(aRenderingContext, - p2t, mRect.width, mRect.height); - - } - PRBool clip; - aRenderingContext.PopState(clip); -} - - -NS_METHOD -nsCheckboxControlFrame::Paint(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer) -{ - - const nsStyleDisplay* disp = (const nsStyleDisplay*) - mStyleContext->GetStyleData(eStyleStruct_Display); - if (!disp->mVisible) - return NS_OK; - - // Paint the background - nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); - if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { - // Paint the checkmark - PaintCheckBox(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); - } - return NS_OK; -} - NS_METHOD nsCheckboxControlFrame::HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus) @@ -389,61 +129,20 @@ NS_METHOD nsCheckboxControlFrame::HandleEvent(nsIPresContext& aPresContext, break; } - if (nsnull == mWidget) { - // Handle GFX rendered widget Mouse Down event - PRInt32 type; - GetType(&type); - switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - mMouseDownOnCheckbox = PR_TRUE; - //XXX: TODO render gray rectangle on mouse down - break; - - case NS_MOUSE_EXIT: - mMouseDownOnCheckbox = PR_FALSE; - //XXX: TO DO clear gray rectangle on mouse up - break; - - } - } - - return(nsFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus)); + return(Inherited::HandleEvent(aPresContext, aEvent, aEventStatus)); } void nsCheckboxControlFrame::GetCheckboxControlFrameState(nsString& aValue) { - if (nsnull != mWidget) { - nsICheckButton* checkBox = nsnull; - if (NS_OK == mWidget->QueryInterface(kICheckButtonIID,(void**)&checkBox)) { - PRBool state = PR_FALSE; - checkBox->GetState(state); - nsFormControlHelper::GetBoolString(state, aValue); - NS_RELEASE(checkBox); - } - } - else { - // Get the state for GFX-rendered widgets - nsFormControlHelper::GetBoolString(mChecked, aValue); - } + nsFormControlHelper::GetBoolString(GetCheckboxState(), aValue); } void nsCheckboxControlFrame::SetCheckboxControlFrameState(const nsString& aValue) { - if (nsnull != mWidget) { - nsICheckButton* checkBox = nsnull; - if (NS_OK == mWidget->QueryInterface(kICheckButtonIID,(void**)&checkBox)) { - PRBool state = nsFormControlHelper::GetBool(aValue); - checkBox->SetState(state); - NS_RELEASE(checkBox); - } - } - else { - // Set the state for GFX-rendered widgets - mChecked = nsFormControlHelper::GetBool(aValue); - nsFormControlHelper::ForceDrawFrame(this); - } + PRBool state = nsFormControlHelper::GetBool(aValue); + SetCheckboxState(state); } NS_IMETHODIMP nsCheckboxControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) @@ -452,7 +151,7 @@ NS_IMETHODIMP nsCheckboxControlFrame::SetProperty(nsIAtom* aName, const nsString SetCheckboxControlFrameState(aValue); } else { - return nsFormControlFrame::SetProperty(aName, aValue); + return Inherited::SetProperty(aName, aValue); } return NS_OK; @@ -468,7 +167,7 @@ NS_IMETHODIMP nsCheckboxControlFrame::GetProperty(nsIAtom* aName, nsString& aVal GetCheckboxControlFrameState(aValue); } else { - return nsFormControlFrame::GetProperty(aName, aValue); + return Inherited::GetProperty(aName, aValue); } return NS_OK; diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index d21f30f0642..70b47cf01f5 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -416,19 +416,6 @@ NS_IMETHODIMP nsFileControlFrame::GetProperty(nsIAtom* aName, nsString& aValue) return NS_OK; } -PRBool -nsFileControlFrame::HasWidget() -{ - PRBool hasWidget = PR_FALSE; - nsIWidget* widget; - mTextFrame->GetWidget(&widget); - if (widget) { - NS_RELEASE(widget); - hasWidget = PR_TRUE; - } - return(hasWidget); -} - diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.h b/mozilla/layout/html/forms/src/nsFileControlFrame.h index eef454d3327..cb604749742 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.h +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.h @@ -85,8 +85,6 @@ public: virtual nsresult RequiresWidget(PRBool &aRequiresWidget); - PRBool HasWidget(); - // from nsIAnonymousContentCreator NS_IMETHOD CreateAnonymousContent(nsISupportsArray& aChildList); diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp index 4dff9feb9e0..3ea3d5500c2 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp @@ -63,9 +63,7 @@ static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID); nsFormControlFrame::nsFormControlFrame() : nsLeafFrame() { - mLastMouseState = eMouseNone; mDidInit = PR_FALSE; - mWidget = nsnull; mFormFrame = nsnull; mSuggestedWidth = NS_FORMSIZE_NOTSET; mSuggestedHeight = NS_FORMSIZE_NOTSET; @@ -74,7 +72,6 @@ nsFormControlFrame::nsFormControlFrame() nsFormControlFrame::~nsFormControlFrame() { mFormFrame = nsnull; - NS_IF_RELEASE(mWidget); } nsresult @@ -231,101 +228,16 @@ nsFormControlFrame::Reflow(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { - nsresult result = NS_OK; - // add ourself as an nsIFormControlFrame if (!mFormFrame && (eReflowReason_Initial == aReflowState.reason)) { nsFormFrame::AddFormControlFrame(aPresContext, *this); } - nsCOMPtr dx; - aPresContext.GetDeviceContext(getter_AddRefs(dx)); - PRBool requiresWidget = PR_TRUE; - - // Checkto see if the device context supports widgets at all - if (dx) { - dx->SupportsNativeWidgets(requiresWidget); - } - - nsWidgetRendering mode; - aPresContext.GetWidgetRenderingMode(&mode); - if ((eWidgetRendering_Gfx == mode) || (eWidgetRendering_PartialGfx == mode)) { - // Check with the frame to see if requires a widget to render - if (PR_TRUE == requiresWidget) { - RequiresWidget(requiresWidget); - } - } - GetDesiredSize(&aPresContext, aReflowState, aDesiredSize, mWidgetSize); if (!mDidInit) { - if (PR_TRUE == requiresWidget) { - nsCOMPtr presShell; - aPresContext.GetShell(getter_AddRefs(presShell)); - nsCOMPtr viewMan; - presShell->GetViewManager(getter_AddRefs(viewMan)); - nsRect boundBox(0, 0, aDesiredSize.width, aDesiredSize.height); - - // absolutely positioned controls already have a view but not a widget - nsIView* view = nsnull; - GetView(&view); - if (nsnull == view) { - result = nsComponentManager::CreateInstance(kViewCID, nsnull, kIViewIID, (void **)&view); - if (!NS_SUCCEEDED(result)) { - NS_ASSERTION(0, "Could not create view for form control"); - aStatus = NS_FRAME_NOT_COMPLETE; - return result; - } - - nsIFrame* parWithView; - nsIView *parView; - - GetParentWithView(&parWithView); - parWithView->GetView(&parView); - - // initialize the view as hidden since we don't know the (x,y) until Paint - result = view->Init(viewMan, boundBox, parView, nsnull, nsViewVisibility_kHide); - if (NS_OK != result) { - NS_ASSERTION(0, "view initialization failed"); - aStatus = NS_FRAME_NOT_COMPLETE; - return NS_OK; - } - - viewMan->InsertChild(parView, view, 0); - SetView(view); - } - - PRInt32 type; - GetType(&type); - const nsIID& id = GetCID(); - - if ((NS_FORM_INPUT_HIDDEN != type) && (PR_TRUE == requiresWidget)) { - // Do the following only if a widget is created - nsWidgetInitData* initData = GetWidgetInitData(aPresContext); // needs to be deleted - view->CreateWidget(id, initData); - - if (nsnull != initData) { - delete(initData); - } - - // set our widget - result = GetWidget(view, &mWidget); - if ((PR_FALSE == NS_SUCCEEDED(result)) || (nsnull == mWidget)) { // keep the ref on mWidget - NS_ASSERTION(0, "could not get widget"); - } - } - - PostCreateWidget(&aPresContext, aDesiredSize.width, aDesiredSize.height); - mDidInit = PR_TRUE; - - if ((aDesiredSize.width != boundBox.width) || (aDesiredSize.height != boundBox.height)) { - viewMan->ResizeView(view, aDesiredSize.width, aDesiredSize.height); - } - - } else { - PostCreateWidget(&aPresContext, aDesiredSize.width, aDesiredSize.height); - mDidInit = PR_TRUE; - } + PostCreateWidget(&aPresContext, aDesiredSize.width, aDesiredSize.height); + mDidInit = PR_TRUE; } aDesiredSize.ascent = aDesiredSize.height; @@ -340,108 +252,20 @@ nsFormControlFrame::Reflow(nsIPresContext& aPresContext, } -NS_IMETHODIMP -nsFormControlFrame::AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute, - PRInt32 aHint) -{ - if (nsnull != mWidget) { - if (nsHTMLAtoms::disabled == aAttribute) { - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - } - } - return NS_OK; -} - nsWidgetInitData* nsFormControlFrame::GetWidgetInitData(nsIPresContext& aPresContext) { return nsnull; } -void -nsFormControlFrame::SetColors(nsIPresContext& aPresContext) -{ - if (mWidget) { - nsCompatibility mode; - aPresContext.GetCompatibilityMode(&mode); - const nsStyleColor* color = - (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color); - if (nsnull != color) { - if (!(NS_STYLE_BG_COLOR_TRANSPARENT & color->mBackgroundFlags)) { - mWidget->SetBackgroundColor(color->mBackgroundColor); -#ifdef bug_1021_closed - } else if (eCompatibility_NavQuirks == mode) { -#else - } else { -#endif - mWidget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF)); - } - mWidget->SetForegroundColor(color->mColor); - } - } -} - void nsFormControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight) { } -// native widgets don't need to repaint void nsFormControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) { - if (mWidget) { - if (aOn) { - mWidget->SetFocus(); - } - else { - //Unsetting of focus on native widget is accomplised - //by pushing focus up to its parent - nsIWidget *parentWidget = mWidget->GetParent(); - if (parentWidget) { - parentWidget->SetFocus(); - NS_RELEASE(parentWidget); - } - } - } -} - -nsresult -nsFormControlFrame::GetWidget(nsIWidget** aWidget) -{ - if (mWidget) { - NS_ADDREF(mWidget); - *aWidget = mWidget; - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - return NS_OK; - } else { - *aWidget = nsnull; - return NS_FORM_NOTOK; - } -} - -nsresult -nsFormControlFrame::GetWidget(nsIView* aView, nsIWidget** aWidget) -{ - nsIWidget* widget; - aView->GetWidget(widget); - nsresult result; - - if (nsnull == widget) { - *aWidget = nsnull; - result = NS_ERROR_FAILURE; - - } else { - result = widget->QueryInterface(kIWidgetIID, (void**)aWidget); // keep the ref - if (NS_FAILED(result)) { - NS_ASSERTION(0, "The widget interface is invalid"); // need to print out more details of the widget - } - NS_RELEASE(widget); - } - - return result; } const nsIID& @@ -571,74 +395,25 @@ NS_METHOD nsFormControlFrame::HandleEvent(nsIPresContext& aPresContext, return NS_OK; } - if (nsnull != mWidget) { - // make sure that the widget in the event is this input - // XXX if there is no view, it could be an image button. Unfortunately, - // every image button will get every event. - nsIView* view; - GetView(&view); - if (view) { - if (mWidget != aEvent->widget) { - aEventStatus = nsEventStatus_eIgnore; - return NS_OK; - } - } - } - // if not native then use the NS_MOUSE_LEFT_CLICK to see if pressed // unfortunately native widgets don't seem to handle this right. // so use the old code for native stuff. -EDV - if (nsnull == mWidget) { - switch (aEvent->message) { - case NS_MOUSE_LEFT_CLICK: - MouseClicked(&aPresContext); - break; - } - } else { - //printf(" %d %d %d %d (%d,%d) \n", this, aEvent->widget, aEvent->widgetSupports, - // aEvent->message, aEvent->point.x, aEvent->point.y); - - PRInt32 type; - GetType(&type); - switch (aEvent->message) { - case NS_MOUSE_ENTER: - mLastMouseState = eMouseEnter; - break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - if (NS_FORM_INPUT_IMAGE == type) { - mLastMouseState = eMouseDown; - } else { - mLastMouseState = (eMouseEnter == mLastMouseState) ? eMouseDown : eMouseNone; - } - break; - case NS_MOUSE_LEFT_BUTTON_UP: - if (eMouseDown == mLastMouseState) { - MouseClicked(&aPresContext); - } - mLastMouseState = eMouseEnter; - break; - case NS_MOUSE_EXIT: - mLastMouseState = eMouseNone; - break; - case NS_CONTROL_CHANGE: - ControlChanged(&aPresContext); - break; - } - } - - // see if a key was pressed - switch (aEvent->message) { - case NS_KEY_DOWN: - if (NS_KEY_EVENT == aEvent->eventStructType) { - nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; - if (NS_VK_RETURN == keyEvent->keyCode) { - EnterPressed(aPresContext); - } - else if (NS_VK_SPACE == keyEvent->keyCode) { + switch (aEvent->message) { + case NS_MOUSE_LEFT_CLICK: MouseClicked(&aPresContext); - } - } - break; + break; + + case NS_KEY_DOWN: + if (NS_KEY_EVENT == aEvent->eventStructType) { + nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; + if (NS_VK_RETURN == keyEvent->keyCode) { + EnterPressed(aPresContext); + } + else if (NS_VK_SPACE == keyEvent->keyCode) { + MouseClicked(&aPresContext); + } + } + break; } aEventStatus = nsEventStatus_eConsumeDoDefault; diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.h b/mozilla/layout/html/forms/src/nsFormControlFrame.h index 4d807356638..847bd3666c7 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.h +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.h @@ -90,11 +90,6 @@ public: const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus); - - NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute, - PRInt32 aHint); // new behavior /** @@ -116,15 +111,6 @@ public: virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues, nsString* aNames); - /** - * Get the widget associated with this frame - * @param aView the view associated with the frame. It is a convience parm. - * @param aWidget the address of address of where the widget will be placed. - * This method doses an AddRef on the widget. - */ - nsresult GetWidget(nsIView* aView, nsIWidget** aWidget); - nsresult GetWidget(nsIWidget** aWidget); - /** * Respond to a enter key being pressed */ @@ -148,8 +134,6 @@ public: nscoord& aWidth, nscoord& aHeight); virtual void SetFocus(PRBool aOn = PR_TRUE, PRBool aRepaint = PR_FALSE); - - void SetColors(nsIPresContext& aPresContext); virtual void Reset(); virtual PRBool IsSuccessful(nsIFormControlFrame* aSubmitter); @@ -272,8 +256,6 @@ protected: nsresult SetDefaultCheckState(PRBool aState); - nsMouseState mLastMouseState; - nsIWidget* mWidget; nsSize mWidgetSize; PRBool mDidInit; nsPoint mLastClickPoint; diff --git a/mozilla/layout/html/forms/src/nsFormFrame.cpp b/mozilla/layout/html/forms/src/nsFormFrame.cpp index c801cc3fda2..99d00cb4a20 100644 --- a/mozilla/layout/html/forms/src/nsFormFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFormFrame.cpp @@ -28,7 +28,7 @@ #include "nsIFormControlFrame.h" #include "nsFormControlFrame.h" #include "nsFileControlFrame.h" -#include "nsRadioControlFrame.h" +#include "nsRadioControlGroup.h" #include "nsIForm.h" #include "nsIFormControl.h" diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp index fb962381fe2..291213013e1 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp @@ -429,7 +429,7 @@ nsGfxTextControlFrame::AttributeChanged(nsIPresContext* aPresContext, // Allow the base class to handle common attributes supported // by all form elements... else { - result = nsFormControlFrame::AttributeChanged(aPresContext, aChild, aAttribute, aHint); + result = Inherited::AttributeChanged(aPresContext, aChild, aAttribute, aHint); } // DUMMY @@ -632,7 +632,7 @@ NS_IMETHODIMP nsGfxTextControlFrame::SetProperty(nsIAtom* aName, const nsString& mEditor->EnableUndo(PR_TRUE); // fire up a new txn stack } else { - return nsFormControlFrame::SetProperty(aName, aValue); + return Inherited::SetProperty(aName, aValue); } return NS_OK; } @@ -646,7 +646,7 @@ NS_IMETHODIMP nsGfxTextControlFrame::GetProperty(nsIAtom* aName, nsString& aValu GetTextControlFrameState(aValue); } else { - return nsFormControlFrame::GetProperty(aName, aValue); + return Inherited::GetProperty(aName, aValue); } return NS_OK; @@ -792,7 +792,7 @@ nsGfxTextControlFrame::Reflow(nsIPresContext& aPresContext, NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow"); - nsresult rv = nsFormControlFrame::Reflow(aPresContext, aMetrics, aReflowState, aStatus); + nsresult rv = Inherited::Reflow(aPresContext, aMetrics, aReflowState, aStatus); #ifdef NOISY printf ("exit nsGfxTextControlFrame::Reflow: size=%d,%d", aMetrics.width, aMetrics.height); diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.h b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.h index 604965be7a7..1a45919b91e 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.h @@ -373,6 +373,9 @@ protected: class nsGfxTextControlFrame : public nsTextControlFrame { +private: + typedef nsFormControlFrame Inherited; + public: nsGfxTextControlFrame(); virtual ~nsGfxTextControlFrame(); diff --git a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp index c608cc9b7d9..139a0542419 100644 --- a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp @@ -175,7 +175,7 @@ nsNativeTextControlFrame::AttributeChanged(nsIPresContext* aPresContext, // Allow the base class to handle common attributes supported // by all form elements... else { - result = nsFormControlFrame::AttributeChanged(aPresContext, aChild, aAttribute, aHint); + result = Inherited::AttributeChanged(aPresContext, aChild, aAttribute, aHint); } NS_RELEASE(text); } @@ -206,12 +206,12 @@ nsNativeTextControlFrame::AttributeChanged(nsIPresContext* aPresContext, // Allow the base class to handle common attributes supported // by all form elements... else { - result = nsFormControlFrame::AttributeChanged(aPresContext, aChild, aAttribute, aHint); + result = Inherited::AttributeChanged(aPresContext, aChild, aAttribute, aHint); } NS_RELEASE(textArea); } else { // We didn't get a Text or TextArea. Uh oh... - result = nsFormControlFrame::AttributeChanged(aPresContext, aChild, aAttribute, aHint); + result = Inherited::AttributeChanged(aPresContext, aChild, aAttribute, aHint); } } } @@ -331,7 +331,7 @@ nsNativeTextControlFrame::PaintTextControlBackground(nsIPresContext& aPresContex nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) { - nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); + Inherited::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); } void @@ -563,7 +563,7 @@ NS_IMETHODIMP nsNativeTextControlFrame::SetProperty(nsIAtom* aName, const nsStri } } else { - return nsFormControlFrame::SetProperty(aName, aValue); + return Inherited::SetProperty(aName, aValue); } return rv; } @@ -577,7 +577,7 @@ NS_IMETHODIMP nsNativeTextControlFrame::GetProperty(nsIAtom* aName, nsString& aV GetTextControlFrameState(aValue); } else { - return nsFormControlFrame::GetProperty(aName, aValue); + return Inherited::GetProperty(aName, aValue); } return NS_OK; diff --git a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h index 86d6c43e066..d999b1b8b2d 100644 --- a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h +++ b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h @@ -26,6 +26,9 @@ class nsIPresContext; class nsNativeTextControlFrame : public nsTextControlFrame { +private: + typedef nsNativeFormControlFrame Inherited; + public: // nsIFormControlFrame NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); diff --git a/mozilla/layout/html/forms/src/nsRadioControlFrame.cpp b/mozilla/layout/html/forms/src/nsRadioControlFrame.cpp index 272ee40a4c2..c0aa59ac8b0 100644 --- a/mozilla/layout/html/forms/src/nsRadioControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsRadioControlFrame.cpp @@ -17,70 +17,18 @@ */ #include "nsRadioControlFrame.h" -#include "nsFormControlFrame.h" -#include "nsIContent.h" -#include "prtypes.h" -#include "nsIFrame.h" -#include "nsISupports.h" -#include "nsIAtom.h" -#include "nsIPresContext.h" -#include "nsIHTMLContent.h" -#include "nsHTMLIIDs.h" #include "nsIRadioButton.h" +#include "nsNativeFormControlFrame.h" #include "nsWidgetsCID.h" -#include "nsSize.h" +#include "nsIContent.h" #include "nsHTMLAtoms.h" -#include "nsIFormControl.h" -#include "nsIFormManager.h" -#include "nsIView.h" -#include "nsIStyleContext.h" -#include "nsStyleUtil.h" #include "nsFormFrame.h" -#include "nsIDOMHTMLInputElement.h" #include "nsINameSpaceManager.h" -#include "nsILookAndFeel.h" -#include "nsIComponentManager.h" -#include "nsCOMPtr.h" -#include "nsCSSRendering.h" -static NS_DEFINE_IID(kIRadioIID, NS_IRADIOBUTTON_IID); -static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); -static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID); -static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); -static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); - -#define NS_DEFAULT_RADIOBOX_SIZE 12 static NS_DEFINE_IID(kIRadioControlFrameIID, NS_IRADIOCONTROLFRAME_IID); -nsresult -NS_NewRadioControlFrame(nsIFrame** aNewFrame) -{ - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsRadioControlFrame* it = new nsRadioControlFrame; - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; -} -nsRadioControlFrame::nsRadioControlFrame() -{ - // Initialize GFX-rendered state - mChecked = PR_FALSE; - mRadioButtonFaceStyle = nsnull; -} - -nsRadioControlFrame::~nsRadioControlFrame() -{ - NS_IF_RELEASE(mRadioButtonFaceStyle); -} - -//-------------------------------------------------------------- nsresult nsRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) { @@ -93,13 +41,14 @@ nsRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) return NS_OK; } - return nsFormControlFrame::QueryInterface(aIID, aInstancePtr); + return Inherited::QueryInterface(aIID, aInstancePtr); } const nsIID& nsRadioControlFrame::GetIID() { + static NS_DEFINE_IID(kIRadioIID, NS_IRADIOBUTTON_IID); return kIRadioIID; } @@ -111,84 +60,6 @@ nsRadioControlFrame::GetCID() } -NS_IMETHODIMP -nsRadioControlFrame::ReResolveStyleContext(nsIPresContext* aPresContext, - nsIStyleContext* aParentContext, - PRInt32 aParentChange, - nsStyleChangeList* aChangeList, - PRInt32* aLocalChange) -{ - // this re-resolves |mStyleContext|, so it may change - nsresult rv = nsFormControlFrame::ReResolveStyleContext(aPresContext, aParentContext, aParentChange, - aChangeList, aLocalChange); - if (NS_FAILED(rv)) { - return rv; - } - - if (NS_COMFALSE != rv) { // frame style changed - if (aLocalChange) { - aParentChange = *aLocalChange; // tell children about or change - } - } - - // see if the outline has changed. - nsCOMPtr oldRadioButtonFaceStyle = mRadioButtonFaceStyle; - aPresContext->ProbePseudoStyleContextFor(mContent, nsHTMLAtoms::radioPseudo, mStyleContext, - PR_FALSE, - &mRadioButtonFaceStyle); - - if ((mRadioButtonFaceStyle && oldRadioButtonFaceStyle.get()) && (mRadioButtonFaceStyle != oldRadioButtonFaceStyle.get())) { - nsFormControlFrame::CaptureStyleChangeFor(this, oldRadioButtonFaceStyle, mRadioButtonFaceStyle, - aParentChange, aChangeList, aLocalChange); - } - - return rv; -} - - -nscoord -nsRadioControlFrame::GetRadioboxSize(float aPixToTwip) const -{ - nsILookAndFeel * lookAndFeel; - PRInt32 radioboxSize = 0; - if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_RadioboxSize, radioboxSize); - NS_RELEASE(lookAndFeel); - } - if (radioboxSize == 0) - radioboxSize = NS_DEFAULT_RADIOBOX_SIZE; - return NSIntPixelsToTwips(radioboxSize, aPixToTwip); -} - -void -nsRadioControlFrame::GetDesiredSize(nsIPresContext* aPresContext, - const nsHTMLReflowState& aReflowState, - nsHTMLReflowMetrics& aDesiredLayoutSize, - nsSize& aDesiredWidgetSize) -{ - - nsWidgetRendering mode; - aPresContext->GetWidgetRenderingMode(&mode); - if ((eWidgetRendering_Gfx == mode) || (eWidgetRendering_PartialGfx == mode)) { - nsFormControlFrame::GetDesiredSize(aPresContext,aReflowState,aDesiredLayoutSize, - aDesiredWidgetSize); - } else { - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - aDesiredWidgetSize.width = GetRadioboxSize(p2t); - aDesiredWidgetSize.height = aDesiredWidgetSize.width; - - aDesiredLayoutSize.width = aDesiredWidgetSize.width; - aDesiredLayoutSize.height = aDesiredWidgetSize.height; - aDesiredLayoutSize.ascent = aDesiredLayoutSize.height; - aDesiredLayoutSize.descent = 0; - if (aDesiredLayoutSize.maxElementSize) { - aDesiredLayoutSize.maxElementSize->width = aDesiredLayoutSize.width; - aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height; - } - } -} - void nsRadioControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight) { @@ -201,52 +72,6 @@ nsRadioControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWi else SetRadioControlFrameState(NS_STRING_FALSE); } - - if (mWidget != nsnull) { - const nsStyleColor* color = - nsStyleUtil::FindNonTransparentBackground(mStyleContext); - - if (nsnull != color) { - mWidget->SetBackgroundColor(color->mBackgroundColor); - } else { - mWidget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF)); - } - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - } - -} - - -NS_IMETHODIMP -nsRadioControlFrame::AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute, - PRInt32 aHint) -{ - nsresult result = NS_OK; - if (mWidget) { - if (nsHTMLAtoms::checked == aAttribute) { - nsIRadioButton* button = nsnull; - result = mWidget->QueryInterface(kIRadioIID, (void**)&button); - if ((NS_SUCCEEDED(result)) && (nsnull != button)) { - PRBool checkedAttr = PR_TRUE; - GetCurrentCheckState(&checkedAttr); - PRBool checkedPrevState = PR_TRUE; - button->GetState(checkedPrevState); - if (checkedAttr != checkedPrevState) { - button->SetState(checkedAttr); - mFormFrame->OnRadioChecked(*this, checkedAttr); - } - NS_RELEASE(button); - } - } - // Allow the base class to handle common attributes supported - // by all form elements... - else { - result = nsFormControlFrame::AttributeChanged(aPresContext, aChild, aAttribute, aHint); - } - } - return result; } void @@ -304,17 +129,7 @@ nsRadioControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, return PR_FALSE; } - PRBool state = PR_FALSE; - - if (nsnull == mWidget) { - state = mChecked; - } else { - nsIRadioButton* radio = nsnull; - if (mWidget && (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio))) { - radio->GetState(state); - NS_RELEASE(radio); - } - } + PRBool state = GetRadioState(); if(PR_TRUE != state) { return PR_FALSE; @@ -342,61 +157,6 @@ nsRadioControlFrame::Reset() SetCurrentCheckState(checked); } - -// CLASS nsRadioControlGroup - -nsRadioControlGroup::nsRadioControlGroup(nsString& aName) -:mName(aName), mCheckedRadio(nsnull) -{ -} - -nsRadioControlGroup::~nsRadioControlGroup() -{ - mCheckedRadio = nsnull; -} - -PRInt32 -nsRadioControlGroup::GetRadioCount() const -{ - return mRadios.Count(); -} - -nsRadioControlFrame* -nsRadioControlGroup::GetRadioAt(PRInt32 aIndex) const -{ - return (nsRadioControlFrame*) mRadios.ElementAt(aIndex); -} - -PRBool -nsRadioControlGroup::AddRadio(nsRadioControlFrame* aRadio) -{ - return mRadios.AppendElement(aRadio); -} - -PRBool -nsRadioControlGroup::RemoveRadio(nsRadioControlFrame* aRadio) -{ - return mRadios.RemoveElement(aRadio); -} - -nsRadioControlFrame* -nsRadioControlGroup::GetCheckedRadio() -{ - return mCheckedRadio; -} - -void -nsRadioControlGroup::SetCheckedRadio(nsRadioControlFrame* aRadio) -{ - mCheckedRadio = aRadio; -} - -void -nsRadioControlGroup::GetName(nsString& aNameResult) const -{ - aNameResult = mName; -} - NS_IMETHODIMP nsRadioControlFrame::GetFrameName(nsString& aResult) const { @@ -407,63 +167,10 @@ nsRadioControlFrame::GetFrameName(nsString& aResult) const NS_IMETHODIMP nsRadioControlFrame::SetRadioButtonFaceStyleContext(nsIStyleContext *aRadioButtonFaceStyleContext) { - mRadioButtonFaceStyle = aRadioButtonFaceStyleContext; - NS_ADDREF(mRadioButtonFaceStyle); - return NS_OK; + /* for gfx widgets only */ + return NS_OK; } -void -nsRadioControlFrame::PaintRadioButton(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect) -{ - - PRBool checked = PR_TRUE; - GetCurrentCheckState(&checked); // Get check state from the content model - if (PR_TRUE == checked) { - // Paint the button for the radio button using CSS background rendering code - if (nsnull != mRadioButtonFaceStyle) { - const nsStyleColor* myColor = (const nsStyleColor*) - mRadioButtonFaceStyle->GetStyleData(eStyleStruct_Color); - const nsStyleSpacing* mySpacing = (const nsStyleSpacing*) - mRadioButtonFaceStyle->GetStyleData(eStyleStruct_Spacing); - const nsStylePosition* myPosition = (const nsStylePosition*) - mRadioButtonFaceStyle->GetStyleData(eStyleStruct_Position); - - nscoord width = myPosition->mWidth.GetCoordValue(); - nscoord height = myPosition->mHeight.GetCoordValue(); - // Position the button centered within the radio control's rectangle. - nscoord x = (mRect.width - width) / 2; - nscoord y = (mRect.height - height) / 2; - nsRect rect(x, y, width, height); - - nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, - aDirtyRect, rect, *myColor, *mySpacing, 0, 0); - nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, rect, *mySpacing, mRadioButtonFaceStyle, 0); - } - } -} - -NS_METHOD -nsRadioControlFrame::Paint(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer) -{ - const nsStyleDisplay* disp = (const nsStyleDisplay*) - mStyleContext->GetStyleData(eStyleStruct_Display); - if (!disp->mVisible) - return NS_OK; - - // Paint the background - nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); - - if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { - PaintRadioButton(aPresContext, aRenderingContext, aDirtyRect); - } - return NS_OK; -} NS_METHOD nsRadioControlFrame::HandleEvent(nsIPresContext& aPresContext, @@ -487,44 +194,18 @@ nsRadioControlFrame::HandleEvent(nsIPresContext& aPresContext, break; } - return(nsFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus)); + return(Inherited::HandleEvent(aPresContext, aEvent, aEventStatus)); } void nsRadioControlFrame::GetRadioControlFrameState(nsString& aValue) { - if (nsnull != mWidget) { - nsIRadioButton* radio = nsnull; - if (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio)) { - PRBool state = PR_FALSE; - radio->GetState(state); - nsFormControlHelper::GetBoolString(state, aValue); - NS_RELEASE(radio); - } - } - else { - // Get the state for GFX-rendered widgets - nsFormControlHelper::GetBoolString(mChecked, aValue); - } + nsFormControlHelper::GetBoolString(GetRadioState(), aValue); } void nsRadioControlFrame::SetRadioControlFrameState(const nsString& aValue) { - if (nsnull != mWidget) { - nsIRadioButton* radio = nsnull; - if (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio)) { - if (aValue == NS_STRING_TRUE) - radio->SetState(PR_TRUE); - else - radio->SetState(PR_FALSE); - - NS_RELEASE(radio); - } - } - else { - // Set the state for GFX-rendered widgets - mChecked = nsFormControlHelper::GetBool(aValue); - nsFormControlHelper::ForceDrawFrame(this); - } + PRBool state = nsFormControlHelper::GetBool(aValue); + SetRadioState(state); } NS_IMETHODIMP nsRadioControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) @@ -537,7 +218,7 @@ NS_IMETHODIMP nsRadioControlFrame::SetProperty(nsIAtom* aName, const nsString& a } } else { - return nsFormControlFrame::SetProperty(aName, aValue); + return Inherited::SetProperty(aName, aValue); } return NS_OK; @@ -552,7 +233,7 @@ NS_IMETHODIMP nsRadioControlFrame::GetProperty(nsIAtom* aName, nsString& aValue) GetRadioControlFrameState(aValue); } else { - return nsFormControlFrame::GetProperty(aName, aValue); + return Inherited::GetProperty(aName, aValue); } return NS_OK; diff --git a/mozilla/layout/html/forms/src/nsRadioControlFrame.h b/mozilla/layout/html/forms/src/nsRadioControlFrame.h index 8f596536b6e..9851b07fef2 100644 --- a/mozilla/layout/html/forms/src/nsRadioControlFrame.h +++ b/mozilla/layout/html/forms/src/nsRadioControlFrame.h @@ -20,18 +20,19 @@ #define nsRadioControlFrame_h___ #include "nsIRadioControlFrame.h" -#include "nsFormControlFrame.h" +#include "nsNativeFormControlFrame.h" #include "nsVoidArray.h" #include "nsString.h" class nsIAtom; // nsRadioControlFrame -class nsRadioControlFrame : public nsFormControlFrame, public nsIRadioControlFrame +class nsRadioControlFrame : public nsNativeFormControlFrame, public nsIRadioControlFrame { +private: + typedef nsNativeFormControlFrame Inherited; + public: - nsRadioControlFrame(); - ~nsRadioControlFrame(); // nsFormControlFrame overrides nsresult RequiresWidget(PRBool &aHasWidget); @@ -44,11 +45,6 @@ public: nscoord& aWidth, nscoord& aHeight); - NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute, - PRInt32 aHint); - NS_IMETHOD GetFrameName(nsString& aResult) const; //nsIRadioControlFrame methods @@ -69,26 +65,12 @@ public: virtual const nsIID& GetIID(); - NS_IMETHOD ReResolveStyleContext(nsIPresContext* aPresContext, - nsIStyleContext* aParentContext, - PRInt32 aParentChange, - nsStyleChangeList* aChangeList, - PRInt32* aLocalChange); - // // 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, - nsFramePaintLayer aWhichLayer); - - virtual void PaintRadioButton(nsIPresContext& aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); NS_IMETHOD HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, @@ -102,45 +84,15 @@ protected: void SetRadioControlFrameState(const nsString& aValue); void GetRadioControlFrameState(nsString& aValue); - virtual nscoord GetRadioboxSize(float aPixToTwip) const; - virtual void GetDesiredSize(nsIPresContext* aPresContext, - const nsHTMLReflowState& aReflowState, - nsHTMLReflowMetrics& aDesiredLayoutSize, - nsSize& aDesiredWidgetSize); - //GFX-rendered state variables - PRBool mChecked; - - nsIStyleContext* mRadioButtonFaceStyle; +protected: + virtual PRBool GetRadioState() = 0; + virtual void SetRadioState(PRBool aValue) = 0; private: NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } }; -// nsRadioControlGroup - -class nsRadioControlGroup -{ -public: - nsRadioControlGroup(nsString& aName); - virtual ~nsRadioControlGroup(); - - PRBool AddRadio(nsRadioControlFrame* aRadio); - PRInt32 GetRadioCount() const; - nsRadioControlFrame* GetRadioAt(PRInt32 aIndex) const; - PRBool RemoveRadio(nsRadioControlFrame* aRadio); - - nsRadioControlFrame* GetCheckedRadio(); - void SetCheckedRadio(nsRadioControlFrame* aRadio); - void GetName(nsString& aNameResult) const; - -protected: - nsString mName; - nsVoidArray mRadios; - nsRadioControlFrame* mCheckedRadio; - -}; - #endif diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.h b/mozilla/layout/html/forms/src/nsTextControlFrame.h index 989f6d70815..075a830883c 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.h +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.h @@ -19,12 +19,12 @@ #ifndef nsTextControlFrame_h___ #define nsTextControlFrame_h___ -#include "nsFormControlFrame.h" +#include "nsNativeFormControlFrame.h" class nsIContent; class nsIFrame; class nsIPresContext; -class nsTextControlFrame : public nsFormControlFrame +class nsTextControlFrame : public nsNativeFormControlFrame { /* ---------- methods implemented by base class ---------- */ public: diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index ffa75c02123..2659db59274 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -798,22 +798,22 @@ nsCSSFrameConstructor::CreateInputFrame(nsIPresContext *aPresContext, nsAutoString val; if (NS_OK == aContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, val)) { if (val.EqualsIgnoreCase("submit")) { - rv = NS_NewButtonControlFrame(&aFrame); + rv = ConstructButtonControlFrame(aPresContext, aFrame); } else if (val.EqualsIgnoreCase("reset")) { - rv = NS_NewButtonControlFrame(&aFrame); + rv = ConstructButtonControlFrame(aPresContext, aFrame); } else if (val.EqualsIgnoreCase("button")) { - rv = NS_NewButtonControlFrame(&aFrame); + rv = ConstructButtonControlFrame(aPresContext, aFrame); } else if (val.EqualsIgnoreCase("checkbox")) { - rv = NS_NewCheckboxControlFrame(&aFrame); + rv = ConstructCheckboxControlFrame(aPresContext, aFrame); } else if (val.EqualsIgnoreCase("file")) { rv = NS_NewFileControlFrame(&aFrame); } else if (val.EqualsIgnoreCase("hidden")) { - rv = NS_NewButtonControlFrame(&aFrame); + rv = ConstructButtonControlFrame(aPresContext, aFrame); } else if (val.EqualsIgnoreCase("image")) { rv = NS_NewImageControlFrame(&aFrame); @@ -2350,13 +2350,71 @@ nsCSSFrameConstructor::CreatePlaceholderFrameFor(nsIPresContext* aPresContext, return rv; } + +nsWidgetRendering +nsCSSFrameConstructor::GetFormElementRenderingMode(nsIPresContext* aPresContext, + nsWidgetType aWidgetType) +{ + if (!aPresContext) { return eWidgetRendering_Gfx;} + + nsWidgetRendering mode; + aPresContext->GetWidgetRenderingMode(&mode); + + switch (mode) + { + case eWidgetRendering_Gfx: + return eWidgetRendering_Gfx; + + case eWidgetRendering_PartialGfx: + switch (aWidgetType) + { + case eWidgetType_Button: + case eWidgetType_Checkbox: + case eWidgetType_Radio: + case eWidgetType_Text: + return eWidgetRendering_Gfx; + + default: + return eWidgetRendering_Native; + } + + case eWidgetRendering_Native: + PRBool useNativeWidgets = PR_FALSE; + nsIDeviceContext* dc; + aPresContext->GetDeviceContext(&dc); + if (dc) { + PRBool supportsWidgets; + if (NS_SUCCEEDED(dc->SupportsNativeWidgets(supportsWidgets))) { + useNativeWidgets = supportsWidgets; + } + NS_RELEASE(dc); + } + if (useNativeWidgets) + return eWidgetRendering_Native; + else + return eWidgetRendering_Gfx; + } + return eWidgetRendering_Gfx; +} + + nsresult nsCSSFrameConstructor::ConstructRadioControlFrame(nsIPresContext* aPresContext, nsIFrame*& aNewFrame, nsIContent* aContent, nsIStyleContext* aStyleContext) { - nsresult rv = NS_NewRadioControlFrame(&aNewFrame); + nsresult rv = NS_OK; + if (GetFormElementRenderingMode(aPresContext, eWidgetType_Radio) == eWidgetRendering_Gfx) + rv = NS_NewGfxRadioControlFrame(&aNewFrame); + else + rv = NS_NewNativeRadioControlFrame(&aNewFrame); + + if (NS_FAILED(rv)) { + aNewFrame = nsnull; + return rv; + } + nsCOMPtr radioStyle; aPresContext->ResolvePseudoStyleContextFor(aContent, nsHTMLAtoms::radioPseudo, aStyleContext, PR_FALSE, getter_AddRefs(radioStyle)); @@ -2368,6 +2426,38 @@ nsCSSFrameConstructor::ConstructRadioControlFrame(nsIPresContext* aPresContext, return rv; } +nsresult +nsCSSFrameConstructor::ConstructCheckboxControlFrame(nsIPresContext* aPresContext, + nsIFrame*& aNewFrame) +{ + nsresult rv = NS_OK; + if (GetFormElementRenderingMode(aPresContext, eWidgetType_Checkbox) == eWidgetRendering_Gfx) + rv = NS_NewGfxCheckboxControlFrame(&aNewFrame); + else + rv = NS_NewNativeCheckboxControlFrame(&aNewFrame); + + if (NS_FAILED(rv)) { + aNewFrame = nsnull; + } + return rv; +} + +nsresult +nsCSSFrameConstructor::ConstructButtonControlFrame(nsIPresContext* aPresContext, + nsIFrame*& aNewFrame) +{ + nsresult rv = NS_OK; + if (GetFormElementRenderingMode(aPresContext, eWidgetType_Button) == eWidgetRendering_Gfx) + rv = NS_NewGfxButtonControlFrame(&aNewFrame); + else + rv = NS_NewNativeButtonControlFrame(&aNewFrame); + + if (NS_FAILED(rv)) { + aNewFrame = nsnull; + } + return rv; +} + nsresult nsCSSFrameConstructor::ConstructTextControlFrame(nsIPresContext* aPresContext, nsIFrame*& aNewFrame) @@ -2517,12 +2607,12 @@ nsCSSFrameConstructor::ConstructSelectFrame(nsIPresContext* aPresContex } NS_RELEASE(select); } else { - rv = NS_NewSelectControlFrame(&aNewFrame); + rv = NS_NewNativeSelectControlFrame(&aNewFrame); } } else { // Not frame based. Use a SelectFrame which creates a native widget. - rv = NS_NewSelectControlFrame(&aNewFrame); + rv = NS_NewNativeSelectControlFrame(&aNewFrame); } return rv; @@ -2866,7 +2956,7 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresContext* aPresContext, // Create a frame based on the tag if (aTag == nsXULAtoms::button) - rv = NS_NewButtonControlFrame(&newFrame); + rv = ConstructButtonControlFrame(aPresContext, newFrame); else if (aTag == nsXULAtoms::checkbox) rv = NS_NewTriStateCheckboxFrame(&newFrame); else if (aTag == nsXULAtoms::spinner) diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.h b/mozilla/layout/html/style/src/nsCSSFrameConstructor.h index f698058b3c7..3fa35437abb 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.h +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.h @@ -20,6 +20,7 @@ #include "nsIStyleFrameConstruction.h" #include "nslayout.h" +#include "nsIPresContext.h" class nsIDocument; struct nsFrameItems; @@ -404,11 +405,20 @@ protected: nsIFrame* aParentFrame, nsIFrame*& aFrame); + nsWidgetRendering GetFormElementRenderingMode(nsIPresContext* aPresContext, + nsWidgetType aWidgetType); + nsresult ConstructRadioControlFrame(nsIPresContext* aPresContext, nsIFrame*& aNewFrame, nsIContent* aContent, nsIStyleContext* aStyleContext); + nsresult ConstructCheckboxControlFrame(nsIPresContext* aPresContext, + nsIFrame*& aNewFrame); + + nsresult ConstructButtonControlFrame(nsIPresContext* aPresContext, + nsIFrame*& aNewFrame); + nsresult ConstructTextControlFrame(nsIPresContext* aPresContext, nsIFrame*& aNewFrame); diff --git a/mozilla/layout/macbuild/layout.mcp b/mozilla/layout/macbuild/layout.mcp index b8b2c536db75f8f2ab79cb939a8abc56e7f8988a..18eba6cb2c25921aae5e832adaaac53bca64bcde 100644 GIT binary patch delta 1909 zcmeHIT}+!*7(Vam&*+RBLYK8ru*!&Y*s{T*UMUp^PPVl{=FPG(=vqPBehqDvcmYEq zQEx{57EYpz@>6K(m|^+mnz%*LxF7kaS0*Ng-56ttV08WrV|~xQ)7p!9=cOlk@;uKu z?>T+WcTT@=ST+pD4aIIr@)1Hbgure>8&?TEc(K?7m1#ogDk1g+A$xJ0rb)};Lk(SR ze$N4)$L|S*8=C8%lwI&d*(OdkYOzL3=oAw7J9H>?geH|3uw%Up7x)T$u-Pu5o)vl- z^_>NJx$7SPr(*gmc71O z1MY=qrAx|??*+{RxE;O?dJ}=M=?(ci$$38pqGu6zH=sNf?9|B9W7;B1v(wpCB(b%}a&u~+KyTisG1+$H&}UVa=Q9Mk00 zSoChm@0SADUC?mw&;dLJv*4Enmk16EE)`rRI4-yxm+j5|c8TUCZ#OQg6@#OK#|0+@ zznhn(R3B&ycfRVuX?ig{B6v)2Oz?!@VZpLs=wJgjcn}_C*Ew~vzid#Vy!g6J6LnZv z^*&gGOUzOO>$=PMD<8AMTG)i^to(5(WsmF!i{Tn}e~Gvu|8RQRisBc>dyke})^8SC-4Yq`F7Gm{~tga@c&o&}p&g#|(?9?=RyV=ZZ|8#O)p%&M7c-*hFOWpPAADh2s?e1WZ1VVh$ znFy3-SNc2xrqbrNQ=O8iZS0aF!MtK#klND+eUK_!g#KNr{RwDoONY@FPCD zG)>Kz=+DN~H#Qz`6w7B>VHK^=jiH=VB@aEXN}hN@l|1gEDtXo=Rq~+As^lqGRLLWz z^Cf=**$jVDw)JUx8%__^(K8TZgLTwiQf2jrgFZZREkAd)^*oQ(#lEhid-QL-hcDf= mRDpwj0p(>ggj78zCg`%|gbWPegckPwGqf7kQl@(Pmi}+aiQk0) delta 2662 zcma*pdr(wW90&08JM5zC^x&ngB49k!c<-V!+GN0(8wd!}lGPH65|)avjaXUg28!8` zw0MB4RPr#hvHsBR)Hz3^bI&>V zw(c>t3R7@NMMW87%#Sge!T8)B##8qPn<=o1G2X*iLOWy0vYdC-r%w?1G%IXaMpq2- zU|@WgM2oK)<-y2!oB9SR4r8rWU#&V9O2Scer+-7)$VlUM)m3EW{&f==OI_?;vXHKm zXkTiUiII_QGquDGq9AeT@hma1)TZW?n#WM5SXP#z?k>yo6DC)->6q-cL4Fg|rLN_E z^?A`^-!4OtIX^eoE>HjOCs6dR4pH}Cs3mGs=k`V#CI#Cvv**jpn+!vt5JmkHX`9lN zK-KDj{scc83R;_QrlG$ye&B%kNAD{EDKsMgPhwSy=_8r=SbmR+6;=Dx=IZI3BGkj1 zDCOugw1=IWx_BZ=~mLBf78p4#fu=ctDdo{0L7fpJG`|54t%TKF>D z3YWm8uoRZS)$mbWYSm>IkgtciC?D;AjUKysB`Pe|W#1zn44-oQMsf z-tX`acukiV!8o5$j63xNwV@yZ=D|fGe2rOL+!rEl^@K(n80|rWM%V;f&|tfm+Z*nd zW9mR65IzVWf<|c9W#7VH873${#u->ljooP80Qawu>mgwZEVCo0!l5M}{Ai}*Px zd(t|hO+H0uU$i!`NqUygLFrN036H@pcpQELyWt6V5`GF#!O!65@C&JLU{53QB|HPa zf@k5^@Edpzo`<;O^c`ZX8tOrenLvGr<>GMr#sjN?en0{49AS0PCFFmEKf#~jFYs4* z84kiB_#4D(qG6j`zadvpfGI*)W;D9YLQwuE{0m-(H{jp!CLGb_3=+gt<@bn`wUKk= zjA%!L-SADA3@y6c1Ml!D>ehz2u?+MFfSgXDsL}|h!6~o-n&BjPH!OoI;7XVX^hBP;qVhU>-U=fkuMb|LWud=0)1pM=X{1uTcpz_k$T zpSuxP!D?6owSA#LyWovTG{MdAMX10Xuo>=zEwB}~i3{td-X=RX5TYV2=#?olhtpFO0@3R$CYKteO#9ESKiL+SatPU+MEVNkbVl8nF`_@8- zy|6}{sY$C(Kd&4LqP_Kbxn9qBx}UtRg_Oiq&$&iYWWuDrGql0uO|GUYl1YE^hMlC1 z(cYPFk<)36kgr3@N}hp7dBqss6QE?7d5pIsj1PyP%#|d|RI66DavqOSiYHR6GA@%} zCDycnzd{X)X8})~JZ