Removing these unneeded files from from cvs, they have been in the build in years

r=kmcclusk,buster
This commit is contained in:
kmcclusk@netscape.com
2000-11-16 21:41:14 +00:00
parent 1b18124578
commit 8ba7536215
22 changed files with 0 additions and 7336 deletions

View File

@@ -1,407 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsCOMPtr.h"
#include "nsTextControlFrame.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIFrame.h"
#include "nsISupports.h"
#include "nsIAtom.h"
#include "nsIPresContext.h"
#include "nsIHTMLContent.h"
#include "nsHTMLIIDs.h"
#include "nsITextWidget.h"
#include "nsWidgetsCID.h"
#include "nsSize.h"
#include "nsString.h"
#include "nsLinebreakConverter.h"
#include "nsHTMLAtoms.h"
#include "nsIStyleContext.h"
#include "nsFont.h"
#include "nsDOMEvent.h"
#include "nsIFormControl.h"
#include "nsFormFrame.h"
#include "nsIContent.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLTextAreaElement.h"
#include "nsCSSRendering.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsILookAndFeel.h"
#include "nsIComponentManager.h"
#include "nsIStatefulFrame.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kTextCID, NS_TEXTFIELD_CID);
static NS_DEFINE_IID(kTextAreaCID, NS_TEXTAREA_CID);
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
const nscoord kSuggestedNotSet = -1;
nsTextControlFrame::nsTextControlFrame()
{
mSuggestedWidth = kSuggestedNotSet;
mSuggestedHeight = kSuggestedNotSet;
}
nsTextControlFrame::~nsTextControlFrame()
{
}
// Frames are not refcounted, no need to AddRef
NS_IMETHODIMP
nsTextControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
} else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
*aInstancePtr = (void*)(nsIStatefulFrame*) this;
return NS_OK;
}
return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
}
nscoord
nsTextControlFrame::GetVerticalBorderWidth(float aPixToTwip) const
{
return NSIntPixelsToTwips(4, aPixToTwip);
}
nscoord
nsTextControlFrame::GetHorizontalBorderWidth(float aPixToTwip) const
{
return GetVerticalBorderWidth(aPixToTwip);
}
// for a text area aInnerHeight is the height of one line
nscoord
nsTextControlFrame::GetVerticalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerHeight) const
{
// XXX NOTE: the enums eMetric_TextShouldUseVerticalInsidePadding and eMetric_TextVerticalInsidePadding
// are ONLY needed because GTK is not using the "float" padding values and wants to only use an
// integer value for the padding instead of calculating like the other platforms.
//
// If GTK decides to start calculating the value, PLEASE remove these two enum from nsILookAndFeel and
// all the platforms nsLookAndFeel impementations so we don't have these extra values remaining in the code.
// The two enums are:
// eMetric_TextVerticalInsidePadding
// eMetric_TextShouldUseVerticalInsidePadding
//
float padTextArea;
float padTextField;
PRInt32 vertPad;
PRInt32 shouldUseVertPad;
nsCOMPtr<nsILookAndFeel> lookAndFeel;
if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextAreaVerticalInsidePadding, padTextArea);
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextFieldVerticalInsidePadding, padTextField);
// These two (below) are really only needed for GTK
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextVerticalInsidePadding, vertPad);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextShouldUseVerticalInsidePadding, shouldUseVertPad);
}
if (1 == shouldUseVertPad) {
return NSIntPixelsToTwips(vertPad, aPixToTwip); // XXX this is probably wrong (for GTK)
} else {
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return (nscoord)NSToIntRound(float(aInnerHeight) * padTextArea);
} else {
return (nscoord)NSToIntRound(float(aInnerHeight) * padTextField);
}
}
}
//static float pad = 0.95F;
nscoord
nsTextControlFrame::GetHorizontalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerWidth,
nscoord aCharWidth) const
{
// XXX NOTE: the enum eMetric_TextShouldUseHorizontalInsideMinimumPadding
// is ONLY needed because GTK is not using the "float" padding values and wants to only use the
// "minimum" integer value for the padding instead of calculating and comparing like the other platforms.
//
// If GTK decides to start calculating and comparing the values,
// PLEASE remove these the enum from nsILookAndFeel and
// all the platforms nsLookAndFeel impementations so we don't have these extra values remaining in the code.
// The enum is:
// eMetric_TextShouldUseHorizontalInsideMinimumPadding
//
float padTextField;
float padTextArea;
PRInt32 padMinText;
PRInt32 shouldUsePadMinText;
nsCOMPtr<nsILookAndFeel> lookAndFeel;
if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextFieldHorizontalInsidePadding, padTextField);
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextAreaHorizontalInsidePadding, padTextArea);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextHorizontalInsideMinimumPadding, padMinText);
// This one (below) is really only needed for GTK
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextShouldUseHorizontalInsideMinimumPadding, shouldUsePadMinText);
}
//padTextField = pad;
nscoord padding;
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
padding = (nscoord)(aCharWidth * padTextArea);
} else {
padding = (nscoord)(aCharWidth * padTextField);
}
nscoord min = NSIntPixelsToTwips(padMinText, aPixToTwip);
if (padding > min && (1 == shouldUsePadMinText)) {
return padding;
} else {
return min;
}
}
/*
* FIXME: this ::GetIID() method has no meaning in life and should be
* removed.
* Pierre Phaneuf <pp@ludusdesign.com>
*/
const nsIID&
nsTextControlFrame::GetIID()
{
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return kITextAreaWidgetIID;
} else {
return kITextWidgetIID;
}
}
const nsIID&
nsTextControlFrame::GetCID()
{
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return kTextAreaCID;
} else {
return kTextCID;
}
}
void
nsTextControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize)
{
nsSize widgetSize;
GetDesiredSize(aPresContext, aReflowState, aDesiredLayoutSize, widgetSize);
}
void
nsTextControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize)
{
nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode);
// get the css size and let the frame use or override it
nsSize styleSize;
GetStyleSize(aPresContext, aReflowState, styleSize);
nsSize desiredSize;
nsSize minSize;
PRBool widthExplicit, heightExplicit;
PRInt32 ignore;
PRInt32 type;
GetType(&type);
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
PRInt32 width;
if (NS_CONTENT_ATTR_HAS_VALUE != GetSizeFromContent(&width)) {
width = GetDefaultColumnWidth();
}
//if (eCompatibility_NavQuirks == mode) {
// width += 1;
//}
nsInputDimensionSpec textSpec(nsnull, PR_FALSE, nsnull,
nsnull, width, PR_FALSE, nsnull, 1);
nsFormControlHelper::CalculateSize(aPresContext, aReflowState.rendContext, this, styleSize,
textSpec, desiredSize, minSize, widthExplicit, heightExplicit, ignore);
} else {
nsInputDimensionSpec areaSpec(nsHTMLAtoms::cols, PR_FALSE, nsnull, nsnull, GetDefaultColumnWidth(),
PR_FALSE, nsHTMLAtoms::rows, 1);
nsFormControlHelper::CalculateSize(aPresContext, aReflowState.rendContext, this, styleSize,
areaSpec, desiredSize, minSize, widthExplicit, heightExplicit, ignore);
}
// CalculateSize makes calls in the nsFormControlHelper that figures
// out the entire size of the control when in NavQuirks mode. For the
// textarea, this means the scrollbar sizes hav already been added to
// its overall size and do not need to be added here.
float p2t;
aPresContext->GetPixelsToTwips(&p2t);
if (NS_FORM_TEXTAREA == type && mode == eCompatibility_Standard) {
nscoord scrollbarWidth = 0;
nscoord scrollbarHeight = 0;
float scale;
nsCOMPtr<nsIDeviceContext> dx;
aPresContext->GetDeviceContext(getter_AddRefs(dx));
if (dx) {
float sbWidth;
float sbHeight;
dx->GetCanonicalPixelScale(scale);
dx->GetScrollBarDimensions(sbWidth, sbHeight);
scrollbarWidth = PRInt32(sbWidth * scale);
scrollbarHeight = PRInt32(sbHeight * scale);
} else {
scrollbarWidth = GetScrollbarWidth(p2t);
scrollbarHeight = scrollbarWidth;
}
if (!heightExplicit) {
desiredSize.height += scrollbarHeight;
minSize.height += scrollbarHeight;
}
if (!widthExplicit) {
desiredSize.width += scrollbarWidth;
minSize.width += scrollbarWidth;
}
}
aDesiredLayoutSize.width = desiredSize.width;
aDesiredLayoutSize.height = desiredSize.height;
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
aDesiredLayoutSize.descent = 0;
if (aDesiredLayoutSize.maxElementSize) {
aDesiredLayoutSize.maxElementSize->width = minSize.width;
aDesiredLayoutSize.maxElementSize->height = minSize.height;
}
aDesiredWidgetSize.width = aDesiredLayoutSize.width;
aDesiredWidgetSize.height = aDesiredLayoutSize.height;
}
PRInt32
nsTextControlFrame::GetMaxNumValues()
{
return 1;
}
NS_IMETHODIMP
nsTextControlFrame::GetCursor(nsIPresContext* aPresContext, nsPoint& aPoint, PRInt32& aCursor)
{
/*const nsStyleColor* styleColor;
GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)styleColor);
aCursor = styleColor->mCursor;*/
//XXX This is wrong, should be through style.
aCursor = NS_STYLE_CURSOR_TEXT;
return NS_OK;
}
#ifdef DEBUG
NS_IMETHODIMP
nsTextControlFrame::GetFrameName(nsString& aResult) const
{
return MakeFrameName("TextControl", aResult);
}
#endif
//---------------------------------------------------------
NS_IMETHODIMP
nsTextControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight)
{
mSuggestedWidth = aWidth;
mSuggestedHeight = aHeight;
return NS_OK;
}
//----------------------------------------------------------------------
// nsIStatefulFrame
//----------------------------------------------------------------------
NS_IMETHODIMP
nsTextControlFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::StateType* aStateType)
{
*aStateType = nsIStatefulFrame::eTextType;
return NS_OK;
}
NS_IMETHODIMP
nsTextControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
nsAutoString theString;
nsresult res = GetProperty(nsHTMLAtoms::value, theString);
if (NS_SUCCEEDED(res)) {
char* chars = theString.ToNewCString();
if (chars) {
// GetProperty returns platform-native line breaks. We must convert
// these to content line breaks.
char* newChars = nsLinebreakConverter::ConvertLineBreaks(chars,
nsLinebreakConverter::eLinebreakPlatform, nsLinebreakConverter::eLinebreakContent);
if (newChars) {
nsCRT::free(chars);
chars = newChars;
}
(*aState)->SetStateProperty("value", nsAutoString(chars));
nsCRT::free(chars);
} else {
res = NS_ERROR_OUT_OF_MEMORY;
}
}
(*aState)->SetStateProperty("value", theString);
return res;
}
NS_IMETHODIMP
nsTextControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{
nsAutoString stateString;
aState->GetStateProperty("value", stateString);
nsresult res = SetProperty(aPresContext, nsHTMLAtoms::value, stateString);
return res;
}

View File

