1999-08-06 09:13:07 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-08-06 09:13:07 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-08-06 09:13:07 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-08-06 09:13:07 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-08-06 09:13:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsGfxRadioControlFrame.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsFormFrame.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2000-02-09 22:34:39 +03:00
|
|
|
#include "nsIPresState.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-04-01 05:01:33 +04:00
|
|
|
#include "nsIAccessibilityService.h"
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-04-01 05:01:33 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMNode.h"
|
1999-08-06 09:13:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-05 02:49:50 +03:00
|
|
|
nsGfxRadioControlFrame* it = new (aPresShell) nsGfxRadioControlFrame;
|
1999-08-06 09:13:07 +04:00
|
|
|
if (!it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGfxRadioControlFrame::nsGfxRadioControlFrame()
|
|
|
|
{
|
|
|
|
// Initialize GFX-rendered state
|
|
|
|
mChecked = PR_FALSE;
|
|
|
|
mRadioButtonFaceStyle = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
|
|
|
|
{
|
2000-02-09 22:34:39 +03:00
|
|
|
NS_IF_RELEASE(mRadioButtonFaceStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Frames are not refcounted, no need to AddRef
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIRadioControlFrame))) {
|
|
|
|
*aInstancePtr = (void*) ((nsIRadioControlFrame*) this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
|
|
|
|
*aInstancePtr = (void*) ((nsIStatefulFrame*) this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-01 05:01:33 +04:00
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-18 03:52:32 +04:00
|
|
|
NS_IMETHODIMP nsGfxRadioControlFrame::GetAccessible(nsIAccessible** aAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
|
|
|
nsIAccessible* acc = nsnull;
|
|
|
|
return accService->CreateHTMLRadioButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
1999-08-06 09:13:07 +04:00
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//--------------------------------------------------------------
|
1999-09-04 03:36:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxRadioControlFrame::GetAdditionalStyleContext(PRInt32 aIndex,
|
|
|
|
nsIStyleContext** aStyleContext) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aStyleContext, "null OUT parameter pointer");
|
|
|
|
if (aIndex < 0) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
*aStyleContext = nsnull;
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_GFX_RADIO_CONTROL_FRAME_FACE_CONTEXT_INDEX:
|
|
|
|
*aStyleContext = mRadioButtonFaceStyle;
|
1999-09-21 11:56:18 +04:00
|
|
|
NS_IF_ADDREF(*aStyleContext);
|
1999-09-04 03:36:32 +04:00
|
|
|
break;
|
1999-09-21 11:56:18 +04:00
|
|
|
default:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
1999-09-04 03:36:32 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//--------------------------------------------------------------
|
1999-09-04 03:36:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxRadioControlFrame::SetAdditionalStyleContext(PRInt32 aIndex,
|
|
|
|
nsIStyleContext* aStyleContext)
|
|
|
|
{
|
|
|
|
if (aIndex < 0) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_GFX_RADIO_CONTROL_FRAME_FACE_CONTEXT_INDEX:
|
|
|
|
NS_IF_RELEASE(mRadioButtonFaceStyle);
|
|
|
|
mRadioButtonFaceStyle = aStyleContext;
|
|
|
|
NS_IF_ADDREF(aStyleContext);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//--------------------------------------------------------------
|
2000-08-23 21:27:06 +04:00
|
|
|
NS_IMETHODIMP nsGfxRadioControlFrame::SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue)
|
2000-02-09 22:34:39 +03:00
|
|
|
{
|
|
|
|
if (nsHTMLAtoms::checked == aName) {
|
2000-08-23 21:27:06 +04:00
|
|
|
PRBool state = (aValue.Equals(NS_STRING_TRUE)) ? PR_TRUE : PR_FALSE;
|
2000-02-09 22:34:39 +03:00
|
|
|
|
2000-02-16 02:02:55 +03:00
|
|
|
|
|
|
|
// if there is no form than the radiobtn is an orphan
|
2000-02-09 22:34:39 +03:00
|
|
|
if (mFormFrame) {
|
2000-02-16 02:02:55 +03:00
|
|
|
// if this failed then it didn't have a named radio group
|
|
|
|
if (NS_FAILED(mFormFrame->OnRadioChecked(aPresContext, *this, state))) {
|
|
|
|
// The line below is commented out to duplicate NavQuirks behavior
|
|
|
|
//SetRadioState(aPresContext, state);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SetRadioState(aPresContext, state);
|
2000-02-09 22:34:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return nsFormControlFrame::SetProperty(aPresContext, aName, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
2000-08-23 21:27:06 +04:00
|
|
|
NS_IMETHODIMP nsGfxRadioControlFrame::GetProperty(nsIAtom* aName, nsAWritableString& aValue)
|
2000-02-09 22:34:39 +03:00
|
|
|
{
|
|
|
|
// Return the value of the property from the widget it is not null.
|
|
|
|
// If is null, assume the widget is GFX-rendered and return a member variable instead.
|
1999-08-06 09:13:07 +04:00
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
if (nsHTMLAtoms::checked == aName) {
|
|
|
|
nsFormControlHelper::GetBoolString(GetRadioState(), aValue);
|
|
|
|
} else {
|
|
|
|
return nsFormControlFrame::GetProperty(aName, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
PRBool
|
2000-02-15 18:05:56 +03:00
|
|
|
nsGfxRadioControlFrame::GetChecked()
|
2000-02-09 22:34:39 +03:00
|
|
|
{
|
|
|
|
PRBool checked = PR_FALSE;
|
2000-03-17 01:57:08 +03:00
|
|
|
GetCurrentCheckState(&checked);
|
2000-02-15 18:05:56 +03:00
|
|
|
return(checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
PRBool
|
|
|
|
nsGfxRadioControlFrame::GetDefaultChecked()
|
|
|
|
{
|
|
|
|
PRBool checked = PR_FALSE;
|
2000-03-17 01:57:08 +03:00
|
|
|
GetDefaultCheckState(&checked);
|
2000-02-09 22:34:39 +03:00
|
|
|
return(checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsGfxRadioControlFrame::SetChecked(nsIPresContext* aPresContext, PRBool aValue, PRBool aSetInitialValue)
|
|
|
|
{
|
|
|
|
if (aSetInitialValue) {
|
|
|
|
if (aValue) {
|
2001-08-17 12:14:14 +04:00
|
|
|
mContent->SetAttr(kNameSpaceID_HTML, nsHTMLAtoms::checked, NS_ConvertASCIItoUCS2("1"), PR_FALSE); // XXX should be "empty" value
|
2000-02-09 22:34:39 +03:00
|
|
|
} else {
|
2001-08-17 12:14:14 +04:00
|
|
|
mContent->SetAttr(kNameSpaceID_HTML, nsHTMLAtoms::checked, NS_ConvertASCIItoUCS2("0"), PR_FALSE);
|
2000-02-09 22:34:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetRadioState(aPresContext, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
1999-08-06 09:13:07 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxRadioControlFrame::SetRadioButtonFaceStyleContext(nsIStyleContext *aRadioButtonFaceStyleContext)
|
|
|
|
{
|
|
|
|
mRadioButtonFaceStyle = aRadioButtonFaceStyleContext;
|
|
|
|
NS_ADDREF(mRadioButtonFaceStyle);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-03 02:06:33 +04:00
|
|
|
//--------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2000-12-10 19:05:29 +03:00
|
|
|
nsGfxRadioControlFrame::GetRadioGroupSelectedContent(nsIContent ** aRadioBtn)
|
2000-08-03 02:06:33 +04:00
|
|
|
{
|
2000-12-10 19:05:29 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aRadioBtn);
|
|
|
|
nsFormFrame::GetRadioGroupSelectedContent(this, aRadioBtn);
|
2000-08-03 02:06:33 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//--------------------------------------------------------------
|
|
|
|
PRBool
|
|
|
|
nsGfxRadioControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
|
|
|
|
nsString* aValues, nsString* aNames)
|
|
|
|
{
|
|
|
|
nsAutoString name;
|
|
|
|
nsresult result = GetName(&name);
|
|
|
|
if ((aMaxNumValues <= 0) || (NS_CONTENT_ATTR_HAS_VALUE != result)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool state = GetRadioState();
|
|
|
|
|
|
|
|
if(PR_TRUE != state) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
result = GetValue(&value);
|
|
|
|
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
|
|
|
aValues[0] = value;
|
|
|
|
} else {
|
2000-04-16 15:19:26 +04:00
|
|
|
aValues[0].AssignWithConversion("on");
|
2000-02-09 22:34:39 +03:00
|
|
|
}
|
|
|
|
aNames[0] = name;
|
|
|
|
aNumValues = 1;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsGfxRadioControlFrame::Reset(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
PRBool checked = PR_TRUE;
|
|
|
|
GetDefaultCheckState(&checked);
|
|
|
|
SetCurrentCheckState(checked);
|
|
|
|
}
|
|
|
|
|
2000-08-09 03:38:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxRadioControlFrame::HandleEvent(nsIPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
|
|
|
// Check for user-input:none style
|
|
|
|
const nsStyleUserInterface* uiStyle;
|
2000-08-09 04:52:02 +04:00
|
|
|
GetStyleData(eStyleStruct_UserInterface, (const nsStyleStruct *&)uiStyle);
|
2000-08-09 03:38:00 +04:00
|
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
|
|
|
|
// otherwise, do nothing. Events are handled by the DOM.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//--------------------------------------------------------------
|
1999-08-06 09:13:07 +04:00
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
nsGfxRadioControlFrame::PaintRadioButton(nsIPresContext* aPresContext,
|
1999-08-06 09:13:07 +04:00
|
|
|
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) {
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleBackground* myColor = (const nsStyleBackground*)
|
|
|
|
mRadioButtonFaceStyle->GetStyleData(eStyleStruct_Background);
|
|
|
|
|
|
|
|
const nsStyleColor* color = (const nsStyleColor*)
|
1999-08-06 09:13:07 +04:00
|
|
|
mRadioButtonFaceStyle->GetStyleData(eStyleStruct_Color);
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleBorder* myBorder = (const nsStyleBorder*)
|
|
|
|
mRadioButtonFaceStyle->GetStyleData(eStyleStruct_Border);
|
1999-08-06 09:13:07 +04:00
|
|
|
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);
|
|
|
|
|
2000-08-03 02:06:33 +04:00
|
|
|
// So we will use the PaintBackground to paint the dot,
|
|
|
|
// but it uses the mBackgroundColor for painting and we need to use the mColor
|
|
|
|
// so create a temporary style color struct and set it up appropriately
|
2001-06-01 02:19:43 +04:00
|
|
|
nsStyleBackground tmpColor = *myColor;
|
|
|
|
tmpColor.mBackgroundColor = color->mColor;
|
1999-08-06 09:13:07 +04:00
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
2001-02-07 12:57:26 +03:00
|
|
|
aDirtyRect, rect, tmpColor, *myBorder, 0, 0);
|
1999-08-06 09:13:07 +04:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
2001-02-07 12:57:26 +03:00
|
|
|
aDirtyRect, rect, *myBorder, mRadioButtonFaceStyle, 0);
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//--------------------------------------------------------------
|
1999-08-06 09:13:07 +04:00
|
|
|
NS_METHOD
|
2001-09-19 16:35:19 +04:00
|
|
|
nsGfxRadioControlFrame::Paint(nsIPresContext* aPresContext,
|
1999-08-06 09:13:07 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2001-09-19 16:35:19 +04:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
2001-01-27 17:09:34 +03:00
|
|
|
PRBool isVisible;
|
|
|
|
if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) && !isVisible) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
// Paint the background
|
2000-02-09 22:34:39 +03:00
|
|
|
nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1999-08-06 09:13:07 +04:00
|
|
|
|
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
|
|
|
PaintRadioButton(aPresContext, aRenderingContext, aDirtyRect);
|
|
|
|
}
|
2000-08-09 03:38:00 +04:00
|
|
|
|
|
|
|
// Call to the base class to draw selection borders when appropriate
|
|
|
|
return nsFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//--------------------------------------------------------------
|
1999-08-06 09:13:07 +04:00
|
|
|
PRBool nsGfxRadioControlFrame::GetRadioState()
|
|
|
|
{
|
|
|
|
return mChecked;
|
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//--------------------------------------------------------------
|
1999-10-26 08:44:41 +04:00
|
|
|
void nsGfxRadioControlFrame::SetRadioState(nsIPresContext* aPresContext, PRBool aValue)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
|
|
|
mChecked = aValue;
|
1999-10-26 08:44:41 +04:00
|
|
|
nsFormControlHelper::ForceDrawFrame(aPresContext, this);
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
1999-10-08 01:07:38 +04:00
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
void
|
|
|
|
nsGfxRadioControlFrame::InitializeControl(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsFormControlFrame::InitializeControl(aPresContext);
|
|
|
|
|
|
|
|
// set the widget to the initial state
|
|
|
|
PRBool checked = PR_FALSE;
|
|
|
|
nsresult result = GetDefaultCheckState(&checked);
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
|
|
|
SetRadioState(aPresContext, checked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIStatefulFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
|
|
|
|
{
|
2001-02-06 04:59:59 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
2000-02-09 22:34:39 +03:00
|
|
|
|
2001-04-24 12:33:57 +04:00
|
|
|
// Don't save state before we are initialized
|
|
|
|
if (!mDidInit) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-06 04:59:59 +03:00
|
|
|
nsresult res = NS_OK;
|
|
|
|
PRBool stateBool = GetRadioState();
|
|
|
|
PRBool defaultStateBool = GetDefaultChecked();
|
|
|
|
|
|
|
|
// Compare to default value, and only save if needed (Bug 62713)
|
|
|
|
if (stateBool != defaultStateBool) {
|
|
|
|
|
|
|
|
// Get the value string
|
|
|
|
nsAutoString stateString;
|
|
|
|
nsFormControlHelper::GetBoolString(stateBool, stateString);
|
|
|
|
|
|
|
|
// Construct a pres state and store value in it.
|
|
|
|
res = NS_NewPresState(aState);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
res = (*aState)->SetStateProperty(NS_LITERAL_STRING("checked"), stateString);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2000-02-09 22:34:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
|
|
|
|
{
|
2001-02-06 04:59:59 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
if (!mDidInit) {
|
|
|
|
mPresContext = aPresContext;
|
|
|
|
InitializeControl(aPresContext);
|
|
|
|
mDidInit = PR_TRUE;
|
|
|
|
}
|
2000-02-15 18:05:56 +03:00
|
|
|
|
|
|
|
mIsRestored = PR_TRUE;
|
2001-02-06 04:59:59 +03:00
|
|
|
nsAutoString stateString;
|
|
|
|
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("checked"), stateString);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
|
|
|
|
res = SetProperty(aPresContext, nsHTMLAtoms::checked, stateString);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
|
2000-02-15 18:05:56 +03:00
|
|
|
mRestoredChecked = mChecked;
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Extra Debug Helper Methods
|
|
|
|
//----------------------------------------------------------------------
|
1999-12-22 22:52:56 +03:00
|
|
|
#ifdef DEBUG_rodsXXX
|
1999-10-08 01:07:38 +04:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsGfxRadioControlFrame::Reflow(nsIPresContext* aPresContext,
|
1999-10-08 01:07:38 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2000-04-22 01:51:35 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsGfxRadioControlFrame", aReflowState.reason);
|
|
|
|
|
1999-10-08 01:07:38 +04:00
|
|
|
nsresult rv = nsNativeFormControlFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
|
|
|
|
COMPARE_QUIRK_SIZE("nsGfxRadioControlFrame", 12, 11)
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
#endif
|