mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-02 12:32:55 +00:00
Added new interface to support additional StyleContexts that can be used for "skinning" checkboxes.
r=kmcclusk
This commit is contained in:
parent
2229b04792
commit
decb8aabb8
@ -31,6 +31,7 @@
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIPresState.h"
|
||||
#include "nsCSSRendering.h"
|
||||
|
||||
//------------------------------------------------------------
|
||||
nsresult
|
||||
@ -52,10 +53,17 @@ NS_NewGfxCheckboxControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||
//------------------------------------------------------------
|
||||
// Initialize GFX-rendered state
|
||||
nsGfxCheckboxControlFrame::nsGfxCheckboxControlFrame()
|
||||
: mChecked(eOff)
|
||||
: mChecked(eOff),
|
||||
mCheckButtonFaceStyle(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
nsGfxCheckboxControlFrame::~nsGfxCheckboxControlFrame()
|
||||
{
|
||||
NS_IF_RELEASE(mCheckButtonFaceStyle);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsISupports
|
||||
//----------------------------------------------------------------------
|
||||
@ -70,9 +78,22 @@ nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr
|
||||
*aInstancePtr = (void*)(nsIStatefulFrame*) this;
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsICheckboxControlFrame))) {
|
||||
*aInstancePtr = (void*) ((nsICheckboxControlFrame*) this);
|
||||
return NS_OK;
|
||||
}
|
||||
return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsGfxCheckboxControlFrame::SetCheckboxFaceStyleContext(nsIStyleContext *aCheckboxFaceStyleContext)
|
||||
{
|
||||
mCheckButtonFaceStyle = aCheckboxFaceStyleContext;
|
||||
NS_ADDREF(mCheckButtonFaceStyle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
//
|
||||
// Init
|
||||
@ -103,6 +124,48 @@ nsGfxCheckboxControlFrame::Init(nsIPresContext* aPresContext,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
//
|
||||
// GetTristateAtom [static]
|
||||
@ -312,8 +375,36 @@ nsGfxCheckboxControlFrame::Paint(nsIPresContext* aPresContext,
|
||||
// Paint the background
|
||||
nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
||||
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
||||
PRBool doDefaultPainting = PR_TRUE;
|
||||
// Paint the checkmark
|
||||
PaintCheckBox(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
||||
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);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -24,13 +24,19 @@
|
||||
|
||||
#include "nsFormControlFrame.h"
|
||||
#include "nsIStatefulFrame.h"
|
||||
#include "nsICheckboxControlFrame.h"
|
||||
|
||||
|
||||
#define NS_GFX_CHECKBOX_CONTROL_FRAME_FACE_CONTEXT_INDEX 0 // for additional style contexts
|
||||
#define NS_GFX_CHECKBOX_CONTROL_FRAME_LAST_CONTEXT_INDEX 0
|
||||
|
||||
class nsGfxCheckboxControlFrame : public nsFormControlFrame,
|
||||
public nsIStatefulFrame
|
||||
public nsIStatefulFrame,
|
||||
public nsICheckboxControlFrame
|
||||
{
|
||||
public:
|
||||
nsGfxCheckboxControlFrame();
|
||||
virtual ~nsGfxCheckboxControlFrame();
|
||||
|
||||
#ifdef DEBUG
|
||||
NS_IMETHOD GetFrameName(nsString& aResult) const {
|
||||
@ -57,8 +63,16 @@ public:
|
||||
const nsRect& aDirtyRect,
|
||||
nsFramePaintLayer aWhichLayer);
|
||||
|
||||
//nsIRadioControlFrame methods
|
||||
NS_IMETHOD SetCheckboxFaceStyleContext(nsIStyleContext *aCheckboxFaceStyleContext);
|
||||
|
||||
void InitializeControl(nsIPresContext* aPresContext);
|
||||
|
||||
NS_IMETHOD GetAdditionalStyleContext(PRInt32 aIndex,
|
||||
nsIStyleContext** aStyleContext) const;
|
||||
NS_IMETHOD SetAdditionalStyleContext(PRInt32 aIndex,
|
||||
nsIStyleContext* aStyleContext);
|
||||
|
||||
// nsIFormControlFrame
|
||||
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsString& aValue);
|
||||
NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue);
|
||||
@ -121,6 +135,7 @@ protected:
|
||||
|
||||
//GFX-rendered state variables
|
||||
CheckState mChecked;
|
||||
nsIStyleContext* mCheckButtonFaceStyle;
|
||||
|
||||
private:
|
||||
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIPresState.h"
|
||||
#include "nsCSSRendering.h"
|
||||
|
||||
//------------------------------------------------------------
|
||||
nsresult
|
||||
@ -52,10 +53,17 @@ NS_NewGfxCheckboxControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||
//------------------------------------------------------------
|
||||
// Initialize GFX-rendered state
|
||||
nsGfxCheckboxControlFrame::nsGfxCheckboxControlFrame()
|
||||
: mChecked(eOff)
|
||||
: mChecked(eOff),
|
||||
mCheckButtonFaceStyle(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
nsGfxCheckboxControlFrame::~nsGfxCheckboxControlFrame()
|
||||
{
|
||||
NS_IF_RELEASE(mCheckButtonFaceStyle);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsISupports
|
||||
//----------------------------------------------------------------------
|
||||
@ -70,9 +78,22 @@ nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr
|
||||
*aInstancePtr = (void*)(nsIStatefulFrame*) this;
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsICheckboxControlFrame))) {
|
||||
*aInstancePtr = (void*) ((nsICheckboxControlFrame*) this);
|
||||
return NS_OK;
|
||||
}
|
||||
return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsGfxCheckboxControlFrame::SetCheckboxFaceStyleContext(nsIStyleContext *aCheckboxFaceStyleContext)
|
||||
{
|
||||
mCheckButtonFaceStyle = aCheckboxFaceStyleContext;
|
||||
NS_ADDREF(mCheckButtonFaceStyle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
//
|
||||
// Init
|
||||
@ -103,6 +124,48 @@ nsGfxCheckboxControlFrame::Init(nsIPresContext* aPresContext,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
//
|
||||
// GetTristateAtom [static]
|
||||
@ -312,8 +375,36 @@ nsGfxCheckboxControlFrame::Paint(nsIPresContext* aPresContext,
|
||||
// Paint the background
|
||||
nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
||||
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
||||
PRBool doDefaultPainting = PR_TRUE;
|
||||
// Paint the checkmark
|
||||
PaintCheckBox(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
||||
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);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -24,13 +24,19 @@
|
||||
|
||||
#include "nsFormControlFrame.h"
|
||||
#include "nsIStatefulFrame.h"
|
||||
#include "nsICheckboxControlFrame.h"
|
||||
|
||||
|
||||
#define NS_GFX_CHECKBOX_CONTROL_FRAME_FACE_CONTEXT_INDEX 0 // for additional style contexts
|
||||
#define NS_GFX_CHECKBOX_CONTROL_FRAME_LAST_CONTEXT_INDEX 0
|
||||
|
||||
class nsGfxCheckboxControlFrame : public nsFormControlFrame,
|
||||
public nsIStatefulFrame
|
||||
public nsIStatefulFrame,
|
||||
public nsICheckboxControlFrame
|
||||
{
|
||||
public:
|
||||
nsGfxCheckboxControlFrame();
|
||||
virtual ~nsGfxCheckboxControlFrame();
|
||||
|
||||
#ifdef DEBUG
|
||||
NS_IMETHOD GetFrameName(nsString& aResult) const {
|
||||
@ -57,8 +63,16 @@ public:
|
||||
const nsRect& aDirtyRect,
|
||||
nsFramePaintLayer aWhichLayer);
|
||||
|
||||
//nsIRadioControlFrame methods
|
||||
NS_IMETHOD SetCheckboxFaceStyleContext(nsIStyleContext *aCheckboxFaceStyleContext);
|
||||
|
||||
void InitializeControl(nsIPresContext* aPresContext);
|
||||
|
||||
NS_IMETHOD GetAdditionalStyleContext(PRInt32 aIndex,
|
||||
nsIStyleContext** aStyleContext) const;
|
||||
NS_IMETHOD SetAdditionalStyleContext(PRInt32 aIndex,
|
||||
nsIStyleContext* aStyleContext);
|
||||
|
||||
// nsIFormControlFrame
|
||||
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsString& aValue);
|
||||
NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue);
|
||||
@ -121,6 +135,7 @@ protected:
|
||||
|
||||
//GFX-rendered state variables
|
||||
CheckState mChecked;
|
||||
nsIStyleContext* mCheckButtonFaceStyle;
|
||||
|
||||
private:
|
||||
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user