@@ -1,138 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsTextControlFrame_h___
#define nsTextControlFrame_h___
#include "nsNativeFormControlFrame.h"
#include "nsIStatefulFrame.h"
#include "nsIPresState.h"
class nsIContent;
class nsIFrame;
class nsIPresContext;
class nsTextControlFrame : public nsNativeFormControlFrame,
public nsIStatefulFrame
{
/* ---------- methods implemented by base class ---------- */
public:
nsTextControlFrame();
virtual ~nsTextControlFrame();
virtual const nsIID& GetCID();
virtual const nsIID& GetIID();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const;
#endif
virtual nscoord GetVerticalBorderWidth(float aPixToTwip) const;
virtual nscoord GetHorizontalBorderWidth(float aPixToTwip) const;
virtual nscoord GetVerticalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerHeight) const;
virtual nscoord GetHorizontalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerWidth,
nscoord aCharWidth) const;
virtual PRInt32 GetMaxNumValues();
NS_IMETHOD GetCursor(nsIPresContext* aPresContext, nsPoint& aPoint, PRInt32& aCursor);
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
//nsIStatefulFrame
NS_IMETHOD GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::StateType* aStateType);
NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState);
NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState);
protected:
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize);
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize);
PRInt32 GetDefaultColumnWidth() const { return (PRInt32)(20); } // this was DEFAULT_PIXEL_WIDTH
private:
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
/* ---------- abstract methods derived class must implement ---------- */
public:
// nsIFormControlFrame
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue)=0;
NS_IMETHOD GetProperty(nsIAtom* aName, nsAWritableString& aValue)=0;
virtual nsWidgetInitData* GetWidgetInitData(nsIPresContext* aPresContext)=0;
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)=0;
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight)=0;
NS_IMETHOD GetText(nsString* aValue, PRBool aInitialValue)=0;
virtual void EnterPressed(nsIPresContext* aPresContext)=0;
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames)=0;
virtual void Reset(nsIPresContext* aPresContext)=0;
NS_IMETHOD Paint(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)=0;
virtual void PaintTextControlBackground(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)=0;
virtual void PaintTextControl(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect, nsString& aText,
nsIStyleContext* aStyleContext,
nsRect& aRect)=0;
// Utility methods to get and set current widget state
virtual void GetTextControlFrameState(nsString& aValue)=0;
virtual void SetTextControlFrameState(const nsString& aValue)=0;
virtual nsresult RequiresWidget(PRBool &aRequiresWidget)=0;
};
#endif

View File

@@ -1,360 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsFileControlFrame.h"
#include "nsFormControlHelper.h"
#include "nsButtonControlFrame.h"
#include "nsIRenderingContext.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsIStyleContext.h"
#include "nsLeafFrame.h"
#include "nsCSSRendering.h"
#include "nsHTMLIIDs.h"
#include "nsIButton.h"
#include "nsIViewManager.h"
#include "nsISupports.h"
#include "nsHTMLAtoms.h"
#include "nsIButton.h"
#include "nsIView.h"
#include "nsViewsCID.h"
#include "nsWidgetsCID.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsIFormControl.h"
#include "nsStyleUtil.h"
#include "nsDOMEvent.h"
#include "nsStyleConsts.h"
#include "nsIHTMLAttributes.h"
#include "nsGenericHTMLElement.h"
#include "nsFormFrame.h"
#include "nsILookAndFeel.h"
#include "nsCOMPtr.h"
#include "nsDOMEvent.h"
#include "nsIViewManager.h"
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
void
nsButtonControlFrame::GetDefaultLabel(nsString& aString)
{
PRInt32 type;
GetType(&type);
if (NS_FORM_INPUT_RESET == type) {
aString = "Reset";
}
else if (NS_FORM_INPUT_SUBMIT == type) {
aString = "Submit Query";
}
else if (NS_FORM_BROWSE == type) {
aString = "Browse...";
}
else {
aString = " ";
}
}
PRBool
nsButtonControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
{
PRInt32 type;
GetType(&type);
if ((NS_FORM_INPUT_HIDDEN == type) || (this == aSubmitter)) {
return Inherited::IsSuccessful(aSubmitter);
} else {
return PR_FALSE;
}
}
PRInt32
nsButtonControlFrame::GetMaxNumValues()
{
PRInt32 type;
GetType(&type);
if ((NS_FORM_INPUT_SUBMIT == type) || (NS_FORM_INPUT_HIDDEN == type)) {
return 1;
} else {
return 0;
}
}
PRBool
nsButtonControlFrame::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;
}
PRInt32 type;
GetType(&type);
if (NS_FORM_INPUT_RESET == type) {
aNumValues = 0;
return PR_FALSE;
} else {
nsAutoString value;
/*XXX nsresult valResult = */GetValue(&value);
aValues[0] = value;
aNames[0] = name;
aNumValues = 1;
return PR_TRUE;
}
}
nscoord
nsButtonControlFrame::GetVerticalBorderWidth(float aPixToTwip) const
{
return NSIntPixelsToTwips(4, aPixToTwip);
}
nscoord
nsButtonControlFrame::GetHorizontalBorderWidth(float aPixToTwip) const
{
return GetVerticalBorderWidth(aPixToTwip);
}
nscoord
nsButtonControlFrame::GetVerticalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerHeight) const
{
float pad;
nsCOMPtr<nsILookAndFeel> lookAndFeel;
if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_ButtonVerticalInsidePadding, pad);
}
return (nscoord)NSToIntRound((float)aInnerHeight * pad);
}
nscoord
nsButtonControlFrame::GetHorizontalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerWidth,
nscoord aCharWidth) const
{
nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode);
float pad;
PRInt32 padQuirks;
PRInt32 padQuirksOffset;
nsCOMPtr<nsILookAndFeel> lookAndFeel;
if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_ButtonHorizontalInsidePadding, pad);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ButtonHorizontalInsidePaddingNavQuirks, padQuirks);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks, padQuirksOffset);
}
if (eCompatibility_NavQuirks == mode) {
return (nscoord)NSToIntRound(float(aInnerWidth) * pad);
} else {
return NSIntPixelsToTwips(padQuirks, aPixToTwip) + padQuirksOffset;
}
}
void
nsButtonControlFrame::MouseClicked(nsIPresContext* aPresContext)
{
//XXX: This method should probably go away. The nsHTMLButtonControl frame's
//mouse click should be sufficient.
PRInt32 type;
GetType(&type);
if ((nsnull != mFormFrame) && !nsFormFrame::GetDisabled(this)) {
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
nsIContent *formContent = nsnull;
mFormFrame->GetContent(&formContent);
switch(type) {
case NS_FORM_INPUT_RESET:
event.message = NS_FORM_RESET;
if (nsnull != formContent) {
formContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
}
if (nsEventStatus_eConsumeNoDefault != status) {
mFormFrame->OnReset(aPresContext);
}
break;
case NS_FORM_INPUT_SUBMIT:
event.message = NS_FORM_SUBMIT;
if (nsnull != formContent) {
formContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
}
if (nsEventStatus_eConsumeNoDefault != status) {
mFormFrame->OnSubmit(aPresContext, this);
}
}
NS_IF_RELEASE(formContent);
}
//else if ((NS_FORM_BROWSE == type) && mMouseListener) {
else if (nsnull != mMouseListener) {
mMouseListener->MouseClicked(aPresContext);
}
}
void
nsButtonControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize)
{
// This "do-nothing" implementation exists to remove compiler warnings caused
// by the fact that GetDesiredSize is both overloaded and overridden.
Inherited::GetDesiredSize(aPresContext, aReflowState, aDesiredSize);
}
void
nsButtonControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize)
{
PRInt32 type;
GetType(&type);
#if 0
if ((NS_FORM_INPUT_HIDDEN != type) && ((NS_FORMSIZE_NOTSET != mSuggestedWidth) && (
NS_FORMSIZE_NOTSET != mSuggestedHeight)))
{
aDesiredLayoutSize.width = mSuggestedWidth;
aDesiredLayoutSize.height = mSuggestedHeight;
aDesiredLayoutSize.ascent = mSuggestedHeight;
aDesiredLayoutSize.descent = 0;
if (aDesiredLayoutSize.maxElementSize) {
aDesiredLayoutSize.maxElementSize->width = mSuggestedWidth;
aDesiredLayoutSize.maxElementSize->height = mSuggestedWidth;
}
aDesiredWidgetSize.width = aDesiredLayoutSize.width;
aDesiredWidgetSize.height= aDesiredLayoutSize.height;
return;
}
#endif
if (NS_FORM_INPUT_HIDDEN == type) { // there is no physical rep
aDesiredLayoutSize.width = 0;
aDesiredLayoutSize.height = 0;
aDesiredLayoutSize.ascent = 0;
aDesiredLayoutSize.descent = 0;
if (aDesiredLayoutSize.maxElementSize) {
aDesiredLayoutSize.maxElementSize->width = 0;
aDesiredLayoutSize.maxElementSize->height = 0;
}
} else {
nsSize styleSize;
GetStyleSize(aPresContext, aReflowState, styleSize);
// a browse button shares its style context with its parent nsInputFile
// it uses everything from it except width
if (NS_FORM_BROWSE == type) {
styleSize.width = CSS_NOTSET;
}
nsSize desiredSize;
nsSize minSize;
PRBool widthExplicit, heightExplicit;
PRInt32 ignore;
nsAutoString defaultLabel;
GetDefaultLabel(defaultLabel);
nsInputDimensionSpec spec(nsHTMLAtoms::size, PR_TRUE, nsHTMLAtoms::value,
&defaultLabel, 1, PR_FALSE, nsnull, 1);
nsFormControlHelper::CalculateSize(aPresContext, aReflowState.rendContext, this, styleSize,
spec, desiredSize, minSize, widthExplicit, heightExplicit, ignore);
// set desired size, max element size
aDesiredLayoutSize.width = desiredSize.width;
aDesiredLayoutSize.height= desiredSize.height;
if (aDesiredLayoutSize.maxElementSize) {
aDesiredLayoutSize.maxElementSize->width = minSize.width;
aDesiredLayoutSize.maxElementSize->height = minSize.height;
}
}
aDesiredWidgetSize.width = aDesiredLayoutSize.width;
aDesiredWidgetSize.height= aDesiredLayoutSize.height;
}
/*
* FIXME: this ::GetIID() method has no meaning in life and should be
* removed.
* Pierre Phaneuf <pp@ludusdesign.com>
*/
const nsIID&
nsButtonControlFrame::GetIID()
{
static NS_DEFINE_IID(kButtonIID, NS_IBUTTON_IID);
return kButtonIID;
}
const nsIID&
nsButtonControlFrame::GetCID()
{
static NS_DEFINE_IID(kButtonCID, NS_BUTTON_CID);
return kButtonCID;
}
#ifdef DEBUG
NS_IMETHODIMP
nsButtonControlFrame::GetFrameName(nsString& aResult) const
{
return MakeFrameName("ButtonControl", aResult);
}
#endif
void
nsButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
{
}
void
nsButtonControlFrame::Redraw(nsIPresContext* aPresContext)
{ nsRect rect(0, 0, mRect.width, mRect.height);
Invalidate(aPresContext, rect, PR_FALSE);
}
NS_IMETHODIMP nsButtonControlFrame::SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsString& aValue)
{
return NS_OK;
}
NS_IMETHODIMP nsButtonControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)
{
return NS_OK;
}
nsresult nsButtonControlFrame::RequiresWidget(PRBool& aRequiresWidget)
{
aRequiresWidget = PR_FALSE;
return NS_OK;
}

View File

@@ -1,94 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsButtonControlFrame_h___
#define nsButtonControlFrame_h___
#include "nsNativeFormControlFrame.h"
#include "nsButtonFrameRenderer.h"
class nsButtonControlFrame : public nsNativeFormControlFrame {
private:
typedef nsNativeFormControlFrame Inherited;
public:
// nsFormControlFrame overrides
nsresult RequiresWidget(PRBool &aHasWidget);
// nsIFormControlFrame
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue);
NS_IMETHOD GetProperty(nsIAtom* aName, nsAWritableString& aValue);
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const;
#endif
virtual void MouseClicked(nsIPresContext* aPresContext);
virtual const nsIID& GetCID();
virtual const nsIID& GetIID();
virtual nscoord GetVerticalBorderWidth(float aPixToTwip) const;
virtual nscoord GetHorizontalBorderWidth(float aPixToTwip) const;
virtual nscoord GetVerticalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerHeight) const;
virtual nscoord GetHorizontalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerWidth,
nscoord aCharWidth) const;
//nsFileControlFrame* GetFileControlFrame() { return mFileControlFrame; }
void GetDefaultLabel(nsString& aLabel);
PRBool IsSuccessful(nsIFormControlFrame* aSubmitter);
virtual PRInt32 GetMaxNumValues();
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames);
// Sets listener for button click
void SetMouseListener(nsIFormControlFrame* aListener) { mMouseListener = aListener; }
protected:
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize);
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize);
virtual void Redraw(nsIPresContext* aPresContext);
virtual void SetFocus(PRBool aOn, PRBool aRepaint);
nsIFormControlFrame* mMouseListener; // for browse buttons only
};
#endif

View File

