diff --git a/content/html/content/public/nsIFormControl.h b/content/html/content/public/nsIFormControl.h
index 2c5a1b4b6dfa..31ab60959d71 100644
--- a/content/html/content/public/nsIFormControl.h
+++ b/content/html/content/public/nsIFormControl.h
@@ -20,7 +20,6 @@
#include "nsISupports.h"
class nsIDOMHTMLFormElement;
-class nsIWidget;
#define NS_FORM_BROWSE 0
#define NS_FORM_BUTTON_BUTTON 1
@@ -79,8 +78,6 @@ public:
*/
NS_IMETHOD GetType(PRInt32* aType) = 0;
- NS_IMETHOD SetWidget(nsIWidget* aWidget) = 0;
-
NS_IMETHOD Init() = 0;
};
diff --git a/content/html/content/src/nsHTMLButtonElement.cpp b/content/html/content/src/nsHTMLButtonElement.cpp
index c03a27efc6d5..d093c36d1112 100644
--- a/content/html/content/src/nsHTMLButtonElement.cpp
+++ b/content/html/content/src/nsHTMLButtonElement.cpp
@@ -95,7 +95,6 @@ public:
// nsIFormControl
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm);
NS_IMETHOD GetType(PRInt32* aType);
- NS_IMETHOD SetWidget(nsIWidget* aWidget) { return NS_OK; };
NS_IMETHOD Init() { return NS_OK; }
// nsIFocusableContent
diff --git a/content/html/content/src/nsHTMLFieldSetElement.cpp b/content/html/content/src/nsHTMLFieldSetElement.cpp
index 1bf56cc1685e..416547cf63e6 100644
--- a/content/html/content/src/nsHTMLFieldSetElement.cpp
+++ b/content/html/content/src/nsHTMLFieldSetElement.cpp
@@ -75,7 +75,6 @@ public:
// nsIFormControl
NS_IMETHOD GetType(PRInt32* aType);
- NS_IMETHOD SetWidget(nsIWidget* aWidget);
NS_IMETHOD Init() { return NS_OK; }
protected:
@@ -262,12 +261,6 @@ nsHTMLFieldSetElement::GetType(PRInt32* aType)
}
}
-NS_IMETHODIMP
-nsHTMLFieldSetElement::SetWidget(nsIWidget* aWidget)
-{
- NS_ASSERTION(0, "Fieldset has no widget");
- return NS_FORM_NOTOK;
-}
NS_IMETHODIMP
nsHTMLFieldSetElement::GetStyleHintForAttributeChange(
diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp
index f96e954dfdca..1988f4a5bccb 100644
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -30,13 +30,6 @@
#include "nsIHTMLAttributes.h"
#include "nsIFormControl.h"
#include "nsIForm.h"
-#include "nsIWidget.h"
-#include "nsITextWidget.h"
-// XXX: All of the header files related to accessing widgets directly
-// should be removed when all widget references are replaced with
-// frame references.
-#include "nsICheckButton.h"
-#include "nsIRadioButton.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIFormControlFrame.h"
@@ -50,9 +43,6 @@ static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID);
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
-static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
-static NS_DEFINE_IID(kIRadioIID, NS_IRADIOBUTTON_IID);
-static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID);
@@ -134,7 +124,6 @@ public:
// nsIFormControl
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm);
NS_IMETHOD GetType(PRInt32* aType);
- NS_IMETHOD SetWidget(nsIWidget* aWidget);
NS_IMETHOD Init() { return NS_OK; }
// nsIFocusableContent
@@ -143,7 +132,6 @@ public:
protected:
nsGenericHTMLLeafElement mInner;
- nsIWidget* mWidget; // XXX this needs to go away when FindFrameWithContent is efficient
nsIForm* mForm;
PRInt32 mType;
@@ -176,14 +164,12 @@ nsHTMLInputElement::nsHTMLInputElement(nsIAtom* aTag)
mInner.Init(this, aTag);
mType = NS_FORM_INPUT_TEXT; // default value
mForm = nsnull;
- mWidget = nsnull;
//nsTraceRefcnt::Create((nsIFormControl*)this, "nsHTMLFormControlElement", __FILE__, __LINE__);
}
nsHTMLInputElement::~nsHTMLInputElement()
{
- NS_IF_RELEASE(mWidget);
if (nsnull != mForm) {
// prevent mForm from decrementing its ref count on us
mForm->RemoveElement(this, PR_FALSE);
@@ -333,7 +319,6 @@ nsHTMLInputElement::GetValue(nsString& aValue)
if (NS_SUCCEEDED(nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame))) {
if (nsnull != formControlFrame) {
formControlFrame->GetProperty(nsHTMLAtoms::value, aValue);
- NS_RELEASE(formControlFrame);
}
return NS_OK;
}
@@ -353,7 +338,6 @@ nsHTMLInputElement::SetValue(const nsString& aValue)
if (NS_SUCCEEDED(nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame))) {
if (nsnull != formControlFrame ) {
formControlFrame->SetProperty(nsHTMLAtoms::value, aValue);
- NS_RELEASE(formControlFrame);
}
return NS_OK;
}
@@ -374,8 +358,6 @@ nsHTMLInputElement::GetChecked(PRBool* aValue)
*aValue = PR_TRUE;
else
*aValue = PR_FALSE;
-
- NS_RELEASE(formControlFrame);
}
}
return NS_OK;
@@ -393,7 +375,6 @@ nsHTMLInputElement::SetChecked(PRBool aValue)
else {
formControlFrame->SetProperty(nsHTMLAtoms::checked, "0");
}
- NS_RELEASE(formControlFrame);
}
return NS_OK;
}
@@ -401,23 +382,27 @@ nsHTMLInputElement::SetChecked(PRBool aValue)
NS_IMETHODIMP
nsHTMLInputElement::Blur()
{
- if (nsnull != mWidget) {
- nsIWidget *mParentWidget = mWidget->GetParent();
- if (nsnull != mParentWidget) {
- mParentWidget->SetFocus();
- NS_RELEASE(mParentWidget);
- }
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ // Ask the frame to Deselect focus (i.e Blur).
+ formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
}
NS_IMETHODIMP
nsHTMLInputElement::Focus()
{
- if (nsnull != mWidget) {
- mWidget->SetFocus();
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
+
}
NS_IMETHODIMP
@@ -447,18 +432,18 @@ nsHTMLInputElement::RemoveFocus(nsIPresContext* aPresContext)
return NS_OK;
}
-
NS_IMETHODIMP
nsHTMLInputElement::Select()
{
- if ((NS_FORM_INPUT_TEXT == mType) && (nsnull != mWidget)) {
- nsITextWidget *textWidget;
- if (NS_OK == mWidget->QueryInterface(kITextWidgetIID, (void**)&textWidget)) {
- textWidget->SelectAll();
- NS_RELEASE(textWidget);
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ if (nsnull != formControlFrame ) {
+ formControlFrame->SetProperty(nsHTMLAtoms::select, "");
+ return NS_OK;
}
}
- return NS_OK;
+ return rv;
}
NS_IMETHODIMP
@@ -706,24 +691,13 @@ nsHTMLInputElement::GetType(PRInt32* aType)
}
}
-NS_IMETHODIMP
-nsHTMLInputElement::SetWidget(nsIWidget* aWidget)
-{
- if (aWidget != mWidget) {
- NS_IF_RELEASE(mWidget);
- NS_IF_ADDREF(aWidget);
- mWidget = aWidget;
- }
- return NS_OK;
-}
NS_IMETHODIMP
nsHTMLInputElement::GetStyleHintForAttributeChange(
const nsIAtom* aAttribute,
PRInt32 *aHint) const
{
- *aHint = (nsnull != mWidget ? NS_STYLE_HINT_CONTENT : NS_STYLE_HINT_REFLOW);
-
+ *aHint = NS_STYLE_HINT_CONTENT;
return NS_OK;
}
diff --git a/content/html/content/src/nsHTMLLabelElement.cpp b/content/html/content/src/nsHTMLLabelElement.cpp
index 41a2f24ccd34..59cae50e8b21 100644
--- a/content/html/content/src/nsHTMLLabelElement.cpp
+++ b/content/html/content/src/nsHTMLLabelElement.cpp
@@ -80,7 +80,6 @@ public:
// nsIFormControl
NS_IMETHOD GetType(PRInt32* aType) { return NS_FORM_LABEL; }
- NS_IMETHOD SetWidget(nsIWidget* aWidget) { return NS_OK; }
NS_IMETHOD Init() { return NS_OK; }
protected:
diff --git a/content/html/content/src/nsHTMLSelectElement.cpp b/content/html/content/src/nsHTMLSelectElement.cpp
index e55479f0e655..2af9d40f8c58 100644
--- a/content/html/content/src/nsHTMLSelectElement.cpp
+++ b/content/html/content/src/nsHTMLSelectElement.cpp
@@ -30,7 +30,6 @@
#include "nsIHTMLAttributes.h"
#include "nsIFormControl.h"
#include "nsIForm.h"
-#include "nsIWidget.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMHTMLOptionElement.h"
#include "nsIFocusableContent.h"
@@ -160,7 +159,6 @@ public:
// nsIFormControl
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm);
NS_IMETHOD GetType(PRInt32* aType);
- NS_IMETHOD SetWidget(nsIWidget* aWidget);
NS_IMETHOD Init();
NS_IMETHOD SetFocus(nsIPresContext* aPresContext);
@@ -172,7 +170,6 @@ public:
protected:
nsGenericHTMLContainerElement mInner;
- nsIWidget* mWidget; // XXX this needs to go away when FindFrameWithContent is efficient
nsIForm* mForm;
nsOptionList* mOptions;
};
@@ -202,12 +199,10 @@ nsHTMLSelectElement::nsHTMLSelectElement(nsIAtom* aTag)
mInner.Init(this, aTag);
mOptions = nsnull;
mForm = nsnull;
- mWidget = nsnull;
}
nsHTMLSelectElement::~nsHTMLSelectElement()
{
- NS_IF_RELEASE(mWidget);
if (nsnull != mForm) {
// prevent mForm from decrementing its ref count on us
mForm->RemoveElement(this, PR_FALSE);
@@ -480,7 +475,6 @@ nsHTMLSelectElement::SetSelectedIndex(PRInt32 aValue)
nsString value;
value.Append(aValue, 10);
formControlFrame->SetProperty(nsHTMLAtoms::selectedindex, value);
- NS_RELEASE(formControlFrame);
}
return NS_OK;
}
@@ -495,23 +489,27 @@ NS_IMPL_INT_ATTR(nsHTMLSelectElement, TabIndex, tabindex)
NS_IMETHODIMP
nsHTMLSelectElement::Blur() // XXX not tested
{
- if (nsnull != mWidget) {
- nsIWidget *mParentWidget = mWidget->GetParent();
- if (nsnull != mParentWidget) {
- mParentWidget->SetFocus();
- NS_RELEASE(mParentWidget);
- }
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ // Ask the frame to Deselect focus (i.e Blur).
+ formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
}
NS_IMETHODIMP
nsHTMLSelectElement::Focus()
{
- if (nsnull != mWidget) { // XXX not tested
- mWidget->SetFocus();
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
+
}
NS_IMETHODIMP
@@ -651,16 +649,6 @@ nsHTMLSelectElement::GetType(PRInt32* aType)
}
}
-NS_IMETHODIMP
-nsHTMLSelectElement::SetWidget(nsIWidget* aWidget)
-{
- if (aWidget != mWidget) {
- NS_IF_RELEASE(mWidget);
- NS_IF_ADDREF(aWidget);
- mWidget = aWidget;
- }
- return NS_OK;
-}
// An important assumption is that if aForm is null, the previous mForm will not be released
// This allows nsHTMLFormElement to deal with circular references.
diff --git a/content/html/content/src/nsHTMLTextAreaElement.cpp b/content/html/content/src/nsHTMLTextAreaElement.cpp
index b1bcb1483c6d..d2e71ee70870 100644
--- a/content/html/content/src/nsHTMLTextAreaElement.cpp
+++ b/content/html/content/src/nsHTMLTextAreaElement.cpp
@@ -29,8 +29,6 @@
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
#include "nsIPresContext.h"
-#include "nsIWidget.h"
-#include "nsITextAreaWidget.h"
#include "nsIHTMLAttributes.h"
#include "nsIFormControlFrame.h"
#include "nsIFocusableContent.h"
@@ -40,7 +38,6 @@ static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID
static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID);
-static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID);
class nsHTMLTextAreaElement : public nsIDOMHTMLTextAreaElement,
@@ -106,7 +103,6 @@ public:
// nsIFormControl
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm);
NS_IMETHOD GetType(PRInt32* aType);
- NS_IMETHOD SetWidget(nsIWidget* aWidget);
NS_IMETHOD Init() { return NS_OK; }
// nsIFocusableContent
@@ -115,7 +111,6 @@ public:
protected:
nsGenericHTMLContainerElement mInner;
- nsIWidget* mWidget; // XXX this needs to go away when FindFrameWithContent is efficient
nsIForm* mForm;
};
@@ -138,12 +133,10 @@ nsHTMLTextAreaElement::nsHTMLTextAreaElement(nsIAtom* aTag)
NS_INIT_REFCNT();
mInner.Init(this, aTag);
mForm = nsnull;
- mWidget = nsnull;
}
nsHTMLTextAreaElement::~nsHTMLTextAreaElement()
{
- NS_IF_RELEASE(mWidget);
if (nsnull != mForm) {
// prevent mForm from decrementing its ref count on us
mForm->RemoveElement(this, PR_FALSE);
@@ -223,23 +216,27 @@ nsHTMLTextAreaElement::GetForm(nsIDOMHTMLFormElement** aForm)
NS_IMETHODIMP
nsHTMLTextAreaElement::Blur() // XXX not tested
{
- if (nsnull != mWidget) {
- nsIWidget *mParentWidget = mWidget->GetParent();
- if (nsnull != mParentWidget) {
- mParentWidget->SetFocus();
- NS_RELEASE(mParentWidget);
- }
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ // Ask the frame to Deselect focus (i.e Blur).
+ formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
+
}
NS_IMETHODIMP
-nsHTMLTextAreaElement::Focus() // XXX not tested
+nsHTMLTextAreaElement::Focus()
{
- if (nsnull != mWidget) {
- mWidget->SetFocus();
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
}
@@ -266,16 +263,17 @@ nsHTMLTextAreaElement::RemoveFocus(nsIPresContext* aPresContext)
}
NS_IMETHODIMP
-nsHTMLTextAreaElement::Select() // XXX not tested
+nsHTMLTextAreaElement::Select()
{
- if (nsnull != mWidget) {
- nsITextAreaWidget *textWidget;
- if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID, (void**)&textWidget)) {
- textWidget->SelectAll();
- NS_RELEASE(textWidget);
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ if (nsnull != formControlFrame ) {
+ formControlFrame->SetProperty(nsHTMLAtoms::select, "");
+ return NS_OK;
}
}
- return NS_OK;
+ return rv;
}
NS_IMPL_STRING_ATTR(nsHTMLTextAreaElement, AccessKey, accesskey)
@@ -300,7 +298,6 @@ nsHTMLTextAreaElement::GetValue(nsString& aValue)
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->GetProperty(nsHTMLAtoms::value, aValue);
- NS_RELEASE(formControlFrame);
return NS_OK;
}
//XXX: Should this ASSERT instead of getting the default value here?
@@ -314,7 +311,6 @@ nsHTMLTextAreaElement::SetValue(const nsString& aValue)
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->SetProperty(nsHTMLAtoms::value, aValue);
- NS_RELEASE(formControlFrame);
}
return NS_OK;
}
@@ -436,16 +432,6 @@ nsHTMLTextAreaElement::GetType(PRInt32* aType)
}
}
-NS_IMETHODIMP
-nsHTMLTextAreaElement::SetWidget(nsIWidget* aWidget)
-{
- if (aWidget != mWidget) {
- NS_IF_RELEASE(mWidget);
- NS_IF_ADDREF(aWidget);
- mWidget = aWidget;
- }
- return NS_OK;
-}
// An important assumption is that if aForm is null, the previous mForm will not be released
// This allows nsHTMLFormElement to deal with circular references.
diff --git a/layout/forms/nsComboboxControlFrame.h b/layout/forms/nsComboboxControlFrame.h
index ff243d029dcf..477ac59c1c13 100644
--- a/layout/forms/nsComboboxControlFrame.h
+++ b/layout/forms/nsComboboxControlFrame.h
@@ -77,9 +77,12 @@ public:
// nsIFormControLFrame
NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue);
NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue);
+ void SetFocus(PRBool aOn, PRBool aRepaint);
+
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);
+
//nsTextControlFrame* GetTextFrame() { return mTextFrame; }
@@ -87,7 +90,6 @@ public:
//nsButtonControlFrame* GetBrowseFrame() { return mBrowseFrame; }
//void SetBrowseFrame(nsButtonControlFrame* aFrame) { mBrowseFrame = aFrame; }
- void SetFocus(PRBool aOn, PRBool aRepaint);
virtual PRBool IsSuccessful(nsIFormControlFrame* aSubmitter);
virtual void SetFormFrame(nsFormFrame* aFormFrame) { mFormFrame = aFormFrame; }
virtual void Reset();
diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp
index 39c738c69190..bc4864a578f0 100644
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -28,7 +28,6 @@
#include "nsHTMLIIDs.h"
#include "nsHTMLAtoms.h"
#include "nsIFileWidget.h"
-#include "nsITextWidget.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIView.h"
@@ -43,7 +42,6 @@
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID);
-static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
@@ -142,19 +140,8 @@ void nsFileControlFrame::MouseClicked(nsIPresContext* aPresContext)
if (nsnull == textView) {
return;
}
- nsIWidget* widget;
- mTextFrame->GetWidget(&widget);
- if (!widget) {
- return;
- }
-
- nsITextWidget* textWidget;
- nsresult result = widget->QueryInterface(kITextWidgetIID, (void**)&textWidget);
- if (NS_OK != result) {
- NS_RELEASE(widget);
- return;
- }
-
+
+ nsresult result = NS_OK;
nsIView* parentView;
textView->GetParent(parentView);
nsIWidget* parentWidget = GetWindowTemp(parentView);
@@ -174,16 +161,13 @@ void nsFileControlFrame::MouseClicked(nsIPresContext* aPresContext)
result = fileWidget->Show();
if (result) {
- PRUint32 size;
nsString fileName;
fileWidget->GetFile(fileName);
- textWidget->SetText(fileName,size);
+ mTextFrame->SetProperty(nsHTMLAtoms::value,fileName);
}
NS_RELEASE(fileWidget);
}
NS_RELEASE(parentWidget);
- NS_RELEASE(textWidget);
- NS_RELEASE(widget);
}
@@ -348,17 +332,12 @@ nsFileControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
// use our name and the text widgets value
aNames[0] = name;
nsresult status = PR_FALSE;
- nsIWidget* widget;
- nsITextWidget* textWidget;
- mTextFrame->GetWidget(&widget);
- if (widget && (NS_OK == widget->QueryInterface(kITextWidgetIID, (void**)&textWidget))) {
- PRUint32 actualSize;
- textWidget->GetText(aValues[0], 0, actualSize);
+
+ if (NS_SUCCEEDED(mTextFrame->GetProperty(nsHTMLAtoms::value, aValues[0]))) {
aNumValues = 1;
- NS_RELEASE(textWidget);
status = PR_TRUE;
}
- NS_IF_RELEASE(widget);
+
return status;
}
@@ -468,12 +447,14 @@ nsFileControlFrame::Paint(nsIPresContext& aPresContext,
if (HasWidget())
return NS_OK;
+
nsAutoString browse("Browse...");
nsRect rect;
mBrowseFrame->GetRect(rect);
mBrowseFrame->PaintButton(aPresContext, aRenderingContext, aDirtyRect,
browse, rect);
+
mTextFrame->PaintTextControlBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
diff --git a/layout/forms/nsFormControlFrame.cpp b/layout/forms/nsFormControlFrame.cpp
index 63d2a01c44d4..a3a7cbec1b14 100644
--- a/layout/forms/nsFormControlFrame.cpp
+++ b/layout/forms/nsFormControlFrame.cpp
@@ -299,15 +299,7 @@ nsFormControlFrame::Reflow(nsIPresContext& aPresContext,
// set our widget
result = GetWidget(view, &mWidget);
- if ((NS_OK == result) && mWidget) { // keep the ref on mWidget
- nsIFormControl* formControl = nsnull;
- result = mContent->QueryInterface(kIFormControlIID, (void**)&formControl);
- if ((NS_OK == result) && formControl) {
- // set the content's widget, so it can get content modified by the widget
- formControl->SetWidget(mWidget);
- NS_RELEASE(formControl);
- }
- } else {
+ if ((PR_FALSE == NS_SUCCEEDED(result)) || (nsnull == mWidget)) { // keep the ref on mWidget
NS_ASSERTION(0, "could not get widget");
}
}
diff --git a/layout/forms/nsIFormControlFrame.h b/layout/forms/nsIFormControlFrame.h
index d2c68cd42fbe..82f30663c815 100644
--- a/layout/forms/nsIFormControlFrame.h
+++ b/layout/forms/nsIFormControlFrame.h
@@ -88,7 +88,8 @@ public:
NS_IMETHOD GetFormContent(nsIContent*& aContent) const = 0;
/**
- * Set a property on the form control frame
+ * Set a property on the form control frame.
+ *
* @param aName name of the property to set
* @param aValue value of the property
* @returns NS_OK if the property name is valid, otherwise an error code
@@ -98,6 +99,7 @@ public:
/**
* Get a property from the form control frame
+ *
* @param aName name of the property to get
* @param aValue value of the property
* @returns NS_OK if the property name is valid, otherwise an error code
@@ -105,7 +107,7 @@ public:
NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue) = 0;
-
+
};
diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp
index 6c961e7f4f0e..0c22db51ce21 100644
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -198,6 +198,8 @@ nsIFrame* nsListControlFrame::GetNextSelectableFrame(nsVoidArray *aList, PRInt32
}
+
+
//----------------------------------------------------------------------
NS_IMETHODIMP
nsListControlFrame::GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame)
@@ -214,7 +216,12 @@ nsListControlFrame::GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame)
rv = GetFrameForPointUsing(aPoint, nsnull, aFrame);
if (NS_OK == rv) {
if (*aFrame != this) {
- mHitFrame = *aFrame;
+ *aFrame = GetSelectableFrame(*aFrame);
+ if (nsnull == *aFrame) {
+ mHitFrame = this;
+ } else {
+ mHitFrame = *aFrame;
+ }
*aFrame = this;
}
return NS_OK;
@@ -591,6 +598,50 @@ nsListControlFrame::GetFont(nsIPresContext* aPresContext,
}
+PRBool nsListControlFrame::IsOptionElement(nsIContent* aContent)
+{
+ PRBool result = PR_FALSE;
+
+ nsIDOMHTMLOptionElement* oe = nsnull;
+ if (NS_SUCCEEDED(aContent->QueryInterface(kIDOMHTMLOptionElementIID, (void**) &oe))) {
+ if (oe != nsnull) {
+ result = PR_TRUE;
+ NS_RELEASE(oe);
+ }
+ }
+
+ return result;
+}
+
+
+PRBool nsListControlFrame::IsOptionElementFrame(nsIFrame *aFrame)
+{
+ nsIContent *content = nsnull;
+ aFrame->GetContent(&content);
+ PRBool result = PR_FALSE;
+ if (nsnull != content) {
+ result = IsOptionElement(content);
+ NS_RELEASE(content);
+ }
+ return(result);
+}
+
+
+// Go up the frame tree looking for the first ancestor that has content
+// which is selectable
+
+nsIFrame *nsListControlFrame::GetSelectableFrame(nsIFrame *aFrame)
+{
+ nsIFrame* selectedFrame = aFrame;
+
+ while ((nsnull != selectedFrame) &&
+ (PR_FALSE ==IsOptionElementFrame(selectedFrame))) {
+ selectedFrame->GetParent(&selectedFrame);
+ }
+
+ return(selectedFrame);
+}
+
void nsListControlFrame::ForceRedraw(nsIContent* aContent)
{
//XXX: Hack. This should not be needed. The problem is DisplaySelected
@@ -728,6 +779,39 @@ void nsListControlFrame::ExtendedSelection(PRInt32 aStartIndex, PRInt32 aEndInde
void nsListControlFrame::SingleSelection()
{
+//XXX: Experimental code for supporting option groups
+#if 0
+ // Donothing if a item was not clicked on
+ if (this == mHitFrame)
+ return;
+
+ // Store previous selection
+ nsIFrame* oldSelectedFrame = mSelectedFrame;
+ // Get Current selection
+ mSelectedFrame = mHitFrame;
+ if (mSelectedFrame != nsnull) {
+ if (oldSelectedFrame != mSelectedFrame) {
+ // Deselect the previous selection if there is one
+ if (oldSelectedFrame != nsnull) {
+ nsIContent* content = nsnull;
+ oldSelectedFrame->GetContent(&content);
+ DisplayDeselected(content);
+ NS_RELEASE(content);
+ }
+ // Display the new selection
+ nsIContent* content = nsnull;
+ mSelectedFrame->GetContent(&content);
+ DisplaySelected(content);
+ NS_RELEASE(content);
+ mSelectedContent = mHitContent;
+ } else {
+ // Selecting the currently selected item so do nothing.
+ }
+ }
+#endif
+//XXX: Endof experimental code
+
+
// Store previous selection
PRInt32 oldSelectedIndex = mSelectedIndex;
// Get Current selection
@@ -738,13 +822,14 @@ void nsListControlFrame::SingleSelection()
if (oldSelectedIndex != kNothingSelected) {
SetFrameSelected(oldSelectedIndex, PR_FALSE);
}
- // Dipslay the new selection
+ // Display the new selection
SetFrameSelected(mSelectedIndex, PR_TRUE);
mSelectedContent = mHitContent;
} else {
// Selecting the currently selected item so do nothing.
}
}
+
}
void nsListControlFrame::MultipleSelection(PRBool aIsShift, PRBool aIsControl)
diff --git a/layout/forms/nsListControlFrame.h b/layout/forms/nsListControlFrame.h
index c16a2115b578..8abf2f6edb48 100644
--- a/layout/forms/nsListControlFrame.h
+++ b/layout/forms/nsListControlFrame.h
@@ -173,6 +173,9 @@ protected:
// Utility methods
+ PRBool IsOptionElement(nsIContent* aContent);
+ PRBool IsOptionElementFrame(nsIFrame *aFrame);
+ nsIFrame *GetSelectableFrame(nsIFrame *aFrame);
void DisplaySelected(nsIContent* aContent);
void DisplayDeselected(nsIContent* aContent);
void UpdateItem(nsIContent* aContent, PRBool aSelected);
@@ -220,6 +223,7 @@ protected:
nsIFrame * mCurrentHitFrame;
nsIContent * mCurrentHitContent;
nsIContent * mSelectedContent;
+ nsIFrame * mSelectedFrame;
PRBool mIsInitializedFromContent;
nsIFrame * mContentFrame;
PRBool mInDropDownMode;
diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp
index 9945cc2f07c4..f61f26a621c7 100644
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -857,13 +857,30 @@ void nsTextControlFrame::SetTextControlFrameState(const nsString& aValue)
NS_IMETHODIMP nsTextControlFrame::SetProperty(nsIAtom* aName, const nsString& 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 nsFormControlFrame::SetProperty(aName, aValue);
}
- return NS_OK;
+ return rv;
}
NS_IMETHODIMP nsTextControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)
diff --git a/layout/html/content/public/nsIFormControl.h b/layout/html/content/public/nsIFormControl.h
index 2c5a1b4b6dfa..31ab60959d71 100644
--- a/layout/html/content/public/nsIFormControl.h
+++ b/layout/html/content/public/nsIFormControl.h
@@ -20,7 +20,6 @@
#include "nsISupports.h"
class nsIDOMHTMLFormElement;
-class nsIWidget;
#define NS_FORM_BROWSE 0
#define NS_FORM_BUTTON_BUTTON 1
@@ -79,8 +78,6 @@ public:
*/
NS_IMETHOD GetType(PRInt32* aType) = 0;
- NS_IMETHOD SetWidget(nsIWidget* aWidget) = 0;
-
NS_IMETHOD Init() = 0;
};
diff --git a/layout/html/content/src/nsHTMLButtonElement.cpp b/layout/html/content/src/nsHTMLButtonElement.cpp
index c03a27efc6d5..d093c36d1112 100644
--- a/layout/html/content/src/nsHTMLButtonElement.cpp
+++ b/layout/html/content/src/nsHTMLButtonElement.cpp
@@ -95,7 +95,6 @@ public:
// nsIFormControl
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm);
NS_IMETHOD GetType(PRInt32* aType);
- NS_IMETHOD SetWidget(nsIWidget* aWidget) { return NS_OK; };
NS_IMETHOD Init() { return NS_OK; }
// nsIFocusableContent
diff --git a/layout/html/content/src/nsHTMLFieldSetElement.cpp b/layout/html/content/src/nsHTMLFieldSetElement.cpp
index 1bf56cc1685e..416547cf63e6 100644
--- a/layout/html/content/src/nsHTMLFieldSetElement.cpp
+++ b/layout/html/content/src/nsHTMLFieldSetElement.cpp
@@ -75,7 +75,6 @@ public:
// nsIFormControl
NS_IMETHOD GetType(PRInt32* aType);
- NS_IMETHOD SetWidget(nsIWidget* aWidget);
NS_IMETHOD Init() { return NS_OK; }
protected:
@@ -262,12 +261,6 @@ nsHTMLFieldSetElement::GetType(PRInt32* aType)
}
}
-NS_IMETHODIMP
-nsHTMLFieldSetElement::SetWidget(nsIWidget* aWidget)
-{
- NS_ASSERTION(0, "Fieldset has no widget");
- return NS_FORM_NOTOK;
-}
NS_IMETHODIMP
nsHTMLFieldSetElement::GetStyleHintForAttributeChange(
diff --git a/layout/html/content/src/nsHTMLInputElement.cpp b/layout/html/content/src/nsHTMLInputElement.cpp
index f96e954dfdca..1988f4a5bccb 100644
--- a/layout/html/content/src/nsHTMLInputElement.cpp
+++ b/layout/html/content/src/nsHTMLInputElement.cpp
@@ -30,13 +30,6 @@
#include "nsIHTMLAttributes.h"
#include "nsIFormControl.h"
#include "nsIForm.h"
-#include "nsIWidget.h"
-#include "nsITextWidget.h"
-// XXX: All of the header files related to accessing widgets directly
-// should be removed when all widget references are replaced with
-// frame references.
-#include "nsICheckButton.h"
-#include "nsIRadioButton.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIFormControlFrame.h"
@@ -50,9 +43,6 @@ static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID);
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
-static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
-static NS_DEFINE_IID(kIRadioIID, NS_IRADIOBUTTON_IID);
-static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID);
@@ -134,7 +124,6 @@ public:
// nsIFormControl
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm);
NS_IMETHOD GetType(PRInt32* aType);
- NS_IMETHOD SetWidget(nsIWidget* aWidget);
NS_IMETHOD Init() { return NS_OK; }
// nsIFocusableContent
@@ -143,7 +132,6 @@ public:
protected:
nsGenericHTMLLeafElement mInner;
- nsIWidget* mWidget; // XXX this needs to go away when FindFrameWithContent is efficient
nsIForm* mForm;
PRInt32 mType;
@@ -176,14 +164,12 @@ nsHTMLInputElement::nsHTMLInputElement(nsIAtom* aTag)
mInner.Init(this, aTag);
mType = NS_FORM_INPUT_TEXT; // default value
mForm = nsnull;
- mWidget = nsnull;
//nsTraceRefcnt::Create((nsIFormControl*)this, "nsHTMLFormControlElement", __FILE__, __LINE__);
}
nsHTMLInputElement::~nsHTMLInputElement()
{
- NS_IF_RELEASE(mWidget);
if (nsnull != mForm) {
// prevent mForm from decrementing its ref count on us
mForm->RemoveElement(this, PR_FALSE);
@@ -333,7 +319,6 @@ nsHTMLInputElement::GetValue(nsString& aValue)
if (NS_SUCCEEDED(nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame))) {
if (nsnull != formControlFrame) {
formControlFrame->GetProperty(nsHTMLAtoms::value, aValue);
- NS_RELEASE(formControlFrame);
}
return NS_OK;
}
@@ -353,7 +338,6 @@ nsHTMLInputElement::SetValue(const nsString& aValue)
if (NS_SUCCEEDED(nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame))) {
if (nsnull != formControlFrame ) {
formControlFrame->SetProperty(nsHTMLAtoms::value, aValue);
- NS_RELEASE(formControlFrame);
}
return NS_OK;
}
@@ -374,8 +358,6 @@ nsHTMLInputElement::GetChecked(PRBool* aValue)
*aValue = PR_TRUE;
else
*aValue = PR_FALSE;
-
- NS_RELEASE(formControlFrame);
}
}
return NS_OK;
@@ -393,7 +375,6 @@ nsHTMLInputElement::SetChecked(PRBool aValue)
else {
formControlFrame->SetProperty(nsHTMLAtoms::checked, "0");
}
- NS_RELEASE(formControlFrame);
}
return NS_OK;
}
@@ -401,23 +382,27 @@ nsHTMLInputElement::SetChecked(PRBool aValue)
NS_IMETHODIMP
nsHTMLInputElement::Blur()
{
- if (nsnull != mWidget) {
- nsIWidget *mParentWidget = mWidget->GetParent();
- if (nsnull != mParentWidget) {
- mParentWidget->SetFocus();
- NS_RELEASE(mParentWidget);
- }
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ // Ask the frame to Deselect focus (i.e Blur).
+ formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
}
NS_IMETHODIMP
nsHTMLInputElement::Focus()
{
- if (nsnull != mWidget) {
- mWidget->SetFocus();
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
+
}
NS_IMETHODIMP
@@ -447,18 +432,18 @@ nsHTMLInputElement::RemoveFocus(nsIPresContext* aPresContext)
return NS_OK;
}
-
NS_IMETHODIMP
nsHTMLInputElement::Select()
{
- if ((NS_FORM_INPUT_TEXT == mType) && (nsnull != mWidget)) {
- nsITextWidget *textWidget;
- if (NS_OK == mWidget->QueryInterface(kITextWidgetIID, (void**)&textWidget)) {
- textWidget->SelectAll();
- NS_RELEASE(textWidget);
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ if (nsnull != formControlFrame ) {
+ formControlFrame->SetProperty(nsHTMLAtoms::select, "");
+ return NS_OK;
}
}
- return NS_OK;
+ return rv;
}
NS_IMETHODIMP
@@ -706,24 +691,13 @@ nsHTMLInputElement::GetType(PRInt32* aType)
}
}
-NS_IMETHODIMP
-nsHTMLInputElement::SetWidget(nsIWidget* aWidget)
-{
- if (aWidget != mWidget) {
- NS_IF_RELEASE(mWidget);
- NS_IF_ADDREF(aWidget);
- mWidget = aWidget;
- }
- return NS_OK;
-}
NS_IMETHODIMP
nsHTMLInputElement::GetStyleHintForAttributeChange(
const nsIAtom* aAttribute,
PRInt32 *aHint) const
{
- *aHint = (nsnull != mWidget ? NS_STYLE_HINT_CONTENT : NS_STYLE_HINT_REFLOW);
-
+ *aHint = NS_STYLE_HINT_CONTENT;
return NS_OK;
}
diff --git a/layout/html/content/src/nsHTMLLabelElement.cpp b/layout/html/content/src/nsHTMLLabelElement.cpp
index 41a2f24ccd34..59cae50e8b21 100644
--- a/layout/html/content/src/nsHTMLLabelElement.cpp
+++ b/layout/html/content/src/nsHTMLLabelElement.cpp
@@ -80,7 +80,6 @@ public:
// nsIFormControl
NS_IMETHOD GetType(PRInt32* aType) { return NS_FORM_LABEL; }
- NS_IMETHOD SetWidget(nsIWidget* aWidget) { return NS_OK; }
NS_IMETHOD Init() { return NS_OK; }
protected:
diff --git a/layout/html/content/src/nsHTMLSelectElement.cpp b/layout/html/content/src/nsHTMLSelectElement.cpp
index e55479f0e655..2af9d40f8c58 100644
--- a/layout/html/content/src/nsHTMLSelectElement.cpp
+++ b/layout/html/content/src/nsHTMLSelectElement.cpp
@@ -30,7 +30,6 @@
#include "nsIHTMLAttributes.h"
#include "nsIFormControl.h"
#include "nsIForm.h"
-#include "nsIWidget.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMHTMLOptionElement.h"
#include "nsIFocusableContent.h"
@@ -160,7 +159,6 @@ public:
// nsIFormControl
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm);
NS_IMETHOD GetType(PRInt32* aType);
- NS_IMETHOD SetWidget(nsIWidget* aWidget);
NS_IMETHOD Init();
NS_IMETHOD SetFocus(nsIPresContext* aPresContext);
@@ -172,7 +170,6 @@ public:
protected:
nsGenericHTMLContainerElement mInner;
- nsIWidget* mWidget; // XXX this needs to go away when FindFrameWithContent is efficient
nsIForm* mForm;
nsOptionList* mOptions;
};
@@ -202,12 +199,10 @@ nsHTMLSelectElement::nsHTMLSelectElement(nsIAtom* aTag)
mInner.Init(this, aTag);
mOptions = nsnull;
mForm = nsnull;
- mWidget = nsnull;
}
nsHTMLSelectElement::~nsHTMLSelectElement()
{
- NS_IF_RELEASE(mWidget);
if (nsnull != mForm) {
// prevent mForm from decrementing its ref count on us
mForm->RemoveElement(this, PR_FALSE);
@@ -480,7 +475,6 @@ nsHTMLSelectElement::SetSelectedIndex(PRInt32 aValue)
nsString value;
value.Append(aValue, 10);
formControlFrame->SetProperty(nsHTMLAtoms::selectedindex, value);
- NS_RELEASE(formControlFrame);
}
return NS_OK;
}
@@ -495,23 +489,27 @@ NS_IMPL_INT_ATTR(nsHTMLSelectElement, TabIndex, tabindex)
NS_IMETHODIMP
nsHTMLSelectElement::Blur() // XXX not tested
{
- if (nsnull != mWidget) {
- nsIWidget *mParentWidget = mWidget->GetParent();
- if (nsnull != mParentWidget) {
- mParentWidget->SetFocus();
- NS_RELEASE(mParentWidget);
- }
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ // Ask the frame to Deselect focus (i.e Blur).
+ formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
}
NS_IMETHODIMP
nsHTMLSelectElement::Focus()
{
- if (nsnull != mWidget) { // XXX not tested
- mWidget->SetFocus();
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
+
}
NS_IMETHODIMP
@@ -651,16 +649,6 @@ nsHTMLSelectElement::GetType(PRInt32* aType)
}
}
-NS_IMETHODIMP
-nsHTMLSelectElement::SetWidget(nsIWidget* aWidget)
-{
- if (aWidget != mWidget) {
- NS_IF_RELEASE(mWidget);
- NS_IF_ADDREF(aWidget);
- mWidget = aWidget;
- }
- return NS_OK;
-}
// An important assumption is that if aForm is null, the previous mForm will not be released
// This allows nsHTMLFormElement to deal with circular references.
diff --git a/layout/html/content/src/nsHTMLTextAreaElement.cpp b/layout/html/content/src/nsHTMLTextAreaElement.cpp
index b1bcb1483c6d..d2e71ee70870 100644
--- a/layout/html/content/src/nsHTMLTextAreaElement.cpp
+++ b/layout/html/content/src/nsHTMLTextAreaElement.cpp
@@ -29,8 +29,6 @@
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
#include "nsIPresContext.h"
-#include "nsIWidget.h"
-#include "nsITextAreaWidget.h"
#include "nsIHTMLAttributes.h"
#include "nsIFormControlFrame.h"
#include "nsIFocusableContent.h"
@@ -40,7 +38,6 @@ static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID
static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID);
-static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID);
class nsHTMLTextAreaElement : public nsIDOMHTMLTextAreaElement,
@@ -106,7 +103,6 @@ public:
// nsIFormControl
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm);
NS_IMETHOD GetType(PRInt32* aType);
- NS_IMETHOD SetWidget(nsIWidget* aWidget);
NS_IMETHOD Init() { return NS_OK; }
// nsIFocusableContent
@@ -115,7 +111,6 @@ public:
protected:
nsGenericHTMLContainerElement mInner;
- nsIWidget* mWidget; // XXX this needs to go away when FindFrameWithContent is efficient
nsIForm* mForm;
};
@@ -138,12 +133,10 @@ nsHTMLTextAreaElement::nsHTMLTextAreaElement(nsIAtom* aTag)
NS_INIT_REFCNT();
mInner.Init(this, aTag);
mForm = nsnull;
- mWidget = nsnull;
}
nsHTMLTextAreaElement::~nsHTMLTextAreaElement()
{
- NS_IF_RELEASE(mWidget);
if (nsnull != mForm) {
// prevent mForm from decrementing its ref count on us
mForm->RemoveElement(this, PR_FALSE);
@@ -223,23 +216,27 @@ nsHTMLTextAreaElement::GetForm(nsIDOMHTMLFormElement** aForm)
NS_IMETHODIMP
nsHTMLTextAreaElement::Blur() // XXX not tested
{
- if (nsnull != mWidget) {
- nsIWidget *mParentWidget = mWidget->GetParent();
- if (nsnull != mParentWidget) {
- mParentWidget->SetFocus();
- NS_RELEASE(mParentWidget);
- }
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ // Ask the frame to Deselect focus (i.e Blur).
+ formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
+
}
NS_IMETHODIMP
-nsHTMLTextAreaElement::Focus() // XXX not tested
+nsHTMLTextAreaElement::Focus()
{
- if (nsnull != mWidget) {
- mWidget->SetFocus();
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
+ return NS_OK;
}
- return NS_OK;
+ return rv;
}
@@ -266,16 +263,17 @@ nsHTMLTextAreaElement::RemoveFocus(nsIPresContext* aPresContext)
}
NS_IMETHODIMP
-nsHTMLTextAreaElement::Select() // XXX not tested
+nsHTMLTextAreaElement::Select()
{
- if (nsnull != mWidget) {
- nsITextAreaWidget *textWidget;
- if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID, (void**)&textWidget)) {
- textWidget->SelectAll();
- NS_RELEASE(textWidget);
+ nsIFormControlFrame* formControlFrame = nsnull;
+ nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
+ if (NS_SUCCEEDED(rv)) {
+ if (nsnull != formControlFrame ) {
+ formControlFrame->SetProperty(nsHTMLAtoms::select, "");
+ return NS_OK;
}
}
- return NS_OK;
+ return rv;
}
NS_IMPL_STRING_ATTR(nsHTMLTextAreaElement, AccessKey, accesskey)
@@ -300,7 +298,6 @@ nsHTMLTextAreaElement::GetValue(nsString& aValue)
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->GetProperty(nsHTMLAtoms::value, aValue);
- NS_RELEASE(formControlFrame);
return NS_OK;
}
//XXX: Should this ASSERT instead of getting the default value here?
@@ -314,7 +311,6 @@ nsHTMLTextAreaElement::SetValue(const nsString& aValue)
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->SetProperty(nsHTMLAtoms::value, aValue);
- NS_RELEASE(formControlFrame);
}
return NS_OK;
}
@@ -436,16 +432,6 @@ nsHTMLTextAreaElement::GetType(PRInt32* aType)
}
}
-NS_IMETHODIMP
-nsHTMLTextAreaElement::SetWidget(nsIWidget* aWidget)
-{
- if (aWidget != mWidget) {
- NS_IF_RELEASE(mWidget);
- NS_IF_ADDREF(aWidget);
- mWidget = aWidget;
- }
- return NS_OK;
-}
// An important assumption is that if aForm is null, the previous mForm will not be released
// This allows nsHTMLFormElement to deal with circular references.
diff --git a/layout/html/forms/public/nsIFormControlFrame.h b/layout/html/forms/public/nsIFormControlFrame.h
index d2c68cd42fbe..82f30663c815 100644
--- a/layout/html/forms/public/nsIFormControlFrame.h
+++ b/layout/html/forms/public/nsIFormControlFrame.h
@@ -88,7 +88,8 @@ public:
NS_IMETHOD GetFormContent(nsIContent*& aContent) const = 0;
/**
- * Set a property on the form control frame
+ * Set a property on the form control frame.
+ *
* @param aName name of the property to set
* @param aValue value of the property
* @returns NS_OK if the property name is valid, otherwise an error code
@@ -98,6 +99,7 @@ public:
/**
* Get a property from the form control frame
+ *
* @param aName name of the property to get
* @param aValue value of the property
* @returns NS_OK if the property name is valid, otherwise an error code
@@ -105,7 +107,7 @@ public:
NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue) = 0;
-
+
};
diff --git a/layout/html/forms/src/nsComboboxControlFrame.h b/layout/html/forms/src/nsComboboxControlFrame.h
index ff243d029dcf..477ac59c1c13 100644
--- a/layout/html/forms/src/nsComboboxControlFrame.h
+++ b/layout/html/forms/src/nsComboboxControlFrame.h
@@ -77,9 +77,12 @@ public:
// nsIFormControLFrame
NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue);
NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue);
+ void SetFocus(PRBool aOn, PRBool aRepaint);
+
virtual void PostCreateWidget(nsIPresContext* aPresContext,
nscoord& aWidth,
nscoord& aHeight);
+
//nsTextControlFrame* GetTextFrame() { return mTextFrame; }
@@ -87,7 +90,6 @@ public:
//nsButtonControlFrame* GetBrowseFrame() { return mBrowseFrame; }
//void SetBrowseFrame(nsButtonControlFrame* aFrame) { mBrowseFrame = aFrame; }
- void SetFocus(PRBool aOn, PRBool aRepaint);
virtual PRBool IsSuccessful(nsIFormControlFrame* aSubmitter);
virtual void SetFormFrame(nsFormFrame* aFormFrame) { mFormFrame = aFormFrame; }
virtual void Reset();
diff --git a/layout/html/forms/src/nsFileControlFrame.cpp b/layout/html/forms/src/nsFileControlFrame.cpp
index 39c738c69190..bc4864a578f0 100644
--- a/layout/html/forms/src/nsFileControlFrame.cpp
+++ b/layout/html/forms/src/nsFileControlFrame.cpp
@@ -28,7 +28,6 @@
#include "nsHTMLIIDs.h"
#include "nsHTMLAtoms.h"
#include "nsIFileWidget.h"
-#include "nsITextWidget.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIView.h"
@@ -43,7 +42,6 @@
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID);
-static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
@@ -142,19 +140,8 @@ void nsFileControlFrame::MouseClicked(nsIPresContext* aPresContext)
if (nsnull == textView) {
return;
}
- nsIWidget* widget;
- mTextFrame->GetWidget(&widget);
- if (!widget) {
- return;
- }
-
- nsITextWidget* textWidget;
- nsresult result = widget->QueryInterface(kITextWidgetIID, (void**)&textWidget);
- if (NS_OK != result) {
- NS_RELEASE(widget);
- return;
- }
-
+
+ nsresult result = NS_OK;
nsIView* parentView;
textView->GetParent(parentView);
nsIWidget* parentWidget = GetWindowTemp(parentView);
@@ -174,16 +161,13 @@ void nsFileControlFrame::MouseClicked(nsIPresContext* aPresContext)
result = fileWidget->Show();
if (result) {
- PRUint32 size;
nsString fileName;
fileWidget->GetFile(fileName);
- textWidget->SetText(fileName,size);
+ mTextFrame->SetProperty(nsHTMLAtoms::value,fileName);
}
NS_RELEASE(fileWidget);
}
NS_RELEASE(parentWidget);
- NS_RELEASE(textWidget);
- NS_RELEASE(widget);
}
@@ -348,17 +332,12 @@ nsFileControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
// use our name and the text widgets value
aNames[0] = name;
nsresult status = PR_FALSE;
- nsIWidget* widget;
- nsITextWidget* textWidget;
- mTextFrame->GetWidget(&widget);
- if (widget && (NS_OK == widget->QueryInterface(kITextWidgetIID, (void**)&textWidget))) {
- PRUint32 actualSize;
- textWidget->GetText(aValues[0], 0, actualSize);
+
+ if (NS_SUCCEEDED(mTextFrame->GetProperty(nsHTMLAtoms::value, aValues[0]))) {
aNumValues = 1;
- NS_RELEASE(textWidget);
status = PR_TRUE;
}
- NS_IF_RELEASE(widget);
+
return status;
}
@@ -468,12 +447,14 @@ nsFileControlFrame::Paint(nsIPresContext& aPresContext,
if (HasWidget())
return NS_OK;
+
nsAutoString browse("Browse...");
nsRect rect;
mBrowseFrame->GetRect(rect);
mBrowseFrame->PaintButton(aPresContext, aRenderingContext, aDirtyRect,
browse, rect);
+
mTextFrame->PaintTextControlBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
diff --git a/layout/html/forms/src/nsFormControlFrame.cpp b/layout/html/forms/src/nsFormControlFrame.cpp
index 63d2a01c44d4..a3a7cbec1b14 100644
--- a/layout/html/forms/src/nsFormControlFrame.cpp
+++ b/layout/html/forms/src/nsFormControlFrame.cpp
@@ -299,15 +299,7 @@ nsFormControlFrame::Reflow(nsIPresContext& aPresContext,
// set our widget
result = GetWidget(view, &mWidget);
- if ((NS_OK == result) && mWidget) { // keep the ref on mWidget
- nsIFormControl* formControl = nsnull;
- result = mContent->QueryInterface(kIFormControlIID, (void**)&formControl);
- if ((NS_OK == result) && formControl) {
- // set the content's widget, so it can get content modified by the widget
- formControl->SetWidget(mWidget);
- NS_RELEASE(formControl);
- }
- } else {
+ if ((PR_FALSE == NS_SUCCEEDED(result)) || (nsnull == mWidget)) { // keep the ref on mWidget
NS_ASSERTION(0, "could not get widget");
}
}
diff --git a/layout/html/forms/src/nsListControlFrame.cpp b/layout/html/forms/src/nsListControlFrame.cpp
index 6c961e7f4f0e..0c22db51ce21 100644
--- a/layout/html/forms/src/nsListControlFrame.cpp
+++ b/layout/html/forms/src/nsListControlFrame.cpp
@@ -198,6 +198,8 @@ nsIFrame* nsListControlFrame::GetNextSelectableFrame(nsVoidArray *aList, PRInt32
}
+
+
//----------------------------------------------------------------------
NS_IMETHODIMP
nsListControlFrame::GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame)
@@ -214,7 +216,12 @@ nsListControlFrame::GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame)
rv = GetFrameForPointUsing(aPoint, nsnull, aFrame);
if (NS_OK == rv) {
if (*aFrame != this) {
- mHitFrame = *aFrame;
+ *aFrame = GetSelectableFrame(*aFrame);
+ if (nsnull == *aFrame) {
+ mHitFrame = this;
+ } else {
+ mHitFrame = *aFrame;
+ }
*aFrame = this;
}
return NS_OK;
@@ -591,6 +598,50 @@ nsListControlFrame::GetFont(nsIPresContext* aPresContext,
}
+PRBool nsListControlFrame::IsOptionElement(nsIContent* aContent)
+{
+ PRBool result = PR_FALSE;
+
+ nsIDOMHTMLOptionElement* oe = nsnull;
+ if (NS_SUCCEEDED(aContent->QueryInterface(kIDOMHTMLOptionElementIID, (void**) &oe))) {
+ if (oe != nsnull) {
+ result = PR_TRUE;
+ NS_RELEASE(oe);
+ }
+ }
+
+ return result;
+}
+
+
+PRBool nsListControlFrame::IsOptionElementFrame(nsIFrame *aFrame)
+{
+ nsIContent *content = nsnull;
+ aFrame->GetContent(&content);
+ PRBool result = PR_FALSE;
+ if (nsnull != content) {
+ result = IsOptionElement(content);
+ NS_RELEASE(content);
+ }
+ return(result);
+}
+
+
+// Go up the frame tree looking for the first ancestor that has content
+// which is selectable
+
+nsIFrame *nsListControlFrame::GetSelectableFrame(nsIFrame *aFrame)
+{
+ nsIFrame* selectedFrame = aFrame;
+
+ while ((nsnull != selectedFrame) &&
+ (PR_FALSE ==IsOptionElementFrame(selectedFrame))) {
+ selectedFrame->GetParent(&selectedFrame);
+ }
+
+ return(selectedFrame);
+}
+
void nsListControlFrame::ForceRedraw(nsIContent* aContent)
{
//XXX: Hack. This should not be needed. The problem is DisplaySelected
@@ -728,6 +779,39 @@ void nsListControlFrame::ExtendedSelection(PRInt32 aStartIndex, PRInt32 aEndInde
void nsListControlFrame::SingleSelection()
{
+//XXX: Experimental code for supporting option groups
+#if 0
+ // Donothing if a item was not clicked on
+ if (this == mHitFrame)
+ return;
+
+ // Store previous selection
+ nsIFrame* oldSelectedFrame = mSelectedFrame;
+ // Get Current selection
+ mSelectedFrame = mHitFrame;
+ if (mSelectedFrame != nsnull) {
+ if (oldSelectedFrame != mSelectedFrame) {
+ // Deselect the previous selection if there is one
+ if (oldSelectedFrame != nsnull) {
+ nsIContent* content = nsnull;
+ oldSelectedFrame->GetContent(&content);
+ DisplayDeselected(content);
+ NS_RELEASE(content);
+ }
+ // Display the new selection
+ nsIContent* content = nsnull;
+ mSelectedFrame->GetContent(&content);
+ DisplaySelected(content);
+ NS_RELEASE(content);
+ mSelectedContent = mHitContent;
+ } else {
+ // Selecting the currently selected item so do nothing.
+ }
+ }
+#endif
+//XXX: Endof experimental code
+
+
// Store previous selection
PRInt32 oldSelectedIndex = mSelectedIndex;
// Get Current selection
@@ -738,13 +822,14 @@ void nsListControlFrame::SingleSelection()
if (oldSelectedIndex != kNothingSelected) {
SetFrameSelected(oldSelectedIndex, PR_FALSE);
}
- // Dipslay the new selection
+ // Display the new selection
SetFrameSelected(mSelectedIndex, PR_TRUE);
mSelectedContent = mHitContent;
} else {
// Selecting the currently selected item so do nothing.
}
}
+
}
void nsListControlFrame::MultipleSelection(PRBool aIsShift, PRBool aIsControl)
diff --git a/layout/html/forms/src/nsListControlFrame.h b/layout/html/forms/src/nsListControlFrame.h
index c16a2115b578..8abf2f6edb48 100644
--- a/layout/html/forms/src/nsListControlFrame.h
+++ b/layout/html/forms/src/nsListControlFrame.h
@@ -173,6 +173,9 @@ protected:
// Utility methods
+ PRBool IsOptionElement(nsIContent* aContent);
+ PRBool IsOptionElementFrame(nsIFrame *aFrame);
+ nsIFrame *GetSelectableFrame(nsIFrame *aFrame);
void DisplaySelected(nsIContent* aContent);
void DisplayDeselected(nsIContent* aContent);
void UpdateItem(nsIContent* aContent, PRBool aSelected);
@@ -220,6 +223,7 @@ protected:
nsIFrame * mCurrentHitFrame;
nsIContent * mCurrentHitContent;
nsIContent * mSelectedContent;
+ nsIFrame * mSelectedFrame;
PRBool mIsInitializedFromContent;
nsIFrame * mContentFrame;
PRBool mInDropDownMode;
diff --git a/layout/html/forms/src/nsTextControlFrame.cpp b/layout/html/forms/src/nsTextControlFrame.cpp
index 9945cc2f07c4..f61f26a621c7 100644
--- a/layout/html/forms/src/nsTextControlFrame.cpp
+++ b/layout/html/forms/src/nsTextControlFrame.cpp
@@ -857,13 +857,30 @@ void nsTextControlFrame::SetTextControlFrameState(const nsString& aValue)
NS_IMETHODIMP nsTextControlFrame::SetProperty(nsIAtom* aName, const nsString& 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 nsFormControlFrame::SetProperty(aName, aValue);
}
- return NS_OK;
+ return rv;
}
NS_IMETHODIMP nsTextControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)