From 622694d09ffbc3103286c599c3802fe73631bb7b Mon Sep 17 00:00:00 2001 From: "kmcclusk%netscape.com" Date: Thu, 16 Nov 2000 21:41:14 +0000 Subject: [PATCH] Removing these unneeded files from from cvs, they have been in the build in years r=kmcclusk,buster git-svn-id: svn://10.0.0.236/trunk@82697 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/nsTextControlFrame.cpp | 407 ----- mozilla/layout/forms/nsTextControlFrame.h | 138 -- .../html/forms/src/nsButtonControlFrame.cpp | 360 ---- .../html/forms/src/nsButtonControlFrame.h | 94 - .../html/forms/src/nsCheckboxControlFrame.cpp | 449 ----- .../html/forms/src/nsCheckboxControlFrame.h | 139 -- .../forms/src/nsNativeButtonControlFrame.cpp | 106 -- .../forms/src/nsNativeButtonControlFrame.h | 49 - .../forms/src/nsNativeCheckboxControlFram.cpp | 161 -- .../forms/src/nsNativeCheckboxControlFram.h | 59 - .../forms/src/nsNativeFormControlFrame.cpp | 332 ---- .../html/forms/src/nsNativeFormControlFrame.h | 90 - .../forms/src/nsNativeRadioControlFrame.cpp | 178 -- .../forms/src/nsNativeRadioControlFrame.h | 76 - .../forms/src/nsNativeSelectControlFrame.cpp | 1584 ----------------- .../forms/src/nsNativeTextControlFrame.cpp | 632 ------- .../html/forms/src/nsNativeTextControlFrame.h | 87 - .../html/forms/src/nsRadioControlFrame.cpp | 309 ---- .../html/forms/src/nsRadioControlFrame.h | 108 -- .../html/forms/src/nsSelectControlFrame.cpp | 1433 --------------- .../html/forms/src/nsTextControlFrame.cpp | 407 ----- .../html/forms/src/nsTextControlFrame.h | 138 -- 22 files changed, 7336 deletions(-) delete mode 100644 mozilla/layout/forms/nsTextControlFrame.cpp delete mode 100644 mozilla/layout/forms/nsTextControlFrame.h delete mode 100644 mozilla/layout/html/forms/src/nsButtonControlFrame.cpp delete mode 100644 mozilla/layout/html/forms/src/nsButtonControlFrame.h delete mode 100644 mozilla/layout/html/forms/src/nsCheckboxControlFrame.cpp delete mode 100644 mozilla/layout/html/forms/src/nsCheckboxControlFrame.h delete mode 100644 mozilla/layout/html/forms/src/nsNativeButtonControlFrame.cpp delete mode 100644 mozilla/layout/html/forms/src/nsNativeButtonControlFrame.h delete mode 100644 mozilla/layout/html/forms/src/nsNativeCheckboxControlFram.cpp delete mode 100644 mozilla/layout/html/forms/src/nsNativeCheckboxControlFram.h delete mode 100644 mozilla/layout/html/forms/src/nsNativeFormControlFrame.cpp delete mode 100644 mozilla/layout/html/forms/src/nsNativeFormControlFrame.h delete mode 100644 mozilla/layout/html/forms/src/nsNativeRadioControlFrame.cpp delete mode 100644 mozilla/layout/html/forms/src/nsNativeRadioControlFrame.h delete mode 100644 mozilla/layout/html/forms/src/nsNativeSelectControlFrame.cpp delete mode 100644 mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp delete mode 100644 mozilla/layout/html/forms/src/nsNativeTextControlFrame.h delete mode 100644 mozilla/layout/html/forms/src/nsRadioControlFrame.cpp delete mode 100644 mozilla/layout/html/forms/src/nsRadioControlFrame.h delete mode 100644 mozilla/layout/html/forms/src/nsSelectControlFrame.cpp delete mode 100644 mozilla/layout/html/forms/src/nsTextControlFrame.cpp delete mode 100644 mozilla/layout/html/forms/src/nsTextControlFrame.h diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp deleted file mode 100644 index 804e77d7836..00000000000 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ /dev/null @@ -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 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 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 - */ -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 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; -} diff --git a/mozilla/layout/forms/nsTextControlFrame.h b/mozilla/layout/forms/nsTextControlFrame.h deleted file mode 100644 index 63d2a95e61a..00000000000 --- a/mozilla/layout/forms/nsTextControlFrame.h +++ /dev/null @@ -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 diff --git a/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp deleted file mode 100644 index d734dd05d94..00000000000 --- a/mozilla/layout/html/forms/src/nsButtonControlFrame.cpp +++ /dev/null @@ -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 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 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 - */ -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; -} - diff --git a/mozilla/layout/html/forms/src/nsButtonControlFrame.h b/mozilla/layout/html/forms/src/nsButtonControlFrame.h deleted file mode 100644 index 526a9d62245..00000000000 --- a/mozilla/layout/html/forms/src/nsButtonControlFrame.h +++ /dev/null @@ -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 - diff --git a/mozilla/layout/html/forms/src/nsCheckboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsCheckboxControlFrame.cpp deleted file mode 100644 index dc0e1f334ab..00000000000 --- a/mozilla/layout/html/forms/src/nsCheckboxControlFrame.cpp +++ /dev/null @@ -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 - */ -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; -} diff --git a/mozilla/layout/html/forms/src/nsCheckboxControlFrame.h b/mozilla/layout/html/forms/src/nsCheckboxControlFrame.h deleted file mode 100644 index d97494392db..00000000000 --- a/mozilla/layout/html/forms/src/nsCheckboxControlFrame.h +++ /dev/null @@ -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 diff --git a/mozilla/layout/html/forms/src/nsNativeButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsNativeButtonControlFrame.cpp deleted file mode 100644 index 4e7f6e6dbf4..00000000000 --- a/mozilla/layout/html/forms/src/nsNativeButtonControlFrame.cpp +++ /dev/null @@ -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)); - } -} - diff --git a/mozilla/layout/html/forms/src/nsNativeButtonControlFrame.h b/mozilla/layout/html/forms/src/nsNativeButtonControlFrame.h deleted file mode 100644 index b8d1b6db81a..00000000000 --- a/mozilla/layout/html/forms/src/nsNativeButtonControlFrame.h +++ /dev/null @@ -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 - diff --git a/mozilla/layout/html/forms/src/nsNativeCheckboxControlFram.cpp b/mozilla/layout/html/forms/src/nsNativeCheckboxControlFram.cpp deleted file mode 100644 index 8551c5d02a6..00000000000 --- a/mozilla/layout/html/forms/src/nsNativeCheckboxControlFram.cpp +++ /dev/null @@ -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 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); - } - } -} diff --git a/mozilla/layout/html/forms/src/nsNativeCheckboxControlFram.h b/mozilla/layout/html/forms/src/nsNativeCheckboxControlFram.h deleted file mode 100644 index d8e8ef5b00d..00000000000 --- a/mozilla/layout/html/forms/src/nsNativeCheckboxControlFram.h +++ /dev/null @@ -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 diff --git a/mozilla/layout/html/forms/src/nsNativeFormControlFrame.cpp b/mozilla/layout/html/forms/src/nsNativeFormControlFrame.cpp deleted file mode 100644 index 6b8063aa11d..00000000000 --- a/mozilla/layout/html/forms/src/nsNativeFormControlFrame.cpp +++ /dev/null @@ -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 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 presShell; - aPresContext->GetShell(getter_AddRefs(presShell)); - nsCOMPtr 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; -} - diff --git a/mozilla/layout/html/forms/src/nsNativeFormControlFrame.h b/mozilla/layout/html/forms/src/nsNativeFormControlFrame.h deleted file mode 100644 index 1624cddf855..00000000000 --- a/mozilla/layout/html/forms/src/nsNativeFormControlFrame.h +++ /dev/null @@ -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 - diff --git a/mozilla/layout/html/forms/src/nsNativeRadioControlFrame.cpp b/mozilla/layout/html/forms/src/nsNativeRadioControlFrame.cpp deleted file mode 100644 index fbbf093eee5..00000000000 --- a/mozilla/layout/html/forms/src/nsNativeRadioControlFrame.cpp +++ /dev/null @@ -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 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); - } - } -} diff --git a/mozilla/layout/html/forms/src/nsNativeRadioControlFrame.h b/mozilla/layout/html/forms/src/nsNativeRadioControlFrame.h deleted file mode 100644 index 575c086e3cb..00000000000 --- a/mozilla/layout/html/forms/src/nsNativeRadioControlFrame.h +++ /dev/null @@ -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 - - diff --git a/mozilla/layout/html/forms/src/nsNativeSelectControlFrame.cpp b/mozilla/layout/html/forms/src/nsNativeSelectControlFrame.cpp deleted file mode 100644 index b2c98623a4d..00000000000 --- a/mozilla/layout/html/forms/src/nsNativeSelectControlFrame.cpp +++ /dev/null @@ -1,1584 +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): - */ - -// YY need to pass isMultiple before create called -#include "nsCOMPtr.h" -#include "nsNativeFormControlFrame.h" -#include "nsFormFrame.h" -#include "nsIDOMNode.h" -#include "nsIDOMHTMLSelectElement.h" -#include "nsIDOMHTMLOptionElement.h" -#include "nsIDOMHTMLCollection.h" -#include "nsDOMEvent.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 "nsIRadioButton.h" -#include "nsWidgetsCID.h" -#include "nsSize.h" -#include "nsHTMLAtoms.h" -#include "nsIView.h" -#include "nsIListWidget.h" -#include "nsIComboBox.h" -#include "nsIListBox.h" -#include "nsIStyleContext.h" -#include "nsStyleConsts.h" -#include "nsStyleUtil.h" -#include "nsFont.h" -#include "nsIDeviceContext.h" -#include "nsIFontMetrics.h" -#include "nsILookAndFeel.h" -#include "nsIComponentManager.h" -#include "nsISelectControlFrame.h" -#include "nsIStatefulFrame.h" -#include "nsISupportsArray.h" -#include "nsISupportsPrimitives.h" -#include "nsIComponentManager.h" -#include "nsIPresState.h" - -static NS_DEFINE_IID(kIDOMHTMLSelectElementIID, NS_IDOMHTMLSELECTELEMENT_IID); -static NS_DEFINE_IID(kIDOMHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID); -static NS_DEFINE_IID(kIDOMHTMLCollectionIID, NS_IDOMHTMLCOLLECTION_IID); -static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); -static NS_DEFINE_IID(kListWidgetIID, NS_ILISTWIDGET_IID); -static NS_DEFINE_IID(kComboBoxIID, NS_ICOMBOBOX_IID); -static NS_DEFINE_IID(kListBoxIID, NS_ILISTBOX_IID); -static NS_DEFINE_IID(kComboCID, NS_COMBOBOX_CID); -static NS_DEFINE_IID(kListCID, NS_LISTBOX_CID); -static NS_DEFINE_IID(kISelectControlFrameIID, NS_ISELECTCONTROLFRAME_IID); - -class nsOption; - -class nsNativeSelectControlFrame : public nsNativeFormControlFrame, - public nsISelectControlFrame, - public nsIStatefulFrame -{ -public: - nsNativeSelectControlFrame(); - - NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); - -#ifdef DEBUG - NS_IMETHOD GetFrameName(nsString& aResult) const { - return MakeFrameName("SelectControl", aResult); - } -#endif - - virtual nsWidgetInitData* GetWidgetInitData(nsIPresContext* aPresContext); - - virtual void PostCreateWidget(nsIPresContext* aPresContext, - nscoord& aWidth, - nscoord& aHeight); - - 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; - virtual PRInt32 GetMaxNumValues(); - - virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, - nsString* aValues, nsString* aNames); - - NS_METHOD GetMultiple(PRBool* aResult, nsIDOMHTMLSelectElement* aSelect = nsnull); - virtual void Reset(nsIPresContext* aPresContext); - - NS_IMETHOD AppendFrames(nsIPresContext* aPresContext, - nsIPresShell& aPresShell, - nsIAtom* aListName, - nsIFrame* aFrameList); - - // - // 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 Paint(nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer); - - virtual void PaintOption(PRBool aPaintSelected, nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, nsString aText, nscoord aX, nscoord aY, - const nsRect& aInside, nscoord aTextHeight); - - virtual void PaintSelectControl(nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); - - ///XXX: End o the temporary methods - - virtual void MouseClicked(nsIPresContext* aPresContext); - virtual void ControlChanged(nsIPresContext* aPresContext); - - // nsIFormControLFrame - NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue); - NS_IMETHOD GetProperty(nsIAtom* aName, nsAWritableString& aValue); - - NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aHint); - - // nsISelectControlFrame - NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 aIndex); - NS_IMETHOD RemoveOption(nsIPresContext* aPresContext, PRInt32 aIndex); - NS_IMETHOD SetOptionSelected(PRInt32 aIndex, PRBool aValue); - NS_IMETHOD GetOptionSelected(PRInt32 aIndex, PRBool* aValue); - NS_IMETHOD DoneAddingContent(PRBool aIsDone); - - //nsIStatefulFrame - NS_IMETHOD GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::StateType* aStateType); - NS_IMETHOD SaveState(nsIPresContext* aPresContext, nsIPresState** aState); - NS_IMETHOD RestoreState(nsIPresContext* aPresContext, nsIPresState* aState); - -protected: - PRInt32 mNumRows; - - nsIDOMHTMLSelectElement* GetSelect(); - nsIDOMHTMLCollection* GetOptions(nsIDOMHTMLSelectElement* aSelect = nsnull); - nsIDOMHTMLOptionElement* GetOption(nsIDOMHTMLCollection& aOptions, PRUint32 aIndex); - PRBool GetOptionValue(nsIDOMHTMLCollection& aCollecton, PRUint32 aIndex, nsString& aValue); - PRInt32 GetSelectedIndex(); - nsresult UpdateWidgetToCache(PRBool aDeselectFirst = PR_TRUE); - nsresult Deselect(); - - 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); } - - void GetWidgetSize(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight); - - PRBool mIsComboBox; - PRBool mOptionsAdded; - - // Store the state of the options in a local array whether the widget is - // GFX-rendered or not. This is used to detect changes in MouseClicked - PRInt32 mNumOptions; - PRBool* mOptionSelected; - PRBool mCachedState; // A flag meaning "Don't reset state on PostCreateWidget" - - // Accessor methods for mOptionsSelected and mNumOptions - void GetOptionSelectedCache(PRInt32 index, PRBool* aValue); - void SetOptionSelectedCache(PRInt32 index, PRBool aValue); - void GetOptionSelectedWidget(PRInt32 index, PRBool* aValue); - nsresult GetOptionText(nsIDOMHTMLCollection*& aOptions, - PRUint32 aIndex, - nsString& aText); - - // Free our locally cached option array - ~nsNativeSelectControlFrame(); - -private: - NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } - NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } -}; - -nsresult -NS_NewNativeSelectControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) -{ - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsNativeSelectControlFrame* it = new (aPresShell) nsNativeSelectControlFrame; - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; -} - -nsNativeSelectControlFrame::nsNativeSelectControlFrame() - : nsNativeFormControlFrame() -{ - mIsComboBox = PR_FALSE; - mOptionsAdded = PR_FALSE; - mNumRows = 0; - mNumOptions = 0; - mOptionSelected = nsnull; - mCachedState = PR_FALSE; -} - -// XXX is this the right way to clean up? -nsNativeSelectControlFrame::~nsNativeSelectControlFrame() -{ - if (mOptionSelected) - delete[] mOptionSelected; -} - -// Frames are not refcounted, no need to AddRef -NS_IMETHODIMP -nsNativeSelectControlFrame::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(nsISelectControlFrame))) { - *aInstancePtr = (void*)(nsISelectControlFrame*) this; - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { - *aInstancePtr = (void*)(nsIStatefulFrame*) this; - return NS_OK; - } - - return nsNativeFormControlFrame::QueryInterface(aIID, aInstancePtr); -} - -nscoord -nsNativeSelectControlFrame::GetVerticalBorderWidth(float aPixToTwip) const -{ - return NSIntPixelsToTwips(1, aPixToTwip); -} - -nscoord -nsNativeSelectControlFrame::GetHorizontalBorderWidth(float aPixToTwip) const -{ - return GetVerticalBorderWidth(aPixToTwip); -} - -nscoord -nsNativeSelectControlFrame::GetVerticalInsidePadding(nsIPresContext* aPresContext, - float aPixToTwip, - nscoord aInnerHeight) const -{ - // XXX NOTE: the enums eMetric_ListVerticalInsidePadding and eMetric_ListShouldUseVerticalInsidePadding - // 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_ListVerticalInsidePadding - // eMetric_ListShouldUseVerticalInsidePadding - // - float pad; - PRInt32 padInside; - PRInt32 shouldUsePadInside; - nsCOMPtr lookAndFeel; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) { - lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_ListVerticalInsidePadding, pad); - // These two (below) are really only needed for GTK - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListVerticalInsidePadding, padInside); - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListShouldUseVerticalInsidePadding, shouldUsePadInside); - } - - if (1 == shouldUsePadInside) { - return NSIntPixelsToTwips(padInside, aPixToTwip); // XXX this is probably wrong (GTK) - } else { - return (nscoord)NSToIntRound(float(aInnerHeight) * pad); - } -} - -PRInt32 -nsNativeSelectControlFrame::GetHorizontalInsidePadding(nsIPresContext* aPresContext, - float aPixToTwip, - nscoord aInnerWidth, - nscoord aCharWidth) const -{ - // XXX NOTE: the enum eMetric_ListShouldUseHorizontalInsideMinimumPadding - // 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_ListShouldUseHorizontalInsideMinimumPadding - // - float pad; - PRInt32 padMin; - PRInt32 shouldUsePadMin; - nsCOMPtr lookAndFeel; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) { - lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_ListHorizontalInsidePadding, pad); - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListHorizontalInsideMinimumPadding, padMin); - // This one (below) is really only needed for GTK - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListShouldUseHorizontalInsideMinimumPadding, shouldUsePadMin); - } - - if (1 == shouldUsePadMin) { - return NSIntPixelsToTwips(padMin, aPixToTwip); // XXX this is probably wrong (GTK) - } else { - nscoord padding = (nscoord)NSToIntRound(float(aCharWidth) * pad); - nscoord min = NSIntPixelsToTwips(padMin, aPixToTwip); - if (padding > min) { - return padding; - } else { - return min; - } - } -} - -/* - * FIXME: this ::GetIID() method has no meaning in life and should be - * removed. - * Pierre Phaneuf - */ -const nsIID& -nsNativeSelectControlFrame::GetIID() -{ - if (mIsComboBox) { - return kComboBoxIID; - } else { - return kListBoxIID; - } -} - -const nsIID& -nsNativeSelectControlFrame::GetCID() -{ - if (mIsComboBox) { - return kComboCID; - } else { - return kListCID; - } -} - -void -nsNativeSelectControlFrame::GetDesiredSize(nsIPresContext* aPresContext, - const nsHTMLReflowState& aReflowState, - nsHTMLReflowMetrics& aDesiredLayoutSize, - nsSize& aDesiredWidgetSize) -{ - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) - return; - - // get the css size - nsSize styleSize; - GetStyleSize(aPresContext, aReflowState, styleSize); - - // get the size of the longest option - PRInt32 maxWidth = 1; - PRUint32 numOptions; - options->GetLength(&numOptions); - - nsString text; - for (PRInt32 i = 0; i < (PRInt32)numOptions; i++) { - nsresult res = GetOptionText(options, i, text); - if (NS_CONTENT_ATTR_HAS_VALUE != res) { - continue; - } - nsSize textSize; - // use the style for the select rather that the option, since widgets don't support it - nsFormControlHelper::GetTextSize(aPresContext, this, text, textSize, aReflowState.rendContext); - if (textSize.width > maxWidth) { - maxWidth = textSize.width; - } - } - - PRInt32 rowHeight = 0; - nsSize desiredSize; - nsSize minSize; - PRBool widthExplicit, heightExplicit; - nsInputDimensionSpec textSpec(nsnull, PR_FALSE, nsnull, nsnull, - maxWidth, PR_TRUE, nsHTMLAtoms::size, 1); - // XXX fix CalculateSize to return PRUint32 - mNumRows = - (PRUint32)nsFormControlHelper::CalculateSize(aPresContext, aReflowState.rendContext, this, styleSize, - textSpec, desiredSize, minSize, widthExplicit, - heightExplicit, rowHeight); - - // here it is determined whether we are a combo box - PRInt32 sizeAttr; - GetSizeFromContent(&sizeAttr); - PRBool multiple; - GetMultiple(&multiple); - if (!multiple && - ((1 >= sizeAttr) || ((ATTR_NOTSET == sizeAttr) && (1 >= mNumRows)))) { - mIsComboBox = PR_TRUE; - } - - float sp2t; - float p2t; - aPresContext->GetPixelsToTwips(&p2t); - aPresContext->GetScaledPixelsToTwips(&sp2t); - - nscoord scrollbarWidth = 0; - nscoord scrollbarHeight = 0; - float scale; - nsCOMPtr 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(sp2t); - scrollbarHeight = scrollbarWidth; - } - - aDesiredLayoutSize.width = desiredSize.width; - PRBool needScrollbar; -#ifdef XP_MAC - needScrollbar = PR_TRUE; - scrollbarWidth = (mIsComboBox) - ? NSIntPixelsToTwips(25, p2t*scale) - : (scrollbarWidth + NSIntPixelsToTwips(2, p2t*scale)); -#else - needScrollbar = ((mNumRows < (PRInt32)numOptions) || mIsComboBox); -#endif - // account for vertical scrollbar, if present - if (!widthExplicit && needScrollbar) { - aDesiredLayoutSize.width += scrollbarWidth; - } - if (aDesiredLayoutSize.maxElementSize) { - aDesiredLayoutSize.maxElementSize->width = minSize.width; - if (!widthExplicit && needScrollbar) { - aDesiredLayoutSize.maxElementSize->width += scrollbarWidth; - } - } - - // XXX put this in widget library, combo boxes are fixed height (visible part) - aDesiredLayoutSize.height = (mIsComboBox) - ? rowHeight + (2 * GetVerticalInsidePadding(aPresContext, p2t, rowHeight)) - : desiredSize.height; - if (aDesiredLayoutSize.maxElementSize) { - aDesiredLayoutSize.maxElementSize->height = (mIsComboBox) - ? rowHeight + (2 * GetVerticalInsidePadding(aPresContext, p2t, rowHeight)) - : minSize.height; - } - - aDesiredLayoutSize.ascent = aDesiredLayoutSize.height; - aDesiredLayoutSize.descent = 0; - - aDesiredWidgetSize.width = aDesiredLayoutSize.width; - aDesiredWidgetSize.height = aDesiredLayoutSize.height; - if (mIsComboBox) { // add in pull down size - PRInt32 extra = NSIntPixelsToTwips(10, p2t*scale); - aDesiredWidgetSize.height += (rowHeight * (numOptions > 20 ? 20 : numOptions)) + extra; - } - - // override the width and height for a combo box that has already got a widget - if (mWidget && mIsComboBox) { - nscoord ignore; - GetWidgetSize(aPresContext, ignore, aDesiredLayoutSize.height); - aDesiredLayoutSize.ascent = aDesiredLayoutSize.height; - if (aDesiredLayoutSize.maxElementSize) { - aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height; - } - } - - NS_RELEASE(options); -} - -nsWidgetInitData* -nsNativeSelectControlFrame::GetWidgetInitData(nsIPresContext* aPresContext) -{ - if (mIsComboBox) { - nsComboBoxInitData* initData = new nsComboBoxInitData(); - if (initData) { - initData->clipChildren = PR_TRUE; - float twipToPix; - aPresContext->GetTwipsToPixels(&twipToPix); - initData->mDropDownHeight = NSTwipsToIntPixels(mWidgetSize.height, twipToPix); - } - return initData; - } else { - PRBool multiple; - GetMultiple(&multiple); - nsListBoxInitData* initData = nsnull; - if (multiple) { - initData = new nsListBoxInitData(); - if (initData) { - initData->clipChildren = PR_TRUE; - initData->mMultiSelect = PR_TRUE; - } - } - return initData; - } -} - -NS_IMETHODIMP -nsNativeSelectControlFrame::GetMultiple(PRBool* aMultiple, nsIDOMHTMLSelectElement* aSelect) -{ - if (!aSelect) { - nsIDOMHTMLSelectElement* thisSelect = nsnull; - nsresult result = mContent->QueryInterface(kIDOMHTMLSelectElementIID, (void**)&thisSelect); - if ((NS_OK == result) && thisSelect) { - result = thisSelect->GetMultiple(aMultiple); - NS_RELEASE(thisSelect); - } - return result; - } else { - return aSelect->GetMultiple(aMultiple); - } -} - -nsIDOMHTMLSelectElement* -nsNativeSelectControlFrame::GetSelect() -{ - nsIDOMHTMLSelectElement* thisSelect = nsnull; - nsresult result = mContent->QueryInterface(kIDOMHTMLSelectElementIID, (void**)&thisSelect); - if ((NS_OK == result) && thisSelect) { - return thisSelect; - } else { - return nsnull; - } -} - -PRInt32 -nsNativeSelectControlFrame::GetSelectedIndex() -{ - PRInt32 indx = -1; // No selection - nsIDOMHTMLSelectElement* thisSelect = nsnull; - if (NS_SUCCEEDED(mContent->QueryInterface(kIDOMHTMLSelectElementIID, (void**)&thisSelect))) { - thisSelect->GetSelectedIndex(&indx); - NS_RELEASE(thisSelect); - } - return(indx); -} - - -nsIDOMHTMLCollection* -nsNativeSelectControlFrame::GetOptions(nsIDOMHTMLSelectElement* aSelect) -{ - nsIDOMHTMLCollection* options = nsnull; - if (!aSelect) { - nsIDOMHTMLSelectElement* thisSelect = GetSelect(); - if (thisSelect) { - thisSelect->GetOptions(&options); - NS_RELEASE(thisSelect); - return options; - } else { - return nsnull; - } - } else { - aSelect->GetOptions(&options); - return options; - } -} - -void -nsNativeSelectControlFrame::GetWidgetSize(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight) -{ - nsRect bounds; - mWidget->GetBounds(bounds); - float p2t; - aPresContext->GetPixelsToTwips(&p2t); - aWidth = NSIntPixelsToTwips(bounds.width, p2t); - aHeight = NSTwipsToIntPixels(bounds.height, p2t); -} - - -void -nsNativeSelectControlFrame::PostCreateWidget(nsIPresContext* aPresContext, - nscoord& aWidth, - nscoord& aHeight) -{ - if (!mWidget) { - NS_ASSERTION(PR_FALSE, "no widget"); - return; // XXX NS_ERROR_UNEXPECTED; - } - - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - const nsFont * font; - nsresult res = GetFont(aPresContext, font); - if (NS_SUCCEEDED(res) && font != nsnull) { - mWidget->SetFont(*font); - } - SetColors(aPresContext); - - // add the options - if (!mOptionsAdded) { - nsIListWidget* listWidget; - // Grab the widget (we need to update it) - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_FAILED(result)) || (nsnull == listWidget)) { - return; // XXX NS_ERROR_UNEXPECTED; - } - - nsIDOMHTMLCollection* options = GetOptions(); - if (options) { - PRUint32 numOptions; - options->GetLength(&numOptions); - - // Create the locally cached numOptions and optionSelected array. - // The values of the mOptionsSelected array are filled in by Reset() - mNumOptions = numOptions; - if ((numOptions > 0) && (mOptionSelected == nsnull)) { - mOptionSelected = new PRBool[numOptions]; - if (!mOptionSelected) { - return; // XXX NS_ERROR_OUT_OF_MEMORY; - } - } - - for (PRUint32 i = 0; i < numOptions; i++) { - nsString text(" "); - GetOptionText(options,i,text); - listWidget->AddItemAt(text,i); - } - } - - NS_RELEASE(listWidget); - mOptionsAdded = PR_TRUE; - } - - // get the size of the combo box and let Reflow change its desired size - // XXX this technique should be considered for other widgets as well - if (mIsComboBox) { - nscoord ignore; - nscoord height; - GetWidgetSize(aPresContext, ignore, height); - if (height > aHeight) { - aHeight = height; - } - } - - Reset(aPresContext); // initializes selections -} - -nsresult -nsNativeSelectControlFrame::GetOptionText(nsIDOMHTMLCollection*& aOptions, - PRUint32 aIndex, - nsString& aText) -{ - nsresult res = NS_OK; - - // Get the correct text of the option - nsIDOMHTMLOptionElement* option = GetOption(*aOptions, aIndex); - if (option) { - // XXX need to compress whitespace - // option->CompressContent(); - res = option->GetText(aText); - if (NS_CONTENT_ATTR_HAS_VALUE != res) { - aText = " "; // needed? - } - NS_RELEASE(option); - } else { - res = NS_ERROR_UNEXPECTED; - aText = " "; - } - return res; -} - - -PRInt32 -nsNativeSelectControlFrame::GetMaxNumValues() -{ - PRBool multiple; - GetMultiple(&multiple); - if (multiple) { - PRUint32 length = 0; - nsIDOMHTMLCollection* options = GetOptions(); - if (options) { - options->GetLength(&length); - NS_RELEASE(options); - } - return (PRInt32)length; // XXX fix return on GetMaxNumValues - } else { - return 1; - } -} - -PRBool -nsNativeSelectControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, - nsString* aValues, nsString* aNames) -{ - aNumValues = 0; - nsAutoString name; - nsresult result = GetName(&name); - if ((aMaxNumValues <= 0) || (NS_CONTENT_ATTR_NOT_THERE == result)) { - return PR_FALSE; - } - - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) { - return PR_FALSE; - } - - PRBool status = PR_FALSE; - PRBool multiple; - GetMultiple(&multiple); - if (!multiple) { - nsIListWidget* listWidget; - result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_OK == result) && listWidget) { - PRInt32 indx = listWidget->GetSelectedIndex(); - NS_RELEASE(listWidget); - if (indx >= 0) { - nsAutoString value; - GetOptionValue(*options, indx, value); - aNumValues = 1; - aNames[0] = name; - aValues[0] = value; - status = PR_TRUE; - } - } - } else { - nsIListBox* listBox; - result = mWidget->QueryInterface(kListBoxIID, (void **) &listBox); - if ((NS_OK == result) && listBox) { - PRInt32 numSelections = listBox->GetSelectedCount(); - NS_ASSERTION(aMaxNumValues >= numSelections, "invalid max num values"); - if (numSelections >= 0) { - PRInt32* selections = new PRInt32[numSelections]; - listBox->GetSelectedIndices(selections, numSelections); - aNumValues = 0; - for (int i = 0; i < numSelections; i++) { - nsAutoString value; - GetOptionValue(*options, selections[i], value); - aNames[i] = name; - aValues[i] = value; - aNumValues++; - } - delete[] selections; - status = PR_TRUE; - } - NS_RELEASE(listBox); - } - } - - NS_RELEASE(options); - - return status; -} - - -void -nsNativeSelectControlFrame::Reset(nsIPresContext* aPresContext) -{ - if (mCachedState) { - mCachedState = PR_FALSE; - } else { - // Reset selection to default - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) return; // XXX NS_ERROR_UNEXPECTED; - PRUint32 numOptions; - options->GetLength(&numOptions); - for (PRUint32 i = 0; i < numOptions; i++) { - nsIDOMHTMLOptionElement* option = GetOption(*options, i); - if (option) { - // Cache the state of each option locally - PRBool selected = PR_FALSE; - option->GetDefaultSelected(&selected); - SetOptionSelectedCache(i, selected); - NS_RELEASE(option); - } - } - NS_RELEASE(options); - } - - UpdateWidgetToCache(); -} - - - -/* XXX add this to nsHTMLOptionElement.cpp -void -nsOption::CompressContent() -{ - if (nsnull != mContent) { - mContent->CompressWhitespace(PR_TRUE, PR_TRUE); - } -}*/ - -nsIDOMHTMLOptionElement* -nsNativeSelectControlFrame::GetOption(nsIDOMHTMLCollection& aCollection, PRUint32 aIndex) -{ - nsIDOMNode* node = nsnull; - if ((NS_OK == aCollection.Item(aIndex, &node)) && node) { - nsIDOMHTMLOptionElement* option = nsnull; - node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option); - NS_RELEASE(node); - return option; - } - return nsnull; -} - -PRBool -nsNativeSelectControlFrame::GetOptionValue(nsIDOMHTMLCollection& aCollection, PRUint32 aIndex, nsString& aValue) -{ - PRBool status = PR_FALSE; - nsIDOMHTMLOptionElement* option = GetOption(aCollection, aIndex); - if (option) { - nsIHTMLContent* content = nsnull; - nsresult result = option->QueryInterface(kIHTMLContentIID, (void **)&content); - if (NS_SUCCEEDED(result) && content) { - nsHTMLValue value(aValue); - result = content->GetHTMLAttribute(nsHTMLAtoms::value, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - value.GetStringValue(aValue); - status = PR_TRUE; - } - NS_RELEASE(content); - } - if (!status) { - result = option->GetText(aValue); - if (aValue.Length() > 0) { - status = PR_TRUE; - } - } - NS_RELEASE(option); - } - return status; -} - - -void -nsNativeSelectControlFrame::PaintOption(PRBool aPaintSelected, nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, nsString aText, nscoord aX, nscoord aY, - const nsRect& aInside, - nscoord aTextHeight) -{ - nscolor foreground = NS_RGB(0, 0, 0); - nscolor background = NS_RGB(255, 255, 255); - if (PR_TRUE == aPaintSelected) { - background = NS_RGB(0, 0, 0); - foreground = NS_RGB(255, 255, 255); - } - - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); - nsRect rect(aInside.x, aY-onePixel, mRect.width-onePixel, aTextHeight+onePixel); - nscolor currentColor; - aRenderingContext.GetColor(currentColor); - aRenderingContext.SetColor(background); - aRenderingContext.FillRect(rect); - aRenderingContext.SetColor(foreground); - aRenderingContext.DrawString(aText, aX, aY); - aRenderingContext.SetColor(currentColor); -} - - -void -nsNativeSelectControlFrame::PaintSelectControl(nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect) -{ - aRenderingContext.PushState(); - - /** - * Resolve style for a pseudo frame within the given aParentContent & aParentContext. - * The tag should be lowercase and inclue the colon. - * ie: NS_NewAtom(":first-line"); - */ - nsIAtom * sbAtom = NS_NewAtom(":scrollbar-look"); - nsIStyleContext* scrollbarStyle; - aPresContext->ResolvePseudoStyleContextFor(mContent, sbAtom, mStyleContext, - PR_FALSE, &scrollbarStyle); - NS_RELEASE(sbAtom); - - sbAtom = NS_NewAtom(":scrollbar-arrow-look"); - nsIStyleContext* arrowStyle; - aPresContext->ResolvePseudoStyleContextFor(mContent, sbAtom, mStyleContext, - PR_FALSE, &arrowStyle); - NS_RELEASE(sbAtom); - - - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) { - return; - } - PRUint32 numOptions; - options->GetLength(&numOptions); - - float scale; - nsIDeviceContext * context; - aRenderingContext.GetDeviceContext(context); - context->GetCanonicalPixelScale(scale); - - const nsStyleSpacing* spacing = - (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); - nsMargin border; - spacing->CalcBorderFor(this, border); - - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); - - nsRect outside(0, 0, mRect.width, mRect.height); - outside.Deflate(border); - outside.Deflate(onePixel, onePixel); - - nsRect inside(outside); - - 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; - nsString text; - - // Calculate the height of the text - nsIFontMetrics* metrics; - if (font != nsnull) { - context->GetMetricsFor(*font, metrics); - } - metrics->GetHeight(textHeight); - - // Calculate the width of the scrollbar - PRInt32 scrollbarWidth; - if ((PRInt32)numOptions > mNumRows) { - float sbWidth; - float sbHeight; - context->GetCanonicalPixelScale(scale); - context->GetScrollBarDimensions(sbWidth, sbHeight); - scrollbarWidth = PRInt32(sbWidth * scale); - } else { - scrollbarWidth = 0; - } - - // shrink the inside rect's width for the scrollbar - inside.width -= scrollbarWidth; - PRBool clipEmpty; - aRenderingContext.PushState(); - nsRect clipRect(inside); - clipRect.Inflate(onePixel, onePixel); - - aRenderingContext.SetClipRect(clipRect, nsClipCombine_kReplace, clipEmpty); - - nscoord x = inside.x + onePixel; - nscoord y; - if (mIsComboBox) { - y = ((inside.height - textHeight) / 2) + inside.y; - } else { - y = inside.y; - } - - // Get Selected index out of Content model - PRInt32 selectedIndex = GetSelectedIndex(); - PRBool multiple = PR_FALSE; - GetMultiple(&multiple); - - for (PRInt32 i = 0; i < (PRInt32)numOptions; i++) { - if (NS_SUCCEEDED(GetOptionText(options,i,text))) { - if (mIsComboBox) { - // Paint a non-selected option - if ((selectedIndex == -1) && (i == 0)) { - PaintOption(PR_FALSE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - } - else if (selectedIndex == i) { - PaintOption(PR_FALSE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - } - - if ((-1 == selectedIndex && (0 == i)) || (selectedIndex == i)) { - i = numOptions; - } - - } else { - // Its a list box - if (!multiple) { - // Single select list box - if (selectedIndex == i) - PaintOption(PR_TRUE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - else - PaintOption(PR_FALSE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - } else { - PRBool selected = PR_FALSE; - GetOptionSelectedCache(i, &selected); - // Multi-selection list box - if (selected) - PaintOption(PR_TRUE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - else - PaintOption(PR_FALSE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - } - y += textHeight; - if (i == mNumRows-1) { - i = numOptions; - } - } - } - } - - aRenderingContext.PopState(clipEmpty); - // Draw Scrollbars - if ((PRInt32)numOptions > mNumRows) { - //const nsStyleColor* myColor = - // (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color); - - if (mIsComboBox) { - // Get the Scrollbar's Arrow's Style structs - const nsStyleSpacing* arrowSpacing = (const nsStyleSpacing*)arrowStyle->GetStyleData(eStyleStruct_Spacing); -//XXX const nsStyleColor* arrowColor = (const nsStyleColor*)arrowStyle->GetStyleData(eStyleStruct_Color); - - nsRect srect(mRect.width-scrollbarWidth-onePixel, onePixel, scrollbarWidth, mRect.height-(onePixel*2)); - nsFormControlHelper::PaintArrow(nsFormControlHelper::eArrowDirection_Down, aRenderingContext,aPresContext, - aDirtyRect, srect, onePixel, arrowStyle, *arrowSpacing, this, mRect); - } else { - nsRect srect(mRect.width-scrollbarWidth-onePixel, onePixel, scrollbarWidth, mRect.height-(onePixel*2)); - - nsFormControlHelper::PaintScrollbar(aRenderingContext,aPresContext, aDirtyRect, srect, PR_FALSE, onePixel, - scrollbarStyle, arrowStyle, this, mRect); - } - } - - - NS_RELEASE(context); - - NS_RELEASE(options); - aRenderingContext.PopState(clipEmpty); - - NS_RELEASE(scrollbarStyle); - NS_RELEASE(arrowStyle); - -} - -NS_METHOD -nsNativeSelectControlFrame::Paint(nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer) -{ - nsNativeFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, - aWhichLayer); - if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { - PaintSelectControl(aPresContext, aRenderingContext, aDirtyRect); - } - return NS_OK; -} - -// Forward this on as a control changed event - this enables onChange for -// list boxes as ControlChanged is currently only sent for combos -void -nsNativeSelectControlFrame::MouseClicked(nsIPresContext* aPresContext) -{ - ControlChanged(aPresContext); -} - -// Update the locally cached selection array. -// If different option(s) are selected, send a DOM onChange event. -// This routine is basically "UpdateCacheToWidget()" -void -nsNativeSelectControlFrame::ControlChanged(nsIPresContext* aPresContext) -{ - if (!nsFormFrame::GetDisabled(this)) { - - PRBool changed = PR_FALSE; - PRBool multiple; - GetMultiple(&multiple); - if (!multiple) { - nsIListWidget* listWidget; - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_OK == result) && listWidget) { - PRInt32 viewIndex = listWidget->GetSelectedIndex(); - NS_RELEASE(listWidget); - - PRBool wasSelected = PR_FALSE; - GetOptionSelectedCache(viewIndex, &wasSelected); - - if (wasSelected == PR_FALSE) { - changed = PR_TRUE; - } - // Update the locally cached array - for (PRInt32 i=0; i < mNumOptions; i++) - SetOptionSelectedCache(i, PR_FALSE); - SetOptionSelectedCache(viewIndex, PR_TRUE); - - } - } else { - // Get the selected option from the widget - nsIListBox* listBox; - nsresult result = mWidget->QueryInterface(kListBoxIID, (void **) &listBox); - if (!(NS_OK == result) || !listBox) { - return; - } - PRInt32 numSelected = listBox->GetSelectedCount(); - PRInt32* selOptions = nsnull; - if (numSelected > 0) { - selOptions = new PRInt32[numSelected]; - listBox->GetSelectedIndices(selOptions, numSelected); - } - NS_RELEASE(listBox); - - // XXX Assume options are sorted in selOptions - - PRInt32 selIndex = 0; - PRInt32 nextSel = 0; - if ((nsnull != selOptions) && (numSelected > 0)) { - nextSel = selOptions[selIndex]; - } - - // Step through each option in local cache - for (PRInt32 i=0; i < mNumOptions; i++) { - PRBool selectedInLocalCache = PR_FALSE; - PRBool selectedInView = (i == nextSel); - GetOptionSelectedCache(i, &selectedInLocalCache); - if (selectedInView != selectedInLocalCache) { - changed = PR_TRUE; - SetOptionSelectedCache(i, selectedInView); - - if (selectedInView) { - // Get the next selected option in the view - selIndex++; - if (selIndex < numSelected) { - nextSel = selOptions[selIndex]; - } - } - } - } - delete[] selOptions; - } - - if (changed) { - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - - event.message = NS_FORM_CHANGE; - if (nsnull != mContent) { - mContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - } - } -} - -NS_IMETHODIMP -nsNativeSelectControlFrame::DoneAddingContent(PRBool aIsDone) -{ - return NS_OK; -} - -// Get the selected state from the local cache -void nsNativeSelectControlFrame::GetOptionSelectedCache(PRInt32 indx, PRBool* aValue) -{ - if (nsnull != mOptionSelected) { - if (mNumOptions >= indx) { - *aValue = mOptionSelected[indx]; - return; - } - } - *aValue = PR_FALSE; -} - -// Get the selected state from the widget -void nsNativeSelectControlFrame::GetOptionSelectedWidget(PRInt32 indx, PRBool* aValue) -{ - *aValue = PR_FALSE; - nsresult result; - PRBool multiple; - - GetMultiple(&multiple); - if (!multiple) { - nsIListWidget* listWidget; - result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - - if ((NS_OK == result) && (nsnull != listWidget)) { - PRInt32 selIndex = listWidget->GetSelectedIndex(); - NS_RELEASE(listWidget); - - if (selIndex == indx) { - *aValue = PR_TRUE; - } - } - } - else { - nsIListBox* listBox; - result = mWidget->QueryInterface(kListBoxIID, (void **) &listBox); - if ((NS_OK == result) && (nsnull != listBox)) { - PRUint32 numSelected = listBox->GetSelectedCount(); - PRInt32* selOptions = nsnull; - if (numSelected > 0) { - // Could we set numSelected to 1 here? (memory, speed optimization) - selOptions = new PRInt32[numSelected]; - listBox->GetSelectedIndices(selOptions, numSelected); - PRUint32 i; - for (i = 0; i < numSelected; i++) { - if (selOptions[i] == indx) { - *aValue = PR_TRUE; - break; - } - } - delete[] selOptions; - } - NS_RELEASE(listBox); - } - } -} - -// Update the locally cached selection state (not widget) -void nsNativeSelectControlFrame::SetOptionSelectedCache(PRInt32 indx, PRBool aValue) -{ - if (nsnull != mOptionSelected) { - if ((-1 < indx) && (mNumOptions >= indx)) { - mOptionSelected[indx] = aValue; - } - } -} - -NS_IMETHODIMP -nsNativeSelectControlFrame::AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aHint) -{ - if (nsnull != mWidget) { - if (nsHTMLAtoms::disabled == aAttribute) { - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - } - } - return NS_OK; -} - - -NS_IMETHODIMP nsNativeSelectControlFrame::SetProperty(nsIPresContext* aPresContext, - nsIAtom* aName, const nsString& aValue) -{ - if (nsHTMLAtoms::selected == aName) { - return NS_ERROR_INVALID_ARG; // Selected is readonly according to spec. - } else if (nsHTMLAtoms::selectedindex == aName) { - PRInt32 error = 0; - PRInt32 selectedIndex = aValue.ToInteger(&error, 10); // Get index from aValue - if (error) - return NS_ERROR_INVALID_ARG; // Couldn't convert to integer - - // Update local cache of selected values - nsresult res = Deselect(); - if (NS_SUCCEEDED(res)) { - SetOptionSelectedCache(selectedIndex, PR_TRUE); // Select selectedIndex - } - - // Update widget - UpdateWidgetToCache(); - } else { - return nsNativeFormControlFrame::SetProperty(aPresContext, aName, aValue); - } - return NS_OK; -} - -NS_IMETHODIMP nsNativeSelectControlFrame::AddOption(nsIPresContext* aPresContext, - PRInt32 aIndex) -{ - // Grab the content model information - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) return NS_ERROR_UNEXPECTED; - - // Save the cache data structure - PRBool* saveOptionSelected = mOptionSelected; - PRBool selected = PR_FALSE; - - // Grab the widget (we need to update it) - nsIListWidget* listWidget; - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_FAILED(result)) || (nsnull == listWidget)) - return NS_ERROR_UNEXPECTED; - - mNumOptions++; - mOptionSelected = new PRBool[mNumOptions]; - if (!mOptionSelected) return NS_ERROR_OUT_OF_MEMORY; - - // Copy saved local cache into new local cache - for (PRInt32 i=0, j=0; j < mNumOptions; i++,j++) { - if (i == aIndex) { // At the point of insertion - // Add the option to the widget - nsString text(" "); - GetOptionText(options, i, text); - listWidget->AddItemAt(text, i); - - // Get the correct selected value and text of the option - nsIDOMHTMLOptionElement* option = GetOption(*options, i); - if (option) { - option->GetDefaultSelected(&selected); - NS_RELEASE(option); - } else { - selected = PR_FALSE; // XXX failure case. - } - mOptionSelected[j]=selected; - j++; - } - - // Copy old selected value - if (j < mNumOptions) { - mOptionSelected[j]=saveOptionSelected[i]; - } - } - - UpdateWidgetToCache(); - - NS_RELEASE(options); - NS_RELEASE(listWidget); - if (saveOptionSelected) - delete [] saveOptionSelected; - - return NS_OK; -} - -NS_IMETHODIMP nsNativeSelectControlFrame::RemoveOption(nsIPresContext* aPresContext, - PRInt32 aIndex) -{ - // Grab the content model information - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) return NS_ERROR_UNEXPECTED; - - // Save the cache data structure - PRUint32 saveNumOptions = mNumOptions; - PRBool* saveOptionSelected = mOptionSelected; - PRBool selected = PR_FALSE; - - // Grab the widget (we need to update it) - nsIListWidget* listWidget; - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_FAILED(result)) || (nsnull == listWidget)) { - return NS_ERROR_UNEXPECTED; - } - - mNumOptions--; - if (mNumOptions) { - mOptionSelected = new PRBool[mNumOptions]; - if (!mOptionSelected) return NS_ERROR_OUT_OF_MEMORY; - } else { - mOptionSelected = nsnull; - } - // If we got the index, remove just that one option, like this: - if (aIndex >= 0) { - // Copy saved local cache into new local cache - for (PRInt32 i=0, j=0; j < mNumOptions; i++,j++) { - if (i == aIndex) i++; // At the point of deletion - mOptionSelected[j]=saveOptionSelected[i]; - } - - // Update widget - listWidget->RemoveItemAt(aIndex); - - // No index, so we'll have to remove all options and recreate. (Performance hit) - // We also loose the status of what has been selected. - } else { - // Remove all stale options - PRInt32 i; - for (i=saveNumOptions; i>=0; i--) { - listWidget->RemoveItemAt(i); - } - - // Add all the options back in - for (i=0; iAddItemAt(text, i); - - // Get the default (XXXincorrect) selected value and text of the option - nsIDOMHTMLOptionElement* option = GetOption(*options, i); - if (option) { - option->GetDefaultSelected(&selected); // Should be sel, not defsel :( - NS_RELEASE(option); - } else { - selected = PR_FALSE; // XXX failure case - } - mOptionSelected[i]=selected; - } - } - - UpdateWidgetToCache(); - - NS_RELEASE(options); - NS_RELEASE(listWidget); - if (saveOptionSelected) - delete [] saveOptionSelected; - - return NS_OK; -} - -NS_IMETHODIMP nsNativeSelectControlFrame::GetProperty(nsIAtom* aName, nsAWritableString& aValue) -{ - // Get the selected value of option from local cache (optimization vs. widget) - if (nsHTMLAtoms::selected == aName) { - PRInt32 error = 0; - PRBool selected = PR_FALSE; - PRInt32 indx = aValue.ToInteger(&error, 10); // Get index from aValue - GetOptionSelectedCache(indx, &selected); - nsFormControlHelper::GetBoolString(selected, aValue); - - // For selectedIndex, get the value from the widget - } else if (nsHTMLAtoms::selectedindex == aName) { - PRInt32 selectedIndex = -1; - if (mWidget) { - PRBool multiple; - GetMultiple(&multiple); - if (!multiple) { - nsIListWidget* listWidget; - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_OK == result) && (nsnull != listWidget)) { - selectedIndex = listWidget->GetSelectedIndex(); - NS_RELEASE(listWidget); - } - } else { - // Listboxes don't do GetSelectedIndex on windows. Use GetSelectedIndices - nsIListBox* listBox; - nsresult result = mWidget->QueryInterface(kListBoxIID, (void **) &listBox); - if ((NS_OK == result) && (nsnull != listBox)) { - PRUint32 numSelected = listBox->GetSelectedCount(); - PRInt32* selOptions = nsnull; - if (numSelected > 0) { - // Could we set numSelected to 1 here? (memory, speed optimization) - selOptions = new PRInt32[numSelected]; - listBox->GetSelectedIndices(selOptions, numSelected); - selectedIndex = selOptions[0]; - delete[] selOptions; - } - NS_RELEASE(listBox); - } - } - } - aValue.Append(selectedIndex, 10); - } else { - return nsNativeFormControlFrame::GetProperty(aName, aValue); - } - return NS_OK; -} - -// Set the selection of option in the local selection cache, then update widget -NS_IMETHODIMP -nsNativeSelectControlFrame::SetOptionSelected(PRInt32 aIndex, PRBool aValue) -{ - PRBool multiple = PR_FALSE; - GetMultiple(&multiple); - - if (PR_TRUE == multiple) { - SetOptionSelectedCache(aIndex, aValue); - } else { - if (aValue) { - // Get Selected index out of Content model - PRInt32 selectedIndex = GetSelectedIndex(); - if (-1 < selectedIndex) - SetOptionSelectedCache(selectedIndex, PR_FALSE); - SetOptionSelectedCache(aIndex, PR_TRUE); - } else { - SetOptionSelectedCache(aIndex, PR_FALSE); - } - } - // Note that UpdateWidgetToCache may return NS_ERROR_UNEXPECTED if the - // widget is not created yet. We can safely ignore this as when Reset is - // called, it will update the widget to the cache's state. - UpdateWidgetToCache(!aValue); // Don't deselect all if adding selection - return NS_OK; -} - -NS_IMETHODIMP -nsNativeSelectControlFrame::GetOptionSelected(PRInt32 aIndex, PRBool* aValue) -{ - // Determine if option is selected in local cache - GetOptionSelectedCache(aIndex, aValue); - return NS_OK; -} - -nsresult -nsNativeSelectControlFrame::UpdateWidgetToCache(PRBool aDeselectFirst) -{ - if (!mWidget) { - mCachedState = PR_TRUE; // Handle this update later when widget is created. - return NS_OK; - } - - // Grab the list widget - nsIListWidget* listWidget; - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_FAILED(result)) || !listWidget) { - return NS_ERROR_UNEXPECTED; - } - - // Update widget selection to the cached values. - // Normally, we have to deselect, then reselect all - if (aDeselectFirst) { - listWidget->Deselect(); - } - PRInt32 selectedIndex = -1; - PRBool selected = PR_FALSE; - for (PRInt32 i=0; i < mNumOptions; i++) { - GetOptionSelectedCache(i, &selected); - if (selected) { - listWidget->SelectItem(i); - selectedIndex = i; - } - } - - // Select first option of combobox if needed - if (mIsComboBox && (mNumOptions > 0) && (selectedIndex == -1)) { - listWidget->SelectItem(0); - SetOptionSelectedCache(0, PR_TRUE); - } - return NS_OK; -} - -NS_IMETHODIMP -nsNativeSelectControlFrame::AppendFrames(nsIPresContext* aPresContext, - nsIPresShell& aPresShell, - nsIAtom* aListName, - nsIFrame* aFrameList) -{ - //NS_PRECONDITION(PR_FALSE, "not a container"); - return NS_ERROR_UNEXPECTED; -} - -nsresult -nsNativeSelectControlFrame::Deselect() -{ - nsresult res = NS_OK; - for (PRInt32 i=0; (iCanSubmit(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;iGetCanonicalPixelScale(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; -} - diff --git a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h deleted file mode 100644 index 39dfb58aab1..00000000000 --- a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h +++ /dev/null @@ -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 diff --git a/mozilla/layout/html/forms/src/nsRadioControlFrame.cpp b/mozilla/layout/html/forms/src/nsRadioControlFrame.cpp deleted file mode 100644 index 7f9ef489661..00000000000 --- a/mozilla/layout/html/forms/src/nsRadioControlFrame.cpp +++ /dev/null @@ -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 - */ -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; -} diff --git a/mozilla/layout/html/forms/src/nsRadioControlFrame.h b/mozilla/layout/html/forms/src/nsRadioControlFrame.h deleted file mode 100644 index 1933f71a34f..00000000000 --- a/mozilla/layout/html/forms/src/nsRadioControlFrame.h +++ /dev/null @@ -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 - - diff --git a/mozilla/layout/html/forms/src/nsSelectControlFrame.cpp b/mozilla/layout/html/forms/src/nsSelectControlFrame.cpp deleted file mode 100644 index 4aaa753bfd7..00000000000 --- a/mozilla/layout/html/forms/src/nsSelectControlFrame.cpp +++ /dev/null @@ -1,1433 +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): - */ - -// YY need to pass isMultiple before create called -#include "nsCOMPtr.h" -#include "nsFormControlFrame.h" -#include "nsFormFrame.h" -#include "nsIDOMNode.h" -#include "nsIDOMHTMLSelectElement.h" -#include "nsIDOMHTMLOptionElement.h" -#include "nsIDOMHTMLCollection.h" -#include "nsDOMEvent.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 "nsIRadioButton.h" -#include "nsWidgetsCID.h" -#include "nsSize.h" -#include "nsHTMLAtoms.h" -#include "nsIView.h" -#include "nsIListWidget.h" -#include "nsIComboBox.h" -#include "nsIListBox.h" -#include "nsIStyleContext.h" -#include "nsStyleConsts.h" -#include "nsStyleUtil.h" -#include "nsFont.h" -#include "nsIDeviceContext.h" -#include "nsIFontMetrics.h" -#include "nsILookAndFeel.h" -#include "nsIComponentManager.h" - -static NS_DEFINE_IID(kIDOMHTMLSelectElementIID, NS_IDOMHTMLSELECTELEMENT_IID); -static NS_DEFINE_IID(kIDOMHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID); -static NS_DEFINE_IID(kIDOMHTMLCollectionIID, NS_IDOMHTMLCOLLECTION_IID); -static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); -static NS_DEFINE_IID(kListWidgetIID, NS_ILISTWIDGET_IID); -static NS_DEFINE_IID(kComboBoxIID, NS_ICOMBOBOX_IID); -static NS_DEFINE_IID(kListBoxIID, NS_ILISTBOX_IID); -static NS_DEFINE_IID(kComboCID, NS_COMBOBOX_CID); -static NS_DEFINE_IID(kListCID, NS_LISTBOX_CID); - - -class nsOption; - -class nsSelectControlFrame : public nsFormControlFrame { -public: - nsSelectControlFrame(); - - NS_IMETHOD GetFrameName(nsString& aResult) const { - return MakeFrameName("SelectControl", aResult); - } - - virtual nsWidgetInitData* GetWidgetInitData(nsIPresContext* aPresContext); - - virtual void PostCreateWidget(nsIPresContext* aPresContext, - nscoord& aWidth, - nscoord& aHeight); - - 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; - virtual PRInt32 GetMaxNumValues(); - - virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, - nsString* aValues, nsString* aNames); - - NS_METHOD GetMultiple(PRBool* aResult, nsIDOMHTMLSelectElement* aSelect = nsnull); - virtual void Reset(nsIPresContext* aPresContext); - - // - // 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 Paint(nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer); - - virtual void PaintOption(PRBool aPaintSelected, nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, nsString aText, nscoord aX, nscoord aY, - const nsRect& aInside, nscoord aTextHeight); - - virtual void PaintSelectControl(nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); - - ///XXX: End o the temporary methods - - virtual void MouseClicked(nsIPresContext* aPresContext); - virtual void ControlChanged(nsIPresContext* aPresContext); - - // nsIFormControLFrame - NS_IMETHOD SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue); - NS_IMETHOD GetProperty(nsIAtom* aName, nsAWritableString& aValue); - - NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aHint); -protected: - PRUint32 mNumRows; - - nsIDOMHTMLSelectElement* GetSelect(); - nsIDOMHTMLCollection* GetOptions(nsIDOMHTMLSelectElement* aSelect = nsnull); - nsIDOMHTMLOptionElement* GetOption(nsIDOMHTMLCollection& aOptions, PRUint32 aIndex); - PRBool GetOptionValue(nsIDOMHTMLCollection& aCollecton, PRUint32 aIndex, nsString& aValue); - PRUint32 GetSelectedIndex(); - - virtual void GetDesiredSize(nsIPresContext* aPresContext, - const nsHTMLReflowState& aReflowState, - nsHTMLReflowMetrics& aDesiredLayoutSize, - nsSize& aDesiredWidgetSize); - - void GetWidgetSize(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight); - - PRBool mIsComboBox; - PRBool mOptionsAdded; - - // Store the state of the options in a local array whether the widget is - // GFX-rendered or not. This is used to detect changes in MouseClicked - PRUint32 mNumOptions; - PRBool* mOptionSelected; - - // Accessor methods for mOptionsSelected and mNumOptions - void GetOptionSelected(PRUint32 index, PRBool* aValue); - void SetOptionSelected(PRUint32 index, PRBool aValue); - void GetOptionSelectedFromWidget(PRInt32 index, PRBool* aValue); - - // Free our locally cached option array - ~nsSelectControlFrame(); -}; - -nsresult -NS_NewSelectControlFrame(nsIFrame** aNewFrame) -{ - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsSelectControlFrame* it = new nsSelectControlFrame; - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; -} - -nsSelectControlFrame::nsSelectControlFrame() - : nsFormControlFrame() -{ - mIsComboBox = PR_FALSE; - mOptionsAdded = PR_FALSE; - mNumRows = 0; - mNumOptions = 0; - mOptionSelected = nsnull; -} - -// XXX is this the right way to clean up? -nsSelectControlFrame::~nsSelectControlFrame() -{ - if (mOptionSelected) - delete[] mOptionSelected; -} - -nscoord -nsSelectControlFrame::GetVerticalBorderWidth(float aPixToTwip) const -{ - return NSIntPixelsToTwips(1, aPixToTwip); -} - -nscoord -nsSelectControlFrame::GetHorizontalBorderWidth(float aPixToTwip) const -{ - return GetVerticalBorderWidth(aPixToTwip); -} - -nscoord -nsSelectControlFrame::GetVerticalInsidePadding(nsIPresContext* aPresContext, - float aPixToTwip, - nscoord aInnerHeight) const -{ - // XXX NOTE: the enums eMetric_ListVerticalInsidePadding and eMetric_ListShouldUseVerticalInsidePadding - // 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_ListVerticalInsidePadding - // eMetric_ListShouldUseVerticalInsidePadding - // - float pad; - PRInt32 padInside; - PRInt32 shouldUsePadInside; - nsCOMPtr lookAndFeel; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) { - lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_ListVerticalInsidePadding, pad); - // These two (below) are really only needed for GTK - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListVerticalInsidePadding, padInside); - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListShouldUseVerticalInsidePadding, shouldUsePadInside); - NS_RELEASE(lookAndFeel); - } - - if (1 == shouldUsePadInside) { - return NSIntPixelsToTwips(padInside, aPixToTwip); // XXX this is probably wrong (GTK) - } else { - return (nscoord)NSToIntRound(float(aInnerHeight) * pad); - } -} - -PRInt32 -nsSelectControlFrame::GetHorizontalInsidePadding(nsIPresContext* aPresContext, - float aPixToTwip, - nscoord aInnerWidth, - nscoord aCharWidth) const -{ - // XXX NOTE: the enum eMetric_ListShouldUseHorizontalInsideMinimumPadding - // 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_ListShouldUseHorizontalInsideMinimumPadding - // - float pad; - PRInt32 padMin; - PRInt32 shouldUsePadMin; - nsCOMPtr lookAndFeel; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)))) { - lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_ListHorizontalInsidePadding, pad); - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListHorizontalInsideMinimumPadding, padMin); - // This one (below) is really only needed for GTK - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListShouldUseHorizontalInsideMinimumPadding, shouldUsePadMin); - NS_RELEASE(lookAndFeel); - } - - if (1 == shouldUsePadMin) { - return NSIntPixelsToTwips(padMin, aPixToTwip); // XXX this is probably wrong (GTK) - } else { - nscoord padding = (nscoord)NSToIntRound(float(aCharWidth) * pad); - nscoord min = NSIntPixelsToTwips(padMin, aPixToTwip); - if (padding > min) { - return padding; - } else { - return min; - } - } -} - -/* - * FIXME: this ::GetIID() method has no meaning in life and should be - * removed. - * Pierre Phaneuf - */ -const nsIID& -nsSelectControlFrame::GetIID() -{ - if (mIsComboBox) { - return kComboBoxIID; - } else { - return kListBoxIID; - } -} - -const nsIID& -nsSelectControlFrame::GetCID() -{ - if (mIsComboBox) { - return kComboCID; - } else { - return kListCID; - } -} - -void -nsSelectControlFrame::GetDesiredSize(nsIPresContext* aPresContext, - const nsHTMLReflowState& aReflowState, - nsHTMLReflowMetrics& aDesiredLayoutSize, - nsSize& aDesiredWidgetSize) -{ - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) - return; - - // get the css size - nsSize styleSize; - GetStyleSize(aPresContext, aReflowState, styleSize); - - // get the size of the longest option - PRInt32 maxWidth = 1; - PRUint32 numOptions; - options->GetLength(&numOptions); - for (PRUint32 i = 0; i < numOptions; i++) { - nsIDOMHTMLOptionElement* option = GetOption(*options, i); - if (option) { - //option->CompressContent(); - nsAutoString text; - if (NS_CONTENT_ATTR_HAS_VALUE != option->GetText(text)) { - continue; - } - nsSize textSize; - // use the style for the select rather that the option, since widgets don't support it - nsFormControlHelper::GetTextSize(aPresContext, this, text, textSize, aReflowState.rendContext); - if (textSize.width > maxWidth) { - maxWidth = textSize.width; - } - NS_RELEASE(option); - } - } - - PRInt32 rowHeight = 0; - nsSize desiredSize; - nsSize minSize; - PRBool widthExplicit, heightExplicit; - nsInputDimensionSpec textSpec(nsnull, PR_FALSE, nsnull, nsnull, - maxWidth, PR_TRUE, nsHTMLAtoms::size, 1); - // XXX fix CalculateSize to return PRUint32 - mNumRows = - (PRUint32)nsFormControlHelper::CalculateSize(aPresContext, aReflowState.rendContext, this, styleSize, - textSpec, desiredSize, minSize, widthExplicit, - heightExplicit, rowHeight); - - // here it is determined whether we are a combo box - PRInt32 sizeAttr; - GetSizeFromContent(&sizeAttr); - PRBool multiple; - if (!GetMultiple(&multiple) && - ((1 >= sizeAttr) || ((ATTR_NOTSET == sizeAttr) && (1 >= mNumRows)))) { - mIsComboBox = PR_TRUE; - } - - float sp2t; - float p2t; - aPresContext->GetPixelsToTwips(&p2t); - aPresContext->GetScaledPixelsToTwips(&sp2t); - - nscoord scrollbarWidth = 0; - nscoord scrollbarHeight = 0; - float scale; - nsCOMPtr 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(sp2t); - scrollbarHeight = scrollbarWidth; - } - - aDesiredLayoutSize.width = desiredSize.width; - PRBool needScrollbar; -#ifdef XP_MAC - needScrollbar = PR_TRUE; - scrollbarWidth = (mIsComboBox) - ? NSIntPixelsToTwips(25, p2t*scale) - : (scrollbarWidth + NSIntPixelsToTwips(2, p2t*scale)); -#else - needScrollbar = ((mNumRows < numOptions) || mIsComboBox); -#endif - // account for vertical scrollbar, if present - if (!widthExplicit && needScrollbar) { - aDesiredLayoutSize.width += scrollbarWidth; - } - if (aDesiredLayoutSize.maxElementSize) { - aDesiredLayoutSize.maxElementSize->width = minSize.width; - if (!widthExplicit && needScrollbar) { - aDesiredLayoutSize.maxElementSize->width += scrollbarWidth; - } - } - - // XXX put this in widget library, combo boxes are fixed height (visible part) - aDesiredLayoutSize.height = (mIsComboBox) - ? rowHeight + (2 * GetVerticalInsidePadding(aPresContext, p2t, rowHeight)) - : desiredSize.height; - if (aDesiredLayoutSize.maxElementSize) { - aDesiredLayoutSize.maxElementSize->height = (mIsComboBox) - ? rowHeight + (2 * GetVerticalInsidePadding(aPresContext, p2t, rowHeight)) - : minSize.height; - } - - aDesiredLayoutSize.ascent = aDesiredLayoutSize.height; - aDesiredLayoutSize.descent = 0; - - aDesiredWidgetSize.width = aDesiredLayoutSize.width; - aDesiredWidgetSize.height = aDesiredLayoutSize.height; - if (mIsComboBox) { // add in pull down size - PRInt32 extra = NSIntPixelsToTwips(10, p2t*scale); - aDesiredWidgetSize.height += (rowHeight * (numOptions > 20 ? 20 : numOptions)) + extra; - } - - // override the width and height for a combo box that has already got a widget - if (mWidget && mIsComboBox) { - nscoord ignore; - GetWidgetSize(aPresContext, ignore, aDesiredLayoutSize.height); - aDesiredLayoutSize.ascent = aDesiredLayoutSize.height; - if (aDesiredLayoutSize.maxElementSize) { - aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height; - } - } - - NS_RELEASE(options); -} - -nsWidgetInitData* -nsSelectControlFrame::GetWidgetInitData(nsIPresContext* aPresContext) -{ - if (mIsComboBox) { - nsComboBoxInitData* initData = new nsComboBoxInitData(); - if (initData) { - initData->clipChildren = PR_TRUE; - float twipToPix; - aPresContext->GetTwipsToPixels(&twipToPix); - initData->mDropDownHeight = NSTwipsToIntPixels(mWidgetSize.height, twipToPix); - } - return initData; - } else { - PRBool multiple; - GetMultiple(&multiple); - nsListBoxInitData* initData = nsnull; - if (multiple) { - initData = new nsListBoxInitData(); - if (initData) { - initData->clipChildren = PR_TRUE; - initData->mMultiSelect = PR_TRUE; - } - } - return initData; - } -} - -NS_IMETHODIMP -nsSelectControlFrame::GetMultiple(PRBool* aMultiple, nsIDOMHTMLSelectElement* aSelect) -{ - if (!aSelect) { - nsIDOMHTMLSelectElement* thisSelect = nsnull; - nsresult result = mContent->QueryInterface(kIDOMHTMLSelectElementIID, (void**)&thisSelect); - if ((NS_OK == result) && thisSelect) { - result = thisSelect->GetMultiple(aMultiple); - NS_RELEASE(thisSelect); - } - return result; - } else { - return aSelect->GetMultiple(aMultiple); - } -} - -nsIDOMHTMLSelectElement* -nsSelectControlFrame::GetSelect() -{ - nsIDOMHTMLSelectElement* thisSelect = nsnull; - nsresult result = mContent->QueryInterface(kIDOMHTMLSelectElementIID, (void**)&thisSelect); - if ((NS_OK == result) && thisSelect) { - return thisSelect; - } else { - return nsnull; - } -} - -PRUint32 -nsSelectControlFrame::GetSelectedIndex() -{ - PRInt32 indx = -1; // No selection - nsIDOMHTMLSelectElement* thisSelect = nsnull; - if (NS_SUCCEEDED(mContent->QueryInterface(kIDOMHTMLSelectElementIID, (void**)&thisSelect))) { - thisSelect->GetSelectedIndex(&indx); - NS_RELEASE(thisSelect); - } - return(indx); -} - - -nsIDOMHTMLCollection* -nsSelectControlFrame::GetOptions(nsIDOMHTMLSelectElement* aSelect) -{ - nsIDOMHTMLCollection* options = nsnull; - if (!aSelect) { - nsIDOMHTMLSelectElement* thisSelect = GetSelect(); - if (thisSelect) { - thisSelect->GetOptions(&options); - NS_RELEASE(thisSelect); - return options; - } else { - return nsnull; - } - } else { - aSelect->GetOptions(&options); - return options; - } -} - -void -nsSelectControlFrame::GetWidgetSize(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight) -{ - nsRect bounds; - mWidget->GetBounds(bounds); - float p2t; - aPresContext->GetPixelsToTwips(&p2t); - aWidth = NSIntPixelsToTwips(bounds.width, p2t); - aHeight = NSTwipsToIntPixels(bounds.height, p2t); -} - -void -nsSelectControlFrame::PostCreateWidget(nsIPresContext* aPresContext, - nscoord& aWidth, - nscoord& aHeight) -{ - if (!mWidget) { - return; - } - - nsIListWidget* listWidget; - if (NS_OK != mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget)) { - NS_ASSERTION(PR_FALSE, "invalid widget"); - return; - } - - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - const nsFont * font = nsnull; - nsresult res = GetFont(aPresContext, font); - if (NS_SUCCEEDED(res) && font != nsnull) { - mWidget->SetFont(font); - } - SetColors(aPresContext); - - // add the options - if (!mOptionsAdded) { - nsIDOMHTMLCollection* options = GetOptions(); - if (options) { - PRUint32 numOptions; - options->GetLength(&numOptions); - nsIDOMNode* node; - nsIDOMHTMLOptionElement* option; - - // Initialize the locally cached numOptions and optionSelected array. - // The values of the optionsSelected array are filled in by Reset() - mNumOptions = numOptions; - if ((numOptions > 0) && (mOptionSelected == nsnull)) { - mOptionSelected = new PRBool[numOptions]; - } - - for (PRUint32 i = 0; i < numOptions; i++) { - options->Item(i, &node); - if (node) { - nsresult result = node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option); - if ((NS_OK == result) && option) { - nsString text; - // XXX need to compress whitespace - if (NS_CONTENT_ATTR_HAS_VALUE != option->GetText(text)) { - text = " "; - } - listWidget->AddItemAt(text, i); - NS_RELEASE(option); - } - NS_RELEASE(node); - } - } - NS_RELEASE(options); - } - mOptionsAdded = PR_TRUE; - } - - NS_RELEASE(listWidget); - - // get the size of the combo box and let Reflow change its desired size - // XXX this technique should be considered for other widgets as well - if (mIsComboBox) { - nscoord ignore; - nscoord height; - GetWidgetSize(aPresContext, ignore, height); - if (height > aHeight) { - aHeight = height; - } - } - - Reset(aPresContext); // initializes selections -} - - -PRInt32 -nsSelectControlFrame::GetMaxNumValues() -{ - PRBool multiple; - GetMultiple(&multiple); - if (multiple) { - PRUint32 length = 0; - nsIDOMHTMLCollection* options = GetOptions(); - if (options) { - options->GetLength(&length); - NS_RELEASE(options); - } - return (PRInt32)length; // XXX fix return on GetMaxNumValues - } else { - return 1; - } -} - -PRBool -nsSelectControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, - nsString* aValues, nsString* aNames) -{ - aNumValues = 0; - nsAutoString name; - nsresult result = GetName(&name); - if ((aMaxNumValues <= 0) || (NS_CONTENT_ATTR_NOT_THERE == result)) { - return PR_FALSE; - } - - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) { - return PR_FALSE; - } - - PRBool status = PR_FALSE; - PRBool multiple; - GetMultiple(&multiple); - if (!multiple) { - nsIListWidget* listWidget; - result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_OK == result) && listWidget) { - PRInt32 indx = listWidget->GetSelectedIndex(); - NS_RELEASE(listWidget); - if (indx >= 0) { - nsAutoString value; - GetOptionValue(*options, indx, value); - aNumValues = 1; - aNames[0] = name; - aValues[0] = value; - status = PR_TRUE; - } - } - } else { - nsIListBox* listBox; - result = mWidget->QueryInterface(kListBoxIID, (void **) &listBox); - if ((NS_OK == result) && listBox) { - PRInt32 numSelections = listBox->GetSelectedCount(); - NS_ASSERTION(aMaxNumValues >= numSelections, "invalid max num values"); - if (numSelections >= 0) { - PRInt32* selections = new PRInt32[numSelections]; - listBox->GetSelectedIndices(selections, numSelections); - aNumValues = 0; - for (int i = 0; i < numSelections; i++) { - nsAutoString value; - GetOptionValue(*options, selections[i], value); - aNames[i] = name; - aValues[i] = value; - aNumValues++; - } - delete[] selections; - status = PR_TRUE; - } - NS_RELEASE(listBox); - } - } - - NS_RELEASE(options); - - return status; -} - - -void -nsSelectControlFrame::Reset(nsIPresContext* aPresContext) -{ - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) { - return; - } - - PRBool multiple; - GetMultiple(&multiple); - - PRUint32 numOptions; - options->GetLength(&numOptions); - - PRInt32 selectedIndex = -1; - nsIListWidget* listWidget; - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_OK == result) && listWidget) { - listWidget->Deselect(); - for (PRUint32 i = 0; i < numOptions; i++) { - nsIDOMHTMLOptionElement* option = GetOption(*options, i); - if (option) { - PRBool selected = PR_FALSE; - - // Cache the state of each option locally - option->GetDefaultSelected(&selected); - SetOptionSelected(i, selected); - if (selected) { - listWidget->SelectItem(i); - if (selectedIndex < 0) - selectedIndex = i; - } - NS_RELEASE(option); - } - } - } - - // if none were selected, select 1st one if we are a combo box - if (mIsComboBox && (numOptions > 0) && (selectedIndex < 0)) { - listWidget->SelectItem(0); - SetOptionSelected(0, PR_TRUE); - } - NS_RELEASE(listWidget); - NS_RELEASE(options); -} - - - -/* XXX add this to nsHTMLOptionElement.cpp -void -nsOption::CompressContent() -{ - if (nsnull != mContent) { - mContent->CompressWhitespace(PR_TRUE, PR_TRUE); - } -}*/ - -nsIDOMHTMLOptionElement* -nsSelectControlFrame::GetOption(nsIDOMHTMLCollection& aCollection, PRUint32 aIndex) -{ - nsIDOMNode* node = nsnull; - if ((NS_OK == aCollection.Item(aIndex, &node)) && node) { - nsIDOMHTMLOptionElement* option = nsnull; - node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option); - NS_RELEASE(node); - return option; - } - return nsnull; -} - -PRBool -nsSelectControlFrame::GetOptionValue(nsIDOMHTMLCollection& aCollection, PRUint32 aIndex, nsString& aValue) -{ - PRBool status = PR_FALSE; - nsIDOMHTMLOptionElement* option = GetOption(aCollection, aIndex); - if (option) { - nsIHTMLContent* content = nsnull; - nsresult result = option->QueryInterface(kIHTMLContentIID, (void **)&content); - if (NS_SUCCEEDED(result) && content) { - nsHTMLValue value(aValue); - result = content->GetHTMLAttribute(nsHTMLAtoms::value, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - value.GetStringValue(aValue); - status = PR_TRUE; - } - NS_RELEASE(content); - } - if (!status) { - result = option->GetText(aValue); - if (aValue.Length() > 0) { - status = PR_TRUE; - } - } - NS_RELEASE(option); - } - return status; -} - - -void -nsSelectControlFrame::PaintOption(PRBool aPaintSelected, nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, nsString aText, nscoord aX, nscoord aY, - const nsRect& aInside, - nscoord aTextHeight) -{ - nscolor foreground = NS_RGB(0, 0, 0); - nscolor background = NS_RGB(255, 255, 255); - if (PR_TRUE == aPaintSelected) { - background = NS_RGB(0, 0, 0); - foreground = NS_RGB(255, 255, 255); - } - - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); - nsRect rect(aInside.x, aY-onePixel, mRect.width-onePixel, aTextHeight+onePixel); - nscolor currentColor; - aRenderingContext.GetColor(currentColor); - aRenderingContext.SetColor(background); - aRenderingContext.FillRect(rect); - aRenderingContext.SetColor(foreground); - aRenderingContext.DrawString(aText, aX, aY); - aRenderingContext.SetColor(currentColor); -} - - -void -nsSelectControlFrame::PaintSelectControl(nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect) -{ - aRenderingContext.PushState(); - - /** - * Resolve style for a pseudo frame within the given aParentContent & aParentContext. - * The tag should be lowercase and inclue the colon. - * ie: NS_NewAtom(":first-line"); - */ - nsIAtom * sbAtom = NS_NewAtom(":scrollbar-look"); - nsIStyleContext* scrollbarStyle; - aPresContext->ResolvePseudoStyleContextFor(mContent, sbAtom, mStyleContext, - PR_FALSE, &scrollbarStyle); - NS_RELEASE(sbAtom); - - sbAtom = NS_NewAtom(":scrollbar-arrow-look"); - nsIStyleContext* arrowStyle; - aPresContext->ResolvePseudoStyleContextFor(mContent, sbAtom, mStyleContext, - PR_FALSE, &arrowStyle); - NS_RELEASE(sbAtom); - - - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) { - return; - } - PRUint32 numOptions; - options->GetLength(&numOptions); - - float scale; - nsIDeviceContext * context; - aRenderingContext.GetDeviceContext(context); - context->GetCanonicalPixelScale(scale); - - const nsStyleSpacing* spacing = - (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); - nsMargin border; - spacing->CalcBorderFor(this, border); - - float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); - nscoord onePixel = NSIntPixelsToTwips(1, p2t); - - nsRect outside(0, 0, mRect.width, mRect.height); - outside.Deflate(border); - outside.Deflate(onePixel, onePixel); - - nsRect inside(outside); - - aRenderingContext.SetColor(NS_RGB(0,0,0)); - - const nsFont * font = nsnull; - nsresult res = GetFont(aPresContext, font); - if (NS_SUCCEEDED(res) && font != nsnull) { - aRenderingContext.SetFont(font); - } - - - //nscoord textWidth; - nscoord textHeight; - nsString text; - - // Calculate the height of the text - nsIFontMetrics* metrics; - context->GetMetricsFor(font, metrics); - metrics->GetHeight(textHeight); - - // Calculate the width of the scrollbar - PRInt32 scrollbarWidth; - if (numOptions > mNumRows) { - float sbWidth; - float sbHeight; - context->GetCanonicalPixelScale(scale); - context->GetScrollBarDimensions(sbWidth, sbHeight); - scrollbarWidth = PRInt32(sbWidth * scale); - } else { - scrollbarWidth = 0; - } - - // shrink the inside rect's width for the scrollbar - inside.width -= scrollbarWidth; - PRBool clipEmpty; - aRenderingContext.PushState(); - nsRect clipRect(inside); - clipRect.Inflate(onePixel, onePixel); - - aRenderingContext.SetClipRect(clipRect, nsClipCombine_kReplace, clipEmpty); - - nscoord x = inside.x + onePixel; - nscoord y; - if (mIsComboBox) { - y = ((inside.height - textHeight) / 2) + inside.y; - } else { - y = inside.y; - } - - // Get Selected index out of Content model - PRInt32 selectedIndex = GetSelectedIndex(); - PRBool multiple = PR_FALSE; - GetMultiple(&multiple); - - nsIDOMNode* node; - nsIDOMHTMLOptionElement* option; - for (PRUint32 i = 0; i < numOptions; i++) { - options->Item(i, &node); - if (node) { - nsresult result = node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option); - if ((NS_OK == result) && option) { - // XXX need to compress whitespace - if (NS_CONTENT_ATTR_HAS_VALUE != option->GetText(text)) { - text = " "; - } - - if (mIsComboBox) { - // Paint a non-selected option - if ((selectedIndex == -1) && (i == 0)) { - PaintOption(PR_FALSE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - } - else if ((PRUint32)selectedIndex == i) { - PaintOption(PR_FALSE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - } - - if ((-1 == selectedIndex && (0 == i)) || ((PRUint32)selectedIndex == i)) { - i = numOptions; - } - - } else { - // Its a list box - if (!multiple) { - // Single select list box - if (selectedIndex == i) - PaintOption(PR_TRUE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - else - PaintOption(PR_FALSE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - } - else { - PRBool selected = PR_FALSE; - option->GetSelected(&selected); - // Multi-selection list box - if (selected) - PaintOption(PR_TRUE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - else - PaintOption(PR_FALSE, aPresContext, aRenderingContext, text, x, y, inside, textHeight); - } - y += textHeight; - if (i == mNumRows-1) { - i = numOptions; - } - } - } - - NS_RELEASE(option); - } - NS_RELEASE(node); - } - - - aRenderingContext.PopState(clipEmpty); - // Draw Scrollbars - if (numOptions > mNumRows) { - //const nsStyleColor* myColor = - // (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color); - - if (mIsComboBox) { - // Get the Scrollbar's Arrow's Style structs - const nsStyleSpacing* arrowSpacing = (const nsStyleSpacing*)arrowStyle->GetStyleData(eStyleStruct_Spacing); -//XXX const nsStyleColor* arrowColor = (const nsStyleColor*)arrowStyle->GetStyleData(eStyleStruct_Color); - - nsRect srect(mRect.width-scrollbarWidth-onePixel, onePixel, scrollbarWidth, mRect.height-(onePixel*2)); - nsFormControlHelper::PaintArrow(nsFormControlHelper::eArrowDirection_Down, aRenderingContext,aPresContext, - aDirtyRect, srect, onePixel, arrowStyle, *arrowSpacing, this, mRect); - } else { - nsRect srect(mRect.width-scrollbarWidth-onePixel, onePixel, scrollbarWidth, mRect.height-(onePixel*2)); - - nsFormControlHelper::PaintScrollbar(aRenderingContext,aPresContext, aDirtyRect, srect, PR_FALSE, onePixel, - scrollbarStyle, arrowStyle, this, mRect); - } - } - - - NS_RELEASE(context); - - NS_RELEASE(options); - aRenderingContext.PopState(clipEmpty); - - NS_RELEASE(scrollbarStyle); - NS_RELEASE(arrowStyle); - -} - -NS_METHOD -nsSelectControlFrame::Paint(nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer) -{ - nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, - aWhichLayer); - if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { - PaintSelectControl(aPresContext, aRenderingContext, aDirtyRect); - } - return NS_OK; -} - -// Forward this on as a control changed event - this enables onChange for -// list boxes as ControlChanged is currently only sent for combos -void -nsSelectControlFrame::MouseClicked(nsIPresContext* aPresContext) -{ - ControlChanged(aPresContext); -} - -// Update the locally cached selection array. -// If different option(s) are selected, send a DOM onChange event. -void -nsSelectControlFrame::ControlChanged(nsIPresContext* aPresContext) -{ - if (!nsFormFrame::GetDisabled(this)) { - - PRBool changed = PR_FALSE; - PRBool multiple; - GetMultiple(&multiple); - if (!multiple) { - nsIListWidget* listWidget; - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_OK == result) && listWidget) { - PRInt32 viewIndex = listWidget->GetSelectedIndex(); - NS_RELEASE(listWidget); - - PRBool wasSelected = PR_FALSE; - GetOptionSelected(viewIndex, &wasSelected); - - if (wasSelected == PR_FALSE) { - changed = PR_TRUE; - } - // Update the locally cached array - for (PRUint32 i=0; i < mNumOptions; i++) - SetOptionSelected(i, PR_FALSE); - SetOptionSelected(viewIndex, PR_TRUE); - - } - } else { - // Get the selected option from the widget - nsIListBox* listBox; - nsresult result = mWidget->QueryInterface(kListBoxIID, (void **) &listBox); - if (!(NS_OK == result) || !listBox) { - return; - } - PRUint32 numSelected = listBox->GetSelectedCount(); - PRInt32* selOptions = nsnull; - if (numSelected >= 0) { - selOptions = new PRInt32[numSelected]; - listBox->GetSelectedIndices(selOptions, numSelected); - } - NS_RELEASE(listBox); - - // XXX Assume options are sorted in selOptions - - PRUint32 selIndex = 0; - PRUint32 nextSel = 0; - if ((nsnull != selOptions) && (numSelected > 0)) { - nextSel = selOptions[selIndex]; - } - - // Step through each option in local cache - for (PRUint32 i=0; i < mNumOptions; i++) { - PRBool selectedInLocalCache = PR_FALSE; - PRBool selectedInView = (i == nextSel); - GetOptionSelected(i, &selectedInLocalCache); - if (selectedInView != selectedInLocalCache) { - changed = PR_TRUE; - SetOptionSelected(i, selectedInView); - - if (selectedInView) { - // Get the next selected option in the view - selIndex++; - if (selIndex < numSelected) { - nextSel = selOptions[selIndex]; - } - } - } - } - delete[] selOptions; - } - - if (changed) { - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - - event.message = NS_FORM_CHANGE; - if (nsnull != mContent) { - mContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status); - } - } - } -} - -// Get the selected state from the local cache (not widget) -void nsSelectControlFrame::GetOptionSelected(PRUint32 indx, PRBool* aValue) -{ - if (nsnull != mOptionSelected) { - if (mNumOptions >= indx) { - *aValue = mOptionSelected[indx]; - return; - } - } - *aValue = PR_FALSE; -} - -// Get the selected state from the widget -void nsSelectControlFrame::GetOptionSelectedFromWidget(PRInt32 indx, PRBool* aValue) -{ - *aValue = PR_FALSE; - nsresult result; - PRBool multiple; - - GetMultiple(&multiple); - if (!multiple) { - nsIListWidget* listWidget; - result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - - if ((NS_OK == result) && (nsnull != listWidget)) { - PRInt32 selIndex = listWidget->GetSelectedIndex(); - NS_RELEASE(listWidget); - - if (selIndex == indx) { - *aValue = PR_TRUE; - } - } - } - else { - nsIListBox* listBox; - result = mWidget->QueryInterface(kListBoxIID, (void **) &listBox); - if ((NS_OK == result) && (nsnull != listBox)) { - PRUint32 numSelected = listBox->GetSelectedCount(); - PRInt32* selOptions = nsnull; - if (numSelected > 0) { - // Could we set numSelected to 1 here? (memory, speed optimization) - selOptions = new PRInt32[numSelected]; - listBox->GetSelectedIndices(selOptions, numSelected); - PRUint32 i; - for (i = 0; i < numSelected; i++) { - if (selOptions[i] == indx) { - *aValue = PR_TRUE; - break; - } - } - delete[] selOptions; - } - NS_RELEASE(listBox); - } - } -} - -// Update the locally cached selection state (not widget) -void nsSelectControlFrame::SetOptionSelected(PRUint32 indx, PRBool aValue) -{ - if (nsnull != mOptionSelected) { - if (mNumOptions >= indx) { - mOptionSelected[indx] = aValue; - } - } -} - -NS_IMETHODIMP -nsSelectControlFrame::AttributeChanged(nsIPresContext* aPresContext, - nsIContent* aChild, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aHint) -{ - if (nsnull != mWidget) { - if (nsHTMLAtoms::disabled == aAttribute) { - mWidget->Enable(!nsFormFrame::GetDisabled(this)); - } - } - return NS_OK; -} - - -NS_IMETHODIMP nsSelectControlFrame::SetProperty(nsIPresContext* aPresContext, nsIAtom* aName, const nsAReadableString& aValue) -{ - if (nsHTMLAtoms::selected == aName) { - return NS_ERROR_INVALID_ARG; // Selected is readonly according to spec. - } else if (nsHTMLAtoms::selectedindex == aName) { - PRInt32 error = 0; - PRInt32 selectedIndex = aValue.ToInteger(&error, 10); // Get index from aValue - if (error) - return NS_ERROR_INVALID_ARG; // Couldn't convert to integer - - // Update local cache of selected values - for (PRUint32 i=0; i < mNumOptions; i++) - SetOptionSelected(i, PR_FALSE); - SetOptionSelected(selectedIndex, PR_TRUE); - - // Update widget - nsIListWidget* listWidget; - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_OK == result) && (nsnull != listWidget)) { - listWidget->Deselect(); - listWidget->SelectItem(selectedIndex); - NS_RELEASE(listWidget); - } - } else if (nsHTMLAtoms::option == aName) { // Add or Remove an option - nsString aValCopy(aValue); - aValCopy.Trim("ar",PR_TRUE,PR_FALSE); // Chop off leading a or r - PRInt32 error = 0; - PRUint32 actionIndex = aValCopy.ToInteger(&error, 10); - if (error) return NS_ERROR_INVALID_ARG; // Couldn't convert to integer - - // Grab the content model information (merge with postcreatewidget code?) - nsIDOMHTMLCollection* options = GetOptions(); - if (!options) return NS_ERROR_UNEXPECTED; - - // Save the cache data structure - PRUint32 saveNumOptions = mNumOptions; - PRBool* saveOptionSelected = mOptionSelected; - PRBool selected = PR_FALSE; - nsString text(" "); - - // Grab the widget (we need to update it) - nsIListWidget* listWidget; - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_FAILED(result)) || (nsnull == listWidget)) { - return NS_ERROR_UNEXPECTED; - } - - if (!aValue.Find("a")) { // First character is "a" = add an option - mNumOptions++; - mOptionSelected = new PRBool[mNumOptions]; - if (!mOptionSelected) return NS_ERROR_OUT_OF_MEMORY; - - // Copy saved local cache into new local cache - for (PRUint32 i=0, j=0; j < mNumOptions; i++,j++) { - if (i == actionIndex) { // At the point of insertion - - // Get the correct selected value and text of the option - nsIDOMNode* node = nsnull; - options->Item(i, &node); - if (node) { - nsIDOMHTMLOptionElement* option = nsnull; - result = node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option); - if ((NS_OK == result) && option) { - option->GetDefaultSelected(&selected); - mOptionSelected[j]=selected; - - // XXX need to compress whitespace - if (NS_CONTENT_ATTR_HAS_VALUE != option->GetText(text)) { - text = " "; // needed? - } - NS_RELEASE(option); - } else { - mOptionSelected[j]=PR_FALSE; // Couldn't get selected val from content! - } - NS_RELEASE(node); - } else { - mOptionSelected[j]=PR_FALSE; // Couldn't get selected val from content! - } - j++; - } - - // Copy old selected value - if (j < mNumOptions) { - mOptionSelected[j]=saveOptionSelected[i]; - } - } - - // Update widget - listWidget->AddItemAt(text, actionIndex); - } else { - mNumOptions--; - if (mNumOptions) { - mOptionSelected = new PRBool[mNumOptions]; - if (!mOptionSelected) return NS_ERROR_OUT_OF_MEMORY; - } else { - mOptionSelected = nsnull; - } - // If we got the index, remove just that one option, like this: - if (actionIndex >= 0) { - // Copy saved local cache into new local cache - for (PRUint32 i=0, j=0; j < mNumOptions; i++,j++) { - if (i == (PRUint32)actionIndex) i++; // At the point of insertion - mOptionSelected[j]=saveOptionSelected[i]; - } - - // Update widget - listWidget->RemoveItemAt(actionIndex); - - // No index, so we'll have to remove all options and recreate. (Performance hit) - // We also loose the status of what has been selected. - } else { - // Remove all stale options - PRUint32 i; - for (i=saveNumOptions; i>=0; i--) { - listWidget->RemoveItemAt(i); - } - - // Add all the options back in - for (i=0; iItem(i, &node); - if (node) { - nsIDOMHTMLOptionElement* option = nsnull; - result = node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option); - if ((NS_OK == result) && option) { - option->GetDefaultSelected(&selected); // Should be sel, not defsel :( - mOptionSelected[i]=selected; - - // XXX need to compress whitespace - if (NS_CONTENT_ATTR_HAS_VALUE != option->GetText(text)) { - text = " "; // needed? - } - NS_RELEASE(option); - } else { - mOptionSelected[i]=PR_FALSE; // Couldn't get selected val from content! - text = " "; - } - NS_RELEASE(node); - } else { - mOptionSelected[i]=PR_FALSE; // Couldn't get selected val from content! - text = " "; - } - listWidget->AddItemAt(text, i); - } - } - } - // Select options as needed (this is needed for Windows at least) - // Note, as mentioned above, we can't restore selection if option is - // replaced - no index is reported back to us - use DefaultSelected instead - listWidget->Deselect(); - PRInt32 selectedIndex = -1; - for (PRUint32 i=0; i < mNumOptions; i++) { - GetOptionSelected(i, &selected); - if (selected) { - listWidget->SelectItem(i); - selectedIndex = i; - } - } - if (mIsComboBox && (mNumOptions > 0) && (selectedIndex == -1)) { - listWidget->SelectItem(0); - SetOptionSelected(0, PR_TRUE); - } - - NS_RELEASE(options); - NS_RELEASE(listWidget); - if (saveOptionSelected) - delete [] saveOptionSelected; - } else { - return nsFormControlFrame::SetProperty(aPresContext, aName, aValue); - } - return NS_OK; -} - -NS_IMETHODIMP nsSelectControlFrame::GetProperty(nsIAtom* aName, nsAWritableString& aValue) -{ - // Get the selected value of option from local cache (optimization vs. widget) - if (nsHTMLAtoms::selected == aName) { - PRInt32 error = 0; - PRBool selected = PR_FALSE; - PRInt32 indx = aValue.ToInteger(&error, 10); // Get index from aValue - if (error == 0) - GetOptionSelectedFromWidget(indx, &selected); - nsFormControlHelper::GetBoolString(selected, aValue); - - // For selectedIndex, get the value from the widget - } else if (nsHTMLAtoms::selectedindex == aName) { - PRInt32 selectedIndex = -1; - PRBool multiple; - GetMultiple(&multiple); - if (!multiple) { - nsIListWidget* listWidget; - nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); - if ((NS_OK == result) && (nsnull != listWidget)) { - selectedIndex = listWidget->GetSelectedIndex(); - NS_RELEASE(listWidget); - } - } else { - // Listboxes don't do GetSelectedIndex on windows. Use GetSelectedIndices - nsIListBox* listBox; - nsresult result = mWidget->QueryInterface(kListBoxIID, (void **) &listBox); - if ((NS_OK == result) && (nsnull != listBox)) { - PRUint32 numSelected = listBox->GetSelectedCount(); - PRInt32* selOptions = nsnull; - if (numSelected > 0) { - // Could we set numSelected to 1 here? (memory, speed optimization) - selOptions = new PRInt32[numSelected]; - listBox->GetSelectedIndices(selOptions, numSelected); - selectedIndex = selOptions[0]; - delete[] selOptions; - } - NS_RELEASE(listBox); - } - } - aValue.Append(selectedIndex, 10); - } else { - return nsFormControlFrame::GetProperty(aName, aValue); - } - return NS_OK; -} diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp deleted file mode 100644 index 804e77d7836..00000000000 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp +++ /dev/null @@ -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 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 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 - */ -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 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; -} diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.h b/mozilla/layout/html/forms/src/nsTextControlFrame.h deleted file mode 100644 index 63d2a95e61a..00000000000 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.h +++ /dev/null @@ -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