@@ -1,449 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsCheckboxControlFrame.h"
#include "nsICheckButton.h"
#include "nsNativeFormControlFrame.h"
#include "nsWidgetsCID.h"
#include "nsIContent.h"
#include "nsHTMLAtoms.h"
#include "nsCOMPtr.h"
#include "nsINameSpaceManager.h"
#include "nsFormFrame.h"
#include "nsIStatefulFrame.h"
#include "nsIPresState.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
//----------------------------------------------------------------------
// nsISupports
//----------------------------------------------------------------------
// Frames are not refcounted, no need to AddRef
NS_IMETHODIMP
nsCheckboxControlFrame::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;
}
return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
}
//
// 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*
nsCheckboxControlFrame :: 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*
nsCheckboxControlFrame :: GetTristateValueAtom ( )
{
return nsHTMLAtoms::moz_tristatevalue;
}
//
// Constructor
//
nsCheckboxControlFrame :: nsCheckboxControlFrame ( )
: mIsTristate(PR_FALSE)
{
}
//
// Init
//
// We need to override this in order to see if we're a tristate checkbox.
//
NS_IMETHODIMP
nsCheckboxControlFrame::Init(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsNativeFormControlFrame::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() )
mContent->SetAttribute ( kNameSpaceID_None, GetTristateValueAtom(), "0", PR_FALSE );
return NS_OK;
}
/*
* FIXME: this ::GetIID() method has no meaning in life and should be
* removed.
* Pierre Phaneuf <pp@ludusdesign.com>
*/
const nsIID&
nsCheckboxControlFrame::GetIID()
{
static NS_DEFINE_IID(kCheckboxIID, NS_ICHECKBUTTON_IID);
return kCheckboxIID;
}
const nsIID&
nsCheckboxControlFrame::GetCID()
{
static NS_DEFINE_IID(kCheckboxCID, NS_CHECKBUTTON_CID);
return kCheckboxCID;
}
//
// PostCreateWidget
//
// Set the default checked state of the checkbox.
//
void
nsCheckboxControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight)
{
PRBool checked = PR_FALSE;
nsresult result = GetDefaultCheckState(&checked);
if (NS_CONTENT_ATTR_HAS_VALUE == result)
SetCheckboxState (aPresContext, checked ? eOn : eOff );
}
//
// 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
nsCheckboxControlFrame::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 nsNativeFormControlFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
return NS_OK;
}
void
nsCheckboxControlFrame::MouseUp(nsIPresContext* aPresContext)
{
if ( IsTristateCheckbox() ) {
CheckState newState = eOn;
switch ( GetCheckboxState() ) {
case eOn:
newState = eOff;
break;
case eMixed:
newState = eOn;
break;
case eOff:
newState = eMixed;
break;
}
SetCheckboxState(aPresContext, newState);
// Keep the tri-state stuff on the content node current. No need to force an
// attribute changed event since we just set the state of the checkbox ourselves.
nsAutoString value;
CheckStateToString ( newState, value );
mContent->SetAttribute ( kNameSpaceID_None, GetTristateValueAtom(), value, PR_FALSE );
}
else {
CheckState newState = GetCheckboxState() == eOn ? eOff : eOn;
SetCheckboxState(aPresContext, newState);
}
}
PRInt32
nsCheckboxControlFrame::GetMaxNumValues()
{
return 1;
}
PRBool
nsCheckboxControlFrame::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) {
aValues[0] = "on";
} else {
aValues[0] = value;
}
aNames[0] = name;
aNumValues = 1;
}
return result;
}
void
nsCheckboxControlFrame::Reset(nsIPresContext* aPresContext)
{
PRBool checked;
GetDefaultCheckState(&checked);
SetCheckboxState (aPresContext, checked ? eOn : eOff );
}
NS_METHOD nsCheckboxControlFrame::HandleEvent(nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
NS_ENSURE_ARG_POINTER(aEventStatus);
if (nsEventStatus_eConsumeNoDefault == *aEventStatus)
return NS_OK;
if (nsFormFrame::GetDisabled(this))
return NS_OK;
if (NS_MOUSE_LEFT_BUTTON_UP == aEvent->message) {
MouseUp(aPresContext);
}
return(nsNativeFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus));
}
void nsCheckboxControlFrame::GetCheckboxControlFrameState(nsString& aValue)
{
CheckStateToString(GetCheckboxState(), aValue);
}
void nsCheckboxControlFrame::SetCheckboxControlFrameState(nsIPresContext* aPresContext,
const nsString& aValue)
{
CheckState state = StringToCheckState(aValue);
SetCheckboxState(aPresContext, state);
}
NS_IMETHODIMP nsCheckboxControlFrame::SetProperty(nsIPresContext* aPresContext,
nsIAtom* aName,
const nsAReadableString& aValue)
{
if (nsHTMLAtoms::checked == aName)
SetCheckboxControlFrameState(aPresContext, aValue);
else
return nsNativeFormControlFrame::SetProperty(aPresContext, aName, aValue);
return NS_OK;
}
NS_IMETHODIMP nsCheckboxControlFrame::GetProperty(nsIAtom* aName, nsAReadableString& aValue)
{
if (nsHTMLAtoms::checked == aName)
GetCheckboxControlFrameState(aValue);
else
return nsNativeFormControlFrame::GetProperty(aName, aValue);
return NS_OK;
}
nsresult nsCheckboxControlFrame::RequiresWidget(PRBool& aRequiresWidget)
{
aRequiresWidget = PR_FALSE;
return NS_OK;
}
//
// CheckStateToString
//
// Converts from a CheckState to a string
//
void
nsCheckboxControlFrame :: CheckStateToString ( CheckState inState, nsString& outStateAsString )
{
switch ( inState ) {
case eOn:
outStateAsString = NS_STRING_TRUE;
break;
case eOff:
outStateAsString = NS_STRING_FALSE;
break;
case eMixed:
outStateAsString = "2";
break;
}
} // CheckStateToString
//
// StringToCheckState
//
// Converts from a string to a CheckState enum
//
nsCheckboxControlFrame::CheckState
nsCheckboxControlFrame :: StringToCheckState ( const nsString & aStateAsString )
{
if ( aStateAsString == NS_STRING_TRUE )
return eOn;
else if ( aStateAsString == NS_STRING_FALSE )
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
nsCheckboxControlFrame :: 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 nsCheckboxControlFrame::GetStateType(nsIPresContext* aPresContext,
nsIStatefulFrame::StateType* aStateType)
{
*aStateType=nsIStatefulFrame::eCheckboxType;
return NS_OK;
}
NS_IMETHODIMP nsCheckboxControlFrame::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);
(*aState)->SetStateProperty("checked", stateString);
return NS_OK;
}
NS_IMETHODIMP nsCheckboxControlFrame::RestoreState(nsIPresContext* aPresContext,
nsIPresState* aState)
{
nsAutoString string;
aState->GetStateProperty("checked", string);
SetCheckboxControlFrameState(aPresContext, string);
return NS_OK;
}

View File

@@ -1,139 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsCheckboxControlFrame_h___
#define nsCheckboxControlFrame_h___
#include "nsFormControlFrame.h"
#include "nsIStatefulFrame.h"
class nsIPresState;
//
// nsCheckboxControlFrame
//
// This class implements the logic for both regular checkboxes _and_
// tri-state checkboxes (used in XUL). By default, this is a regular checkbox
// and is visibly no different from what is described by the HTML4 standard. When
// the attribute "moz-tristate" is set (value is unimportant), this transforms
// into a tri-state checkbox whose value is get/set via the attribute
// "moz-tristatevalue."
//
// Why not use "checked?" The HTML4 standard declares it to be a boolean (a fact
// enforced by our parser), so in order to not break anything, we use a different
// attribute to store the value.
//
// The checkbox can switch between being regular and tri-state on-the-fly at any time
// without losing the value of the checkbox. However, if the checkbox is in the
// "mixed" state when it is transformed back into a normal checkbox, it will
// become checked since "mixed" doesn't exist on normal checkboxes.
//
class nsCheckboxControlFrame : public nsFormControlFrame,
public nsIStatefulFrame
{
public:
nsCheckboxControlFrame ( ) ;
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);
NS_IMETHOD Init(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow) ;
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const {
return MakeFrameName("CheckboxControl", aResult);
}
#endif
virtual const nsIID& GetCID();
virtual const nsIID& GetIID();
// nsIFormControlFrame
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue);
NS_IMETHOD GetProperty(nsIAtom* aName, nsAWritableString& aValue);
virtual void Reset(nsIPresContext* aPresContext);
virtual PRInt32 GetMaxNumValues();
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames);
virtual void MouseUp(nsIPresContext* aPresContext);
// nsFormControlFrame overrides
nsresult RequiresWidget(PRBool &aHasWidget);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint) ;
NS_IMETHOD HandleEvent(nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
// this should be protected, but VC6 is lame.
enum CheckState { eOff, eOn, eMixed } ;
// nsIStatefulFrame
NS_IMETHOD GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::StateType* aStateType);
NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState);
NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
protected:
// native/gfx implementations need to implement needs.
virtual CheckState GetCheckboxState() = 0;
virtual void SetCheckboxState(nsIPresContext* aPresContext, CheckState aValue) = 0;
// Utility methods for implementing SetProperty/GetProperty
void SetCheckboxControlFrameState(nsIPresContext* aPresContext,
const nsString& aValue);
void GetCheckboxControlFrameState(nsString& aValue);
// utility routine for converting from DOM values to internal enum
void CheckStateToString ( CheckState inState, nsString& outStateAsString ) ;
CheckState StringToCheckState ( const nsString & aStateAsString ) ;
// figure out if we're a tri-state checkbox.
PRBool IsTristateCheckbox ( ) const { return mIsTristate; }
// we just became a tri-state, or we just lost tri-state status. fix up
// the attributes for the new mode.
void SwitchModesWithEmergencyBrake ( nsIPresContext* aPresContext,
PRBool inIsNowTristate ) ;
// for tri-state checkbox. meaningless for normal HTML
PRBool mIsTristate;
static nsIAtom* GetTristateAtom() ;
static nsIAtom* GetTristateValueAtom() ;
private:
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
}; // class nsCheckboxControlFrame
#endif

View File

@@ -1,106 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsNativeButtonControlFrame.h"
#include "nsHTMLAtoms.h"
#include "nsFormFrame.h"
#include "nsIFormControl.h"
#include "nsIContent.h"
#include "nsIButton.h"
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
nsresult
NS_NewNativeButtonControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsNativeButtonControlFrame* it = new (aPresShell) nsNativeButtonControlFrame;
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aNewFrame = it;
return NS_OK;
}
NS_IMETHODIMP
nsNativeButtonControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult result = NS_OK;
if (mWidget) {
if (nsHTMLAtoms::value == aAttribute) {
nsIButton* button = nsnull;
result = mWidget->QueryInterface(kIButtonIID, (void**)&button);
if ((NS_SUCCEEDED(result)) && (nsnull != button)) {
nsString value;
/*XXXnsresult result = */GetValue(&value);
button->SetLabel(value);
NS_RELEASE(button);
if (aHint != NS_STYLE_HINT_REFLOW)
nsFormFrame::StyleChangeReflow(aPresContext, this);
}
} else if (nsHTMLAtoms::size == aAttribute &&
aHint != NS_STYLE_HINT_REFLOW) {
nsFormFrame::StyleChangeReflow(aPresContext, this);
}
// Allow the base class to handle common attributes supported
// by all form elements...
else {
result = Inherited::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
}
}
return result;
}
void
nsNativeButtonControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight)
{
nsIButton* button = nsnull;
if (mWidget && (NS_OK == mWidget->QueryInterface(kIButtonIID,(void**)&button))) {
const nsFont * font = nsnull;
nsresult res = GetFont(aPresContext, font);
if (NS_SUCCEEDED(res) && font != nsnull) {
mWidget->SetFont(*font);
}
SetColors(aPresContext);
nsAutoString value;
nsresult result = GetValue(&value);
if (NS_CONTENT_ATTR_HAS_VALUE != result) {
GetDefaultLabel(value);
}
button->SetLabel(value);
NS_RELEASE(button);
mWidget->Enable(!nsFormFrame::GetDisabled(this));
}
}

