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 "nsGfxCheckboxControlFrame.h"
|
|
|
|
#include "nsICheckButton.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsFormFrame.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2000-02-09 22:34:39 +03:00
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIPresState.h"
|
2000-03-24 18:02:02 +03:00
|
|
|
#include "nsCSSRendering.h"
|
1999-08-06 09:13:07 +04:00
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//------------------------------------------------------------
|
1999-08-06 09:13:07 +04:00
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewGfxCheckboxControlFrame(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
|
|
|
nsGfxCheckboxControlFrame* it = new (aPresShell) nsGfxCheckboxControlFrame;
|
1999-08-06 09:13:07 +04:00
|
|
|
if (!it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-11 08:45:49 +04:00
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//------------------------------------------------------------
|
1999-08-11 08:45:49 +04:00
|
|
|
// Initialize GFX-rendered state
|
1999-08-06 09:13:07 +04:00
|
|
|
nsGfxCheckboxControlFrame::nsGfxCheckboxControlFrame()
|
2000-03-24 18:02:02 +03:00
|
|
|
: mChecked(eOff),
|
2000-08-03 02:07:46 +04:00
|
|
|
mCheckButtonFaceStyle(nsnull),
|
|
|
|
mInClickEvent(PR_FALSE)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-03-24 18:02:02 +03:00
|
|
|
nsGfxCheckboxControlFrame::~nsGfxCheckboxControlFrame()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mCheckButtonFaceStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Frames are not refcounted, no need to AddRef
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aInstancePtr, "QueryInterface requires a non-NULL destination!");
|
|
|
|
if ( !aInstancePtr )
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
|
|
|
|
*aInstancePtr = (void*)(nsIStatefulFrame*) this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-24 18:02:02 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsICheckboxControlFrame))) {
|
|
|
|
*aInstancePtr = (void*) ((nsICheckboxControlFrame*) this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-09 22:34:39 +03:00
|
|
|
return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
2000-03-24 18:02:02 +03:00
|
|
|
//--------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxCheckboxControlFrame::SetCheckboxFaceStyleContext(nsIStyleContext *aCheckboxFaceStyleContext)
|
|
|
|
{
|
|
|
|
mCheckButtonFaceStyle = aCheckboxFaceStyleContext;
|
|
|
|
NS_ADDREF(mCheckButtonFaceStyle);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-03 02:07:46 +04:00
|
|
|
//--------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxCheckboxControlFrame::SetIsInClickEvent(PRBool aVal)
|
|
|
|
{
|
|
|
|
mInClickEvent = aVal;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Init
|
|
|
|
//
|
|
|
|
// We need to override this in order to see if we're a tristate checkbox.
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxCheckboxControlFrame::Init(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsFormControlFrame::Init ( aPresContext, aContent, aParent, aContext, aPrevInFlow );
|
|
|
|
|
|
|
|
// figure out if we're a tristate at the start. This may change later on once
|
|
|
|
// we've been running for a while, so more code is in AttributeChanged() to pick
|
|
|
|
// that up. Regardless, we need this check when initializing.
|
|
|
|
nsAutoString value;
|
|
|
|
nsresult res = mContent->GetAttribute ( kNameSpaceID_None, GetTristateAtom(), value );
|
|
|
|
if ( res == NS_CONTENT_ATTR_HAS_VALUE )
|
|
|
|
mIsTristate = PR_TRUE;
|
|
|
|
|
|
|
|
// give the attribute a default value so it's always present, if we're a tristate
|
|
|
|
if ( IsTristateCheckbox() )
|
2000-04-16 15:19:26 +04:00
|
|
|
mContent->SetAttribute ( kNameSpaceID_None, GetTristateValueAtom(), NS_ConvertASCIItoUCS2("0"), PR_FALSE );
|
2000-02-09 22:34:39 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-24 18:02:02 +03:00
|
|
|
//--------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxCheckboxControlFrame::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_CHECKBOX_CONTROL_FRAME_FACE_CONTEXT_INDEX:
|
|
|
|
*aStyleContext = mCheckButtonFaceStyle;
|
|
|
|
NS_IF_ADDREF(*aStyleContext);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxCheckboxControlFrame::SetAdditionalStyleContext(PRInt32 aIndex,
|
|
|
|
nsIStyleContext* aStyleContext)
|
|
|
|
{
|
|
|
|
if (aIndex < 0) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_GFX_CHECKBOX_CONTROL_FRAME_FACE_CONTEXT_INDEX:
|
|
|
|
NS_IF_RELEASE(mCheckButtonFaceStyle);
|
|
|
|
mCheckButtonFaceStyle = aStyleContext;
|
|
|
|
NS_IF_ADDREF(aStyleContext);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// GetTristateAtom [static]
|
|
|
|
//
|
|
|
|
// Use a lazily instantiated static initialization scheme to create an atom that
|
|
|
|
// represents the attribute set when this should be a tri-state checkbox.
|
|
|
|
//
|
|
|
|
// Does NOT addref!
|
|
|
|
//
|
|
|
|
nsIAtom*
|
|
|
|
nsGfxCheckboxControlFrame :: GetTristateAtom ( )
|
|
|
|
{
|
|
|
|
return nsHTMLAtoms::moz_tristate;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// GetTristateValueAtom [static]
|
|
|
|
//
|
|
|
|
// Use a lazily instantiated static initialization scheme to create an atom that
|
|
|
|
// represents the attribute that holds the value when the button is a tri-state (since
|
|
|
|
// we can't use "checked").
|
|
|
|
//
|
|
|
|
// Does NOT addref!
|
|
|
|
//
|
|
|
|
nsIAtom*
|
|
|
|
nsGfxCheckboxControlFrame :: GetTristateValueAtom ( )
|
|
|
|
{
|
|
|
|
return nsHTMLAtoms::moz_tristatevalue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// AttributeChanged
|
|
|
|
//
|
|
|
|
// Override to check for the attribute that determines if we're a normal or a
|
|
|
|
// tristate checkbox. If we notice a switch from one to the other, we need
|
|
|
|
// to adjust the proper attributes in the content model accordingly.
|
|
|
|
//
|
|
|
|
// Also, since the value of a tri-state is kept in a separate attribute (we
|
|
|
|
// can't use "checked" because it's a boolean), we have to notice it changing
|
|
|
|
// here.
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxCheckboxControlFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
if ( aAttribute == GetTristateAtom() ) {
|
|
|
|
nsAutoString value;
|
|
|
|
nsresult res = mContent->GetAttribute ( kNameSpaceID_None, GetTristateAtom(), value );
|
|
|
|
PRBool isNowTristate = (res == NS_CONTENT_ATTR_HAS_VALUE);
|
|
|
|
if ( isNowTristate != mIsTristate )
|
|
|
|
SwitchModesWithEmergencyBrake(aPresContext, isNowTristate);
|
|
|
|
}
|
|
|
|
else if ( aAttribute == GetTristateValueAtom() ) {
|
|
|
|
// ignore this change if we're not a tri-state checkbox
|
|
|
|
if ( IsTristateCheckbox() ) {
|
|
|
|
nsAutoString value;
|
|
|
|
nsresult res = mContent->GetAttribute ( kNameSpaceID_None, GetTristateValueAtom(), value );
|
|
|
|
if ( res == NS_CONTENT_ATTR_HAS_VALUE )
|
|
|
|
SetCheckboxControlFrameState(aPresContext, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return nsFormControlFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// InitializeControl
|
|
|
|
//
|
|
|
|
// Set the default checked state of the checkbox.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsGfxCheckboxControlFrame::InitializeControl(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsFormControlFrame::InitializeControl(aPresContext);
|
|
|
|
|
|
|
|
PRBool checked = PR_FALSE;
|
|
|
|
nsresult result = GetDefaultCheckState(&checked);
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
|
|
|
SetCheckboxState (aPresContext, checked ? eOn : eOff );
|
|
|
|
}
|
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
|
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
|
|
|
nsGfxCheckboxControlFrame::PaintCheckBox(nsIPresContext* aPresContext,
|
2000-02-09 22:34:39 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
|
|
|
|
float p2t;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
1999-08-06 09:13:07 +04:00
|
|
|
|
1999-08-27 18:31:59 +04:00
|
|
|
const nsStyleSpacing* spacing =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
|
|
|
|
nsRect checkRect(0,0, mRect.width, mRect.height);
|
|
|
|
|
|
|
|
nsMargin borderPadding;
|
|
|
|
spacing->CalcBorderPaddingFor(this, borderPadding);
|
|
|
|
checkRect.Deflate(borderPadding);
|
|
|
|
|
|
|
|
const nsStyleColor* color = (const nsStyleColor*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
aRenderingContext.SetColor(color->mColor);
|
|
|
|
|
1999-08-11 08:45:49 +04:00
|
|
|
if ( IsTristateCheckbox() ) {
|
|
|
|
// Get current checked state through content model.
|
|
|
|
// XXX this won't work under printing. does that matter???
|
|
|
|
CheckState checked = GetCheckboxState();
|
|
|
|
switch ( checked ) {
|
|
|
|
case eOn:
|
1999-08-27 18:31:59 +04:00
|
|
|
nsFormControlHelper::PaintCheckMark(aRenderingContext, p2t, checkRect);
|
1999-08-11 08:45:49 +04:00
|
|
|
break;
|
1999-08-27 18:31:59 +04:00
|
|
|
|
1999-08-11 08:45:49 +04:00
|
|
|
case eMixed:
|
1999-08-27 18:31:59 +04:00
|
|
|
PaintMixedMark(aRenderingContext, p2t, checkRect);
|
1999-08-11 08:45:49 +04:00
|
|
|
break;
|
1999-10-20 22:59:00 +04:00
|
|
|
|
|
|
|
// no special drawing otherwise
|
|
|
|
default:
|
|
|
|
break;
|
1999-08-11 08:45:49 +04:00
|
|
|
} // case of value of checkbox
|
1999-08-27 18:31:59 +04:00
|
|
|
} else {
|
1999-08-06 09:13:07 +04:00
|
|
|
// 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.
|
1999-08-11 08:45:49 +04:00
|
|
|
PRBool checked = PR_FALSE;
|
|
|
|
GetCurrentCheckState(&checked);
|
|
|
|
if ( checked ) {
|
1999-08-27 18:31:59 +04:00
|
|
|
nsFormControlHelper::PaintCheckMark(aRenderingContext, p2t, checkRect);
|
1999-08-11 08:45:49 +04:00
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
1999-08-11 08:45:49 +04:00
|
|
|
|
1999-08-06 09:13:07 +04:00
|
|
|
PRBool clip;
|
|
|
|
aRenderingContext.PopState(clip);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//------------------------------------------------------------
|
1999-08-11 08:45:49 +04:00
|
|
|
//
|
|
|
|
// PaintMixedMark
|
|
|
|
//
|
|
|
|
// Like nsFormControlHelper::PaintCheckMark(), but paints the horizontal "mixed"
|
|
|
|
// bar inside the box. Only used for tri-state checkboxes.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsGfxCheckboxControlFrame::PaintMixedMark ( nsIRenderingContext& aRenderingContext,
|
1999-08-27 18:31:59 +04:00
|
|
|
float aPixelsToTwips, const nsRect& aRect)
|
1999-08-11 08:45:49 +04:00
|
|
|
{
|
|
|
|
const PRUint32 checkpoints = 4;
|
|
|
|
const PRUint32 checksize = 6; //This is value is determined by added 2 units to the end
|
|
|
|
//of the 7X& pixel rectangle below to provide some white space
|
|
|
|
//around the checkmark when it is rendered.
|
|
|
|
|
|
|
|
// Points come from the coordinates on a 7X7 pixels
|
|
|
|
// box with 0,0 at the lower left.
|
|
|
|
nscoord checkedPolygonDef[] = { 1,2, 5,2, 5,4, 1,4 };
|
|
|
|
// Location of the center point of the checkmark
|
|
|
|
const PRUint32 centerx = 3;
|
|
|
|
const PRUint32 centery = 3;
|
|
|
|
|
|
|
|
nsPoint checkedPolygon[checkpoints];
|
|
|
|
PRUint32 defIndex = 0;
|
|
|
|
PRUint32 polyIndex = 0;
|
|
|
|
|
|
|
|
// Scale the checkmark based on the smallest dimension
|
1999-08-27 18:31:59 +04:00
|
|
|
PRUint32 size = aRect.width / checksize;
|
|
|
|
if (aRect.height < aRect.width)
|
|
|
|
size = aRect.height / checksize;
|
1999-08-11 08:45:49 +04:00
|
|
|
|
|
|
|
// Center and offset each point in the polygon definition.
|
|
|
|
for (defIndex = 0; defIndex < (checkpoints * 2); defIndex++) {
|
1999-08-27 18:31:59 +04:00
|
|
|
checkedPolygon[polyIndex].x = nscoord((((checkedPolygonDef[defIndex]) - centerx) * (size)) + (aRect.width / 2) + aRect.x);
|
1999-08-11 08:45:49 +04:00
|
|
|
defIndex++;
|
1999-08-27 18:31:59 +04:00
|
|
|
checkedPolygon[polyIndex].y = nscoord((((checkedPolygonDef[defIndex]) - centery) * (size)) + (aRect.height / 2) + aRect.y);
|
1999-08-11 08:45:49 +04:00
|
|
|
polyIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRenderingContext.FillPolygon(checkedPolygon, checkpoints);
|
|
|
|
|
|
|
|
} // PaintMixedMark
|
|
|
|
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//------------------------------------------------------------
|
1999-08-06 09:13:07 +04:00
|
|
|
NS_METHOD
|
1999-11-24 09:03:41 +03:00
|
|
|
nsGfxCheckboxControlFrame::Paint(nsIPresContext* aPresContext,
|
1999-08-06 09:13:07 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)
|
1999-08-11 08:45:49 +04:00
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
2000-03-17 13:15:13 +03:00
|
|
|
if (!disp->IsVisible())
|
1999-08-11 08:45:49 +04:00
|
|
|
return NS_OK;
|
1999-08-06 09:13:07 +04:00
|
|
|
|
1999-08-11 08:45:49 +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) {
|
2000-03-24 18:02:02 +03:00
|
|
|
PRBool doDefaultPainting = PR_TRUE;
|
1999-08-11 08:45:49 +04:00
|
|
|
// Paint the checkmark
|
2000-03-24 18:02:02 +03:00
|
|
|
if (nsnull != mCheckButtonFaceStyle && GetCheckboxState() == eOn) {
|
|
|
|
const nsStyleColor* myColor = (const nsStyleColor*)
|
|
|
|
mCheckButtonFaceStyle->GetStyleData(eStyleStruct_Color);
|
|
|
|
|
|
|
|
if (myColor->mBackgroundImage.Length() > 0) {
|
|
|
|
const nsStyleSpacing* mySpacing = (const nsStyleSpacing*)
|
|
|
|
mCheckButtonFaceStyle->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
const nsStylePosition* myPosition = (const nsStylePosition*)
|
|
|
|
mCheckButtonFaceStyle->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, mCheckButtonFaceStyle, 0);
|
|
|
|
doDefaultPainting = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doDefaultPainting) {
|
|
|
|
PaintCheckBox(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
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
|
|
|
//------------------------------------------------------------
|
|
|
|
nsGfxCheckboxControlFrame::CheckState
|
|
|
|
nsGfxCheckboxControlFrame::GetCheckboxState ( )
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
2000-08-03 02:07:46 +04:00
|
|
|
// If we are processing an onclick event then
|
|
|
|
// always return the opposite value
|
|
|
|
// additional explanantion is in nsICheckboxControlFrame or nsHTMLInputElement.cpp
|
|
|
|
if (mInClickEvent) {
|
|
|
|
if (!IsTristateCheckbox()) {
|
|
|
|
return mChecked == eOn? eOff : eOn;
|
|
|
|
} else {
|
|
|
|
switch (mChecked) {
|
|
|
|
case eOff: return eOn;
|
|
|
|
case eOn: return eMixed;
|
|
|
|
case eMixed: return eOff;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
return mChecked;
|
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//------------------------------------------------------------
|
1999-08-11 08:45:49 +04:00
|
|
|
void
|
2000-02-09 22:34:39 +03:00
|
|
|
nsGfxCheckboxControlFrame::SetCheckboxState (nsIPresContext* aPresContext,
|
|
|
|
nsGfxCheckboxControlFrame::CheckState 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
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//------------------------------------------------------------
|
|
|
|
void nsGfxCheckboxControlFrame::GetCheckboxControlFrameState(nsString& aValue)
|
|
|
|
{
|
|
|
|
CheckStateToString(GetCheckboxState(), aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
void nsGfxCheckboxControlFrame::SetCheckboxControlFrameState(nsIPresContext* aPresContext,
|
|
|
|
const nsString& aValue)
|
|
|
|
{
|
|
|
|
CheckState state = StringToCheckState(aValue);
|
|
|
|
SetCheckboxState(aPresContext, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsGfxCheckboxControlFrame::SetProperty(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aName,
|
|
|
|
const nsString& aValue)
|
|
|
|
{
|
|
|
|
if (nsHTMLAtoms::checked == aName)
|
|
|
|
SetCheckboxControlFrameState(aPresContext, aValue);
|
|
|
|
else
|
|
|
|
return nsFormControlFrame::SetProperty(aPresContext, aName, aValue);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsGfxCheckboxControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)
|
|
|
|
{
|
|
|
|
if (nsHTMLAtoms::checked == aName)
|
|
|
|
GetCheckboxControlFrameState(aValue);
|
|
|
|
else
|
|
|
|
return nsFormControlFrame::GetProperty(aName, aValue);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
PRInt32
|
|
|
|
nsGfxCheckboxControlFrame::GetMaxNumValues()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
PRBool
|
|
|
|
nsGfxCheckboxControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
|
|
|
|
nsString* aValues, nsString* aNames)
|
|
|
|
{
|
|
|
|
nsAutoString name;
|
|
|
|
nsresult nameResult = GetName(&name);
|
|
|
|
if ((aMaxNumValues <= 0) || (NS_CONTENT_ATTR_HAS_VALUE != nameResult)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool result = PR_TRUE;
|
|
|
|
CheckState state = GetCheckboxState();
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
nsresult valueResult = GetValue(&value);
|
|
|
|
|
|
|
|
if (eOn != state) {
|
|
|
|
result = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE != valueResult) {
|
2000-04-16 15:19:26 +04:00
|
|
|
aValues[0].AssignWithConversion("on");
|
2000-02-09 22:34:39 +03:00
|
|
|
} else {
|
|
|
|
aValues[0] = value;
|
|
|
|
}
|
|
|
|
aNames[0] = name;
|
|
|
|
aNumValues = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsGfxCheckboxControlFrame::Reset(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
PRBool checked;
|
|
|
|
GetDefaultCheckState(&checked);
|
|
|
|
SetCheckboxState (aPresContext, checked ? eOn : eOff );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// CheckStateToString
|
|
|
|
//
|
|
|
|
// Converts from a CheckState to a string
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsGfxCheckboxControlFrame::CheckStateToString ( CheckState inState, nsString& outStateAsString )
|
|
|
|
{
|
|
|
|
switch ( inState ) {
|
|
|
|
case eOn:
|
2000-04-16 15:19:26 +04:00
|
|
|
outStateAsString.AssignWithConversion(NS_STRING_TRUE);
|
2000-02-09 22:34:39 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eOff:
|
2000-04-16 15:19:26 +04:00
|
|
|
outStateAsString.AssignWithConversion(NS_STRING_FALSE);
|
2000-02-09 22:34:39 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eMixed:
|
2000-04-16 15:19:26 +04:00
|
|
|
outStateAsString.AssignWithConversion("2");
|
2000-02-09 22:34:39 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // CheckStateToString
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// StringToCheckState
|
|
|
|
//
|
|
|
|
// Converts from a string to a CheckState enum
|
|
|
|
//
|
|
|
|
nsGfxCheckboxControlFrame::CheckState
|
|
|
|
nsGfxCheckboxControlFrame::StringToCheckState ( const nsString & aStateAsString )
|
|
|
|
{
|
2000-04-16 15:19:26 +04:00
|
|
|
if ( aStateAsString.EqualsWithConversion(NS_STRING_TRUE) )
|
2000-02-09 22:34:39 +03:00
|
|
|
return eOn;
|
2000-04-16 15:19:26 +04:00
|
|
|
else if ( aStateAsString.EqualsWithConversion(NS_STRING_FALSE) )
|
2000-02-09 22:34:39 +03:00
|
|
|
return eOff;
|
|
|
|
|
|
|
|
// not true and not false means mixed
|
|
|
|
return eMixed;
|
|
|
|
|
|
|
|
} // StringToCheckState
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SwitchModesWithEmergencyBrake
|
|
|
|
//
|
|
|
|
// Since we use an attribute to decide if we're a tristate box or not, this can change
|
|
|
|
// at any time. Since we have to use separate attributes to store the values depending
|
|
|
|
// on the mode, we have to convert from one to the other.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsGfxCheckboxControlFrame::SwitchModesWithEmergencyBrake ( nsIPresContext* aPresContext,
|
|
|
|
PRBool inIsNowTristate )
|
|
|
|
{
|
|
|
|
if ( inIsNowTristate ) {
|
|
|
|
// we were a normal checkbox, and now we're a tristate. That means that the
|
|
|
|
// state of the checkbox was in "checked" and needs to be copied over into
|
|
|
|
// our parallel attribute.
|
|
|
|
nsAutoString value;
|
|
|
|
CheckStateToString ( GetCheckboxState(), value );
|
|
|
|
mContent->SetAttribute ( kNameSpaceID_None, GetTristateValueAtom(), value, PR_FALSE );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// we were a tri-state checkbox, and now we're a normal checkbox. The current
|
|
|
|
// state is already up to date (because it's always up to date). We just have
|
|
|
|
// to make sure it's not mixed. If it is, just set it to checked. Remove our
|
|
|
|
// parallel attribute so that we're nice and HTML4 compliant.
|
|
|
|
if ( GetCheckboxState() == eMixed )
|
|
|
|
SetCheckboxState(aPresContext, eOn);
|
|
|
|
mContent->UnsetAttribute ( kNameSpaceID_None, GetTristateValueAtom(), PR_FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
// switch!
|
|
|
|
mIsTristate = inIsNowTristate;
|
|
|
|
|
|
|
|
} // SwitchModesWithEmergencyBrake
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIStatefulFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsGfxCheckboxControlFrame::GetStateType(nsIPresContext* aPresContext,
|
|
|
|
nsIStatefulFrame::StateType* aStateType)
|
|
|
|
{
|
|
|
|
*aStateType=nsIStatefulFrame::eCheckboxType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsGfxCheckboxControlFrame::SaveState(nsIPresContext* aPresContext,
|
|
|
|
nsIPresState** aState)
|
|
|
|
{
|
|
|
|
// Construct a pres state.
|
|
|
|
NS_NewPresState(aState); // The addref happens here.
|
|
|
|
|
|
|
|
// This string will hold a single item, whether or not we're checked.
|
|
|
|
nsAutoString stateString;
|
|
|
|
GetCheckboxControlFrameState(stateString);
|
2000-04-16 15:19:26 +04:00
|
|
|
(*aState)->SetStateProperty(NS_ConvertASCIItoUCS2("checked"), stateString);
|
2000-02-09 22:34:39 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsGfxCheckboxControlFrame::RestoreState(nsIPresContext* aPresContext,
|
|
|
|
nsIPresState* aState)
|
|
|
|
{
|
|
|
|
if (!mDidInit) {
|
|
|
|
mPresContext = aPresContext;
|
|
|
|
InitializeControl(aPresContext);
|
|
|
|
mDidInit = PR_TRUE;
|
|
|
|
}
|
|
|
|
nsAutoString string;
|
2000-04-16 15:19:26 +04:00
|
|
|
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string);
|
2000-02-09 22:34:39 +03:00
|
|
|
SetCheckboxControlFrameState(aPresContext, string);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
// Extra Debug Methods
|
|
|
|
//------------------------------------------------------------
|
1999-12-22 22:54:21 +03:00
|
|
|
#ifdef DEBUG_rodsXXX
|
1999-10-08 01:07:38 +04:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsGfxCheckboxControlFrame::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("nsGfxCheckboxControlFrame", aReflowState.reason);
|
2000-02-09 22:34:39 +03:00
|
|
|
nsresult rv = nsFormControlFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1999-10-08 01:07:38 +04:00
|
|
|
|
|
|
|
COMPARE_QUIRK_SIZE("nsGfxCheckboxControlFrame", 13, 13)
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
#endif
|