Commit c82d985b authored by karnaze%netscape.com's avatar karnaze%netscape.com
Browse files

fixed bug 958, checkboxes wrong background when not checked, select always...

fixed bug 958, checkboxes wrong background when not checked, select always multiple, text & texarea not reset. html 4 button work in progress.
parent 8c374057
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -23,23 +23,25 @@ class nsIDOMHTMLFormElement;
class nsIWidget;

#define NS_FORM_BROWSE          0
#define NS_FORM_BUTTON          1
#define NS_FORM_FIELDSET        2
#define NS_FORM_INPUT_BUTTON    3
#define NS_FORM_INPUT_CHECKBOX  4
#define NS_FORM_INPUT_FILE      5
#define NS_FORM_INPUT_HIDDEN    6
#define NS_FORM_INPUT_RESET     7
#define NS_FORM_INPUT_IMAGE     8
#define NS_FORM_INPUT_PASSWORD  9
#define NS_FORM_INPUT_RADIO    10
#define NS_FORM_INPUT_SUBMIT   11
#define NS_FORM_INPUT_TEXT     12
#define NS_FORM_OPTION         13
#define NS_FORM_OPTGROUP       14
#define NS_FORM_LEGEND         15
#define NS_FORM_SELECT         16
#define NS_FORM_TEXTAREA       17
#define NS_FORM_BUTTON_BUTTON   1
#define NS_FORM_BUTTON_RESET    2
#define NS_FORM_BUTTON_SUBMIT   3
#define NS_FORM_FIELDSET        4
#define NS_FORM_INPUT_BUTTON    5
#define NS_FORM_INPUT_CHECKBOX  6
#define NS_FORM_INPUT_FILE      7
#define NS_FORM_INPUT_HIDDEN    8
#define NS_FORM_INPUT_RESET     9
#define NS_FORM_INPUT_IMAGE    10
#define NS_FORM_INPUT_PASSWORD 11
#define NS_FORM_INPUT_RADIO    12
#define NS_FORM_INPUT_SUBMIT   13
#define NS_FORM_INPUT_TEXT     14
#define NS_FORM_OPTION         15
#define NS_FORM_OPTGROUP       16
#define NS_FORM_LEGEND         17
#define NS_FORM_SELECT         18
#define NS_FORM_TEXTAREA       19

#define NS_FORM_NOTOK          0xFFFFFFF7
#define NS_FORM_NOTSET         0xFFFFFFF7
+3 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ nsIAtom* nsHTMLAtoms::bordercolor;
nsIAtom* nsHTMLAtoms::bottompadding;
nsIAtom* nsHTMLAtoms::br;
nsIAtom* nsHTMLAtoms::bulletPseudo;
nsIAtom* nsHTMLAtoms::button;
nsIAtom* nsHTMLAtoms::caption;
nsIAtom* nsHTMLAtoms::cellpadding;
nsIAtom* nsHTMLAtoms::cellspacing;
@@ -259,6 +260,7 @@ void nsHTMLAtoms::AddrefAtoms()
    bottompadding = NS_NewAtom("BOTTOMPADDING");
    br = NS_NewAtom("BR");
    bulletPseudo = NS_NewAtom(":BULLET");
    button = NS_NewAtom("BUTTON");
    caption = NS_NewAtom("CAPTION");
    cellpadding = NS_NewAtom("CELLPADDING");
    cellspacing = NS_NewAtom("CELLSPACING");
@@ -471,6 +473,7 @@ void nsHTMLAtoms::ReleaseAtoms()
    NS_RELEASE(bottompadding);
    NS_RELEASE(br);
    NS_RELEASE(bulletPseudo);
    NS_RELEASE(button);
    NS_RELEASE(caption);
    NS_RELEASE(cellpadding);
    NS_RELEASE(cellspacing);
+1 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ public:
  static nsIAtom* bottompadding;
  static nsIAtom* br;
  static nsIAtom* bulletPseudo;
  static nsIAtom* button;

  static nsIAtom* caption;
  static nsIAtom* cellpadding;
+127 −10
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
 * Netscape Communications Corporation.  All Rights Reserved.
 */
#include "nsIDOMHTMLButtonElement.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIHTMLContent.h"
@@ -26,6 +27,8 @@
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
#include "nsIPresContext.h"
#include "nsIFormControl.h"
#include "nsIForm.h"