View File

@@ -1,49 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsNativeButtonControlFrame_h___
#define nsNativeButtonControlFrame_h___
#include "nsNativeFormControlFrame.h"
#include "nsButtonControlFrame.h"
#include "nsButtonFrameRenderer.h"
class nsNativeButtonControlFrame : public nsButtonControlFrame {
private:
typedef nsButtonControlFrame Inherited;
public:
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);
};
#endif

View File

@@ -1,161 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsNativeCheckboxControlFram.h"
#include "nsICheckButton.h"
#include "nsHTMLAtoms.h"
#include "nsHTMLParts.h"
#include "nsFormFrame.h"
#include "nsIFormControl.h"
#include "nsIContent.h"
#include "nsILookAndFeel.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsCOMPtr.h"
#define NS_DEFAULT_CHECKBOX_SIZE 12
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
nsresult
NS_NewNativeCheckboxControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsNativeCheckboxControlFrame* it = new (aPresShell) nsNativeCheckboxControlFrame;
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aNewFrame = it;
return NS_OK;
}
nscoord
nsNativeCheckboxControlFrame::GetCheckboxSize(nsIPresContext* aPresContext, float aPixToTwip) const
{
PRInt32 checkboxSize = 0;
nsCOMPtr<nsILookAndFeel> lookAndFeel;
if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_CheckboxSize, checkboxSize);
}
if (checkboxSize == 0)
checkboxSize = NS_DEFAULT_CHECKBOX_SIZE;
return NSIntPixelsToTwips(checkboxSize, aPixToTwip);
}
void
nsNativeCheckboxControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize)
{
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
aDesiredWidgetSize.width = GetCheckboxSize(aPresContext, p2t);
aDesiredWidgetSize.height = aDesiredWidgetSize.width;
aDesiredLayoutSize.width = aDesiredWidgetSize.width;
aDesiredLayoutSize.height = aDesiredWidgetSize.height;
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
aDesiredLayoutSize.descent = 0;
if (aDesiredLayoutSize.maxElementSize) {
aDesiredLayoutSize.maxElementSize->width = aDesiredLayoutSize.width;
aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height;
}
}
void
nsNativeCheckboxControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight)
{
Inherited::PostCreateWidget(aPresContext, aWidth, aHeight);
if (mWidget != nsnull) {
SetColors(aPresContext);
mWidget->Enable(!nsFormFrame::GetDisabled(this));
}
}
NS_IMETHODIMP
nsNativeCheckboxControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult result = NS_OK;
if (mWidget) {
if (nsHTMLAtoms::checked == aAttribute) {
nsICheckButton* button = nsnull;
result = mWidget->QueryInterface(GetIID(), (void**)&button);
if ((NS_SUCCEEDED(result)) && (nsnull != button)) {
PRBool checkedAttr;
GetCurrentCheckState(&checkedAttr);
PRBool checkedPrevState;
button->GetState(checkedPrevState);
if (checkedAttr != checkedPrevState) {
button->SetState(checkedAttr);
}
NS_RELEASE(button);
}
}
// Allow the base class to handle common attributes supported
// by all form elements...
else {
result = Inherited::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
}
}
return result;
}
nsCheckboxControlFrame::CheckState
nsNativeCheckboxControlFrame::GetCheckboxState()
{
PRBool state = PR_FALSE;
nsICheckButton* checkBox = nsnull;
if (nsnull != mWidget) {
// native-widget
if (NS_SUCCEEDED(mWidget->QueryInterface(kICheckButtonIID,(void**)&checkBox))) {
checkBox->GetState(state);
NS_RELEASE(checkBox);
}
}
return state ? eOn : eOff;
}
void nsNativeCheckboxControlFrame::SetCheckboxState(nsIPresContext* aPresContext, CheckState aValue)
{
if (nsnull != mWidget) {
nsICheckButton* checkBox = nsnull;
if (NS_OK == mWidget->QueryInterface(kICheckButtonIID,(void**)&checkBox)) {
checkBox->SetState(aValue == eOn);
NS_RELEASE(checkBox);
}
}
}

View File

@@ -1,59 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsNativeCheckboxControlFrame_h___
#define nsNativeCheckboxControlFrame_h___
#include "nsCheckboxControlFrame.h"
class nsNativeCheckboxControlFrame : public nsCheckboxControlFrame {
private:
typedef nsCheckboxControlFrame Inherited;
public:
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
protected:
virtual CheckState GetCheckboxState();
virtual void SetCheckboxState(nsIPresContext* aPresContext, CheckState aValue);
virtual nscoord GetCheckboxSize(nsIPresContext* aPresContext, float aPixToTwip) const;
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize);
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize)
{ nsFormControlFrame::GetDesiredSize(aPresContext, aReflowState, aDesiredSize); }
};
#endif

View File

@@ -1,332 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsCOMPtr.h"
#include "nsHTMLAtoms.h"
#include "nsWidgetsCID.h"
#include "nsViewsCID.h"
#include "nsIDeviceContext.h"
#include "nsIPresShell.h"
#include "nsIViewManager.h"
#include "nsIComponentManager.h"
#include "nsIFormControl.h"
#include "nsFormFrame.h"
#include "nsNativeFormControlFrame.h"
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
static NS_DEFINE_IID(kViewCID, NS_VIEW_CID);
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
nsNativeFormControlFrame::nsNativeFormControlFrame()
: nsFormControlFrame()
{
mLastMouseState = eMouseNone;
mWidget = nsnull;
}
nsNativeFormControlFrame::~nsNativeFormControlFrame()
{
NS_IF_RELEASE(mWidget);
}
NS_METHOD
nsNativeFormControlFrame::Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
if (mDidInit) {
return nsFormControlFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
}
nsresult result = NS_OK;
nsCOMPtr<nsIDeviceContext> dx;
aPresContext->GetDeviceContext(getter_AddRefs(dx));
PRBool requiresWidget = PR_TRUE;
// Checkto see if the device context supports widgets at all
if (dx) {
dx->SupportsNativeWidgets(requiresWidget);
}
nsWidgetRendering mode;
aPresContext->GetWidgetRenderingMode(&mode);
if ((eWidgetRendering_Gfx == mode) || (eWidgetRendering_PartialGfx == mode)) {
// Check with the frame to see if requires a widget to render
if (PR_TRUE == requiresWidget) {
RequiresWidget(requiresWidget);
}
}
if (! requiresWidget) {
return nsFormControlFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
}
// add ourself as an nsIFormControlFrame
if (!mFormFrame && (eReflowReason_Initial == aReflowState.reason)) {
nsFormFrame::AddFormControlFrame(aPresContext, *NS_STATIC_CAST(nsIFrame*, this));
}
GetDesiredSize(aPresContext, aReflowState, aDesiredSize, mWidgetSize);
{
nsCOMPtr<nsIPresShell> presShell;
aPresContext->GetShell(getter_AddRefs(presShell));
nsCOMPtr<nsIViewManager> viewMan;
presShell->GetViewManager(getter_AddRefs(viewMan));
nsRect boundBox(0, 0, aDesiredSize.width, aDesiredSize.height);
// absolutely positioned controls already have a view but not a widget
nsIView* view = nsnull;
GetView(aPresContext, &view);
if (nsnull == view) {
result = nsComponentManager::CreateInstance(kViewCID, nsnull, kIViewIID, (void **)&view);
if (!NS_SUCCEEDED(result)) {
NS_ASSERTION(0, "Could not create view for form control");
aStatus = NS_FRAME_NOT_COMPLETE;
return result;
}
nsIFrame* parWithView;
nsIView *parView;
GetParentWithView(aPresContext, &parWithView);
parWithView->GetView(aPresContext, &parView);
// initialize the view as hidden since we don't know the (x,y) until Paint
result = view->Init(viewMan, boundBox, parView, nsnull, nsViewVisibility_kHide);
if (NS_OK != result) {
NS_ASSERTION(0, "view initialization failed");
aStatus = NS_FRAME_NOT_COMPLETE;
return NS_OK;
}
viewMan->InsertChild(parView, view, 0);
SetView(aPresContext, view);
}
PRInt32 type;
GetType(&type);
const nsIID& id = GetCID();
if ((NS_FORM_INPUT_HIDDEN != type) && (PR_TRUE == requiresWidget)) {
// Do the following only if a widget is created
nsWidgetInitData* initData = GetWidgetInitData(aPresContext); // needs to be deleted
view->CreateWidget(id, initData);
if (nsnull != initData) {
delete(initData);
}
// set our widget
result = GetWidget(view, &mWidget);
if ((PR_FALSE == NS_SUCCEEDED(result)) || (nsnull == mWidget)) { // keep the ref on mWidget
NS_ASSERTION(0, "could not get widget");
}
}
PostCreateWidget(aPresContext, aDesiredSize.width, aDesiredSize.height);
mDidInit = PR_TRUE;
if ((aDesiredSize.width != boundBox.width) || (aDesiredSize.height != boundBox.height)) {
viewMan->ResizeView(view, aDesiredSize.width, aDesiredSize.height);
}
}
aDesiredSize.ascent = aDesiredSize.height;
aDesiredSize.descent = 0;
if (nsnull != aDesiredSize.maxElementSize) {
//XXX aDesiredSize.AddBorderPaddingToMaxElementSize(borderPadding);
}
aStatus = NS_FRAME_COMPLETE;
return NS_OK;
}
NS_IMETHODIMP
nsNativeFormControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)
{
if (mWidget) {
if (nsHTMLAtoms::disabled == aAttribute) {
mWidget->Enable(!nsFormFrame::GetDisabled(this));
}
}
return NS_OK;
}
void
nsNativeFormControlFrame::SetColors(nsIPresContext* aPresContext)
{
if (mWidget) {
nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode);
const nsStyleColor* color =
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
if (nsnull != color) {
if (!(NS_STYLE_BG_COLOR_TRANSPARENT & color->mBackgroundFlags)) {
mWidget->SetBackgroundColor(color->mBackgroundColor);
#ifdef bug_1021_closed
} else if (eCompatibility_NavQuirks == mode) {
#else
} else {
#endif
mWidget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
}
mWidget->SetForegroundColor(color->mColor);
}
}
}
// native widgets don't need to repaint
void
nsNativeFormControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
{
if (mWidget) {
if (aOn) {
mWidget->SetFocus();
}
else {
//Unsetting of focus on native widget is accomplised
//by pushing focus up to its parent
nsIWidget *parentWidget = mWidget->GetParent();
if (parentWidget) {
parentWidget->SetFocus();
NS_RELEASE(parentWidget);
}
}
}
}
nsresult
nsNativeFormControlFrame::GetWidget(nsIWidget** aWidget)
{
if (mWidget) {
NS_ADDREF(mWidget);
*aWidget = mWidget;
mWidget->Enable(!nsFormFrame::GetDisabled(this));
return NS_OK;
} else {
*aWidget = nsnull;
return NS_FORM_NOTOK;
}
}
nsresult
nsNativeFormControlFrame::GetWidget(nsIView* aView, nsIWidget** aWidget)
{
nsIWidget* widget;
aView->GetWidget(widget);
nsresult result;
if (nsnull == widget) {
*aWidget = nsnull;
result = NS_ERROR_FAILURE;
} else {
result = widget->QueryInterface(kIWidgetIID, (void**)aWidget); // keep the ref
if (NS_FAILED(result)) {
NS_ASSERTION(0, "The widget interface is invalid"); // need to print out more details of the widget
}
NS_RELEASE(widget);
}
return result;
}
NS_METHOD nsNativeFormControlFrame::HandleEvent(nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
NS_ENSURE_ARG_POINTER(aEventStatus);
if (nsnull == mWidget) {
return nsFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
return NS_OK;
}
// make sure that the widget in the event is this input
// XXX if there is no view, it could be an image button. Unfortunately,
// every image button will get every event.
nsIView* view;
GetView(aPresContext, &view);
if (view) {
if (mWidget != aEvent->widget) {
*aEventStatus = nsEventStatus_eIgnore;
return NS_OK;
}
}
// if not native then use the NS_MOUSE_LEFT_CLICK to see if pressed
// unfortunately native widgets don't seem to handle this right.
// so use the old code for native stuff. -EDV
//printf(" %d %d %d %d (%d,%d) \n", this, aEvent->widget, aEvent->widgetSupports,
// aEvent->message, aEvent->point.x, aEvent->point.y);
PRInt32 type;
GetType(&type);
switch (aEvent->message) {
case NS_MOUSE_ENTER_SYNTH:
mLastMouseState = eMouseEnter;
break;
case NS_MOUSE_LEFT_BUTTON_DOWN:
mLastMouseState = eMouseDown;
break;
case NS_MOUSE_LEFT_BUTTON_UP:
if (eMouseDown == mLastMouseState) {
MouseClicked(aPresContext);
}
mLastMouseState = eMouseEnter;
break;
case NS_MOUSE_EXIT_SYNTH:
mLastMouseState = eMouseNone;
break;
case NS_CONTROL_CHANGE:
ControlChanged(aPresContext);
break;
case NS_KEY_DOWN:
return nsFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}
*aEventStatus = nsEventStatus_eConsumeDoDefault;
return NS_OK;
}

