2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-08-06 09:13:07 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
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.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of 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"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-06 09:13:07 +04:00
|
|
|
|
|
|
|
#include "nsGfxCheckboxControlFrame.h"
|
|
|
|
#include "nsICheckButton.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2000-02-09 22:34:39 +03:00
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIPresState.h"
|
2001-11-16 05:43:23 +03:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDocument.h"
|
2000-03-24 18:02:02 +03:00
|
|
|
#include "nsCSSRendering.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"
|
2002-06-04 04:44:04 +04:00
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
2002-09-21 05:03:38 +04:00
|
|
|
#include "nsITheme.h"
|
2004-03-12 19:51:26 +03:00
|
|
|
#include "imgIRequest.h"
|
2001-04-01 05:01:33 +04:00
|
|
|
|
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()
|
2002-01-24 22:04:55 +03:00
|
|
|
: mCheckButtonFaceStyle(nsnull)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-03-24 18:02:02 +03:00
|
|
|
nsGfxCheckboxControlFrame::~nsGfxCheckboxControlFrame()
|
|
|
|
{
|
2003-02-22 03:32:13 +03:00
|
|
|
if (mCheckButtonFaceStyle)
|
|
|
|
mCheckButtonFaceStyle->Release();
|
2000-03-24 18:02:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2002-03-31 14:14:01 +04:00
|
|
|
|
2000-03-24 18:02:02 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsICheckboxControlFrame))) {
|
|
|
|
*aInstancePtr = (void*) ((nsICheckboxControlFrame*) 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);
|
|
|
|
}
|
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-18 03:52:32 +04:00
|
|
|
NS_IMETHODIMP nsGfxCheckboxControlFrame::GetAccessible(nsIAccessible** aAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
|
|
|
return accService->CreateHTMLCheckboxAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-05-18 03:52:32 +04:00
|
|
|
|
2000-03-24 18:02:02 +03:00
|
|
|
//--------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2003-02-22 03:32:13 +03:00
|
|
|
nsGfxCheckboxControlFrame::SetCheckboxFaceStyleContext(nsStyleContext *aCheckboxFaceStyleContext)
|
2000-03-24 18:02:02 +03:00
|
|
|
{
|
|
|
|
mCheckButtonFaceStyle = aCheckboxFaceStyleContext;
|
2003-02-22 03:32:13 +03:00
|
|
|
mCheckButtonFaceStyle->AddRef();
|
2000-03-24 18:02:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
|
2000-03-24 18:02:02 +03:00
|
|
|
//--------------------------------------------------------------
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext*
|
|
|
|
nsGfxCheckboxControlFrame::GetAdditionalStyleContext(PRInt32 aIndex) const
|
2000-03-24 18:02:02 +03:00
|
|
|
{
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_GFX_CHECKBOX_CONTROL_FRAME_FACE_CONTEXT_INDEX:
|
2003-02-22 03:32:13 +03:00
|
|
|
return mCheckButtonFaceStyle;
|
2000-03-24 18:02:02 +03:00
|
|
|
break;
|
|
|
|
default:
|
2003-02-22 03:32:13 +03:00
|
|
|
return nsnull;
|
2000-03-24 18:02:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
2003-02-22 03:32:13 +03:00
|
|
|
void
|
2000-03-24 18:02:02 +03:00
|
|
|
nsGfxCheckboxControlFrame::SetAdditionalStyleContext(PRInt32 aIndex,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aStyleContext)
|
2000-03-24 18:02:02 +03:00
|
|
|
{
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_GFX_CHECKBOX_CONTROL_FRAME_FACE_CONTEXT_INDEX:
|
2003-02-22 03:32:13 +03:00
|
|
|
if (mCheckButtonFaceStyle)
|
|
|
|
mCheckButtonFaceStyle->Release();
|
2000-03-24 18:02:02 +03:00
|
|
|
mCheckButtonFaceStyle = aStyleContext;
|
2003-02-22 03:32:13 +03:00
|
|
|
if (aStyleContext)
|
|
|
|
aStyleContext->AddRef();
|
2000-03-24 18:02:02 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsGfxCheckboxControlFrame::OnChecked(nsPresContext* aPresContext,
|
2002-01-24 22:04:55 +03:00
|
|
|
PRBool aChecked)
|
2000-02-09 22:34:39 +03:00
|
|
|
{
|
2004-08-26 04:07:56 +04:00
|
|
|
Invalidate(GetOverflowRect(), PR_FALSE);
|
2002-01-24 22:04:55 +03:00
|
|
|
return aChecked;
|
2000-02-09 22:34:39 +03:00
|
|
|
}
|
|
|
|
|
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
|
2004-08-01 03:15:21 +04:00
|
|
|
nsGfxCheckboxControlFrame::PaintCheckBox(nsPresContext* aPresContext,
|
2000-02-09 22:34:39 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* disp = GetStyleDisplay();
|
2002-09-21 05:03:38 +04:00
|
|
|
if (disp->mAppearance) {
|
2004-07-29 23:41:39 +04:00
|
|
|
nsITheme *theme = aPresContext->GetTheme();
|
2002-09-21 05:03:38 +04:00
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, this, disp->mAppearance))
|
|
|
|
return; // No need to paint the checkbox. The theme will do it.
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
// Get current checked state through content model.
|
|
|
|
if (!GetCheckboxState())
|
|
|
|
return; // we're not checked, nothing to paint.
|
1999-08-06 09:13:07 +04:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
aRenderingContext.PushState();
|
1999-08-06 09:13:07 +04:00
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
nsMargin borderPadding(0,0,0,0);
|
|
|
|
CalcBorderPadding(borderPadding);
|
1999-08-27 18:31:59 +04:00
|
|
|
|
|
|
|
nsRect checkRect(0,0, mRect.width, mRect.height);
|
|
|
|
checkRect.Deflate(borderPadding);
|
|
|
|
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleColor* color = GetStyleColor();
|
1999-08-27 18:31:59 +04:00
|
|
|
aRenderingContext.SetColor(color->mColor);
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
nsFormControlHelper::PaintCheckMark(aRenderingContext,
|
|
|
|
aPresContext->ScaledPixelsToTwips(),
|
|
|
|
checkRect);
|
|
|
|
|
2004-04-18 17:13:35 +04:00
|
|
|
aRenderingContext.PopState();
|
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
|
2004-08-01 03:15:21 +04:00
|
|
|
nsGfxCheckboxControlFrame::Paint(nsPresContext* 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) {
|
1999-08-11 08:45:49 +04:00
|
|
|
return NS_OK;
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
|
1999-08-11 08:45:49 +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) {
|
2000-03-24 18:02:02 +03:00
|
|
|
PRBool doDefaultPainting = PR_TRUE;
|
2002-01-24 22:04:55 +03:00
|
|
|
// Paint the checkmark
|
|
|
|
if (!mCheckButtonFaceStyle && GetCheckboxState()) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBackground* myColor = mCheckButtonFaceStyle->GetStyleBackground();
|
2000-03-24 18:02:02 +03:00
|
|
|
|
2003-10-02 02:53:56 +04:00
|
|
|
if (myColor->mBackgroundImage) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBorder* myBorder = mCheckButtonFaceStyle->GetStyleBorder();
|
|
|
|
const nsStylePadding* myPadding = mCheckButtonFaceStyle->GetStylePadding();
|
|
|
|
const nsStylePosition* myPosition = mCheckButtonFaceStyle->GetStylePosition();
|
2000-03-24 18:02:02 +03:00
|
|
|
|
|
|
|
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,
|
2002-10-08 14:24:53 +04:00
|
|
|
aDirtyRect, rect, *myBorder, *myPadding,
|
2003-02-23 05:49:22 +03:00
|
|
|
PR_FALSE);
|
2000-03-24 18:02:02 +03:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
2001-02-07 12:57:26 +03:00
|
|
|
aDirtyRect, rect, *myBorder, mCheckButtonFaceStyle, 0);
|
2000-03-24 18:02:02 +03:00
|
|
|
doDefaultPainting = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doDefaultPainting) {
|
|
|
|
PaintCheckBox(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
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
|
|
|
//------------------------------------------------------------
|
2002-01-24 22:04:55 +03:00
|
|
|
PRBool
|
2000-02-09 22:34:39 +03:00
|
|
|
nsGfxCheckboxControlFrame::GetCheckboxState ( )
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
2002-01-24 22:04:55 +03:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> elem(do_QueryInterface(mContent));
|
|
|
|
PRBool retval = PR_FALSE;
|
|
|
|
elem->GetChecked(&retval);
|
|
|
|
return retval;
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
|
2000-02-09 22:34:39 +03:00
|
|
|
//------------------------------------------------------------
|
|
|
|
// Extra Debug Methods
|
|
|
|
//------------------------------------------------------------
|
1999-12-22 22:54:21 +03:00
|
|
|
#ifdef DEBUG_rodsXXX
|
2002-03-07 23:53:40 +03:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsGfxCheckboxControlFrame::Reflow(nsPresContext* 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);
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
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)
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
1999-10-08 01:07:38 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
#endif
|
2001-11-02 10:40:01 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxCheckboxControlFrame::OnContentReset()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|