#include "nsIEventStateManager.h"
#include "nsDOMEvent.h"
@@ -35,7 +38,8 @@ static NS_DEFINE_IID(kIDOMHTMLButtonElementIID, NS_IDOMHTMLBUTTONELEMENT_IID);
class nsHTMLButtonElement : public nsIDOMHTMLButtonElement,
                            public nsIScriptObjectOwner,
                            public nsIDOMEventReceiver,
                            public nsIHTMLContent
                            public nsIHTMLContent,
                            public nsIFormControl
{
public:
  nsHTMLButtonElement(nsIAtom* aTag);
@@ -81,10 +85,23 @@ public:
  // nsIHTMLContent
  NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner)

  // nsIFormControl
  NS_IMETHOD GetType(PRInt32* aType);
  NS_IMETHOD SetWidget(nsIWidget* aWidget) { return NS_OK; };
  NS_IMETHOD Init() { return NS_OK; }

protected:
  nsGenericHTMLContainerElement mInner;
  nsIForm*                      mForm;
  PRInt32                       mType;
};

static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
static NS_DEFINE_IID(kIFormIID, NS_IFORM_IID);
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);

// Construction, destruction

nsresult
NS_NewHTMLButtonElement(nsIHTMLContent** aInstancePtrResult, nsIAtom* aTag)
{
@@ -103,29 +120,64 @@ nsHTMLButtonElement::nsHTMLButtonElement(nsIAtom* aTag)
{
  NS_INIT_REFCNT();
  mInner.Init(this, aTag);
  mForm = nsnull;
  mType = NS_FORM_BUTTON_BUTTON; // default
}

nsHTMLButtonElement::~nsHTMLButtonElement()
{
  if (nsnull != mForm) {
    // prevent mForm from decrementing its ref count on us
    mForm->RemoveElement(this, PR_FALSE); 
    NS_RELEASE(mForm);
  }
}

NS_IMPL_ADDREF(nsHTMLButtonElement)
// nsISupports

NS_IMPL_RELEASE(nsHTMLButtonElement)
NS_IMETHODIMP_(nsrefcnt) 
nsHTMLButtonElement::AddRef(void)
{
  PRInt32 refCnt = mRefCnt;  // debugging 
  return ++mRefCnt; 
}

nsresult
nsHTMLButtonElement::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
  NS_IMPL_HTML_CONTENT_QUERY_INTERFACE(aIID, aInstancePtr, this)
  if (aIID.Equals(kIDOMHTMLButtonElementIID)) {
    nsIDOMHTMLButtonElement* tmp = this;
    *aInstancePtr = (void*) tmp;
    *aInstancePtr = (void*)(nsIDOMHTMLButtonElement*)this;
    mRefCnt++;
    return NS_OK;
  }
  else if (aIID.Equals(kIFormControlIID)) {
    *aInstancePtr = (void*)(nsIFormControl*) this;
    NS_ADDREF_THIS();
    return NS_OK;
  }
  return NS_NOINTERFACE;
}

NS_IMETHODIMP_(nsrefcnt)
nsHTMLButtonElement::Release()
{
  --mRefCnt;
	if (mRefCnt <= 0) {
    delete this;                                       
    return 0;                                          
  } else if ((1 == mRefCnt) && mForm) { 
    mRefCnt = 0;
    delete this;
    return 0;
  } else {
    return mRefCnt;
  }
}


// nsIDOMHTMLButtonElement

nsresult
nsHTMLButtonElement::CloneNode(nsIDOMNode** aReturn)
{
@@ -137,17 +189,43 @@ nsHTMLButtonElement::CloneNode(nsIDOMNode** aReturn)
  return it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
}

// An important assumption is that if aForm is null, the previous mForm will not be released
// This allows nsHTMLFormElement to deal with circular references.
NS_IMETHODIMP
nsHTMLButtonElement::GetForm(nsIDOMHTMLFormElement** aForm)
nsHTMLButtonElement::SetForm(nsIDOMHTMLFormElement* aForm)
{
  *aForm = nsnull;/* XXX */
  nsresult result = NS_OK;
	if (nsnull == aForm) {
    mForm = nsnull;
    return NS_OK;
  } else {
    NS_IF_RELEASE(mForm);
    nsIFormControl* formControl = nsnull;
    result = QueryInterface(kIFormControlIID, (void**)&formControl);
    if ((NS_OK == result) && formControl) {
      result = aForm->QueryInterface(kIFormIID, (void**)&mForm); // keep the ref
      if ((NS_OK == result) && mForm) {
        mForm->AddElement(formControl);
      }
      NS_RELEASE(formControl);
    }
  }
  return result;
}