View File

@@ -1,90 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsNativeFormControlFrame_h___
#define nsNativeFormControlFrame_h___
#include "nsFormControlFrame.h"
/**
* nsFormControlFrame is the base class for frames of form controls. It
* provides a uniform way of creating widgets, resizing, and painting.
* @see nsLeafFrame and its base classes for more info
*/
class nsNativeFormControlFrame : public nsFormControlFrame
{
public:
nsNativeFormControlFrame();
/**
* Respond to the request to resize and/or reflow
* @see nsIFrame::Reflow
*/
NS_IMETHOD Reflow(nsIPresContext* aCX,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
/**
* Respond to a gui event
* @see nsIFrame::HandleEvent
*/
NS_IMETHOD HandleEvent(nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
/**
* Get the widget associated with this frame
* @param aView the view associated with the frame. It is a convience parm.
* @param aWidget the address of address of where the widget will be placed.
* This method doses an AddRef on the widget.
*/
nsresult GetWidget(nsIView* aView, nsIWidget** aWidget);
nsresult GetWidget(nsIWidget** aWidget);
PRBool HasNativeWidget() { return (nsnull != mWidget);}
virtual void SetFocus(PRBool aOn = PR_TRUE, PRBool aRepaint = PR_FALSE);
void SetColors(nsIPresContext* aPresContext);
protected:
virtual ~nsNativeFormControlFrame();
nsMouseState mLastMouseState;
nsIWidget* mWidget;
};
#endif

View File

@@ -1,178 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsNativeRadioControlFrame.h"
#include "nsIRadioButton.h"
#include "nsHTMLAtoms.h"
#include "nsHTMLParts.h"
#include "nsFormFrame.h"
#include "nsIFormControl.h"
#include "nsIContent.h"
#include "nsILookAndFeel.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsStyleUtil.h"
#include "nsCOMPtr.h"
static NS_DEFINE_IID(kIRadioIID, NS_IRADIOBUTTON_IID);
#define NS_DEFAULT_RADIOBOX_SIZE 12
nsresult
NS_NewNativeRadioControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsNativeRadioControlFrame* it = new (aPresShell) nsNativeRadioControlFrame;
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aNewFrame = it;
return NS_OK;
}
//--------------------------------------------------------------
nscoord
nsNativeRadioControlFrame::GetRadioboxSize(nsIPresContext* aPresContext, float aPixToTwip) const
{
PRInt32 radioboxSize = 0;
nsCOMPtr<nsILookAndFeel> lookAndFeel;
if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_RadioboxSize, radioboxSize);
}
if (radioboxSize == 0)
radioboxSize = NS_DEFAULT_RADIOBOX_SIZE;
return NSIntPixelsToTwips(radioboxSize, aPixToTwip);
}
void
nsNativeRadioControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize)
{
nsWidgetRendering mode;
aPresContext->GetWidgetRenderingMode(&mode);
if ((eWidgetRendering_Gfx == mode) || (eWidgetRendering_PartialGfx == mode)) {
Inherited::GetDesiredSize(aPresContext,aReflowState,aDesiredLayoutSize,
aDesiredWidgetSize);
} else {
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
aDesiredWidgetSize.width = GetRadioboxSize(aPresContext, p2t);
aDesiredWidgetSize.height = aDesiredWidgetSize.width;
aDesiredLayoutSize.width = aDesiredWidgetSize.width;
aDesiredLayoutSize.height = aDesiredWidgetSize.height;
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
aDesiredLayoutSize.descent = 0;
if (aDesiredLayoutSize.maxElementSize) {
aDesiredLayoutSize.maxElementSize->width = aDesiredLayoutSize.width;
aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height;
}
}
}
void
nsNativeRadioControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight)
{
Inherited::PostCreateWidget(aPresContext, aWidth, aHeight);
if (mWidget != nsnull) {
const nsStyleColor* color =
nsStyleUtil::FindNonTransparentBackground(mStyleContext);
if (nsnull != color) {
mWidget->SetBackgroundColor(color->mBackgroundColor);
} else {
mWidget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
}
mWidget->Enable(!nsFormFrame::GetDisabled(this));
}
}
NS_IMETHODIMP
nsNativeRadioControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult result = NS_OK;
if (mWidget) {
if (nsHTMLAtoms::checked == aAttribute) {
nsIRadioButton* button = nsnull;
result = mWidget->QueryInterface(kIRadioIID, (void**)&button);
if ((NS_SUCCEEDED(result)) && (nsnull != button)) {
PRBool checkedAttr = PR_TRUE;
GetCurrentCheckState(&checkedAttr);
PRBool checkedPrevState = PR_TRUE;
button->GetState(checkedPrevState);
if (checkedAttr != checkedPrevState) {
button->SetState(checkedAttr);
mFormFrame->OnRadioChecked(aPresContext, *this, checkedAttr);
}
NS_RELEASE(button);
}
}
// Allow the base class to handle common attributes supported
// by all form elements...
else {
result = Inherited::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
}
}
return result;
}
PRBool nsNativeRadioControlFrame::GetRadioState()
{
PRBool state = PR_FALSE;
if (nsnull != mWidget) {
nsIRadioButton* radio = nsnull;
if (NS_SUCCEEDED(mWidget->QueryInterface(kIRadioIID,(void**)&radio))) {
radio->GetState(state);
NS_RELEASE(radio);
}
}
return state;
}
void nsNativeRadioControlFrame::SetRadioState(nsIPresContext* aPresContext, PRBool aValue)
{
if (nsnull != mWidget) {
nsIRadioButton* radio = nsnull;
if (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio)) {
radio->SetState(aValue);
NS_RELEASE(radio);
}
}
}

View File

