2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-08-06 09:13:07 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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
|
|
|
*
|
2001-09-29 00:14:13 +04: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.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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"
|
2001-11-16 05:43:23 +03:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDocument.h"
|
2000-02-09 22:34:39 +03:00
|
|
|
#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) {
|
|
|
|
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) {
|
2002-01-11 22:39:51 +03:00
|
|
|
mContent->SetAttr(kNameSpaceID_HTML, nsHTMLAtoms::checked, NS_LITERAL_STRING("1"), PR_FALSE); // XXX should be "empty" value
|
2000-02-09 22:34:39 +03:00
|
|
|
} else {
|
2002-01-11 22:39:51 +03:00
|
|
|
mContent->SetAttr(kNameSpaceID_HTML, nsHTMLAtoms::checked, NS_LITERAL_STRING("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-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
|
2002-01-08 02:46:07 +03:00
|
|
|
// XXXldb It would make more sense to use
|
|
|
|
// |aRenderingContext.FillEllipse| here, but on at least GTK that
|
|
|
|
// doesn't draw a round enough circle.
|
2001-06-01 02:19:43 +04:00
|
|
|
nsStyleBackground tmpColor = *myColor;
|
|
|
|
tmpColor.mBackgroundColor = color->mColor;
|
2002-01-08 02:46:07 +03:00
|
|
|
nsCSSRendering::PaintBackgroundWithSC(aPresContext, aRenderingContext,
|
|
|
|
this, 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
|
2001-11-03 09:23:19 +03:00
|
|
|
nsresult rv = 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);
|
|
|
|
}
|
2001-11-03 09:23:19 +03:00
|
|
|
return rv;
|
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;
|
2002-01-07 23:37:22 +03: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);
|
2001-11-16 05:43:23 +03:00
|
|
|
|
|
|
|
// Only reset on init if this is the primary shell
|
|
|
|
// Temporary workaround until radio state is in content
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
if (!presShell) return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
presShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (!doc) return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> primaryPresShell;
|
|
|
|
doc->GetShellAt(0, getter_AddRefs(primaryPresShell));
|
|
|
|
if (!primaryPresShell) return;
|
|
|
|
|
|
|
|
if (presShell.get() == primaryPresShell.get()) {
|
2002-01-07 23:37:22 +03:00
|
|
|
// set the widget to the initial state
|
|
|
|
// XXX We can't use reset because radio buttons fire onChange
|
|
|
|
// from content (much to our dismay)
|
|
|
|
PRBool checked = PR_FALSE;
|
|
|
|
nsresult rv = GetDefaultCheckState(&checked);
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == rv) {
|
|
|
|
SetRadioState(aPresContext, checked);
|
|
|
|
}
|
2001-11-16 05:43:23 +03:00
|
|
|
}
|
2000-02-09 22:34:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// 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);
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
2000-04-22 01:51:35 +04:00
|
|
|
|
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
|
2001-11-02 10:40:01 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxRadioControlFrame::OnContentReset()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|