NS_IMETHODIMP
nsHTMLButtonElement::SetForm(nsIDOMHTMLFormElement* aForm)
nsHTMLButtonElement::GetForm(nsIDOMHTMLFormElement** aForm)
{
  return NS_OK;
  nsresult result = NS_OK;
  *aForm = nsnull;
  if (nsnull != mForm) {
    nsIDOMHTMLFormElement* formElem = nsnull;
    result = mForm->QueryInterface(kIDOMHTMLFormElementIID, (void**)&formElem);
    if (NS_OK == result) {
      *aForm = formElem;
    }
  }
  return result;
}

NS_IMPL_STRING_ATTR(nsHTMLButtonElement, AccessKey, accesskey, eSetAttrNotify_None)
@@ -157,6 +235,13 @@ NS_IMPL_STRING_ATTR(nsHTMLButtonElement, Type, type, eSetAttrNotify_Restart)
NS_IMPL_INT_ATTR(nsHTMLButtonElement, TabIndex, tabindex, eSetAttrNotify_None)
NS_IMPL_STRING_ATTR(nsHTMLButtonElement, Value, value, eSetAttrNotify_Render)

static nsGenericHTMLElement::EnumTable kButtonTypeTable[] = {
  { "button", NS_FORM_BUTTON_BUTTON },
  { "reset", NS_FORM_BUTTON_RESET },
  { "submit", NS_FORM_BUTTON_SUBMIT },
  { 0 }
};

NS_IMETHODIMP
nsHTMLButtonElement::StringToAttribute(nsIAtom* aAttribute,
                                       const nsString& aValue,
@@ -167,6 +252,21 @@ nsHTMLButtonElement::StringToAttribute(nsIAtom* aAttribute,
                                     eHTMLUnit_Integer);
    return NS_CONTENT_ATTR_HAS_VALUE;
  }
  if (aAttribute == nsHTMLAtoms::type) {
    nsGenericHTMLElement::EnumTable *table = kButtonTypeTable;
    while (nsnull != table->tag) { 
      if (aValue.EqualsIgnoreCase(table->tag)) {
        aResult.SetIntValue(table->value, eHTMLUnit_Enumerated);
        mType = table->value;  
        return NS_CONTENT_ATTR_HAS_VALUE;
      }
      table++;
    }
  }
  else if (aAttribute == nsHTMLAtoms::disabled) {
    aResult.SetEmptyValue();
    return NS_CONTENT_ATTR_HAS_VALUE;
  }
  return NS_CONTENT_ATTR_NOT_THERE;
}

@@ -175,6 +275,12 @@ nsHTMLButtonElement::AttributeToString(nsIAtom* aAttribute,
                                       nsHTMLValue& aValue,
                                       nsString& aResult) const
{
  if (aAttribute == nsHTMLAtoms::type) {
    if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
      nsGenericHTMLElement::EnumValueToString(aValue, kButtonTypeTable, aResult);
      return NS_CONTENT_ATTR_HAS_VALUE;
    }
  }
  return mInner.AttributeToString(aAttribute, aValue, aResult);
}

@@ -282,3 +388,14 @@ nsHTMLButtonElement::HandleDOMEvent(nsIPresContext& aPresContext,
  }
  return ret;
}

NS_IMETHODIMP
nsHTMLButtonElement::GetType(PRInt32* aType)
{
  if (aType) {
    *aType = mType;
    return NS_OK;
  } else {
    return NS_FORM_NOTOK;
  }
}
+8 −0
Original line number Diff line number Diff line
@@ -352,6 +352,14 @@ nsHTMLInputElement::StringToAttribute(nsIAtom* aAttribute,
    aResult.SetEmptyValue();
    return NS_CONTENT_ATTR_HAS_VALUE;
  }
  else if (aAttribute == nsHTMLAtoms::disabled) {
    aResult.SetEmptyValue();
    return NS_CONTENT_ATTR_HAS_VALUE;
  }
  else if (aAttribute == nsHTMLAtoms::readonly) {
    aResult.SetEmptyValue();
    return NS_CONTENT_ATTR_HAS_VALUE;
  }
  else if (aAttribute == nsHTMLAtoms::width) {
    nsGenericHTMLElement::ParseValueOrPercent(aValue, aResult,
                                              eHTMLUnit_Pixel);
Loading