@@ -1,76 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsNativeRadioControlFrame_h___
#define nsNativeRadioControlFrame_h___
#include "nsIRadioControlFrame.h"
#include "nsRadioControlFrame.h"
#include "nsVoidArray.h"
#include "nsString.h"
class nsIAtom;
// nsNativeRadioControlFrame
class nsNativeRadioControlFrame : public nsRadioControlFrame
{
private:
typedef nsRadioControlFrame Inherited;
public:
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
protected:
virtual PRBool GetRadioState();
virtual void SetRadioState(nsIPresContext* aPresContetx, PRBool aValue);
virtual nscoord GetRadioboxSize(nsIPresContext* aPresContext, float aPixToTwip) const;
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize);
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize)
{ nsFormControlFrame::GetDesiredSize(aPresContext, aReflowState, aDesiredSize); }
private:
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,632 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsCOMPtr.h"
#include "nsNativeTextControlFrame.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIFrame.h"
#include "nsISupports.h"
#include "nsIAtom.h"
#include "nsIPresContext.h"
#include "nsIHTMLContent.h"
#include "nsHTMLIIDs.h"
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsWidgetsCID.h"
#include "nsSize.h"
#include "nsString.h"
#include "nsHTMLAtoms.h"
#include "nsIStyleContext.h"
#include "nsFont.h"
#include "nsDOMEvent.h"
#include "nsIFormControl.h"
#include "nsFormFrame.h"
#include "nsIContent.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLTextAreaElement.h"
#include "nsCSSRendering.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsILookAndFeel.h"
#include "nsIComponentManager.h"
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kTextCID, NS_TEXTFIELD_CID);
static NS_DEFINE_IID(kTextAreaCID, NS_TEXTAREA_CID);
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
nsresult
NS_NewNativeTextControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsNativeTextControlFrame* it = new (aPresShell) nsNativeTextControlFrame;
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aNewFrame = it;
return NS_OK;
}
nsNativeTextControlFrame::nsNativeTextControlFrame()
: mCachedState(nsnull)
{
}
nsNativeTextControlFrame::~nsNativeTextControlFrame()
{
if (mCachedState) {
delete mCachedState;
mCachedState = nsnull;
}
}
void
nsNativeTextControlFrame::EnterPressed(nsIPresContext* aPresContext)
{
if (mFormFrame && mFormFrame->CanSubmit(this)) {
nsIContent *formContent = nsnull;
mFormFrame->GetContent(&formContent);
if (nsnull != formContent) {
nsEvent event;
nsEventStatus status = nsEventStatus_eIgnore;
event.eventStructType = NS_EVENT;
event.message = NS_FORM_SUBMIT;
formContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
NS_RELEASE(formContent);
}
mFormFrame->OnSubmit(aPresContext, this);
}
}
nsWidgetInitData*
nsNativeTextControlFrame::GetWidgetInitData(nsIPresContext* aPresContext)
{
PRInt32 type;
GetType(&type);
nsTextWidgetInitData* data = nsnull;
PRBool readOnly = nsFormFrame::GetReadonly(this);
if ((NS_FORM_INPUT_PASSWORD == type) || readOnly) {
data = new nsTextWidgetInitData();
data->mIsPassword = PR_FALSE;
data->mIsReadOnly = PR_FALSE;
if (NS_FORM_INPUT_PASSWORD == type) {
data->clipChildren = PR_TRUE;
data->mIsPassword = PR_TRUE;
}
if (readOnly) {
data->mIsReadOnly = PR_TRUE;
}
}
return data;
}
NS_IMETHODIMP
nsNativeTextControlFrame::GetText(nsString* aText, PRBool aInitialValue)
{
nsresult result = NS_CONTENT_ATTR_NOT_THERE;
PRInt32 type;
GetType(&type);
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
result = nsFormControlHelper::GetInputElementValue(mContent, aText, aInitialValue);
} else {
nsIDOMHTMLTextAreaElement* textArea = nsnull;
result = mContent->QueryInterface(kIDOMHTMLTextAreaElementIID, (void**)&textArea);
if ((NS_OK == result) && textArea) {
if (PR_TRUE == aInitialValue) {
result = textArea->GetDefaultValue(*aText);
}
else {
result = textArea->GetValue(*aText);
}
NS_RELEASE(textArea);
}
}
return result;
}
NS_IMETHODIMP
nsNativeTextControlFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult result = NS_OK;
if (mWidget) {
nsITextWidget* text = nsnull;
result = mWidget->QueryInterface(kITextWidgetIID, (void**)&text);
if ((NS_OK == result) && (nsnull != text)) {
if (nsHTMLAtoms::value == aAttribute) {
nsString value;
/*XXXnsresult rv = */GetText(&value, PR_TRUE);
PRUint32 ignore;
text->SetText(value, ignore);
if (aHint != NS_STYLE_HINT_REFLOW)
nsFormFrame::StyleChangeReflow(aPresContext, this);
} else if (nsHTMLAtoms::maxlength == aAttribute) {
PRInt32 maxLength;
nsresult rv = GetMaxLength(&maxLength);
if (NS_CONTENT_ATTR_NOT_THERE != rv) {
text->SetMaxTextLength(maxLength);
}
} else if (nsHTMLAtoms::readonly == aAttribute) {
PRBool oldReadOnly;
text->SetReadOnly(nsFormFrame::GetReadonly(this),oldReadOnly);
}
else if (nsHTMLAtoms::size == aAttribute &&
aHint != NS_STYLE_HINT_REFLOW) {
nsFormFrame::StyleChangeReflow(aPresContext, this);
}
// Allow the base class to handle common attributes supported
// by all form elements...
else {
result = nsNativeFormControlFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
}
NS_RELEASE(text);
}
// XXX Ick, create an common interface that has the functionality of nsTextHelper
else { // We didn't get a Text, is it a TextArea?
nsITextAreaWidget* textArea = nsnull;
result = mWidget->QueryInterface(kITextAreaWidgetIID, (void**)&textArea);
if ((NS_OK == result) && (nsnull != textArea)) {
if (nsHTMLAtoms::value == aAttribute) {
nsString value;
/*XXXnsresult rv = */GetText(&value, PR_TRUE);
PRUint32 ignore;
textArea->SetText(value, ignore);
nsFormFrame::StyleChangeReflow(aPresContext, this);
} else if (nsHTMLAtoms::maxlength == aAttribute) {
PRInt32 maxLength;
nsresult rv = GetMaxLength(&maxLength);
if (NS_CONTENT_ATTR_NOT_THERE != rv) {
textArea->SetMaxTextLength(maxLength);
}
} else if (nsHTMLAtoms::readonly == aAttribute) {
PRBool oldReadOnly;
textArea->SetReadOnly(nsFormFrame::GetReadonly(this),oldReadOnly);
}
else if (nsHTMLAtoms::size == aAttribute) {
nsFormFrame::StyleChangeReflow(aPresContext, this);
}
// Allow the base class to handle common attributes supported
// by all form elements...
else {
result = nsNativeFormControlFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
}
NS_RELEASE(textArea);
}
else { // We didn't get a Text or TextArea. Uh oh...
result = nsNativeFormControlFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
}
}
}
return result;
}
void
nsNativeTextControlFrame::PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight)
{
if (!mWidget) {
return;
}
PRInt32 type;
GetType(&type);
const nsFont * font = nsnull;
if (NS_SUCCEEDED(GetFont(aPresContext, font))) {
mWidget->SetFont(*font);
}
SetColors(aPresContext);
PRUint32 ignore;
nsAutoString value;
nsITextAreaWidget* textArea = nsnull;
nsITextWidget* text = nsnull;
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
if (mCachedState) {
value = *mCachedState;
delete mCachedState;
mCachedState = nsnull;
} else
GetText(&value, PR_TRUE);
text->SetText(value, ignore);
PRInt32 maxLength;
nsresult result = GetMaxLength(&maxLength);
if (NS_CONTENT_ATTR_NOT_THERE != result) {
text->SetMaxTextLength(maxLength);
}
NS_RELEASE(text);
} else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&textArea)) {
if (mCachedState) {
value = *mCachedState;
delete mCachedState;
mCachedState = nsnull;
} else
GetText(&value, PR_TRUE);
textArea->SetText(value, ignore);
NS_RELEASE(textArea);
}
if (nsFormFrame::GetDisabled(this)) {
mWidget->Enable(PR_FALSE);
}
}
PRBool
nsNativeTextControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames)
{
if (!mWidget) {
return PR_FALSE;
}
nsAutoString name;
nsresult result = GetName(&name);
if ((aMaxNumValues <= 0) || (NS_CONTENT_ATTR_NOT_THERE == result)) {
return PR_FALSE;
}
PRUint32 size;
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
aNames[0] = name;
aNumValues = 1;
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
text->GetText(aValues[0],0,size); // the last parm is not used
NS_RELEASE(text);
return PR_TRUE;
} else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&textArea)) {
textArea->GetText(aValues[0],0,size); // the last parm is not used
NS_RELEASE(textArea);
return PR_TRUE;
}
return PR_FALSE;
}
void
nsNativeTextControlFrame::Reset(nsIPresContext* aPresContext)
{
if (!mWidget) {
return;
}
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
nsAutoString value;
nsresult valStatus = GetText(&value, PR_TRUE);
PRUint32 size;
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
if (NS_CONTENT_ATTR_HAS_VALUE == valStatus) {
text->SetText(value,size);
} else {
text->SetText("",size);
}
NS_RELEASE(text);
} else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&textArea)) {
if (NS_CONTENT_ATTR_HAS_VALUE == valStatus) {
textArea->SetText(value,size);
} else {
textArea->SetText("",size);
}
NS_RELEASE(textArea);
}
}
void
nsNativeTextControlFrame::PaintTextControlBackground(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer) {
nsNativeFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
}
void
nsNativeTextControlFrame::PaintTextControl(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsString& aText,
nsIStyleContext* aStyleContext, nsRect& aRect)
{
aRenderingContext.PushState();
const nsStyleSpacing* spacing =
(const nsStyleSpacing*)aStyleContext->GetStyleData(eStyleStruct_Spacing);
nsMargin border;
spacing->CalcBorderFor(this, border);
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
nsRect outside(aRect.x, aRect.y, aRect.width, aRect.height);
outside.Deflate(border);
outside.Deflate(onePixel, onePixel);
nsRect inside(outside);
inside.Deflate(onePixel, onePixel);
#if 0
if (mGotFocus) {
PaintFocus(aRenderingContext,
aDirtyRect, inside, outside);
}
#endif
float appUnits;
float devUnits;
float scale;
nsIDeviceContext * context;
aRenderingContext.GetDeviceContext(context);
context->GetCanonicalPixelScale(scale);
context->GetAppUnitsToDevUnits(devUnits);
context->GetDevUnitsToAppUnits(appUnits);
aRenderingContext.SetColor(NS_RGB(0,0,0));
const nsFont * font = nsnull;
nsresult res = GetFont(aPresContext, font);
if (NS_SUCCEEDED(res) && font != nsnull) {
mWidget->SetFont(*font);
aRenderingContext.SetFont(*font);
}
nscoord textWidth;
nscoord textHeight;
aRenderingContext.GetWidth(aText, textWidth);
nsIFontMetrics* metrics;
if (font != nsnull) {
context->GetMetricsFor(*font, metrics);
}
metrics->GetHeight(textHeight);
PRInt32 type;
GetType(&type);
if (NS_FORM_INPUT_TEXT == type || NS_FORM_INPUT_PASSWORD == type) {
nscoord x = inside.x + onePixel + onePixel;
nscoord y;
if (NS_FORM_INPUT_TEXT == type) {
y = ((inside.height - textHeight) / 2) + inside.y;
} else {
metrics->GetMaxAscent(textHeight);
y = ((inside.height - textHeight) / 2) + inside.y;
PRInt32 i;
PRInt32 len = aText.Length();
aText.SetLength(0);
for (i=0;i<len;i++) {
aText.Append("*");
}
}
aRenderingContext.DrawString(aText, x, y);
} else {
float sbWidth;
float sbHeight;
context->GetCanonicalPixelScale(scale);
context->GetScrollBarDimensions(sbWidth, sbHeight);
PRInt32 scrollbarScaledWidth = PRInt32(sbWidth * scale);
PRInt32 scrollbarScaledHeight = PRInt32(sbWidth * scale);
inside.width -= scrollbarScaledWidth;
inside.height -= scrollbarScaledHeight;
PRBool clipEmpty;
aRenderingContext.PushState();
aRenderingContext.SetClipRect(inside, nsClipCombine_kReplace, clipEmpty);
nscoord x = inside.x + onePixel;
nscoord y = inside.y + onePixel;
// Draw multi-line text
PRInt32 oldPos = 0;
PRInt32 pos = aText.FindChar('\n', PR_FALSE,0);
while (1) {
nsString substr;
if (-1 == pos) {
// Single line, no carriage return.
aText.Right(substr, aText.Length()-oldPos);
aRenderingContext.DrawString(substr, x, y);
break;
}
// Strip off substr up to carriage return
aText.Mid(substr, oldPos, ((pos - oldPos) - 1));
aRenderingContext.DrawString(substr, x, y);
y += textHeight;
// Advance to the next carriage return
pos++;
oldPos = pos;
pos = aText.FindChar('\n', PR_FALSE,pos);
}
aRenderingContext.PopState(clipEmpty);
// Scrollbars
nsIAtom * sbAtom = NS_NewAtom(":scrollbar-look");
nsIStyleContext* scrollbarStyle;
aPresContext->ResolvePseudoStyleContextFor(mContent, sbAtom, aStyleContext, PR_FALSE, &scrollbarStyle);
NS_RELEASE(sbAtom);
sbAtom = NS_NewAtom(":scrollbar-arrow-look");
nsIStyleContext* arrowStyle;
aPresContext->ResolvePseudoStyleContextFor(mContent, sbAtom, aStyleContext, PR_FALSE, &arrowStyle);
NS_RELEASE(sbAtom);
nsRect srect(aRect.width-scrollbarScaledWidth-(2*onePixel), 2*onePixel, scrollbarScaledWidth, aRect.height-(onePixel*4)-scrollbarScaledWidth);
nsFormControlHelper::PaintScrollbar(aRenderingContext,aPresContext, aDirtyRect, srect, PR_FALSE, onePixel,
scrollbarStyle, arrowStyle, this, aRect);
// Horizontal
srect.SetRect(2*onePixel, aRect.height-scrollbarScaledHeight-(2*onePixel), aRect.width-(onePixel*4)-scrollbarScaledHeight, scrollbarScaledHeight);
nsFormControlHelper::PaintScrollbar(aRenderingContext,aPresContext, aDirtyRect, srect, PR_TRUE, onePixel,
scrollbarStyle, arrowStyle, this, aRect);
// Draw the small rect "gap" in the bottom right that the two scrollbars don't cover
const nsStyleColor* sbColor = (const nsStyleColor*)scrollbarStyle->GetStyleData(eStyleStruct_Color);
srect.SetRect(aRect.width-scrollbarScaledWidth-(2*onePixel), aRect.height-scrollbarScaledHeight-(onePixel*2), scrollbarScaledWidth, scrollbarScaledHeight);
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
aDirtyRect, srect, *sbColor, *spacing, 0, 0);
}
NS_RELEASE(context);
PRBool status;
aRenderingContext.PopState(status);
}
NS_METHOD
nsNativeTextControlFrame::Paint(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
PaintTextControlBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
nsString text;
GetText(&text, PR_FALSE);
nsRect rect(0, 0, mRect.width, mRect.height);
PaintTextControl(aPresContext, aRenderingContext, aDirtyRect, text, mStyleContext, rect);
}
return NS_OK;
}
void nsNativeTextControlFrame::GetTextControlFrameState(nsString& aValue)
{
if (nsnull != mWidget) {
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
PRUint32 size = 0;
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
text->GetText(aValue,0,size);
NS_RELEASE(text);
}
else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,
(void**)&textArea)) {
textArea->GetText(aValue,0, size);
NS_RELEASE(textArea);
}
}
else {
//XXX: this should return the a local field for GFX-rendered widgets aValue = "";
}
}
void nsNativeTextControlFrame::SetTextControlFrameState(const nsString& aValue)
{
if (nsnull != mWidget) {
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
PRUint32 size = 0;
if (NS_SUCCEEDED(mWidget->QueryInterface(kITextWidgetIID,(void**)&text))) {
text->SetText(aValue,size);
NS_RELEASE(text);
} else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,
(void**)&textArea)) {
textArea->SetText(aValue,size);
NS_RELEASE(textArea);
}
} else {
if (mCachedState) delete mCachedState;
mCachedState = new nsString(aValue);
// XXX if (!mCachedState) rv = NS_ERROR_OUT_OF_MEMORY;
NS_ASSERTION(mCachedState, "Error: new nsString failed!");
}
}
NS_IMETHODIMP nsNativeTextControlFrame::SetProperty(nsIPresContext* aPresContext,
nsIAtom* aName,
const nsAReadableString& aValue)
{
nsresult rv = NS_OK;
if (nsHTMLAtoms::value == aName) {
SetTextControlFrameState(aValue);
} else if (nsHTMLAtoms::select == aName) {
if (nsnull != mWidget) {
nsITextWidget *textWidget;
rv = mWidget->QueryInterface(kITextWidgetIID, (void**)&textWidget);
if (NS_SUCCEEDED(rv)) {
textWidget->SelectAll();
NS_RELEASE(textWidget);
}
nsITextAreaWidget *textAreaWidget;
rv = mWidget->QueryInterface(kITextAreaWidgetIID, (void**)&textAreaWidget);
if (NS_SUCCEEDED(rv)) {
textAreaWidget->SelectAll();
NS_RELEASE(textAreaWidget);
}
}
}
else {
return nsNativeFormControlFrame::SetProperty(aPresContext, aName, aValue);
}
return rv;
}
NS_IMETHODIMP nsNativeTextControlFrame::GetProperty(nsIAtom* aName, nsAWritableString& aValue)
{
// Return the value of the property from the widget it is not null.
// If widget is null, assume the widget is GFX-rendered and return a member variable instead.
if (nsHTMLAtoms::value == aName) {
GetTextControlFrameState(aValue);
}
else {
return nsNativeFormControlFrame::GetProperty(aName, aValue);
}
return NS_OK;
}
nsresult nsNativeTextControlFrame::RequiresWidget(PRBool &aRequiresWidget)
{
aRequiresWidget = PR_TRUE;
return NS_OK;
}

