option and optgroup should match :enabled/:disabled too. Bug 306620, r+sr=bzbarsky

This commit is contained in:
allan%beaufour.dk 2005-09-28 08:32:40 +00:00
parent ac626ee74e
commit 63413f73f4
3 changed files with 126 additions and 2 deletions

View File

@ -3358,8 +3358,6 @@ nsGenericHTMLFormElement::CanBeDisabled() const
// It's easier to test the types that _cannot_ be disabled
return
type != NS_FORM_LABEL &&
type != NS_FORM_OPTION &&
type != NS_FORM_OPTGROUP &&
type != NS_FORM_LEGEND &&
type != NS_FORM_FIELDSET &&
type != NS_FORM_OBJECT;

View File

@ -42,6 +42,8 @@
#include "nsPresContext.h"
#include "nsIFrame.h"
#include "nsIFormControlFrame.h"
#include "nsIEventStateManager.h"
#include "nsIDocument.h"
#include "nsISelectElement.h"
#include "nsIDOMHTMLSelectElement.h"
@ -83,6 +85,34 @@ public:
PRUint32 aFlags,
nsEventStatus* aEventStatus);
virtual PRInt32 IntrinsicState() const;
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, PRBool aNotify)
{
return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
}
virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
PRBool aNotify)
{
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
aValue, aNotify);
AfterSetAttr(aNameSpaceID, aName, &aValue, aNotify);
return rv;
}
virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
PRBool aNotify)
{
nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute,
aNotify);
AfterSetAttr(aNameSpaceID, aAttribute, nsnull, aNotify);
return rv;
}
protected:
/**
@ -90,6 +120,12 @@ protected:
* @param aSelectElement the select element [OUT]
*/
void GetSelect(nsISelectElement **aSelectElement);
/**
* Called when an attribute has just been changed
*/
void AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString* aValue, PRBool aNotify);
};
@ -164,6 +200,21 @@ nsHTMLOptGroupElement::GetSelect(nsISelectElement **aSelectElement)
}
}
void
nsHTMLOptGroupElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString* aValue, PRBool aNotify)
{
if (aNotify && aNameSpaceID == kNameSpaceID_None &&
aName == nsHTMLAtoms::disabled) {
nsIDocument* document = GetCurrentDoc();
if (document) {
mozAutoDocUpdate(document, UPDATE_CONTENT_STATE, PR_TRUE);
document->ContentStatesChanged(this, nsnull, NS_EVENT_STATE_DISABLED |
NS_EVENT_STATE_ENABLED);
}
}
}
nsresult
nsHTMLOptGroupElement::WillAddOrRemoveChild(nsIContent* aKid,
PRUint32 aIndex,
@ -181,3 +232,20 @@ nsHTMLOptGroupElement::WillAddOrRemoveChild(nsIContent* aKid,
return nsGenericHTMLElement::WillAddOrRemoveChild(aKid, aIndex, aRemove);
}
PRInt32
nsHTMLOptGroupElement::IntrinsicState() const
{
PRInt32 state = nsGenericHTMLElement::IntrinsicState();
PRBool disabled;
GetBoolAttr(nsHTMLAtoms::disabled, &disabled);
if (disabled) {
state |= NS_EVENT_STATE_DISABLED;
state &= ~NS_EVENT_STATE_ENABLED;
} else {
state &= ~NS_EVENT_STATE_DISABLED;
state |= NS_EVENT_STATE_ENABLED;
}
return state;
}

View File

@ -67,6 +67,7 @@
#include "nsCOMPtr.h"
#include "nsLayoutAtoms.h"
#include "nsIEventStateManager.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
/**
@ -113,6 +114,32 @@ public:
// nsIContent
virtual PRInt32 IntrinsicState() const;
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, PRBool aNotify)
{
return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
}
virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
PRBool aNotify)
{
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
aValue, aNotify);
AfterSetAttr(aNameSpaceID, aName, &aValue, aNotify);
return rv;
}
virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
PRBool aNotify)
{
nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute,
aNotify);
AfterSetAttr(aNameSpaceID, aAttribute, nsnull, aNotify);
return rv;
}
protected:
/**
* Get the primary frame associated with this content
@ -128,6 +155,11 @@ protected:
*/
void GetSelect(nsIDOMHTMLSelectElement **aSelectElement) const;
/**
* Called when an attribute has just been changed
*/
void AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString* aValue, PRBool aNotify);
PRPackedBool mIsInitialized;
PRPackedBool mIsSelected;
};
@ -423,6 +455,17 @@ nsHTMLOptionElement::IntrinsicState() const
if (selected) {
state |= NS_EVENT_STATE_CHECKED;
}
PRBool disabled;
GetBoolAttr(nsHTMLAtoms::disabled, &disabled);
if (disabled) {
state |= NS_EVENT_STATE_DISABLED;
state &= ~NS_EVENT_STATE_ENABLED;
} else {
state &= ~NS_EVENT_STATE_DISABLED;
state |= NS_EVENT_STATE_ENABLED;
}
return state;
}
@ -468,6 +511,21 @@ nsHTMLOptionElement::GetSelect(nsIDOMHTMLSelectElement **aSelectElement) const
}
}
void
nsHTMLOptionElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString* aValue, PRBool aNotify)
{
if (aNotify && aNameSpaceID == kNameSpaceID_None &&
aName == nsHTMLAtoms::disabled) {
nsIDocument* document = GetCurrentDoc();
if (document) {
mozAutoDocUpdate(document, UPDATE_CONTENT_STATE, PR_TRUE);
document->ContentStatesChanged(this, nsnull, NS_EVENT_STATE_DISABLED |
NS_EVENT_STATE_ENABLED);
}
}
}
NS_IMETHODIMP
nsHTMLOptionElement::Initialize(JSContext* aContext,
JSObject *aObj,