View File

@@ -1,87 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsNativeTextControlFrame_h___
#define nsNativeTextControlFrame_h___
#include "nsTextControlFrame.h"
class nsIContent;
class nsIFrame;
class nsIPresContext;
class nsNativeTextControlFrame : public nsTextControlFrame
{
public:
nsNativeTextControlFrame();
virtual ~nsNativeTextControlFrame();
// nsIFormControlFrame
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue);
NS_IMETHOD GetProperty(nsIAtom* aName, nsAWritableString& aValue);
virtual nsWidgetInitData* GetWidgetInitData(nsIPresContext* aPresContext);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);
NS_IMETHOD GetText(nsString* aValue, PRBool aInitialValue);
virtual void EnterPressed(nsIPresContext* aPresContext) ;
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames);
virtual void Reset(nsIPresContext* aPresContext);
NS_IMETHOD Paint(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
virtual void PaintTextControlBackground(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
virtual void PaintTextControl(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect, nsString& aText,
nsIStyleContext* aStyleContext,
nsRect& aRect);
// Utility methods to get and set current widget state
void GetTextControlFrameState(nsString& aValue);
void SetTextControlFrameState(const nsString& aValue);
virtual nsresult RequiresWidget(PRBool &aRequiresWidget);
protected:
nsString* mCachedState;
};
#endif

View File

@@ -1,309 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsRadioControlFrame.h"
#include "nsIRadioButton.h"
#include "nsNativeFormControlFrame.h"
#include "nsWidgetsCID.h"
#include "nsIContent.h"
#include "nsHTMLAtoms.h"
#include "nsFormFrame.h"
#include "nsINameSpaceManager.h"
#include "nsFormFrame.h"
#include "nsIStatefulFrame.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
static NS_DEFINE_IID(kIRadioControlFrameIID, NS_IRADIOCONTROLFRAME_IID);
// Frames are not refcounted, no need to AddRef
NS_IMETHODIMP
nsRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIRadioControlFrameIID)) {
*aInstancePtr = (void*) ((nsIRadioControlFrame*) this);
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
*aInstancePtr = (void*) ((nsIStatefulFrame*) this);
return NS_OK;
}
return nsNativeFormControlFrame::QueryInterface(aIID, aInstancePtr);
}
/*
* FIXME: this ::GetIID() method has no meaning in life and should be
* removed.
* Pierre Phaneuf <pp@ludusdesign.com>
*/
const nsIID&
nsRadioControlFrame::GetIID()
{
static NS_DEFINE_IID(kIRadioIID, NS_IRADIOBUTTON_IID);
return kIRadioIID;
}
const nsIID&
nsRadioControlFrame::GetCID()
{
static NS_DEFINE_IID(kRadioCID, NS_RADIOBUTTON_CID);
return kRadioCID;
}
void
nsRadioControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight)
{
// set the widget to the initial state
PRBool checked = PR_FALSE;
nsresult result = GetDefaultCheckState(&checked);
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
if (PR_TRUE == checked)
SetRadioControlFrameState(aPresContext, NS_STRING_TRUE);
else
SetRadioControlFrameState(aPresContext, NS_STRING_FALSE);
}
}
void
nsRadioControlFrame::MouseUp(nsIPresContext* aPresContext)
{
SetRadioControlFrameState(aPresContext, NS_STRING_TRUE);
if (mFormFrame) {
// The form frame will determine which radio button needs
// to be turned off and will call SetChecked on the
// nsRadioControlFrame to unset the checked state
mFormFrame->OnRadioChecked(aPresContext, *this);
}
}
PRBool
nsRadioControlFrame::GetChecked(PRBool aGetInitialValue)
{
PRBool checked = PR_FALSE;
if (PR_TRUE == aGetInitialValue) {
GetDefaultCheckState(&checked);
}
else {
GetCurrentCheckState(&checked);
}
return(checked);
}
void
nsRadioControlFrame::SetChecked(nsIPresContext* aPresContext, PRBool aValue, PRBool aSetInitialValue)
{
if (aSetInitialValue) {
if (aValue) {
mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::checked, nsAutoString("1"), PR_FALSE); // XXX should be "empty" value
} else {
mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::checked, nsAutoString("0"), PR_FALSE);
}
}
if (PR_TRUE == aValue) {
SetRadioControlFrameState(aPresContext, NS_STRING_TRUE);
} else {
SetRadioControlFrameState(aPresContext, NS_STRING_FALSE);
}
}
PRBool
nsRadioControlFrame::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 {
aValues[0] = "on";
}
aNames[0] = name;
aNumValues = 1;
return PR_TRUE;
}
void
nsRadioControlFrame::Reset(nsIPresContext* aPresContext)
{
PRBool checked = PR_TRUE;
GetDefaultCheckState(&checked);
SetCurrentCheckState(checked);
}
#ifdef DEBUG
NS_IMETHODIMP
nsRadioControlFrame::GetFrameName(nsString& aResult) const
{
return MakeFrameName("RadioControl", aResult);
}
#endif
NS_IMETHODIMP
nsRadioControlFrame::SetRadioButtonFaceStyleContext(nsIStyleContext *aRadioButtonFaceStyleContext)
{
/* for gfx widgets only */
return NS_OK;
}
NS_METHOD
nsRadioControlFrame::HandleEvent(nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
NS_ENSURE_ARG_POINTER(aEventStatus);
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
return NS_OK;
}
if (nsFormFrame::GetDisabled(this)) {
return NS_OK;
}
switch(aEvent->message) {
case NS_KEY_PRESS:
if (NS_KEY_EVENT == aEvent->eventStructType) {
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
if (NS_VK_SPACE == keyEvent->keyCode || NS_VK_RETURN == keyEvent->keyCode) {
MouseClicked(aPresContext);
}
}
break;
case NS_MOUSE_LEFT_BUTTON_UP:
MouseUp(aPresContext);
break;
default:
break;
}
return(nsNativeFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus));
}
void nsRadioControlFrame::GetRadioControlFrameState(nsString& aValue)
{
nsFormControlHelper::GetBoolString(GetRadioState(), aValue);
}
void nsRadioControlFrame::SetRadioControlFrameState(nsIPresContext* aPresContext,
const nsString& aValue)
{
PRBool state = nsFormControlHelper::GetBool(aValue);
SetRadioState(aPresContext, state);
}
NS_IMETHODIMP nsRadioControlFrame::SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue)
{
if (nsHTMLAtoms::checked == aName) {
// Set the current state for the radio button because
// the mFormFrame->OnRadioChecked will not set it.
SetRadioControlFrameState(aPresContext, aValue);
if (mFormFrame) {
PRBool state = (aValue == NS_STRING_TRUE) ? PR_TRUE : PR_FALSE;
mFormFrame->OnRadioChecked(aPresContext, *this, state);
}
}
else {
return nsNativeFormControlFrame::SetProperty(aPresContext, aName, aValue);
}
return NS_OK;
}
NS_IMETHODIMP nsRadioControlFrame::GetProperty(nsIAtom* aName, nsAWritableString& aValue)
{
// 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.
if (nsHTMLAtoms::checked == aName) {
GetRadioControlFrameState(aValue);
}
else {
return nsNativeFormControlFrame::GetProperty(aName, aValue);
}
return NS_OK;
}
nsresult nsRadioControlFrame::RequiresWidget(PRBool& aRequiresWidget)
{
aRequiresWidget = PR_FALSE;
return NS_OK;
}
//----------------------------------------------------------------------
// nsIStatefulFrame
//----------------------------------------------------------------------
NS_IMETHODIMP
nsRadioControlFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::StateType* aStateType)
{
*aStateType = nsIStatefulFrame::eRadioType;
return NS_OK;
}
NS_IMETHODIMP
nsRadioControlFrame::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;
GetRadioControlFrameState(stateString);
(*aState)->SetStateProperty("checked", stateString);
return NS_OK;
}
NS_IMETHODIMP
nsRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{
nsAutoString string;
aState->GetStateProperty("checked", string);
SetRadioControlFrameState(aPresContext, string);
return NS_OK;
}

View File

@@ -1,108 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsRadioControlFrame_h___
#define nsRadioControlFrame_h___
#include "nsIRadioControlFrame.h"
#include "nsNativeFormControlFrame.h"
#include "nsVoidArray.h"
#include "nsString.h"
#include "nsIStatefulFrame.h"
#include "nsIPresState.h"
class nsIAtom;
// nsRadioControlFrame
class nsRadioControlFrame : public nsNativeFormControlFrame,
public nsIRadioControlFrame,
public nsIStatefulFrame
{
public:
// nsFormControlFrame overrides
nsresult RequiresWidget(PRBool &aHasWidget);
// nsIFormControlFrame
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue);
NS_IMETHOD GetProperty(nsIAtom* aName, nsAWritableString& aValue);
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const;
#endif
//nsIRadioControlFrame methods
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD SetRadioButtonFaceStyleContext(nsIStyleContext *aRadioButtonFaceStyleContext);
virtual PRBool GetChecked(PRBool aGetInitialValue);
virtual void SetChecked(nsIPresContext* aPresContext, PRBool aValue, PRBool aSetInitialValue);
virtual PRInt32 GetMaxNumValues() { return 1; }
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames);
virtual void MouseUp(nsIPresContext* aPresContext);
virtual void Reset(nsIPresContext* aPresContext);
virtual const nsIID& GetCID();
//
// XXX: The following paint methods are TEMPORARY. It is being used to get printing working
// under windows. Later it may be used to GFX-render the controls to the display.
// Expect this code to repackaged and moved to a new location in the future.
//
NS_IMETHOD HandleEvent(nsIPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
///XXX: End o the temporary methods
//nsIStatefulFrame
NS_IMETHOD GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::StateType* aStateType);
NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState);
NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState);
protected:
// Utility methods for implementing SetProperty/GetProperty
void SetRadioControlFrameState(nsIPresContext* aPresContext, const nsString& aValue);
void GetRadioControlFrameState(nsString& aValue);
protected:
virtual PRBool GetRadioState() = 0;
virtual void SetRadioState(nsIPresContext* aPresContext, PRBool aValue) = 0;
private:
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,407 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsCOMPtr.h"
#include "nsTextControlFrame.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIFrame.h"
#include "nsISupports.h"
#include "nsIAtom.h"
#include "nsIPresContext.h"
#include "nsIHTMLContent.h"
#include "nsHTMLIIDs.h"
#include "nsITextWidget.h"
#include "nsWidgetsCID.h"
#include "nsSize.h"
#include "nsString.h"
#include "nsLinebreakConverter.h"
#include "nsHTMLAtoms.h"
#include "nsIStyleContext.h"
#include "nsFont.h"
#include "nsDOMEvent.h"
#include "nsIFormControl.h"
#include "nsFormFrame.h"
#include "nsIContent.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLTextAreaElement.h"
#include "nsCSSRendering.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsILookAndFeel.h"
#include "nsIComponentManager.h"
#include "nsIStatefulFrame.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kTextCID, NS_TEXTFIELD_CID);
static NS_DEFINE_IID(kTextAreaCID, NS_TEXTAREA_CID);
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
const nscoord kSuggestedNotSet = -1;
nsTextControlFrame::nsTextControlFrame()
{
mSuggestedWidth = kSuggestedNotSet;
mSuggestedHeight = kSuggestedNotSet;
}
nsTextControlFrame::~nsTextControlFrame()
{
}
// Frames are not refcounted, no need to AddRef
NS_IMETHODIMP
nsTextControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
} else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
*aInstancePtr = (void*)(nsIStatefulFrame*) this;
return NS_OK;
}
return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
}
nscoord
nsTextControlFrame::GetVerticalBorderWidth(float aPixToTwip) const
{
return NSIntPixelsToTwips(4, aPixToTwip);
}
nscoord
nsTextControlFrame::GetHorizontalBorderWidth(float aPixToTwip) const
{
return GetVerticalBorderWidth(aPixToTwip);
}
// for a text area aInnerHeight is the height of one line
nscoord
nsTextControlFrame::GetVerticalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerHeight) const
{
// XXX NOTE: the enums eMetric_TextShouldUseVerticalInsidePadding and eMetric_TextVerticalInsidePadding
// are ONLY needed because GTK is not using the "float" padding values and wants to only use an
// integer value for the padding instead of calculating like the other platforms.
//
// If GTK decides to start calculating the value, PLEASE remove these two enum from nsILookAndFeel and
// all the platforms nsLookAndFeel impementations so we don't have these extra values remaining in the code.
// The two enums are:
// eMetric_TextVerticalInsidePadding
// eMetric_TextShouldUseVerticalInsidePadding
//
float padTextArea;
float padTextField;
PRInt32 vertPad;
PRInt32 shouldUseVertPad;
nsCOMPtr<nsILookAndFeel> lookAndFeel;
if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextAreaVerticalInsidePadding, padTextArea);
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextFieldVerticalInsidePadding, padTextField);
// These two (below) are really only needed for GTK
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextVerticalInsidePadding, vertPad);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextShouldUseVerticalInsidePadding, shouldUseVertPad);
}
if (1 == shouldUseVertPad) {
return NSIntPixelsToTwips(vertPad, aPixToTwip); // XXX this is probably wrong (for GTK)
} else {
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return (nscoord)NSToIntRound(float(aInnerHeight) * padTextArea);
} else {
return (nscoord)NSToIntRound(float(aInnerHeight) * padTextField);
}
}
}
//static float pad = 0.95F;
nscoord
nsTextControlFrame::GetHorizontalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerWidth,
nscoord aCharWidth) const
{
// XXX NOTE: the enum eMetric_TextShouldUseHorizontalInsideMinimumPadding
// is ONLY needed because GTK is not using the "float" padding values and wants to only use the
// "minimum" integer value for the padding instead of calculating and comparing like the other platforms.
//
// If GTK decides to start calculating and comparing the values,
// PLEASE remove these the enum from nsILookAndFeel and
// all the platforms nsLookAndFeel impementations so we don't have these extra values remaining in the code.
// The enum is:
// eMetric_TextShouldUseHorizontalInsideMinimumPadding
//
float padTextField;
float padTextArea;
PRInt32 padMinText;
PRInt32 shouldUsePadMinText;
nsCOMPtr<nsILookAndFeel> lookAndFeel;
if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextFieldHorizontalInsidePadding, padTextField);
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextAreaHorizontalInsidePadding, padTextArea);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextHorizontalInsideMinimumPadding, padMinText);
// This one (below) is really only needed for GTK
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextShouldUseHorizontalInsideMinimumPadding, shouldUsePadMinText);
}
//padTextField = pad;
nscoord padding;
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
padding = (nscoord)(aCharWidth * padTextArea);
} else {
padding = (nscoord)(aCharWidth * padTextField);
}
nscoord min = NSIntPixelsToTwips(padMinText, aPixToTwip);
if (padding > min && (1 == shouldUsePadMinText)) {
return padding;
} else {
return min;
}
}
/*
* FIXME: this ::GetIID() method has no meaning in life and should be
* removed.
* Pierre Phaneuf <pp@ludusdesign.com>
*/
const nsIID&
nsTextControlFrame::GetIID()
{
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return kITextAreaWidgetIID;
} else {
return kITextWidgetIID;
}
}
const nsIID&
nsTextControlFrame::GetCID()
{
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return kTextAreaCID;
} else {
return kTextCID;
}
}
void
nsTextControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize)
{
nsSize widgetSize;
GetDesiredSize(aPresContext, aReflowState, aDesiredLayoutSize, widgetSize);
}
void
nsTextControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize)
{
nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode);
// get the css size and let the frame use or override it
nsSize styleSize;
GetStyleSize(aPresContext, aReflowState, styleSize);
nsSize desiredSize;
nsSize minSize;
PRBool widthExplicit, heightExplicit;
PRInt32 ignore;
PRInt32 type;
GetType(&type);
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
PRInt32 width;
if (NS_CONTENT_ATTR_HAS_VALUE != GetSizeFromContent(&width)) {
width = GetDefaultColumnWidth();
}
//if (eCompatibility_NavQuirks == mode) {
// width += 1;
//}
nsInputDimensionSpec textSpec(nsnull, PR_FALSE, nsnull,
nsnull, width, PR_FALSE, nsnull, 1);
nsFormControlHelper::CalculateSize(aPresContext, aReflowState.rendContext, this, styleSize,
textSpec, desiredSize, minSize, widthExplicit, heightExplicit, ignore);
} else {
nsInputDimensionSpec areaSpec(nsHTMLAtoms::cols, PR_FALSE, nsnull, nsnull, GetDefaultColumnWidth(),
PR_FALSE, nsHTMLAtoms::rows, 1);
nsFormControlHelper::CalculateSize(aPresContext, aReflowState.rendContext, this, styleSize,
areaSpec, desiredSize, minSize, widthExplicit, heightExplicit, ignore);
}
// CalculateSize makes calls in the nsFormControlHelper that figures
// out the entire size of the control when in NavQuirks mode. For the
// textarea, this means the scrollbar sizes hav already been added to
// its overall size and do not need to be added here.
float p2t;
aPresContext->GetPixelsToTwips(&p2t);
if (NS_FORM_TEXTAREA == type && mode == eCompatibility_Standard) {
nscoord scrollbarWidth = 0;
nscoord scrollbarHeight = 0;
float scale;
nsCOMPtr<nsIDeviceContext> dx;
aPresContext->GetDeviceContext(getter_AddRefs(dx));
if (dx) {
float sbWidth;
float sbHeight;
dx->GetCanonicalPixelScale(scale);
dx->GetScrollBarDimensions(sbWidth, sbHeight);
scrollbarWidth = PRInt32(sbWidth * scale);
scrollbarHeight = PRInt32(sbHeight * scale);
} else {
scrollbarWidth = GetScrollbarWidth(p2t);
scrollbarHeight = scrollbarWidth;
}
if (!heightExplicit) {
desiredSize.height += scrollbarHeight;
minSize.height += scrollbarHeight;
}
if (!widthExplicit) {
desiredSize.width += scrollbarWidth;
minSize.width += scrollbarWidth;
}
}
aDesiredLayoutSize.width = desiredSize.width;
aDesiredLayoutSize.height = desiredSize.height;
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
aDesiredLayoutSize.descent = 0;
if (aDesiredLayoutSize.maxElementSize) {
aDesiredLayoutSize.maxElementSize->width = minSize.width;
aDesiredLayoutSize.maxElementSize->height = minSize.height;
}
aDesiredWidgetSize.width = aDesiredLayoutSize.width;
aDesiredWidgetSize.height = aDesiredLayoutSize.height;
}
PRInt32
nsTextControlFrame::GetMaxNumValues()
{
return 1;
}
NS_IMETHODIMP
nsTextControlFrame::GetCursor(nsIPresContext* aPresContext, nsPoint& aPoint, PRInt32& aCursor)
{
/*const nsStyleColor* styleColor;
GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)styleColor);
aCursor = styleColor->mCursor;*/
//XXX This is wrong, should be through style.
aCursor = NS_STYLE_CURSOR_TEXT;
return NS_OK;
}
#ifdef DEBUG
NS_IMETHODIMP
nsTextControlFrame::GetFrameName(nsString& aResult) const
{
return MakeFrameName("TextControl", aResult);
}
#endif
//---------------------------------------------------------
NS_IMETHODIMP
nsTextControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight)
{
mSuggestedWidth = aWidth;
mSuggestedHeight = aHeight;
return NS_OK;
}
//----------------------------------------------------------------------
// nsIStatefulFrame
//----------------------------------------------------------------------
NS_IMETHODIMP
nsTextControlFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::StateType* aStateType)
{
*aStateType = nsIStatefulFrame::eTextType;
return NS_OK;
}
NS_IMETHODIMP
nsTextControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
nsAutoString theString;
nsresult res = GetProperty(nsHTMLAtoms::value, theString);
if (NS_SUCCEEDED(res)) {
char* chars = theString.ToNewCString();
if (chars) {
// GetProperty returns platform-native line breaks. We must convert
// these to content line breaks.
char* newChars = nsLinebreakConverter::ConvertLineBreaks(chars,
nsLinebreakConverter::eLinebreakPlatform, nsLinebreakConverter::eLinebreakContent);
if (newChars) {
nsCRT::free(chars);
chars = newChars;
}
(*aState)->SetStateProperty("value", nsAutoString(chars));
nsCRT::free(chars);
} else {
res = NS_ERROR_OUT_OF_MEMORY;
}
}
(*aState)->SetStateProperty("value", theString);
return res;
}
NS_IMETHODIMP
nsTextControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{
nsAutoString stateString;
aState->GetStateProperty("value", stateString);
nsresult res = SetProperty(aPresContext, nsHTMLAtoms::value, stateString);
return res;
}

View File

@@ -1,138 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsTextControlFrame_h___
#define nsTextControlFrame_h___
#include "nsNativeFormControlFrame.h"
#include "nsIStatefulFrame.h"
#include "nsIPresState.h"
class nsIContent;
class nsIFrame;
class nsIPresContext;
class nsTextControlFrame : public nsNativeFormControlFrame,
public nsIStatefulFrame
{
/* ---------- methods implemented by base class ---------- */
public:
nsTextControlFrame();
virtual ~nsTextControlFrame();
virtual const nsIID& GetCID();
virtual const nsIID& GetIID();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsString& aResult) const;
#endif
virtual nscoord GetVerticalBorderWidth(float aPixToTwip) const;
virtual nscoord GetHorizontalBorderWidth(float aPixToTwip) const;
virtual nscoord GetVerticalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerHeight) const;
virtual nscoord GetHorizontalInsidePadding(nsIPresContext* aPresContext,
float aPixToTwip,
nscoord aInnerWidth,
nscoord aCharWidth) const;
virtual PRInt32 GetMaxNumValues();
NS_IMETHOD GetCursor(nsIPresContext* aPresContext, nsPoint& aPoint, PRInt32& aCursor);
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
//nsIStatefulFrame
NS_IMETHOD GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::StateType* aStateType);
NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState);
NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState);
protected:
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize);
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize);
PRInt32 GetDefaultColumnWidth() const { return (PRInt32)(20); } // this was DEFAULT_PIXEL_WIDTH
private:
NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
/* ---------- abstract methods derived class must implement ---------- */
public:
// nsIFormControlFrame
NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue)=0;
NS_IMETHOD GetProperty(nsIAtom* aName, nsAWritableString& aValue)=0;
virtual nsWidgetInitData* GetWidgetInitData(nsIPresContext* aPresContext)=0;
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint)=0;
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight)=0;
NS_IMETHOD GetText(nsString* aValue, PRBool aInitialValue)=0;
virtual void EnterPressed(nsIPresContext* aPresContext)=0;
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames)=0;
virtual void Reset(nsIPresContext* aPresContext)=0;
NS_IMETHOD Paint(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)=0;
virtual void PaintTextControlBackground(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)=0;
virtual void PaintTextControl(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect, nsString& aText,
nsIStyleContext* aStyleContext,
nsRect& aRect)=0;
// Utility methods to get and set current widget state
virtual void GetTextControlFrameState(nsString& aValue)=0;
virtual void SetTextControlFrameState(const nsString& aValue)=0;
virtual nsresult RequiresWidget(PRBool &aRequiresWidget)=0;
};
#endif